diff options
Diffstat (limited to 'src/namestore/gnunet-namestore.c')
-rw-r--r-- | src/namestore/gnunet-namestore.c | 194 |
1 files changed, 145 insertions, 49 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index d329dcb3b..c5f48848e 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2012, 2013, 2014 GNUnet e.V. | 3 | Copyright (C) 2012, 2013, 2014 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file gnunet-namestore.c | 19 | * @file gnunet-namestore.c |
@@ -80,6 +78,11 @@ static struct GNUNET_NAMESTORE_QueueEntry *add_qe_uri; | |||
80 | static struct GNUNET_NAMESTORE_QueueEntry *add_qe; | 78 | static struct GNUNET_NAMESTORE_QueueEntry *add_qe; |
81 | 79 | ||
82 | /** | 80 | /** |
81 | * Queue entry for the 'lookup' operation. | ||
82 | */ | ||
83 | static struct GNUNET_NAMESTORE_QueueEntry *get_qe; | ||
84 | |||
85 | /** | ||
83 | * Queue entry for the 'reverse lookup' operation (in combination with a name). | 86 | * Queue entry for the 'reverse lookup' operation (in combination with a name). |
84 | */ | 87 | */ |
85 | static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe; | 88 | static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe; |
@@ -234,6 +237,11 @@ do_shutdown (void *cls) | |||
234 | GNUNET_NAMESTORE_cancel (add_qe_uri); | 237 | GNUNET_NAMESTORE_cancel (add_qe_uri); |
235 | add_qe_uri = NULL; | 238 | add_qe_uri = NULL; |
236 | } | 239 | } |
240 | if (NULL != get_qe) | ||
241 | { | ||
242 | GNUNET_NAMESTORE_cancel (get_qe); | ||
243 | get_qe = NULL; | ||
244 | } | ||
237 | if (NULL != del_qe) | 245 | if (NULL != del_qe) |
238 | { | 246 | { |
239 | GNUNET_NAMESTORE_cancel (del_qe); | 247 | GNUNET_NAMESTORE_cancel (del_qe); |
@@ -271,6 +279,7 @@ test_finished () | |||
271 | { | 279 | { |
272 | if ( (NULL == add_qe) && | 280 | if ( (NULL == add_qe) && |
273 | (NULL == add_qe_uri) && | 281 | (NULL == add_qe_uri) && |
282 | (NULL == get_qe) && | ||
274 | (NULL == del_qe) && | 283 | (NULL == del_qe) && |
275 | (NULL == reverse_qe) && | 284 | (NULL == reverse_qe) && |
276 | (NULL == list_it) ) | 285 | (NULL == list_it) ) |
@@ -374,16 +383,12 @@ zone_iteration_error_cb (void *cls) | |||
374 | /** | 383 | /** |
375 | * Process a record that was stored in the namestore. | 384 | * Process a record that was stored in the namestore. |
376 | * | 385 | * |
377 | * @param cls closure | ||
378 | * @param zone_key private key of the zone | ||
379 | * @param rname name that is being mapped (at most 255 characters long) | 386 | * @param rname name that is being mapped (at most 255 characters long) |
380 | * @param rd_len number of entries in @a rd array | 387 | * @param rd_len number of entries in @a rd array |
381 | * @param rd array of records with data to store | 388 | * @param rd array of records with data to store |
382 | */ | 389 | */ |
383 | static void | 390 | static void |
384 | display_record (void *cls, | 391 | display_record (const char *rname, |
385 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | ||
386 | const char *rname, | ||
387 | unsigned int rd_len, | 392 | unsigned int rd_len, |
388 | const struct GNUNET_GNSRECORD_Data *rd) | 393 | const struct GNUNET_GNSRECORD_Data *rd) |
389 | { | 394 | { |
@@ -393,8 +398,6 @@ display_record (void *cls, | |||
393 | struct GNUNET_TIME_Absolute at; | 398 | struct GNUNET_TIME_Absolute at; |
394 | struct GNUNET_TIME_Relative rt; | 399 | struct GNUNET_TIME_Relative rt; |
395 | 400 | ||
396 | (void) cls; | ||
397 | (void) zone_key; | ||
398 | if ( (NULL != name) && | 401 | if ( (NULL != name) && |
399 | (0 != strcmp (name, rname)) ) | 402 | (0 != strcmp (name, rname)) ) |
400 | { | 403 | { |
@@ -442,12 +445,86 @@ display_record (void *cls, | |||
442 | GNUNET_free (s); | 445 | GNUNET_free (s); |
443 | } | 446 | } |
444 | FPRINTF (stdout, "%s", "\n"); | 447 | FPRINTF (stdout, "%s", "\n"); |
448 | } | ||
449 | |||
450 | |||
451 | /** | ||
452 | * Process a record that was stored in the namestore. | ||
453 | * | ||
454 | * @param cls closure | ||
455 | * @param zone_key private key of the zone | ||
456 | * @param rname name that is being mapped (at most 255 characters long) | ||
457 | * @param rd_len number of entries in @a rd array | ||
458 | * @param rd array of records with data to store | ||
459 | */ | ||
460 | static void | ||
461 | display_record_iterator (void *cls, | ||
462 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | ||
463 | const char *rname, | ||
464 | unsigned int rd_len, | ||
465 | const struct GNUNET_GNSRECORD_Data *rd) | ||
466 | { | ||
467 | (void) cls; | ||
468 | (void) zone_key; | ||
469 | display_record (rname, | ||
470 | rd_len, | ||
471 | rd); | ||
445 | GNUNET_NAMESTORE_zone_iterator_next (list_it, | 472 | GNUNET_NAMESTORE_zone_iterator_next (list_it, |
446 | 1); | 473 | 1); |
447 | } | 474 | } |
448 | 475 | ||
449 | 476 | ||
450 | /** | 477 | /** |
478 | * Process a record that was stored in the namestore. | ||
479 | * | ||
480 | * @param cls closure | ||
481 | * @param zone_key private key of the zone | ||
482 | * @param rname name that is being mapped (at most 255 characters long) | ||
483 | * @param rd_len number of entries in @a rd array | ||
484 | * @param rd array of records with data to store | ||
485 | */ | ||
486 | static void | ||
487 | display_record_monitor (void *cls, | ||
488 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | ||
489 | const char *rname, | ||
490 | unsigned int rd_len, | ||
491 | const struct GNUNET_GNSRECORD_Data *rd) | ||
492 | { | ||
493 | (void) cls; | ||
494 | (void) zone_key; | ||
495 | display_record (rname, | ||
496 | rd_len, | ||
497 | rd); | ||
498 | GNUNET_NAMESTORE_zone_monitor_next (zm, | ||
499 | 1); | ||
500 | } | ||
501 | |||
502 | |||
503 | /** | ||
504 | * Process a record that was stored in the namestore. | ||
505 | * | ||
506 | * @param cls closure | ||
507 | * @param zone_key private key of the zone | ||
508 | * @param rname name that is being mapped (at most 255 characters long) | ||
509 | * @param rd_len number of entries in @a rd array | ||
510 | * @param rd array of records with data to store | ||
511 | */ | ||
512 | static void | ||
513 | display_record_lookup (void *cls, | ||
514 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | ||
515 | const char *rname, | ||
516 | unsigned int rd_len, | ||
517 | const struct GNUNET_GNSRECORD_Data *rd) | ||
518 | { | ||
519 | get_qe = NULL; | ||
520 | display_record (rname, | ||
521 | rd_len, | ||
522 | rd); | ||
523 | test_finished (); | ||
524 | } | ||
525 | |||
526 | |||
527 | /** | ||
451 | * Function called once we are in sync in monitor mode. | 528 | * Function called once we are in sync in monitor mode. |
452 | * | 529 | * |
453 | * @param cls NULL | 530 | * @param cls NULL |
@@ -478,12 +555,29 @@ monitor_error_cb (void *cls) | |||
478 | 555 | ||
479 | 556 | ||
480 | /** | 557 | /** |
481 | * Function called if lookup fails. | 558 | * Function called on errors while monitoring. |
559 | * | ||
560 | * @param cls NULL | ||
482 | */ | 561 | */ |
483 | static void | 562 | static void |
484 | lookup_error_cb (void *cls) | 563 | lookup_error_cb (void *cls) |
485 | { | 564 | { |
486 | (void) cls; | 565 | (void) cls; |
566 | get_qe = NULL; | ||
567 | FPRINTF (stderr, | ||
568 | "%s", | ||
569 | "Failed to lookup record.\n"); | ||
570 | test_finished (); | ||
571 | } | ||
572 | |||
573 | |||
574 | /** | ||
575 | * Function called if lookup fails. | ||
576 | */ | ||
577 | static void | ||
578 | add_error_cb (void *cls) | ||
579 | { | ||
580 | (void) cls; | ||
487 | add_qe = NULL; | 581 | add_qe = NULL; |
488 | GNUNET_break (0); | 582 | GNUNET_break (0); |
489 | ret = 1; | 583 | ret = 1; |
@@ -545,14 +639,6 @@ get_existing_record (void *cls, | |||
545 | ret = 1; | 639 | ret = 1; |
546 | test_finished (); | 640 | test_finished (); |
547 | return; | 641 | return; |
548 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: | ||
549 | fprintf (stderr, | ||
550 | _("A %s record exists already under `%s', no other records can be added.\n"), | ||
551 | "GNS2DNS", | ||
552 | rec_name); | ||
553 | ret = 1; | ||
554 | test_finished (); | ||
555 | return; | ||
556 | } | 642 | } |
557 | } | 643 | } |
558 | switch (type) | 644 | switch (type) |
@@ -582,16 +668,16 @@ get_existing_record (void *cls, | |||
582 | } | 668 | } |
583 | break; | 669 | break; |
584 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: | 670 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: |
585 | if (0 != rd_count) | 671 | for (unsigned int i=0;i<rd_count;i++) |
586 | { | 672 | if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type) |
587 | fprintf (stderr, | 673 | { |
588 | _("Records already exist under `%s', cannot add `%s' record.\n"), | 674 | fprintf (stderr, |
589 | rec_name, | 675 | _("Non-GNS2DNS records already exist under `%s', cannot add GNS2DNS record.\n"), |
590 | "GNS2DNS"); | 676 | rec_name); |
591 | ret = 1; | 677 | ret = 1; |
592 | test_finished (); | 678 | test_finished (); |
593 | return; | 679 | return; |
594 | } | 680 | } |
595 | break; | 681 | break; |
596 | } | 682 | } |
597 | memset (rdn, | 683 | memset (rdn, |
@@ -666,12 +752,13 @@ handle_reverse_lookup (void *cls, | |||
666 | reverse_qe = NULL; | 752 | reverse_qe = NULL; |
667 | if (NULL == label) | 753 | if (NULL == label) |
668 | FPRINTF (stdout, | 754 | FPRINTF (stdout, |
669 | "%s.zkey\n", | 755 | "%s\n", |
670 | reverse_pkey); | 756 | reverse_pkey); |
671 | else | 757 | else |
672 | FPRINTF (stdout, | 758 | FPRINTF (stdout, |
673 | "%s.gnu\n", | 759 | "%s.%s\n", |
674 | label); | 760 | label, |
761 | ego_name); | ||
675 | test_finished (); | 762 | test_finished (); |
676 | } | 763 | } |
677 | 764 | ||
@@ -926,7 +1013,7 @@ identity_cb (void *cls, | |||
926 | add_qe = GNUNET_NAMESTORE_records_lookup (ns, | 1013 | add_qe = GNUNET_NAMESTORE_records_lookup (ns, |
927 | &zone_pkey, | 1014 | &zone_pkey, |
928 | name, | 1015 | name, |
929 | &lookup_error_cb, | 1016 | &add_error_cb, |
930 | NULL, | 1017 | NULL, |
931 | &get_existing_record, | 1018 | &get_existing_record, |
932 | NULL); | 1019 | NULL); |
@@ -952,14 +1039,23 @@ identity_cb (void *cls, | |||
952 | } | 1039 | } |
953 | if (list) | 1040 | if (list) |
954 | { | 1041 | { |
955 | list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | 1042 | if (NULL != name) |
956 | &zone_pkey, | 1043 | get_qe = GNUNET_NAMESTORE_records_lookup (ns, |
957 | &zone_iteration_error_cb, | 1044 | &zone_pkey, |
958 | NULL, | 1045 | name, |
959 | &display_record, | 1046 | &lookup_error_cb, |
960 | NULL, | 1047 | NULL, |
961 | &zone_iteration_finished, | 1048 | &display_record_lookup, |
962 | NULL); | 1049 | NULL); |
1050 | else | ||
1051 | list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | ||
1052 | &zone_pkey, | ||
1053 | &zone_iteration_error_cb, | ||
1054 | NULL, | ||
1055 | &display_record_iterator, | ||
1056 | NULL, | ||
1057 | &zone_iteration_finished, | ||
1058 | NULL); | ||
963 | } | 1059 | } |
964 | if (NULL != reverse_pkey) | 1060 | if (NULL != reverse_pkey) |
965 | { | 1061 | { |
@@ -1054,7 +1150,7 @@ identity_cb (void *cls, | |||
1054 | GNUNET_YES, | 1150 | GNUNET_YES, |
1055 | &monitor_error_cb, | 1151 | &monitor_error_cb, |
1056 | NULL, | 1152 | NULL, |
1057 | &display_record, | 1153 | &display_record_monitor, |
1058 | NULL, | 1154 | NULL, |
1059 | &sync_cb, | 1155 | &sync_cb, |
1060 | NULL); | 1156 | NULL); |