2021-02-26 00:23:22 +00:00
|
|
|
import std/sequtils
|
2021-05-10 11:47:15 +00:00
|
|
|
import std/random
|
2022-04-13 16:32:35 +00:00
|
|
|
import std/algorithm
|
2021-02-26 00:23:22 +00:00
|
|
|
|
|
|
|
import pkg/stew/byteutils
|
|
|
|
import pkg/asynctest
|
|
|
|
import pkg/chronos
|
|
|
|
import pkg/libp2p
|
2022-04-13 16:32:35 +00:00
|
|
|
import pkg/libp2p/routing_record
|
|
|
|
import pkg/libp2pdht/discv5/protocol as discv5
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2022-05-19 19:56:03 +00:00
|
|
|
import pkg/codex/rng
|
|
|
|
import pkg/codex/blockexchange
|
|
|
|
import pkg/codex/stores
|
|
|
|
import pkg/codex/chunker
|
|
|
|
import pkg/codex/discovery
|
|
|
|
import pkg/codex/blocktype as bt
|
|
|
|
import pkg/codex/utils/asyncheapqueue
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2022-05-19 22:28:53 +00:00
|
|
|
import ../../helpers
|
|
|
|
import ../../examples
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
suite "NetworkStore engine basic":
|
2022-05-19 02:29:15 +00:00
|
|
|
var
|
|
|
|
rng: Rng
|
|
|
|
seckey: PrivateKey
|
|
|
|
peerId: PeerID
|
|
|
|
chunker: Chunker
|
|
|
|
wallet: WalletRef
|
|
|
|
blockDiscovery: Discovery
|
|
|
|
peerStore: PeerCtxStore
|
|
|
|
pendingBlocks: PendingBlocksManager
|
|
|
|
blocks: seq[bt.Block]
|
|
|
|
done: Future[void]
|
|
|
|
|
|
|
|
setup:
|
2021-02-26 00:23:22 +00:00
|
|
|
rng = Rng.instance()
|
2022-01-13 00:42:18 +00:00
|
|
|
seckey = PrivateKey.random(rng[]).tryGet()
|
|
|
|
peerId = PeerID.init(seckey.getPublicKey().tryGet()).tryGet()
|
2022-01-10 15:32:56 +00:00
|
|
|
chunker = RandomChunker.new(Rng.instance(), size = 1024, chunkSize = 256)
|
2021-04-19 14:37:38 +00:00
|
|
|
wallet = WalletRef.example
|
2022-05-19 02:29:15 +00:00
|
|
|
blockDiscovery = Discovery.new()
|
|
|
|
peerStore = PeerCtxStore.new()
|
|
|
|
pendingBlocks = PendingBlocksManager.new()
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
while true:
|
|
|
|
let chunk = await chunker.getBytes()
|
|
|
|
if chunk.len <= 0:
|
|
|
|
break
|
|
|
|
|
2022-03-18 19:50:53 +00:00
|
|
|
blocks.add(bt.Block.new(chunk).tryGet())
|
2022-01-10 15:32:56 +00:00
|
|
|
|
2021-02-26 00:23:22 +00:00
|
|
|
done = newFuture[void]()
|
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
test "Should send want list to new peers":
|
2021-02-26 00:23:22 +00:00
|
|
|
proc sendWantList(
|
|
|
|
id: PeerID,
|
|
|
|
cids: seq[Cid],
|
|
|
|
priority: int32 = 0,
|
|
|
|
cancel: bool = false,
|
|
|
|
wantType: WantType = WantType.wantHave,
|
|
|
|
full: bool = false,
|
|
|
|
sendDontHave: bool = false) {.gcsafe.} =
|
2022-04-13 16:32:35 +00:00
|
|
|
check cids.mapIt($it).sorted == blocks.mapIt( $it.cid ).sorted
|
2021-02-26 00:23:22 +00:00
|
|
|
done.complete()
|
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
let
|
|
|
|
network = BlockExcNetwork(request: BlockExcRequest(
|
|
|
|
sendWantList: sendWantList,
|
|
|
|
))
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
localStore = CacheStore.new(blocks.mapIt( it ))
|
|
|
|
discovery = DiscoveryEngine.new(
|
|
|
|
localStore,
|
|
|
|
peerStore,
|
|
|
|
network,
|
|
|
|
blockDiscovery,
|
|
|
|
pendingBlocks)
|
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
engine = BlockExcEngine.new(
|
2022-05-19 02:29:15 +00:00
|
|
|
localStore,
|
2022-01-10 15:32:56 +00:00
|
|
|
wallet,
|
2022-04-13 16:32:35 +00:00
|
|
|
network,
|
2022-05-19 02:29:15 +00:00
|
|
|
discovery,
|
|
|
|
peerStore,
|
|
|
|
pendingBlocks)
|
2022-05-12 21:52:03 +00:00
|
|
|
|
2022-04-13 16:32:35 +00:00
|
|
|
for b in blocks:
|
2022-05-12 21:52:03 +00:00
|
|
|
discard engine.pendingBlocks.getWantHandle(b.cid)
|
2021-02-26 00:23:22 +00:00
|
|
|
engine.setupPeer(peerId)
|
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
await done.wait(100.millis)
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
test "Should send account to new peers":
|
2021-04-08 12:27:49 +00:00
|
|
|
let pricing = Pricing.example
|
|
|
|
|
2021-05-10 14:21:47 +00:00
|
|
|
proc sendAccount(peer: PeerID, account: Account) =
|
|
|
|
check account.address == pricing.address
|
2021-04-08 12:27:49 +00:00
|
|
|
done.complete()
|
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
let
|
|
|
|
network = BlockExcNetwork(request: BlockExcRequest(
|
2022-05-19 02:29:15 +00:00
|
|
|
sendAccount: sendAccount
|
2022-01-10 15:32:56 +00:00
|
|
|
))
|
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
localStore = CacheStore.new()
|
|
|
|
discovery = DiscoveryEngine.new(
|
|
|
|
localStore,
|
|
|
|
peerStore,
|
|
|
|
network,
|
|
|
|
blockDiscovery,
|
|
|
|
pendingBlocks)
|
|
|
|
|
|
|
|
engine = BlockExcEngine.new(
|
|
|
|
localStore,
|
|
|
|
wallet,
|
|
|
|
network,
|
|
|
|
discovery,
|
|
|
|
peerStore,
|
|
|
|
pendingBlocks)
|
2021-04-08 12:27:49 +00:00
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
engine.pricing = pricing.some
|
2021-04-08 12:27:49 +00:00
|
|
|
engine.setupPeer(peerId)
|
2022-05-19 02:29:15 +00:00
|
|
|
|
2021-04-08 12:27:49 +00:00
|
|
|
await done.wait(100.millis)
|
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
suite "NetworkStore engine handlers":
|
2021-02-26 00:23:22 +00:00
|
|
|
var
|
2022-05-19 02:29:15 +00:00
|
|
|
rng: Rng
|
|
|
|
seckey: PrivateKey
|
|
|
|
peerId: PeerID
|
|
|
|
chunker: Chunker
|
|
|
|
wallet: WalletRef
|
|
|
|
blockDiscovery: Discovery
|
|
|
|
peerStore: PeerCtxStore
|
|
|
|
pendingBlocks: PendingBlocksManager
|
|
|
|
network: BlockExcNetwork
|
2021-08-30 19:25:20 +00:00
|
|
|
engine: BlockExcEngine
|
2022-05-19 02:29:15 +00:00
|
|
|
discovery: DiscoveryEngine
|
2021-08-30 19:25:20 +00:00
|
|
|
peerCtx: BlockExcPeerCtx
|
2022-05-19 02:29:15 +00:00
|
|
|
localStore: BlockStore
|
2021-02-26 00:23:22 +00:00
|
|
|
done: Future[void]
|
2022-01-10 15:32:56 +00:00
|
|
|
blocks: seq[bt.Block]
|
2021-02-26 00:23:22 +00:00
|
|
|
|
|
|
|
setup:
|
2022-05-19 02:29:15 +00:00
|
|
|
rng = Rng.instance()
|
|
|
|
chunker = RandomChunker.new(rng, size = 1024, chunkSize = 256)
|
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
while true:
|
|
|
|
let chunk = await chunker.getBytes()
|
|
|
|
if chunk.len <= 0:
|
|
|
|
break
|
|
|
|
|
2022-03-18 19:50:53 +00:00
|
|
|
blocks.add(bt.Block.new(chunk).tryGet())
|
2022-01-10 15:32:56 +00:00
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
seckey = PrivateKey.random(rng[]).tryGet()
|
|
|
|
peerId = PeerID.init(seckey.getPublicKey().tryGet()).tryGet()
|
|
|
|
wallet = WalletRef.example
|
|
|
|
blockDiscovery = Discovery.new()
|
|
|
|
peerStore = PeerCtxStore.new()
|
|
|
|
pendingBlocks = PendingBlocksManager.new()
|
|
|
|
|
|
|
|
localStore = CacheStore.new()
|
|
|
|
network = BlockExcNetwork()
|
|
|
|
|
|
|
|
discovery = DiscoveryEngine.new(
|
|
|
|
localStore,
|
|
|
|
peerStore,
|
|
|
|
network,
|
|
|
|
blockDiscovery,
|
|
|
|
pendingBlocks)
|
|
|
|
|
|
|
|
engine = BlockExcEngine.new(
|
|
|
|
localStore,
|
|
|
|
wallet,
|
|
|
|
network,
|
|
|
|
discovery,
|
|
|
|
peerStore,
|
|
|
|
pendingBlocks)
|
|
|
|
|
2021-08-30 19:25:20 +00:00
|
|
|
peerCtx = BlockExcPeerCtx(
|
2021-02-26 00:23:22 +00:00
|
|
|
id: peerId
|
|
|
|
)
|
|
|
|
engine.peers.add(peerCtx)
|
2022-05-19 02:29:15 +00:00
|
|
|
done = newFuture[void]()
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
test "Should handle want list":
|
2021-02-26 00:23:22 +00:00
|
|
|
let wantList = makeWantList(blocks.mapIt( it.cid ))
|
2022-01-10 15:32:56 +00:00
|
|
|
proc handler() {.async.} =
|
|
|
|
let ctx = await engine.taskQueue.pop()
|
2021-02-26 00:23:22 +00:00
|
|
|
check ctx.id == peerId
|
|
|
|
check ctx.peerWants.mapIt( it.cid ) == blocks.mapIt( it.cid )
|
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
let done = handler()
|
|
|
|
await engine.wantListHandler(peerId, wantList)
|
2021-02-26 00:23:22 +00:00
|
|
|
await done
|
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
test "Should handle want list - `dont-have`":
|
2021-02-26 00:23:22 +00:00
|
|
|
let wantList = makeWantList(blocks.mapIt( it.cid ), sendDontHave = true)
|
|
|
|
proc sendPresence(peerId: PeerID, presence: seq[BlockPresence]) =
|
|
|
|
check presence.mapIt( it.cid ) == wantList.entries.mapIt( it.`block` )
|
|
|
|
for p in presence:
|
|
|
|
check:
|
|
|
|
p.`type` == BlockPresenceType.presenceDontHave
|
|
|
|
|
|
|
|
done.complete()
|
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
engine.network = BlockExcNetwork(request: BlockExcRequest(
|
|
|
|
sendPresence: sendPresence
|
|
|
|
))
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
await engine.wantListHandler(peerId, wantList)
|
2021-02-26 00:23:22 +00:00
|
|
|
|
|
|
|
await done
|
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
test "Should handle want list - `dont-have` some blocks":
|
2021-02-26 00:23:22 +00:00
|
|
|
let wantList = makeWantList(blocks.mapIt( it.cid ), sendDontHave = true)
|
|
|
|
proc sendPresence(peerId: PeerID, presence: seq[BlockPresence]) =
|
|
|
|
check presence.mapIt( it.cid ) == blocks[2..blocks.high].mapIt( it.cid.data.buffer )
|
|
|
|
for p in presence:
|
|
|
|
check:
|
|
|
|
p.`type` == BlockPresenceType.presenceDontHave
|
|
|
|
|
|
|
|
done.complete()
|
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
engine.network = BlockExcNetwork(request: BlockExcRequest(
|
|
|
|
sendPresence: sendPresence
|
|
|
|
))
|
|
|
|
|
|
|
|
check await engine.localStore.putBlock(blocks[0])
|
|
|
|
check await engine.localStore.putBlock(blocks[1])
|
|
|
|
await engine.wantListHandler(peerId, wantList)
|
2021-02-26 00:23:22 +00:00
|
|
|
|
|
|
|
await done
|
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
test "Should store blocks in local store":
|
2021-02-26 00:23:22 +00:00
|
|
|
let pending = blocks.mapIt(
|
2022-05-12 21:52:03 +00:00
|
|
|
engine.pendingBlocks.getWantHandle( it.cid )
|
2021-02-26 00:23:22 +00:00
|
|
|
)
|
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
await engine.blocksHandler(peerId, blocks)
|
2021-02-26 00:23:22 +00:00
|
|
|
let resolved = await allFinished(pending)
|
|
|
|
check resolved.mapIt( it.read ) == blocks
|
|
|
|
for b in blocks:
|
|
|
|
check engine.localStore.hasBlock(b.cid)
|
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
test "Should send payments for received blocks":
|
2021-05-10 14:21:47 +00:00
|
|
|
let account = Account(address: EthAddress.example)
|
2022-05-19 02:29:15 +00:00
|
|
|
let peerContext = peerStore.get(peerId)
|
2021-05-10 14:21:47 +00:00
|
|
|
peerContext.account = account.some
|
2021-05-10 11:47:15 +00:00
|
|
|
peerContext.peerPrices = blocks.mapIt((it.cid, rand(uint16).u256)).toTable
|
2021-04-14 14:19:45 +00:00
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
engine.network = BlockExcNetwork(request: BlockExcRequest(
|
|
|
|
sendPayment: proc(receiver: PeerID, payment: SignedState) =
|
|
|
|
let amount = blocks.mapIt(peerContext.peerPrices[it.cid]).foldl(a+b)
|
|
|
|
let balances = !payment.state.outcome.balances(Asset)
|
|
|
|
check receiver == peerId
|
|
|
|
check balances[account.address.toDestination] == amount
|
|
|
|
done.complete()
|
|
|
|
))
|
2021-04-14 14:19:45 +00:00
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
await engine.blocksHandler(peerId, blocks)
|
2021-04-14 14:19:45 +00:00
|
|
|
await done.wait(100.millis)
|
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
test "Should handle block presence":
|
2021-04-26 15:11:11 +00:00
|
|
|
let price = UInt256.example
|
2022-01-10 15:32:56 +00:00
|
|
|
await engine.blockPresenceHandler(
|
2021-02-26 00:23:22 +00:00
|
|
|
peerId,
|
|
|
|
blocks.mapIt(
|
2021-04-26 15:11:11 +00:00
|
|
|
PresenceMessage.init(
|
|
|
|
Presence(
|
|
|
|
cid: it.cid,
|
|
|
|
have: true,
|
|
|
|
price: price
|
|
|
|
))))
|
|
|
|
|
|
|
|
for cid in blocks.mapIt(it.cid):
|
|
|
|
check peerCtx.peerHave.contains(cid)
|
|
|
|
check peerCtx.peerPrices[cid] == price
|
2021-02-26 00:23:22 +00:00
|
|
|
|
|
|
|
suite "Task Handler":
|
|
|
|
var
|
2022-05-19 02:29:15 +00:00
|
|
|
rng: Rng
|
|
|
|
seckey: PrivateKey
|
|
|
|
peerId: PeerID
|
|
|
|
chunker: Chunker
|
|
|
|
wallet: WalletRef
|
|
|
|
blockDiscovery: Discovery
|
|
|
|
peerStore: PeerCtxStore
|
|
|
|
pendingBlocks: PendingBlocksManager
|
|
|
|
network: BlockExcNetwork
|
2021-08-30 19:25:20 +00:00
|
|
|
engine: BlockExcEngine
|
2022-05-19 02:29:15 +00:00
|
|
|
discovery: DiscoveryEngine
|
|
|
|
peerCtx: BlockExcPeerCtx
|
|
|
|
localStore: BlockStore
|
|
|
|
|
2021-08-30 19:25:20 +00:00
|
|
|
peersCtx: seq[BlockExcPeerCtx]
|
2021-02-26 00:23:22 +00:00
|
|
|
peers: seq[PeerID]
|
2022-01-10 15:32:56 +00:00
|
|
|
blocks: seq[bt.Block]
|
2021-02-26 00:23:22 +00:00
|
|
|
|
|
|
|
setup:
|
2022-05-19 02:29:15 +00:00
|
|
|
rng = Rng.instance()
|
|
|
|
chunker = RandomChunker.new(rng, size = 1024, chunkSize = 256)
|
2022-01-10 15:32:56 +00:00
|
|
|
while true:
|
|
|
|
let chunk = await chunker.getBytes()
|
|
|
|
if chunk.len <= 0:
|
|
|
|
break
|
|
|
|
|
2022-03-18 19:50:53 +00:00
|
|
|
blocks.add(bt.Block.new(chunk).tryGet())
|
2022-01-10 15:32:56 +00:00
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
seckey = PrivateKey.random(rng[]).tryGet()
|
|
|
|
peerId = PeerID.init(seckey.getPublicKey().tryGet()).tryGet()
|
|
|
|
wallet = WalletRef.example
|
|
|
|
blockDiscovery = Discovery.new()
|
|
|
|
peerStore = PeerCtxStore.new()
|
|
|
|
pendingBlocks = PendingBlocksManager.new()
|
|
|
|
|
|
|
|
localStore = CacheStore.new()
|
|
|
|
network = BlockExcNetwork()
|
|
|
|
|
|
|
|
discovery = DiscoveryEngine.new(
|
|
|
|
localStore,
|
|
|
|
peerStore,
|
|
|
|
network,
|
|
|
|
blockDiscovery,
|
|
|
|
pendingBlocks)
|
|
|
|
|
|
|
|
engine = BlockExcEngine.new(
|
|
|
|
localStore,
|
|
|
|
wallet,
|
|
|
|
network,
|
|
|
|
discovery,
|
|
|
|
peerStore,
|
|
|
|
pendingBlocks)
|
2021-02-26 00:23:22 +00:00
|
|
|
peersCtx = @[]
|
|
|
|
|
|
|
|
for i in 0..3:
|
2022-01-13 00:42:18 +00:00
|
|
|
let seckey = PrivateKey.random(rng[]).tryGet()
|
|
|
|
peers.add(PeerID.init(seckey.getPublicKey().tryGet()).tryGet())
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2021-08-30 19:25:20 +00:00
|
|
|
peersCtx.add(BlockExcPeerCtx(
|
2021-02-26 00:23:22 +00:00
|
|
|
id: peers[i]
|
|
|
|
))
|
2022-05-19 02:29:15 +00:00
|
|
|
peerStore.add(peersCtx[i])
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2021-05-10 10:47:45 +00:00
|
|
|
engine.pricing = Pricing.example.some
|
2021-02-26 00:23:22 +00:00
|
|
|
|
|
|
|
test "Should send want-blocks in priority order":
|
|
|
|
proc sendBlocks(
|
|
|
|
id: PeerID,
|
|
|
|
blks: seq[bt.Block]) {.gcsafe.} =
|
|
|
|
check blks.len == 2
|
|
|
|
check:
|
|
|
|
blks[1].cid == blocks[0].cid
|
|
|
|
blks[0].cid == blocks[1].cid
|
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
for blk in blocks:
|
|
|
|
check await engine.localStore.putBlock(blk)
|
|
|
|
engine.network.request.sendBlocks = sendBlocks
|
2021-02-26 00:23:22 +00:00
|
|
|
|
|
|
|
# second block to send by priority
|
|
|
|
peersCtx[0].peerWants.add(
|
|
|
|
Entry(
|
|
|
|
`block`: blocks[0].cid.data.buffer,
|
|
|
|
priority: 49,
|
|
|
|
cancel: false,
|
|
|
|
wantType: WantType.wantBlock,
|
|
|
|
sendDontHave: false)
|
|
|
|
)
|
|
|
|
|
|
|
|
# first block to send by priority
|
|
|
|
peersCtx[0].peerWants.add(
|
|
|
|
Entry(
|
|
|
|
`block`: blocks[1].cid.data.buffer,
|
|
|
|
priority: 50,
|
|
|
|
cancel: false,
|
|
|
|
wantType: WantType.wantBlock,
|
|
|
|
sendDontHave: false)
|
|
|
|
)
|
|
|
|
|
|
|
|
await engine.taskHandler(peersCtx[0])
|
|
|
|
|
|
|
|
test "Should send presence":
|
2021-05-10 09:20:37 +00:00
|
|
|
let present = blocks
|
2022-03-18 19:50:53 +00:00
|
|
|
let missing = @[bt.Block.new("missing".toBytes).tryGet()]
|
2021-05-10 10:47:45 +00:00
|
|
|
let price = (!engine.pricing).price
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2021-05-10 09:20:37 +00:00
|
|
|
proc sendPresence(id: PeerID, presence: seq[BlockPresence]) =
|
|
|
|
check presence.mapIt(!Presence.init(it)) == @[
|
2021-05-10 10:47:45 +00:00
|
|
|
Presence(cid: present[0].cid, have: true, price: price),
|
|
|
|
Presence(cid: present[1].cid, have: true, price: price),
|
2021-05-10 09:20:37 +00:00
|
|
|
Presence(cid: missing[0].cid, have: false)
|
|
|
|
]
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2022-01-10 15:32:56 +00:00
|
|
|
for blk in blocks:
|
|
|
|
check await engine.localStore.putBlock(blk)
|
|
|
|
engine.network.request.sendPresence = sendPresence
|
2021-02-26 00:23:22 +00:00
|
|
|
|
|
|
|
# have block
|
|
|
|
peersCtx[0].peerWants.add(
|
|
|
|
Entry(
|
2021-05-10 09:20:37 +00:00
|
|
|
`block`: present[0].cid.data.buffer,
|
2021-02-26 00:23:22 +00:00
|
|
|
priority: 1,
|
|
|
|
cancel: false,
|
|
|
|
wantType: WantType.wantHave,
|
|
|
|
sendDontHave: false)
|
|
|
|
)
|
|
|
|
|
|
|
|
# have block
|
|
|
|
peersCtx[0].peerWants.add(
|
|
|
|
Entry(
|
2021-05-10 09:20:37 +00:00
|
|
|
`block`: present[1].cid.data.buffer,
|
2021-02-26 00:23:22 +00:00
|
|
|
priority: 1,
|
|
|
|
cancel: false,
|
|
|
|
wantType: WantType.wantHave,
|
|
|
|
sendDontHave: false)
|
|
|
|
)
|
|
|
|
|
|
|
|
# don't have block
|
|
|
|
peersCtx[0].peerWants.add(
|
|
|
|
Entry(
|
2021-05-10 09:20:37 +00:00
|
|
|
`block`: missing[0].cid.data.buffer,
|
2021-02-26 00:23:22 +00:00
|
|
|
priority: 1,
|
|
|
|
cancel: false,
|
|
|
|
wantType: WantType.wantHave,
|
|
|
|
sendDontHave: false)
|
|
|
|
)
|
|
|
|
|
|
|
|
await engine.taskHandler(peersCtx[0])
|