akNet

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 12, 2020 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnMessage_MainIDPackLen = 2  //主命令
	EnMessage_SubIDPackLen  = 2  //次命令
	EnMessage_PostType      = 2  //发送类型
	EnMessage_DataPackLen   = 6  //真实数据长度 (主命令+次命令+发送类型)
	EnMessage_NoDataLen     = 10 //非data数据长度(包体之前的)->(主命令+次命令+发送类型+datalen)

	EnMessage_SvrDataPackLen  = 50 //真实数据长度 (主命令+次命令+发送类型+ Identify长度 + Identify内容+RemoteAddr 长度+RemoteAddr 内容)
	EnMessage_SvrNoDataLen    = 54 //非data数据长度(包体之前的)->(主命令+次命令+发送类型+ Identify长度 + Identify内容+datalen+RemoteAddr 长度+RemoteAddr 内容)
	EnMessage_IdentifyEixst   = 1  //Identify 长度
	EnMessage_IdentifyLen     = 21 //Identify 内容
	EnMessage_RemoteAddrEixst = 1  //RemoteAddr 长度
	EnMessage_RemoteAddrLen   = 21 //RemoteAddr 内容
)

- 协议格式,小端字节序

转发目的位置 |主命令号 | 次命令号 | 包长度 | 包体 ------------|--------| --------| -------- | ---- 2字节 |2字节 | 2字节 | 4字节 | 包体

View Source
const (
	MsgPostType_Single    = uint16(1)
	MsgPostType_Broadcast = uint16(2)
)

message Post type

View Source
const (
	ESessionBeginNum = uint64(10000)
)

session begin number with 10000

Variables

View Source
var (
	GTrustedList   = map[string]bool{}
	GUnTrustedList = map[string]bool{}
)
View Source
var (
	GClientSessionPool *TClientSession
	GServerSessionPool *TServerSession
)

Functions

func DecodeCmd

func DecodeCmd(cmd uint32) (uint16, uint16)

func: DecodeCmd purpose: DecodeCmd message cmd to mainid and subid.

func EncodeCmd

func EncodeCmd(mainID, subID uint16) uint32

func: EncodeCmd purpose: Encode message mainid and subid to cmd.

func GetAllMessageIDs

func GetAllMessageIDs() (msgs []uint32)

func GetModuleDef

func GetModuleDef(routeid define.ERouteId) string

func InitTrusted

func InitTrusted()

func Int64Toip

func Int64Toip(ipn int64) net.IP

ip地址int64转string

func IpToInt64

func IpToInt64(ip net.IP) int64

ip地址string转int64

func IsTrusted

func IsTrusted(ip string) bool

func IsUnTrusted

func IsUnTrusted(ip string) bool

func MSGConsumer

func MSGConsumer(Addr string, session TcpSession)

会话消息消费者 session message consumer.

func MSGProducer

func MSGProducer(addr string, data []byte, topic string, session TcpSession)

会话消息生产者 session message producer.

func RegisterMessage

func RegisterMessage(mainID, subID uint16, proc interface{})

func RegisterMessageRet

func RegisterMessageRet(session TcpSession) (succ bool, err error)

func ResponseHeartBeat

func ResponseHeartBeat(session TcpSession) (succ bool, err error)

func SpecialLoginMsgFilter

func SpecialLoginMsgFilter(main, sub uint16) (ok bool)

func UnPackExternalMsg

func UnPackExternalMsg(c *net.TCPConn, pack IMessagePack) (succ bool)

@func: UnPackExternalMsg 解服务器外部消息(客户端,clientsession 注册消息) @parma1: 连接对象 c *net.TCPConn @param2: 解包对象 pack IMessagePack

func UnPackInnerMsg

func UnPackInnerMsg(c *net.TCPConn, pack IMessagePack) (succ bool)

@func: UnPackInnerMsg 解服务器内部消息(server 间客户端发来的请求或者其他rpc消息传递) @parma1: 连接对象 c *net.TCPConn @param2: 解包对象 pack IMessagePack

Types

type AfterDialAct

type AfterDialAct func(s TcpSession)

after dial connect todo action.

type ClientProtocol

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

model: ClientProtocol Client to Server, message

func (*ClientProtocol) Clean

func (this *ClientProtocol) Clean()

func (*ClientProtocol) GetDataLen

func (this *ClientProtocol) GetDataLen() (datalen uint32)

