fix gocritic linter warnings

This commit is contained in:
Dzyanis Kuzmenka 2022-03-17 22:54:04 +03:00
parent 7abbf5188d
commit 70fb6d396d
9 changed files with 27 additions and 27 deletions

View File

@ -425,8 +425,8 @@ func (pxy *XTCPProxy) sendDetectMsg(addr string, port int, laddr *net.UDPAddr, c
return err return err
} }
//uConn := ipv4.NewConn(tConn) // uConn := ipv4.NewConn(tConn)
//uConn.SetTTL(3) // uConn.SetTTL(3)
tConn.Write(content) tConn.Write(content)
tConn.Close() tConn.Close()

View File

@ -113,10 +113,8 @@ func (pm *Manager) Reload(pxyCfgs map[string]config.ProxyConf) {
cfg, ok := pxyCfgs[name] cfg, ok := pxyCfgs[name]
if !ok { if !ok {
del = true del = true
} else { } else if !pxy.Cfg.Compare(cfg) {
if !pxy.Cfg.Compare(cfg) { del = true
del = true
}
} }
if del { if del {

View File

@ -181,7 +181,7 @@ func (svr *Service) keepControllerWorking() {
xl.Warn("reconnect to server error: %v, wait %v for another retry", err, delayTime) xl.Warn("reconnect to server error: %v, wait %v for another retry", err, delayTime)
util.RandomSleep(delayTime, 0.9, 1.1) util.RandomSleep(delayTime, 0.9, 1.1)
delayTime = delayTime * 2 delayTime *= 2
if delayTime > maxDelayTime { if delayTime > maxDelayTime {
delayTime = maxDelayTime delayTime = maxDelayTime
} }

View File

@ -99,10 +99,8 @@ func (vm *VisitorManager) Reload(cfgs map[string]config.VisitorConf) {
cfg, ok := cfgs[name] cfg, ok := cfgs[name]
if !ok { if !ok {
del = true del = true
} else { } else if !oldCfg.Compare(cfg) {
if !oldCfg.Compare(cfg) { del = true
del = true
}
} }
if del { if del {

View File

@ -34,7 +34,7 @@ type OidcClientConfig struct {
// is "". // is "".
OidcClientSecret string `ini:"oidc_client_secret" json:"oidc_client_secret"` OidcClientSecret string `ini:"oidc_client_secret" json:"oidc_client_secret"`
// OidcAudience specifies the audience of the token in OIDC authentication // OidcAudience specifies the audience of the token in OIDC authentication
//if AuthenticationMethod == "oidc". By default, this value is "". // if AuthenticationMethod == "oidc". By default, this value is "".
OidcAudience string `ini:"oidc_audience" json:"oidc_audience"` OidcAudience string `ini:"oidc_audience" json:"oidc_audience"`
// OidcTokenEndpointURL specifies the URL which implements OIDC Token Endpoint. // OidcTokenEndpointURL specifies the URL which implements OIDC Token Endpoint.
// It will be used to get an OIDC token if AuthenticationMethod == "oidc". // It will be used to get an OIDC token if AuthenticationMethod == "oidc".

View File

@ -110,7 +110,7 @@ type ClientCommonConf struct {
// all supplied proxies are enabled. By default, this value is an empty // all supplied proxies are enabled. By default, this value is an empty
// set. // set.
Start []string `ini:"start" json:"start"` Start []string `ini:"start" json:"start"`
//Start map[string]struct{} `json:"start"` // Start map[string]struct{} `json:"start"`
// Protocol specifies the protocol to use when interacting with the server. // Protocol specifies the protocol to use when interacting with the server.
// Valid values are "tcp", "kcp" and "websocket". By default, this value // Valid values are "tcp", "kcp" and "websocket". By default, this value
// is "tcp". // is "tcp".

View File

@ -41,13 +41,16 @@ func CheckAndEnableTLSServerConnWithTimeout(
return return
} }
if n == 1 && int(buf[0]) == FRPTLSHeadByte { if n == 1 {
out = tls.Server(c, tlsConfig) switch int(buf[0]) {
isTLS = true case FRPTLSHeadByte:
custom = true out = tls.Server(c, tlsConfig)
} else if n == 1 && int(buf[0]) == 0x16 { isTLS = true
out = tls.Server(sc, tlsConfig) custom = true
isTLS = true case 0x16:
out = tls.Server(sc, tlsConfig)
isTLS = true
}
} else { } else {
if tlsOnly { if tlsOnly {
err = fmt.Errorf("non-TLS connection received on a TlsOnly server") err = fmt.Errorf("non-TLS connection received on a TlsOnly server")

View File

@ -44,7 +44,7 @@ func RandIDWithLen(idLen int) (id string, err error) {
} }
func GetAuthKey(token string, timestamp int64) (key string) { func GetAuthKey(token string, timestamp int64) (key string) {
token = token + fmt.Sprintf("%d", timestamp) token += fmt.Sprintf("%d", timestamp)
md5Ctx := md5.New() md5Ctx := md5.New()
md5Ctx.Write([]byte(token)) md5Ctx.Write([]byte(token))
data := md5Ctx.Sum(nil) data := md5Ctx.Sum(nil)
@ -70,7 +70,8 @@ func ParseRangeNumbers(rangeStr string) (numbers []int64, err error) {
numArray := strings.Split(numRangeStr, "-") numArray := strings.Split(numRangeStr, "-")
// length: only 1 or 2 is correct // length: only 1 or 2 is correct
rangeType := len(numArray) rangeType := len(numArray)
if rangeType == 1 { switch rangeType {
case 1:
// single number // single number
singleNum, errRet := strconv.ParseInt(strings.TrimSpace(numArray[0]), 10, 64) singleNum, errRet := strconv.ParseInt(strings.TrimSpace(numArray[0]), 10, 64)
if errRet != nil { if errRet != nil {
@ -78,7 +79,7 @@ func ParseRangeNumbers(rangeStr string) (numbers []int64, err error) {
return return
} }
numbers = append(numbers, singleNum) numbers = append(numbers, singleNum)
} else if rangeType == 2 { case 2:
// range numbers // range numbers
min, errRet := strconv.ParseInt(strings.TrimSpace(numArray[0]), 10, 64) min, errRet := strconv.ParseInt(strings.TrimSpace(numArray[0]), 10, 64)
if errRet != nil { if errRet != nil {
@ -97,7 +98,7 @@ func ParseRangeNumbers(rangeStr string) (numbers []int64, err error) {
for i := min; i <= max; i++ { for i := min; i <= max; i++ {
numbers = append(numbers, i) numbers = append(numbers, i)
} }
} else { default:
err = fmt.Errorf("range number is invalid") err = fmt.Errorf("range number is invalid")
return return
} }

View File

@ -528,13 +528,13 @@ func (ctl *Control) RegisterProxy(pxyMsg *msg.NewProxy) (remoteAddr string, err
err = fmt.Errorf("exceed the max_ports_per_client") err = fmt.Errorf("exceed the max_ports_per_client")
return return
} }
ctl.portsUsedNum = ctl.portsUsedNum + pxy.GetUsedPortsNum() ctl.portsUsedNum += pxy.GetUsedPortsNum()
ctl.mu.Unlock() ctl.mu.Unlock()
defer func() { defer func() {
if err != nil { if err != nil {
ctl.mu.Lock() ctl.mu.Lock()
ctl.portsUsedNum = ctl.portsUsedNum - pxy.GetUsedPortsNum() ctl.portsUsedNum -= pxy.GetUsedPortsNum()
ctl.mu.Unlock() ctl.mu.Unlock()
} }
}() }()
@ -570,7 +570,7 @@ func (ctl *Control) CloseProxy(closeMsg *msg.CloseProxy) (err error) {
} }
if ctl.serverCfg.MaxPortsPerClient > 0 { if ctl.serverCfg.MaxPortsPerClient > 0 {
ctl.portsUsedNum = ctl.portsUsedNum - pxy.GetUsedPortsNum() ctl.portsUsedNum -= pxy.GetUsedPortsNum()
} }
pxy.Close() pxy.Close()
ctl.pxyManager.Del(pxy.GetName()) ctl.pxyManager.Del(pxy.GetName())