chore: replace zhangyunhao116/fastrand to our metacubex/randv2

This commit is contained in:
wwqgtxx
2024-05-31 11:31:17 +08:00
parent d3fea909e9
commit 39eda257a7
35 changed files with 136 additions and 111 deletions

View File

@@ -12,8 +12,8 @@ import (
"github.com/metacubex/mihomo/common/utils"
"github.com/metacubex/mihomo/component/trie"
"github.com/metacubex/randv2"
"github.com/miekg/dns"
"github.com/zhangyunhao116/fastrand"
)
var (
@@ -93,7 +93,7 @@ func ResolveIPv4WithResolver(ctx context.Context, host string, r Resolver) (neti
} else if len(ips) == 0 {
return netip.Addr{}, fmt.Errorf("%w: %s", ErrIPNotFound, host)
}
return ips[fastrand.Intn(len(ips))], nil
return ips[randv2.IntN(len(ips))], nil
}
// ResolveIPv4 with a host, return ipv4
@@ -149,7 +149,7 @@ func ResolveIPv6WithResolver(ctx context.Context, host string, r Resolver) (neti
} else if len(ips) == 0 {
return netip.Addr{}, fmt.Errorf("%w: %s", ErrIPNotFound, host)
}
return ips[fastrand.Intn(len(ips))], nil
return ips[randv2.IntN(len(ips))], nil
}
func ResolveIPv6(ctx context.Context, host string) (netip.Addr, error) {
@@ -200,9 +200,9 @@ func ResolveIPWithResolver(ctx context.Context, host string, r Resolver) (netip.
}
ipv4s, ipv6s := SortationAddr(ips)
if len(ipv4s) > 0 {
return ipv4s[fastrand.Intn(len(ipv4s))], nil
return ipv4s[randv2.IntN(len(ipv4s))], nil
}
return ipv6s[fastrand.Intn(len(ipv6s))], nil
return ipv6s[randv2.IntN(len(ipv6s))], nil
}
// ResolveIP with a host, return ip and priority return TypeA