saver

package
v0.0.0-...-d436db8 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GroupJoined  = "join"
	GroupCreated = "owner"
	GroupAll     = "all"
)
View Source
const (
	ReqRoleGroupExited = 1
	ReqRoleGroupUser   = 2
	ReqRoleGroupOwner  = 4

	ReqRoleGroupUserOrOwner = 6
	ReqRoleGroupAll         = 255
)
View Source
const (
	ChatChannelNotify   = "peer"
	ChatChannelPublic   = "public"
	ChatChannelIM       = "im"
	ChatChannelIMInbox  = "iminbox"
	ChatChannelIMOutbox = "imoutbox"
)

Variables

View Source
var (
	ErrNotFound    = errors.New("specified message not found")
	ErrRecalledYet = errors.New("message has been recalled yet")
)
View Source
var GorpcClient *gorpc.Client = func() *gorpc.Client {
	netOptions := gorpc.NewNetOptions(gorpc.DefaultConnectTimeout, gorpc.DefaultReadTimeout, gorpc.DefaultWriteTimeout)
	g := gorpc.NewClient(netOptions)
	statNetOption := gorpc.NewNetOptions(1*time.Second, 1*time.Second, 1*time.Second)
	g.SetMethodNetOptinons("GorpcService", "GetSaverQps", statNetOption)
	g.SetMethodNetOptinons("GorpcService", "GetSaverTotalOps", statNetOption)
	return g
}()

Functions

func AddChatRoomRobot

func AddChatRoomRobot(req *session.UserChatRoomRequest) error

func AddChatRoomUser

func AddChatRoomUser(req *session.UserChatRoomRequest) (int, error)

func AddChatroomCountKeys

func AddChatroomCountKeys(appid uint16, roomids []string) error

func AddQpsCount

func AddQpsCount(module, api string, limit int) (bool, error)

func CacheChatRoomMessage

func CacheChatRoomMessage(req *logic.ChatRoomMessage) (uint, error)

func CheckUserSessionInRoom

func CheckUserSessionInRoom(req *session.UserChatRoomRequest) (bool, error)

func CleanChatRoom

func CleanChatRoom(room string, appid uint16) error

func CreateChatRoom

func CreateChatRoom(req *session.UserChatRoomRequest) error

func DelChatroomCountKeys

func DelChatroomCountKeys(appid uint16, roomids []string) error

func GetActiveChatRoomNum

func GetActiveChatRoomNum(appid uint16) (int, error)

func GetActiveUserNum

func GetActiveUserNum(appid uint16) (int, error)

func GetActiveUserSessions

func GetActiveUserSessions(appid uint16, zoneid uint16) ([]*session.UserSession, error)

func GetCachedChatRoomMessages

func GetCachedChatRoomMessages(req *FetchChatRoomMessageReq) (map[uint]*logic.ChatRoomMessage, error)

func QueryChatRoomDetail

func QueryChatRoomDetail(room string, appid uint16) (*session.ChatRoomDetail, error)

func QueryChatRoomMemberCount

func QueryChatRoomMemberCount(rooms []string, appid uint16) (map[string]map[string]int, error)

func QueryChatRoomUsers

func QueryChatRoomUsers(room string, appid uint16) ([]string, error)

func QueryChatRoomsByZone

func QueryChatRoomsByZone(appid uint16, zoneid uint16) (map[string]*session.ChatRoomDetail, error)

func QueryUserInRoom

func QueryUserInRoom(room string, user string, appid uint16) (bool, error)

判断用户是否在某直播间

func QueryUserSession

func QueryUserSession(query []*session.UserSession) ([]*session.UserSession, error)

func QueryUserSessionChatRoomList

func QueryUserSessionChatRoomList(req *session.UserChatRoomRequest) ([]string, error)

func QueryUserSessionSummary

func QueryUserSessionSummary(appid uint16, user string) (map[string]int, error)

func RemoveChatRoomRobot

