Skip to content
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

feat: add peer block filter option #8772

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion core/node/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
)

// OnlineExchange creates new LibP2P backed block exchange (BitSwap)
func OnlineExchange(cfg *config.Config, provide bool) interface{} {
func OnlineExchange(cfg *config.Config, provide bool, pbrf bitswap.PeerBlockRequestFilter) interface{} {
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, rt routing.Routing, bs blockstore.GCBlockstore) exchange.Interface {
bitswapNetwork := network.NewFromIpfsHost(host, rt)

Expand All @@ -40,6 +40,11 @@ func OnlineExchange(cfg *config.Config, provide bool) interface{} {
bitswap.EngineTaskWorkerCount(int(internalBsCfg.EngineTaskWorkerCount.WithDefault(DefaultEngineTaskWorkerCount))),
bitswap.MaxOutstandingBytesPerPeer(int(internalBsCfg.MaxOutstandingBytesPerPeer.WithDefault(DefaultMaxOutstandingBytesPerPeer))),
}

if pbrf != nil {
opts = append(opts, bitswap.WithPeerBlockRequestFilter(pbrf))
}

exch := bitswap.New(helpers.LifecycleCtx(mctx, lc), bitswapNetwork, bs, opts...)
lc.Append(fx.Hook{
OnStop: func(ctx context.Context) error {
Expand Down
4 changes: 4 additions & 0 deletions core/node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"go.uber.org/fx"

"github.com/ipfs/go-bitswap"
"github.com/ipfs/go-ipfs/core/node/helpers"
"github.com/ipfs/go-ipfs/core/node/libp2p"
"github.com/ipfs/go-ipfs/repo"
Expand Down Expand Up @@ -40,6 +41,9 @@ type BuildCfg struct {
Routing libp2p.RoutingOption
Host libp2p.HostOption
Repo repo.Repo

// Bitswap
PeerBlockRequestFilter bitswap.PeerBlockRequestFilter
Copy link
Contributor Author

@laurentsenta laurentsenta Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure which we prefer:

  1. Pass the PeerBlockRequestFilter function, shown here,
  2. Pass a generic bitswap.Option function.

(2) is more "obviously future-proof", but that'd mean we'd have two different ways to configure most values in the bitswap instance (json from cfg and code from buildcfg).

Access control is probably a cross-cutting concern that will eventually span multiple modules and protocols, not only bitswap. So by decoupling the access control config from the bitswap option, (1) might make it easier to build upon this feature.

}

func (cfg *BuildCfg) getOpt(key string) bool {
Expand Down
3 changes: 2 additions & 1 deletion core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,10 @@ func Online(bcfg *BuildCfg, cfg *config.Config) fx.Option {

/* don't provide from bitswap when the strategic provider service is active */
shouldBitswapProvide := !cfg.Experimental.StrategicProviding
pbrf := bcfg.PeerBlockRequestFilter

return fx.Options(
fx.Provide(OnlineExchange(cfg, shouldBitswapProvide)),
fx.Provide(OnlineExchange(cfg, shouldBitswapProvide, pbrf)),
Comment on lines +284 to +287
Copy link
Contributor

@Jorropo Jorropo Mar 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I belive you inspired your pbrf variable from the line above, this code (shouldBitswapProvide) is a clarification variable, it translate !cfg.Experimental.StrategicProviding into a usefull thing we understand.
In your case you are turning a perfectly good bitswapConfig.PeerBlockRequestFilter into a meaningless without prior knowledge pbrf one.

Suggested change
pbrf := bcfg.PeerBlockRequestFilter
return fx.Options(
fx.Provide(OnlineExchange(cfg, shouldBitswapProvide)),
fx.Provide(OnlineExchange(cfg, shouldBitswapProvide, pbrf)),
return fx.Options(
fx.Provide(OnlineExchange(cfg, shouldBitswapProvide, bcfg.PeerBlockRequestFilter)),

maybeProvide(Graphsync, cfg.Experimental.GraphsyncEnabled),
fx.Provide(DNSResolver),
fx.Provide(Namesys(ipnsCacheSize)),
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/go-ipfs-as-a-library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ As a bonus, you can also find lines that show you how to spawn a node over your
- [Comment these lines](./main.go#L219-L223)
- [Uncomment these lines](./main.go#L209-L216)

## Voilá! You are now a go-ipfs hacker
## Voilà! You are now a go-ipfs hacker

You've learned how to spawn a go-ipfs node using the go-ipfs core API. There are many more [methods to experiment next](https://godoc.org/github.com/ipfs/interface-go-ipfs-core). Happy hacking!