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.
This commit is contained in:
Hector Sanjuan 2025-08-01 12:22:13 +02:00
parent 8862a5e58e
commit 19300f2d3f
4 changed files with 13 additions and 4 deletions

View File

@ -98,6 +98,7 @@ type IpfsNode struct {
Filters *ma.Filters `optional:"true"`
Bootstrapper io.Closer `optional:"true"` // the periodic bootstrapper
Routing irouting.ProvideManyRouter `optional:"true"` // the routing system. recommend ipfs-dht
ContentDiscovery routing.ContentDiscovery `optional:"true"` // the discovery part of the routing system
DNSResolver *madns.Resolver // the DNS resolver
IPLDPathResolver pathresolver.Resolver `name:"ipldPathResolver"` // The IPLD path resolver
UnixFSPathResolver pathresolver.Resolver `name:"unixFSPathResolver"` // The UnixFS path resolver

View File

@ -21,9 +21,9 @@ import (
ipld "github.com/ipfs/go-ipld-format"
version "github.com/ipfs/kubo"
"github.com/ipfs/kubo/config"
irouting "github.com/ipfs/kubo/routing"
"github.com/libp2p/go-libp2p/core/host"
peer "github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/routing"
"go.uber.org/fx"
blocks "github.com/ipfs/go-block-format"
@ -75,7 +75,7 @@ type bitswapIn struct {
Mctx helpers.MetricsCtx
Cfg *config.Config
Host host.Host
Rt irouting.ProvideManyRouter
Discovery routing.ContentDiscovery
Bs blockstore.GCBlockstore
BitswapOpts []bitswap.Option `group:"bitswap-options"`
}
@ -178,7 +178,7 @@ func Bitswap(serverEnabled, libp2pEnabled, httpEnabled bool) interface{} {
ignoredPeerIDs = append(ignoredPeerIDs, pid)
}
providerQueryMgr, err := rpqm.New(bitswapNetworks,
in.Rt,
in.Discovery,
rpqm.WithMaxProviders(maxProviders),
rpqm.WithIgnoreProviders(ignoredPeerIDs...),
)

View File

@ -216,6 +216,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part
fx.Provide(libp2p.Routing),
fx.Provide(libp2p.ContentRouting),
fx.Provide(libp2p.ContentDiscovery),
fx.Provide(libp2p.BaseRouting(cfg)),
maybeProvide(libp2p.PubsubRouter, bcfg.getOpt("ipnsps")),
@ -380,6 +381,7 @@ func Offline(cfg *config.Config) fx.Option {
fx.Provide(libp2p.Routing),
fx.Provide(libp2p.ContentRouting),
fx.Provide(libp2p.OfflineRouting),
fx.Provide(libp2p.ContentDiscovery),
OfflineProviders(),
)
}

View File

@ -177,6 +177,12 @@ func ContentRouting(in p2pOnlineContentRoutingIn) routing.ContentRouting {
}
}
// ContentDiscovery narrows down the given content routing facility so that it
// only does discovery.
func ContentDiscovery(in irouting.ProvideManyRouter) routing.ContentDiscovery {
return in
}
type p2pOnlineRoutingIn struct {
fx.In
@ -185,7 +191,7 @@ type p2pOnlineRoutingIn struct {
}
// Routing will get all routers obtained from different methods (delegated
// routers, pub-sub, and so on) and add them all together using a TieredRouter.
// routers, pub-sub, and so on) and add them all together using a ParallelRouter.
func Routing(in p2pOnlineRoutingIn) irouting.ProvideManyRouter {
routers := in.Routers