From f574cd4b80e13870f6f31ce8535e568f67847f16 Mon Sep 17 00:00:00 2001 From: Jeromy <jeromyj@gmail.com> Date: Sun, 24 May 2015 23:10:04 -0700 Subject: [PATCH] Move findproviders out of main block request path This PR moves the addition of new blocks to our wantlist (and their subsequent broadcast to the network) outside of the clientWorker loop. This allows blocks to more quickly propogate to peers we are already connected to, where before we had to wait for the previous findProviders call in clientworker to complete before we could notify our partners of the next blocks that we want. I then changed the naming of the clientWorker and related variables to be a bit more appropriate to the model. Although the clientWorker (now named providerConnector) feels a bit awkward and should probably be changed. fix test assumption --- exchange/bitswap/bitswap.go | 2 ++ exchange/bitswap/workers.go | 4 +--- test/integration/bitswap_wo_routing_test.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index 27be53967..f849c1ed9 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -202,6 +202,8 @@ func (bs *Bitswap) GetBlocks(ctx context.Context, keys []u.Key) (<-chan *blocks. } promise := bs.notifications.Subscribe(ctx, keys...) + bs.wm.WantBlocks(keys) + req := &blockRequest{ keys: keys, ctx: ctx, diff --git a/exchange/bitswap/workers.go b/exchange/bitswap/workers.go index 1083566a1..b41f0dd30 100644 --- a/exchange/bitswap/workers.go +++ b/exchange/bitswap/workers.go @@ -134,7 +134,7 @@ func (bs *Bitswap) provideCollector(ctx context.Context) { } } -// TODO ensure only one active request per key +// TODO: figure out clientWorkers purpose in life func (bs *Bitswap) clientWorker(parent context.Context) { defer log.Info("bitswap client worker shutting down...") @@ -147,8 +147,6 @@ func (bs *Bitswap) clientWorker(parent context.Context) { continue } - bs.wm.WantBlocks(keys) - // NB: Optimization. Assumes that providers of key[0] are likely to // be able to provide for all keys. This currently holds true in most // every situation. Later, this assumption may not hold as true. diff --git a/test/integration/bitswap_wo_routing_test.go b/test/integration/bitswap_wo_routing_test.go index f0f5d5d31..560e20ec3 100644 --- a/test/integration/bitswap_wo_routing_test.go +++ b/test/integration/bitswap_wo_routing_test.go @@ -75,7 +75,7 @@ func TestBitswapWithoutRouting(t *testing.T) { } log.Debugf("%d %s get block.", i, n.Identity) - b, err := n.Exchange.GetBlock(ctx, block0.Key()) + b, err := n.Blocks.GetBlock(ctx, block0.Key()) if err != nil { t.Error(err) } else if !bytes.Equal(b.Data, block0.Data) { @@ -92,7 +92,7 @@ func TestBitswapWithoutRouting(t *testing.T) { // get it out. for _, n := range nodes { - b, err := n.Exchange.GetBlock(ctx, block1.Key()) + b, err := n.Blocks.GetBlock(ctx, block1.Key()) if err != nil { t.Error(err) } else if !bytes.Equal(b.Data, block1.Data) { -- GitLab