aboutsummaryrefslogtreecommitdiff
path: root/src/escrow/plugin_escrow_gns.c
diff options
context:
space:
mode:
authorjospaeth <spaethj@in.tum.de>2020-08-15 11:39:15 +0200
committerjospaeth <spaethj@in.tum.de>2020-08-15 11:39:15 +0200
commit84ecd31b7adda178f64f107fbadebc85287d2ea2 (patch)
treee86685796c23df98d666679f543f36745dc17377 /src/escrow/plugin_escrow_gns.c
parent40b6d8bb8bbb36588318be02a6e7a130dfc3ee88 (diff)
downloadgnunet-84ecd31b7adda178f64f107fbadebc85287d2ea2.tar.gz
gnunet-84ecd31b7adda178f64f107fbadebc85287d2ea2.zip
delay gns escrow until plugin is intialized, fixes
Diffstat (limited to 'src/escrow/plugin_escrow_gns.c')
-rw-r--r--src/escrow/plugin_escrow_gns.c116
1 files changed, 81 insertions, 35 deletions
diff --git a/src/escrow/plugin_escrow_gns.c b/src/escrow/plugin_escrow_gns.c
index 26bbcc06b..3e2025b08 100644
--- a/src/escrow/plugin_escrow_gns.c
+++ b/src/escrow/plugin_escrow_gns.c
@@ -177,6 +177,11 @@ struct ESCROW_GnsPluginOperation
177 uint8_t share_threshold; 177 uint8_t share_threshold;
178 178
179 /** 179 /**
180 * The ego
181 */
182 struct GNUNET_IDENTITY_Ego *ego;
183
184 /**
180 * Private key of the ego 185 * Private key of the ego
181 */ 186 */
182 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 187 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
@@ -254,31 +259,31 @@ cleanup_plugin_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap)
254 /* clean up identity operation list */ 259 /* clean up identity operation list */
255 for (curr_id_op = p_op->id_ops_head; NULL != curr_id_op; curr_id_op = next_id_op) 260 for (curr_id_op = p_op->id_ops_head; NULL != curr_id_op; curr_id_op = next_id_op)
256 { 261 {
262 next_id_op = curr_id_op->next;
257 GNUNET_CONTAINER_DLL_remove (p_op->id_ops_head, 263 GNUNET_CONTAINER_DLL_remove (p_op->id_ops_head,
258 p_op->id_ops_tail, 264 p_op->id_ops_tail,
259 curr_id_op); 265 curr_id_op);
260 GNUNET_IDENTITY_cancel (curr_id_op->id_op); 266 GNUNET_IDENTITY_cancel (curr_id_op->id_op);
261 next_id_op = curr_id_op->next;
262 GNUNET_free (curr_id_op); 267 GNUNET_free (curr_id_op);
263 } 268 }
264 /* clean up escrow pk list */ 269 /* clean up escrow pk list */
265 for (curr_pk = p_op->escrow_pks_head; NULL != curr_pk; curr_pk = next_pk) 270 for (curr_pk = p_op->escrow_pks_head; NULL != curr_pk; curr_pk = next_pk)
266 { 271 {
272 next_pk = curr_pk->next;
267 GNUNET_CONTAINER_DLL_remove (p_op->escrow_pks_head, 273 GNUNET_CONTAINER_DLL_remove (p_op->escrow_pks_head,
268 p_op->escrow_pks_tail, 274 p_op->escrow_pks_tail,
269 curr_pk); 275 curr_pk);
270 next_pk = curr_pk->next;
271 GNUNET_free (curr_pk); 276 GNUNET_free (curr_pk);
272 } 277 }
273 /* clean up namestore operation list */ 278 /* clean up namestore operation list */
274 for (curr_ns_qe = p_op->ns_qes_head; NULL != curr_ns_qe; curr_ns_qe = next_ns_qe) 279 for (curr_ns_qe = p_op->ns_qes_head; NULL != curr_ns_qe; curr_ns_qe = next_ns_qe)
275 { 280 {
281 next_ns_qe = curr_ns_qe->next;
276 GNUNET_CONTAINER_DLL_remove (p_op->ns_qes_head, 282 GNUNET_CONTAINER_DLL_remove (p_op->ns_qes_head,
277 p_op->ns_qes_tail, 283 p_op->ns_qes_tail,
278 curr_ns_qe); 284 curr_ns_qe);
279 // also frees the curr_ns_qe->ns_qe 285 // also frees the curr_ns_qe->ns_qe
280 GNUNET_NAMESTORE_cancel (curr_ns_qe->ns_qe); 286 GNUNET_NAMESTORE_cancel (curr_ns_qe->ns_qe);
281 next_ns_qe = curr_ns_qe->next;
282 GNUNET_free (curr_ns_qe); 287 GNUNET_free (curr_ns_qe);
283 } 288 }
284 /* disconnect from namestore service */ 289 /* disconnect from namestore service */
@@ -338,6 +343,9 @@ keyshare_distribution_finished (struct ESCROW_PluginOperationWrapper *plugin_op_
338 343
339 p_op->anchor_wrap->escrowAnchor = anchor; 344 p_op->anchor_wrap->escrowAnchor = anchor;
340 345
346 /* set the last escrow time */
347 ESCROW_update_escrow_status (p_op->h, p_op->ego, "gns");
348
341 /* call the continuation */ 349 /* call the continuation */
342 start_cont (plugin_op_wrap); 350 start_cont (plugin_op_wrap);
343} 351}
@@ -538,11 +546,13 @@ static uint8_t
538count_digits (uint8_t n) 546count_digits (uint8_t n)
539{ 547{
540 uint8_t i = 0; 548 uint8_t i = 0;
541 while (n != 0) 549
550 do
542 { 551 {
543 i++; 552 i++;
544 n /= 10; 553 n /= 10;
545 } 554 } while (n != 0);
555
546 return i; 556 return i;
547} 557}
548 558
@@ -688,11 +698,11 @@ create_escrow_identities (struct ESCROW_PluginOperationWrapper *plugin_op_wrap,
688 /* an ego with identifier name but the wrong pk exists, delete it first */ 698 /* an ego with identifier name but the wrong pk exists, delete it first */
689 curr_id_op = GNUNET_new (struct IdentityOperationEntry); 699 curr_id_op = GNUNET_new (struct IdentityOperationEntry);
690 curr_id_op->pk = curr_pk; 700 curr_id_op->pk = curr_pk;
691 curr_id_op->name = name; 701 curr_id_op->name = curr_name;
692 curr_id_op->i = i; 702 curr_id_op->i = i;
693 curr_id_op->plugin_op_wrap = plugin_op_wrap; 703 curr_id_op->plugin_op_wrap = plugin_op_wrap;
694 curr_id_op->id_op = GNUNET_IDENTITY_delete (identity_handle, 704 curr_id_op->id_op = GNUNET_IDENTITY_delete (identity_handle,
695 name, 705 curr_name,
696 &handle_existing_wrong_ego_deletion, 706 &handle_existing_wrong_ego_deletion,
697 curr_id_op); 707 curr_id_op);
698 GNUNET_CONTAINER_DLL_insert (p_op->id_ops_head, 708 GNUNET_CONTAINER_DLL_insert (p_op->id_ops_head,
@@ -708,13 +718,19 @@ create_escrow_identities (struct ESCROW_PluginOperationWrapper *plugin_op_wrap,
708 GNUNET_CONTAINER_DLL_insert (p_op->escrow_pks_head, 718 GNUNET_CONTAINER_DLL_insert (p_op->escrow_pks_head,
709 p_op->escrow_pks_tail, 719 p_op->escrow_pks_tail,
710 curr_pk_entry); 720 curr_pk_entry);
721
722 p_op->escrow_id_counter++;
723 if (p_op->escrow_id_counter == p_op->shares)
724 {
725 escrow_ids_finished (plugin_op_wrap);
726 }
711 } 727 }
712 else // GNUNET_NO 728 else // GNUNET_NO
713 { 729 {
714 /* store the identity operation in our list */ 730 /* store the identity operation in our list */
715 curr_id_op = GNUNET_new (struct IdentityOperationEntry); 731 curr_id_op = GNUNET_new (struct IdentityOperationEntry);
716 curr_id_op->pk = curr_pk; 732 curr_id_op->pk = curr_pk;
717 curr_id_op->name = name; 733 curr_id_op->name = curr_name;
718 curr_id_op->i = i; 734 curr_id_op->i = i;
719 curr_id_op->plugin_op_wrap = plugin_op_wrap; 735 curr_id_op->plugin_op_wrap = plugin_op_wrap;
720 curr_id_op->id_op = GNUNET_IDENTITY_create (identity_handle, 736 curr_id_op->id_op = GNUNET_IDENTITY_create (identity_handle,
@@ -730,6 +746,55 @@ create_escrow_identities (struct ESCROW_PluginOperationWrapper *plugin_op_wrap,
730} 746}
731 747
732 748
749void
750continue_start (void *cls)
751{
752 struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls;
753 struct ESCROW_GnsPluginOperation *p_op;
754 unsigned long long shares, share_threshold;
755 struct GNUNET_TIME_Relative delay;
756
757 p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op;
758
759 if (ESCROW_PLUGIN_STATE_POST_INIT != ph.state)
760 {
761 delay.rel_value_us = 200 * GNUNET_TIME_relative_get_millisecond_().rel_value_us;
762 GNUNET_SCHEDULER_add_delayed (delay, &continue_start, plugin_op_wrap);
763 return;
764 }
765
766 // get config
767 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (p_op->h->cfg,
768 "escrow",
769 "gns_shares",
770 &shares))
771 {
772 fprintf (stderr, "Number of shares not specified in config!");
773 p_op->anchor_wrap->escrowAnchor = NULL;
774 p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap);
775 return;
776 }
777 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (p_op->h->cfg,
778 "escrow",
779 "gns_share_threshold",
780 &share_threshold))
781 {
782 fprintf (stderr, "Share threshold not specified in config");
783 p_op->anchor_wrap->escrowAnchor = NULL;
784 p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap);
785 return;
786 }
787 p_op->shares = (uint8_t)shares;
788 p_op->share_threshold = (uint8_t)share_threshold;
789
790 /* create the escrow identities */
791 create_escrow_identities (plugin_op_wrap, p_op->ego->name);
792
793 /* operation continues in escrow_ids_finished
794 after all escrow identities are created */
795}
796
797
733/** 798/**
734 * Start the GNS escrow of the key 799 * Start the GNS escrow of the key
735 * 800 *
@@ -751,7 +816,7 @@ start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h,
751 struct ESCROW_PluginOperationWrapper *plugin_op_wrap; 816 struct ESCROW_PluginOperationWrapper *plugin_op_wrap;
752 struct ESCROW_GnsPluginOperation *p_op; 817 struct ESCROW_GnsPluginOperation *p_op;
753 struct ESCROW_Plugin_AnchorContinuationWrapper *w; 818 struct ESCROW_Plugin_AnchorContinuationWrapper *w;
754 unsigned long long shares, share_threshold; 819 struct GNUNET_TIME_Relative delay;
755 820
756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting GNS escrow\n"); 821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting GNS escrow\n");
757 822
@@ -765,6 +830,7 @@ start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h,
765 p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; 830 p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op;
766 p_op->h = h; 831 p_op->h = h;
767 p_op->cont = cb; 832 p_op->cont = cb;
833 p_op->ego = ego;
768 834
769 w = GNUNET_new (struct ESCROW_Plugin_AnchorContinuationWrapper); 835 w = GNUNET_new (struct ESCROW_Plugin_AnchorContinuationWrapper);
770 w->h = h; 836 w->h = h;
@@ -784,35 +850,15 @@ start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h,
784 p_op->pk = GNUNET_IDENTITY_ego_get_private_key (ego); 850 p_op->pk = GNUNET_IDENTITY_ego_get_private_key (ego);
785 p_op->userSecret = userSecret; 851 p_op->userSecret = userSecret;
786 852
787 // get config 853 if (ESCROW_PLUGIN_STATE_POST_INIT == ph.state)
788 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (h->cfg,
789 "escrow",
790 "gns_shares",
791 &shares))
792 { 854 {
793 fprintf (stderr, "Number of shares not specified in config!"); 855 continue_start (plugin_op_wrap);
794 w->escrowAnchor = NULL;
795 p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap);
796 return plugin_op_wrap;
797 } 856 }
798 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (h->cfg, 857 else
799 "escrow",
800 "gns_share_threshold",
801 &share_threshold))
802 { 858 {
803 fprintf (stderr, "Share threshold not specified in config"); 859 delay.rel_value_us = 200 * GNUNET_TIME_relative_get_millisecond_().rel_value_us;
804 w->escrowAnchor = NULL; 860 GNUNET_SCHEDULER_add_delayed (delay, &continue_start, plugin_op_wrap);
805 p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap);
806 return plugin_op_wrap;
807 } 861 }
808 p_op->shares = (uint8_t)shares;
809 p_op->share_threshold = (uint8_t)share_threshold;
810
811 /* create the escrow identities */
812 create_escrow_identities (plugin_op_wrap, ego->name);
813
814 /* operation continues in escrow_ids_finished
815 after all escrow identities are created */
816 862
817 return plugin_op_wrap; 863 return plugin_op_wrap;
818} 864}
@@ -1017,7 +1063,7 @@ cancel_gns_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap)
1017void 1063void
1018gns_cont_init () 1064gns_cont_init ()
1019{ 1065{
1020 return; 1066 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GNS plugin initialized");
1021} 1067}
1022 1068
1023 1069