diff --git a/codex/blockexchange/engine/engine.nim b/codex/blockexchange/engine/engine.nim index 9925a5c2..394fdf7e 100644 --- a/codex/blockexchange/engine/engine.nim +++ b/codex/blockexchange/engine/engine.nim @@ -399,7 +399,6 @@ proc wantListHandler*( peer = peerCtx.id address = e.address wantType = $e.wantType - isCancel = $e.cancel # Update metrics if e.wantType == WantType.WantHave: @@ -412,18 +411,9 @@ proc wantListHandler*( if idx < 0: # new entry if not e.cancel: peerCtx.peerWants.add(e) - else: # update existing entry - # peer doesn't want this block anymore - if e.cancel: - peerCtx.peerWants.del(idx) - else: - # peer might want to ask for the same cid with - # different want params - peerCtx.peerWants[idx] = e # update entry - if not e.cancel: - # Respond to wantHaves immediately if e.wantType == WantType.WantHave: + # does this happen for cancels?! let have = await e.address in b.localStore price = @( @@ -443,6 +433,15 @@ proc wantListHandler*( `type`: BlockPresenceType.Have, price: price)) + else: # update existing entry + # peer doesn't want this block anymore + if e.cancel: + peerCtx.peerWants.del(idx) + else: + # peer might want to ask for the same cid with + # different want params + peerCtx.peerWants[idx] = e # update entry + if presence.len > 0: trace "Sending presence to remote", items = presence.mapIt($it).join(",") await b.network.request.sendPresence(peer, presence)