diff options
author | jospaeth <spaethj@in.tum.de> | 2020-08-06 12:51:27 +0200 |
---|---|---|
committer | jospaeth <spaethj@in.tum.de> | 2020-08-06 12:51:27 +0200 |
commit | 8c3c9d1ae8086a8498b0e5159b8168fb47bf50e0 (patch) | |
tree | 5963fe1172e4fb78fb259a2036aa66f43e3eeb24 /src/escrow/plugin_escrow_plaintext.c | |
parent | e35aa4c6b22ae0ae81a23e973eda3655f29e29b5 (diff) | |
download | gnunet-8c3c9d1ae8086a8498b0e5159b8168fb47bf50e0.tar.gz gnunet-8c3c9d1ae8086a8498b0e5159b8168fb47bf50e0.zip |
clean up plugin operations
Diffstat (limited to 'src/escrow/plugin_escrow_plaintext.c')
-rw-r--r-- | src/escrow/plugin_escrow_plaintext.c | 132 |
1 files changed, 104 insertions, 28 deletions
diff --git a/src/escrow/plugin_escrow_plaintext.c b/src/escrow/plugin_escrow_plaintext.c index 7d0fb24fb..72579b829 100644 --- a/src/escrow/plugin_escrow_plaintext.c +++ b/src/escrow/plugin_escrow_plaintext.c | |||
@@ -42,12 +42,6 @@ struct ESCROW_PlaintextPluginOperation | |||
42 | struct GNUNET_ESCROW_Handle *h; | 42 | struct GNUNET_ESCROW_Handle *h; |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Continuation for a plugin operation (e.g. used for restore, as this | ||
46 | * callback has to be called from the IDENTITY service after finishing) | ||
47 | */ | ||
48 | GNUNET_SCHEDULER_TaskCallback cont; | ||
49 | |||
50 | /** | ||
51 | * Scheduler task the SCHEDULE operation returns (needed for cancellation) | 45 | * Scheduler task the SCHEDULE operation returns (needed for cancellation) |
52 | */ | 46 | */ |
53 | struct GNUNET_SCHEDULER_Task *sched_task; | 47 | struct GNUNET_SCHEDULER_Task *sched_task; |
@@ -63,9 +57,25 @@ struct ESCROW_PlaintextPluginOperation | |||
63 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | 57 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; |
64 | 58 | ||
65 | /** | 59 | /** |
60 | * Continuation for a plugin operation (e.g. used for restore, as this | ||
61 | * callback has to be called from the IDENTITY service after finishing) | ||
62 | */ | ||
63 | ESCROW_Plugin_Continuation cont; | ||
64 | |||
65 | /** | ||
66 | * Ego continuation wrapper | 66 | * Ego continuation wrapper |
67 | */ | 67 | */ |
68 | struct ESCROW_Plugin_EgoContinuationWrapper *ego_cont_wrap; | 68 | struct ESCROW_Plugin_EgoContinuationWrapper *ego_wrap; |
69 | |||
70 | /** | ||
71 | * Anchor continuation wrapper | ||
72 | */ | ||
73 | struct ESCROW_Plugin_AnchorContinuationWrapper *anchor_wrap; | ||
74 | |||
75 | /** | ||
76 | * Verify continuation wrapper | ||
77 | */ | ||
78 | struct ESCROW_Plugin_VerifyContinuationWrapper *verify_wrap; | ||
69 | }; | 79 | }; |
70 | 80 | ||
71 | /** | 81 | /** |
@@ -80,6 +90,44 @@ struct ESCROW_PluginHandle ph; | |||
80 | 90 | ||
81 | 91 | ||
82 | /** | 92 | /** |
93 | * Clean up a plugin operation, i.e. remove it from the list and | ||
94 | * free the respective memory | ||
95 | */ | ||
96 | void | ||
97 | cleanup_plugin_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | ||
98 | { | ||
99 | struct ESCROW_PlaintextPluginOperation *p_op; | ||
100 | |||
101 | p_op = (struct ESCROW_PlaintextPluginOperation*)plugin_op_wrap->plugin_op; | ||
102 | |||
103 | GNUNET_CONTAINER_DLL_remove (ph.plugin_op_head, | ||
104 | ph.plugin_op_tail, | ||
105 | plugin_op_wrap); | ||
106 | if (NULL != p_op->anchor_wrap) | ||
107 | GNUNET_free (p_op->anchor_wrap); | ||
108 | if (NULL != p_op->ego_wrap) | ||
109 | GNUNET_free (p_op->ego_wrap); | ||
110 | if (NULL != p_op->verify_wrap) | ||
111 | GNUNET_free (p_op->verify_wrap); | ||
112 | GNUNET_free (p_op); | ||
113 | GNUNET_free (plugin_op_wrap); | ||
114 | } | ||
115 | |||
116 | |||
117 | void | ||
118 | start_cont (void *cls) | ||
119 | { | ||
120 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | ||
121 | struct ESCROW_PlaintextPluginOperation *p_op; | ||
122 | |||
123 | p_op = (struct ESCROW_PlaintextPluginOperation*)plugin_op_wrap->plugin_op; | ||
124 | p_op->cont (p_op->anchor_wrap); | ||
125 | |||
126 | cleanup_plugin_operation (plugin_op_wrap); | ||
127 | } | ||
128 | |||
129 | |||
130 | /** | ||
83 | * Start the plaintext escrow of the key, i.e. simply hand out the key | 131 | * Start the plaintext escrow of the key, i.e. simply hand out the key |
84 | * | 132 | * |
85 | * @param h the handle for the escrow component | 133 | * @param h the handle for the escrow component |
@@ -91,7 +139,7 @@ struct ESCROW_PluginHandle ph; | |||
91 | struct ESCROW_PluginOperationWrapper * | 139 | struct ESCROW_PluginOperationWrapper * |
92 | start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | 140 | start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, |
93 | const struct GNUNET_IDENTITY_Ego *ego, | 141 | const struct GNUNET_IDENTITY_Ego *ego, |
94 | GNUNET_SCHEDULER_TaskCallback cb) | 142 | ESCROW_Plugin_Continuation cb) |
95 | { | 143 | { |
96 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | 144 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; |
97 | struct GNUNET_ESCROW_Anchor *anchor; | 145 | struct GNUNET_ESCROW_Anchor *anchor; |
@@ -110,14 +158,16 @@ start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
110 | 158 | ||
111 | p_op = (struct ESCROW_PlaintextPluginOperation *)plugin_op_wrap->plugin_op; | 159 | p_op = (struct ESCROW_PlaintextPluginOperation *)plugin_op_wrap->plugin_op; |
112 | p_op->h = h; | 160 | p_op->h = h; |
161 | p_op->cont = cb; | ||
113 | 162 | ||
114 | w = GNUNET_new (struct ESCROW_Plugin_AnchorContinuationWrapper); | 163 | w = GNUNET_new (struct ESCROW_Plugin_AnchorContinuationWrapper); |
115 | w->h = h; | 164 | w->h = h; |
165 | p_op->anchor_wrap = w; | ||
116 | 166 | ||
117 | if (NULL == ego) | 167 | if (NULL == ego) |
118 | { | 168 | { |
119 | w->escrowAnchor = NULL; | 169 | w->escrowAnchor = NULL; |
120 | p_op->sched_task = GNUNET_SCHEDULER_add_now (cb, w); | 170 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap); |
121 | return plugin_op_wrap; | 171 | return plugin_op_wrap; |
122 | } | 172 | } |
123 | pk = GNUNET_IDENTITY_ego_get_private_key (ego); | 173 | pk = GNUNET_IDENTITY_ego_get_private_key (ego); |
@@ -131,11 +181,24 @@ start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
131 | 181 | ||
132 | w->escrowAnchor = anchor; | 182 | w->escrowAnchor = anchor; |
133 | 183 | ||
134 | p_op->sched_task = GNUNET_SCHEDULER_add_now (cb, w); | 184 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap); |
135 | return plugin_op_wrap; | 185 | return plugin_op_wrap; |
136 | } | 186 | } |
137 | 187 | ||
138 | 188 | ||
189 | void | ||
190 | verify_cont (void *cls) | ||
191 | { | ||
192 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | ||
193 | struct ESCROW_PlaintextPluginOperation *p_op; | ||
194 | |||
195 | p_op = (struct ESCROW_PlaintextPluginOperation*)plugin_op_wrap->plugin_op; | ||
196 | p_op->cont (p_op->verify_wrap); | ||
197 | |||
198 | cleanup_plugin_operation (plugin_op_wrap); | ||
199 | } | ||
200 | |||
201 | |||
139 | /** | 202 | /** |
140 | * Verify the plaintext escrow of the key | 203 | * Verify the plaintext escrow of the key |
141 | * | 204 | * |
@@ -150,7 +213,7 @@ struct ESCROW_PluginOperationWrapper * | |||
150 | verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | 213 | verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, |
151 | const struct GNUNET_IDENTITY_Ego *ego, | 214 | const struct GNUNET_IDENTITY_Ego *ego, |
152 | struct GNUNET_ESCROW_Anchor *escrowAnchor, | 215 | struct GNUNET_ESCROW_Anchor *escrowAnchor, |
153 | GNUNET_SCHEDULER_TaskCallback cb) | 216 | ESCROW_Plugin_Continuation cb) |
154 | { | 217 | { |
155 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | 218 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; |
156 | char *pkString; | 219 | char *pkString; |
@@ -168,14 +231,16 @@ verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
168 | 231 | ||
169 | p_op = (struct ESCROW_PlaintextPluginOperation *)plugin_op_wrap->plugin_op; | 232 | p_op = (struct ESCROW_PlaintextPluginOperation *)plugin_op_wrap->plugin_op; |
170 | p_op->h = h; | 233 | p_op->h = h; |
234 | p_op->cont = cb; | ||
171 | 235 | ||
172 | w = GNUNET_new (struct ESCROW_Plugin_VerifyContinuationWrapper); | 236 | w = GNUNET_new (struct ESCROW_Plugin_VerifyContinuationWrapper); |
173 | w->h = h; | 237 | w->h = h; |
238 | p_op->verify_wrap = w; | ||
174 | 239 | ||
175 | if (NULL == ego) | 240 | if (NULL == ego) |
176 | { | 241 | { |
177 | w->verificationResult = GNUNET_ESCROW_INVALID; | 242 | w->verificationResult = GNUNET_ESCROW_INVALID; |
178 | p_op->sched_task = GNUNET_SCHEDULER_add_now (cb, w); | 243 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); |
179 | return plugin_op_wrap; | 244 | return plugin_op_wrap; |
180 | } | 245 | } |
181 | pk = GNUNET_IDENTITY_ego_get_private_key (ego); | 246 | pk = GNUNET_IDENTITY_ego_get_private_key (ego); |
@@ -186,7 +251,7 @@ verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
186 | GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID; | 251 | GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID; |
187 | 252 | ||
188 | w->verificationResult = verificationResult; | 253 | w->verificationResult = verificationResult; |
189 | p_op->sched_task = GNUNET_SCHEDULER_add_now (cb, w); | 254 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); |
190 | return plugin_op_wrap; | 255 | return plugin_op_wrap; |
191 | } | 256 | } |
192 | 257 | ||
@@ -208,15 +273,12 @@ ego_created (const struct GNUNET_IDENTITY_Ego *ego) | |||
208 | if (0 == strcmp (ego_pk_string, curr_pk_string)) | 273 | if (0 == strcmp (ego_pk_string, curr_pk_string)) |
209 | { | 274 | { |
210 | // the ego was created due to a restore operation that is not yet finished | 275 | // the ego was created due to a restore operation that is not yet finished |
276 | curr_p_op->ego_wrap->ego = ego; | ||
277 | curr_p_op->cont (curr_p_op->ego_wrap); | ||
278 | |||
279 | cleanup_plugin_operation (curr); | ||
280 | |||
211 | GNUNET_free (curr_pk_string); | 281 | GNUNET_free (curr_pk_string); |
212 | GNUNET_CONTAINER_DLL_remove (ph.plugin_op_head, | ||
213 | ph.plugin_op_tail, | ||
214 | curr); | ||
215 | curr_p_op->ego_cont_wrap->ego = ego; | ||
216 | curr_p_op->sched_task = GNUNET_SCHEDULER_add_now (curr_p_op->cont, | ||
217 | curr_p_op->ego_cont_wrap); | ||
218 | GNUNET_free (curr_p_op); | ||
219 | GNUNET_free (curr); | ||
220 | GNUNET_free (ego_pk_string); | 282 | GNUNET_free (ego_pk_string); |
221 | return; | 283 | return; |
222 | } | 284 | } |
@@ -251,8 +313,8 @@ create_finished (void *cls, | |||
251 | emsg); | 313 | emsg); |
252 | else | 314 | else |
253 | fprintf (stderr, "Failed to create ego!"); | 315 | fprintf (stderr, "Failed to create ego!"); |
254 | p_op->ego_cont_wrap->ego = NULL; | 316 | p_op->ego_wrap->ego = NULL; |
255 | p_op->sched_task = GNUNET_SCHEDULER_add_now (p_op->cont, p_op->ego_cont_wrap); | 317 | p_op->cont (p_op->ego_wrap); |
256 | return; | 318 | return; |
257 | } | 319 | } |
258 | 320 | ||
@@ -262,6 +324,19 @@ create_finished (void *cls, | |||
262 | } | 324 | } |
263 | 325 | ||
264 | 326 | ||
327 | void | ||
328 | handle_restore_error (void *cls) | ||
329 | { | ||
330 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | ||
331 | struct ESCROW_PlaintextPluginOperation *p_op; | ||
332 | |||
333 | p_op = (struct ESCROW_PlaintextPluginOperation*)plugin_op_wrap->plugin_op; | ||
334 | p_op->cont (p_op->ego_wrap); | ||
335 | |||
336 | cleanup_plugin_operation (plugin_op_wrap); | ||
337 | } | ||
338 | |||
339 | |||
265 | /** | 340 | /** |
266 | * Restore the key from plaintext escrow | 341 | * Restore the key from plaintext escrow |
267 | * | 342 | * |
@@ -276,7 +351,7 @@ struct ESCROW_PluginOperationWrapper * | |||
276 | restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | 351 | restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, |
277 | struct GNUNET_ESCROW_Anchor *escrowAnchor, | 352 | struct GNUNET_ESCROW_Anchor *escrowAnchor, |
278 | char *egoName, | 353 | char *egoName, |
279 | GNUNET_SCHEDULER_TaskCallback cb) | 354 | ESCROW_Plugin_Continuation cb) |
280 | { | 355 | { |
281 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; | 356 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; |
282 | struct GNUNET_IDENTITY_Operation *id_op; | 357 | struct GNUNET_IDENTITY_Operation *id_op; |
@@ -298,14 +373,14 @@ restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
298 | 373 | ||
299 | w = GNUNET_new (struct ESCROW_Plugin_EgoContinuationWrapper); | 374 | w = GNUNET_new (struct ESCROW_Plugin_EgoContinuationWrapper); |
300 | w->h = h; | 375 | w->h = h; |
301 | 376 | p_op->ego_wrap = w; | |
302 | p_op->ego_cont_wrap = w; | ||
303 | 377 | ||
304 | if (NULL == escrowAnchor) | 378 | if (NULL == escrowAnchor) |
305 | { | 379 | { |
306 | // TODO: correct error handling? | 380 | // TODO: correct error handling? |
307 | w->ego = NULL; | 381 | w->ego = NULL; |
308 | p_op->sched_task = GNUNET_SCHEDULER_add_now (cb, w); | 382 | // schedule handle_restore_error, which calls the callback and cleans up |
383 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&handle_restore_error, plugin_op_wrap); | ||
309 | return plugin_op_wrap; | 384 | return plugin_op_wrap; |
310 | } | 385 | } |
311 | if (GNUNET_OK != | 386 | if (GNUNET_OK != |
@@ -314,7 +389,8 @@ restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
314 | &pk)) | 389 | &pk)) |
315 | { | 390 | { |
316 | w->ego = NULL; | 391 | w->ego = NULL; |
317 | p_op->sched_task = GNUNET_SCHEDULER_add_now (cb, w); | 392 | // schedule handle_restore_error, which calls the callback and cleans up |
393 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&handle_restore_error, plugin_op_wrap); | ||
318 | return plugin_op_wrap; | 394 | return plugin_op_wrap; |
319 | } | 395 | } |
320 | 396 | ||