lib

package
v0.0.0-...-4345fab Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//REDIS METHOD
	REDIS_METHOD_SINGLE = 0 //simplest method ,only use addr[0] as read and write candidate
	REDIS_METHOD_SM     = 1 //1 master and many slaves. ps:addr[0] is defined as master

	//REDIS OPERATION
	REDIS_OPT_R  = 1 //only for read operation,may dispatch to slave
	REDIS_OPT_W  = 2 //write operation will only disaptch to master
	REDIS_OPT_RW = REDIS_OPT_R | REDIS_OPT_W

	PASSWD_SALT_LEN    = 32
	LOGIN_LOCK_LIFE    = 10     //login lock life (second)
	CHAT_MSG_LIST_SIZE = 100000 //single tab of chat-msg size
	CHAT_MSG_DES_KEY   = "MikmiYua"

	FORMAT_TAB_GLOBAL_UID             = "global:uid"       // ++ string ++
	FORMAT_TAB_USER_GLOBAL            = "users:global:%s"  //users:global:[name]  ++ hash ++ name | pass | uid | salt
	FORMAT_TAB_USER_INFO_REFIX        = "user:"            // user:[uid] ++ hash ++ uid | name | age | sex  | addr | level | online_logic | blob_info | head_url
	FORMAT_TAB_USER_LOGIN_LOCK_PREFIX = "user:login_lock:" //user:login:[uid] +string+ valid_second
	FORMAT_TAB_USER_PROFILE_PREFIX    = "user:profile:"    //user:profile:[uid] +string+ <user_basic>
	FORMAT_TAB_GLOBAL_GRPID           = "global:grp_id"    // +string+
	FORMAT_TAB_GROUP_INFO_PREFIX      = "group:"           // group:[grp_id] +hash+ gid | name | master_uid | pass | salt | create_ts | msg_count | load_serv
	// | blob_info
	FORMAT_TAB_GROUP_MEMBERS       = "group:mem:"          //group:mem:[grp_id] +set+ <uid>
	FORMAT_TAB_GROUP_APPLY_LIST    = "group:apply:"        // group:apply:[grp_id] +list+ <apply_uid|apply_name|apply_msg>
	FORMAT_TAB_USER_GROUP_APPLIED  = "user:group:applied:" //user:group:applied:[uid] +set+ <grp_id|grp_name>
	FORMAT_TAB_USER_GROUP_AUDITED  = "user:group:audited:" //user:group:audited:[uid] +list+ <grp_id|grp_name|result>
	FORMAT_TAB_CHAT_MSG_LIST       = "chat_msg:%d:%d"      //chat_msg:[group]:[index] +list+ <chat_msg encoded>
	FORMAT_TAB_OFFLINE_INFO_PREFIX = "offline_info:"       // offline_info:[uid] +list+ <off_type|xxx...> off_type:REFER SS_OFFLINE_INFO_TYPE_xx

	FORMAT_TAB_VISIBLE_GROUP_SET    = "visible_group"  //visible_group_set +zset+  <grp_id|grp_name>
	FORMAT_TAB_GROUP_PROFILE_PREFIX = "group:profile:" //* #group:profile:[grp_id] +string+ <GroupGroudItem>

	//Useful FIELD
	FIELD_USER_INFO_NAME         = "name"
	FIELD_USER_INFO_ONLINE_LOGIC = "online_logic"
	FIELD_GROUP_INFO_MSG_COUNT   = "msg_count"
	FIELD_GROUP_INFO_NAME        = "name"
	FIELD_GROUP_BLOB_NAME        = "blob_info"
	FIELD_USER_INFO_HEAD_URL     = "head_url"
	FIELD_USER_INFO_BLOB         = "blob_info"
)
View Source
const (
	MESSAGE_LEN = ss.MAX_SS_MSG_SIZE //200k
)

Variables

This section is empty.

Functions

func AfterReLoadConfig

func AfterReLoadConfig(pconfig *Config, old_config *FileConfig, new_config *FileConfig)

After ReLoad Config If Need Handle

func AppendOfflineInfo

func AppendOfflineInfo(pclient *comm.RedisClient, phead *comm.SyncCmdHead, uid int64, info string) (int, ss.SS_COMMON_RESULT)

Append offline_info @return: list_len , result

func CalcRedisConn

func CalcRedisConn(pconfig *Config) int

all conn

func CloseRedis

func CloseRedis(pconfig *Config)

close redis client

func CommSet

func CommSet(pconfig *Config) bool

Comm Config Setting

func DelGroupProfile

