diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-24 18:21:14 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-24 18:21:14 +0900 |
commit | 6e874ef92f6df138a3091395f6f0240ad301fb03 (patch) | |
tree | c4f96fa528366ead7f78c872573e569717c555f6 /src/namestore | |
parent | aec54ad722ce1cedb763a90196aa25c28c26698a (diff) | |
download | gnunet-6e874ef92f6df138a3091395f6f0240ad301fb03.tar.gz gnunet-6e874ef92f6df138a3091395f6f0240ad301fb03.zip |
NAMESTORE: Allow to purge/recover orphans using CLI. Do not handle orphans in service
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-namestore.c | 297 | ||||
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 251 |
2 files changed, 278 insertions, 270 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 5329ee2ef..57751d5a2 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -56,6 +56,57 @@ struct RecordSetEntry | |||
56 | struct GNUNET_GNSRECORD_Data record; | 56 | struct GNUNET_GNSRECORD_Data record; |
57 | }; | 57 | }; |
58 | 58 | ||
59 | /** | ||
60 | * The orphaned record | ||
61 | */ | ||
62 | struct Orphan | ||
63 | { | ||
64 | /** | ||
65 | * DLL | ||
66 | */ | ||
67 | struct Orphan *next; | ||
68 | |||
69 | /** | ||
70 | * DLL | ||
71 | */ | ||
72 | struct Orphan *prev; | ||
73 | |||
74 | /** | ||
75 | * Ego Identifier | ||
76 | */ | ||
77 | char *name; | ||
78 | |||
79 | /** | ||
80 | * The zone key | ||
81 | */ | ||
82 | struct GNUNET_IDENTITY_PrivateKey key; | ||
83 | }; | ||
84 | |||
85 | /** | ||
86 | * The default namestore ego | ||
87 | */ | ||
88 | struct EgoEntry | ||
89 | { | ||
90 | /** | ||
91 | * DLL | ||
92 | */ | ||
93 | struct EgoEntry *next; | ||
94 | |||
95 | /** | ||
96 | * DLL | ||
97 | */ | ||
98 | struct EgoEntry *prev; | ||
99 | |||
100 | /** | ||
101 | * Ego Identifier | ||
102 | */ | ||
103 | char *identifier; | ||
104 | |||
105 | /** | ||
106 | * The Ego | ||
107 | */ | ||
108 | struct GNUNET_IDENTITY_Ego *ego; | ||
109 | }; | ||
59 | 110 | ||
60 | /** | 111 | /** |
61 | * Handle to the namestore. | 112 | * Handle to the namestore. |
@@ -113,6 +164,27 @@ static struct GNUNET_NAMESTORE_QueueEntry *get_qe; | |||
113 | static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe; | 164 | static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe; |
114 | 165 | ||
115 | /** | 166 | /** |
167 | * Orphan list | ||
168 | */ | ||
169 | static struct Orphan *orphans_head; | ||
170 | |||
171 | /** | ||
172 | * Orphan list | ||
173 | */ | ||
174 | static struct Orphan *orphans_tail; | ||
175 | |||
176 | |||
177 | /** | ||
178 | * Ego list | ||
179 | */ | ||
180 | static struct EgoEntry *ego_head; | ||
181 | |||
182 | /** | ||
183 | * Ego list | ||
184 | */ | ||
185 | static struct EgoEntry *ego_tail; | ||
186 | |||
187 | /** | ||
116 | * Desired action is to list records. | 188 | * Desired action is to list records. |
117 | */ | 189 | */ |
118 | static int list; | 190 | static int list; |
@@ -148,6 +220,16 @@ static int omit_private; | |||
148 | static int include_maintenance; | 220 | static int include_maintenance; |
149 | 221 | ||
150 | /** | 222 | /** |
223 | * Purge orphaned records | ||
224 | */ | ||
225 | static int purge_orphaned; | ||
226 | |||
227 | /** | ||
228 | * Recover zone keys of orphaned records | ||
229 | */ | ||
230 | static int recover_orphaned; | ||
231 | |||
232 | /** | ||
151 | * Queue entry for the 'del' operation. | 233 | * Queue entry for the 'del' operation. |
152 | */ | 234 | */ |
153 | static struct GNUNET_NAMESTORE_QueueEntry *del_qe; | 235 | static struct GNUNET_NAMESTORE_QueueEntry *del_qe; |
@@ -237,6 +319,10 @@ static int monitor; | |||
237 | */ | 319 | */ |
238 | static struct RecordSetEntry *recordset; | 320 | static struct RecordSetEntry *recordset; |
239 | 321 | ||
322 | /** | ||
323 | * Purge task | ||
324 | */ | ||
325 | static struct GNUNET_SCHEDULER_Task *purge_task; | ||
240 | 326 | ||
241 | /** | 327 | /** |
242 | * Task run on shutdown. Cleans up everything. | 328 | * Task run on shutdown. Cleans up everything. |
@@ -246,12 +332,21 @@ static struct RecordSetEntry *recordset; | |||
246 | static void | 332 | static void |
247 | do_shutdown (void *cls) | 333 | do_shutdown (void *cls) |
248 | { | 334 | { |
335 | struct EgoEntry *ego_entry; | ||
336 | struct EgoEntry *ego_tmp; | ||
337 | struct Orphan *orphan; | ||
338 | struct Orphan *orphan_tmp; | ||
249 | (void) cls; | 339 | (void) cls; |
250 | if (NULL != get_default) | 340 | if (NULL != get_default) |
251 | { | 341 | { |
252 | GNUNET_IDENTITY_cancel (get_default); | 342 | GNUNET_IDENTITY_cancel (get_default); |
253 | get_default = NULL; | 343 | get_default = NULL; |
254 | } | 344 | } |
345 | if (NULL != purge_task) | ||
346 | { | ||
347 | GNUNET_SCHEDULER_cancel (purge_task); | ||
348 | purge_task = NULL; | ||
349 | } | ||
255 | if (NULL != idh) | 350 | if (NULL != idh) |
256 | { | 351 | { |
257 | GNUNET_IDENTITY_disconnect (idh); | 352 | GNUNET_IDENTITY_disconnect (idh); |
@@ -262,6 +357,20 @@ do_shutdown (void *cls) | |||
262 | GNUNET_IDENTITY_ego_lookup_cancel (el); | 357 | GNUNET_IDENTITY_ego_lookup_cancel (el); |
263 | el = NULL; | 358 | el = NULL; |
264 | } | 359 | } |
360 | for (orphan = orphans_head; NULL != orphan;) | ||
361 | { | ||
362 | orphan_tmp = orphan; | ||
363 | orphan = orphan->next; | ||
364 | GNUNET_free (orphan_tmp->name); | ||
365 | GNUNET_free (orphan_tmp); | ||
366 | } | ||
367 | for (ego_entry = ego_head; NULL != ego_entry;) | ||
368 | { | ||
369 | ego_tmp = ego_entry; | ||
370 | ego_entry = ego_entry->next; | ||
371 | GNUNET_free (ego_tmp->identifier); | ||
372 | GNUNET_free (ego_tmp); | ||
373 | } | ||
265 | if (NULL != list_it) | 374 | if (NULL != list_it) |
266 | { | 375 | { |
267 | GNUNET_NAMESTORE_zone_iteration_stop (list_it); | 376 | GNUNET_NAMESTORE_zone_iteration_stop (list_it); |
@@ -361,6 +470,48 @@ del_continuation (void *cls, enum GNUNET_ErrorCode ec) | |||
361 | test_finished (); | 470 | test_finished (); |
362 | } | 471 | } |
363 | 472 | ||
473 | static void | ||
474 | purge_next_orphan (void *cls); | ||
475 | |||
476 | static void | ||
477 | orphan_deleted (void *cls, enum GNUNET_ErrorCode ec) | ||
478 | { | ||
479 | del_qe = NULL; | ||
480 | if (GNUNET_EC_NONE != ec) | ||
481 | { | ||
482 | fprintf (stderr, | ||
483 | _ ("Deleting orphan failed: %s\n"), | ||
484 | GNUNET_ErrorCode_get_hint (ec)); | ||
485 | } | ||
486 | purge_task = GNUNET_SCHEDULER_add_now (&purge_next_orphan, NULL); | ||
487 | } | ||
488 | |||
489 | |||
490 | static void | ||
491 | purge_next_orphan (void *cls) | ||
492 | { | ||
493 | struct Orphan *orphan; | ||
494 | purge_task = NULL; | ||
495 | |||
496 | if (NULL == orphans_head) | ||
497 | { | ||
498 | ret = 0; | ||
499 | test_finished (); | ||
500 | return; | ||
501 | } | ||
502 | orphan = orphans_head; | ||
503 | GNUNET_CONTAINER_DLL_remove (orphans_head, | ||
504 | orphans_tail, | ||
505 | orphan); | ||
506 | del_qe = GNUNET_NAMESTORE_records_store (ns, | ||
507 | &orphan->key, | ||
508 | orphan->name, | ||
509 | 0, NULL, | ||
510 | &orphan_deleted, | ||
511 | NULL); | ||
512 | GNUNET_free (orphan->name); | ||
513 | GNUNET_free (orphan); | ||
514 | } | ||
364 | 515 | ||
365 | /** | 516 | /** |
366 | * Function called when we are done with a zone iteration. | 517 | * Function called when we are done with a zone iteration. |
@@ -370,6 +521,12 @@ zone_iteration_finished (void *cls) | |||
370 | { | 521 | { |
371 | (void) cls; | 522 | (void) cls; |
372 | list_it = NULL; | 523 | list_it = NULL; |
524 | if (purge_orphaned) | ||
525 | { | ||
526 | purge_task = GNUNET_SCHEDULER_add_now (&purge_next_orphan, NULL); | ||
527 | return; | ||
528 | } | ||
529 | ret = 0; | ||
373 | test_finished (); | 530 | test_finished (); |
374 | } | 531 | } |
375 | 532 | ||
@@ -387,6 +544,36 @@ zone_iteration_error_cb (void *cls) | |||
387 | test_finished (); | 544 | test_finished (); |
388 | } | 545 | } |
389 | 546 | ||
547 | static void | ||
548 | collect_orphans (const struct GNUNET_IDENTITY_PrivateKey *zone_key, | ||
549 | const char *rname, | ||
550 | unsigned int rd_len, | ||
551 | const struct GNUNET_GNSRECORD_Data *rd) | ||
552 | { | ||
553 | struct EgoEntry *ego; | ||
554 | struct Orphan *orphan; | ||
555 | int is_orphaned = 1; | ||
556 | |||
557 | for (ego = ego_head; NULL != ego; ego = ego->next) | ||
558 | { | ||
559 | if (0 == memcmp (GNUNET_IDENTITY_ego_get_private_key (ego->ego), | ||
560 | zone_key, | ||
561 | sizeof (*zone_key))) | ||
562 | { | ||
563 | is_orphaned = 0; | ||
564 | break; | ||
565 | } | ||
566 | } | ||
567 | if (is_orphaned) | ||
568 | { | ||
569 | orphan = GNUNET_new (struct Orphan); | ||
570 | orphan->key = *zone_key; | ||
571 | orphan->name = GNUNET_strdup (rname); | ||
572 | GNUNET_CONTAINER_DLL_insert (orphans_head, | ||
573 | orphans_tail, | ||
574 | orphan); | ||
575 | } | ||
576 | } | ||
390 | 577 | ||
391 | /** | 578 | /** |
392 | * Process a record that was stored in the namestore. | 579 | * Process a record that was stored in the namestore. |
@@ -396,7 +583,8 @@ zone_iteration_error_cb (void *cls) | |||
396 | * @param rd array of records with data to store | 583 | * @param rd array of records with data to store |
397 | */ | 584 | */ |
398 | static void | 585 | static void |
399 | display_record (const char *rname, | 586 | display_record (const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
587 | const char *rname, | ||
400 | unsigned int rd_len, | 588 | unsigned int rd_len, |
401 | const struct GNUNET_GNSRECORD_Data *rd) | 589 | const struct GNUNET_GNSRECORD_Data *rd) |
402 | { | 590 | { |
@@ -405,7 +593,10 @@ display_record (const char *rname, | |||
405 | const char *ets; | 593 | const char *ets; |
406 | struct GNUNET_TIME_Absolute at; | 594 | struct GNUNET_TIME_Absolute at; |
407 | struct GNUNET_TIME_Relative rt; | 595 | struct GNUNET_TIME_Relative rt; |
596 | struct EgoEntry *ego; | ||
408 | int have_record; | 597 | int have_record; |
598 | int is_orphaned = 1; | ||
599 | char *orphaned_str; | ||
409 | 600 | ||
410 | if ((NULL != name) && (0 != strcmp (name, rname))) | 601 | if ((NULL != name) && (0 != strcmp (name, rname))) |
411 | return; | 602 | return; |
@@ -422,7 +613,23 @@ display_record (const char *rname, | |||
422 | } | 613 | } |
423 | if (GNUNET_NO == have_record) | 614 | if (GNUNET_NO == have_record) |
424 | return; | 615 | return; |
425 | fprintf (stdout, "%s:\n", rname); | 616 | for (ego = ego_head; NULL != ego; ego = ego->next) |
617 | { | ||
618 | if (0 == memcmp (GNUNET_IDENTITY_ego_get_private_key (ego->ego), | ||
619 | zone_key, | ||
620 | sizeof (*zone_key))) | ||
621 | { | ||
622 | is_orphaned = 0; | ||
623 | break; | ||
624 | } | ||
625 | } | ||
626 | if (recover_orphaned) | ||
627 | orphaned_str = GNUNET_IDENTITY_private_key_to_string (zone_key); | ||
628 | else | ||
629 | orphaned_str = GNUNET_strdup ("<orphaned>"); | ||
630 | fprintf (stdout, "%s.%s:\n", rname, is_orphaned ? orphaned_str : | ||
631 | ego->identifier); | ||
632 | GNUNET_free (orphaned_str); | ||
426 | if (NULL != typestring) | 633 | if (NULL != typestring) |
427 | type = GNUNET_GNSRECORD_typename_to_number (typestring); | 634 | type = GNUNET_GNSRECORD_typename_to_number (typestring); |
428 | else | 635 | else |
@@ -469,6 +676,21 @@ display_record (const char *rname, | |||
469 | fprintf (stdout, "%s", "\n"); | 676 | fprintf (stdout, "%s", "\n"); |
470 | } | 677 | } |
471 | 678 | ||
679 | static void | ||
680 | purge_orphans_iterator (void *cls, | ||
681 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, | ||
682 | const char *rname, | ||
683 | unsigned int rd_len, | ||
684 | const struct GNUNET_GNSRECORD_Data *rd, | ||
685 | struct GNUNET_TIME_Absolute expiry) | ||
686 | { | ||
687 | (void) cls; | ||
688 | (void) zone_key; | ||
689 | (void) expiry; | ||
690 | collect_orphans (zone_key, rname, rd_len, rd); | ||
691 | GNUNET_NAMESTORE_zone_iterator_next (list_it, 1); | ||
692 | } | ||
693 | |||
472 | 694 | ||
473 | /** | 695 | /** |
474 | * Process a record that was stored in the namestore. | 696 | * Process a record that was stored in the namestore. |
@@ -490,7 +712,7 @@ display_record_iterator (void *cls, | |||
490 | (void) cls; | 712 | (void) cls; |
491 | (void) zone_key; | 713 | (void) zone_key; |
492 | (void) expiry; | 714 | (void) expiry; |
493 | display_record (rname, rd_len, rd); | 715 | display_record (zone_key, rname, rd_len, rd); |
494 | GNUNET_NAMESTORE_zone_iterator_next (list_it, 1); | 716 | GNUNET_NAMESTORE_zone_iterator_next (list_it, 1); |
495 | } | 717 | } |
496 | 718 | ||
@@ -515,7 +737,7 @@ display_record_monitor (void *cls, | |||
515 | (void) cls; | 737 | (void) cls; |
516 | (void) zone_key; | 738 | (void) zone_key; |
517 | (void) expiry; | 739 | (void) expiry; |
518 | display_record (rname, rd_len, rd); | 740 | display_record (zone_key, rname, rd_len, rd); |
519 | GNUNET_NAMESTORE_zone_monitor_next (zm, 1); | 741 | GNUNET_NAMESTORE_zone_monitor_next (zm, 1); |
520 | } | 742 | } |
521 | 743 | ||
@@ -539,7 +761,7 @@ display_record_lookup (void *cls, | |||
539 | (void) cls; | 761 | (void) cls; |
540 | (void) zone_key; | 762 | (void) zone_key; |
541 | get_qe = NULL; | 763 | get_qe = NULL; |
542 | display_record (rname, rd_len, rd); | 764 | display_record (zone_key, rname, rd_len, rd); |
543 | test_finished (); | 765 | test_finished (); |
544 | } | 766 | } |
545 | 767 | ||
@@ -911,7 +1133,8 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
911 | if (include_maintenance) | 1133 | if (include_maintenance) |
912 | filter_flags |= GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE; | 1134 | filter_flags |= GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE; |
913 | if (! (add | del | list | (NULL != nickstring) | (NULL != uri) | 1135 | if (! (add | del | list | (NULL != nickstring) | (NULL != uri) |
914 | | (NULL != reverse_pkey) | (NULL != recordset) | (monitor))) | 1136 | | (NULL != reverse_pkey) | (NULL != recordset) | (monitor) |
1137 | | (purge_orphaned) | (recover_orphaned)) ) | ||
915 | { | 1138 | { |
916 | /* nothing more to be done */ | 1139 | /* nothing more to be done */ |
917 | fprintf (stderr, _ ("No options given\n")); | 1140 | fprintf (stderr, _ ("No options given\n")); |
@@ -1089,7 +1312,21 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1089 | &del_monitor, | 1312 | &del_monitor, |
1090 | NULL); | 1313 | NULL); |
1091 | } | 1314 | } |
1092 | if (list) | 1315 | if (purge_orphaned) |
1316 | { | ||
1317 | list_it = GNUNET_NAMESTORE_zone_iteration_start2 (ns, | ||
1318 | (NULL == ego_name) ? | ||
1319 | NULL : &zone_pkey, | ||
1320 | &zone_iteration_error_cb, | ||
1321 | NULL, | ||
1322 | &purge_orphans_iterator, | ||
1323 | NULL, | ||
1324 | &zone_iteration_finished, | ||
1325 | NULL, | ||
1326 | filter_flags); | ||
1327 | |||
1328 | } | ||
1329 | else if (list) | ||
1093 | { | 1330 | { |
1094 | if (NULL != name) | 1331 | if (NULL != name) |
1095 | get_qe = GNUNET_NAMESTORE_records_lookup (ns, | 1332 | get_qe = GNUNET_NAMESTORE_records_lookup (ns, |
@@ -1101,7 +1338,8 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1101 | NULL); | 1338 | NULL); |
1102 | else | 1339 | else |
1103 | list_it = GNUNET_NAMESTORE_zone_iteration_start2 (ns, | 1340 | list_it = GNUNET_NAMESTORE_zone_iteration_start2 (ns, |
1104 | &zone_pkey, | 1341 | (NULL == ego_name) ? |
1342 | NULL : &zone_pkey, | ||
1105 | &zone_iteration_error_cb, | 1343 | &zone_iteration_error_cb, |
1106 | NULL, | 1344 | NULL, |
1107 | &display_record_iterator, | 1345 | &display_record_iterator, |
@@ -1289,13 +1527,29 @@ id_connect_cb (void *cls, | |||
1289 | const char *name) | 1527 | const char *name) |
1290 | { | 1528 | { |
1291 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 1529 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
1530 | struct GNUNET_IDENTITY_PublicKey pk; | ||
1531 | struct EgoEntry *ego_entry; | ||
1292 | 1532 | ||
1293 | (void) ctx; | 1533 | (void) ctx; |
1294 | (void) name; | 1534 | (void) name; |
1535 | if ((NULL != name) && (NULL != ego)) | ||
1536 | { | ||
1537 | ego_entry = GNUNET_new (struct EgoEntry); | ||
1538 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | ||
1539 | ego_entry->ego = ego; | ||
1540 | ego_entry->identifier = GNUNET_strdup (name); | ||
1541 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | ||
1542 | ego_tail, | ||
1543 | ego_entry); | ||
1544 | return; | ||
1545 | } | ||
1295 | if (NULL != ego) | 1546 | if (NULL != ego) |
1296 | return; | 1547 | return; |
1297 | get_default = | 1548 | if (NULL != ego_name) |
1298 | GNUNET_IDENTITY_get (idh, "namestore", &default_ego_cb, (void *) cfg); | 1549 | el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg); |
1550 | else | ||
1551 | get_default = | ||
1552 | GNUNET_IDENTITY_get (idh, "namestore", &default_ego_cb, (void *) cfg); | ||
1299 | } | 1553 | } |
1300 | 1554 | ||
1301 | 1555 | ||
@@ -1346,15 +1600,10 @@ run (void *cls, | |||
1346 | run_with_zone_pkey (cfg); | 1600 | run_with_zone_pkey (cfg); |
1347 | return; | 1601 | return; |
1348 | } | 1602 | } |
1349 | if (NULL == ego_name) | 1603 | idh = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, (void *) cfg); |
1350 | { | 1604 | if (NULL == idh) |
1351 | idh = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, (void *) cfg); | 1605 | fprintf (stderr, _ ("Cannot connect to identity service\n")); |
1352 | if (NULL == idh) | 1606 | ret = -1; |
1353 | fprintf (stderr, _ ("Cannot connect to identity service\n")); | ||
1354 | ret = -1; | ||
1355 | return; | ||
1356 | } | ||
1357 | el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg); | ||
1358 | } | 1607 | } |
1359 | 1608 | ||
1360 | 1609 | ||
@@ -1600,6 +1849,16 @@ main (int argc, char *const *argv) | |||
1600 | gettext_noop ( | 1849 | gettext_noop ( |
1601 | "do not filter maintenance records"), | 1850 | "do not filter maintenance records"), |
1602 | &include_maintenance), | 1851 | &include_maintenance), |
1852 | GNUNET_GETOPT_option_flag ('P', | ||
1853 | "purge-orphans", | ||
1854 | gettext_noop ( | ||
1855 | "purge namestore of all orphans"), | ||
1856 | &purge_orphaned), | ||
1857 | GNUNET_GETOPT_option_flag ('S', | ||
1858 | "show-orphans-private-key", | ||
1859 | gettext_noop ( | ||
1860 | "show private key for orphaned records for recovery using `gnunet-identity -C -P <key>'. Use in combination with --display"), | ||
1861 | &recover_orphaned), | ||
1603 | GNUNET_GETOPT_option_flag ( | 1862 | GNUNET_GETOPT_option_flag ( |
1604 | 's', | 1863 | 's', |
1605 | "shadow", | 1864 | "shadow", |
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 49c165732..b3c077141 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -341,37 +341,6 @@ struct NickCache | |||
341 | }; | 341 | }; |
342 | 342 | ||
343 | /** | 343 | /** |
344 | * The default namestore ego | ||
345 | */ | ||
346 | struct EgoEntry | ||
347 | { | ||
348 | /** | ||
349 | * DLL | ||
350 | */ | ||
351 | struct EgoEntry *next; | ||
352 | |||
353 | /** | ||
354 | * DLL | ||
355 | */ | ||
356 | struct EgoEntry *prev; | ||
357 | |||
358 | /** | ||
359 | * Ego Identifier | ||
360 | */ | ||
361 | char *identifier; | ||
362 | |||
363 | /** | ||
364 | * Public key string | ||
365 | */ | ||
366 | char *keystring; | ||
367 | |||
368 | /** | ||
369 | * The Ego | ||
370 | */ | ||
371 | struct GNUNET_IDENTITY_Ego *ego; | ||
372 | }; | ||
373 | |||
374 | /** | ||
375 | * We cache nick records to reduce DB load. | 344 | * We cache nick records to reduce DB load. |
376 | */ | 345 | */ |
377 | static struct NickCache nick_cache[NC_SIZE]; | 346 | static struct NickCache nick_cache[NC_SIZE]; |
@@ -392,27 +361,6 @@ static const struct GNUNET_CONFIGURATION_Handle *GSN_cfg; | |||
392 | static struct GNUNET_STATISTICS_Handle *statistics; | 361 | static struct GNUNET_STATISTICS_Handle *statistics; |
393 | 362 | ||
394 | /** | 363 | /** |
395 | * Handle to the identity service | ||
396 | */ | ||
397 | static struct GNUNET_IDENTITY_Handle *identity_handle; | ||
398 | |||
399 | /** | ||
400 | * Indicator if we already have passed the first iteration if egos | ||
401 | */ | ||
402 | static int egos_collected = GNUNET_NO; | ||
403 | |||
404 | /** | ||
405 | * Ego list | ||
406 | */ | ||
407 | static struct EgoEntry *ego_head; | ||
408 | |||
409 | /** | ||
410 | * Ego list | ||
411 | */ | ||
412 | static struct EgoEntry *ego_tail; | ||
413 | |||
414 | |||
415 | /** | ||
416 | * Name of the database plugin | 364 | * Name of the database plugin |
417 | */ | 365 | */ |
418 | static char *db_lib_name; | 366 | static char *db_lib_name; |
@@ -461,9 +409,6 @@ static int return_orphaned; | |||
461 | static void | 409 | static void |
462 | cleanup_task (void *cls) | 410 | cleanup_task (void *cls) |
463 | { | 411 | { |
464 | struct EgoEntry *ego_entry; | ||
465 | struct EgoEntry *ego_tmp; | ||
466 | |||
467 | (void) cls; | 412 | (void) cls; |
468 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n"); | 413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n"); |
469 | if (NULL != monitor_nc) | 414 | if (NULL != monitor_nc) |
@@ -476,20 +421,6 @@ cleanup_task (void *cls) | |||
476 | GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); | 421 | GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); |
477 | statistics = NULL; | 422 | statistics = NULL; |
478 | } | 423 | } |
479 | if (NULL != identity_handle) | ||
480 | { | ||
481 | GNUNET_IDENTITY_disconnect (identity_handle); | ||
482 | identity_handle = NULL; | ||
483 | // FIXME cleanup EgoEntries | ||
484 | } | ||
485 | for (ego_entry = ego_head; NULL != ego_entry;) | ||
486 | { | ||
487 | ego_tmp = ego_entry; | ||
488 | ego_entry = ego_entry->next; | ||
489 | GNUNET_free (ego_tmp->identifier); | ||
490 | GNUNET_free (ego_tmp->keystring); | ||
491 | GNUNET_free (ego_tmp); | ||
492 | } | ||
493 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database)); | 424 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database)); |
494 | GNUNET_free (db_lib_name); | 425 | GNUNET_free (db_lib_name); |
495 | db_lib_name = NULL; | 426 | db_lib_name = NULL; |
@@ -508,51 +439,6 @@ free_store_activity (struct StoreActivity *sa) | |||
508 | GNUNET_free (sa); | 439 | GNUNET_free (sa); |
509 | } | 440 | } |
510 | 441 | ||
511 | static enum GNUNET_GenericReturnValue | ||
512 | is_orphaned (const struct GNUNET_IDENTITY_PrivateKey *zone) | ||
513 | { | ||
514 | struct EgoEntry *ego_entry; | ||
515 | struct GNUNET_IDENTITY_PublicKey pk; | ||
516 | char *keystring; | ||
517 | |||
518 | GNUNET_IDENTITY_key_get_public (zone, &pk); | ||
519 | keystring = GNUNET_IDENTITY_public_key_to_string (&pk); | ||
520 | |||
521 | if (GNUNET_YES == return_orphaned) | ||
522 | return GNUNET_NO; | ||
523 | for (ego_entry = ego_head; NULL != ego_entry; | ||
524 | ego_entry = ego_entry->next) | ||
525 | { | ||
526 | if (0 == strcmp (ego_entry->keystring, keystring)) | ||
527 | break; | ||
528 | } | ||
529 | if (NULL != ego_entry) | ||
530 | { | ||
531 | GNUNET_free (keystring); | ||
532 | return GNUNET_NO; | ||
533 | } | ||
534 | /*if (purge_orphans) | ||
535 | { | ||
536 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
537 | "Removing orphaned zone data for ego %s\n", | ||
538 | ego_entry->keystring); | ||
539 | res = GSN_database->delete_records (GSN_database->cls, | ||
540 | zone, | ||
541 | &emsg); | ||
542 | if (GNUNET_SYSERR == res) | ||
543 | { | ||
544 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
545 | "Error removing orphaned zone data: %s\n", emsg); | ||
546 | } | ||
547 | }*/ | ||
548 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
549 | "Found orphaned zone data for zone key %s\n", | ||
550 | keystring); | ||
551 | GNUNET_free (keystring); | ||
552 | return GNUNET_YES; | ||
553 | } | ||
554 | |||
555 | |||
556 | /** | 442 | /** |
557 | * Function called with the records for the #GNUNET_GNS_EMPTY_LABEL_AT | 443 | * Function called with the records for the #GNUNET_GNS_EMPTY_LABEL_AT |
558 | * label in the zone. Used to locate the #GNUNET_GNSRECORD_TYPE_NICK | 444 | * label in the zone. Used to locate the #GNUNET_GNSRECORD_TYPE_NICK |
@@ -917,31 +803,6 @@ send_lookup_response_with_filter (struct NamestoreClient *nc, | |||
917 | } | 803 | } |
918 | 804 | ||
919 | /** | 805 | /** |
920 | * Generate a `struct LookupNameResponseMessage` and send it to the | ||
921 | * given client using the given notification context. | ||
922 | * | ||
923 | * @param nc client to unicast to | ||
924 | * @param request_id request ID to use | ||
925 | * @param zone_key zone key of the zone | ||
926 | * @param name name | ||
927 | * @param rd_count number of records in @a rd | ||
928 | * @param rd array of records | ||
929 | */ | ||
930 | static int | ||
931 | send_lookup_response (struct NamestoreClient *nc, | ||
932 | uint32_t request_id, | ||
933 | const struct | ||
934 | GNUNET_IDENTITY_PrivateKey *zone_key, | ||
935 | const char *name, | ||
936 | unsigned int rd_count, | ||
937 | const struct GNUNET_GNSRECORD_Data *rd) | ||
938 | { | ||
939 | return send_lookup_response_with_filter (nc, request_id, zone_key, name, | ||
940 | rd_count, rd, | ||
941 | GNUNET_GNSRECORD_FILTER_NONE); | ||
942 | } | ||
943 | |||
944 | /** | ||
945 | * Send response to the store request to the client. | 806 | * Send response to the store request to the client. |
946 | * | 807 | * |
947 | * @param nc client to talk to | 808 | * @param nc client to talk to |
@@ -2201,13 +2062,6 @@ zone_iterate_proc (void *cls, | |||
2201 | return; | 2062 | return; |
2202 | } | 2063 | } |
2203 | proc->zi->seq = seq; | 2064 | proc->zi->seq = seq; |
2204 | if (GNUNET_YES == is_orphaned (zone_key)) | ||
2205 | { | ||
2206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2207 | "Skipping orphaned zone data\n"); | ||
2208 | proc->run_again = GNUNET_YES; | ||
2209 | return; | ||
2210 | } | ||
2211 | if (0 < send_lookup_response_with_filter (proc->zi->nc, | 2065 | if (0 < send_lookup_response_with_filter (proc->zi->nc, |
2212 | proc->zi->request_id, | 2066 | proc->zi->request_id, |
2213 | zone_key, | 2067 | zone_key, |
@@ -2471,13 +2325,6 @@ monitor_iterate_cb (void *cls, | |||
2471 | "Monitor notifications sent", | 2325 | "Monitor notifications sent", |
2472 | 1, | 2326 | 1, |
2473 | GNUNET_NO); | 2327 | GNUNET_NO); |
2474 | if (GNUNET_YES == is_orphaned (zone_key)) | ||
2475 | { | ||
2476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2477 | "Skipping orphaned zone data\n"); | ||
2478 | zm->run_again = GNUNET_YES; | ||
2479 | return; | ||
2480 | } | ||
2481 | if (0 < send_lookup_response_with_filter (zm->nc, 0, zone_key, name, | 2328 | if (0 < send_lookup_response_with_filter (zm->nc, 0, zone_key, name, |
2482 | rd_count, rd, zm->filter)) | 2329 | rd_count, rd, zm->filter)) |
2483 | { | 2330 | { |
@@ -2635,100 +2482,6 @@ handle_monitor_next (void *cls, const struct ZoneMonitorNextMessage *nm) | |||
2635 | } | 2482 | } |
2636 | } | 2483 | } |
2637 | 2484 | ||
2638 | static void | ||
2639 | ego_callback (void *cls, | ||
2640 | struct GNUNET_IDENTITY_Ego *ego, | ||
2641 | void **ctx, | ||
2642 | const char *identifier) | ||
2643 | { | ||
2644 | struct EgoEntry *ego_entry; | ||
2645 | struct GNUNET_SERVICE_Handle *service = cls; | ||
2646 | struct GNUNET_IDENTITY_PublicKey pk; | ||
2647 | |||
2648 | if ((NULL == ego) && (GNUNET_NO == egos_collected)) | ||
2649 | { | ||
2650 | egos_collected = GNUNET_YES; | ||
2651 | GNUNET_SERVICE_resume (service); | ||
2652 | return; | ||
2653 | } | ||
2654 | if (NULL == ego) | ||
2655 | { | ||
2656 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2657 | "Called with NULL ego\n"); | ||
2658 | return; | ||
2659 | } | ||
2660 | if ((GNUNET_NO == egos_collected) && | ||
2661 | (NULL != identifier)) | ||
2662 | { | ||
2663 | ego_entry = GNUNET_new (struct EgoEntry); | ||
2664 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | ||
2665 | ego_entry->keystring = GNUNET_IDENTITY_public_key_to_string (&pk); | ||
2666 | ego_entry->ego = ego; | ||
2667 | ego_entry->identifier = GNUNET_strdup (identifier); | ||
2668 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | ||
2669 | ego_tail, | ||
2670 | ego_entry); | ||
2671 | return; | ||
2672 | } | ||
2673 | /* Ego renamed or added */ | ||
2674 | if (identifier != NULL) | ||
2675 | { | ||
2676 | for (ego_entry = ego_head; NULL != ego_entry; | ||
2677 | ego_entry = ego_entry->next) | ||
2678 | { | ||
2679 | if (ego_entry->ego == ego) | ||
2680 | { | ||
2681 | /* Rename */ | ||
2682 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2683 | "Renaming ego %s->%s\n", ego_entry->identifier, | ||
2684 | identifier); | ||
2685 | GNUNET_free (ego_entry->identifier); | ||
2686 | ego_entry->identifier = GNUNET_strdup (identifier); | ||
2687 | break; | ||
2688 | } | ||
2689 | } | ||
2690 | if (NULL == ego_entry) | ||
2691 | { | ||
2692 | /* Add */ | ||
2693 | ego_entry = GNUNET_new (struct EgoEntry); | ||
2694 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | ||
2695 | ego_entry->keystring = GNUNET_IDENTITY_public_key_to_string (&pk); | ||
2696 | ego_entry->ego = ego; | ||
2697 | ego_entry->identifier = GNUNET_strdup (identifier); | ||
2698 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | ||
2699 | ego_tail, | ||
2700 | ego_entry); | ||
2701 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2702 | "Added ego %s\n", ego_entry->identifier); | ||
2703 | } | ||
2704 | } | ||
2705 | else | ||
2706 | { | ||
2707 | /* Delete */ | ||
2708 | for (ego_entry = ego_head; NULL != ego_entry; | ||
2709 | ego_entry = ego_entry->next) | ||
2710 | { | ||
2711 | if (ego_entry->ego == ego) | ||
2712 | break; | ||
2713 | } | ||
2714 | if (NULL == ego_entry) | ||
2715 | return; /* Not found */ | ||
2716 | |||
2717 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2718 | "Removing ego %s\n", ego_entry->identifier); | ||
2719 | GNUNET_CONTAINER_DLL_remove (ego_head, | ||
2720 | ego_tail, | ||
2721 | ego_entry); | ||
2722 | GNUNET_free (ego_entry->identifier); | ||
2723 | GNUNET_free (ego_entry->keystring); | ||
2724 | GNUNET_free (ego_entry); | ||
2725 | return; | ||
2726 | } | ||
2727 | |||
2728 | } | ||
2729 | |||
2730 | |||
2731 | |||
2732 | /** | 2485 | /** |
2733 | * Process namestore requests. | 2486 | * Process namestore requests. |
2734 | * | 2487 | * |
@@ -2773,10 +2526,6 @@ run (void *cls, | |||
2773 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); | 2526 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); |
2774 | return; | 2527 | return; |
2775 | } | 2528 | } |
2776 | egos_collected = GNUNET_NO; | ||
2777 | /** Suspend until we have all egos */ | ||
2778 | GNUNET_SERVICE_suspend (service); | ||
2779 | identity_handle = GNUNET_IDENTITY_connect (cfg, &ego_callback, service); | ||
2780 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); | 2529 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); |
2781 | } | 2530 | } |
2782 | 2531 | ||