1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 01:12:24 +08:00

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
This commit is contained in:
Jeromy
2015-05-24 23:10:04 -07:00
parent 6f155239ef
commit f574cd4b80
3 changed files with 5 additions and 5 deletions

View File

@ -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,

View File

@ -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.

View File

@ -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) {