mirror of
https://github.com/ipfs/kubo.git
synced 2025-05-17 23:16:11 +08:00
Merge pull request #10765 from ipfs/ignore-providers
Support WithIgnoreProviders() in provider query manager
This commit is contained in:
@ -48,9 +48,10 @@ func InitWithIdentity(identity Identity) (*Config, error) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
Routing: Routing{
|
Routing: Routing{
|
||||||
Type: nil,
|
Type: nil,
|
||||||
Methods: nil,
|
Methods: nil,
|
||||||
Routers: nil,
|
Routers: nil,
|
||||||
|
IgnoreProviders: []peer.ID{},
|
||||||
},
|
},
|
||||||
|
|
||||||
// setup the node mount points.
|
// setup the node mount points.
|
||||||
|
@ -6,6 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
peer "github.com/libp2p/go-libp2p/core/peer"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -41,6 +43,8 @@ type Routing struct {
|
|||||||
|
|
||||||
LoopbackAddressesOnLanDHT Flag `json:",omitempty"`
|
LoopbackAddressesOnLanDHT Flag `json:",omitempty"`
|
||||||
|
|
||||||
|
IgnoreProviders []peer.ID
|
||||||
|
|
||||||
Routers Routers
|
Routers Routers
|
||||||
|
|
||||||
Methods Methods
|
Methods Methods
|
||||||
|
@ -5,11 +5,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ipfs/boxo/bitswap"
|
"github.com/ipfs/boxo/bitswap"
|
||||||
|
"github.com/ipfs/boxo/bitswap/client"
|
||||||
bsnet "github.com/ipfs/boxo/bitswap/network/bsnet"
|
bsnet "github.com/ipfs/boxo/bitswap/network/bsnet"
|
||||||
blockstore "github.com/ipfs/boxo/blockstore"
|
blockstore "github.com/ipfs/boxo/blockstore"
|
||||||
exchange "github.com/ipfs/boxo/exchange"
|
exchange "github.com/ipfs/boxo/exchange"
|
||||||
"github.com/ipfs/boxo/exchange/providing"
|
"github.com/ipfs/boxo/exchange/providing"
|
||||||
provider "github.com/ipfs/boxo/provider"
|
provider "github.com/ipfs/boxo/provider"
|
||||||
|
rpqm "github.com/ipfs/boxo/routing/providerquerymanager"
|
||||||
"github.com/ipfs/kubo/config"
|
"github.com/ipfs/kubo/config"
|
||||||
irouting "github.com/ipfs/kubo/routing"
|
irouting "github.com/ipfs/kubo/routing"
|
||||||
"github.com/libp2p/go-libp2p/core/host"
|
"github.com/libp2p/go-libp2p/core/host"
|
||||||
@ -61,6 +63,7 @@ type bitswapIn struct {
|
|||||||
fx.In
|
fx.In
|
||||||
|
|
||||||
Mctx helpers.MetricsCtx
|
Mctx helpers.MetricsCtx
|
||||||
|
Cfg *config.Config
|
||||||
Host host.Host
|
Host host.Host
|
||||||
Rt irouting.ProvideManyRouter
|
Rt irouting.ProvideManyRouter
|
||||||
Bs blockstore.GCBlockstore
|
Bs blockstore.GCBlockstore
|
||||||
@ -71,12 +74,24 @@ type bitswapIn struct {
|
|||||||
// Additional options to bitswap.New can be provided via the "bitswap-options"
|
// Additional options to bitswap.New can be provided via the "bitswap-options"
|
||||||
// group.
|
// group.
|
||||||
func Bitswap(provide bool) interface{} {
|
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)
|
bitswapNetwork := bsnet.NewFromIpfsHost(in.Host)
|
||||||
|
|
||||||
var provider routing.ContentDiscovery
|
var provider routing.ContentDiscovery
|
||||||
if provide {
|
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...)
|
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.Close()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return bs
|
return bs, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,13 @@ This release was brought to you by the [Shipyard](http://ipshipyard.com/) team.
|
|||||||
|
|
||||||
### 🔦 Highlights
|
### 🔦 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
|
#### 📦️ Important dependency updates
|
||||||
|
|
||||||
### 📝 Changelog
|
### 📝 Changelog
|
||||||
|
@ -119,6 +119,7 @@ config file at runtime.
|
|||||||
- [`Routing.Type`](#routingtype)
|
- [`Routing.Type`](#routingtype)
|
||||||
- [`Routing.AcceleratedDHTClient`](#routingaccelerateddhtclient)
|
- [`Routing.AcceleratedDHTClient`](#routingaccelerateddhtclient)
|
||||||
- [`Routing.LoopbackAddressesOnLanDHT`](#routingloopbackaddressesonlandht)
|
- [`Routing.LoopbackAddressesOnLanDHT`](#routingloopbackaddressesonlandht)
|
||||||
|
- [`Routing.IgnoreProviders`](#routingignoreproviders)
|
||||||
- [`Routing.Routers`](#routingrouters)
|
- [`Routing.Routers`](#routingrouters)
|
||||||
- [`Routing.Routers: Type`](#routingrouters-type)
|
- [`Routing.Routers: Type`](#routingrouters-type)
|
||||||
- [`Routing.Routers: Parameters`](#routingrouters-parameters)
|
- [`Routing.Routers: Parameters`](#routingrouters-parameters)
|
||||||
@ -1718,6 +1719,19 @@ Default: `false`
|
|||||||
|
|
||||||
Type: `bool` (missing means `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`
|
### `Routing.Routers`
|
||||||
|
|
||||||
**EXPERIMENTAL: `Routing.Routers` configuration may change in future release**
|
**EXPERIMENTAL: `Routing.Routers` configuration may change in future release**
|
||||||
|
Reference in New Issue
Block a user