lim

package
v0.0.0-...-325de3d Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: MIT Imports: 51 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ChannelTypePerson 个人频道
	ChannelTypePerson uint8 = 1
	// ChannelTypeGroup 群频道
	ChannelTypeGroup uint8 = 2 // 群组频道
)
View Source
const (
	// EventMsgOffline 离线消息
	EventMsgOffline = "msg.offline"
	// EventMsgNotify 消息通知(将所有消息通知到第三方程序)
	EventMsgNotify = "msg.notify"
	// EventOnlineStatus 用户在线状态
	EventOnlineStatus = "user.onlinestatus"
)
View Source
const (
	// DebugMode indicates gin mode is debug.
	DebugMode = "debug"
	// ReleaseMode indicates gin mode is release.
	ReleaseMode = "release"
	// TestMode indicates gin mode is test.
	TestMode = "test"
)
View Source
const (
	TestUID = "test"
)

Variables

View Source
var (
	// ErrorDoCommandTimeout  Execution command timed out
	ErrorDoCommandTimeout = errors.New("do command timeout")
)
View Source
var NewCluster func(l *LiMao) IClusterManager // 创建一个分布式实现

NewCluster NewCluster

Functions

func GetFakeChannelID

func GetFakeChannelID(recvPacket *lmproto.RecvPacket) string

GetFakeChannelID 通过接受包获取伪频道ID

func GetFakeChannelIDWith

func GetFakeChannelIDWith(fromUID, toUID string) string

GetFakeChannelIDWith GetFakeChannelIDWith

func GetOtherSideUIDByFakeChannelID

func GetOtherSideUIDByFakeChannelID(uid string, fakeChannelID string) string

GetOtherSideUIDByFakeChannelID 通过伪频道ID获取聊天对方UID uid: 当前用户

func GetSlotNum

func GetSlotNum(slotCount uint, channelID string, channelType uint8) uint

GetSlotNum GetSlotNum

func MustConnectLiMao

func MustConnectLiMao(l *LiMao, uid string) *client.Client

MustConnectLiMao MustConnectLiMao

func UnmarshalCMD

func UnmarshalCMD(data []byte, cmd *CMD) error

UnmarshalCMD UnmarshalCMD

Types

type APIServer

type APIServer struct {
	limlog.Log
	// contains filtered or unexported fields
}

APIServer ApiServer

func NewAPIServer

func NewAPIServer(l *LiMao) *APIServer

NewAPIServer new一个api server

func (*APIServer) Start

func (s *APIServer) Start()

Start 开始

func (*APIServer) Stop

func (s *APIServer) Stop()

Stop 停止服务

type CMD

type CMD struct {
	Type    CMDType
	Version uint8
	Param   []byte
}

CMD CMD

func NewCMD

func NewCMD(typ CMDType) *CMD

NewCMD NewCMD

func (*CMD) DecodeAddOrUpdateChannel

func (c *CMD) DecodeAddOrUpdateChannel() (*ChannelInfo, error)

DecodeAddOrUpdateChannel DecodeAddOrUpdateChannel

func (*CMD) DecodeAppendMessage

func (c *CMD) DecodeAppendMessage() (*db.Message, error)

DecodeAppendMessage DecodeAppendMessage

func (*CMD) DecodeCMDAddAllowlist

func (c *CMD) DecodeCMDAddAllowlist() (channelID string, channelType uint8, uids []string, err error)

DecodeCMDAddAllowlist DecodeCMDAddAllowlist

func (*CMD) DecodeCMDAddDenylist

func (c *CMD) DecodeCMDAddDenylist() (channelID string, channelType uint8, uids []string, err error)

DecodeCMDAddDenylist DecodeCMDAddDenylist

func (*CMD) DecodeCMDAddNodeInFlightData

func (c *CMD) DecodeCMDAddNodeInFlightData() ([]*db.NodeInFlightDataModel, error)

DecodeCMDAddNodeInFlightData DecodeCMDAddNodeInFlightData

func (*CMD) DecodeCMDAddOrUpdateConversations

func (c *CMD) DecodeCMDAddOrUpdateConversations() (uid string, conversations []*db.Conversation, err error)

DecodeCMDAddOrUpdateConversations DecodeCMDAddOrUpdateConversations

func (*CMD) DecodeCMDAddSubscribers

func (c *CMD) DecodeCMDAddSubscribers() (channelID string, channelType uint8, uids []string, err error)

DecodeCMDAddSubscribers DecodeCMDAddSubscribers

func (*CMD) DecodeCMDAppendMessageOfNotifyQueue

func (c *CMD) DecodeCMDAppendMessageOfNotifyQueue() (*db.Message, error)

DecodeCMDAppendMessageOfNotifyQueue DecodeCMDAppendMessageOfNotifyQueue

func (*CMD) DecodeCMDAppendMessageOfUser

func (c *CMD) DecodeCMDAppendMessageOfUser() (m *db.Message, err error)

DecodeCMDAppendMessageOfUser DecodeCMDAppendMessageOfUser

func (*CMD) DecodeCMDDeleteChannel

func (c *CMD) DecodeCMDDeleteChannel() (channelID string, channelType uint8, err error)

DecodeCMDDeleteChannel DecodeCMDDeleteChannel

func (*CMD) DecodeCMDDeleteChannelAndClearMessages

func (c *CMD) DecodeCMDDeleteChannelAndClearMessages() (channelID string, channelType uint8, err error)

DecodeCMDDeleteChannelAndClearMessages DecodeCMDDeleteChannelAndClearMessages

func (*CMD) DecodeCMDRemoveAllAllowlist

func (c *CMD) DecodeCMDRemoveAllAllowlist() (channelID string, channelType uint8, err error)

DecodeCMDRemoveAllAllowlist DecodeCMDRemoveAllAllowlist

func (*CMD) DecodeCMDRemoveAllDenylist

func (c *CMD) DecodeCMDRemoveAllDenylist() (channelID string, channelType uint8, err error)

DecodeCMDRemoveAllDenylist DecodeCMDRemoveAllDenylist

func (*CMD) DecodeCMDRemoveAllowlist

func (c *CMD) DecodeCMDRemoveAllowlist() (channelID string, channelType uint8, uids []string, err error)

DecodeCMDRemoveAllowlist DecodeCMDRemoveAllowlist

func (*CMD) DecodeCMDRemoveDenylist

func (c *CMD) DecodeCMDRemoveDenylist() (channelID string, channelType uint8, uids []string, err error)

DecodeCMDRemoveDenylist DecodeCMDRemoveDenylist

func (*CMD) DecodeCMDRemoveMessagesOfNotifyQueue

func (c *CMD) DecodeCMDRemoveMessagesOfNotifyQueue() ([]int64, error)

DecodeCMDRemoveMessagesOfNotifyQueue DecodeCMDRemoveMessagesOfNotifyQueue

func (*CMD) DecodeCMDUpdateMessageOfUserCursorIfNeed

func (c *CMD) DecodeCMDUpdateMessageOfUserCursorIfNeed() (uid string, messageSeq uint32, err error)

DecodeCMDUpdateMessageOfUserCursorIfNeed DecodeCMDUpdateMessageOfUserCursorIfNeed

func (*CMD) DecodeRemoveAllSubscriber

func (c *CMD) DecodeRemoveAllSubscriber() (channelID string, channelType uint8, err error)

DecodeRemoveAllSubscriber DecodeRemoveAllSubscriber

func (*CMD) DecodeRemoveSubscribers

func (c *CMD) DecodeRemoveSubscribers() (channelID string, channelType uint8, uids []string, err error)

DecodeRemoveSubscribers DecodeRemoveSubscribers

func (*CMD) DecodeUserToken

func (c *CMD) DecodeUserToken() (uid string, deviceFlag lmproto.DeviceFlag, deviceLevel lmproto.DeviceLevel, token string, err error)

