2021-01-03 22:42:06 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# https://web.archive.org/web/20200413111226/http://redsymbol.net/articles/unofficial-bash-strict-mode/
|
|
|
|
set -uo pipefail
|
|
|
|
IFS=$'\n\t'
|
|
|
|
|
|
|
|
# Starts a given amount of routers and waits for them to dump their router information in the netdb
|
|
|
|
# Once that's done, they should all know of each other
|
|
|
|
# TODO: Make sure they can connect to each other
|
|
|
|
|
|
|
|
|
|
|
|
# First param is the number of routers (default is 2)
|
|
|
|
routerCount=${1:-2}
|
|
|
|
|
|
|
|
WAIT_TIME=60
|
2021-01-05 19:36:39 +01:00
|
|
|
FLOODFILL_COUNT=2
|
2021-01-03 22:42:06 +01:00
|
|
|
|
|
|
|
_log(){
|
|
|
|
echo "====$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
_execAll(){
|
2021-01-05 19:36:39 +01:00
|
|
|
service=$1 ; shift
|
|
|
|
serviceCount=$1 ; shift
|
|
|
|
for i in $(seq 1 ${serviceCount})
|
2021-01-03 22:42:06 +01:00
|
|
|
do
|
2021-01-05 19:36:39 +01:00
|
|
|
_log "==$service $i"
|
|
|
|
docker-compose exec --index $i $service "$@"
|
2021-01-03 22:42:06 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
_log "Clean everything"
|
2021-01-04 23:55:19 +01:00
|
|
|
docker-compose down -v --remove-orphans
|
2021-01-03 22:42:06 +01:00
|
|
|
|
2021-01-05 19:36:39 +01:00
|
|
|
_log "Start up ${routerCount} router(s) and ${FLOODFILL_COUNT} floodfills"
|
|
|
|
docker-compose up -d --scale i2pd=${routerCount} --scale=i2pd-floodfill=${FLOODFILL_COUNT}
|
2021-01-03 22:42:06 +01:00
|
|
|
|
2021-01-05 19:36:39 +01:00
|
|
|
totalRouterCount=$(( $routerCount + $FLOODFILL_COUNT ))
|
2021-01-03 22:42:06 +01:00
|
|
|
riCount=0
|
2021-01-05 19:36:39 +01:00
|
|
|
while [ $riCount != $totalRouterCount ]; do
|
2021-01-03 22:42:06 +01:00
|
|
|
_log "Waiting ${WAIT_TIME} seconds out of courtesy"
|
|
|
|
sleep ${WAIT_TIME}s
|
|
|
|
|
|
|
|
_log "Gracefully shut them down to store their routerInfo (RI) in the netDb"
|
2021-01-05 19:36:39 +01:00
|
|
|
_execAll i2pd-floodfill ${FLOODFILL_COUNT} i2prouter stop
|
|
|
|
_execAll i2pd ${routerCount} i2prouter stop
|
2021-01-03 22:42:06 +01:00
|
|
|
|
|
|
|
_log "Starting all routers back up"
|
|
|
|
sleep 5s
|
2021-01-05 19:36:39 +01:00
|
|
|
docker-compose start i2pd-floodfill
|
2021-01-04 23:55:19 +01:00
|
|
|
docker-compose start i2pd
|
2021-01-03 22:42:06 +01:00
|
|
|
|
2021-01-05 19:36:39 +01:00
|
|
|
_log "Contents of netDb (expecting ${totalRouterCount} entries)"
|
2021-01-04 23:55:19 +01:00
|
|
|
netDbOutput="$(docker-compose exec i2pd find netDb -name '*.dat')"
|
2021-01-04 01:05:55 +01:00
|
|
|
riCount=$(echo "${netDbOutput[@]}" | grep routerInfo | wc -l)
|
2021-01-03 22:42:06 +01:00
|
|
|
_log "Found $riCount entries:"
|
2021-01-04 01:05:55 +01:00
|
|
|
echo "${netDbOutput[@]}"
|
2021-01-03 22:42:06 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
echo "Done! You have a complete netDb"
|