Documentation ¶
Index ¶
- Constants
- func CalcUserToken(uid int64, server_token string) string
- func CloseProFile(pconfig *CommConfig)
- func Conv2Bytes(result interface{}) ([]byte, error)
- func Conv2Float64(result interface{}) (float64, error)
- func Conv2Int(result interface{}) (int, error)
- func Conv2Int64(result interface{}) (int64, error)
- func Conv2Int64Map(result interface{}) (map[string]int64, error)
- func Conv2IntMap(result interface{}) (map[string]int, error)
- func Conv2String(result interface{}) (string, error)
- func Conv2StringMap(result interface{}) (map[string]string, error)
- func Conv2Strings(result interface{}) ([]string, error)
- func Conv2UInt64(result interface{}) (uint64, error)
- func Conv2Values(result interface{}) ([]interface{}, error)
- func Daemonize()
- func DecodeReportMsg(data []byte, pmsg *ReportMsg) error
- func DefaultHandleProfile(pconfig *CommConfig) bool
- func EncMd5Bytes(p []byte) string
- func EncPassString(pass string, salt string) string
- func EncSha256(p []byte) string
- func EncodeReportMsg(pmsg *ReportMsg) ([]byte, error)
- func EndPProf(pconfig *CommConfig) bool
- func FileExist(file_path string) bool
- func FillSSPkg(ss_msg *ss.SSMsg, proto ss.SS_PROTO_TYPE, pmsg interface{}) error
- func GenDispMsg(target ss.DISP_MSG_TARGET, method ss.DISP_MSG_METHOD, proto ss.DISP_PROTO_TYPE, ...) (*ss.SSMsg, error)
- func GenRandNumStr(str_len int) (string, error)
- func GenRandStr(str_len int) (string, error)
- func GenerateLocalId(wid int16, seq *uint16) int64
- func GetUrlIndex(url string) (int, error)
- func GetUrlType(url string) (int, error)
- func HandleSignal(pconfig *CommConfig)
- func IsNetError(err error) bool
- func LoadJsonFile(config_file string, file_config interface{}, pconfig *CommConfig) bool
- func LoadTableFiles(table_map TableMap, pconfig *CommConfig) bool
- func LockUniqFile(pconfig *CommConfig, name_space string, proc_id int, proc_name string) bool
- func ReLoadTableFiles(table_map TableMap, pconfig *CommConfig) bool
- func ReadFile(file_name string, close bool) ([]byte, error)
- func SelectProperServ(pconfig *CommConfig, method int, hash_v int64, candidate []int, ...) int
- func StartPProf(pconfig *CommConfig) bool
- func UnlockUniqFile(pconfig *CommConfig, name_space string, proc_id int, proc_name string) bool
- type ClientPkg
- type CmdExtraMsg
- type CommConfig
- type HeadTable
- type ProfileConfig
- type RedisCallBack
- type RedisClient
- func (pclient *RedisClient) AllocSyncCmdHead() *SyncCmdHead
- func (pclient *RedisClient) Close()
- func (pclient *RedisClient) FreeSyncCmdHead(phead *SyncCmdHead)
- func (pclient *RedisClient) GetConnNum() int
- func (pclient *RedisClient) GetLog() log.LogHeader
- func (pclient *RedisClient) RedisExeCmd(pconfig *CommConfig, cb_func RedisCallBack, cb_arg []interface{}, cmd string, ...)
- func (pclient *RedisClient) RedisExeCmdSync(phead *SyncCmdHead, cmd string, arg ...interface{}) (interface{}, error)
- func (pclient *RedisClient) Reset(redis_addr string, auth string, max_conn int, normal_conn int)
- type ReportHead
- type ReportMsg
- type ReportServ
- type SyncCmdHead
- type SyncServerMsg
- type TableMap
- type TcpServ
- type TickFunc
- type TickPool
- type TinyNewFunc
- type TinyPool
Constants ¶
const ( TIME_EPOLL_BASE int64 = 1577808000 //2020-01-01 00:00:00 TIME_FORMAT_SEC = "2006-01-02 15:04:05" TIME_FORMAT_MILL = "2006-01-02 15:04:05.000" TIME_FORMAT_MICR = "2006-01-02 15:04:05.000000" TIME_FORMAT_NANO = "2006-01-02 15:04:05.000000000" DEFAULT_SERVER_SLEEP_IDLE = 5 //ms. server sleeps when idle MIN_LOAD_WEIGHT = 0 //load & weight min MAX_LOAD_WEIGHT = 100 //load & weight max INFO_EXIT = 0 //0 server exit #sig-int INFO_RELOAD_CFG = 1 //1 server reload config #sig-usr1 INFO_USR2 = 2 //2 sig-usr2 #sig-usr2 INFO_PPROF = 3 //3 go pprof #sig-term SELECT_METHOD_RAND = 1 //select id by rand SELECT_METHOD_HASH = 2 //select by hash RAND_STR_POOL = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+?<>;:" RAND_NUM_POOL = "0123456789" //FILE_URL_TYPE FILE_URL_T_CHAT = 1 FILE_URL_T_HEAD = 2 FILE_URL_T_GROUP = 3 //group head url //FILE_UPDATE_CHECK FILE_UPT_CHECK_ONLINE = 1 //not online FILE_UPT_CHECK_GROUP = 2 //not in group FILE_UPT_CHECK_DEL = 3 //normal del //FILE_TOKEN_KEY FILE_TOKEN_KEY = "Be^^orNot&t*_be" //FILE_UPDATE_FILE FILE_TYPE_IMAGE int = 0 FILE_TYPE_MP4 int = 1 FILE_TYPE_VOICE int = 2 //SEX SEX_INT_MALE = 1 SEX_INT_FEMALE = 2 )
const ( TEMP_DIR_PREFIX = "/tmp/sg_run_2020" REWRITE_LOCK_FILE_TICK = (3600 * 6) //seconds maintain lock file in /tmp )
const ( HARD_MAX_CONN_LIMIT = 1000 REDIS_CONN_NONE = 0 REDIS_CONN_ING = 1 REDIS_CONN_DONE = 2 )
const ( //if manger count > 1 or no use REPORT_METHOD_SEQ = 1 //report status to manager which is latest valid REPORT_METHOD_ALL = 2 //report status to all manager REPORT_METHOD_MOD = 3 //report status to proc_id%manager_count to manager REPORT_METHOD_RAND = 4 //report status to a rand manager //MSG CHAN BUFFER REPROT_MSG_CHAN_SIZE = 100 //MAX SEND&RECV MAX_SEND_PER_TICK = 10 MAX_RECV_PER_TICK = 10 )
const ( MAX_REPORT_MSG_LEN = 10 * 1024 //sys defined proto here REPORT_PROTO_MONITOR = 1 //monitor information from top cmd REPORT_PROTO_RESERVED = 10000 //reserved proto id //user defined proto starts here REPORT_PROTO_SERVER_START = 10001 //server start time REPORT_PROTO_SERVER_HEART = 10002 //server heartbeat REPORT_PROTO_CONN_NUM = 10003 //server connection number. REPORT_PROTO_SYNC_SERVER = 10004 //sync basic server information REPORT_PROTO_SERVER_STOP = 10005 //server stop time REPORT_PROTO_CMD_REQ = 10006 //cmd to reload cfg REPORT_PROTO_CMD_RSP = 10007 //reload rsp //Cmd Stat CMD_STAT_NONE = "" CMD_STAT_ING = "ing" CMD_STAT_SUCCESS = "done" CMD_STAT_FAIL = "fail" CMD_STAT_NOP = "nop" //no operation //Report Cmd CMD_CMD_NONE = "" CMD_RELOAD_CFG = "reload_cfg" CMD_RELOAD_TAB = "reload_table" CMD_STOP_SERVER = "stop_server" CMD_LOG_LEVEL = "log_level" //chg log filt level CMD_LOG_DEGREE = "log_degree" //chg log time degree CMD_LOG_ROTATE = "log_rotate" //chg log rotate CMD_LOG_SIZE = "log_size" //chg log size CMD_START_GPROF = "start_gprof" CMD_END_GRPOF = "end_gprof" )
report proto
const ( CPU_PROFILE string = "cpu.profile" MEM_PROFILE string = "mem.profile" )
const ( TablePath = "./table" HeadTableFile = "__head.json" )
const ( MAX_PKG_LEN = ss.MAX_SS_MSG_SIZE //200K TCP_SERV_ACC_TIMEOUT = 5 //tcp_serv accept timeout ms CLIENT_STAT_CLOSING = 0 CLIENT_STAT_NORMAL = 1 MAX_QUEUE_DATA = MAX_PKG_LEN //max queue data == max_pkg_len //RECV_QUEUE_LEN=128 SND_QUEUE_LEN = 128 SERV_RECV_QUEUE = 4096 SERV_SND_QUEUE = 4096 MAX_PKG_PER_RECV = 200 //max pkg per recv //QUEUE_INFO QUEUE_INFO_NORMAL = 0 QUEUE_INFO_CLOSE = 1 QUEUE_INFO_BROADCAST = 2 //ClientPkg.PkgType CLIENT_PKG_T_NORMAL = 1 // special pkg using key CLIENT_PKG_T_BROADCAST = 2 //broadcast pkg CLIENT_PKG_T_CONN_CLOSED = 3 //client connection closed CLIENT_PKG_T_CLOSE_CONN = 4 //close client //R&W TIMEOUT CLIENT_RW_TIMEOUT = 2 //ms //RW CACHE CLIENT_RW_CACHE_SHRINK_FACTOR = 4 //if cache_size / base_size > factor will shrink memory CLIENT_RW_CACHE_BASE = (10 * 1024) //base 10K )
const ( TICKER_TYPE_SINGLE int8 = 1 TICKER_TYPE_CIRCLE int8 = 2 MAX_EXPIRE_MS int64 = 0xFFFFFFFFFFFF PERIOD_HEART_BEAT_DEFAULT = 10000 //10s PERIOD_REPORT_SYNC_DEFAULT = 60000 //1min PERIOD_RECV_REPORT_CMD_DEFAULT = 5000 //5s PERIOD_NOTIFY_LOAD_DEFAULT = 8000 //8s )
Variables ¶
This section is empty.
Functions ¶
func CalcUserToken ¶
func CloseProFile ¶
func CloseProFile(pconfig *CommConfig)
func Conv2Bytes ¶
func Conv2Float64 ¶
func Conv2Int64 ¶
func Conv2Int64Map ¶
func Conv2IntMap ¶
func Conv2String ¶
func Conv2StringMap ¶
func Conv2Strings ¶
func Conv2UInt64 ¶
func Conv2Values ¶
func Conv2Values(result interface{}) ([]interface{}, error)
func DecodeReportMsg ¶
func DefaultHandleProfile ¶
func DefaultHandleProfile(pconfig *CommConfig) bool
func EncMd5Bytes ¶
func EncodeReportMsg ¶
func EndPProf ¶
func EndPProf(pconfig *CommConfig) bool
func FillSSPkg ¶
func FillSSPkg(ss_msg *ss.SSMsg, proto ss.SS_PROTO_TYPE, pmsg interface{}) error
Fill SSMsg By ProtoType and MsgBody This is a helper for wrapper pkg @pmsg: ss.Msg*** defined in SSMsg.msg_body @pss_msg: fill info of this ss_msg @return: error
func GenDispMsg ¶
func GenDispMsg(target ss.DISP_MSG_TARGET, method ss.DISP_MSG_METHOD, proto ss.DISP_PROTO_TYPE, spec int, sender int, hash_v int64, disp_msg interface{}) (*ss.SSMsg, error)
Generate Disp Msg by arg. this function should be modified when new ss.DISP_PROTO_TYPE added @disp_msg: Disp sub msg like ss.MsgDispxxxx @target:target server type @method:choose spec target server method @spec:spec target server will ignore @target and @method @hash_v: if method is hash , this specify hash_value @return:ss_msg , error
func GenRandNumStr ¶
generate rand str only contains number lenth==str_len
func GenerateLocalId ¶
generate local id var seq uint16 = 1;
func GetUrlIndex ¶
get url file_serv index @return: index , error . if success error==nil and index is valid
func GetUrlType ¶
get url type @return: type , error . if success error==nil and type is valid
func HandleSignal ¶
func HandleSignal(pconfig *CommConfig)
func LoadJsonFile ¶
func LoadJsonFile(config_file string, file_config interface{}, pconfig *CommConfig) bool
func LoadTableFiles ¶
func LoadTableFiles(table_map TableMap, pconfig *CommConfig) bool
func LockUniqFile ¶
func LockUniqFile(pconfig *CommConfig, name_space string, proc_id int, proc_name string) bool
uniq process lock file
func ReLoadTableFiles ¶
func ReLoadTableFiles(table_map TableMap, pconfig *CommConfig) bool
func SelectProperServ ¶
func SelectProperServ(pconfig *CommConfig, method int, hash_v int64, candidate []int, stats map[int]int64, life_time int64) int
select a proper id * @method:refer SELECT_METHOD_XX * @hash_v:if method==SELECT_METHOD_HASH ,it sets hash value * @candidate:: candidate proc_id of servers * @stats: server heart stats * @life_time: valid life_time in stats * @result <=0 failed >0 success * PS:if candidate lens == 1 will only select one if in life_time
func StartPProf ¶
func StartPProf(pconfig *CommConfig) bool
func UnlockUniqFile ¶
func UnlockUniqFile(pconfig *CommConfig, name_space string, proc_id int, proc_name string) bool
unlock
Types ¶
type ClientPkg ¶
type ClientPkg struct { PkgType int8 //Flag uint8 ClientKey int64 //the key identify a client Data []byte }
Caller Proc <-> tcp_serv
type CmdExtraMsg ¶
type CmdExtraMsg struct {
ExtraValue string `json:"ext_value"`
}
type CommConfig ¶
type CommConfig struct { StartTs int64 Log log.LogHeader LockFile *os.File Proc proc.ProcHeader ChSig chan os.Signal ChInfo chan int PeerStats map[int]int64 //peer [procid]->heart_beat_ts TickPool *TickPool ServerCfg interface{} //server *config if assigend PProf ProfileConfig ReportCmdToken int64 //if exe report cmd ReportCmd string }
func InitCommConfig ¶
func InitCommConfig(log_file string, name_space string, proc_id int) *CommConfig
type ProfileConfig ¶
type ProfileConfig struct { Stat bool //false:closed true:open // contains filtered or unexported fields }
type RedisCallBack ¶
type RedisCallBack func(pconfig *CommConfig, result interface{}, cb_arg []interface{})
call back
type RedisClient ¶
func NewRedisClient ¶
func NewRedisClient(pconfig *CommConfig, redis_addr string, auth string, max_conn, normal_conn int) *RedisClient
New RedisClient
func (*RedisClient) AllocSyncCmdHead ¶
func (pclient *RedisClient) AllocSyncCmdHead() *SyncCmdHead
Alloc Synchronise Cmd Head Warning: 1.This Method Must Be Put in an independent go-routine or will block main process 2.Must Release Head After using head
func (*RedisClient) Close ¶
func (pclient *RedisClient) Close()
func (*RedisClient) FreeSyncCmdHead ¶
func (pclient *RedisClient) FreeSyncCmdHead(phead *SyncCmdHead)
Release Synchronise Cmd Head
func (*RedisClient) GetConnNum ¶
func (pclient *RedisClient) GetConnNum() int
func (*RedisClient) GetLog ¶
func (pclient *RedisClient) GetLog() log.LogHeader
func (*RedisClient) RedisExeCmd ¶
func (pclient *RedisClient) RedisExeCmd(pconfig *CommConfig, cb_func RedisCallBack, cb_arg []interface{}, cmd string, arg ...interface{})
redis exe cmd Asynchronously
func (*RedisClient) RedisExeCmdSync ¶
func (pclient *RedisClient) RedisExeCmdSync(phead *SyncCmdHead, cmd string, arg ...interface{}) (interface{}, error)
redis exe cmd synchronised
func (*RedisClient) Reset ¶
func (pclient *RedisClient) Reset(redis_addr string, auth string, max_conn int, normal_conn int)
Reset Addr * @redis_addr:new redis addr; "" means no use * @auth:new redis auth. "" means no use * @max_conn:new max conn. <=0 means no use;(ATTENTION: max_conn only support expand,and <=HARD_MAX_CONN_LIMIT) * @normal_conn: new normal conn. <=0 means no use
type ReportHead ¶
type ReportMsg ¶
type ReportMsg struct { ProtoId int `json:"proto"` ProcId int `json:"proc_id"` IntValue int64 `json:"intv"` //for normal int value StrValue string `json:"strv"` //for normal string value Sub interface{} `json:sub` //for complex info }
report msg
type ReportServ ¶
func StartReport ¶
func StartReport(pconfig *CommConfig, proc_id int, proc_name string, manage_addr []string, method int8, monitor_inv int) *ReportServ
Start a Report Go-Routine * @proc_id process proc id * @proc_name process proc_name * @manage_addr manage servers addr, it could be many servers. addr like: "ip:port" * @moniter_inv monitor interval of monitor goroutine. -1:no monitor =0:no sleep(at least 1 second sleep) >0 sleep seconds
func (*ReportServ) Close ¶
func (pserv *ReportServ) Close()
func (*ReportServ) Recv ¶
func (pserv *ReportServ) Recv() *ReportMsg
func (*ReportServ) Report ¶
func (pserv *ReportServ) Report(proto int, v_int int64, v_str string, v_msg interface{}) bool
* Report Msg To Manager * @proto:Refer REPORT_PROTO_XX * @v_msg: used for complex information. should be defined in report_proto.go
func (*ReportServ) SetMonitor ¶
func (pserv *ReportServ) SetMonitor(interval int)
set monitor interval
type SyncCmdHead ¶
type SyncCmdHead struct {
// contains filtered or unexported fields
}
redis exe cmd using synchronized
type SyncServerMsg ¶
type SyncServerMsg struct {
StartTime int64
}
-----------------------------------SubMsg--------------------
type TcpServ ¶
func StartTcpServ ¶
func StartTcpServ(pconfig *CommConfig, addr string, max_conn int, valid_conn int8, enc_type int8, rsa_pub_key []byte, rsa_pri_key []byte) *TcpServ
new tcp_serv and start listener serve rsa_pub_key & rsa_pri_key is needed when enc_type==NET_ENCRYPT_RSA
func (*TcpServ) GetConnNum ¶
func (*TcpServ) Recv ¶
func (pserv *TcpServ) Recv(pconfig *CommConfig, pkgs []*ClientPkg) int
read from clients @return: nil:read fail or empty; []*ClientPkg read success
func (*TcpServ) Send ¶
func (pserv *TcpServ) Send(pconfig *CommConfig, ppkg *ClientPkg) int
Send pkg to client @return: -1: failed 0:success
func (*TcpServ) SetMaxConn ¶
type TickPool ¶
type TickPool struct {
// contains filtered or unexported fields
}
func (*TickPool) AddTicker ¶
func (pool *TickPool) AddTicker(name string, ctype int8, start_ms int64, period_ms int64, callback TickFunc, arg interface{}) bool
add ticker
@ctype:ticker type refer TICKER_TYPE_XX @start_ms:started ms. <=0:started from current >0 futrue timestamp @period_ms:interval timeing @callback:trig function if not nil @arg: arg for callback func if not nil
type TinyNewFunc ¶
type TinyNewFunc func() interface{}