Documentation ¶
Index ¶
- Variables
- type AuthAccept
- type ChangeCipherSpecAccept
- type ChangeCipherSpecFin
- type ContinueAccept
- type CtrlProtocol
- type ECDHESecretKeyExchangeFin
- type ErrorHandler
- type Event
- type EventDispatcher
- type EventHandler
- type FinishedAccept
- type HandshakeProtocol
- func (h *HandshakeProtocol) ClientAuth(ctx context.Context, auth Event[gtp.MsgAuth]) (err error)
- func (h *HandshakeProtocol) ClientContinue(ctx context.Context, cont Event[gtp.MsgContinue]) (err error)
- func (h *HandshakeProtocol) ClientFinished(ctx context.Context, finishedAccept FinishedAccept) (err error)
- func (h *HandshakeProtocol) ClientHello(ctx context.Context, hello Event[gtp.MsgHello], helloFin HelloFin) (err error)
- func (h *HandshakeProtocol) ClientSecretKeyExchange(ctx context.Context, secretKeyExchangeAccept SecretKeyExchangeAccept, ...) (err error)
- func (h *HandshakeProtocol) ServerAuth(ctx context.Context, authAccept AuthAccept) (err error)
- func (h *HandshakeProtocol) ServerContinue(ctx context.Context, continueAccept ContinueAccept) (err error)
- func (h *HandshakeProtocol) ServerECDHESecretKeyExchange(ctx context.Context, secretKeyExchange Event[gtp.MsgECDHESecretKeyExchange], ...) (err error)
- func (h *HandshakeProtocol) ServerFinished(ctx context.Context, finished Event[gtp.MsgFinished]) (err error)
- func (h *HandshakeProtocol) ServerHello(ctx context.Context, helloAccept HelloAccept) (err error)
- type HeartbeatHandler
- type HelloAccept
- type HelloFin
- type IEvent
- type ISynchronizer
- type PayloadHandler
- type Retry
- type RstError
- type RstHandler
- type SecretKeyExchangeAccept
- type SequencedSynchronizer
- func (s *SequencedSynchronizer) Ack(ack uint32) error
- func (s *SequencedSynchronizer) AckSeq() uint32
- func (s *SequencedSynchronizer) Cached() int
- func (s *SequencedSynchronizer) Cap() int
- func (s *SequencedSynchronizer) Clean()
- func (s *SequencedSynchronizer) RecvSeq() uint32
- func (s *SequencedSynchronizer) Reset(sendSeq, recvSeq uint32, cap int)
- func (s *SequencedSynchronizer) SendSeq() uint32
- func (s *SequencedSynchronizer) Synchronization(remoteRecvSeq uint32) error
- func (s *SequencedSynchronizer) Validate(msgHead gtp.MsgHead, msgBuff []byte) error
- func (s *SequencedSynchronizer) Write(p []byte) (n int, err error)
- func (s *SequencedSynchronizer) WriteTo(w io.Writer) (int64, error)
- type SyncTimeHandler
- type TransProtocol
- type Transceiver
- func (t *Transceiver) Clean()
- func (t *Transceiver) Continue()
- func (t *Transceiver) GC()
- func (t *Transceiver) Pause()
- func (t *Transceiver) Recv(ctx context.Context) (IEvent, error)
- func (t *Transceiver) Renew(conn net.Conn, remoteRecvSeq uint32) (sendReq, recvReq uint32, err error)
- func (t *Transceiver) Resend() error
- func (t *Transceiver) Send(e IEvent) error
- func (t *Transceiver) SendRst(err error) error
- type UnsequencedSynchronizer
- func (s *UnsequencedSynchronizer) Ack(ack uint32) error
- func (s *UnsequencedSynchronizer) AckSeq() uint32
- func (s *UnsequencedSynchronizer) Cached() int
- func (s *UnsequencedSynchronizer) Clean()
- func (s *UnsequencedSynchronizer) RecvSeq() uint32
- func (s *UnsequencedSynchronizer) SendSeq() uint32
- func (s *UnsequencedSynchronizer) Synchronization(remoteRecvSeq uint32) error
- func (s *UnsequencedSynchronizer) Validate(msgHead gtp.MsgHead, msgBuff []byte) error
- func (s *UnsequencedSynchronizer) WriteTo(w io.Writer) (int64, error)
Constants ¶
This section is empty.
Variables ¶
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结束 )
var (
ErrUnexpectedMsg = errors.New("gtp: unexpected msg") // 收到非预期的消息
)
Functions ¶
This section is empty.
Types ¶
type ChangeCipherSpecAccept ¶
type ChangeCipherSpecAccept = generic.PairFunc1[Event[gtp.MsgChangeCipherSpec], Event[gtp.MsgChangeCipherSpec], error] // 客户端确认服务端ChangeCipherSpec请求
type ChangeCipherSpecFin ¶
type ContinueAccept ¶
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 IEvent) error
HandleEvent 消息事件处理器
func (*CtrlProtocol) RequestTime ¶
func (c *CtrlProtocol) RequestTime(corrId int64) error
RequestTime 请求同步时间
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 消息事件
type EventDispatcher ¶
type EventDispatcher struct { Transceiver *Transceiver // 消息事件收发器 RetryTimes int // 网络io超时时的重试次数 EventHandler EventHandler // 消息事件处理器列表 }
EventDispatcher 消息事件分发器
func (*EventDispatcher) Dispatching ¶
func (d *EventDispatcher) Dispatching(ctx context.Context) error
Dispatching 分发事件
func (*EventDispatcher) Run ¶
func (d *EventDispatcher) Run(ctx context.Context, errorHandler ...ErrorHandler)
Run 运行
type EventHandler ¶
type EventHandler = generic.DelegateFunc1[IEvent, error] // 消息事件处理器
type FinishedAccept ¶
type HandshakeProtocol ¶
type HandshakeProtocol struct { Transceiver *Transceiver // 消息事件收发器 RetryTimes int // 网络io超时时的重试次数 }
HandshakeProtocol 握手协议
func (*HandshakeProtocol) ClientAuth ¶
ClientAuth 客户端发起鉴权
func (*HandshakeProtocol) ClientContinue ¶
func (h *HandshakeProtocol) ClientContinue(ctx context.Context, cont Event[gtp.MsgContinue]) (err error)
ClientContinue 客户端发起重连
func (*HandshakeProtocol) ClientFinished ¶
func (h *HandshakeProtocol) ClientFinished(ctx context.Context, finishedAccept FinishedAccept) (err error)
ClientFinished 客户端握手结束
func (*HandshakeProtocol) ClientHello ¶
func (h *HandshakeProtocol) ClientHello(ctx context.Context, hello Event[gtp.MsgHello], helloFin HelloFin) (err error)
ClientHello 客户端Hello
func (*HandshakeProtocol) ClientSecretKeyExchange ¶
func (h *HandshakeProtocol) ClientSecretKeyExchange(ctx context.Context, secretKeyExchangeAccept SecretKeyExchangeAccept, changeCipherSpecAccept ChangeCipherSpecAccept) (err error)
ClientSecretKeyExchange 客户端交换秘钥
func (*HandshakeProtocol) ServerAuth ¶
func (h *HandshakeProtocol) ServerAuth(ctx context.Context, authAccept AuthAccept) (err error)
ServerAuth 服务端验证鉴权
func (*HandshakeProtocol) ServerContinue ¶
func (h *HandshakeProtocol) ServerContinue(ctx context.Context, continueAccept ContinueAccept) (err error)
ServerContinue 服务端处理重连
func (*HandshakeProtocol) ServerECDHESecretKeyExchange ¶
func (h *HandshakeProtocol) ServerECDHESecretKeyExchange(ctx context.Context, secretKeyExchange Event[gtp.MsgECDHESecretKeyExchange], secretKeyExchangeFin ECDHESecretKeyExchangeFin, changeCipherSpecFin ChangeCipherSpecFin) (err error)
ServerECDHESecretKeyExchange 服务端交换秘钥(ECDHE)
func (*HandshakeProtocol) ServerFinished ¶
func (h *HandshakeProtocol) ServerFinished(ctx context.Context, finished Event[gtp.MsgFinished]) (err error)
ServerFinished 服务端握手结束
func (*HandshakeProtocol) ServerHello ¶
func (h *HandshakeProtocol) ServerHello(ctx context.Context, helloAccept HelloAccept) (err error)
ServerHello 服务端Hello
type HeartbeatHandler ¶
type HeartbeatHandler = generic.DelegateFunc1[Event[gtp.MsgHeartbeat], error] // Heartbeat消息事件处理器
type HelloAccept ¶
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 Ctx context.Context }
Retry 网络io超时时重试
type RstHandler ¶
type SecretKeyExchangeAccept ¶
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) 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 验证消息包
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 IEvent) error
HandleEvent 消息事件处理器
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) Recv ¶
func (t *Transceiver) Recv(ctx context.Context) (IEvent, error)
Recv 接收消息事件
type UnsequencedSynchronizer ¶
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) 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 同步对端时序,对齐缓存序号