gate

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Rpc_GateRouteRegister       core.Rpc_Key = "Rpc_GateRouteRegister"       //网关路由注册
	Rpc_GateCustomRouteRegister core.Rpc_Key = "Rpc_GateCustomRouteRegister" //自定义网关路由注册
	Rpc_GateRoute               core.Rpc_Key = "Rpc_GateRoute"               //网关路由
	Rpc_GateAgentsIsKeep        core.Rpc_Key = "Rpc_GateAgentsIsKeep"        //校验代理是否还在
	RPC_GateAgentBuild          core.Rpc_Key = "RPC_GateAgentBuild"          //代理绑定
	RPC_GateAgentUnBuild        core.Rpc_Key = "RPC_GateAgentUnBuild"        //代理解绑
	RPC_GateSendMsg             core.Rpc_Key = "RPC_GateSendMsg"             //代理发送消息
	RPC_GateSendMsgByGroup      core.Rpc_Key = "RPC_GateSendMsgByGroup"      //代理群发消息
	RPC_GateSendMsgByBroadcast  core.Rpc_Key = "RPC_GateSendMsgByBroadcast"  //代理广播消息
	RPC_GateAgentClose          core.Rpc_Key = "RPC_GateAgentClose"          //代理关闭
)

Variables

This section is empty.

Functions

func NewLocalSession

func NewLocalSession(module IGateModule, data map[string]interface{}) (s core.IUserSession, err error)

func NewRemoteSession

func NewRemoteSession(service base.IClusterService, data map[string]interface{}) (s core.IUserSession, err error)

Types

type AgentBase

type AgentBase struct {
	Module IGateModule
	Agent  IAgent
	Conn   IConn

	Isclose bool
	// contains filtered or unexported fields
}

远程链接代理

func (*AgentBase) Destory

func (this *AgentBase) Destory()

func (*AgentBase) IP

func (this *AgentBase) IP() string

func (*AgentBase) Id

func (this *AgentBase) Id() string

func (*AgentBase) IsClosed

func (this *AgentBase) IsClosed() bool

func (*AgentBase) OnClose

func (this *AgentBase) OnClose()

func (*AgentBase) OnInit

func (this *AgentBase) OnInit(module IGateModule, coon IConn, agent IAgent) (err error)

func (*AgentBase) OnRecover

func (this *AgentBase) OnRecover(msg proto.IMessage)

func (*AgentBase) OnRun

func (this *AgentBase) OnRun()

func (*AgentBase) RevNum

func (this *AgentBase) RevNum() int64

func (*AgentBase) SendNum

func (this *AgentBase) SendNum() int64

func (*AgentBase) WriteMsg

func (this *AgentBase) WriteMsg(msg proto.IMessage) error

type AgentMgrComp

type AgentMgrComp struct {
	cbase.ModuleCompBase
	Agents *container.BeeMap
}

func (*AgentMgrComp) Close

func (this *AgentMgrComp) Close(aId string) (result string, err string)

func (*AgentMgrComp) Connect

func (this *AgentMgrComp) Connect(a IAgent)

func (*AgentMgrComp) Destroy

func (this *AgentMgrComp) Destroy() (err error)

func (*AgentMgrComp) DisConnect

func (this *AgentMgrComp) DisConnect(a IAgent)

func (*AgentMgrComp) Init

func (this *AgentMgrComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error)

func (*AgentMgrComp) SendMsg

func (this *AgentMgrComp) SendMsg(aId string, msg proto.IMessage) (result int, err string)

func (*AgentMgrComp) SendMsgByBroadcast

func (this *AgentMgrComp) SendMsgByBroadcast(msg proto.IMessage) (result int, err string)

func (*AgentMgrComp) SendMsgByGroup

func (this *AgentMgrComp) SendMsgByGroup(aIds []string, msg proto.IMessage) (result []string, err string)

type CustomRouteComp

type CustomRouteComp struct {
	cbase.ModuleCompBase
	// contains filtered or unexported fields
}

自定义网关组件 特殊消息转发可以在自定义网关内实现与注册

func (*CustomRouteComp) Init

func (this *CustomRouteComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error)

