Documentation ¶
Index ¶
- Constants
- Variables
- func NewTcpServer(addr string, processor Processor, logger *logging.Logger) (s *tcpServer, err error)
- func SetConf(cfg *Data)
- type BroadcastNode
- func (bNode *BroadcastNode) AddConn(conn IConnection) error
- func (bNode *BroadcastNode) Complete() error
- func (bNode *BroadcastNode) DelConn(key string) error
- func (bNode *BroadcastNode) Destroy() error
- func (bNode *BroadcastNode) GetAllMessage() chan []interface{}
- func (bNode *BroadcastNode) OnProtocolMessage(msg interface{}) error
- func (bNode *BroadcastNode) OnRawMessage([]byte) error
- func (bNode *BroadcastNode) Serve()
- type Data
- type Encryptor
- type FrameNode
- func (gr *FrameNode) AddConn(conn IConnection) error
- func (gr *FrameNode) Complete() error
- func (gr *FrameNode) DelConn(key string) error
- func (gr *FrameNode) Destroy() error
- func (gr *FrameNode) GetAllMessage() chan []interface{}
- func (gr *FrameNode) OnProtocolMessage(interface{}) error
- func (gr *FrameNode) OnRawMessage(msg []byte) error
- func (gr *FrameNode) Serve()
- type IConnection
- type INode
- type KCPConn
- type PbProcessor
- func (pbf *PbProcessor) GetBigEndian() bool
- func (pbf *PbProcessor) OnReceivedPackage(writer interface{}, body []byte) error
- func (pbf *PbProcessor) RegisterHandler(id int, entity interface{}, handle func(args ...interface{}))
- func (pbf *PbProcessor) SetBigEndian()
- func (pbf *PbProcessor) SetEncryptor(enc Encryptor)
- func (pbf *PbProcessor) WrapIdMsg(id uint32, message interface{}) ([]byte, error)
- func (pbf *PbProcessor) WrapMsg(message interface{}) ([]byte, error)
- func (pbf *PbProcessor) WrapMsgNoHeader(message interface{}) ([]byte, error)
- type Processor
- type Protocol
- type ScFrame
- type ScProtocolPack
- func (*ScProtocolPack) Descriptor() ([]byte, []int)deprecated
- func (x *ScProtocolPack) GetId() uint32
- func (x *ScProtocolPack) GetPack() []*Protocol
- func (*ScProtocolPack) ProtoMessage()
- func (x *ScProtocolPack) ProtoReflect() protoreflect.Message
- func (x *ScProtocolPack) Reset()
- func (x *ScProtocolPack) String() string
- type Server
- type TCPConn
- func (tc *TCPConn) AfterClose(cb func())
- func (tc *TCPConn) Close() error
- func (tc *TCPConn) GetData() interface{}
- func (tc *TCPConn) GetNode() INode
- func (tc *TCPConn) GetUuid() string
- func (tc *TCPConn) IsClosed() bool
- func (tc *TCPConn) ReadMsg()
- func (tc *TCPConn) SetData(data interface{})
- func (tc *TCPConn) SetNode(node INode)
- func (tc *TCPConn) WriteMsg(message interface{})
Constants ¶
const ( Msg = iota Conn Raw )
回调传参常量
Variables ¶
var File_base_proto protoreflect.FileDescriptor
Functions ¶
Types ¶
type BroadcastNode ¶
type BroadcastNode struct { // 节点ID NodeId string // 网络连接 Connections map[interface{}]IConnection // contains filtered or unexported fields }
BroadcastNode 广播转发节点
func NewBroadcastNode ¶
func NewBroadcastNode(logger *logging.Logger) *BroadcastNode
NewBroadcastNode return a new BroadcastNode
func (*BroadcastNode) AddConn ¶
func (bNode *BroadcastNode) AddConn(conn IConnection) error
AddConn by conn
func (*BroadcastNode) DelConn ¶
func (bNode *BroadcastNode) DelConn(key string) error
DelConn by key
func (*BroadcastNode) GetAllMessage ¶
func (bNode *BroadcastNode) GetAllMessage() chan []interface{}
GetAllMessage return chan []interface{}
func (*BroadcastNode) OnProtocolMessage ¶
func (bNode *BroadcastNode) OnProtocolMessage(msg interface{}) error
OnProtocolMessage interface
func (*BroadcastNode) OnRawMessage ¶
func (bNode *BroadcastNode) OnRawMessage([]byte) error
OnRawMessage bytes
type Data ¶
type Data struct { // 单个连接未处理消息包缓存队列大小 // 注意:[超过这个大小,包将丢弃,视为当前系统无法处理,默认100] ConnUndoQueueSize int // 单个连接未写入消息包队列大小 [超过这个大小,包将丢弃,视为当前系统无法处理,默认为1] ConnWriteQueueSize int // 第一个包等待超市时间 (s) [默认5秒,连接上来未读到正确包,断开连接] FirstPackageTimeout int // 连接读取超时(s) [默认35秒, 超时等待时间内,请发送任何数据包,如心跳包] ConnReadTimeout int // 连接写超时(s) [默认5秒, 超时等待时间内,请发送任何数据包,如心跳包] ConnWriteTimeout int // 数据包最大限制,[默认2048] MaxDataPackageSize int // ws 最大header,[默认1024] MaxHeaderLen int }
Data is the config struct
var ( // Cfg is the config instance Cfg *Data )
type FrameNode ¶
type FrameNode struct { // 节点ID NodeId string // 网络连接 Connections map[interface{}]IConnection // 同步周期 FrameTicker *time.Ticker // rand seed RandSeed int64 // contains filtered or unexported fields }
FrameNode 帧同步节点
func NewFrameNode ¶
NewFrameNode return a new FrameNode
func (*FrameNode) GetAllMessage ¶
func (gr *FrameNode) GetAllMessage() chan []interface{}
GetAllMessage return chan []interface
func (*FrameNode) OnProtocolMessage ¶
OnProtocolMessage interface
func (*FrameNode) OnRawMessage ¶
OnRawMessage msg
type IConnection ¶
type IConnection interface { GetUuid() string ReadMsg() WriteMsg(message interface{}) Close() error AfterClose(func()) //SetData 设置自定义数据 SetData(interface{}) GetData() interface{} //SetNode 设置节点 SetNode(INode) GetNode() INode //IsClosed 是否关闭 IsClosed() bool }
IConnection 网络连接
type INode ¶
type INode interface { AddConn(IConnection) error DelConn(string) error Serve() OnRawMessage([]byte) error OnProtocolMessage(interface{}) error GetAllMessage() chan []interface{} Destroy() error Complete() error }
INode 网络同步节点,如消息节点,聊天室节点
type PbProcessor ¶
type PbProcessor struct {
// contains filtered or unexported fields
}
PbProcessor one of Processor implement protoc --go_out=. *.proto
func NewPbProcessor ¶
func NewPbProcessor(logger *logging.Logger) *PbProcessor
NewPbProcessor return PB processor
func (*PbProcessor) GetBigEndian ¶
func (pbf *PbProcessor) GetBigEndian() bool
GetBigEndian of the order
func (*PbProcessor) OnReceivedPackage ¶
func (pbf *PbProcessor) OnReceivedPackage(writer interface{}, body []byte) error
OnReceivedPackage 收到完整数据包, 返回解包错误
func (*PbProcessor) RegisterHandler ¶
func (pbf *PbProcessor) RegisterHandler(id int, entity interface{}, handle func(args ...interface{}))
RegisterHandler for logic
func (*PbProcessor) SetEncryptor ¶
func (pbf *PbProcessor) SetEncryptor(enc Encryptor)
SetEncryptor for processor
func (*PbProcessor) WrapIdMsg ¶
func (pbf *PbProcessor) WrapIdMsg(id uint32, message interface{}) ([]byte, error)
WrapIdMsg format the interface message to []byte with id
func (*PbProcessor) WrapMsg ¶
func (pbf *PbProcessor) WrapMsg(message interface{}) ([]byte, error)
WrapMsg format the interface message to []byte
func (*PbProcessor) WrapMsgNoHeader ¶
func (pbf *PbProcessor) WrapMsgNoHeader(message interface{}) ([]byte, error)
WrapMsgNoHeader without header length
type Processor ¶
type Processor interface { SetBigEndian() GetBigEndian() bool SetEncryptor(enc Encryptor) OnReceivedPackage(interface{}, []byte) error WrapMsg(interface{}) ([]byte, error) WrapIdMsg(id uint32, data interface{}) ([]byte, error) RegisterHandler(id int, entity interface{}, handle func(args ...interface{})) }
Processor interface
type Protocol ¶
type Protocol struct { Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` Content []byte `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"` // contains filtered or unexported fields }
协议消息
func (*Protocol) Descriptor
deprecated
func (*Protocol) GetContent ¶
func (*Protocol) ProtoMessage ¶
func (*Protocol) ProtoMessage()
func (*Protocol) ProtoReflect ¶
func (x *Protocol) ProtoReflect() protoreflect.Message
type ScFrame ¶
type ScFrame struct { Frame uint32 `protobuf:"varint,1,opt,name=frame,proto3" json:"frame,omitempty"` Protocols [][]byte `protobuf:"bytes,2,rep,name=protocols,proto3" json:"protocols,omitempty"` // contains filtered or unexported fields }
帧消息
func (*ScFrame) Descriptor
deprecated
func (*ScFrame) GetProtocols ¶
func (*ScFrame) ProtoMessage ¶
func (*ScFrame) ProtoMessage()
func (*ScFrame) ProtoReflect ¶
func (x *ScFrame) ProtoReflect() protoreflect.Message
type ScProtocolPack ¶
type ScProtocolPack struct { Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` Pack []*Protocol `protobuf:"bytes,2,rep,name=pack,proto3" json:"pack,omitempty"` // contains filtered or unexported fields }
打包消息
func (*ScProtocolPack) Descriptor
deprecated
func (*ScProtocolPack) Descriptor() ([]byte, []int)
Deprecated: Use ScProtocolPack.ProtoReflect.Descriptor instead.
func (*ScProtocolPack) GetId ¶
func (x *ScProtocolPack) GetId() uint32
func (*ScProtocolPack) GetPack ¶
func (x *ScProtocolPack) GetPack() []*Protocol
func (*ScProtocolPack) ProtoMessage ¶
func (*ScProtocolPack) ProtoMessage()
func (*ScProtocolPack) ProtoReflect ¶
func (x *ScProtocolPack) ProtoReflect() protoreflect.Message
func (*ScProtocolPack) Reset ¶
func (x *ScProtocolPack) Reset()
func (*ScProtocolPack) String ¶
func (x *ScProtocolPack) String() string