network

package
v0.0.0-...-ee7ecfe Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

定义了消息的接口

报文解析模块

Package network is a generated protocol buffer package.

It is generated from these files:

service.proto

It has these top-level messages:

Data

通用的tcp服务器

通用的websocket服务器

Index

Constants

This section is empty.

Variables

View Source
var Data_FrameType_name = map[int32]string{
	0: "Message",
	1: "Kick",
	2: "Ping",
}
View Source
var Data_FrameType_value = map[string]int32{
	"Message": 0,
	"Kick":    1,
	"Ping":    2,
}

Functions

func RegisterServiceServer

func RegisterServiceServer(s *grpc.Server, srv ServiceServer)

Types

type Config

type Config struct {
	ServerAddress string         // 服务地址
	MaxConnNum    int            // 最大连接数
	MaxMsgLen     int            // client<->gateway message上限
	MinMsgLen     int            // client<->gateway message下限
	ReadDeadline  int            // gateway->client读超时
	WriteDeadline int            // gateway->client写超时
	MaxHeader     int            // header上限(for websocket)
	HttpTimeout   int            // http-get超时(for websocket)
	CertFile      string         // for ssl
	KeyFile       string         // for ssl
	MsgParser     Imessage       // for message
	Parser        *MessageParser // for 报文
	Gate          Iagent         // 网关
	PendingNum    int            // gateway->client异步ipc队列上限
	Rpm           int            // client->gateway流量上限/min
	AsyncMQ       int            // service->gateway异步ipc队列上限
	GateWayIds    uint16         // gateway本地路由id段(当前路由规则是简单的id分段规则)
}

type Data

type Data struct {
}

func (*Data) Descriptor

func (*Data) Descriptor() ([]byte, []int)

func (*Data) ProtoMessage

func (*Data) ProtoMessage()

func (*Data) Reset

func (m *Data) Reset()

func (*Data) String

func (m *Data) String() string

type Data_Frame

type Data_Frame struct {
	Type    Data_FrameType `protobuf:"varint,1,opt,name=Type,enum=network.Data_FrameType" json:"Type,omitempty"`
	Message []byte         `protobuf:"bytes,2,opt,name=Message,proto3" json:"Message,omitempty"`
}

func (*Data_Frame) Descriptor

func (*Data_Frame) Descriptor() ([]byte, []int)

func (*Data_Frame) ProtoMessage

func (*Data_Frame) ProtoMessage()

func (*Data_Frame) Reset

func (m *Data_Frame) Reset()

func (*Data_Frame) String

func (m *Data_Frame) String() string

type Data_FrameType

type Data_FrameType int32
const (
	Data_Message Data_FrameType = 0
	Data_Kick    Data_FrameType = 1
	Data_Ping    Data_FrameType = 2
)

func (Data_FrameType) EnumDescriptor

func (Data_FrameType) EnumDescriptor() ([]byte, []int)

func (Data_FrameType) String

func (x Data_FrameType) String() string

type Iagent

type Iagent interface {
	NewIagent() Iagent            // 拷贝构造器
	Close()                       // 关闭
	Start(Iconn)                  // 启动
	GetUserData() interface{}     // 获取用户数据
	SetUserData(data interface{}) // 设置用户数据
}

type Iconn

type Iconn interface {
	ReadMsg() ([]byte, error)           // 读取
	WriteMsg(arg []byte) error          // 写入
	LocalAddr() net.Addr                // 本地地址
	RemoteAddr() net.Addr               // 远程地址
	SetReadDeadline(t time.Time) error  // 读超时
	SetWriteDeadline(t time.Time) error // 写超时
	Close()                             // 关闭
}

type Imessage

type Imessage interface {
	Register(msg *RawMessage) error               // 消息注册
	UnRegister(msg *RawMessage)                   // 消息反注册
	Serialize(msg RawMessage) ([]byte, error)     // 序列化消息
	Deserialize(date []byte) (*RawMessage, error) // 反序列化消息
}

type MessageInfo

type MessageInfo struct {
	MsgType reflect.Type
}

消息

type MessageParser

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

func NewMessageParser

func NewMessageParser() (newMsg *MessageParser)

func (*MessageParser) NewMessageParser

