Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
use more peers if less than 3 are connected
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Oct 4, 2018
1 parent aadb8db commit d7f55b0
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions autonat.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (

var (
AutoNATBootDelay = 15 * time.Second
AutoNATRetryInterval = 60 * time.Second
AutoNATRetryInterval = 90 * time.Second
AutoNATRefreshInterval = 15 * time.Minute
AutoNATRequestTimeout = 60 * time.Second
)
Expand Down Expand Up @@ -174,23 +174,24 @@ func (as *AmbientAutoNAT) getPeers() []peer.ID {
return nil
}

peers := make([]peer.ID, 0, len(as.peers))
var connected, others []peer.ID

for p := range as.peers {
if as.host.Network().Connectedness(p) == inet.Connected {
peers = append(peers, p)
connected = append(connected, p)
} else {
others = append(others, p)
}
}

if len(peers) == 0 {
// we don't have any open connections, try any autonat peer that we know about
for p := range as.peers {
peers = append(peers, p)
}
}
shufflePeers(connected)

shufflePeers(peers)

return peers
if len(connected) < 3 {
shufflePeers(others)
return append(connected, others...)
} else {
return connected
}
}

func shufflePeers(peers []peer.ID) {
Expand Down

0 comments on commit d7f55b0

Please sign in to comment.