diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-10-06 19:25:05 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-10-06 19:25:05 +0000 |
commit | 892ea474164020cbc2efd4fbd2b00fd00ae54e1a (patch) | |
tree | 5800dabb5d38e133be5b0bc9b8cd1991e95471c1 | |
parent | e43731d9df9fb2ffd8720af47ed5249f87cca3fd (diff) | |
download | gnunet-892ea474164020cbc2efd4fbd2b00fd00ae54e1a.tar.gz gnunet-892ea474164020cbc2efd4fbd2b00fd00ae54e1a.zip |
-add tests
-rw-r--r-- | src/gns/gnunet-service-gns_reverser.c | 204 | ||||
-rwxr-xr-x | src/gns/test_gns_reverse_lookup.sh | 45 |
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 | ||
32 | struct 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 | |||
51 | struct 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 | |||
32 | struct ReverseTreeNode | 80 | struct 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 | */ | ||
151 | static struct GNUNET_SCHEDULER_Task *reverse_record_check_task; | ||
152 | |||
153 | /** | ||
154 | * GNS lookup handle | ||
155 | */ | ||
156 | static struct GNS_ResolverHandle *gns_lookup_reverse; | ||
157 | |||
158 | /** | ||
159 | * NS handle | ||
160 | */ | ||
161 | static struct GNUNET_NAMESTORE_Handle *ns; | ||
162 | |||
163 | /** | ||
164 | * NS Iterator | ||
165 | */ | ||
166 | static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; | ||
167 | |||
100 | void | 168 | void |
101 | cleanup_handle (struct GNS_ReverserHandle *rh) | 169 | cleanup_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 | ||
312 | void | ||
313 | next_it (void *cls); | ||
314 | |||
315 | void | ||
316 | handle_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 | |||
345 | void | ||
346 | next_it (void *cls) | ||
347 | { | ||
348 | GNUNET_assert (NULL != namestore_iter); | ||
349 | GNUNET_NAMESTORE_zone_iterator_next (namestore_iter); | ||
350 | } | ||
351 | |||
352 | void | ||
353 | iterator_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 | |||
387 | void check_reverse_records (void *cls); | ||
388 | |||
389 | void | ||
390 | finished_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 | |||
410 | void | ||
411 | it_error (void *cls) | ||
412 | { | ||
413 | finished_cb (cls); | ||
414 | } | ||
415 | |||
416 | void | ||
417 | check_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 | |||
430 | void | ||
431 | GNS_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 | ||
2 | trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT | ||
3 | which timeout &> /dev/null && DO_TIMEOUT="timeout 30" | ||
4 | |||
5 | LOCATION=$(which gnunet-config) | ||
6 | if [ -z $LOCATION ] | ||
7 | then | ||
8 | LOCATION="gnunet-config" | ||
9 | fi | ||
10 | $LOCATION --version 1> /dev/null | ||
11 | if test $? != 0 | ||
12 | then | ||
13 | echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX" | ||
14 | exit 77 | ||
15 | fi | ||
16 | |||
17 | TEST_NAME="dave.bob.alice.gnu" | ||
18 | gnunet-arm -s -c test_gns_lookup.conf | ||
19 | gnunet-identity -C bobego -c test_gns_lookup.conf | ||
20 | BOB_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep bob | awk '{print $3}') | ||
21 | gnunet-identity -C daveego -c test_gns_lookup.conf | ||
22 | DAVE_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep dave | awk '{print $3}') | ||
23 | gnunet-identity -C aliceego -c test_gns_lookup.conf | ||
24 | ALICE_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep alice | awk '{print $3}') | ||
25 | gnunet-identity -C testego -c test_gns_lookup.conf | ||
26 | ROOT_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep testego | awk '{print $3}') | ||
27 | gnunet-namestore -p -z testego -a -n alice -t PKEY -V $ALICE_PKEY -e never -c test_gns_lookup.conf | ||
28 | gnunet-namestore -p -z aliceego -a -n bob -t PKEY -V $BOB_PKEY -e never -c test_gns_lookup.conf | ||
29 | gnunet-namestore -p -z aliceego -a -n + -t REVERSE -V "alice $ROOT_PKEY 0" -e never -c test_gns_lookup.conf | ||
30 | gnunet-namestore -p -z bobego -a -n dave -t PKEY -V $DAVE_PKEY -e never -c test_gns_lookup.conf | ||
31 | gnunet-namestore -p -z bobego -a -n + -t REVERSE -V "bob $ALICE_PKEY 0" -e never -c test_gns_lookup.conf | ||
32 | gnunet-namestore -p -z daveego -a -n + -t REVERSE -V "dave $BOB_PKEY 0" -e never -c test_gns_lookup.conf | ||
33 | gnunet-arm -i gns -c test_gns_lookup.conf | ||
34 | sleep 0.5 | ||
35 | RES_NAME=`$DO_TIMEOUT gnunet-gns --raw -z testego -R $DAVE_PKEY -c test_gns_lookup.conf` | ||
36 | gnunet-arm -e -c test_gns_lookup.conf | ||
37 | rm -rf /tmp/test-gnunet-gns-peer-1/ | ||
38 | |||
39 | if [ "$RES_NAME" == "$TEST_NAME" ] | ||
40 | then | ||
41 | exit 0 | ||
42 | else | ||
43 | echo "Failed to resolve to proper IP, got $RES_IP." | ||
44 | exit 1 | ||
45 | fi | ||