From d8b1f4e7cd43759cf4d80a68501ef22a2d7f637d Mon Sep 17 00:00:00 2001 From: Carlo Teubner Date: Sat, 24 Jun 2023 20:56:03 +0100 Subject: [PATCH] Fix miscellaneous style issues (#2421) Found by running: golangci-lint run --enable-all I have only addressed the reported issues that seemed relevant to me. --- dnscrypt-proxy/common.go | 5 ----- dnscrypt-proxy/config.go | 2 +- dnscrypt-proxy/dnscrypt_certs.go | 2 +- dnscrypt-proxy/main.go | 2 +- dnscrypt-proxy/netprobe_others.go | 2 +- dnscrypt-proxy/oblivious_doh.go | 2 +- dnscrypt-proxy/plugin_allow_ip.go | 2 +- dnscrypt-proxy/plugin_cloak.go | 6 +++--- dnscrypt-proxy/plugins.go | 20 ++++++++++---------- dnscrypt-proxy/proxy.go | 6 +++--- dnscrypt-proxy/serversInfo.go | 4 ++-- 11 files changed, 24 insertions(+), 29 deletions(-) diff --git a/dnscrypt-proxy/common.go b/dnscrypt-proxy/common.go index 0eed4efd..499f0b0b 100644 --- a/dnscrypt-proxy/common.go +++ b/dnscrypt-proxy/common.go @@ -46,11 +46,6 @@ const ( InheritedDescriptorsBase = uintptr(50) ) -const ( - IPv4Arpa = "in-addr.arpa" - IPv6Arpa = "ip6.arpa" -) - func PrefixWithSize(packet []byte) ([]byte, error) { packetLen := len(packet) if packetLen > 0xffff { diff --git a/dnscrypt-proxy/config.go b/dnscrypt-proxy/config.go index e9d99d5a..13b211bd 100644 --- a/dnscrypt-proxy/config.go +++ b/dnscrypt-proxy/config.go @@ -906,7 +906,7 @@ func (config *Config) loadSource(proxy *Proxy, cfgSourceName string, cfgSource * cfgSource.Prefix, ) if err != nil { - if len(source.bin) <= 0 { + if len(source.bin) == 0 { dlog.Criticalf("Unable to retrieve source [%s]: [%s]", cfgSourceName, err) return err } diff --git a/dnscrypt-proxy/dnscrypt_certs.go b/dnscrypt-proxy/dnscrypt_certs.go index 7305ca2e..66f37899 100644 --- a/dnscrypt-proxy/dnscrypt_certs.go +++ b/dnscrypt-proxy/dnscrypt_certs.go @@ -35,7 +35,7 @@ func FetchCurrentDNSCryptCert( return CertInfo{}, 0, false, errors.New("Invalid public key length") } if !strings.HasSuffix(providerName, ".") { - providerName = providerName + "." + providerName += "." } if serverName == nil { serverName = &providerName diff --git a/dnscrypt-proxy/main.go b/dnscrypt-proxy/main.go index a44272f2..d5cacd5c 100644 --- a/dnscrypt-proxy/main.go +++ b/dnscrypt-proxy/main.go @@ -35,7 +35,7 @@ func main() { if _, err := crypto_rand.Read(seed); err != nil { dlog.Fatal(err) } - rand.Seed(int64(binary.LittleEndian.Uint64(seed[:]))) + rand.Seed(int64(binary.LittleEndian.Uint64(seed))) pwd, err := os.Getwd() if err != nil { diff --git a/dnscrypt-proxy/netprobe_others.go b/dnscrypt-proxy/netprobe_others.go index 1745b46f..4d399298 100644 --- a/dnscrypt-proxy/netprobe_others.go +++ b/dnscrypt-proxy/netprobe_others.go @@ -11,7 +11,7 @@ import ( ) func NetProbe(proxy *Proxy, address string, timeout int) error { - if len(address) <= 0 || timeout == 0 { + if len(address) == 0 || timeout == 0 { return nil } if captivePortalHandler, err := ColdStart(proxy); err == nil { diff --git a/dnscrypt-proxy/oblivious_doh.go b/dnscrypt-proxy/oblivious_doh.go index db3f72fb..e76152b0 100644 --- a/dnscrypt-proxy/oblivious_doh.go +++ b/dnscrypt-proxy/oblivious_doh.go @@ -181,7 +181,7 @@ func (q ODoHQuery) decryptResponse(response []byte) ([]byte, error) { responseLength := binary.BigEndian.Uint16(responsePlaintext[0:2]) valid := 1 for i := 4 + int(responseLength); i < len(responsePlaintext); i++ { - valid = valid & subtle.ConstantTimeByteEq(response[i], 0x00) + valid &= subtle.ConstantTimeByteEq(response[i], 0x00) } if valid != 1 { return nil, fmt.Errorf("Malformed response") diff --git a/dnscrypt-proxy/plugin_allow_ip.go b/dnscrypt-proxy/plugin_allow_ip.go index 18212c53..bba56db1 100644 --- a/dnscrypt-proxy/plugin_allow_ip.go +++ b/dnscrypt-proxy/plugin_allow_ip.go @@ -36,7 +36,7 @@ func (plugin *PluginAllowedIP) Init(proxy *Proxy) error { } plugin.allowedPrefixes = iradix.New() plugin.allowedIPs = make(map[string]interface{}) - for lineNo, line := range strings.Split(string(bin), "\n") { + for lineNo, line := range strings.Split(bin, "\n") { line = TrimAndStripInlineComments(line) if len(line) == 0 { continue diff --git a/dnscrypt-proxy/plugin_cloak.go b/dnscrypt-proxy/plugin_cloak.go index 4148bbfd..48810774 100644 --- a/dnscrypt-proxy/plugin_cloak.go +++ b/dnscrypt-proxy/plugin_cloak.go @@ -47,7 +47,7 @@ func (plugin *PluginCloak) Init(proxy *Proxy) error { plugin.createPTR = proxy.cloakedPTR plugin.patternMatcher = NewPatternMatcher() cloakedNames := make(map[string]*CloakedName) - for lineNo, line := range strings.Split(string(bin), "\n") { + for lineNo, line := range strings.Split(bin, "\n") { line = TrimAndStripInlineComments(line) if len(line) == 0 { continue @@ -73,9 +73,9 @@ func (plugin *PluginCloak) Init(proxy *Proxy) error { ip := net.ParseIP(target) if ip != nil { if ipv4 := ip.To4(); ipv4 != nil { - cloakedName.ipv4 = append((*cloakedName).ipv4, ipv4) + cloakedName.ipv4 = append(cloakedName.ipv4, ipv4) } else if ipv6 := ip.To16(); ipv6 != nil { - cloakedName.ipv6 = append((*cloakedName).ipv6, ipv6) + cloakedName.ipv6 = append(cloakedName.ipv6, ipv6) } else { dlog.Errorf("Invalid IP address in cloaking rule at line %d", 1+lineNo) continue diff --git a/dnscrypt-proxy/plugins.go b/dnscrypt-proxy/plugins.go index 37bc41e9..ebbfce02 100644 --- a/dnscrypt-proxy/plugins.go +++ b/dnscrypt-proxy/plugins.go @@ -189,11 +189,11 @@ func parseBlockedQueryResponse(blockedResponse string, pluginsGlobals *PluginsGl if strings.HasPrefix(blockedResponse, "a:") { blockedIPStrings := strings.Split(blockedResponse, ",") - (*pluginsGlobals).respondWithIPv4 = net.ParseIP(strings.TrimPrefix(blockedIPStrings[0], "a:")) + pluginsGlobals.respondWithIPv4 = net.ParseIP(strings.TrimPrefix(blockedIPStrings[0], "a:")) - if (*pluginsGlobals).respondWithIPv4 == nil { + if pluginsGlobals.respondWithIPv4 == nil { dlog.Notice("Error parsing IPv4 response given in blocked_query_response option, defaulting to `hinfo`") - (*pluginsGlobals).refusedCodeInResponses = false + pluginsGlobals.refusedCodeInResponses = false return } @@ -203,9 +203,9 @@ func parseBlockedQueryResponse(blockedResponse string, pluginsGlobals *PluginsGl if strings.HasPrefix(ipv6Response, "[") { ipv6Response = strings.Trim(ipv6Response, "[]") } - (*pluginsGlobals).respondWithIPv6 = net.ParseIP(ipv6Response) + pluginsGlobals.respondWithIPv6 = net.ParseIP(ipv6Response) - if (*pluginsGlobals).respondWithIPv6 == nil { + if pluginsGlobals.respondWithIPv6 == nil { dlog.Notice( "Error parsing IPv6 response given in blocked_query_response option, defaulting to IPv4", ) @@ -215,18 +215,18 @@ func parseBlockedQueryResponse(blockedResponse string, pluginsGlobals *PluginsGl } } - if (*pluginsGlobals).respondWithIPv6 == nil { - (*pluginsGlobals).respondWithIPv6 = (*pluginsGlobals).respondWithIPv4 + if pluginsGlobals.respondWithIPv6 == nil { + pluginsGlobals.respondWithIPv6 = pluginsGlobals.respondWithIPv4 } } else { switch blockedResponse { case "refused": - (*pluginsGlobals).refusedCodeInResponses = true + pluginsGlobals.refusedCodeInResponses = true case "hinfo": - (*pluginsGlobals).refusedCodeInResponses = false + pluginsGlobals.refusedCodeInResponses = false default: dlog.Noticef("Invalid blocked_query_response option [%s], defaulting to `hinfo`", blockedResponse) - (*pluginsGlobals).refusedCodeInResponses = false + pluginsGlobals.refusedCodeInResponses = false } } } diff --git a/dnscrypt-proxy/proxy.go b/dnscrypt-proxy/proxy.go index b7edf329..2f1afc66 100644 --- a/dnscrypt-proxy/proxy.go +++ b/dnscrypt-proxy/proxy.go @@ -127,7 +127,7 @@ func (proxy *Proxy) addDNSListener(listenAddrStr string) { } // if 'userName' is not set, continue as before - if len(proxy.userName) <= 0 { + if len(proxy.userName) == 0 { if err := proxy.udpListenerFromAddr(listenUDPAddr); err != nil { dlog.Fatal(err) } @@ -191,7 +191,7 @@ func (proxy *Proxy) addLocalDoHListener(listenAddrStr string) { } // if 'userName' is not set, continue as before - if len(proxy.userName) <= 0 { + if len(proxy.userName) == 0 { if err := proxy.localDoHListenerFromAddr(listenTCPAddr); err != nil { dlog.Fatal(err) } @@ -619,7 +619,7 @@ func (proxy *Proxy) processIncomingQuery( start time.Time, onlyCached bool, ) []byte { - var response []byte = nil + var response []byte if len(query) < MinDNSPacketSize { return response } diff --git a/dnscrypt-proxy/serversInfo.go b/dnscrypt-proxy/serversInfo.go index 11a02245..16015823 100644 --- a/dnscrypt-proxy/serversInfo.go +++ b/dnscrypt-proxy/serversInfo.go @@ -312,7 +312,7 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo { serversInfo.estimatorUpdate(candidate) } serverInfo := serversInfo.inner[candidate] - dlog.Debugf("Using candidate [%s] RTT: %d", (*serverInfo).Name, int((*serverInfo).rtt.Value())) + dlog.Debugf("Using candidate [%s] RTT: %d", serverInfo.Name, int(serverInfo.rtt.Value())) serversInfo.Unlock() return serverInfo @@ -534,7 +534,7 @@ func route(proxy *Proxy, name string, serverProto stamps.StampProtoType) (*Relay func fetchDNSCryptServerInfo(proxy *Proxy, name string, stamp stamps.ServerStamp, isNew bool) (ServerInfo, error) { if len(stamp.ServerPk) != ed25519.PublicKeySize { - serverPk, err := hex.DecodeString(strings.Replace(string(stamp.ServerPk), ":", "", -1)) + serverPk, err := hex.DecodeString(strings.ReplaceAll(string(stamp.ServerPk), ":", "")) if err != nil || len(serverPk) != ed25519.PublicKeySize { dlog.Fatalf("Unsupported public key for [%s]: [%s]", name, stamp.ServerPk) }