/
config.go
63 lines (48 loc) · 1.31 KB
/
config.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
61
62
63
package requester
import (
"fmt"
"net"
)
type Config struct {
// TransportMethod is the transport method to be used
TransportMethod TransportMethodType
// Target is the target addr/url for the recursive DNS server used
Target string
// Domain is the base domain for the DNS request that the responder is authoritative for
BaseDomain string
// Pubkey is the public key for the listening responder
Pubkey []byte
// UtlsDistribution allows utls distribution to be specified for the utls connection used during DoH and DoT
UtlsDistribution string
// DialTransport allows for a custom dialer to be used for the underlying TCP/UDP transport
DialTransport dialFunc
}
// TransportMethodType declares the transport method to be used
type TransportMethodType int
const (
DoH TransportMethodType = iota
DoT
UDP
)
func defaultDialTransport() dialFunc {
dialer := net.Dialer{}
return dialer.DialContext
}
func (c *Config) dialTransport() dialFunc {
if c.DialTransport == nil {
return defaultDialTransport()
}
return c.DialTransport
}
func validateConfig(config *Config) error {
if config == nil {
return fmt.Errorf("no config provided")
}
if config.Target == "" {
return fmt.Errorf("no target configured")
}
if config.BaseDomain == "" {
return fmt.Errorf("no base domain configured")
}
return nil
}