From e8e7fe3afbd64c8891579f0cac138778f1e7284b Mon Sep 17 00:00:00 2001 From: Mewster Date: Thu, 14 Feb 2019 12:07:12 +0100 Subject: [PATCH] Added backward compatibility with login_fail_exit In case both login_fail_exit is defined, a warning will tell to use login_fail_retry. In case login_fail_exit = false and login_fail_retry >= 0, an error will warn about the mismatch. --- conf/frpc_full.ini | 9 +++++++-- models/config/client_common.go | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/conf/frpc_full.ini b/conf/frpc_full.ini index eaf32644..3b64e26c 100644 --- a/conf/frpc_full.ini +++ b/conf/frpc_full.ini @@ -37,8 +37,13 @@ tcp_mux = true user = your_name # decide if exit program when first login failed, otherwise continuous relogin to frps -# default is -1, meaning always retry. 0 exits after first fail, 5 retries 5 times... -login_fail_retry = -1 +# default is true. Will be overridden by login_fail_retry +login_fail_exit = true + +# decide if exit program when first login failed, otherwise continuous relogin to frps +# default is 0, meaning exits after first failed attempt (and it's equivalent to login_fail_exit = true). +# -1 never exits, 5 retries 5 times... +login_fail_retry = 0 # communication protocol used to connect to server # now it supports tcp and kcp and websocket, default is tcp diff --git a/models/config/client_common.go b/models/config/client_common.go index 06e13571..d5379d40 100644 --- a/models/config/client_common.go +++ b/models/config/client_common.go @@ -66,7 +66,7 @@ func GetDefaultClientConf() *ClientCommonConf { TcpMux: true, User: "", DnsServer: "", - LoginFailRetry: -1, + LoginFailRetry: 0, Start: make(map[string]struct{}), Protocol: "tcp", HeartBeatInterval: 30, @@ -179,13 +179,28 @@ func UnmarshalClientConfFromIni(defaultCfg *ClientCommonConf, content string) (c } } + if tmpStr, ok = conf.Get("common", "login_fail_exit"); ok { + fmt.Println("Parse conf warning: login_fail_exit is deprecated; will be overridden by login_fail_retry if present") + if tmpStr == "false" { + cfg.LoginFailRetry = -1 + } else { + cfg.LoginFailRetry = 0 + } + } + if tmpStr, ok = conf.Get("common", "login_fail_retry"); ok { v, err = strconv.ParseInt(tmpStr, 10, 0) if err != nil { err = fmt.Errorf("Parse conf error: invalid login_fail_retry") return } - cfg.LoginFailRetry = int(v) + val := int(v) + if cfg.LoginFailRetry == -1 && val >= 0 { + err = fmt.Errorf("Parse conf error: cannot have login_fail_exit = false and login_fail_retry >= 0") + return + } else { + cfg.LoginFailRetry = val + } } if tmpStr, ok = conf.Get("common", "protocol"); ok {