initial commit

This commit is contained in:
ginuerzh
2022-03-14 20:27:14 +08:00
commit 9397cb5351
175 changed files with 16196 additions and 0 deletions

41
handler/dns/metadata.go Normal file
View File

@ -0,0 +1,41 @@
package dns
import (
"net"
"time"
mdata "github.com/go-gost/gost/v3/pkg/metadata"
)
type metadata struct {
readTimeout time.Duration
ttl time.Duration
timeout time.Duration
clientIP net.IP
// nameservers
dns []string
}
func (h *dnsHandler) parseMetadata(md mdata.Metadata) (err error) {
const (
readTimeout = "readTimeout"
ttl = "ttl"
timeout = "timeout"
clientIP = "clientIP"
dns = "dns"
)
h.md.readTimeout = mdata.GetDuration(md, readTimeout)
h.md.ttl = mdata.GetDuration(md, ttl)
h.md.timeout = mdata.GetDuration(md, timeout)
if h.md.timeout <= 0 {
h.md.timeout = 5 * time.Second
}
sip := mdata.GetString(md, clientIP)
if sip != "" {
h.md.clientIP = net.ParseIP(sip)
}
h.md.dns = mdata.GetStrings(md, dns)
return
}