5
0
mirror of https://github.com/cwinfo/yggdrasil-map synced 2024-11-22 17:30:26 +00:00
yggdrasil-map/mapper/start-mappers.sh

57 lines
1.6 KiB
Bash
Raw Normal View History

2014-03-29 23:51:57 +00:00
#!/bin/bash
2014-03-30 11:34:08 +00:00
source conf_sh.py
2014-03-29 23:51:57 +00:00
mkdir -p mapper-confs
2014-05-13 14:03:14 +00:00
# Generate configurations and collect their publick keys and ports
for i in $(seq 1 $num_of_nodes)
do
file=mapper-confs/node$i.conf
$cjdns_path/cjdroute --genconf > $file
# Get connecting info
publicKey=$(grep -oP -m1 '(?<="publicKey": ").*(?=",)' $file)
connectPort=$(grep -oP -m1 '(?<="0.0.0.0:).*(?=",)' $file)
connectToInfo[i]='"127.0.0.1:'"$connectPort"'":{"password":"'"$rpc_pw"'","publicKey":"'"$publicKey"'"},'
done
# Modify configurations
2014-03-29 23:51:57 +00:00
for i in $(seq 1 $num_of_nodes)
do
echo "Starting mapper node $i/$num_of_nodes"
file=mapper-confs/node$i.conf
rpcport=$(($rpc_firstport + $i - 1))
2014-05-13 14:03:14 +00:00
# Connect to all mapper nodes except itself
connectInfo=""
for j in $(seq 1 $num_of_nodes)
do
if [[ $i != $j ]]; then
connectInfo+="${connectToInfo[j]}"
fi
done
2014-03-29 23:51:57 +00:00
# Set peer credentials
2014-05-13 14:03:14 +00:00
sed -i 's/\/\/ Add connection credentials here to join the network/'"$connectInfo"'/g' $file
sed -i 's/\/\/ Ask somebody who is already connected./"'"${peer_ip}"':'"${peer_port}"'":{"password":"'"${peer_pw}"'","publicKey":"'"${peer_pk}"'"}/g' $file
2014-03-29 23:51:57 +00:00
# Set admin rpc credentials
sed -i 's/127.0.0.1:11234/'"${rpc_bind}"':'"${rpcport}"'/g' $file
sed -i 's/"password": ".*"/"password": "'"${rpc_pw}"'"/g' $file
# Disable tun interface
sed -i 's/"type": "TUNInterface"/\/\/"type": "TUNInterface"/g' $file
2014-05-13 14:03:14 +00:00
# Start mappers
if [[ $* == *-d* ]]; then
2014-04-03 18:09:38 +00:00
# Log to stdout
sed -i 's/\/\/ "logTo":"stdout"/"logTo":"stdout"/g' $file
gdb $cjdns_path/cjdroute -ex 'set follow-fork-mode child' -ex 'run < '"${file}" -ex 'thread apply all bt' -ex 'quit' > gdb-$i.log 2>&1 &
else
$cjdns_path/cjdroute < $file
fi
2014-03-29 23:51:57 +00:00
done