Changed LoginFailExit to LoginFailRetry

When client attempts a connection to the server, attempts a certain
amount of times before exiting.
This commit is contained in:
Mewster 2019-02-14 11:21:49 +01:00
parent de4bfcc43c
commit 83039d354b
3 changed files with 18 additions and 10 deletions

View File

@ -75,16 +75,21 @@ func (svr *Service) GetController() *Control {
func (svr *Service) Run() error { func (svr *Service) Run() error {
// first login // first login
retries := g.GlbClientCfg.LoginFailRetry
for { for {
conn, session, err := svr.login() conn, session, err := svr.login()
if err != nil { if err != nil {
log.Warn("login to server failed: %v", err) log.Warn("login to server failed: %v", err)
// if login_fail_exit is true, just exit this program // if retries exceeded login_fail_retry, just exit this program
// otherwise sleep a while and try again to connect to server // otherwise sleep a while and try again to connect to server
if g.GlbClientCfg.LoginFailExit { if retries == 0 {
return err return err
} else { } else {
//if retries < 0 we always retry
if retries > 0 {
retries--
}
time.Sleep(10 * time.Second) time.Sleep(10 * time.Second)
} }
} else { } else {

View File

@ -37,8 +37,8 @@ tcp_mux = true
user = your_name user = your_name
# decide if exit program when first login failed, otherwise continuous relogin to frps # decide if exit program when first login failed, otherwise continuous relogin to frps
# default is true # default is -1, meaning always retry. 0 exits after first fail, 5 retries 5 times...
login_fail_exit = true login_fail_retry = -1
# communication protocol used to connect to server # communication protocol used to connect to server
# now it supports tcp and kcp and websocket, default is tcp # now it supports tcp and kcp and websocket, default is tcp

View File

@ -41,7 +41,7 @@ type ClientCommonConf struct {
TcpMux bool `json:"tcp_mux"` TcpMux bool `json:"tcp_mux"`
User string `json:"user"` User string `json:"user"`
DnsServer string `json:"dns_server"` DnsServer string `json:"dns_server"`
LoginFailExit bool `json:"login_fail_exit"` LoginFailRetry int `json:"login_fail_retry"`
Start map[string]struct{} `json:"start"` Start map[string]struct{} `json:"start"`
Protocol string `json:"protocol"` Protocol string `json:"protocol"`
HeartBeatInterval int64 `json:"heartbeat_interval"` HeartBeatInterval int64 `json:"heartbeat_interval"`
@ -66,7 +66,7 @@ func GetDefaultClientConf() *ClientCommonConf {
TcpMux: true, TcpMux: true,
User: "", User: "",
DnsServer: "", DnsServer: "",
LoginFailExit: true, LoginFailRetry: -1,
Start: make(map[string]struct{}), Start: make(map[string]struct{}),
Protocol: "tcp", Protocol: "tcp",
HeartBeatInterval: 30, HeartBeatInterval: 30,
@ -179,10 +179,13 @@ func UnmarshalClientConfFromIni(defaultCfg *ClientCommonConf, content string) (c
} }
} }
if tmpStr, ok = conf.Get("common", "login_fail_exit"); ok && tmpStr == "false" { if tmpStr, ok = conf.Get("common", "login_fail_retry"); ok {
cfg.LoginFailExit = false v, err = strconv.ParseInt(tmpStr, 10, 0)
} else { if err != nil {
cfg.LoginFailExit = true err = fmt.Errorf("Parse conf error: invalid login_fail_retry")
return
}
cfg.LoginFailRetry = int(v)
} }
if tmpStr, ok = conf.Get("common", "protocol"); ok { if tmpStr, ok = conf.Get("common", "protocol"); ok {