DecodeUserToken DecodeUserToken

func (*CMD) Encode

func (c *CMD) Encode() []byte

Encode Encode

func (*CMD) EncodeAddOrUpdateChannel

func (c *CMD) EncodeAddOrUpdateChannel(channelInfo *ChannelInfo) *CMD

EncodeAddOrUpdateChannel EncodeAddOrUpdateChannel

func (*CMD) EncodeAppendMessage

func (c *CMD) EncodeAppendMessage(m *db.Message) *CMD

EncodeAppendMessage EncodeAppendMessage

func (*CMD) EncodeCMDAddAllowlist

func (c *CMD) EncodeCMDAddAllowlist(channelID string, channelType uint8, uids []string) *CMD

EncodeCMDAddAllowlist EncodeCMDAddAllowlist

func (*CMD) EncodeCMDAddDenylist

func (c *CMD) EncodeCMDAddDenylist(channelID string, channelType uint8, uids []string) *CMD

EncodeCMDAddDenylist EncodeCMDAddDenylist

func (*CMD) EncodeCMDAddNodeInFlightData

func (c *CMD) EncodeCMDAddNodeInFlightData(data []*db.NodeInFlightDataModel) *CMD

EncodeCMDAddNodeInFlightData EncodeCMDAddNodeInFlightData

func (*CMD) EncodeCMDAddOrUpdateConversations

func (c *CMD) EncodeCMDAddOrUpdateConversations(uid string, conversations []*db.Conversation) *CMD

EncodeCMDAddOrUpdateConversations EncodeCMDAddOrUpdateConversations

func (*CMD) EncodeCMDAddSubscribers

func (c *CMD) EncodeCMDAddSubscribers(channelID string, channelType uint8, uids []string) *CMD

EncodeCMDAddSubscribers EncodeCMDAddSubscribers

func (*CMD) EncodeCMDAppendMessageOfNotifyQueue

func (c *CMD) EncodeCMDAppendMessageOfNotifyQueue(m *db.Message) *CMD

EncodeCMDAppendMessageOfNotifyQueue EncodeCMDAppendMessageOfNotifyQueue

func (*CMD) EncodeCMDAppendMessageOfUser

func (c *CMD) EncodeCMDAppendMessageOfUser(m *db.Message) *CMD

EncodeCMDAppendMessageOfUser EncodeCMDAppendMessageOfUser

func (*CMD) EncodeCMDClearNodeInFlightData

func (c *CMD) EncodeCMDClearNodeInFlightData() *CMD

EncodeCMDClearNodeInFlightData EncodeCMDClearNodeInFlightData

func (*CMD) EncodeCMDDeleteChannel

func (c *CMD) EncodeCMDDeleteChannel(channelID string, channelType uint8) *CMD

EncodeCMDDeleteChannel EncodeCMDDeleteChannel

func (*CMD) EncodeCMDDeleteChannelAndClearMessages

func (c *CMD) EncodeCMDDeleteChannelAndClearMessages(channelID string, channelType uint8) *CMD

EncodeCMDDeleteChannelAndClearMessages EncodeCMDDeleteChannelAndClearMessages

func (*CMD) EncodeCMDRemoveAllAllowlist

func (c *CMD) EncodeCMDRemoveAllAllowlist(channelID string, channelType uint8) *CMD

EncodeCMDRemoveAllAllowlist EncodeCMDRemoveAllAllowlist

func (*CMD) EncodeCMDRemoveAllDenylist

func (c *CMD) EncodeCMDRemoveAllDenylist(channelID string, channelType uint8) *CMD

EncodeCMDRemoveAllDenylist EncodeCMDRemoveAllDenylist

func (*CMD) EncodeCMDRemoveAllowlist

func (c *CMD) EncodeCMDRemoveAllowlist(channelID string, channelType uint8, uids []string) *CMD

EncodeCMDRemoveAllowlist EncodeCMDRemoveAllowlist

func (*CMD) EncodeCMDRemoveDenylist

func (c *CMD) EncodeCMDRemoveDenylist(channelID string, channelType uint8, uids []string) *CMD

EncodeCMDRemoveDenylist EncodeCMDRemoveDenylist

func (*CMD) EncodeCMDRemoveMessagesOfNotifyQueue

func (c *CMD) EncodeCMDRemoveMessagesOfNotifyQueue(messageIDs []int64) *CMD

EncodeCMDRemoveMessagesOfNotifyQueue EncodeCMDRemoveMessagesOfNotifyQueue

func (*CMD) EncodeCMDRemoveSubscribers

func (c *CMD) EncodeCMDRemoveSubscribers(channelID string, channelType uint8, uids []string) *CMD

EncodeCMDRemoveSubscribers EncodeCMDRemoveSubscribers

func (*CMD) EncodeCMDUpdateMessageOfUserCursorIfNeed

func (c *CMD) EncodeCMDUpdateMessageOfUserCursorIfNeed(uid string, messageSeq uint32) *CMD

EncodeCMDUpdateMessageOfUserCursorIfNeed EncodeCMDUpdateMessageOfUserCursorIfNeed

func (*CMD) EncodeRemoveAllSubscriber

func (c *CMD) EncodeRemoveAllSubscriber(channelID string, channelType uint8) *CMD

EncodeRemoveAllSubscriber EncodeRemoveAllSubscriber

func (*CMD) EncodeUserToken

func (c *CMD) EncodeUserToken(uid string, deviceFlag lmproto.DeviceFlag, deviceLevel lmproto.DeviceLevel, token string) *CMD

EncodeUserToken EncodeUserToken

func (*CMD) String

func (c *CMD) String() string

type CMDType

type CMDType int

CMDType CMDType

const (
	// CMDUnknown unknown
	CMDUnknown CMDType = iota
	// CMDAppendMessage append message
	CMDAppendMessage
	// CMDAddOrUpdateChannel CMDAddOrUpdateChannel
	CMDAddOrUpdateChannel
	// CMDUpdateUserToken CMDUpdateUserToken
	CMDUpdateUserToken
	// CMDAddSubscribers CMDAddSubscribers
	CMDAddSubscribers
	// CMDRemoveAllSubscriber CMDRemoveAllSubscriber
	CMDRemoveAllSubscriber
	// CMDRemoveSubscribers CMDRemoveSubscribers
	CMDRemoveSubscribers
	// CMDDeleteChannel CMDDeleteChannel
	CMDDeleteChannel
	// CMDDeleteChannelAndClearMessages CMDDeleteChannelAndClearMessages
	CMDDeleteChannelAndClearMessages
	// CMDAppendMessageOfUser CMDAppendMessageOfUser
	CMDAppendMessageOfUser
	// CMDAppendMessageOfNotifyQueue CMDAppendMessageOfNotifyQueue
	CMDAppendMessageOfNotifyQueue
	// CMDRemoveMessagesOfNotifyQueue CMDRemoveMessagesOfNotifyQueue
	CMDRemoveMessagesOfNotifyQueue
	// CMDAddOrUpdateConversations CMDAddOrUpdateConversations
	CMDAddOrUpdateConversations
	// CMDAddDenylist CMDAddDenylist
	CMDAddDenylist
	// CMDRemoveDenylist CMDRemoveDenylist
	CMDRemoveDenylist
	// CMDRemoveAllDenylist CMDRemoveAllDenylist
	CMDRemoveAllDenylist
	// CMDAddAllowlist CMDAddAllowlist
	CMDAddAllowlist
	// CMDRemoveAllowlist CMDRemoveAllowlist
	CMDRemoveAllowlist
	// CMDRemoveAllAllowlist CMDRemoveAllAllowlist
	CMDRemoveAllAllowlist
	// CMDAddNodeInFlightData CMDAddNodeInFlightData
	CMDAddNodeInFlightData
	// CMDClearNodeInFlightData CMDClearNodeInFlightData
	CMDClearNodeInFlightData
	// CMDUpdateMessageOfUserCursorIfNeed CMDUpdateMessageOfUserCursorIfNeed
	CMDUpdateMessageOfUserCursorIfNeed
)

