transport

package
v0.1.25 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: LGPL-2.1 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRenewConn     = errors.New("gtp: renew conn")          // 刷新链路错误
	ErrUnexpectedSeq = errors.New("gtp: unexpected sequence") // 收到非预期的消息序号,表示序号不连续
	ErrDiscardSeq    = errors.New("gtp: discard sequence")    // 收到已过期的消息序号,表示次消息已收到过
	ErrNetIO         = errors.New("gtp: net i/o")             // 网络io错误
	ErrTimeout       = os.ErrDeadlineExceeded                 // 网络io超时
	ErrClosed        = os.ErrClosed                           // 网络链路已关闭
	ErrUnexpectedEOF = io.ErrUnexpectedEOF                    // 非预期的io结束
	EOF              = io.EOF                                 // io结束
)
View Source
var (
	ErrUnexpectedMsg = errors.New("gtp: unexpected msg") // 收到非预期的消息
)

Functions

This section is empty.

Types

type AuthAccept

type AuthAccept = generic.Func1[Event[gtp.MsgAuth], error] // 服务端确认客户端Auth请求

type ChangeCipherSpecAccept

type ChangeCipherSpecAccept = generic.PairFunc1[Event[gtp.MsgChangeCipherSpec], Event[gtp.MsgChangeCipherSpec], error] // 客户端确认服务端ChangeCipherSpec请求

type ChangeCipherSpecFin

type ChangeCipherSpecFin = generic.Func1[Event[gtp.MsgChangeCipherSpec], error] // 服务端获取客户端ChangeCipherSpec响应

type ContinueAccept

type ContinueAccept = generic.Func1[Event[gtp.MsgContinue], error] // 服务端确认客户端Continue请求

type CtrlProtocol

type CtrlProtocol struct {
	Transceiver      *Transceiver     // 消息事件收发器
	RetryTimes       int              // 网络io超时时的重试次数
	RstHandler       RstHandler       // Rst消息事件处理器
	SyncTimeHandler  SyncTimeHandler  // SyncTime消息事件处理器
	HeartbeatHandler HeartbeatHandler // Heartbeat消息事件处理器
}

CtrlProtocol 控制协议

func (*CtrlProtocol) HandleEvent

func (c *CtrlProtocol) HandleEvent(e Event[gtp.Msg]) error

HandleEvent 消息事件处理器

func (*CtrlProtocol) RequestTime

func (c *CtrlProtocol) RequestTime(corrId int64) error

RequestTime 请求同步时间

func (*CtrlProtocol) SendPing

func (c *CtrlProtocol) SendPing() error

SendPing 发送ping

func (*CtrlProtocol) SendRst

func (c *CtrlProtocol) SendRst(err error) error

SendRst 发送Rst消息事件

type ECDHESecretKeyExchangeFin

type ECDHESecretKeyExchangeFin = generic.PairFunc1[Event[gtp.MsgECDHESecretKeyExchange], Event[gtp.MsgChangeCipherSpec], error] // 服务端获取客户端ECDHESecretKeyExchange响应

type ErrorHandler

type ErrorHandler = generic.DelegateAction1[error] // 错误处理器

type Event

type Event[T gtp.MsgReader] struct {
	Flags gtp.Flags // 标志位
	Seq   uint32    // 消息序号
	Ack   uint32    // 应答序号
	Msg   T         // 消息
}

Event 消息事件

func UnpackEvent

func UnpackEvent[T gtp.MsgReader](me Event[gtp.Msg]) Event[T]

UnpackEvent 解包事件,用于解析消息

func (Event[T]) Pack

func (e Event[T]) Pack() Event[gtp.MsgReader]

Pack 打包事件,用于发送消息

type EventDispatcher

type EventDispatcher struct {
	Transceiver  *Transceiver // 消息事件收发器
	RetryTimes   int          // 网络io超时时的重试次数
	EventHandler EventHandler // 消息事件处理器列表
}

