Add nitro wallet to BitswapNetwork
This commit is contained in:
parent
5cd714ea83
commit
8adea94196
|
@ -13,12 +13,14 @@ import pkg/chronicles
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
|
|
||||||
import pkg/libp2p
|
import pkg/libp2p
|
||||||
|
import pkg/nitro
|
||||||
|
|
||||||
import ../blocktype as bt
|
import ../blocktype as bt
|
||||||
import ./protobuf/bitswap as pb
|
import ./protobuf/bitswap as pb
|
||||||
import ./networkpeer
|
import ./networkpeer
|
||||||
|
|
||||||
export pb, networkpeer
|
export pb, networkpeer
|
||||||
|
export nitro
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "dagger bitswap network"
|
topics = "dagger bitswap network"
|
||||||
|
@ -55,6 +57,7 @@ type
|
||||||
BitswapNetwork* = ref object of LPProtocol
|
BitswapNetwork* = ref object of LPProtocol
|
||||||
peers*: Table[PeerID, NetworkPeer]
|
peers*: Table[PeerID, NetworkPeer]
|
||||||
switch*: Switch
|
switch*: Switch
|
||||||
|
wallet*: Wallet
|
||||||
handlers*: BitswapHandlers
|
handlers*: BitswapHandlers
|
||||||
request*: BitswapRequest
|
request*: BitswapRequest
|
||||||
getConn: ConnProvider
|
getConn: ConnProvider
|
||||||
|
@ -273,12 +276,14 @@ method init*(b: BitswapNetwork) =
|
||||||
proc new*(
|
proc new*(
|
||||||
T: type BitswapNetwork,
|
T: type BitswapNetwork,
|
||||||
switch: Switch,
|
switch: Switch,
|
||||||
|
wallet: Wallet,
|
||||||
connProvider: ConnProvider = nil): T =
|
connProvider: ConnProvider = nil): T =
|
||||||
## Create a new BitswapNetwork instance
|
## Create a new BitswapNetwork instance
|
||||||
##
|
##
|
||||||
|
|
||||||
let b = BitswapNetwork(
|
let b = BitswapNetwork(
|
||||||
switch: switch,
|
switch: switch,
|
||||||
|
wallet: wallet,
|
||||||
getConn: connProvider)
|
getConn: connProvider)
|
||||||
|
|
||||||
proc sendWantList(
|
proc sendWantList(
|
||||||
|
|
|
@ -27,6 +27,7 @@ suite "Bitswap engine - 2 nodes":
|
||||||
|
|
||||||
var
|
var
|
||||||
switch1, switch2: Switch
|
switch1, switch2: Switch
|
||||||
|
wallet1, wallet2: Wallet
|
||||||
network1, network2: BitswapNetwork
|
network1, network2: BitswapNetwork
|
||||||
bitswap1, bitswap2: Bitswap
|
bitswap1, bitswap2: Bitswap
|
||||||
awaiters: seq[Future[void]]
|
awaiters: seq[Future[void]]
|
||||||
|
@ -39,17 +40,19 @@ suite "Bitswap engine - 2 nodes":
|
||||||
|
|
||||||
switch1 = newStandardSwitch()
|
switch1 = newStandardSwitch()
|
||||||
switch2 = newStandardSwitch()
|
switch2 = newStandardSwitch()
|
||||||
|
wallet1 = Wallet.init(EthPrivateKey.random())
|
||||||
|
wallet2 = Wallet.init(EthPrivateKey.random())
|
||||||
awaiters.add(await switch1.start())
|
awaiters.add(await switch1.start())
|
||||||
awaiters.add(await switch2.start())
|
awaiters.add(await switch2.start())
|
||||||
|
|
||||||
peerId1 = switch1.peerInfo.peerId
|
peerId1 = switch1.peerInfo.peerId
|
||||||
peerId2 = switch2.peerInfo.peerId
|
peerId2 = switch2.peerInfo.peerId
|
||||||
|
|
||||||
network1 = BitswapNetwork.new(switch = switch1)
|
network1 = BitswapNetwork.new(switch1, wallet1)
|
||||||
bitswap1 = Bitswap.new(MemoryStore.new(blocks1), network1)
|
bitswap1 = Bitswap.new(MemoryStore.new(blocks1), network1)
|
||||||
switch1.mount(network1)
|
switch1.mount(network1)
|
||||||
|
|
||||||
network2 = BitswapNetwork.new(switch = switch2)
|
network2 = BitswapNetwork.new(switch2, wallet2)
|
||||||
bitswap2 = Bitswap.new(MemoryStore.new(blocks2), network2)
|
bitswap2 = Bitswap.new(MemoryStore.new(blocks2), network2)
|
||||||
switch2.mount(network2)
|
switch2.mount(network2)
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ suite "Bitswap network":
|
||||||
buffer = newBufferStream()
|
buffer = newBufferStream()
|
||||||
network = BitswapNetwork.new(
|
network = BitswapNetwork.new(
|
||||||
switch = newStandardSwitch(),
|
switch = newStandardSwitch(),
|
||||||
|
wallet = Wallet.init(EthPrivateKey.random()),
|
||||||
connProvider = getConn)
|
connProvider = getConn)
|
||||||
network.setupPeer(peerId)
|
network.setupPeer(peerId)
|
||||||
networkPeer = network.peers[peerId]
|
networkPeer = network.peers[peerId]
|
||||||
|
@ -108,6 +109,7 @@ suite "Bitswap Network - e2e":
|
||||||
|
|
||||||
var
|
var
|
||||||
switch1, switch2: Switch
|
switch1, switch2: Switch
|
||||||
|
wallet1, wallet2: Wallet
|
||||||
network1, network2: BitswapNetwork
|
network1, network2: BitswapNetwork
|
||||||
awaiters: seq[Future[void]]
|
awaiters: seq[Future[void]]
|
||||||
done: Future[void]
|
done: Future[void]
|
||||||
|
@ -116,15 +118,15 @@ suite "Bitswap Network - e2e":
|
||||||
done = newFuture[void]()
|
done = newFuture[void]()
|
||||||
switch1 = newStandardSwitch()
|
switch1 = newStandardSwitch()
|
||||||
switch2 = newStandardSwitch()
|
switch2 = newStandardSwitch()
|
||||||
|
wallet1 = Wallet.init(EthPrivateKey.random())
|
||||||
|
wallet2 = Wallet.init(EthPrivateKey.random())
|
||||||
awaiters.add(await switch1.start())
|
awaiters.add(await switch1.start())
|
||||||
awaiters.add(await switch2.start())
|
awaiters.add(await switch2.start())
|
||||||
|
|
||||||
network1 = BitswapNetwork.new(
|
network1 = BitswapNetwork.new(switch1, wallet1)
|
||||||
switch = switch1)
|
|
||||||
switch1.mount(network1)
|
switch1.mount(network1)
|
||||||
|
|
||||||
network2 = BitswapNetwork.new(
|
network2 = BitswapNetwork.new(switch2, wallet2)
|
||||||
switch = switch2)
|
|
||||||
switch2.mount(network2)
|
switch2.mount(network2)
|
||||||
|
|
||||||
await switch1.connect(
|
await switch1.connect(
|
||||||
|
|
|
@ -17,7 +17,8 @@ proc generateNodes*(
|
||||||
for i in 0..<num:
|
for i in 0..<num:
|
||||||
let
|
let
|
||||||
switch = newStandardSwitch(transportFlags = {ServerFlags.ReuseAddr})
|
switch = newStandardSwitch(transportFlags = {ServerFlags.ReuseAddr})
|
||||||
network = BitswapNetwork.new(switch = switch)
|
wallet = Wallet.init(EthPrivateKey.random())
|
||||||
|
network = BitswapNetwork.new(switch, wallet)
|
||||||
bitswap = Bitswap.new(MemoryStore.new(blocks), network)
|
bitswap = Bitswap.new(MemoryStore.new(blocks), network)
|
||||||
|
|
||||||
switch.mount(network)
|
switch.mount(network)
|
||||||
|
|
Loading…
Reference in New Issue