Send block prices
This commit is contained in:
parent
98d8571ceb
commit
f69827d582
|
@ -338,15 +338,11 @@ proc taskHandler*(b: BitswapEngine, task: BitswapPeerCtx) {.gcsafe, async.} =
|
||||||
# we send the block or get a cancel
|
# we send the block or get a cancel
|
||||||
for e in task.peerWants:
|
for e in task.peerWants:
|
||||||
if e.wantType == WantType.wantHave:
|
if e.wantType == WantType.wantHave:
|
||||||
wants.add(
|
var presence = Presence(cid: e.cid)
|
||||||
BlockPresence(
|
presence.have = b.localStore.hasblock(presence.cid)
|
||||||
cid: e.`block`,
|
if presence.have and price =? b.pricing.?price:
|
||||||
`type`: if b.localStore.hasBlock(e.cid):
|
presence.price = price
|
||||||
BlockPresenceType.presenceHave
|
wants.add(BlockPresence.init(presence))
|
||||||
else:
|
|
||||||
BlockPresenceType.presenceDontHave
|
|
||||||
))
|
|
||||||
|
|
||||||
if wants.len > 0:
|
if wants.len > 0:
|
||||||
b.request.sendPresence(task.id, wants)
|
b.request.sendPresence(task.id, wants)
|
||||||
|
|
||||||
|
|
|
@ -303,6 +303,7 @@ suite "Task Handler":
|
||||||
))
|
))
|
||||||
|
|
||||||
engine.peers = peersCtx
|
engine.peers = peersCtx
|
||||||
|
engine.pricing = Pricing.example.some
|
||||||
|
|
||||||
test "Should send want-blocks in priority order":
|
test "Should send want-blocks in priority order":
|
||||||
proc sendBlocks(
|
proc sendBlocks(
|
||||||
|
@ -341,11 +342,12 @@ suite "Task Handler":
|
||||||
test "Should send presence":
|
test "Should send presence":
|
||||||
let present = blocks
|
let present = blocks
|
||||||
let missing = @[bt.Block.new("missing".toBytes)]
|
let missing = @[bt.Block.new("missing".toBytes)]
|
||||||
|
let price = (!engine.pricing).price
|
||||||
|
|
||||||
proc sendPresence(id: PeerID, presence: seq[BlockPresence]) =
|
proc sendPresence(id: PeerID, presence: seq[BlockPresence]) =
|
||||||
check presence.mapIt(!Presence.init(it)) == @[
|
check presence.mapIt(!Presence.init(it)) == @[
|
||||||
Presence(cid: present[0].cid, have: true),
|
Presence(cid: present[0].cid, have: true, price: price),
|
||||||
Presence(cid: present[1].cid, have: true),
|
Presence(cid: present[1].cid, have: true, price: price),
|
||||||
Presence(cid: missing[0].cid, have: false)
|
Presence(cid: missing[0].cid, have: false)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue