1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-05-17 23:16:11 +08:00

Support WithIgnoreProviders() in provider query manager

Adds `Routing.IgnoreProviders`.

This requires initializing a custom providerQueryManager and using it instead
of the default created internally in Bitswap. Since the default is created
with some internal default configuration options (MaxProviders), this hardcodes it.
This commit is contained in:
Hector Sanjuan
2025-03-24 15:16:46 +01:00
parent b339490381
commit ecca2eba8e
4 changed files with 40 additions and 6 deletions

View File

@ -51,6 +51,7 @@ func InitWithIdentity(identity Identity) (*Config, error) {
Type: nil,
Methods: nil,
Routers: nil,
IgnoreProviders: []peer.ID{},
},
// setup the node mount points.

View File

@ -6,6 +6,8 @@ import (
"os"
"runtime"
"strings"
peer "github.com/libp2p/go-libp2p/core/peer"
)
const (
@ -41,6 +43,8 @@ type Routing struct {
LoopbackAddressesOnLanDHT Flag `json:",omitempty"`
IgnoreProviders []peer.ID
Routers Routers
Methods Methods

View File

@ -5,11 +5,13 @@ import (
"time"
"github.com/ipfs/boxo/bitswap"
"github.com/ipfs/boxo/bitswap/client"
bsnet "github.com/ipfs/boxo/bitswap/network/bsnet"
blockstore "github.com/ipfs/boxo/blockstore"
exchange "github.com/ipfs/boxo/exchange"
"github.com/ipfs/boxo/exchange/providing"
provider "github.com/ipfs/boxo/provider"
rpqm "github.com/ipfs/boxo/routing/providerquerymanager"
"github.com/ipfs/kubo/config"
irouting "github.com/ipfs/kubo/routing"
"github.com/libp2p/go-libp2p/core/host"
@ -61,6 +63,7 @@ type bitswapIn struct {
fx.In
Mctx helpers.MetricsCtx
Cfg *config.Config
Host host.Host
Rt irouting.ProvideManyRouter
Bs blockstore.GCBlockstore
@ -71,12 +74,24 @@ type bitswapIn struct {
// Additional options to bitswap.New can be provided via the "bitswap-options"
// group.
func Bitswap(provide bool) interface{} {
return func(in bitswapIn, lc fx.Lifecycle) *bitswap.Bitswap {
return func(in bitswapIn, lc fx.Lifecycle) (*bitswap.Bitswap, error) {
bitswapNetwork := bsnet.NewFromIpfsHost(in.Host)
var provider routing.ContentDiscovery
if provide {
provider = in.Rt
// We need to hardcode the default because it is an
// internal setting in boxo.
pqm, err := rpqm.New(bitswapNetwork,
in.Rt,
rpqm.WithMaxProviders(10),
rpqm.WithIgnoreProviders(in.Cfg.Routing.IgnoreProviders...),
)
if err != nil {
return nil, err
}
in.BitswapOpts = append(in.BitswapOpts, bitswap.WithClientOption(client.WithDefaultProviderQueryManager(false)))
provider = pqm
}
bs := bitswap.New(helpers.LifecycleCtx(in.Mctx, lc), bitswapNetwork, provider, in.Bs, in.BitswapOpts...)
@ -85,7 +100,7 @@ func Bitswap(provide bool) interface{} {
return bs.Close()
},
})
return bs
return bs, nil
}
}

View File

@ -119,6 +119,7 @@ config file at runtime.
- [`Routing.Type`](#routingtype)
- [`Routing.AcceleratedDHTClient`](#routingaccelerateddhtclient)
- [`Routing.LoopbackAddressesOnLanDHT`](#routingloopbackaddressesonlandht)
- [`Routing.IgnoreProviders`](#routingignoreproviders)
- [`Routing.Routers`](#routingrouters)
- [`Routing.Routers: Type`](#routingrouters-type)
- [`Routing.Routers: Parameters`](#routingrouters-parameters)
@ -1718,6 +1719,19 @@ Default: `false`
Type: `bool` (missing means `false`)
### `Routing.IgnoreProviders`
An array of peerIDs. Any provider record associated to one of these peer IDs is ignored.
Apart from ignoring specific providers for reasons like misbehaviour etc. this
setting is useful to ignore providers as a way to indicate preference, when the same provider
is found under different peerIDs (i.e. one for HTTP and one for Bitswap retrieval).
Default: `[]`
Type: `array[peerID]`
### `Routing.Routers`
**EXPERIMENTAL: `Routing.Routers` configuration may change in future release**