func RemoveChatRoomRobot(req *session.UserChatRoomRequest) error

func RemoveChatRoomUser

func RemoveChatRoomUser(req *session.UserChatRoomRequest) (int, error)

func RemoveSession

func RemoveSession(userSession *session.UserSession) error

func SaveSession

func SaveSession(userSession *session.UserSession) ([]*session.UserSession, error)

func SetMethodNetOptinons

func SetMethodNetOptinons(service string, netOptionsList map[string]*gorpc.NetOptions) error

func UpdateChatRoomMember

func UpdateChatRoomMember(req *ChatRoomMemberUpdate) error

Types

type ChatMessage

type ChatMessage struct {
	Content        string // content of the message
	Type           uint32 // message type, like text, voice, picture or others
	To             string // message recipient
	From           string // message initiator
	TraceSN        int64  // the unique message sequence number used to trace message
	ExpireInterval int    // expire time interval, the unit is second
	StoreOutbox    uint8  // indicate the message box to store, 0 for inbox only, 1 for both inbox and outbox.

	// below fields usually are generated by saver
	MsgId      uint64    // unique message id
	Creation   time.Time // the time when the message is saved
	ExpireTime time.Time // the time when the message is expired, it means saver will remove this message from DB after that point
	Box        uint8     // indicate the message is retrieved from which message box, 0 is from inbox, 1 is from outbox.
}

* Message struct, is used to store/retrieve the messages from saver * * Caller filled fields: * Content: the message's content * Type: the message content's type * To: the key info, such as jid, of message recipient * From: the key info, such as jid, of message sender * TraceSN: the unique message sequence number * ExpireInterval: indicates that message will be deleted after expire time interval from saved time, * the unit is second. The value range of this filed is min ~ max expire time interval seconds which * defined in config; saver will treat all data less than min as min while treat all * data more than max as max. * If this field is not set, the default is used. * By default, the default is 604,800s (7 days), min is 3600s (1 hours) * while max is 8,640,000s (100 days). * Also we allow to define independent expire time interval for special message types in config * * StoreOutbox: indicate the message retrieved from which message box, 0 is from inbox, 1 is from outbox. * This field is used by 'im' channel messages only and will not be stored * * Below fields usually are generated by saver * MsgId: unique message id if message saved successfully * Creation: the time when the message is saved in storage * ExpireTime: the time when the message is expired, it means saver will remove this message from storage after that point * Box: indicates the message is retrieved from which message box, 0 is from inbox, 1 is from outbox.

func (*ChatMessage) JsonString

func (msg *ChatMessage) JsonString() string

func (*ChatMessage) String

func (msg *ChatMessage) String() string

* default string will not include content information

func (*ChatMessage) ToString

func (msg *ChatMessage) ToString(args ...string) string

type ChatRoomMemberUpdate

type ChatRoomMemberUpdate struct {
	RoomID string
	Appid  uint16
	Type   string
	Count  int
}

type ChatRoomsAppid

type ChatRoomsAppid struct {
	Appid   uint16
	RoomIDs []string
}

type ChatroomCountKeysRequest

type ChatroomCountKeysRequest struct {
	Appid   uint16
	Roomids []string
}

type ChatroomCountKeysResponse

type ChatroomCountKeysResponse struct {
	Roomids []string
}

func GetChatroomCountKeys

func GetChatroomCountKeys(appid uint16, rpcIndex, rpcLength int, clientIP string) (*ChatroomCountKeysResponse, error)

type FetchChatRoomMessageReq

type FetchChatRoomMessageReq struct {
	RoomID string
	Appid  uint16
	MsgIDs []uint
}

type GetActiveReq

type GetActiveReq struct {
	AppId  uint16
	ZoneId uint16
}

type GetChatroomCountKeysRequest

type GetChatroomCountKeysRequest struct {
	Appid     uint16
	ClientIP  string
	RpcIndex  int
	RpcLength int
}

type GroupAppid

