gtp_cli

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reonnect

func Reonnect(client *Client) error

Reonnect 重连服务端

Types

type Client

type Client struct {
	context.Context
	// contains filtered or unexported fields
}

Client 客户端

func Connect

func Connect(ctx context.Context, endpoint string, settings ...option.Setting[ClientOptions]) (*Client, error)

Connect 连接服务端

func (*Client) Close

func (c *Client) Close() <-chan struct{}

Close 关闭

func (*Client) GetEndpoint

func (c *Client) GetEndpoint() string

GetEndpoint 获取服务器地址

func (*Client) GetFutures

func (c *Client) GetFutures() concurrent.IFutures

GetFutures 获取异步模型Future控制器

func (*Client) GetLocalAddr

func (c *Client) GetLocalAddr() net.Addr

GetLocalAddr 获取本地地址

func (*Client) GetRemoteAddr

func (c *Client) GetRemoteAddr() net.Addr

GetRemoteAddr 获取对端地址

func (*Client) GetSessionId

func (c *Client) GetSessionId() string

GetSessionId 获取会话Id

func (*Client) GetToken

func (c *Client) GetToken() string

GetToken 获取token

func (*Client) RecvDataChan

func (c *Client) RecvDataChan() <-chan []byte

RecvDataChan 接收数据的channel

func (*Client) RecvEventChan

func (c *Client) RecvEventChan() <-chan transport.Event[gtp.Msg]

RecvEventChan 接收自定义事件的channel

func (*Client) RequestTime

func (c *Client) RequestTime(ctx context.Context) concurrent.Reply[*ResponseTime]

RequestTime 请求对端同步时间

func (*Client) SendData

func (c *Client) SendData(data []byte) error

SendData 发送数据

func (*Client) SendDataChan

func (c *Client) SendDataChan() chan<- []byte

SendDataChan 发送数据的channel

func (*Client) SendEvent

func (c *Client) SendEvent(event transport.Event[gtp.MsgReader]) error

SendEvent 发送自定义事件

func (*Client) SendEventChan

func (c *Client) SendEventChan() chan<- transport.Event[gtp.MsgReader]

SendEventChan 发送自定义事件的channel

func (*Client) String

func (c *Client) String() string

String implements fmt.Stringer

func (*Client) WatchData

func (c *Client) WatchData(ctx context.Context, handler RecvDataHandler) Watcher

WatchData 监听数据

func (*Client) WatchEvent

func (c *Client) WatchEvent(ctx context.Context, handler RecvEventHandler) Watcher

WatchEvent 监听自定义事件

type ClientOptions

type ClientOptions struct {
	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                     // 消息包解码器的消息构建器
	EncCipherSuite              gtp.CipherSuite                     // 加密通信中的密码学套件
	EncSignatureAlgorithm       gtp.SignatureAlgorithm              // 加密通信中的签名算法
	EncSignaturePrivateKey      crypto.PrivateKey                   // 加密通信中,签名用的私钥
	EncVerifyServerSignature    bool                                // 加密通信中,是否验证服务端签名
	EncVerifySignaturePublicKey crypto.PublicKey                    // 加密通信中,验证服务端签名用的公钥
	Compression                 gtp.Compression                     // 通信中的压缩函数
	CompressedSize              int                                 // 通信中启用压缩阀值(字节),<=0表示不开启
	AutoReconnect               bool                                // 开启自动重连
	AutoReconnectInterval       time.Duration                       // 自动重连的时间间隔
	AutoReconnectRetryTimes     int                                 // 自动重连的重试次数,<=0表示无限重试
	InactiveTimeout             time.Duration                       // 连接不活跃后的超时时间,开启自动重连后无效
	SendDataChan                chan []byte                         // 发送数据的channel
	RecvDataChan                chan []byte                         // 接收数据的channel
	SendEventChan               chan transport.Event[gtp.MsgReader] // 发送自定义事件的channel
	RecvEventChan               chan transport.Event[gtp.Msg]       // 接收自定义事件的channel
	RecvDataHandler             RecvDataHandler                     // 接收的数据的处理器
	RecvEventHandler            RecvEventHandler                    // 接收的自定义事件的处理器
	FutureTimeout               time.Duration                       // 异步模型Future超时时间
	AuthUserId                  string                              // 鉴权userid
	AuthToken                   string                              // 鉴权token
	AuthExtensions              []byte                              // 鉴权extensions
	ZapLogger                   *zap.Logger                         // zap日志
}

type Option

type Option struct{}

func (Option) AuthExtensions

func (Option) AuthExtensions(extensions []byte) option.Setting[ClientOptions]

