Documentation
      ¶
    
    
  
    
      Index ¶
- Variables
 - type Authenticator
 - type GateOptions
 - type IGate
 - type ISession
 - type IWatcher
 - type SessionRecvDataHandler
 - type SessionRecvEventHandler
 - type SessionSettings
 - func (s SessionSettings) Change() error
 - func (s SessionSettings) RecvDataChanSize(size int, recyclable bool) SessionSettings
 - func (s SessionSettings) RecvDataHandler(handler SessionRecvDataHandler) SessionSettings
 - func (s SessionSettings) RecvEventChanSize(size int) SessionSettings
 - func (s SessionSettings) RecvEventHandler(handler SessionRecvEventHandler) SessionSettings
 - func (s SessionSettings) SendDataChanSize(size int) SessionSettings
 - func (s SessionSettings) SendEventChanSize(size int) SessionSettings
 - func (s SessionSettings) StateChangedHandler(handler SessionStateChangedHandler) SessionSettings
 
- type SessionState
 - type SessionStateChangedHandler
 
Constants ¶
This section is empty.
Variables ¶
      View Source
      
  
    var ( Name = self.Name Using = self.Using Install = self.Install Uninstall = self.Uninstall )
      View Source
      
  var CliDetails = netpath.NodeDetails{
	Domain:             "cli",
	BroadcastSubdomain: "cli.bc",
	MulticastSubdomain: "cli.mc",
	NodeSubdomain:      "cli.nd",
	PathSeparator:      ".",
}
    CliDetails 客户端地址信息
      View Source
      
  
var With _GateOption
    Functions ¶
This section is empty.
Types ¶
type Authenticator ¶ added in v0.1.45
type GateOptions ¶
type GateOptions struct {
	TCPAddress                     string                     // TCP监听地址
	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表示使用系统默认值
	TCPTLSConfig                   *tls.Config                // TCP的TLS配置,nil表示不使用TLS加密链路
	WebSocketURL                   *url.URL                   // WebSocket监听地址
	WebSocketTLSConfig             *tls.Config                // TCP的TLS配置,nil表示不使用TLS加密链路
	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表示不开启
	AcceptTimeout                  time.Duration              // 接受连接超时时间
	Authenticator                  Authenticator              // 鉴权客户端处理器
	SessionInactiveTimeout         time.Duration              // 会话不活跃后的超时时间
	SessionStateChangedHandler     SessionStateChangedHandler // 会话状态变化的处理器(优先级低于会话的处理器)
	SessionSendDataChanSize        int                        // 会话默认发送数据的channel的大小,<=0表示不使用channel
	SessionRecvDataChanSize        int                        // 会话默认接收数据的channel的大小,<=0表示不使用channel
	SessionRecvDataChanRecyclable  bool                       // 会话默认接收数据的channel中是否使用可回收字节对象
	SessionSendEventChanSize       int                        // 会话默认发送自定义事件的channel的大小,<=0表示不使用channel
	SessionRecvEventChanSize       int                        // 会话默认接收自定义事件的channel的大小,<=0表示不使用channel
	SessionRecvDataHandler         SessionRecvDataHandler     // 会话接收的数据的处理器(优先级低于会话的处理器)
	SessionRecvEventHandler        SessionRecvEventHandler    // 会话接收的自定义事件的处理器(优先级低于会话的处理器)
}
    type IGate ¶
type IGate interface {
	// GetSession 查询会话
	GetSession(sessionId uid.Id) (ISession, bool)
	// RangeSessions 遍历所有会话
	RangeSessions(fun generic.Func1[ISession, bool])
	// EachSessions 遍历所有会话
	EachSessions(fun generic.Action1[ISession])
	// CountSessions 统计所有会话数量
	CountSessions() int
	// Watch 监听会话变化
	Watch(ctx context.Context, handler SessionStateChangedHandler) IWatcher
}
    IGate 网关