func DelGroupProfile(pclient *comm.RedisClient, phead *comm.SyncCmdHead, grp_id int64) ss.SS_COMMON_RESULT

del group profile

func GetGroupInfo

func GetGroupInfo(pclient *comm.RedisClient, phead *comm.SyncCmdHead, grp_id int64, field string) (interface{}, ss.SS_COMMON_RESULT)

Get Group Name @return(res , SS_COMMON_RESULT)

func HandleReportCmd

func HandleReportCmd(pconfig *Config, pmsg *comm.ReportMsg)

func HeartBeatToRedis

func HeartBeatToRedis(arg interface{})

func InitRedisDb

func InitRedisDb(arg interface{})

init db info when first started only use addr[0] as master

func InvisibleGroup

func InvisibleGroup(pclient *comm.RedisClient, phead *comm.SyncCmdHead, uid int64, grp_id int64) ss.SS_COMMON_RESULT

del visible

func LocalSet

func LocalSet(pconfig *Config) bool

Local Proc Setting

func OpenRedis

func OpenRedis(pconfig *Config) bool

open redis client

func PackChat

func PackChat(pconfig *Config, uid int64, pchat *ss.ChatMsg) []byte

Decrypt and Unpack Chat

func RecvApplyGroupAudit

func RecvApplyGroupAudit(pconfig *Config, preq *ss.MsgApplyGroupAudit, from int)

func RecvApplyGroupReq

func RecvApplyGroupReq(pconfig *Config, preq *ss.MsgApplyGroupReq, from int)

func RecvBatchQueryGroupSnap

func RecvBatchQueryGroupSnap(pconfig *Config, preq *ss.MsgBatchQueryGroupSnap, from_serv int)

func RecvChgGroupAttrReq

func RecvChgGroupAttrReq(pconfig *Config, preq *ss.MsgChgGroupAttrReq, from_serv int)

func RecvCreateGroupReq

func RecvCreateGroupReq(pconfig *Config, preq *ss.MsgCreateGrpReq, from int)

func RecvEnterGroupReq

func RecvEnterGroupReq(pconfig *Config, preq *ss.MsgEnterGroupReq, from int)

func RecvExitGroupReq

func RecvExitGroupReq(pconfig *Config, preq *ss.MsgExitGroupReq, from int)

func RecvFetchApplyGroupReq

func RecvFetchApplyGroupReq(pconfig *Config, preq *ss.MsgFetchApplyGrpReq, from int)

func RecvFetchAuditGroupReq

func RecvFetchAuditGroupReq(pconfig *Config, preq *ss.MsgFetchAuditGrpReq, from int)

func RecvFetchChatReq

func RecvFetchChatReq(pconfig *Config, preq *ss.MsgFetchChatReq, from int)

func RecvFetchOfflineInfoReq

func RecvFetchOfflineInfoReq(pconfig *Config, preq *ss.MsgFetchOfflineInfoReq, from int)

func RecvFetchUserProfileReq

func RecvFetchUserProfileReq(pconfig *Config, preq *ss.MsgFetchUserProfileReq, from_serv int)

func RecvGroupGroundReq

func RecvGroupGroundReq(pconfig *Config, preq *ss.MsgGroupGroudReq, from int)

func RecvHeartBeatReq

func RecvHeartBeatReq(pconfig *Config, preq *ss.MsgHeartBeatReq, from int)

func RecvKickGroupReq

func RecvKickGroupReq(pconfig *Config, preq *ss.MsgKickGroupReq, from int)

func RecvLoadGroupReq

func RecvLoadGroupReq(pconfig *Config, preq *ss.MsgLoadGroupReq, from int)

func RecvMsg

func RecvMsg(pconfig *Config) int64

func RecvRegReq

func RecvRegReq(pconfig *Config, preq *ss.MsgRegReq, from int)

func RecvReportCmd

func RecvReportCmd(arg interface{})

func RecvSaveChatGroupReq

func RecvSaveChatGroupReq(pconfig *Config, preq *ss.MsgSaveGroupReq, from int)

func RecvSaveUserProfileReq

func RecvSaveUserProfileReq(pconfig *Config, preq *ss.MsgSaveUserProfileReq)

func RecvSendChatReq

func RecvSendChatReq(pconfig *Config, preq *ss.MsgSendChatReq, from int)

func RecvUpdateChatReq

func RecvUpdateChatReq(pconfig *Config, preq *ss.MsgUpdateChatReq, from int)

func RecvUpdateUserReq

func RecvUpdateUserReq(pconfig *Config, preq *ss.MsgUpdateUserReq, from int)

