remove err return values that are never set

This commit is contained in:
Alison Winters 2019-11-01 23:37:33 +08:00 committed by Frank Denis
parent 36808cdec7
commit 97e4c44223
7 changed files with 17 additions and 40 deletions

View File

@ -54,11 +54,7 @@ func FetchCurrentDNSCryptCert(proxy *Proxy, serverName *string, proto string, pk
} else { } else {
txt = strings.Join(t.Txt, "") txt = strings.Join(t.Txt, "")
} }
binCert, err := packTxtString(txt) binCert := packTxtString(txt)
if err != nil {
dlog.Warnf("[%v] Unable to unpack the certificate", providerName)
continue
}
if len(binCert) < 124 { if len(binCert) < 124 {
dlog.Warnf("[%v] Certificate too short", providerName) dlog.Warnf("[%v] Certificate too short", providerName)
continue continue
@ -154,7 +150,7 @@ func dddToByte(s []byte) byte {
return byte((s[0]-'0')*100 + (s[1]-'0')*10 + (s[2] - '0')) 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)) bs := make([]byte, len(s))
msg := make([]byte, 0) msg := make([]byte, 0)
copy(bs, s) copy(bs, s)
@ -180,7 +176,7 @@ func packTxtString(s string) ([]byte, error) {
msg = append(msg, bs[i]) 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) { func dnsExchange(proxy *Proxy, proto string, query *dns.Msg, serverAddress string, relayUDPAddr *net.UDPAddr, relayTCPAddr *net.TCPAddr, serverName *string) (*dns.Msg, time.Duration, error) {

View File

@ -23,20 +23,17 @@ func TruncatedResponse(packet []byte) ([]byte, error) {
return dstMsg.Pack() return dstMsg.Pack()
} }
func EmptyResponseFromMessage(srcMsg *dns.Msg) (*dns.Msg, error) { func EmptyResponseFromMessage(srcMsg *dns.Msg) *dns.Msg {
dstMsg := srcMsg dstMsg := srcMsg
dstMsg.Response = true dstMsg.Response = true
dstMsg.Answer = make([]dns.RR, 0) dstMsg.Answer = make([]dns.RR, 0)
dstMsg.Ns = make([]dns.RR, 0) dstMsg.Ns = make([]dns.RR, 0)
dstMsg.Extra = 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) { func RefusedResponseFromMessage(srcMsg *dns.Msg, refusedCode bool, ipv4 net.IP, ipv6 net.IP, ttl uint32) *dns.Msg {
dstMsg, err := EmptyResponseFromMessage(srcMsg) dstMsg := EmptyResponseFromMessage(srcMsg)
if err != nil {
return dstMsg, err
}
if refusedCode { if refusedCode {
dstMsg.Rcode = dns.RcodeRefused dstMsg.Rcode = dns.RcodeRefused
} else { } 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 { func HasTCFlag(packet []byte) bool {

View File

@ -37,10 +37,7 @@ func (plugin *PluginBlockIPv6) Eval(pluginsState *PluginsState, msg *dns.Msg) er
if question.Qclass != dns.ClassINET || question.Qtype != dns.TypeAAAA { if question.Qclass != dns.ClassINET || question.Qtype != dns.TypeAAAA {
return nil return nil
} }
synth, err := EmptyResponseFromMessage(msg) synth := EmptyResponseFromMessage(msg)
if err != nil {
return err
}
hinfo := new(dns.HINFO) hinfo := new(dns.HINFO)
hinfo.Hdr = dns.RR_Header{Name: question.Name, Rrtype: dns.TypeHINFO, hinfo.Hdr = dns.RR_Header{Name: question.Name, Rrtype: dns.TypeHINFO,
Class: dns.ClassINET, Ttl: 86400} Class: dns.ClassINET, Ttl: 86400}

View File

@ -166,10 +166,7 @@ func (plugin *PluginCloak) Eval(pluginsState *PluginsState, msg *dns.Msg) error
} }
} }
plugin.RUnlock() plugin.RUnlock()
synth, err := EmptyResponseFromMessage(msg) synth := EmptyResponseFromMessage(msg)
if err != nil {
return err
}
if ip == nil { if ip == nil {
synth.Answer = []dns.RR{} synth.Answer = []dns.RR{}
} else if question.Qtype == dns.TypeA { } else if question.Qtype == dns.TypeA {

View File

@ -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.") { if qName != "use-application-dns.net." && !strings.HasSuffix(qName, ".use-application-dns.net.") {
return nil return nil
} }
synth, err := EmptyResponseFromMessage(msg) synth := EmptyResponseFromMessage(msg)
if err != nil {
return err
}
synth.Rcode = dns.RcodeNameError synth.Rcode = dns.RcodeNameError
pluginsState.synthResponse = synth pluginsState.synthResponse = synth
pluginsState.action = PluginsActionSynth pluginsState.action = PluginsActionSynth

View File

@ -251,10 +251,7 @@ func (pluginsState *PluginsState) ApplyQueryPlugins(pluginsGlobals *PluginsGloba
return packet, err return packet, err
} }
if pluginsState.action == PluginsActionReject { if pluginsState.action == PluginsActionReject {
synth, err := RefusedResponseFromMessage(&msg, pluginsGlobals.refusedCodeInResponses, pluginsGlobals.respondWithIPv4, pluginsGlobals.respondWithIPv6, pluginsState.rejectTTL) synth := RefusedResponseFromMessage(&msg, pluginsGlobals.refusedCodeInResponses, pluginsGlobals.respondWithIPv4, pluginsGlobals.respondWithIPv6, pluginsState.rejectTTL)
if err != nil {
return nil, err
}
pluginsState.synthResponse = synth pluginsState.synthResponse = synth
} }
if pluginsState.action != PluginsActionForward { if pluginsState.action != PluginsActionForward {
@ -298,10 +295,7 @@ func (pluginsState *PluginsState) ApplyResponsePlugins(pluginsGlobals *PluginsGl
return packet, err return packet, err
} }
if pluginsState.action == PluginsActionReject { if pluginsState.action == PluginsActionReject {
synth, err := RefusedResponseFromMessage(&msg, pluginsGlobals.refusedCodeInResponses, pluginsGlobals.respondWithIPv4, pluginsGlobals.respondWithIPv6, pluginsState.rejectTTL) synth := RefusedResponseFromMessage(&msg, pluginsGlobals.refusedCodeInResponses, pluginsGlobals.respondWithIPv4, pluginsGlobals.respondWithIPv6, pluginsState.rejectTTL)
if err != nil {
return nil, err
}
dlog.Infof("Blocking [%s]", synth.Question[0].Name) dlog.Infof("Blocking [%s]", synth.Question[0].Name)
pluginsState.synthResponse = synth pluginsState.synthResponse = synth
} }

View File

@ -75,18 +75,17 @@ func NewServersInfo() ServersInfo {
return ServersInfo{lbStrategy: DefaultLBStrategy, lbEstimator: true, registeredServers: make([]RegisteredServer, 0)} 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} newRegisteredServer := RegisteredServer{name: name, stamp: stamp}
serversInfo.Lock() serversInfo.Lock()
defer serversInfo.Unlock() defer serversInfo.Unlock()
for i, oldRegisteredServer := range serversInfo.registeredServers { for i, oldRegisteredServer := range serversInfo.registeredServers {
if oldRegisteredServer.name == name { if oldRegisteredServer.name == name {
serversInfo.registeredServers[i] = newRegisteredServer serversInfo.registeredServers[i] = newRegisteredServer
return nil return
} }
} }
serversInfo.registeredServers = append(serversInfo.registeredServers, newRegisteredServer) serversInfo.registeredServers = append(serversInfo.registeredServers, newRegisteredServer)
return nil
} }
func (serversInfo *ServersInfo) refreshServer(proxy *Proxy, name string, stamp stamps.ServerStamp) error { 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") 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 routes := proxy.routes
if routes == nil { if routes == nil {
return nil, nil, 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)) dlog.Warnf("Public key [%s] shouldn't be hex-encoded any more", string(stamp.ServerPk))
stamp.ServerPk = serverPk stamp.ServerPk = serverPk
} }
relayUDPAddr, relayTCPAddr, err := route(proxy, name, &stamp) relayUDPAddr, relayTCPAddr, err := route(proxy, name)
if err != nil { if err != nil {
return ServerInfo{}, err return ServerInfo{}, err
} }