func (CMDType) Int32

func (c CMDType) Int32() int32

Int32 Int32

func (CMDType) String

func (c CMDType) String() string

type Channel

type Channel struct {
	*ChannelInfo

	limlog.Log
	MessageChan chan *Message
	// contains filtered or unexported fields
}

Channel Channel

func NewChannel

func NewChannel(channelInfo *ChannelInfo, l *LiMao) *Channel

NewChannel NewChannel

func (*Channel) AddAllowlist

func (c *Channel) AddAllowlist(uids []string)

AddAllowlist 添加白名单

func (*Channel) AddDenylist

func (c *Channel) AddDenylist(uids []string)

AddDenylist 添加黑名单

func (*Channel) AddSubscriber

func (c *Channel) AddSubscriber(uid string)

AddSubscriber Add subscribers

func (*Channel) Allow

func (c *Channel) Allow(uid string) bool

Allow Whether to allow sending of messages If it is in the white list or not in the black list, it is allowed to send

func (*Channel) GetAllSubscribers

func (c *Channel) GetAllSubscribers() []string

GetAllSubscribers 获取所有订阅者

func (*Channel) IsBlacklist

func (c *Channel) IsBlacklist(uid string) bool

IsBlacklist 是否在黑名单内

func (*Channel) IsSubscriber

func (c *Channel) IsSubscriber(uid string) bool

IsSubscriber 是否已订阅

func (*Channel) LoadData

func (c *Channel) LoadData() error

LoadData load data

func (*Channel) PutMessage

func (c *Channel) PutMessage(m *Message) error

PutMessage put message

func (*Channel) RemoveAllSubscriber

func (c *Channel) RemoveAllSubscriber()

RemoveAllSubscriber 移除所有订阅者

func (*Channel) RemoveAllowlist

func (c *Channel) RemoveAllowlist(uids []string)

RemoveAllowlist 移除白名单

func (*Channel) RemoveDenylist

func (c *Channel) RemoveDenylist(uids []string)

RemoveDenylist 移除黑名单

func (*Channel) RemoveSubscriber

func (c *Channel) RemoveSubscriber(uid string)

RemoveSubscriber 移除订阅者

func (*Channel) SetAllowlist

func (c *Channel) SetAllowlist(uids []string)

SetAllowlist SetAllowlist

func (*Channel) SetDenylist

func (c *Channel) SetDenylist(uids []string)

SetDenylist SetDenylist

type ChannelAPI

type ChannelAPI struct {
	limlog.Log
	// contains filtered or unexported fields
}

ChannelAPI ChannelAPI

func NewChannelAPI

func NewChannelAPI(lim *LiMao) *ChannelAPI

NewChannelAPI 创建API

func (*ChannelAPI) Route

func (ch *ChannelAPI) Route(r *lmhttp.LMHttp)

Route Route

type ChannelCreateReq

type ChannelCreateReq struct {
	ChannelInfoReq
	Subscribers []string `json:"subscribers"` // 订阅者
}

ChannelCreateReq 频道创建请求

func (ChannelCreateReq) Check

func (r ChannelCreateReq) Check() error

Check 检查请求参数

type ChannelDeleteReq

type ChannelDeleteReq struct {
	ChannelID   string `json:"channel_id"`   // 频道ID
	ChannelType uint8  `json:"channel_type"` // 频道类型
}

ChannelDeleteReq 删除频道请求

type ChannelInfo

type ChannelInfo struct {
	ChannelID   string `json:"-"`
	ChannelType uint8  `json:"-"`
	Mute        bool   `json:"mute"`   // Whether to mute
	Parent      string `json:"parent"` // Parent channel
}

ChannelInfo ChannelInfo

func NewChannelInfo

func NewChannelInfo(channelID string, channelType uint8) *ChannelInfo

NewChannelInfo NewChannelInfo

func (*ChannelInfo) ToMap

func (c *ChannelInfo) ToMap() map[string]interface{}

ToMap ToMap

type ChannelInfoReq

type ChannelInfoReq struct {
	ChannelID   string `json:"channel_id"`   // 频道ID
	ChannelType uint8  `json:"channel_type"` // 频道类型
	Bind        string `json:"bind"`         // 绑定的频道(如果有值标示 这个频道的成员将使用bind对应频道的成员)
	Forbidden   int    `json:"forbidden"`    // 是否禁言
}

ChannelInfoReq ChannelInfoReq

type ChannelManager

type ChannelManager struct {
	limlog.Log
	// contains filtered or unexported fields
}

ChannelManager 频道管理

func NewChannelManager

func NewChannelManager(l *LiMao) *ChannelManager

NewChannelManager 创建一个频道管理者

func (*ChannelManager) CreateOrUpdateChannel

func (cm *ChannelManager) CreateOrUpdateChannel(channel *Channel) error

CreateOrUpdateChannel 创建或更新频道

func (*ChannelManager) CreateOrUpdatePersonChannel

func (cm *ChannelManager) CreateOrUpdatePersonChannel(uid string) error

CreateOrUpdatePersonChannel 创建或更新个人频道

func (*ChannelManager) CreateTmpChannel

func (cm *ChannelManager) CreateTmpChannel(channelID string, channelType uint8, subscribers []string) error

CreateTmpChannel 创建临时频道

func (*ChannelManager) DeleteChannel

func (cm *ChannelManager) DeleteChannel(channelID string, channelType uint8) error

DeleteChannel 删除频道

func (*ChannelManager) DeleteChannelFromCache

func (cm *ChannelManager) DeleteChannelFromCache(channelID string, channelType uint8)

DeleteChannelFromCache DeleteChannelFromCache

func (*ChannelManager) GetChannel

func (cm *ChannelManager) GetChannel(channelID string, channelType uint8) (*Channel, error)

GetChannel 获取频道

func (*ChannelManager) GetPersonChannel

func (cm *ChannelManager) GetPersonChannel(channelID string, channelType uint8) (*Channel, error)

GetPersonChannel 创建临时频道

func (*ChannelManager) GetTmpChannel

func (cm *ChannelManager) GetTmpChannel(channelID string, channelType uint8) (*Channel, error)

GetTmpChannel 获取临时频道

type Client

type Client struct {
	limlog.Log
	// contains filtered or unexported fields
}

Client 客户端

func NewClient

func NewClient(uid string, deviceFlag lmproto.DeviceFlag, deviceLevel lmproto.DeviceLevel, conn limnet.Conn, aesKey, aesIV string, l *LiMao) *Client

NewClient 创建一个新的客户端

func (*Client) Close

func (c *Client) Close() error

Close Close

func (*Client) GetID

func (c *Client) GetID() int64

GetID GetID

func (*Client) String

func (c *Client) String() string

func (*Client) Version

func (c *Client) Version() uint8

Version Version

func (*Client) Write

func (c *Client) Write(data []byte) error

func (*Client) WritePacket

func (c *Client) WritePacket(packet interface{})

WritePacket 写包

type ClientManager

type ClientManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ClientManager 客户端管理

func NewClientManager

func NewClientManager() *ClientManager

NewClientManager 创建一个默认的客户端管理者

func (*ClientManager) Add

func (m *ClientManager) Add(client *Client)

Add 添加客户端

func (*ClientManager) Get

func (m *ClientManager) Get(id int64) *Client

Get 获取客户端

func (*ClientManager) GetClientWith

func (m *ClientManager) GetClientWith(uid string, deviceFlag lmproto.DeviceFlag) *Client

GetClientWith 查询设备

func (*ClientManager) GetClientsWithUID

