fix dns handler panic

This commit is contained in:
ginuerzh 2024-01-08 21:20:56 +08:00
parent 262ac0e9a5
commit 936954ecf2
2 changed files with 13 additions and 2 deletions

View File

@ -71,7 +71,10 @@ func (h *dnsHandler) Init(md md.Metadata) (err error) {
for i, addr := range h.md.dns { for i, addr := range h.md.dns {
nodes = append(nodes, chain.NewNode(fmt.Sprintf("target-%d", i), addr)) nodes = append(nodes, chain.NewNode(fmt.Sprintf("target-%d", i), addr))
} }
h.hop = xhop.NewHop(xhop.NodeOption(nodes...)) h.hop = xhop.NewHop(
xhop.NodeOption(nodes...),
xhop.LoggerOption(log),
)
} }
var nodes []*chain.Node var nodes []*chain.Node

View File

@ -2,6 +2,7 @@ package dns
import ( import (
"net" "net"
"strings"
"time" "time"
mdata "github.com/go-gost/core/metadata" mdata "github.com/go-gost/core/metadata"
@ -45,7 +46,14 @@ func (h *dnsHandler) parseMetadata(md mdata.Metadata) (err error) {
if sip != "" { if sip != "" {
h.md.clientIP = net.ParseIP(sip) h.md.clientIP = net.ParseIP(sip)
} }
h.md.dns = mdutil.GetStrings(md, dns) 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) h.md.bufferSize = mdutil.GetInt(md, bufferSize)
if h.md.bufferSize <= 0 { if h.md.bufferSize <= 0 {
h.md.bufferSize = defaultBufferSize h.md.bufferSize = defaultBufferSize