EventDispatcher 消息事件分发器

func (*EventDispatcher) Dispatching

func (d *EventDispatcher) Dispatching() error

Dispatching 分发事件

func (*EventDispatcher) Run

func (d *EventDispatcher) Run(ctx context.Context, errorHandler ErrorHandler)

Run 运行

type EventHandler

type EventHandler = generic.DelegateFunc1[Event[gtp.Msg], error] // 消息事件处理器

type FinishedAccept

type FinishedAccept = generic.Func1[Event[gtp.MsgFinished], error] // 客户端确认服务端Finished请求

type HandshakeProtocol

type HandshakeProtocol struct {
	Transceiver *Transceiver // 消息事件收发器
	RetryTimes  int          // 网络io超时时的重试次数
}

HandshakeProtocol 握手协议

func (*HandshakeProtocol) ClientAuth

func (h *HandshakeProtocol) ClientAuth(auth Event[gtp.MsgAuth]) (err error)

ClientAuth 客户端发起鉴权

func (*HandshakeProtocol) ClientContinue

func (h *HandshakeProtocol) ClientContinue(cont Event[gtp.MsgContinue]) (err error)

ClientContinue 客户端发起重连

func (*HandshakeProtocol) ClientFinished

func (h *HandshakeProtocol) ClientFinished(finishedAccept FinishedAccept) (err error)

ClientFinished 客户端握手结束

func (*HandshakeProtocol) ClientHello

func (h *HandshakeProtocol) ClientHello(hello Event[gtp.MsgHello], helloFin HelloFin) (err error)

ClientHello 客户端Hello

func (*HandshakeProtocol) ClientSecretKeyExchange

func (h *HandshakeProtocol) ClientSecretKeyExchange(secretKeyExchangeAccept SecretKeyExchangeAccept, changeCipherSpecAccept ChangeCipherSpecAccept) (err error)

ClientSecretKeyExchange 客户端交换秘钥

func (*HandshakeProtocol) ServerAuth

func (h *HandshakeProtocol) ServerAuth(authAccept AuthAccept) (err error)

ServerAuth 服务端验证鉴权

func (*HandshakeProtocol) ServerContinue

func (h *HandshakeProtocol) ServerContinue(continueAccept ContinueAccept) (err error)

ServerContinue 服务端处理重连

func (*HandshakeProtocol) ServerECDHESecretKeyExchange

func (h *HandshakeProtocol) ServerECDHESecretKeyExchange(secretKeyExchange Event[gtp.MsgECDHESecretKeyExchange], secretKeyExchangeFin ECDHESecretKeyExchangeFin, changeCipherSpecFin ChangeCipherSpecFin) (err error)

ServerECDHESecretKeyExchange 服务端交换秘钥(ECDHE)

func (*HandshakeProtocol) ServerFinished

func (h *HandshakeProtocol) ServerFinished(finished Event[gtp.MsgFinished]) (err error)

ServerFinished 服务端握手结束

func (*HandshakeProtocol) ServerHello

func (h *HandshakeProtocol) ServerHello(helloAccept HelloAccept) (err error)

ServerHello 服务端Hello

type HeartbeatHandler

type HeartbeatHandler = generic.DelegateFunc1[Event[gtp.MsgHeartbeat], error] // Heartbeat消息事件处理器

type HelloAccept

type HelloAccept = generic.PairFunc1[Event[gtp.MsgHello], Event[gtp.MsgHello], error] // 服务端确认客户端Hello请求

type HelloFin

type HelloFin = generic.Func1[Event[gtp.MsgHello], error] // 客户端获取服务端Hello响应

type ISynchronizer

