forked from miguelfreitas/twister-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path50nodes-exp
executable file
·145 lines (141 loc) · 4.11 KB
/
50nodes-exp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
NUM_NODI=$2
if [ "$1" = "start" ]; then
if [ -z $2 ]; then
echo -e "usage:\n50nodes-exp start <num_nodes>"
exit 0
fi
echo $(($2+1)) > ./.global_vars
echo "$0: creo i $NUM_NODI nodi"
for i in $(seq -f %02g 01 $NUM_NODI)
do
if [ ! -d /tmp/nodo$i ]; then
mkdir /tmp/nodo$i
fi
./twisterd -datadir=/tmp/nodo$i -port=266$i -rpcport=276$i -rpcuser=user -rpcpassword=pwd -rpcallowip=127.0.0.1 &
sleep 0.2
done
echo -n "Starting servers"
while true
do
echo -n "."
sleep 5
declare -a arrNThreads=($(top -l 1 | grep twisterd | awk '{print $5}'))
areTheyAll24=true
for nthreads in "${arrNThreads[@]}"
do
if [ $nthreads != 23 ] && [ $nthreads != 24 ] && [ $nthreads != 25 ]; then
areTheyAll24=false
break
fi
done
if [ $areTheyAll24 = true ]; then
break
fi
done
echo "Servers initialized."
elif [ "$1" = "connect" ]; then
if [ "$2" != "" ] && [ "$3" != "" ]; then
./50nodes-exp cmd $2 addnode 127.0.0.1:266$(printf %02g $3) onetry
echo "connecting $2 to $3"
exit 0
fi
NUM_NODI=$(cat ./.global_vars)
echo "$0: connetto i $NUM_NODI nodi"
for i in $(seq 1 $NUM_NODI)
do
n=$(($RANDOM%(($NUM_NODI/10)+2)))
if (( $n > 0 )); then
echo "will connect $i to $n nodes:"
for s in $(seq 1 $n)
do
r=$RANDOM
if ((($r%$NUM_NODI)+1==$i)); then
continue
fi
randomPort=$((($r%$NUM_NODI)+1))
portFrom=$(printf %02g $i)
portToConnect="266$(printf %02g $randomPort)"
./twisterd -rpcuser=user -rpcpassword=pwd -rpcallowip=127.0.0.1 -rpcport=276$portFrom addnode 127.0.0.1:$portToConnect onetry
echo "connecting $i to $((($r%$NUM_NODI)+1))"
sleep 0.7
done
fi
done
elif [ "$1" = "simul" ]; then
echo "per mettere in background: ctrl-z; bg %1"
if (($#<2)); then
echo -e "usage:\n50nodes-exp simul <node> &"
exit 0
fi
for u in 1 2 3
do
nUtente=$(date +%s | shasum5.16 --algorithm 256 | base64 | head -c 4 | tr '[:upper:]' '[:lower:]' )
echo "$2: createwalletuser utente$nUtente"
./twisterd -rpcuser=user -rpcpassword=pwd -rpcallowip=127.0.0.1 -rpcport=276$(printf %02g $2) createwalletuser utente$nUtente
./twisterd -rpcuser=user -rpcpassword=pwd -rpcallowip=127.0.0.1 -rpcport=276$(printf %02g $2) sendnewusertransaction utente$nUtente
sleep 5
for k in 1 2 3 4 5
do
echo "$2: newpostmsg utente$nUtente $k \"utente$nUtente Says Ciao$k\""
./twisterd -rpcuser=user -rpcpassword=pwd -rpcallowip=127.0.0.1 -rpcport=276$(printf %02g $2) newpostmsg utente$nUtente $k "utente$nUtente Says Ciao$k"
sleep 10
done
done
elif [ "$1" = "cmd" ]; then
if (($#<3)); then
echo -e "usage:\n50nodes-exp cmd <node> <command> [params]\ntry command help on any node"
exit 0
fi
args=($@)
params=${args[2]}
for i in $(seq 3 $#)
do
params=$params" "${args[$i]}
done
echo "sending command '$params' to port 276$(printf %02g $2)"
./twisterd -rpcuser=user -rpcpassword=pwd -rpcallowip=127.0.0.1 -rpcport=276$(printf %02g $2) $params
elif [ "$1" = "stop" ]; then
NUM_NODI=$(cat ./.global_vars)
echo "$0: distruggo i $NUM_NODI nodi"
for i in $(seq -f %02g 01 $NUM_NODI)
do
echo "./twisterd -rpcuser=user -rpcpassword=pwd -rpcallowip=127.0.0.1 -rpcport=2\
76$i stop"
./twisterd -rpcuser=user -rpcpassword=pwd -rpcallowip=127.0.0.1 -rpcport=276$i stop
done
echo -n "waiting for processes to end gracefully"
while true
do
echo -n "."
sleep 2
if [ -z "$(ps aux | grep twisterd | grep -v "ZN\|grep")" ]; then
echo -e "\nprocessi terminati."
break
fi
done
if [ "$2" != "pause" ]; then
for i in $(seq -f %02g 1 $NUM_NODI)
do
set -e #exit on error or it will delete everything
cd /tmp/nodo$i
ls | grep -v debug.log | xargs rm -rf
set +e
done
echo "file cancellati"
fi
elif [ "$1" = "sequence" ]; then
if [ "$2" == "" ]; then
echo "Usage $0 $1 <num_nodes>"
echo "Connects <num_nodes> in a ring start a miner in the last one and prompt the first so send some messages."
exit 0
fi
$0 start $2
for i in $(seq 2 $2)
do
$0 connect $(($i-1)) $i
sleep 0.1
done
$0 cmd $2 setgenerate true 1
$0 simul 1
fi