diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-02 12:15:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-02 12:15:35 +0000 |
commit | 42b829bb6005f07403370931509d0f83b4235e15 (patch) | |
tree | dc70bfbb15271f45443e2d2267bfb3cb3fa490b1 /src/namestore/gnunet-service-namestore.c | |
parent | 98bbddca603be552e75903ac6ac5f44b9388977c (diff) | |
download | gnunet-42b829bb6005f07403370931509d0f83b4235e15.tar.gz gnunet-42b829bb6005f07403370931509d0f83b4235e15.zip |
-address #3050, refresh encrypted blocks from plaintext blocks during iteration, compute block expiration time correctly
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 108 |
1 files changed, 74 insertions, 34 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 4c64dcd29..b39d3858c 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -552,6 +552,45 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc, | |||
552 | 552 | ||
553 | 553 | ||
554 | /** | 554 | /** |
555 | * We just touched the plaintext information about a name in our zone; | ||
556 | * refresh the corresponding (encrypted) block in the namestore. | ||
557 | * | ||
558 | * @param zone_key private key of the zone | ||
559 | * @param name label for the records | ||
560 | * @param rd_count number of records | ||
561 | * @param rd records stored under the given @a name | ||
562 | */ | ||
563 | static void | ||
564 | refresh_block (const struct GNUNET_CRYPTO_EccPrivateKey *zone_key, | ||
565 | const char *name, | ||
566 | unsigned int rd_count, | ||
567 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
568 | { | ||
569 | struct GNUNET_NAMESTORE_Block *block; | ||
570 | |||
571 | if (0 == rd_count) | ||
572 | block = GNUNET_NAMESTORE_block_create (zone_key, | ||
573 | GNUNET_TIME_UNIT_ZERO_ABS, | ||
574 | name, | ||
575 | rd, rd_count); | ||
576 | else | ||
577 | block = GNUNET_NAMESTORE_block_create (zone_key, | ||
578 | GNUNET_NAMESTORE_record_get_expiration_time (rd_count, | ||
579 | rd), | ||
580 | name, | ||
581 | rd, rd_count); | ||
582 | if (GNUNET_OK != | ||
583 | GSN_database->cache_block (GSN_database->cls, | ||
584 | block)) | ||
585 | { | ||
586 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
587 | _("Failed to cache encrypted block of my own zone!\n")); | ||
588 | } | ||
589 | GNUNET_free (block); | ||
590 | } | ||
591 | |||
592 | |||
593 | /** | ||
555 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message | 594 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message |
556 | * | 595 | * |
557 | * @param cls unused | 596 | * @param cls unused |
@@ -577,6 +616,7 @@ handle_record_store (void *cls, | |||
577 | unsigned int rd_count; | 616 | unsigned int rd_count; |
578 | int res; | 617 | int res; |
579 | struct GNUNET_CRYPTO_EccPublicSignKey pubkey; | 618 | struct GNUNET_CRYPTO_EccPublicSignKey pubkey; |
619 | struct ZoneMonitor *zm; | ||
580 | 620 | ||
581 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 621 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
582 | "Received `%s' message\n", | 622 | "Received `%s' message\n", |
@@ -644,7 +684,10 @@ handle_record_store (void *cls, | |||
644 | conv_name, | 684 | conv_name, |
645 | GNUNET_NAMESTORE_z2s (&pubkey)); | 685 | GNUNET_NAMESTORE_z2s (&pubkey)); |
646 | 686 | ||
647 | if ((rd_count == 0) && (GNUNET_NO == GSN_database->iterate_records (GSN_database->cls, &rp_msg->private_key, 0, NULL, 0))) | 687 | if ( (0 == rd_count) && |
688 | (GNUNET_NO == | ||
689 | GSN_database->iterate_records (GSN_database->cls, | ||
690 | &rp_msg->private_key, 0, NULL, 0)) ) | ||
648 | { | 691 | { |
649 | /* This name does not exist, so cannot be removed */ | 692 | /* This name does not exist, so cannot be removed */ |
650 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 693 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -660,39 +703,20 @@ handle_record_store (void *cls, | |||
660 | rd_count, rd); | 703 | rd_count, rd); |
661 | if (GNUNET_OK == res) | 704 | if (GNUNET_OK == res) |
662 | { | 705 | { |
663 | struct ZoneMonitor *zm; | 706 | refresh_block (&rp_msg->private_key, |
664 | struct GNUNET_NAMESTORE_Block *block; | 707 | conv_name, |
665 | 708 | rd_count, rd); | |
666 | if (0 == rd_count) | 709 | |
667 | block = GNUNET_NAMESTORE_block_create (&rp_msg->private_key, | 710 | for (zm = monitor_head; NULL != zm; zm = zm->next) |
668 | GNUNET_TIME_UNIT_ZERO_ABS, | 711 | if (0 == memcmp (&rp_msg->private_key, &zm->zone, |
669 | conv_name, | 712 | sizeof (struct GNUNET_CRYPTO_EccPrivateKey))) |
670 | rd, rd_count); | 713 | send_lookup_response (monitor_nc, |
671 | else | 714 | zm->nc->client, |
672 | block = GNUNET_NAMESTORE_block_create (&rp_msg->private_key, | 715 | zm->request_id, |
673 | GNUNET_TIME_UNIT_FOREVER_ABS, | 716 | &rp_msg->private_key, |
674 | conv_name, | 717 | conv_name, |
675 | rd, rd_count); | 718 | rd_count, rd); |
676 | if (GNUNET_OK != | 719 | } |
677 | GSN_database->cache_block (GSN_database->cls, | ||
678 | block)) | ||
679 | { | ||
680 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
681 | _("Failed to cache encrypted block of my own zone!\n")); | ||
682 | res = GNUNET_SYSERR; | ||
683 | } | ||
684 | GNUNET_free (block); | ||
685 | |||
686 | for (zm = monitor_head; NULL != zm; zm = zm->next) | ||
687 | if (0 == memcmp (&rp_msg->private_key, &zm->zone, | ||
688 | sizeof (struct GNUNET_CRYPTO_EccPrivateKey))) | ||
689 | send_lookup_response (monitor_nc, | ||
690 | zm->nc->client, | ||
691 | zm->request_id, | ||
692 | &rp_msg->private_key, | ||
693 | conv_name, | ||
694 | rd_count, rd); | ||
695 | } | ||
696 | GNUNET_free (conv_name); | 720 | GNUNET_free (conv_name); |
697 | } | 721 | } |
698 | } | 722 | } |
@@ -914,6 +938,8 @@ zone_iteraterate_proc (void *cls, | |||
914 | const struct GNUNET_NAMESTORE_RecordData *rd) | 938 | const struct GNUNET_NAMESTORE_RecordData *rd) |
915 | { | 939 | { |
916 | struct ZoneIterationProcResult *proc = cls; | 940 | struct ZoneIterationProcResult *proc = cls; |
941 | unsigned int i; | ||
942 | int do_refresh_block; | ||
917 | 943 | ||
918 | if ((NULL == zone_key) && (NULL == name)) | 944 | if ((NULL == zone_key) && (NULL == name)) |
919 | { | 945 | { |
@@ -937,6 +963,20 @@ zone_iteraterate_proc (void *cls, | |||
937 | name, | 963 | name, |
938 | rd_count, | 964 | rd_count, |
939 | rd); | 965 | rd); |
966 | do_refresh_block = GNUNET_NO; | ||
967 | for (i=0;i<rd_count;i++) | ||
968 | if( (0 != (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)) && | ||
969 | (0 == (rd[i].flags & GNUNET_NAMESTORE_RF_PENDING)) ) | ||
970 | { | ||
971 | do_refresh_block = GNUNET_YES; | ||
972 | break; | ||
973 | } | ||
974 | if (GNUNET_YES == do_refresh_block) | ||
975 | refresh_block (zone_key, | ||
976 | name, | ||
977 | rd_count, | ||
978 | rd); | ||
979 | |||
940 | } | 980 | } |
941 | 981 | ||
942 | 982 | ||