func (m *ClientManager) GetClientsWithUID(uid string) []*Client

GetClientsWithUID 通过用户uid获取客户端集合

func (*ClientManager) GetOnlineUIDs

func (m *ClientManager) GetOnlineUIDs(uids []string) []string

GetOnlineUIDs 传一批uids 返回在线的uids

func (*ClientManager) Remove

func (m *ClientManager) Remove(id int64)

Remove 移除客户端

type ClusterStorage

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

ClusterStorage ClusterStorage

func (*ClusterStorage) AddAllowlist

func (c *ClusterStorage) AddAllowlist(channelID string, channelType uint8, uids []string) error

AddAllowlist 添加白名单

func (*ClusterStorage) AddDenylist

func (c *ClusterStorage) AddDenylist(channelID string, channelType uint8, uids []string) error

AddDenylist AddDenylist

func (*ClusterStorage) AddNodeInFlightData

func (c *ClusterStorage) AddNodeInFlightData(data []*db.NodeInFlightDataModel) error

AddNodeInFlightData 添加节点inflight数据

func (*ClusterStorage) AddOrUpdateChannel

func (c *ClusterStorage) AddOrUpdateChannel(channelInfo *ChannelInfo) error

AddOrUpdateChannel AddOrUpdateChannel

func (*ClusterStorage) AddOrUpdateConversations

func (c *ClusterStorage) AddOrUpdateConversations(uid string, conversations []*db.Conversation) error

AddOrUpdateConversations AddOrUpdateConversations

func (*ClusterStorage) AddSubscribers

func (c *ClusterStorage) AddSubscribers(channelID string, channelType uint8, uids []string) error

AddSubscribers AddSubscribers

func (*ClusterStorage) AppendMessage

func (c *ClusterStorage) AppendMessage(m *db.Message) error

AppendMessage AppendMessage

func (*ClusterStorage) AppendMessageOfNotifyQueue

func (c *ClusterStorage) AppendMessageOfNotifyQueue(m *db.Message) error

AppendMessageOfNotifyQueue AppendMessageOfNotifyQueue

func (*ClusterStorage) AppendMessageOfUser

func (c *ClusterStorage) AppendMessageOfUser(m *db.Message) error

AppendMessageOfUser AppendMessageOfUser

func (*ClusterStorage) ClearNodeInFlightData

func (c *ClusterStorage) ClearNodeInFlightData() error

ClearNodeInFlightData 清除inflight数据

func (*ClusterStorage) DeleteChannel

func (c *ClusterStorage) DeleteChannel(channelID string, channelType uint8) error

DeleteChannel DeleteChannel

func (*ClusterStorage) DeleteChannelAndClearMessages

func (c *ClusterStorage) DeleteChannelAndClearMessages(channelID string, channelType uint8) error

DeleteChannelAndClearMessages DeleteChannelAndClearMessages

func (*ClusterStorage) RemoveAllAllowlist

func (c *ClusterStorage) RemoveAllAllowlist(channelID string, channelType uint8) error

RemoveAllAllowlist 移除指定频道的所有白名单

func (*ClusterStorage) RemoveAllDenylist

func (c *ClusterStorage) RemoveAllDenylist(channelID string, channelType uint8) error

RemoveAllDenylist RemoveAllDenylist

func (*ClusterStorage) RemoveAllSubscriber

func (c *ClusterStorage) RemoveAllSubscriber(channelID string, channelType uint8) error

RemoveAllSubscriber RemoveAllSubscriber

func (*ClusterStorage) RemoveAllowlist

func (c *ClusterStorage) RemoveAllowlist(channelID string, channelType uint8, uids []string) error

RemoveAllowlist 移除白名单

func (*ClusterStorage) RemoveDenylist

func (c *ClusterStorage) RemoveDenylist(channelID string, channelType uint8, uids []string) error

RemoveDenylist RemoveDenylist

func (*ClusterStorage) RemoveMessagesOfNotifyQueue

func (c *ClusterStorage) RemoveMessagesOfNotifyQueue(messageIDs []int64) error

RemoveMessagesOfNotifyQueue RemoveMessagesOfNotifyQueue

func (*ClusterStorage) RemoveSubscribers

func (c *ClusterStorage) RemoveSubscribers(channelID string, channelType uint8, uids []string) error

RemoveSubscribers RemoveSubscribers

func (*ClusterStorage) UpdateMessageOfUserCursorIfNeed

func (c *ClusterStorage) UpdateMessageOfUserCursorIfNeed(uid string, offset uint32) error

UpdateMessageOfUserCursorIfNeed UpdateMessageOfUserCursorIfNeed

func (*ClusterStorage) UpdateUserToken

func (c *ClusterStorage) UpdateUserToken(uid string, deviceFlag lmproto.DeviceFlag, deviceLevel lmproto.DeviceLevel, token string) error

UpdateUserToken UpdateUserToken

type ConnStatus

type ConnStatus int

ConnStatus 连接状态

const (
	// ConnStatusNoAuth 未认证
	ConnStatusNoAuth ConnStatus = iota
	// ConnStatusAuthed 已认证
	ConnStatusAuthed
)

func (ConnStatus) Int

func (c ConnStatus) Int() int

Int Int

type ConversationAPI

type ConversationAPI struct {
	limlog.Log
	// contains filtered or unexported fields
}

ConversationAPI ConversationAPI

func NewConversationAPI

func NewConversationAPI(lim *LiMao) *ConversationAPI

NewConversationAPI NewConversationAPI

func (*ConversationAPI) Route

func (s *ConversationAPI) Route(r *lmhttp.LMHttp)

Route 路由

type ConversationManager

type ConversationManager struct {
	limlog.Log
	// contains filtered or unexported fields
}

ConversationManager ConversationManager

func NewConversationManager

func NewConversationManager(l *LiMao) *ConversationManager

NewConversationManager NewConversationManager

func (*ConversationManager) DeleteConversation

func (cm *ConversationManager) DeleteConversation(uids []string, channelID string, channelType uint8) error

DeleteConversation 删除最近会话

func (*ConversationManager) FlushConversations

func (cm *ConversationManager) FlushConversations()

FlushConversations 同步最近会话

func (*ConversationManager) GetConversations

func (cm *ConversationManager) GetConversations(uid string, version int64) []*db.Conversation

GetConversations GetConversations

func (*ConversationManager) PushMessage

func (cm *ConversationManager) PushMessage(message *Message, subscribers []string)

PushMessage PushMessage

func (*ConversationManager) SetConversationUnread

func (cm *ConversationManager) SetConversationUnread(uid string, channelID string, channelType uint8, unread int) error

SetConversationUnread set unread data from conversation

func (*ConversationManager) Start

func (cm *ConversationManager) Start()

Start Start

func (*ConversationManager) Stop

func (cm *ConversationManager) Stop()

Stop Stop

type Datasource

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

Datasource Datasource

func (*Datasource) GetBlacklist

func (d *Datasource) GetBlacklist(channelID string, channelType uint8) ([]string, error)

GetBlacklist 获取频道的黑名单

func (*Datasource) GetSubscribers

func (d *Datasource) GetSubscribers(channelID string, channelType uint8) ([]string, error)

GetSubscribers 获取频道的订阅者

func (*Datasource) GetSystemUIDs

func (d *Datasource) GetSystemUIDs() ([]string, error)

GetSystemUIDs 获取系统账号

func (*Datasource) GetWhitelist

func (d *Datasource) GetWhitelist(channelID string, channelType uint8) ([]string, error)

GetWhitelist 获取频道的白明单

type DefaultStorage

type DefaultStorage struct {
	StorageReader
	StorageWriter
	// contains filtered or unexported fields
}

DefaultStorage DefaultStorage

func (*DefaultStorage) GetFileStorage

