dial: shuffle relays
@@ -3,6 +3,7 @@ package relay
import (
"context"
"fmt"
+ "math/rand"
pb "github.com/libp2p/go-libp2p-circuit/pb"
@@ -71,6 +72,12 @@ func (d *RelayDialer) tryDialRelays(ctx context.Context, dinfo pstore.PeerInfo)
}
d.mx.Unlock()
+ // shuffle list of relays, avoid overloading a specific relay
+ for i := range relays {
+ j := rand.Intn(i + 1)
+ relays[i], relays[j] = relays[j], relays[i]
+ }
+
for _, relay := range relays {
if len(d.host.Network().ConnsToPeer(relay)) == 0 {
continue
