@@ -7,27 +7,32 @@ import (
7
7
"github.com/ipfs/go-bitswap/network"
8
8
blockstore "github.com/ipfs/go-ipfs-blockstore"
9
9
exchange "github.com/ipfs/go-ipfs-exchange-interface"
10
- config "github.com/ipfs/kubo/config"
10
+ "github.com/ipfs/kubo/config"
11
11
irouting "github.com/ipfs/kubo/routing"
12
12
"github.com/libp2p/go-libp2p/core/host"
13
13
"go.uber.org/fx"
14
14
15
15
"github.com/ipfs/kubo/core/node/helpers"
16
16
)
17
17
18
+ // Docs: https://github.com/ipfs/kubo/blob/master/docs/config.md#internalbitswap
18
19
const (
19
- // Docs: https://github.com/ipfs/kubo/blob/master/docs/config.md#internalbitswap
20
20
DefaultEngineBlockstoreWorkerCount = 128
21
21
DefaultTaskWorkerCount = 8
22
22
DefaultEngineTaskWorkerCount = 8
23
23
DefaultMaxOutstandingBytesPerPeer = 1 << 20
24
24
)
25
25
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
30
28
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 {
31
36
var internalBsCfg config.InternalBitswap
32
37
if cfg .Internal .Bitswap != nil {
33
38
internalBsCfg = * cfg .Internal .Bitswap
@@ -40,13 +45,34 @@ func OnlineExchange(cfg *config.Config, provide bool) interface{} {
40
45
bitswap .EngineTaskWorkerCount (int (internalBsCfg .EngineTaskWorkerCount .WithDefault (DefaultEngineTaskWorkerCount ))),
41
46
bitswap .MaxOutstandingBytesPerPeer (int (internalBsCfg .MaxOutstandingBytesPerPeer .WithDefault (DefaultMaxOutstandingBytesPerPeer ))),
42
47
}
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 ... )
44
71
lc .Append (fx.Hook {
45
72
OnStop : func (ctx context.Context ) error {
46
73
return exch .Close ()
47
74
},
48
75
})
49
76
return exch
50
-
51
77
}
52
78
}
0 commit comments