gtp_gate

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: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Name      = plugin.Name
	Using     = plugin.Using
	Install   = plugin.Install
	Uninstall = plugin.Uninstall
)

Functions

func CountSessions

func CountSessions(servCtx service.Context) int

CountSessions 统计所有会话数量

func RangeSessions

func RangeSessions(servCtx service.Context, fun func(session ISession) bool)

RangeSessions 遍历所有会话

Types

type AuthClientHandler

type AuthClientHandler = generic.DelegateFunc5[IGate, net.Conn, string, string, []byte, error] // 客户端鉴权处理器

type GateOptions

type GateOptions struct {
	Endpoints                      []string                   // 所有监听地址
	TLSConfig                      *tls.Config                // TLS配置,nil表示不使用TLS加密链路
	TCPNoDelay                     *bool                      // TCP的NoDelay选项,nil表示使用系统默认值
	TCPQuickAck                    *bool                      // TCP的QuickAck选项,nil表示使用系统默认值
	TCPRecvBuf                     *int                       // TCP的RecvBuf大小(字节)选项,nil表示使用系统默认值
	TCPSendBuf                     *int                       // TCP的SendBuf大小(字节)选项,nil表示使用系统默认值
	TCPLinger                      *int                       // TCP的PLinger选项,nil表示使用系统默认值
	IOTimeout                      time.Duration              // 网络io超时时间
	IORetryTimes                   int                        // 网络io超时后的重试次数
	IOBufferCap                    int                        // 网络io缓存容量(字节)
	DecoderMsgCreator              gtp.IMsgCreator            // 消息包解码器的消息构建器
	AgreeClientEncryptionProposal  bool                       // 是否同意使用客户端建议的加密方案
	EncCipherSuite                 gtp.CipherSuite            // 加密通信中的密码学套件
	EncNonceStep                   *big.Int                   // 加密通信中,使用需要nonce的加密算法时,每次加解密自增值
	EncECDHENamedCurve             gtp.NamedCurve             // 加密通信中,在ECDHE交换秘钥时使用的曲线类型
	EncSignatureAlgorithm          gtp.SignatureAlgorithm     // 加密通信中的签名算法
	EncSignaturePrivateKey         crypto.PrivateKey          // 加密通信中,签名用的私钥
	EncVerifyClientSignature       bool                       // 加密通信中,是否验证客户端签名
	EncVerifySignaturePublicKey    crypto.PublicKey           // 加密通信中,验证客户端签名用的公钥
	AgreeClientCompressionProposal bool                       // 是否同意使用客户端建议的压缩方案
	Compression                    gtp.Compression            // 通信中的压缩函数
	CompressedSize                 int                        // 通信中启用压缩阀值(字节),<=0表示不开启
	AuthClientHandler              AuthClientHandler          // 客户端鉴权鉴权处理器
	SessionInactiveTimeout         time.Duration              // 会话不活跃后的超时时间
	SessionStateChangedHandler     SessionStateChangedHandler // 会话状态变化的处理器(优先级低于会话的处理器)
	SessionSendDataChanSize        int                        // 会话发送数据的channel的大小,<=0表示不使用channel
	SessionRecvDataChanSize        int                        // 会话接收数据的channel的大小,<=0表示不使用channel
	SessionSendEventChanSize       int                        // 会话发送自定义事件的channel的大小,<=0表示不使用channel
	SessionRecvEventChanSize       int                        // 会话接收自定义事件的channel的大小,<=0表示不使用channel
	SessionRecvDataHandler         SessionRecvDataHandler     // 会话接收的数据的处理器(优先级低于会话的处理器)
	SessionRecvEventHandler        SessionRecvEventHandler    // 会话接收的自定义事件的处理器(优先级低于会话的处理器)
	FutureTimeout                  time.Duration              // 异步模型Future超时时间
}

type IGate

type IGate interface {
	// GetSession 查询会话
	GetSession(sessionId string) (ISession, bool)
	// RangeSessions 遍历所有会话
	RangeSessions(fun func(session ISession) bool)
	// CountSessions 统计所有会话数量
	CountSessions() int
}