func (msgParser *MessageParser) NewMessageParser() *MessageParser

func (*MessageParser) ReadBody

func (msgParser *MessageParser) ReadBody(data []byte) ([]byte, error)

获取body(除header)

func (*MessageParser) ReadBodyFull

func (msgParser *MessageParser) ReadBodyFull(data []byte) (uint32, uint16, []byte, error)

拆分body数据 @return 数据1(序列号),数据2(协议号),数据3(id+message),错误描述

func (*MessageParser) SetMsgLen

func (msgParser *MessageParser) SetMsgLen(MaxMessageLen uint16, MinMessageLen uint16)

func (*MessageParser) Write

func (msgParser *MessageParser) Write(data []byte) ([]byte, error)

@params data:id+message @return header+data

type MsgManager

type MsgManager struct {
	MsgMap map[uint16]*MessageInfo // id池:主要用于识别id对应的pb结构
}

处理器的数据结构

func NewMsgManager

func NewMsgManager() *MsgManager

构建一个新的消息处理器

func (*MsgManager) Deserialize

func (msgManager *MsgManager) Deserialize(data []byte) (*RawMessage, error)

for id+message goroutine safe

func (*MsgManager) Register

func (msgManager *MsgManager) Register(rawM *RawMessage) error

not goroutine safe

func (*MsgManager) Serialize

func (msgManager *MsgManager) Serialize(rawM RawMessage) ([]byte, error)

for id+message goroutine safe

func (*MsgManager) UnRegister

func (msgManager *MsgManager) UnRegister(rawM *RawMessage)

not goroutine safe

type RawMessage

type RawMessage struct {
	MsgId   uint16
	MsgData interface{}
}

type ServiceClient

type ServiceClient interface {
	Stream(ctx context.Context, opts ...grpc.CallOption) (Service_StreamClient, error)
}

func NewServiceClient

func NewServiceClient(cc *grpc.ClientConn) ServiceClient

type ServiceServer

type ServiceServer interface {
	Stream(Service_StreamServer) error
}

type Service_StreamClient

type Service_StreamClient interface {
	Send(*Data_Frame) error
	Recv() (*Data_Frame, error)
	grpc.ClientStream
}

type Service_StreamServer

type Service_StreamServer interface {
	Send(*Data_Frame) error
	Recv() (*Data_Frame, error)
	grpc.ServerStream
}

type TcpConn

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

func (*TcpConn) Close

func (conn *TcpConn) Close()

func (*TcpConn) LocalAddr

func (conn *TcpConn) LocalAddr() net.Addr

func (*TcpConn) Read

func (conn *TcpConn) Read(b []byte) (int, error)

func (*TcpConn) ReadMsg

func (conn *TcpConn) ReadMsg() ([]byte, error)

func (*TcpConn) RemoteAddr

func (conn *TcpConn) RemoteAddr() net.Addr

func (*TcpConn) SetReadDeadline

func (conn *TcpConn) SetReadDeadline(t time.Time) error

func (*TcpConn) SetWriteDeadline

func (conn *TcpConn) SetWriteDeadline(t time.Time) error

func (*TcpConn) WriteMsg

func (conn *TcpConn) WriteMsg(arg []byte) error

type TcpServer

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

func StartTcp

func StartTcp(config *Config) *TcpServer

func (*TcpServer) Close

func (server *TcpServer) Close()

type WsConn

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

func (*WsConn) Close

func (conn *WsConn) Close()

func (*WsConn) LocalAddr

func (conn *WsConn) LocalAddr() net.Addr

func (*WsConn) ReadMsg

func (conn *WsConn) ReadMsg() ([]byte, error)

func (*WsConn) RemoteAddr

func (conn *WsConn) RemoteAddr() net.Addr

func (*WsConn) SetReadDeadline

func (conn *WsConn) SetReadDeadline(t time.Time) error

func (*WsConn) SetWriteDeadline

func (conn *WsConn) SetWriteDeadline(t time.Time) error

func (*WsConn) WriteMsg

func (conn *WsConn) WriteMsg(arg []byte) error

type WsServer

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

func StartWs

func StartWs(config *Config) *WsServer

func (*WsServer) Close

func (server *WsServer) Close()

Jump to

Keyboard shortcuts

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