From d700ab6085c9c3896b7650de4d84daa5d4a0d0b4 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 12 Dec 2020 22:19:09 +0100 Subject: [PATCH] Nits --- dnscrypt-proxy/coldstart.go | 13 +++++-------- dnscrypt-proxy/serversInfo.go | 7 ++----- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/dnscrypt-proxy/coldstart.go b/dnscrypt-proxy/coldstart.go index 6d71abba..0150c3a2 100644 --- a/dnscrypt-proxy/coldstart.go +++ b/dnscrypt-proxy/coldstart.go @@ -13,10 +13,7 @@ import ( type CaptivePortalEntryips []net.IP -type CaptivePortalEntry struct { - name string - ips CaptivePortalEntryips -} +type CaptivePortalMap map[string]CaptivePortalEntryips type CaptivePortalHandler struct { cancelChannels []chan struct{} @@ -25,11 +22,11 @@ type CaptivePortalHandler struct { func (captivePortalHandler *CaptivePortalHandler) Stop() { for _, cancelChannel := range captivePortalHandler.cancelChannels { cancelChannel <- struct{}{} - _ = <-cancelChannel + <-cancelChannel } } -func handleColdStartClient(clientPc *net.UDPConn, cancelChannel chan struct{}, ipsMap *map[string]CaptivePortalEntryips) bool { +func handleColdStartClient(clientPc *net.UDPConn, cancelChannel chan struct{}, ipsMap *CaptivePortalMap) bool { buffer := make([]byte, MaxDNSPacketSize-1) clientPc.SetDeadline(time.Now().Add(time.Duration(1) * time.Second)) length, clientAddr, err := clientPc.ReadFrom(buffer) @@ -105,7 +102,7 @@ func handleColdStartClient(clientPc *net.UDPConn, cancelChannel chan struct{}, i return false } -func addColdStartListener(proxy *Proxy, ipsMap *map[string]CaptivePortalEntryips, listenAddrStr string, cancelChannel chan struct{}) error { +func addColdStartListener(proxy *Proxy, ipsMap *CaptivePortalMap, listenAddrStr string, cancelChannel chan struct{}) error { listenUDPAddr, err := net.ResolveUDPAddr("udp", listenAddrStr) if err != nil { return err @@ -132,7 +129,7 @@ func ColdStart(proxy *Proxy) (*CaptivePortalHandler, error) { dlog.Warn(err) return nil, err } - ipsMap := make(map[string]CaptivePortalEntryips) + ipsMap := make(CaptivePortalMap) for lineNo, line := range strings.Split(string(bin), "\n") { line = TrimAndStripInlineComments(line) if len(line) == 0 { diff --git a/dnscrypt-proxy/serversInfo.go b/dnscrypt-proxy/serversInfo.go index a4837e47..97316a33 100644 --- a/dnscrypt-proxy/serversInfo.go +++ b/dnscrypt-proxy/serversInfo.go @@ -16,7 +16,6 @@ import ( "github.com/VividCortex/ewma" "github.com/jedisct1/dlog" - "github.com/jedisct1/go-dnsstamps" stamps "github.com/jedisct1/go-dnsstamps" "github.com/miekg/dns" "golang.org/x/crypto/ed25519" @@ -59,7 +58,7 @@ type ServerInfo struct { SharedKey [32]byte MagicQuery [8]byte knownBugs ServerBugs - Proto dnsstamps.StampProtoType + Proto stamps.StampProtoType useGet bool } @@ -99,8 +98,6 @@ func (LBStrategyRandom) getCandidate(serversCount int) int { var DefaultLBStrategy = LBStrategyP2{} -type ODoHRelay struct{} - type DNSCryptRelay struct { RelayUDPAddr *net.UDPAddr RelayTCPAddr *net.TCPAddr @@ -260,7 +257,7 @@ func fetchServerInfo(proxy *Proxy, name string, stamp stamps.ServerStamp, isNew } else if stamp.Proto == stamps.StampProtoTypeDoH { return fetchDoHServerInfo(proxy, name, stamp, isNew) } - return ServerInfo{}, errors.New(fmt.Sprintf("Unsupported protocol for [%s]: [%s]", name, stamp.Proto.String())) + return ServerInfo{}, fmt.Errorf("Unsupported protocol for [%s]: [%s]", name, stamp.Proto.String()) } func route(proxy *Proxy, name string) (*Relay, error) {