func (*ClientProtocol) GetIdentify

func (this *ClientProtocol) GetIdentify() string

func (*ClientProtocol) GetMessageID

func (this *ClientProtocol) GetMessageID() (mainID uint16, subID uint16)

func (*ClientProtocol) GetPostType

func (this *ClientProtocol) GetPostType() (pt uint16)

func (*ClientProtocol) GetRemoteAddr

func (this *ClientProtocol) GetRemoteAddr() (addr string)

func (*ClientProtocol) GetRouteID

func (this *ClientProtocol) GetRouteID() (route uint16)

func (*ClientProtocol) GetSrcMsg

func (this *ClientProtocol) GetSrcMsg() (data []byte)

func (*ClientProtocol) PackAction

func (this *ClientProtocol) PackAction(Output []byte) (err error)

func (*ClientProtocol) PackAction4Client

func (this *ClientProtocol) PackAction4Client(Output []byte) (err error)

func (*ClientProtocol) PackClientMsg

func (this *ClientProtocol) PackClientMsg(mainid, subid uint16, msg proto.Message) (out []byte, err error)

func (*ClientProtocol) PackData

func (this *ClientProtocol) PackData(msg proto.Message) (data []byte, err error)

func (*ClientProtocol) PackInnerMsg

func (this *ClientProtocol) PackInnerMsg(mainid, subid uint16, msg proto.Message) (out []byte, err error)

func (*ClientProtocol) SetCmd

func (this *ClientProtocol) SetCmd(mainid, subid uint16, data []byte)

func (*ClientProtocol) SetIdentify

func (this *ClientProtocol) SetIdentify(identify string)

func (*ClientProtocol) SetPostType

func (this *ClientProtocol) SetPostType(pt uint16)

func (*ClientProtocol) SetRemoteAddr

func (this *ClientProtocol) SetRemoteAddr(addr string)

func (*ClientProtocol) UnPackData

func (this *ClientProtocol) UnPackData() (msg proto.Message, cb reflect.Value, err error, exist bool)

func (*ClientProtocol) UnPackMsg4Client

func (this *ClientProtocol) UnPackMsg4Client(InData []byte) (pos int, err error)

func (*ClientProtocol) UnPackMsg4Svr

func (this *ClientProtocol) UnPackMsg4Svr(InData []byte) (pos int, err error)

type ClientTcpSession

type ClientTcpSession struct {
	sync.Mutex

	RemoteAddr string

	// session id
	SessionID uint64
	//Dest point
	SvrType define.ERouteId
	//src point
	RegPoint define.ERouteId
	//person StrIdentify
	StrIdentify string
	//
	Name string
	// contains filtered or unexported fields
}

func NewClientSession

func NewClientSession(addr string,
	conn *net.TCPConn,
	ctx context.Context,
	SvrType define.ERouteId,
	off chan *ClientTcpSession,
	pack IMessagePack,
	procName string) *ClientTcpSession

func (*ClientTcpSession) Alive

func (this *ClientTcpSession) Alive() bool

func (*ClientTcpSession) GetIdentify

func (this *ClientTcpSession) GetIdentify() string

func (*ClientTcpSession) GetModuleName

func (this *ClientTcpSession) GetModuleName() string

func (*ClientTcpSession) GetPack

func (this *ClientTcpSession) GetPack() (obj IMessagePack)

func (*ClientTcpSession) GetRegPoint

func (this *ClientTcpSession) GetRegPoint() (RegPoint define.ERouteId)

func (*ClientTcpSession) GetRemoteAddr

func (this *ClientTcpSession) GetRemoteAddr() string

func (*ClientTcpSession) HandleSession

func (this *ClientTcpSession) HandleSession(sw *sync.WaitGroup)

func (*ClientTcpSession) IsUser

func (this *ClientTcpSession) IsUser() bool

func (*ClientTcpSession) Offline

func (this *ClientTcpSession) Offline()

func (*ClientTcpSession) Push

func (this *ClientTcpSession) Push(RegPoint define.ERouteId)

func (*ClientTcpSession) RefreshHeartBeat

func (this *ClientTcpSession) RefreshHeartBeat(mainid, subid uint16) bool

func (*ClientTcpSession) SendInnerBroadcastMsg

func (this *ClientTcpSession) SendInnerBroadcastMsg(mainid, subid uint16, msg proto.Message) (succ bool, err error)

