Documentation ¶
Index ¶
- Constants
- Variables
- func Backtrace(message interface{}, fp *os.File)
- func Catch()
- func DateTime() string
- func DecodeAsMsg(value interface{}, msg proto.Message) error
- func DecodeAsString(value interface{}) string
- func DecodeU32(data []byte) (uint32, error)
- func EncodeNumber(value interface{}, data []byte) []byte
- func EncodeValue(value interface{}) ([]byte, error)
- func GetServiceNames() []string
- func GetServiceTypeByName(name string) uint8
- func Now() time.Time
- func ReadFileOption(filename string, opts *Options) error
- func Register(service Service)
- func StartClock()
- func StopClock()
- func WallClock() *datetime.Clock
- type BasicRoutePolicy
- type CapturedRunnable
- type Codec
- type Endpoint
- type EndpointMap
- type Environ
- type Executor
- type MessageEndpoint
- type MessageSubscriber
- func (s *MessageSubscriber) AddSubNode(start, end int32, node NodeID)
- func (s *MessageSubscriber) DeleteNodeSubs(dest NodeID)
- func (s *MessageSubscriber) DeleteSubNode(start, end int32, node NodeID)
- func (s *MessageSubscriber) GetSubNodes(startMsg, endMsg int32) NodeIDSet
- func (s *MessageSubscriber) HasSubNodes(startMsg, endMsg int32) bool
- type MySQLConf
- type NodeID
- func (n NodeID) District() uint16
- func (n NodeID) Instance() uint8
- func (n NodeID) IsBackend() bool
- func (n NodeID) IsClient() bool
- func (n NodeID) Service() uint8
- func (n *NodeID) SetDistrict(v uint16)
- func (n *NodeID) SetInstance(v uint8)
- func (n *NodeID) SetService(v uint8)
- func (n NodeID) String() string
- type NodeIDSet
- type Options
- type Packet
- func (m *Packet) Ack(msgId int32, ack proto.Message) error
- func (m *Packet) Clone() *Packet
- func (m *Packet) DecodeAsString() string
- func (m *Packet) DecodeMsg(msg proto.Message) error
- func (m *Packet) Encode() ([]byte, error)
- func (m *Packet) Errno() uint32
- func (m *Packet) Refuse(command int32, errno uint32) error
- func (m *Packet) Reply(ack proto.Message) error
- func (m *Packet) ReplyAny(command uint32, data interface{}) error
- func (m *Packet) Reset()
- func (m *Packet) Run() error
- func (m *Packet) SetErrno(ec uint32)
- func (m Packet) String() string
- type PacketFilter
- type PacketHandler
- type PacketQueue
- type RoutePolicy
- type Router
- type RoutingTable
- type RoutingTableEntry
- type Runnable
- type Runner
- type Scheduler
- type Service
- type ServiceContext
- func (c *ServiceContext) AddFinalizer(finalizer func())
- func (c *ServiceContext) Env() *Environ
- func (c *ServiceContext) Go()
- func (c *ServiceContext) InboundQueue() chan<- *Packet
- func (c *ServiceContext) IsClosing() bool
- func (c *ServiceContext) Options() *Options
- func (c *ServiceContext) Router() *Router
- func (c *ServiceContext) SendMessage(pkt *Packet) error
- func (c *ServiceContext) Service() Service
- func (c *ServiceContext) SetMessageFilter(f PacketFilter) PacketFilter
- func (c *ServiceContext) Shutdown()
- func (c *ServiceContext) Start(srv Service) error
- type Stats
- type TimerHeap
- func (q TimerHeap) Empty() bool
- func (q TimerHeap) Len() int
- func (q TimerHeap) Less(i, j int) bool
- func (q TimerHeap) Peek() *TimerNode
- func (q *TimerHeap) Pop() interface{}
- func (q *TimerHeap) Push(x interface{})
- func (q TimerHeap) Swap(i, j int)
- func (q *TimerHeap) Update(item *TimerNode, priority int64)
- type TimerNode
Constants ¶
View Source
const ( StatCommit int = iota StatTimer StatExec StatError StatDropped NumStats )
View Source
const ( NodeServiceShift = 8 NodeServiceMask = 0xFFFF00FF NodeDistrictShift = 16 NodeDistrictMask = 0xF000FFFF NodeInstanceMask = 0xFFFFFF00 NodeTypeShift = 31 NodeTypeClient = NodeID(1 << NodeTypeShift) )
View Source
const ( PacketFlagError = 0x0100 PacketFlagRefer = 0x0200 PacketFlagRpc = 0x0400 PacketFlagJSONText = 0x0800 PacketFlagCompress = 0x0001 PacketFlagEncrypt = 0x0002 PacketFlagBitsMask = 0xFF00 // 低8位的标志用于传输处理,完成传输后需要清除,不能再返回给ack )
View Source
const ( TimerTickInterval = 10 // every 10ms a tick TimerChanCapacity = 256 // )
Variables ¶
View Source
var ( ErrExecutorClosed = errors.New("executor is closed") ErrExecutorBusy = errors.New("executor is busy") )
Functions ¶
func EncodeValue ¶
编码一个字符串、字节流、protobuf消息对象 编码后的字节用于传输,不能修改其内容
func StartClock ¶
func StartClock()
Types ¶
type BasicRoutePolicy ¶
type BasicRoutePolicy struct {
// contains filtered or unexported fields
}
func (*BasicRoutePolicy) IsLoopBack ¶
func (r *BasicRoutePolicy) IsLoopBack(router *Router, pkt *Packet) bool
type CapturedRunnable ¶
type CapturedRunnable struct {
F func() error
}
func (*CapturedRunnable) Run ¶
func (r *CapturedRunnable) Run() error
type Codec ¶
type Codec interface { Version() uint8 Clone() Codec SetSeqNo(seq uint16) SetEncryptKey(key, iv []byte) // 消息编解码 Decode(rd io.Reader, pkt *Packet) (int, error) Encode(pkt *Packet, buf *bytes.Buffer) error }
消息编码器
type Endpoint ¶
type Endpoint interface { MessageEndpoint RawConn() net.Conn Stats() *Stats Codec() Codec Go(write, read bool) SetUserData(interface{}) UserData() interface{} }
网络连接端点
type EndpointMap ¶
线程安全的endpoint map
func NewEndpointMap ¶
func NewEndpointMap() *EndpointMap
func (*EndpointMap) Add ¶
func (e *EndpointMap) Add(node NodeID, endpoint Endpoint)
func (*EndpointMap) Delete ¶
func (e *EndpointMap) Delete(node NodeID) bool
func (*EndpointMap) Get ¶
func (e *EndpointMap) Get(node NodeID) Endpoint
func (*EndpointMap) List ¶
func (e *EndpointMap) List() []Endpoint
func (*EndpointMap) Reset ¶
func (e *EndpointMap) Reset()
func (*EndpointMap) Size ¶
func (e *EndpointMap) Size() int
type Environ ¶
type Environ struct { DevelopMode bool // 测试/生产环境 GameID string // 游戏ID ChannelID string // 渠道ID ServerID string // 服务器ID ServerName string // 服务器名称 AccessKey string // MysqlDSN string // RedisAddr string // ExecutorCapacity int // ExecutorConcurrency int // ContextInboundQueueSize int // ContextOutboundQueueSize int // EndpointOutboundQueueSize int // NetEnableEncryption bool NetPublicKeyFile string // NetPrivateKeyFile string // NetPeerPingInterval int // NetPeerReadTimeout int // NetSessionReadTimeout int // NetRpcTimeoutInterval int // }
通用环境变量
func LoadEnviron ¶
func LoadEnviron() *Environ
func NewEnviron ¶
func NewEnviron() *Environ
type Executor ¶
type Executor struct { Scheduler // contains filtered or unexported fields }
Runner执行器
type MessageEndpoint ¶
type MessageEndpoint interface { NodeID() NodeID SetNodeID(NodeID) RemoteAddr() string // 发送消息 SendPacket(*Packet) error // 关闭读/写 Close() error ForceClose(error) IsClosing() bool Context() *ServiceContext SetContext(*ServiceContext) }
type MessageSubscriber ¶
消息订阅
func NewMessageSub ¶
func NewMessageSub() *MessageSubscriber
func (*MessageSubscriber) AddSubNode ¶
func (s *MessageSubscriber) AddSubNode(start, end int32, node NodeID)
func (*MessageSubscriber) DeleteNodeSubs ¶
func (s *MessageSubscriber) DeleteNodeSubs(dest NodeID)
func (*MessageSubscriber) DeleteSubNode ¶
func (s *MessageSubscriber) DeleteSubNode(start, end int32, node NodeID)
func (*MessageSubscriber) GetSubNodes ¶
func (s *MessageSubscriber) GetSubNodes(startMsg, endMsg int32) NodeIDSet
func (*MessageSubscriber) HasSubNodes ¶
func (s *MessageSubscriber) HasSubNodes(startMsg, endMsg int32) bool
type NodeID ¶
type NodeID uint32
func MakeNodeID ¶
func MakeSessionNodeID ¶
func MustParseNodeID ¶
func (*NodeID) SetDistrict ¶
func (*NodeID) SetInstance ¶
func (*NodeID) SetService ¶
type Options ¶
type Options struct { ShowVersion bool `short:"v" long:"version" description:"version string"` List bool `short:"l" long:"list" description:"list available services"` ConfigFile string `short:"C" long:"config" description:"load option from file"` EnvFile string `short:"E" long:"envfile" description:"dotenv file path"` WorkingDir string `short:"W" long:"workdir" description:"runtime working directory"` ResourceDir string `short:"R" long:"resdir" description:"resource directory"` ServiceType string `short:"S" long:"service-type" description:"name of service type"` ServiceIndex int `short:"N" long:"service-index" description:"instance index of this service"` ServiceDistrict int `short:"D" long:"service-district" description:"district of this service"` ServiceDependency string `short:"P" long:"dependency" description:"service dependency list"` IsCrossDistrict bool `short:"X" long:"cross-district" description:"serve all districts"` Interface string `short:"I" long:"interface" description:"service interface address"` LogLevel string `short:"L" long:"loglevel" description:"debug,info,warn,error,fatal,panic"` EtcdAddress string `short:"F" long:"etcd-addr" description:"etcd host address"` EtcdKeySpace string `short:"K" long:"keyspace" description:"etcd key prefix"` EtcdLeaseTTL int `long:"lease-ttl" description:"etcd lease key TTL"` PprofAddr string `long:"pprof-addr" description:"pprof http listen address"` EnableSysLog bool `long:"enable-syslog" description:"enable write log to syslog/eventlog"` SysLogParams string `long:"syslog-param" description:"syslog/eventlog parameters"` }
命令行选项参数
func NewOptions ¶
func NewOptions() *Options
type Packet ¶
type Packet struct { Command uint32 `json:"cmd"` // 消息ID Seq uint16 `json:"seq"` // 消息序列号 Flags uint16 `json:"flg,omitempty"` // 消息标记位 Referer uint32 `json:"ref,omitempty"` // 引用的client session Node NodeID `json:"node,omitempty"` // 目标节点 Body interface{} `json:"body,omitempty"` // 消息内容,integer/bytes/string/pb.Message Endpoint MessageEndpoint `json:"-"` // 关联的endpoint }
应用层消息
func MakePacket ¶
func MakePacket() *Packet
type PacketFilter ¶
type PacketHandler ¶
type PacketQueue ¶
type PacketQueue struct { C chan struct{} // notify channel // contains filtered or unexported fields }
A memory-bound packet queue
func NewMessageQueue ¶
func NewMessageQueue() *PacketQueue
func (*PacketQueue) Len ¶
func (q *PacketQueue) Len() int
func (*PacketQueue) Notify ¶
func (q *PacketQueue) Notify()
func (*PacketQueue) Peek ¶
func (q *PacketQueue) Peek() *Packet
func (*PacketQueue) Pop ¶
func (q *PacketQueue) Pop() *Packet
func (*PacketQueue) Push ¶
func (q *PacketQueue) Push(v *Packet)
type RoutePolicy ¶
type RoutePolicy interface { IsLoopBack(*Router, *Packet) bool Multicast(*Router, *Packet) bool Lookup(*Router, *Packet) Endpoint }
路由策略
func NewBasicRoutePolicy ¶
func NewBasicRoutePolicy(endpoints *EndpointMap) RoutePolicy
type Router ¶
type Router struct { *MessageSubscriber // 消息订阅 *RoutingTable // 路由表 // contains filtered or unexported fields }
路由器
func (*Router) AddPolicy ¶
func (r *Router) AddPolicy(policy RoutePolicy)
func (*Router) IsLoopBack ¶
type RoutingTable ¶
func NewRoutingTable ¶
func NewRoutingTable() *RoutingTable
func (*RoutingTable) AddEntry ¶
func (r *RoutingTable) AddEntry(src, dst NodeID)
func (*RoutingTable) DeleteDestEntry ¶
func (r *RoutingTable) DeleteDestEntry(dest NodeID)
func (*RoutingTable) DeleteEntry ¶
func (r *RoutingTable) DeleteEntry(src NodeID)
func (*RoutingTable) EntryList ¶
func (r *RoutingTable) EntryList() []RoutingTableEntry
func (*RoutingTable) GetEntry ¶
func (r *RoutingTable) GetEntry(key NodeID) NodeID
type RoutingTableEntry ¶
type RoutingTableEntry struct {
// contains filtered or unexported fields
}
路由表
type Scheduler ¶
type Scheduler struct { C chan *TimerNode // 到期的定时器 // contains filtered or unexported fields }
type Service ¶
type Service interface { ID() uint8 Name() string NodeID() NodeID SetNodeID(NodeID) // 初始化、启动和关闭 Init(*ServiceContext) error Startup() error Shutdown() // 服务上下文 Context() *ServiceContext // 执行 Execute(Runner) error Dispatch(*Packet) error }
服务
type ServiceContext ¶
type ServiceContext struct {
// contains filtered or unexported fields
}
服务的上下文
func NewServiceContext ¶
func NewServiceContext(opt *Options, env *Environ) *ServiceContext
func (*ServiceContext) AddFinalizer ¶
func (c *ServiceContext) AddFinalizer(finalizer func())
func (*ServiceContext) Env ¶
func (c *ServiceContext) Env() *Environ
func (*ServiceContext) Go ¶
func (c *ServiceContext) Go()
func (*ServiceContext) InboundQueue ¶
func (c *ServiceContext) InboundQueue() chan<- *Packet
func (*ServiceContext) IsClosing ¶
func (c *ServiceContext) IsClosing() bool
func (*ServiceContext) Options ¶
func (c *ServiceContext) Options() *Options
func (*ServiceContext) Router ¶
func (c *ServiceContext) Router() *Router
func (*ServiceContext) SendMessage ¶
func (c *ServiceContext) SendMessage(pkt *Packet) error
func (*ServiceContext) Service ¶
func (c *ServiceContext) Service() Service
func (*ServiceContext) SetMessageFilter ¶
func (c *ServiceContext) SetMessageFilter(f PacketFilter) PacketFilter
func (*ServiceContext) Shutdown ¶
func (c *ServiceContext) Shutdown()
func (*ServiceContext) Start ¶
func (c *ServiceContext) Start(srv Service) error
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
This package provides immutable UUID structs and the functions NewV3, NewV4, NewV5 and Parse() for generating versions 3, 4 and 5 UUIDs as specified in RFC 4122.
|
This package provides immutable UUID structs and the functions NewV3, NewV4, NewV5 and Parse() for generating versions 3, 4 and 5 UUIDs as specified in RFC 4122. |
x
|
|
Click to show internal directories.
Click to hide internal directories.