aboutsummaryrefslogtreecommitdiff
path: root/lib/dns/example_server_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2019-04-08 12:09:22 +0700
committerShulhan <ms@kilabit.info>2019-04-12 19:13:07 +0700
commitfaeaebe07acecd3fa18cc1fdb8e868108d318658 (patch)
treee09e300bc653588be538b5f13b830989a649cbc4 /lib/dns/example_server_test.go
parentce558fb263d4bdef58ebfd801331c6b074349f33 (diff)
downloadpakakeh.go-faeaebe07acecd3fa18cc1fdb8e868108d318658.tar.xz
dns: add caches for server
There are two type of answer: local and non-local. Local answer is a DNS record that is loaded from hosts file or master zone file. Non-local answer is a DNS record that is received from parent name servers. Server caches the DNS answers in two storages: map and list. The map caches store local and non local answers, using domain name as a key and list of answers as value, domain-name -> [{A,IN,...},{AAAA,IN,...}] The list caches store non-local answers, ordered by last accessed time, it is used to prune least frequently accessed answers. Local caches will never get pruned.
Diffstat (limited to 'lib/dns/example_server_test.go')
-rw-r--r--lib/dns/example_server_test.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/dns/example_server_test.go b/lib/dns/example_server_test.go
index 5046c042..e2689f08 100644
--- a/lib/dns/example_server_test.go
+++ b/lib/dns/example_server_test.go
@@ -3,6 +3,7 @@ package dns_test
import (
"fmt"
"log"
+ "time"
"github.com/shuLhan/share/lib/dns"
)
@@ -211,10 +212,6 @@ func ExampleServer() {
handler.generateResponses()
- server := &dns.Server{
- Handler: handler,
- }
-
serverOptions := &dns.ServerOptions{
IPAddress: "127.0.0.1",
TCPPort: 5300,
@@ -225,11 +222,16 @@ func ExampleServer() {
DoHAllowInsecure: true,
}
- err := server.Start(serverOptions)
+ server, err := dns.NewServer(serverOptions, handler)
if err != nil {
log.Fatal(err)
}
+ server.Start()
+
+ // Wait for all listeners running.
+ time.Sleep(500 * time.Millisecond)
+
clientLookup(serverAddress)
server.Stop()