|
@@ -84,11 +84,20 @@ func (d *DHT) Run(c *zap.Logger, ctx context.Context, host host.Host) error {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
- d.bootstrapPeers(c, ctx, host)
|
|
|
|
- d.announceAndConnect(ctx, kademliaDHT, host, d.Rendezvous())
|
|
|
|
|
|
+ connect := func() {
|
|
|
|
+ d.bootstrapPeers(c, ctx, host)
|
|
|
|
+ if d.latestRendezvous != "" {
|
|
|
|
+ d.announceAndConnect(ctx, kademliaDHT, host, d.latestRendezvous)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ rv := d.Rendezvous()
|
|
|
|
+ d.announceAndConnect(ctx, kademliaDHT, host, rv)
|
|
|
|
+ }
|
|
|
|
|
|
go func() {
|
|
go func() {
|
|
|
|
|
|
|
|
+ connect()
|
|
|
|
+
|
|
t := jitterbug.New(
|
|
t := jitterbug.New(
|
|
time.Second*time.Duration(d.RefreshDiscoveryTime),
|
|
time.Second*time.Duration(d.RefreshDiscoveryTime),
|
|
&jitterbug.Norm{Stdev: time.Second * 10},
|
|
&jitterbug.Norm{Stdev: time.Second * 10},
|
|
@@ -97,13 +106,7 @@ func (d *DHT) Run(c *zap.Logger, ctx context.Context, host host.Host) error {
|
|
for {
|
|
for {
|
|
select {
|
|
select {
|
|
case <-t.C:
|
|
case <-t.C:
|
|
- d.bootstrapPeers(c, ctx, host)
|
|
|
|
- if d.latestRendezvous != "" {
|
|
|
|
- d.announceAndConnect(ctx, kademliaDHT, host, d.latestRendezvous)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- rv := d.Rendezvous()
|
|
|
|
- d.announceAndConnect(ctx, kademliaDHT, host, rv)
|
|
|
|
|
|
+ connect()
|
|
|
|
|
|
case <-ctx.Done():
|
|
case <-ctx.Done():
|
|
return
|
|
return
|