github.com/aswedchain/aswed@v1.0.1/p2p/simulations/examples/ping-pong.sh (about) 1 #!/bin/bash 2 # 3 # Boot a ping-pong network simulation using the HTTP API started by ping-pong.go 4 5 set -e 6 7 main() { 8 if ! which p2psim &>/dev/null; then 9 fail "missing p2psim binary (you need to build cmd/p2psim and put it in \$PATH)" 10 fi 11 12 info "creating 10 nodes" 13 for i in $(seq 1 10); do 14 p2psim node create --name "$(node_name $i)" 15 p2psim node start "$(node_name $i)" 16 done 17 18 info "connecting node01 to all other nodes" 19 for i in $(seq 2 10); do 20 p2psim node connect "node01" "$(node_name $i)" 21 done 22 23 info "done" 24 } 25 26 node_name() { 27 local num=$1 28 echo "node$(printf '%02d' $num)" 29 } 30 31 info() { 32 echo -e "\033[1;32m---> $(date +%H:%M:%S) ${@}\033[0m" 33 } 34 35 fail() { 36 echo -e "\033[1;31mERROR: ${@}\033[0m" >&2 37 exit 1 38 } 39 40 main "$@"