server

package
v0.0.0-...-83adff0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: GPL-3.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// server
	ErrHandshake = errors.New("handshake failed")
	ErrOperation = errors.New("request operation not valid")
	// ring
	ErrRingEmpty = errors.New("ring buffer empty")
	ErrRingFull  = errors.New("ring buffer full")
	// timer
	ErrTimerFull   = errors.New("timer full")
	ErrTimerEmpty  = errors.New("timer empty")
	ErrTimerNoItem = errors.New("timer item not exist")
	// channel
	ErrPushMsgArg   = errors.New("rpc pushmsg arg error")
	ErrPushMsgsArg  = errors.New("rpc pushmsgs arg error")
	ErrMPushMsgArg  = errors.New("rpc mpushmsg arg error")
	ErrMPushMsgsArg = errors.New("rpc mpushmsgs arg error")
	// bucket
	ErrBroadCastArg     = errors.New("rpc broadcast arg error")
	ErrBroadCastRoomArg = errors.New("rpc broadcast  room arg error")

	// room
	ErrRoomDroped = errors.New("room droped")
	// rpc
	ErrLogic = errors.New("logic rpc is not available")
)

.

Functions

func InitTCP

func InitTCP(server *Server, addrs []string, accept int) (err error)

InitTCP listen all tcp.bind and start accept connections.

func InitTCPV1

func InitTCPV1(server *Server, addrs []string, accept int) (err error)

InitTCPV1 listen all tcp.bind and start accept connections.

func InitWebsocket

func InitWebsocket(server *Server, addrs []string, accept int) (err error)

InitWebsocket listen all tcp.bind and start accept connections.

func InitWebsocketV1

func InitWebsocketV1(s *Server, addrs []string, accept int) (err error)

InitWebsocketV1 listen all tcp.bind and start accept connections.

func InitWebsocketWithTLS

func InitWebsocketWithTLS(server *Server, addrs []string, certFile, privateFile string, accept int) (err error)

InitWebsocketWithTLS init websocket with tls.

func InitWebsocketWithTLSV1

func InitWebsocketWithTLSV1(s *Server, addrs []string, certFile, privateFile string, accept int) (err error)

InitWebsocketWithTLSV1 .

func InitWhitelist

func InitWhitelist(c *conf.Whitelist) (err error)

InitWhitelist a whitelist struct.

Types

type Bucket

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

Bucket is a channel holder.

func NewBucket

func NewBucket(c *conf.Bucket) (b *Bucket)

NewBucket new a bucket struct. store the key with im channel.

func (*Bucket) Broadcast

func (b *Bucket) Broadcast(p *model.Proto, op int32, platform string)

Broadcast push msgs to all channels in the bucket.

func (*Bucket) BroadcastRoom

func (b *Bucket) BroadcastRoom(arg ProtoRoom)

BroadcastRoom broadcast a message to specified room

func (*Bucket) ChangeRoom

func (b *Bucket) ChangeRoom(nrid string, ch *Channel) (err error)

ChangeRoom change ro room

func (*Bucket) Channel

func (b *Bucket) Channel(key string) (ch *Channel)

Channel get a channel by sub key.

func (*Bucket) ChannelCount

func (b *Bucket) ChannelCount() int

ChannelCount channel count in the bucket

func (*Bucket) Del

func (b *Bucket) Del(dch *Channel)

Del delete the channel by sub key.

func (*Bucket) DelRoom

func (b *Bucket) DelRoom(room *Room)

DelRoom delete a room by roomid.

func (*Bucket) IPCount

func (b *Bucket) IPCount() (res map[string]struct{})

IPCount get ip count.

func (*Bucket) Put

func (b *Bucket) Put(rid string, ch *Channel) (err error)

Put put a channel according with sub key.

func (*Bucket) Room

func (b *Bucket) Room(rid string) (room *Room)

Room get a room by roomid.

func (*Bucket) RoomCount

func (b *Bucket) RoomCount() int

RoomCount room count in the bucket

func (*Bucket) RoomIPCount

func (b *Bucket) RoomIPCount() (res map[string]struct{})

RoomIPCount get ip count.

func (*Bucket) Rooms

func (b *Bucket) Rooms() (res map[string]struct{})

Rooms get all room id where online number > 0.

func (*Bucket) RoomsCount

func (b *Bucket) RoomsCount() (res map[string]int32)

RoomsCount get all room id where online number > 0.

func (*Bucket) UpRoomsCount

func (b *Bucket) UpRoomsCount(roomCountMap map[string]int32)

UpRoomsCount update all room count

type Channel

type Channel struct {
	Room     *Room
	CliProto Ring

	Writer bufio.Writer
	Reader bufio.Reader
	Next   *Channel
	Prev   *Channel

	Mid      int64
	Key      string
	IP       string
	Platform string

	V1 bool
	// contains filtered or unexported fields
}

Channel used by message pusher send msg to write goroutine.

func NewChannel

func NewChannel(cli, svr int) *Channel

NewChannel new a channel.

func (*Channel) Close

func (c *Channel) Close()

Close close the channel.

func (*Channel) NeedPush

func (c *Channel) NeedPush(op int32, platform string) bool

NeedPush verify if in watch.

func (*Channel) Push

func (c *Channel) Push(p *model.Proto) (err error)

Push server push message.

func (*Channel) Ready

func (c *Channel) Ready() *model.Proto

Ready check the channel ready or close?

func (*Channel) Signal

func (c *Channel) Signal()

Signal send signal to the channel, protocol ready.

func (*Channel) UnWatch

