Simplified the code a bit
Some checks failed
Compile dohproxy / build (push) Failing after 45s

This commit is contained in:
Afonso Franco 2024-09-01 15:51:35 +01:00
parent 2270f0d967
commit 08350321fd
Signed by: afonso
SSH key fingerprint: SHA256:PQTRDHPH3yALEGtHXnXBp3Orfcn21pK20t0tS1kHg54

View file

@ -15,31 +15,26 @@ import (
"golang.org/x/net/http2" "golang.org/x/net/http2"
) )
// ProtocolType represents the type of DNS protocol
type ProtocolType int
const ( const (
// Enum-like constants for ProtocolType // Enum-like constants for ProtocolType
TCP ProtocolType = iota TCP int = iota
UDP UDP
) )
// DoHProxy represents the DNS-over-HTTPS proxy // DoHProxy represents the DNS-over-HTTPS proxy
type DoHProxy struct { type DoHProxy struct {
listenAddress string listenAddress string // Address to listen for DNS queries on
port string port string // Port to listen for DNS queries on
upstreamURLs []string upstreamURLs []string // Upstream DoH server URLs
client *http.Client protocols []int // List of protocols to listen on
protocols []ProtocolType // List of protocols to listen on client *http.Client //Http client that makes the requests to the upstream servers
logRequests bool logRequests bool // Flag that enables logging
} }
// NewDoHProxy initializes a new DoHProxy instance // NewDoHProxy initializes a new DoHProxy instance
func NewDoHProxy(listenAddress, port string, upstreamURLs []string, protocols []ProtocolType, logRequests bool) *DoHProxy { func NewDoHProxy(listenAddress, port string, upstreamURLs []string, protocols []int, logRequests bool) *DoHProxy {
// HTTP client with support for HTTP/2 // HTTP client with support for HTTP/2
transport := &http.Transport{ transport := &http.Transport{}
TLSClientConfig: &tls.Config{},
}
http2.ConfigureTransport(transport) // Enable HTTP/2 support http2.ConfigureTransport(transport) // Enable HTTP/2 support
@ -186,7 +181,7 @@ WARNING:
} }
// Determine which protocols to use // Determine which protocols to use
var protocols []ProtocolType var protocols []int
if *tcpFlag { if *tcpFlag {
protocols = append(protocols, TCP) protocols = append(protocols, TCP)
} }
@ -195,7 +190,7 @@ WARNING:
} }
if !*tcpFlag && !*udpFlag { if !*tcpFlag && !*udpFlag {
// Default to both if no specific flag is provided // Default to both if no specific flag is provided
protocols = []ProtocolType{TCP, UDP} protocols = []int{TCP, UDP}
} }
if *logFlag { if *logFlag {
log.Println("Logging requests") log.Println("Logging requests")