Documentation ¶
Index ¶
- Constants
- Variables
- func CreateContextWithMessage(ctx context.Context, message *msg.RelayMsgBuf) context.Context
- func CreateContextWithNetID(ctx context.Context, netID int64) context.Context
- func CreateContextWithPacketId(ctx context.Context, packetId int64) context.Context
- func CreateContextWithParentReqId(ctx context.Context, reqId int64) context.Context
- func CreateContextWithParentReqIdAsReqId(ctx context.Context) context.Context
- func CreateContextWithRecvStartTime(ctx context.Context, recvStartTime int64) context.Context
- func CreateContextWithReqId(ctx context.Context, reqId int64) context.Context
- func CreateContextWithSrcP2pAddr(ctx context.Context, srcP2pAddress string) context.Context
- func CreateFirstMessage(connType string, ip net.IP, serverPort uint16, channelId uint32) []byte
- func GenerateNewReqId(msgid uint8) int64
- func GetPacketIdFromContext(ctx context.Context) int64
- func GetParentReqIdFromContext(ctx context.Context) int64
- func GetRecvCostTimeFromContext(ctx context.Context) int64
- func GetRecvStartTimeFromContext(ctx context.Context) int64
- func GetRemoteReqId(ctx context.Context) string
- func GetReqIdFromContext(ctx context.Context) int64
- func GetSrcP2pAddrFromContext(ctx context.Context) string
- func InheritRemoteReqIdFromParentReqId(ctx context.Context, reqId int64)
- func InheritRpcLoggerFromParentReqId(ctx context.Context, reqId int64)
- func MessageFromContext(ctx context.Context) *msg.RelayMsgBuf
- func Mylog(b bool, module string, v ...interface{})
- func NetIDFromContext(ctx context.Context) int64
- func Pack(privKey, plaintext []byte) ([]byte, error)
- func ParseFirstMessage(data []byte) (string, net.IP, uint16, uint32, error)
- func ReadEncryptionHeader(c net.Conn) (nonce uint64, dataLen uint32, bytesRead int, err error)
- func Register(cmd header.MsgType, handler func(context.Context, WriteCloser))
- func RegisterRemoteReqId(ctx context.Context, remoteReqId string) context.Context
- func RegisterReqId(ctx context.Context, rootReqId string)
- func StoreRemoteReqId(reqId int64, rootReqId string)
- func Unpack(c net.Conn, privKey []byte, maxBodySize int) (plaintext []byte, bytesRead int, err error)
- func WriteFull(c net.Conn, data []byte) error
- type ContextKV
- type Handler
- type HandlerFunc
- type MsgHandler
- type Server
- func (s *Server) AddVolumeLogJob(logAll bool, logRead bool, logWrite bool, logInbound bool, logOutbound bool)
- func (s *Server) Broadcast(msg *msg.RelayMsgBuf)
- func (s *Server) ConnsSize() int
- func (s *Server) GetInboundAndReset() int64
- func (s *Server) GetOutboundAndReset() int64
- func (s *Server) GetReadFlow() int64
- func (s *Server) GetSecondReadFlow() int64
- func (s *Server) GetSecondWriteFlow() int64
- func (s *Server) GetWriteFlow() int64
- func (s *Server) SetVolRecOptions(opt ...ServerVolRecOption)
- func (s *Server) Start(l net.Listener) error
- func (s *Server) Stop()
- func (s *Server) Unicast(ctx context.Context, netid int64, msg *msg.RelayMsgBuf) error
- type ServerConn
- func (sc *ServerConn) Close()
- func (sc *ServerConn) GetIP() string
- func (sc *ServerConn) GetLocalAddr() string
- func (sc *ServerConn) GetLocalP2pAddress() string
- func (sc *ServerConn) GetName() string
- func (sc *ServerConn) GetNetID() int64
- func (sc *ServerConn) GetPort() string
- func (sc *ServerConn) GetRemoteAddr() string
- func (sc *ServerConn) GetRemoteNetworkAddress() string
- func (sc *ServerConn) GetRemoteP2pAddress() string
- func (sc *ServerConn) SendBadVersionMsg(data []byte)
- func (sc *ServerConn) SetConnName(name string)
- func (sc *ServerConn) SetRemoteNetworkAddress(networkAddress string)
- func (sc *ServerConn) SetWriteHook(h []WriteHook)
- func (sc *ServerConn) Start()
- func (sc *ServerConn) Write(message *fwmsg.RelayMsgBuf, ctx context.Context) error
- type ServerOption
- func BufferSizeOption(indicator int) ServerOption
- func ContextKVOption(kv []ContextKV) ServerOption
- func LogOpenOption(b bool) ServerOption
- func MaxConnectionsOption(indicator int) ServerOption
- func MaxFlowOption(indicator int) ServerOption
- func MinAppVersionOption(minAppVersion uint16) ServerOption
- func OnBadAppVerOption(cb func(uint16, uint8, uint16) []byte) ServerOption
- func OnCloseOption(cb func(WriteCloser)) ServerOption
- func OnConnectOption(cb func(WriteCloser) bool) ServerOption
- func OnErrorOption(cb func(WriteCloser)) ServerOption
- func OnHandleOption(cb onHandleFunc) ServerOption
- func OnReadOption(cb onReadFunc) ServerOption
- func OnWriteOption(cb onWriteFunc) ServerOption
- func P2pAddressOption(p2pAddress string) ServerOption
- func ReadDeadlineOption(timeout int64) ServerOption
- type ServerVolRecOption
- func LogAllOption(logOpen bool) ServerVolRecOption
- func LogInboundOption(logOpen bool) ServerVolRecOption
- func LogOutboundOption(logOpen bool) ServerVolRecOption
- func LogReadOption(logOpen bool) ServerVolRecOption
- func LogWriteOption(logOpen bool) ServerVolRecOption
- func OnStartLogOption(cb func(*Server)) ServerVolRecOption
- type TaskPool
- type WriteCloser
- type WriteHook
- type WriteHookFunc
Constants ¶
View Source
const ( LOG_MODULE_SERVER = "server: " LOG_MODULE_START = "start: " LOG_MODULE_WRITELOOP = "writeLoop: " LOG_MODULE_READLOOP = "readLoop: " LOG_MODULE_HANDLELOOP = "handleLoop: " LOG_MODULE_CLOSE = "close: " )
View Source
const ( // This is either a client creating a connection, or a temporary connection made for a handshake // Read the first message from the connection. It should indicate what kind of connection it is ConnFirstMsgSize = 30 // Conn type (8) + IP (16) + server port (2) + channel ID (4) ConnTypeClient = "client__" ConnTypeHandshake = "handshke" HandshakeMessage = "sds_handshake" EncryptionHeaderSize = EncryptionNonceSize + EncryptionLengthSize // Nonce (8) + data length (4) EncryptionNonceSize = 8 EncryptionLengthSize = 4 )
Variables ¶
View Source
var ( GoroutineMap = &sync.Map{} HandshakeChanMap = &sync.Map{} // map[string]chan []byte Map that stores channels used during handshake process TimeRcv int64 )
View Source
var RemoteReqIdMap = utils.NewAutoCleanMap(24 * time.Hour)
Functions ¶
func CreateContextWithNetID ¶
func CreateContextWithReqId ¶
func CreateFirstMessage ¶
func GenerateNewReqId ¶
func GetPacketIdFromContext ¶
func GetRemoteReqId ¶
func GetReqIdFromContext ¶
func MessageFromContext ¶
func MessageFromContext(ctx context.Context) *msg.RelayMsgBuf
MessageFromContext get msg from context
func NetIDFromContext ¶
func ParseFirstMessage ¶
func ReadEncryptionHeader ¶
func RegisterRemoteReqId ¶
func RegisterReqId ¶
func StoreRemoteReqId ¶
Types ¶
type HandlerFunc ¶
type HandlerFunc func(context.Context, WriteCloser)
func GetHandlerFunc ¶
func GetHandlerFunc(id uint8) HandlerFunc
func (HandlerFunc) Handle ¶
func (f HandlerFunc) Handle(ctx context.Context, c WriteCloser)
type MsgHandler ¶
type MsgHandler struct {
// contains filtered or unexported fields
}
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func CreateServer ¶
func CreateServer(opt ...ServerOption) *Server
func (*Server) AddVolumeLogJob ¶
func (*Server) Broadcast ¶
func (s *Server) Broadcast(msg *msg.RelayMsgBuf)
func (*Server) GetInboundAndReset ¶
func (*Server) GetOutboundAndReset ¶
func (*Server) GetReadFlow ¶
func (*Server) GetSecondReadFlow ¶
func (*Server) GetSecondWriteFlow ¶
func (*Server) GetWriteFlow ¶
func (*Server) SetVolRecOptions ¶
func (s *Server) SetVolRecOptions(opt ...ServerVolRecOption)
type ServerConn ¶
type ServerConn struct {
// contains filtered or unexported fields
}
func CreateServerConn ¶
func CreateServerConn(id int64, s *Server, c net.Conn) *ServerConn
func (*ServerConn) Close ¶
func (sc *ServerConn) Close()
func (*ServerConn) GetIP ¶
func (sc *ServerConn) GetIP() string
func (*ServerConn) GetLocalAddr ¶
func (sc *ServerConn) GetLocalAddr() string
func (*ServerConn) GetLocalP2pAddress ¶
func (sc *ServerConn) GetLocalP2pAddress() string
func (*ServerConn) GetName ¶
func (sc *ServerConn) GetName() string
func (*ServerConn) GetNetID ¶
func (sc *ServerConn) GetNetID() int64
func (*ServerConn) GetPort ¶
func (sc *ServerConn) GetPort() string
func (*ServerConn) GetRemoteAddr ¶
func (sc *ServerConn) GetRemoteAddr() string
GetRemoteAddr returns the address from which the connection is directly coming from. In a VM with port forwarding, this might be the address of the host machine
func (*ServerConn) GetRemoteNetworkAddress ¶
func (sc *ServerConn) GetRemoteNetworkAddress() string
GetRemoteNetworkAddress returns the actual remote network address, as advertised by the remote node itself
func (*ServerConn) GetRemoteP2pAddress ¶
func (sc *ServerConn) GetRemoteP2pAddress() string
func (*ServerConn) SendBadVersionMsg ¶
func (sc *ServerConn) SendBadVersionMsg(data []byte)
func (*ServerConn) SetConnName ¶
func (sc *ServerConn) SetConnName(name string)
func (*ServerConn) SetRemoteNetworkAddress ¶
func (sc *ServerConn) SetRemoteNetworkAddress(networkAddress string)
func (*ServerConn) SetWriteHook ¶
func (sc *ServerConn) SetWriteHook(h []WriteHook)
func (*ServerConn) Start ¶
func (sc *ServerConn) Start()
Start server starts readLoop, writeLoop, handleLoop
func (*ServerConn) Write ¶
func (sc *ServerConn) Write(message *fwmsg.RelayMsgBuf, ctx context.Context) error
error is caught at application layer, if it's utils.ErrWouldBlock,sleep and then continue write
type ServerOption ¶
type ServerOption func(*options)
func BufferSizeOption ¶
func BufferSizeOption(indicator int) ServerOption
func ContextKVOption ¶
func ContextKVOption(kv []ContextKV) ServerOption
func LogOpenOption ¶
func LogOpenOption(b bool) ServerOption
func MaxConnectionsOption ¶
func MaxConnectionsOption(indicator int) ServerOption
func MaxFlowOption ¶
func MaxFlowOption(indicator int) ServerOption
func MinAppVersionOption ¶
func MinAppVersionOption(minAppVersion uint16) ServerOption
func OnBadAppVerOption ¶
func OnBadAppVerOption(cb func(uint16, uint8, uint16) []byte) ServerOption
func OnCloseOption ¶
func OnCloseOption(cb func(WriteCloser)) ServerOption
func OnConnectOption ¶
func OnConnectOption(cb func(WriteCloser) bool) ServerOption
func OnErrorOption ¶
func OnErrorOption(cb func(WriteCloser)) ServerOption
func OnHandleOption ¶
func OnHandleOption(cb onHandleFunc) ServerOption
func OnReadOption ¶
func OnReadOption(cb onReadFunc) ServerOption
func OnWriteOption ¶
func OnWriteOption(cb onWriteFunc) ServerOption
func P2pAddressOption ¶
func P2pAddressOption(p2pAddress string) ServerOption
func ReadDeadlineOption ¶
func ReadDeadlineOption(timeout int64) ServerOption
type ServerVolRecOption ¶
type ServerVolRecOption func(*volRecOpts)
func OnStartLogOption ¶
func OnStartLogOption(cb func(*Server)) ServerVolRecOption
type TaskPool ¶
type TaskPool struct {
// contains filtered or unexported fields
}
TaskPool
var GlobalTaskPool *TaskPool
GlobalTaskPool
type WriteCloser ¶
type WriteCloser interface { Write(*fwmsg.RelayMsgBuf, context.Context) error Close() }
type WriteHook ¶
type WriteHook struct { MessageId uint8 Fn WriteHookFunc }
type WriteHookFunc ¶
type WriteHookFunc func(ctx context.Context, packetId, costTime int64, conn WriteCloser)
Click to show internal directories.
Click to hide internal directories.