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.
This commit is contained in:
Mewster 2019-02-14 12:07:12 +01:00
parent 83039d354b
commit e8e7fe3afb
2 changed files with 24 additions and 4 deletions

View File

@ -37,8 +37,13 @@ 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 -1, meaning always retry. 0 exits after first fail, 5 retries 5 times... # default is true. Will be overridden by login_fail_retry
login_fail_retry = -1 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 # 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

@ -66,7 +66,7 @@ func GetDefaultClientConf() *ClientCommonConf {
TcpMux: true, TcpMux: true,
User: "", User: "",
DnsServer: "", DnsServer: "",
LoginFailRetry: -1, LoginFailRetry: 0,
Start: make(map[string]struct{}), Start: make(map[string]struct{}),
Protocol: "tcp", Protocol: "tcp",
HeartBeatInterval: 30, 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 { if tmpStr, ok = conf.Get("common", "login_fail_retry"); ok {
v, err = strconv.ParseInt(tmpStr, 10, 0) v, err = strconv.ParseInt(tmpStr, 10, 0)
if err != nil { if err != nil {
err = fmt.Errorf("Parse conf error: invalid login_fail_retry") err = fmt.Errorf("Parse conf error: invalid login_fail_retry")
return 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 { if tmpStr, ok = conf.Get("common", "protocol"); ok {