sbox

package module
v0.5.16 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 37 Imported by: 3

Documentation

Index

Constants

View Source
const (
	TransHandlerOnConnect = iota // 新连接连接上box时触发
	TransHandlerOnMessage
	TransHandlerBeforeCall
	TransHandlerOnClose
	TransHandlerMax
)
View Source
const (
	ServiceAdd = iota
	ServiceClose
)
View Source
const (
	ReceiveBufferLen = 1024 * 16
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BoxChannel

type BoxChannel struct {
	// contains filtered or unexported fields
}

BoxChannel implement rpc backend go transport interface one connect has its own channel

func NewBoxChannel

func NewBoxChannel(conn net.IBoxConn, cacheLen int) *BoxChannel

func (*BoxChannel) Clean

func (bch *BoxChannel) Clean()

Clean channel and recover

func (*BoxChannel) Close

func (bch *BoxChannel) Close()

Close active close net channel !

func (*BoxChannel) GetID

func (bch *BoxChannel) GetID() uint32

func (*BoxChannel) GlobalIndex

func (bch *BoxChannel) GlobalIndex() protocol.GlobalIndexType

func (*BoxChannel) Heartbeat added in v0.4.24

func (bch *BoxChannel) Heartbeat() error

func (*BoxChannel) IdentityID added in v0.5.3

func (bch *BoxChannel) IdentityID() string

func (*BoxChannel) IdentityTag added in v0.5.3

func (bch *BoxChannel) IdentityTag() string

func (*BoxChannel) IsClose

func (bch *BoxChannel) IsClose() bool

func (*BoxChannel) LocalAddr

func (bch *BoxChannel) LocalAddr() string

func (*BoxChannel) Peek

func (bch *BoxChannel) Peek(length int) ([]byte, int, error)

Peek read buffer without modify read point

func (*BoxChannel) Read

func (bch *BoxChannel) Read(pkg []byte, length int) (int, error)

func (*BoxChannel) RemoteAddr

func (bch *BoxChannel) RemoteAddr() string

func (*BoxChannel) Send

func (bch *BoxChannel) Send(pkg []byte) error

func (*BoxChannel) SetGlobalIndex

func (bch *BoxChannel) SetGlobalIndex(uuid protocol.GlobalIndexType)

func (*BoxChannel) SetID

func (bch *BoxChannel) SetID(transID uint32)

func (*BoxChannel) SetIdentityID added in v0.5.3

func (bch *BoxChannel) SetIdentityID(id string)

func (*BoxChannel) SetIdentityTag added in v0.5.3

func (bch *BoxChannel) SetIdentityTag(tag string)

func (*BoxChannel) Size

func (bch *BoxChannel) Size() uint32

func (*BoxChannel) Write

func (bch *BoxChannel) Write(pkg []byte, length int) (int, error)

type BoxNetwork

type BoxNetwork struct {
	// contains filtered or unexported fields
}

BoxNetwork service box network manager

func NewBoxNetWork

func NewBoxNetWork(option *NetworkOptions) *BoxNetwork

func (*BoxNetwork) ConnectTo

func (bn *BoxNetwork) ConnectTo(network, address string) (net.IBoxConn, error)

ConnectTo connect to other server block

func (*BoxNetwork) ConnectToService

func (bn *BoxNetwork) ConnectToService(service, network, address string)

func (*BoxNetwork) Init

func (bn *BoxNetwork) Init()

Init box net work

func (*BoxNetwork) ListenAt

func (bn *BoxNetwork) ListenAt(network, address string) error

ListenAt start Server at address !

func (*BoxNetwork) RegisterEventHandle

func (bn *BoxNetwork) RegisterEventHandle(eventType net.EventType, handle NetActionCallback)

func (*BoxNetwork) Start

func (bn *BoxNetwork) Start()

Start start all box network loop, like redis, zookeeper

func (*BoxNetwork) Stop

func (bn *BoxNetwork) Stop()

Stop box net work, send c

func (*BoxNetwork) Tick

func (bn *BoxNetwork) Tick()

Tick framework main loop

func (*BoxNetwork) TryGetChannel added in v0.4.7

func (bn *BoxNetwork) TryGetChannel(host string) *BoxChannel

type ChannelCache

type ChannelCache map[string]*BoxChannel

ChannelCache LoopCache map[string]*boxNetLoop

type ComponentsManager added in v0.4.31

type ComponentsManager struct {
	// contains filtered or unexported fields
}

ComponentsManager 组件管理工具

func (*ComponentsManager) GetComponent added in v0.4.31

func (c *ComponentsManager) GetComponent(name string) IComponent

func (*ComponentsManager) RegisterComponent added in v0.4.31

func (c *ComponentsManager) RegisterComponent(component IComponent) error

RegisterComponent 注册组件到box, 一个名字只允许注册一次

func (*ComponentsManager) UnRegisterComponent added in v0.4.31

func (c *ComponentsManager) UnRegisterComponent(name string) error

UnRegisterComponent 移除某个组件,非协程安全

type ConnectHandle added in v0.4.4

type ConnectHandle func(string, string, string)

type HostInfo

type HostInfo struct {
	InnerHost  string `yaml:"host"`
	PublicHost string `yaml:"expose_host"`
}

type IComponent added in v0.4.31

type IComponent interface {
	// GetName 返回自定义组件名,用于管理器管理,由外部用户自定义
	GetName() string
	// OnInit 初始化函数,在系统组件初始化完成之后由box进行调用,这个时候系统组件处于非运行状态,但是内存和资源已经申请完毕
	OnInit(*ServiceBox) error
	// OnStart 启动函数,在box的其余组件成功启动后,由系统调用
	OnStart(*ServiceBox) error
	// OnStop 停机通知函数,在box其余组件停机前调用,这个时候系统其余组件尚未销毁其资源
	OnStop(*ServiceBox) error
	// OnDestroy 销毁函数,销毁组件申请的资源,如果是使用的box系统的资源,应该在这个时候销毁
	OnDestroy(*ServiceBox) error
	// OnTick 主循环函数,在主线程中执行,请不要调用阻塞函数
	OnTick()
}

type IdentityChannelMap added in v0.5.3

type IdentityChannelMap map[string]transport.ITransport

IdentityChannelMap channel cache

type LoggedHandler added in v0.5.3

type LoggedHandler func(index protocol.GlobalIndexType)

LoggedHandler User logout notification handle

type NetActionCallback

type NetActionCallback func(string, *BoxChannel, error)

NetActionCallback network event call back

type NetworkOptions added in v0.4.26

type NetworkOptions struct {
	RecvBufferLen int `yaml:"recv_buffer_len"` // Message receiving buffer length.
}

BoxNetwork service box network manager

type Option

type Option func(*Options)

func WithOsArgs

func WithOsArgs(args []string) Option

type Options

type Options struct {
	// contains filtered or unexported fields
}

func NewBoxOptions added in v0.4.13

func NewBoxOptions() *Options

func (*Options) GetOneHostIp

func (o *Options) GetOneHostIp() string

func (*Options) PreHosts added in v0.4.4

func (o *Options) PreHosts() error

type ProxyCallBack

type ProxyCallBack func(string, *BoxChannel, error) //get proxy call back

type ProxyFinder added in v0.4.4

type ProxyFinder func(uuid uint64, trans transport.ITransport) (idlrpc.IProxy, error)

ProxyFinder 服务proxy获取接口

type ProxyHandler

type ProxyHandler struct {
	// contains filtered or unexported fields
}

func (*ProxyHandler) NewReplaceID

func (p *ProxyHandler) NewReplaceID() uint32

func (*ProxyHandler) OnRelay

func (p *ProxyHandler) OnRelay(from transport.ITransport, header *protocol.RpcMsgHeader) error

func (*ProxyHandler) UseHandler added in v0.5.7

func (p *ProxyHandler) UseHandler(handlerType int, handler TransHandlerFunc) error

UseHandler 设置扩展函数

type RawMsgHandler added in v0.5.7

type RawMsgHandler func(trans transport.ITransport, msg []byte) error

RawMsgHandler raw message handle

type RpcConfig added in v0.4.24

type RpcConfig struct {
	StackTrace bool `yaml:"stack_trace"`
	CallTrace  bool `yaml:"call_trace"`
}

type SBoxKey

type SBoxKey struct{}

type ServiceBox

type ServiceBox struct {
	// contains filtered or unexported fields
}

func MakeServiceBox

func MakeServiceBox() *ServiceBox

func (*ServiceBox) AddComponent added in v0.4.31

func (sb *ServiceBox) AddComponent(component IComponent) error

func (*ServiceBox) AddServicePackage

func (sb *ServiceBox) AddServicePackage(pack *idlrpc.PackageInfo) error

func (*ServiceBox) GetConfig

func (sb *ServiceBox) GetConfig() config.Config

func (*ServiceBox) GetDirectHande added in v0.5.7

func (sb *ServiceBox) GetDirectHande() transport.ITransport

GetDirectHande 返回直连模式下的handler

func (*ServiceBox) GetExtraProxy added in v0.5.3

func (sb *ServiceBox) GetExtraProxy(uuid uint64, globalIndex protocol.GlobalIndexType, trans transport.ITransport) (idlrpc.IProxy, error)

func (*ServiceBox) GetHttp added in v0.4.19

func (sb *ServiceBox) GetHttp() *http_proxy.HttpProxy

GetHttp 返回http模块,需要配置中开启http模块,并且以网关模式启动plato应用

func (*ServiceBox) GetLogger

func (sb *ServiceBox) GetLogger() slog.BoxLogger

func (*ServiceBox) GetMessageHandle added in v0.5.3

func (sb *ServiceBox) GetMessageHandle() *ServiceMessageHandle

func (*ServiceBox) GetMongoClient added in v0.4.2

func (sb *ServiceBox) GetMongoClient() *mongodb.MongoDB

func (*ServiceBox) GetOptions

func (sb *ServiceBox) GetOptions() string

func (*ServiceBox) GetProxy

func (sb *ServiceBox) GetProxy(uuid uint64) (idlrpc.IProxy, error)

func (*ServiceBox) GetProxyFromPeer

func (sb *ServiceBox) GetProxyFromPeer(ctx idlrpc.IServiceContext, uuid uint64) (idlrpc.IProxy, error)

func (*ServiceBox) GetProxyHandler added in v0.5.7

func (sb *ServiceBox) GetProxyHandler() *ProxyHandler

GetProxyHandler 返回proxy模块,需要配置中开启proxy模块,并且以网关模式启动plato应用

func (*ServiceBox) GetProxyWithNickName

func (sb *ServiceBox) GetProxyWithNickName(uuid uint64, name string) (idlrpc.IProxy, error)

func (*ServiceBox) GetRedisClient added in v0.4.2

func (sb *ServiceBox) GetRedisClient() redis.IClient

func (*ServiceBox) GetScheduler added in v0.4.24

func (sb *ServiceBox) GetScheduler() scheduler.ITimer

func (*ServiceBox) GetTransport

func (sb *ServiceBox) GetTransport(uuid uint64) (*BoxChannel, error)

func (*ServiceBox) Init

func (sb *ServiceBox) Init(opts ...Option) error

func (*ServiceBox) KickOutUser added in v0.4.24

func (sb *ServiceBox) KickOutUser(proxy idlrpc.IProxy) error

KickOutUser 踢用户下线

func (*ServiceBox) NewUuid added in v0.5.1

func (sb *ServiceBox) NewUuid() string

func (*ServiceBox) ShutDown

func (sb *ServiceBox) ShutDown() error

func (*ServiceBox) Start

func (sb *ServiceBox) Start() error

func (*ServiceBox) Tick

func (sb *ServiceBox) Tick()

func (*ServiceBox) UnWatchService added in v0.4.4

func (sb *ServiceBox) UnWatchService(name string, watcher ServiceWatcher) error

func (*ServiceBox) UseTransHandler added in v0.5.7

func (sb *ServiceBox) UseTransHandler(handlerType int, handler TransHandlerFunc) error

func (*ServiceBox) WatchService added in v0.4.4

func (sb *ServiceBox) WatchService(uuid uint64, watcher ServiceWatcher) error

func (*ServiceBox) WatchServiceWithNickName added in v0.4.4

func (sb *ServiceBox) WatchServiceWithNickName(uuid uint64, name string, watcher ServiceWatcher) error

type ServiceBoxContext added in v0.5.4

type ServiceBoxContext struct {
	*idlrpc.RpcContext
	// contains filtered or unexported fields
}

ServiceBoxContext service-box context

func NewServiceBoxContext added in v0.5.4

func NewServiceBoxContext(box *ServiceBox) *ServiceBoxContext

func (*ServiceBoxContext) Clone added in v0.5.6

Clone clone 一个新的上下文,保留连接,身份信息但是不保留global index 和 用户协议的中间态

func (*ServiceBoxContext) Debug added in v0.5.8

func (c *ServiceBoxContext) Debug(format string, i ...interface{})

func (*ServiceBoxContext) Error added in v0.5.4

func (c *ServiceBoxContext) Error(format string, i ...interface{})

func (*ServiceBoxContext) GetIdentityID added in v0.5.4

func (c *ServiceBoxContext) GetIdentityID() string

func (*ServiceBoxContext) GetIdentityTag added in v0.5.4

func (c *ServiceBoxContext) GetIdentityTag() string

func (*ServiceBoxContext) GetProxy added in v0.5.4

func (c *ServiceBoxContext) GetProxy(uuid uint64) idlrpc.IProxy

func (*ServiceBoxContext) GetProxyFromPeer added in v0.5.4

func (c *ServiceBoxContext) GetProxyFromPeer(uuid uint64) idlrpc.IProxy

func (*ServiceBoxContext) GetProxyWithNickname added in v0.5.4

func (c *ServiceBoxContext) GetProxyWithNickname(uuid uint64, name string) idlrpc.IProxy

func (*ServiceBoxContext) GetServiceBox added in v0.5.4

func (c *ServiceBoxContext) GetServiceBox() *ServiceBox

func (*ServiceBoxContext) GetTransport added in v0.5.4

func (c *ServiceBoxContext) GetTransport() transport.ITransport

func (*ServiceBoxContext) Info added in v0.5.4

func (c *ServiceBoxContext) Info(format string, i ...interface{})

func (*ServiceBoxContext) Warning added in v0.5.4

func (c *ServiceBoxContext) Warning(format string, i ...interface{})

type ServiceCfg

type ServiceCfg struct {
	//CustomName service nickname cache
	CustomName map[uint64]string `yaml:"custom_name"`
}

type ServiceEvent added in v0.4.4

type ServiceEvent int

ServiceEvent 服务变化事件类型 ServiceAdd 添加 ServiceClose 关闭

type ServiceMessageHandle added in v0.5.3

type ServiceMessageHandle struct {
	// contains filtered or unexported fields
}

ServiceMessageHandle The RPC message handling handle

func (*ServiceMessageHandle) GetTransport added in v0.5.3

func (mh *ServiceMessageHandle) GetTransport(identityID string) transport.ITransport

GetTransport getting the transport by identity id

func (*ServiceMessageHandle) Init added in v0.5.3

func (mh *ServiceMessageHandle) Init()

func (*ServiceMessageHandle) OnIdentityNotify added in v0.5.3

func (mh *ServiceMessageHandle) OnIdentityNotify(trans transport.ITransport, identityID string, identityTag string)

OnIdentityNotify This function is triggered when the other connection notifies it of its identity

func (*ServiceMessageHandle) OnLoggedOut added in v0.5.3

func (mh *ServiceMessageHandle) OnLoggedOut(index protocol.GlobalIndexType)

OnLoggedOut This function is triggered when the external connection is broken.

func (*ServiceMessageHandle) OnRawMessage added in v0.5.7

func (mh *ServiceMessageHandle) OnRawMessage(trans transport.ITransport, msg []byte)

OnRawMessage This function is triggered when the other connection sends a message

func (*ServiceMessageHandle) SetLoggedOutHandle added in v0.5.3

func (mh *ServiceMessageHandle) SetLoggedOutHandle(cb LoggedHandler)

SetLoggedOutHandle Call in the main coroutine and set the user logout response handle to ensure coroutine security.

func (*ServiceMessageHandle) SetRawMsgHandle added in v0.5.7

func (mh *ServiceMessageHandle) SetRawMsgHandle(handler RawMsgHandler)

SetRawMsgHandle Call in the main coroutine and set the raw message handle to ensure coroutine security.

func (*ServiceMessageHandle) UnInit added in v0.5.3

func (mh *ServiceMessageHandle) UnInit()

type ServiceWatcher added in v0.4.4

type ServiceWatcher func(eType ServiceEvent, name string, host string, proxy idlrpc.IProxy)

ServiceWatcher 是服务监听回调函数类型

type TransHandlerFunc added in v0.5.7

type TransHandlerFunc func(trans transport.ITransport) error

TransHandlerFunc trans handler 用于扩展处理box's 连接

type WatcherList added in v0.4.4

type WatcherList struct {
	// contains filtered or unexported fields
}

type WatcherManager added in v0.4.4

type WatcherManager struct {
	// contains filtered or unexported fields
}

WatcherManager 服务变化监听管理

Directories

Path Synopsis
Package common some common define
Package common some common define
example
testcallee
Generated by the go idl tools.
Generated by the go idl tools.
testcaller
Generated by the go idl tools.
Generated by the go idl tools.
internal
net
util
config/loader/memory
Package memory loader will load config info from source, encoder it and store to memory
Package memory loader will load config info from source, encoder it and store to memory

Jump to

Keyboard shortcuts

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