func (d *DefaultStorage) GetFileStorage() *FileStorage

GetFileStorage GetFileStorage

type Event

type Event struct {
	Event string      `json:"event"` // 事件标示
	Data  interface{} `json:"data"`  // 事件数据
}

Event Event

func (*Event) String

func (e *Event) String() string

type FileStorage

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

FileStorage FileStorage

func NewFileStorage

func NewFileStorage(l *LiMao) *FileStorage

NewFileStorage NewFileStorage

func (*FileStorage) AddAllowlist

func (f *FileStorage) AddAllowlist(channelID string, channelType uint8, uids []string) error

AddAllowlist 添加白名单

func (*FileStorage) AddDenylist

func (f *FileStorage) AddDenylist(channelID string, channelType uint8, uids []string) error

AddDenylist AddDenylist

func (*FileStorage) AddNodeInFlightData

func (f *FileStorage) AddNodeInFlightData(data []*db.NodeInFlightDataModel) error

AddNodeInFlightData 添加节点inflight数据

func (*FileStorage) AddOrUpdateChannel

func (f *FileStorage) AddOrUpdateChannel(channelInfo *ChannelInfo) error

AddOrUpdateChannel AddOrUpdateChannel

func (*FileStorage) AddOrUpdateConversations

func (f *FileStorage) AddOrUpdateConversations(uid string, conversations []*db.Conversation) error

AddOrUpdateConversations AddOrUpdateConversations

func (*FileStorage) AddSubscribers

func (f *FileStorage) AddSubscribers(channelID string, channelType uint8, uids []string) error

AddSubscribers AddSubscribers

func (*FileStorage) AppendMessage

func (f *FileStorage) AppendMessage(m *db.Message) error

AppendMessage AppendMessage

func (*FileStorage) AppendMessageOfNotifyQueue

func (f *FileStorage) AppendMessageOfNotifyQueue(m *db.Message) error

AppendMessageOfNotifyQueue AppendMessageOfNotifyQueue

func (*FileStorage) AppendMessageOfUser

func (f *FileStorage) AppendMessageOfUser(m *db.Message) error

AppendMessageOfUser AppendMessageOfUser

func (*FileStorage) BackupSlots

func (f *FileStorage) BackupSlots(slots []byte, w io.Writer) error

BackupSlots BackupSlots

func (*FileStorage) ClearNodeInFlightData

func (f *FileStorage) ClearNodeInFlightData() error

ClearNodeInFlightData 清除inflight数据

func (*FileStorage) Close

func (f *FileStorage) Close() error

Close Close

func (*FileStorage) DeleteChannel

func (f *FileStorage) DeleteChannel(channelID string, channelType uint8) error

DeleteChannel DeleteChannel

func (*FileStorage) DeleteChannelAndClearMessages

func (f *FileStorage) DeleteChannelAndClearMessages(channelID string, channelType uint8) error

DeleteChannelAndClearMessages DeleteChannelAndClearMessages

func (*FileStorage) ExistChannel

func (f *FileStorage) ExistChannel(channelID string, channelType uint8) (bool, error)

ExistChannel ExistChannel

func (*FileStorage) GetAllowlist

func (f *FileStorage) GetAllowlist(channelID string, channelType uint8) ([]string, error)

GetAllowlist 获取白名单

func (*FileStorage) GetChannel

func (f *FileStorage) GetChannel(channelID string, channelType uint8) (*ChannelInfo, error)

GetChannel GetChannel

func (*FileStorage) GetConversations

func (f *FileStorage) GetConversations(uid string) ([]*db.Conversation, error)

GetConversations GetConversations

func (*FileStorage) GetDenylist

func (f *FileStorage) GetDenylist(channelID string, channelType uint8) ([]string, error)

GetDenylist GetDenylist

func (*FileStorage) GetFileStorage

func (f *FileStorage) GetFileStorage() *FileStorage

GetFileStorage GetFileStorage

func (*FileStorage) GetLastMessages

func (f *FileStorage) GetLastMessages(channelID string, channelType uint8, endOffset uint32, limit uint64) ([]*db.Message, error)

GetLastMessages GetLastMessages

func (*FileStorage) GetMessage

func (f *FileStorage) GetMessage(channelID string, channelType uint8, messageSeq uint32) (*db.Message, error)

GetMessage GetMessage

func (*FileStorage) GetMessages

func (f *FileStorage) GetMessages(channelID string, channelType uint8, offset uint32, limit uint64) ([]*db.Message, error)

GetMessages GetMessages

func (*FileStorage) GetMessagesOfNotifyQueue

func (f *FileStorage) GetMessagesOfNotifyQueue(count int) ([]*db.Message, error)

GetMessagesOfNotifyQueue GetMessagesOfNotifyQueue

func (*FileStorage) GetMessagesOfUser

func (f *FileStorage) GetMessagesOfUser(uid string, offset uint32, limit uint64) ([]*db.Message, error)

GetMessagesOfUser GetMessagesOfUser

func (*FileStorage) GetMessagesWithOptions

func (f *FileStorage) GetMessagesWithOptions(channelID string, channelType uint8, offsetMessageSeq uint32, limit uint64, reverse bool, endMessageSeq uint32) ([]*db.Message, error)

GetMessagesWithOptions GetMessagesWithOptions

func (*FileStorage) GetMetaData

func (f *FileStorage) GetMetaData() (uint64, error)

GetMetaData GetMetaData

func (*FileStorage) GetNextMessageSeq

func (f *FileStorage) GetNextMessageSeq(channelID string, channelType uint8) (uint32, error)

GetNextMessageSeq GetNextMessageSeq

func (*FileStorage) GetNodeInFlightData

func (f *FileStorage) GetNodeInFlightData() ([]*db.NodeInFlightDataModel, error)

GetNodeInFlightData GetNodeInFlightData

func (*FileStorage) GetSubscribers

func (f *FileStorage) GetSubscribers(channelID string, channelType uint8) ([]string, error)

GetSubscribers GetSubscribers

func (*FileStorage) GetUserNextMessageSeq

func (f *FileStorage) GetUserNextMessageSeq(uid string) (uint32, error)

GetUserNextMessageSeq GetUserNextMessageSeq

func (*FileStorage) GetUserToken

func (f *FileStorage) GetUserToken(uid string, deviceFlag lmproto.DeviceFlag) (string, lmproto.DeviceLevel, error)

GetUserToken GetUserToken

func (*FileStorage) RecoverSlotBackup

func (f *FileStorage) RecoverSlotBackup(reader io.Reader) error

RecoverSlotBackup 恢复备份

func (*FileStorage) RemoveAllAllowlist

func (f *FileStorage) RemoveAllAllowlist(channelID string, channelType uint8) error

RemoveAllAllowlist 移除指定频道的所有白名单

func (*FileStorage) RemoveAllDenylist

func (f *FileStorage) RemoveAllDenylist(channelID string, channelType uint8) error

RemoveAllDenylist RemoveAllDenylist

func (*FileStorage) RemoveAllSubscriber

func (f *FileStorage) RemoveAllSubscriber(channelID string, channelType uint8) error

RemoveAllSubscriber RemoveAllSubscriber

func (*FileStorage) RemoveAllowlist

func (f *FileStorage) RemoveAllowlist(channelID string, channelType uint8, uids []string) error

RemoveAllowlist 移除白名单

func (*FileStorage) RemoveDenylist

func (f *FileStorage) RemoveDenylist(channelID string, channelType uint8, uids []string) error

RemoveDenylist RemoveDenylist

func (*FileStorage) RemoveMessagesOfNotifyQueue

func (f *FileStorage) RemoveMessagesOfNotifyQueue(messageIDs []int64) error

RemoveMessagesOfNotifyQueue RemoveMessagesOfNotifyQueue

func (*FileStorage) RemoveSubscribers