func (*CustomRouteComp) OnRoute

func (this *CustomRouteComp) OnRoute(agent IAgent, msg proto.IMessage) (code core.ErrorCode, err error)

func (*CustomRouteComp) RegisterRoute

func (this *CustomRouteComp) RegisterRoute(route core.CustomRoute, msgs map[uint16][]uint16) (result string, err string)

添加自定义网关组注册接口

func (*CustomRouteComp) RegisterRouteFunc

func (this *CustomRouteComp) RegisterRouteFunc(route core.CustomRoute, f func(a IAgent, msg proto.IMessage) (code core.ErrorCode, err error))

添加自定义网关组注册接口

func (*CustomRouteComp) Start

func (this *CustomRouteComp) Start() (err error)

type Gate

type Gate struct {
	cbase.ModuleBase

	CustomRouteComp    ICustomRouteComp
	LocalRouteMgrComp  ILocalRouteMgrComp
	RemoteRouteMgrComp IRemoteRouteMgrComp
	AgentMgrComp       IAgentMgrComp
	// contains filtered or unexported fields
}

func (*Gate) CloseAgent

func (this *Gate) CloseAgent(sId string) (result string, err string)

主动关闭代理

func (*Gate) Connect

func (this *Gate) Connect(a IAgent)

需重构处理 内部函数为重构代码 代理链接

func (*Gate) DisConnect

func (this *Gate) DisConnect(a IAgent)

代理关闭

func (*Gate) GetLocalRouteMgrComp

func (this *Gate) GetLocalRouteMgrComp() ILocalRouteMgrComp

func (*Gate) GetOptions

func (this *Gate) GetOptions() (options IOptions)

func (*Gate) Init

func (this *Gate) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error)

func (*Gate) OnInstallComp

func (this *Gate) OnInstallComp()

func (*Gate) OnRoute

func (this *Gate) OnRoute(a IAgent, msg proto.IMessage) (code core.ErrorCode, err error)

接收代理消息

func (*Gate) RegisterLocalRoute

func (this *Gate) RegisterLocalRoute(comId uint16, f func(session core.IUserSession, msg proto.IMessage) (code core.ErrorCode, err string))

func (*Gate) RegisterRemoteRoute

func (this *Gate) RegisterRemoteRoute(comId uint16, sId, sType string) (result string, err string)

需重构处理 内部函数为重构代码d

func (*Gate) SendMsg

func (this *Gate) SendMsg(sId string, msg proto.IMessage) (result int, err string)

发送代理消息

func (*Gate) SendMsgByBroadcast

func (this *Gate) SendMsgByBroadcast(msg proto.IMessage) (result int, err string)

广播代理消息

func (*Gate) SendMsgByGroup

func (this *Gate) SendMsgByGroup(aIds []string, msg proto.IMessage) (result []string, err string)

群发代理消息

func (*Gate) UnRegisterLocalRoute

func (this *Gate) UnRegisterLocalRoute(comId uint16, f func(session core.IUserSession, msg proto.IMessage) (code core.ErrorCode, err string))

func (*Gate) UnRegisterRemoteRoute

func (this *Gate) UnRegisterRemoteRoute(comId uint16, sType, sId string)

type IAgent

type IAgent interface {
	Id() string
	IP() string
	GetSessionData() map[string]interface{}
	OnInit(gate IGateModule, coon IConn, agent IAgent) (err error)
	WriteMsg(msg proto.IMessage) (err error)
	OnRecover(msg proto.IMessage)
	RevNum() int64
	SendNum() int64
	IsClosed() bool
	OnRun()
	OnClose() //主动关闭接口
	Destory() //关闭销毁
}

type IAgentMgrComp

type IAgentMgrComp interface {
	core.IModuleComp
	Connect(a IAgent)
	DisConnect(a IAgent)
	SendMsg(aId string, msg proto.IMessage) (result int, err string)                //发送消息到用户
	SendMsgByGroup(aIds []string, msg proto.IMessage) (result []string, err string) //发送消息到用户组
	SendMsgByBroadcast(msg proto.IMessage) (result int, err string)                 //发送消息到全服
	Close(aId string) (result string, err string)
}

