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 {
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) {

View File

@ -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 {

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 {
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}

View File

@ -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 {

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

View File

@ -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
}

View File

@ -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
}