From 6c3aeec9d232e40406bc3e977441fc9a16d5d99a Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Mon, 30 Dec 2019 15:27:39 +0100 Subject: Add support for prefetching --- README.md | 3 ++- cmd/zdns/main.go | 6 +++++- config.go | 1 + zdnsrc | 8 ++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4aeb9d6..fbbf057 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ configure. * **Control**: Filter unwanted content at the DNS-level. Similar to [Pi-hole](https://github.com/pi-hole/pi-hole). -* **Fast**: Efficient filtering and caching of DNS requests. +* **Fast**: Efficient filtering and caching of DNS requests. With pre-fetching + enabled, cached requests will never block waiting for the upstream resolver. * **Reliable**: Built with Go and [miekg/dns](https://github.com/miekg/dns) - a mature DNS library. * **Secure**: Protect your DNS requests from snooping and tampering using [DNS diff --git a/cmd/zdns/main.go b/cmd/zdns/main.go index fef8455..03fdb26 100644 --- a/cmd/zdns/main.go +++ b/cmd/zdns/main.go @@ -94,7 +94,11 @@ func (c *cli) run() { client := dnsutil.NewClient(config.Resolver.Protocol, config.Resolver.Timeout, config.DNS.Resolvers...) // Cache - cache := cache.New(config.DNS.CacheSize, nil) + var cclient *dnsutil.Client + if config.DNS.CachePrefetch { + cclient = client + } + cache := cache.New(config.DNS.CacheSize, cclient) sigHandler.OnClose(cache) // DNS server diff --git a/config.go b/config.go index e74413f..3d581f1 100644 --- a/config.go +++ b/config.go @@ -25,6 +25,7 @@ type DNSOptions struct { Listen string Protocol string `toml:"protocol"` CacheSize int `toml:"cache_size"` + CachePrefetch bool `toml:"cache_prefetch"` HijackMode string `toml:"hijack_mode"` hijackMode int RefreshInterval string `toml:"hosts_refresh_interval"` diff --git a/zdnsrc b/zdnsrc index 449a2b3..35daa0b 100644 --- a/zdnsrc +++ b/zdnsrc @@ -14,6 +14,14 @@ # # cache_size = 4096 +# Cache pre-fetching. +# +# If enabled, cached entries will be re-resolved asynchronously. Note that this +# may lead to slightly stale entries, but cached requests will never block +# waiting for the upstream resolver. +# +# cache_prefetch = false + # Upstream DNS servers to use when answering queries. # # The default is Cloudflare DNS servers, which support DNS-over-TLS. -- cgit v1.2.3