@@ -126,10 +126,10 @@ type IpfsDHT struct {
126126
127127 autoRefresh bool
128128
129- // A set of bootstrap peers to fallback on if all other attempts to fix
129+ // A function returning a set of bootstrap peers to fallback on if all other attempts to fix
130130 // the routing table fail (or, e.g., this is the first time this node is
131131 // connecting to the network).
132- bootstrapPeers []peer.AddrInfo
132+ bootstrapPeers func () []peer.AddrInfo
133133
134134 maxRecordAge time.Duration
135135
@@ -473,15 +473,16 @@ func (dht *IpfsDHT) fixLowPeers(ctx context.Context) {
473473 // We should first use non-bootstrap peers we knew of from previous
474474 // snapshots of the Routing Table before we connect to the bootstrappers.
475475 // See https://github.com/libp2p/go-libp2p-kad-dht/issues/387.
476- if dht .routingTable .Size () == 0 {
477- if len (dht .bootstrapPeers ) == 0 {
476+ if dht .routingTable .Size () == 0 && dht .bootstrapPeers != nil {
477+ bootstrapPeers := dht .bootstrapPeers ()
478+ if len (bootstrapPeers ) == 0 {
478479 // No point in continuing, we have no peers!
479480 return
480481 }
481482
482483 found := 0
483- for _ , i := range rand .Perm (len (dht . bootstrapPeers )) {
484- ai := dht . bootstrapPeers [i ]
484+ for _ , i := range rand .Perm (len (bootstrapPeers )) {
485+ ai := bootstrapPeers [i ]
485486 err := dht .Host ().Connect (ctx , ai )
486487 if err == nil {
487488 found ++
0 commit comments