engine

package
v0.0.0-...-72e5503 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2018 License: GPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TYPE_CLIENT = 1
	TYPE_SERVER = 2

	CLIENT_STATE_CREATE    = 0
	CLIENT_STATE_INIT_DOEN = 1
	CLIENT_STATE_DEAD      = 2
)
View Source
const (
	CMD_OFFLINE_MSG = "ofli_msg"
	CMD_CREATE_USER = "user_create"

	CMD_ACK_MSG            = "ack"
	CMD_DISOLVE            = "disolve"
	CMD_UNSUBS             = "unsubs"
	CMD_SUBS               = "subs"
	CMD_ADD_USER_INTO_ROOM = "add_into_room"
	CMD_APPKEY             = "getappkey"
	CMD_SENDMSG            = "sendmsg"
	CMD_SETUUID            = "setuuid"
	CMD_SUBSCRIBE          = "sub"
	CMD_PUBLISH            = "pub"
	CMD_UNSUBSCRIBE        = "unsub"
	CMD_HISTORY            = "his"
	CMD_TOKEN              = "gettoken"
	CMD_AUTH_CLIENT        = "auth_client"
	CMD_AUTH_SERVER        = "auth_server"
	CMD_PING               = "ping"
	CMD_CREATEROOM         = "create_room"
	CMD_JOINROOM           = "join_room"
	CMD_LEAVEROOM          = "leave_room"

	// 发送二进制,如语音单聊
	CMD_VIDO_CHAT = "vido"

	// 语音、视频聊天相关(发起视频对话,接受对话,拒绝对话,发起多对多,一对一,加入视频对话)
	CMD_FRAME_APPLY         = "frame_apply"
	CMD_FRAME_JOIN          = "frame_join"
	CMD_FRAME_OUT           = "frame_out"
	CMD_FRAME_ACCEPT        = "frame_accept"
	CMD_FRAME_DISMISS       = "frame_dismiss"
	CMD_FRAME_REFUSE        = "frame_refuse"
	CMD_FRAME_INFO          = "frame_info"
	CMD_INVOKE_FRAME_ACTION = "frame_action"

	CMD_RETRACT_MESSAGE = "retract_msg" // 撤回消息

	CMD_UPDATE_OR_ADD_PUSH_ID = "up_ad_pushId"

	// app server通过im往客户端推送消息
	CMD_SET_OFF_NOTIFY                    = "set_notify"
	CMD_PUBLISH_NOTIFICATION_IN_CHAT_ROOM = "pnicr"
	CMD_PUSH_NOTIFY_TO_USERS              = "pntus"
	CMD_ACK_SERVER_NOTIFY                 = "asn"
	CMD_PEEK_SERVER_NOTIFY                = "psn"

	OUTPUT_FRAME_CHAT         = "FRAMECHAT"
	OUTPUT_TOKEN              = "TOKEN"
	OUTPUT_AUTH_SERVER        = "AUTHSERVER"
	OUTPUT_RCIV               = "RCIV"
	OUTPUT_APPKEY             = "APPKEY"
	OUTPUT_SUBSCRIBED         = "SUBSCRIBED"
	OUTPUT_ALREADY_SUBSCRIBED = "ALREADY SUBSCRIBED"
	OUTPUT_NOT_SUBSCRIBED     = "NOT SUBSCRIBED"
	OUTPUT_UNSUBSCRIBED       = "UNSUBSCRIBED"
	OUTPUT_PONG               = "pong"
)
View Source
const (
	TYPE_SINGLE_VOICE = 1
	TYPE_MUL_VOICE    = 2
	TYPE_SINGLE_VIDEO = 3
	TYPE_MUL_VIDEO    = 4
)

TODO 思考定义了这些常量,为什么没有用上

View Source
const (
	CODE_SUCCESS             = 200
	CODE_PARAM_ERROR         = 202
	CODE_SERVER_ERROR        = 500
	CODE_FAILED              = 400
	CODE_TOKEN_OR_TERM_ERROR = 508
)

TODO 所有响应消息,修改为使用code码来区别类型

View Source
const (
	// 正常消息
	MESSAGE_TYPE_NORMAL = 0

	// 某人创建群聊
	CREATE_CHAT_ROOM = 2

	// 某人撤回消息
	RETRACT_MESSAGE = 3

	// 某人加入群聊
	SOME_ONE_JOIN_CHAT_ROOM = 4

	// 某人退出群聊
	SOME_ONE_QUIT_CHAT_ROOM = 5

	// 某人被踢出群聊
	SOME_ONE_EXPELLED_FROM_CHAT_ROOM = 6

	// 某人修改了群名称
	SOME_ONE_MODIFY_NAME_OF_CHAT_ROOM = 7

	// 某人被邀请加入群聊
	SOME_ONE_BE_INVITED_OT_CHAT_ROOM = 8

	// 面对面群中某人加入群聊
	FACE_TO_FACE_SOME_ONE_JOIN_CHAT_ROOM = 9

	// 群主变更
	MASTER_CHANGE_CHAT_ROOM = 11

	// 按人通知
	MESSAGE_FOR_PERSON = 1000
)

