aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2016-10-06 19:25:05 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2016-10-06 19:25:05 +0000
commit892ea474164020cbc2efd4fbd2b00fd00ae54e1a (patch)
tree5800dabb5d38e133be5b0bc9b8cd1991e95471c1 /src/gns
parente43731d9df9fb2ffd8720af47ed5249f87cca3fd (diff)
downloadgnunet-892ea474164020cbc2efd4fbd2b00fd00ae54e1a.tar.gz
gnunet-892ea474164020cbc2efd4fbd2b00fd00ae54e1a.zip
-add tests
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/gnunet-service-gns_reverser.c204
-rwxr-xr-xsrc/gns/test_gns_reverse_lookup.sh45
2 files changed, 248 insertions, 1 deletions
diff --git a/src/gns/gnunet-service-gns_reverser.c b/src/gns/gnunet-service-gns_reverser.c
index 6bae20b61..2e66e7fa6 100644
--- a/src/gns/gnunet-service-gns_reverser.c
+++ b/src/gns/gnunet-service-gns_reverser.c
@@ -29,6 +29,54 @@
29#include "gnunet-service-gns_resolver.h" 29#include "gnunet-service-gns_resolver.h"
30#include "gnunet-service-gns_reverser.h" 30#include "gnunet-service-gns_reverser.h"
31 31
32struct ReverseRecordEntry
33{
34 /**
35 * DLL
36 */
37 struct ReverseRecordEntry *next;
38
39 /**
40 * DLL
41 */
42 struct ReverseRecordEntry *prev;
43
44 /**
45 * ReverseRecord
46 */
47 struct GNUNET_GNSRECORD_ReverseRecord *record;
48
49};
50
51struct IteratorHandle
52{
53 /**
54 * Records found
55 */
56 struct ReverseRecordEntry *records_head;
57
58 /**
59 * Records found
60 */
61 struct ReverseRecordEntry *records_tail;
62
63 /**
64 * Current delegation to expect
65 */
66 struct GNUNET_CRYPTO_EcdsaPublicKey target;
67
68 /**
69 * The zone target for reverse record resolution
70 */
71 struct GNUNET_CRYPTO_EcdsaPublicKey myzone;
72
73 /**
74 * The nick of our zone
75 */
76 char *mynick;
77
78};
79
32struct ReverseTreeNode 80struct ReverseTreeNode
33{ 81{
34 /** 82 /**
@@ -70,7 +118,7 @@ struct GNS_ReverserHandle
70 * The authority to look for 118 * The authority to look for
71 */ 119 */
72 struct GNUNET_CRYPTO_EcdsaPublicKey authority; 120 struct GNUNET_CRYPTO_EcdsaPublicKey authority;
73 121
74 /** 122 /**
75 * Resolution candidate queue 123 * Resolution candidate queue
76 */ 124 */
@@ -97,6 +145,26 @@ struct GNS_ReverserHandle
97 void *proc_cls; 145 void *proc_cls;
98}; 146};
99 147
148/**
149 * Reverse record collection task
150 */
151static struct GNUNET_SCHEDULER_Task *reverse_record_check_task;
152
153/**
154 * GNS lookup handle
155 */
156static struct GNS_ResolverHandle *gns_lookup_reverse;
157
158/**
159 * NS handle
160 */
161static struct GNUNET_NAMESTORE_Handle *ns;
162
163/**
164 * NS Iterator
165 */
166static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
167
100void 168void
101cleanup_handle (struct GNS_ReverserHandle *rh) 169cleanup_handle (struct GNS_ReverserHandle *rh)
102{ 170{
@@ -241,4 +309,138 @@ GNS_reverse_lookup_cancel (struct GNS_ReverserHandle *rh)
241 return; 309 return;
242} 310}
243 311
312void
313next_it (void *cls);
314
315void
316handle_gns_result_iter (void *cls,
317 uint32_t rd_count,
318 const struct GNUNET_GNSRECORD_Data *rd)
319{
320 struct IteratorHandle *ith = cls;
321 struct ReverseRecordEntry *rr;
322 if ((rd_count != 1) ||
323 (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type))
324 {
325 gns_lookup_reverse = NULL;
326 GNUNET_SCHEDULER_add_now (&next_it, NULL);
327 return;
328 }
329
330
331 rr = GNUNET_new (struct ReverseRecordEntry);
332 rr->record = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_ReverseRecord)
333 + strlen (ith->mynick) + 1);
334 rr->record->pkey = ith->target;
335 rr->record->expiration.abs_value_us = rd->expiration_time;
336 GNUNET_memcpy ((char*)&rr->record[1],
337 ith->mynick,
338 strlen (ith->mynick));
339 GNUNET_CONTAINER_DLL_insert (ith->records_head,
340 ith->records_tail,
341 rr);
342 GNUNET_SCHEDULER_add_now (&next_it, NULL);
343}
344
345void
346next_it (void *cls)
347{
348 GNUNET_assert (NULL != namestore_iter);
349 GNUNET_NAMESTORE_zone_iterator_next (namestore_iter);
350}
351
352void
353iterator_cb (void *cls,
354 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
355 const char *label,
356 unsigned int rd_count,
357 const struct GNUNET_GNSRECORD_Data *rd)
358{
359 struct IteratorHandle *ith = cls;
360 struct GNUNET_CRYPTO_EcdsaPublicKey *target;
361 struct GNUNET_CRYPTO_EcdsaPublicKey zone;
362
363 if ((rd_count != 1) ||
364 (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type))
365 {
366 GNUNET_SCHEDULER_add_now (&next_it, NULL);
367 return;
368 }
369 GNUNET_CRYPTO_ecdsa_key_get_public (key,
370 &zone);
371 if (0 != memcmp (&zone, &ith->myzone,
372 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
373 {
374 GNUNET_SCHEDULER_add_now (&next_it, NULL);
375 return;
376 }
377 target = (struct GNUNET_CRYPTO_EcdsaPublicKey *) rd->data;
378 gns_lookup_reverse = GNS_resolver_lookup (target,
379 GNUNET_GNSRECORD_TYPE_PKEY,
380 ith->mynick,
381 NULL,
382 GNUNET_GNS_LO_DEFAULT,
383 &handle_gns_result_iter,
384 ith);
385}
386
387void check_reverse_records (void *cls);
388
389void
390finished_cb (void *cls)
391{
392 struct IteratorHandle *ith = cls;
393 struct ReverseRecordEntry *rr;
394
395 //TODO add results to namestore!
396 for (rr = ith->records_head; NULL != rr; rr = ith->records_head)
397 {
398 GNUNET_CONTAINER_DLL_remove (ith->records_head,
399 ith->records_tail,
400 rr);
401 GNUNET_free (rr->record);
402 GNUNET_free (rr);
403 }
404 reverse_record_check_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_DAYS,
405 &check_reverse_records,
406 NULL);
407
408}
409
410void
411it_error (void *cls)
412{
413 finished_cb (cls);
414}
415
416void
417check_reverse_records (void *cls)
418{
419 struct IteratorHandle *ith = cls;
420 namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (ns,
421 NULL,
422 &it_error,
423 ith,
424 &iterator_cb,
425 ith,
426 &finished_cb,
427 ith);
428}
429
430void
431GNS_reverse_init (const struct GNUNET_CONFIGURATION_Handle *c,
432 const struct GNUNET_NAMESTORE_Handle *nh,
433 const struct GNUNET_CRYPTO_EcdsaPublicKey *myzone,
434 const char *mynick)
435{
436 struct IteratorHandle *ith;
437
438 ns = ns;
439 ith = GNUNET_new (struct IteratorHandle);
440 ith->mynick = GNUNET_strdup (mynick);
441 ith->myzone = *myzone;
442 reverse_record_check_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_DAYS,
443 &check_reverse_records,
444 NULL);
445}
244 446
diff --git a/src/gns/test_gns_reverse_lookup.sh b/src/gns/test_gns_reverse_lookup.sh
new file mode 100755
index 000000000..73b829e07
--- /dev/null
+++ b/src/gns/test_gns_reverse_lookup.sh
@@ -0,0 +1,45 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
3which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
4
5LOCATION=$(which gnunet-config)
6if [ -z $LOCATION ]
7then
8 LOCATION="gnunet-config"
9fi
10$LOCATION --version 1> /dev/null
11if test $? != 0
12then
13 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
14 exit 77
15fi
16
17TEST_NAME="dave.bob.alice.gnu"
18gnunet-arm -s -c test_gns_lookup.conf
19gnunet-identity -C bobego -c test_gns_lookup.conf
20BOB_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep bob | awk '{print $3}')
21gnunet-identity -C daveego -c test_gns_lookup.conf
22DAVE_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep dave | awk '{print $3}')
23gnunet-identity -C aliceego -c test_gns_lookup.conf
24ALICE_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep alice | awk '{print $3}')
25gnunet-identity -C testego -c test_gns_lookup.conf
26ROOT_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep testego | awk '{print $3}')
27gnunet-namestore -p -z testego -a -n alice -t PKEY -V $ALICE_PKEY -e never -c test_gns_lookup.conf
28gnunet-namestore -p -z aliceego -a -n bob -t PKEY -V $BOB_PKEY -e never -c test_gns_lookup.conf
29gnunet-namestore -p -z aliceego -a -n + -t REVERSE -V "alice $ROOT_PKEY 0" -e never -c test_gns_lookup.conf
30gnunet-namestore -p -z bobego -a -n dave -t PKEY -V $DAVE_PKEY -e never -c test_gns_lookup.conf
31gnunet-namestore -p -z bobego -a -n + -t REVERSE -V "bob $ALICE_PKEY 0" -e never -c test_gns_lookup.conf
32gnunet-namestore -p -z daveego -a -n + -t REVERSE -V "dave $BOB_PKEY 0" -e never -c test_gns_lookup.conf
33gnunet-arm -i gns -c test_gns_lookup.conf
34sleep 0.5
35RES_NAME=`$DO_TIMEOUT gnunet-gns --raw -z testego -R $DAVE_PKEY -c test_gns_lookup.conf`
36gnunet-arm -e -c test_gns_lookup.conf
37rm -rf /tmp/test-gnunet-gns-peer-1/
38
39if [ "$RES_NAME" == "$TEST_NAME" ]
40then
41 exit 0
42else
43 echo "Failed to resolve to proper IP, got $RES_IP."
44 exit 1
45fi