Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use next hint in case a hint fails. #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main
import (
"fmt"
"net"
"net/netip"
"os"
"sync"
"time"
Expand Down Expand Up @@ -95,22 +96,31 @@ func (b *Bootstrapper) tryBootstrapping() error {
wg.Wait()
close(hintersDone)
}()
seenIPs := make(map[netip.AddrPort]bool)
OuterLoop:
for {
select {
case ipAddr := <-b.ipHintsChan:
serverAddr := &ipAddr
if serverAddr.Port == 0 {
serverAddr.Port = int(hinting.DiscoveryPort)
}
addrPort := serverAddr.AddrPort()
if seenIPs[addrPort] {
log.Info("Ignoring previously seen hint", "hint", ipAddr)
continue
}
// Mark the ip as having been seen before, to prevent duplicate queries.
seenIPs[addrPort] = true
if err := checkIsRoutable(ipAddr.IP); err != nil {
// Ignore IPv6 hints if device does not have an IPv6 address, etc.
log.Debug("Ignore hint, no route", "hint", ipAddr, "err", err)
continue
}
serverAddr := &ipAddr
if serverAddr.Port == 0 {
serverAddr.Port = int(hinting.DiscoveryPort)
}
err := fetcher.FetchConfiguration(&cfg, serverAddr)
if err != nil {
return err
log.Debug("Failed to fetch configuration from server", "server", serverAddr, "err", err)
continue
}
break OuterLoop
case <-hintsTimeout:
Expand Down