func (f *FileStorage) RemoveSubscribers(channelID string, channelType uint8, uids []string) error

RemoveSubscribers RemoveSubscribers

func (*FileStorage) SaveMetaData

func (f *FileStorage) SaveMetaData(appliIndex uint64) error

SaveMetaData SaveMetaData

func (*FileStorage) UpdateMessageOfUserCursorIfNeed

func (f *FileStorage) UpdateMessageOfUserCursorIfNeed(uid string, offset uint32) error

UpdateMessageOfUserCursorIfNeed UpdateMessageOfUserCursorIfNeed

func (*FileStorage) UpdateUserToken

func (f *FileStorage) UpdateUserToken(uid string, deviceFlag lmproto.DeviceFlag, deviceLevel lmproto.DeviceLevel, token string) error

UpdateUserToken UpdateUserToken

type IClusterManager

type IClusterManager interface {
	Start() error
	Stop() error
	IsLeader() bool
	GetNode(value string) *lmproxyproto.Node
	GetNodeWithID(id int32) *lmproxyproto.Node
	SyncPropose(ctx context.Context, data []byte) error
	SendCMD(cmd *lmproxyproto.CMD) error
	GetClusterConfig() *lmproxyproto.ClusterConfig
	LeaderUpdated(f func(leaderID uint32))
}

IClusterManager IClusterManager

type IDatasource

type IDatasource interface {
	// 获取订阅者
	GetSubscribers(channelID string, channelType uint8) ([]string, error)
	// 获取黑名单
	GetBlacklist(channelID string, channelType uint8) ([]string, error)
	// 获取白名单
	GetWhitelist(channelID string, channelType uint8) ([]string, error)
	// 获取系统账号的uid集合 系统账号可以给任何人发消息
	GetSystemUIDs() ([]string, error)
}

IDatasource 数据源第三方应用可以提供

func NewDatasource

func NewDatasource(l *LiMao) IDatasource

NewDatasource 创建一个数据源

type LiMao

type LiMao struct {
	limlog.Log

	DoCommand func(cmd *CMD) error // 执行命令(分布式副本之间执行命令)
	// contains filtered or unexported fields
}

LiMao core

func New

func New(opts *Options) *LiMao

New New

func NewTestLiMao

func NewTestLiMao(ots ...*Options) *LiMao

NewTestLiMao NewTestLiMao

func (*LiMao) DeliveryMsg

func (l *LiMao) DeliveryMsg(msg *Message, subscriberSeqMap map[string]uint32, subscribers ...string)

DeliveryMsg 投递消息

func (*LiMao) GetConversationManager

func (l *LiMao) GetConversationManager() *ConversationManager

GetConversationManager GetConversationManager

func (*LiMao) GetOptions

func (l *LiMao) GetOptions() *Options

GetOptions GetOptions

func (*LiMao) GetStore

func (l *LiMao) GetStore() Storage

GetStore GetStore

func (*LiMao) OnClose

func (l *LiMao) OnClose(c limnet.Conn)

OnClose 连接关闭

func (*LiMao) OnConnect

func (l *LiMao) OnConnect(c limnet.Conn)

OnConnect establish connection

func (*LiMao) OnPacket

func (l *LiMao) OnPacket(c limnet.Conn, data []byte) (out []byte)

OnPacket Packet received

func (*LiMao) Schedule

func (l *LiMao) Schedule(interval time.Duration, f func())

Schedule 延迟任务

func (*LiMao) Start

func (l *LiMao) Start(startCompleteC ...chan struct{}) error

Start Start

func (*LiMao) Stop

func (l *LiMao) Stop() error

Stop Stop

func (*LiMao) TriggerEvent

func (l *LiMao) TriggerEvent(event *Event)

TriggerEvent 触发事件

type Message

type Message struct {
	lmproto.RecvPacket
	ToUID       string   // 接受者
	Subscribers []string // 订阅者 如果此字段有值 则表示消息只发送给指定的订阅者
	// contains filtered or unexported fields
}

Message 消息对象

func (*Message) String

func (m *Message) String() string

type MessageAPI

type MessageAPI struct {
	limlog.Log
	// contains filtered or unexported fields
}

MessageAPI MessageAPI

func NewMessageAPI

func NewMessageAPI(lim *LiMao) *MessageAPI

NewMessageAPI NewMessageAPI

func (*MessageAPI) Route

func (m *MessageAPI) Route(r *lmhttp.LMHttp)

Route route

type MessageHeader

type MessageHeader struct {
	NoPersist int `json:"no_persist"` // Is it not persistent
	RedDot    int `json:"red_dot"`    // Whether to show red dot
	SyncOnce  int `json:"sync_once"`  // This message is only synchronized or consumed once
}

MessageHeader Message header

type MessageResp

type MessageResp struct {
	Header       MessageHeader `json:"header"`        // 消息头
	Setting      uint8         `json:"setting"`       // 设置
	MessageID    int64         `json:"message_id"`    // 服务端的消息ID(全局唯一)
	MessageIDStr string        `json:"message_idstr"` // 服务端的消息ID(全局唯一)
	ClientMsgNo  string        `json:"client_msg_no"` // 客户端消息唯一编号
	MessageSeq   uint32        `json:"message_seq"`   // 消息序列号 (用户唯一,有序递增)
	FromUID      string        `json:"from_uid"`      // 发送者UID
	ChannelID    string        `json:"channel_id"`    // 频道ID
	ChannelType  uint8         `json:"channel_type"`  // 频道类型
	Timestamp    int32         `json:"timestamp"`     // 服务器消息时间戳(10位,到秒)
	Payload      []byte        `json:"payload"`       // 消息内容
}

MessageResp 消息返回

type MessageRespSlice

type MessageRespSlice []*MessageResp

MessageRespSlice MessageRespSlice

func (MessageRespSlice) Len

func (m MessageRespSlice) Len() int

func (MessageRespSlice) Less

func (m MessageRespSlice) Less(i, j int) bool

func (MessageRespSlice) Swap

func (m MessageRespSlice) Swap(i, j int)

type MessageSendReq

type MessageSendReq struct {
	Header      MessageHeader `json:"header"`        // 消息头
	ClientMsgNo string        `json:"client_msg_no"` // 客户端消息编号(相同编号,客户端只会显示一条)
	FromUID     string        `json:"from_uid"`      // 发送者UID
	ChannelID   string        `json:"channel_id"`    // 频道ID
	ChannelType uint8         `json:"channel_type"`  // 频道类型
	Subscribers []string      `json:"subscribers"`   // 订阅者 如果此字段有值,表示消息只发给指定的订阅者
	Payload     []byte        `json:"payload"`       // 消息内容
}

MessageSendReq 消息发送请求

func (MessageSendReq) Check

func (m MessageSendReq) Check() error

Check 检查输入

type Monitor

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

Monitor 监控

func NewMonitor

func NewMonitor(l *LiMao) *Monitor

NewMonitor 创建监控对象

func (*Monitor) ConnDec

func (m *Monitor) ConnDec()

ConnDec 连接递减

func (*Monitor) ConnInc

func (m *Monitor) ConnInc()

ConnInc 连接递增

func (*Monitor) DownstreamAdd

func (m *Monitor) DownstreamAdd(count int)

DownstreamAdd 上行流量增加

func (*Monitor) DownstreamPacketInc

func (m *Monitor) DownstreamPacketInc()

DownstreamPacketInc 上行包递增

func (*Monitor) Start

func (m *Monitor) Start()

Start 开始

func (*Monitor) UpstreamAdd

func (m *Monitor) UpstreamAdd(count int)

UpstreamAdd 上行流量增加

func (*Monitor) UpstreamPacketInc

func (m *Monitor) UpstreamPacketInc()

UpstreamPacketInc 上行包递增

type NodeInFlightData

