#!/bin/sh # This file is in the public domain. # Two peers on this host learn each other's HELLO URL and have to connect: # transport, CORE (CAKE), topology and the DHT, which must forward a PUT # with a recorded path. Nothing may log a protocol violation. CA=test_core_two_peers_a.conf CB=test_core_two_peers_b.conf if ! gnunet-config --list-sections > /dev/null 2>&1 then echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX" exit 77 fi HA=$(gnunet-config -c $CA -s PATHS -o GNUNET_TEST_HOME -f) HB=$(gnunet-config -c $CB -s PATHS -o GNUNET_TEST_HOME -f) stop () { gnunet-arm -e -c $CA > /dev/null 2>&1 gnunet-arm -e -c $CB > /dev/null 2>&1 } fail () { echo "FAIL: $1" stop cat "$HA"/log/*.log "$HB"/log/*.log 2>/dev/null | grep 'WARNING\|ERROR' | tail -40 exit 1 } # A HELLO URL with a TCP and a UDP address that is the same twice in a # row: the peer identity follows the address set until the communicators # are done reporting addresses. (Every URL has a query, for its records.) stable_url () { prev="" i=0 while [ $i -lt 30 ] do url=$(timeout 5 gnunet-hello -e -c "$1" 2> /dev/null) if echo "$url" | grep -q '[?&]tcp=' && echo "$url" | grep -q '[?&]udp=' then if [ "$url" = "$prev" ] then echo "$url" return 0 fi prev=$url fi sleep 2 i=$((i + 1)) done return 1 } # Wait up to $4 seconds for statistic $3 of subsystem $2 of peer $1 to # become positive. wait_stat () { i=0 while [ $i -lt "$4" ] do v=$(gnunet-statistics -c "$1" -s "$2" -n "$3" -q 2> /dev/null | tr -d ' ') if [ -n "$v" ] && [ "$v" -gt 0 ] 2> /dev/null then return 0 fi sleep 1 i=$((i + 1)) done return 1 } rm -rf "$HA" "$HB" trap stop INT TERM gnunet-arm -s -c $CA || fail "cannot start peer A" gnunet-arm -s -c $CB || fail "cannot start peer B" UA=$(stable_url $CA) || fail "peer A has no HELLO with an address" UB=$(stable_url $CB) || fail "peer B has no HELLO with an address" echo "$UB" | timeout 10 gnunet-hello -i -c $CA > /dev/null || fail "peer A cannot import the HELLO of peer B" echo "$UA" | timeout 10 gnunet-hello -i -c $CB > /dev/null || fail "peer B cannot import the HELLO of peer A" wait_stat $CA core "# peers connected" 60 || fail "CORE of peer A did not connect" wait_stat $CB core "# peers connected" 60 || fail "CORE of peer B did not connect" wait_stat $CA dht "# peers connected" 30 || fail "DHT of peer A did not connect" wait_stat $CB dht "# peers connected" 30 || fail "DHT of peer B did not connect" wait_stat $CA dht "# P2P PUT requests received" 60 || fail "peer A received no DHT PUT" wait_stat $CB dht "# P2P PUT requests received" 60 || fail "peer B received no DHT PUT" stop if grep -l 'protocol violation' "$HA"/log/*.log "$HB"/log/*.log then fail "protocol violation logged" fi rm -rf "$HA" "$HB" exit 0