This repository has been archived by the owner on Oct 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sh
executable file
·94 lines (84 loc) · 1.85 KB
/
main.sh
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
#! /bin/bash
IDS=()
print_usage() {
echo "$0 usage:" && grep " .)\ #" $0;
exit 0;
}
finish() {
kill $(jobs -p);
rm mine_lock;
exit;
}
if [[ $UID != 0 ]]; then
echo 'Please run script with sudo (for nice):'
echo "sudo $0 $*"
exit 1
fi
trap finish SIGHUP SIGINT SIGTERM
while getopts ":hm:s:fd" flag; do
case $flag in
m) # Set miner count.
miner_count=$OPTARG ;;
s) # Set SPV client count.
spv_client_count=$OPTARG ;;
d) # Enable double spend.
double_spend=true ;;
f) # enable selfish miner
selfish=true ;;
h | *) # Display help.
print_usage ;;
esac
done
if [ $OPTIND -eq 1 ]; then
print_usage;
exit 1;
elif [ -z "$miner_count" ]; then
echo 'Please set miners';
exit 1;
elif [ -n "$double_spend" ] && [ -n "$selfish" ]; then
echo 'Cannot set double spend and selfish miner together'
exit 1;
else
echo 'Use [CTRL+C] to stop the program if you want...'
python src/trusted_server.py &
IDS+=($!)
sleep 3
if [ -n "$spv_client_count" ]; then
for i in $(seq 1 $spv_client_count)
do
python src/spv_client.py $(($i + 22345)) &
IDS+=($!)
sleep 1
done
fi
for i in $(seq 1 $miner_count)
do
if [ -n "$selfish" ]; then
python src/miner.py $(($i + 12345)) 's' &
else
python src/miner.py $(($i + 12345)) $double_spend &
fi
IDS+=($!)
sleep 1
done
if [ -n "$double_spend" ]; then
python src/double_spend.py $((33345)) 'VENDOR' &
sleep 1
sudo nice -n -5 python src/double_spend.py $((33346)) 'MINER' &
sleep 1
python src/double_spend.py $((33347)) 'SPV' &
sleep 1
elif [ -n "$selfish" ]; then
sudo nice -n -5 python src/selfish.py $((33345)) &
IDS+=($!)
sleep 1
fi
fi
sleep 5
echo 'Initialization complete, starting demo...'
echo ''
touch mine_lock
while true
do
sleep 1
done