aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-service-namestore.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r--src/namestore/gnunet-service-namestore.c79
1 files changed, 54 insertions, 25 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 7483c0a89..e67ffaa65 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -228,11 +228,24 @@ get_block_expiration_time (unsigned int rd_count, const struct GNUNET_NAMESTORE_
228{ 228{
229 unsigned int c; 229 unsigned int c;
230 struct GNUNET_TIME_Absolute expire = GNUNET_TIME_UNIT_FOREVER_ABS; 230 struct GNUNET_TIME_Absolute expire = GNUNET_TIME_UNIT_FOREVER_ABS;
231 struct GNUNET_TIME_Absolute at;
232 struct GNUNET_TIME_Relative rt;
231 233
232 if (NULL == rd) 234 if (NULL == rd)
233 return GNUNET_TIME_UNIT_ZERO_ABS; 235 return GNUNET_TIME_UNIT_ZERO_ABS;
234 for (c = 0; c < rd_count; c++) 236 for (c = 0; c < rd_count; c++)
235 expire = GNUNET_TIME_absolute_min (rd[c].expiration, expire); 237 {
238 if (0 != (rd[c].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION))
239 {
240 rt.rel_value = rd[c].expiration_time;
241 at = GNUNET_TIME_relative_to_absolute (rt);
242 }
243 else
244 {
245 at.abs_value = rd[c].expiration_time;
246 }
247 expire = GNUNET_TIME_absolute_min (at, expire);
248 }
236 return expire; 249 return expire;
237} 250}
238 251
@@ -725,12 +738,12 @@ struct CreateRecordContext
725 738
726static void 739static void
727handle_create_record_it (void *cls, 740handle_create_record_it (void *cls,
728 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey, 741 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey,
729 struct GNUNET_TIME_Absolute expire, 742 struct GNUNET_TIME_Absolute expire,
730 const char *name, 743 const char *name,
731 unsigned int rd_count, 744 unsigned int rd_count,
732 const struct GNUNET_NAMESTORE_RecordData *rd, 745 const struct GNUNET_NAMESTORE_RecordData *rd,
733 const struct GNUNET_CRYPTO_RsaSignature *signature) 746 const struct GNUNET_CRYPTO_RsaSignature *signature)
734{ 747{
735 struct CreateRecordContext * crc = cls; 748 struct CreateRecordContext * crc = cls;
736 struct GNUNET_NAMESTORE_RecordData *rd_new = NULL; 749 struct GNUNET_NAMESTORE_RecordData *rd_new = NULL;
@@ -745,37 +758,43 @@ handle_create_record_it (void *cls,
745 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u existing records for `%s'\n", rd_count, crc->name); 758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u existing records for `%s'\n", rd_count, crc->name);
746 for (c = 0; c < rd_count; c++) 759 for (c = 0; c < rd_count; c++)
747 { 760 {
748 if ((crc->rd->record_type == GNUNET_NAMESTORE_TYPE_PKEY) && (rd[c].record_type == GNUNET_NAMESTORE_TYPE_PKEY)) 761 if ( (crc->rd->record_type == GNUNET_NAMESTORE_TYPE_PKEY) &&
762 (rd[c].record_type == GNUNET_NAMESTORE_TYPE_PKEY))
749 { 763 {
750 /* Update unique PKEY */ 764 /* Update unique PKEY */
751 exist = c; 765 exist = c;
752 update = GNUNET_YES; 766 update = GNUNET_YES;
753 break; 767 break;
754 } 768 }
755 else if ((crc->rd->record_type == GNUNET_NAMESTORE_TYPE_PSEU) && (rd[c].record_type == GNUNET_NAMESTORE_TYPE_PSEU)) 769 if ( (crc->rd->record_type == GNUNET_NAMESTORE_TYPE_PSEU) &&
770 (rd[c].record_type == GNUNET_NAMESTORE_TYPE_PSEU))
756 { 771 {
757 /* Update unique PSEU */ 772 /* Update unique PSEU */
758 exist = c; 773 exist = c;
759 update = GNUNET_YES; 774 update = GNUNET_YES;
760 break; 775 break;
761 } 776 }
762 else if ((crc->rd->record_type == rd[c].record_type) && 777 if ((crc->rd->record_type == rd[c].record_type) &&
763 (crc->rd->data_size == rd[c].data_size) && 778 (crc->rd->data_size == rd[c].data_size) &&
764 (0 == memcmp (crc->rd->data, rd[c].data, rd[c].data_size))) 779 (0 == memcmp (crc->rd->data, rd[c].data, rd[c].data_size)))
765 { 780 {
766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found existing records for `%s' to update expiration date!\n", crc->name); 781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
782 "Found existing records for `%s' to update expiration date!\n",
783 crc->name);
767 exist = c; 784 exist = c;
768 if (crc->rd->expiration.abs_value != rd[c].expiration.abs_value) 785 if ( (crc->rd->expiration_time != rd[c].expiration_time) &&
786 ((crc->rd->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)
787 == (rd[c].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION) ) )
769 update = GNUNET_YES; 788 update = GNUNET_YES;
770 break; 789 break;
771 } 790 }
772 } 791 }
773 792
774 if (exist == GNUNET_SYSERR) 793 if (exist == GNUNET_SYSERR)
775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New record does not exist for name `%s'!\n", crc->name);
776
777 if (exist == GNUNET_SYSERR)
778 { 794 {
795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
796 "No existing record for name `%s'!\n",
797 crc->name);
779 rd_new = GNUNET_malloc ((rd_count+1) * sizeof (struct GNUNET_NAMESTORE_RecordData)); 798 rd_new = GNUNET_malloc ((rd_count+1) * sizeof (struct GNUNET_NAMESTORE_RecordData));
780 memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData)); 799 memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
781 rd_count_new = rd_count + 1; 800 rd_count_new = rd_count + 1;
@@ -784,24 +803,34 @@ handle_create_record_it (void *cls,
784 else if (update == GNUNET_NO) 803 else if (update == GNUNET_NO)
785 { 804 {
786 /* Exact same record already exists */ 805 /* Exact same record already exists */
787 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No update for %s' record required!\n", crc->name); 806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
807 "Matching record for %s' exists, no change required!\n",
808 crc->name);
788 res = GNUNET_NO; 809 res = GNUNET_NO;
789 goto end; 810 goto end;
790 } 811 }
791 else if (update == GNUNET_YES) 812 else
792 { 813 {
793 /* Update record */ 814 /* Update record */
794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating existing records for `%s'!\n", crc->name); 815 GNUNET_assert (GNUNET_YES == update);
816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
817 "Updating existing records for `%s'!\n",
818 crc->name);
795 rd_new = GNUNET_malloc ((rd_count) * sizeof (struct GNUNET_NAMESTORE_RecordData)); 819 rd_new = GNUNET_malloc ((rd_count) * sizeof (struct GNUNET_NAMESTORE_RecordData));
796 memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData)); 820 memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
797 rd_count_new = rd_count; 821 rd_count_new = rd_count;
798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating expiration from %llu to %llu!\n", rd_new[exist].expiration.abs_value, crc->rd->expiration.abs_value); 822 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
823 (0 == (crc->rd->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION))
824 ? "Updating absolute expiration from %llu to %llu!\n"
825 : "Updating relative expiration from %llu to %llu!\n",
826 rd_new[exist].expiration_time, crc->rd->expiration_time);
799 rd_new[exist] = *(crc->rd); 827 rd_new[exist] = *(crc->rd);
800 } 828 }
801 829
802 block_expiration = GNUNET_TIME_absolute_max(crc->expire, expire); 830 block_expiration = GNUNET_TIME_absolute_max(crc->expire, expire);
803 if (block_expiration.abs_value != expire.abs_value) 831 if (block_expiration.abs_value != expire.abs_value)
804 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updated block expiration time\n"); 832 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
833 "Updated block expiration time\n");
805 834
806 memset (&dummy_signature, '\0', sizeof (dummy_signature)); 835 memset (&dummy_signature, '\0', sizeof (dummy_signature));
807 836