gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

commit bb469c915099839cdba380d0e7e436d4971b6431
parent 6d56e7dc6cdadd73a277e0ca760e4e938bea2ee2
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Mon, 24 Oct 2022 08:34:23 +0900

-fix namestore JSON; fix zone monitor

Diffstat:
Msrc/gnsrecord/json_gnsrecord.c | 2+-
Msrc/namestore/gnunet-namestore.c | 80+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
Msrc/namestore/gnunet-service-namestore.c | 67++++++++++++++++++++++++++++++++++++++++++-------------------------
Msrc/namestore/namestore_api_monitor.c | 2+-
4 files changed, 96 insertions(+), 55 deletions(-)

diff --git a/src/gnsrecord/json_gnsrecord.c b/src/gnsrecord/json_gnsrecord.c @@ -338,7 +338,7 @@ GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname, record = json_pack ("{s:s,s:s,s:I,s:b,s:b,s:b,s:b}", GNUNET_JSON_GNSRECORD_VALUE, value_str, - GNUNET_JSON_GNSRECORD_VALUE, + GNUNET_JSON_GNSRECORD_TYPE, record_type_str, (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION) ? GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME : GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME, diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c @@ -138,6 +138,16 @@ static int is_public; static int is_shadow; /** + * Filter private records + */ +static int omit_private; + +/** + * Do not filter maintenance records + */ +static int include_maintenance; + +/** * Queue entry for the 'del' operation. */ static struct GNUNET_NAMESTORE_QueueEntry *del_qe; @@ -345,7 +355,8 @@ del_continuation (void *cls, enum GNUNET_ErrorCode ec) if (GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND == ec) { fprintf (stderr, - _ ("Deleting record failed: %s\n"), GNUNET_ErrorCode_get_hint (ec)); + _ ("Deleting record failed: %s\n"), GNUNET_ErrorCode_get_hint ( + ec)); } test_finished (); } @@ -397,18 +408,13 @@ display_record (const char *rname, int have_record; if ((NULL != name) && (0 != strcmp (name, rname))) - { - GNUNET_NAMESTORE_zone_iterator_next (list_it, 1); return; - } have_record = GNUNET_NO; for (unsigned int i = 0; i < rd_len; i++) { if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT))) continue; - if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type) - continue; if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type)) continue; have_record = GNUNET_YES; @@ -426,8 +432,6 @@ display_record (const char *rname, if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT))) continue; - if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type) - continue; if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type)) continue; typestr = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); @@ -480,10 +484,12 @@ display_record_iterator (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone_key, const char *rname, unsigned int rd_len, - const struct GNUNET_GNSRECORD_Data *rd) + const struct GNUNET_GNSRECORD_Data *rd, + struct GNUNET_TIME_Absolute expiry) { (void) cls; (void) zone_key; + (void) expiry; display_record (rname, rd_len, rd); GNUNET_NAMESTORE_zone_iterator_next (list_it, 1); } @@ -503,10 +509,12 @@ display_record_monitor (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone_key, const char *rname, unsigned int rd_len, - const struct GNUNET_GNSRECORD_Data *rd) + const struct GNUNET_GNSRECORD_Data *rd, + struct GNUNET_TIME_Absolute expiry) { (void) cls; (void) zone_key; + (void) expiry; display_record (rname, rd_len, rd); GNUNET_NAMESTORE_zone_monitor_next (zm, 1); } @@ -896,9 +904,14 @@ static void run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_GNSRECORD_Data rd; + enum GNUNET_GNSRECORD_Filter filter_flags = GNUNET_GNSRECORD_FILTER_NONE; + if (omit_private) + filter_flags |= GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE; + if (include_maintenance) + filter_flags |= GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE; if (! (add | del | list | (NULL != nickstring) | (NULL != uri) - | (NULL != reverse_pkey) | (NULL != recordset))) + | (NULL != reverse_pkey) | (NULL != recordset) | (monitor))) { /* nothing more to be done */ fprintf (stderr, _ ("No options given\n")); @@ -1087,14 +1100,15 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) &display_record_lookup, NULL); else - list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, - &zone_pkey, - &zone_iteration_error_cb, - NULL, - &display_record_iterator, - NULL, - &zone_iteration_finished, - NULL); + list_it = GNUNET_NAMESTORE_zone_iteration_start2 (ns, + &zone_pkey, + &zone_iteration_error_cb, + NULL, + &display_record_iterator, + NULL, + &zone_iteration_finished, + NULL, + filter_flags); } if (NULL != reverse_pkey) { @@ -1171,15 +1185,16 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) } if (monitor) { - zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, - &zone_pkey, - GNUNET_YES, - &monitor_error_cb, - NULL, - &display_record_monitor, - NULL, - &sync_cb, - NULL); + zm = GNUNET_NAMESTORE_zone_monitor_start2 (cfg, + &zone_pkey, + GNUNET_YES, + &monitor_error_cb, + NULL, + &display_record_monitor, + NULL, + &sync_cb, + NULL, + filter_flags); } } @@ -1576,6 +1591,15 @@ main (int argc, char *const *argv) "public", gettext_noop ("create or list public record"), &is_public), + GNUNET_GETOPT_option_flag ('o', + "omit-private", + gettext_noop ("omit private records"), + &omit_private), + GNUNET_GETOPT_option_flag ('T', + "include-maintenance", + gettext_noop ( + "do not filter maintenance records"), + &include_maintenance), GNUNET_GETOPT_option_flag ( 's', "shadow", diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c @@ -806,7 +806,7 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd, * @param rd array of records * @param filter record set filter */ -static void +static int send_lookup_response_with_filter (struct NamestoreClient *nc, uint32_t request_id, const struct @@ -865,6 +865,8 @@ send_lookup_response_with_filter (struct NamestoreClient *nc, if (NULL != nick) GNUNET_free (nick); + if (0 == res_count) + return 0; GNUNET_assert (-1 != GNUNET_GNSRECORD_records_get_size (res_count, res)); @@ -876,7 +878,7 @@ send_lookup_response_with_filter (struct NamestoreClient *nc, GNUNET_free (res); GNUNET_break (0); GNUNET_SERVICE_client_drop (nc->client); - return; + return 0; } if (((size_t) rd_ser_len) >= UINT16_MAX - name_len - sizeof(*zir_msg)) { @@ -884,7 +886,7 @@ send_lookup_response_with_filter (struct NamestoreClient *nc, GNUNET_free (res); GNUNET_break (0); GNUNET_SERVICE_client_drop (nc->client); - return; + return 0; } env = GNUNET_MQ_msg_extra (zir_msg, name_len + rd_ser_len, @@ -911,6 +913,7 @@ send_lookup_response_with_filter (struct NamestoreClient *nc, GNUNET_MQ_send (nc->mq, env); if (rd_nf != res) GNUNET_free (res); + return res_count; } /** @@ -924,7 +927,7 @@ send_lookup_response_with_filter (struct NamestoreClient *nc, * @param rd_count number of records in @a rd * @param rd array of records */ -static void +static int send_lookup_response (struct NamestoreClient *nc, uint32_t request_id, const struct @@ -933,8 +936,9 @@ send_lookup_response (struct NamestoreClient *nc, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd) { - send_lookup_response_with_filter (nc, request_id, zone_key, name, - rd_count, rd, GNUNET_GNSRECORD_FILTER_NONE); + return send_lookup_response_with_filter (nc, request_id, zone_key, name, + rd_count, rd, + GNUNET_GNSRECORD_FILTER_NONE); } /** @@ -1092,14 +1096,14 @@ continue_store_activity (struct StoreActivity *sa, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Notifying monitor about changes under label `%s'\n", conv_name); - zm->limit--; - send_lookup_response_with_filter (zm->nc, - 0, - &sa->private_key, - conv_name, - rd_count, - rd, - zm->filter); + if (0 < send_lookup_response_with_filter (zm->nc, + 0, + &sa->private_key, + conv_name, + rd_count, + rd, + zm->filter)) + zm->limit--; sa->zm_pos = zm->next; } sa->rd_set_pos++; @@ -2204,14 +2208,16 @@ zone_iterate_proc (void *cls, proc->run_again = GNUNET_YES; return; } - proc->limit--; - send_lookup_response_with_filter (proc->zi->nc, - proc->zi->request_id, - zone_key, - name, - rd_count, - rd, - proc->zi->filter); + if (0 < send_lookup_response_with_filter (proc->zi->nc, + proc->zi->request_id, + zone_key, + name, + rd_count, + rd, + proc->zi->filter)) + proc->limit--; + else + proc->run_again = GNUNET_YES; } @@ -2472,9 +2478,16 @@ monitor_iterate_cb (void *cls, zm->run_again = GNUNET_YES; return; } - zm->limit--; - zm->iteration_cnt--; - send_lookup_response (zm->nc, 0, zone_key, name, rd_count, rd); + if (0 < send_lookup_response_with_filter (zm->nc, 0, zone_key, name, + rd_count, rd, zm->filter)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sent records.\n"); + zm->limit--; + zm->iteration_cnt--; + } + else + zm->run_again = GNUNET_YES; if ((0 == zm->iteration_cnt) && (0 != zm->limit)) { /* We are done with the current iteration batch, AND the @@ -2538,6 +2551,8 @@ monitor_iteration_next (void *cls) zm->run_again = GNUNET_YES; while (GNUNET_YES == zm->run_again) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Running iteration\n"); zm->run_again = GNUNET_NO; ret = nc->GSN_database->iterate_records (nc->GSN_database->cls, (GNUNET_YES == GNUNET_is_zero ( @@ -2554,6 +2569,8 @@ monitor_iteration_next (void *cls) } if (GNUNET_NO == ret) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Zone empty... syncing\n"); /* empty zone */ monitor_sync (zm); return; diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c @@ -286,7 +286,7 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START); sm->iterate_first = htonl (zm->iterate_first); sm->zone = zm->zone; - sm->filter = htons ((uint16_t) zm->filter); + sm->filter = htons (zm->filter); GNUNET_MQ_send (zm->mq, env); }