forked from folbricht/routedns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dotlistener.go
52 lines (42 loc) · 1.17 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
package rdns
import (
"crypto/tls"
"github.com/miekg/dns"
"github.com/sirupsen/logrus"
)
// 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 string, opt DoTListenerOptions, resolver Resolver) *DoTListener {
return &DoTListener{
id: id,
Server: &dns.Server{
Addr: addr,
Net: "tcp-tls",
TLSConfig: opt.TLSConfig,
Handler: listenHandler(id, "dot", addr, resolver, opt.AllowedNet),
},
}
}
// Start the Dot server.
func (s DoTListener) Start() error {
Log.WithFields(logrus.Fields{"id": s.id, "protocol": "dot", "addr": s.Addr}).Info("starting listener")
return s.ListenAndServe()
}
// Stop the server.
func (s DoTListener) Stop() error {
Log.WithFields(logrus.Fields{"id": s.id, "protocol": "dot", "addr": s.Addr}).Info("stopping listener")
return s.Shutdown()
}
func (s DoTListener) String() string {
return s.id
}