aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-10-24 08:34:23 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2022-10-24 08:34:23 +0900
commitbb469c915099839cdba380d0e7e436d4971b6431 (patch)
tree81b02a06440c1ec5142607e9a9ec80ee7c86b11c /src/namestore
parent6d56e7dc6cdadd73a277e0ca760e4e938bea2ee2 (diff)
downloadgnunet-bb469c915099839cdba380d0e7e436d4971b6431.tar.gz
gnunet-bb469c915099839cdba380d0e7e436d4971b6431.zip
-fix namestore JSON; fix zone monitor
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/gnunet-namestore.c80
-rw-r--r--src/namestore/gnunet-service-namestore.c67
-rw-r--r--src/namestore/namestore_api_monitor.c2
3 files changed, 95 insertions, 54 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index a636644f8..5329ee2ef 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -138,6 +138,16 @@ static int is_public;
138static int is_shadow; 138static int is_shadow;
139 139
140/** 140/**
141 * Filter private records
142 */
143static int omit_private;
144
145/**
146 * Do not filter maintenance records
147 */
148static int include_maintenance;
149
150/**
141 * Queue entry for the 'del' operation. 151 * Queue entry for the 'del' operation.
142 */ 152 */
143static struct GNUNET_NAMESTORE_QueueEntry *del_qe; 153static struct GNUNET_NAMESTORE_QueueEntry *del_qe;
@@ -345,7 +355,8 @@ del_continuation (void *cls, enum GNUNET_ErrorCode ec)
345 if (GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND == ec) 355 if (GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND == ec)
346 { 356 {
347 fprintf (stderr, 357 fprintf (stderr,
348 _ ("Deleting record failed: %s\n"), GNUNET_ErrorCode_get_hint (ec)); 358 _ ("Deleting record failed: %s\n"), GNUNET_ErrorCode_get_hint (
359 ec));
349 } 360 }
350 test_finished (); 361 test_finished ();
351} 362}
@@ -397,18 +408,13 @@ display_record (const char *rname,
397 int have_record; 408 int have_record;
398 409
399 if ((NULL != name) && (0 != strcmp (name, rname))) 410 if ((NULL != name) && (0 != strcmp (name, rname)))
400 {
401 GNUNET_NAMESTORE_zone_iterator_next (list_it, 1);
402 return; 411 return;
403 }
404 have_record = GNUNET_NO; 412 have_record = GNUNET_NO;
405 for (unsigned int i = 0; i < rd_len; i++) 413 for (unsigned int i = 0; i < rd_len; i++)
406 { 414 {
407 if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && 415 if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
408 (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT))) 416 (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT)))
409 continue; 417 continue;
410 if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type)
411 continue;
412 if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type)) 418 if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type))
413 continue; 419 continue;
414 have_record = GNUNET_YES; 420 have_record = GNUNET_YES;
@@ -426,8 +432,6 @@ display_record (const char *rname,
426 if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && 432 if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
427 (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT))) 433 (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT)))
428 continue; 434 continue;
429 if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type)
430 continue;
431 if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type)) 435 if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type))
432 continue; 436 continue;
433 typestr = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); 437 typestr = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
@@ -480,10 +484,12 @@ display_record_iterator (void *cls,
480 const struct GNUNET_IDENTITY_PrivateKey *zone_key, 484 const struct GNUNET_IDENTITY_PrivateKey *zone_key,
481 const char *rname, 485 const char *rname,
482 unsigned int rd_len, 486 unsigned int rd_len,
483 const struct GNUNET_GNSRECORD_Data *rd) 487 const struct GNUNET_GNSRECORD_Data *rd,
488 struct GNUNET_TIME_Absolute expiry)
484{ 489{
485 (void) cls; 490 (void) cls;
486 (void) zone_key; 491 (void) zone_key;
492 (void) expiry;
487 display_record (rname, rd_len, rd); 493 display_record (rname, rd_len, rd);
488 GNUNET_NAMESTORE_zone_iterator_next (list_it, 1); 494 GNUNET_NAMESTORE_zone_iterator_next (list_it, 1);
489} 495}
@@ -503,10 +509,12 @@ display_record_monitor (void *cls,
503 const struct GNUNET_IDENTITY_PrivateKey *zone_key, 509 const struct GNUNET_IDENTITY_PrivateKey *zone_key,
504 const char *rname, 510 const char *rname,
505 unsigned int rd_len, 511 unsigned int rd_len,
506 const struct GNUNET_GNSRECORD_Data *rd) 512 const struct GNUNET_GNSRECORD_Data *rd,
513 struct GNUNET_TIME_Absolute expiry)
507{ 514{
508 (void) cls; 515 (void) cls;
509 (void) zone_key; 516 (void) zone_key;
517 (void) expiry;
510 display_record (rname, rd_len, rd); 518 display_record (rname, rd_len, rd);
511 GNUNET_NAMESTORE_zone_monitor_next (zm, 1); 519 GNUNET_NAMESTORE_zone_monitor_next (zm, 1);
512} 520}
@@ -896,9 +904,14 @@ static void
896run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) 904run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg)
897{ 905{
898 struct GNUNET_GNSRECORD_Data rd; 906 struct GNUNET_GNSRECORD_Data rd;
907 enum GNUNET_GNSRECORD_Filter filter_flags = GNUNET_GNSRECORD_FILTER_NONE;
899 908
909 if (omit_private)
910 filter_flags |= GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE;
911 if (include_maintenance)
912 filter_flags |= GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE;
900 if (! (add | del | list | (NULL != nickstring) | (NULL != uri) 913 if (! (add | del | list | (NULL != nickstring) | (NULL != uri)
901 | (NULL != reverse_pkey) | (NULL != recordset))) 914 | (NULL != reverse_pkey) | (NULL != recordset) | (monitor)))
902 { 915 {
903 /* nothing more to be done */ 916 /* nothing more to be done */
904 fprintf (stderr, _ ("No options given\n")); 917 fprintf (stderr, _ ("No options given\n"));
@@ -1087,14 +1100,15 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg)
1087 &display_record_lookup, 1100 &display_record_lookup,
1088 NULL); 1101 NULL);
1089 else 1102 else
1090 list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, 1103 list_it = GNUNET_NAMESTORE_zone_iteration_start2 (ns,
1091 &zone_pkey, 1104 &zone_pkey,
1092 &zone_iteration_error_cb, 1105 &zone_iteration_error_cb,
1093 NULL, 1106 NULL,
1094 &display_record_iterator, 1107 &display_record_iterator,
1095 NULL, 1108 NULL,
1096 &zone_iteration_finished, 1109 &zone_iteration_finished,
1097 NULL); 1110 NULL,
1111 filter_flags);
1098 } 1112 }
1099 if (NULL != reverse_pkey) 1113 if (NULL != reverse_pkey)
1100 { 1114 {
@@ -1171,15 +1185,16 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg)
1171 } 1185 }
1172 if (monitor) 1186 if (monitor)
1173 { 1187 {
1174 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, 1188 zm = GNUNET_NAMESTORE_zone_monitor_start2 (cfg,
1175 &zone_pkey, 1189 &zone_pkey,
1176 GNUNET_YES, 1190 GNUNET_YES,
1177 &monitor_error_cb, 1191 &monitor_error_cb,
1178 NULL, 1192 NULL,
1179 &display_record_monitor, 1193 &display_record_monitor,
1180 NULL, 1194 NULL,
1181 &sync_cb, 1195 &sync_cb,
1182 NULL); 1196 NULL,
1197 filter_flags);
1183 } 1198 }
1184} 1199}
1185 1200
@@ -1576,6 +1591,15 @@ main (int argc, char *const *argv)
1576 "public", 1591 "public",
1577 gettext_noop ("create or list public record"), 1592 gettext_noop ("create or list public record"),
1578 &is_public), 1593 &is_public),
1594 GNUNET_GETOPT_option_flag ('o',
1595 "omit-private",
1596 gettext_noop ("omit private records"),
1597 &omit_private),
1598 GNUNET_GETOPT_option_flag ('T',
1599 "include-maintenance",
1600 gettext_noop (
1601 "do not filter maintenance records"),
1602 &include_maintenance),
1579 GNUNET_GETOPT_option_flag ( 1603 GNUNET_GETOPT_option_flag (
1580 's', 1604 's',
1581 "shadow", 1605 "shadow",
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 0c8b89a91..49c165732 100644
--- 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,
806 * @param rd array of records 806 * @param rd array of records
807 * @param filter record set filter 807 * @param filter record set filter
808 */ 808 */
809static void 809static int
810send_lookup_response_with_filter (struct NamestoreClient *nc, 810send_lookup_response_with_filter (struct NamestoreClient *nc,
811 uint32_t request_id, 811 uint32_t request_id,
812 const struct 812 const struct
@@ -865,6 +865,8 @@ send_lookup_response_with_filter (struct NamestoreClient *nc,
865 if (NULL != nick) 865 if (NULL != nick)
866 GNUNET_free (nick); 866 GNUNET_free (nick);
867 867
868 if (0 == res_count)
869 return 0;
868 GNUNET_assert (-1 != GNUNET_GNSRECORD_records_get_size (res_count, res)); 870 GNUNET_assert (-1 != GNUNET_GNSRECORD_records_get_size (res_count, res));
869 871
870 872
@@ -876,7 +878,7 @@ send_lookup_response_with_filter (struct NamestoreClient *nc,
876 GNUNET_free (res); 878 GNUNET_free (res);
877 GNUNET_break (0); 879 GNUNET_break (0);
878 GNUNET_SERVICE_client_drop (nc->client); 880 GNUNET_SERVICE_client_drop (nc->client);
879 return; 881 return 0;
880 } 882 }
881 if (((size_t) rd_ser_len) >= UINT16_MAX - name_len - sizeof(*zir_msg)) 883 if (((size_t) rd_ser_len) >= UINT16_MAX - name_len - sizeof(*zir_msg))
882 { 884 {
@@ -884,7 +886,7 @@ send_lookup_response_with_filter (struct NamestoreClient *nc,
884 GNUNET_free (res); 886 GNUNET_free (res);
885 GNUNET_break (0); 887 GNUNET_break (0);
886 GNUNET_SERVICE_client_drop (nc->client); 888 GNUNET_SERVICE_client_drop (nc->client);
887 return; 889 return 0;
888 } 890 }
889 env = GNUNET_MQ_msg_extra (zir_msg, 891 env = GNUNET_MQ_msg_extra (zir_msg,
890 name_len + rd_ser_len, 892 name_len + rd_ser_len,
@@ -911,6 +913,7 @@ send_lookup_response_with_filter (struct NamestoreClient *nc,
911 GNUNET_MQ_send (nc->mq, env); 913 GNUNET_MQ_send (nc->mq, env);
912 if (rd_nf != res) 914 if (rd_nf != res)
913 GNUNET_free (res); 915 GNUNET_free (res);
916 return res_count;
914} 917}
915 918
916/** 919/**
@@ -924,7 +927,7 @@ send_lookup_response_with_filter (struct NamestoreClient *nc,
924 * @param rd_count number of records in @a rd 927 * @param rd_count number of records in @a rd
925 * @param rd array of records 928 * @param rd array of records
926 */ 929 */
927static void 930static int
928send_lookup_response (struct NamestoreClient *nc, 931send_lookup_response (struct NamestoreClient *nc,
929 uint32_t request_id, 932 uint32_t request_id,
930 const struct 933 const struct
@@ -933,8 +936,9 @@ send_lookup_response (struct NamestoreClient *nc,
933 unsigned int rd_count, 936 unsigned int rd_count,
934 const struct GNUNET_GNSRECORD_Data *rd) 937 const struct GNUNET_GNSRECORD_Data *rd)
935{ 938{
936 send_lookup_response_with_filter (nc, request_id, zone_key, name, 939 return send_lookup_response_with_filter (nc, request_id, zone_key, name,
937 rd_count, rd, GNUNET_GNSRECORD_FILTER_NONE); 940 rd_count, rd,
941 GNUNET_GNSRECORD_FILTER_NONE);
938} 942}
939 943
940/** 944/**
@@ -1092,14 +1096,14 @@ continue_store_activity (struct StoreActivity *sa,
1092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1096 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1093 "Notifying monitor about changes under label `%s'\n", 1097 "Notifying monitor about changes under label `%s'\n",
1094 conv_name); 1098 conv_name);
1095 zm->limit--; 1099 if (0 < send_lookup_response_with_filter (zm->nc,
1096 send_lookup_response_with_filter (zm->nc, 1100 0,
1097 0, 1101 &sa->private_key,
1098 &sa->private_key, 1102 conv_name,
1099 conv_name, 1103 rd_count,
1100 rd_count, 1104 rd,
1101 rd, 1105 zm->filter))
1102 zm->filter); 1106 zm->limit--;
1103 sa->zm_pos = zm->next; 1107 sa->zm_pos = zm->next;
1104 } 1108 }
1105 sa->rd_set_pos++; 1109 sa->rd_set_pos++;
@@ -2204,14 +2208,16 @@ zone_iterate_proc (void *cls,
2204 proc->run_again = GNUNET_YES; 2208 proc->run_again = GNUNET_YES;
2205 return; 2209 return;
2206 } 2210 }
2207 proc->limit--; 2211 if (0 < send_lookup_response_with_filter (proc->zi->nc,
2208 send_lookup_response_with_filter (proc->zi->nc, 2212 proc->zi->request_id,
2209 proc->zi->request_id, 2213 zone_key,
2210 zone_key, 2214 name,
2211 name, 2215 rd_count,
2212 rd_count, 2216 rd,
2213 rd, 2217 proc->zi->filter))
2214 proc->zi->filter); 2218 proc->limit--;
2219 else
2220 proc->run_again = GNUNET_YES;
2215} 2221}
2216 2222
2217 2223
@@ -2472,9 +2478,16 @@ monitor_iterate_cb (void *cls,
2472 zm->run_again = GNUNET_YES; 2478 zm->run_again = GNUNET_YES;
2473 return; 2479 return;
2474 } 2480 }
2475 zm->limit--; 2481 if (0 < send_lookup_response_with_filter (zm->nc, 0, zone_key, name,
2476 zm->iteration_cnt--; 2482 rd_count, rd, zm->filter))
2477 send_lookup_response (zm->nc, 0, zone_key, name, rd_count, rd); 2483 {
2484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2485 "Sent records.\n");
2486 zm->limit--;
2487 zm->iteration_cnt--;
2488 }
2489 else
2490 zm->run_again = GNUNET_YES;
2478 if ((0 == zm->iteration_cnt) && (0 != zm->limit)) 2491 if ((0 == zm->iteration_cnt) && (0 != zm->limit))
2479 { 2492 {
2480 /* We are done with the current iteration batch, AND the 2493 /* We are done with the current iteration batch, AND the
@@ -2538,6 +2551,8 @@ monitor_iteration_next (void *cls)
2538 zm->run_again = GNUNET_YES; 2551 zm->run_again = GNUNET_YES;
2539 while (GNUNET_YES == zm->run_again) 2552 while (GNUNET_YES == zm->run_again)
2540 { 2553 {
2554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2555 "Running iteration\n");
2541 zm->run_again = GNUNET_NO; 2556 zm->run_again = GNUNET_NO;
2542 ret = nc->GSN_database->iterate_records (nc->GSN_database->cls, 2557 ret = nc->GSN_database->iterate_records (nc->GSN_database->cls,
2543 (GNUNET_YES == GNUNET_is_zero ( 2558 (GNUNET_YES == GNUNET_is_zero (
@@ -2554,6 +2569,8 @@ monitor_iteration_next (void *cls)
2554 } 2569 }
2555 if (GNUNET_NO == ret) 2570 if (GNUNET_NO == ret)
2556 { 2571 {
2572 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2573 "Zone empty... syncing\n");
2557 /* empty zone */ 2574 /* empty zone */
2558 monitor_sync (zm); 2575 monitor_sync (zm);
2559 return; 2576 return;
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c
index 968d7ed58..56ae8cb53 100644
--- a/src/namestore/namestore_api_monitor.c
+++ b/src/namestore/namestore_api_monitor.c
@@ -286,7 +286,7 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
286 env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START); 286 env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START);
287 sm->iterate_first = htonl (zm->iterate_first); 287 sm->iterate_first = htonl (zm->iterate_first);
288 sm->zone = zm->zone; 288 sm->zone = zm->zone;
289 sm->filter = htons ((uint16_t) zm->filter); 289 sm->filter = htons (zm->filter);
290 GNUNET_MQ_send (zm->mq, env); 290 GNUNET_MQ_send (zm->mq, env);
291} 291}
292 292