This commit is contained in:
Alex Schittko 2024-07-13 08:00:00 +00:00
parent 46fc5d3601
commit 650c88db1b
1 changed files with 24 additions and 15 deletions

View File

@ -91,28 +91,37 @@ func CreateListener(address string, port uint16, upstreams []string, bootstraps
upstreamList = append(upstreamList, upstream)
}
// Create a local cache with HTTPS proxy plugin
proxyPlugin := ProxyPlugin{
Upstreams: upstreamList,
}
chain := cache.New()
chain.Next = proxyPlugin
// Optionally disable http response caching
if os.Getenv("DISABLE_TUNNELDNS_CACHE") == "true" {
chain = proxyPlugin
}
// Format an endpoint
endpoint := "dns://" + net.JoinHostPort(address, strconv.FormatUint(uint64(port), 10))
// get middlewares for DNS Server
middlewares := getMiddlewares(upstreamList)
chain := NewMetricsPlugin(middlewares)
// Create the actual middleware server
server, err := dnsserver.NewServer(endpoint, []*dnsserver.Config{createConfig(address, port, NewMetricsPlugin(chain))})
server, err := dnsserver.NewServer(endpoint, []*dnsserver.Config{createConfig(address, port, chain)})
if err != nil {
return nil, err
}
return &Listener{server: server, log: log}, nil
}
// getMiddlewares() returns the middleware chain for DNS Server
//
// Middleware includes features like...
// * Response Cache
// * HTTP Proxy Settings
func getMiddlewares(upstreamList []Upstream) plugin.Handler {
proxyPlugin := ProxyPlugin{
Upstreams: upstreamList,
}
cachePlugin := cache.New()
cachePlugin.Next = proxyPlugin
if os.Getenv("DISABLE_TUNNELDNS_CACHE") == "true" {
return cachePlugin
}
return proxyPlugin
}