Skip to content

Commit

Permalink
fix: compile error in mac
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Feb 20, 2024
1 parent 358368f commit b08f041
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion route/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func NewRouter(
}

for domain, tag := range checkDNSLoopDomain {
addrs, err := lookupStaticIP(domain, dns.DomainStrategyAsIS, router.staticDns)
addrs, err := router.lookupStaticIP(domain, dns.DomainStrategyAsIS)
if err == nil && addrs != nil && len(addrs) != 0 {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion route/router_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (r *Router) Lookup(ctx context.Context, domain string, strategy dns.DomainS
ctx, cancel := context.WithTimeout(ctx, C.DNSTimeout)
defer cancel()

addrs, err := lookupStaticIP(domain, strategy, r.staticDns)
addrs, err := r.lookupStaticIP(domain, strategy)
if addrs == nil || err != nil {
addrs, err = r.dnsClient.Lookup(ctx, transport, domain, strategy)
}
Expand Down
42 changes: 21 additions & 21 deletions route/staticDNS.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ func errorIfEmpty(addrs []netip.Addr) ([]netip.Addr, error) {
}
return addrs, nil
}
func lookupStaticIP(domain string, strategy uint8, entries map[string]StaticDNSEntry) ([]netip.Addr, error) {

if staticDns, ok := entries[domain]; ok {
func (router *Router) lookupStaticIP(domain string, strategy uint8) ([]netip.Addr, error) {
if staticDns, ok := router.staticDns[domain]; ok {

switch strategy {
case dns.DomainStrategyUseIPv4:
Expand Down Expand Up @@ -79,24 +78,25 @@ func lookupStaticIP(domain string, strategy uint8, entries map[string]StaticDNSE
}
return []netip.Addr{ipaddr}, nil
}
if strings.Contains(domain, ",") {
entry := StaticDNSEntry{}
for _, ipString := range strings.Split(domain, ",") {
ip, err := netip.ParseAddr(ipString)
if err != nil {
fmt.Printf("Invalid IP address for domain %s: %s\n", domain, ipString)
continue
}

if ip.Is4() {
entry.IPv4 = append(entry.IPv4, ip)
} else {
entry.IPv6 = append(entry.IPv6, ip)
}
}
entries[domain] = entry
return lookupStaticIP(domain, strategy, entries)
}
// if strings.Contains(domain, ",") {
// entry := StaticDNSEntry{}
// for _, ipString := range strings.Split(domain, ",") {
// ip, err := netip.ParseAddr(ipString)
// if err != nil {
// fmt.Printf("Invalid IP address for domain %s: %s\n", domain, ipString)
// continue
// }

// if ip.Is4() {
// entry.IPv4 = append(entry.IPv4, ip)
// } else {
// entry.IPv6 = append(entry.IPv6, ip)
// }
// }
// fmt.Println("Adding ",domain, entry)
// router.staticDns[domain] = entry
// return router.lookupStaticIP(domain, strategy)
// }
return nil, fmt.Errorf("NotFound")
}

Expand Down

0 comments on commit b08f041

Please sign in to comment.