数据库集合msg_log中各记录的类型

View Source
const (
	RETRY_CNT = 2

	S2S_SUB_CMD             = "sub"
	S2S_PUB_CMD             = "pub"
	S2S_UNSUB_CMD           = "unsub"
	S2S_PUSH_BINARY_MESSAGE = "push_bin_msg" // 广播内容为二进制的消息
	S2S_PUSH_STRING_MESSAGE = "push_str_msg" // 广播内容为字符型的消息

)
View Source
const (
	UNSTABLE_INFO_TYPE_FRAME_CHAT = 1
)

Variables

View Source
var (
	PubsubChannels *PubsubChans
	UuidToClient   *UuidClientMap
)
View Source
var (
	ErrNotPermit error = errors.New("Not Permit")
)

Functions

func AclCheck

func AclCheck(cli *Client, cmd string) (err error)

func CheckAndPush

func CheckAndPush(channel, message, ownerId string)

func InitAclEnv

func InitAclEnv()

func InitOffPushService

func InitOffPushService() error

func LoadUserIdsByChannel

func LoadUserIdsByChannel(channel string) []string

func LoadUserIdsFromDatabase

func LoadUserIdsFromDatabase(channel string) ([]string, error)

func Publish

func Publish(channel, msg, userId string, msgId int64, fromS2s bool) string

func PublishBinMsg

func PublishBinMsg(channel, ownerId string, msg []byte, isToOtherServer bool)

推送和转发二进制类型消息

func PublishStrMsg

func PublishStrMsg(channel, msg, ownerId string, isToOtherServer bool)

推送和转发字符类型消息

func PushToClients

func PushToClients(msg string, isToOtherServer bool, userIds ...string)

func RegisterEtc

func RegisterEtc() error

func Subscribe

func Subscribe(cli *Client, channel string) string

func TokenCheck

func TokenCheck(cli *Cmdline) error

func UnregisterEtc

func UnregisterEtc() error

func Unsubscribe

func Unsubscribe(cli *Client, channel string) string

func UnsubscribeAllChannels

func UnsubscribeAllChannels(cli *Client)

Types

type ChannelToUserIds

type ChannelToUserIds struct {
	*cache.LruCache
}

存储群聊Id到群聊中用户集合的映射

func (*ChannelToUserIds) AddAllUserIds

func (this *ChannelToUserIds) AddAllUserIds(channel string, freshUserIds ...string)

func (*ChannelToUserIds) AddUserId

func (this *ChannelToUserIds) AddUserId(channel, userId string)

func (*ChannelToUserIds) Exists

func (this *ChannelToUserIds) Exists(channel string) (exists bool)

func (*ChannelToUserIds) GetUserIdsByChannel

func (this *ChannelToUserIds) GetUserIdsByChannel(channel string) ([]string, bool)

func (*ChannelToUserIds) RemoveUserId

func (this *ChannelToUserIds) RemoveUserId(channel, userId string)

type Client

type Client struct {
	Channels map[string]int
	Type     uint8
	*server.Client

	PushId             string
	IsAllowForceNotify bool
	// contains filtered or unexported fields
}

func NewClient

func NewClient() (this *Client)

func (*Client) AckMsg

func (this *Client) AckMsg(msgId, ts int64, ownerId, channelId string)

func (*Client) ClearIdentity

func (this *Client) ClearIdentity()

func (*Client) Close

func (this *Client) Close()

func (*Client) IsClient

func (this *Client) IsClient() bool

func (*Client) IsServer

func (this *Client) IsServer() bool

func (*Client) SetClient

func (this *Client) SetClient()

func (*Client) SetServer

func (this *Client) SetServer()

type Cmdline

type Cmdline struct {
	Cmd     string
	Params  string
	Params2 []byte
	*Client
}

func NewCmdline

func NewCmdline(input []byte, cli *Client) (this *Cmdline, err error)

func (*Cmdline) Process

func (this *Cmdline) Process() (ret string, err error)

type ForwardTuple

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

func NewForwardTuple

func NewForwardTuple(peers set.Set, msg []byte, cmd string) (this *ForwardTuple)

type IOffSender

