From 216067618ef77f9fc7c1683c6f47facfb56accd0 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 8 Oct 2013 18:30:02 +0000 Subject: -implement #2992 (but reverse lookup itself seems to not yet work properly) --- src/namestore/gnunet-namestore.c | 111 ++++++++++++++++++++++++++++++--------- 1 file changed, 86 insertions(+), 25 deletions(-) (limited to 'src/namestore/gnunet-namestore.c') diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index ceedadc24..2ff640604 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c @@ -25,7 +25,6 @@ * * TODO: * - test - * - add options to list/lookup individual records */ #include "platform.h" #include @@ -52,7 +51,7 @@ static struct GNUNET_IDENTITY_EgoLookup *el; /** * Name of the ego controlling the zone. */ -static char *ego_name; +static char *ego_name; /** * Desired action is to add a record. @@ -79,6 +78,11 @@ static struct GNUNET_NAMESTORE_QueueEntry *add_qe; */ static struct GNUNET_NAMESTORE_QueueEntry *list_qe; +/** + * Queue entry for the 'reverse lookup' operation (in combination with a name). + */ +static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe; + /** * Desired action is to list records. */ @@ -124,6 +128,11 @@ static char *value; */ static char *uri; +/** + * Reverse lookup to perform. + */ +static char *reverse_pkey; + /** * Type of the record to add/remove, NULL to remove all. */ @@ -244,6 +253,22 @@ do_shutdown (void *cls, } +/** + * Check if we are finished, and if so, perform shutdown. + */ +static void +test_finished () +{ + if ( (NULL == add_qe) && + (NULL == list_qe) && + (NULL == add_qe_uri) && + (NULL == del_qe) && + (NULL == reverse_qe) && + (NULL == list_it) ) + GNUNET_SCHEDULER_shutdown (); +} + + /** * Continuation called to notify client about result of the * operation. @@ -270,12 +295,7 @@ add_continuation (void *cls, if (GNUNET_NO != success) ret = 1; } - if ( (NULL == add_qe) && - (NULL == list_qe) && - (NULL == add_qe_uri) && - (NULL == del_qe) && - (NULL == list_it) ) - GNUNET_SCHEDULER_shutdown (); + test_finished (); } @@ -299,11 +319,7 @@ del_continuation (void *cls, fprintf (stderr, _("Deleting record failed: %s\n"), emsg); - if ( (NULL == add_qe) && - (NULL == list_qe) && - (NULL == add_qe_uri) && - (NULL == list_it) ) - GNUNET_SCHEDULER_shutdown (); + test_finished (); } @@ -333,11 +349,7 @@ display_record (void *cls, if (NULL == name) { list_it = NULL; - if ( (NULL == del_qe) && - (NULL == list_qe) && - (NULL == add_qe_uri) && - (NULL == add_qe) ) - GNUNET_SCHEDULER_shutdown (); + test_finished (); return; } FPRINTF (stdout, @@ -532,11 +544,37 @@ handle_block (void *cls, fprintf (stderr, "Failed to decrypt block!\n"); } - if ( (NULL == del_qe) && - (NULL == list_it) && - (NULL == add_qe_uri) && - (NULL == add_qe) ) - GNUNET_SCHEDULER_shutdown (); + test_finished (); +} + + +/** + * Function called with the result of our attempt to obtain a name for a given + * public key. + * + * @param cls NULL + * @param zone private key of the zone; NULL on disconnect + * @param label label of the records; NULL on disconnect + * @param rd_count number of entries in @a rd array, 0 if label was deleted + * @param rd array of records with data to store + */ +static void +handle_reverse_lookup (void *cls, + const struct GNUNET_CRYPTO_EccPrivateKey *zone, + const char *label, + unsigned int rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd) +{ + reverse_qe = NULL; + if (NULL == label) + FPRINTF (stdout, + "%s.zkey\n", + reverse_pkey); + else + FPRINTF (stdout, + "%s.gnu\n", + label); + test_finished (); } @@ -562,7 +600,7 @@ testservice_task (void *cls, "namestore"); return; } - if (! (add|del|list|(NULL != uri))) + if (! (add|del|list|(NULL != uri)|(NULL != reverse_pkey)) ) { /* nothing more to be done */ fprintf (stderr, @@ -709,10 +747,30 @@ testservice_task (void *cls, &query); list_qe = GNUNET_NAMESTORE_lookup_block (ns, &query, - handle_block, + &handle_block, NULL); } } + if (NULL != reverse_pkey) + { + struct GNUNET_CRYPTO_EccPublicSignKey pubkey; + + if (GNUNET_OK != + GNUNET_CRYPTO_ecc_public_sign_key_from_string (reverse_pkey, + strlen (reverse_pkey), + &pubkey)) + { + fprintf (stderr, + _("Invalid public key for reverse lookup `%s'\n"), + reverse_pkey); + GNUNET_SCHEDULER_shutdown (); + } + reverse_qe = GNUNET_NAMESTORE_zone_to_name (ns, + &zone_pkey, + &pubkey, + &handle_reverse_lookup, + NULL); + } if (NULL != uri) { char sh[105]; @@ -859,6 +917,9 @@ main (int argc, char *const *argv) {'n', "name", "NAME", gettext_noop ("name of the record to add/delete/display"), 1, &GNUNET_GETOPT_set_string, &name}, + {'r', "reverse", "PKEY", + gettext_noop ("determine our name for the given PKEY"), 1, + &GNUNET_GETOPT_set_string, &reverse_pkey}, {'t', "type", "TYPE", gettext_noop ("type of the record to add/delete/display"), 1, &GNUNET_GETOPT_set_string, &typestring}, -- cgit v1.2.3