diff options
author | jospaeth <spaethj@in.tum.de> | 2020-08-03 11:58:50 +0200 |
---|---|---|
committer | jospaeth <spaethj@in.tum.de> | 2020-08-03 11:58:50 +0200 |
commit | 1c09fd9efa3ce06b980b8e493644a7d271c52747 (patch) | |
tree | b1c1dfaa305d0a9e8b8b6a1145df80e1538854db /src/escrow/escrow_api.c | |
parent | 7694804564e41a04e9d6e0909a59ee7ec3b7e627 (diff) | |
download | gnunet-1c09fd9efa3ce06b980b8e493644a7d271c52747.tar.gz gnunet-1c09fd9efa3ce06b980b8e493644a7d271c52747.zip |
major restructuring of the escrow component
refine the several layers (CLI, API, plugins) and enable async execution
Diffstat (limited to 'src/escrow/escrow_api.c')
-rw-r--r-- | src/escrow/escrow_api.c | 96 |
1 files changed, 63 insertions, 33 deletions
diff --git a/src/escrow/escrow_api.c b/src/escrow/escrow_api.c index 579707af2..20cae2f5c 100644 --- a/src/escrow/escrow_api.c +++ b/src/escrow/escrow_api.c | |||
@@ -128,6 +128,8 @@ GNUNET_ESCROW_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
128 | 128 | ||
129 | h = GNUNET_new (struct GNUNET_ESCROW_Handle); | 129 | h = GNUNET_new (struct GNUNET_ESCROW_Handle); |
130 | h->cfg = cfg; | 130 | h->cfg = cfg; |
131 | h->op_head = NULL; | ||
132 | h->op_tail = NULL; | ||
131 | return h; | 133 | return h; |
132 | } | 134 | } |
133 | 135 | ||
@@ -174,22 +176,26 @@ GNUNET_ESCROW_fini (struct GNUNET_ESCROW_Handle *h) | |||
174 | 176 | ||
175 | 177 | ||
176 | void | 178 | void |
177 | handle_start_escrow_result (void *cls, | 179 | handle_start_escrow_result (void *cls) |
178 | struct GNUNET_ESCROW_Anchor *escrowAnchor) | ||
179 | { | 180 | { |
180 | struct GNUNET_ESCROW_Handle *h = cls; | 181 | struct GNUNET_ESCROW_Plugin_AnchorContinuationWrapper *w = cls; |
181 | struct GNUNET_ESCROW_Operation *op; | 182 | struct GNUNET_ESCROW_Operation *op; |
182 | 183 | ||
183 | op = h->op_head; | 184 | for (op = w->h->op_head; NULL != op; op = op->next) |
185 | if (1) // TODO: find condition (e.g. unique ID) | ||
186 | break; | ||
187 | |||
184 | if (NULL == op) | 188 | if (NULL == op) |
185 | { | 189 | { |
186 | GNUNET_break (0); | 190 | GNUNET_break (0); |
191 | GNUNET_free (w); | ||
187 | return; | 192 | return; |
188 | } | 193 | } |
189 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 194 | GNUNET_CONTAINER_DLL_remove (w->h->op_head, w->h->op_tail, op); |
190 | if (NULL != op->cb_get) | 195 | if (NULL != op->cb_put) |
191 | op->cb_put (op->cb_cls, escrowAnchor); | 196 | op->cb_put (w->escrowAnchor); |
192 | GNUNET_free (op); | 197 | GNUNET_free (op); |
198 | GNUNET_free (w); | ||
193 | } | 199 | } |
194 | 200 | ||
195 | 201 | ||
@@ -216,12 +222,13 @@ GNUNET_ESCROW_put (struct GNUNET_ESCROW_Handle *h, | |||
216 | 222 | ||
217 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); | 223 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); |
218 | op->h = h; | 224 | op->h = h; |
225 | op->method = method; | ||
219 | op->cb_put = cb; | 226 | op->cb_put = cb; |
220 | op->cb_cls = cb_cls; | 227 | op->cb_cls = cb_cls; |
221 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 228 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); |
222 | 229 | ||
223 | api = init_plugin (h, method); | 230 | api = init_plugin (h, method); |
224 | api->start_key_escrow (h, ego, &handle_start_escrow_result); | 231 | op->plugin_op_wrap = api->start_key_escrow (h, ego, &handle_start_escrow_result); |
225 | 232 | ||
226 | return op; | 233 | return op; |
227 | } | 234 | } |
@@ -250,6 +257,7 @@ GNUNET_ESCROW_renew (struct GNUNET_ESCROW_Handle *h, | |||
250 | 257 | ||
251 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); | 258 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); |
252 | op->h = h; | 259 | op->h = h; |
260 | op->method = method; | ||
253 | op->cb_renew = cb; | 261 | op->cb_renew = cb; |
254 | op->cb_cls = cb_cls; | 262 | op->cb_cls = cb_cls; |
255 | 263 | ||
@@ -261,22 +269,26 @@ GNUNET_ESCROW_renew (struct GNUNET_ESCROW_Handle *h, | |||
261 | 269 | ||
262 | 270 | ||
263 | static void | 271 | static void |
264 | handle_restore_key_result (void *cls, | 272 | handle_restore_key_result (void *cls) |
265 | const struct GNUNET_IDENTITY_Ego *ego) | ||
266 | { | 273 | { |
267 | struct GNUNET_ESCROW_Handle *h = cls; | 274 | struct GNUNET_ESCROW_Plugin_EgoContinuationWrapper *w = cls; |
268 | struct GNUNET_ESCROW_Operation *op; | 275 | struct GNUNET_ESCROW_Operation *op; |
269 | 276 | ||
270 | op = h->op_head; | 277 | for (op = w->h->op_head; NULL != op; op = op->next) |
278 | if (1) // TODO: find condition (e.g. unique ID) | ||
279 | break; | ||
280 | |||
271 | if (NULL == op) | 281 | if (NULL == op) |
272 | { | 282 | { |
273 | GNUNET_break (0); | 283 | GNUNET_break (0); |
284 | GNUNET_free (w); | ||
274 | return; | 285 | return; |
275 | } | 286 | } |
276 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 287 | GNUNET_CONTAINER_DLL_remove (w->h->op_head, w->h->op_tail, op); |
277 | if (NULL != op->cb_get) | 288 | if (NULL != op->cb_get) |
278 | op->cb_get (op->cb_cls, ego); | 289 | op->cb_get (w->ego); |
279 | GNUNET_free (op); | 290 | GNUNET_free (op); |
291 | GNUNET_free (w); | ||
280 | } | 292 | } |
281 | 293 | ||
282 | 294 | ||
@@ -305,34 +317,41 @@ GNUNET_ESCROW_get (struct GNUNET_ESCROW_Handle *h, | |||
305 | 317 | ||
306 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); | 318 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); |
307 | op->h = h; | 319 | op->h = h; |
320 | op->method = method; | ||
308 | op->cb_get = cb; | 321 | op->cb_get = cb; |
309 | op->cb_cls = cb_cls; | 322 | op->cb_cls = cb_cls; |
310 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 323 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); |
311 | 324 | ||
312 | api = init_plugin (h, method); | 325 | api = init_plugin (h, method); |
313 | api->restore_key (h, escrowAnchor, egoName, &handle_restore_key_result); | 326 | op->plugin_op_wrap = api->restore_key (h, escrowAnchor, egoName, &handle_restore_key_result); |
314 | 327 | ||
315 | return op; | 328 | return op; |
316 | } | 329 | } |
317 | 330 | ||
318 | 331 | ||
319 | void | 332 | void |
320 | handle_verify_escrow_result (void *cls, | 333 | handle_verify_escrow_result (void *cls) |
321 | int verificationResult) | ||
322 | { | 334 | { |
323 | struct GNUNET_ESCROW_Handle *h = cls; | 335 | struct GNUNET_ESCROW_Plugin_VerifyContinuationWrapper *w = cls; |
324 | struct GNUNET_ESCROW_Operation *op; | 336 | struct GNUNET_ESCROW_Operation *op; |
325 | 337 | ||
326 | op = h->op_head; | 338 | for (op = w->h->op_head; NULL != op; op = op->next) |
339 | if (1) // TODO: find condition (e.g. unique ID) | ||
340 | break; | ||
341 | |||
327 | if (NULL == op) | 342 | if (NULL == op) |
328 | { | 343 | { |
329 | GNUNET_break (0); | 344 | GNUNET_break (0); |
345 | GNUNET_free (w); | ||
330 | return; | 346 | return; |
331 | } | 347 | } |
332 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 348 | GNUNET_CONTAINER_DLL_remove (w->h->op_head, w->h->op_tail, op); |
333 | if (NULL != op->cb_get) | 349 | if (NULL != op->cb_verify) |
334 | op->cb_verify (op->cb_cls, verificationResult); | 350 | op->cb_verify (w->verificationResult); |
351 | GNUNET_free (op->plugin_op_wrap->plugin_op); | ||
352 | GNUNET_free (op->plugin_op_wrap); | ||
335 | GNUNET_free (op); | 353 | GNUNET_free (op); |
354 | GNUNET_free (w); | ||
336 | } | 355 | } |
337 | 356 | ||
338 | 357 | ||
@@ -361,12 +380,13 @@ GNUNET_ESCROW_verify (struct GNUNET_ESCROW_Handle *h, | |||
361 | 380 | ||
362 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); | 381 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); |
363 | op->h = h; | 382 | op->h = h; |
383 | op->method = method; | ||
364 | op->cb_verify = cb; | 384 | op->cb_verify = cb; |
365 | op->cb_cls = cb_cls; | 385 | op->cb_cls = cb_cls; |
366 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 386 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); |
367 | 387 | ||
368 | api = init_plugin (h, method); | 388 | api = init_plugin (h, method); |
369 | api->verify_key_escrow (h, ego, escrowAnchor, &handle_verify_escrow_result); | 389 | op->plugin_op_wrap = api->verify_key_escrow (h, ego, escrowAnchor, &handle_verify_escrow_result); |
370 | 390 | ||
371 | return op; | 391 | return op; |
372 | } | 392 | } |
@@ -420,21 +440,31 @@ GNUNET_ESCROW_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h, | |||
420 | * be executed; this merely cancels the continuation. | 440 | * be executed; this merely cancels the continuation. |
421 | * | 441 | * |
422 | * @param op operation to cancel | 442 | * @param op operation to cancel |
423 | * @param method the escrow method to use | ||
424 | */ | 443 | */ |
425 | void | 444 | void |
426 | GNUNET_ESCROW_cancel (struct GNUNET_ESCROW_Operation *op, | 445 | GNUNET_ESCROW_cancel (struct GNUNET_ESCROW_Operation *op) |
427 | enum GNUNET_ESCROW_Key_Escrow_Method method) | ||
428 | { | 446 | { |
429 | const struct GNUNET_ESCROW_KeyPluginFunctions *api; | 447 | const struct GNUNET_ESCROW_KeyPluginFunctions *api; |
448 | struct GNUNET_ESCROW_Handle *h = op->h; | ||
449 | struct GNUNET_ESCROW_Operation *curr; | ||
430 | 450 | ||
431 | api = init_plugin (op->h, method); | 451 | // check if op is in our DLL |
432 | // TODO: api->cancel (...); | 452 | for (curr = h->op_head; NULL != curr; curr = curr->next) |
433 | 453 | { | |
434 | op->cb_put = NULL; | 454 | if (curr == op) |
435 | op->cb_renew = NULL; | 455 | { |
436 | op->cb_verify = NULL; | 456 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
437 | op->cb_get = NULL; | 457 | api = init_plugin (op->h, op->method); |
458 | api->cancel_plugin_operation (op->plugin_op_wrap); | ||
459 | // TODO: check which callback is not NULL? | ||
460 | op->cb_put = NULL; | ||
461 | op->cb_renew = NULL; | ||
462 | op->cb_verify = NULL; | ||
463 | op->cb_get = NULL; | ||
464 | GNUNET_free (op); | ||
465 | return; | ||
466 | } | ||
467 | } | ||
438 | } | 468 | } |
439 | 469 | ||
440 | 470 | ||