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: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UPLOAD_TMPL = "./html_tmpl/upload.html"

	//UPLOAD LABEL
	FORM_LABEL_URL_TYPE = "url_type"
	FORM_LABEL_UID      = "uid"
	FORM_LABEL_GRP_ID   = "grp_id"
	FORM_LABEL_TMP_ID   = "tmp_id"
	FORM_LABEL_UPLOAD   = "upload_file"
	FORM_LABEL_TOKEN    = "token"

	//UPLOAD RESULT
	UPLOAD_RESULT_SUCCESS = 0
	UPLOAD_RESULT_FAILED  = 1
	UPLOAD_RESULT_SIZE    = 2
	UPLOAD_RESULT_TYPE    = 3

	FILE_MSG_CHAN_SIZE = 1000
	MAX_FETCH_PER_TICK = 10

	//SUB_DIR --> type
	FILE_PARENT_DIR_CHATS       = "chat"
	FILE_PARENT_DIR_HEADS       = "head"
	FILE_PARENT_DIR_GROUP_HEADS = "g_head"

	//URL PATTERN
	URL_HEAD_CHATS   = "/static"
	URL_HEAD_HEADS   = "/head"
	URL_HEAD_G_HEADS = "/g_head"

	//FILE_MSG_TYPE
	FILE_MSG_EXIT              = 0 //exit
	FILE_MSG_UPLOAD            = 1 //server-->main upload one file
	FILE_MSG_UPLOAD_CHECK_FAIL = 2 //main-->server upload check err
	FILE_MSG_UPDATE_TOKEN      = 3 //update token

	//MAX_SUB_DIR
	MAX_HEAD_SUB_DIRS       = 64 //uid % dirs
	MAX_GROUP_HEAD_SUB_DIRS = 61 //grp_id % dirs

	//HTTPS
	KEY_FILE_PATH  = "./cfg/key.pem"
	CERT_FILE_PATH = "./cfg/cert.pem"
)
View Source
const (
	//TOKEN LEN
	FILE_SERV_TOKEN_LEN = 10

	PERIOD_UPDATE_TOKEN = 3600000 //1h update token
	PERIOD_SYNC_TOKEN   = 600000  //10min sync token to dir

	//SAFE MOD
	SAFE_MOD_NONE  = 0
	SAFE_MOD_PATH  = 1 //check path valid when query files
	SAFE_MOD_TOKEN = 2 //check token valid, will include above check when query files
	SAFE_MOD_IP    = 3 //check ip valid,will include above check when query files. query failed times will record ip to blacklist

	//WATCHER
	SUSPECT_JAIL_TIME       = 3600 //1h suspect ip in watcher if no fail again
	SUSPECT_SAFE_FAIL       = 5    //most safe failed times
	SUSPECT_FAIL_PUNISH_SEC = 60   //overflow safe door, will block ip punish_sec per 1 failed access
	SUSPECT_CHECK_PEROID    = 60
)
View Source
const (
	MESSAGE_LEN = ss.MAX_SS_MSG_SIZE //200k
)
View Source
const (
	RECV_FILE_MSG_TICK = 10
)

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 ClientIP

func ClientIP(r *http.Request) string
--------------code from gayhub -------------

refer https://github.com/thinkeridea/go-extend/tree/master/exnet ClientIP 尽最大努力实现获取客户端 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。

func ClientPublicIP

func ClientPublicIP(r *http.Request) string

ClientPublicIP 尽最大努力实现获取客户端公网 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。

func CommSet

func CommSet(pconfig *Config) bool

Comm Config Setting

func GetFileType

func GetFileType(fSrc []byte) string

用文件前面几个字节来判断 fSrc: 文件字节流(就用前面几个字节)

func HandleFileMsg

func HandleFileMsg(pconfig *Config, pmsg *FileMsg)

func HandleReportCmd

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

func HasLocalIP

func HasLocalIP(ip net.IP) bool

HasLocalIP 检测 IP 地址是否是内网地址 通过直接对比ip段范围效率更高

func HasLocalIPddr

func HasLocalIPddr(ip string) bool

HasLocalIPddr 检测 IP 地址字符串是否是内网地址

func LocalSet

func LocalSet(pconfig *Config) bool

Local Proc Setting

func ReadFileMsg

func ReadFileMsg(pconfig *Config)

func ReadUploadMsg

func ReadUploadMsg(pconfig *Config, pmsg *FileMsg)

func RecvCommNotify

func RecvCommNotify(pconfig *Config, pnotify *ss.MsgCommonNotify, src_serv int)

func RecvDispMsg

func RecvDispMsg(pconfig *Config, pdisp *ss.MsgDisp)

func RecvFileTokenNotify

func RecvFileTokenNotify(pconfig *Config, pnotify *ss.MsgCommonNotify, dir_serv int)

dir --> file query

func RecvHeartBeatReq

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

func RecvMsg

func RecvMsg(pconfig *Config) int64

func RecvReportCmd

func RecvReportCmd(arg interface{})

func RecvUploadNotify

func RecvUploadNotify(pconfig *Config, pnotify *ss.MsgCommonNotify)

func ReportSyncServer

func ReportSyncServer(arg interface{})

func SendHeartBeatMsg

func SendHeartBeatMsg(arg interface{})

func SendToDisp

func SendToDisp(pconfig *Config, hash_v int64, v interface{}) bool

send to disp hash if hash_v>0 use hash first; or use rand method

func SendToServ

func SendToServ(pconfig *Config, target_serv int, v interface{}) bool

@v only support []byte and *ss.SSMsg

func ServerExit

func ServerExit(pconfig *Config)

func ServerStart

func ServerStart(pconfig *Config)

Main Proc

func SyncServToken

func SyncServToken(arg interface{})

func UpdateServToken

func UpdateServToken(arg interface{})

Types

type AccMIME

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

func (*AccMIME) Accept

func (pa *AccMIME) Accept(mime_type string) (int, bool)

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
	NowToken   string
	FileServer *FileServer //file server
}

type FileConfig

type FileConfig struct {
	DispServList []int    `json:"disp_serv_list"`
	LogFile      string   `json:"log_file"`
	ServIndex    int      `json:"serv_index"`
	HttpAddr     string   `json:"http_addr"`
	MaxFileSize  int      `json:"max_file_size"`
	RealFilePath string   `json:"real_file_path"`
	SafeMode     int      `json:"safe_mod"` //refer SAFE_MOD_XX
	ManageAddr   []string `json:"manage_addr"`
	MonitorInv   int      `json:"monitor_inv"` //monitor interval seconds
}

type FileMsg

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

type FileServer

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

func StartFileServer

func StartFileServer(pconfig *Config) *FileServer

func (*FileServer) Close

func (fs *FileServer) Close()

func (*FileServer) Read

func (fs *FileServer) Read(msg_list []*FileMsg) int

upper read from FileServer

func (*FileServer) Send

func (fs *FileServer) Send(pmsg *FileMsg) bool

upper send to FileServer

func (*FileServer) Suspect

func (fs *FileServer) Suspect() int

type MiMeRefer

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

func (*MiMeRefer) GetEnding

func (pm *MiMeRefer) GetEnding(file_type string) (string, bool)

type Msg

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

type UploadResult

type UploadResult struct {
	Result int    `json:"result"`
	Info   string `json:"info"`
	TmpId  int64  `json:"tmp_id"`
}

Jump to

Keyboard shortcuts

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