node

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2022 License: Apache-2.0 Imports: 26 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")
	ErrInvalidSessionKind = errors.New("invalid session kind")
	ErrNotFoundUserSource = errors.New("not found user source")
	ErrReceiveTargetEmpty = errors.New("the receive target is empty")
	ErrUnableLocateSource = errors.New("unable to locate source")
)

Functions

This section is empty.

Types

type BroadcastArgs

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

type DeliverArgs

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

type DisconnectArgs

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

type EventHandler

type EventHandler func(gid string, uid int64)

type GetIPArgs

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

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 Node

type Node struct {
	component.Base
	// contains filtered or unexported fields
}

func NewNode

func NewNode(opts ...Option) *Node

func (*Node) Destroy

func (n *Node) Destroy()

Destroy 销毁网关服务器

func (*Node) Init

func (n *Node) Init()

Init 初始化节点

func (*Node) Name

func (n *Node) Name() string

Name 组件名称

func (*Node) Proxy

func (n *Node) Proxy() Proxy

Proxy 获取节点代理

func (*Node) Start

func (n *Node) Start()

Start 启动节点

type Option

type Option func(o *options)

func WithCodec

func WithCodec(codec encoding.Codec) Option

WithCodec 设置编解码器

func WithContext

func WithContext(ctx context.Context) Option

WithContext 设置上下文

func WithDecryptor

func WithDecryptor(decryptor crypto.Decryptor) Option

WithDecryptor 设置消息解密器

func WithEncryptor

func WithEncryptor(encryptor crypto.Encryptor) Option

WithEncryptor 设置消息加密器

func WithID

func WithID(id string) Option

WithID 设置实例ID

func WithLocator

func WithLocator(locator locate.Locator) Option

WithLocator 设置定位器

func WithName

func WithName(name string) Option

WithName 设置实例名称

func WithRegistry

func WithRegistry(r registry.Registry) Option

WithRegistry 设置服务注册器

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout 设置RPC调用超时时间

func WithTransporter

func WithTransporter(transporter transport.Transporter) Option

WithTransporter 设置消息传输器

type Proxy

type Proxy interface {
	// GetID 获取当前节点ID
	GetID() string
	// AddRouteHandler 添加路由处理器
	AddRouteHandler(route int32, stateful bool, handler RouteHandler)
	// SetDefaultRouteHandler 设置默认路由处理器,所有未注册的路由均走默认路由处理器
	SetDefaultRouteHandler(handler RouteHandler)
	// AddEventListener 添加事件监听器
	AddEventListener(event cluster.Event, handler EventHandler)
	// BindGate 绑定网关
	BindGate(ctx context.Context, gid string, cid, uid int64) error
	// UnbindGate 绑定网关
	UnbindGate(ctx context.Context, uid int64) error
	// BindNode 绑定节点
	BindNode(ctx context.Context, uid int64, nid ...string) error
	// UnbindNode 解绑节点
	UnbindNode(ctx context.Context, uid int64, nid ...string) error
	// LocateGate 定位用户所在网关
	LocateGate(ctx context.Context, uid int64) (string, error)
	// LocateNode 定位用户所在节点
	LocateNode(ctx context.Context, uid int64) (string, error)
	// FetchGateList 拉取网关列表
	FetchGateList(ctx context.Context, states ...cluster.State) ([]*registry.ServiceInstance, error)
	// FetchNodeList 拉取节点列表
	FetchNodeList(ctx context.Context, states ...cluster.State) ([]*registry.ServiceInstance, error)
	// GetIP 获取客户端IP
	GetIP(ctx context.Context, args *GetIPArgs) (string, error)
	// Push 推送消息
	Push(ctx context.Context, args *PushArgs) error
	// Response 响应消息
	Response(ctx context.Context, req Request, message interface{}) error
	// Multicast 推送组播消息
	Multicast(ctx context.Context, args *MulticastArgs) (int64, error)
	// Broadcast 推送广播消息
	Broadcast(ctx context.Context, args *BroadcastArgs) (int64, error)
	// Disconnect 断开连接
	Disconnect(ctx context.Context, args *DisconnectArgs) error
	// Deliver 投递消息给节点处理
	Deliver(ctx context.Context, args *DeliverArgs) error
}

type PushArgs

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

type Request

type Request interface {
	// GID 获取来源网关ID
	GID() string
	// NID 获取来源节点ID
	NID() string
	// CID 获取来源连接ID
	CID() int64
	// UID 获取来源用户ID
	UID() int64
	// Seq 获取消息序列号
	Seq() int32
	// Route 获取路由
	Route() int32
	// Data 获取数据
	Data() interface{}
	// Parse 解析请求
	Parse(v interface{}) error
	// Context 获取上线文
	Context() context.Context
	// GetIP 获取IP地址
	GetIP() (string, error)
	// Response 响应请求
	Response(message interface{}) error
	// BindGate 绑定网关
	BindGate(uid int64) error
	// UnbindGate 解绑网关
	UnbindGate() error
	// BindNode 绑定节点
	BindNode() error
	// UnbindNode 解绑节点
	UnbindNode() error
	// Disconnect 断开连接
	Disconnect(isForce ...bool) error
}

type RouteHandler

type RouteHandler func(req Request)

Jump to

Keyboard shortcuts

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