diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/reclaim/gnunet-service-reclaim_tickets.c | 640 | ||||
-rw-r--r-- | src/reclaim/gnunet-service-reclaim_tickets.h | 139 |
2 files changed, 613 insertions, 166 deletions
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c index 645f26baf..fcfb2267d 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.c +++ b/src/reclaim/gnunet-service-reclaim_tickets.c | |||
@@ -27,8 +27,17 @@ | |||
27 | #include <inttypes.h> | 27 | #include <inttypes.h> |
28 | #include "gnunet-service-reclaim_tickets.h" | 28 | #include "gnunet-service-reclaim_tickets.h" |
29 | 29 | ||
30 | |||
31 | /** | ||
32 | * FIXME: the defaul ticket iteration interval should probably | ||
33 | * be the minimim attribute expiration. | ||
34 | */ | ||
30 | #define DEFAULT_TICKET_REFRESH_INTERVAL GNUNET_TIME_UNIT_HOURS | 35 | #define DEFAULT_TICKET_REFRESH_INTERVAL GNUNET_TIME_UNIT_HOURS |
31 | 36 | ||
37 | /** | ||
38 | * Handle for a parallel GNS lookup job | ||
39 | * (Declaration further below) | ||
40 | */ | ||
32 | struct ParallelLookup; | 41 | struct ParallelLookup; |
33 | 42 | ||
34 | 43 | ||
@@ -59,6 +68,9 @@ struct TicketReference | |||
59 | }; | 68 | }; |
60 | 69 | ||
61 | 70 | ||
71 | /** | ||
72 | * Handle to a consume operation | ||
73 | */ | ||
62 | struct RECLAIM_TICKETS_ConsumeHandle | 74 | struct RECLAIM_TICKETS_ConsumeHandle |
63 | { | 75 | { |
64 | /** | 76 | /** |
@@ -117,6 +129,7 @@ struct RECLAIM_TICKETS_ConsumeHandle | |||
117 | void *cb_cls; | 129 | void *cb_cls; |
118 | }; | 130 | }; |
119 | 131 | ||
132 | |||
120 | /** | 133 | /** |
121 | * Handle for a parallel GNS lookup job | 134 | * Handle for a parallel GNS lookup job |
122 | */ | 135 | */ |
@@ -185,6 +198,7 @@ struct TicketIssueHandle | |||
185 | void *cb_cls; | 198 | void *cb_cls; |
186 | }; | 199 | }; |
187 | 200 | ||
201 | |||
188 | /** | 202 | /** |
189 | * Ticket iterator | 203 | * Ticket iterator |
190 | */ | 204 | */ |
@@ -297,28 +311,25 @@ struct RECLAIM_TICKETS_RevokeHandle | |||
297 | struct TicketRecordsEntry *tickets_to_update_tail; | 311 | struct TicketRecordsEntry *tickets_to_update_tail; |
298 | }; | 312 | }; |
299 | 313 | ||
314 | |||
300 | /** | 315 | /** |
301 | * Ticket expiration interval | 316 | * Ticket expiration interval |
302 | */ | 317 | */ |
303 | static struct GNUNET_TIME_Relative ticket_refresh_interval; | 318 | static struct GNUNET_TIME_Relative ticket_refresh_interval; |
304 | 319 | ||
320 | |||
305 | /* Namestore handle */ | 321 | /* Namestore handle */ |
306 | static struct GNUNET_NAMESTORE_Handle *nsh; | 322 | static struct GNUNET_NAMESTORE_Handle *nsh; |
307 | 323 | ||
324 | |||
308 | /* GNS handle */ | 325 | /* GNS handle */ |
309 | static struct GNUNET_GNS_Handle *gns; | 326 | static struct GNUNET_GNS_Handle *gns; |
310 | 327 | ||
328 | |||
311 | /* Handle to the statistics service */ | 329 | /* Handle to the statistics service */ |
312 | static struct GNUNET_STATISTICS_Handle *stats; | 330 | static struct GNUNET_STATISTICS_Handle *stats; |
313 | 331 | ||
314 | static void | ||
315 | move_attrs (struct RECLAIM_TICKETS_RevokeHandle *rh); | ||
316 | 332 | ||
317 | static void | ||
318 | move_attrs_cont (void *cls) | ||
319 | { | ||
320 | move_attrs ((struct RECLAIM_TICKETS_RevokeHandle *) cls); | ||
321 | } | ||
322 | 333 | ||
323 | /** | 334 | /** |
324 | * Cleanup revoke handle | 335 | * Cleanup revoke handle |
@@ -353,108 +364,117 @@ cleanup_rvk (struct RECLAIM_TICKETS_RevokeHandle *rh) | |||
353 | GNUNET_free (rh); | 364 | GNUNET_free (rh); |
354 | } | 365 | } |
355 | 366 | ||
367 | |||
368 | /** | ||
369 | * For each ticket, store new, updated attribute references | ||
370 | * (Implementation further below) | ||
371 | * | ||
372 | * @param cls handle to the operation | ||
373 | */ | ||
356 | static void | 374 | static void |
357 | del_attr_finished (void *cls, int32_t success, const char *emsg) | 375 | process_tickets (void *cls); |
376 | |||
377 | |||
378 | /** | ||
379 | * Finished storing updated attribute references. | ||
380 | * Abort on error, else continue processing tickets | ||
381 | * | ||
382 | * @param cls handle to the operation | ||
383 | * @param success result of namestore operation | ||
384 | * @param emsg (NULL on success) | ||
385 | */ | ||
386 | static void | ||
387 | ticket_processed (void *cls, int32_t success, const char *emsg) | ||
358 | { | 388 | { |
359 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 389 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
360 | rvk->ns_qe = NULL; | 390 | rvk->ns_qe = NULL; |
361 | if (GNUNET_SYSERR == success) | 391 | GNUNET_SCHEDULER_add_now (&process_tickets, rvk); |
362 | { | ||
363 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
364 | "Error removing attribute: %s\n", | ||
365 | emsg); | ||
366 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | ||
367 | cleanup_rvk (rvk); | ||
368 | return; | ||
369 | } | ||
370 | rvk->move_attr = rvk->move_attr->next; | ||
371 | GNUNET_SCHEDULER_add_now (&move_attrs_cont, rvk); | ||
372 | } | 392 | } |
373 | 393 | ||
394 | |||
395 | /** | ||
396 | * For each ticket, store new, updated attribute references | ||
397 | * | ||
398 | * @param cls handle to the operation | ||
399 | */ | ||
374 | static void | 400 | static void |
375 | move_attr_finished (void *cls, int32_t success, const char *emsg) | 401 | process_tickets (void *cls) |
376 | { | 402 | { |
377 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 403 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
378 | char *label; | 404 | struct TicketRecordsEntry *le; |
379 | rvk->ns_qe = NULL; | 405 | struct RevokedAttributeEntry *ae; |
380 | if (GNUNET_SYSERR == success) | 406 | if (NULL == rvk->tickets_to_update_head) |
381 | { | 407 | { |
382 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error moving attribute: %s\n", emsg); | 408 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
409 | "Finished updatding tickets, success\n"); | ||
410 | rvk->cb (rvk->cb_cls, GNUNET_OK); | ||
411 | cleanup_rvk (rvk); | ||
412 | return; | ||
413 | } | ||
414 | le = rvk->tickets_to_update_head; | ||
415 | GNUNET_CONTAINER_DLL_remove (rvk->tickets_to_update_head, | ||
416 | rvk->tickets_to_update_tail, | ||
417 | le); | ||
418 | struct GNUNET_GNSRECORD_Data rd[le->rd_count]; | ||
419 | if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize (le->data_size, | ||
420 | le->data, | ||
421 | le->rd_count, | ||
422 | rd)) | ||
423 | { | ||
424 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
425 | "Unable to deserialize ticket record(s)\n"); | ||
383 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | 426 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); |
384 | cleanup_rvk (rvk); | 427 | cleanup_rvk (rvk); |
385 | return; | 428 | return; |
386 | } | 429 | } |
387 | label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->old_id, | 430 | for (int i = 0; i < le->rd_count; i++) |
388 | sizeof (uint64_t)); | 431 | { |
389 | GNUNET_assert (NULL != label); | 432 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) |
390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing attribute %s\n", label); | 433 | continue; |
434 | for (ae = rvk->attrs_head; NULL != ae; ae = ae->next) | ||
435 | { | ||
436 | if (0 != memcmp (rd[i].data, &ae->old_id, sizeof (uint64_t))) | ||
437 | continue; | ||
438 | rd[i].data = &ae->new_id; | ||
439 | } | ||
440 | } | ||
391 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 441 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, |
392 | &rvk->identity, | 442 | &rvk->identity, |
393 | label, | 443 | le->label, |
394 | 0, | 444 | le->rd_count, |
395 | NULL, | 445 | rd, |
396 | &del_attr_finished, | 446 | &ticket_processed, |
397 | rvk); | 447 | rvk); |
398 | GNUNET_free (label); | 448 | GNUNET_free (le->label); |
449 | GNUNET_free (le->data); | ||
450 | GNUNET_free (le); | ||
399 | } | 451 | } |
400 | 452 | ||
401 | 453 | ||
454 | /** | ||
455 | * Done collecting tickets. Start processing. | ||
456 | * | ||
457 | * @param cls handle to the operation | ||
458 | */ | ||
402 | static void | 459 | static void |
403 | rvk_move_attr_cb (void *cls, | 460 | rvk_ticket_update_finished (void *cls) |
404 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | ||
405 | const char *label, | ||
406 | unsigned int rd_count, | ||
407 | const struct GNUNET_GNSRECORD_Data *rd) | ||
408 | { | 461 | { |
409 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 462 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
410 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; | 463 | rvk->ns_it = NULL; |
411 | struct GNUNET_GNSRECORD_Data new_rd; | 464 | GNUNET_SCHEDULER_add_now (&process_tickets, rvk); |
412 | struct RevokedAttributeEntry *le; | ||
413 | char *new_label; | ||
414 | char *attr_data; | ||
415 | rvk->ns_qe = NULL; | ||
416 | if (0 == rd_count) | ||
417 | { | ||
418 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
419 | "The attribute %s no longer exists!\n", | ||
420 | label); | ||
421 | le = rvk->move_attr; | ||
422 | rvk->move_attr = le->next; | ||
423 | GNUNET_CONTAINER_DLL_remove (rvk->attrs_head, rvk->attrs_tail, le); | ||
424 | GNUNET_free (le); | ||
425 | GNUNET_SCHEDULER_add_now (&move_attrs_cont, rvk); | ||
426 | return; | ||
427 | } | ||
428 | /** find a new place for this attribute **/ | ||
429 | rvk->move_attr->new_id = | ||
430 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | ||
431 | new_rd = *rd; | ||
432 | claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd->data, rd->data_size); | ||
433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
434 | "Attribute to update: Name=%s, ID=%" PRIu64 "\n", | ||
435 | claim->name, | ||
436 | claim->id); | ||
437 | claim->id = rvk->move_attr->new_id; | ||
438 | new_rd.data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (claim); | ||
439 | attr_data = GNUNET_malloc (rd->data_size); | ||
440 | new_rd.data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize (claim, attr_data); | ||
441 | new_rd.data = attr_data; | ||
442 | new_label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id, | ||
443 | sizeof (uint64_t)); | ||
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label); | ||
445 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | ||
446 | &rvk->identity, | ||
447 | new_label, | ||
448 | 1, | ||
449 | &new_rd, | ||
450 | &move_attr_finished, | ||
451 | rvk); | ||
452 | GNUNET_free (new_label); | ||
453 | GNUNET_free (claim); | ||
454 | GNUNET_free (attr_data); | ||
455 | } | 465 | } |
456 | 466 | ||
457 | 467 | ||
468 | /** | ||
469 | * We need to update all other tickets with the new attribute IDs. | ||
470 | * We first collect them all. Processing after. | ||
471 | * | ||
472 | * @param cls handle to the operation | ||
473 | * @param zone ticket issuer private key | ||
474 | * @param label ticket rnd | ||
475 | * @param rd_cound size of record set | ||
476 | * @param rd record set | ||
477 | */ | ||
458 | static void | 478 | static void |
459 | rvk_ticket_update (void *cls, | 479 | rvk_ticket_update (void *cls, |
460 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 480 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
@@ -498,106 +518,204 @@ rvk_ticket_update (void *cls, | |||
498 | } | 518 | } |
499 | 519 | ||
500 | 520 | ||
521 | /** | ||
522 | * Error iterating namestore. Abort. | ||
523 | * | ||
524 | * @param cls handle to the operation | ||
525 | */ | ||
501 | static void | 526 | static void |
502 | process_tickets (void *cls); | 527 | rvk_ns_iter_err (void *cls) |
528 | { | ||
529 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | ||
530 | rvk->ns_it = NULL; | ||
531 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
532 | "Namestore error on revocation (id=%" PRIu64 "\n", | ||
533 | rvk->move_attr->old_id); | ||
534 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | ||
535 | cleanup_rvk (rvk); | ||
536 | } | ||
503 | 537 | ||
504 | 538 | ||
539 | /** | ||
540 | * Error storing new attribute in namestore. Abort | ||
541 | * | ||
542 | * @param cls handle to the operation | ||
543 | */ | ||
505 | static void | 544 | static void |
506 | ticket_processed (void *cls, int32_t success, const char *emsg) | 545 | rvk_ns_err (void *cls) |
507 | { | 546 | { |
508 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 547 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
509 | rvk->ns_qe = NULL; | 548 | rvk->ns_qe = NULL; |
510 | GNUNET_SCHEDULER_add_now (&process_tickets, rvk); | 549 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
550 | "Namestore error on revocation (id=%" PRIu64 "\n", | ||
551 | rvk->move_attr->old_id); | ||
552 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | ||
553 | cleanup_rvk (rvk); | ||
511 | } | 554 | } |
512 | 555 | ||
556 | |||
557 | /** | ||
558 | * We change every attribute ID of the ticket attributes we | ||
559 | * want to revoke. | ||
560 | * When we are done, we need to update any other ticket which | ||
561 | * included references to any of the changed attributes. | ||
562 | * (Implementation further below) | ||
563 | * | ||
564 | * @param rvk handle to the operation | ||
565 | */ | ||
513 | static void | 566 | static void |
514 | process_tickets (void *cls) | 567 | move_attrs (struct RECLAIM_TICKETS_RevokeHandle *rh); |
568 | |||
569 | |||
570 | /** | ||
571 | * Delayed continuation for move_attrs | ||
572 | * | ||
573 | * @param cls handle to the operation. | ||
574 | */ | ||
575 | static void | ||
576 | move_attrs_cont (void *cls) | ||
577 | { | ||
578 | move_attrs ((struct RECLAIM_TICKETS_RevokeHandle *) cls); | ||
579 | } | ||
580 | |||
581 | |||
582 | /** | ||
583 | * Done deleting the old record. Abort on error. | ||
584 | * Else, continue updating attribute IDs. | ||
585 | * | ||
586 | * @param cls handle to the operation | ||
587 | * @param success result of the namestore operation | ||
588 | * @param emsg error message (NULL on success) | ||
589 | */ | ||
590 | static void | ||
591 | del_attr_finished (void *cls, int32_t success, const char *emsg) | ||
515 | { | 592 | { |
516 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 593 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
517 | struct TicketRecordsEntry *le; | 594 | rvk->ns_qe = NULL; |
518 | struct RevokedAttributeEntry *ae; | 595 | if (GNUNET_SYSERR == success) |
519 | if (NULL == rvk->tickets_to_update_head) | ||
520 | { | ||
521 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
522 | "Finished updatding tickets, success\n"); | ||
523 | rvk->cb (rvk->cb_cls, GNUNET_OK); | ||
524 | cleanup_rvk (rvk); | ||
525 | return; | ||
526 | } | ||
527 | le = rvk->tickets_to_update_head; | ||
528 | GNUNET_CONTAINER_DLL_remove (rvk->tickets_to_update_head, | ||
529 | rvk->tickets_to_update_tail, | ||
530 | le); | ||
531 | struct GNUNET_GNSRECORD_Data rd[le->rd_count]; | ||
532 | if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize (le->data_size, | ||
533 | le->data, | ||
534 | le->rd_count, | ||
535 | rd)) | ||
536 | { | 596 | { |
537 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 597 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
538 | "Unable to deserialize ticket record(s)\n"); | 598 | "Error removing attribute: %s\n", |
599 | emsg); | ||
539 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | 600 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); |
540 | cleanup_rvk (rvk); | 601 | cleanup_rvk (rvk); |
541 | return; | 602 | return; |
542 | } | 603 | } |
543 | for (int i = 0; i < le->rd_count; i++) | 604 | rvk->move_attr = rvk->move_attr->next; |
544 | { | 605 | GNUNET_SCHEDULER_add_now (&move_attrs_cont, rvk); |
545 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | ||
546 | continue; | ||
547 | for (ae = rvk->attrs_head; NULL != ae; ae = ae->next) | ||
548 | { | ||
549 | if (0 != memcmp (rd[i].data, &ae->old_id, sizeof (uint64_t))) | ||
550 | continue; | ||
551 | rd[i].data = &ae->new_id; | ||
552 | } | ||
553 | } | ||
554 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | ||
555 | &rvk->identity, | ||
556 | le->label, | ||
557 | le->rd_count, | ||
558 | rd, | ||
559 | &ticket_processed, | ||
560 | rvk); | ||
561 | GNUNET_free (le->label); | ||
562 | GNUNET_free (le->data); | ||
563 | GNUNET_free (le); | ||
564 | } | ||
565 | |||
566 | static void | ||
567 | rvk_ticket_update_finished (void *cls) | ||
568 | { | ||
569 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | ||
570 | rvk->ns_it = NULL; | ||
571 | GNUNET_SCHEDULER_add_now (&process_tickets, rvk); | ||
572 | } | 606 | } |
573 | 607 | ||
574 | 608 | ||
609 | /** | ||
610 | * Updated an attribute ID. | ||
611 | * Abort on error if namestore operation failed. | ||
612 | * Else, we have to delete the old record. | ||
613 | * | ||
614 | * @param cls handle to the operation | ||
615 | * @param success result of the store operation | ||
616 | * @param emsg error message (NULL on success) | ||
617 | */ | ||
575 | static void | 618 | static void |
576 | rvk_ns_iter_err (void *cls) | 619 | move_attr_finished (void *cls, int32_t success, const char *emsg) |
577 | { | 620 | { |
578 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 621 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
579 | rvk->ns_it = NULL; | 622 | char *label; |
580 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 623 | rvk->ns_qe = NULL; |
581 | "Namestore error on revocation (id=%" PRIu64 "\n", | 624 | if (GNUNET_SYSERR == success) |
582 | rvk->move_attr->old_id); | 625 | { |
583 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | 626 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error moving attribute: %s\n", emsg); |
584 | cleanup_rvk (rvk); | 627 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); |
628 | cleanup_rvk (rvk); | ||
629 | return; | ||
630 | } | ||
631 | label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->old_id, | ||
632 | sizeof (uint64_t)); | ||
633 | GNUNET_assert (NULL != label); | ||
634 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing attribute %s\n", label); | ||
635 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | ||
636 | &rvk->identity, | ||
637 | label, | ||
638 | 0, | ||
639 | NULL, | ||
640 | &del_attr_finished, | ||
641 | rvk); | ||
642 | GNUNET_free (label); | ||
585 | } | 643 | } |
586 | 644 | ||
587 | 645 | ||
646 | /** | ||
647 | * Got the referenced attribute. Updating the ID | ||
648 | * | ||
649 | * @param cls handle to the operation | ||
650 | * @param zone issuer identity | ||
651 | * @param label attribute ID | ||
652 | * @param rd_count size of record set (should be 1) | ||
653 | * @param rd record set (the attribute) | ||
654 | */ | ||
588 | static void | 655 | static void |
589 | rvk_ns_err (void *cls) | 656 | rvk_move_attr_cb (void *cls, |
657 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | ||
658 | const char *label, | ||
659 | unsigned int rd_count, | ||
660 | const struct GNUNET_GNSRECORD_Data *rd) | ||
590 | { | 661 | { |
591 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 662 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
663 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; | ||
664 | struct GNUNET_GNSRECORD_Data new_rd; | ||
665 | struct RevokedAttributeEntry *le; | ||
666 | char *new_label; | ||
667 | char *attr_data; | ||
592 | rvk->ns_qe = NULL; | 668 | rvk->ns_qe = NULL; |
593 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 669 | if (0 == rd_count) |
594 | "Namestore error on revocation (id=%" PRIu64 "\n", | 670 | { |
595 | rvk->move_attr->old_id); | 671 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
596 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | 672 | "The attribute %s no longer exists!\n", |
597 | cleanup_rvk (rvk); | 673 | label); |
674 | le = rvk->move_attr; | ||
675 | rvk->move_attr = le->next; | ||
676 | GNUNET_CONTAINER_DLL_remove (rvk->attrs_head, rvk->attrs_tail, le); | ||
677 | GNUNET_free (le); | ||
678 | GNUNET_SCHEDULER_add_now (&move_attrs_cont, rvk); | ||
679 | return; | ||
680 | } | ||
681 | /** find a new place for this attribute **/ | ||
682 | rvk->move_attr->new_id = | ||
683 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | ||
684 | new_rd = *rd; | ||
685 | claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd->data, rd->data_size); | ||
686 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
687 | "Attribute to update: Name=%s, ID=%" PRIu64 "\n", | ||
688 | claim->name, | ||
689 | claim->id); | ||
690 | claim->id = rvk->move_attr->new_id; | ||
691 | new_rd.data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (claim); | ||
692 | attr_data = GNUNET_malloc (rd->data_size); | ||
693 | new_rd.data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize (claim, attr_data); | ||
694 | new_rd.data = attr_data; | ||
695 | new_label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id, | ||
696 | sizeof (uint64_t)); | ||
697 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label); | ||
698 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | ||
699 | &rvk->identity, | ||
700 | new_label, | ||
701 | 1, | ||
702 | &new_rd, | ||
703 | &move_attr_finished, | ||
704 | rvk); | ||
705 | GNUNET_free (new_label); | ||
706 | GNUNET_free (claim); | ||
707 | GNUNET_free (attr_data); | ||
598 | } | 708 | } |
599 | 709 | ||
600 | 710 | ||
711 | /** | ||
712 | * We change every attribute ID of the ticket attributes we | ||
713 | * want to revoke. | ||
714 | * When we are done, we need to update any other ticket which | ||
715 | * included references to any of the changed attributes. | ||
716 | * | ||
717 | * @param rvk handle to the operation | ||
718 | */ | ||
601 | static void | 719 | static void |
602 | move_attrs (struct RECLAIM_TICKETS_RevokeHandle *rvk) | 720 | move_attrs (struct RECLAIM_TICKETS_RevokeHandle *rvk) |
603 | { | 721 | { |
@@ -632,6 +750,17 @@ move_attrs (struct RECLAIM_TICKETS_RevokeHandle *rvk) | |||
632 | } | 750 | } |
633 | 751 | ||
634 | 752 | ||
753 | /** | ||
754 | * Finished deleting ticket and attribute references. | ||
755 | * Abort on failure. | ||
756 | * Else, we start changing every attribute ID in the | ||
757 | * found attribute references so that access is no longer | ||
758 | * possible. | ||
759 | * | ||
760 | * @param cls handle to the operation | ||
761 | * @param success Namestore operation return value | ||
762 | * @param emsg error message (NULL on success) | ||
763 | */ | ||
635 | static void | 764 | static void |
636 | remove_ticket_cont (void *cls, int32_t success, const char *emsg) | 765 | remove_ticket_cont (void *cls, int32_t success, const char *emsg) |
637 | { | 766 | { |
@@ -658,6 +787,16 @@ remove_ticket_cont (void *cls, int32_t success, const char *emsg) | |||
658 | } | 787 | } |
659 | 788 | ||
660 | 789 | ||
790 | /** | ||
791 | * We found the attribute references. | ||
792 | * Store them for later and remove the record set. | ||
793 | * | ||
794 | * @param cls handle to the operation | ||
795 | * @param zone the issuer key | ||
796 | * @param label ticket rnd | ||
797 | * @param rd_cound size of record set | ||
798 | * @param rd record set | ||
799 | */ | ||
661 | static void | 800 | static void |
662 | revoke_attrs_cb (void *cls, | 801 | revoke_attrs_cb (void *cls, |
663 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 802 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
@@ -669,6 +808,10 @@ revoke_attrs_cb (void *cls, | |||
669 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 808 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
670 | struct RevokedAttributeEntry *le; | 809 | struct RevokedAttributeEntry *le; |
671 | rvk->ns_qe = NULL; | 810 | rvk->ns_qe = NULL; |
811 | /** | ||
812 | * Temporarily store attribute references. | ||
813 | * We need it later. | ||
814 | */ | ||
672 | for (int i = 0; i < rd_count; i++) | 815 | for (int i = 0; i < rd_count; i++) |
673 | { | 816 | { |
674 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | 817 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) |
@@ -679,7 +822,7 @@ revoke_attrs_cb (void *cls, | |||
679 | rvk->ticket_attrs++; | 822 | rvk->ticket_attrs++; |
680 | } | 823 | } |
681 | 824 | ||
682 | /** Now, remove ticket **/ | 825 | /** Remove attribute references **/ |
683 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 826 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, |
684 | &rvk->identity, | 827 | &rvk->identity, |
685 | label, | 828 | label, |
@@ -690,6 +833,11 @@ revoke_attrs_cb (void *cls, | |||
690 | } | 833 | } |
691 | 834 | ||
692 | 835 | ||
836 | /** | ||
837 | * Failed to query namestore. Abort operation | ||
838 | * | ||
839 | * @param cls handle to the operation | ||
840 | */ | ||
693 | static void | 841 | static void |
694 | rvk_attrs_err_cb (void *cls) | 842 | rvk_attrs_err_cb (void *cls) |
695 | { | 843 | { |
@@ -699,6 +847,17 @@ rvk_attrs_err_cb (void *cls) | |||
699 | } | 847 | } |
700 | 848 | ||
701 | 849 | ||
850 | /** | ||
851 | * Revoke a ticket. | ||
852 | * We start by looking up attribute references in order | ||
853 | * to change attribute IDs. | ||
854 | * | ||
855 | * @param ticket ticket to revoke | ||
856 | * @param identity private key of issuer | ||
857 | * @param cb revocation status callback | ||
858 | * @param cb_cls callback closure | ||
859 | * @return handle to the operation | ||
860 | */ | ||
702 | struct RECLAIM_TICKETS_RevokeHandle * | 861 | struct RECLAIM_TICKETS_RevokeHandle * |
703 | RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, | 862 | RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, |
704 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 863 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
@@ -729,17 +888,26 @@ RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, | |||
729 | } | 888 | } |
730 | 889 | ||
731 | 890 | ||
891 | /** | ||
892 | * Cancel a revocation. | ||
893 | * | ||
894 | * @param rh handle to the operation | ||
895 | */ | ||
732 | void | 896 | void |
733 | RECLAIM_TICKETS_revoke_cancel (struct RECLAIM_TICKETS_RevokeHandle *rh) | 897 | RECLAIM_TICKETS_revoke_cancel (struct RECLAIM_TICKETS_RevokeHandle *rh) |
734 | { | 898 | { |
899 | GNUNET_assert (NULL != rh); | ||
735 | cleanup_rvk (rh); | 900 | cleanup_rvk (rh); |
736 | } | 901 | } |
902 | |||
903 | |||
737 | /******************************* | 904 | /******************************* |
738 | * Ticket consume | 905 | * Ticket consume |
739 | *******************************/ | 906 | *******************************/ |
740 | 907 | ||
741 | /** | 908 | /** |
742 | * Cleanup ticket consume handle | 909 | * Cleanup ticket consume handle |
910 | * | ||
743 | * @param cth the handle to clean up | 911 | * @param cth the handle to clean up |
744 | */ | 912 | */ |
745 | static void | 913 | static void |
@@ -767,6 +935,13 @@ cleanup_cth (struct RECLAIM_TICKETS_ConsumeHandle *cth) | |||
767 | } | 935 | } |
768 | 936 | ||
769 | 937 | ||
938 | /** | ||
939 | * We found an attribute record. | ||
940 | * | ||
941 | * @param cls handle to the operation | ||
942 | * @param rd_cound size of record set | ||
943 | * @param rd record set | ||
944 | */ | ||
770 | static void | 945 | static void |
771 | process_parallel_lookup_result (void *cls, | 946 | process_parallel_lookup_result (void *cls, |
772 | uint32_t rd_count, | 947 | uint32_t rd_count, |
@@ -795,7 +970,7 @@ process_parallel_lookup_result (void *cls, | |||
795 | 970 | ||
796 | GNUNET_free (parallel_lookup); | 971 | GNUNET_free (parallel_lookup); |
797 | if (1 != rd_count) | 972 | if (1 != rd_count) |
798 | GNUNET_break (0); // TODO | 973 | GNUNET_break (0); // FIXME: We should never find this. |
799 | if (rd->record_type == GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR) | 974 | if (rd->record_type == GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR) |
800 | { | 975 | { |
801 | attr_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 976 | attr_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); |
@@ -805,15 +980,21 @@ process_parallel_lookup_result (void *cls, | |||
805 | cth->attrs->list_tail, | 980 | cth->attrs->list_tail, |
806 | attr_le); | 981 | attr_le); |
807 | } | 982 | } |
983 | |||
808 | if (NULL != cth->parallel_lookups_head) | 984 | if (NULL != cth->parallel_lookups_head) |
809 | return; // Wait for more | 985 | return; // Wait for more |
810 | /* Else we are done */ | ||
811 | 986 | ||
987 | /* Else we are done */ | ||
812 | cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL); | 988 | cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL); |
813 | cleanup_cth (cth); | 989 | cleanup_cth (cth); |
814 | } | 990 | } |
815 | 991 | ||
816 | 992 | ||
993 | /** | ||
994 | * Cancel the lookups for attribute records | ||
995 | * | ||
996 | * @param cls handle to the operation | ||
997 | */ | ||
817 | static void | 998 | static void |
818 | abort_parallel_lookups (void *cls) | 999 | abort_parallel_lookups (void *cls) |
819 | { | 1000 | { |
@@ -837,6 +1018,15 @@ abort_parallel_lookups (void *cls) | |||
837 | } | 1018 | } |
838 | 1019 | ||
839 | 1020 | ||
1021 | /** | ||
1022 | * GNS result with attribute references. | ||
1023 | * For each result, we start a (parallel) lookup of the actual | ||
1024 | * attribute record under the referenced label. | ||
1025 | * | ||
1026 | * @param cls handle to the operation | ||
1027 | * @param rd_cound size of the record set | ||
1028 | * @param rd record set | ||
1029 | */ | ||
840 | static void | 1030 | static void |
841 | lookup_authz_cb (void *cls, | 1031 | lookup_authz_cb (void *cls, |
842 | uint32_t rd_count, | 1032 | uint32_t rd_count, |
@@ -881,6 +1071,10 @@ lookup_authz_cb (void *cls, | |||
881 | cth->parallel_lookups_tail, | 1071 | cth->parallel_lookups_tail, |
882 | parallel_lookup); | 1072 | parallel_lookup); |
883 | } | 1073 | } |
1074 | /** | ||
1075 | * We started lookups. Add a timeout task. | ||
1076 | * FIXME: Really needed here? | ||
1077 | */ | ||
884 | if (NULL != cth->parallel_lookups_head) | 1078 | if (NULL != cth->parallel_lookups_head) |
885 | { | 1079 | { |
886 | cth->kill_task = GNUNET_SCHEDULER_add_delayed ( | 1080 | cth->kill_task = GNUNET_SCHEDULER_add_delayed ( |
@@ -889,11 +1083,25 @@ lookup_authz_cb (void *cls, | |||
889 | cth); | 1083 | cth); |
890 | return; | 1084 | return; |
891 | } | 1085 | } |
1086 | /** | ||
1087 | * No references found, return empty attribute list | ||
1088 | */ | ||
892 | cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL); | 1089 | cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL); |
893 | cleanup_cth (cth); | 1090 | cleanup_cth (cth); |
894 | } | 1091 | } |
895 | 1092 | ||
896 | 1093 | ||
1094 | /** | ||
1095 | * Consume a ticket. | ||
1096 | * We first looking attribute references under the label | ||
1097 | * ticket.rnd in GNS. | ||
1098 | * | ||
1099 | * @param id the audience of the ticket | ||
1100 | * @param ticket the ticket to consume | ||
1101 | * @param cb callback to call with attributes of ticket | ||
1102 | * @param cb_cls callback closure | ||
1103 | * @return handle to the operation | ||
1104 | */ | ||
897 | struct RECLAIM_TICKETS_ConsumeHandle * | 1105 | struct RECLAIM_TICKETS_ConsumeHandle * |
898 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | 1106 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, |
899 | const struct GNUNET_RECLAIM_Ticket *ticket, | 1107 | const struct GNUNET_RECLAIM_Ticket *ticket, |
@@ -928,6 +1136,12 @@ RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | |||
928 | return cth; | 1136 | return cth; |
929 | } | 1137 | } |
930 | 1138 | ||
1139 | |||
1140 | /** | ||
1141 | * Cancel a consume operation | ||
1142 | * | ||
1143 | * @param cth the operation to cancel | ||
1144 | */ | ||
931 | void | 1145 | void |
932 | RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth) | 1146 | RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth) |
933 | { | 1147 | { |
@@ -953,6 +1167,14 @@ cleanup_issue_handle (struct TicketIssueHandle *handle) | |||
953 | } | 1167 | } |
954 | 1168 | ||
955 | 1169 | ||
1170 | /** | ||
1171 | * Store finished, abort on error. | ||
1172 | * Else, return new ticket to caller. | ||
1173 | * | ||
1174 | * @param cls handle to the operation | ||
1175 | * @param success store operation result | ||
1176 | * @param emsg error message (or NULL on success) | ||
1177 | */ | ||
956 | static void | 1178 | static void |
957 | store_ticket_issue_cont (void *cls, int32_t success, const char *emsg) | 1179 | store_ticket_issue_cont (void *cls, int32_t success, const char *emsg) |
958 | { | 1180 | { |
@@ -972,6 +1194,13 @@ store_ticket_issue_cont (void *cls, int32_t success, const char *emsg) | |||
972 | } | 1194 | } |
973 | 1195 | ||
974 | 1196 | ||
1197 | /** | ||
1198 | * Issue a new ticket. | ||
1199 | * We store references to attribute record labels and the ticket itself | ||
1200 | * under the label base64(ticket.rnd). | ||
1201 | * | ||
1202 | * @param ih handle to the operation containing relevant metadata | ||
1203 | */ | ||
975 | static void | 1204 | static void |
976 | issue_ticket (struct TicketIssueHandle *ih) | 1205 | issue_ticket (struct TicketIssueHandle *ih) |
977 | { | 1206 | { |
@@ -991,7 +1220,10 @@ issue_ticket (struct TicketIssueHandle *ih) | |||
991 | { | 1220 | { |
992 | attrs_record[i].data = &le->claim->id; | 1221 | attrs_record[i].data = &le->claim->id; |
993 | attrs_record[i].data_size = sizeof (le->claim->id); | 1222 | attrs_record[i].data_size = sizeof (le->claim->id); |
994 | //FIXME: Should this be the attribute expiration time or ticket refresh intv | 1223 | /** |
1224 | * FIXME: Should this be the attribute expiration time or ticket | ||
1225 | * refresh interval? Probably min(attrs.expiration) | ||
1226 | */ | ||
995 | attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us; | 1227 | attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us; |
996 | attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF; | 1228 | attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF; |
997 | attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 1229 | attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
@@ -1022,6 +1254,12 @@ issue_ticket (struct TicketIssueHandle *ih) | |||
1022 | * Ticket iteration (finding a specific ticket) | 1254 | * Ticket iteration (finding a specific ticket) |
1023 | *************************************************/ | 1255 | *************************************************/ |
1024 | 1256 | ||
1257 | |||
1258 | /** | ||
1259 | * Namestore error on issue. Abort. | ||
1260 | * | ||
1261 | * @param cls handle to the operation | ||
1262 | */ | ||
1025 | static void | 1263 | static void |
1026 | filter_tickets_error_cb (void *cls) | 1264 | filter_tickets_error_cb (void *cls) |
1027 | { | 1265 | { |
@@ -1034,6 +1272,19 @@ filter_tickets_error_cb (void *cls) | |||
1034 | cleanup_issue_handle (tih); | 1272 | cleanup_issue_handle (tih); |
1035 | } | 1273 | } |
1036 | 1274 | ||
1275 | |||
1276 | /** | ||
1277 | * Iterator over records. | ||
1278 | * Check if any previously issued ticket already | ||
1279 | * matches what we need to prevent duplicates and | ||
1280 | * improve resolution synergy. | ||
1281 | * | ||
1282 | * @param cls handle to the operation | ||
1283 | * @param zone issuer identity | ||
1284 | * @param label ticket rnd | ||
1285 | * @param rd_count size of record set | ||
1286 | * @param rd record set | ||
1287 | */ | ||
1037 | static void | 1288 | static void |
1038 | filter_tickets_cb (void *cls, | 1289 | filter_tickets_cb (void *cls, |
1039 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1290 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
@@ -1087,6 +1338,10 @@ filter_tickets_cb (void *cls, | |||
1087 | } | 1338 | } |
1088 | } | 1339 | } |
1089 | 1340 | ||
1341 | /** | ||
1342 | * If we found a matching ticket, return that to the caller and | ||
1343 | * we are done. | ||
1344 | */ | ||
1090 | if (attr_cnt == found_attrs_cnt && NULL != ticket) | 1345 | if (attr_cnt == found_attrs_cnt && NULL != ticket) |
1091 | { | 1346 | { |
1092 | GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it); | 1347 | GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it); |
@@ -1095,11 +1350,18 @@ filter_tickets_cb (void *cls, | |||
1095 | return; | 1350 | return; |
1096 | } | 1351 | } |
1097 | 1352 | ||
1098 | // ticket not found in current record | 1353 | // ticket not found in current record, checking next record set |
1099 | GNUNET_NAMESTORE_zone_iterator_next (tih->ns_it, 1); | 1354 | GNUNET_NAMESTORE_zone_iterator_next (tih->ns_it, 1); |
1100 | } | 1355 | } |
1101 | 1356 | ||
1102 | 1357 | ||
1358 | /** | ||
1359 | * Done iterating over tickets and we apparently did | ||
1360 | * not find an existing, matching ticket. | ||
1361 | * Continue by issuing a new ticket. | ||
1362 | * | ||
1363 | * @param cls handle to the operation | ||
1364 | */ | ||
1103 | static void | 1365 | static void |
1104 | filter_tickets_finished_cb (void *cls) | 1366 | filter_tickets_finished_cb (void *cls) |
1105 | { | 1367 | { |
@@ -1110,6 +1372,18 @@ filter_tickets_finished_cb (void *cls) | |||
1110 | issue_ticket (tih); | 1372 | issue_ticket (tih); |
1111 | } | 1373 | } |
1112 | 1374 | ||
1375 | |||
1376 | /** | ||
1377 | * Issue a new reclaim ticket, thereby authorizing | ||
1378 | * the audience to access the set of provided attributes. | ||
1379 | * | ||
1380 | * @param identity the issuer | ||
1381 | * @param attrs the attributes to share | ||
1382 | * @param audience the audience to share the attributes with | ||
1383 | * @param cb the callback to call with the ticket result | ||
1384 | * @param cb_cls the callback closure | ||
1385 | * FIXME: Return handle?? | ||
1386 | */ | ||
1113 | void | 1387 | void |
1114 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1388 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
1115 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 1389 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
@@ -1125,7 +1399,7 @@ RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | |||
1125 | tih->identity = *identity; | 1399 | tih->identity = *identity; |
1126 | tih->ticket.audience = *audience; | 1400 | tih->ticket.audience = *audience; |
1127 | 1401 | ||
1128 | // check whether the ticket has already been issued | 1402 | // First check whether the ticket has already been issued |
1129 | tih->ns_it = | 1403 | tih->ns_it = |
1130 | GNUNET_NAMESTORE_zone_iteration_start (nsh, | 1404 | GNUNET_NAMESTORE_zone_iteration_start (nsh, |
1131 | &tih->identity, | 1405 | &tih->identity, |
@@ -1137,10 +1411,16 @@ RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | |||
1137 | tih); | 1411 | tih); |
1138 | } | 1412 | } |
1139 | 1413 | ||
1414 | |||
1140 | /************************************ | 1415 | /************************************ |
1141 | * Ticket iteration | 1416 | * Ticket iteration |
1142 | ************************************/ | 1417 | ************************************/ |
1143 | 1418 | ||
1419 | /** | ||
1420 | * Cleanup ticket iterator | ||
1421 | * | ||
1422 | * @param iter handle to the iteration | ||
1423 | */ | ||
1144 | static void | 1424 | static void |
1145 | cleanup_iter (struct RECLAIM_TICKETS_Iterator *iter) | 1425 | cleanup_iter (struct RECLAIM_TICKETS_Iterator *iter) |
1146 | { | 1426 | { |
@@ -1150,6 +1430,17 @@ cleanup_iter (struct RECLAIM_TICKETS_Iterator *iter) | |||
1150 | } | 1430 | } |
1151 | 1431 | ||
1152 | 1432 | ||
1433 | /** | ||
1434 | * Return each record of type @GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET | ||
1435 | * to the caller and proceed with the iteration. | ||
1436 | * FIXME: Should we _not_ proceed automatically here? | ||
1437 | * | ||
1438 | * @param cls handle to the iteration | ||
1439 | * @param zone the ticket issuer | ||
1440 | * @param label the ticket rnd | ||
1441 | * @param rd_count number of records in record set | ||
1442 | * @param rd record set containing a ticket | ||
1443 | */ | ||
1153 | static void | 1444 | static void |
1154 | collect_tickets_cb (void *cls, | 1445 | collect_tickets_cb (void *cls, |
1155 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1446 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
@@ -1170,6 +1461,11 @@ collect_tickets_cb (void *cls, | |||
1170 | } | 1461 | } |
1171 | 1462 | ||
1172 | 1463 | ||
1464 | /** | ||
1465 | * Signal ticket iteration has finished | ||
1466 | * | ||
1467 | * @param cls handle to the iteration | ||
1468 | */ | ||
1173 | static void | 1469 | static void |
1174 | collect_tickets_finished_cb (void *cls) | 1470 | collect_tickets_finished_cb (void *cls) |
1175 | { | 1471 | { |
@@ -1180,6 +1476,11 @@ collect_tickets_finished_cb (void *cls) | |||
1180 | } | 1476 | } |
1181 | 1477 | ||
1182 | 1478 | ||
1479 | /** | ||
1480 | * Cancel ticket iteration on namestore error | ||
1481 | * | ||
1482 | * @param cls the iteration handle | ||
1483 | */ | ||
1183 | static void | 1484 | static void |
1184 | collect_tickets_error_cb (void *cls) | 1485 | collect_tickets_error_cb (void *cls) |
1185 | { | 1486 | { |
@@ -1190,6 +1491,11 @@ collect_tickets_error_cb (void *cls) | |||
1190 | } | 1491 | } |
1191 | 1492 | ||
1192 | 1493 | ||
1494 | /** | ||
1495 | * Continue ticket iteration | ||
1496 | * | ||
1497 | * @param iter the iteration to continue | ||
1498 | */ | ||
1193 | void | 1499 | void |
1194 | RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter) | 1500 | RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter) |
1195 | { | 1501 | { |
@@ -1197,6 +1503,11 @@ RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter) | |||
1197 | } | 1503 | } |
1198 | 1504 | ||
1199 | 1505 | ||
1506 | /** | ||
1507 | * Stop a running ticket iteration | ||
1508 | * | ||
1509 | * @param iter iteration to cancel | ||
1510 | */ | ||
1200 | void | 1511 | void |
1201 | RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter) | 1512 | RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter) |
1202 | { | 1513 | { |
@@ -1205,6 +1516,14 @@ RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter) | |||
1205 | } | 1516 | } |
1206 | 1517 | ||
1207 | 1518 | ||
1519 | /** | ||
1520 | * Iterate over all tickets issued by an identity | ||
1521 | * | ||
1522 | * @param identity the issuing identity | ||
1523 | * @param cb ticket callback function | ||
1524 | * @param cb_cls callback closure | ||
1525 | * @return a handle to the iteration | ||
1526 | */ | ||
1208 | struct RECLAIM_TICKETS_Iterator * | 1527 | struct RECLAIM_TICKETS_Iterator * |
1209 | RECLAIM_TICKETS_iteration_start ( | 1528 | RECLAIM_TICKETS_iteration_start ( |
1210 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1529 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
@@ -1229,6 +1548,12 @@ RECLAIM_TICKETS_iteration_start ( | |||
1229 | } | 1548 | } |
1230 | 1549 | ||
1231 | 1550 | ||
1551 | /** | ||
1552 | * Initialize tickets component | ||
1553 | * | ||
1554 | * @param c the configuration | ||
1555 | * @return GNUNET_SYSERR on error | ||
1556 | */ | ||
1232 | int | 1557 | int |
1233 | RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c) | 1558 | RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c) |
1234 | { | 1559 | { |
@@ -1266,6 +1591,11 @@ RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
1266 | return GNUNET_OK; | 1591 | return GNUNET_OK; |
1267 | } | 1592 | } |
1268 | 1593 | ||
1594 | |||
1595 | /** | ||
1596 | * Close handles and clean up. | ||
1597 | * FIXME: cancel all pending operations (gns, ns etc) | ||
1598 | */ | ||
1269 | void | 1599 | void |
1270 | RECLAIM_TICKETS_deinit (void) | 1600 | RECLAIM_TICKETS_deinit (void) |
1271 | { | 1601 | { |
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.h b/src/reclaim/gnunet-service-reclaim_tickets.h index 6e69355fa..05f834b1e 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.h +++ b/src/reclaim/gnunet-service-reclaim_tickets.h | |||
@@ -42,11 +42,27 @@ | |||
42 | #include "gnunet_statistics_service.h" | 42 | #include "gnunet_statistics_service.h" |
43 | #include "reclaim.h" | 43 | #include "reclaim.h" |
44 | 44 | ||
45 | /** | ||
46 | * Ticket iterator | ||
47 | */ | ||
45 | struct RECLAIM_TICKETS_Iterator; | 48 | struct RECLAIM_TICKETS_Iterator; |
49 | |||
50 | |||
51 | /** | ||
52 | * Handle to a consume operation | ||
53 | */ | ||
46 | struct RECLAIM_TICKETS_ConsumeHandle; | 54 | struct RECLAIM_TICKETS_ConsumeHandle; |
55 | |||
56 | |||
57 | /** | ||
58 | * Ticket revocation request handle | ||
59 | */ | ||
47 | struct RECLAIM_TICKETS_RevokeHandle; | 60 | struct RECLAIM_TICKETS_RevokeHandle; |
48 | 61 | ||
49 | 62 | ||
63 | /** | ||
64 | * List of tickets | ||
65 | */ | ||
50 | struct TicketRecordsEntry | 66 | struct TicketRecordsEntry |
51 | { | 67 | { |
52 | /** | 68 | /** |
@@ -88,7 +104,8 @@ struct TicketRecordsEntry | |||
88 | * @param ticket the ticket | 104 | * @param ticket the ticket |
89 | */ | 105 | */ |
90 | typedef void (*RECLAIM_TICKETS_TicketIter) ( | 106 | typedef void (*RECLAIM_TICKETS_TicketIter) ( |
91 | void *cls, struct GNUNET_RECLAIM_Ticket *ticket); | 107 | void *cls, |
108 | struct GNUNET_RECLAIM_Ticket *ticket); | ||
92 | 109 | ||
93 | 110 | ||
94 | /** | 111 | /** |
@@ -101,59 +118,159 @@ typedef void (*RECLAIM_TICKETS_TicketIter) ( | |||
101 | * @param emsg NULL on success, otherwise an error message | 118 | * @param emsg NULL on success, otherwise an error message |
102 | */ | 119 | */ |
103 | typedef void (*RECLAIM_TICKETS_TicketResult) ( | 120 | typedef void (*RECLAIM_TICKETS_TicketResult) ( |
104 | void *cls, struct GNUNET_RECLAIM_Ticket *ticket, int32_t success, | 121 | void *cls, |
105 | const char *emsg); | 122 | struct GNUNET_RECLAIM_Ticket *ticket, |
123 | int32_t success, | ||
124 | const char *emsg); | ||
106 | 125 | ||
107 | 126 | ||
127 | /** | ||
128 | * Consume callback. | ||
129 | * | ||
130 | * @param cls closure | ||
131 | * @param identity the issuer of the ticket/attributes | ||
132 | * @param l attribute list retrieved through ticket | ||
133 | * @param success GNUNET_OK on success | ||
134 | * @param emsg error message (NULL on success) | ||
135 | */ | ||
108 | typedef void (*RECLAIM_TICKETS_ConsumeCallback) ( | 136 | typedef void (*RECLAIM_TICKETS_ConsumeCallback) ( |
109 | void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 137 | void *cls, |
110 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *l, int32_t success, | 138 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
111 | const char *emsg); | 139 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *l, |
140 | int32_t success, | ||
141 | const char *emsg); | ||
112 | 142 | ||
113 | 143 | ||
144 | /** | ||
145 | * Revocation callback. | ||
146 | * | ||
147 | * @param cls closure | ||
148 | * @param success GNUNET_OK on success | ||
149 | */ | ||
114 | typedef void (*RECLAIM_TICKETS_RevokeCallback) (void *cls, int32_t success); | 150 | typedef void (*RECLAIM_TICKETS_RevokeCallback) (void *cls, int32_t success); |
115 | 151 | ||
152 | |||
153 | /** | ||
154 | * Revoke a ticket. | ||
155 | * We start by looking up attribute references in order | ||
156 | * to change attribute IDs. | ||
157 | * | ||
158 | * @param ticket ticket to revoke | ||
159 | * @param identity private key of issuer | ||
160 | * @param cb revocation status callback | ||
161 | * @param cb_cls callback closure | ||
162 | * @return handle to the operation | ||
163 | */ | ||
116 | struct RECLAIM_TICKETS_RevokeHandle * | 164 | struct RECLAIM_TICKETS_RevokeHandle * |
117 | RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, | 165 | RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, |
118 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 166 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
119 | RECLAIM_TICKETS_RevokeCallback cb, void *cb_cls); | 167 | RECLAIM_TICKETS_RevokeCallback cb, |
168 | void *cb_cls); | ||
120 | 169 | ||
121 | 170 | ||
171 | /** | ||
172 | * Cancel a revocation. | ||
173 | * | ||
174 | * @param rh handle to the operation | ||
175 | */ | ||
122 | void | 176 | void |
123 | RECLAIM_TICKETS_revoke_cancel (struct RECLAIM_TICKETS_RevokeHandle *rh); | 177 | RECLAIM_TICKETS_revoke_cancel (struct RECLAIM_TICKETS_RevokeHandle *rh); |
124 | 178 | ||
125 | 179 | ||
180 | /** | ||
181 | * Consume a ticket. | ||
182 | * We first looking attribute references under the label | ||
183 | * ticket.rnd in GNS. | ||
184 | * | ||
185 | * @param id the audience of the ticket | ||
186 | * @param ticket the ticket to consume | ||
187 | * @param cb callback to call with attributes of ticket | ||
188 | * @param cb_cls callback closure | ||
189 | * @return handle to the operation | ||
190 | */ | ||
126 | struct RECLAIM_TICKETS_ConsumeHandle * | 191 | struct RECLAIM_TICKETS_ConsumeHandle * |
127 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | 192 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, |
128 | const struct GNUNET_RECLAIM_Ticket *ticket, | 193 | const struct GNUNET_RECLAIM_Ticket *ticket, |
129 | RECLAIM_TICKETS_ConsumeCallback cb, void *cb_cls); | 194 | RECLAIM_TICKETS_ConsumeCallback cb, |
195 | void *cb_cls); | ||
130 | 196 | ||
197 | |||
198 | /** | ||
199 | * Cancel a consume operation | ||
200 | * | ||
201 | * @param cth the operation to cancel | ||
202 | */ | ||
131 | void | 203 | void |
132 | RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth); | 204 | RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth); |
133 | 205 | ||
206 | |||
207 | /** | ||
208 | * Issue a new reclaim ticket, thereby authorizing | ||
209 | * the audience to access the set of provided attributes. | ||
210 | * | ||
211 | * @param identity the issuer | ||
212 | * @param attrs the attributes to share | ||
213 | * @param audience the audience to share the attributes with | ||
214 | * @param cb the callback to call with the ticket result | ||
215 | * @param cb_cls the callback closure | ||
216 | * FIXME: Return handle?? | ||
217 | */ | ||
134 | void | 218 | void |
135 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 219 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
136 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 220 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
137 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | 221 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, |
138 | RECLAIM_TICKETS_TicketResult cb, void *cb_cls); | 222 | RECLAIM_TICKETS_TicketResult cb, |
223 | void *cb_cls); | ||
224 | |||
139 | 225 | ||
226 | /** | ||
227 | * Continue ticket iteration | ||
228 | * | ||
229 | * @param iter the iteration to continue | ||
230 | */ | ||
140 | void | 231 | void |
141 | RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter); | 232 | RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter); |
142 | 233 | ||
143 | 234 | ||
235 | /** | ||
236 | * Stop a running ticket iteration | ||
237 | * | ||
238 | * @param iter iteration to cancel | ||
239 | */ | ||
144 | void | 240 | void |
145 | RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter); | 241 | RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter); |
146 | 242 | ||
147 | 243 | ||
244 | /** | ||
245 | * Iterate over all tickets issued by an identity | ||
246 | * | ||
247 | * @param identity the issuing identity | ||
248 | * @param cb ticket callback function | ||
249 | * @param cb_cls callback closure | ||
250 | * @return a handle to the iteration | ||
251 | */ | ||
148 | struct RECLAIM_TICKETS_Iterator * | 252 | struct RECLAIM_TICKETS_Iterator * |
149 | RECLAIM_TICKETS_iteration_start ( | 253 | RECLAIM_TICKETS_iteration_start ( |
150 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 254 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
151 | RECLAIM_TICKETS_TicketIter cb, void *cb_cls); | 255 | RECLAIM_TICKETS_TicketIter cb, |
256 | void *cb_cls); | ||
152 | 257 | ||
153 | 258 | ||
259 | /** | ||
260 | * Initialize tickets component | ||
261 | * | ||
262 | * @param c the configuration | ||
263 | * @return GNUNET_SYSERR on error | ||
264 | */ | ||
154 | int | 265 | int |
155 | RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c); | 266 | RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c); |
156 | 267 | ||
268 | |||
269 | /** | ||
270 | * Close handles and clean up. | ||
271 | * FIXME: cancel all pending operations (gns, ns etc) | ||
272 | */ | ||
157 | void | 273 | void |
158 | RECLAIM_TICKETS_deinit (void); | 274 | RECLAIM_TICKETS_deinit (void); |
275 | |||
159 | #endif | 276 | #endif |