Commit 289757f9 authored by juga  's avatar juga
Browse files

Merge branch 'bug29046'

parents 878e21e3 0e8f6a15
auth?/
relay?/
exit?/
client?/
datadir/
tor/
config*.ini
*.log
#!/usr/bin/env bash
set -e
function cleanup {
kill $(jobs -p)
echo -n ''
}
trap cleanup EXIT
function list_of_nets {
find . -mindepth 2 -maxdepth 2 -type f -name '.net' |\
xargs dirname | sort -u | xargs
}
function usage {
echo "Usage: $0 <net>"
echo "Where <net> is one of: $(list_of_nets)"
}
[ "$1" == "" ] && usage && exit 1 || net="$1"
[ ! -d "$net" ] && usage && exit 1
[ ! -f "$net/.net" ] && usage && exit 1
pushd $net
./01-gen-configs.sh
./02-start-network.sh
sleep 5
num_relays=$(ls -ld {auth,relay,exit}* | wc -l)
echo "Waiting until network of $num_relays relays is ready ..."
time ./03-network-in-ready-state.py auth* relay* exit* --size $num_relays
echo 'All ready!'
#sbws -d . server > debug.server.log &
#sleep 1
sbws -d . scanner > debug.scanner.log &
run_time="45"
echo "Running for $run_time seconds ..."
sleep $run_time
sbws -d . generate --output /dev/stdout | tee generate.log
sbws -d . stats | tee stats.log
./04-stop-network.sh
ip_space="127.10.0."
socksport="2000"
controlport="2001"
orport="2002"
dirport="2003"
auth_torrc_section="auth.torrc.part"
sbws_server_host="127.0.0.1"
../simple.common/01-gen-configs.sh
\ No newline at end of file
../simple.common/02-start-network.sh
\ No newline at end of file
../simple.common/03-network-in-ready-state.py
\ No newline at end of file
../simple.common/04-stop-network.sh
\ No newline at end of file
abcdefghijklmnopqrstuvwxyz
\ No newline at end of file
ip_space="127.10.0."
socksport="2000"
controlport="2001"
orport="2002"
dirport="2003"
auth_torrc_section="auth.torrc.part"
sbws_server_host="::1"
../simple.common/01-gen-configs.sh
\ No newline at end of file
../simple.common/02-start-network.sh
\ No newline at end of file
../simple.common/03-network-in-ready-state.py
\ No newline at end of file
../simple.common/04-stop-network.sh
\ No newline at end of file
#!/usr/bin/env bash
set -e
which tor || exit 1
which tor-gencert || exit 1
source 00-common.sh
function get_fingerprint {
dir=$1
[ -f $dir/torrc ] || exit 2
tor --ignore-missing-torrc -f $dir/torrc --Address 8.8.8.8 \
--list-fingerprint | tail -n 1 | cut -d ' ' -f 2- \
| sed 's|\ ||g'
}
function get_v3ident {
dir=$1
cert=$dir/keys/authority_certificate
[ -f $cert ] || exit 2
grep fingerprint $cert | cut -d ' ' -f 2
}
next_ip="1"
scanner_tor_socks_proxy_ip=""
scanner_tor_socks_proxy_nick=""
echo -n '' > $auth_torrc_section
rm -fr auth?/ relay?/ exit?/ config*.ini datadir/ tor/ *.log
for A in auth1 auth2 auth3
do
mkdir -pv $A/keys
chmod 700 $A
ip=${ip_space}${next_ip}
[ "$scanner_tor_socks_proxy_ip" == "" ] && scanner_tor_socks_proxy_ip="$ip"
[ "$scanner_tor_socks_proxy_nick" == "" ] && scanner_tor_socks_proxy_nick="$A"
echo -n '' | tor-gencert --create-identity-key --passphrase-fd 0 -m 24 -a $ip:$dirport
echo "
DataDirectory $A
PidFile $A/tor.pid
Log notice file $A/notice.log
ShutdownWaitLength 2
ExitRelay 0
AuthoritativeDirectory 1
V3AuthoritativeDirectory 1
Address $ip
SocksPort $ip:$socksport
ControlPort $ip:$controlport
ControlSocket $(pwd)/$A/control_socket
CookieAuthentication 1
ORPort $ip:$orport
DirPort $ip:$dirport
Nickname $A
ContactInfo pastly@torproject.org
" > $A/torrc
mv -v authority_* $A/keys/
fp=$(get_fingerprint $A)
v3ident=$(get_v3ident $A)
echo "DirAuthority $A orport=$orport no-v2 v3ident=$v3ident $ip:$dirport $fp" \
>> $auth_torrc_section
next_ip=$((next_ip+1))
done
for A in relay1 relay2 relay3 relay4 relay5 relay6 relay7
do
mkdir -pv $A
chmod 700 $A
ip=${ip_space}${next_ip}
echo "
DataDirectory $A
PidFile $A/tor.pid
Log notice file $A/notice.log
ShutdownWaitLength 2
ExitRelay 0
Address $ip
SocksPort $ip:$socksport
ControlPort $ip:$controlport
ControlSocket $(pwd)/$A/control_socket
CookieAuthentication 1
ORPort $ip:$orport
DirPort $ip:$dirport
Nickname $A
ContactInfo pastly@torproject.org
" > $A/torrc
next_ip=$((next_ip+1))
done
for A in exit1 exit2 exit3
do
mkdir -pv $A
chmod 700 $A
ip=${ip_space}${next_ip}
echo "
DataDirectory $A
PidFile $A/tor.pid
Log notice file $A/notice.log
ShutdownWaitLength 2
ExitRelay 1
IPv6Exit 1
ExitPolicy accept *:*
ExitPolicy reject *:*
Address $ip
SocksPort $ip:$socksport
ControlPort $ip:$controlport
ControlSocket $(pwd)/$A/control_socket
CookieAuthentication 1
ORPort $ip:$orport
DirPort $ip:$dirport
Nickname $A
ContactInfo pastly@torproject.org
" > $A/torrc
next_ip=$((next_ip+1))
done
for torrc in ./auth*/torrc
do
echo "
TestingV3AuthInitialVotingInterval 5
V3AuthVotingInterval 10
TestingV3AuthInitialVoteDelay 2
V3AuthVoteDelay 2
TestingV3AuthInitialDistDelay 2
V3AuthDistDelay 2
" >> $torrc
done
for torrc in ./{auth,relay,exit}*/torrc
do
cat $auth_torrc_section >> $torrc
echo "
TestingTorNetwork 1
NumCPUs 1
LogTimeGranularity 1
SafeLogging 0
" >> $torrc
done
# Get a random port between 2000 and 62000 while handling the fact that $RANDOM
# doesn't go up that high
sbws_server_port=$(( ((RANDOM<<15)|RANDOM) % 60000 + 2000 ))
echo "
[paths]
sbws_home = $(pwd)
[tor]
extra_lines =
TestingTorNetwork 1
NumCPUs 1
LogTimeGranularity 1
SafeLogging 0
$(cat $auth_torrc_section | while read LINE; do printf " $LINE\n"; done)
[scanner]
nickname = SbwsTestnetScanner
measurement_threads = 4
download_toofast = 0.1
download_min = 1
download_target = 2
download_max = 5
num_rtts = 5
num_downloads = 3
[destinations]
debian_cd_mirror_will_break = on
[destinations.debian_cd_mirror_will_break]
url = https://saimei.ftp.acc.umu.se/debian-cd/9.4.0/amd64/iso-dvd/debian-9.4.0-amd64-DVD-1.iso
#url = https://cdimage.debian.org/debian-cd/9.4.0/amd64/iso-dvd/debian-9.4.0-amd64-DVD-1.iso
" > config.ini
touch config.log.ini
rm $auth_torrc_section
#!/usr/bin/env bash
set -e
function cleanup {
#kill -INT $(cat {auth,relay,exit}*/tor.pid)
#kill -INT $(jobs -p)
echo -n ''
}
trap cleanup EXIT
for A in {auth,relay,exit}*
do
tor -f $A/torrc --quiet &
done
#!/usr/bin/env python3
from argparse import RawTextHelpFormatter, ArgumentParser
from stem.control import Controller
import time
import os
import logging
logger = logging.getLogger(__name__)
def get_controller(sock_fname):
cont = Controller.from_socket_file(path=sock_fname)
cont.authenticate()
return cont
def get_is_bootstrapped(cont, timeout=60):
start_time = time.time()
while start_time + timeout > time.time():
line = cont.get_info('status/bootstrap-phase')
state, _, progress, *_ = line.split()
progress = int(progress.split('=')[1])
if state == 'NOTICE' and progress == 100:
logger.debug('Tor is bootstrapped')
return True
time.sleep(1)
logger.debug('Tor didn\'t bootstrap before timeout. Last line: %s', line)
return False
def get_has_full_consensus(cont, network_size, timeout=60):
start_time = time.time()
while start_time + timeout > time.time():
relays = [r for r in cont.get_network_statuses()]
if len(relays) == network_size:
logger.debug('Tor has correct network size %d',
network_size)
return True
elif len(relays) > network_size:
logger.warning('Tor has more relays than expected. %d vs %d',
len(relays), network_size)
return True
time.sleep(1)
logger.debug('Tor didn\'t reach expected network size %d before '
'timeout', network_size)
return False
def is_tor_ready(sock_fname, network_size):
with get_controller(sock_fname) as cont:
if not get_is_bootstrapped(cont):
logger.warning('%s not bootstrapped, Tor not ready', sock_fname)
return False
if not get_has_full_consensus(cont, network_size):
logger.warning('%s doesn\'t have full consensus, Tor not ready',
sock_fname)
return False
logger.info('%s is ready', sock_fname)
return True
def main(args):
for datadir in args.datadir:
logger.info('Checking if %s is ready', datadir)
sock_fname = os.path.join(datadir, 'control_socket')
assert os.path.exists(sock_fname)
if not is_tor_ready(sock_fname, network_size=args.size):
return 1
# If we got to this point, it seems like every relay is completely ready.
# Do one more check to make sure that's still the case.
for datadir in args.datadir:
logger.info('Verifying %s is still ready', datadir)
sock_fname = os.path.join(datadir, 'control_socket')
assert os.path.exists(sock_fname)
if not is_tor_ready(sock_fname, network_size=args.size):
return 1
return 0
if __name__ == '__main__':
desc = '''
Given the data directories for a local tor network, connect to the control
socket in each directory and verify that the tor on the other end of the socket
is fully bootstrapped and has the right size of consensus.
The "right size of consensus" is determined based on the number of data
directories given to check. If that is not okay to assume (for example, there
are some Tor client [non-relay] data directories given to check), then specify
the size manually with --size.
Waits up to 60 seconds for each check for each tor.
- In the worst case, this script will take a long time to run (if every tor
suddenly passes each check after 59 seconds).
- In the normal failure case, this script will take about 60 seconds to run
(the first tor is not ready and fails its checks).
- In the normal case, it will run very quickly (every tor is bootstrapped and
ready).
Exits with 0 if everything is good. Otherwise exits with a postive integer.
'''
parser = ArgumentParser(
formatter_class=RawTextHelpFormatter, description=desc)
parser.add_argument('-s', '--size', type=int, help='If given, don\'t '
'assume the network size based on the number of '
'datadirs, but use this size instead.')
parser.add_argument('-d', '--debug', action='store_true')
parser.add_argument('datadir', nargs='+', type=str)
args = parser.parse_args()
if args.debug:
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.WARNING)
ch = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
if not args.size:
args.size = len(args.datadir)
try:
exit(main(args))
except KeyboardInterrupt:
pass
#!/usr/bin/env bash
kill -INT $(cat {auth,relay,exit}*/tor.pid)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment