Commit 70c89ffb authored by Jeromy's avatar Jeromy Committed by Juan Batiz-Benet

add priorities to GetBlocks requests, and add waitgroup to sendWantListTo

parent 13f98cb1
...@@ -174,10 +174,12 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e ...@@ -174,10 +174,12 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
for _, wanted := range bs.wantlist.Entries() { for _, wanted := range bs.wantlist.Entries() {
message.AddEntry(wanted.Value, wanted.Priority, false) message.AddEntry(wanted.Value, wanted.Priority, false)
} }
wg := sync.WaitGroup{}
for peerToQuery := range peers { for peerToQuery := range peers {
log.Debug("sending query to: %s", peerToQuery)
log.Event(ctx, "PeerToQuery", peerToQuery) log.Event(ctx, "PeerToQuery", peerToQuery)
wg.Add(1)
go func(p peer.Peer) { go func(p peer.Peer) {
defer wg.Done()
log.Event(ctx, "DialPeer", p) log.Event(ctx, "DialPeer", p)
err := bs.sender.DialPeer(ctx, p) err := bs.sender.DialPeer(ctx, p)
...@@ -197,6 +199,7 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e ...@@ -197,6 +199,7 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
bs.ledgerset.MessageSent(p, message) bs.ledgerset.MessageSent(p, message)
}(peerToQuery) }(peerToQuery)
} }
wg.Wait()
return nil return nil
} }
...@@ -305,8 +308,8 @@ func (bs *bitswap) clientWorker(parent context.Context) { ...@@ -305,8 +308,8 @@ func (bs *bitswap) clientWorker(parent context.Context) {
log.Warning("Received batch request for zero blocks") log.Warning("Received batch request for zero blocks")
continue continue
} }
for _, k := range ks { for i, k := range ks {
bs.wantlist.Add(k, 1) bs.wantlist.Add(k, len(ks)-i)
} }
// NB: send want list to providers for the first peer in this list. // NB: send want list to providers for the first peer in this list.
// the assumption is made that the providers of the first key in // the assumption is made that the providers of the first key in
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment