diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/plugin_gnsrecord_gns.c | 16 | ||||
-rw-r--r-- | src/gnsrecord/gnsrecord_misc.c | 54 | ||||
-rw-r--r-- | src/gnsrecord/gnunet-gnsrecord-tvg.c | 6 | ||||
-rw-r--r-- | src/include/gnunet_gnsrecord_lib.h | 22 | ||||
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 108 | ||||
-rw-r--r-- | src/namestore/namestore.h | 6 | ||||
-rw-r--r-- | src/namestore/namestore_api.c | 36 | ||||
-rw-r--r-- | src/zonemaster/Makefile.am | 6 | ||||
-rw-r--r-- | src/zonemaster/gnunet-service-zonemaster-monitor.c | 89 | ||||
-rw-r--r-- | src/zonemaster/gnunet-service-zonemaster.c | 88 | ||||
-rw-r--r-- | src/zonemaster/zonemaster_misc.c | 132 | ||||
-rw-r--r-- | src/zonemaster/zonemaster_misc.h | 62 |
12 files changed, 142 insertions, 483 deletions
diff --git a/src/gns/plugin_gnsrecord_gns.c b/src/gns/plugin_gnsrecord_gns.c index 694dc6351..beeeda295 100644 --- a/src/gns/plugin_gnsrecord_gns.c +++ b/src/gns/plugin_gnsrecord_gns.c | |||
@@ -133,10 +133,7 @@ gns_value_to_string (void *cls, | |||
133 | return box_str; | 133 | return box_str; |
134 | } | 134 | } |
135 | case GNUNET_GNSRECORD_TYPE_TOMBSTONE: { | 135 | case GNUNET_GNSRECORD_TYPE_TOMBSTONE: { |
136 | const struct GNUNET_GNSRECORD_TombstoneRecord *ts = data; | 136 | return GNUNET_strdup ("\u271E"); |
137 | struct GNUNET_TIME_Absolute tod; | ||
138 | tod = GNUNET_TIME_absolute_ntoh (ts->time_of_death); | ||
139 | return GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (tod)); | ||
140 | } | 137 | } |
141 | default: | 138 | default: |
142 | return NULL; | 139 | return NULL; |
@@ -303,15 +300,8 @@ gns_string_to_value (void *cls, | |||
303 | return GNUNET_OK; | 300 | return GNUNET_OK; |
304 | } | 301 | } |
305 | case GNUNET_GNSRECORD_TYPE_TOMBSTONE: { | 302 | case GNUNET_GNSRECORD_TYPE_TOMBSTONE: { |
306 | struct GNUNET_TIME_Absolute tod; | 303 | *data_size = 0; |
307 | struct GNUNET_TIME_AbsoluteNBO *tod_nbo; | 304 | *data = NULL; |
308 | if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (s, | ||
309 | &tod)) | ||
310 | return GNUNET_SYSERR; | ||
311 | tod_nbo = GNUNET_new (struct GNUNET_TIME_AbsoluteNBO); | ||
312 | *tod_nbo = GNUNET_TIME_absolute_hton (tod); | ||
313 | *data_size = sizeof (*tod_nbo); | ||
314 | *data = tod_nbo; | ||
315 | return GNUNET_OK; | 305 | return GNUNET_OK; |
316 | } | 306 | } |
317 | 307 | ||
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c index 61604c730..5c20dbedc 100644 --- a/src/gnsrecord/gnsrecord_misc.c +++ b/src/gnsrecord/gnsrecord_misc.c | |||
@@ -144,19 +144,11 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, | |||
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | /** | ||
148 | * Returns the expiration time of the given block of records. The block | ||
149 | * expiration time is the expiration time of the record with smallest | ||
150 | * expiration time. | ||
151 | * | ||
152 | * @param rd_count number of records given in @a rd | ||
153 | * @param rd array of records | ||
154 | * @return absolute expiration time | ||
155 | */ | ||
156 | struct GNUNET_TIME_Absolute | 147 | struct GNUNET_TIME_Absolute |
157 | GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count, | 148 | GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count, |
158 | const struct | 149 | const struct |
159 | GNUNET_GNSRECORD_Data *rd) | 150 | GNUNET_GNSRECORD_Data *rd, |
151 | struct GNUNET_TIME_Absolute min) | ||
160 | { | 152 | { |
161 | struct GNUNET_TIME_Absolute expire; | 153 | struct GNUNET_TIME_Absolute expire; |
162 | struct GNUNET_TIME_Absolute at; | 154 | struct GNUNET_TIME_Absolute at; |
@@ -202,6 +194,7 @@ GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count, | |||
202 | expire = GNUNET_TIME_absolute_min (at, | 194 | expire = GNUNET_TIME_absolute_min (at, |
203 | expire); | 195 | expire); |
204 | } | 196 | } |
197 | expire = GNUNET_TIME_absolute_min (expire, min); | ||
205 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 198 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
206 | "Determined expiration time for block with %u records to be %s\n", | 199 | "Determined expiration time for block with %u records to be %s\n", |
207 | rd_count, | 200 | rd_count, |
@@ -406,5 +399,46 @@ GNUNET_GNSRECORD_record_to_identity_key (const struct GNUNET_GNSRECORD_Data *rd, | |||
406 | 399 | ||
407 | } | 400 | } |
408 | 401 | ||
402 | unsigned int | ||
403 | GNUNET_GNSRECORD_convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd, | ||
404 | unsigned int rd_count, | ||
405 | struct GNUNET_GNSRECORD_Data *rd_public, | ||
406 | struct GNUNET_TIME_Absolute *expiry) | ||
407 | { | ||
408 | struct GNUNET_TIME_Absolute expiry_tombstone; | ||
409 | struct GNUNET_TIME_Absolute now; | ||
410 | struct GNUNET_TIME_Absolute minimum_expiration; | ||
411 | unsigned int rd_public_count; | ||
412 | |||
413 | rd_public_count = 0; | ||
414 | minimum_expiration = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
415 | now = GNUNET_TIME_absolute_get (); | ||
416 | for (unsigned int i = 0; i < rd_count; i++) | ||
417 | { | ||
418 | if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type) | ||
419 | { | ||
420 | minimum_expiration.abs_value_us = rd[i].expiration_time; | ||
421 | continue; | ||
422 | } | ||
423 | if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) | ||
424 | continue; | ||
425 | if ((0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) && | ||
426 | (rd[i].expiration_time < now.abs_value_us)) | ||
427 | continue; /* record already expired, skip it */ | ||
428 | rd_public[rd_public_count] = rd[i]; | ||
429 | /* Make sure critical record types are published as such */ | ||
430 | if (GNUNET_YES == GNUNET_GNSRECORD_is_critical (rd[i].record_type)) | ||
431 | rd_public[rd_public_count].flags |= GNUNET_GNSRECORD_RF_CRITICAL; | ||
432 | rd_public_count++; | ||
433 | } | ||
434 | |||
435 | *expiry = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count, | ||
436 | rd_public, | ||
437 | minimum_expiration); | ||
438 | |||
439 | return rd_public_count; | ||
440 | } | ||
441 | |||
442 | |||
409 | 443 | ||
410 | /* end of gnsrecord_misc.c */ | 444 | /* end of gnsrecord_misc.c */ |
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c index f9b83e48b..dec0855eb 100644 --- a/src/gnsrecord/gnunet-gnsrecord-tvg.c +++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c | |||
@@ -212,7 +212,8 @@ run_pkey (void) | |||
212 | fprintf (stdout, "RDATA:\n"); | 212 | fprintf (stdout, "RDATA:\n"); |
213 | print_bytes (rdata, rdata_size, 8); | 213 | print_bytes (rdata, rdata_size, 8); |
214 | fprintf (stdout, "\n"); | 214 | fprintf (stdout, "\n"); |
215 | expire = GNUNET_GNSRECORD_record_get_expiration_time (TEST_RRCOUNT, rd); | 215 | expire = GNUNET_GNSRECORD_record_get_expiration_time (TEST_RRCOUNT, rd, |
216 | GNUNET_TIME_UNIT_FOREVER_ABS); | ||
216 | GNR_derive_block_aes_key (ctr, | 217 | GNR_derive_block_aes_key (ctr, |
217 | skey, | 218 | skey, |
218 | TEST_RECORD_LABEL, | 219 | TEST_RECORD_LABEL, |
@@ -348,7 +349,8 @@ run_edkey (void) | |||
348 | rdata_size = GNUNET_GNSRECORD_records_get_size (TEST_RRCOUNT, | 349 | rdata_size = GNUNET_GNSRECORD_records_get_size (TEST_RRCOUNT, |
349 | rd); | 350 | rd); |
350 | expire = GNUNET_GNSRECORD_record_get_expiration_time (TEST_RRCOUNT, | 351 | expire = GNUNET_GNSRECORD_record_get_expiration_time (TEST_RRCOUNT, |
351 | rd); | 352 | rd, |
353 | GNUNET_TIME_UNIT_FOREVER_ABS); | ||
352 | rdata = GNUNET_malloc (rdata_size); | 354 | rdata = GNUNET_malloc (rdata_size); |
353 | GNUNET_GNSRECORD_records_serialize (2, | 355 | GNUNET_GNSRECORD_records_serialize (2, |
354 | rd, | 356 | rd, |
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h index 7d30055fc..fd630b987 100644 --- a/src/include/gnunet_gnsrecord_lib.h +++ b/src/include/gnunet_gnsrecord_lib.h | |||
@@ -631,11 +631,13 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, | |||
631 | * | 631 | * |
632 | * @param rd_count number of records given in @a rd | 632 | * @param rd_count number of records given in @a rd |
633 | * @param rd array of records | 633 | * @param rd array of records |
634 | * @param min minimum expiration time | ||
634 | * @return absolute expiration time | 635 | * @return absolute expiration time |
635 | */ | 636 | */ |
636 | struct GNUNET_TIME_Absolute | 637 | struct GNUNET_TIME_Absolute |
637 | GNUNET_GNSRECORD_record_get_expiration_time ( | 638 | GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count, |
638 | unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd); | 639 | const struct GNUNET_GNSRECORD_Data *rd, |
640 | struct GNUNET_TIME_Absolute min); | ||
639 | 641 | ||
640 | 642 | ||
641 | /** | 643 | /** |
@@ -724,6 +726,22 @@ GNUNET_GNSRECORD_is_zonekey_type (uint32_t type); | |||
724 | enum GNUNET_GenericReturnValue | 726 | enum GNUNET_GenericReturnValue |
725 | GNUNET_GNSRECORD_is_critical (uint32_t type); | 727 | GNUNET_GNSRECORD_is_critical (uint32_t type); |
726 | 728 | ||
729 | /** | ||
730 | * Convert namestore records from the internal format to that | ||
731 | * suitable for publication (removes private records, converts | ||
732 | * to absolute expiration time). | ||
733 | * | ||
734 | * @param rd input records | ||
735 | * @param rd_count size of the @a rd and @a rd_public arrays | ||
736 | * @param rd_public where to write the converted records | ||
737 | * @param expiry the expiration of the block | ||
738 | * @return number of records written to @a rd_public | ||
739 | */ | ||
740 | unsigned int | ||
741 | GNUNET_GNSRECORD_convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd, | ||
742 | unsigned int rd_count, | ||
743 | struct GNUNET_GNSRECORD_Data *rd_public, | ||
744 | struct GNUNET_TIME_Absolute *expiry); | ||
727 | 745 | ||
728 | #if 0 /* keep Emacsens' auto-indent happy */ | 746 | #if 0 /* keep Emacsens' auto-indent happy */ |
729 | { | 747 | { |
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 7669e90f5..acf49de9e 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -948,7 +948,8 @@ refresh_block (struct NamestoreClient *nc, | |||
948 | GNUNET_free (res); | 948 | GNUNET_free (res); |
949 | return; | 949 | return; |
950 | } | 950 | } |
951 | exp_time = GNUNET_GNSRECORD_record_get_expiration_time (res_count, res); | 951 | exp_time = GNUNET_GNSRECORD_record_get_expiration_time (res_count, res, |
952 | GNUNET_TIME_UNIT_FOREVER_ABS); | ||
952 | if (cache_keys) | 953 | if (cache_keys) |
953 | GNUNET_assert (GNUNET_OK == | 954 | GNUNET_assert (GNUNET_OK == |
954 | GNUNET_GNSRECORD_block_create2 (zone_key, exp_time, name, | 955 | GNUNET_GNSRECORD_block_create2 (zone_key, exp_time, name, |
@@ -1461,25 +1462,21 @@ check_record_store (void *cls, const struct RecordStoreMessage *rp_msg) | |||
1461 | * @param rd records stored under @a label in the zone | 1462 | * @param rd records stored under @a label in the zone |
1462 | */ | 1463 | */ |
1463 | static void | 1464 | static void |
1464 | lookup_tombstone_it (void *cls, | 1465 | get_block_exp_existing (void *cls, |
1465 | uint64_t seq, | 1466 | uint64_t seq, |
1466 | const struct GNUNET_IDENTITY_PrivateKey *private_key, | 1467 | const struct |
1467 | const char *label, | 1468 | GNUNET_IDENTITY_PrivateKey *private_key, |
1468 | unsigned int rd_count, | 1469 | const char *label, |
1469 | const struct GNUNET_GNSRECORD_Data *rd) | 1470 | unsigned int rd_count, |
1471 | const struct GNUNET_GNSRECORD_Data *rd) | ||
1470 | { | 1472 | { |
1471 | struct GNUNET_GNSRECORD_TombstoneRecord *ts = cls; | 1473 | struct GNUNET_TIME_Absolute *exp = cls; |
1474 | struct GNUNET_GNSRECORD_Data rd_pub[rd_count]; | ||
1472 | 1475 | ||
1473 | (void) private_key; | 1476 | GNUNET_GNSRECORD_convert_records_for_export (rd, |
1474 | GNUNET_assert (0 != seq); | 1477 | rd_count, |
1475 | for (unsigned int c = 0; c < rd_count; c++) | 1478 | rd_pub, |
1476 | { | 1479 | exp); |
1477 | if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[c].record_type) | ||
1478 | { | ||
1479 | memcpy (ts, rd[c].data, rd[c].data_size); | ||
1480 | return; | ||
1481 | } | ||
1482 | } | ||
1483 | } | 1480 | } |
1484 | 1481 | ||
1485 | 1482 | ||
@@ -1502,11 +1499,14 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) | |||
1502 | unsigned int rd_count; | 1499 | unsigned int rd_count; |
1503 | int res; | 1500 | int res; |
1504 | struct StoreActivity *sa; | 1501 | struct StoreActivity *sa; |
1505 | struct GNUNET_GNSRECORD_TombstoneRecord tombstone; | 1502 | struct GNUNET_TIME_Absolute existing_block_exp; |
1503 | struct GNUNET_TIME_Absolute new_block_exp; | ||
1504 | struct GNUNET_GNSRECORD_Data *tombstone_record; | ||
1506 | 1505 | ||
1507 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1508 | "Received NAMESTORE_RECORD_STORE message\n"); | 1507 | "Received NAMESTORE_RECORD_STORE message\n"); |
1509 | tombstone.time_of_death.abs_value_us__ = 0; | 1508 | existing_block_exp.abs_value_us = 0; |
1509 | tombstone_record = NULL; | ||
1510 | rid = ntohl (rp_msg->gns_header.r_id); | 1510 | rid = ntohl (rp_msg->gns_header.r_id); |
1511 | name_len = ntohs (rp_msg->name_len); | 1511 | name_len = ntohs (rp_msg->name_len); |
1512 | rd_count = ntohs (rp_msg->rd_count); | 1512 | rd_count = ntohs (rp_msg->rd_count); |
@@ -1545,8 +1545,8 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) | |||
1545 | if ((GNUNET_NO == GSN_database->lookup_records (GSN_database->cls, | 1545 | if ((GNUNET_NO == GSN_database->lookup_records (GSN_database->cls, |
1546 | &rp_msg->private_key, | 1546 | &rp_msg->private_key, |
1547 | conv_name, | 1547 | conv_name, |
1548 | &lookup_tombstone_it, | 1548 | &get_block_exp_existing, |
1549 | &tombstone)) && | 1549 | &existing_block_exp)) && |
1550 | (rd_count == 0)) | 1550 | (rd_count == 0)) |
1551 | { | 1551 | { |
1552 | /* This name does not exist, so cannot be removed */ | 1552 | /* This name does not exist, so cannot be removed */ |
@@ -1559,28 +1559,20 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) | |||
1559 | { | 1559 | { |
1560 | /* remove "NICK" records, unless this is for the | 1560 | /* remove "NICK" records, unless this is for the |
1561 | #GNUNET_GNS_EMPTY_LABEL_AT label | 1561 | #GNUNET_GNS_EMPTY_LABEL_AT label |
1562 | Also, add or update tombstone record if this is a zonemaster request. | 1562 | We may need one additional record later for tombstone. |
1563 | Also, add existing tombstone record to set if this is not a zonemaster | 1563 | */ |
1564 | request if one existed in the old set. | ||
1565 | This is why we (may) need one additional record */ | ||
1566 | struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL (rd_count) + 1]; | 1564 | struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL (rd_count) + 1]; |
1567 | unsigned int rd_clean_off; | 1565 | unsigned int rd_clean_off; |
1568 | int have_nick; | 1566 | int have_nick; |
1569 | int have_tombstone; | ||
1570 | 1567 | ||
1571 | rd_clean_off = 0; | 1568 | rd_clean_off = 0; |
1572 | have_nick = GNUNET_NO; | 1569 | have_nick = GNUNET_NO; |
1573 | have_tombstone = GNUNET_NO; | ||
1574 | for (unsigned int i = 0; i < rd_count; i++) | 1570 | for (unsigned int i = 0; i < rd_count; i++) |
1575 | { | 1571 | { |
1576 | /* Do not allow to set tombstone records unless zonemaster */ | 1572 | /* Do not allow to set tombstone records unless zonemaster */ |
1577 | if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type) | ||
1578 | { | ||
1579 | if (1 != ntohs (rp_msg->is_zonemaster)) | ||
1580 | continue; | ||
1581 | have_tombstone = GNUNET_YES; | ||
1582 | } | ||
1583 | rd_clean[rd_clean_off] = rd[i]; | 1573 | rd_clean[rd_clean_off] = rd[i]; |
1574 | if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type) | ||
1575 | tombstone_record = &rd_clean[rd_clean_off]; | ||
1584 | if (GNUNET_YES == GNUNET_GNSRECORD_is_critical (rd[i].record_type)) | 1576 | if (GNUNET_YES == GNUNET_GNSRECORD_is_critical (rd[i].record_type)) |
1585 | rd_clean[rd_clean_off].flags |= GNUNET_GNSRECORD_RF_CRITICAL; | 1577 | rd_clean[rd_clean_off].flags |= GNUNET_GNSRECORD_RF_CRITICAL; |
1586 | 1578 | ||
@@ -1595,24 +1587,38 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) | |||
1595 | have_nick = GNUNET_YES; | 1587 | have_nick = GNUNET_YES; |
1596 | } | 1588 | } |
1597 | } | 1589 | } |
1598 | /* At this point we are either zonemaster and have set a new tombstone | 1590 | GNUNET_GNSRECORD_convert_records_for_export (rd, |
1599 | * (have_tombstone) | 1591 | rd_clean_off, |
1600 | * or we are not zonemaster and we may want to | 1592 | rd_clean, |
1601 | * add the old tombstone (if there was any and if it is not already | 1593 | &new_block_exp); |
1602 | * old). | 1594 | /* |
1595 | * If existing_block_exp is 0, then there was not record set | ||
1596 | * and no tombstone. | ||
1597 | * Otherwise, if the existing block expiration is after the | ||
1598 | * new block expiration would be, we need to add a tombstone | ||
1599 | * or update it. | ||
1603 | */ | 1600 | */ |
1604 | if ((GNUNET_NO == have_tombstone) && | 1601 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1605 | GNUNET_TIME_absolute_cmp ( | 1602 | "New exp: %s\n", |
1606 | GNUNET_TIME_absolute_get (), <, GNUNET_TIME_absolute_ntoh ( | 1603 | GNUNET_STRINGS_absolute_time_to_string (new_block_exp)); |
1607 | tombstone.time_of_death))) | 1604 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1605 | "Old exp: %s\n", | ||
1606 | GNUNET_STRINGS_absolute_time_to_string (existing_block_exp)); | ||
1607 | if (GNUNET_TIME_absolute_cmp (new_block_exp, <=, existing_block_exp)) | ||
1608 | { | 1608 | { |
1609 | rd_clean[rd_clean_off].record_type = GNUNET_GNSRECORD_TYPE_TOMBSTONE; | 1609 | /* There was already a TS record in the set given */ |
1610 | rd_clean[rd_clean_off].expiration_time = | 1610 | if (NULL != tombstone_record) |
1611 | GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 1611 | { |
1612 | rd_clean[rd_clean_off].data = &tombstone; | 1612 | tombstone_record->expiration_time = existing_block_exp.abs_value_us; |
1613 | rd_clean[rd_clean_off].data_size = sizeof (tombstone); | 1613 | } |
1614 | rd_clean[rd_clean_off].flags |= GNUNET_GNSRECORD_RF_PRIVATE; | 1614 | else { |
1615 | rd_clean_off++; | 1615 | rd_clean[rd_clean_off].record_type = GNUNET_GNSRECORD_TYPE_TOMBSTONE; |
1616 | rd_clean[rd_clean_off].expiration_time = existing_block_exp.abs_value_us; | ||
1617 | rd_clean[rd_clean_off].data = NULL; | ||
1618 | rd_clean[rd_clean_off].data_size = 0; | ||
1619 | rd_clean[rd_clean_off].flags |= GNUNET_GNSRECORD_RF_PRIVATE; | ||
1620 | rd_clean_off++; | ||
1621 | } | ||
1616 | } | 1622 | } |
1617 | if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) && | 1623 | if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) && |
1618 | (GNUNET_NO == have_nick)) | 1624 | (GNUNET_NO == have_nick)) |
@@ -1627,7 +1633,7 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) | |||
1627 | rd_clean); | 1633 | rd_clean); |
1628 | } | 1634 | } |
1629 | 1635 | ||
1630 | if ((GNUNET_OK != res) || (1 == ntohs (rp_msg->is_zonemaster))) | 1636 | if (GNUNET_OK != res) |
1631 | { | 1637 | { |
1632 | /* store not successful or zonemaster, not need to tell monitors */ | 1638 | /* store not successful or zonemaster, not need to tell monitors */ |
1633 | send_store_response (nc, res, rid); | 1639 | send_store_response (nc, res, rid); |
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h index bcc8f5d4e..05a1d97ad 100644 --- a/src/namestore/namestore.h +++ b/src/namestore/namestore.h | |||
@@ -83,11 +83,9 @@ struct RecordStoreMessage | |||
83 | uint16_t rd_count GNUNET_PACKED; | 83 | uint16_t rd_count GNUNET_PACKED; |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * This is a zonemaster request. | 86 | * Reserved for alignment. |
87 | * It means more authoritative tombstone processing | ||
88 | * and not notification of monitors. | ||
89 | */ | 87 | */ |
90 | uint16_t is_zonemaster GNUNET_PACKED; | 88 | uint16_t reserved GNUNET_PACKED; |
91 | 89 | ||
92 | /** | 90 | /** |
93 | * The private key of the authority. | 91 | * The private key of the authority. |
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 935357d36..d4d06bab9 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -970,13 +970,12 @@ warn_delay (void *cls) | |||
970 | } | 970 | } |
971 | 971 | ||
972 | struct GNUNET_NAMESTORE_QueueEntry * | 972 | struct GNUNET_NAMESTORE_QueueEntry * |
973 | GNUNET_NAMESTORE_records_store_ ( | 973 | GNUNET_NAMESTORE_records_store ( |
974 | struct GNUNET_NAMESTORE_Handle *h, | 974 | struct GNUNET_NAMESTORE_Handle *h, |
975 | const struct GNUNET_IDENTITY_PrivateKey *pkey, | 975 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
976 | const char *label, | 976 | const char *label, |
977 | unsigned int rd_count, | 977 | unsigned int rd_count, |
978 | const struct GNUNET_GNSRECORD_Data *rd, | 978 | const struct GNUNET_GNSRECORD_Data *rd, |
979 | int is_zonemaster, | ||
980 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | 979 | GNUNET_NAMESTORE_ContinuationWithStatus cont, |
981 | void *cont_cls) | 980 | void *cont_cls) |
982 | { | 981 | { |
@@ -1023,7 +1022,7 @@ GNUNET_NAMESTORE_records_store_ ( | |||
1023 | msg->name_len = htons (name_len); | 1022 | msg->name_len = htons (name_len); |
1024 | msg->rd_count = htons (rd_count); | 1023 | msg->rd_count = htons (rd_count); |
1025 | msg->rd_len = htons (rd_ser_len); | 1024 | msg->rd_len = htons (rd_ser_len); |
1026 | msg->is_zonemaster = (GNUNET_YES == is_zonemaster) ? ntohs(1) : ntohs(0); | 1025 | msg->reserved = ntohs(0); |
1027 | msg->private_key = *pkey; | 1026 | msg->private_key = *pkey; |
1028 | 1027 | ||
1029 | name_tmp = (char *) &msg[1]; | 1028 | name_tmp = (char *) &msg[1]; |
@@ -1057,37 +1056,6 @@ GNUNET_NAMESTORE_records_store_ ( | |||
1057 | } | 1056 | } |
1058 | 1057 | ||
1059 | /** | 1058 | /** |
1060 | * Store an item in the namestore. If the item is already present, | ||
1061 | * it is replaced with the new record. Use an empty array to | ||
1062 | * remove all records under the given name. | ||
1063 | * | ||
1064 | * @param h handle to the namestore | ||
1065 | * @param pkey private key of the zone | ||
1066 | * @param label name that is being mapped (at most 255 characters long) | ||
1067 | * @param rd_count number of records in the @a rd array | ||
1068 | * @param rd array of records with data to store | ||
1069 | * @param cont continuation to call when done | ||
1070 | * @param cont_cls closure for @a cont | ||
1071 | * @return handle to abort the request | ||
1072 | */ | ||
1073 | struct GNUNET_NAMESTORE_QueueEntry * | ||
1074 | GNUNET_NAMESTORE_records_store ( | ||
1075 | struct GNUNET_NAMESTORE_Handle *h, | ||
1076 | const struct GNUNET_IDENTITY_PrivateKey *pkey, | ||
1077 | const char *label, | ||
1078 | unsigned int rd_count, | ||
1079 | const struct GNUNET_GNSRECORD_Data *rd, | ||
1080 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | ||
1081 | void *cont_cls) | ||
1082 | { | ||
1083 | return GNUNET_NAMESTORE_records_store_ (h, pkey, label, rd_count, rd, | ||
1084 | GNUNET_NO, cont, cont_cls); | ||
1085 | } | ||
1086 | |||
1087 | |||
1088 | |||
1089 | |||
1090 | /** | ||
1091 | * Lookup an item in the namestore. | 1059 | * Lookup an item in the namestore. |
1092 | * | 1060 | * |
1093 | * @param h handle to the namestore | 1061 | * @param h handle to the namestore |
diff --git a/src/zonemaster/Makefile.am b/src/zonemaster/Makefile.am index d561d75fe..f2d569c75 100644 --- a/src/zonemaster/Makefile.am +++ b/src/zonemaster/Makefile.am | |||
@@ -20,8 +20,7 @@ libexec_PROGRAMS = \ | |||
20 | gnunet-service-zonemaster-monitor | 20 | gnunet-service-zonemaster-monitor |
21 | 21 | ||
22 | gnunet_service_zonemaster_SOURCES = \ | 22 | gnunet_service_zonemaster_SOURCES = \ |
23 | gnunet-service-zonemaster.c \ | 23 | gnunet-service-zonemaster.c |
24 | zonemaster_misc.c zonemaster_misc.h | ||
25 | gnunet_service_zonemaster_LDADD = \ | 24 | gnunet_service_zonemaster_LDADD = \ |
26 | $(top_builddir)/src/dht/libgnunetdht.la \ | 25 | $(top_builddir)/src/dht/libgnunetdht.la \ |
27 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 26 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
@@ -33,8 +32,7 @@ gnunet_service_zonemaster_LDADD = \ | |||
33 | 32 | ||
34 | 33 | ||
35 | gnunet_service_zonemaster_monitor_SOURCES = \ | 34 | gnunet_service_zonemaster_monitor_SOURCES = \ |
36 | gnunet-service-zonemaster-monitor.c \ | 35 | gnunet-service-zonemaster-monitor.c |
37 | zonemaster_misc.c zonemaster_misc.h | ||
38 | gnunet_service_zonemaster_monitor_LDADD = \ | 36 | gnunet_service_zonemaster_monitor_LDADD = \ |
39 | $(top_builddir)/src/dht/libgnunetdht.la \ | 37 | $(top_builddir)/src/dht/libgnunetdht.la \ |
40 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 38 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
diff --git a/src/zonemaster/gnunet-service-zonemaster-monitor.c b/src/zonemaster/gnunet-service-zonemaster-monitor.c index dcacec60f..fef9e6b82 100644 --- a/src/zonemaster/gnunet-service-zonemaster-monitor.c +++ b/src/zonemaster/gnunet-service-zonemaster-monitor.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include "gnunet_dht_service.h" | 28 | #include "gnunet_dht_service.h" |
29 | #include "gnunet_namestore_service.h" | 29 | #include "gnunet_namestore_service.h" |
30 | #include "gnunet_statistics_service.h" | 30 | #include "gnunet_statistics_service.h" |
31 | #include "zonemaster_misc.h" | ||
32 | 31 | ||
33 | #define LOG_STRERROR_FILE(kind, syscall, \ | 32 | #define LOG_STRERROR_FILE(kind, syscall, \ |
34 | filename) GNUNET_log_from_strerror_file (kind, "util", \ | 33 | filename) GNUNET_log_from_strerror_file (kind, "util", \ |
@@ -59,30 +58,6 @@ | |||
59 | #define DHT_GNS_REPLICATION_LEVEL 5 | 58 | #define DHT_GNS_REPLICATION_LEVEL 5 |
60 | 59 | ||
61 | /** | 60 | /** |
62 | * Handle for tombston updates which are executed for each published | ||
63 | * record set. | ||
64 | */ | ||
65 | struct TombstoneActivity | ||
66 | { | ||
67 | /** | ||
68 | * Kept in a DLL. | ||
69 | */ | ||
70 | struct TombstoneActivity *next; | ||
71 | |||
72 | /** | ||
73 | * Kept in a DLL. | ||
74 | */ | ||
75 | struct TombstoneActivity *prev; | ||
76 | |||
77 | /** | ||
78 | * Handle for the store operation. | ||
79 | */ | ||
80 | struct GNUNET_NAMESTORE_QueueEntry *ns_qe; | ||
81 | |||
82 | }; | ||
83 | |||
84 | |||
85 | /** | ||
86 | * Handle for DHT PUT activity triggered from the namestore monitor. | 61 | * Handle for DHT PUT activity triggered from the namestore monitor. |
87 | */ | 62 | */ |
88 | struct DhtPutActivity | 63 | struct DhtPutActivity |
@@ -130,17 +105,6 @@ static struct GNUNET_NAMESTORE_Handle *namestore_handle; | |||
130 | static struct GNUNET_NAMESTORE_ZoneMonitor *zmon; | 105 | static struct GNUNET_NAMESTORE_ZoneMonitor *zmon; |
131 | 106 | ||
132 | /** | 107 | /** |
133 | * Head of the tombstone operations | ||
134 | */ | ||
135 | static struct TombstoneActivity *ta_head; | ||
136 | |||
137 | /** | ||
138 | * Tail of the tombstone operations | ||
139 | */ | ||
140 | static struct TombstoneActivity *ta_tail; | ||
141 | |||
142 | |||
143 | /** | ||
144 | * Head of monitor activities; kept in a DLL. | 108 | * Head of monitor activities; kept in a DLL. |
145 | */ | 109 | */ |
146 | static struct DhtPutActivity *ma_head; | 110 | static struct DhtPutActivity *ma_head; |
@@ -186,14 +150,6 @@ shutdown_task (void *cls) | |||
186 | ma); | 150 | ma); |
187 | GNUNET_free (ma); | 151 | GNUNET_free (ma); |
188 | } | 152 | } |
189 | while (NULL != (ta = ta_head)) | ||
190 | { | ||
191 | GNUNET_NAMESTORE_cancel (ta->ns_qe); | ||
192 | GNUNET_CONTAINER_DLL_remove (ta_head, | ||
193 | ta_tail, | ||
194 | ta); | ||
195 | GNUNET_free (ta); | ||
196 | } | ||
197 | if (NULL != statistics) | 153 | if (NULL != statistics) |
198 | { | 154 | { |
199 | GNUNET_STATISTICS_destroy (statistics, | 155 | GNUNET_STATISTICS_destroy (statistics, |
@@ -309,21 +265,6 @@ perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key, | |||
309 | return ret; | 265 | return ret; |
310 | } | 266 | } |
311 | 267 | ||
312 | static void | ||
313 | ts_store_cont (void *cls, int32_t success, const char *emsg) | ||
314 | { | ||
315 | struct TombstoneActivity *ta = cls; | ||
316 | |||
317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
318 | "Tombstone update complete\n"); | ||
319 | GNUNET_CONTAINER_DLL_remove (ta_head, | ||
320 | ta_tail, | ||
321 | ta); | ||
322 | GNUNET_free (ta); | ||
323 | |||
324 | } | ||
325 | |||
326 | |||
327 | /** | 268 | /** |
328 | * Process a record that was stored in the namestore | 269 | * Process a record that was stored in the namestore |
329 | * (invoked by the monitor). | 270 | * (invoked by the monitor). |
@@ -346,7 +287,6 @@ handle_monitor_event (void *cls, | |||
346 | unsigned int rd_public_count; | 287 | unsigned int rd_public_count; |
347 | unsigned int rd_fresh_count; | 288 | unsigned int rd_fresh_count; |
348 | struct DhtPutActivity *ma; | 289 | struct DhtPutActivity *ma; |
349 | struct TombstoneActivity *ta; | ||
350 | struct GNUNET_TIME_Absolute expire; | 290 | struct GNUNET_TIME_Absolute expire; |
351 | 291 | ||
352 | (void) cls; | 292 | (void) cls; |
@@ -360,10 +300,10 @@ handle_monitor_event (void *cls, | |||
360 | label); | 300 | label); |
361 | /* filter out records that are not public, and convert to | 301 | /* filter out records that are not public, and convert to |
362 | absolute expiration time. */ | 302 | absolute expiration time. */ |
363 | rd_public_count = ZMSTR_convert_records_for_export (rd, | 303 | rd_public_count = GNUNET_GNSRECORD_convert_records_for_export (rd, |
364 | rd_count, | 304 | rd_count, |
365 | rd_public, | 305 | rd_public, |
366 | &expire); | 306 | &expire); |
367 | if (0 == rd_public_count) | 307 | if (0 == rd_public_count) |
368 | { | 308 | { |
369 | GNUNET_NAMESTORE_zone_monitor_next (zmon, | 309 | GNUNET_NAMESTORE_zone_monitor_next (zmon, |
@@ -378,27 +318,6 @@ handle_monitor_event (void *cls, | |||
378 | rd_count, | 318 | rd_count, |
379 | expire, | 319 | expire, |
380 | ma); | 320 | ma); |
381 | ta = GNUNET_new (struct TombstoneActivity); | ||
382 | ZMSTR_touch_tombstone (zone, | ||
383 | label, | ||
384 | rd, | ||
385 | rd_count, | ||
386 | rd_fresh, | ||
387 | &rd_fresh_count, | ||
388 | expire); | ||
389 | ta->ns_qe = GNUNET_NAMESTORE_records_store_ (namestore_handle, | ||
390 | zone, | ||
391 | label, | ||
392 | rd_fresh_count, | ||
393 | rd_fresh, | ||
394 | GNUNET_YES, | ||
395 | &ts_store_cont, | ||
396 | ta); | ||
397 | |||
398 | |||
399 | GNUNET_CONTAINER_DLL_insert_tail (ta_head, | ||
400 | ta_tail, | ||
401 | ta); | ||
402 | if (NULL == ma->ph) | 321 | if (NULL == ma->ph) |
403 | { | 322 | { |
404 | /* PUT failed, do not remember operation */ | 323 | /* PUT failed, do not remember operation */ |
diff --git a/src/zonemaster/gnunet-service-zonemaster.c b/src/zonemaster/gnunet-service-zonemaster.c index 9f0de8a54..9eb3432ee 100644 --- a/src/zonemaster/gnunet-service-zonemaster.c +++ b/src/zonemaster/gnunet-service-zonemaster.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include "gnunet_dht_service.h" | 29 | #include "gnunet_dht_service.h" |
30 | #include "gnunet_namestore_service.h" | 30 | #include "gnunet_namestore_service.h" |
31 | #include "gnunet_statistics_service.h" | 31 | #include "gnunet_statistics_service.h" |
32 | #include "zonemaster_misc.h" | ||
33 | 32 | ||
34 | #define LOG_STRERROR_FILE(kind, syscall, \ | 33 | #define LOG_STRERROR_FILE(kind, syscall, \ |
35 | filename) GNUNET_log_from_strerror_file (kind, "util", \ | 34 | filename) GNUNET_log_from_strerror_file (kind, "util", \ |
@@ -91,30 +90,6 @@ | |||
91 | #define DHT_GNS_REPLICATION_LEVEL 5 | 90 | #define DHT_GNS_REPLICATION_LEVEL 5 |
92 | 91 | ||
93 | /** | 92 | /** |
94 | * Handle for tombston updates which are executed for each published | ||
95 | * record set. | ||
96 | */ | ||
97 | struct TombstoneActivity | ||
98 | { | ||
99 | /** | ||
100 | * Kept in a DLL. | ||
101 | */ | ||
102 | struct TombstoneActivity *next; | ||
103 | |||
104 | /** | ||
105 | * Kept in a DLL. | ||
106 | */ | ||
107 | struct TombstoneActivity *prev; | ||
108 | |||
109 | /** | ||
110 | * Handle for the store operation. | ||
111 | */ | ||
112 | struct GNUNET_NAMESTORE_QueueEntry *ns_qe; | ||
113 | |||
114 | }; | ||
115 | |||
116 | |||
117 | /** | ||
118 | * Handle for DHT PUT activity triggered from the namestore monitor. | 93 | * Handle for DHT PUT activity triggered from the namestore monitor. |
119 | */ | 94 | */ |
120 | struct DhtPutActivity | 95 | struct DhtPutActivity |
@@ -172,16 +147,6 @@ static struct DhtPutActivity *it_head; | |||
172 | static struct DhtPutActivity *it_tail; | 147 | static struct DhtPutActivity *it_tail; |
173 | 148 | ||
174 | /** | 149 | /** |
175 | * Head of the tombstone operations | ||
176 | */ | ||
177 | static struct TombstoneActivity *ta_head; | ||
178 | |||
179 | /** | ||
180 | * Tail of the tombstone operations | ||
181 | */ | ||
182 | static struct TombstoneActivity *ta_tail; | ||
183 | |||
184 | /** | ||
185 | * Number of entries in the DHT queue #it_head. | 150 | * Number of entries in the DHT queue #it_head. |
186 | */ | 151 | */ |
187 | static unsigned int dht_queue_length; | 152 | static unsigned int dht_queue_length; |
@@ -296,14 +261,6 @@ shutdown_task (void *cls) | |||
296 | dht_queue_length--; | 261 | dht_queue_length--; |
297 | GNUNET_free (ma); | 262 | GNUNET_free (ma); |
298 | } | 263 | } |
299 | while (NULL != (ta = ta_head)) | ||
300 | { | ||
301 | GNUNET_NAMESTORE_cancel (ta->ns_qe); | ||
302 | GNUNET_CONTAINER_DLL_remove (ta_head, | ||
303 | ta_tail, | ||
304 | ta); | ||
305 | GNUNET_free (ta); | ||
306 | } | ||
307 | if (NULL != statistics) | 264 | if (NULL != statistics) |
308 | { | 265 | { |
309 | GNUNET_STATISTICS_destroy (statistics, | 266 | GNUNET_STATISTICS_destroy (statistics, |
@@ -713,21 +670,6 @@ zone_iteration_finished (void *cls) | |||
713 | } | 670 | } |
714 | } | 671 | } |
715 | 672 | ||
716 | static void | ||
717 | ts_store_cont (void *cls, int32_t success, const char *emsg) | ||
718 | { | ||
719 | struct TombstoneActivity *ta = cls; | ||
720 | |||
721 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
722 | "Tombstone update complete\n"); | ||
723 | GNUNET_CONTAINER_DLL_remove (ta_head, | ||
724 | ta_tail, | ||
725 | ta); | ||
726 | GNUNET_free (ta); | ||
727 | |||
728 | } | ||
729 | |||
730 | |||
731 | /** | 673 | /** |
732 | * Function used to put all records successively into the DHT. | 674 | * Function used to put all records successively into the DHT. |
733 | * | 675 | * |
@@ -749,15 +691,14 @@ put_gns_record (void *cls, | |||
749 | unsigned int rd_public_count; | 691 | unsigned int rd_public_count; |
750 | unsigned int rd_fresh_count = 0; | 692 | unsigned int rd_fresh_count = 0; |
751 | struct DhtPutActivity *ma; | 693 | struct DhtPutActivity *ma; |
752 | struct TombstoneActivity *ta; | ||
753 | struct GNUNET_TIME_Absolute expire; | 694 | struct GNUNET_TIME_Absolute expire; |
754 | 695 | ||
755 | (void) cls; | 696 | (void) cls; |
756 | ns_iteration_left--; | 697 | ns_iteration_left--; |
757 | rd_public_count = ZMSTR_convert_records_for_export (rd, | 698 | rd_public_count = GNUNET_GNSRECORD_convert_records_for_export (rd, |
758 | rd_count, | 699 | rd_count, |
759 | rd_public, | 700 | rd_public, |
760 | &expire); | 701 | &expire); |
761 | if (0 == rd_public_count) | 702 | if (0 == rd_public_count) |
762 | { | 703 | { |
763 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 704 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -790,27 +731,6 @@ put_gns_record (void *cls, | |||
790 | rd_public_count, | 731 | rd_public_count, |
791 | expire, | 732 | expire, |
792 | ma); | 733 | ma); |
793 | ta = GNUNET_new (struct TombstoneActivity); | ||
794 | ZMSTR_touch_tombstone (key, | ||
795 | label, | ||
796 | rd, | ||
797 | rd_count, | ||
798 | rd_fresh, | ||
799 | &rd_fresh_count, | ||
800 | expire); | ||
801 | ta->ns_qe = GNUNET_NAMESTORE_records_store_ (namestore_handle, | ||
802 | key, | ||
803 | label, | ||
804 | rd_fresh_count, | ||
805 | rd_fresh, | ||
806 | GNUNET_YES, | ||
807 | &ts_store_cont, | ||
808 | ta); | ||
809 | |||
810 | |||
811 | GNUNET_CONTAINER_DLL_insert_tail (ta_head, | ||
812 | ta_tail, | ||
813 | ta); | ||
814 | put_cnt++; | 734 | put_cnt++; |
815 | if (0 == put_cnt % DELTA_INTERVAL) | 735 | if (0 == put_cnt % DELTA_INTERVAL) |
816 | update_velocity (DELTA_INTERVAL); | 736 | update_velocity (DELTA_INTERVAL); |
diff --git a/src/zonemaster/zonemaster_misc.c b/src/zonemaster/zonemaster_misc.c deleted file mode 100644 index f067e9c62..000000000 --- a/src/zonemaster/zonemaster_misc.c +++ /dev/null | |||
@@ -1,132 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | |||
22 | #include "zonemaster_misc.h" | ||
23 | |||
24 | /** | ||
25 | * Convert namestore records from the internal format to that | ||
26 | * suitable for publication (removes private records, converts | ||
27 | * to absolute expiration time). | ||
28 | * | ||
29 | * @param rd input records | ||
30 | * @param rd_count size of the @a rd and @a rd_public arrays | ||
31 | * @param rd_public where to write the converted records | ||
32 | * @param expire the expiration of the block | ||
33 | * @return number of records written to @a rd_public | ||
34 | */ | ||
35 | unsigned int | ||
36 | ZMSTR_convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd, | ||
37 | unsigned int rd_count, | ||
38 | struct GNUNET_GNSRECORD_Data *rd_public, | ||
39 | struct GNUNET_TIME_Absolute *expiry) | ||
40 | { | ||
41 | const struct GNUNET_GNSRECORD_TombstoneRecord *tombstone; | ||
42 | struct GNUNET_TIME_Absolute expiry_tombstone; | ||
43 | struct GNUNET_TIME_Absolute now; | ||
44 | unsigned int rd_public_count; | ||
45 | |||
46 | rd_public_count = 0; | ||
47 | tombstone = NULL; | ||
48 | now = GNUNET_TIME_absolute_get (); | ||
49 | for (unsigned int i = 0; i < rd_count; i++) | ||
50 | { | ||
51 | if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type) | ||
52 | { | ||
53 | tombstone = rd[i].data; | ||
54 | continue; | ||
55 | } | ||
56 | if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) | ||
57 | continue; | ||
58 | if ((0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) && | ||
59 | (rd[i].expiration_time < now.abs_value_us)) | ||
60 | continue; /* record already expired, skip it */ | ||
61 | rd_public[rd_public_count] = rd[i]; | ||
62 | /* Make sure critical record types are published as such */ | ||
63 | if (GNUNET_YES == GNUNET_GNSRECORD_is_critical (rd[i].record_type)) | ||
64 | rd_public[rd_public_count].flags |= GNUNET_GNSRECORD_RF_CRITICAL; | ||
65 | rd_public_count++; | ||
66 | } | ||
67 | |||
68 | *expiry = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count, | ||
69 | rd_public); | ||
70 | |||
71 | /* We need to check if the tombstone has an expiration in the fututre | ||
72 | * which would mean there was a block published under this label | ||
73 | * previously that is still valid. In this case we MUST NOT publish this | ||
74 | * block | ||
75 | */ | ||
76 | if (NULL != tombstone) | ||
77 | { | ||
78 | expiry_tombstone = GNUNET_TIME_absolute_ntoh (tombstone->time_of_death); | ||
79 | if (GNUNET_TIME_absolute_cmp (*expiry,<=,expiry_tombstone)) | ||
80 | return 0; | ||
81 | } | ||
82 | return rd_public_count; | ||
83 | } | ||
84 | |||
85 | |||
86 | /** | ||
87 | * Update tombstone records. | ||
88 | * | ||
89 | * @param key key of the zone | ||
90 | * @param label label to store under | ||
91 | * @param rd_public public record data | ||
92 | * @param rd_public_count number of records in @a rd_public | ||
93 | * @param rd the buffer for the result. Must be rd_public_count +1 | ||
94 | * @param rd_count the actual number of records written to rd | ||
95 | * @param expire the expiration time for the tombstone | ||
96 | * @return Namestore queue entry, NULL on error | ||
97 | */ | ||
98 | void | ||
99 | ZMSTR_touch_tombstone (const struct GNUNET_IDENTITY_PrivateKey *key, | ||
100 | const char *label, | ||
101 | const struct GNUNET_GNSRECORD_Data *rd_original, | ||
102 | unsigned int rd_count_original, | ||
103 | struct GNUNET_GNSRECORD_Data *rd, | ||
104 | unsigned int *rd_count, | ||
105 | const struct GNUNET_TIME_Absolute expire) | ||
106 | { | ||
107 | struct GNUNET_TIME_AbsoluteNBO exp_nbo; | ||
108 | int tombstone_exists = GNUNET_NO; | ||
109 | unsigned int i; | ||
110 | |||
111 | exp_nbo = GNUNET_TIME_absolute_hton (expire); | ||
112 | for (i = 0; i < rd_count_original; i++) | ||
113 | { | ||
114 | memcpy (&rd[i], &rd_original[i], | ||
115 | sizeof (struct GNUNET_GNSRECORD_Data)); | ||
116 | if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type) | ||
117 | { | ||
118 | rd[i].data = &exp_nbo; | ||
119 | tombstone_exists = GNUNET_YES; | ||
120 | } | ||
121 | } | ||
122 | if (GNUNET_NO == tombstone_exists) | ||
123 | { | ||
124 | rd[i].data = &exp_nbo; | ||
125 | rd[i].data_size = sizeof (exp_nbo); | ||
126 | rd[i].record_type = GNUNET_GNSRECORD_TYPE_TOMBSTONE; | ||
127 | rd[i].flags = GNUNET_GNSRECORD_RF_PRIVATE; | ||
128 | rd[i].expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | ||
129 | i++; | ||
130 | } | ||
131 | *rd_count = i; | ||
132 | } | ||
diff --git a/src/zonemaster/zonemaster_misc.h b/src/zonemaster/zonemaster_misc.h deleted file mode 100644 index 27ef3aab7..000000000 --- a/src/zonemaster/zonemaster_misc.h +++ /dev/null | |||
@@ -1,62 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | #include "platform.h" | ||
22 | #include "gnunet_util_lib.h" | ||
23 | #include "gnunet_namestore_service.h" | ||
24 | |||
25 | |||
26 | /** | ||
27 | * Convert namestore records from the internal format to that | ||
28 | * suitable for publication (removes private records, converts | ||
29 | * to absolute expiration time). | ||
30 | * | ||
31 | * @param rd input records | ||
32 | * @param rd_count size of the @a rd and @a rd_public arrays | ||
33 | * @param rd_public where to write the converted records | ||
34 | * @param expire the expiration of the block | ||
35 | * @return number of records written to @a rd_public | ||
36 | */ | ||
37 | unsigned int | ||
38 | ZMSTR_convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd, | ||
39 | unsigned int rd_count, | ||
40 | struct GNUNET_GNSRECORD_Data *rd_public, | ||
41 | struct GNUNET_TIME_Absolute *expiry); | ||
42 | |||
43 | /** | ||
44 | * Update tombstone records. | ||
45 | * | ||
46 | * @param key key of the zone | ||
47 | * @param label label to store under | ||
48 | * @param rd_public public record data | ||
49 | * @param rd_public_count number of records in @a rd_public | ||
50 | * @param rd the buffer for the result. Must be rd_public_count +1 | ||
51 | * @param rd_count the actual number of records written to rd | ||
52 | * @param expire the expiration time for the tombstone | ||
53 | * @return Namestore queue entry, NULL on error | ||
54 | */ | ||
55 | void | ||
56 | ZMSTR_touch_tombstone (const struct GNUNET_IDENTITY_PrivateKey *key, | ||
57 | const char *label, | ||
58 | const struct GNUNET_GNSRECORD_Data *rd_original, | ||
59 | unsigned int rd_count_original, | ||
60 | struct GNUNET_GNSRECORD_Data *rd, | ||
61 | unsigned int *rd_count, | ||
62 | const struct GNUNET_TIME_Absolute expire); | ||