-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support bitswap configurability (#8268)
* feat: extract Bitswap fx initialization to its own file * chore: bump go-bitswap dependency * feat: bump go-ipfs-config dependency and utilize the new Internal.Bitswap configuration options. Add documentation around the new OptionalInteger config type as well as the Internal.Bitswap options. * docs(docs/config.md): move the table of contents towards the top of the document and update it Co-authored-by: Petar Maymounkov <[email protected]> Co-authored-by: Marcin Rataj <[email protected]> Co-authored-by: Gus Eggert <[email protected]>
- Loading branch information
1 parent
a7e2c23
commit 7448340
Showing
7 changed files
with
283 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package node | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ipfs/go-bitswap" | ||
"github.com/ipfs/go-bitswap/network" | ||
blockstore "github.com/ipfs/go-ipfs-blockstore" | ||
config "github.com/ipfs/go-ipfs-config" | ||
exchange "github.com/ipfs/go-ipfs-exchange-interface" | ||
"github.com/libp2p/go-libp2p-core/host" | ||
"github.com/libp2p/go-libp2p-core/routing" | ||
"go.uber.org/fx" | ||
|
||
"github.com/ipfs/go-ipfs/core/node/helpers" | ||
) | ||
|
||
const ( | ||
// Docs: https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#internalbitswap | ||
DefaultEngineBlockstoreWorkerCount = 128 | ||
DefaultTaskWorkerCount = 8 | ||
DefaultEngineTaskWorkerCount = 8 | ||
DefaultMaxOutstandingBytesPerPeer = 1 << 20 | ||
) | ||
|
||
// OnlineExchange creates new LibP2P backed block exchange (BitSwap) | ||
func OnlineExchange(cfg *config.Config, provide bool) 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) | ||
|
||
var internalBsCfg config.InternalBitswap | ||
if cfg.Internal.Bitswap != nil { | ||
internalBsCfg = *cfg.Internal.Bitswap | ||
} | ||
|
||
opts := []bitswap.Option{ | ||
bitswap.ProvideEnabled(provide), | ||
bitswap.EngineBlockstoreWorkerCount(int(internalBsCfg.EngineBlockstoreWorkerCount.WithDefault(DefaultEngineBlockstoreWorkerCount))), | ||
bitswap.TaskWorkerCount(int(internalBsCfg.TaskWorkerCount.WithDefault(DefaultTaskWorkerCount))), | ||
bitswap.EngineTaskWorkerCount(int(internalBsCfg.EngineTaskWorkerCount.WithDefault(DefaultEngineTaskWorkerCount))), | ||
bitswap.MaxOutstandingBytesPerPeer(int(internalBsCfg.MaxOutstandingBytesPerPeer.WithDefault(DefaultMaxOutstandingBytesPerPeer))), | ||
} | ||
exch := bitswap.New(helpers.LifecycleCtx(mctx, lc), bitswapNetwork, bs, opts...) | ||
lc.Append(fx.Hook{ | ||
OnStop: func(ctx context.Context) error { | ||
return exch.Close() | ||
}, | ||
}) | ||
return exch | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.