func (*ClientTcpSession) SendInnerClientMsg

func (this *ClientTcpSession) SendInnerClientMsg(mainid, subid uint16, msg proto.Message) (succ bool, err error)

func (*ClientTcpSession) SendInnerSvrMsg

func (this *ClientTcpSession) SendInnerSvrMsg(mainid, subid uint16, msg proto.Message) (succ bool, err error)

func (*ClientTcpSession) SendSvrClientMsg

func (this *ClientTcpSession) SendSvrClientMsg(mainid, subid uint16, msg proto.Message) (succ bool, err error)

func (*ClientTcpSession) SetIdentify

func (this *ClientTcpSession) SetIdentify(StrIdentify string)

func (*ClientTcpSession) SetSendCache

func (this *ClientTcpSession) SetSendCache(data []byte)

func (*ClientTcpSession) WriteMessage

func (this *ClientTcpSession) WriteMessage(data []byte) (succ bool)

type ESessionGetType

type ESessionGetType int
const (
	ESessionGetType_Identify ESessionGetType = 1
	ESessionGetType_RegPoint ESessionGetType = 2
)

type ESessionType

type ESessionType int8
const (
	ESessionType_Server ESessionType = 1
	ESessionType_Client ESessionType = 2
)

type IMessagePack

type IMessagePack interface {
	PackAction(Output []byte) (err error)
	PackAction4Client(Output []byte) (err error)
	PackData(msg proto.Message) (data []byte, err error)
	UnPackMsg4Client(InData []byte) (pos int, err error)
	UnPackData() (msg proto.Message, cb reflect.Value, err error, exist bool)
	GetRouteID() (route uint16)
	GetMessageID() (mainID uint16, subID uint16)
	Clean()
	SetCmd(mainid, subid uint16, data []byte)
	PackInnerMsg(mainid, subid uint16, msg proto.Message) (out []byte, err error)
	PackClientMsg(mainid, subid uint16, msg proto.Message) (out []byte, err error)
	GetSrcMsg() (data []byte)
	SetIdentify(identify string)
	GetIdentify() string
	UnPackMsg4Svr(InData []byte) (pos int, err error)
	GetDataLen() (datalen uint32)
	SetRemoteAddr(addr string)
	GetRemoteAddr() (addr string)
	SetPostType(pt uint16)
	GetPostType() (pt uint16)
}

type IProcessConnSession

type IProcessConnSession interface {
	RemoveSession(key interface{})
	AddSession(key interface{}, session TcpSession)
	GetSession(key interface{}) (session TcpSession)
	GetSessionByIdentify(key interface{}) (session TcpSession)
	GetAllSession() (sessions sync.Map)
}

type MessageCb

type MessageCb func(c net.Conn, mainID uint16, subID uint16, msg proto.Message)

session, data, data len

type ServerProtocol

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

model: ServerProtocol server to server, message

func (*ServerProtocol) Clean

func (this *ServerProtocol) Clean()

func (*ServerProtocol) GetDataLen

func (this *ServerProtocol) GetDataLen() (datalen uint32)

func (*ServerProtocol) GetIdentify

func (this *ServerProtocol) GetIdentify() string

func (*ServerProtocol) GetMessageID

func (this *ServerProtocol) GetMessageID() (mainID uint16, subID uint16)

func (*ServerProtocol) GetPostType

func (this *ServerProtocol) GetPostType() (pt uint16)

func (*ServerProtocol) GetRemoteAddr

func (this *ServerProtocol) GetRemoteAddr() (addr string)

func (*ServerProtocol) GetRouteID

func (this *ServerProtocol) GetRouteID() (route uint16)

func (*ServerProtocol) GetSrcMsg

func (this *ServerProtocol) GetSrcMsg() (data []byte)

func (*ServerProtocol) PackAction

func (this *ServerProtocol) PackAction(Output []byte) (err error)

func (*ServerProtocol) PackAction4Client

func (this *ServerProtocol) PackAction4Client(Output []byte) (err error)

func (*ServerProtocol) PackClientMsg

func (this *ServerProtocol) PackClientMsg(mainid, subid uint16, msg proto.Message) (out []byte, err error)

func (*ServerProtocol) PackData

func (this *ServerProtocol) PackData(msg proto.Message) (data []byte, err error)

func (*ServerProtocol) PackInnerMsg

