link

package
v0.0.57 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidGID             = errors.New("invalid gate id")
	ErrInvalidNID             = errors.New("invalid node id")
	ErrInvalidMessage         = errors.New("invalid message")
	ErrInvalidSessionKind     = errors.New("invalid session kind")
	ErrNotFoundUserSource     = errors.New("not found user source")
	ErrGateNotFoundUserSource = errors.New("gate not found user source")
	ErrNodeNotFoundUserSource = errors.New("node not found user source")
	ErrReceiveTargetEmpty     = errors.New("the receive target is empty")
	ErrInvalidArgument        = errors.New("invalid argument")
)

Functions

This section is empty.

Types

type BroadcastArgs

type BroadcastArgs struct {
	Kind    session.Kind // 会话类型,session.Conn 或 session.User
	Message *Message     // 消息
}

type BroadcastDeliverArgs

type BroadcastDeliverArgs struct {
	Kind    DeliverKind
	Message interface{} // 消息
}

type DeliverArgs

type DeliverArgs struct {
	NID     string      // 接收节点。存在接收节点时,消息会直接投递给接收节点;不存在接收节点时,系统定位用户所在节点,然后投递。
	CID     int64       // 连接ID
	UID     int64       // 用户ID
	Message interface{} // 消息
}

type DeliverKind

type DeliverKind int
const (
	Gate DeliverKind = iota + 1
	Center
	Game
)

type DisconnectArgs

type DisconnectArgs struct {
	GID     string       // 网关ID,会话类型为用户时可忽略此参数
	Kind    session.Kind // 会话类型,session.Conn 或 session.User
	Target  int64        // 会话目标,CID 或 UID
	IsForce bool         // 是否强制断开
}

type GetIPArgs

type GetIPArgs struct {
	GID    string       // 网关ID,会话类型为用户时可忽略此参数
	Kind   session.Kind // 会话类型,session.Conn 或 session.User
	Target int64        // 会话目标,CID 或 UID
}

type GetIdArgs

type GetIdArgs struct {
	GID    string       // 网关ID,会话类型为用户时可忽略此参数
	Kind   session.Kind // 会话类型,session.Conn 或 session.User
	Target int64        // 会话目标,CID 或 UID
}

type IsOnlineArgs

type IsOnlineArgs struct {
	GID    string       // 网关ID,会话类型为用户时可忽略此参数
	Kind   session.Kind // 会话类型,session.Conn 或 session.User
	Target int64        // 会话目标,CID 或 UID
}
type Link struct {
	// contains filtered or unexported fields
}
func NewLink(opts *Options) *Link

func (*Link) AskGate

func (l *Link) AskGate(ctx context.Context, uid int64, gid string) (string, bool, error)

AskGate 检测用户是否在给定的网关上

func (*Link) AskNode

func (l *Link) AskNode(ctx context.Context, uid int64, nid string) (string, bool, error)

AskNode 检测用户是否在给定的节点上

func (*Link) BindGate

func (l *Link) BindGate(ctx context.Context, uid int64, gid string, cid int64) error

BindGate 绑定网关

func (*Link) BindNode

func (l *Link) BindNode(ctx context.Context, uid int64, nid string) error

BindNode 绑定节点 单个用户只能被绑定到某一台节点服务器上,多次绑定会直接覆盖上次绑定 绑定操作会通过发布订阅方式同步到网关服务器和其他相关节点服务器上 nid 为需要绑定的节点ID

func (*Link) BlockConn

func (l *Link) BlockConn(ctx context.Context, onid string, nnid string, target uint64)

func (*Link) Broadcast

func (l *Link) Broadcast(ctx context.Context, args *BroadcastArgs) (int64, error)

Broadcast 推送广播消息

func (*Link) BroadcastDeliver

func (l *Link) BroadcastDeliver(ctx context.Context, args *BroadcastDeliverArgs) error

func (*Link) Deliver

func (l *Link) Deliver(ctx context.Context, args *DeliverArgs) error

Deliver 投递消息给节点处理

func (*Link) Disconnect

func (l *Link) Disconnect(ctx context.Context, args *DisconnectArgs) error

Disconnect 断开连接

func (*Link) FetchServiceAliasIDs

func (l *Link) FetchServiceAliasIDs(ctx context.Context, kind cluster.Kind, alias string, states ...cluster.State) ([]string, error)

func (*Link) FetchServiceAliasList

func (l *Link) FetchServiceAliasList(ctx context.Context, kind cluster.Kind, alias string, states ...cluster.State) ([]*registry.ServiceInstance, error)

