engine

package
v0.0.0-...-58a2b35 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 30 Imported by: 0

README

engine

Documentation

Overview

Package log provides 全局日志记录,内部使用beego/log

Index

Constants

View Source
const (
	SendQueueCacheNum = 100000
	MSGID_heartbeat   = 0 //心跳连接

	MaxSendQueueDealCnt      = 20     // 同时处理协程数量
	MaxQueue                 = 100000 //伸缩发送队列最大长度
	AreaNameResult_same      = 1      //相同
	AreaNameResult_different = 2      //不同
	MaxRetryCnt              = 2      //发送最大重试次数
)
View Source
const (
	AddressUp   = "up"       //addSession方法添加upSession标识
	AddressDown = "down"     //addSession方法添加downSession标识
	BothMod     = "both"     //AddClientConn方法全规则添加模式
	OnebyoneMod = "onebyone" //AddClientConn方法onebyone规则添加模式
	KadMod      = "kad"      //AddClientConn方法kad规则添加模式
	VnodeMod    = "vnode"    //AddClientConn方法vnode规则添加模式
)
View Source
const (
	CONN_TYPE_TCP  = 0 // tcp连接
	CONN_TYPE_QUIC = 1 // quic连接
)
View Source
const (
	LOG_default          = 0 //
	LOG_console          = 1 //打印到控制台
	LOG_file             = 2 //打印到文件
	LOG_console_and_file = 3 //同时打印到控制台和文件

)

Variables

View Source
var (
	ERROR_send_cache_full  = errors.New("send cache full error") //发送队列满了
	ERROR_send_cache_close = errors.New("send cache close")      //发送队列关闭
	ERROR_send_timeout     = errors.New("send timeout error")    //发送超时
	Error_different_netid  = errors.New("netid different")       //
	Error_node_unwanted    = errors.New("node unwante")          //不需要的节点
	SendTimeOut            = time.Second * 10                    //默认超时时间
)
"github.com/astaxie/beego/logs"

) beego Log

Functions

func AddRuntime

func AddRuntime(file string, line int, goroutineId string)

func CatchPanic

func CatchPanic()

* 错误处理 * 捕获后不打印相关堆栈信息

func DelRuntime

func DelRuntime(file string, line int, goroutineId string)

func GetRandNum

func GetRandNum(n int64) int64

获得一个随机数(0 - n],包含0,不包含n

func GetRandomDomain

func GetRandomDomain() string

随机获取一个域名

func GlobalInit

func GlobalInit(kind, path, level string, length int) error

func InitRuntimeMap

func InitRuntimeMap()

func MarshalPacket

func MarshalPacket(msgID uint64, data, dataplus *[]byte) (*[]byte, error)

func NewSessionStore

func NewSessionStore() *sessionStore

func PrintPanicStack

func PrintPanicStack()

错误处理

func ReadFull

func ReadFull(length int, conn net.Conn) ([]byte, error)

func ReadQuicFull

func ReadQuicFull(length int, conn quic.Stream) ([]byte, error)

func SetLogPath

func SetLogPath(logPath string)

func TimeFormatToNanosecondStr

func TimeFormatToNanosecondStr() string

Types

type AddressNet

type AddressNet []byte

节点地址

func AddressFromB58String

func AddressFromB58String(str string) AddressNet

func BuildAddr

func BuildAddr(pubKey []byte) AddressNet