func (this *ServerProtocol) PackInnerMsg(mainid, subid uint16, msg proto.Message) (out []byte, err error)

func (*ServerProtocol) SetCmd

func (this *ServerProtocol) SetCmd(mainid, subid uint16, data []byte)

func (*ServerProtocol) SetIdentify

func (this *ServerProtocol) SetIdentify(identify string)

func (*ServerProtocol) SetPostType

func (this *ServerProtocol) SetPostType(pt uint16)

func (*ServerProtocol) SetRemoteAddr

func (this *ServerProtocol) SetRemoteAddr(addr string)

func (*ServerProtocol) UnPackData

func (this *ServerProtocol) UnPackData() (msg proto.Message, cb reflect.Value, err error, exist bool)

func (*ServerProtocol) UnPackMsg4Client

func (this *ServerProtocol) UnPackMsg4Client(InData []byte) (pos int, err error)

func (*ServerProtocol) UnPackMsg4Svr

func (this *ServerProtocol) UnPackMsg4Svr(InData []byte) (pos int, err error)

type SvrTcpSession

type SvrTcpSession struct {
	sync.Mutex

	RemoteAddr string

	// session id
	SessionID uint64
	//Dest point
	SvrType define.ERouteId
	//src point
	RegPoint define.ERouteId
	//person StrIdentify
	StrIdentify string

	//
	Name string
	// contains filtered or unexported fields
}

func NewSvrSession

func NewSvrSession(addr string,
	conn *net.TCPConn,
	ctx context.Context,
	SvrType define.ERouteId,
	off chan *SvrTcpSession,
	pack IMessagePack,
	procName string) *SvrTcpSession

func (*SvrTcpSession) Alive

func (this *SvrTcpSession) Alive() bool

func (*SvrTcpSession) GetIdentify

func (this *SvrTcpSession) GetIdentify() string

func (*SvrTcpSession) GetModuleName

func (this *SvrTcpSession) GetModuleName() string

func (*SvrTcpSession) GetPack

func (this *SvrTcpSession) GetPack() (obj IMessagePack)

func (*SvrTcpSession) GetRegPoint

func (this *SvrTcpSession) GetRegPoint() (RegPoint define.ERouteId)

func (*SvrTcpSession) GetRemoteAddr

func (this *SvrTcpSession) GetRemoteAddr() string

func (*SvrTcpSession) HandleSession

func (this *SvrTcpSession) HandleSession(sw *sync.WaitGroup)

func (*SvrTcpSession) IsUser

func (this *SvrTcpSession) IsUser() bool

func (*SvrTcpSession) Offline

func (this *SvrTcpSession) Offline()

func (*SvrTcpSession) Push

func (this *SvrTcpSession) Push(RegPoint define.ERouteId)

func (*SvrTcpSession) RefreshHeartBeat

func (this *SvrTcpSession) RefreshHeartBeat(mainid, subid uint16) bool

func (*SvrTcpSession) SendInnerBroadcastMsg

func (this *SvrTcpSession) SendInnerBroadcastMsg(mainid, subid uint16, msg proto.Message) (succ bool, err error)

func (*SvrTcpSession) SendInnerClientMsg

func (this *SvrTcpSession) SendInnerClientMsg(mainid, subid uint16, msg proto.Message) (succ bool, err error)

func (*SvrTcpSession) SendInnerSvrMsg

func (this *SvrTcpSession) SendInnerSvrMsg(mainid, subid uint16, msg proto.Message) (succ bool, err error)

func (*SvrTcpSession) SendSvrClientMsg

func (this *SvrTcpSession) SendSvrClientMsg(mainid, subid uint16, msg proto.Message) (succ bool, err error)

func (*SvrTcpSession) SetIdentify

func (this *SvrTcpSession) SetIdentify(StrIdentify string)

func (*SvrTcpSession) SetSendCache

func (this *SvrTcpSession) SetSendCache(data []byte)

func (*SvrTcpSession) WriteMessage

func (this *SvrTcpSession) WriteMessage(data []byte) (succ bool)

type TClient2ServerSession

type TClient2ServerSession struct {
	sync.Mutex
	// contains filtered or unexported fields
}
var (
	GClient2ServerSession *TClient2ServerSession
)

func (*TClient2ServerSession) AddSession

func (this *TClient2ServerSession) AddSession(key interface{}, session TcpSession)

func (*TClient2ServerSession) GetAllSession

