protobuf

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgRequest  MsgType = 0x00
	MsgNotify           = 0x01
	MsgResponse         = 0x02
	MsgPush             = 0x03
)

Message types

View Source
const (

	// Handshake represents a handshake: request(client) <====> handshake response(server)
	PkgHandshake = 0x01

	// HandshakeAck represents a handshake ack from client to server
	PkgHandshakeAck = 0x02

	// Heartbeat represents a heartbeat
	PkgHeartbeat = 0x03

	// Data represents a common data packet
	PkgData = 0x04

	// Kick represents a kick off packet
	PkgKick = 0x05 // disconnect message from server
)
View Source
const (
	HeadLength    = 4
	MaxPacketSize = 64 * 1024
)
View Source
const (
	CODE_OK         = 200
	CODE_USE_ERROR  = 500
	CODE_OLD_CLIENT = 501
)

Variables

View Source
var (
	ErrWrongMessageType  = errors.New("wrong message type")
	ErrInvalidMessage    = errors.New("invalid message")
	ErrRouteInfoNotFound = errors.New("route info not found in dictionary")
	ErrWrongMessage      = errors.New("wrong message")
	ErrWrongPacketType   = errors.New("wrong packet type")
)

Functions

func EncodeMsg added in v1.0.8

func EncodeMsg(m *Message) ([]byte, error)

Encode marshals message to binary format. Different message types is corresponding to different message header, message types is identified by 2-4 bit of flag field. The relationship between message types and message header is presented as follows: ------------------------------------------ | type | flag | other | |----------|--------|--------------------| | request |----000-|<message id>|<route>| | notify |----001-|<route> | | response |----010-|<message id> | | push |----011-|<route> | ------------------------------------------ The figure above indicates that the bit does not affect the type of message. See ref: https://github.com/lonnng/nano/blob/master/docs/communication_protocol.md

func EncodePkg added in v1.0.8

func EncodePkg(typ PkgType, data []byte) ([]byte, error)

func NewAgent

func NewAgent(conn network.Conn, connector *Connector) *agent

func NewAgentHandler

func NewAgentHandler(a *agent) *agentHandler

Types

type Connector

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

func NewConnector

func NewConnector(opts ...Option) *Connector

func (*Connector) GetSessionMap

func (c *Connector) GetSessionMap() *connector.SessionMap

func (*Connector) OnDestroy

func (c *Connector) OnDestroy()

func (*Connector) OnInit

func (c *Connector) OnInit(server component.ServerImpl)

func (*Connector) OnRun

func (c *Connector) OnRun(closeSig chan bool)

func (*Connector) Route

func (c *Connector) Route(f rpc.CustomerRoute)

func (*Connector) SetConnectionListener

func (c *Connector) SetConnectionListener(conn connector.Connection)

func (*Connector) SetHandlerFilter

func (c *Connector) SetHandlerFilter(f filter.Filter)

Set a filter for client handler

type Message added in v1.0.1

type Message struct {
	Type    MsgType // message type
	ID      uint64  // unique id, zero while notify mode
	Route   string  // route for locating service
	Data    []byte  // payload
	Payload []byte
	// contains filtered or unexported fields
}

type MsgType added in v1.0.1

type MsgType byte

type Option

type Option func(*Options)

func CertFile

func CertFile(f string) Option

Cert file for https

func HTTPTimeout

func HTTPTimeout(t time.Duration) Option

Timeout for http handshake. Default is 10s

func HeartbeatTimeout

func HeartbeatTimeout(t time.Duration) Option

Heartbeat timeout. Default is 10s. Disconnect if after 2*t

func KeyFile

func KeyFile(f string) Option

Key file for https

func MaxConnNum

func MaxConnNum(num int) Option

Max connections support. Default is 20000

func MaxMsgLen

func MaxMsgLen(length uint32) Option

Max message length. If a message exceeds the limit, the connection sends a close message to the peer. Default is 4096

func TCPAddr

func TCPAddr(addr string) Option

Address of tcp server as "host:port"

func WSAddr

func WSAddr(addr string) Option

Address of websocket server as "host:port"

type Options

type Options struct {
	MaxConnNum       int
	MaxMsgLen        uint32
	HeartbeatTimeout time.Duration

	// websocket
	WSAddr      string
	HTTPTimeout time.Duration
	CertFile    string
	KeyFile     string

	// tcp
	TCPAddr string
}

type PkgType added in v1.0.8

type PkgType byte

Jump to

Keyboard shortcuts

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