Skip to content

Conversation

@Joyabrata001
Copy link

@Joyabrata001 Joyabrata001 commented Oct 5, 2025

Implements DHT-based peer discovery using libp2p’s Kademlia DHT. (#55 )

Changes

  • Updated internal/config/vault.go:

    • Added DiscoveryConfig and DHTConfig structs.
    • Added default discovery configuration under BuildVaultConfigWithDeduplication. (requires improvement)
  • Updated internal/p2p/factory.go:

    • CreateDHT() now returns a new DHTDiscovery instance.
  • Updated internal/p2p/dht.go:

    • Implements config.Discovery using libp2p’s Kademlia DHT.
    • Handles peer discovery, bootstrapping, and lifecycle management.
  • Added internal/p2p/dht_test.go:

    • Test for DHT discovery lifecycle and bootstrap connectivity.

    • Includes relay and NAT diagnostic checks.

    • go test ./internal/p2p -run TestDHTDiscovery -v

Scope of improvement:

  • internal/config/vault.go

    • Replace the hardcoded bootstrap peer with a configurable list or fallback to dht.GetDefaultBootstrapPeerAddrInfos() only when DHT is explicitly enabled.
    • The configuration structure below is hardcoded and needs to be made flexible:
      // Set default discovery settings
      config.Discovery = DiscoveryConfig{
          MDNS: true,
          DHT: DHTConfig{
              Enabled: true,
              BootstrapNodes: []string{
                  "/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
              },
          },
      }
  • internal/p2p/dht.go

    • Discovery interval and channel buffer are not configurable as of now.
    • Code can be logically refactored better
  • internal/p2p/dht_test.go

    • Replace time.Sleep with context or event-based waits

@codecov
Copy link

codecov bot commented Oct 5, 2025

Codecov Report

❌ Patch coverage is 62.29508% with 46 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/p2p/dht.go 68.46% 22 Missing and 13 partials ⚠️
internal/config/vault.go 0.00% 10 Missing ⚠️
internal/p2p/discovery.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Joyabrata001
Copy link
Author

@SubstantialCattle5 please reach out in case of any issues/suggestions/recommendations

@S4tvara
Copy link
Owner

S4tvara commented Oct 6, 2025

@Joyabrata001 Gimme some time to review the code.

@S4tvara
Copy link
Owner

S4tvara commented Oct 15, 2025

Hi @Joyabrata001 ,
could you provide screenshots and the steps to replicate the results you've obtained.
I wasn't able to replicate them from my end.

Cheers,
Nilay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants