-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Nim ping test * Working interop * Add nim toml * Add CI * fix workflow name * Delete go-rust specifics * Update .github/workflows/ping-interop-latest.yml Co-authored-by: Max Inden <mail@max-inden.de> Co-authored-by: Max Inden <mail@max-inden.de>
- Loading branch information
Showing
9 changed files
with
236 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[custom] | ||
NimVersion = "1.6.8" | ||
|
||
[[groups]] | ||
Id = "1.0.0" | ||
NimVersion = "1.6.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ARG NimVersion="latest" | ||
FROM nimlang/nim:${NimVersion}-alpine as builder | ||
|
||
RUN nimble install -y "https://github.com/status-im/testground-nim-sdk@#c282ff68c08ef85a7ca011e077e3e69eb1a6edec" | ||
|
||
ARG Libp2pVersion="#unstable" | ||
RUN nimble install -y "libp2p@${Libp2pVersion}" | ||
FROM builder | ||
|
||
ARG PLAN_PATH="./" | ||
COPY ./plan/${PLAN_PATH} ./plan | ||
RUN cd plan && nimble install -dy && nim c -d:chronicles_log_level=NOTICE main.nim | ||
|
||
ENTRYPOINT ["plan/main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Package | ||
|
||
version = "0.1.0" | ||
author = "The author" | ||
description = "Demo for another package" | ||
license = "MIT" | ||
|
||
|
||
# Dependencies | ||
|
||
requires "nim >= 1.2.2", | ||
"https://github.com/status-im/testground-nim-sdk", | ||
"libp2p == 1.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import serialization, json_serialization | ||
import libp2p, testground_sdk, libp2p/protocols/ping | ||
import chronos | ||
import sequtils | ||
|
||
type | ||
PeerData = object | ||
id {.serializedFieldName: "ID".}: string | ||
addrs {.serializedFieldName: "Addrs".}: seq[string] | ||
|
||
testground(client): | ||
let addresses = getInterfaces().filterIt(it.name == "eth1").mapIt(it.addresses) | ||
if addresses.len < 1 or addresses[0].len < 1: | ||
quit "Can't find local ip!" | ||
|
||
discard await client.signal("initialized_global") | ||
|
||
let | ||
maxLatency = client.param(int, "max_latency_ms") | ||
rng = libp2p.newRng() | ||
address = addresses[0][0].host | ||
switch = | ||
SwitchBuilder | ||
.new() | ||
.withAddress(MultiAddress.init(address).tryGet()) | ||
.withRng(rng) | ||
.withYamux() | ||
.withTcpTransport() | ||
.withNoise() | ||
.build() | ||
pingProtocol = Ping.new(rng = rng) | ||
|
||
switch.mount(pingProtocol) | ||
await switch.start() | ||
defer: await switch.stop() | ||
|
||
let peersTopic = client.subscribe("peers", PeerData) | ||
await client.publish("peers", | ||
PeerData( | ||
id: $switch.peerInfo.peerId, | ||
addrs: switch.peerInfo.addrs.mapIt($it) | ||
) | ||
) | ||
echo "Listening on ", switch.peerInfo.addrs | ||
|
||
var peersInfo: seq[PeerData] | ||
while peersInfo.len < client.testInstanceCount: | ||
peersInfo.add(await peersTopic.popFirst()) | ||
|
||
for peerInfo in peersInfo: | ||
if peerInfo.id == $switch.peerInfo.peerId: break | ||
let | ||
peerId = PeerId.init(peerInfo.id).tryGet() | ||
addrs = peerInfo.addrs.mapIt(MultiAddress.init(it).tryGet()) | ||
await switch.connect(peerId, addrs) | ||
|
||
discard await client.signalAndWait("connected", client.testInstanceCount) | ||
|
||
proc pingPeer(peer: PeerData, tag: string) {.async.} = | ||
if peer.id == $switch.peerInfo.peerId: return | ||
let | ||
stream = await switch.dial(PeerId.init(peer.id).tryGet(), PingCodec) | ||
rtt = await pingProtocol.ping(stream) | ||
await stream.close() | ||
client.recordMessage("ping result (" & tag & ") from peer " & peer.id & ": " & $rtt) | ||
|
||
var futs: seq[Future[void]] | ||
for peer in peersInfo: futs.add(pingPeer(peer, "initial")) | ||
await allFutures(futs) | ||
|
||
discard await client.signalAndWait("initial", client.testInstanceCount) | ||
|
||
for iter in 1 .. client.param(int, "iterations"): | ||
let | ||
latency = milliseconds(rng.rand(maxLatency)) | ||
callbackState = "network-configured-" & $iter | ||
client.recordMessage("Iteration " & $iter & ", my latency: " & $latency) | ||
await client.updateNetworkParameter( | ||
NetworkConf( | ||
enable: true, | ||
network: "default", | ||
callback_state: callbackState, | ||
callback_target: some client.testInstanceCount, | ||
routing_policy: "accept_all", | ||
default: LinkShape(latency: int(latency.nanoseconds)) | ||
) | ||
) | ||
await client.waitForBarrier(callbackState, client.testInstanceCount) | ||
|
||
for peer in peersInfo: futs.add(pingPeer(peer, "iteration-" & $iter)) | ||
await allFutures(futs) | ||
|
||
discard await client.signalAndWait("done-" & $iter, client.testInstanceCount) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name = "compatibility-nim" | ||
|
||
[defaults] | ||
builder = "docker:generic" | ||
runner = "local:docker" | ||
|
||
[builders."docker:generic"] | ||
enabled = true | ||
|
||
[runners."local:docker"] | ||
enabled = true | ||
|
||
[[testcases]] | ||
name = "ping" | ||
instances = { min = 2, max = 10000, default = 5 } | ||
|
||
[testcases.params] | ||
max_latency_ms = { type = "int", desc = "maximum value for random local link latency", unit = "ms", default = 1000 } | ||
iterations = { type = "int", desc = "number of ping iterations we'll run against each peer", unit = "count", default = 5 } |