func (this *TClient2ServerSession) GetAllSession() (sessions sync.Map)

func (*TClient2ServerSession) GetSession

func (this *TClient2ServerSession) GetSession(key interface{}) (session TcpSession)

func (*TClient2ServerSession) GetSessionByIdentify

func (this *TClient2ServerSession) GetSessionByIdentify(key interface{}) (session TcpSession)

func (*TClient2ServerSession) RemoveSession

func (this *TClient2ServerSession) RemoveSession(key interface{})

type TClientSession

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

func (*TClientSession) Get

func (this *TClientSession) Get() (s *TConnSession)

func (*TClientSession) Push

func (this *TClientSession) Push(s *TConnSession)

type TConnSession

type TConnSession struct {
	Connsess *TcpSession
	Svr      int32
}

type TMessageProc

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

func GetMessageInfo

func GetMessageInfo(mainID, subID uint16) (proc *TMessageProc, finded bool)

type TServerSession

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

func (*TServerSession) Get

func (this *TServerSession) Get() (s *TConnSession)

func (*TServerSession) Push

func (this *TServerSession) Push(s *TConnSession)

type TSvr2SvrSession

type TSvr2SvrSession struct {
	sync.Mutex
	// contains filtered or unexported fields
}
var (
	GServer2ServerSession *TSvr2SvrSession
)

func (*TSvr2SvrSession) AddSession

func (this *TSvr2SvrSession) AddSession(key interface{}, session TcpSession)

func (*TSvr2SvrSession) GetAllSession

func (this *TSvr2SvrSession) GetAllSession() (sessions sync.Map)

func (*TSvr2SvrSession) GetSession

func (this *TSvr2SvrSession) GetSession(key interface{}) (session TcpSession)

func (*TSvr2SvrSession) GetSessionByIdentify

func (this *TSvr2SvrSession) GetSessionByIdentify(key interface{}) (session TcpSession)

func (*TSvr2SvrSession) RemoveSession

func (this *TSvr2SvrSession) RemoveSession(key interface{})

type TcpClient

type TcpClient struct {
	sync.Mutex

	SvrType define.ERouteId
	Adacb   AfterDialAct
	// contains filtered or unexported fields
}

func NewClient

func NewClient(host, pprofAddr string, SvrType define.ERouteId, Ada AfterDialAct, procName string) *TcpClient

func (*TcpClient) Exit

func (this *TcpClient) Exit(sw *sync.WaitGroup)

func (*TcpClient) Run

func (this *TcpClient) Run()

func (*TcpClient) Send

func (this *TcpClient) Send(data []byte)

func (*TcpClient) SendMessage

func (this *TcpClient) SendMessage()

func (*TcpClient) SessionType

func (this *TcpClient) SessionType() (st ESessionType)

type TcpServer

type TcpServer struct {
	sync.Mutex

	SvrType define.ERouteId

	// session id
	SessionID uint64
	// contains filtered or unexported fields
}

func NewTcpServer

func NewTcpServer(listenAddr, pprofAddr string, SvrType define.ERouteId, procName string) *TcpServer

func (*TcpServer) Exit

func (this *TcpServer) Exit(sw *sync.WaitGroup)

func (*TcpServer) Run

func (this *TcpServer) Run()

func (*TcpServer) SendMessage

func (this *TcpServer) SendMessage()

func (*TcpServer) SessionType

func (this *TcpServer) SessionType() (st ESessionType)

type TcpSession

type TcpSession interface {
	GetRemoteAddr() string
	GetRegPoint() (RegPoint define.ERouteId)
	GetIdentify() string
	SetSendCache(data []byte)
	Push(RegPoint define.ERouteId)
	SetIdentify(StrIdentify string)
	SendInnerSvrMsg(mainid, subid uint16, msg proto.Message) (succ bool, err error)
	SendSvrClientMsg(mainid, subid uint16, msg proto.Message) (succ bool, err error)
	SendInnerClientMsg(mainid, subid uint16, msg proto.Message) (succ bool, err error)
	SendInnerBroadcastMsg(mainid, subid uint16, msg proto.Message) (succ bool, err error)
	WriteMessage(data []byte) (succ bool)
	Alive() bool
	GetPack() (obj IMessagePack)
	IsUser() bool
	RefreshHeartBeat(mainid, subid uint16) bool
	GetModuleName() string
}

Jump to

Keyboard shortcuts

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