type GroupAppid struct {
	AppId    uint16
	GroupId  string
	UserId   string
	SinceId  int
	PageSize int
	Version  int64
	ReqType  string
	Extras   []string
}

type GroupMsgReq

type GroupMsgReq struct {
	AppId   uint16
	GroupId string
	StartId uint64
	Offset  int32
}

type QpsCount

type QpsCount struct {
	Module string
	API    string
	Limit  int
}

type RecallMessagesRequest

type RecallMessagesRequest struct {
	Appid       uint16
	ChatChannel string
	Sender      string
	Receiver    string
	InboxId     uint64
	TraceSN     string
}

* [Request] other modules -> saver; this is used by recall notification/im messages functions * Appid: application id * ChatChannel: indicates information of channels will be recalled * Sender: the sender of message which need to be recalled * Receiver: the receiver of message which need to be recalled * InboxId: the msg id from inbox to indicate which one should be delete

func (RecallMessagesRequest) String

func (req RecallMessagesRequest) String() string

type RetrieveChannel

type RetrieveChannel struct {
	Channel    string
	StartMsgId int64
	MaxCount   int
}

* RetrieveChannel indicates message of what channel will be retrieved * Channel: tells the channel type of the message to be retrieved, so far only 'notify', 'public', 'im', 'imInbox' and * 'imOutbox' are supported. * If this field is filled and value isn't 'notify', 'public', 'im', 'imInbox' and 'imOutbox' or not filled, * this entry will be ignored when saver is handling retrieve message request. * 'notify' type: request to retrieve notification channel messages * 'public' type: request to retrieve public channel messages * 'im' type: request to retrieve im channel messages, both inbox and outbox * 'imInbox' type: request to retrieve im channel messages, inbox only * 'imOutBox' type: request to retrieve im channel messages, outbox only * StartMsgId: inclusive message id base; * set as 0 will return messages from last read include last read, * set as negative will return latest messages * otherwise will return from request start id if there are * MaxCount: max return count in this request; this field is set as 0 will use default value 5 * this field is set as negative will return messages before start id

func (RetrieveChannel) String

func (info RetrieveChannel) String() string

type RetrieveMessagesRequest

type RetrieveMessagesRequest struct {
	Appid        uint16
	Owner        string
	ChatChannels map[string]*RetrieveChannel
	TraceSN      string
}

* [Request] other modules -> saver; this is used by retrieve notification/im/public messages functions * Appid: application id * Owner: owner who requests to retrieve messages * ChatChannels: indicates information of channels will be retrieved

func (RetrieveMessagesRequest) String

func (req RetrieveMessagesRequest) String() string

type RetrieveMessagesResponse

type RetrieveMessagesResponse struct {
	Inbox      map[string][]*ChatMessage
	Outbox     map[string][]*ChatMessage
	LatestID   map[string]uint64
	LastReadID map[string]uint64
	Appid      uint16
	Owner      string
}

* [Response] saver -> other modules; this is used by retrieve notification/im/public messages response * * Inbox: messages have been retrieved from inbox storage; key is channels in request and value are message slice of * channel. If a channel in request is not found in Inbox means there isn't any messages from specified start id * have response in this field * Outbox: messages have been retrieved from inbox storage; key is channels in request and value are message slice of * channel. So far only IM channel may have outbox * LatestID: each latest ID of channels in request * LastReadID: each last read ID of channels in request

func RetrieveChatMessages

func RetrieveChatMessages(req *RetrieveMessagesRequest) (*RetrieveMessagesResponse, error)

* Retrieves chat messages from storage * @param req is a saver.RetrieveMessagesRequest point which include retrieving request information * @param resp is a saver.RetrieveMessagesResponse point which includes response * @return (*RetrieveMessagesResponse, nil) if no error occurs, otherwise (nil, error) is returned

func RetrieveUnreadCount

func RetrieveUnreadCount(appid uint16, userIds, channels []string) ([]*RetrieveMessagesResponse, error)

