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 RegisterTimeoutHandler(msgType header.MsgType, handler TimeoutHandler)
- 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 MyValue
- 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(version uint16, cmd uint8)
- 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 *message.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 OnCloseOption(cb func(WriteCloser)) ServerOption
- func OnConnectOption(cb func(WriteCloser) bool) ServerOption
- func OnErrorOption(cb func(WriteCloser)) ServerOption
- func OnMessageOption(cb func(msg.RelayMsgBuf, WriteCloser)) ServerOption
- func P2pAddressOption(p2pAddress string) ServerOption
- type ServerVolRecOption
- func LogAllOption(logOpen bool) ServerVolRecOption
- func LogInboundOption(logOpen bool) ServerVolRecOption
- func LogOutboundOption(logOpen bool) ServerVolRecOption
- func LogReadOption(logOpen bool) ServerVolRecOption
- func OnStartLogOption(cb func(*Server)) ServerVolRecOption
- func OnWriteOption(logOpen bool) ServerVolRecOption
- type TaskPool
- type TimeoutHandler
- 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 ( TimeoutRegistry [header.NUMBER_MESSAGE_TYPES]TimeoutHandler TimoutMap = newTimeoutMap() )
View Source
var RemoteReqIdMap = utils.NewAutoCleanMap(24 * time.Hour)
Functions ¶
func CreateContextWithNetID ¶
func CreateContextWithPacketId ¶ added in v0.9.0
func CreateContextWithParentReqId ¶ added in v0.9.0
func CreateContextWithParentReqIdAsReqId ¶ added in v0.9.0
func CreateContextWithRecvStartTime ¶ added in v0.9.0
func CreateContextWithReqId ¶ added in v0.9.0
func CreateContextWithSrcP2pAddr ¶ added in v0.10.0
func CreateFirstMessage ¶ added in v0.8.0
func GenerateNewReqId ¶ added in v0.10.0
func GetPacketIdFromContext ¶ added in v0.9.0
func GetParentReqIdFromContext ¶ added in v0.9.0
func GetRecvCostTimeFromContext ¶ added in v0.9.0
func GetRecvStartTimeFromContext ¶ added in v0.9.0
func GetRemoteReqId ¶ added in v0.9.0
func GetReqIdFromContext ¶ added in v0.9.0
func GetSrcP2pAddrFromContext ¶ added in v0.10.0
func InheritRemoteReqIdFromParentReqId ¶ added in v0.9.0
func InheritRpcLoggerFromParentReqId ¶ added in v0.9.0
func MessageFromContext ¶
func MessageFromContext(ctx context.Context) *msg.RelayMsgBuf
MessageFromContext get msg from context
func NetIDFromContext ¶
func ParseFirstMessage ¶ added in v0.8.0
func ReadEncryptionHeader ¶ added in v0.9.0
func RegisterRemoteReqId ¶ added in v0.9.0
func RegisterReqId ¶ added in v0.9.0
func RegisterTimeoutHandler ¶ added in v0.7.0
func RegisterTimeoutHandler(msgType header.MsgType, handler TimeoutHandler)
func StoreRemoteReqId ¶ added in v0.9.0
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 ¶ added in v0.8.0
func (*Server) Broadcast ¶
func (s *Server) Broadcast(msg *msg.RelayMsgBuf)
func (*Server) GetInboundAndReset ¶ added in v0.5.0
func (*Server) GetOutboundAndReset ¶ added in v0.5.0
func (*Server) GetReadFlow ¶
func (*Server) GetSecondReadFlow ¶
func (*Server) GetSecondWriteFlow ¶
func (*Server) GetWriteFlow ¶
func (*Server) SetVolRecOptions ¶ added in v0.8.0
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 ¶ added in v0.5.0
func (sc *ServerConn) GetLocalAddr() string
func (*ServerConn) GetLocalP2pAddress ¶ added in v0.8.0
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 ¶ added in v0.5.0
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 ¶ added in v0.11.0
func (sc *ServerConn) GetRemoteNetworkAddress() string
GetRemoteNetworkAddress returns the actual remote network address, as advertised by the remote node itself
func (*ServerConn) GetRemoteP2pAddress ¶ added in v0.8.0
func (sc *ServerConn) GetRemoteP2pAddress() string
func (*ServerConn) SendBadVersionMsg ¶ added in v0.7.0
func (sc *ServerConn) SendBadVersionMsg(version uint16, cmd uint8)
func (*ServerConn) SetConnName ¶
func (sc *ServerConn) SetConnName(name string)
func (*ServerConn) SetRemoteNetworkAddress ¶ added in v0.11.0
func (sc *ServerConn) SetRemoteNetworkAddress(networkAddress string)
func (*ServerConn) SetWriteHook ¶ added in v0.9.0
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 *message.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 ¶ added in v0.9.0
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 ¶ added in v0.7.0
func MinAppVersionOption(minAppVersion uint16) 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 OnMessageOption ¶
func OnMessageOption(cb func(msg.RelayMsgBuf, WriteCloser)) ServerOption
func P2pAddressOption ¶ added in v0.8.0
func P2pAddressOption(p2pAddress string) ServerOption
type ServerVolRecOption ¶ added in v0.8.0
type ServerVolRecOption func(*volRecOpts)
func LogInboundOption ¶ added in v0.8.0
func LogInboundOption(logOpen bool) ServerVolRecOption
LogInboundOption
func LogOutboundOption ¶ added in v0.8.0
func LogOutboundOption(logOpen bool) ServerVolRecOption
LogOutboundOption
func LogReadOption ¶ added in v0.8.0
func LogReadOption(logOpen bool) ServerVolRecOption
LogReadOption
func OnStartLogOption ¶ added in v0.8.0
func OnStartLogOption(cb func(*Server)) ServerVolRecOption
func OnWriteOption ¶ added in v0.8.0
func OnWriteOption(logOpen bool) ServerVolRecOption
OnWriteOption
type TaskPool ¶
type TaskPool struct {
// contains filtered or unexported fields
}
TaskPool
var GlobalTaskPool *TaskPool
GlobalTaskPool
type TimeoutHandler ¶ added in v0.7.0
type TimeoutHandler interface { Handle(ctx context.Context, message *msg.RelayMsgBuf) GetDuration() time.Duration GetTimeoutMsg(reqMessage *msg.RelayMsgBuf) *msg.RelayMsgBuf CanDelete(rspMessage *msg.RelayMsgBuf) bool }
type WriteCloser ¶
type WriteCloser interface { Write(*message.RelayMsgBuf, context.Context) error Close() }
type WriteHook ¶ added in v0.9.0
type WriteHook struct { MessageId uint8 Fn WriteHookFunc }
type WriteHookFunc ¶ added in v0.11.4
type WriteHookFunc func(ctx context.Context, packetId, costTime int64, conn WriteCloser)
Click to show internal directories.
Click to hide internal directories.