core: Add a ContentDiscovery field
No behaviour changes. Currently we are using ProvideManyRouter for Bitswap, which is only meant to use ContentDiscovery. This makes things more clear in that there is a designated ContentDiscovery instance.
Hector Sanjuan committed
Aug 1, 2025 at 12:22 UTC
19300f2d3faa26d29892a5d46900b3f591114db9
4 files changed
+13
-4
core/core.go
+1
@@ -98,6 +98,7 @@ type IpfsNode struct {
98
Filters *ma.Filters `optional:"true"`
99
Bootstrapper io.Closer `optional:"true"` // the periodic bootstrapper
100
Routing irouting.ProvideManyRouter `optional:"true"` // the routing system. recommend ipfs-dht
101
+ ContentDiscovery routing.ContentDiscovery `optional:"true"` // the discovery part of the routing system
102
DNSResolver *madns.Resolver // the DNS resolver
103
IPLDPathResolver pathresolver.Resolver `name:"ipldPathResolver"` // The IPLD path resolver
104
UnixFSPathResolver pathresolver.Resolver `name:"unixFSPathResolver"` // The UnixFS path resolver
core/node/bitswap.go
+3
-3
@@ -21,9 +21,9 @@ import (
21
ipld "github.com/ipfs/go-ipld-format"
22
version "github.com/ipfs/kubo"
23
"github.com/ipfs/kubo/config"
24
- irouting "github.com/ipfs/kubo/routing"
24
"github.com/libp2p/go-libp2p/core/host"
25
peer "github.com/libp2p/go-libp2p/core/peer"
26
+ "github.com/libp2p/go-libp2p/core/routing"
27
"go.uber.org/fx"
28
29
blocks "github.com/ipfs/go-block-format"
@@ -75,7 +75,7 @@ type bitswapIn struct {
75
Mctx helpers.MetricsCtx
76
Cfg *config.Config
77
Host host.Host
78
- Rt irouting.ProvideManyRouter
78
+ Discovery routing.ContentDiscovery
79
Bs blockstore.GCBlockstore
80
BitswapOpts []bitswap.Option `group:"bitswap-options"`
81
}
@@ -178,7 +178,7 @@ func Bitswap(serverEnabled, libp2pEnabled, httpEnabled bool) interface{} {
178
ignoredPeerIDs = append(ignoredPeerIDs, pid)
179
}
180
providerQueryMgr, err := rpqm.New(bitswapNetworks,
181
- in.Rt,
181
+ in.Discovery,
182
rpqm.WithMaxProviders(maxProviders),
183
rpqm.WithIgnoreProviders(ignoredPeerIDs...),
184
)
core/node/groups.go
+2
@@ -216,6 +216,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part
216
217
fx.Provide(libp2p.Routing),
218
fx.Provide(libp2p.ContentRouting),
219
+ fx.Provide(libp2p.ContentDiscovery),
220
221
fx.Provide(libp2p.BaseRouting(cfg)),
222
maybeProvide(libp2p.PubsubRouter, bcfg.getOpt("ipnsps")),
@@ -380,6 +381,7 @@ func Offline(cfg *config.Config) fx.Option {
381
fx.Provide(libp2p.Routing),
382
fx.Provide(libp2p.ContentRouting),
383
fx.Provide(libp2p.OfflineRouting),
384
+ fx.Provide(libp2p.ContentDiscovery),
385
OfflineProviders(),
386
)
387
}
core/node/libp2p/routing.go
+7
-1
@@ -177,6 +177,12 @@ func ContentRouting(in p2pOnlineContentRoutingIn) routing.ContentRouting {
177
}
178
}
179
180
+// ContentDiscovery narrows down the given content routing facility so that it
181
+// only does discovery.
182
+func ContentDiscovery(in irouting.ProvideManyRouter) routing.ContentDiscovery {
183
+ return in
184
+}
185
+
186
type p2pOnlineRoutingIn struct {
187
fx.In
188
@@ -185,7 +191,7 @@ type p2pOnlineRoutingIn struct {
191
}
192
193
// Routing will get all routers obtained from different methods (delegated
188
-// routers, pub-sub, and so on) and add them all together using a TieredRouter.
194
+// routers, pub-sub, and so on) and add them all together using a ParallelRouter.
195
func Routing(in p2pOnlineRoutingIn) irouting.ProvideManyRouter {
196
routers := in.Routers
197