type NodeInFlightData struct {
	db.NodeInFlightDataModel
	// contains filtered or unexported fields
}

NodeInFlightData NodeInFlightData

type NodeInFlightQueue

type NodeInFlightQueue struct {
	limlog.Log
	// contains filtered or unexported fields
}

NodeInFlightQueue 正在投递的节点消息的队列

func NewNodeInFlightQueue

func NewNodeInFlightQueue(l *LiMao) *NodeInFlightQueue

NewNodeInFlightQueue NewNodeInFlightQueue

func (*NodeInFlightQueue) Start

func (n *NodeInFlightQueue) Start()

Start 开始运行重试

func (*NodeInFlightQueue) Stop

func (n *NodeInFlightQueue) Stop()

Stop Stop

type NodeRemoteCall

type NodeRemoteCall struct {
	limlog.Log
	// contains filtered or unexported fields
}

NodeRemoteCall NodeRemoteCall

func NewNodeRemoteCall

func NewNodeRemoteCall(l *LiMao) *NodeRemoteCall

NewNodeRemoteCall NewNodeRemoteCall

func (*NodeRemoteCall) ForwardRecvPacket

func (n *NodeRemoteCall) ForwardRecvPacket(req *rpc.ForwardRecvPacketReq, nodeID int32) error

ForwardRecvPacket 转发消息

func (*NodeRemoteCall) ForwardSendPacket

func (n *NodeRemoteCall) ForwardSendPacket(req *rpc.ForwardSendPacketReq, nodeID int32) (*rpc.ForwardSendPacketResp, error)

ForwardSendPacket 转发发送包

func (*NodeRemoteCall) GetChannelMessageSeq

func (n *NodeRemoteCall) GetChannelMessageSeq(channelID string, channelType uint8, nodeID int32) (uint32, error)

GetChannelMessageSeq 获取频道消息序号

func (*NodeRemoteCall) GetSubscribers

func (n *NodeRemoteCall) GetSubscribers(channelID string, channelType uint8, nodeID int32) ([]string, error)

GetSubscribers 获取订阅者

func (*NodeRemoteCall) SendCMD

func (n *NodeRemoteCall) SendCMD(ctx context.Context, nodeID int32, cmd *rpc.CMDReq) (*rpc.CMDResp, error)

SendCMD 发送cmd给指定节点

type OnlineStatusWebhook

type OnlineStatusWebhook struct {
	limlog.Log
	// contains filtered or unexported fields
}

OnlineStatusWebhook 在线状态webhook

func NewOnlineStatusWebhook

func NewOnlineStatusWebhook(l *LiMao) *OnlineStatusWebhook

NewOnlineStatusWebhook NewOnlineStatusWebhook

func (*OnlineStatusWebhook) Offline

func (w *OnlineStatusWebhook) Offline(uid string, deviceFlag lmproto.DeviceFlag)

Offline 用户离线

func (*OnlineStatusWebhook) Online

func (w *OnlineStatusWebhook) Online(uid string, deviceFlag lmproto.DeviceFlag)

Online 用户在线

type Options

type Options struct {
	NodeID                     int32            `env:"nodeID"` // node id < 1024
	Addr                       string           `env:"addr"`   // server addr (Internet address)
	WSAddr                     string           `env:"wsAddr"` // websocket listening address
	HTTPAddr                   string           `env:"httpAddr"`
	Mode                       string           `env:"mode"`         // mode
	NodeRaftAddr               string           `env:"nodeRaftAddr"` // node address IP:PORT example127.0.0.1:6000
	NodeAPIAddr                string           `env:"nodeAPIAddr"`  // 节点API地址 例如: http://127.0.0.1:1516
	NodeRPCAddr                string           `env:"nodeRPCAddr"`  // 节点rpc通讯地址,主要用来转发消息
	NodeTCPAddr                string           `env:"nodeTCPAddr"`  // 节点的TCP地址 对外公开,APP端长连接通讯
	DataDir                    string           `env:"dataDir"`
	Proxy                      string           `env:"proxy"` // proxy server addr (If there is no value, stand-alone mode)
	ElectionTicks              int              `env:"electionTicks"`
	ProxyTickPer               duration         `env:"proxyTickPer"`
	SlotCount                  int              `env:"slotCount"` // slot count
	SegmentMaxBytes            int64            `env:"segmentMaxBytes"`
	CMDSendTimeout             duration         `env:"cmdSendTimeout"`
	EventPoolSize              int              // 事件协程池大小
	MessagePoolSize            int              `env:"messagePoolSize"` // The size of the coroutine pool for processing packets
	DeliveryMsgPoolSize        int              `env:"deliveryMsgPoolSize"`
	MsgTimeout                 duration         `env:"msgTimeout"`          // Message sending timeout time, after this time it will try again
	TimeoutScanInterval        duration         `env:"timeoutScanInterval"` //  Message timeout queue scan frequency
	Proto                      lmproto.Protocol // protocol
	Webhook                    string           `env:"webhook"`                   // The URL address of the third party that receives the message notification
	MessageNotifyMaxCount      int              `env:"messageNotifyMaxCount"`     // Maximum number of notifications received each time
	MessageNotifyScanInterval  duration         `env:"messageNotifyScanInterval"` // 消息通知间隔
	TimingWheelTick            duration         // The time-round training interval must be 1ms or more
	TimingWheelSize            int64            // Time wheel size
	MaxMessagePerSecond        int              `env:"maxMessagePerSecond"` //Number of messages per second
	TmpChannelSuffix           string           // Temporary channel suffix
	CreateIfChannelNotExist    bool             // If the channel does not exist, whether to create it automatically
	Datasource                 string           `env:"datasource"`               // Source address of external data source
	ConversationSyncInterval   duration         `env:"conversationSaveInterval"` // How often to sync recent conversations
	ConversationSyncOnce       int              `env:"conversationSaveOnce"`     // When how many recent sessions have not been saved, save once
	ConversationOfUserMaxCount int              `env:"conversationMaxCount"`     //The maximum number of user conversation

	NodeRPCMsgTimeout          duration // 节点消息发送超时时间,超过这时间将重试
	NodeRPCTimeoutScanInterval duration // 节点之间调用RPC消息超时队列扫描频率
	IsCluster                  bool     // 是否开启分布式
	SlotBackupDir              string   // slot备份目录
}

Options IM配置信息

func NewOptions

func NewOptions() *Options

NewOptions NewOptions

func NewTestOptions

func NewTestOptions() *Options

NewTestOptions NewTestOptions

func (*Options) HasDatasource

func (o *Options) HasDatasource() bool

HasDatasource 是否有配置数据源

func (*Options) IsFakeChannel

func (o *Options) IsFakeChannel(channelID string) bool

IsFakeChannel 是fake频道

func (*Options) IsTmpChannel

func (o *Options) IsTmpChannel(channelID string) bool

IsTmpChannel 是否是临时频道

func (*Options) Load

func (o *Options) Load(fpath ...string)

Load 从配置文件加载配置

func (*Options) WebhookOn

func (o *Options) WebhookOn() bool

WebhookOn WebhookOn

type PacketHandler

type PacketHandler struct {
	limlog.Log
	// contains filtered or unexported fields
}

PacketHandler PacketHandler

func NewPacketHandler

func NewPacketHandler(l *LiMao) *PacketHandler

NewPacketHandler 创建处理者

func (*PacketHandler) HandleSend

func (s *PacketHandler) HandleSend(c *Client, sendPacket *lmproto.SendPacket)

HandleSend HandleSend

func (*PacketHandler) OnGetChannelMessageSeq

func (s *PacketHandler) OnGetChannelMessageSeq(channelID string, channelType uint8) (uint32, error)

OnGetChannelMessageSeq OnGetChannelMessageSeq

func (*PacketHandler) OnGetSubscribers

