mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-03-29 09:50:25 +00:00
cleanup code style
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user