core

package
v0.11.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

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 CreateContextWithMessage

func CreateContextWithMessage(ctx context.Context, message *msg.RelayMsgBuf) context.Context

func CreateContextWithNetID

func CreateContextWithNetID(ctx context.Context, netID int64) context.Context

func CreateContextWithPacketId added in v0.9.0

func CreateContextWithPacketId(ctx context.Context, packetId int64) context.Context

func CreateContextWithParentReqId added in v0.9.0

func CreateContextWithParentReqId(ctx context.Context, reqId int64) context.Context

func CreateContextWithParentReqIdAsReqId added in v0.9.0

func CreateContextWithParentReqIdAsReqId(ctx context.Context) context.Context

func CreateContextWithRecvStartTime added in v0.9.0

func CreateContextWithRecvStartTime(ctx context.Context, recvStartTime int64) context.Context

func CreateContextWithReqId added in v0.9.0

func CreateContextWithReqId(ctx context.Context, reqId int64) context.Context

func CreateContextWithSrcP2pAddr added in v0.10.0

func CreateContextWithSrcP2pAddr(ctx context.Context, srcP2pAddress string) context.Context

func CreateFirstMessage added in v0.8.0

func CreateFirstMessage(connType string, ip net.IP, serverPort uint16, channelId uint32) []byte

func GenerateNewReqId added in v0.10.0

func GenerateNewReqId(msgid uint8) int64

func GetPacketIdFromContext added in v0.9.0

func GetPacketIdFromContext(ctx context.Context) int64

func GetParentReqIdFromContext added in v0.9.0

func GetParentReqIdFromContext(ctx context.Context) int64

func GetRecvCostTimeFromContext added in v0.9.0

func GetRecvCostTimeFromContext(ctx context.Context) int64

func GetRecvStartTimeFromContext added in v0.9.0

func GetRecvStartTimeFromContext(ctx context.Context) int64

func GetRemoteReqId added in v0.9.0

func GetRemoteReqId(ctx context.Context) string

func GetReqIdFromContext added in v0.9.0

func GetReqIdFromContext(ctx context.Context) int64

func GetSrcP2pAddrFromContext added in v0.10.0

func GetSrcP2pAddrFromContext(ctx context.Context) string

func InheritRemoteReqIdFromParentReqId added in v0.9.0

func InheritRemoteReqIdFromParentReqId(ctx context.Context, reqId int64)

func InheritRpcLoggerFromParentReqId added in v0.9.0

func InheritRpcLoggerFromParentReqId(ctx context.Context, reqId int64)

func MessageFromContext

func MessageFromContext(ctx context.Context) *msg.RelayMsgBuf

MessageFromContext get msg from context

func Mylog

func Mylog(b bool, module string, v ...interface{})

func NetIDFromContext

func NetIDFromContext(ctx context.Context) int64

func Pack added in v0.9.0

func Pack(privKey, plaintext []byte) ([]byte, error)

func ParseFirstMessage added in v0.8.0

func ParseFirstMessage(data []byte) (string, net.IP, uint16, uint32, error)

func ReadEncryptionHeader added in v0.9.0

func ReadEncryptionHeader(c net.Conn) (nonce uint64, dataLen uint32, bytesRead int, err error)

func Register

func Register(cmd header.MsgType, handler func(context.Context, WriteCloser))

func RegisterRemoteReqId added in v0.9.0

func RegisterRemoteReqId(ctx context.Context, remoteReqId string) context.Context

func RegisterReqId added in v0.9.0

func RegisterReqId(ctx context.Context, rootReqId string)

func RegisterTimeoutHandler added in v0.7.0

func RegisterTimeoutHandler(msgType header.MsgType, handler TimeoutHandler)

func StoreRemoteReqId added in v0.9.0

func StoreRemoteReqId(reqId int64, rootReqId string)

func Unpack added in v0.10.0

func Unpack(c net.Conn, privKey []byte, maxBodySize int) (plaintext []byte, bytesRead int, err error)

func WriteFull added in v0.8.0

func WriteFull(c net.Conn, data []byte) error

Types

type ContextKV added in v0.9.0

type ContextKV struct {
	Key   interface{}
	Value interface{}
}

type Handler

type Handler interface {
	Handle(context.Context, interface{})
}

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 MyValue added in v0.7.0

type MyValue struct {
	// contains filtered or unexported fields
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func CreateServer

func CreateServer(opt ...ServerOption) *Server

func ServerFromCtx

func ServerFromCtx(ctx context.Context) (*Server, bool)

func (*Server) AddVolumeLogJob added in v0.8.0

func (s *Server) AddVolumeLogJob(logAll bool, logRead bool, logWrite bool, logInbound bool, logOutbound bool)

func (*Server) Broadcast

func (s *Server) Broadcast(msg *msg.RelayMsgBuf)

func (*Server) ConnsSize

func (s *Server) ConnsSize() int

func (*Server) GetInboundAndReset added in v0.5.0

func (s *Server) GetInboundAndReset() int64

func (*Server) GetOutboundAndReset added in v0.5.0

func (s *Server) GetOutboundAndReset() int64

func (*Server) GetReadFlow

func (s *Server) GetReadFlow() int64

func (*Server) GetSecondReadFlow

func (s *Server) GetSecondReadFlow() int64

func (*Server) GetSecondWriteFlow

func (s *Server) GetSecondWriteFlow() int64

func (*Server) GetWriteFlow

func (s *Server) GetWriteFlow() int64

func (*Server) SetVolRecOptions added in v0.8.0

func (s *Server) SetVolRecOptions(opt ...ServerVolRecOption)

func (*Server) Start

func (s *Server) Start(l net.Listener) error

func (*Server) Stop

func (s *Server) Stop()

func (*Server) Unicast

func (s *Server) Unicast(ctx context.Context, netid int64, msg *msg.RelayMsgBuf) error

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 LogAllOption added in v0.8.0

func LogAllOption(logOpen bool) ServerVolRecOption

LogAllOption

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

func (*TaskPool) Job

func (tp *TaskPool) Job(id int64, fc func()) error

Job: add job to the pool

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL