-
Notifications
You must be signed in to change notification settings - Fork 43
/
metadata.go
64 lines (56 loc) · 1.27 KB
/
metadata.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
64
package dns
import (
"net"
"strings"
"time"
mdata "github.com/go-gost/core/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
const (
defaultTimeout = 5 * time.Second
defaultBufferSize = 1024
)
type metadata struct {
readTimeout time.Duration
ttl time.Duration
timeout time.Duration
clientIP net.IP
// nameservers
dns []string
bufferSize int
async bool
}
func (h *dnsHandler) parseMetadata(md mdata.Metadata) (err error) {
const (
readTimeout = "readTimeout"
ttl = "ttl"
timeout = "timeout"
clientIP = "clientIP"
dns = "dns"
bufferSize = "bufferSize"
async = "async"
)
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
h.md.ttl = mdutil.GetDuration(md, ttl)
h.md.timeout = mdutil.GetDuration(md, timeout)
if h.md.timeout <= 0 {
h.md.timeout = defaultTimeout
}
sip := mdutil.GetString(md, clientIP)
if sip != "" {
h.md.clientIP = net.ParseIP(sip)
}
for _, v := range strings.Split(mdutil.GetString(md, dns), ",") {
v = strings.TrimSpace(v)
if v == "" {
continue
}
h.md.dns = append(h.md.dns, v)
}
h.md.bufferSize = mdutil.GetInt(md, bufferSize)
if h.md.bufferSize <= 0 {
h.md.bufferSize = defaultBufferSize
}
h.md.async = mdutil.GetBool(md, async)
return
}