From 17ee6fbf872c602a5487c084871f0e5a630bf80d Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 3 Sep 2025 14:54:49 +0200 Subject: [PATCH 1/3] Add DHTRouter interface The implementation of https://github.com/ipfs/specs/pull/476 suggests that content routers should support a DHT-specific operations (GetClosestPeers). Content routers depend on routing interfaces defined in the `routing` package and some decorator interfaces defined here. So it seems like the natural place to add yet another interface for this type of router. --- compconfig.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/compconfig.go b/compconfig.go index d259c44..3ba17f1 100644 --- a/compconfig.go +++ b/compconfig.go @@ -5,6 +5,7 @@ import ( "time" "github.com/libp2p/go-libp2p-routing-helpers/tracing" + "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" "github.com/multiformats/go-multihash" ) @@ -37,3 +38,13 @@ type ReadyAbleRouter interface { type ComposableRouter interface { Routers() []routing.Routing } + +// A DHTRouter provides DHT-specific operations. +type DHTRouter interface { + // GetClosestPeers returns the DHT closest peers to the given peer ID. + // If empty, it will use the content router's peer ID + // (self). `closerThan` (optional) forces the resulting records to be + // closer to `PeerID` than to `closerThan`. `count` specifies how many + // records to return ([1,100], with 20 as default when set to 0). + GetClosestPeers(ctx context.Context, pid peer.ID, closerThan peer.ID, count int) (<-chan peer.AddrInfo, error) +} From fe2c8e446449dfcb54377459684e244db1df523f Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 25 Sep 2025 14:00:12 +0200 Subject: [PATCH 2/3] DHTRouter.GetClosestPeers: remove params. --- compconfig.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/compconfig.go b/compconfig.go index 3ba17f1..1d39096 100644 --- a/compconfig.go +++ b/compconfig.go @@ -43,8 +43,6 @@ type ComposableRouter interface { type DHTRouter interface { // GetClosestPeers returns the DHT closest peers to the given peer ID. // If empty, it will use the content router's peer ID - // (self). `closerThan` (optional) forces the resulting records to be - // closer to `PeerID` than to `closerThan`. `count` specifies how many - // records to return ([1,100], with 20 as default when set to 0). - GetClosestPeers(ctx context.Context, pid peer.ID, closerThan peer.ID, count int) (<-chan peer.AddrInfo, error) + // (self). + GetClosestPeers(ctx context.Context, pid peer.ID) (<-chan peer.AddrInfo, error) } From f098f492895eb4c370e9c986630e02d26708dd9b Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 16 Oct 2025 10:36:11 +0200 Subject: [PATCH 3/3] DHTRouter: GetClosestPeers uses Cid --- compconfig.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compconfig.go b/compconfig.go index 1d39096..ebfab3c 100644 --- a/compconfig.go +++ b/compconfig.go @@ -4,6 +4,7 @@ import ( "context" "time" + "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-routing-helpers/tracing" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" @@ -44,5 +45,5 @@ type DHTRouter interface { // GetClosestPeers returns the DHT closest peers to the given peer ID. // If empty, it will use the content router's peer ID // (self). - GetClosestPeers(ctx context.Context, pid peer.ID) (<-chan peer.AddrInfo, error) + GetClosestPeers(ctx context.Context, key cid.Cid) (<-chan peer.AddrInfo, error) }