|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Kill any running Go processes |
| 4 | +ps aux | grep go | grep -v grep | awk '{print $2}' | xargs kill -9 |
| 5 | + |
| 6 | +# Remove previous files and create output directory |
| 7 | +rm -f DispersalNode.txt |
| 8 | +rm -f bootstrap_addrs.txt |
| 9 | +rm -rf output |
| 10 | +mkdir output |
| 11 | + |
| 12 | +# Configuration |
| 13 | +NUM_NODES=21 |
| 14 | +PORT_BASE=4007 |
| 15 | +BOOTSTRAP_PORT_BASE=4001 |
| 16 | +BOOTSTRAP_NODES=3 |
| 17 | +BOOTSTRAP_READY_TIMEOUT=30 |
| 18 | +IP_BASE="127.0.0." |
| 19 | +CODING_METHOD="RS" |
| 20 | +MODE="download" |
| 21 | + |
| 22 | +# Function to set up IP aliases |
| 23 | +setup_ip_aliases() { |
| 24 | + for i in $(seq 1 $((BOOTSTRAP_NODES + NUM_NODES + 1))); do |
| 25 | + ip_suffix=$((i + 1)) |
| 26 | + ip="${IP_BASE}${ip_suffix}" |
| 27 | + if ! ip addr show lo | grep -q "$ip"; then |
| 28 | + sudo ip addr add $ip dev lo |
| 29 | + echo "Aliased $ip to loopback interface." |
| 30 | + else |
| 31 | + echo "$ip is already aliased to loopback interface." |
| 32 | + fi |
| 33 | + done |
| 34 | + sudo ip link set dev lo up |
| 35 | +} |
| 36 | + |
| 37 | +# Function to check if a bootstrap node is ready |
| 38 | +check_bootstrap_ready() { |
| 39 | + local ip=$1 |
| 40 | + local port=$2 |
| 41 | + for i in $(seq 1 $BOOTSTRAP_READY_TIMEOUT); do |
| 42 | + nc -z $ip $port && return 0 |
| 43 | + sleep 1 |
| 44 | + done |
| 45 | + return 1 |
| 46 | +} |
| 47 | + |
| 48 | +# Set up IP aliases |
| 49 | +setup_ip_aliases |
| 50 | + |
| 51 | +# Start tmux session |
| 52 | +tmux new-session -d -s mynodes -n "BootstrapNode0" |
| 53 | + |
| 54 | +# Start the bootstrap nodes first |
| 55 | +for i in $(seq 0 $((BOOTSTRAP_NODES - 1))) |
| 56 | +do |
| 57 | + ip_suffix=$((i + 1)) |
| 58 | + ip="${IP_BASE}${ip_suffix}" |
| 59 | + if [ $i -eq 0 ]; then |
| 60 | + tmux send-keys "go run ./cmd/main.go -node=BootstrapNode$i -port=$((BOOTSTRAP_PORT_BASE + i)) -bootstrap=true -ip=$ip -mode=$MODE -coding=$CODING_METHOD" C-m |
| 61 | + else |
| 62 | + tmux new-window -t mynodes: -n "BootstrapNode$i" "go run ./cmd/main.go -node=BootstrapNode$i -port=$((BOOTSTRAP_PORT_BASE + i)) -bootstrap=true -ip=$ip -mode=$MODE -coding=$CODING_METHOD; read" |
| 63 | + fi |
| 64 | +done |
| 65 | + |
| 66 | +# Wait for all bootstrap nodes to be ready |
| 67 | +for i in $(seq 0 $((BOOTSTRAP_NODES - 1))) |
| 68 | +do |
| 69 | + ip_suffix=$((i + 1)) |
| 70 | + ip="${IP_BASE}${ip_suffix}" |
| 71 | + port=$((BOOTSTRAP_PORT_BASE + i)) |
| 72 | + echo "Waiting for BootstrapNode$i on IP $ip and port $port to be ready..." |
| 73 | + if ! check_bootstrap_ready $ip $port; then |
| 74 | + echo "BootstrapNode$i on IP $ip and port $port did not become ready in time. Exiting..." |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + echo "BootstrapNode$i on IP $ip and port $port is ready." |
| 78 | +done |
| 79 | + |
| 80 | +echo "All bootstrap nodes are ready. Starting regular nodes in 10 seconds..." |
| 81 | +sleep 10 |
| 82 | + |
| 83 | +# Start Node 1 in the current tmux window |
| 84 | +tmux new-window -t mynodes: -n "Node1" |
| 85 | +tmux send-keys -t mynodes:Node1 "go run ./cmd/main.go -node=Node1 -port=4006 -ip=${IP_BASE}7 -mode=$MODE -coding=$CODING_METHOD" C-m |
| 86 | + |
| 87 | +# Start the rest of the regular nodes in tmux windows |
| 88 | +for i in $(seq 2 $((NUM_NODES + 1))) |
| 89 | +do |
| 90 | + ip_suffix=$((i + 6)) |
| 91 | + ip="${IP_BASE}${ip_suffix}" |
| 92 | + tmux new-window -t mynodes: -n "Node$i" "go run ./cmd/main.go -node=Node$i -port=$((PORT_BASE + i - 2)) -ip=$ip -mode=$MODE -coding=$CODING_METHOD; read" |
| 93 | + sleep 2 |
| 94 | + echo "Node$i started on port $((PORT_BASE + i - 2)) with IP $ip -coding=$CODING_METHOD" |
| 95 | +done |
| 96 | + |
| 97 | +echo "$NUM_NODES nodes started in separate tmux windows. Use 'tmux attach -t mynodes' to view them." |
0 commit comments