通过公钥生成网络节点地址,将公钥两次hash得到网络节点地址 @version []byte 版本号(如比特币主网版本号“0x00")

func (*AddressNet) B58String

func (this *AddressNet) B58String() string

type Auth

type Auth interface {
	SendKey(conn net.Conn, session Session, name string, setGodAddr bool) (remoteName, machineID string, setGodTime int64, params interface{}, connectKey string, err error)
	RecvKey(conn net.Conn, name string) (remoteName, machineID string, setGodTime int64, params interface{}, connectKey string, err error)
	GetAreaName() (areaName string)
	SendQuicKey(conn quic.Connection, stream quic.Stream, session Session, name string, setGodAddr bool) (remoteName, machineID string, setGodTime int64, params interface{}, connectKey string, err error)
	RecvQuicKey(conn quic.Connection, stream quic.Stream, name string) (remoteName, machineID string, setGodTime int64, params interface{}, connectKey string, err error)
}

type Client

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

本机向其他服务器的连接

func NewClient

func NewClient(areaName []byte, name, ip string, port uint32) *Client

func (*Client) Close

func (this *Client) Close()

客户端关闭时,退出recv,send

func (*Client) Connect

func (this *Client) Connect(ip string, port uint32) (remoteName string, params interface{}, connectKey string, err error)

func (*Client) Get

func (this *Client) Get(name string) interface{}

func (*Client) GetAreaName

func (this *Client) GetAreaName() string

* GetAreaName 获取区域名称 * * @return areaName string 区域名称

func (Client) GetConnType

func (this Client) GetConnType() string

func (*Client) GetIndex

func (this *Client) GetIndex() uint64

func (*Client) GetMachineID

func (this *Client) GetMachineID() string

获取节点机器Id

func (*Client) GetName

func (this *Client) GetName() string

func (*Client) GetRemoteHost

func (this *Client) GetRemoteHost() string

获取远程ip地址和端口

func (*Client) GetSetGodTime

func (this *Client) GetSetGodTime() int64

* GetSetGodTime 获取设置超级代理的时间 * * @return setGodTime int64 设置超级代理的时间

func (*Client) Send

func (this *Client) Send(msgID uint64, data, dataplus *[]byte, timeout time.Duration) error

发送序列化后的数据

func (*Client) Set

func (this *Client) Set(name string, value interface{})

func (*Client) SetName

func (this *Client) SetName(name string)

func (*Client) SetTryIsClose

func (this *Client) SetTryIsClose(isClose bool) bool

尝试设置为是否关闭 @return bool 是否设置成功

type ClientNewConnCallback

type ClientNewConnCallback func(ss Session, params interface{}) error

客户端有新连接,触发的回调方法

type ClientQuic

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

本机向其他服务器的连接

func NewClientQuic

func NewClientQuic(areaName []byte, name, ip string, port uint32) *ClientQuic

func (*ClientQuic) Close

func (this *ClientQuic) Close()

客户端关闭时,退出recv,send

func (*ClientQuic) Connect

func (this *ClientQuic) Connect(ip string, port uint32) (remoteName string, params interface{}, connectKey string, err error)

func (*ClientQuic) Get

func (this *ClientQuic) Get(name string) interface{}

func (*ClientQuic) GetAreaName

func (this *ClientQuic) GetAreaName() string

* GetAreaName 获取区域名称 * * @return areaName string 区域名称

func (ClientQuic) GetConnType

func (this ClientQuic) GetConnType() string

func (*ClientQuic) GetIndex

func (this *ClientQuic) GetIndex() uint64

func (*ClientQuic) GetMachineID

func (this *ClientQuic) GetMachineID() string

获取节点机器Id

func (*ClientQuic) GetName

func (this *ClientQuic) GetName() string

func (*ClientQuic) GetRemoteHost

func (this *ClientQuic) GetRemoteHost() string

获取远程ip地址和端口

func (*ClientQuic) GetSetGodTime

func (this *ClientQuic) GetSetGodTime() int64

* GetSetGodTime 获取设置超级代理的时间 * * @return setGodTime int64 设置超级代理的时间

func (*ClientQuic) Send

func (this *ClientQuic) Send(msgID uint64, data, dataplus *[]byte, timeout time.Duration) error

发送序列化后的数据

func (*ClientQuic) Set

func (this *ClientQuic) Set(name string, value interface{})

func (*ClientQuic) SetName

func (this *ClientQuic) SetName(name string)

func (*ClientQuic) SetTryIsClose

func (this *ClientQuic) SetTryIsClose(isClose bool) bool

尝试设置为是否关闭 @return bool 是否设置成功

type CloseCallback

type CloseCallback func(ss Session)

关闭连接回调接口

type Controller

type Controller interface {
	GetSession(areaName []byte, name string) (Session, bool) //通过accId得到客户端的连接Id
	GetNet() *Engine                                         //获得连接到本地的计算机连接
	SetAttribute(name string, value interface{})             //设置共享数据,实现业务模块之间通信
	GetAttribute(name string) interface{}                    //得到共享数据,实现业务模块之间通信

}

type ControllerImpl

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

func (*ControllerImpl) GetAttribute

func (this *ControllerImpl) GetAttribute(name string) interface{}

func (*ControllerImpl) GetNet

func (this *ControllerImpl) GetNet() *Engine

得到net模块,用于给用户发送消息

func (*ControllerImpl) GetSession

func (this *ControllerImpl) GetSession(areaName []byte, name string) (Session, bool)

func (*ControllerImpl) SetAttribute

func (this *ControllerImpl) SetAttribute(name string, value interface{})

type Engine

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

不能设置handler运行总量,不能容忍业务阻塞,所以用户自己去处理

func NewEngine

func NewEngine(name string) *Engine

@name 本服务器名称

func (*Engine) AddAuth

func (this *Engine) AddAuth(auth Auth)

添加自定义权限验证

func (*Engine) AddClientConn

func (this *Engine) AddClientConn(areaName []byte, ip string, port uint32, powerful bool, onlyAddOneSess string) (ss Session, err error)

添加一个连接,给这个连接取一个名字,连接名字可以在自定义权限验证方法里面修改 @powerful 是否是强连接 @return name 对方的名称

func (*Engine) AddClientQuicConn

func (this *Engine) AddClientQuicConn(areaName []byte, ip string, port uint32, powerful bool, onlyAddOneSess string) (ss Session, err error)

添加一个Quic连接,给这个连接取一个名字,连接名字可以在自定义权限验证方法里面修改 @powerful 是否是强连接 @return name 对方的名称

func (*Engine) AddConnectBySessionAndNode

func (this *Engine) AddConnectBySessionAndNode(areaName []byte, clientConn *Client, params interface{})

* 根据客户端连接session,和节点信息,建立连接处理 * @param clientConn 客户端连接session * @param params 连接的节点信息

func (*Engine) AddDownSession

func (this *Engine) AddDownSession(areaName []byte, ss Session)

* downSession中添加session

func (*Engine) AddInterceptor

func (this *Engine) AddInterceptor(itpr Interceptor)

添加一个拦截器,所有消息到达业务方法之前都要经过拦截器处理

func (*Engine) AddOnlyConnect

func (this *Engine) AddOnlyConnect(ss []string)

* 白名单传递给Engine

func (*Engine) AddQuicConnectBySessionAndNode

func (this *Engine) AddQuicConnectBySessionAndNode(areaName []byte, clientConn *ClientQuic, params interface{})

* 根据客户端连接session,和节点信息,建立连接处理 * @param clientConn 客户端连接session * @param params 连接的节点信息

func (*Engine) AddUpSession

func (this *Engine) AddUpSession(areaName []byte, ss Session)

* upSession中添加session

func (*Engine) CheckInSessionByIndex

func (this *Engine) CheckInSessionByIndex(ss Session) bool

* 检查是否存在特定session

func (*Engine) CompareAddressNet

func (this *Engine) CompareAddressNet(node AddressNet) bool

自己比传入地址大 true 传入地址比自己大 false

func (*Engine) DelNodeDownSession

func (this *Engine) DelNodeDownSession(areaName []byte, ss Session)

* 删除downSession中某个特定session

func (*Engine) DelNodeUpSession

func (this *Engine) DelNodeUpSession(areaName []byte, ss Session)

* 删除upSession中某个特定session

func (*Engine) DeleteConnecting

func (this *Engine) DeleteConnecting(name string)

* 直接删除正在处于连接状态中的地址

func (*Engine) DelyDeleteConnecting

func (this *Engine) DelyDeleteConnecting(name string)

* 延迟一秒删除正在处于连接状态中的地址

func (*Engine) Destroy

func (this *Engine) Destroy(areaName []byte)

* 销毁,断开连接,关闭监听 * * @param areaName []byte 区域名

func (*Engine) GetAllDownSession

func (this *Engine) GetAllDownSession(areaName []byte) []Session

* 获取本节点所有downSession

func (*Engine) GetAllDownUp

func (this *Engine) GetAllDownUp(areaName []byte) []string

* 获取本节点所有downSession 和 upSession

func (*Engine) GetAllSession

func (this *Engine) GetAllSession(areaName []byte) []Session

* 获取区域名的所有session

func (*Engine) GetAllUpSession

func (this *Engine) GetAllUpSession(areaName []byte) []Session

* 获取本节点所有upSession

func (*Engine) GetAuth

func (this *Engine) GetAuth(areaName string) (auth Auth, exist bool)

* GetAuth 获取区域对应的区域信息管理器 * * @param areaName string 区域名称 * @return auth Auth 区域信息管理器 * @return exist bool 是否存在回调标识

func (*Engine) GetClientConnCallback

func (this *Engine) GetClientConnCallback(areaName string) (callback ClientNewConnCallback, exist bool)

* GetClientConnCallback 获取区域对应的客户端端连接回调方法 * * @param areaName string 区域名称 * @return closeCallback ClientNewConnCallback 回调方法 * @return exist bool 是否存在回调标识

func (*Engine) GetCloseCallback

func (this *Engine) GetCloseCallback(areaName string) (callback CloseCallback, exist bool)

* GetCloseCallback 获取区域对应的关闭回调方法 * * @param areaName string 区域名称 * @return call CloseCallback 关闭回调方法 * @return exist bool 是否存在回调标识

func (*Engine) GetConnectInfoByIpAddr

func (this *Engine) GetConnectInfoByIpAddr(areaName []byte, ip string, port uint32) (ss *Client, node interface{}, err error)

* 根据ip地址及端口,获取连接session及node信息 * @param ip ip地址 * @param port 端口 * @param setGodAddr 是否设置对方为自己的上帝节点 * @return ss 连接session * @return node 连接节点node * @return err 是否发生错误

func (*Engine) GetGodAddr

func (this *Engine) GetGodAddr(areaName []byte) (ip string, port uint16)

* 获取当前上帝节点地址 * * @auth qlw * @param areaName []byte 区域名称 * @return ip string ip地址 * @return port uint16 端口

func (*Engine) GetOnlyConnectNum

func (this *Engine) GetOnlyConnectNum() int

* 获取配置的只连节点数量

func (*Engine) GetQuicConnectInfoByIpAddr

func (this *Engine) GetQuicConnectInfoByIpAddr(areaName []byte, ip string, port uint32) (ss *ClientQuic, node interface{}, err error)

* 根据ip地址及端口,获取Quic连接session及node信息 * @param ip ip地址 * @param port 端口 * @param setGodAddr 是否设置对方为自己的上帝节点 * @return ss 连接session * @return node 连接节点node * @return err 是否发生错误

func (*Engine) GetServerConnCallback

func (this *Engine) GetServerConnCallback(areaName string) (callback ServerNewConnCallback, exist bool)

* GetServerConnCallback 获取区域对应的服务端连接回调方法 * * @param areaName string 区域名称 * @return closeCallback ServerNewConnCallback 回调方法 * @return exist bool 是否存在回调标识

func (*Engine) GetSession

func (this *Engine) GetSession(areaName []byte, name string) (Session, bool)

获得session

func (*Engine) GetSessionAll

func (this *Engine) GetSessionAll(areaName []byte, name string) ([]Session, bool)

获得某个地址所有session

func (*Engine) GetSessionCnt

func (this *Engine) GetSessionCnt(areaName []byte) int64

* 获取本节点session总数

func (*Engine) GetSortSessionByKey

func (this *Engine) GetSortSessionByKey(key string) ([]AddressNet, bool)

* 通过字符串获取排序好的网络地址数组

func (*Engine) GetTcpHost

func (this *Engine) GetTcpHost() (string, uint16)

获取监听地址和端口 格式:0.0.0.0:8888

func (*Engine) IsNodeUpdownSess

func (this *Engine) IsNodeUpdownSess(areaName []byte, addr AddressNet) bool

真实节点onebyone规则连接,up和down地址

func (*Engine) Listen

func (this *Engine) Listen(ip string, port uint32, async bool) error

func (*Engine) ListenByListener

func (this *Engine) ListenByListener(listener *net.TCPListener, async bool) error

func (*Engine) ListenQuic

func (this *Engine) ListenQuic(ip string, port uint32, async bool) error

* 监听quic信息

func (*Engine) LoadOrStoreConnecting

func (this *Engine) LoadOrStoreConnecting(name string) bool

* 加载并保存到正处于连接状态的地址 * 返回 true map中存在 * 返回 false map中不存在并保存

func (*Engine) Recovery

func (this *Engine) Recovery()

恢复服务器

func (*Engine) RecvKey

func (this *Engine) RecvKey(conn net.Conn, name string) (remoteName, machineID, remoteAreaName string, setGodTime int64, params interface{}, connectKey string, err error)

* RecvKey 接收信息 * * @param conn Conn tcp连接 * @param name string 自己节点id * @return remoteName string 对方节点id * @return params interface 对方节点信息 * @return err error 错误信息 * @return remoteAreaName string 对方的域名,主要用于当本地启动了多个area时,根据域名来查找对应的回调

func (*Engine) RecvQuicKey

func (this *Engine) RecvQuicKey(conn quic.Connection, stream quic.Stream, name string) (remoteName, machineID, remoteAreaName string, setGodTime int64, params interface{}, connectKey string, err error)

* RecvQuicKey 接收信息 * * @param conn Conn tcp连接 * @param name string 自己节点id * @return remoteName string 对方节点id * @return params interface 对方节点信息 * @return err error 错误信息 * @return remoteAreaName string 对方的域名,主要用于当本地启动了多个area时,根据域名来查找对应的回调

func (*Engine) RegisterMsg

func (this *Engine) RegisterMsg(areaName []byte, msgId uint64, handler MsgHandler)

注册一个普通消息

func (*Engine) RemoveCustomSession

func (this *Engine) RemoveCustomSession(ss Session)

* 删除customNameStore中特定session

func (*Engine) RemoveSession

func (this *Engine) RemoveSession(areaName []byte, ss Session)

* 删除sessionStore中特定session

func (*Engine) SetClientConnCallback

func (this *Engine) SetClientConnCallback(areaName []byte, call ClientNewConnCallback)

设置客户端新连接的回调方法

func (*Engine) SetCloseCallback

func (this *Engine) SetCloseCallback(areaName []byte, call CloseCallback)

设置关闭连接回调方法

func (*Engine) SetGodAddr

func (this *Engine) SetGodAddr(areaName []byte, ip string, port uint16)

* 设置上帝节点地址 * * @auth qlw * @param ip string ip地址 * @param port uint16 端口

func (*Engine) SetServerConnCallback

func (this *Engine) SetServerConnCallback(areaName []byte, call ServerNewConnCallback)

* 设置服务器有新连接的回调方法

func (*Engine) SetSortSessionByKey

func (this *Engine) SetSortSessionByKey(key string, addrs []AddressNet)

* 使用字符串作为key存储排序好的地址数组

func (*Engine) StoreConnecting

func (this *Engine) StoreConnecting(name string)

* 保存正在连接状态的地址

func (*Engine) Suspend

func (this *Engine) Suspend()

暂停服务器

type GetPacket

type GetPacket func(cache *[]byte, index *uint32) (packet *Packet, n int)

type GetPacketBytes

type GetPacketBytes func(msgID, opt, errcode uint32, cryKey []byte, data *[]byte) *[]byte

type GodAddrInfo

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

* GodAddrInfo 上帝地址信息

type Interceptor

type Interceptor interface {
	In(c Controller, msg Packet) bool
	Out(c Controller, msg Packet)
}

type InterceptorProvider

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

func NewInterceptor

func NewInterceptor() *InterceptorProvider

type LogOne

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

type LogQueue

type LogQueue struct {
	// contains filtered or unexported fields
}
var NLog *LogQueue = NewLog(LOG_console, "log.txt")

func NewLog

func NewLog(t int, filepath string) *LogQueue

func (*LogQueue) Debug

func (this *LogQueue) Debug(t int, format string, str ...interface{})

@t int 打印日志类型,0=系统默认类型

func (*LogQueue) Error

func (this *LogQueue) Error(t int, format string, str ...interface{})

@t int 打印日志类型,0=系统默认类型

func (*LogQueue) Info

func (this *LogQueue) Info(t int, format string, str ...interface{})

@t int 打印日志类型,0=系统默认类型

type MsgHandler

type MsgHandler func(c Controller, msg Packet)

type NoneAuth

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

func (*NoneAuth) RecvKey

func (this *NoneAuth) RecvKey(conn net.Conn, name string) (remoteName, machineID string, setGodTime int64, params interface{}, err error)

接收 @name 本机服务器的名称 @return remoteName 对方服务器的名称

func (*NoneAuth) SendKey

func (this *NoneAuth) SendKey(conn net.Conn, session Session, name string, setGodAddr bool) (remoteName, machineID string, setGodTime int64, params interface{}, err error)

发送 @name 本机服务器的名称 @setGodAddr 是否设置对方为自己的上帝节点标识 @return remoteName 对方服务器的名称

type Packet

type Packet struct {
	MsgID    uint64 //
	Size     uint64 //数据包长度,包含头部4字节
	Data     []byte
	Dataplus []byte //未加密部分数据分开
	Session  Session
}

func RecvPackage

func RecvPackage(conn net.Conn) (*Packet, error)

系统默认的消息接收并转化为Packet的方法 一个packet包括包头和包体,保证在接收到包头后两秒钟内接收到包体,否则线程会一直阻塞 因此,引入了超时机制

func RecvQuicPackage

func RecvQuicPackage(stream quic.Stream) (*Packet, error)

系统默认的消息接收并转化为Packet的方法 一个packet包括包头和包体,保证在接收到包头后两秒钟内接收到包体,否则线程会一直阻塞 因此,引入了超时机制

type Router

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

func NewRouter

func NewRouter() *Router

func (*Router) AddRouter

func (this *Router) AddRouter(areaName []byte, msgId uint64, handler MsgHandler)

* AddRouter 添加引擎路由 * * @param areaName []byte 区域名称 * @param msgId uint64 消息id *

func (*Router) GetHandler

func (this *Router) GetHandler(areaName string, msgId uint64) MsgHandler

* GetHandler 根据区域名和消息号获取回调方法 * * @param areaName string 区域名 * @param msgId uint64 消息号 * @return handler MsgHandler 回调方法

func (*Router) RemoveHandlers

func (this *Router) RemoveHandlers(areaName string)

* RemoveHandlers 移除区域名对应的所有消息号回调方法 * * @param areaName string 区域名

type SendPacket

type SendPacket struct {
	ID uint64 //
	// contains filtered or unexported fields
}

type SendQueue

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

func NewSendQueue

func NewSendQueue(cache uint64, c context.Context, cance context.CancelFunc, name string) *SendQueue

func (*SendQueue) AddAndWaitTimeout

func (this *SendQueue) AddAndWaitTimeout(bs *[]byte, timeout time.Duration) error

添加

func (*SendQueue) Destroy

func (this *SendQueue) Destroy()

设置返回

func (*SendQueue) GetQueueChan

func (this *SendQueue) GetQueueChan() <-chan *SendPacket

func (*SendQueue) SetResult

func (this *SendQueue) SetResult(id uint64, err error)

设置返回

type ServerConn

type ServerConn struct {
	Ip             string //
	Connected_time string //
	CloseTime      string //
	// contains filtered or unexported fields
}

其他计算机对本机的连接

func (*ServerConn) Close

func (this *ServerConn) Close()

关闭这个连接

func (*ServerConn) Get

func (this *ServerConn) Get(name string) interface{}

func (*ServerConn) GetAreaName

func (this *ServerConn) GetAreaName() string

* GetAreaName 获取区域名称 * * @return areaName string 区域名称

func (ServerConn) GetConnType

func (this ServerConn) GetConnType() string

func (*ServerConn) GetIndex

func (this *ServerConn) GetIndex() uint64

func (*ServerConn) GetMachineID

func (this *ServerConn) GetMachineID() string

获取节点机器Id

func (*ServerConn) GetName

func (this *ServerConn) GetName() string

func (*ServerConn) GetRemoteHost

func (this *ServerConn) GetRemoteHost() string

获取远程ip地址和端口

func (*ServerConn) GetSetGodTime

func (this *ServerConn) GetSetGodTime() int64

* GetSetGodTime 获取设置超级代理的时间 * * @return setGodTime int64 设置超级代理的时间

func (*ServerConn) Send

func (this *ServerConn) Send(msgID uint64, data, dataplus *[]byte, timeout time.Duration) error

发送序列化后的数据

func (*ServerConn) SendJSON

func (this *ServerConn) SendJSON(msgID uint64, data interface{}, waite bool) error

给客户端发送数据

func (*ServerConn) SendOld

func (this *ServerConn) SendOld(msgID uint64, data, dataplus *[]byte, waite bool) error

给客户端发送数据

func (*ServerConn) Set

func (this *ServerConn) Set(name string, value interface{})

func (*ServerConn) SetName

func (this *ServerConn) SetName(name string)

func (*ServerConn) SetTryIsClose

func (this *ServerConn) SetTryIsClose(isClose bool) bool

尝试设置为是否关闭 @return bool 是否设置成功

type ServerNewConnCallback

type ServerNewConnCallback func(ss Session, params interface{}) error

服务器有新连接,触发的回调方法

type ServerQuicConn

type ServerQuicConn struct {
	Ip             string //
	Connected_time string //
	CloseTime      string //
	// contains filtered or unexported fields
}

其他计算机对本机的连接

func (*ServerQuicConn) Close

func (this *ServerQuicConn) Close()

关闭这个连接

func (*ServerQuicConn) Get

func (this *ServerQuicConn) Get(name string) interface{}

func (*ServerQuicConn) GetAreaName

func (this *ServerQuicConn) GetAreaName() string

* GetAreaName 获取区域名称 * * @return areaName string 区域名称

func (ServerQuicConn) GetConnType

func (this ServerQuicConn) GetConnType() string

func (*ServerQuicConn) GetIndex

func (this *ServerQuicConn) GetIndex() uint64

func (*ServerQuicConn) GetMachineID

func (this *ServerQuicConn) GetMachineID() string

获取节点机器Id

func (*ServerQuicConn) GetName

func (this *ServerQuicConn) GetName() string

func (*ServerQuicConn) GetRemoteHost

func (this *ServerQuicConn) GetRemoteHost() string

获取远程ip地址和端口

func (*ServerQuicConn) GetSetGodTime

func (this *ServerQuicConn) GetSetGodTime() int64

* GetSetGodTime 获取设置超级代理的时间 * * @return setGodTime int64 设置超级代理的时间

func (*ServerQuicConn) Send

func (this *ServerQuicConn) Send(msgID uint64, data, dataplus *[]byte, timeout time.Duration) error

发送序列化后的数据

func (*ServerQuicConn) SendJSON

func (this *ServerQuicConn) SendJSON(msgID uint64, data interface{}, waite bool) error

给客户端发送数据

func (*ServerQuicConn) Set

func (this *ServerQuicConn) Set(name string, value interface{})

func (*ServerQuicConn) SetName

func (this *ServerQuicConn) SetName(name string)

func (*ServerQuicConn) SetTryIsClose

func (this *ServerQuicConn) SetTryIsClose(isClose bool) bool

尝试设置为是否关闭 @return bool 是否设置成功

type Session

type Session interface {
	GetIndex() uint64
	Send(msgID uint64, data, datapuls *[]byte, timeout time.Duration) error
	Close()
	Set(name string, value interface{})
	Get(name string) interface{}
	GetName() string
	SetName(name string)
	GetRemoteHost() string
	GetMachineID() string
	GetAreaName() string
	GetSetGodTime() int64
	GetConnType() string
}

type TimeOut

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

func NewTimeOut

func NewTimeOut(f func()) *TimeOut

func (*TimeOut) Do

func (this *TimeOut) Do(duration time.Duration) bool

Directories

Path Synopsis
Package crypto provides aes 加解密
Package crypto provides aes 加解密
protobuf

Jump to

Keyboard shortcuts

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