diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-08 18:30:02 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-08 18:30:02 +0000 |
commit | 216067618ef77f9fc7c1683c6f47facfb56accd0 (patch) | |
tree | f443d27f1b05d6210b7e7b6bcf83bf35d030236f | |
parent | 042cb093ce1f6c8d7ff2e806903ea9d65947f34e (diff) | |
download | gnunet-216067618ef77f9fc7c1683c6f47facfb56accd0.tar.gz gnunet-216067618ef77f9fc7c1683c6f47facfb56accd0.zip |
-implement #2992 (but reverse lookup itself seems to not yet work properly)
-rw-r--r-- | doc/man/gnunet-namestore.1 | 3 | ||||
-rw-r--r-- | src/namestore/gnunet-namestore.c | 111 |
2 files changed, 89 insertions, 25 deletions
diff --git a/doc/man/gnunet-namestore.1 b/doc/man/gnunet-namestore.1 index 18a4091d0..ec99d088d 100644 --- a/doc/man/gnunet-namestore.1 +++ b/doc/man/gnunet-namestore.1 | |||
@@ -40,6 +40,9 @@ Monitor changes to the zone on an ongoing basis (in contrast to \-D, which merel | |||
40 | .IP "\-n NAME, \-\-name=NAME" | 40 | .IP "\-n NAME, \-\-name=NAME" |
41 | Name of the record to add/delete/display | 41 | Name of the record to add/delete/display |
42 | .B | 42 | .B |
43 | .IP "\-r PKEY, \-\-reverse=PKEY" | ||
44 | Determine our GNS name for the given public key (reverse lookup of the PKEY) in the given zone. | ||
45 | .B | ||
43 | .IP "\-t TYPE, \-\-type=TYPE" | 46 | .IP "\-t TYPE, \-\-type=TYPE" |
44 | Type of the record to add/delete/display (i.e. "A", "AAAA", "NS", "PKEY", "MX" etc.) | 47 | Type of the record to add/delete/display (i.e. "A", "AAAA", "NS", "PKEY", "MX" etc.) |
45 | .B | 48 | .B |
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 @@ | |||
25 | * | 25 | * |
26 | * TODO: | 26 | * TODO: |
27 | * - test | 27 | * - test |
28 | * - add options to list/lookup individual records | ||
29 | */ | 28 | */ |
30 | #include "platform.h" | 29 | #include "platform.h" |
31 | #include <gnunet_util_lib.h> | 30 | #include <gnunet_util_lib.h> |
@@ -52,7 +51,7 @@ static struct GNUNET_IDENTITY_EgoLookup *el; | |||
52 | /** | 51 | /** |
53 | * Name of the ego controlling the zone. | 52 | * Name of the ego controlling the zone. |
54 | */ | 53 | */ |
55 | static char *ego_name; | 54 | static char *ego_name; |
56 | 55 | ||
57 | /** | 56 | /** |
58 | * Desired action is to add a record. | 57 | * Desired action is to add a record. |
@@ -80,6 +79,11 @@ static struct GNUNET_NAMESTORE_QueueEntry *add_qe; | |||
80 | static struct GNUNET_NAMESTORE_QueueEntry *list_qe; | 79 | static struct GNUNET_NAMESTORE_QueueEntry *list_qe; |
81 | 80 | ||
82 | /** | 81 | /** |
82 | * Queue entry for the 'reverse lookup' operation (in combination with a name). | ||
83 | */ | ||
84 | static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe; | ||
85 | |||
86 | /** | ||
83 | * Desired action is to list records. | 87 | * Desired action is to list records. |
84 | */ | 88 | */ |
85 | static int list; | 89 | static int list; |
@@ -125,6 +129,11 @@ static char *value; | |||
125 | static char *uri; | 129 | static char *uri; |
126 | 130 | ||
127 | /** | 131 | /** |
132 | * Reverse lookup to perform. | ||
133 | */ | ||
134 | static char *reverse_pkey; | ||
135 | |||
136 | /** | ||
128 | * Type of the record to add/remove, NULL to remove all. | 137 | * Type of the record to add/remove, NULL to remove all. |
129 | */ | 138 | */ |
130 | static char *typestring; | 139 | static char *typestring; |
@@ -245,6 +254,22 @@ do_shutdown (void *cls, | |||
245 | 254 | ||
246 | 255 | ||
247 | /** | 256 | /** |
257 | * Check if we are finished, and if so, perform shutdown. | ||
258 | */ | ||
259 | static void | ||
260 | test_finished () | ||
261 | { | ||
262 | if ( (NULL == add_qe) && | ||
263 | (NULL == list_qe) && | ||
264 | (NULL == add_qe_uri) && | ||
265 | (NULL == del_qe) && | ||
266 | (NULL == reverse_qe) && | ||
267 | (NULL == list_it) ) | ||
268 | GNUNET_SCHEDULER_shutdown (); | ||
269 | } | ||
270 | |||
271 | |||
272 | /** | ||
248 | * Continuation called to notify client about result of the | 273 | * Continuation called to notify client about result of the |
249 | * operation. | 274 | * operation. |
250 | * | 275 | * |
@@ -270,12 +295,7 @@ add_continuation (void *cls, | |||
270 | if (GNUNET_NO != success) | 295 | if (GNUNET_NO != success) |
271 | ret = 1; | 296 | ret = 1; |
272 | } | 297 | } |
273 | if ( (NULL == add_qe) && | 298 | test_finished (); |
274 | (NULL == list_qe) && | ||
275 | (NULL == add_qe_uri) && | ||
276 | (NULL == del_qe) && | ||
277 | (NULL == list_it) ) | ||
278 | GNUNET_SCHEDULER_shutdown (); | ||
279 | } | 299 | } |
280 | 300 | ||
281 | 301 | ||
@@ -299,11 +319,7 @@ del_continuation (void *cls, | |||
299 | fprintf (stderr, | 319 | fprintf (stderr, |
300 | _("Deleting record failed: %s\n"), | 320 | _("Deleting record failed: %s\n"), |
301 | emsg); | 321 | emsg); |
302 | if ( (NULL == add_qe) && | 322 | test_finished (); |
303 | (NULL == list_qe) && | ||
304 | (NULL == add_qe_uri) && | ||
305 | (NULL == list_it) ) | ||
306 | GNUNET_SCHEDULER_shutdown (); | ||
307 | } | 323 | } |
308 | 324 | ||
309 | 325 | ||
@@ -333,11 +349,7 @@ display_record (void *cls, | |||
333 | if (NULL == name) | 349 | if (NULL == name) |
334 | { | 350 | { |
335 | list_it = NULL; | 351 | list_it = NULL; |
336 | if ( (NULL == del_qe) && | 352 | test_finished (); |
337 | (NULL == list_qe) && | ||
338 | (NULL == add_qe_uri) && | ||
339 | (NULL == add_qe) ) | ||
340 | GNUNET_SCHEDULER_shutdown (); | ||
341 | return; | 353 | return; |
342 | } | 354 | } |
343 | FPRINTF (stdout, | 355 | FPRINTF (stdout, |
@@ -532,11 +544,37 @@ handle_block (void *cls, | |||
532 | fprintf (stderr, | 544 | fprintf (stderr, |
533 | "Failed to decrypt block!\n"); | 545 | "Failed to decrypt block!\n"); |
534 | } | 546 | } |
535 | if ( (NULL == del_qe) && | 547 | test_finished (); |
536 | (NULL == list_it) && | 548 | } |
537 | (NULL == add_qe_uri) && | 549 | |
538 | (NULL == add_qe) ) | 550 | |
539 | GNUNET_SCHEDULER_shutdown (); | 551 | /** |
552 | * Function called with the result of our attempt to obtain a name for a given | ||
553 | * public key. | ||
554 | * | ||
555 | * @param cls NULL | ||
556 | * @param zone private key of the zone; NULL on disconnect | ||
557 | * @param label label of the records; NULL on disconnect | ||
558 | * @param rd_count number of entries in @a rd array, 0 if label was deleted | ||
559 | * @param rd array of records with data to store | ||
560 | */ | ||
561 | static void | ||
562 | handle_reverse_lookup (void *cls, | ||
563 | const struct GNUNET_CRYPTO_EccPrivateKey *zone, | ||
564 | const char *label, | ||
565 | unsigned int rd_count, | ||
566 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
567 | { | ||
568 | reverse_qe = NULL; | ||
569 | if (NULL == label) | ||
570 | FPRINTF (stdout, | ||
571 | "%s.zkey\n", | ||
572 | reverse_pkey); | ||
573 | else | ||
574 | FPRINTF (stdout, | ||
575 | "%s.gnu\n", | ||
576 | label); | ||
577 | test_finished (); | ||
540 | } | 578 | } |
541 | 579 | ||
542 | 580 | ||
@@ -562,7 +600,7 @@ testservice_task (void *cls, | |||
562 | "namestore"); | 600 | "namestore"); |
563 | return; | 601 | return; |
564 | } | 602 | } |
565 | if (! (add|del|list|(NULL != uri))) | 603 | if (! (add|del|list|(NULL != uri)|(NULL != reverse_pkey)) ) |
566 | { | 604 | { |
567 | /* nothing more to be done */ | 605 | /* nothing more to be done */ |
568 | fprintf (stderr, | 606 | fprintf (stderr, |
@@ -709,10 +747,30 @@ testservice_task (void *cls, | |||
709 | &query); | 747 | &query); |
710 | list_qe = GNUNET_NAMESTORE_lookup_block (ns, | 748 | list_qe = GNUNET_NAMESTORE_lookup_block (ns, |
711 | &query, | 749 | &query, |
712 | handle_block, | 750 | &handle_block, |
713 | NULL); | 751 | NULL); |
714 | } | 752 | } |
715 | } | 753 | } |
754 | if (NULL != reverse_pkey) | ||
755 | { | ||
756 | struct GNUNET_CRYPTO_EccPublicSignKey pubkey; | ||
757 | |||
758 | if (GNUNET_OK != | ||
759 | GNUNET_CRYPTO_ecc_public_sign_key_from_string (reverse_pkey, | ||
760 | strlen (reverse_pkey), | ||
761 | &pubkey)) | ||
762 | { | ||
763 | fprintf (stderr, | ||
764 | _("Invalid public key for reverse lookup `%s'\n"), | ||
765 | reverse_pkey); | ||
766 | GNUNET_SCHEDULER_shutdown (); | ||
767 | } | ||
768 | reverse_qe = GNUNET_NAMESTORE_zone_to_name (ns, | ||
769 | &zone_pkey, | ||
770 | &pubkey, | ||
771 | &handle_reverse_lookup, | ||
772 | NULL); | ||
773 | } | ||
716 | if (NULL != uri) | 774 | if (NULL != uri) |
717 | { | 775 | { |
718 | char sh[105]; | 776 | char sh[105]; |
@@ -859,6 +917,9 @@ main (int argc, char *const *argv) | |||
859 | {'n', "name", "NAME", | 917 | {'n', "name", "NAME", |
860 | gettext_noop ("name of the record to add/delete/display"), 1, | 918 | gettext_noop ("name of the record to add/delete/display"), 1, |
861 | &GNUNET_GETOPT_set_string, &name}, | 919 | &GNUNET_GETOPT_set_string, &name}, |
920 | {'r', "reverse", "PKEY", | ||
921 | gettext_noop ("determine our name for the given PKEY"), 1, | ||
922 | &GNUNET_GETOPT_set_string, &reverse_pkey}, | ||
862 | {'t', "type", "TYPE", | 923 | {'t', "type", "TYPE", |
863 | gettext_noop ("type of the record to add/delete/display"), 1, | 924 | gettext_noop ("type of the record to add/delete/display"), 1, |
864 | &GNUNET_GETOPT_set_string, &typestring}, | 925 | &GNUNET_GETOPT_set_string, &typestring}, |