type IConn

type IConn interface {
	Read(b []byte) (n int, err error)
	Write(b []byte) (n int, err error)
	RemoteAddr() net.Addr
	Close()
}

func NewTcpConn

func NewTcpConn(conn net.Conn) IConn

func NewWsConn

func NewWsConn(conn *websocket.Conn, heartbeat time.Duration) IConn

type ICustomRouteComp

type ICustomRouteComp interface {
	core.IModuleComp
	RegisterRoute(route core.CustomRoute, msgs map[uint16][]uint16) (result string, err string)
	RegisterRouteFunc(route core.CustomRoute, f func(a IAgent, msg proto.IMessage))
	OnRoute(agent IAgent, msg proto.IMessage) (code core.ErrorCode, err error)
}

type IGateModule

type IGateModule interface {
	core.IModule
	GetOptions() (options IOptions)
	GetLocalRouteMgrComp() ILocalRouteMgrComp
	RegisterRemoteRoute(comId uint16, sId, sType string) (result string, err string)
	UnRegisterRemoteRoute(comId uint16, sType, sId string)
	RegisterLocalRoute(comId uint16, f func(session core.IUserSession, msg proto.IMessage) (code core.ErrorCode, err string))
	UnRegisterLocalRoute(comId uint16, f func(session core.IUserSession, msg proto.IMessage) (code core.ErrorCode, err string))
	OnRoute(a IAgent, msg proto.IMessage) (core.ErrorCode, error)
	Connect(a IAgent)
	DisConnect(a IAgent)
	CloseAgent(sId string) (result string, err string)
	SendMsg(sId string, msg proto.IMessage) (result int, err string)                //发送消息到用户
	SendMsgByGroup(aIds []string, msg proto.IMessage) (result []string, err string) //发送消息到用户组
	SendMsgByBroadcast(msg proto.IMessage) (result int, err string)                 //发送消息到全服
}

type ILocalRouteMgrComp

type ILocalRouteMgrComp interface {
	core.IModuleComp
	SetNewSession(f func(module IGateModule, data map[string]interface{}) (s core.IUserSession, err error))
	RegisterRoute(comId uint16, f func(session core.IUserSession, msg proto.IMessage) (code core.ErrorCode, err string))
	UnRegisterRoute(comId uint16, f func(session core.IUserSession, msg proto.IMessage) (code core.ErrorCode, err string))
	OnRoute(agent IAgent, msg proto.IMessage) (code core.ErrorCode, err error)
}

type IOptions

type IOptions interface {
	GetTcpAddr() string
	GetWSAddr() string
	GetWSOuttime() time.Duration
	GetWSHeartbeat() time.Duration
	GetWSCertFile() string
	GetWSKeyFile() string
}

type IRemoteRouteMgrComp

type IRemoteRouteMgrComp interface {
	core.IModuleComp
	SetNewSession(f func(service base.IClusterService, data map[string]interface{}) (s core.IUserSession, err error))
	RegisterRoute(comId uint16, sId, sType string) (result string, err string)
	UnRegisterRoute(comId uint16, sType, sId string)
	OnRoute(agent IAgent, msg proto.IMessage) (code core.ErrorCode, err error)
}

type LocalRoute

type LocalRoute struct {
	Module IGateModule
	ComId  uint16
	// contains filtered or unexported fields
}

func NewLocalRoute

func NewLocalRoute(module IGateModule, comId uint16, sf func(module IGateModule, data map[string]interface{}) (s core.IUserSession, err error), f func(session core.IUserSession, msg proto.IMessage) (code core.ErrorCode, err string)) *LocalRoute

func (*LocalRoute) OnRoute

func (this *LocalRoute) OnRoute(a IAgent, msg proto.IMessage) (code core.ErrorCode, err string)

type LocalRouteMgrComp

type LocalRouteMgrComp struct {
	cbase.ModuleCompBase

	NewSession func(module IGateModule, data map[string]interface{}) (s core.IUserSession, err error)
	// contains filtered or unexported fields
}

func (*LocalRouteMgrComp) Init

func (this *LocalRouteMgrComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error)

