add priorities to GetBlocks requests, and add waitgroup to sendWantListTo
Jeromy committed
Dec 10, 2014 at 21:12 UTC
e7bba82dcbff2c02284a3ce0a89274ba2fbff0c5
1 file changed
+6
-3
exchange/bitswap/bitswap.go
+6
-3
@@ -174,10 +174,12 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
174
for _, wanted := range bs.wantlist.Entries() {
175
message.AddEntry(wanted.Value, wanted.Priority, false)
176
}
177
+ wg := sync.WaitGroup{}
178
for peerToQuery := range peers {
178
- log.Debug("sending query to: %s", peerToQuery)
179
log.Event(ctx, "PeerToQuery", peerToQuery)
180
+ wg.Add(1)
181
go func(p peer.Peer) {
182
+ defer wg.Done()
183
184
log.Event(ctx, "DialPeer", p)
185
err := bs.sender.DialPeer(ctx, p)
@@ -197,6 +199,7 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
199
bs.ledgerset.MessageSent(p, message)
200
}(peerToQuery)
201
}
202
+ wg.Wait()
203
return nil
204
}
205
@@ -305,8 +308,8 @@ func (bs *bitswap) clientWorker(parent context.Context) {
308
log.Warning("Received batch request for zero blocks")
309
continue
310
}
308
- for _, k := range ks {
309
- bs.wantlist.Add(k, 1)
311
+ for i, k := range ks {
312
+ bs.wantlist.Add(k, len(ks)-i)
313
}
314
// NB: send want list to providers for the first peer in this list.
315
// the assumption is made that the providers of the first key in