aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/simulations/examples/ping-pong.sh
diff options
context:
space:
mode:
authorLewis Marshall <lewis@lmars.net>2017-09-25 16:08:07 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-09-25 16:08:07 +0800
commit9feec51e2dd754819e5c730ac5985d28d57adb48 (patch)
tree32b07b659cf7d0b4c1a7da67b5c49daf7a10a9d3 /p2p/simulations/examples/ping-pong.sh
parent673007d7aed1d2678ea3277eceb7b55dc29cf092 (diff)
downloadgo-tangerine-9feec51e2dd754819e5c730ac5985d28d57adb48.tar
go-tangerine-9feec51e2dd754819e5c730ac5985d28d57adb48.tar.gz
go-tangerine-9feec51e2dd754819e5c730ac5985d28d57adb48.tar.bz2
go-tangerine-9feec51e2dd754819e5c730ac5985d28d57adb48.tar.lz
go-tangerine-9feec51e2dd754819e5c730ac5985d28d57adb48.tar.xz
go-tangerine-9feec51e2dd754819e5c730ac5985d28d57adb48.tar.zst
go-tangerine-9feec51e2dd754819e5c730ac5985d28d57adb48.zip
p2p: add network simulation framework (#14982)
This commit introduces a network simulation framework which can be used to run simulated networks of devp2p nodes. The intention is to use this for testing protocols, performing benchmarks and visualising emergent network behaviour.
Diffstat (limited to 'p2p/simulations/examples/ping-pong.sh')
-rwxr-xr-xp2p/simulations/examples/ping-pong.sh40
1 files changed, 40 insertions, 0 deletions
diff --git a/p2p/simulations/examples/ping-pong.sh b/p2p/simulations/examples/ping-pong.sh
new file mode 100755
index 000000000..47936bd9a
--- /dev/null
+++ b/p2p/simulations/examples/ping-pong.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+#
+# Boot a ping-pong network simulation using the HTTP API started by ping-pong.go
+
+set -e
+
+main() {
+ if ! which p2psim &>/dev/null; then
+ fail "missing p2psim binary (you need to build cmd/p2psim and put it in \$PATH)"
+ fi
+
+ info "creating 10 nodes"
+ for i in $(seq 1 10); do
+ p2psim node create --name "$(node_name $i)"
+ p2psim node start "$(node_name $i)"
+ done
+
+ info "connecting node01 to all other nodes"
+ for i in $(seq 2 10); do
+ p2psim node connect "node01" "$(node_name $i)"
+ done
+
+ info "done"
+}
+
+node_name() {
+ local num=$1
+ echo "node$(printf '%02d' $num)"
+}
+
+info() {
+ echo -e "\033[1;32m---> $(date +%H:%M:%S) ${@}\033[0m"
+}
+
+fail() {
+ echo -e "\033[1;31mERROR: ${@}\033[0m" >&2
+ exit 1
+}
+
+main "$@"