diff --git a/dnscrypt-proxy/dnscrypt_certs.go b/dnscrypt-proxy/dnscrypt_certs.go index 0d77b766..a9f75810 100644 --- a/dnscrypt-proxy/dnscrypt_certs.go +++ b/dnscrypt-proxy/dnscrypt_certs.go @@ -54,11 +54,7 @@ func FetchCurrentDNSCryptCert(proxy *Proxy, serverName *string, proto string, pk } else { txt = strings.Join(t.Txt, "") } - binCert, err := packTxtString(txt) - if err != nil { - dlog.Warnf("[%v] Unable to unpack the certificate", providerName) - continue - } + binCert := packTxtString(txt) if len(binCert) < 124 { dlog.Warnf("[%v] Certificate too short", providerName) continue @@ -154,7 +150,7 @@ func dddToByte(s []byte) byte { return byte((s[0]-'0')*100 + (s[1]-'0')*10 + (s[2] - '0')) } -func packTxtString(s string) ([]byte, error) { +func packTxtString(s string) []byte { bs := make([]byte, len(s)) msg := make([]byte, 0) copy(bs, s) @@ -180,7 +176,7 @@ func packTxtString(s string) ([]byte, error) { msg = append(msg, bs[i]) } } - return msg, nil + return msg } func dnsExchange(proxy *Proxy, proto string, query *dns.Msg, serverAddress string, relayUDPAddr *net.UDPAddr, relayTCPAddr *net.TCPAddr, serverName *string) (*dns.Msg, time.Duration, error) { diff --git a/dnscrypt-proxy/dnsutils.go b/dnscrypt-proxy/dnsutils.go index 386c134a..2a8261b0 100644 --- a/dnscrypt-proxy/dnsutils.go +++ b/dnscrypt-proxy/dnsutils.go @@ -23,20 +23,17 @@ func TruncatedResponse(packet []byte) ([]byte, error) { return dstMsg.Pack() } -func EmptyResponseFromMessage(srcMsg *dns.Msg) (*dns.Msg, error) { +func EmptyResponseFromMessage(srcMsg *dns.Msg) *dns.Msg { dstMsg := srcMsg dstMsg.Response = true dstMsg.Answer = make([]dns.RR, 0) dstMsg.Ns = make([]dns.RR, 0) dstMsg.Extra = make([]dns.RR, 0) - return dstMsg, nil + return dstMsg } -func RefusedResponseFromMessage(srcMsg *dns.Msg, refusedCode bool, ipv4 net.IP, ipv6 net.IP, ttl uint32) (*dns.Msg, error) { - dstMsg, err := EmptyResponseFromMessage(srcMsg) - if err != nil { - return dstMsg, err - } +func RefusedResponseFromMessage(srcMsg *dns.Msg, refusedCode bool, ipv4 net.IP, ipv6 net.IP, ttl uint32) *dns.Msg { + dstMsg := EmptyResponseFromMessage(srcMsg) if refusedCode { dstMsg.Rcode = dns.RcodeRefused } else { @@ -74,7 +71,7 @@ func RefusedResponseFromMessage(srcMsg *dns.Msg, refusedCode bool, ipv4 net.IP, } } } - return dstMsg, nil + return dstMsg } func HasTCFlag(packet []byte) bool { diff --git a/dnscrypt-proxy/plugin_block_ipv6.go b/dnscrypt-proxy/plugin_block_ipv6.go index 6327e3ce..52fd63cd 100644 --- a/dnscrypt-proxy/plugin_block_ipv6.go +++ b/dnscrypt-proxy/plugin_block_ipv6.go @@ -37,10 +37,7 @@ func (plugin *PluginBlockIPv6) Eval(pluginsState *PluginsState, msg *dns.Msg) er if question.Qclass != dns.ClassINET || question.Qtype != dns.TypeAAAA { return nil } - synth, err := EmptyResponseFromMessage(msg) - if err != nil { - return err - } + synth := EmptyResponseFromMessage(msg) hinfo := new(dns.HINFO) hinfo.Hdr = dns.RR_Header{Name: question.Name, Rrtype: dns.TypeHINFO, Class: dns.ClassINET, Ttl: 86400} diff --git a/dnscrypt-proxy/plugin_cloak.go b/dnscrypt-proxy/plugin_cloak.go index 8d43205e..c47f0832 100644 --- a/dnscrypt-proxy/plugin_cloak.go +++ b/dnscrypt-proxy/plugin_cloak.go @@ -166,10 +166,7 @@ func (plugin *PluginCloak) Eval(pluginsState *PluginsState, msg *dns.Msg) error } } plugin.RUnlock() - synth, err := EmptyResponseFromMessage(msg) - if err != nil { - return err - } + synth := EmptyResponseFromMessage(msg) if ip == nil { synth.Answer = []dns.RR{} } else if question.Qtype == dns.TypeA { diff --git a/dnscrypt-proxy/plugin_firefox.go b/dnscrypt-proxy/plugin_firefox.go index d2ab4bf9..c3c0dcf5 100644 --- a/dnscrypt-proxy/plugin_firefox.go +++ b/dnscrypt-proxy/plugin_firefox.go @@ -46,10 +46,7 @@ func (plugin *PluginFirefox) Eval(pluginsState *PluginsState, msg *dns.Msg) erro if qName != "use-application-dns.net." && !strings.HasSuffix(qName, ".use-application-dns.net.") { return nil } - synth, err := EmptyResponseFromMessage(msg) - if err != nil { - return err - } + synth := EmptyResponseFromMessage(msg) synth.Rcode = dns.RcodeNameError pluginsState.synthResponse = synth pluginsState.action = PluginsActionSynth diff --git a/dnscrypt-proxy/plugins.go b/dnscrypt-proxy/plugins.go index 45e1f344..f830cae3 100644 --- a/dnscrypt-proxy/plugins.go +++ b/dnscrypt-proxy/plugins.go @@ -251,10 +251,7 @@ func (pluginsState *PluginsState) ApplyQueryPlugins(pluginsGlobals *PluginsGloba return packet, err } if pluginsState.action == PluginsActionReject { - synth, err := RefusedResponseFromMessage(&msg, pluginsGlobals.refusedCodeInResponses, pluginsGlobals.respondWithIPv4, pluginsGlobals.respondWithIPv6, pluginsState.rejectTTL) - if err != nil { - return nil, err - } + synth := RefusedResponseFromMessage(&msg, pluginsGlobals.refusedCodeInResponses, pluginsGlobals.respondWithIPv4, pluginsGlobals.respondWithIPv6, pluginsState.rejectTTL) pluginsState.synthResponse = synth } if pluginsState.action != PluginsActionForward { @@ -298,10 +295,7 @@ func (pluginsState *PluginsState) ApplyResponsePlugins(pluginsGlobals *PluginsGl return packet, err } if pluginsState.action == PluginsActionReject { - synth, err := RefusedResponseFromMessage(&msg, pluginsGlobals.refusedCodeInResponses, pluginsGlobals.respondWithIPv4, pluginsGlobals.respondWithIPv6, pluginsState.rejectTTL) - if err != nil { - return nil, err - } + synth := RefusedResponseFromMessage(&msg, pluginsGlobals.refusedCodeInResponses, pluginsGlobals.respondWithIPv4, pluginsGlobals.respondWithIPv6, pluginsState.rejectTTL) dlog.Infof("Blocking [%s]", synth.Question[0].Name) pluginsState.synthResponse = synth } diff --git a/dnscrypt-proxy/serversInfo.go b/dnscrypt-proxy/serversInfo.go index d4f07ff9..08a3c18b 100644 --- a/dnscrypt-proxy/serversInfo.go +++ b/dnscrypt-proxy/serversInfo.go @@ -75,18 +75,17 @@ func NewServersInfo() ServersInfo { return ServersInfo{lbStrategy: DefaultLBStrategy, lbEstimator: true, registeredServers: make([]RegisteredServer, 0)} } -func (serversInfo *ServersInfo) registerServer(name string, stamp stamps.ServerStamp) error { +func (serversInfo *ServersInfo) registerServer(name string, stamp stamps.ServerStamp) { newRegisteredServer := RegisteredServer{name: name, stamp: stamp} serversInfo.Lock() defer serversInfo.Unlock() for i, oldRegisteredServer := range serversInfo.registeredServers { if oldRegisteredServer.name == name { serversInfo.registeredServers[i] = newRegisteredServer - return nil + return } } serversInfo.registeredServers = append(serversInfo.registeredServers, newRegisteredServer) - return nil } func (serversInfo *ServersInfo) refreshServer(proxy *Proxy, name string, stamp stamps.ServerStamp) error { @@ -225,7 +224,7 @@ func fetchServerInfo(proxy *Proxy, name string, stamp stamps.ServerStamp, isNew return ServerInfo{}, errors.New("Unsupported protocol") } -func route(proxy *Proxy, name string, stamp *stamps.ServerStamp) (*net.UDPAddr, *net.TCPAddr, error) { +func route(proxy *Proxy, name string) (*net.UDPAddr, *net.TCPAddr, error) { routes := proxy.routes if routes == nil { return nil, nil, nil @@ -293,7 +292,7 @@ func fetchDNSCryptServerInfo(proxy *Proxy, name string, stamp stamps.ServerStamp dlog.Warnf("Public key [%s] shouldn't be hex-encoded any more", string(stamp.ServerPk)) stamp.ServerPk = serverPk } - relayUDPAddr, relayTCPAddr, err := route(proxy, name, &stamp) + relayUDPAddr, relayTCPAddr, err := route(proxy, name) if err != nil { return ServerInfo{}, err }