Browse Source

Added --timeout and --redirect

master
maze 1 year ago
parent
commit
7b56df4640
2 changed files with 27 additions and 10 deletions
  1. +5
    -1
      cmd/doh/main.go
  2. +22
    -9
      server.go

+ 5
- 1
cmd/doh/main.go View File

@ -24,12 +24,16 @@ func main() {
email = flag.String("email", "", "auto TLS email address")
certFile = flag.String("cert", "", "X.509 certificate file")
keyFile = flag.String("key", "", "X.509 key file")
timeout = flag.Duration("timeout", doh.DefaultQueryTimeout, "query timeout")
redirect = flag.String("redirect", doh.DefaultRedirect, "redirect page")
)
flag.Parse()
server := doh.NewServer()
server := doh.NewServer(*timeout)
server.Insecure = *insecure
server.Upstream = strings.Split(*upstream, ",")
server.Redirect = *redirect
if *autoTLS != "" {
server.AutoTLSManager.Cache = autocert.DirCache(*autoTLS)
server.AutoTLSManager.Email = *email


+ 22
- 9
server.go View File

@ -12,17 +12,20 @@ import (
"strings"
"time"
"github.com/sirupsen/logrus"
"github.com/miekg/dns"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/miekg/dns"
"github.com/sirupsen/logrus"
)
const (
queryTimeout = 5 * time.Second
userAgent = "maze.io/doh 1.0"
// DefaultQueryTimeout for doing DNS lookups.
DefaultQueryTimeout = 5 * time.Second
// DefaultRedirect is the redirect page for the root.
DefaultRedirect = "https://maze.io"
userAgent = "maze.io/doh 1.0"
)
type Server struct {
@ -38,14 +41,18 @@ type Server struct {
Verbose bool
LogGuessedIP bool
// Redirect URL
Redirect string
udpClient *dns.Client
tcpClient *dns.Client
tcpClientTLS *dns.Client
}
func NewServer() *Server {
func NewServer(queryTimeout time.Duration) *Server {
server := &Server{
Echo: echo.New(),
Echo: echo.New(),
Redirect: DefaultRedirect,
udpClient: &dns.Client{
Net: "udp",
UDPSize: dns.DefaultMsgSize,
@ -62,11 +69,17 @@ func NewServer() *Server {
},
}
// Tuning
server.HideBanner = true
// Middleware
//server.Use(middleware.Recover())
server.Use(middleware.Recover())
server.Use(middleware.Logger())
// Routes
server.GET("/", func(c echo.Context) error {
return c.Redirect(http.StatusFound, server.Redirect)
})
server.GET("/dns-query", server.handleDNSQuery)
server.POST("/dns-query", server.handleDNSQuery)


Loading…
Cancel
Save