func (Option) AuthToken

func (Option) AuthToken(token string) option.Setting[ClientOptions]

func (Option) AuthUserId

func (Option) AuthUserId(userId string) option.Setting[ClientOptions]

func (Option) AutoReconnect

func (Option) AutoReconnect(b bool) option.Setting[ClientOptions]

func (Option) AutoReconnectInterval

func (Option) AutoReconnectInterval(dur time.Duration) option.Setting[ClientOptions]

func (Option) AutoReconnectRetryTimes

func (Option) AutoReconnectRetryTimes(times int) option.Setting[ClientOptions]

func (Option) CompressedSize

func (Option) CompressedSize(size int) option.Setting[ClientOptions]

func (Option) Compression

func (Option) DecoderMsgCreator

func (Option) DecoderMsgCreator(mc gtp.IMsgCreator) option.Setting[ClientOptions]

func (Option) Default

func (Option) Default() option.Setting[ClientOptions]

func (Option) EncCipherSuite

func (Option) EncCipherSuite(cs gtp.CipherSuite) option.Setting[ClientOptions]

func (Option) EncSignatureAlgorithm

func (Option) EncSignatureAlgorithm(sa gtp.SignatureAlgorithm) option.Setting[ClientOptions]

func (Option) EncSignaturePrivateKey

func (Option) EncSignaturePrivateKey(priv crypto.PrivateKey) option.Setting[ClientOptions]

func (Option) EncVerifyServerSignature

func (Option) EncVerifyServerSignature(b bool) option.Setting[ClientOptions]

func (Option) EncVerifySignaturePublicKey

func (Option) EncVerifySignaturePublicKey(pub crypto.PublicKey) option.Setting[ClientOptions]

func (Option) FutureTimeout

func (Option) FutureTimeout(d time.Duration) option.Setting[ClientOptions]

func (Option) IOBufferCap

func (Option) IOBufferCap(cap int) option.Setting[ClientOptions]

func (Option) IORetryTimes

func (Option) IORetryTimes(times int) option.Setting[ClientOptions]

func (Option) IOTimeout

func (Option) InactiveTimeout

func (Option) InactiveTimeout(d time.Duration) option.Setting[ClientOptions]

func (Option) RecvDataChanSize

func (Option) RecvDataChanSize(size int) option.Setting[ClientOptions]

func (Option) RecvDataHandler

func (Option) RecvDataHandler(handler RecvDataHandler) option.Setting[ClientOptions]

func (Option) RecvEventChanSize

func (Option) RecvEventChanSize(size int) option.Setting[ClientOptions]

func (Option) RecvEventHandler

func (Option) RecvEventHandler(handler RecvEventHandler) option.Setting[ClientOptions]

func (Option) SendDataChanSize

func (Option) SendDataChanSize(size int) option.Setting[ClientOptions]

func (Option) SendEventChanSize

func (Option) SendEventChanSize(size int) option.Setting[ClientOptions]

func (Option) TCPLinger

func (Option) TCPLinger(sec *int) option.Setting[ClientOptions]

func (Option) TCPNoDelay

func (Option) TCPNoDelay(b *bool) option.Setting[ClientOptions]

func (Option) TCPQuickAck

func (Option) TCPQuickAck(b *bool) option.Setting[ClientOptions]

func (Option) TCPRecvBuf

func (Option) TCPRecvBuf(size *int) option.Setting[ClientOptions]

func (Option) TCPSendBuf

func (Option) TCPSendBuf(size *int) option.Setting[ClientOptions]

func (Option) TLSConfig

func (Option) TLSConfig(tlsConfig *tls.Config) option.Setting[ClientOptions]

func (Option) ZapLogger

func (Option) ZapLogger(logger *zap.Logger) option.Setting[ClientOptions]

type RecvDataHandler

type RecvDataHandler = generic.DelegateFunc1[[]byte, error]

type RecvEventHandler

type RecvEventHandler = transport.EventHandler

type ResponseTime

type ResponseTime struct {
	RequestTime time.Time // 请求时的本地时间
	LocalTime   time.Time // 响应时的本地时间
	RemoteTime  time.Time // 响应时的对端时间
}

ResponseTime 响应同步时间

func (*ResponseTime) NowTime

func (rt *ResponseTime) NowTime() time.Time

NowTime 当前时间

func (*ResponseTime) RTT

func (rt *ResponseTime) RTT() time.Duration

RTT 往返时间

func (*ResponseTime) SyncTime

func (rt *ResponseTime) SyncTime() time.Time

SyncTime 同步的时间

type Watcher

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

Watcher 监听器

Jump to

Keyboard shortcuts

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