Skip to content

Commit 8b54407

Browse files
authored
Merge pull request #10765 from ipfs/ignore-providers
Support WithIgnoreProviders() in provider query manager
2 parents 370bb9f + 112eb61 commit 8b54407

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

config/init.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ func InitWithIdentity(identity Identity) (*Config, error) {
4848
},
4949

5050
Routing: Routing{
51-
Type: nil,
52-
Methods: nil,
53-
Routers: nil,
51+
Type: nil,
52+
Methods: nil,
53+
Routers: nil,
54+
IgnoreProviders: []peer.ID{},
5455
},
5556

5657
// setup the node mount points.

config/routing.go

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"os"
77
"runtime"
88
"strings"
9+
10+
peer "github.com/libp2p/go-libp2p/core/peer"
911
)
1012

1113
const (
@@ -41,6 +43,8 @@ type Routing struct {
4143

4244
LoopbackAddressesOnLanDHT Flag `json:",omitempty"`
4345

46+
IgnoreProviders []peer.ID
47+
4448
Routers Routers
4549

4650
Methods Methods

core/node/bitswap.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import (
55
"time"
66

77
"github.com/ipfs/boxo/bitswap"
8+
"github.com/ipfs/boxo/bitswap/client"
89
bsnet "github.com/ipfs/boxo/bitswap/network/bsnet"
910
blockstore "github.com/ipfs/boxo/blockstore"
1011
exchange "github.com/ipfs/boxo/exchange"
1112
"github.com/ipfs/boxo/exchange/providing"
1213
provider "github.com/ipfs/boxo/provider"
14+
rpqm "github.com/ipfs/boxo/routing/providerquerymanager"
1315
"github.com/ipfs/kubo/config"
1416
irouting "github.com/ipfs/kubo/routing"
1517
"github.com/libp2p/go-libp2p/core/host"
@@ -61,6 +63,7 @@ type bitswapIn struct {
6163
fx.In
6264

6365
Mctx helpers.MetricsCtx
66+
Cfg *config.Config
6467
Host host.Host
6568
Rt irouting.ProvideManyRouter
6669
Bs blockstore.GCBlockstore
@@ -71,12 +74,24 @@ type bitswapIn struct {
7174
// Additional options to bitswap.New can be provided via the "bitswap-options"
7275
// group.
7376
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) {
7578
bitswapNetwork := bsnet.NewFromIpfsHost(in.Host)
7679

7780
var provider routing.ContentDiscovery
7881
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+
8095
}
8196
bs := bitswap.New(helpers.LifecycleCtx(in.Mctx, lc), bitswapNetwork, provider, in.Bs, in.BitswapOpts...)
8297

@@ -85,7 +100,7 @@ func Bitswap(provide bool) interface{} {
85100
return bs.Close()
86101
},
87102
})
88-
return bs
103+
return bs, nil
89104
}
90105
}
91106

docs/changelogs/v0.35.md

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ This release was brought to you by the [Shipyard](http://ipshipyard.com/) team.
1818

1919
### 🔦 Highlights
2020

21+
##### `Routing.IgnoreProviders`
22+
23+
This new option allows ignoring specific peer IDs when returned by the content
24+
routing system as providers of content. See the
25+
[documentation](https://github.com/ipfs/kubo/blob/master/docs/config.md#routingignoreproviders)
26+
for for information.
27+
2128
#### 📦️ Important dependency updates
2229

2330
### 📝 Changelog

docs/config.md

+14
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ config file at runtime.
119119
- [`Routing.Type`](#routingtype)
120120
- [`Routing.AcceleratedDHTClient`](#routingaccelerateddhtclient)
121121
- [`Routing.LoopbackAddressesOnLanDHT`](#routingloopbackaddressesonlandht)
122+
- [`Routing.IgnoreProviders`](#routingignoreproviders)
122123
- [`Routing.Routers`](#routingrouters)
123124
- [`Routing.Routers: Type`](#routingrouters-type)
124125
- [`Routing.Routers: Parameters`](#routingrouters-parameters)
@@ -1718,6 +1719,19 @@ Default: `false`
17181719

17191720
Type: `bool` (missing means `false`)
17201721

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+
17211735
### `Routing.Routers`
17221736

17231737
**EXPERIMENTAL: `Routing.Routers` configuration may change in future release**

0 commit comments

Comments
 (0)