-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Support WithIgnoreProviders() in provider query manager #10765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hsanjuan why do we hardcode 10 here? Wasn't previous default limiting to 10 feels like DoS vector, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is the value we always used: When passing in the pqm explicitally we need to set it... No change on that front. As to why 10... 🤷 In rainbow we do unlimited, but in Kubo we never ventured to change the default of 10. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Feels we should avoid hardcoding magic numbers without docs, opened #10773 to sort this out + maybe align with rainbow. |
||
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 | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something I realized while testing #10772 is that user is unable to set PeerID in json when this field type id
peer.ID
.even tho
peer.ID
type in go isstring
, the value stored there is binary and not base-encoded 🙃Proof:
peer.ID.String()
requires extra conversion from binary to base58: https://github.com/libp2p/go-libp2p/blob/50d714c94c043f2a326c6c8e16c7a3c4821b87ad/core/peer/peer.go#L52C8-L52C31This means we we need to:
peer.ID
I've fixed that in 3c24a60#diff-6ef0b54f0ea8496cf31cb4bca6c5e8ca92facee272e34097201d832894bf9d7bR116, but good to keep that in mind in future config changes.
cc @gammazero for visibility