libp2p / go-libp2p-kad-dht

A Kademlia DHT implementation on go-libp2p
https://github.com/libp2p/specs/tree/master/kad-dht
MIT License
524 stars 224 forks source link

How to make dht reconnect after network fault #294

Closed avbasov closed 5 years ago

avbasov commented 5 years ago

I have a problem with a DHT peer. It stops working after network faults.

  1. I connect a peer from my laptop to a p2p network on Digital Ocean droplet. And it works perfectly fine.
  2. Then I turn off WiFi on the laptop and wait for a bootstrap error dht: error bootstrapping: failed to find any peer in table.
  3. I turn WiFi on, but the peer doesn't reconnect to the p2p network and keeps writing the same error about empty peer table.

Could you, please, tell me what the proper way to restore connectivity is?

Here is a simplified code

ctx := context.Background()
ipfsLogLevel, _ := logging.LogLevel("DEBUG")
ipfsLog.SetAllLoggers(ipfsLogLevel)

host, _ := libp2p.New(ctx)
dht, _ := kadDHT.New(ctx, host)

host.Connect(ctx, seedPeer)
dht.BootstrapOnce(ctx, kadDHT.DefaultBootstrapConfig)

cfg := kadDHT.DefaultBootstrapConfig
cfg.Period = 30 * time.Second
dht.BootstrapWithConfig(ctx, cfg)

<-ctx.Done()
raulk commented 5 years ago

@anacrolix is the best person to dig into this.

anacrolix commented 5 years ago

Hi @avbasov . #254 and #283 are related to this. In the meanwhile, you'll have to manually reconnect to the seed peers. You might do this periodically, or when network conditions change, or when you get failed to find any peer in table errors. In https://github.com/libp2p/go-libp2p-kad-dht/issues/254#issuecomment-468105273, I mention fallback nodes, I think this issue is sufficient to prompt a stand-alone issue for that feature.

anacrolix commented 5 years ago

I've proposed the fix in #295. I'll leave this issue open for a while for any questions you have about workarounds.

avbasov commented 5 years ago

@anacrolix Thanks for the answer. The reconnection works.

anacrolix commented 5 years ago

Cheers.