获取未读消息数

func (RetrieveMessagesResponse) String

func (resp RetrieveMessagesResponse) String() string

type SaverStat

type SaverStat struct {
	OpenSessions               uint64
	OpenSessionFails           uint64
	CloseSessions              uint64
	CloseSessionFails          uint64
	QuerySessions              uint64
	QuerySessionSuccess        uint64
	QuerySessionFails          uint64
	TotalSessionResponseTime   uint64
	StoreIMs                   uint64
	StoreIMFails               uint64
	RetrieveIms                uint64
	RetrieveImFails            uint64
	StorePeers                 uint64
	StorePeerFails             uint64
	RetrievePeers              uint64
	RetrievePeerFails          uint64
	TotalP2pResponseTime       uint64
	RetrievePublics            uint64
	RetrievePublicResponseTime uint64
	StatResponse               int32
}

func GetSaverQps

func GetSaverQps(saverGorpcAddr string) (*SaverStat, error)

* get saver qps from specified saver * @param saverGorpcAddr is specified saver go rpc address * @return (*SaverStat, nil) if successful, otherwise (*SaverStat{}, error) will be return

func GetSaverTotalOps

func GetSaverTotalOps(saverGorpcAddr string) (*SaverStat, error)

* get saver total operations count after start from specified saver * @param saverGorpcAddr is specified saver go rpc address * @return (*SaverStat, nil) if successful, otherwise (*SaverStat{}, error) will be return

func (*SaverStat) Add

func (stat *SaverStat) Add(add *SaverStat) *SaverStat

* stat add add and then store result in stat * @param add is value will be added * @return stat with new value

func (*SaverStat) AtomicAddCloseSessionFails

func (stat *SaverStat) AtomicAddCloseSessionFails(i uint64) uint64

func (*SaverStat) AtomicAddCloseSessions

func (stat *SaverStat) AtomicAddCloseSessions(i uint64) uint64

func (*SaverStat) AtomicAddOpenSessionFails

func (stat *SaverStat) AtomicAddOpenSessionFails(i uint64) uint64

func (*SaverStat) AtomicAddOpenSessions

func (stat *SaverStat) AtomicAddOpenSessions(i uint64) uint64

func (*SaverStat) AtomicAddP2pResponseTime

func (stat *SaverStat) AtomicAddP2pResponseTime(i uint64) uint64

* add a p2p message request response time to total atomicly * @param i is p2p message request response time with unit nanosecond * @return new total p2p message request response time

func (*SaverStat) AtomicAddQuerySessionFails

func (stat *SaverStat) AtomicAddQuerySessionFails(i uint64) uint64

func (*SaverStat) AtomicAddQuerySessionSuccess

func (stat *SaverStat) AtomicAddQuerySessionSuccess(i uint64) uint64

func (*SaverStat) AtomicAddQuerySessions

func (stat *SaverStat) AtomicAddQuerySessions(i uint64) uint64

func (*SaverStat) AtomicAddRetrieveImFails

func (stat *SaverStat) AtomicAddRetrieveImFails(i uint64) uint64

func (*SaverStat) AtomicAddRetrieveIms

func (stat *SaverStat) AtomicAddRetrieveIms(i uint64) uint64

func (*SaverStat) AtomicAddRetrievePeerFails

func (stat *SaverStat) AtomicAddRetrievePeerFails(i uint64) uint64

func (*SaverStat) AtomicAddRetrievePeers

func (stat *SaverStat) AtomicAddRetrievePeers(i uint64) uint64

func (*SaverStat) AtomicAddRetrievePublicResponseTime

func (stat *SaverStat) AtomicAddRetrievePublicResponseTime(i uint64) uint64

func (*SaverStat) AtomicAddRetrievePublics

func (stat *SaverStat) AtomicAddRetrievePublics(i uint64) uint64

func (*SaverStat) AtomicAddSessionResponseTime

func (stat *SaverStat) AtomicAddSessionResponseTime(i uint64) uint64