type IOffSender interface {
	// contains filtered or unexported methods
}

type OffSenderPool

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

func (*OffSenderPool) ObtainOneOffSender

func (this *OffSenderPool) ObtainOneOffSender() IOffSender

type Peer

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

func NewPeer

func NewPeer(addr string) (this *Peer)

func (*Peer) WriteFormatMsg

func (this *Peer) WriteFormatMsg(op string, msg []byte)

type ProxyStats

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

type PubsubChans

type PubsubChans struct {
	*cache.LruCache
}

func NewPubsubChannels

func NewPubsubChannels(maxChannelItems int) (this *PubsubChans)

func (*PubsubChans) Get

func (this *PubsubChans) Get(channel string) (clients cmap.ConcurrentMap, exists bool)

type PushdClientProcessor

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

func NewPushdClientProcessor

func NewPushdClientProcessor(server *server.TcpServer, serverStats *ServerStats) *PushdClientProcessor

func (*PushdClientProcessor) DisableAclCheck

func (this *PushdClientProcessor) DisableAclCheck()

func (*PushdClientProcessor) EnableAclCheck

func (this *PushdClientProcessor) EnableAclCheck()

func (*PushdClientProcessor) OnAccept

func (this *PushdClientProcessor) OnAccept(c *server.Client)

func (*PushdClientProcessor) OnRead

func (this *PushdClientProcessor) OnRead(client *Client, input []byte) (res error)

type PushdLongPollingServer

type PushdLongPollingServer struct {
	*server.HttpServer
	// contains filtered or unexported fields
}

func NewPushdLongPollingServer

func NewPushdLongPollingServer(name string) *PushdLongPollingServer

func (*PushdLongPollingServer) Launch

func (this *PushdLongPollingServer) Launch(listenAddr string, sessTimeout time.Duration)

func (*PushdLongPollingServer) ServeHistory

func (this *PushdLongPollingServer) ServeHistory(w http.ResponseWriter, req *http.Request)

func (*PushdLongPollingServer) ServePublish

func (this *PushdLongPollingServer) ServePublish(w http.ResponseWriter, req *http.Request)

func (*PushdLongPollingServer) ServeSubscribe

func (this *PushdLongPollingServer) ServeSubscribe(w http.ResponseWriter, req *http.Request)

type Router

type Router struct {
	Peers map[string]*Peer
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter(maxCacheItems int) *Router

func (*Router) AddPeerToChannel

func (this *Router) AddPeerToChannel(peerAddr, channel string) error

func (*Router) LookupPeersByChannel

func (this *Router) LookupPeersByChannel(channel string) (peers set.Set, exists bool)

func (*Router) RemovePeerFromChannel

func (this *Router) RemovePeerFromChannel(peerAddr, channel string) error

type S2sClientProcessor

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

func NewS2sClientProcessor

func NewS2sClientProcessor(server *server.TcpServer) *S2sClientProcessor

func (*S2sClientProcessor) OnAccept

func (this *S2sClientProcessor) OnAccept(client *server.Client)

func (*S2sClientProcessor) OnRead

func (this *S2sClientProcessor) OnRead(client *server.Client, input []byte) error

type S2sProxy

type S2sProxy struct {
	Router       *Router
	ForwardTuple chan *ForwardTuple
	Stats        *ProxyStats
}
var (
	Proxy *S2sProxy
)

func NewS2sProxy

func NewS2sProxy() (this *S2sProxy)

func (*S2sProxy) WaitMsg

func (this *S2sProxy) WaitMsg()

type Sender

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

type ServerCmdline

type ServerCmdline struct {
	Cmd    string
	Params []byte
	*server.Client
}

func NewServerCmdline

func NewServerCmdline(input []byte, cli *server.Client) (this *ServerCmdline, err error)

type ServerStats

type ServerStats struct {
	*server.HttpJsonServer
	CallLatencies metrics.Histogram
	CallPerSecond metrics.Meter
}

func NewServerStats

func NewServerStats() (this *ServerStats)

func (*ServerStats) Start

func (this *ServerStats) Start(interval time.Duration, logFile string)

type TokenInfo

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

type UserIdCollection

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

存储某个群聊中所有的用户的Id

type UuidClientMap

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

func NewUuidClientMap

func NewUuidClientMap() (this *UuidClientMap)

func (*UuidClientMap) AddClient

func (this *UuidClientMap) AddClient(uuid string, client *Client)

func (*UuidClientMap) GetClient

func (this *UuidClientMap) GetClient(uuid string) (client *Client, exists bool)

func (*UuidClientMap) Remove

func (this *UuidClientMap) Remove(uuid string, client *Client)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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