diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-09-28 14:05:01 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-09-28 14:05:01 +0900 |
commit | 3ec2b451f938398eb4d2f92603f0659c26f6675c (patch) | |
tree | 03f34b6819b1422ad8da2e566908748e87cf9975 /src/zonemaster | |
parent | 64480e6f4e07743a5fd20389eef92e0e9eadc563 (diff) | |
download | gnunet-3ec2b451f938398eb4d2f92603f0659c26f6675c.tar.gz gnunet-3ec2b451f938398eb4d2f92603f0659c26f6675c.zip |
NAMESTORE: Allow service-side record set filtering. Fixes #7193
This commit enables zone iteration APIs which allow you to set a record
set filter to determine which records should be returned or not.
In particular filtering of private records and maintenance records
(TOMBSTONE) for zonemaster.
Diffstat (limited to 'src/zonemaster')
-rw-r--r-- | src/zonemaster/gnunet-service-zonemaster-monitor.c | 50 | ||||
-rw-r--r-- | src/zonemaster/gnunet-service-zonemaster.c | 51 |
2 files changed, 33 insertions, 68 deletions
diff --git a/src/zonemaster/gnunet-service-zonemaster-monitor.c b/src/zonemaster/gnunet-service-zonemaster-monitor.c index 748a0f342..08749bede 100644 --- a/src/zonemaster/gnunet-service-zonemaster-monitor.c +++ b/src/zonemaster/gnunet-service-zonemaster-monitor.c | |||
@@ -273,19 +273,17 @@ perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key, | |||
273 | * @param label label of the records; NULL on disconnect | 273 | * @param label label of the records; NULL on disconnect |
274 | * @param rd_count number of entries in @a rd array, 0 if label was deleted | 274 | * @param rd_count number of entries in @a rd array, 0 if label was deleted |
275 | * @param rd array of records with data to store | 275 | * @param rd array of records with data to store |
276 | * @param expire expiration of this record set | ||
276 | */ | 277 | */ |
277 | static void | 278 | static void |
278 | handle_monitor_event (void *cls, | 279 | handle_monitor_event (void *cls, |
279 | const struct GNUNET_IDENTITY_PrivateKey *zone, | 280 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
280 | const char *label, | 281 | const char *label, |
281 | unsigned int rd_count, | 282 | unsigned int rd_count, |
282 | const struct GNUNET_GNSRECORD_Data *rd) | 283 | const struct GNUNET_GNSRECORD_Data *rd, |
284 | struct GNUNET_TIME_Absolute expire) | ||
283 | { | 285 | { |
284 | struct GNUNET_GNSRECORD_Data rd_public[rd_count]; | ||
285 | unsigned int rd_public_count; | ||
286 | struct DhtPutActivity *ma; | 286 | struct DhtPutActivity *ma; |
287 | struct GNUNET_TIME_Absolute expire; | ||
288 | char *emsg; | ||
289 | 287 | ||
290 | (void) cls; | 288 | (void) cls; |
291 | GNUNET_STATISTICS_update (statistics, | 289 | GNUNET_STATISTICS_update (statistics, |
@@ -296,24 +294,7 @@ handle_monitor_event (void *cls, | |||
296 | "Received %u records for label `%s' via namestore monitor\n", | 294 | "Received %u records for label `%s' via namestore monitor\n", |
297 | rd_count, | 295 | rd_count, |
298 | label); | 296 | label); |
299 | /* filter out records that are not public, and convert to | 297 | if (0 == rd_count) |
300 | absolute expiration time. */ | ||
301 | if (GNUNET_OK != GNUNET_GNSRECORD_convert_records_for_export (label, | ||
302 | rd, | ||
303 | rd_count, | ||
304 | rd_public, | ||
305 | &rd_public_count, | ||
306 | &expire, | ||
307 | &emsg)) | ||
308 | { | ||
309 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
310 | "Zonemaster-monitor failed: %s\n", emsg); | ||
311 | GNUNET_free (emsg); | ||
312 | GNUNET_NAMESTORE_zone_monitor_next (zmon, | ||
313 | 1); | ||
314 | return; /* nothing to do */ | ||
315 | } | ||
316 | if (0 == rd_public_count) | ||
317 | { | 298 | { |
318 | GNUNET_NAMESTORE_zone_monitor_next (zmon, | 299 | GNUNET_NAMESTORE_zone_monitor_next (zmon, |
319 | 1); | 300 | 1); |
@@ -323,8 +304,8 @@ handle_monitor_event (void *cls, | |||
323 | ma->start_date = GNUNET_TIME_absolute_get (); | 304 | ma->start_date = GNUNET_TIME_absolute_get (); |
324 | ma->ph = perform_dht_put (zone, | 305 | ma->ph = perform_dht_put (zone, |
325 | label, | 306 | label, |
326 | rd_public, | 307 | rd, |
327 | rd_public_count, | 308 | rd_count, |
328 | expire, | 309 | expire, |
329 | ma); | 310 | ma); |
330 | if (NULL == ma->ph) | 311 | if (NULL == ma->ph) |
@@ -427,15 +408,16 @@ run (void *cls, | |||
427 | /* Schedule periodic put for our records. */ | 408 | /* Schedule periodic put for our records. */ |
428 | statistics = GNUNET_STATISTICS_create ("zonemaster-mon", | 409 | statistics = GNUNET_STATISTICS_create ("zonemaster-mon", |
429 | c); | 410 | c); |
430 | zmon = GNUNET_NAMESTORE_zone_monitor_start (c, | 411 | zmon = GNUNET_NAMESTORE_zone_monitor_start2 (c, |
431 | NULL, | 412 | NULL, |
432 | GNUNET_NO, | 413 | GNUNET_NO, |
433 | &handle_monitor_error, | 414 | &handle_monitor_error, |
434 | NULL, | 415 | NULL, |
435 | &handle_monitor_event, | 416 | &handle_monitor_event, |
436 | NULL, | 417 | NULL, |
437 | NULL /* sync_cb */, | 418 | NULL /* sync_cb */, |
438 | NULL); | 419 | NULL, |
420 | GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE); | ||
439 | GNUNET_NAMESTORE_zone_monitor_next (zmon, | 421 | GNUNET_NAMESTORE_zone_monitor_next (zmon, |
440 | NAMESTORE_QUEUE_LIMIT - 1); | 422 | NAMESTORE_QUEUE_LIMIT - 1); |
441 | GNUNET_break (NULL != zmon); | 423 | GNUNET_break (NULL != zmon); |
diff --git a/src/zonemaster/gnunet-service-zonemaster.c b/src/zonemaster/gnunet-service-zonemaster.c index c6b86bf71..dba1b24ce 100644 --- a/src/zonemaster/gnunet-service-zonemaster.c +++ b/src/zonemaster/gnunet-service-zonemaster.c | |||
@@ -683,46 +683,28 @@ put_gns_record (void *cls, | |||
683 | const struct GNUNET_IDENTITY_PrivateKey *key, | 683 | const struct GNUNET_IDENTITY_PrivateKey *key, |
684 | const char *label, | 684 | const char *label, |
685 | unsigned int rd_count, | 685 | unsigned int rd_count, |
686 | const struct GNUNET_GNSRECORD_Data *rd) | 686 | const struct GNUNET_GNSRECORD_Data *rd, |
687 | struct GNUNET_TIME_Absolute expire) | ||
687 | { | 688 | { |
688 | struct GNUNET_GNSRECORD_Data rd_public[rd_count]; | ||
689 | unsigned int rd_public_count; | ||
690 | struct DhtPutActivity *ma; | 689 | struct DhtPutActivity *ma; |
691 | struct GNUNET_TIME_Absolute expire; | ||
692 | char *emsg; | ||
693 | 690 | ||
694 | (void) cls; | 691 | (void) cls; |
695 | ns_iteration_left--; | 692 | ns_iteration_left--; |
696 | if (GNUNET_OK != GNUNET_GNSRECORD_convert_records_for_export (label, | 693 | if (0 == rd_count) |
697 | rd, | ||
698 | rd_count, | ||
699 | rd_public, | ||
700 | &rd_public_count, | ||
701 | &expire, | ||
702 | &emsg)) | ||
703 | { | ||
704 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
705 | "Record set inconsistent, moving to next record set: %s\n", | ||
706 | emsg); | ||
707 | GNUNET_free (emsg); | ||
708 | check_zone_namestore_next (); | ||
709 | return; | ||
710 | } | ||
711 | if (0 == rd_public_count) | ||
712 | { | 694 | { |
713 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 695 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
714 | "Record set empty, moving to next record set\n"); | 696 | "Record set empty, moving to next record set\n"); |
715 | check_zone_namestore_next (); | 697 | check_zone_namestore_next (); |
716 | return; | 698 | return; |
717 | } | 699 | } |
718 | for (unsigned int i = 0; i < rd_public_count; i++) | 700 | for (unsigned int i = 0; i < rd_count; i++) |
719 | { | 701 | { |
720 | if (0 != (rd_public[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | 702 | if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) |
721 | { | 703 | { |
722 | /* GNUNET_GNSRECORD_block_create will convert to absolute time; | 704 | /* GNUNET_GNSRECORD_block_create will convert to absolute time; |
723 | we just need to adjust our iteration frequency */ | 705 | we just need to adjust our iteration frequency */ |
724 | min_relative_record_time.rel_value_us = | 706 | min_relative_record_time.rel_value_us = |
725 | GNUNET_MIN (rd_public[i].expiration_time, | 707 | GNUNET_MIN (rd[i].expiration_time, |
726 | min_relative_record_time.rel_value_us); | 708 | min_relative_record_time.rel_value_us); |
727 | } | 709 | } |
728 | } | 710 | } |
@@ -736,8 +718,8 @@ put_gns_record (void *cls, | |||
736 | ma->start_date = GNUNET_TIME_absolute_get (); | 718 | ma->start_date = GNUNET_TIME_absolute_get (); |
737 | ma->ph = perform_dht_put (key, | 719 | ma->ph = perform_dht_put (key, |
738 | label, | 720 | label, |
739 | rd_public, | 721 | rd, |
740 | rd_public_count, | 722 | rd_count, |
741 | expire, | 723 | expire, |
742 | ma); | 724 | ma); |
743 | put_cnt++; | 725 | put_cnt++; |
@@ -793,14 +775,15 @@ publish_zone_dht_start (void *cls) | |||
793 | GNUNET_assert (NULL == namestore_iter); | 775 | GNUNET_assert (NULL == namestore_iter); |
794 | ns_iteration_left = 1; | 776 | ns_iteration_left = 1; |
795 | namestore_iter | 777 | namestore_iter |
796 | = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle, | 778 | = GNUNET_NAMESTORE_zone_iteration_start2 (namestore_handle, |
797 | NULL, /* All zones */ | 779 | NULL, /* All zones */ |
798 | &zone_iteration_error, | 780 | &zone_iteration_error, |
799 | NULL, | 781 | NULL, |
800 | &put_gns_record, | 782 | &put_gns_record, |
801 | NULL, | 783 | NULL, |
802 | &zone_iteration_finished, | 784 | &zone_iteration_finished, |
803 | NULL); | 785 | NULL, |
786 | GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE); | ||
804 | GNUNET_assert (NULL != namestore_iter); | 787 | GNUNET_assert (NULL != namestore_iter); |
805 | } | 788 | } |
806 | 789 | ||