* add a session request response time to total atomicly * @param i is session request response time with unit nanosecond * @return new total session request response time

func (*SaverStat) AtomicAddStoreIMFails

func (stat *SaverStat) AtomicAddStoreIMFails(i uint64) uint64

func (*SaverStat) AtomicAddStoreIMs

func (stat *SaverStat) AtomicAddStoreIMs(i uint64) uint64

func (*SaverStat) AtomicAddStorePeerFails

func (stat *SaverStat) AtomicAddStorePeerFails(i uint64) uint64

func (*SaverStat) AtomicAddStorePeers

func (stat *SaverStat) AtomicAddStorePeers(i uint64) uint64

func (*SaverStat) AtomicCopyTo

func (stat *SaverStat) AtomicCopyTo(copy *SaverStat) *SaverStat

* this copy content of stat to 'copy' atomicly * @param copy is target the content copy to * @return copy if it is not nil, otherwise will return a new SaverStat point

func (*SaverStat) AtomicGetCloseSessionFails

func (stat *SaverStat) AtomicGetCloseSessionFails() uint64

func (*SaverStat) AtomicGetCloseSessions

func (stat *SaverStat) AtomicGetCloseSessions() uint64

func (*SaverStat) AtomicGetOpenSessionFails

func (stat *SaverStat) AtomicGetOpenSessionFails() uint64

func (*SaverStat) AtomicGetOpenSessions

func (stat *SaverStat) AtomicGetOpenSessions() uint64

* get total open session request count atomicly

func (*SaverStat) AtomicGetQuerySessionFails

func (stat *SaverStat) AtomicGetQuerySessionFails() uint64

func (*SaverStat) AtomicGetQuerySessionSuccess

func (stat *SaverStat) AtomicGetQuerySessionSuccess() uint64

func (*SaverStat) AtomicGetQuerySessions

func (stat *SaverStat) AtomicGetQuerySessions() uint64

func (*SaverStat) AtomicGetRetrieveImFails

func (stat *SaverStat) AtomicGetRetrieveImFails() uint64

func (*SaverStat) AtomicGetRetrieveIms

func (stat *SaverStat) AtomicGetRetrieveIms() uint64

func (*SaverStat) AtomicGetRetrievePeerFails

func (stat *SaverStat) AtomicGetRetrievePeerFails() uint64

func (*SaverStat) AtomicGetRetrievePeers

func (stat *SaverStat) AtomicGetRetrievePeers() uint64

func (*SaverStat) AtomicGetRetrievePublicResponseTime

func (stat *SaverStat) AtomicGetRetrievePublicResponseTime() uint64

func (*SaverStat) AtomicGetRetrievePublics

func (stat *SaverStat) AtomicGetRetrievePublics() uint64

func (*SaverStat) AtomicGetStatResponse

func (stat *SaverStat) AtomicGetStatResponse() bool

func (*SaverStat) AtomicGetStoreIMFails

func (stat *SaverStat) AtomicGetStoreIMFails() uint64

func (*SaverStat) AtomicGetStoreIMs

func (stat *SaverStat) AtomicGetStoreIMs() uint64

func (*SaverStat) AtomicGetStorePeerFails

func (stat *SaverStat) AtomicGetStorePeerFails() uint64

func (*SaverStat) AtomicGetStorePeers

func (stat *SaverStat) AtomicGetStorePeers() uint64

func (*SaverStat) AtomicGetTotalP2pResponseTime

func (stat *SaverStat) AtomicGetTotalP2pResponseTime() uint64

func (*SaverStat) AtomicGetTotalSessionResponseTime

func (stat *SaverStat) AtomicGetTotalSessionResponseTime() uint64

func (*SaverStat) AtomicMakeQps

func (stat *SaverStat) AtomicMakeQps(i uint64) string

* this computes qps with stat according to interval * @param i is interval which unit is second * @return a json string that include saver QPS information

