-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathdotlistener.go
60 lines (50 loc) · 1.15 KB
/
dotlistener.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
49
50
51
52
53
54
55
56
57
58
59
60
package rdns
import (
"crypto/tls"
"github.com/miekg/dns"
)
// DoTListener is a DNS listener/server for DNS-over-TLS.
type DoTListener struct {
*dns.Server
id string
}
var _ Listener = &DoTListener{}
// DoTListenerOptions contains options used by the DNS-over-TLS server.
type DoTListenerOptions struct {
ListenOptions
TLSConfig *tls.Config
}
// NewDoTListener returns an instance of a DNS-over-TLS listener.
func NewDoTListener(id, addr, network string, opt DoTListenerOptions, resolver Resolver) *DoTListener {
if network == "" {
network = "tcp-tls"
}
return &DoTListener{
id: id,
Server: &dns.Server{
Addr: addr,
Net: network,
TLSConfig: opt.TLSConfig,
Handler: listenHandler(id, "dot", addr, resolver, opt.AllowedNet),
},
}
}
// Start the Dot server.
func (s DoTListener) Start() error {
Log.Info("starting listener",
"id", s.id,
"protocol", "dot",
"addr", s.Addr)
return s.ListenAndServe()
}
// Stop the server.
func (s DoTListener) Stop() error {
Log.Info("stopping listener",
"id", s.id,
"protocol", "dot",
"addr", s.Addr)
return s.Shutdown()
}
func (s DoTListener) String() string {
return s.id
}