Broadcast pricing

This commit is contained in:
Mark Spanbroek 2021-04-08 10:20:35 +02:00 committed by markspanbroek
parent e02c40db80
commit 6e7220efbb
2 changed files with 22 additions and 0 deletions

View File

@ -208,6 +208,15 @@ proc handlePricing(network: BitswapNetwork,
return
network.handlers.onPricing(peer.id, pricing)
proc broadcastPricing*(network: BitswapNetwork,
id: PeerId,
pricing: Pricing) =
if id notin network.peers:
return
let message = Message(pricing: PricingMessage.init(pricing))
asyncSpawn network.peers[id].send(message)
proc handlePayment(network: BitswapNetwork,
peer: NetworkPeer,
payment: SignedState) =

View File

@ -225,3 +225,16 @@ suite "Bitswap Network - e2e":
)))
await done.wait(500.millis)
test "broadcasts pricing":
let pricing = Pricing.example
proc handlePricing(peer: PeerID, received: Pricing) =
check received == pricing
done.complete()
network2.handlers.onPricing = handlePricing
network1.broadcastPricing(switch2.peerInfo.peerId, pricing)
await done.wait(100.millis)