type ISynchronizer interface {
	io.Writer
	io.WriterTo
	codec.IValidate
	// Synchronization 同步对端时序,对齐缓存序号
	Synchronization(remoteRecvSeq uint32) error
	// Ack 确认消息序号
	Ack(ack uint32) error
	// SendSeq 发送消息序号
	SendSeq() uint32
	// RecvSeq 接收消息序号
	RecvSeq() uint32
	// AckSeq 当前ack序号
	AckSeq() uint32
	// Cap 缓存区容量
	Cap() int
	// Cached 已缓存大小
	Cached() int
	// Clean 清理
	Clean()
}

ISynchronizer 同步器缓存

func NewSequencedSynchronizer

func NewSequencedSynchronizer(sendSeq, recvSeq uint32, cap int) ISynchronizer

NewSequencedSynchronizer 创建有时序同步器缓存

func NewUnsequencedSynchronizer

func NewUnsequencedSynchronizer() ISynchronizer

NewUnsequencedSynchronizer 创建无时序同步器缓存

type PayloadHandler

type PayloadHandler = generic.DelegateFunc1[Event[gtp.MsgPayload], error] // Payload消息事件处理器

type Retry

type Retry struct {
	Transceiver *Transceiver
	Times       int
}

Retry 网络io超时时重试

func (Retry) Recv

func (r Retry) Recv(e Event[gtp.Msg], err error) (Event[gtp.Msg], error)

Recv 重试接收

func (Retry) Send

func (r Retry) Send(err error) error

Send 重试发送

type RstError

type RstError struct {
	Code    gtp.Code // 错误码
	Message string   // 错误信息
}

RstError Rst错误提示

func CastRstErr

func CastRstErr(e Event[gtp.MsgRst]) RstError

CastRstErr Rst错误事件转换为错误提示

func (RstError) CastEvent

func (err RstError) CastEvent() Event[gtp.MsgRst]

CastEvent 转换为消息事件

func (RstError) Error

func (err RstError) Error() string

Error 错误信息

type RstHandler

type RstHandler = generic.DelegateFunc1[Event[gtp.MsgRst], error] // Rst消息事件处理器

type SecretKeyExchangeAccept

type SecretKeyExchangeAccept = generic.PairFunc1[Event[gtp.Msg], Event[gtp.MsgReader], error] // 客户端确认服务端SecretKeyExchange请求,需要自己判断消息Id并处理,用于支持多种秘钥交换函数

type SequencedSynchronizer

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

SequencedSynchronizer 有时序同步器缓存,主要用于断线重连时,同步对端时序,补发消息

func (*SequencedSynchronizer) Ack

func (s *SequencedSynchronizer) Ack(ack uint32) error

Ack 确认消息序号

func (*SequencedSynchronizer) AckSeq

func (s *SequencedSynchronizer) AckSeq() uint32

AckSeq 当前ack序号

func (*SequencedSynchronizer) Cached

func (s *SequencedSynchronizer) Cached() int

Cached 已缓存大小

func (*SequencedSynchronizer) Cap

func (s *SequencedSynchronizer) Cap() int

Cap 缓存区容量

func (*SequencedSynchronizer) Clean

func (s *SequencedSynchronizer) Clean()

Clean 清理

func (*SequencedSynchronizer) RecvSeq

func (s *SequencedSynchronizer) RecvSeq() uint32

RecvSeq 接收消息序号

func (*SequencedSynchronizer) Reset

func (s *SequencedSynchronizer) Reset(sendSeq, recvSeq uint32, cap int)

Reset 重置缓存

func (*SequencedSynchronizer) SendSeq

func (s *SequencedSynchronizer) SendSeq() uint32

SendSeq 发送消息序号

func (*SequencedSynchronizer) Synchronization

func (s *SequencedSynchronizer) Synchronization(remoteRecvSeq uint32) error

Synchronization 同步对端时序,对齐缓存序号

func (*SequencedSynchronizer) Validate

func (s *SequencedSynchronizer) Validate(msgHead gtp.MsgHead, msgBuff []byte) error

Validate 验证消息包

func (*SequencedSynchronizer) Write

func (s *SequencedSynchronizer) Write(p []byte) (n int, err error)

