rename bitwsap to blockexc and move to stores
This commit is contained in:
parent
163fcefb31
commit
231276d6fe
|
@ -14,13 +14,13 @@ import pkg/chronos
|
||||||
import pkg/libp2p
|
import pkg/libp2p
|
||||||
import pkg/libp2p/errors
|
import pkg/libp2p/errors
|
||||||
|
|
||||||
import ./blockexc/protobuf/blockexc as pb
|
import ./stores/network/protobuf/blockexc as pb
|
||||||
import ./blocktype as bt
|
import ./blocktype as bt
|
||||||
import ./stores/blockstore
|
import ./stores/blockstore
|
||||||
import ./utils/asyncheapqueue
|
import ./utils/asyncheapqueue
|
||||||
|
|
||||||
import ./blockexc/network
|
import ./stores/network/network
|
||||||
import ./blockexc/engine
|
import ./stores/network/engine
|
||||||
|
|
||||||
export network, blockstore, asyncheapqueue, engine
|
export network, blockstore, asyncheapqueue, engine
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ method putBlocks*(b: BlockExc, blocks: seq[bt.Block]) =
|
||||||
|
|
||||||
procCall BlockStore(b).putBlocks(blocks)
|
procCall BlockStore(b).putBlocks(blocks)
|
||||||
|
|
||||||
func new*(
|
proc new*(
|
||||||
T: type BlockExc,
|
T: type BlockExc,
|
||||||
localStore: BlockStore,
|
localStore: BlockStore,
|
||||||
wallet: WalletRef,
|
wallet: WalletRef,
|
|
@ -17,7 +17,7 @@ import pkg/libp2p/errors
|
||||||
|
|
||||||
import ./protobuf/blockexc
|
import ./protobuf/blockexc
|
||||||
import ./protobuf/presence
|
import ./protobuf/presence
|
||||||
import ../blocktype as bt
|
import ../../blocktype as bt
|
||||||
import ../blockstore
|
import ../blockstore
|
||||||
import ../../utils/asyncheapqueue
|
import ../../utils/asyncheapqueue
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,12 @@ import pkg/libp2p
|
||||||
import pkg/questionable
|
import pkg/questionable
|
||||||
import pkg/questionable/results
|
import pkg/questionable/results
|
||||||
|
|
||||||
import ../blocktype as bt
|
import ../../blocktype as bt
|
||||||
import ./protobuf/blockexc
|
import ./protobuf/blockexc as pb
|
||||||
import ./protobuf/payments
|
import ./protobuf/payments
|
||||||
import ./networkpeer
|
import ./networkpeer
|
||||||
|
|
||||||
export pb, networkpeer
|
export networkpeer
|
||||||
export payments
|
export payments
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
|
@ -242,9 +242,6 @@ proc rpcHandler(b: BlockExcNetwork, peer: NetworkPeer, msg: Message) {.async.} =
|
||||||
if msg.wantlist.entries.len > 0:
|
if msg.wantlist.entries.len > 0:
|
||||||
b.handleWantList(peer, msg.wantlist)
|
b.handleWantList(peer, msg.wantlist)
|
||||||
|
|
||||||
if msg.blocks.len > 0:
|
|
||||||
b.handleBlocks(peer, msg.blocks)
|
|
||||||
|
|
||||||
if msg.payload.len > 0:
|
if msg.payload.len > 0:
|
||||||
b.handleBlocks(peer, msg.payload)
|
b.handleBlocks(peer, msg.payload)
|
||||||
|
|
||||||
|
@ -325,7 +322,7 @@ method init*(b: BlockExcNetwork) =
|
||||||
b.handler = handle
|
b.handler = handle
|
||||||
b.codec = Codec
|
b.codec = Codec
|
||||||
|
|
||||||
func new*(
|
proc new*(
|
||||||
T: type BlockExcNetwork,
|
T: type BlockExcNetwork,
|
||||||
switch: Switch,
|
switch: Switch,
|
||||||
connProvider: ConnProvider = nil): T =
|
connProvider: ConnProvider = nil): T =
|
||||||
|
|
|
@ -13,7 +13,7 @@ import pkg/chronicles
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/libp2p
|
import pkg/libp2p
|
||||||
|
|
||||||
import ../blocktype
|
import ../../blocktype
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "dagger blockexc pendingblocks"
|
topics = "dagger blockexc pendingblocks"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import std/unittest
|
import std/unittest
|
||||||
import pkg/dagger/bitswap/engine/payments
|
import pkg/dagger/stores/network/engine/payments
|
||||||
import ../../examples
|
import ../../examples
|
||||||
|
|
||||||
suite "engine payments":
|
suite "engine payments":
|
||||||
|
@ -8,11 +8,11 @@ suite "engine payments":
|
||||||
let amount = 42.u256
|
let amount = 42.u256
|
||||||
|
|
||||||
var wallet: WalletRef
|
var wallet: WalletRef
|
||||||
var peer: BitswapPeerCtx
|
var peer: BlockExcPeerCtx
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
wallet = WalletRef.example
|
wallet = WalletRef.example
|
||||||
peer = BitswapPeerCtx.example
|
peer = BlockExcPeerCtx.example
|
||||||
peer.account = Account(address: address).some
|
peer.account = Account(address: address).some
|
||||||
|
|
||||||
test "pays for received blocks":
|
test "pays for received blocks":
|
|
@ -2,7 +2,7 @@ import pkg/asynctest
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/stew/byteutils
|
import pkg/stew/byteutils
|
||||||
import ../../examples
|
import ../../examples
|
||||||
import ../../../../dagger/bitswap/protobuf/payments
|
import pkg/dagger/stores/network/protobuf/payments
|
||||||
|
|
||||||
suite "account protobuf messages":
|
suite "account protobuf messages":
|
||||||
|
|
|
@ -2,7 +2,7 @@ import std/sequtils
|
||||||
import pkg/asynctest
|
import pkg/asynctest
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/libp2p
|
import pkg/libp2p
|
||||||
import ../../../../dagger/bitswap/protobuf/presence
|
import pkg/dagger/stores/network/protobuf/presence
|
||||||
import ../../examples
|
import ../../examples
|
||||||
|
|
||||||
suite "block presence protobuf messages":
|
suite "block presence protobuf messages":
|
|
@ -8,8 +8,9 @@ import pkg/libp2p
|
||||||
import pkg/libp2p/errors
|
import pkg/libp2p/errors
|
||||||
|
|
||||||
import pkg/dagger/rng
|
import pkg/dagger/rng
|
||||||
import pkg/dagger/bitswap
|
import pkg/dagger/blockexc
|
||||||
import pkg/dagger/bitswap/engine/payments
|
import pkg/dagger/stores/network/protobuf/blockexc as pb
|
||||||
|
import pkg/dagger/stores/network/engine/payments
|
||||||
import pkg/dagger/stores/memorystore
|
import pkg/dagger/stores/memorystore
|
||||||
import pkg/dagger/chunker
|
import pkg/dagger/chunker
|
||||||
import pkg/dagger/blocktype as bt
|
import pkg/dagger/blocktype as bt
|
||||||
|
@ -19,7 +20,7 @@ import ./utils
|
||||||
import ../helpers
|
import ../helpers
|
||||||
import ../examples
|
import ../examples
|
||||||
|
|
||||||
suite "Bitswap engine - 2 nodes":
|
suite "BlockExc engine - 2 nodes":
|
||||||
|
|
||||||
let
|
let
|
||||||
chunker1 = newRandomChunker(Rng.instance(), size = 1024, chunkSize = 256)
|
chunker1 = newRandomChunker(Rng.instance(), size = 1024, chunkSize = 256)
|
||||||
|
@ -31,11 +32,11 @@ suite "Bitswap engine - 2 nodes":
|
||||||
switch1, switch2: Switch
|
switch1, switch2: Switch
|
||||||
wallet1, wallet2: WalletRef
|
wallet1, wallet2: WalletRef
|
||||||
pricing1, pricing2: Pricing
|
pricing1, pricing2: Pricing
|
||||||
network1, network2: BitswapNetwork
|
network1, network2: BlockExcNetwork
|
||||||
bitswap1, bitswap2: Bitswap
|
blockexc1, blockexc2: BlockExc
|
||||||
awaiters: seq[Future[void]]
|
awaiters: seq[Future[void]]
|
||||||
peerId1, peerId2: PeerID
|
peerId1, peerId2: PeerID
|
||||||
peerCtx1, peerCtx2: BitswapPeerCtx
|
peerCtx1, peerCtx2: BlockExcPeerCtx
|
||||||
done: Future[void]
|
done: Future[void]
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
|
@ -53,40 +54,40 @@ suite "Bitswap engine - 2 nodes":
|
||||||
peerId1 = switch1.peerInfo.peerId
|
peerId1 = switch1.peerInfo.peerId
|
||||||
peerId2 = switch2.peerInfo.peerId
|
peerId2 = switch2.peerInfo.peerId
|
||||||
|
|
||||||
network1 = BitswapNetwork.new(switch = switch1)
|
network1 = BlockExcNetwork.new(switch = switch1)
|
||||||
bitswap1 = Bitswap.new(MemoryStore.new(blocks1), wallet1, network1)
|
blockexc1 = BlockExc.new(MemoryStore.new(blocks1), wallet1, network1)
|
||||||
switch1.mount(network1)
|
switch1.mount(network1)
|
||||||
|
|
||||||
network2 = BitswapNetwork.new(switch = switch2)
|
network2 = BlockExcNetwork.new(switch = switch2)
|
||||||
bitswap2 = Bitswap.new(MemoryStore.new(blocks2), wallet2, network2)
|
blockexc2 = BlockExc.new(MemoryStore.new(blocks2), wallet2, network2)
|
||||||
switch2.mount(network2)
|
switch2.mount(network2)
|
||||||
|
|
||||||
await allFuturesThrowing(
|
await allFuturesThrowing(
|
||||||
bitswap1.start(),
|
blockexc1.start(),
|
||||||
bitswap2.start(),
|
blockexc2.start(),
|
||||||
)
|
)
|
||||||
|
|
||||||
# initialize our want lists
|
# initialize our want lists
|
||||||
bitswap1.engine.wantList = blocks2.mapIt( it.cid )
|
blockexc1.engine.wantList = blocks2.mapIt( it.cid )
|
||||||
bitswap2.engine.wantList = blocks1.mapIt( it.cid )
|
blockexc2.engine.wantList = blocks1.mapIt( it.cid )
|
||||||
|
|
||||||
pricing1.address = wallet1.address
|
pricing1.address = wallet1.address
|
||||||
pricing2.address = wallet2.address
|
pricing2.address = wallet2.address
|
||||||
bitswap1.engine.pricing = pricing1.some
|
blockexc1.engine.pricing = pricing1.some
|
||||||
bitswap2.engine.pricing = pricing2.some
|
blockexc2.engine.pricing = pricing2.some
|
||||||
|
|
||||||
await switch1.connect(
|
await switch1.connect(
|
||||||
switch2.peerInfo.peerId,
|
switch2.peerInfo.peerId,
|
||||||
switch2.peerInfo.addrs)
|
switch2.peerInfo.addrs)
|
||||||
|
|
||||||
await sleepAsync(1.seconds) # give some time to exchange lists
|
await sleepAsync(1.seconds) # give some time to exchange lists
|
||||||
peerCtx2 = bitswap1.engine.getPeerCtx(peerId2)
|
peerCtx2 = blockexc1.engine.getPeerCtx(peerId2)
|
||||||
peerCtx1 = bitswap2.engine.getPeerCtx(peerId1)
|
peerCtx1 = blockexc2.engine.getPeerCtx(peerId1)
|
||||||
|
|
||||||
teardown:
|
teardown:
|
||||||
await allFuturesThrowing(
|
await allFuturesThrowing(
|
||||||
bitswap1.stop(),
|
blockexc1.stop(),
|
||||||
bitswap2.stop(),
|
blockexc2.stop(),
|
||||||
switch1.stop(),
|
switch1.stop(),
|
||||||
switch2.stop())
|
switch2.stop())
|
||||||
|
|
||||||
|
@ -98,10 +99,10 @@ suite "Bitswap engine - 2 nodes":
|
||||||
|
|
||||||
check:
|
check:
|
||||||
peerCtx1.peerHave.mapIt( $it ).sorted(cmp[string]) ==
|
peerCtx1.peerHave.mapIt( $it ).sorted(cmp[string]) ==
|
||||||
bitswap2.engine.wantList.mapIt( $it ).sorted(cmp[string])
|
blockexc2.engine.wantList.mapIt( $it ).sorted(cmp[string])
|
||||||
|
|
||||||
peerCtx2.peerHave.mapIt( $it ).sorted(cmp[string]) ==
|
peerCtx2.peerHave.mapIt( $it ).sorted(cmp[string]) ==
|
||||||
bitswap1.engine.wantList.mapIt( $it ).sorted(cmp[string])
|
blockexc1.engine.wantList.mapIt( $it ).sorted(cmp[string])
|
||||||
|
|
||||||
test "exchanges accounts on connect":
|
test "exchanges accounts on connect":
|
||||||
check peerCtx1.account.?address == pricing1.address.some
|
check peerCtx1.account.?address == pricing1.address.some
|
||||||
|
@ -109,7 +110,7 @@ suite "Bitswap engine - 2 nodes":
|
||||||
|
|
||||||
test "should send want-have for block":
|
test "should send want-have for block":
|
||||||
let blk = !bt.Block.new("Block 1".toBytes)
|
let blk = !bt.Block.new("Block 1".toBytes)
|
||||||
bitswap2.engine.localStore.putBlocks(@[blk])
|
blockexc2.engine.localStore.putBlocks(@[blk])
|
||||||
|
|
||||||
let entry = Entry(
|
let entry = Entry(
|
||||||
`block`: blk.cid.data.buffer,
|
`block`: blk.cid.data.buffer,
|
||||||
|
@ -119,58 +120,58 @@ suite "Bitswap engine - 2 nodes":
|
||||||
sendDontHave: false)
|
sendDontHave: false)
|
||||||
|
|
||||||
peerCtx1.peerWants.add(entry)
|
peerCtx1.peerWants.add(entry)
|
||||||
check bitswap2.taskQueue.pushOrUpdateNoWait(peerCtx1).isOk
|
check blockexc2.taskQueue.pushOrUpdateNoWait(peerCtx1).isOk
|
||||||
await sleepAsync(100.millis)
|
await sleepAsync(100.millis)
|
||||||
|
|
||||||
check bitswap1.engine.localStore.hasBlock(blk.cid)
|
check blockexc1.engine.localStore.hasBlock(blk.cid)
|
||||||
|
|
||||||
test "should get blocks from remote":
|
test "should get blocks from remote":
|
||||||
let blocks = await bitswap1.getBlocks(blocks2.mapIt( it.cid ))
|
let blocks = await blockexc1.getBlocks(blocks2.mapIt( it.cid ))
|
||||||
check blocks == blocks2
|
check blocks == blocks2
|
||||||
|
|
||||||
test "remote should send blocks when available":
|
test "remote should send blocks when available":
|
||||||
let blk = !bt.Block.new("Block 1".toBytes)
|
let blk = !bt.Block.new("Block 1".toBytes)
|
||||||
|
|
||||||
# should fail retrieving block from remote
|
# should fail retrieving block from remote
|
||||||
check not await bitswap1.getBlocks(@[blk.cid])
|
check not await blockexc1.getBlocks(@[blk.cid])
|
||||||
.withTimeout(100.millis) # should expire
|
.withTimeout(100.millis) # should expire
|
||||||
|
|
||||||
proc onBlocks(evt: BlockStoreChangeEvt) =
|
proc onBlocks(evt: BlockStoreChangeEvt) =
|
||||||
check evt.cids == @[blk.cid]
|
check evt.cids == @[blk.cid]
|
||||||
done.complete()
|
done.complete()
|
||||||
|
|
||||||
bitswap1.engine.localStore.addChangeHandler(onBlocks, ChangeType.Added)
|
blockexc1.engine.localStore.addChangeHandler(onBlocks, ChangeType.Added)
|
||||||
|
|
||||||
# first put the required block in the local store
|
# first put the required block in the local store
|
||||||
bitswap2.engine.localStore.putBlocks(@[blk])
|
blockexc2.engine.localStore.putBlocks(@[blk])
|
||||||
|
|
||||||
# second trigger bitswap to resolve any pending requests
|
# second trigger blockexc to resolve any pending requests
|
||||||
# for the block
|
# for the block
|
||||||
bitswap2.putBlocks(@[blk])
|
blockexc2.putBlocks(@[blk])
|
||||||
|
|
||||||
await done
|
await done
|
||||||
|
|
||||||
test "receives payments for blocks that were sent":
|
test "receives payments for blocks that were sent":
|
||||||
let blocks = await bitswap1.getBlocks(blocks2.mapIt(it.cid))
|
let blocks = await blockexc1.getBlocks(blocks2.mapIt(it.cid))
|
||||||
await sleepAsync(100.millis)
|
await sleepAsync(100.millis)
|
||||||
let channel = !peerCtx1.paymentChannel
|
let channel = !peerCtx1.paymentChannel
|
||||||
check wallet2.balance(channel, Asset) > 0
|
check wallet2.balance(channel, Asset) > 0
|
||||||
|
|
||||||
suite "Bitswap - multiple nodes":
|
suite "BlockExc - multiple nodes":
|
||||||
let
|
let
|
||||||
chunker = newRandomChunker(Rng.instance(), size = 4096, chunkSize = 256)
|
chunker = newRandomChunker(Rng.instance(), size = 4096, chunkSize = 256)
|
||||||
blocks = chunker.mapIt( !bt.Block.new(it) )
|
blocks = chunker.mapIt( !bt.Block.new(it) )
|
||||||
|
|
||||||
var
|
var
|
||||||
switch: seq[Switch]
|
switch: seq[Switch]
|
||||||
bitswap: seq[Bitswap]
|
blockexc: seq[BlockExc]
|
||||||
awaiters: seq[Future[void]]
|
awaiters: seq[Future[void]]
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
for e in generateNodes(5):
|
for e in generateNodes(5):
|
||||||
switch.add(e.switch)
|
switch.add(e.switch)
|
||||||
bitswap.add(e.bitswap)
|
blockexc.add(e.blockexc)
|
||||||
await e.bitswap.start()
|
await e.blockexc.start()
|
||||||
|
|
||||||
awaiters = switch.mapIt(
|
awaiters = switch.mapIt(
|
||||||
(await it.start())
|
(await it.start())
|
||||||
|
@ -185,17 +186,17 @@ suite "Bitswap - multiple nodes":
|
||||||
|
|
||||||
test "should receive haves for own want list":
|
test "should receive haves for own want list":
|
||||||
let
|
let
|
||||||
downloader = bitswap[4]
|
downloader = blockexc[4]
|
||||||
engine = downloader.engine
|
engine = downloader.engine
|
||||||
|
|
||||||
# Add blocks from 1st peer to want list
|
# Add blocks from 1st peer to want list
|
||||||
engine.wantList &= blocks[0..3].mapIt( it.cid )
|
engine.wantList &= blocks[0..3].mapIt( it.cid )
|
||||||
engine.wantList &= blocks[12..15].mapIt( it.cid )
|
engine.wantList &= blocks[12..15].mapIt( it.cid )
|
||||||
|
|
||||||
bitswap[0].engine.localStore.putBlocks(blocks[0..3])
|
blockexc[0].engine.localStore.putBlocks(blocks[0..3])
|
||||||
bitswap[1].engine.localStore.putBlocks(blocks[4..7])
|
blockexc[1].engine.localStore.putBlocks(blocks[4..7])
|
||||||
bitswap[2].engine.localStore.putBlocks(blocks[8..11])
|
blockexc[2].engine.localStore.putBlocks(blocks[8..11])
|
||||||
bitswap[3].engine.localStore.putBlocks(blocks[12..15])
|
blockexc[3].engine.localStore.putBlocks(blocks[12..15])
|
||||||
|
|
||||||
await connectNodes(switch)
|
await connectNodes(switch)
|
||||||
|
|
||||||
|
@ -209,17 +210,17 @@ suite "Bitswap - multiple nodes":
|
||||||
|
|
||||||
test "should exchange blocks with multiple nodes":
|
test "should exchange blocks with multiple nodes":
|
||||||
let
|
let
|
||||||
downloader = bitswap[4]
|
downloader = blockexc[4]
|
||||||
engine = downloader.engine
|
engine = downloader.engine
|
||||||
|
|
||||||
# Add blocks from 1st peer to want list
|
# Add blocks from 1st peer to want list
|
||||||
engine.wantList &= blocks[0..3].mapIt( it.cid )
|
engine.wantList &= blocks[0..3].mapIt( it.cid )
|
||||||
engine.wantList &= blocks[12..15].mapIt( it.cid )
|
engine.wantList &= blocks[12..15].mapIt( it.cid )
|
||||||
|
|
||||||
bitswap[0].engine.localStore.putBlocks(blocks[0..3])
|
blockexc[0].engine.localStore.putBlocks(blocks[0..3])
|
||||||
bitswap[1].engine.localStore.putBlocks(blocks[4..7])
|
blockexc[1].engine.localStore.putBlocks(blocks[4..7])
|
||||||
bitswap[2].engine.localStore.putBlocks(blocks[8..11])
|
blockexc[2].engine.localStore.putBlocks(blocks[8..11])
|
||||||
bitswap[3].engine.localStore.putBlocks(blocks[12..15])
|
blockexc[3].engine.localStore.putBlocks(blocks[12..15])
|
||||||
|
|
||||||
await connectNodes(switch)
|
await connectNodes(switch)
|
||||||
let wantListBlocks = await downloader.getBlocks(blocks[0..3].mapIt( it.cid ))
|
let wantListBlocks = await downloader.getBlocks(blocks[0..3].mapIt( it.cid ))
|
|
@ -8,10 +8,11 @@ import pkg/libp2p
|
||||||
import pkg/libp2p/errors
|
import pkg/libp2p/errors
|
||||||
|
|
||||||
import pkg/dagger/rng
|
import pkg/dagger/rng
|
||||||
import pkg/dagger/bitswap
|
import pkg/dagger/blockexc
|
||||||
import pkg/dagger/bitswap/pendingblocks
|
import pkg/dagger/stores/network/protobuf/blockexc as pb
|
||||||
import pkg/dagger/bitswap/engine/payments
|
import pkg/dagger/stores/network/pendingblocks
|
||||||
import pkg/dagger/bitswap/protobuf/presence
|
import pkg/dagger/stores/network/engine/payments
|
||||||
|
import pkg/dagger/stores/network/protobuf/presence
|
||||||
import pkg/dagger/stores/memorystore
|
import pkg/dagger/stores/memorystore
|
||||||
import pkg/dagger/chunker
|
import pkg/dagger/chunker
|
||||||
import pkg/dagger/blocktype as bt
|
import pkg/dagger/blocktype as bt
|
||||||
|
@ -19,7 +20,7 @@ import pkg/dagger/blocktype as bt
|
||||||
import ../helpers
|
import ../helpers
|
||||||
import ../examples
|
import ../examples
|
||||||
|
|
||||||
suite "Bitswap engine basic":
|
suite "BlockExc engine basic":
|
||||||
let
|
let
|
||||||
rng = Rng.instance()
|
rng = Rng.instance()
|
||||||
seckey = PrivateKey.random(rng[]).tryGet()
|
seckey = PrivateKey.random(rng[]).tryGet()
|
||||||
|
@ -47,11 +48,11 @@ suite "Bitswap engine basic":
|
||||||
|
|
||||||
done.complete()
|
done.complete()
|
||||||
|
|
||||||
let request = BitswapRequest(
|
let request = BlockExcRequest(
|
||||||
sendWantList: sendWantList,
|
sendWantList: sendWantList,
|
||||||
)
|
)
|
||||||
|
|
||||||
let engine = BitswapEngine.new(MemoryStore.new(blocks), wallet, request)
|
let engine = BlockExcEngine.new(MemoryStore.new(blocks), wallet, request)
|
||||||
engine.wantList = blocks.mapIt( it.cid )
|
engine.wantList = blocks.mapIt( it.cid )
|
||||||
engine.setupPeer(peerId)
|
engine.setupPeer(peerId)
|
||||||
|
|
||||||
|
@ -64,14 +65,14 @@ suite "Bitswap engine basic":
|
||||||
check account.address == pricing.address
|
check account.address == pricing.address
|
||||||
done.complete()
|
done.complete()
|
||||||
|
|
||||||
let request = BitswapRequest(sendAccount: sendAccount)
|
let request = BlockExcRequest(sendAccount: sendAccount)
|
||||||
let engine = BitswapEngine.new(MemoryStore.new, wallet, request)
|
let engine = BlockExcEngine.new(MemoryStore.new, wallet, request)
|
||||||
engine.pricing = pricing.some
|
engine.pricing = pricing.some
|
||||||
|
|
||||||
engine.setupPeer(peerId)
|
engine.setupPeer(peerId)
|
||||||
await done.wait(100.millis)
|
await done.wait(100.millis)
|
||||||
|
|
||||||
suite "Bitswap engine handlers":
|
suite "BlockExc engine handlers":
|
||||||
let
|
let
|
||||||
rng = Rng.instance()
|
rng = Rng.instance()
|
||||||
seckey = PrivateKey.random(rng[]).tryGet()
|
seckey = PrivateKey.random(rng[]).tryGet()
|
||||||
|
@ -81,21 +82,21 @@ suite "Bitswap engine handlers":
|
||||||
wallet = WalletRef.example
|
wallet = WalletRef.example
|
||||||
|
|
||||||
var
|
var
|
||||||
engine: BitswapEngine
|
engine: BlockExcEngine
|
||||||
peerCtx: BitswapPeerCtx
|
peerCtx: BlockExcPeerCtx
|
||||||
done: Future[void]
|
done: Future[void]
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
done = newFuture[void]()
|
done = newFuture[void]()
|
||||||
engine = BitswapEngine.new(MemoryStore.new(), wallet)
|
engine = BlockExcEngine.new(MemoryStore.new(), wallet)
|
||||||
peerCtx = BitswapPeerCtx(
|
peerCtx = BlockExcPeerCtx(
|
||||||
id: peerId
|
id: peerId
|
||||||
)
|
)
|
||||||
engine.peers.add(peerCtx)
|
engine.peers.add(peerCtx)
|
||||||
|
|
||||||
test "should handle want list":
|
test "should handle want list":
|
||||||
let wantList = makeWantList(blocks.mapIt( it.cid ))
|
let wantList = makeWantList(blocks.mapIt( it.cid ))
|
||||||
proc taskScheduler(ctx: BitswapPeerCtx): bool =
|
proc taskScheduler(ctx: BlockExcPeerCtx): bool =
|
||||||
check ctx.id == peerId
|
check ctx.id == peerId
|
||||||
check ctx.peerWants.mapIt( it.cid ) == blocks.mapIt( it.cid )
|
check ctx.peerWants.mapIt( it.cid ) == blocks.mapIt( it.cid )
|
||||||
|
|
||||||
|
@ -116,7 +117,7 @@ suite "Bitswap engine handlers":
|
||||||
|
|
||||||
done.complete()
|
done.complete()
|
||||||
|
|
||||||
engine.request = BitswapRequest(
|
engine.request = BlockExcRequest(
|
||||||
sendPresence: sendPresence
|
sendPresence: sendPresence
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -134,7 +135,7 @@ suite "Bitswap engine handlers":
|
||||||
|
|
||||||
done.complete()
|
done.complete()
|
||||||
|
|
||||||
engine.request = BitswapRequest(sendPresence: sendPresence)
|
engine.request = BlockExcRequest(sendPresence: sendPresence)
|
||||||
engine.localStore.putBlocks(@[blocks[0], blocks[1]])
|
engine.localStore.putBlocks(@[blocks[0], blocks[1]])
|
||||||
engine.wantListHandler(peerId, wantList)
|
engine.wantListHandler(peerId, wantList)
|
||||||
|
|
||||||
|
@ -193,21 +194,21 @@ suite "Task Handler":
|
||||||
wallet = WalletRef.example
|
wallet = WalletRef.example
|
||||||
|
|
||||||
var
|
var
|
||||||
engine: BitswapEngine
|
engine: BlockExcEngine
|
||||||
peersCtx: seq[BitswapPeerCtx]
|
peersCtx: seq[BlockExcPeerCtx]
|
||||||
peers: seq[PeerID]
|
peers: seq[PeerID]
|
||||||
done: Future[void]
|
done: Future[void]
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
done = newFuture[void]()
|
done = newFuture[void]()
|
||||||
engine = BitswapEngine.new(MemoryStore.new(), wallet)
|
engine = BlockExcEngine.new(MemoryStore.new(), wallet)
|
||||||
peersCtx = @[]
|
peersCtx = @[]
|
||||||
|
|
||||||
for i in 0..3:
|
for i in 0..3:
|
||||||
let seckey = PrivateKey.random(rng[]).tryGet()
|
let seckey = PrivateKey.random(rng[]).tryGet()
|
||||||
peers.add(PeerID.init(seckey.getKey().tryGet()).tryGet())
|
peers.add(PeerID.init(seckey.getKey().tryGet()).tryGet())
|
||||||
|
|
||||||
peersCtx.add(BitswapPeerCtx(
|
peersCtx.add(BlockExcPeerCtx(
|
||||||
id: peers[i]
|
id: peers[i]
|
||||||
))
|
))
|
||||||
|
|
|
@ -7,17 +7,18 @@ import pkg/libp2p
|
||||||
import pkg/libp2p/errors
|
import pkg/libp2p/errors
|
||||||
import pkg/protobuf_serialization
|
import pkg/protobuf_serialization
|
||||||
|
|
||||||
import pkg/dagger/stores/memorystore
|
|
||||||
import pkg/dagger/bitswap/network
|
|
||||||
import pkg/dagger/bitswap/protobuf/payments
|
|
||||||
import pkg/dagger/rng
|
import pkg/dagger/rng
|
||||||
import pkg/dagger/chunker
|
import pkg/dagger/chunker
|
||||||
import pkg/dagger/blocktype as bt
|
import pkg/dagger/blocktype as bt
|
||||||
|
import pkg/dagger/stores/memorystore
|
||||||
|
import pkg/dagger/stores/network/network
|
||||||
|
import pkg/dagger/stores/network/protobuf/blockexc
|
||||||
|
import pkg/dagger/stores/network/protobuf/payments
|
||||||
|
|
||||||
import ../helpers
|
import ../helpers
|
||||||
import ../examples
|
import ../examples
|
||||||
|
|
||||||
suite "Bitswap network":
|
suite "BlockExc network":
|
||||||
let
|
let
|
||||||
rng = Rng.instance()
|
rng = Rng.instance()
|
||||||
seckey = PrivateKey.random(rng[]).tryGet()
|
seckey = PrivateKey.random(rng[]).tryGet()
|
||||||
|
@ -26,7 +27,7 @@ suite "Bitswap network":
|
||||||
blocks = chunker.mapIt( !bt.Block.new(it) )
|
blocks = chunker.mapIt( !bt.Block.new(it) )
|
||||||
|
|
||||||
var
|
var
|
||||||
network: BitswapNetwork
|
network: BlockExcNetwork
|
||||||
networkPeer: NetworkPeer
|
networkPeer: NetworkPeer
|
||||||
buffer: BufferStream
|
buffer: BufferStream
|
||||||
done: Future[void]
|
done: Future[void]
|
||||||
|
@ -37,7 +38,7 @@ suite "Bitswap network":
|
||||||
setup:
|
setup:
|
||||||
done = newFuture[void]()
|
done = newFuture[void]()
|
||||||
buffer = newBufferStream()
|
buffer = newBufferStream()
|
||||||
network = BitswapNetwork.new(
|
network = BlockExcNetwork.new(
|
||||||
switch = newStandardSwitch(),
|
switch = newStandardSwitch(),
|
||||||
connProvider = getConn)
|
connProvider = getConn)
|
||||||
network.setupPeer(peerId)
|
network.setupPeer(peerId)
|
||||||
|
@ -131,14 +132,14 @@ suite "Bitswap network":
|
||||||
|
|
||||||
await done.wait(100.millis)
|
await done.wait(100.millis)
|
||||||
|
|
||||||
suite "Bitswap Network - e2e":
|
suite "BlockExc Network - e2e":
|
||||||
let
|
let
|
||||||
chunker = newRandomChunker(Rng.instance(), size = 1024, chunkSize = 256)
|
chunker = newRandomChunker(Rng.instance(), size = 1024, chunkSize = 256)
|
||||||
blocks = chunker.mapIt( !bt.Block.new(it) )
|
blocks = chunker.mapIt( !bt.Block.new(it) )
|
||||||
|
|
||||||
var
|
var
|
||||||
switch1, switch2: Switch
|
switch1, switch2: Switch
|
||||||
network1, network2: BitswapNetwork
|
network1, network2: BlockExcNetwork
|
||||||
awaiters: seq[Future[void]]
|
awaiters: seq[Future[void]]
|
||||||
done: Future[void]
|
done: Future[void]
|
||||||
|
|
||||||
|
@ -149,11 +150,11 @@ suite "Bitswap Network - e2e":
|
||||||
awaiters.add(await switch1.start())
|
awaiters.add(await switch1.start())
|
||||||
awaiters.add(await switch2.start())
|
awaiters.add(await switch2.start())
|
||||||
|
|
||||||
network1 = BitswapNetwork.new(
|
network1 = BlockExcNetwork.new(
|
||||||
switch = switch1)
|
switch = switch1)
|
||||||
switch1.mount(network1)
|
switch1.mount(network1)
|
||||||
|
|
||||||
network2 = BitswapNetwork.new(
|
network2 = BlockExcNetwork.new(
|
||||||
switch = switch2)
|
switch = switch2)
|
||||||
switch2.mount(network2)
|
switch2.mount(network2)
|
||||||
|
|
|
@ -3,7 +3,7 @@ import std/sequtils
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/libp2p
|
import pkg/libp2p
|
||||||
|
|
||||||
import pkg/dagger/bitswap
|
import pkg/dagger/blockexc
|
||||||
import pkg/dagger/stores/memorystore
|
import pkg/dagger/stores/memorystore
|
||||||
import pkg/dagger/blocktype as bt
|
import pkg/dagger/blocktype as bt
|
||||||
|
|
||||||
|
@ -14,21 +14,21 @@ proc generateNodes*(
|
||||||
blocks: openArray[bt.Block] = [],
|
blocks: openArray[bt.Block] = [],
|
||||||
secureManagers: openarray[SecureProtocol] = [
|
secureManagers: openarray[SecureProtocol] = [
|
||||||
SecureProtocol.Noise,
|
SecureProtocol.Noise,
|
||||||
]): seq[tuple[switch: Switch, bitswap: Bitswap]] =
|
]): seq[tuple[switch: Switch, blockexc: BlockExc]] =
|
||||||
|
|
||||||
for i in 0..<num:
|
for i in 0..<num:
|
||||||
let
|
let
|
||||||
switch = newStandardSwitch(transportFlags = {ServerFlags.ReuseAddr})
|
switch = newStandardSwitch(transportFlags = {ServerFlags.ReuseAddr})
|
||||||
wallet = WalletRef.example
|
wallet = WalletRef.example
|
||||||
network = BitswapNetwork.new(switch)
|
network = BlockExcNetwork.new(switch)
|
||||||
bitswap = Bitswap.new(MemoryStore.new(blocks), wallet, network)
|
blockexc = BlockExc.new(MemoryStore.new(blocks), wallet, network)
|
||||||
|
|
||||||
switch.mount(network)
|
switch.mount(network)
|
||||||
|
|
||||||
# initialize our want lists
|
# initialize our want lists
|
||||||
bitswap.engine.wantList = blocks.mapIt( it.cid )
|
blockexc.engine.wantList = blocks.mapIt( it.cid )
|
||||||
switch.mount(network)
|
switch.mount(network)
|
||||||
result.add((switch, bitswap))
|
result.add((switch, blockexc))
|
||||||
|
|
||||||
proc connectNodes*(nodes: seq[Switch]) {.async.} =
|
proc connectNodes*(nodes: seq[Switch]) {.async.} =
|
||||||
for dialer in nodes:
|
for dialer in nodes:
|
|
@ -3,9 +3,9 @@ import std/sequtils
|
||||||
import pkg/libp2p
|
import pkg/libp2p
|
||||||
import pkg/nitro
|
import pkg/nitro
|
||||||
import pkg/dagger/rng
|
import pkg/dagger/rng
|
||||||
import pkg/dagger/bitswap/protobuf/payments
|
import pkg/dagger/stores/network/protobuf/payments
|
||||||
import pkg/dagger/bitswap/peercontext
|
import pkg/dagger/stores/network/peercontext
|
||||||
import pkg/dagger/bitswap/engine
|
import pkg/dagger/stores/network/engine
|
||||||
import pkg/dagger/blocktype
|
import pkg/dagger/blocktype
|
||||||
|
|
||||||
proc example*(_: type EthAddress): EthAddress =
|
proc example*(_: type EthAddress): EthAddress =
|
||||||
|
@ -50,8 +50,8 @@ proc example*(_: type PeerId): PeerID =
|
||||||
let key = PrivateKey.random(Rng.instance[]).get
|
let key = PrivateKey.random(Rng.instance[]).get
|
||||||
PeerId.init(key.getKey().get).get
|
PeerId.init(key.getKey().get).get
|
||||||
|
|
||||||
proc example*(_: type BitswapPeerCtx): BitswapPeerCtx =
|
proc example*(_: type BlockExcPeerCtx): BlockExcPeerCtx =
|
||||||
BitswapPeerCtx(id: PeerID.example)
|
BlockExcPeerCtx(id: PeerID.example)
|
||||||
|
|
||||||
proc example*(_: type Cid): Cid =
|
proc example*(_: type Cid): Cid =
|
||||||
Block.example.cid
|
Block.example.cid
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import ./dagger/bitswap/testbitswap
|
import ./dagger/blockexc/testblockexc
|
||||||
import ./dagger/bitswap/testengine
|
import ./dagger/blockexc/testengine
|
||||||
import ./dagger/bitswap/testnetwork
|
import ./dagger/blockexc/testnetwork
|
||||||
import ./dagger/bitswap/protobuf/testpayments as testprotobufpayments
|
import ./dagger/blockexc/protobuf/testpayments as testprotobufpayments
|
||||||
import ./dagger/bitswap/protobuf/testpresence
|
import ./dagger/blockexc/protobuf/testpresence
|
||||||
import ./dagger/bitswap/engine/testpayments as testenginepayments
|
import ./dagger/blockexc/engine/testpayments as testenginepayments
|
||||||
import ./dagger/testasyncheapqueue
|
import ./dagger/testasyncheapqueue
|
||||||
import ./dagger/testblockstore
|
import ./dagger/testblockstore
|
||||||
import ./dagger/testchunking
|
import ./dagger/testchunking
|
||||||
|
|
Loading…
Reference in New Issue