diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-11-13 15:04:21 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-11-13 15:04:21 +0000 |
commit | 97f8a1ba8d1d43025ae43ab33bca12efbd49f355 (patch) | |
tree | 406396c6cd263e9cac02f60a9b80663f66bb374c /src/namestore | |
parent | be479981b97e8eeeb4ac251bb413a08b425a0fdd (diff) | |
download | gnunet-97f8a1ba8d1d43025ae43ab33bca12efbd49f355.tar.gz gnunet-97f8a1ba8d1d43025ae43ab33bca12efbd49f355.zip |
adding pseudonym NICK automatically to records sets
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/Makefile.am | 20 | ||||
-rw-r--r-- | src/namestore/gnunet-namestore.c | 16 | ||||
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 183 | ||||
-rw-r--r-- | src/namestore/namestore_api.c | 29 | ||||
-rw-r--r-- | src/namestore/test_namestore_api_lookup_nick.c | 308 | ||||
-rw-r--r-- | src/namestore/test_namestore_api_zone_iteration_nick.c | 466 |
6 files changed, 996 insertions, 26 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index 7656e646c..8b8d7c60f 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -41,11 +41,13 @@ TESTING_TESTS = \ | |||
41 | test_namestore_api_store_update \ | 41 | test_namestore_api_store_update \ |
42 | test_namestore_api_lookup_public \ | 42 | test_namestore_api_lookup_public \ |
43 | test_namestore_api_lookup_private \ | 43 | test_namestore_api_lookup_private \ |
44 | test_namestore_api_lookup_nick \ | ||
44 | test_namestore_api_lookup_shadow \ | 45 | test_namestore_api_lookup_shadow \ |
45 | test_namestore_api_lookup_shadow_filter \ | 46 | test_namestore_api_lookup_shadow_filter \ |
46 | test_namestore_api_remove \ | 47 | test_namestore_api_remove \ |
47 | test_namestore_api_remove_not_existing_record \ | 48 | test_namestore_api_remove_not_existing_record \ |
48 | test_namestore_api_zone_iteration \ | 49 | test_namestore_api_zone_iteration \ |
50 | test_namestore_api_zone_iteration_nick \ | ||
49 | test_namestore_api_zone_iteration_specific_zone \ | 51 | test_namestore_api_zone_iteration_specific_zone \ |
50 | test_namestore_api_zone_iteration_stop \ | 52 | test_namestore_api_zone_iteration_stop \ |
51 | test_namestore_api_monitoring \ | 53 | test_namestore_api_monitoring \ |
@@ -199,6 +201,15 @@ test_namestore_api_lookup_public_LDADD = \ | |||
199 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ | 201 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ |
200 | $(top_builddir)/src/namestore/libgnunetnamestore.la | 202 | $(top_builddir)/src/namestore/libgnunetnamestore.la |
201 | 203 | ||
204 | test_namestore_api_lookup_nick_SOURCES = \ | ||
205 | test_namestore_api_lookup_nick.c | ||
206 | test_namestore_api_lookup_nick_LDADD = \ | ||
207 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
208 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
209 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
210 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ | ||
211 | $(top_builddir)/src/namestore/libgnunetnamestore.la | ||
212 | |||
202 | test_namestore_api_lookup_private_SOURCES = \ | 213 | test_namestore_api_lookup_private_SOURCES = \ |
203 | test_namestore_api_lookup_private.c | 214 | test_namestore_api_lookup_private.c |
204 | test_namestore_api_lookup_private_LDADD = \ | 215 | test_namestore_api_lookup_private_LDADD = \ |
@@ -281,6 +292,15 @@ test_namestore_api_zone_iteration_LDADD = \ | |||
281 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 292 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
282 | $(top_builddir)/src/namestore/libgnunetnamestore.la | 293 | $(top_builddir)/src/namestore/libgnunetnamestore.la |
283 | 294 | ||
295 | test_namestore_api_zone_iteration_nick_SOURCES = \ | ||
296 | test_namestore_api_zone_iteration_nick.c | ||
297 | test_namestore_api_zone_iteration_nick_LDADD = \ | ||
298 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
299 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
300 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
301 | $(top_builddir)/src/namestore/libgnunetnamestore.la | ||
302 | |||
303 | |||
284 | test_namestore_api_zone_iteration_specific_zone_SOURCES = \ | 304 | test_namestore_api_zone_iteration_specific_zone_SOURCES = \ |
285 | test_namestore_api_zone_iteration_specific_zone.c | 305 | test_namestore_api_zone_iteration_specific_zone.c |
286 | test_namestore_api_zone_iteration_specific_zone_LDADD = \ | 306 | test_namestore_api_zone_iteration_specific_zone_LDADD = \ |
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index f8ad83259..5de86182f 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <gnunet_dnsparser_lib.h> | 31 | #include <gnunet_dnsparser_lib.h> |
32 | #include <gnunet_identity_service.h> | 32 | #include <gnunet_identity_service.h> |
33 | #include <gnunet_gnsrecord_lib.h> | 33 | #include <gnunet_gnsrecord_lib.h> |
34 | #include <gnunet_gns_service.h> | ||
34 | #include <gnunet_namestore_service.h> | 35 | #include <gnunet_namestore_service.h> |
35 | 36 | ||
36 | 37 | ||
@@ -732,19 +733,8 @@ testservice_task (void *cls, | |||
732 | ret = 1; | 733 | ret = 1; |
733 | return; | 734 | return; |
734 | } | 735 | } |
735 | memset (&rd, 0, sizeof (rd)); | 736 | add_qe_uri = GNUNET_NAMESTORE_set_nick(ns, &zone_pkey, nickstring, |
736 | rd.data = nickstring; | 737 | &add_continuation, &add_qe_uri); |
737 | rd.data_size = strlen(nickstring); | ||
738 | rd.record_type = GNUNET_GNSRECORD_TYPE_NICK; | ||
739 | rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | ||
740 | rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE; | ||
741 | add_qe_uri = GNUNET_NAMESTORE_records_store (ns, | ||
742 | &zone_pkey, | ||
743 | "+", | ||
744 | 1, | ||
745 | &rd, | ||
746 | &add_continuation, | ||
747 | &add_qe_uri); | ||
748 | } | 738 | } |
749 | if (monitor) | 739 | if (monitor) |
750 | { | 740 | { |
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index ad8c9e798..ffffc704e 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_dnsparser_lib.h" | 29 | #include "gnunet_dnsparser_lib.h" |
30 | #include "gnunet_gns_service.h" | ||
30 | #include "gnunet_namecache_service.h" | 31 | #include "gnunet_namecache_service.h" |
31 | #include "gnunet_namestore_service.h" | 32 | #include "gnunet_namestore_service.h" |
32 | #include "gnunet_namestore_plugin.h" | 33 | #include "gnunet_namestore_plugin.h" |
@@ -63,6 +64,11 @@ struct ZoneIteration | |||
63 | struct NamestoreClient *client; | 64 | struct NamestoreClient *client; |
64 | 65 | ||
65 | /** | 66 | /** |
67 | * The nick to add to the records | ||
68 | */ | ||
69 | struct GNUNET_GNSRECORD_Data *nick; | ||
70 | |||
71 | /** | ||
66 | * Key of the zone we are iterating over. | 72 | * Key of the zone we are iterating over. |
67 | */ | 73 | */ |
68 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone; | 74 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone; |
@@ -391,6 +397,109 @@ client_lookup (struct GNUNET_SERVER_Client *client) | |||
391 | } | 397 | } |
392 | 398 | ||
393 | 399 | ||
400 | static void lookup_nick_it (void *cls, | ||
401 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, | ||
402 | const char *label, | ||
403 | unsigned int rd_count, | ||
404 | const struct GNUNET_GNSRECORD_Data *rd) | ||
405 | { | ||
406 | struct GNUNET_GNSRECORD_Data **res = (cls); | ||
407 | |||
408 | int c; | ||
409 | if (0 != strcmp (label, GNUNET_GNS_MASTERZONE_STR)) | ||
410 | { | ||
411 | GNUNET_break (0); | ||
412 | return; | ||
413 | } | ||
414 | for (c = 0; c < rd_count; c++) | ||
415 | { | ||
416 | if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type) | ||
417 | { | ||
418 | (*res) = GNUNET_malloc (rd[c].data_size + sizeof (struct GNUNET_GNSRECORD_Data)); | ||
419 | (*res)->data = &(*res)[1]; | ||
420 | memcpy ((char *)(*res)->data, rd[c].data, rd[c].data_size); | ||
421 | (*res)->data_size = rd[c].data_size; | ||
422 | (*res)->expiration_time = rd[c].expiration_time; | ||
423 | (*res)->flags = rd[c].flags; | ||
424 | (*res)->record_type = GNUNET_GNSRECORD_TYPE_NICK; | ||
425 | return; | ||
426 | } | ||
427 | } | ||
428 | (*res) = NULL; | ||
429 | } | ||
430 | |||
431 | |||
432 | static struct GNUNET_GNSRECORD_Data * | ||
433 | get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone) | ||
434 | { | ||
435 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | ||
436 | struct GNUNET_GNSRECORD_Data *nick; | ||
437 | int res; | ||
438 | |||
439 | res = GSN_database->lookup_records (GSN_database->cls, zone, | ||
440 | GNUNET_GNS_MASTERZONE_STR, &lookup_nick_it, &nick); | ||
441 | |||
442 | if ((NULL == nick) || (GNUNET_OK != res)) | ||
443 | { | ||
444 | GNUNET_CRYPTO_ecdsa_key_get_public (zone, &pub); | ||
445 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No nick name set for zone `%s'\n", | ||
446 | GNUNET_CRYPTO_ecdsa_public_key_to_string (&pub)); | ||
447 | return NULL; | ||
448 | } | ||
449 | |||
450 | return nick; | ||
451 | } | ||
452 | |||
453 | |||
454 | static void merge_records (unsigned int rdc1, | ||
455 | const struct GNUNET_GNSRECORD_Data *rd1, | ||
456 | unsigned int rdc2, | ||
457 | const struct GNUNET_GNSRECORD_Data *rd2, | ||
458 | unsigned int *rdc_res, | ||
459 | struct GNUNET_GNSRECORD_Data **rd_res) | ||
460 | { | ||
461 | int c; | ||
462 | size_t req; | ||
463 | char *data; | ||
464 | int record_offset; | ||
465 | size_t data_offset; | ||
466 | (*rdc_res) = rdc1 + rdc2; | ||
467 | |||
468 | if (0 == rdc1 + rdc2) | ||
469 | { | ||
470 | (*rd_res) = NULL; | ||
471 | return; | ||
472 | } | ||
473 | |||
474 | req = 0; | ||
475 | for (c=0; c< rdc1; c++) | ||
476 | req += sizeof (struct GNUNET_GNSRECORD_Data) + rd1[c].data_size; | ||
477 | for (c=0; c< rdc2; c++) | ||
478 | req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size; | ||
479 | (*rd_res) = GNUNET_malloc (req); | ||
480 | data = (char *) &(*rd_res)[rdc1 + rdc2]; | ||
481 | data_offset = 0; | ||
482 | |||
483 | for (c=0; c< rdc1; c++) | ||
484 | { | ||
485 | (*rd_res)[c] = rd1[c]; | ||
486 | (*rd_res)[c].data = (void *) &data[data_offset]; | ||
487 | memcpy ((void *) (*rd_res)[c].data, rd1[c].data, rd1[c].data_size); | ||
488 | data_offset += (*rd_res)[c].data_size; | ||
489 | } | ||
490 | record_offset = rdc1; | ||
491 | for (c=0; c< rdc2; c++) | ||
492 | { | ||
493 | (*rd_res)[c+record_offset] = rd2[c]; | ||
494 | (*rd_res)[c+record_offset].data = (void *) &data[data_offset]; | ||
495 | memcpy ((void *) (*rd_res)[c+record_offset].data, rd2[c].data, rd2[c].data_size); | ||
496 | data_offset += (*rd_res)[c+record_offset].data_size; | ||
497 | } | ||
498 | GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset); | ||
499 | } | ||
500 | |||
501 | |||
502 | |||
394 | /** | 503 | /** |
395 | * Generate a 'struct LookupNameResponseMessage' and send it to the | 504 | * Generate a 'struct LookupNameResponseMessage' and send it to the |
396 | * given client using the given notification context. | 505 | * given client using the given notification context. |
@@ -413,14 +522,29 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc, | |||
413 | const struct GNUNET_GNSRECORD_Data *rd) | 522 | const struct GNUNET_GNSRECORD_Data *rd) |
414 | { | 523 | { |
415 | struct RecordResultMessage *zir_msg; | 524 | struct RecordResultMessage *zir_msg; |
525 | struct GNUNET_GNSRECORD_Data *nick; | ||
526 | struct GNUNET_GNSRECORD_Data *res; | ||
527 | unsigned int res_count; | ||
416 | size_t name_len; | 528 | size_t name_len; |
417 | size_t rd_ser_len; | 529 | size_t rd_ser_len; |
418 | size_t msg_size; | 530 | size_t msg_size; |
419 | char *name_tmp; | 531 | char *name_tmp; |
420 | char *rd_ser; | 532 | char *rd_ser; |
421 | 533 | ||
534 | nick = get_nick_record (zone_key); | ||
535 | if ((NULL != nick) && (0 != strcmp(name, GNUNET_GNS_MASTERZONE_STR))) | ||
536 | { | ||
537 | merge_records (rd_count,rd, 1, nick, &res_count, &res); | ||
538 | GNUNET_free (nick); | ||
539 | } | ||
540 | else | ||
541 | { | ||
542 | res_count = rd_count; | ||
543 | res = (struct GNUNET_GNSRECORD_Data *) rd; | ||
544 | } | ||
545 | |||
422 | name_len = strlen (name) + 1; | 546 | name_len = strlen (name) + 1; |
423 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); | 547 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res); |
424 | msg_size = sizeof (struct RecordResultMessage) + name_len + rd_ser_len; | 548 | msg_size = sizeof (struct RecordResultMessage) + name_len + rd_ser_len; |
425 | (void) client_lookup (client); | 549 | (void) client_lookup (client); |
426 | zir_msg = GNUNET_malloc (msg_size); | 550 | zir_msg = GNUNET_malloc (msg_size); |
@@ -428,13 +552,13 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc, | |||
428 | zir_msg->gns_header.header.size = htons (msg_size); | 552 | zir_msg->gns_header.header.size = htons (msg_size); |
429 | zir_msg->gns_header.r_id = htonl (request_id); | 553 | zir_msg->gns_header.r_id = htonl (request_id); |
430 | zir_msg->name_len = htons (name_len); | 554 | zir_msg->name_len = htons (name_len); |
431 | zir_msg->rd_count = htons (rd_count); | 555 | zir_msg->rd_count = htons (res_count); |
432 | zir_msg->rd_len = htons (rd_ser_len); | 556 | zir_msg->rd_len = htons (rd_ser_len); |
433 | zir_msg->private_key = *zone_key; | 557 | zir_msg->private_key = *zone_key; |
434 | name_tmp = (char *) &zir_msg[1]; | 558 | name_tmp = (char *) &zir_msg[1]; |
435 | memcpy (name_tmp, name, name_len); | 559 | memcpy (name_tmp, name, name_len); |
436 | rd_ser = &name_tmp[name_len]; | 560 | rd_ser = &name_tmp[name_len]; |
437 | GNUNET_GNSRECORD_records_serialize (rd_count, rd, rd_ser_len, rd_ser); | 561 | GNUNET_GNSRECORD_records_serialize (res_count, res, rd_ser_len, rd_ser); |
438 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 562 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
439 | "Sending `%s' message with %u records and size %u\n", | 563 | "Sending `%s' message with %u records and size %u\n", |
440 | "RECORD_RESULT", | 564 | "RECORD_RESULT", |
@@ -444,6 +568,8 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc, | |||
444 | client, | 568 | client, |
445 | &zir_msg->gns_header.header, | 569 | &zir_msg->gns_header.header, |
446 | GNUNET_NO); | 570 | GNUNET_NO); |
571 | if (rd != res) | ||
572 | GNUNET_free (res); | ||
447 | GNUNET_free (zir_msg); | 573 | GNUNET_free (zir_msg); |
448 | } | 574 | } |
449 | 575 | ||
@@ -573,25 +699,51 @@ struct RecordLookupContext | |||
573 | size_t rd_ser_len; | 699 | size_t rd_ser_len; |
574 | 700 | ||
575 | char *res_rd; | 701 | char *res_rd; |
702 | |||
703 | struct GNUNET_GNSRECORD_Data *nick; | ||
576 | }; | 704 | }; |
577 | 705 | ||
578 | static void lookup_it (void *cls, | 706 | |
579 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, | 707 | |
580 | const char *label, | 708 | static void |
581 | unsigned int rd_count, | 709 | lookup_it (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, |
582 | const struct GNUNET_GNSRECORD_Data *rd) | 710 | const char *label, unsigned int rd_count, |
711 | const struct GNUNET_GNSRECORD_Data *rd) | ||
583 | { | 712 | { |
584 | struct RecordLookupContext *rlc = cls; | 713 | struct RecordLookupContext *rlc = cls; |
714 | struct GNUNET_GNSRECORD_Data *rd_res; | ||
715 | unsigned int rdc_res; | ||
585 | 716 | ||
586 | if (0 == strcmp (label, rlc->label)) | 717 | if (0 == strcmp (label, rlc->label)) |
587 | { | 718 | { |
588 | rlc->found = GNUNET_YES; | 719 | rlc->found = GNUNET_YES; |
589 | if (0 != rd_count) | 720 | if (0 != rd_count) |
590 | { | 721 | { |
591 | rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); | 722 | if ((NULL != rlc->nick) && (0 != strcmp(label, GNUNET_GNS_MASTERZONE_STR))) |
592 | rlc->res_rd_count = rd_count; | 723 | { |
593 | rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len); | 724 | /* Merge */ |
594 | GNUNET_GNSRECORD_records_serialize (rd_count, rd, rlc->rd_ser_len , rlc->res_rd); | 725 | rd_res = NULL; |
726 | rdc_res = 0; | ||
727 | merge_records (rd_count, rd, | ||
728 | 1, rlc->nick, | ||
729 | &rdc_res, &rd_res); | ||
730 | |||
731 | rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res, rd_res); | ||
732 | rlc->res_rd_count = rdc_res; | ||
733 | rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len); | ||
734 | GNUNET_GNSRECORD_records_serialize (rdc_res, rd_res, rlc->rd_ser_len , rlc->res_rd); | ||
735 | |||
736 | GNUNET_free (rd_res); | ||
737 | GNUNET_free (rlc->nick); | ||
738 | rlc->nick = NULL; | ||
739 | } | ||
740 | else | ||
741 | { | ||
742 | rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); | ||
743 | rlc->res_rd_count = rd_count; | ||
744 | rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len); | ||
745 | GNUNET_GNSRECORD_records_serialize (rd_count, rd, rlc->rd_ser_len , rlc->res_rd); | ||
746 | } | ||
595 | } | 747 | } |
596 | else | 748 | else |
597 | { | 749 | { |
@@ -603,6 +755,9 @@ static void lookup_it (void *cls, | |||
603 | } | 755 | } |
604 | 756 | ||
605 | 757 | ||
758 | |||
759 | |||
760 | |||
606 | /** | 761 | /** |
607 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message | 762 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message |
608 | * | 763 | * |
@@ -666,8 +821,8 @@ handle_record_lookup (void *cls, | |||
666 | rlc.label = name_tmp; | 821 | rlc.label = name_tmp; |
667 | rlc.found = GNUNET_NO; | 822 | rlc.found = GNUNET_NO; |
668 | rlc.res_rd_count = 0; | 823 | rlc.res_rd_count = 0; |
669 | rlc.rd_ser_len = 0; | ||
670 | rlc.res_rd = NULL; | 824 | rlc.res_rd = NULL; |
825 | rlc.nick = get_nick_record (&ll_msg->zone); | ||
671 | 826 | ||
672 | res = GSN_database->lookup_records (GSN_database->cls, | 827 | res = GSN_database->lookup_records (GSN_database->cls, |
673 | &ll_msg->zone, name_tmp, &lookup_it, &rlc); | 828 | &ll_msg->zone, name_tmp, &lookup_it, &rlc); |
@@ -1188,6 +1343,8 @@ handle_iteration_start (void *cls, | |||
1188 | zi->offset = 0; | 1343 | zi->offset = 0; |
1189 | zi->client = nc; | 1344 | zi->client = nc; |
1190 | zi->zone = zis_msg->zone; | 1345 | zi->zone = zis_msg->zone; |
1346 | |||
1347 | |||
1191 | GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); | 1348 | GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); |
1192 | run_zone_iteration_round (zi); | 1349 | run_zone_iteration_round (zi); |
1193 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1350 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index c05386908..034352bd9 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include "gnunet_dnsparser_lib.h" | 33 | #include "gnunet_dnsparser_lib.h" |
34 | #include "gnunet_arm_service.h" | 34 | #include "gnunet_arm_service.h" |
35 | #include "gnunet_signatures.h" | 35 | #include "gnunet_signatures.h" |
36 | #include "gnunet_gns_service.h" | ||
36 | #include "gnunet_namestore_service.h" | 37 | #include "gnunet_namestore_service.h" |
37 | #include "namestore.h" | 38 | #include "namestore.h" |
38 | 39 | ||
@@ -1065,6 +1066,34 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
1065 | return qe; | 1066 | return qe; |
1066 | } | 1067 | } |
1067 | 1068 | ||
1069 | /** | ||
1070 | * Set the desired nick name for a zone | ||
1071 | * | ||
1072 | * @param h handle to the namestore | ||
1073 | * @param pkey private key of the zone | ||
1074 | * @param nick the nick name to set | ||
1075 | * @param cont continuation to call when done | ||
1076 | * @param cont_cls closure for 'cont' | ||
1077 | * @return handle to abort the request | ||
1078 | */ | ||
1079 | struct GNUNET_NAMESTORE_QueueEntry * | ||
1080 | GNUNET_NAMESTORE_set_nick (struct GNUNET_NAMESTORE_Handle *h, | ||
1081 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | ||
1082 | const char *nick, | ||
1083 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | ||
1084 | void *cont_cls) | ||
1085 | { | ||
1086 | struct GNUNET_GNSRECORD_Data rd; | ||
1087 | |||
1088 | memset (&rd, 0, sizeof (rd)); | ||
1089 | rd.data = nick; | ||
1090 | rd.data_size = strlen (nick) +1; | ||
1091 | rd.record_type = GNUNET_GNSRECORD_TYPE_NICK; | ||
1092 | rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | ||
1093 | rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE; | ||
1094 | return GNUNET_NAMESTORE_records_store(h, pkey, GNUNET_GNS_MASTERZONE_STR, 1, &rd, cont, cont_cls); | ||
1095 | } | ||
1096 | |||
1068 | 1097 | ||
1069 | /** | 1098 | /** |
1070 | * Lookup an item in the namestore. | 1099 | * Lookup an item in the namestore. |
diff --git a/src/namestore/test_namestore_api_lookup_nick.c b/src/namestore/test_namestore_api_lookup_nick.c new file mode 100644 index 000000000..c9a1c5f19 --- /dev/null +++ b/src/namestore/test_namestore_api_lookup_nick.c | |||
@@ -0,0 +1,308 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file namestore/test_namestore_api_store.c | ||
22 | * @brief testcase for namestore_api.c: store a record | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_namestore_service.h" | ||
26 | #include "gnunet_testing_lib.h" | ||
27 | |||
28 | #define TEST_RECORD_TYPE 1234 | ||
29 | |||
30 | #define TEST_RECORD_DATALEN 123 | ||
31 | |||
32 | #define TEST_NICK "gnunettestnick" | ||
33 | |||
34 | #define TEST_RECORD_DATA 'a' | ||
35 | |||
36 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
37 | |||
38 | static struct GNUNET_NAMESTORE_Handle *nsh; | ||
39 | |||
40 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | ||
41 | |||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | ||
43 | |||
44 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | ||
45 | |||
46 | static int res; | ||
47 | |||
48 | static struct GNUNET_GNSRECORD_Data rd_orig; | ||
49 | |||
50 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | ||
51 | |||
52 | //static const char * name = "dummy.dummy.gnunet"; | ||
53 | static const char * name = "d"; | ||
54 | |||
55 | static void | ||
56 | cleanup () | ||
57 | { | ||
58 | GNUNET_free_non_null ((void *)rd_orig.data); | ||
59 | if (NULL != nsh) | ||
60 | { | ||
61 | GNUNET_NAMESTORE_disconnect (nsh); | ||
62 | nsh = NULL; | ||
63 | } | ||
64 | if (NULL != privkey) | ||
65 | { | ||
66 | GNUNET_free (privkey); | ||
67 | privkey = NULL; | ||
68 | } | ||
69 | GNUNET_SCHEDULER_shutdown (); | ||
70 | } | ||
71 | |||
72 | |||
73 | /** | ||
74 | * Re-establish the connection to the service. | ||
75 | * | ||
76 | * @param cls handle to use to re-connect. | ||
77 | * @param tc scheduler context | ||
78 | */ | ||
79 | static void | ||
80 | endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
81 | { | ||
82 | if (NULL != nsqe) | ||
83 | { | ||
84 | GNUNET_NAMESTORE_cancel (nsqe); | ||
85 | nsqe = NULL; | ||
86 | } | ||
87 | cleanup (); | ||
88 | res = 1; | ||
89 | } | ||
90 | |||
91 | |||
92 | static void | ||
93 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
94 | { | ||
95 | cleanup (); | ||
96 | res = 0; | ||
97 | } | ||
98 | |||
99 | void lookup_it (void *cls, | ||
100 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | ||
101 | const char *label, | ||
102 | unsigned int rd_count, | ||
103 | const struct GNUNET_GNSRECORD_Data *rd) | ||
104 | { | ||
105 | nsqe = NULL; | ||
106 | int c; | ||
107 | int found_record = GNUNET_NO; | ||
108 | int found_nick = GNUNET_NO; | ||
109 | |||
110 | if (0 != memcmp(privkey, zone, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | ||
111 | { | ||
112 | GNUNET_break(0); | ||
113 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
114 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
115 | return; | ||
116 | } | ||
117 | |||
118 | if (NULL == label) | ||
119 | { | ||
120 | GNUNET_break(0); | ||
121 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
122 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
123 | return; | ||
124 | } | ||
125 | |||
126 | if (0 != strcmp (label, name)) | ||
127 | { | ||
128 | GNUNET_break(0); | ||
129 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
130 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
131 | return; | ||
132 | } | ||
133 | |||
134 | if (2 != rd_count) | ||
135 | { | ||
136 | GNUNET_break(0); | ||
137 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
138 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
139 | return; | ||
140 | } | ||
141 | |||
142 | for (c = 0; c < rd_count; c++) | ||
143 | { | ||
144 | if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type) | ||
145 | { | ||
146 | if (rd[c].data_size != strlen(TEST_NICK)+1) | ||
147 | { | ||
148 | GNUNET_break(0); | ||
149 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
150 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
151 | return; | ||
152 | } | ||
153 | if (rd[c].flags != GNUNET_GNSRECORD_RF_PRIVATE) | ||
154 | { | ||
155 | GNUNET_break(0); | ||
156 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
157 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
158 | return; | ||
159 | } | ||
160 | if (0 != strcmp(rd[c].data, TEST_NICK)) | ||
161 | { | ||
162 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
163 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
164 | return; | ||
165 | } | ||
166 | found_nick = GNUNET_YES; | ||
167 | } | ||
168 | else | ||
169 | { | ||
170 | if (rd[c].record_type != TEST_RECORD_TYPE) | ||
171 | { | ||
172 | GNUNET_break(0); | ||
173 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
174 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
175 | return; | ||
176 | } | ||
177 | if (rd[c].data_size != TEST_RECORD_DATALEN) | ||
178 | { | ||
179 | GNUNET_break(0); | ||
180 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
181 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
182 | return; | ||
183 | } | ||
184 | if (0 != memcmp (rd[c].data, rd_orig.data, TEST_RECORD_DATALEN)) | ||
185 | { | ||
186 | GNUNET_break(0); | ||
187 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
188 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
189 | return; | ||
190 | } | ||
191 | if (rd[c].flags != rd->flags) | ||
192 | { | ||
193 | GNUNET_break(0); | ||
194 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
195 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
196 | return; | ||
197 | } | ||
198 | found_record = GNUNET_YES; | ||
199 | } | ||
200 | |||
201 | } | ||
202 | |||
203 | /* Done */ | ||
204 | if ((GNUNET_YES == found_nick) && (GNUNET_YES == found_record)) | ||
205 | { | ||
206 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
207 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | ||
208 | GNUNET_SCHEDULER_add_now (&end, NULL ); | ||
209 | } | ||
210 | else | ||
211 | { | ||
212 | GNUNET_break (0); | ||
213 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
214 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | ||
215 | GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
216 | } | ||
217 | } | ||
218 | |||
219 | |||
220 | static void | ||
221 | put_cont (void *cls, int32_t success, const char *emsg) | ||
222 | { | ||
223 | const char *name = cls; | ||
224 | |||
225 | nsqe = NULL; | ||
226 | GNUNET_assert (NULL != cls); | ||
227 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
228 | "Name store added record for `%s': %s\n", | ||
229 | name, | ||
230 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | ||
231 | |||
232 | if (GNUNET_OK != success) | ||
233 | { | ||
234 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
235 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
236 | return; | ||
237 | } | ||
238 | /* Lookup */ | ||
239 | nsqe = GNUNET_NAMESTORE_records_lookup (nsh, privkey, name, lookup_it, NULL); | ||
240 | } | ||
241 | |||
242 | static void | ||
243 | nick_cont (void *cls, int32_t success, const char *emsg) | ||
244 | { | ||
245 | const char *name = cls; | ||
246 | |||
247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
248 | "Nick added : %s\n", | ||
249 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | ||
250 | |||
251 | rd_orig.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; | ||
252 | rd_orig.record_type = TEST_RECORD_TYPE; | ||
253 | rd_orig.data_size = TEST_RECORD_DATALEN; | ||
254 | rd_orig.data = GNUNET_malloc (TEST_RECORD_DATALEN); | ||
255 | rd_orig.flags = 0; | ||
256 | memset ((char *) rd_orig.data, 'a', TEST_RECORD_DATALEN); | ||
257 | |||
258 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | ||
259 | 1, &rd_orig, &put_cont, (void *) name); | ||
260 | } | ||
261 | |||
262 | |||
263 | static void | ||
264 | run (void *cls, | ||
265 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
266 | struct GNUNET_TESTING_Peer *peer) | ||
267 | { | ||
268 | char *hostkey_file; | ||
269 | |||
270 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
271 | &endbadly, NULL); | ||
272 | GNUNET_asprintf (&hostkey_file, | ||
273 | "zonefiles%s%s", | ||
274 | DIR_SEPARATOR_STR, | ||
275 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
276 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
277 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | ||
278 | GNUNET_free (hostkey_file); | ||
279 | GNUNET_assert (privkey != NULL); | ||
280 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | ||
281 | |||
282 | nsh = GNUNET_NAMESTORE_connect (cfg); | ||
283 | GNUNET_break (NULL != nsh); | ||
284 | |||
285 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, TEST_NICK, &nick_cont, (void *) name); | ||
286 | if (NULL == nsqe) | ||
287 | { | ||
288 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
289 | _("Namestore cannot store no block\n")); | ||
290 | } | ||
291 | } | ||
292 | |||
293 | |||
294 | int | ||
295 | main (int argc, char *argv[]) | ||
296 | { | ||
297 | res = 1; | ||
298 | if (0 != | ||
299 | GNUNET_TESTING_peer_run ("test-namestore-api", | ||
300 | "test_namestore_api.conf", | ||
301 | &run, | ||
302 | NULL)) | ||
303 | return 1; | ||
304 | return res; | ||
305 | } | ||
306 | |||
307 | |||
308 | /* end of test_namestore_api_store.c */ | ||
diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c b/src/namestore/test_namestore_api_zone_iteration_nick.c new file mode 100644 index 000000000..5328e40a1 --- /dev/null +++ b/src/namestore/test_namestore_api_zone_iteration_nick.c | |||
@@ -0,0 +1,466 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2013 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file namestore/test_namestore_api_zone_iteration.c | ||
22 | * @brief testcase for zone iteration functionality: iterate all zones | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_namestore_service.h" | ||
26 | #include "gnunet_testing_lib.h" | ||
27 | #include "namestore.h" | ||
28 | |||
29 | #define ZONE_NICK_1 "nick1" | ||
30 | #define ZONE_NICK_2 "nick2" | ||
31 | |||
32 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) | ||
33 | |||
34 | |||
35 | static struct GNUNET_NAMESTORE_Handle * nsh; | ||
36 | |||
37 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | ||
38 | |||
39 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey; | ||
40 | |||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey2; | ||
42 | |||
43 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | ||
44 | |||
45 | static int res; | ||
46 | |||
47 | static int returned_records; | ||
48 | |||
49 | static char * s_name_1; | ||
50 | |||
51 | static struct GNUNET_GNSRECORD_Data *s_rd_1; | ||
52 | |||
53 | static char * s_name_2; | ||
54 | |||
55 | static struct GNUNET_GNSRECORD_Data *s_rd_2; | ||
56 | |||
57 | static char * s_name_3; | ||
58 | |||
59 | static struct GNUNET_GNSRECORD_Data *s_rd_3; | ||
60 | |||
61 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | ||
62 | |||
63 | /** | ||
64 | * Re-establish the connection to the service. | ||
65 | * | ||
66 | * @param cls handle to use to re-connect. | ||
67 | * @param tc scheduler context | ||
68 | */ | ||
69 | static void | ||
70 | endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
71 | { | ||
72 | if (NULL != zi) | ||
73 | { | ||
74 | GNUNET_NAMESTORE_zone_iteration_stop (zi); | ||
75 | zi = NULL; | ||
76 | } | ||
77 | if (nsh != NULL) | ||
78 | { | ||
79 | GNUNET_NAMESTORE_disconnect (nsh); | ||
80 | nsh = NULL; | ||
81 | } | ||
82 | GNUNET_free_non_null(s_name_1); | ||
83 | GNUNET_free_non_null(s_name_2); | ||
84 | GNUNET_free_non_null(s_name_3); | ||
85 | |||
86 | if (s_rd_1 != NULL) | ||
87 | { | ||
88 | GNUNET_free ((void *)s_rd_1->data); | ||
89 | GNUNET_free (s_rd_1); | ||
90 | } | ||
91 | if (s_rd_2 != NULL) | ||
92 | { | ||
93 | GNUNET_free ((void *)s_rd_2->data); | ||
94 | GNUNET_free (s_rd_2); | ||
95 | } | ||
96 | if (s_rd_3 != NULL) | ||
97 | { | ||
98 | GNUNET_free ((void *)s_rd_3->data); | ||
99 | GNUNET_free (s_rd_3); | ||
100 | } | ||
101 | |||
102 | if (privkey != NULL) | ||
103 | GNUNET_free (privkey); | ||
104 | privkey = NULL; | ||
105 | |||
106 | if (privkey2 != NULL) | ||
107 | GNUNET_free (privkey2); | ||
108 | privkey2 = NULL; | ||
109 | res = 1; | ||
110 | } | ||
111 | |||
112 | |||
113 | static void | ||
114 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
115 | { | ||
116 | if (NULL != zi) | ||
117 | { | ||
118 | GNUNET_NAMESTORE_zone_iteration_stop (zi); | ||
119 | zi = NULL; | ||
120 | } | ||
121 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
122 | { | ||
123 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
124 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | ||
125 | } | ||
126 | |||
127 | if (privkey != NULL) | ||
128 | GNUNET_free (privkey); | ||
129 | privkey = NULL; | ||
130 | |||
131 | if (privkey2 != NULL) | ||
132 | GNUNET_free (privkey2); | ||
133 | privkey2 = NULL; | ||
134 | |||
135 | GNUNET_free (s_name_1); | ||
136 | GNUNET_free (s_name_2); | ||
137 | GNUNET_free (s_name_3); | ||
138 | if (s_rd_1 != NULL) | ||
139 | { | ||
140 | GNUNET_free ((void *)s_rd_1->data); | ||
141 | GNUNET_free (s_rd_1); | ||
142 | } | ||
143 | if (s_rd_2 != NULL) | ||
144 | { | ||
145 | GNUNET_free ((void *)s_rd_2->data); | ||
146 | GNUNET_free (s_rd_2); | ||
147 | } | ||
148 | if (s_rd_3 != NULL) | ||
149 | { | ||
150 | GNUNET_free ((void *)s_rd_3->data); | ||
151 | GNUNET_free (s_rd_3); | ||
152 | } | ||
153 | if (nsh != NULL) | ||
154 | GNUNET_NAMESTORE_disconnect (nsh); | ||
155 | nsh = NULL; | ||
156 | } | ||
157 | |||
158 | static int | ||
159 | check_zone_1 (const char *label, unsigned int rd_count, | ||
160 | const struct GNUNET_GNSRECORD_Data *rd) | ||
161 | { | ||
162 | int failed = GNUNET_NO; | ||
163 | int c; | ||
164 | for (c = 0; c< rd_count ; c++) | ||
165 | { | ||
166 | if (rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) | ||
167 | if (0 != strcmp (rd[c].data, ZONE_NICK_1)) | ||
168 | { | ||
169 | GNUNET_break (0); | ||
170 | return GNUNET_YES; | ||
171 | } | ||
172 | } | ||
173 | return failed; | ||
174 | } | ||
175 | |||
176 | static int | ||
177 | check_zone_2 (const char *label, | ||
178 | unsigned int rd_count, | ||
179 | const struct GNUNET_GNSRECORD_Data *rd) | ||
180 | { | ||
181 | int failed = GNUNET_NO; | ||
182 | int c; | ||
183 | |||
184 | for (c = 0; c< rd_count ; c++) | ||
185 | { | ||
186 | if (rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) | ||
187 | if (0 != strcmp (rd[c].data, ZONE_NICK_2)) | ||
188 | { | ||
189 | GNUNET_break (0); | ||
190 | return GNUNET_YES; | ||
191 | } | ||
192 | } | ||
193 | |||
194 | return failed; | ||
195 | } | ||
196 | |||
197 | |||
198 | static void | ||
199 | zone_proc (void *cls, | ||
200 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | ||
201 | const char *label, | ||
202 | unsigned int rd_count, | ||
203 | const struct GNUNET_GNSRECORD_Data *rd) | ||
204 | { | ||
205 | int failed = GNUNET_NO; | ||
206 | if ((zone == NULL) && (label == NULL)) | ||
207 | { | ||
208 | zi = NULL; | ||
209 | res = 0; | ||
210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
211 | "Received last result, iteration done after receing %u results\n", | ||
212 | returned_records); | ||
213 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
214 | return; | ||
215 | } | ||
216 | |||
217 | if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | ||
218 | { | ||
219 | failed = check_zone_1 (label, rd_count, rd); | ||
220 | if (GNUNET_YES == failed) | ||
221 | GNUNET_break (0); | ||
222 | } | ||
223 | else if (0 == memcmp (zone, privkey2, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | ||
224 | { | ||
225 | failed = check_zone_2 (label, rd_count, rd); | ||
226 | if (GNUNET_YES == failed) | ||
227 | GNUNET_break (0); | ||
228 | } | ||
229 | else | ||
230 | { | ||
231 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
232 | "Received invalid zone\n"); | ||
233 | failed = GNUNET_YES; | ||
234 | GNUNET_break (0); | ||
235 | } | ||
236 | |||
237 | if (failed == GNUNET_NO) | ||
238 | { | ||
239 | returned_records ++; | ||
240 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
241 | "Telling namestore to send the next result\n"); | ||
242 | GNUNET_NAMESTORE_zone_iterator_next (zi); | ||
243 | } | ||
244 | else | ||
245 | { | ||
246 | GNUNET_break (0); | ||
247 | res = 1; | ||
248 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
249 | } | ||
250 | } | ||
251 | |||
252 | |||
253 | static void | ||
254 | put_cont (void *cls, int32_t success, const char *emsg) | ||
255 | { | ||
256 | static int c = 0; | ||
257 | |||
258 | if (success == GNUNET_OK) | ||
259 | { | ||
260 | c++; | ||
261 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); | ||
262 | } | ||
263 | else | ||
264 | { | ||
265 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", | ||
266 | emsg); | ||
267 | GNUNET_break (0); | ||
268 | if (GNUNET_SCHEDULER_NO_TASK != endbadly_task) | ||
269 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
270 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
271 | return; | ||
272 | } | ||
273 | |||
274 | if (c == 3) | ||
275 | { | ||
276 | res = 1; | ||
277 | returned_records = 0; | ||
278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); | ||
279 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, | ||
280 | NULL, | ||
281 | &zone_proc, | ||
282 | NULL); | ||
283 | if (zi == NULL) | ||
284 | { | ||
285 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); | ||
286 | GNUNET_break (0); | ||
287 | if (GNUNET_SCHEDULER_NO_TASK != endbadly_task) | ||
288 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
289 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
290 | return; | ||
291 | } | ||
292 | } | ||
293 | } | ||
294 | |||
295 | |||
296 | static struct GNUNET_GNSRECORD_Data * | ||
297 | create_record (unsigned int count) | ||
298 | { | ||
299 | unsigned int c; | ||
300 | struct GNUNET_GNSRECORD_Data * rd; | ||
301 | |||
302 | rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); | ||
303 | for (c = 0; c < count; c++) | ||
304 | { | ||
305 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; | ||
306 | rd[c].record_type = 1111; | ||
307 | rd[c].data_size = 50; | ||
308 | rd[c].data = GNUNET_malloc(50); | ||
309 | rd[c].flags = 0; | ||
310 | memset ((char *) rd[c].data, 'a', 50); | ||
311 | } | ||
312 | return rd; | ||
313 | } | ||
314 | |||
315 | static void | ||
316 | nick_2_cont (void *cls, int32_t success, const char *emsg) | ||
317 | { | ||
318 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
319 | "Nick added : %s\n", | ||
320 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | ||
321 | |||
322 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); | ||
323 | |||
324 | GNUNET_asprintf(&s_name_1, "dummy1"); | ||
325 | s_rd_1 = create_record(1); | ||
326 | GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_1, | ||
327 | 1, s_rd_1, | ||
328 | &put_cont, NULL); | ||
329 | |||
330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
331 | "Created record 2 \n"); | ||
332 | GNUNET_asprintf(&s_name_2, "dummy2"); | ||
333 | s_rd_2 = create_record(1); | ||
334 | GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_2, | ||
335 | 1, s_rd_2, &put_cont, NULL); | ||
336 | |||
337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
338 | "Created record 3\n"); | ||
339 | |||
340 | /* name in different zone */ | ||
341 | GNUNET_asprintf(&s_name_3, "dummy3"); | ||
342 | s_rd_3 = create_record(1); | ||
343 | GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, | ||
344 | 1, s_rd_3, | ||
345 | &put_cont, NULL); | ||
346 | } | ||
347 | |||
348 | |||
349 | static void | ||
350 | nick_1_cont (void *cls, int32_t success, const char *emsg) | ||
351 | { | ||
352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
353 | "Nick 1 added : %s\n", | ||
354 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | ||
355 | |||
356 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey2, ZONE_NICK_2, &nick_2_cont, &privkey2); | ||
357 | if (NULL == nsqe) | ||
358 | { | ||
359 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
360 | _("Namestore cannot store no block\n")); | ||
361 | } | ||
362 | |||
363 | |||
364 | |||
365 | } | ||
366 | |||
367 | |||
368 | |||
369 | /** | ||
370 | * Callback called from the zone iterator when we iterate over | ||
371 | * the empty zone. Check that we got no records and then | ||
372 | * start the actual tests by filling the zone. | ||
373 | */ | ||
374 | static void | ||
375 | empty_zone_proc (void *cls, | ||
376 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | ||
377 | const char *label, | ||
378 | unsigned int rd_count, | ||
379 | const struct GNUNET_GNSRECORD_Data *rd) | ||
380 | { | ||
381 | char *hostkey_file; | ||
382 | GNUNET_assert (nsh == cls); | ||
383 | if (NULL != zone) | ||
384 | { | ||
385 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
386 | _("Expected empty zone but received zone private key\n")); | ||
387 | GNUNET_break (0); | ||
388 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
389 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
390 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
391 | return; | ||
392 | } | ||
393 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) | ||
394 | { | ||
395 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
396 | _("Expected no zone content but received data\n")); | ||
397 | GNUNET_break (0); | ||
398 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
399 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
400 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
401 | return; | ||
402 | } | ||
403 | |||
404 | zi = NULL; | ||
405 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, | ||
406 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
408 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | ||
409 | GNUNET_free (hostkey_file); | ||
410 | GNUNET_assert (privkey != NULL); | ||
411 | |||
412 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, | ||
413 | "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); | ||
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
415 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | ||
416 | GNUNET_free (hostkey_file); | ||
417 | GNUNET_assert (privkey2 != NULL); | ||
418 | |||
419 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, ZONE_NICK_1, &nick_1_cont, &privkey); | ||
420 | if (NULL == nsqe) | ||
421 | { | ||
422 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
423 | _("Namestore cannot store no block\n")); | ||
424 | } | ||
425 | |||
426 | } | ||
427 | |||
428 | |||
429 | static void | ||
430 | run (void *cls, | ||
431 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
432 | struct GNUNET_TESTING_Peer *peer) | ||
433 | { | ||
434 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL); | ||
435 | nsh = GNUNET_NAMESTORE_connect (cfg); | ||
436 | GNUNET_break (NULL != nsh); | ||
437 | |||
438 | /* first, iterate over empty namestore */ | ||
439 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, | ||
440 | NULL, &empty_zone_proc, nsh); | ||
441 | if (NULL == zi) | ||
442 | { | ||
443 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); | ||
444 | GNUNET_break (0); | ||
445 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
446 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
447 | } | ||
448 | } | ||
449 | |||
450 | |||
451 | int | ||
452 | main (int argc, char *argv[]) | ||
453 | { | ||
454 | res = 1; | ||
455 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-namestore"); | ||
456 | if (0 != | ||
457 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration", | ||
458 | "test_namestore_api.conf", | ||
459 | &run, | ||
460 | NULL)) | ||
461 | return 1; | ||
462 | return res; | ||
463 | } | ||
464 | |||
465 | |||
466 | /* end of test_namestore_api_zone_iteration.c */ | ||