mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-03-04 02:14:40 +01:00
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.
This commit is contained in:
parent
23a6cd7504
commit
d8b1f4e7cd
11 changed files with 24 additions and 29 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue