Skip to content

Commit 32e9a69

Browse files
authored
Merge pull request #9258 from mrd0ll4r/bitswap-fx-configuration
2 parents 4f9ba1a + 9f155e3 commit 32e9a69

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

core/node/bitswap.go

+34-8
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,32 @@ import (
77
"github.com/ipfs/go-bitswap/network"
88
blockstore "github.com/ipfs/go-ipfs-blockstore"
99
exchange "github.com/ipfs/go-ipfs-exchange-interface"
10-
config "github.com/ipfs/kubo/config"
10+
"github.com/ipfs/kubo/config"
1111
irouting "github.com/ipfs/kubo/routing"
1212
"github.com/libp2p/go-libp2p/core/host"
1313
"go.uber.org/fx"
1414

1515
"github.com/ipfs/kubo/core/node/helpers"
1616
)
1717

18+
// Docs: https://github.com/ipfs/kubo/blob/master/docs/config.md#internalbitswap
1819
const (
19-
// Docs: https://github.com/ipfs/kubo/blob/master/docs/config.md#internalbitswap
2020
DefaultEngineBlockstoreWorkerCount = 128
2121
DefaultTaskWorkerCount = 8
2222
DefaultEngineTaskWorkerCount = 8
2323
DefaultMaxOutstandingBytesPerPeer = 1 << 20
2424
)
2525

26-
// OnlineExchange creates new LibP2P backed block exchange (BitSwap)
27-
func OnlineExchange(cfg *config.Config, provide bool) interface{} {
28-
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, rt irouting.TieredRouter, bs blockstore.GCBlockstore) exchange.Interface {
29-
bitswapNetwork := network.NewFromIpfsHost(host, rt)
26+
type bitswapOptionsOut struct {
27+
fx.Out
3028

29+
BitswapOpts []bitswap.Option `group:"bitswap-options,flatten"`
30+
}
31+
32+
// BitswapOptions creates configuration options for Bitswap from the config file
33+
// and whether to provide data.
34+
func BitswapOptions(cfg *config.Config, provide bool) interface{} {
35+
return func() bitswapOptionsOut {
3136
var internalBsCfg config.InternalBitswap
3237
if cfg.Internal.Bitswap != nil {
3338
internalBsCfg = *cfg.Internal.Bitswap
@@ -40,13 +45,34 @@ func OnlineExchange(cfg *config.Config, provide bool) interface{} {
4045
bitswap.EngineTaskWorkerCount(int(internalBsCfg.EngineTaskWorkerCount.WithDefault(DefaultEngineTaskWorkerCount))),
4146
bitswap.MaxOutstandingBytesPerPeer(int(internalBsCfg.MaxOutstandingBytesPerPeer.WithDefault(DefaultMaxOutstandingBytesPerPeer))),
4247
}
43-
exch := bitswap.New(helpers.LifecycleCtx(mctx, lc), bitswapNetwork, bs, opts...)
48+
49+
return bitswapOptionsOut{BitswapOpts: opts}
50+
}
51+
}
52+
53+
type onlineExchangeIn struct {
54+
fx.In
55+
56+
Mctx helpers.MetricsCtx
57+
Host host.Host
58+
Rt irouting.TieredRouter
59+
Bs blockstore.GCBlockstore
60+
BitswapOpts []bitswap.Option `group:"bitswap-options"`
61+
}
62+
63+
// OnlineExchange creates new LibP2P backed block exchange (BitSwap).
64+
// Additional options to bitswap.New can be provided via the "bitswap-options"
65+
// group.
66+
func OnlineExchange() interface{} {
67+
return func(in onlineExchangeIn, lc fx.Lifecycle) exchange.Interface {
68+
bitswapNetwork := network.NewFromIpfsHost(in.Host, in.Rt)
69+
70+
exch := bitswap.New(helpers.LifecycleCtx(in.Mctx, lc), bitswapNetwork, in.Bs, in.BitswapOpts...)
4471
lc.Append(fx.Hook{
4572
OnStop: func(ctx context.Context) error {
4673
return exch.Close()
4774
},
4875
})
4976
return exch
50-
5177
}
5278
}

core/node/groups.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ func Online(bcfg *BuildCfg, cfg *config.Config) fx.Option {
289289
shouldBitswapProvide := !cfg.Experimental.StrategicProviding
290290

291291
return fx.Options(
292-
fx.Provide(OnlineExchange(cfg, shouldBitswapProvide)),
292+
fx.Provide(BitswapOptions(cfg, shouldBitswapProvide)),
293+
fx.Provide(OnlineExchange()),
293294
maybeProvide(Graphsync, cfg.Experimental.GraphsyncEnabled),
294295
fx.Provide(DNSResolver),
295296
fx.Provide(Namesys(ipnsCacheSize)),

0 commit comments

Comments
 (0)