@cryptotaxi247 / kubo / commits / 9e4b9714c

feat(core) dht.Bootstrap

License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>

Brian Tiger Chow committed Dec 8, 2014 at 18:21 UTC 9e4b9714ce641b151178319569d0eca71b9fd802
2 files changed +9 -4
core/bootstrap.go
+7 -3
@@ -20,9 +20,10 @@ import (
20 )
21
22 const (
23 - period = 30 * time.Second // how often to check connection status
24 - connectiontimeout time.Duration = period / 3 // duration to wait when attempting to connect
25 - recoveryThreshold = 4 // attempt to bootstrap if connection count falls below this value
23 + period = 30 * time.Second // how often to check connection status
24 + connectiontimeout time.Duration = period / 3 // duration to wait when attempting to connect
25 + recoveryThreshold = 4 // attempt to bootstrap if connection count falls below this value
26 + numDHTBootstrapQueries = 10 // number of DHT queries to execute
27 )
28
29 func superviseConnections(parent context.Context,
@@ -133,6 +134,9 @@ func connect(ctx context.Context, ps peer.Peerstore, r *dht.IpfsDHT, peers []pee
134 }(p)
135 }
136 wg.Wait()
137 + if err := r.Bootstrap(ctx, numDHTBootstrapQueries); err != nil {
138 + return err
139 + }
140 return nil
141 }
142
routing/dht/dht.go
+2 -1
@@ -341,7 +341,7 @@ func (dht *IpfsDHT) PingRoutine(t time.Duration) {
341 }
342
343 // Bootstrap builds up list of peers by requesting random peer IDs
344 -func (dht *IpfsDHT) Bootstrap(ctx context.Context, queries int) {
344 +func (dht *IpfsDHT) Bootstrap(ctx context.Context, queries int) error {
345
346 // bootstrap sequentially, as results will compound
347 for i := 0; i < NumBootstrapQueries; i++ {
@@ -357,4 +357,5 @@ func (dht *IpfsDHT) Bootstrap(ctx context.Context, queries int) {
357 log.Errorf("dht seemingly found a peer at a random bootstrap id (%s)...", pi)
358 }
359 }
360 + return nil
361 }