func (*LocalRouteMgrComp) OnRoute

func (this *LocalRouteMgrComp) OnRoute(agent IAgent, msg proto.IMessage) (code core.ErrorCode, err error)

func (*LocalRouteMgrComp) RegisterRoute

func (this *LocalRouteMgrComp) RegisterRoute(comId uint16, f func(session core.IUserSession, msg proto.IMessage) (code core.ErrorCode, err string))

func (*LocalRouteMgrComp) SetNewSession

func (this *LocalRouteMgrComp) SetNewSession(f func(module IGateModule, data map[string]interface{}) (s core.IUserSession, err error))

func (*LocalRouteMgrComp) UnRegisterRoute

func (this *LocalRouteMgrComp) UnRegisterRoute(comId uint16, f func(session core.IUserSession, msg proto.IMessage) (code core.ErrorCode, err string))

type LocalSession

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

func (*LocalSession) Close

func (this *LocalSession) Close() (err error)

func (*LocalSession) GetGateId

func (this *LocalSession) GetGateId() string

func (*LocalSession) GetGateServerId

func (this *LocalSession) GetGateServerId() string

func (*LocalSession) GetIP

func (this *LocalSession) GetIP() string

func (*LocalSession) GetSessionId

func (this *LocalSession) GetSessionId() string

func (*LocalSession) SendMsg

func (this *LocalSession) SendMsg(comdId uint16, msgId uint16, msg interface{}) (err error)

func (*LocalSession) UpDateMap

func (this *LocalSession) UpDateMap(data map[string]interface{}) (err error)

type Options

type Options struct {
	TcpAddr     string
	WSAddr      string
	WSOuttime   int
	WSHeartbeat int
	WSCertFile  string
	WSKeyFile   string
}

func (*Options) GetTcpAddr

func (this *Options) GetTcpAddr() string

func (*Options) GetWSAddr

func (this *Options) GetWSAddr() string

func (*Options) GetWSCertFile

func (this *Options) GetWSCertFile() string

func (*Options) GetWSHeartbeat

func (this *Options) GetWSHeartbeat() time.Duration

func (*Options) GetWSKeyFile

func (this *Options) GetWSKeyFile() string

func (*Options) GetWSOuttime

func (this *Options) GetWSOuttime() time.Duration

func (*Options) LoadConfig

func (this *Options) LoadConfig(settings map[string]interface{}) (err error)

type RemoteRoute

type RemoteRoute struct {
	Service base.IClusterService
	ComId   uint16

	ServiceType string
	// contains filtered or unexported fields
}

func NewRemoteRoute

func NewRemoteRoute(service base.IClusterService, comId uint16, f func(service base.IClusterService, data map[string]interface{}) (s core.IUserSession, err error), sNode registry.ServiceNode) *RemoteRoute

func (*RemoteRoute) Count

func (this *RemoteRoute) Count() int32

func (*RemoteRoute) OnRoute

func (this *RemoteRoute) OnRoute(a IAgent, msg proto.IMessage) (code core.ErrorCode, err string)

func (*RemoteRoute) RegisterRoute

func (this *RemoteRoute) RegisterRoute(sNode registry.ServiceNode) (err error)

注册远程路由

func (*RemoteRoute) UnRegisterRoute

func (this *RemoteRoute) UnRegisterRoute(sId string)

注销远程路由

type RemoteRouteMgrComp

type RemoteRouteMgrComp struct {
	cbase.ModuleCompBase

	NewSession func(service base.IClusterService, data map[string]interface{}) (s core.IUserSession, err error)
	// contains filtered or unexported fields
}

func (*RemoteRouteMgrComp) Init

func (this *RemoteRouteMgrComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error)

func (*RemoteRouteMgrComp) OnRoute

func (this *RemoteRouteMgrComp) OnRoute(agent IAgent, msg proto.IMessage) (code core.ErrorCode, err error)

func (*RemoteRouteMgrComp) RegisterRoute

func (this *RemoteRouteMgrComp) RegisterRoute(comId uint16, sId, sType string) (result string, err string)

func (*RemoteRouteMgrComp) SetNewSession

