提交 9e4b9714 作者: Brian Tiger Chow 提交者: Juan Batiz-Benet

feat(core) dht.Bootstrap

License: MIT
Signed-off-by: 's avatarBrian Tiger Chow <brian@perfmode.com>
上级 c065bcce
......@@ -20,9 +20,10 @@ import (
)
const (
period = 30 * time.Second // how often to check connection status
connectiontimeout time.Duration = period / 3 // duration to wait when attempting to connect
recoveryThreshold = 4 // attempt to bootstrap if connection count falls below this value
period = 30 * time.Second // how often to check connection status
connectiontimeout time.Duration = period / 3 // duration to wait when attempting to connect
recoveryThreshold = 4 // attempt to bootstrap if connection count falls below this value
numDHTBootstrapQueries = 10 // number of DHT queries to execute
)
func superviseConnections(parent context.Context,
......@@ -133,6 +134,9 @@ func connect(ctx context.Context, ps peer.Peerstore, r *dht.IpfsDHT, peers []pee
}(p)
}
wg.Wait()
if err := r.Bootstrap(ctx, numDHTBootstrapQueries); err != nil {
return err
}
return nil
}
......
......@@ -341,7 +341,7 @@ func (dht *IpfsDHT) PingRoutine(t time.Duration) {
}
// Bootstrap builds up list of peers by requesting random peer IDs
func (dht *IpfsDHT) Bootstrap(ctx context.Context, queries int) {
func (dht *IpfsDHT) Bootstrap(ctx context.Context, queries int) error {
// bootstrap sequentially, as results will compound
for i := 0; i < NumBootstrapQueries; i++ {
......@@ -357,4 +357,5 @@ func (dht *IpfsDHT) Bootstrap(ctx context.Context, queries int) {
log.Errorf("dht seemingly found a peer at a random bootstrap id (%s)...", pi)
}
}
return nil
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论