diff options
Diffstat (limited to 'src/namestore/gnunet-namestore.c')
-rw-r--r-- | src/namestore/gnunet-namestore.c | 122 |
1 files changed, 75 insertions, 47 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 9f9a524e3..0a8db7eed 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "platform.h" | 30 | #include "platform.h" |
31 | #include <gnunet_util_lib.h> | 31 | #include <gnunet_util_lib.h> |
32 | #include <gnunet_dnsparser_lib.h> | 32 | #include <gnunet_dnsparser_lib.h> |
33 | #include <gnunet_identity_service.h> | ||
33 | #include <gnunet_namestore_service.h> | 34 | #include <gnunet_namestore_service.h> |
34 | 35 | ||
35 | 36 | ||
@@ -41,12 +42,17 @@ static struct GNUNET_NAMESTORE_Handle *ns; | |||
41 | /** | 42 | /** |
42 | * Private key for the our zone. | 43 | * Private key for the our zone. |
43 | */ | 44 | */ |
44 | static struct GNUNET_CRYPTO_EccPrivateKey *zone_pkey; | 45 | static struct GNUNET_CRYPTO_EccPrivateKey zone_pkey; |
45 | 46 | ||
46 | /** | 47 | /** |
47 | * Keyfile to manipulate. FIXME: change to ego's name! | 48 | * Handle to identity service. |
48 | */ | 49 | */ |
49 | static char *keyfile; | 50 | static struct GNUNET_IDENTITY_Handle *identity; |
51 | |||
52 | /** | ||
53 | * Name of the ego controlling the zone. | ||
54 | */ | ||
55 | static char *ego_name; | ||
50 | 56 | ||
51 | /** | 57 | /** |
52 | * Desired action is to add a record. | 58 | * Desired action is to add a record. |
@@ -204,11 +210,7 @@ do_shutdown (void *cls, | |||
204 | GNUNET_NAMESTORE_disconnect (ns); | 210 | GNUNET_NAMESTORE_disconnect (ns); |
205 | ns = NULL; | 211 | ns = NULL; |
206 | } | 212 | } |
207 | if (NULL != zone_pkey) | 213 | memset (&zone_pkey, 0, sizeof (zone_pkey)); |
208 | { | ||
209 | GNUNET_CRYPTO_ecc_key_free (zone_pkey); | ||
210 | zone_pkey = NULL; | ||
211 | } | ||
212 | if (NULL != uri) | 214 | if (NULL != uri) |
213 | { | 215 | { |
214 | GNUNET_free (uri); | 216 | GNUNET_free (uri); |
@@ -396,7 +398,7 @@ get_existing_record (void *cls, | |||
396 | rde->flags |= GNUNET_NAMESTORE_RF_PRIVATE; | 398 | rde->flags |= GNUNET_NAMESTORE_RF_PRIVATE; |
397 | GNUNET_assert (NULL != name); | 399 | GNUNET_assert (NULL != name); |
398 | add_qe = GNUNET_NAMESTORE_records_store (ns, | 400 | add_qe = GNUNET_NAMESTORE_records_store (ns, |
399 | zone_pkey, | 401 | &zone_pkey, |
400 | name, | 402 | name, |
401 | rd_count + 1, | 403 | rd_count + 1, |
402 | rde, | 404 | rde, |
@@ -429,37 +431,14 @@ testservice_task (void *cls, | |||
429 | "namestore"); | 431 | "namestore"); |
430 | return; | 432 | return; |
431 | } | 433 | } |
432 | if (NULL == keyfile) | ||
433 | { | ||
434 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | ||
435 | "ZONEKEY", &keyfile)) | ||
436 | { | ||
437 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
438 | "gns", "ZONEKEY"); | ||
439 | return; | ||
440 | } | ||
441 | fprintf (stderr, | ||
442 | _("Using default zone file `%s'\n"), | ||
443 | keyfile); | ||
444 | } | ||
445 | zone_pkey = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile); | ||
446 | |||
447 | if (! (add|del|list|(NULL != uri))) | 434 | if (! (add|del|list|(NULL != uri))) |
448 | { | 435 | { |
449 | /* nothing more to be done */ | 436 | /* nothing more to be done */ |
450 | fprintf (stderr, | 437 | fprintf (stderr, |
451 | _("No options given\n")); | 438 | _("No options given\n")); |
452 | GNUNET_CRYPTO_ecc_key_free (zone_pkey); | ||
453 | zone_pkey = NULL; | ||
454 | return; | 439 | return; |
455 | } | 440 | } |
456 | if (NULL == zone_pkey) | 441 | GNUNET_CRYPTO_ecc_key_get_public (&zone_pkey, |
457 | { | ||
458 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
459 | _("Failed to read or create private zone key\n")); | ||
460 | return; | ||
461 | } | ||
462 | GNUNET_CRYPTO_ecc_key_get_public (zone_pkey, | ||
463 | &pub); | 442 | &pub); |
464 | 443 | ||
465 | ns = GNUNET_NAMESTORE_connect (cfg); | 444 | ns = GNUNET_NAMESTORE_connect (cfg); |
@@ -557,7 +536,7 @@ testservice_task (void *cls, | |||
557 | return; | 536 | return; |
558 | } | 537 | } |
559 | add_zit = GNUNET_NAMESTORE_zone_iteration_start (ns, | 538 | add_zit = GNUNET_NAMESTORE_zone_iteration_start (ns, |
560 | zone_pkey, | 539 | &zone_pkey, |
561 | &get_existing_record, | 540 | &get_existing_record, |
562 | NULL); | 541 | NULL); |
563 | } | 542 | } |
@@ -573,7 +552,7 @@ testservice_task (void *cls, | |||
573 | return; | 552 | return; |
574 | } | 553 | } |
575 | del_qe = GNUNET_NAMESTORE_records_store (ns, | 554 | del_qe = GNUNET_NAMESTORE_records_store (ns, |
576 | zone_pkey, | 555 | &zone_pkey, |
577 | name, | 556 | name, |
578 | 0, NULL, | 557 | 0, NULL, |
579 | &del_continuation, | 558 | &del_continuation, |
@@ -582,7 +561,7 @@ testservice_task (void *cls, | |||
582 | if (list) | 561 | if (list) |
583 | { | 562 | { |
584 | list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | 563 | list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, |
585 | zone_pkey, | 564 | &zone_pkey, |
586 | &display_record, | 565 | &display_record, |
587 | NULL); | 566 | NULL); |
588 | } | 567 | } |
@@ -622,7 +601,7 @@ testservice_task (void *cls, | |||
622 | if (1 != nonauthority) | 601 | if (1 != nonauthority) |
623 | rd.flags |= GNUNET_NAMESTORE_RF_AUTHORITY; | 602 | rd.flags |= GNUNET_NAMESTORE_RF_AUTHORITY; |
624 | add_qe_uri = GNUNET_NAMESTORE_records_store (ns, | 603 | add_qe_uri = GNUNET_NAMESTORE_records_store (ns, |
625 | zone_pkey, | 604 | &zone_pkey, |
626 | sname, | 605 | sname, |
627 | 1, | 606 | 1, |
628 | &rd, | 607 | &rd, |
@@ -632,7 +611,7 @@ testservice_task (void *cls, | |||
632 | if (monitor) | 611 | if (monitor) |
633 | { | 612 | { |
634 | zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, | 613 | zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, |
635 | zone_pkey, | 614 | &zone_pkey, |
636 | &display_record, | 615 | &display_record, |
637 | &sync_cb, | 616 | &sync_cb, |
638 | NULL); | 617 | NULL); |
@@ -641,6 +620,52 @@ testservice_task (void *cls, | |||
641 | 620 | ||
642 | 621 | ||
643 | /** | 622 | /** |
623 | * Callback invoked from identity service with ego information. | ||
624 | * An @a ego of NULL and a @a name of NULL indicate the end of | ||
625 | * the initial iteration over known egos. | ||
626 | * | ||
627 | * @param cls closure with the configuration | ||
628 | * @param ego an ego known to identity service, or NULL | ||
629 | * @param ctx per-ego user context (unused) | ||
630 | * @param name name of the ego, or NULL | ||
631 | */ | ||
632 | static void | ||
633 | identity_cb (void *cls, | ||
634 | struct GNUNET_IDENTITY_Ego *ego, | ||
635 | void **ctx, | ||
636 | const char *name) | ||
637 | { | ||
638 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
639 | |||
640 | if ( (NULL != ego_name) && | ||
641 | (0 == strcmp (name, | ||
642 | ego_name)) ) | ||
643 | { | ||
644 | zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); | ||
645 | GNUNET_free (ego_name); | ||
646 | ego_name = NULL; | ||
647 | GNUNET_CLIENT_service_test ("namestore", cfg, | ||
648 | GNUNET_TIME_UNIT_SECONDS, | ||
649 | &testservice_task, | ||
650 | (void *) cfg); | ||
651 | GNUNET_IDENTITY_disconnect (identity); | ||
652 | identity = NULL; | ||
653 | } | ||
654 | if ( (NULL != ego_name) && | ||
655 | (NULL == name) && | ||
656 | (NULL == ego) ) | ||
657 | { | ||
658 | fprintf (stderr, | ||
659 | _("Ego `%s' not known to identity service\n"), | ||
660 | ego_name); | ||
661 | GNUNET_IDENTITY_disconnect (identity); | ||
662 | identity = NULL; | ||
663 | return; | ||
664 | } | ||
665 | } | ||
666 | |||
667 | |||
668 | /** | ||
644 | * Main function that will be run. | 669 | * Main function that will be run. |
645 | * | 670 | * |
646 | * @param cls closure | 671 | * @param cls closure |
@@ -652,14 +677,17 @@ static void | |||
652 | run (void *cls, char *const *args, const char *cfgfile, | 677 | run (void *cls, char *const *args, const char *cfgfile, |
653 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 678 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
654 | { | 679 | { |
655 | 680 | if (NULL == ego_name) | |
681 | { | ||
682 | fprintf (stderr, | ||
683 | _("You must specify which zone should be accessed\n")); | ||
684 | return; | ||
685 | } | ||
656 | if ( (NULL != args[0]) && (NULL == uri) ) | 686 | if ( (NULL != args[0]) && (NULL == uri) ) |
657 | uri = GNUNET_strdup (args[0]); | 687 | uri = GNUNET_strdup (args[0]); |
658 | 688 | identity = GNUNET_IDENTITY_connect (cfg, | |
659 | GNUNET_CLIENT_service_test ("namestore", cfg, | 689 | &identity_cb, |
660 | GNUNET_TIME_UNIT_SECONDS, | 690 | (void *) cfg); |
661 | &testservice_task, | ||
662 | (void *) cfg); | ||
663 | } | 691 | } |
664 | 692 | ||
665 | 693 | ||
@@ -710,9 +738,9 @@ main (int argc, char *const *argv) | |||
710 | {'N', "non-authority", NULL, | 738 | {'N', "non-authority", NULL, |
711 | gettext_noop ("create or list non-authority record"), 0, | 739 | gettext_noop ("create or list non-authority record"), 0, |
712 | &GNUNET_GETOPT_set_one, &nonauthority}, | 740 | &GNUNET_GETOPT_set_one, &nonauthority}, |
713 | {'z', "zonekey", "FILENAME", | 741 | {'z', "zone", "EGO", |
714 | gettext_noop ("filename with the zone key"), 1, | 742 | gettext_noop ("name of the ego controlling the zone"), 1, |
715 | &GNUNET_GETOPT_set_string, &keyfile}, | 743 | &GNUNET_GETOPT_set_string, &ego_name}, |
716 | GNUNET_GETOPT_OPTION_END | 744 | GNUNET_GETOPT_OPTION_END |
717 | }; | 745 | }; |
718 | 746 | ||