diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-30 12:17:46 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-30 12:17:46 +0000 |
commit | ec7d72a656a180ecdd25507439add2656d5bcbae (patch) | |
tree | 308a1e4421ebebf3ffc90503abb210e265a7e23d /src/namestore | |
parent | 3257a3d0944ccd13350f280108f6e4cc7b556cd9 (diff) | |
download | gnunet-ec7d72a656a180ecdd25507439add2656d5bcbae.tar.gz gnunet-ec7d72a656a180ecdd25507439add2656d5bcbae.zip |
-enable looking up individual records
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-namestore.c | 127 |
1 files changed, 123 insertions, 4 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 6c69acd22..617604359 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -75,6 +75,11 @@ static struct GNUNET_NAMESTORE_QueueEntry *add_qe_uri; | |||
75 | static struct GNUNET_NAMESTORE_QueueEntry *add_qe; | 75 | static struct GNUNET_NAMESTORE_QueueEntry *add_qe; |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Queue entry for the 'list' operation (in combination with a name). | ||
79 | */ | ||
80 | static struct GNUNET_NAMESTORE_QueueEntry *list_qe; | ||
81 | |||
82 | /** | ||
78 | * Desired action is to list records. | 83 | * Desired action is to list records. |
79 | */ | 84 | */ |
80 | static int list; | 85 | static int list; |
@@ -200,6 +205,11 @@ do_shutdown (void *cls, | |||
200 | GNUNET_NAMESTORE_cancel (add_qe); | 205 | GNUNET_NAMESTORE_cancel (add_qe); |
201 | add_qe = NULL; | 206 | add_qe = NULL; |
202 | } | 207 | } |
208 | if (NULL != list_qe) | ||
209 | { | ||
210 | GNUNET_NAMESTORE_cancel (list_qe); | ||
211 | list_qe = NULL; | ||
212 | } | ||
203 | if (NULL != add_qe_uri) | 213 | if (NULL != add_qe_uri) |
204 | { | 214 | { |
205 | GNUNET_NAMESTORE_cancel (add_qe_uri); | 215 | GNUNET_NAMESTORE_cancel (add_qe_uri); |
@@ -261,6 +271,7 @@ add_continuation (void *cls, | |||
261 | ret = 1; | 271 | ret = 1; |
262 | } | 272 | } |
263 | if ( (NULL == add_qe) && | 273 | if ( (NULL == add_qe) && |
274 | (NULL == list_qe) && | ||
264 | (NULL == add_qe_uri) && | 275 | (NULL == add_qe_uri) && |
265 | (NULL == del_qe) && | 276 | (NULL == del_qe) && |
266 | (NULL == list_it) ) | 277 | (NULL == list_it) ) |
@@ -289,6 +300,7 @@ del_continuation (void *cls, | |||
289 | _("Deleting record failed: %s\n"), | 300 | _("Deleting record failed: %s\n"), |
290 | emsg); | 301 | emsg); |
291 | if ( (NULL == add_qe) && | 302 | if ( (NULL == add_qe) && |
303 | (NULL == list_qe) && | ||
292 | (NULL == add_qe_uri) && | 304 | (NULL == add_qe_uri) && |
293 | (NULL == list_it) ) | 305 | (NULL == list_it) ) |
294 | GNUNET_SCHEDULER_shutdown (); | 306 | GNUNET_SCHEDULER_shutdown (); |
@@ -319,6 +331,7 @@ display_record (void *cls, | |||
319 | { | 331 | { |
320 | list_it = NULL; | 332 | list_it = NULL; |
321 | if ( (NULL == del_qe) && | 333 | if ( (NULL == del_qe) && |
334 | (NULL == list_qe) && | ||
322 | (NULL == add_qe_uri) && | 335 | (NULL == add_qe_uri) && |
323 | (NULL == add_qe) ) | 336 | (NULL == add_qe) ) |
324 | GNUNET_SCHEDULER_shutdown (); | 337 | GNUNET_SCHEDULER_shutdown (); |
@@ -417,6 +430,93 @@ get_existing_record (void *cls, | |||
417 | } | 430 | } |
418 | 431 | ||
419 | 432 | ||
433 | |||
434 | /** | ||
435 | * Process a record that was stored in the namestore in a block. | ||
436 | * | ||
437 | * @param cls closure, NULL | ||
438 | * @param rd_len number of entries in @a rd array | ||
439 | * @param rd array of records with data to store | ||
440 | */ | ||
441 | static void | ||
442 | display_records_from_block (void *cls, | ||
443 | unsigned int rd_len, | ||
444 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
445 | { | ||
446 | const char *typestring; | ||
447 | char *s; | ||
448 | unsigned int i; | ||
449 | |||
450 | if (0 == rd_len) | ||
451 | { | ||
452 | FPRINTF (stdout, | ||
453 | _("No records found for `%s'"), | ||
454 | name); | ||
455 | return; | ||
456 | } | ||
457 | FPRINTF (stdout, | ||
458 | "%s:\n", | ||
459 | name); | ||
460 | for (i=0;i<rd_len;i++) | ||
461 | { | ||
462 | typestring = GNUNET_NAMESTORE_number_to_typename (rd[i].record_type); | ||
463 | s = GNUNET_NAMESTORE_value_to_string (rd[i].record_type, | ||
464 | rd[i].data, | ||
465 | rd[i].data_size); | ||
466 | if (NULL == s) | ||
467 | { | ||
468 | FPRINTF (stdout, _("\tCorrupt or unsupported record of type %u\n"), | ||
469 | (unsigned int) rd[i].record_type); | ||
470 | continue; | ||
471 | } | ||
472 | FPRINTF (stdout, | ||
473 | "\t%s: %s\n", | ||
474 | typestring, | ||
475 | s); | ||
476 | GNUNET_free (s); | ||
477 | } | ||
478 | FPRINTF (stdout, "%s", "\n"); | ||
479 | } | ||
480 | |||
481 | |||
482 | /** | ||
483 | * Display block obtained from listing (by name). | ||
484 | * | ||
485 | * @param cls NULL | ||
486 | * @param block NULL if not found | ||
487 | */ | ||
488 | static void | ||
489 | handle_block (void *cls, | ||
490 | const struct GNUNET_NAMESTORE_Block *block) | ||
491 | { | ||
492 | struct GNUNET_CRYPTO_EccPublicSignKey zone_pubkey; | ||
493 | |||
494 | list_qe = NULL; | ||
495 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (&zone_pkey, | ||
496 | &zone_pubkey); | ||
497 | if (NULL == block) | ||
498 | { | ||
499 | fprintf (stderr, | ||
500 | "No matching block found\n"); | ||
501 | } | ||
502 | else if (GNUNET_OK != | ||
503 | GNUNET_NAMESTORE_block_decrypt (block, | ||
504 | &zone_pubkey, | ||
505 | name, | ||
506 | &display_records_from_block, | ||
507 | NULL)) | ||
508 | { | ||
509 | fprintf (stderr, | ||
510 | "Failed to decrypt block!\n"); | ||
511 | } | ||
512 | if ( (NULL == del_qe) && | ||
513 | (NULL == list_it) && | ||
514 | (NULL == add_qe_uri) && | ||
515 | (NULL == add_qe) ) | ||
516 | GNUNET_SCHEDULER_shutdown (); | ||
517 | } | ||
518 | |||
519 | |||
420 | /** | 520 | /** |
421 | * Function called with the result from the check if the namestore | 521 | * Function called with the result from the check if the namestore |
422 | * service is actually running. If it is, we start the actual | 522 | * service is actually running. If it is, we start the actual |
@@ -444,6 +544,7 @@ testservice_task (void *cls, | |||
444 | /* nothing more to be done */ | 544 | /* nothing more to be done */ |
445 | fprintf (stderr, | 545 | fprintf (stderr, |
446 | _("No options given\n")); | 546 | _("No options given\n")); |
547 | GNUNET_SCHEDULER_shutdown (); | ||
447 | return; | 548 | return; |
448 | } | 549 | } |
449 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (&zone_pkey, | 550 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (&zone_pkey, |
@@ -566,10 +667,28 @@ testservice_task (void *cls, | |||
566 | } | 667 | } |
567 | if (list) | 668 | if (list) |
568 | { | 669 | { |
569 | list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | 670 | if (NULL == name) |
570 | &zone_pkey, | 671 | { |
571 | &display_record, | 672 | list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, |
572 | NULL); | 673 | &zone_pkey, |
674 | &display_record, | ||
675 | NULL); | ||
676 | } | ||
677 | else | ||
678 | { | ||
679 | struct GNUNET_HashCode query; | ||
680 | struct GNUNET_CRYPTO_EccPublicSignKey zone_pubkey; | ||
681 | |||
682 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (&zone_pkey, | ||
683 | &zone_pubkey); | ||
684 | GNUNET_NAMESTORE_query_from_public_key (&zone_pubkey, | ||
685 | name, | ||
686 | &query); | ||
687 | list_qe = GNUNET_NAMESTORE_lookup_block (ns, | ||
688 | &query, | ||
689 | handle_block, | ||
690 | NULL); | ||
691 | } | ||
573 | } | 692 | } |
574 | if (NULL != uri) | 693 | if (NULL != uri) |
575 | { | 694 | { |