@cryptotaxi247 / kubo / commits / 59f47cfd3

dht: bootstrap query logging

Juan Batiz-Benet committed Dec 9, 2014 at 11:22 UTC 59f47cfd34e88f5123eb1f95c46bba31296c1cc7
1 file changed +12 -4
routing/dht/dht.go
+12 -4
@@ -343,18 +343,26 @@ func (dht *IpfsDHT) PingRoutine(t time.Duration) {
343 // Bootstrap builds up list of peers by requesting random peer IDs
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++ {
346 + randomID := func() peer.ID {
347 + // 16 random bytes is not a valid peer id. it may be fine becuase
348 + // the dht will rehash to its own keyspace anyway.
349 id := make([]byte, 16)
350 rand.Read(id)
350 - pi, err := dht.FindPeer(ctx, peer.ID(id))
351 + return peer.ID(id)
352 + }
353 +
354 + // bootstrap sequentially, as results will compound
355 + for i := 0; i < queries; i++ {
356 + id := randomID()
357 + log.Debugf("Bootstrapping query (%d/%d) to random ID: %s", i, queries, id)
358 + p, err := dht.FindPeer(ctx, id)
359 if err == routing.ErrNotFound {
360 // this isn't an error. this is precisely what we expect.
361 } else if err != nil {
362 log.Errorf("Bootstrap peer error: %s", err)
363 } else {
364 // woah, we got a peer under a random id? it _cannot_ be valid.
357 - log.Errorf("dht seemingly found a peer at a random bootstrap id (%s)...", pi)
365 + log.Errorf("dht seemingly found a peer at a random bootstrap id (%s)...", p)
366 }
367 }
368 return nil