diff --git a/dagger/bitswap/peercontext.nim b/dagger/bitswap/peercontext.nim index 54511e82..cc385c7a 100644 --- a/dagger/bitswap/peercontext.nim +++ b/dagger/bitswap/peercontext.nim @@ -21,6 +21,9 @@ type pricing*: ?Pricing # optional bandwidth price for this peer paymentChannel*: ?ChannelId # payment channel id +proc peerHave*(context: BitswapPeerCtx): seq[Cid] = + toSeq(context.peerPrices.keys) + proc contains*(a: openArray[BitswapPeerCtx], b: PeerID): bool = ## Convenience method to check for peer prepense ## @@ -32,10 +35,8 @@ func updatePresence*(context: BitswapPeerCtx, presence: Presence) = let price = presence.price if cid notin context.peerHave and presence.have: - context.peerHave.add(cid) context.peerPrices[cid] = price elif cid in context.peerHave and not presence.have: - context.peerHave.keepItIf(it != cid) context.peerPrices.del(cid) func price*(context: BitswapPeerCtx, cids: seq[Cid]): UInt256 = diff --git a/tests/dagger/bitswap/testbitswap.nim b/tests/dagger/bitswap/testbitswap.nim index 74836451..673277a1 100644 --- a/tests/dagger/bitswap/testbitswap.nim +++ b/tests/dagger/bitswap/testbitswap.nim @@ -201,8 +201,12 @@ suite "Bitswap - multiple nodes": await connectNodes(switch) await sleepAsync(1.seconds) - check engine.peers[0].peerHave == blocks[0..3].mapIt( it.cid ) - check engine.peers[3].peerHave == blocks[12..15].mapIt( it.cid ) + + check: + engine.peers[0].peerHave.mapIt($it).sorted(cmp[string]) == + blocks[0..3].mapIt( it.cid ).mapIt($it).sorted(cmp[string]) + engine.peers[3].peerHave.mapIt($it).sorted(cmp[string]) == + blocks[12..15].mapIt( it.cid ).mapIt($it).sorted(cmp[string]) test "should exchange blocks with multiple nodes": let