IGate 网关

type ISession

type ISession interface {
	context.Context
	fmt.Stringer
	// Settings 设置会话选项(在会话状态Handshake与Confirmed时可用)
	Settings(settings ...option.Setting[SessionOptions]) error
	// GetContext 获取服务上下文
	GetContext() service.Context
	// GetId 获取会话Id
	GetId() string
	// GetToken 获取token
	GetToken() string
	// GetState 获取会话状态
	GetState() SessionState
	// GetLocalAddr 获取本地地址
	GetLocalAddr() net.Addr
	// GetRemoteAddr 获取对端地址
	GetRemoteAddr() net.Addr
	// GetFutures 获取异步模型Future控制器
	GetFutures() concurrent.IFutures
	// SendData 发送数据
	SendData(data []byte) error
	// WatchData 监听数据
	WatchData(ctx context.Context, handler RecvDataHandler) IWatcher
	// SendEvent 发送自定义事件
	SendEvent(event transport.Event[gtp.MsgReader]) error
	// WatchEvent 监听自定义事件
	WatchEvent(ctx context.Context, handler RecvEventHandler) IWatcher
	// SendDataChan 发送数据的channel
	SendDataChan() chan<- []byte
	// RecvDataChan 接收数据的channel
	RecvDataChan() <-chan []byte
	// SendEventChan 发送自定义事件的channel
	SendEventChan() chan<- transport.Event[gtp.MsgReader]
	// RecvEventChan 接收自定义事件的channel
	RecvEventChan() <-chan transport.Event[gtp.Msg]
	// Close 关闭
	Close(err error) <-chan struct{}
}

ISession 会话

func GetSession

func GetSession(servCtx service.Context, sessionId string) (ISession, bool)

GetSession 查询会话

type IWatcher

type IWatcher interface {
	context.Context
	Stop() <-chan struct{}
}

IWatcher 监听器

type Option

type Option struct {
	Gate    _GateOption
	Session _SessionOption
}

type RecvDataHandler

type RecvDataHandler = generic.DelegateFunc1[[]byte, error] // 会话接收的数据的处理器

type RecvEventHandler

type RecvEventHandler = generic.DelegateFunc1[transport.Event[gtp.Msg], error] // 会话接收的自定义事件的处理器

type SessionOptions

type SessionOptions struct {
	StateChangedHandler StateChangedHandler                 // 接收会话状态变化的处理器
	RecvDataHandler     RecvDataHandler                     // 接收数据的处理器(优先级低于监控器)
	RecvEventHandler    RecvEventHandler                    // 接收自定义事件的处理器(优先级低于监控器)
	SendDataChan        chan []byte                         // 发送数据的channel
	RecvDataChan        chan []byte                         // 接收数据的channel
	SendEventChan       chan transport.Event[gtp.MsgReader] // 发送自定义事件的channel
	RecvEventChan       chan transport.Event[gtp.Msg]       // 接收自定义事件的channel
}

type SessionRecvDataHandler

type SessionRecvDataHandler = generic.DelegateFunc2[ISession, []byte, error] // 会话接收的数据的处理器

type SessionRecvEventHandler

type SessionRecvEventHandler = generic.DelegateFunc2[ISession, transport.Event[gtp.Msg], error] // 会话接收的自定义事件的处理器

type SessionState

type SessionState int32

SessionState 客户端会话状态

const (
	SessionState_Birth     SessionState = iota // 出生
	SessionState_Handshake                     // 与客户端握手中
	SessionState_Confirmed                     // 已确认客户端连接
	SessionState_Active                        // 客户端活跃
	SessionState_Inactive                      // 客户端不活跃,等待重连恢复中
	SessionState_Death                         // 已过期
)

func (SessionState) String

func (i SessionState) String() string

type SessionStateChangedHandler

type SessionStateChangedHandler = generic.DelegateAction3[ISession, SessionState, SessionState] // 会话状态变化的处理器

type StateChangedHandler

type StateChangedHandler = generic.DelegateAction2[SessionState, SessionState] // 会话状态变化的处理器

Jump to

Keyboard shortcuts

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