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 CreateFirstMessage(connType string, serverPort uint16, channelId uint32) []byte
- func EncryptAndPack(privKey, plaintext []byte) ([]byte, error)
- 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 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(plaintext []byte) ([]byte, error)
- func ParseFirstMessage(data []byte) (string, uint16, uint32, error)
- func ReadEncryptedHeaderAndBody(c net.Conn, privKey []byte, maxBodySize int) (plaintext []byte, bytesRead int, err error)
- func ReadEncryptionHeader(c net.Conn) (nonce uint64, dataLen uint32, bytesRead int, err error)
- func ReadNonEncryptedHeaderAndBody(c net.Conn, maxBodySize int) (plaintext []byte, bytesRead int, err error)
- func Register(cmd string, handler func(context.Context, WriteCloser))
- func RegisterRemoteReqId(ctx context.Context, remoteReqId string) context.Context
- func RegisterReqId(ctx context.Context, rootReqId string)
- func RegisterTimeoutHandler(cmd string, handler TimeoutHandler)
- func StoreRemoteReqId(reqId int64, rootReqId string)
- func UnpackEncryptionHeader(data []byte) (uint64, uint32)
- 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) GetRemoteP2pAddress() string
- func (sc *ServerConn) SendBadVersionMsg(version uint16, cmd string)
- func (sc *ServerConn) SetConnName(name 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
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 ( ConnFirstMsgSize = 14 // Conn type (8) + server port (2) + channel ID (4) ConnTypeClient = "client__" ConnTypeHandshake = "handshke" HandshakeMessage = "sds_handshake" EncryptionHeaderSize = 12 // 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 = make(map[string]TimeoutHandler) TimoutMap = newTimeoutMap() )
View Source
var RemoteReqIdMap = utils.NewAutoCleanMap(24 * time.Hour)
Functions ¶
func CreateContextWithMessage ¶
CreateContextWithMessage
func CreateContextWithNetID ¶
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 CreateFirstMessage ¶ added in v0.8.0
func EncryptAndPack ¶ added in v0.8.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 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 ParseFirstMessage ¶ added in v0.8.0
func ReadEncryptedHeaderAndBody ¶ added in v0.8.0
func ReadEncryptionHeader ¶ added in v0.9.0
func ReadNonEncryptedHeaderAndBody ¶ 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(cmd string, handler TimeoutHandler)
func StoreRemoteReqId ¶ added in v0.9.0
func UnpackEncryptionHeader ¶ added in v0.9.0
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server
func (*Server) AddVolumeLogJob ¶ added in v0.8.0
func (*Server) GetInboundAndReset ¶ added in v0.5.0
func (*Server) GetOutboundAndReset ¶ added in v0.5.0
func (*Server) SetVolRecOptions ¶ added in v0.8.0
func (s *Server) SetVolRecOptions(opt ...ServerVolRecOption)
type ServerConn ¶
type ServerConn struct {
// contains filtered or unexported fields
}
ServerConn
func CreateServerConn ¶
func CreateServerConn(id int64, s *Server, c net.Conn) *ServerConn
CreateServerConn
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) GetRemoteAddr ¶ added in v0.5.0
func (sc *ServerConn) GetRemoteAddr() string
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 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
Write * error is caught at application layer, if it's utils.ErrWouldBlock,sleep and then continue write
type ServerOption ¶
type ServerOption func(*options)
ServerOption
func ContextKVOption ¶ added in v0.9.0
func ContextKVOption(kv []ContextKV) ServerOption
ContextKVOption
func MaxConnectionsOption ¶
func MaxConnectionsOption(indicator int) ServerOption
MaxConnectionsOption
func MinAppVersionOption ¶ added in v0.7.0
func MinAppVersionOption(minAppVersion uint16) ServerOption
func OnMessageOption ¶
func OnMessageOption(cb func(msg.RelayMsgBuf, WriteCloser)) ServerOption
OnMessageOption
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() }
WriteCloser
Click to show internal directories.
Click to hide internal directories.