update user req only change password

func RecvUserLoginReq

func RecvUserLoginReq(pconfig *Config, preq *ss.MsgLoginReq, from int)

user login

func RecvUserLogoutReq

func RecvUserLogoutReq(pconfig *Config, preq *ss.MsgLogoutReq, from int)

user logout

func RemGroupMember

func RemGroupMember(pclient *comm.RedisClient, phead *comm.SyncCmdHead, uid int64, grp_id int64) ss.SS_COMMON_RESULT

RM Group Member

func ReportSyncServer

func ReportSyncServer(arg interface{})

func ResetRedis

func ResetRedis(pconfig *Config, old_config *FileConfig, new_config *FileConfig)

ResetRedis must ensure pconfig.RedisClients all member not nil!

func SaveGroupProfile

func SaveGroupProfile(pclient *comm.RedisClient, phead *comm.SyncCmdHead, grp_id int64, profile string) ss.SS_COMMON_RESULT

save group profile

func SaveUserProfile

func SaveUserProfile(pclient *comm.RedisClient, phead *comm.SyncCmdHead, uid int64, profile string) ss.SS_COMMON_RESULT

save user profile

func SelectRedisClient

func SelectRedisClient(pconfig *Config, redis_opt int) *comm.RedisClient

select a proper client to exe cmd

func SendApplyGroupRsp

func SendApplyGroupRsp(pconfig *Config, preq *ss.MsgApplyGroupReq, from int, ret ss.APPLY_GROUP_RESULT)

func SendCreateGroupErrRsp

func SendCreateGroupErrRsp(pconfig *Config, preq *ss.MsgCreateGrpReq, target_serv int, result ss.CREATE_GROUP_RESULT)

func SendEnterGroupRsp

func SendEnterGroupRsp(pconfig *Config, preq *ss.MsgEnterGroupReq, grp_name string, msg_count int64, target_serv int, ret int32)

func SendFetchApplyGroupEmpty

func SendFetchApplyGroupEmpty(pconfig *Config, preq *ss.MsgFetchApplyGrpReq, from int, complete int)

empty means error or no data or complete

func SendHeartBeatMsg

func SendHeartBeatMsg(arg interface{})

func SendRegRsp

func SendRegRsp(pconfig *Config, preq *ss.MsgRegReq, target_serv int, result ss.REG_RESULT)

func SendToServ

func SendToServ(pconfig *Config, target_serv int, pss_msg *ss.SSMsg) bool

send to other server

func SendUpdateUserRsp

func SendUpdateUserRsp(pconfig *Config, preq *ss.MsgUpdateUserReq, from int, result ss.SS_COMMON_RESULT)

func ServerExit

func ServerExit(pconfig *Config)

Server Exit

func ServerStart

func ServerStart(pconfig *Config)

Main Proc

func UnpackChat

func UnpackChat(pconfig *Config, uid int64, db_chat string) *ss.ChatMsg

Decrypt and Unpack Chat

Types

type Config

type Config struct {
	//comm
	NameSpace      string
	ProcId         int
	ProcName       string
	ConfigFile     string
	Daemon         bool
	FileConfig     *FileConfig
	Comm           *comm.CommConfig
	ReportCmd      string //used for report cmd
	ReportCmdToken int64
	ReportServ     *comm.ReportServ //report to manger
	//local
	RedisClients []*RedisClientInfo
}

type FileConfig

type FileConfig struct {
	//	ProcName string `json:"proc_name"`
	TargetServs    []int    `json:"target_servs"` //target serv set
	LogFile        string   `json:"log_file"`
	RedisMethod    int      `json:"redis_method"`
	RedisAddr      []string `json:"redis_addr"`
	MaxConn        int      `json:"max_conn"`    //max redis-conn of process
	NormalConn     int      `json:"normal_conn"` //normal redis-conn
	AuthPass       string   `json:"auth_pass"`
	ManageAddr     []string `json:"manage_addr"`
	InitRedisAfter int      `json:"init_redis_after"` //init redis db info after start xx seconds
	InitUid        int64    `json:"init_uid"`         //init uid number
	UidIncr        int      `json:"uid_incr"`         //uid incr step
	InitGrpId      int64    `json:"init_grp_id"`      //init group id
	GrpIdIncr      int      `json:"grp_id_incr"`      //grp_id incr step
	MonitorInv     int      `json:"monitor_inv"`      //monitor interval seconds
}

type Msg

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

type RedisClientInfo

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

Jump to

Keyboard shortcuts

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