1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-05-17 15:06:47 +08:00

Merge pull request #10765 from ipfs/ignore-providers

Support WithIgnoreProviders() in provider query manager
This commit is contained in:
Hector Sanjuan
2025-04-01 10:03:08 +02:00
committed by GitHub
5 changed files with 47 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

@ -18,6 +18,13 @@ This release was brought to you by the [Shipyard](http://ipshipyard.com/) team.
### 🔦 Highlights
##### `Routing.IgnoreProviders`
This new option allows ignoring specific peer IDs when returned by the content
routing system as providers of content. See the
[documentation](https://github.com/ipfs/kubo/blob/master/docs/config.md#routingignoreproviders)
for for information.
#### 📦️ Important dependency updates
### 📝 Changelog

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**