func (this *RemoteRouteMgrComp) SetNewSession(f func(service base.IClusterService, data map[string]interface{}) (s core.IUserSession, err error))

func (*RemoteRouteMgrComp) Start

func (this *RemoteRouteMgrComp) Start() (err error)

func (*RemoteRouteMgrComp) UnRegisterRoute

func (this *RemoteRouteMgrComp) UnRegisterRoute(comId uint16, sType, sId string)

type RemoteSession

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

func (*RemoteSession) Close

func (this *RemoteSession) Close() (err error)

func (*RemoteSession) GetGateId

func (this *RemoteSession) GetGateId() string

func (*RemoteSession) GetGateServerId

func (this *RemoteSession) GetGateServerId() string

func (*RemoteSession) GetIP

func (this *RemoteSession) GetIP() string

func (*RemoteSession) GetSessionId

func (this *RemoteSession) GetSessionId() string

func (*RemoteSession) SendMsg

func (this *RemoteSession) SendMsg(comdId uint16, msgId uint16, msg interface{}) (err error)

func (*RemoteSession) UpDateMap

func (this *RemoteSession) UpDateMap(data map[string]interface{}) (err error)

type SessionData

type SessionData struct {
	IP           string
	SessionId    string
	GateServerId string //用户所在网关服务
}

type TcpConn

type TcpConn struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*TcpConn) Close

func (this *TcpConn) Close()

func (*TcpConn) Init

func (this *TcpConn) Init(conn net.Conn)

func (*TcpConn) LocalAddr

func (this *TcpConn) LocalAddr() net.Addr

func (*TcpConn) Read

func (this *TcpConn) Read(b []byte) (int, error)

func (*TcpConn) RemoteAddr

func (this *TcpConn) RemoteAddr() net.Addr

func (*TcpConn) SetDeadline

func (this *TcpConn) SetDeadline(t time.Time) error

func (*TcpConn) SetReadDeadline

func (this *TcpConn) SetReadDeadline(t time.Time) error

func (*TcpConn) SetWriteDeadline

func (this *TcpConn) SetWriteDeadline(t time.Time) error

func (*TcpConn) Write

func (this *TcpConn) Write(b []byte) (n int, err error)

type TcpServerComp

type TcpServerComp struct {
	cbase.ModuleCompBase

	NewTcpAgent func(gate IGateModule, coon IConn) (IAgent, error)
	// contains filtered or unexported fields
}

func (*TcpServerComp) Destroy

func (this *TcpServerComp) Destroy() (err error)

func (*TcpServerComp) Init

func (this *TcpServerComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error)

func (*TcpServerComp) Start

func (this *TcpServerComp) Start() (err error)

type WSHandler

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

func (*WSHandler) ServeHTTP

func (handler *WSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WsConn

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

func (*WsConn) Close

func (this *WsConn) Close()

func (*WsConn) Init

func (this *WsConn) Init(conn *websocket.Conn, heartbeat time.Duration)

func (*WsConn) LocalAddr

func (this *WsConn) LocalAddr() net.Addr

func (*WsConn) Read

func (this *WsConn) Read(p []byte) (int, error)

func (*WsConn) RemoteAddr

func (this *WsConn) RemoteAddr() net.Addr

func (*WsConn) SetDeadline

func (this *WsConn) SetDeadline(t time.Time) error

func (*WsConn) SetReadDeadline

func (this *WsConn) SetReadDeadline(t time.Time) error

func (*WsConn) SetWriteDeadline

func (this *WsConn) SetWriteDeadline(t time.Time) error

func (*WsConn) Write

func (this *WsConn) Write(b []byte) (n int, err error)

type WsServerComp

type WsServerComp struct {
	cbase.ModuleCompBase

	NewWsAgent func(gate IGateModule, coon IConn) (IAgent, error)
	// contains filtered or unexported fields
}

func (*WsServerComp) Destroy

func (this *WsServerComp) Destroy() (err error)

func (*WsServerComp) Init

func (this *WsServerComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error)

func (*WsServerComp) Start

func (this *WsServerComp) Start() (err error)

Jump to

Keyboard shortcuts

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