func (*Link) FetchServiceList

func (l *Link) FetchServiceList(ctx context.Context, kind cluster.Kind, states ...cluster.State) ([]*registry.ServiceInstance, error)

FetchServiceList 拉取服务列表

func (*Link) GetID

func (l *Link) GetID(ctx context.Context, args *GetIdArgs) (int64, error)

GetID 获取conn的id

func (*Link) GetIP

func (l *Link) GetIP(ctx context.Context, args *GetIPArgs) (string, error)

GetIP 获取客户端IP

func (*Link) IsOnline

func (l *Link) IsOnline(ctx context.Context, args *IsOnlineArgs) (bool, error)

IsOnline 获取指定target是否在线

func (*Link) LocateGate

func (l *Link) LocateGate(ctx context.Context, uid int64) (string, error)

LocateGate 定位用户所在网关

func (*Link) LocateNode

func (l *Link) LocateNode(ctx context.Context, uid int64) (string, error)

LocateNode 定位用户所在节点

func (*Link) Multicast

func (l *Link) Multicast(ctx context.Context, args *MulticastArgs) (int64, error)

Multicast 推送组播消息

func (*Link) MulticastDeliver

func (l *Link) MulticastDeliver(ctx context.Context, args *MulticastDeliverArgs) error

func (*Link) Ping

func (l *Link) Ping(ctx context.Context, gid string, message string) (string, error)

func (*Link) Push

func (l *Link) Push(ctx context.Context, args *PushArgs) error

Push 推送消息

func (*Link) Stat

func (l *Link) Stat(ctx context.Context, kind session.Kind) (int64, error)

Stat 统计会话总数

func (*Link) StatWithInsId added in v0.0.56

func (l *Link) StatWithInsId(ctx context.Context, kind session.Kind, insId string) (int64, error)

StatWithInsId 统计会话总数

func (*Link) ToBuffer added in v0.0.45

func (l *Link) ToBuffer(message interface{}, encrypt bool) ([]byte, error)

func (*Link) Trigger

func (l *Link) Trigger(ctx context.Context, args *TriggerArgs) error

Trigger 触发事件

func (*Link) UnbindGate

func (l *Link) UnbindGate(ctx context.Context, uid int64) error

UnbindGate 解绑网关

func (*Link) UnbindNode

func (l *Link) UnbindNode(ctx context.Context, uid int64, nid string) error

UnbindNode 解绑节点 解绑时会对解绑节点ID进行校验,不匹配则解绑失败 解绑操作会通过发布订阅方式同步到网关服务器和其他相关节点服务器上 nid 为需要解绑的节点ID

func (*Link) WatchServiceInstance

func (l *Link) WatchServiceInstance(ctx context.Context, kinds ...cluster.Kind)

WatchServiceInstance 监听服务实例

func (*Link) WatchUserLocate

func (l *Link) WatchUserLocate(ctx context.Context, kinds ...cluster.Kind)

WatchUserLocate 监听用户定位

type Message

type Message struct {
	Seq   int32       // 序列号
	Route int32       // 路由ID
	Data  interface{} // 消息数据,接收json、proto、[]byte
}

type MulticastArgs

type MulticastArgs struct {
	GID     string       // 网关ID,会话类型为用户时可忽略此参数
	Kind    session.Kind // 会话类型,session.Conn 或 session.User
	Targets []int64      // 会话目标,CID 或 UID
	Message *Message     // 消息
}

type MulticastDeliverArgs

type MulticastDeliverArgs struct {
	Kind    DeliverKind
	Targets []string
	Message interface{} // 消息
}

type Options

type Options struct {
	GID             string                     // 网关ID
	NID             string                     // 节点ID
	Codec           encoding.Codec             // 编解码器
	Locator         locate.Locator             // 定位器
	Registry        registry.Registry          // 注册器
	Encryptor       crypto.Encryptor           // 加密器
	Transporter     transport.Transporter      // 传输器
	BalanceStrategy dispatcher.BalanceStrategy // 负载均衡策略
	Namespace       string
}

type PushArgs

type PushArgs struct {
	GID     string       // 网关ID,会话类型为用户时可忽略此参数
	Kind    session.Kind // 会话类型,session.Conn 或 session.User
	Target  int64        // 会话目标,CID 或 UID
	Message *Message     // 消息
}

type TriggerArgs

type TriggerArgs struct {
	Event cluster.Event // 事件
	CID   int64         // 连接ID
	UID   int64         // 用户ID
}

Jump to

Keyboard shortcuts

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