func (c *Channel) UnWatch(accepts ...int32)

UnWatch unwatch an operation

func (*Channel) Watch

func (c *Channel) Watch(accepts ...int32)

Watch watch a operation.

type NoAuthParam

type NoAuthParam struct {
	Key    string `json:"key,omitempty"`
	Aid    int64  `json:"aid,omitempty"`
	RoomID int64  `json:"roomid,omitempty"`
	UserID int64  `json:"uid,omitempty"`
	From   int64  `json:"from,omitempty"`
}

NoAuthParam .

type ProtoRoom

type ProtoRoom struct {
	RoomID string
	Proto  *model.Proto
}

ProtoRoom room proto.

type Report

type Report struct {
	From int64
	Aid  int64
	Cid  int64
	Mid  int64
	Key  string
	IP   string
}

Report is report params.

type Ring

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

Ring .

func NewRing

func NewRing(num int) *Ring

NewRing .

func (*Ring) Get

func (r *Ring) Get() (proto *model.Proto, err error)

Get .

func (*Ring) GetAdv

func (r *Ring) GetAdv()

GetAdv .

func (*Ring) Init

func (r *Ring) Init(num int)

Init .

func (*Ring) Reset

func (r *Ring) Reset()

Reset .

func (*Ring) Set

func (r *Ring) Set() (proto *model.Proto, err error)

Set .

func (*Ring) SetAdv

func (r *Ring) SetAdv()

SetAdv .

type Room

type Room struct {
	ID string

	Online    int32 // dirty read is ok
	AllOnline int32
	// contains filtered or unexported fields
}

Room is a room.

func NewRoom

func NewRoom(id string) (r *Room)

NewRoom new a room struct, store channel room info.

func (*Room) Close

func (r *Room) Close()

Close close the room.

func (*Room) Del

func (r *Room) Del(ch *Channel) bool

Del delete channel from the room.

func (*Room) OnlineNum

func (r *Room) OnlineNum() int32

OnlineNum the room all online.

func (*Room) Push

func (r *Room) Push(p *model.Proto)

Push push msg to the room, if chan full discard it.

func (*Room) Put

func (r *Room) Put(ch *Channel) (err error)

Put put channel into the room.

type Round

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

Round userd for connection round-robin get a reader/writer/timer for split big lock.

func NewRound

func NewRound(c *conf.Config) (r *Round)

NewRound new a round struct.

func (*Round) Reader

func (r *Round) Reader(rn int) *bytes.Pool

Reader get a reader memory buffer.

func (*Round) Timer

func (r *Round) Timer(rn int) *time.Timer

Timer get a timer.

func (*Round) Writer

func (r *Round) Writer(rn int) *bytes.Pool

Writer get a writer memory buffer pool.

type RoundOptions

type RoundOptions struct {
	Timer        int
	TimerSize    int
	Reader       int
	ReadBuf      int
	ReadBufSize  int
	Writer       int
	WriteBuf     int
	WriteBufSize int
}

RoundOptions .

type Server

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

Server .

func NewServer

func NewServer(c *conf.Config) *Server

NewServer returns a new Server.

func (*Server) Bucket

func (s *Server) Bucket(subKey string) *Bucket

Bucket get the bucket by subkey.

func (*Server) Buckets

func (s *Server) Buckets() []*Bucket

Buckets return all buckets.

func (*Server) Close

func (s *Server) Close() (err error)

Close close the server.

func (*Server) Connect

func (s *Server) Connect(ctx context.Context, p *model.Proto, cookie string) (mid int64, key, rid, platform string, accepts []int32, err error)

Connect .

func (*Server) Disconnect

func (s *Server) Disconnect(ctx context.Context, mid int64, key string) (err error)

Disconnect .

func (*Server) Heartbeat

func (s *Server) Heartbeat(ctx context.Context, mid int64, key string) (err error)

Heartbeat .

func (*Server) NextKey

func (s *Server) NextKey() string

NextKey generate a server key.

func (*Server) NoAuth

func (s *Server) NoAuth(ver int16, token []byte, ip string) (userID int64, roomID, key string, rpt *Report, err error)

NoAuth .

func (*Server) Operate

func (s *Server) Operate(p *model.Proto, ch *Channel, b *Bucket) error

Operate .

func (*Server) RandServerHearbeat

func (s *Server) RandServerHearbeat() time.Duration

RandServerHearbeat rand server heartbeat.

func (*Server) RenewOnline

func (s *Server) RenewOnline(ctx context.Context, serverID string, shard int32, rommCount map[string]int32) (allRoom map[string]int32, err error)

RenewOnline .

func (*Server) Report

func (s *Server) Report(mid int64, proto *model.Proto) (rp *model.Proto, err error)

Report .

func (*Server) ServeTCP

func (s *Server) ServeTCP(conn *net.TCPConn, rp, wp *bytes.Pool, tr *itime.Timer)

ServeTCP .

func (*Server) ServeWebsocket

func (s *Server) ServeWebsocket(conn net.Conn, rp, wp *bytes.Pool, tr *itime.Timer)

ServeWebsocket .

type Whitelist

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

Whitelist .

func (*Whitelist) Contains

func (w *Whitelist) Contains(mid int64) (ok bool)

Contains whitelist contains a mid or not.

func (*Whitelist) Printf

func (w *Whitelist) Printf(format string, v ...interface{})

Printf calls l.Output to print to the logger.

Directories

Path Synopsis
Package server generate by warden_gen
Package server generate by warden_gen

Jump to

Keyboard shortcuts

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