type ISession ¶
type ISession interface {
	context.Context
	fmt.Stringer
	// GetContext 获取服务上下文
	GetContext() service.Context
	// GetId 获取会话Id
	GetId() uid.Id
	// GetUserId 获取用户Id
	GetUserId() string
	// GetToken 获取token
	GetToken() string
	// GetState 获取会话状态
	GetState() SessionState
	// GetLocalAddr 获取本地地址
	GetLocalAddr() net.Addr
	// GetRemoteAddr 获取对端地址
	GetRemoteAddr() net.Addr
	// GetSettings 获取配置
	GetSettings() SessionSettings
	// SendData 发送数据
	SendData(data []byte) error
	// WatchData 监听数据
	WatchData(ctx context.Context, handler SessionRecvDataHandler) IWatcher
	// SendEvent 发送自定义事件
	SendEvent(event transport.IEvent) error
	// WatchEvent 监听自定义事件
	WatchEvent(ctx context.Context, handler SessionRecvEventHandler) IWatcher
	// SendDataChan 发送数据的channel
	SendDataChan() chan<- binaryutil.RecycleBytes
	// RecvDataChan 接收数据的channel
	RecvDataChan() <-chan binaryutil.RecycleBytes
	// SendEventChan 发送自定义事件的channel
	SendEventChan() chan<- transport.IEvent
	// RecvEventChan 接收自定义事件的channel
	RecvEventChan() <-chan transport.IEvent
	// Close 关闭
	Close(err error) <-chan struct{}
	// Closed 已关闭
	Closed() <-chan struct{}
}
    ISession 会话
type IWatcher ¶
type IWatcher interface {
	context.Context
	Terminate() <-chan struct{}
	Terminated() <-chan struct{}
}
    IWatcher 监听器
type SessionRecvDataHandler ¶
type SessionRecvDataHandler = generic.DelegateFunc2[ISession, []byte, error] // 会话接收的数据的处理器
type SessionRecvEventHandler ¶
type SessionSettings ¶ added in v0.1.32
type SessionSettings struct {
	CurrStateChangedHandler    SessionStateChangedHandler
	CurrSendDataChanSize       int
	CurrRecvDataChanSize       int
	CurrRecvDataChanRecyclable bool
	CurrSendEventChanSize      int
	CurrRecvEventChanSize      int
	CurrRecvDataHandler        SessionRecvDataHandler
	CurrRecvEventHandler       SessionRecvEventHandler
	// contains filtered or unexported fields
}
    SessionSettings 会话设置
func (SessionSettings) Change ¶ added in v0.1.32
func (s SessionSettings) Change() error
Change 执行修改
func (SessionSettings) RecvDataChanSize ¶ added in v0.1.32
func (s SessionSettings) RecvDataChanSize(size int, recyclable bool) SessionSettings
RecvDataChanSize 设置接收数据的channel的大小,<=0表示不使用channel
func (SessionSettings) RecvDataHandler ¶ added in v0.1.32
func (s SessionSettings) RecvDataHandler(handler SessionRecvDataHandler) SessionSettings
RecvDataHandler 设置接收的数据的处理器
func (SessionSettings) RecvEventChanSize ¶ added in v0.1.32
func (s SessionSettings) RecvEventChanSize(size int) SessionSettings
RecvEventChanSize 设置接收自定义事件的channel的大小,<=0表示不使用channel
func (SessionSettings) RecvEventHandler ¶ added in v0.1.32
func (s SessionSettings) RecvEventHandler(handler SessionRecvEventHandler) SessionSettings
RecvEventHandler 设置接收自定义事件的处理器
func (SessionSettings) SendDataChanSize ¶ added in v0.1.32
func (s SessionSettings) SendDataChanSize(size int) SessionSettings
SendDataChanSize 设置发送数据的channel的大小,<=0表示不使用channel
func (SessionSettings) SendEventChanSize ¶ added in v0.1.32
func (s SessionSettings) SendEventChanSize(size int) SessionSettings
SendEventChanSize 设置发送自定义事件的channel的大小,<=0表示不使用channel
func (SessionSettings) StateChangedHandler ¶ added in v0.1.32
func (s SessionSettings) StateChangedHandler(handler SessionStateChangedHandler) SessionSettings
StateChangedHandler 设置会话状态变化的处理器
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] // 会话状态变化的处理器(args: [session, curState, lastState])
      
      Source Files
      ¶
    
   Click to show internal directories. 
   Click to hide internal directories.