remove 'illegal' (non-reentrant) log logic from signal handler
[oweals/gnunet.git] / src / gns / test_gns_multiple_record_lookup.sh
1 #!/bin/bash
2 # This file is in the public domain.
3 trap "gnunet-arm -e -c test_gns_lookup_peer1.conf" INT
4 trap "gnunet-arm -e -c test_gns_lookup_peer2.conf" INT
5 which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 5"
6
7 unset XDG_DATA_HOME
8 unset XDG_CONFIG_HOME
9 unset XDG_CACHE_HOME
10
11 LOCATION=$(which gnunet-config)
12 if [ -z $LOCATION ]
13 then
14   LOCATION="gnunet-config"
15 fi
16 $LOCATION --version 1> /dev/null
17 if test $? != 0
18 then
19         echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
20         exit 77
21 fi
22
23 rm -rf `gnunet-config -c test_gns_lookup_peer1.conf -f -s paths -o GNUNET_TEST_HOME`
24 rm -rf `gnunet-config -c test_gns_lookup_peer2.conf -f -s paths -o GNUNET_TEST_HOME`
25 MY_EGO="localego"
26 OTHER_EGO="remoteego"
27
28 TEST_IP="127.0.0.1"
29 TEST_IPV6="dead::beef"
30 LABEL="fnord"
31
32 gnunet-arm -s -c test_gns_lookup_peer2.conf
33 PKEY=`$DO_TIMEOUT gnunet-identity -V -C $OTHER_EGO -c test_gns_lookup_peer2.conf`
34
35 # Note: if zonemaster is kept running, it MAY publish the "A" record in the
36 # DHT immediately and then _LATER_ also the "AAAA" record. But as then there
37 # will be TWO valid blocks in the DHT (one with only A and one with A and
38 # AAAA), the subsequent GET for both may fail and only return the result with
39 # just the "A" record).
40 # If we _waited_ until the original block with just "A" expired, everything
41 # would be fine, but we don't want to do that for the test, so we
42 # simply pause publishing to the DHT until all records are defined.
43 # In the future, it would be good to have an enhanced gnunet-namestore command
44 # that would read a series of changes to be made to a record set from
45 # stdin and do them _all_ *atomically*. Then we would not need to do this.
46
47 gnunet-arm -c test_gns_lookup_peer2.conf -k zonemaster
48 gnunet-arm -c test_gns_lookup_peer2.conf -k zonemaster-monitor
49
50 gnunet-namestore -p -z $OTHER_EGO -a -n $LABEL -t A -V $TEST_IP -e 3600s -c test_gns_lookup_peer2.conf
51 gnunet-namestore -p -z $OTHER_EGO -a -n $LABEL -t AAAA -V $TEST_IPV6 -e 3600s -c test_gns_lookup_peer2.conf
52 gnunet-namestore -D -z $OTHER_EGO -n $LABEL
53
54 gnunet-arm -c test_gns_lookup_peer2.conf -i zonemaster
55 gnunet-arm -c test_gns_lookup_peer2.conf -i zonemaster-monitor
56
57
58 gnunet-arm -s -c test_gns_lookup_peer1.conf
59
60
61 RESP=`$DO_TIMEOUT gnunet-gns --raw -u $LABEL.$PKEY -t ANY -c test_gns_lookup_peer1.conf`
62 RESP1=`$DO_TIMEOUT gnunet-gns --raw -u $LABEL.$PKEY -t A -c test_gns_lookup_peer1.conf`
63 RESP2=`$DO_TIMEOUT gnunet-gns --raw -u $LABEL.$PKEY -t AAAA -c test_gns_lookup_peer1.conf`
64
65
66 gnunet-arm -e -c test_gns_lookup_peer1.conf
67 gnunet-arm -e -c test_gns_lookup_peer2.conf
68
69 rm -rf `gnunet-config -c test_gns_lookup_peer1.conf -f -s paths -o GNUNET_TEST_HOME`
70 rm -rf `gnunet-config -c test_gns_lookup_peer2.conf -f -s paths -o GNUNET_TEST_HOME`
71
72 RESPONSES=($(echo $RESP | tr "\n" " " ))
73
74 if [ "$RESP1" == "$TEST_IP" ]
75 then
76   echo "PASS: A record resolution from DHT via separate peer"
77 else
78   echo "FAIL: A record resolution from DHT via separate peer, got $RESP1, expected $TEST_IP"
79   exit 1
80 fi
81 if [ "$RESP2" == "$TEST_IPV6" ]
82 then
83   echo "PASS: AAAA record resolution from DHT via separate peer"
84 else
85   echo "FAIL: AAAA record resolution from DHT via separate peer, got $RESP2, expected $TEST_IPV6"
86   exit 1
87 fi
88 if [[ "${RESPONSES[0]} ${RESPONSES[1]}" == "$TEST_IPV6 $TEST_IP" ]] || [[ "${RESPONSES[0]} ${RESPONSES[1]}" == "$TEST_IP $TEST_IPV6" ]]
89 then
90   echo "PASS: ANY record resolution from DHT via separate peer"
91 else
92   echo "FAIL: ANY record resolution from DHT via separate peer, got $RESP, expected $TEST_IPV6 $TEST_IP or $TEST_IP $TEST_IPV6"
93   exit 1
94 fi