Skip to content

Commit 17ee6fb

Browse files
committed
Add DHTRouter interface
The implementation of ipfs/specs#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.
1 parent 246b1c6 commit 17ee6fb

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

compconfig.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"time"
66

77
"github.com/libp2p/go-libp2p-routing-helpers/tracing"
8+
"github.com/libp2p/go-libp2p/core/peer"
89
"github.com/libp2p/go-libp2p/core/routing"
910
"github.com/multiformats/go-multihash"
1011
)
@@ -37,3 +38,13 @@ type ReadyAbleRouter interface {
3738
type ComposableRouter interface {
3839
Routers() []routing.Routing
3940
}
41+
42+
// A DHTRouter provides DHT-specific operations.
43+
type DHTRouter interface {
44+
// GetClosestPeers returns the DHT closest peers to the given peer ID.
45+
// If empty, it will use the content router's peer ID
46+
// (self). `closerThan` (optional) forces the resulting records to be
47+
// closer to `PeerID` than to `closerThan`. `count` specifies how many
48+
// records to return ([1,100], with 20 as default when set to 0).
49+
GetClosestPeers(ctx context.Context, pid peer.ID, closerThan peer.ID, count int) (<-chan peer.AddrInfo, error)
50+
}

0 commit comments

Comments
 (0)