func (s *PacketHandler) OnGetSubscribers(channelID string, channelType uint8) ([]string, error)

OnGetSubscribers 其他节点获取订阅者

func (*PacketHandler) OnRecvPacket

func (s *PacketHandler) OnRecvPacket(deviceFlag lmproto.DeviceFlag, recvPacket *lmproto.RecvPacket, users []string) error

OnRecvPacket 其他服务端节点发送过来的接受包

func (*PacketHandler) OnSendPacket

func (s *PacketHandler) OnSendPacket(fromUID string, deviceFlag lmproto.DeviceFlag, sendPacket *lmproto.SendPacket) (messageID int64, messageSeq uint32, reasonCode lmproto.ReasonCode, err error)

OnSendPacket 其他服务端节点发送过来的包

type Queue

type Queue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Queue Queue

func NewQueue

func NewQueue() *Queue

NewQueue 创建队列

func (*Queue) Close

func (e *Queue) Close()

Close Close

func (*Queue) Len

func (e *Queue) Len() int

Len 获取队列长度

func (*Queue) Pop

func (e *Queue) Pop() (v interface{})

Pop 取出队列,(阻塞模式)

func (*Queue) Push

func (e *Queue) Push(v interface{})

Push Push

func (*Queue) TryPop

func (e *Queue) TryPop() (v interface{}, ok bool)

TryPop 试着取出队列(非阻塞模式)返回ok == false 表示空

func (*Queue) Wait

func (e *Queue) Wait()

Wait 等待队列消费完成

type RetryQueue

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

RetryQueue 重试队列

func NewRetryQueue

func NewRetryQueue(l *LiMao) *RetryQueue

NewRetryQueue NewRetryQueue

func (*RetryQueue) Start

func (r *RetryQueue) Start()

Start 开始运行重试

type State

type State int32

State State

const (
	// StateWaitCluster StateWaitCluster
	StateWaitCluster State = iota
	// StateClustered StateClustered
	StateClustered
)

type Storage

type Storage interface {
	StorageReader
	StorageWriter

	GetFileStorage() *FileStorage
}

Storage Storage

func NewStorage

func NewStorage(l *LiMao) Storage

NewStorage NewStorage

type StorageReader

type StorageReader interface {
	SaveMetaData(appliIndex uint64) error
	GetMetaData() (uint64, error)
	GetUserToken(uid string, deviceFlag lmproto.DeviceFlag) (string, lmproto.DeviceLevel, error)

	// ---------- channel ----------
	GetChannel(channelID string, channelType uint8) (*ChannelInfo, error)
	ExistChannel(channelID string, channelType uint8) (bool, error)

	GetSubscribers(channelID string, channelType uint8) ([]string, error)

	// ---------- denylist ----------
	GetDenylist(channelID string, channelType uint8) ([]string, error)

	// ---------- allowlist ----------
	GetAllowlist(channelID string, channelType uint8) ([]string, error)

	// ---------- message ----------
	GetNextMessageSeq(channelID string, channelType uint8) (uint32, error)
	GetUserNextMessageSeq(uid string) (uint32, error)
	GetMessages(channelID string, channelType uint8, offset uint32, limit uint64) ([]*db.Message, error)
	GetLastMessages(channelID string, channelType uint8, endOffset uint32, limit uint64) ([]*db.Message, error)
	GetMessagesWithOptions(channelID string, channelType uint8, offset uint32, limit uint64, reverse bool, endMessageSeq uint32) ([]*db.Message, error)
	GetMessagesOfUser(uid string, offset uint32, limit uint64) ([]*db.Message, error)
	GetMessage(channelID string, channelType uint8, messageSeq uint32) (*db.Message, error)
	GetMessagesOfNotifyQueue(count int) ([]*db.Message, error)

	// ---------- conversation ----------
	GetConversations(uid string) ([]*db.Conversation, error)

	// 获取投递给节点的inflight数据
	GetNodeInFlightData() ([]*db.NodeInFlightDataModel, error)

	BackupSlots(slots []byte, w io.Writer) error
	// RecoverSlotBackup 恢复备份
	RecoverSlotBackup(reader io.Reader) error

	Close() error
}

StorageReader StorageReader

type StorageWriter

type StorageWriter interface {
	UpdateUserToken(uid string, deviceFlag lmproto.DeviceFlag, deviceLevel lmproto.DeviceLevel, token string) error

	// ---------- channel ----------
	DeleteChannel(channelID string, channelType uint8) error                 // 删除频道 但不清除消息
	DeleteChannelAndClearMessages(channelID string, channelType uint8) error // 删除频道并清除消息
	AddOrUpdateChannel(channelInfo *ChannelInfo) error
	AddSubscribers(channelID string, channelType uint8, uids []string) error
	RemoveAllSubscriber(channelID string, channelType uint8) error
	RemoveSubscribers(channelID string, channelType uint8, uids []string) error

	// ---------- denylist ----------
	AddDenylist(channelID string, channelType uint8, uids []string) error
	RemoveDenylist(channelID string, channelType uint8, uids []string) error
	RemoveAllDenylist(channelID string, channelType uint8) error

	// ---------- allowlist ----------
	AddAllowlist(channelID string, channelType uint8, uids []string) error
	RemoveAllowlist(channelID string, channelType uint8, uids []string) error
	RemoveAllAllowlist(channelID string, channelType uint8) error

	// ---------- message ----------
	AppendMessage(m *db.Message) error
	AppendMessageOfUser(m *db.Message) error
	AppendMessageOfNotifyQueue(m *db.Message) error
	RemoveMessagesOfNotifyQueue(messageIDs []int64) error
	UpdateMessageOfUserCursorIfNeed(uid string, offset uint32) error

	// ---------- conversation ----------
	AddOrUpdateConversations(uid string, conversations []*db.Conversation) error
	// 添加节点inflight数据
	AddNodeInFlightData(data []*db.NodeInFlightDataModel) error
	// 清除inflight数据
	ClearNodeInFlightData() error
}

StorageWriter StorageWriter

func NewClusterStorage

func NewClusterStorage(l *LiMao) StorageWriter

NewClusterStorage NewClusterStorage

type SystemUIDManager

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

SystemUIDManager System uid management

func NewSystemUIDManager

func NewSystemUIDManager(l *LiMao) *SystemUIDManager

NewSystemUIDManager NewSystemUIDManager

func (*SystemUIDManager) AddSystemUID

func (s *SystemUIDManager) AddSystemUID(uid string)

AddSystemUID AddSystemUID

func (*SystemUIDManager) LoadIfNeed

func (s *SystemUIDManager) LoadIfNeed() error

LoadIfNeed LoadIfNeed

func (*SystemUIDManager) RemoveSystemUID

func (s *SystemUIDManager) RemoveSystemUID(uid string)

RemoveSystemUID RemoveSystemUID

func (*SystemUIDManager) SystemUID

func (s *SystemUIDManager) SystemUID(uid string) bool

SystemUID Is it a system account?

type UpdateTokenReq

type UpdateTokenReq struct {
	UID         string              `json:"uid"`
	Token       string              `json:"token"`
	DeviceFlag  lmproto.DeviceFlag  `json:"device_flag"`
	DeviceLevel lmproto.DeviceLevel `json:"device_level"` // 设备等级 0.为从设备 1.为主设备
}

UpdateTokenReq 更新token请求

func (UpdateTokenReq) Check

func (u UpdateTokenReq) Check() error

Check 检查输入

type UserAPI

type UserAPI struct {
	limlog.Log
	// contains filtered or unexported fields
}

UserAPI 用户相关API

func NewUserAPI

func NewUserAPI(l *LiMao) *UserAPI

NewUserAPI NewUserAPI

func (*UserAPI) Route

func (u *UserAPI) Route(r *lmhttp.LMHttp)

Route 用户相关路由配置

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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