44 "context"
55 "time"
66
7+ "github.com/ipfs/boxo/routing/providerquerymanager"
8+
79 "github.com/ipfs/boxo/bitswap"
810 bsclient "github.com/ipfs/boxo/bitswap/client"
911 bsnet "github.com/ipfs/boxo/bitswap/network"
@@ -21,7 +23,16 @@ import (
2123
2224func setupBitswapExchange (ctx context.Context , cfg Config , h host.Host , cr routing.ContentRouting , bstore blockstore.Blockstore ) exchange.Interface {
2325 bsctx := metri .CtxScope (ctx , "ipfs_bitswap" )
24- bn := bsnet .NewFromIpfsHost (h , cr )
26+
27+ bn := bsnet .NewFromIpfsHost (h )
28+
29+ // Custom query manager with the content router and the host
30+ // and our custom options to overwrite the default.
31+ pqm , err := providerquerymanager .New (ctx , h , cr , providerquerymanager .WithMaxInProcessRequests (100 ))
32+ if err != nil {
33+ panic (err )
34+ }
35+ pqm .Startup ()
2536
2637 // --- Client Options
2738 // bitswap.RebroadcastDelay: default is 1 minute to search for a random
@@ -31,6 +42,14 @@ func setupBitswapExchange(ctx context.Context, cfg Config, h host.Host, cr routi
3142 // bitswap.ProviderSearchDelay: default is 1 second.
3243 providerSearchDelay := 1 * time .Second
3344
45+ // --- Bitswap Client Options
46+ clientOpts := []bsclient.Option {
47+ bsclient .RebroadcastDelay (rebroadcastDelay ),
48+ bsclient .ProviderSearchDelay (providerSearchDelay ),
49+ bsclient .WithoutDuplicatedBlockStats (),
50+ bsclient .WithDefaultProviderQueryManager (false ), // we pass it in manually
51+ }
52+
3453 // If peering and shared cache are both enabled, we initialize both a
3554 // Client and a Server with custom request filter and custom options.
3655 // client+server is more expensive but necessary when deployment requires
@@ -48,31 +67,28 @@ func setupBitswapExchange(ctx context.Context, cfg Config, h host.Host, cr routi
4867 return ok
4968 }
5069
51- // Initialize client+server
52- bswap := bitswap .New (bsctx , bn , bstore ,
53- // --- Client Options
54- bitswap .RebroadcastDelay (rebroadcastDelay ),
55- bitswap .ProviderSearchDelay (providerSearchDelay ),
56- bitswap .WithoutDuplicatedBlockStats (),
70+ // turn bitswap clients option into bitswap options
71+ var opts []bitswap.Option
72+ for _ , o := range clientOpts {
73+ opts = append (opts , bitswap .WithClientOption (o ))
74+ }
5775
58- // ---- Server Options
76+ // ---- Server Options
77+ opts = append (opts ,
5978 bitswap .WithPeerBlockRequestFilter (peerBlockRequestFilter ),
60- bitswap .ProvideEnabled (false ),
6179 // When we don't have a block, don't reply. This reduces processment.
6280 bitswap .SetSendDontHaves (false ),
6381 bitswap .WithWantHaveReplaceSize (cfg .BitswapWantHaveReplaceSize ),
6482 )
83+
84+ // Initialize client+server
85+ bswap := bitswap .New (bsctx , bn , pqm , bstore , opts ... )
6586 bn .Start (bswap )
6687 return & noNotifyExchange {bswap }
6788 }
6889
6990 // By default, rainbow runs with bitswap client alone
70- bswap := bsclient .New (bsctx , bn , bstore ,
71- // --- Client Options
72- bsclient .RebroadcastDelay (rebroadcastDelay ),
73- bsclient .ProviderSearchDelay (providerSearchDelay ),
74- bsclient .WithoutDuplicatedBlockStats (),
75- )
91+ bswap := bsclient .New (bsctx , bn , pqm , bstore , clientOpts ... )
7692 bn .Start (bswap )
7793 return bswap
7894}
0 commit comments