Documentation ¶
Index ¶
- Constants
- Variables
- func AddHandler(h context.Handler)
- func Delete(path string, handlers ...context.Handler)
- func EnableCrossOrigin()
- func Get(path string, handlers ...context.Handler)
- func Handle(method string, relativePath string, handlers ...context.Handler)
- func HandleDir(requestPath string, fsOrDir interface{}, opts ...iris.DirOptions) (routes []*router.Route)
- func Iris() *iris.Application
- func NewKcpServer(addr string, processor Processor) (s *kcpServer, err error)
- func NewQUICServer(addr string, processor Processor, config *tls.Config) (s *quicServer, err error)
- func NewTcpServer(addr string, processor Processor) (s *tcpServer, err error)
- func NewWsServer(addr string, processor Processor) (s *wsServer, err error)
- func ParseLittlePassword(passwordString string) (*password, error)
- func Post(path string, handlers ...context.Handler)
- func Put(path string, handlers ...context.Handler)
- func RandLittlePassword() string
- func Run(addr string) error
- func SetConf(cfg *Data)
- func SetLogLv(lv string)
- func SetLogOutput(w io.Writer)
- type AESCipher
- 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 Jar
- type JsonProcessor
- func (jp *JsonProcessor) GetBigEndian() bool
- func (jp *JsonProcessor) OnReceivedPackage(writer interface{}, body []byte) error
- func (jp *JsonProcessor) RegisterHandler(id int, entity interface{}, handle func(args ...interface{}))
- func (jp *JsonProcessor) SetBigEndian()
- func (jp *JsonProcessor) SetEncryptor(enc Encryptor)
- func (jp *JsonProcessor) WrapIdMsg(id uint32, message interface{}) ([]byte, error)
- func (jp *JsonProcessor) WrapMsg(message interface{}) ([]byte, error)
- type JsonProtocol
- type KCPConn
- type LittleCipher
- type PbfProcessor
- func (pbf *PbfProcessor) GetBigEndian() bool
- func (pbf *PbfProcessor) OnReceivedPackage(writer interface{}, body []byte) error
- func (pbf *PbfProcessor) RegisterHandler(id int, entity interface{}, handle func(args ...interface{}))
- func (pbf *PbfProcessor) SetBigEndian()
- func (pbf *PbfProcessor) SetEncryptor(enc Encryptor)
- func (pbf *PbfProcessor) WrapIdMsg(id uint32, message interface{}) ([]byte, error)
- func (pbf *PbfProcessor) WrapMsg(message interface{}) ([]byte, error)
- func (pbf *PbfProcessor) WrapMsgNoHeader(message interface{}) ([]byte, error)
- type Processor
- type Protocol
- type QuicStream
- func (s *QuicStream) AfterClose(cb func())
- func (s *QuicStream) Close() error
- func (s *QuicStream) GetData() interface{}
- func (s *QuicStream) GetNode() INode
- func (s *QuicStream) GetUuid() string
- func (s *QuicStream) IsClosed() bool
- func (s *QuicStream) ReadMsg()
- func (s *QuicStream) SetData(data interface{})
- func (s *QuicStream) SetNode(node INode)
- func (s *QuicStream) WriteMsg(message interface{})
- type Req
- 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{})
- type WSConn
- func (wc *WSConn) AfterClose(cb func())
- func (wc *WSConn) Close() error
- func (wc *WSConn) GetData() interface{}
- func (wc *WSConn) GetNode() INode
- func (wc *WSConn) GetUuid() string
- func (wc *WSConn) IsClosed() bool
- func (wc *WSConn) ReadMsg()
- func (wc *WSConn) SetData(data interface{})
- func (wc *WSConn) SetNode(node INode)
- func (wc *WSConn) WriteMsg(message interface{})
- type XORCipher
Constants ¶
const ( Msg = iota Conn Raw )
回调传参常量
Variables ¶
var File_base_proto protoreflect.FileDescriptor
var (
// UA is user agent
UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.3578.98 Safari/537.36"
)
Functions ¶
func HandleDir ¶
func HandleDir(requestPath string, fsOrDir interface{}, opts ...iris.DirOptions) (routes []*router.Route)
HandleDir static dir
func NewKcpServer ¶
NewKcpServer return a *kcpServer
func NewQUICServer ¶
NewQUICServer return new quicServer
func NewTcpServer ¶
NewTcpServer return new tcpServer
func NewWsServer ¶
NewWsServer return new wsServer
func ParseLittlePassword ¶
ParseLittlePassword 解析采用base64编码的字符串获取密码
func RandLittlePassword ¶
func RandLittlePassword() string
RandLittlePassword 产生 256个byte随机组合的 密码,最后会使用base64编码为字符串存储在配置文件中 不能出现任何一个重复的byte位,必须又 0-255 组成,并且都需要包含
Types ¶
type AESCipher ¶
type AESCipher struct {
// contains filtered or unexported fields
}
AESCipher one of Encryptor implement
type BroadcastNode ¶
type BroadcastNode struct { // 节点ID NodeId string // 网络连接 Connections map[interface{}]IConnection // contains filtered or unexported fields }
BroadcastNode 广播转发节点
func NewBroadcastNode ¶
func NewBroadcastNode() *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 ( // C is the config instance C *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 (*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(interface{}) GetData() interface{} // 设置节点 SetNode(INode) GetNode() INode // 是否关闭 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 JsonProcessor ¶
type JsonProcessor struct {
// contains filtered or unexported fields
}
JsonProcessor one of Processor implement
func NewJSONProcessor ¶
func NewJSONProcessor() *JsonProcessor
NewJSONProcessor return new JsonProcessor
func (*JsonProcessor) GetBigEndian ¶
func (jp *JsonProcessor) GetBigEndian() bool
GetBigEndian of the order
func (*JsonProcessor) OnReceivedPackage ¶
func (jp *JsonProcessor) OnReceivedPackage(writer interface{}, body []byte) error
OnReceivedPackage 收到完整数据包
func (*JsonProcessor) RegisterHandler ¶
func (jp *JsonProcessor) RegisterHandler(id int, entity interface{}, handle func(args ...interface{}))
RegisterHandler for logic
func (*JsonProcessor) SetEncryptor ¶
func (jp *JsonProcessor) SetEncryptor(enc Encryptor)
SetEncryptor for processor
func (*JsonProcessor) WrapIdMsg ¶ added in v1.1.8
func (jp *JsonProcessor) WrapIdMsg(id uint32, message interface{}) ([]byte, error)
WrapIdMsg format the interface message to []byte with id
func (*JsonProcessor) WrapMsg ¶
func (jp *JsonProcessor) WrapMsg(message interface{}) ([]byte, error)
WrapMsg format the interface message to []byte
type JsonProtocol ¶
type JsonProtocol struct { Id int `json:"id"` Content interface{} `json:"content"` }
JsonProtocol is the protocol for JsonProcessor
type LittleCipher ¶
type LittleCipher struct {
// contains filtered or unexported fields
}
LittleCipher one of Encryptor implement
func NewLittleCipher ¶
func NewLittleCipher(encodePassword *password) *LittleCipher
NewLittleCipher 新建一个编码解码器
func (*LittleCipher) Decode ¶
func (cipher *LittleCipher) Decode(bs []byte) []byte
Decode 解码加密后的数据到原数据
type PbfProcessor ¶
type PbfProcessor struct {
// contains filtered or unexported fields
}
PbfProcessor one of Processor implement protoc --go_out=. *.proto
func (*PbfProcessor) GetBigEndian ¶
func (pbf *PbfProcessor) GetBigEndian() bool
GetBigEndian of the order
func (*PbfProcessor) OnReceivedPackage ¶
func (pbf *PbfProcessor) OnReceivedPackage(writer interface{}, body []byte) error
OnReceivedPackage 收到完整数据包, 返回解包错误
func (*PbfProcessor) RegisterHandler ¶
func (pbf *PbfProcessor) RegisterHandler(id int, entity interface{}, handle func(args ...interface{}))
RegisterHandler for logic
func (*PbfProcessor) SetEncryptor ¶
func (pbf *PbfProcessor) SetEncryptor(enc Encryptor)
SetEncryptor for processor
func (*PbfProcessor) WrapIdMsg ¶ added in v1.1.8
func (pbf *PbfProcessor) WrapIdMsg(id uint32, message interface{}) ([]byte, error)
WrapIdMsg format the interface message to []byte with id
func (*PbfProcessor) WrapMsg ¶
func (pbf *PbfProcessor) WrapMsg(message interface{}) ([]byte, error)
WrapMsg format the interface message to []byte
func (*PbfProcessor) WrapMsgNoHeader ¶
func (pbf *PbfProcessor) 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 QuicStream ¶
QuicStream is warped udp conn for luck
func NewQuicStream ¶
func NewQuicStream(stream quic.Stream, processor Processor) *QuicStream
NewQuicStream return new udp conn
func (*QuicStream) AfterClose ¶
func (s *QuicStream) AfterClose(cb func())
AfterClose conn call back
func (*QuicStream) IsClosed ¶
func (s *QuicStream) IsClosed() bool
IsClosed return the status of conn
func (*QuicStream) ReadMsg ¶
func (s *QuicStream) ReadMsg()
ReadMsg read | write end -> write | read end -> conn end
func (*QuicStream) WriteMsg ¶
func (s *QuicStream) WriteMsg(message interface{})
WriteMsg warp msg base on conn's processor
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
type TCPConn ¶
TCPConn is warped tcp conn for luck
func NewTcpConn ¶
NewTcpConn return new tcp conn
type WSConn ¶
WSConn is warped tcp conn for luck
type XORCipher ¶
XORCipher one of Encryptor implement
func NewXORCipher ¶
NewXORCipher 简单的混淆加密 maxBufferLen 加密数据最大长度