router

package
v0.2.36 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: LGPL-2.1 Imports: 26 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Name      = self.Name
	Using     = self.Using
	Install   = self.Install
	Uninstall = self.Uninstall
)
View Source
var (
	ErrEntityNotFound  = errors.New("router: entity not found")
	ErrSessionNotFound = errors.New("router: session not found")
	ErrEntityMapped    = errors.New("router: entity is already mapping")
	ErrSessionMapped   = errors.New("router: session is already mapping")
)
View Source
var With _Option

Functions

This section is empty.

Types

type IGroup

type IGroup interface {
	context.Context
	// GetName 获取分组名称
	GetName() string
	// GetAddr 获取分组地址
	GetAddr() string
	// Add 添加实体
	Add(ctx context.Context, entIds ...uid.Id) error
	// Remove 删除实体
	Remove(ctx context.Context, entIds ...uid.Id) error
	// Range 遍历所有实体
	Range(fun generic.Func1[uid.Id, bool])
	// Each 遍历所有实体
	Each(fun generic.Action1[uid.Id])
	// Count 获取实体数量
	Count() int
	// RefreshTTL 刷新TTL
	RefreshTTL(ctx context.Context) error
	// SendData 发送数据
	SendData(data []byte)
	// SendEvent 发送自定义事件
	SendEvent(event transport.IEvent)
	// SendDataChan 发送数据的channel
	SendDataChan() chan<- binaryutil.RecycleBytes
	// SendEventChan 发送自定义事件的channel
	SendEventChan() chan<- transport.IEvent
}

IGroup 分组接口

type IMapping added in v0.1.45

type IMapping interface {
	context.Context
	// GetEntity 获取实体
	GetEntity() ec.ConcurrentEntity
	// GetSession 获取会话
	GetSession() gate.ISession
	// GetCliAddr 获取客户端地址
	GetCliAddr() string
}

IMapping 映射

type IRouter

type IRouter interface {
	// Mapping 路由映射
	Mapping(entityId, sessionId uid.Id) (IMapping, error)
	// CleanEntity 清理实体路由信息
	CleanEntity(entityId uid.Id)
	// CleanSession 清理会话路由信息
	CleanSession(sessionId uid.Id)
	// LookupEntity 查找实体
	LookupEntity(sessionId uid.Id) (ec.ConcurrentEntity, string, bool)
	// LookupSession 查找会话
	LookupSession(entityId uid.Id) (gate.ISession, bool)
	// AddGroup 添加分组
	AddGroup(ctx context.Context, name string) (IGroup, error)
	// DeleteGroup 删除分组
	DeleteGroup(ctx context.Context, name string)
	// GetGroup 查询分组
	GetGroup(ctx context.Context, name string) (IGroup, bool)
	// GetGroupByAddr 使用分组地址查询分组
	GetGroupByAddr(ctx context.Context, addr string) (IGroup, bool)
	// RangeGroups 遍历包含实体的所有分组
	RangeGroups(ctx context.Context, entityId uid.Id, fun generic.Func1[IGroup, bool])
	// EachGroups 遍历包含实体的所有分组
	EachGroups(ctx context.Context, entityId uid.Id, fun generic.Action1[IGroup])
}

IRouter 路由器接口

type RouterOptions

type RouterOptions struct {
	EtcdClient             *clientv3.Client
	EtcdConfig             *clientv3.Config
	GroupKeyPrefix         string
	GroupTTL               time.Duration
	GroupAutoRefreshTTL    bool
	GroupSendDataChanSize  int
	GroupSendEventChanSize int
	EntityGroupsKeyPrefix  string
	EntityGroupsCacheTTL   time.Duration
	CustomUsername         string
	CustomPassword         string
	CustomAddresses        []string
	CustomTLSConfig        *tls.Config
}

Jump to

Keyboard shortcuts

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