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
Jeromy committed
May 24, 2015 at 23:10 UTC
f574cd4b80e13870f6f31ce8535e568f67847f16
3 files changed
+5
-5
exchange/bitswap/bitswap.go
+2
@@ -202,6 +202,8 @@ func (bs *Bitswap) GetBlocks(ctx context.Context, keys []u.Key) (<-chan *blocks.
202
}
203
promise := bs.notifications.Subscribe(ctx, keys...)
204
205
+ bs.wm.WantBlocks(keys)
206
+
207
req := &blockRequest{
208
keys: keys,
209
ctx: ctx,
exchange/bitswap/workers.go
+1
-3
@@ -134,7 +134,7 @@ func (bs *Bitswap) provideCollector(ctx context.Context) {
134
}
135
}
136
137
-// TODO ensure only one active request per key
137
+// TODO: figure out clientWorkers purpose in life
138
func (bs *Bitswap) clientWorker(parent context.Context) {
139
defer log.Info("bitswap client worker shutting down...")
140
@@ -147,8 +147,6 @@ func (bs *Bitswap) clientWorker(parent context.Context) {
147
continue
148
}
149
150
- bs.wm.WantBlocks(keys)
151
-
150
// NB: Optimization. Assumes that providers of key[0] are likely to
151
// be able to provide for all keys. This currently holds true in most
152
// every situation. Later, this assumption may not hold as true.
test/integration/bitswap_wo_routing_test.go
+2
-2
@@ -75,7 +75,7 @@ func TestBitswapWithoutRouting(t *testing.T) {
75
}
76
77
log.Debugf("%d %s get block.", i, n.Identity)
78
- b, err := n.Exchange.GetBlock(ctx, block0.Key())
78
+ b, err := n.Blocks.GetBlock(ctx, block0.Key())
79
if err != nil {
80
t.Error(err)
81
} else if !bytes.Equal(b.Data, block0.Data) {
@@ -92,7 +92,7 @@ func TestBitswapWithoutRouting(t *testing.T) {
92
93
// get it out.
94
for _, n := range nodes {
95
- b, err := n.Exchange.GetBlock(ctx, block1.Key())
95
+ b, err := n.Blocks.GetBlock(ctx, block1.Key())
96
if err != nil {
97
t.Error(err)
98
} else if !bytes.Equal(b.Data, block1.Data) {