diff --git a/go.mod b/go.mod index 4d0b093..224f96f 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/felixge/httpsnoop v1.0.4 github.com/ipfs-shipyard/nopfs v0.0.12 github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231024163508-120e0c51ee3a - github.com/ipfs/boxo v0.24.3 + github.com/ipfs/boxo v0.21.1-0.20240726111146-e95eeb2ae5f1 github.com/ipfs/go-block-format v0.2.0 github.com/ipfs/go-cid v0.4.1 github.com/ipfs/go-datastore v0.6.0 diff --git a/setup_bitswap.go b/setup_bitswap.go index 3029506..323a46e 100644 --- a/setup_bitswap.go +++ b/setup_bitswap.go @@ -4,6 +4,8 @@ import ( "context" "time" + "github.com/ipfs/boxo/routing/providerquerymanager" + "github.com/ipfs/boxo/bitswap" bsclient "github.com/ipfs/boxo/bitswap/client" bsnet "github.com/ipfs/boxo/bitswap/network" @@ -21,6 +23,12 @@ import ( func setupBitswapExchange(ctx context.Context, cfg Config, h host.Host, cr routing.ContentRouting, bstore blockstore.Blockstore) exchange.Interface { bsctx := metri.CtxScope(ctx, "ipfs_bitswap") + n := &providerQueryNetwork{cr, h} + pqm, err := providerquerymanager.New(ctx, n, providerquerymanager.WithMaxInProcessRequests(100)) + if err != nil { + panic(err) + } + cr = &wrapProv{pqm: pqm} bn := bsnet.NewFromIpfsHost(h, cr) // --- Client Options @@ -31,6 +39,14 @@ func setupBitswapExchange(ctx context.Context, cfg Config, h host.Host, cr routi // bitswap.ProviderSearchDelay: default is 1 second. providerSearchDelay := 1 * time.Second + // --- Bitswap Client Options + clientOpts := []bsclient.Option{ + bsclient.RebroadcastDelay(rebroadcastDelay), + bsclient.ProviderSearchDelay(providerSearchDelay), + bsclient.WithoutDuplicatedBlockStats(), + bsclient.WithDefaultLookupManagement(false), + } + // If peering and shared cache are both enabled, we initialize both a // Client and a Server with custom request filter and custom options. // client+server is more expensive but necessary when deployment requires @@ -48,31 +64,29 @@ func setupBitswapExchange(ctx context.Context, cfg Config, h host.Host, cr routi return ok } - // Initialize client+server - bswap := bitswap.New(bsctx, bn, bstore, - // --- Client Options - bitswap.RebroadcastDelay(rebroadcastDelay), - bitswap.ProviderSearchDelay(providerSearchDelay), - bitswap.WithoutDuplicatedBlockStats(), + // turn bitswap clients option into bitswap options + var opts []bitswap.Option + for _, o := range clientOpts { + opts = append(opts, bitswap.WithClientOption(o)) + } - // ---- Server Options + // ---- Server Options + opts = append(opts, bitswap.WithPeerBlockRequestFilter(peerBlockRequestFilter), bitswap.ProvideEnabled(false), // When we don't have a block, don't reply. This reduces processment. bitswap.SetSendDontHaves(false), bitswap.WithWantHaveReplaceSize(cfg.BitswapWantHaveReplaceSize), ) + + // Initialize client+server + bswap := bitswap.New(bsctx, bn, bstore, opts...) bn.Start(bswap) return &noNotifyExchange{bswap} } // By default, rainbow runs with bitswap client alone - bswap := bsclient.New(bsctx, bn, bstore, - // --- Client Options - bsclient.RebroadcastDelay(rebroadcastDelay), - bsclient.ProviderSearchDelay(providerSearchDelay), - bsclient.WithoutDuplicatedBlockStats(), - ) + bswap := bsclient.New(bsctx, bn, bstore, clientOpts...) bn.Start(bswap) return bswap }