aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-10-24 20:52:27 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2022-10-24 20:52:27 +0900
commit8de99f209e9cc3cd5b212c8e5d7da86e90bf64e6 (patch)
treef6469a4a7bf540b5c67c0761e9f421d70ff4cbac /src/namestore
parent73c3d1e1c4bda76d8c7c371988d79eb1b7b4e548 (diff)
downloadgnunet-8de99f209e9cc3cd5b212c8e5d7da86e90bf64e6.tar.gz
gnunet-8de99f209e9cc3cd5b212c8e5d7da86e90bf64e6.zip
-update namestore manpage and add options for orphan management
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/gnunet-namestore.c173
1 files changed, 115 insertions, 58 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 57751d5a2..c97ada671 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -57,19 +57,19 @@ struct RecordSetEntry
57}; 57};
58 58
59/** 59/**
60 * The orphaned record 60 * The record marked for deletion
61 */ 61 */
62struct Orphan 62struct MarkedRecord
63{ 63{
64 /** 64 /**
65 * DLL 65 * DLL
66 */ 66 */
67 struct Orphan *next; 67 struct MarkedRecord *next;
68 68
69 /** 69 /**
70 * DLL 70 * DLL
71 */ 71 */
72 struct Orphan *prev; 72 struct MarkedRecord *prev;
73 73
74 /** 74 /**
75 * Ego Identifier 75 * Ego Identifier
@@ -164,14 +164,14 @@ static struct GNUNET_NAMESTORE_QueueEntry *get_qe;
164static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe; 164static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe;
165 165
166/** 166/**
167 * Orphan list 167 * Marked record list
168 */ 168 */
169static struct Orphan *orphans_head; 169static struct MarkedRecord *marked_head;
170 170
171/** 171/**
172 * Orphan list 172 * Marked record list
173 */ 173 */
174static struct Orphan *orphans_tail; 174static struct MarkedRecord *marked_tail;
175 175
176 176
177/** 177/**
@@ -215,6 +215,11 @@ static int is_shadow;
215static int omit_private; 215static int omit_private;
216 216
217/** 217/**
218 * Purge zone contents
219 */
220static int purge_zone;
221
222/**
218 * Do not filter maintenance records 223 * Do not filter maintenance records
219 */ 224 */
220static int include_maintenance; 225static int include_maintenance;
@@ -225,9 +230,9 @@ static int include_maintenance;
225static int purge_orphaned; 230static int purge_orphaned;
226 231
227/** 232/**
228 * Recover zone keys of orphaned records 233 * List records and zone keys of orphaned records
229 */ 234 */
230static int recover_orphaned; 235static int list_orphaned;
231 236
232/** 237/**
233 * Queue entry for the 'del' operation. 238 * Queue entry for the 'del' operation.
@@ -334,8 +339,8 @@ do_shutdown (void *cls)
334{ 339{
335 struct EgoEntry *ego_entry; 340 struct EgoEntry *ego_entry;
336 struct EgoEntry *ego_tmp; 341 struct EgoEntry *ego_tmp;
337 struct Orphan *orphan; 342 struct MarkedRecord *mrec;
338 struct Orphan *orphan_tmp; 343 struct MarkedRecord *mrec_tmp;
339 (void) cls; 344 (void) cls;
340 if (NULL != get_default) 345 if (NULL != get_default)
341 { 346 {
@@ -357,12 +362,12 @@ do_shutdown (void *cls)
357 GNUNET_IDENTITY_ego_lookup_cancel (el); 362 GNUNET_IDENTITY_ego_lookup_cancel (el);
358 el = NULL; 363 el = NULL;
359 } 364 }
360 for (orphan = orphans_head; NULL != orphan;) 365 for (mrec = marked_head; NULL != mrec;)
361 { 366 {
362 orphan_tmp = orphan; 367 mrec_tmp = mrec;
363 orphan = orphan->next; 368 mrec = mrec->next;
364 GNUNET_free (orphan_tmp->name); 369 GNUNET_free (mrec_tmp->name);
365 GNUNET_free (orphan_tmp); 370 GNUNET_free (mrec_tmp);
366 } 371 }
367 for (ego_entry = ego_head; NULL != ego_entry;) 372 for (ego_entry = ego_head; NULL != ego_entry;)
368 { 373 {
@@ -471,46 +476,46 @@ del_continuation (void *cls, enum GNUNET_ErrorCode ec)
471} 476}
472 477
473static void 478static void
474purge_next_orphan (void *cls); 479purge_next_record (void *cls);
475 480
476static void 481static void
477orphan_deleted (void *cls, enum GNUNET_ErrorCode ec) 482marked_deleted (void *cls, enum GNUNET_ErrorCode ec)
478{ 483{
479 del_qe = NULL; 484 del_qe = NULL;
480 if (GNUNET_EC_NONE != ec) 485 if (GNUNET_EC_NONE != ec)
481 { 486 {
482 fprintf (stderr, 487 fprintf (stderr,
483 _ ("Deleting orphan failed: %s\n"), 488 _ ("Deleting record failed: %s\n"),
484 GNUNET_ErrorCode_get_hint (ec)); 489 GNUNET_ErrorCode_get_hint (ec));
485 } 490 }
486 purge_task = GNUNET_SCHEDULER_add_now (&purge_next_orphan, NULL); 491 purge_task = GNUNET_SCHEDULER_add_now (&purge_next_record, NULL);
487} 492}
488 493
489 494
490static void 495static void
491purge_next_orphan (void *cls) 496purge_next_record (void *cls)
492{ 497{
493 struct Orphan *orphan; 498 struct MarkedRecord *mrec;
494 purge_task = NULL; 499 purge_task = NULL;
495 500
496 if (NULL == orphans_head) 501 if (NULL == marked_head)
497 { 502 {
498 ret = 0; 503 ret = 0;
499 test_finished (); 504 test_finished ();
500 return; 505 return;
501 } 506 }
502 orphan = orphans_head; 507 mrec = marked_head;
503 GNUNET_CONTAINER_DLL_remove (orphans_head, 508 GNUNET_CONTAINER_DLL_remove (marked_head,
504 orphans_tail, 509 marked_tail,
505 orphan); 510 mrec);
506 del_qe = GNUNET_NAMESTORE_records_store (ns, 511 del_qe = GNUNET_NAMESTORE_records_store (ns,
507 &orphan->key, 512 &mrec->key,
508 orphan->name, 513 mrec->name,
509 0, NULL, 514 0, NULL,
510 &orphan_deleted, 515 &marked_deleted,
511 NULL); 516 NULL);
512 GNUNET_free (orphan->name); 517 GNUNET_free (mrec->name);
513 GNUNET_free (orphan); 518 GNUNET_free (mrec);
514} 519}
515 520
516/** 521/**
@@ -521,9 +526,9 @@ zone_iteration_finished (void *cls)
521{ 526{
522 (void) cls; 527 (void) cls;
523 list_it = NULL; 528 list_it = NULL;
524 if (purge_orphaned) 529 if (purge_orphaned || purge_zone)
525 { 530 {
526 purge_task = GNUNET_SCHEDULER_add_now (&purge_next_orphan, NULL); 531 purge_task = GNUNET_SCHEDULER_add_now (&purge_next_record, NULL);
527 return; 532 return;
528 } 533 }
529 ret = 0; 534 ret = 0;
@@ -545,13 +550,31 @@ zone_iteration_error_cb (void *cls)
545} 550}
546 551
547static void 552static void
553collect_zone_records_to_purge (const struct
554 GNUNET_IDENTITY_PrivateKey *zone_key,
555 const char *rname,
556 unsigned int rd_len,
557 const struct GNUNET_GNSRECORD_Data *rd)
558{
559 struct MarkedRecord *mrec;
560
561 mrec = GNUNET_new (struct MarkedRecord);
562 mrec->key = *zone_key;
563 mrec->name = GNUNET_strdup (rname);
564 GNUNET_CONTAINER_DLL_insert (marked_head,
565 marked_tail,
566 mrec);
567}
568
569
570static void
548collect_orphans (const struct GNUNET_IDENTITY_PrivateKey *zone_key, 571collect_orphans (const struct GNUNET_IDENTITY_PrivateKey *zone_key,
549 const char *rname, 572 const char *rname,
550 unsigned int rd_len, 573 unsigned int rd_len,
551 const struct GNUNET_GNSRECORD_Data *rd) 574 const struct GNUNET_GNSRECORD_Data *rd)
552{ 575{
553 struct EgoEntry *ego; 576 struct EgoEntry *ego;
554 struct Orphan *orphan; 577 struct MarkedRecord *orphan;
555 int is_orphaned = 1; 578 int is_orphaned = 1;
556 579
557 for (ego = ego_head; NULL != ego; ego = ego->next) 580 for (ego = ego_head; NULL != ego; ego = ego->next)
@@ -566,11 +589,11 @@ collect_orphans (const struct GNUNET_IDENTITY_PrivateKey *zone_key,
566 } 589 }
567 if (is_orphaned) 590 if (is_orphaned)
568 { 591 {
569 orphan = GNUNET_new (struct Orphan); 592 orphan = GNUNET_new (struct MarkedRecord);
570 orphan->key = *zone_key; 593 orphan->key = *zone_key;
571 orphan->name = GNUNET_strdup (rname); 594 orphan->name = GNUNET_strdup (rname);
572 GNUNET_CONTAINER_DLL_insert (orphans_head, 595 GNUNET_CONTAINER_DLL_insert (marked_head,
573 orphans_tail, 596 marked_tail,
574 orphan); 597 orphan);
575 } 598 }
576} 599}
@@ -623,10 +646,11 @@ display_record (const struct GNUNET_IDENTITY_PrivateKey *zone_key,
623 break; 646 break;
624 } 647 }
625 } 648 }
626 if (recover_orphaned) 649 if (list_orphaned && !is_orphaned)
627 orphaned_str = GNUNET_IDENTITY_private_key_to_string (zone_key); 650 return;
628 else 651 if (!list_orphaned && is_orphaned)
629 orphaned_str = GNUNET_strdup ("<orphaned>"); 652 return;
653 orphaned_str = GNUNET_IDENTITY_private_key_to_string (zone_key);
630 fprintf (stdout, "%s.%s:\n", rname, is_orphaned ? orphaned_str : 654 fprintf (stdout, "%s.%s:\n", rname, is_orphaned ? orphaned_str :
631 ego->identifier); 655 ego->identifier);
632 GNUNET_free (orphaned_str); 656 GNUNET_free (orphaned_str);
@@ -677,12 +701,28 @@ display_record (const struct GNUNET_IDENTITY_PrivateKey *zone_key,
677} 701}
678 702
679static void 703static void
704purge_zone_iterator (void *cls,
705 const struct GNUNET_IDENTITY_PrivateKey *zone_key,
706 const char *rname,
707 unsigned int rd_len,
708 const struct GNUNET_GNSRECORD_Data *rd,
709 struct GNUNET_TIME_Absolute expiry)
710{
711 (void) cls;
712 (void) zone_key;
713 (void) expiry;
714 collect_zone_records_to_purge (zone_key, rname, rd_len, rd);
715 GNUNET_NAMESTORE_zone_iterator_next (list_it, 1);
716}
717
718
719static void
680purge_orphans_iterator (void *cls, 720purge_orphans_iterator (void *cls,
681 const struct GNUNET_IDENTITY_PrivateKey *zone_key, 721 const struct GNUNET_IDENTITY_PrivateKey *zone_key,
682 const char *rname, 722 const char *rname,
683 unsigned int rd_len, 723 unsigned int rd_len,
684 const struct GNUNET_GNSRECORD_Data *rd, 724 const struct GNUNET_GNSRECORD_Data *rd,
685 struct GNUNET_TIME_Absolute expiry) 725 struct GNUNET_TIME_Absolute expiry)
686{ 726{
687 (void) cls; 727 (void) cls;
688 (void) zone_key; 728 (void) zone_key;
@@ -1134,7 +1174,7 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg)
1134 filter_flags |= GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE; 1174 filter_flags |= GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE;
1135 if (! (add | del | list | (NULL != nickstring) | (NULL != uri) 1175 if (! (add | del | list | (NULL != nickstring) | (NULL != uri)
1136 | (NULL != reverse_pkey) | (NULL != recordset) | (monitor) 1176 | (NULL != reverse_pkey) | (NULL != recordset) | (monitor)
1137 | (purge_orphaned) | (recover_orphaned)) ) 1177 | (purge_orphaned) | (list_orphaned) | (purge_zone)) )
1138 { 1178 {
1139 /* nothing more to be done */ 1179 /* nothing more to be done */
1140 fprintf (stderr, _ ("No options given\n")); 1180 fprintf (stderr, _ ("No options given\n"));
@@ -1315,8 +1355,7 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg)
1315 if (purge_orphaned) 1355 if (purge_orphaned)
1316 { 1356 {
1317 list_it = GNUNET_NAMESTORE_zone_iteration_start2 (ns, 1357 list_it = GNUNET_NAMESTORE_zone_iteration_start2 (ns,
1318 (NULL == ego_name) ? 1358 NULL,
1319 NULL : &zone_pkey,
1320 &zone_iteration_error_cb, 1359 &zone_iteration_error_cb,
1321 NULL, 1360 NULL,
1322 &purge_orphans_iterator, 1361 &purge_orphans_iterator,
@@ -1326,7 +1365,20 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg)
1326 filter_flags); 1365 filter_flags);
1327 1366
1328 } 1367 }
1329 else if (list) 1368 else if (purge_zone)
1369 {
1370 list_it = GNUNET_NAMESTORE_zone_iteration_start2 (ns,
1371 &zone_pkey,
1372 &zone_iteration_error_cb,
1373 NULL,
1374 &purge_zone_iterator,
1375 NULL,
1376 &zone_iteration_finished,
1377 NULL,
1378 filter_flags);
1379
1380 }
1381 else if (list || list_orphaned)
1330 { 1382 {
1331 if (NULL != name) 1383 if (NULL != name)
1332 get_qe = GNUNET_NAMESTORE_records_lookup (ns, 1384 get_qe = GNUNET_NAMESTORE_records_lookup (ns,
@@ -1854,11 +1906,16 @@ main (int argc, char *const *argv)
1854 gettext_noop ( 1906 gettext_noop (
1855 "purge namestore of all orphans"), 1907 "purge namestore of all orphans"),
1856 &purge_orphaned), 1908 &purge_orphaned),
1857 GNUNET_GETOPT_option_flag ('S', 1909 GNUNET_GETOPT_option_flag ('O',
1858 "show-orphans-private-key", 1910 "list-orphans",
1859 gettext_noop ( 1911 gettext_noop (
1860 "show private key for orphaned records for recovery using `gnunet-identity -C -P <key>'. Use in combination with --display"), 1912 "show private key for orphaned records for recovery using `gnunet-identity -C -P <key>'. Use in combination with --display"),
1861 &recover_orphaned), 1913 &list_orphaned),
1914 GNUNET_GETOPT_option_flag ('X',
1915 "purge-zone-records",
1916 gettext_noop (
1917 "delete all records in specified zone"),
1918 &purge_zone),
1862 GNUNET_GETOPT_option_flag ( 1919 GNUNET_GETOPT_option_flag (
1863 's', 1920 's',
1864 "shadow", 1921 "shadow",