-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
80 lines (62 loc) · 1.25 KB
/
Copy pathutils.go
File metadata and controls
80 lines (62 loc) · 1.25 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"net"
"path/filepath"
"time"
"github.com/miekg/dns"
)
func nextPowerOfTwo(v int) int {
v--
v |= v >> 1
v |= v >> 2
v |= v >> 4
v |= v >> 8
v |= v >> 16
v++
return v
}
func setTCPOptions(conn *net.TCPConn) {
conn.SetNoDelay(true)
conn.SetKeepAlive(true)
conn.SetKeepAlivePeriod(time.Duration(config.Upstream.KeepAlive) * time.Second)
conn.SetReadBuffer(config.Upstream.BufferSize)
conn.SetWriteBuffer(config.Upstream.BufferSize)
}
func isNetworkError(err error) bool {
if _, ok := err.(net.Error); ok {
return true
}
return false
}
func parseIncludeFiles(baseDir string, patterns []string) []string {
var files []string
seen := make(map[string]bool)
for _, pattern := range patterns {
if !filepath.IsAbs(pattern) {
pattern = filepath.Join(baseDir, pattern)
}
matches, err := filepath.Glob(pattern)
if err != nil {
continue
}
for _, match := range matches {
if !seen[match] {
files = append(files, match)
seen[match] = true
}
}
}
return files
}
func filterIPv6Records(rrs []dns.RR) []dns.RR {
if len(rrs) == 0 {
return rrs
}
var filtered []dns.RR
for _, rr := range rrs {
if rr.Header().Rrtype != dns.TypeAAAA {
filtered = append(filtered, rr)
}
}
return filtered
}