mirror of
https://github.com/logos-storage/libp2p-storage-mix-transport.git
synced 2026-05-20 09:49:33 +00:00
alignes with the new dependency structure - MIX is now in a separate repo
This commit is contained in:
parent
bf7b13529e
commit
e27acb641c
@ -7,6 +7,7 @@ entryPoints = @["mix_ping_tcp.nim", "mix_ping_quic.nim"]
|
||||
|
||||
requires "nim >= 2.0.0"
|
||||
requires "libp2p >= 1.15.3"
|
||||
requires "https://github.com/logos-co/nim-libp2p-mix.git#feat/mix-read-behavior"
|
||||
requires "chronicles >= 0.11.0"
|
||||
requires "chronos >= 4.2.2"
|
||||
requires "results >= 0.5.0"
|
||||
|
||||
@ -13,9 +13,6 @@
|
||||
import chronicles, chronos, results
|
||||
import std/[strformat, sequtils, sugar]
|
||||
import libp2p/[
|
||||
protocols/mix,
|
||||
protocols/mix/mix_protocol,
|
||||
protocols/mix/curve25519,
|
||||
protocols/ping,
|
||||
peerid,
|
||||
multiaddress,
|
||||
@ -24,13 +21,16 @@ import libp2p/[
|
||||
crypto/crypto,
|
||||
crypto/secp,
|
||||
]
|
||||
import libp2p_mix
|
||||
import libp2p_mix/mix_protocol
|
||||
import libp2p_mix/curve25519
|
||||
|
||||
const NumMixNodes = 10
|
||||
|
||||
proc generateLocalQuicMixNodeInfo(): MixNodeInfo =
|
||||
let
|
||||
(mixPrivKey, mixPubKey) = generateKeyPair().expect("Generate key pair error")
|
||||
keyPair = SkKeyPair.random(newRng()[])
|
||||
keyPair = SkKeyPair.random(newRng())
|
||||
pubKeyProto = PublicKey(scheme: Secp256k1, skkey: keyPair.pubkey)
|
||||
|
||||
MixNodeInfo(
|
||||
@ -52,9 +52,15 @@ proc createSwitch(
|
||||
multiAddr: MultiAddress, libp2pPrivKey: Opt[SkPrivateKey] = Opt.none(SkPrivateKey)
|
||||
): Switch =
|
||||
var rng = newRng()
|
||||
let skkey = libp2pPrivKey.valueOr(SkKeyPair.random(rng[]).seckey)
|
||||
let skkey = libp2pPrivKey.valueOr(SkKeyPair.random(rng).seckey)
|
||||
let privKey = PrivateKey(scheme: Secp256k1, skkey: skkey)
|
||||
newStandardSwitchBuilder(privKey = Opt.some(privKey), addrs = multiAddr, transport = TransportType.QUIC).build()
|
||||
SwitchBuilder
|
||||
.new()
|
||||
.withRng(rng)
|
||||
.withPrivateKey(privKey)
|
||||
.withAddress(multiAddr)
|
||||
.withQuicTransport()
|
||||
.build()
|
||||
|
||||
|
||||
proc mixPingSimulation() {.async: (raises: [Exception]).} =
|
||||
@ -109,7 +115,7 @@ proc mixPingSimulation() {.async: (raises: [Exception]).} =
|
||||
defer:
|
||||
await destNode.stop()
|
||||
|
||||
let pingProto = Ping.new()
|
||||
let pingProto = Ping.new(rng = newRng())
|
||||
destNode.mount(pingProto)
|
||||
|
||||
# Start destination switch after mounting Ping.
|
||||
|
||||
@ -13,8 +13,6 @@
|
||||
import chronicles, chronos, results
|
||||
import std/[sequtils, sugar]
|
||||
import libp2p/[
|
||||
protocols/mix,
|
||||
protocols/mix/mix_protocol,
|
||||
protocols/ping,
|
||||
peerid,
|
||||
multiaddress,
|
||||
@ -23,25 +21,37 @@ import libp2p/[
|
||||
crypto/crypto,
|
||||
crypto/secp,
|
||||
]
|
||||
import libp2p_mix
|
||||
import libp2p_mix/mix_protocol
|
||||
|
||||
const NumMixNodes = 10
|
||||
|
||||
proc createSwitch(
|
||||
multiAddr: MultiAddress, libp2pPrivKey: Opt[SkPrivateKey] = Opt.none(SkPrivateKey)
|
||||
multiAddr: MultiAddress,
|
||||
rng: Rng,
|
||||
libp2pPrivKey: Opt[SkPrivateKey] = Opt.none(SkPrivateKey),
|
||||
): Switch =
|
||||
var rng = newRng()
|
||||
let skkey = libp2pPrivKey.valueOr(SkKeyPair.random(rng[]).seckey)
|
||||
let skkey = libp2pPrivKey.valueOr(SkKeyPair.random(rng).seckey)
|
||||
let privKey = PrivateKey(scheme: Secp256k1, skkey: skkey)
|
||||
newStandardSwitchBuilder(privKey = Opt.some(privKey), addrs = multiAddr).build()
|
||||
SwitchBuilder
|
||||
.new()
|
||||
.withRng(rng)
|
||||
.withPrivateKey(privKey)
|
||||
.withAddress(multiAddr)
|
||||
.withTcpTransport()
|
||||
.withMplex()
|
||||
.withNoise()
|
||||
.build()
|
||||
|
||||
proc mixPingSimulation() {.async: (raises: [Exception]).} =
|
||||
let mixNodeInfos = MixNodeInfo.generateRandomMany(NumMixNodes)
|
||||
let rng = newRng()
|
||||
let mixNodeInfos = MixNodeInfo.generateRandomMany(NumMixNodes, rng)
|
||||
var switches: seq[Switch] = @[]
|
||||
var mixProtos: seq[MixProtocol] = @[]
|
||||
|
||||
# Start switches first so wildcard listen addresses are resolved to dialable addresses.
|
||||
for nodeInfo in mixNodeInfos:
|
||||
var switch = createSwitch(nodeInfo.multiAddr, Opt.some(nodeInfo.libp2pPrivKey))
|
||||
var switch = createSwitch(nodeInfo.multiAddr, rng, Opt.some(nodeInfo.libp2pPrivKey))
|
||||
await switch.start()
|
||||
info "Mix node switch",
|
||||
peerId = switch.peerInfo.peerId,
|
||||
@ -81,11 +91,11 @@ proc mixPingSimulation() {.async: (raises: [Exception]).} =
|
||||
mixProtos.add(proto)
|
||||
|
||||
# Create a destination node (not part of the mix network)
|
||||
let destNode = createSwitch(MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet())
|
||||
let destNode = createSwitch(MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet(), rng)
|
||||
defer:
|
||||
await destNode.stop()
|
||||
|
||||
let pingProto = Ping.new()
|
||||
let pingProto = Ping.new(rng = rng)
|
||||
destNode.mount(pingProto)
|
||||
|
||||
# Start destination switch after mounting Ping.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user