network

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TCP_TIMEOUT = 20
	MaxMsgLen   = uint16(10 * 1024)
	MinMsgLen   = uint16(2)
)

Functions

func GetProtobufPayload

func GetProtobufPayload(data []byte) (uint16, proto.Message, error)

func ParseProtobuf

func ParseProtobuf(msgName protoreflect.FullName, data []byte) (proto.Message, error)

func PutProtobufPayload

func PutProtobufPayload(msgID uint16, msg proto.Message) ([]byte, error)

func RegisterPayload

func RegisterPayload(msgID uint16, msgName protoreflect.FullName) error

Types

type Cipher

type Cipher interface {
	Encrypt(data []byte) []byte
	Decrypt(data []byte) []byte
}

type DefTcpProcessor

type DefTcpProcessor struct {
	MsgHandles map[uint16]MsgHander
}

func (*DefTcpProcessor) HandleRecvMsg

func (slf *DefTcpProcessor) HandleRecvMsg(session *Session, msgData []byte)

func (*DefTcpProcessor) RegisterMsg

func (slf *DefTcpProcessor) RegisterMsg(msgID uint16, name protoreflect.FullName, handle HandleFunc)

type HandleFunc

type HandleFunc func(session *Session, msg proto.Message)

type MsgHander

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

type MsgParser

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

func NewMsgParser

func NewMsgParser(cipher Cipher) *MsgParser

func (*MsgParser) Read

func (slf *MsgParser) Read(conn net.Conn) ([]byte, error)

Read goroutine safe

func (*MsgParser) Write

func (slf *MsgParser) Write(conn net.Conn, msgData []byte) error

Write goroutine safe

type PingPongFunc

type PingPongFunc func(session *Session)

type Rc4Cipher

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

func NewRc4Cipher

func NewRc4Cipher(key []byte) *Rc4Cipher

func (*Rc4Cipher) Decrypt

func (slf *Rc4Cipher) Decrypt(data []byte) []byte

func (*Rc4Cipher) Encrypt

func (slf *Rc4Cipher) Encrypt(data []byte) []byte

type Session

type Session struct {
	sync.Mutex

	Writable bool
	// contains filtered or unexported fields
}

func (*Session) Close

func (slf *Session) Close()

func (*Session) GetActiveTime

func (slf *Session) GetActiveTime() int64

func (*Session) GetID

func (slf *Session) GetID() uint32

func (*Session) LocalAddr

func (slf *Session) LocalAddr() net.Addr

func (*Session) RemoteAddr

func (slf *Session) RemoteAddr() net.Addr

func (*Session) SetCipher

func (slf *Session) SetCipher(recv, send Cipher)

func (*Session) SetPingPong

func (slf *Session) SetPingPong(pingpong PingPongFunc, interval uint32)

func (*Session) SetWritable

func (slf *Session) SetWritable(bWrite bool)

func (*Session) Start

func (slf *Session) Start()

func (*Session) SyncWriteMsg

func (slf *Session) SyncWriteMsg(msg []byte) error

func (*Session) WriteMsg

func (slf *Session) WriteMsg(msg []byte) error

type TCPClient

type TCPClient struct {
	sync.Mutex
	DstAddr         string
	HeartbeatExpire int64
	PendingWriteNum uint16
	AutoReconnect   bool

	Pingpong         PingPongFunc
	PingpongInterval uint32
	// contains filtered or unexported fields
}

func NewTCPClient

func NewTCPClient(dstAddr string, h TcpProcessor) *TCPClient

NewTCPClient ...

func (*TCPClient) Close

func (slf *TCPClient) Close()

func (*TCPClient) Start

func (slf *TCPClient) Start()

func (*TCPClient) SyncWriteMsg

func (slf *TCPClient) SyncWriteMsg(msg []byte) error

func (*TCPClient) WriteMsg

func (slf *TCPClient) WriteMsg(msg []byte) error

type TcpProcessor

type TcpProcessor interface {
	OnConnectSucc(session *Session)
	OnConnectClose(session *Session)
	HandleRecvMsg(session *Session, msg []byte)
}

Jump to

Keyboard shortcuts

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