-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.go
48 lines (40 loc) · 883 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"log"
"time"
"github.com/miekg/dns"
)
type Server struct {
listen string
rTimeout time.Duration
wTimeout time.Duration
zones *ZoneStore
}
func (s *Server) Run() {
mux := dns.NewServeMux()
mux.HandleFunc(".", handleDNS)
tcpServer := &dns.Server{
Addr: s.listen,
Net: "tcp",
Handler: mux,
ReadTimeout: s.rTimeout,
WriteTimeout: s.wTimeout,
}
udpServer := &dns.Server{
Addr: s.listen,
Net: "udp",
Handler: mux,
UDPSize: 65535,
ReadTimeout: s.rTimeout,
WriteTimeout: s.wTimeout,
}
go s.start(udpServer)
go s.start(tcpServer)
}
func (s *Server) start(ds *dns.Server) {
log.Printf("Starting %s listener on %s\n", ds.Net, s.listen)
err := ds.ListenAndServe()
if err != nil {
log.Fatalf("Starting %s listener on %s failed:%s", ds.Net, s.listen, err.Error())
}
}