netutil

package
v1.5.8 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//消息报头字节数
	HEAD_SIZE = 4
	//消息包自增的序号
	SEQ_ID_SIZE = 4
	//消息号占用的字节数
	MSG_ID_SIZE = 2
)
View Source
const (
	SESS_KEYEXCG = 0x1 // 是否已经交换完毕KEY
	SESS_ENCRYPT = 0x2 // 是否可以开始加密
)

Variables

View Source
var (
	ServerEndian = binary.LittleEndian
)

Functions

This section is empty.

Types

type NetConnIF

type NetConnIF interface {
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error
	Close() error
	SetWriteBuffer(bytes int) error
	SetReadBuffer(bytes int) error
	Write(b []byte) (n int, err error)
	RemoteAddr() net.Addr
	Read(p []byte) (n int, err error)
}

type NetPacket

type NetPacket struct {
	MsgId   uint16
	Data    []byte
	Session *TCPSession
	//收到该消息包的时间戳 毫秒
	ReceiveTime time.Time
}

type TCPSession

type TCPSession struct {
	//Conn *net.TCPConn
	Conn     NetConnIF
	IP       net.IP
	SendChan chan *NetPacket
	ReadChan chan *NetPacket
	//离线消息管道,用于外部接收连接断开的消息并处理后续
	OffChan chan int64
	// ID
	SessionId int64
	// 会话标记
	Flag int32

	// Declares how many times we will try to resend message
	MaxSendRetries int

	CloseState chanutil.DoneChan

	// 对收到的包进行计数,可避免重放攻击-REPLAY-ATTACK
	PacketRcvSeq uint32
	//数据包发送计数器
	PacketSndSeq uint32

	OnLineTime  int64
	OffLineTime int64
	EncodeKey   []byte
	DecodeKey   []byte
	// contains filtered or unexported fields
}

func NewSession

func NewSession(conn NetConnIF, readChan, sendChan chan *NetPacket, offChan chan int64) (*TCPSession, error)

func (*TCPSession) Close

func (s *TCPSession) Close()

func (*TCPSession) DirectSend

func (s *TCPSession) DirectSend(packet *NetPacket) bool

func (*TCPSession) DirectSendAndClose added in v1.1.2

func (s *TCPSession) DirectSendAndClose(packet *NetPacket)

func (*TCPSession) HandleConn

func (s *TCPSession) HandleConn(filter func(*NetPacket) bool)

func (*TCPSession) IsClosed added in v1.0.7

func (s *TCPSession) IsClosed() bool

func (*TCPSession) ReadLoop

func (s *TCPSession) ReadLoop(filter func(*NetPacket) bool)

func (*TCPSession) RemoteAddr added in v1.0.7

func (s *TCPSession) RemoteAddr() net.Addr

网络连接远程ip

func (*TCPSession) RemoteIp added in v1.0.7

func (s *TCPSession) RemoteIp() net.IP

网络连接远程ip

func (*TCPSession) Send

func (s *TCPSession) Send(packet *NetPacket) bool

func (*TCPSession) SendLoop added in v1.0.7

func (s *TCPSession) SendLoop()

func (*TCPSession) SetCipher

func (s *TCPSession) SetCipher(encodeKey, decodeKey []byte) error

RC4加密解密

func (*TCPSession) SetParameter

func (s *TCPSession) SetParameter(readDelay, sendDelay time.Duration, maxRecvSize uint32, sendFullClose bool)

设置链接参数

func (*TCPSession) SetRpmParameter

func (s *TCPSession) SetRpmParameter(rpmLimit uint32, rpmInterval time.Duration, msg *NetPacket)

包频率控制参数

func (*TCPSession) TraceErrorf added in v1.0.10

func (s *TCPSession) TraceErrorf(format string, a ...interface{})

func (*TCPSession) TraceFinish added in v1.0.10

func (s *TCPSession) TraceFinish(traceDefer func(*expvar.Map, int64))

func (*TCPSession) TracePrintf added in v1.0.10

func (s *TCPSession) TracePrintf(format string, a ...interface{})

func (*TCPSession) TraceStart added in v1.0.10

func (s *TCPSession) TraceStart(family, title string, expvar bool)

func (*TCPSession) TraceStartWithStart added in v1.4.10

func (s *TCPSession) TraceStartWithStart(family, title string, expvar bool, startTime time.Time)

Directories

Path Synopsis
crypto
dh
********************************************************** * * Diffie–Hellman key exchange * * 1.
********************************************************** * * Diffie–Hellman key exchange * * 1.

Jump to

Keyboard shortcuts

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