Write implements io.Writer

func (*SequencedSynchronizer) WriteTo

func (s *SequencedSynchronizer) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriteTo

type SyncTimeHandler

type SyncTimeHandler = generic.DelegateFunc1[Event[gtp.MsgSyncTime], error] // SyncTime消息事件处理器

type TransProtocol

type TransProtocol struct {
	Transceiver    *Transceiver   // 消息事件收发器
	RetryTimes     int            // 网络io超时时的重试次数
	PayloadHandler PayloadHandler // Payload消息事件处理器
}

TransProtocol 传输协议

func (*TransProtocol) HandleEvent

func (t *TransProtocol) HandleEvent(e Event[gtp.Msg]) error

HandleEvent 消息事件处理器

func (*TransProtocol) SendData

func (t *TransProtocol) SendData(data []byte) error

SendData 发送数据

type Transceiver

type Transceiver struct {
	Conn         net.Conn       // 网络连接
	Encoder      codec.IEncoder // 消息包编码器
	Decoder      codec.IDecoder // 消息包解码器
	Timeout      time.Duration  // 网络io超时时间
	Synchronizer ISynchronizer  // 同步器缓存
	// contains filtered or unexported fields
}

Transceiver 消息事件收发器,线程安全

func (*Transceiver) Clean

func (t *Transceiver) Clean()

Clean 清理

func (*Transceiver) Continue

func (t *Transceiver) Continue()

Continue 继续收发消息

func (*Transceiver) GC

func (t *Transceiver) GC()

GC GC

func (*Transceiver) Pause

func (t *Transceiver) Pause()

Pause 暂停收发消息

func (*Transceiver) Recv

func (t *Transceiver) Recv() (Event[gtp.Msg], error)

Recv 接收消息事件

func (*Transceiver) Renew

func (t *Transceiver) Renew(conn net.Conn, remoteRecvSeq uint32) (sendReq, recvReq uint32, err error)

Renew 刷新链路

func (*Transceiver) Resend

func (t *Transceiver) Resend() error

Resend 重新发送未完整发送的消息事件

func (*Transceiver) Send

func (t *Transceiver) Send(me Event[gtp.MsgReader]) error

Send 发送消息

func (*Transceiver) SendRst

func (t *Transceiver) SendRst(err error) error

SendRst 发送Rst消息事件

type UnsequencedSynchronizer

type UnsequencedSynchronizer struct {
	bytes.Buffer
}

UnsequencedSynchronizer 无时序同步器缓存

func (*UnsequencedSynchronizer) Ack

func (s *UnsequencedSynchronizer) Ack(ack uint32) error

Ack 确认消息序号

func (*UnsequencedSynchronizer) AckSeq

func (s *UnsequencedSynchronizer) AckSeq() uint32

AckSeq 当前ack序号

func (*UnsequencedSynchronizer) Cached

func (s *UnsequencedSynchronizer) Cached() int

Cached 已缓存大小

func (*UnsequencedSynchronizer) Clean

func (s *UnsequencedSynchronizer) Clean()

Clean 清理

func (*UnsequencedSynchronizer) RecvSeq

func (s *UnsequencedSynchronizer) RecvSeq() uint32

RecvSeq 接收消息序号

func (*UnsequencedSynchronizer) SendSeq

func (s *UnsequencedSynchronizer) SendSeq() uint32

SendSeq 发送消息序号

func (*UnsequencedSynchronizer) Synchronization

func (s *UnsequencedSynchronizer) Synchronization(remoteRecvSeq uint32) error

Synchronization 同步对端时序,对齐缓存序号

func (*UnsequencedSynchronizer) Validate

func (s *UnsequencedSynchronizer) Validate(msgHead gtp.MsgHead, msgBuff []byte) error

Validate 验证消息包

func (*UnsequencedSynchronizer) WriteTo

func (s *UnsequencedSynchronizer) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriteTo

Jump to

Keyboard shortcuts

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