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.
Hector Sanjuan committed
Mar 24, 2025 at 15:16 UTC
ecca2eba8e8350f6003a5e0001eaea4de5e543a9
4 files changed
+40
-6
config/init.go
+4
-3
@@ -48,9 +48,10 @@ func InitWithIdentity(identity Identity) (*Config, error) {
48
},
49
50
Routing: Routing{
51
- Type: nil,
52
- Methods: nil,
53
- Routers: nil,
51
+ Type: nil,
52
+ Methods: nil,
53
+ Routers: nil,
54
+ IgnoreProviders: []peer.ID{},
55
},
56
57
// setup the node mount points.
config/routing.go
+4
@@ -6,6 +6,8 @@ import (
6
"os"
7
"runtime"
8
"strings"
9
+
10
+ peer "github.com/libp2p/go-libp2p/core/peer"
11
)
12
13
const (
@@ -41,6 +43,8 @@ type Routing struct {
43
44
LoopbackAddressesOnLanDHT Flag `json:",omitempty"`
45
46
+ IgnoreProviders []peer.ID
47
+
48
Routers Routers
49
50
Methods Methods
core/node/bitswap.go
+18
-3
@@ -5,11 +5,13 @@ import (
5
"time"
6
7
"github.com/ipfs/boxo/bitswap"
8
+ "github.com/ipfs/boxo/bitswap/client"
9
bsnet "github.com/ipfs/boxo/bitswap/network/bsnet"
10
blockstore "github.com/ipfs/boxo/blockstore"
11
exchange "github.com/ipfs/boxo/exchange"
12
"github.com/ipfs/boxo/exchange/providing"
13
provider "github.com/ipfs/boxo/provider"
14
+ rpqm "github.com/ipfs/boxo/routing/providerquerymanager"
15
"github.com/ipfs/kubo/config"
16
irouting "github.com/ipfs/kubo/routing"
17
"github.com/libp2p/go-libp2p/core/host"
@@ -61,6 +63,7 @@ type bitswapIn struct {
63
fx.In
64
65
Mctx helpers.MetricsCtx
66
+ Cfg *config.Config
67
Host host.Host
68
Rt irouting.ProvideManyRouter
69
Bs blockstore.GCBlockstore
@@ -71,12 +74,24 @@ type bitswapIn struct {
74
// Additional options to bitswap.New can be provided via the "bitswap-options"
75
// group.
76
func Bitswap(provide bool) interface{} {
74
- return func(in bitswapIn, lc fx.Lifecycle) *bitswap.Bitswap {
77
+ return func(in bitswapIn, lc fx.Lifecycle) (*bitswap.Bitswap, error) {
78
bitswapNetwork := bsnet.NewFromIpfsHost(in.Host)
79
80
var provider routing.ContentDiscovery
81
if provide {
79
- provider = in.Rt
82
+ // We need to hardcode the default because it is an
83
+ // internal setting in boxo.
84
+ pqm, err := rpqm.New(bitswapNetwork,
85
+ in.Rt,
86
+ rpqm.WithMaxProviders(10),
87
+ rpqm.WithIgnoreProviders(in.Cfg.Routing.IgnoreProviders...),
88
+ )
89
+ if err != nil {
90
+ return nil, err
91
+ }
92
+ in.BitswapOpts = append(in.BitswapOpts, bitswap.WithClientOption(client.WithDefaultProviderQueryManager(false)))
93
+ provider = pqm
94
+
95
}
96
bs := bitswap.New(helpers.LifecycleCtx(in.Mctx, lc), bitswapNetwork, provider, in.Bs, in.BitswapOpts...)
97
@@ -85,7 +100,7 @@ func Bitswap(provide bool) interface{} {
100
return bs.Close()
101
},
102
})
88
- return bs
103
+ return bs, nil
104
}
105
}
106
docs/config.md
+14
@@ -119,6 +119,7 @@ config file at runtime.
119
- [`Routing.Type`](#routingtype)
120
- [`Routing.AcceleratedDHTClient`](#routingaccelerateddhtclient)
121
- [`Routing.LoopbackAddressesOnLanDHT`](#routingloopbackaddressesonlandht)
122
+ - [`Routing.IgnoreProviders`](#routingignoreproviders)
123
- [`Routing.Routers`](#routingrouters)
124
- [`Routing.Routers: Type`](#routingrouters-type)
125
- [`Routing.Routers: Parameters`](#routingrouters-parameters)
@@ -1718,6 +1719,19 @@ Default: `false`
1719
1720
Type: `bool` (missing means `false`)
1721
1722
+### `Routing.IgnoreProviders`
1723
+
1724
+An array of peerIDs. Any provider record associated to one of these peer IDs is ignored.
1725
+
1726
+Apart from ignoring specific providers for reasons like misbehaviour etc. this
1727
+setting is useful to ignore providers as a way to indicate preference, when the same provider
1728
+is found under different peerIDs (i.e. one for HTTP and one for Bitswap retrieval).
1729
+
1730
+Default: `[]`
1731
+
1732
+Type: `array[peerID]`
1733
+
1734
+
1735
### `Routing.Routers`
1736
1737
**EXPERIMENTAL: `Routing.Routers` configuration may change in future release**