func (*SaverStat) AtomicSetStatResponse

func (stat *SaverStat) AtomicSetStatResponse(value bool)

func (*SaverStat) AtomicTotalIMRequests

func (stat *SaverStat) AtomicTotalIMRequests() uint64

* get total IM request count atomicly

func (*SaverStat) AtomicTotalP2PMsgRequests

func (stat *SaverStat) AtomicTotalP2PMsgRequests() uint64

* get total p2p message request count atomicly

func (*SaverStat) AtomicTotalPeerRequests

func (stat *SaverStat) AtomicTotalPeerRequests() uint64

* get total peer request count atomicly

func (*SaverStat) AtomicTotalSessionRequests

func (stat *SaverStat) AtomicTotalSessionRequests() uint64

* get total session request count atomicly

func (*SaverStat) QpsString

func (stat *SaverStat) QpsString() string

func (*SaverStat) String

func (stat *SaverStat) String() string

func (*SaverStat) Sub

func (stat *SaverStat) Sub(sub *SaverStat) *SaverStat

* stat subtract sub and then store result in stat * @param sub is value will be subtracted * @return stat with new value

type StoreMessagesRequest

type StoreMessagesRequest struct {
	Appid       uint16
	Messages    map[string]*ChatMessage
	ChatChannel string
	TraceSN     string
}

* [Request] other modules -> saver; this is used by store notification/im/public messages functions * Appid: application id * Messages: messages need to store; key is receiver of stored messages * ChatChannel: tells the channel type of the message to store, so far only 'notify', 'im' and 'public' * are supported. If this field isn't filled, saver treats it as 'notify' type. * If this field is filled and value isn't 'notify', 'im' and 'public', * a error code will be returned. * 'notify' type: requires all caller filled fields in Message. And 'To' and 'From' fields cannot be * empty string, otherwise the message will be discarded directly with no correspond message in response. * This type message supports to set its own expire time during in range 1~604800 seconds * The default expire time is 604800 seconds if ExpireInterval field isn't filled * 'public' type: requires that ExpireInterval field of messages is filled, otherwise the message * will be discarded directly. This type message does not require 'to' and 'from' fields * 'im' type: IM message, likes 'notify' message but it allows messages are store to outbox too if need

func (StoreMessagesRequest) String

func (req StoreMessagesRequest) String() string

type StoreMessagesResponse

type StoreMessagesResponse struct {
	Inbox  map[string]*ChatMessage
	Outbox map[string]*ChatMessage
}

* [Response] saver -> other modules; this is used by store notification/im/public messages response * Note that store functions will not return error if any message is discarded for invalid value; * if a message cannot be found in response by its TraceSN, it is discarded for invalid value * * Inbox: messages have been stored to inbox of receiver; key is receiver of stored messages * Outbox: messages have been stored to outbox of sender; key is receiver of stored messages * Note: the count of Messages might not be equal to request.Messages for they might be discarded for invalid value

func RecallChatMessages

func RecallChatMessages(req *RecallMessagesRequest) (*StoreMessagesResponse, error)

* Set chat messages recall flag to storage * @param req is a saver.RecallMessagesRequest point which include recall request information * @param resp is a saver.StoreMessagesResponse point which includes response * @return (*StoreMessagesResponse, nil) if no error occurs, otherwise (nil, error) is returned

func StoreChatMessages

func StoreChatMessages(req *StoreMessagesRequest) (*StoreMessagesResponse, error)

* Stores chat messages to storage * @param req is a saver.StoreMessagesRequest point which include messages information need to store * @return (*StoreMessagesResponse, nil) if no error occurs, otherwise (nil, error) is returned

func (StoreMessagesResponse) String

func (resp StoreMessagesResponse) String() string

type UserAppid

type UserAppid struct {
	User  string
	Appid uint16
}

type UserChatRoom

type UserChatRoom struct {
	User   string
	RoomId string
	Appid  uint16
}

Jump to

Keyboard shortcuts

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