From e72363306bb152ed28cb559bc1d7c6785916299e Mon Sep 17 00:00:00 2001 From: GreyXor Date: Tue, 4 Jul 2023 16:09:12 +0200 Subject: [PATCH] cleanup code style --- doh-client/selector/upstreamStatus.go | 6 +++--- doh-server/google.go | 3 ++- doh-server/ietf.go | 5 +++-- doh-server/main.go | 5 ++--- doh-server/server.go | 9 +++++---- json-dns/globalip.go | 1 - 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/doh-client/selector/upstreamStatus.go b/doh-client/selector/upstreamStatus.go index c3faf45..1b3cd93 100644 --- a/doh-client/selector/upstreamStatus.go +++ b/doh-client/selector/upstreamStatus.go @@ -3,12 +3,12 @@ package selector type upstreamStatus int const ( - // when query upstream timeout, usually upstream is unavailable for a long time + // when query upstream timeout, usually upstream is unavailable for a long time. Timeout upstreamStatus = iota - // when query upstream return 5xx response, upstream still alive, maybe just a lof of query for him + // when query upstream return 5xx response, upstream still alive, maybe just a lof of query for him. Error - // when query upstream ok, means upstream is available + // when query upstream ok, means upstream is available. OK ) diff --git a/doh-server/google.go b/doh-server/google.go index 3c5254a..533f314 100644 --- a/doh-server/google.go +++ b/doh-server/google.go @@ -34,9 +34,10 @@ import ( "strings" "time" - jsondns "github.com/m13253/dns-over-https/v2/json-dns" "github.com/miekg/dns" "golang.org/x/net/idna" + + jsondns "github.com/m13253/dns-over-https/v2/json-dns" ) func (s *Server) parseRequestGoogle(ctx context.Context, w http.ResponseWriter, r *http.Request) *DNSRequest { diff --git a/doh-server/ietf.go b/doh-server/ietf.go index 8b29255..c3535b1 100644 --- a/doh-server/ietf.go +++ b/doh-server/ietf.go @@ -36,8 +36,9 @@ import ( "strings" "time" - jsondns "github.com/m13253/dns-over-https/v2/json-dns" "github.com/miekg/dns" + + jsondns "github.com/m13253/dns-over-https/v2/json-dns" ) func (s *Server) parseRequestIETF(ctx context.Context, w http.ResponseWriter, r *http.Request) *DNSRequest { @@ -201,7 +202,7 @@ func (s *Server) generateResponseIETF(ctx context.Context, w http.ResponseWriter } } -// Workaround a bug causing DNSCrypt-Proxy to expect a response with TransactionID = 0xcafe +// Workaround a bug causing DNSCrypt-Proxy to expect a response with TransactionID = 0xcafe. func (s *Server) patchDNSCryptProxyReqID(w http.ResponseWriter, r *http.Request, requestBinary []byte) bool { if strings.Contains(r.UserAgent(), "dnscrypt-proxy") && bytes.Equal(requestBinary, []byte("\xca\xfe\x01\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00\x00\x02\x00\x01\x00\x00\x29\x10\x00\x00\x00\x80\x00\x00\x00")) { if s.conf.Verbose { diff --git a/doh-server/main.go b/doh-server/main.go index 51a2304..692d176 100644 --- a/doh-server/main.go +++ b/doh-server/main.go @@ -26,7 +26,6 @@ package main import ( "flag" "fmt" - "io" "log" "os" "runtime" @@ -35,7 +34,7 @@ import ( func checkPIDFile(pidFile string) (bool, error) { retry: - f, err := os.OpenFile(pidFile, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0666) + f, err := os.OpenFile(pidFile, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o666) if os.IsExist(err) { pidStr, err := os.ReadFile(pidFile) if err != nil { @@ -61,7 +60,7 @@ retry: return false, err } defer f.Close() - _, err = io.WriteString(f, strconv.FormatInt(int64(os.Getpid()), 10)) + _, err = f.WriteString(strconv.FormatInt(int64(os.Getpid()), 10)) if err != nil { return false, err } diff --git a/doh-server/server.go b/doh-server/server.go index bd7420c..35b26c2 100644 --- a/doh-server/server.go +++ b/doh-server/server.go @@ -37,8 +37,9 @@ import ( "time" "github.com/gorilla/handlers" - jsondns "github.com/m13253/dns-over-https/v2/json-dns" "github.com/miekg/dns" + + jsondns "github.com/m13253/dns-over-https/v2/json-dns" ) type Server struct { @@ -318,7 +319,7 @@ func (s *Server) findClientIP(r *http.Request) net.IP { return nil } -// Workaround a bug causing Unbound to refuse returning anything about the root +// Workaround a bug causing Unbound to refuse returning anything about the root. func (s *Server) patchRootRD(req *DNSRequest) *DNSRequest { for _, question := range req.request.Question { if question.Name == "." { @@ -328,7 +329,7 @@ func (s *Server) patchRootRD(req *DNSRequest) *DNSRequest { return req } -// Return the position index for the question of qtype from a DNS msg, otherwise return -1 +// Return the position index for the question of qtype from a DNS msg, otherwise return -1. func (s *Server) indexQuestionType(msg *dns.Msg, qtype uint16) int { for i, question := range msg.Question { if question.Qtype == qtype { @@ -363,7 +364,7 @@ func (s *Server) doDNSQuery(ctx context.Context, req *DNSRequest) (err error) { req.response, _, err = s.tcpClient.ExchangeContext(ctx, req.request, upstream) } - // Retry with TCP if this was an IXFR request and we only received an SOA + // Retry with TCP if this was an IXFR request, and we only received an SOA if (s.indexQuestionType(req.request, dns.TypeIXFR) > -1) && (len(req.response.Answer) == 1) && (req.response.Answer[0].Header().Rrtype == dns.TypeSOA) { diff --git a/json-dns/globalip.go b/json-dns/globalip.go index 7161dfb..39250a8 100644 --- a/json-dns/globalip.go +++ b/json-dns/globalip.go @@ -119,7 +119,6 @@ func init() { IP: net.IP{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, Mask: net.IPMask{0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, }, struct{}{}) - } func IsGlobalIP(ip net.IP) bool {