From 40f4354e65f60271cddda365b479acca656b0098 Mon Sep 17 00:00:00 2001 From: Antonio Navarro Perez Date: Fri, 16 Sep 2022 15:27:56 +0200 Subject: [PATCH] Add ContentRoutingMany interface. We had been using the ProvideMany method in some Routing implementations to improve performance. We had several places where we needed to create this same interface to cast Routers to check if they support the ProvideMany method. To avoid that, and to have a common source of truth we think we should make this interface live with the other Routing ones. --- core/routing/routing.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/routing/routing.go b/core/routing/routing.go index 07437b5dff..f513eaa03a 100644 --- a/core/routing/routing.go +++ b/core/routing/routing.go @@ -7,6 +7,7 @@ import ( ci "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" + "github.com/multiformats/go-multihash" cid "github.com/ipfs/go-cid" ) @@ -36,6 +37,16 @@ type ContentRouting interface { FindProvidersAsync(context.Context, cid.Cid, int) <-chan peer.AddrInfo } +// ContentRoutingMany complements ContentRouting intetface allowing providing several keys at +// the same time, improving performance. +type ContentRoutingMany interface { + // ProvideMany adds the given keys to the content routing system. + ProvideMany(ctx context.Context, keys []multihash.Multihash) error + + // Ready checks if the router is ready to start providing keys. + Ready() bool +} + // PeerRouting is a way to find address information about certain peers. // This can be implemented by a simple lookup table, a tracking server, // or even a DHT.