diff options
author | jospaeth <spaethj@in.tum.de> | 2020-07-22 17:23:53 +0200 |
---|---|---|
committer | jospaeth <spaethj@in.tum.de> | 2020-07-22 17:23:53 +0200 |
commit | 7694804564e41a04e9d6e0909a59ee7ec3b7e627 (patch) | |
tree | e4d0a539e0eec95677f94dba281f5d071d0ff292 /src/escrow/escrow_api.c | |
parent | 0c87a350df02b1dcaffe615f31a63e92be63aef1 (diff) | |
download | gnunet-7694804564e41a04e9d6e0909a59ee7ec3b7e627.tar.gz gnunet-7694804564e41a04e9d6e0909a59ee7ec3b7e627.zip |
handle escrow operations as dll, clean them up
(not yet finished)
Diffstat (limited to 'src/escrow/escrow_api.c')
-rw-r--r-- | src/escrow/escrow_api.c | 109 |
1 files changed, 99 insertions, 10 deletions
diff --git a/src/escrow/escrow_api.c b/src/escrow/escrow_api.c index ccd314db1..579707af2 100644 --- a/src/escrow/escrow_api.c +++ b/src/escrow/escrow_api.c | |||
@@ -75,7 +75,7 @@ static struct GNUNET_ESCROW_KeyPluginFunctions *anastasis_api; | |||
75 | * | 75 | * |
76 | * @return pointer to the escrow plugin API | 76 | * @return pointer to the escrow plugin API |
77 | */ | 77 | */ |
78 | struct GNUNET_ESCROW_KeyPluginFunctions * | 78 | const struct GNUNET_ESCROW_KeyPluginFunctions * |
79 | init_plugin (struct GNUNET_ESCROW_Handle *h, | 79 | init_plugin (struct GNUNET_ESCROW_Handle *h, |
80 | enum GNUNET_ESCROW_Key_Escrow_Method method) | 80 | enum GNUNET_ESCROW_Key_Escrow_Method method) |
81 | { | 81 | { |
@@ -173,6 +173,26 @@ GNUNET_ESCROW_fini (struct GNUNET_ESCROW_Handle *h) | |||
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
176 | void | ||
177 | handle_start_escrow_result (void *cls, | ||
178 | struct GNUNET_ESCROW_Anchor *escrowAnchor) | ||
179 | { | ||
180 | struct GNUNET_ESCROW_Handle *h = cls; | ||
181 | struct GNUNET_ESCROW_Operation *op; | ||
182 | |||
183 | op = h->op_head; | ||
184 | if (NULL == op) | ||
185 | { | ||
186 | GNUNET_break (0); | ||
187 | return; | ||
188 | } | ||
189 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | ||
190 | if (NULL != op->cb_get) | ||
191 | op->cb_put (op->cb_cls, escrowAnchor); | ||
192 | GNUNET_free (op); | ||
193 | } | ||
194 | |||
195 | |||
176 | /** | 196 | /** |
177 | * Put some data in escrow using the specified escrow method | 197 | * Put some data in escrow using the specified escrow method |
178 | * | 198 | * |
@@ -192,15 +212,16 @@ GNUNET_ESCROW_put (struct GNUNET_ESCROW_Handle *h, | |||
192 | void *cb_cls) | 212 | void *cb_cls) |
193 | { | 213 | { |
194 | struct GNUNET_ESCROW_Operation *op; | 214 | struct GNUNET_ESCROW_Operation *op; |
195 | struct GNUNET_ESCROW_KeyPluginFunctions *api; | 215 | const struct GNUNET_ESCROW_KeyPluginFunctions *api; |
196 | 216 | ||
197 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); | 217 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); |
198 | op->h = h; | 218 | op->h = h; |
199 | op->cb_put = cb; | 219 | op->cb_put = cb; |
200 | op->cb_cls = cb_cls; | 220 | op->cb_cls = cb_cls; |
221 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | ||
201 | 222 | ||
202 | api = init_plugin (h, method); | 223 | api = init_plugin (h, method); |
203 | api->start_key_escrow (op, ego); | 224 | api->start_key_escrow (h, ego, &handle_start_escrow_result); |
204 | 225 | ||
205 | return op; | 226 | return op; |
206 | } | 227 | } |
@@ -225,11 +246,12 @@ GNUNET_ESCROW_renew (struct GNUNET_ESCROW_Handle *h, | |||
225 | void *cb_cls) | 246 | void *cb_cls) |
226 | { | 247 | { |
227 | struct GNUNET_ESCROW_Operation *op; | 248 | struct GNUNET_ESCROW_Operation *op; |
228 | struct GNUNET_ESCROW_KeyPluginFunctions *api; | 249 | const struct GNUNET_ESCROW_KeyPluginFunctions *api; |
229 | 250 | ||
230 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); | 251 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); |
231 | op->h = h; | 252 | op->h = h; |
232 | op->cb_renew = cb; | 253 | op->cb_renew = cb; |
254 | op->cb_cls = cb_cls; | ||
233 | 255 | ||
234 | api = init_plugin (h, method); | 256 | api = init_plugin (h, method); |
235 | api->renew_key_escrow (op, escrowAnchor); | 257 | api->renew_key_escrow (op, escrowAnchor); |
@@ -238,6 +260,26 @@ GNUNET_ESCROW_renew (struct GNUNET_ESCROW_Handle *h, | |||
238 | } | 260 | } |
239 | 261 | ||
240 | 262 | ||
263 | static void | ||
264 | handle_restore_key_result (void *cls, | ||
265 | const struct GNUNET_IDENTITY_Ego *ego) | ||
266 | { | ||
267 | struct GNUNET_ESCROW_Handle *h = cls; | ||
268 | struct GNUNET_ESCROW_Operation *op; | ||
269 | |||
270 | op = h->op_head; | ||
271 | if (NULL == op) | ||
272 | { | ||
273 | GNUNET_break (0); | ||
274 | return; | ||
275 | } | ||
276 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | ||
277 | if (NULL != op->cb_get) | ||
278 | op->cb_get (op->cb_cls, ego); | ||
279 | GNUNET_free (op); | ||
280 | } | ||
281 | |||
282 | |||
241 | /** | 283 | /** |
242 | * Get the escrowed data back | 284 | * Get the escrowed data back |
243 | * | 285 | * |
@@ -259,19 +301,41 @@ GNUNET_ESCROW_get (struct GNUNET_ESCROW_Handle *h, | |||
259 | void *cb_cls) | 301 | void *cb_cls) |
260 | { | 302 | { |
261 | struct GNUNET_ESCROW_Operation *op; | 303 | struct GNUNET_ESCROW_Operation *op; |
262 | struct GNUNET_ESCROW_KeyPluginFunctions *api; | 304 | const struct GNUNET_ESCROW_KeyPluginFunctions *api; |
263 | 305 | ||
264 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); | 306 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); |
265 | op->h = h; | 307 | op->h = h; |
266 | op->cb_get = cb; | 308 | op->cb_get = cb; |
309 | op->cb_cls = cb_cls; | ||
310 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | ||
267 | 311 | ||
268 | api = init_plugin (h, method); | 312 | api = init_plugin (h, method); |
269 | api->restore_key (op, escrowAnchor, egoName); | 313 | api->restore_key (h, escrowAnchor, egoName, &handle_restore_key_result); |
270 | 314 | ||
271 | return op; | 315 | return op; |
272 | } | 316 | } |
273 | 317 | ||
274 | 318 | ||
319 | void | ||
320 | handle_verify_escrow_result (void *cls, | ||
321 | int verificationResult) | ||
322 | { | ||
323 | struct GNUNET_ESCROW_Handle *h = cls; | ||
324 | struct GNUNET_ESCROW_Operation *op; | ||
325 | |||
326 | op = h->op_head; | ||
327 | if (NULL == op) | ||
328 | { | ||
329 | GNUNET_break (0); | ||
330 | return; | ||
331 | } | ||
332 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | ||
333 | if (NULL != op->cb_get) | ||
334 | op->cb_verify (op->cb_cls, verificationResult); | ||
335 | GNUNET_free (op); | ||
336 | } | ||
337 | |||
338 | |||
275 | /** | 339 | /** |
276 | * Verify the escrowed data | 340 | * Verify the escrowed data |
277 | * | 341 | * |
@@ -293,14 +357,16 @@ GNUNET_ESCROW_verify (struct GNUNET_ESCROW_Handle *h, | |||
293 | void *cb_cls) | 357 | void *cb_cls) |
294 | { | 358 | { |
295 | struct GNUNET_ESCROW_Operation *op; | 359 | struct GNUNET_ESCROW_Operation *op; |
296 | struct GNUNET_ESCROW_KeyPluginFunctions *api; | 360 | const struct GNUNET_ESCROW_KeyPluginFunctions *api; |
297 | 361 | ||
298 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); | 362 | op = GNUNET_new (struct GNUNET_ESCROW_Operation); |
299 | op->h = h; | 363 | op->h = h; |
300 | op->cb_verify = cb; | 364 | op->cb_verify = cb; |
365 | op->cb_cls = cb_cls; | ||
366 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | ||
301 | 367 | ||
302 | api = init_plugin (h, method); | 368 | api = init_plugin (h, method); |
303 | api->verify_key_escrow (op, ego, escrowAnchor); | 369 | api->verify_key_escrow (h, ego, escrowAnchor, &handle_verify_escrow_result); |
304 | 370 | ||
305 | return op; | 371 | return op; |
306 | } | 372 | } |
@@ -321,7 +387,7 @@ GNUNET_ESCROW_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, | |||
321 | char *anchorString, | 387 | char *anchorString, |
322 | enum GNUNET_ESCROW_Key_Escrow_Method method) | 388 | enum GNUNET_ESCROW_Key_Escrow_Method method) |
323 | { | 389 | { |
324 | struct GNUNET_ESCROW_KeyPluginFunctions *api; | 390 | const struct GNUNET_ESCROW_KeyPluginFunctions *api; |
325 | 391 | ||
326 | api = init_plugin (h, method); | 392 | api = init_plugin (h, method); |
327 | return api->anchor_string_to_data (h, anchorString); | 393 | return api->anchor_string_to_data (h, anchorString); |
@@ -342,11 +408,34 @@ GNUNET_ESCROW_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h, | |||
342 | struct GNUNET_ESCROW_Anchor *escrowAnchor, | 408 | struct GNUNET_ESCROW_Anchor *escrowAnchor, |
343 | enum GNUNET_ESCROW_Key_Escrow_Method method) | 409 | enum GNUNET_ESCROW_Key_Escrow_Method method) |
344 | { | 410 | { |
345 | struct GNUNET_ESCROW_KeyPluginFunctions *api; | 411 | const struct GNUNET_ESCROW_KeyPluginFunctions *api; |
346 | 412 | ||
347 | api = init_plugin (h, method); | 413 | api = init_plugin (h, method); |
348 | return api->anchor_data_to_string (h, escrowAnchor); | 414 | return api->anchor_data_to_string (h, escrowAnchor); |
349 | } | 415 | } |
350 | 416 | ||
351 | 417 | ||
418 | /** | ||
419 | * Cancel an escrow operation. Note that the operation MAY still | ||
420 | * be executed; this merely cancels the continuation. | ||
421 | * | ||
422 | * @param op operation to cancel | ||
423 | * @param method the escrow method to use | ||
424 | */ | ||
425 | void | ||
426 | GNUNET_ESCROW_cancel (struct GNUNET_ESCROW_Operation *op, | ||
427 | enum GNUNET_ESCROW_Key_Escrow_Method method) | ||
428 | { | ||
429 | const struct GNUNET_ESCROW_KeyPluginFunctions *api; | ||
430 | |||
431 | api = init_plugin (op->h, method); | ||
432 | // TODO: api->cancel (...); | ||
433 | |||
434 | op->cb_put = NULL; | ||
435 | op->cb_renew = NULL; | ||
436 | op->cb_verify = NULL; | ||
437 | op->cb_get = NULL; | ||
438 | } | ||
439 | |||
440 | |||
352 | /* end of escrow_api.c */ | 441 | /* end of escrow_api.c */ |