-
-
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.
refactor: core/node/bitswap.go (#8349)
- extracts bitswap init to separate file and defines implicit defaults as consts - fixes a typo where BitswapTaskWorkerCount was 128 (instead of 8) and BitswapEngineBlockstoreWorkerCount was 8 (instead of 128)
- Loading branch information
Showing
2 changed files
with
52 additions
and
33 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