Fix ipv6 stuffs 2

This commit is contained in:
Ben Sarmiento
2024-01-11 02:41:50 +01:00
parent b526da1b4f
commit 8378422b3a
2 changed files with 4 additions and 2 deletions

View File

@@ -56,7 +56,7 @@ func MainApp(configPath string) {
if config.ShouldForceIPv6() { if config.ShouldForceIPv6() {
ipv6List, err = hosts.FetchHosts(hosts.IPV6) ipv6List, err = hosts.FetchHosts(hosts.IPV6)
if err != nil { if err != nil {
panic(err) zurglog.Warnf("Failed to fetch IPv6 hosts: %v", err)
} }
} }
downloadClient := http.NewHTTPClient(config.GetToken(), config.GetRetriesUntilFailed(), 0, ipv6List, config, log.Named("dlclient")) downloadClient := http.NewHTTPClient(config.GetToken(), config.GetRetriesUntilFailed(), 0, ipv6List, config, log.Named("dlclient"))

View File

@@ -127,14 +127,16 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, restrictToHost
} }
} }
if !found { if !found {
log.Warnf("Host %s is not an IPv6 host, replacing with a random host (ensure you have preferred_hosts properly set in your config.yml)", host) log.Warnf("Host %s is not an IPv6 host (ensure you have preferred_hosts properly set in your config.yml, if unset, run `zurg network-test -t ipv6`)", host)
// replace with a random ipv6 host // replace with a random ipv6 host
restrictToHostsLen := len(restrictToHosts) restrictToHostsLen := len(restrictToHosts)
randomHost := restrictToHosts[rand.Intn(restrictToHostsLen)] randomHost := restrictToHosts[rand.Intn(restrictToHostsLen)]
host = randomHost host = randomHost
log.Warnf("Replacing with a random IPv6 host: %s", host)
address = net.JoinHostPort(host, port) address = net.JoinHostPort(host, port)
} }
} }
// todo: replace .com with .cloud if needed
ips, err := net.DefaultResolver.LookupIPAddr(ctx, host) ips, err := net.DefaultResolver.LookupIPAddr(ctx, host)
if err != nil { if err != nil {
return nil, err return nil, err