diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-05-08 16:01:21 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-05-08 16:01:21 +0200 |
commit | e4895ec7c1a1808a13195c346a828c271ca86c78 (patch) | |
tree | 7f8f6e1c67d82000bfc5db33ad07c683574915b8 /src/reclaim/gnunet-service-reclaim.c | |
parent | 1b80ff9ee79b3fbe2028a8c22a01e45e9131cda2 (diff) | |
download | gnunet-e4895ec7c1a1808a13195c346a828c271ca86c78.tar.gz gnunet-e4895ec7c1a1808a13195c346a828c271ca86c78.zip |
RECLAIM: Fix shutdown; tests
Diffstat (limited to 'src/reclaim/gnunet-service-reclaim.c')
-rw-r--r-- | src/reclaim/gnunet-service-reclaim.c | 259 |
1 files changed, 142 insertions, 117 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index 6db97fe87..1447f71f6 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c | |||
@@ -51,10 +51,6 @@ | |||
51 | */ | 51 | */ |
52 | #define MIN_WAIT_TIME GNUNET_TIME_UNIT_MINUTES | 52 | #define MIN_WAIT_TIME GNUNET_TIME_UNIT_MINUTES |
53 | 53 | ||
54 | /** | ||
55 | * Standard token expiration time | ||
56 | */ | ||
57 | #define DEFAULT_TOKEN_EXPIRATION_INTERVAL GNUNET_TIME_UNIT_HOURS | ||
58 | 54 | ||
59 | /** | 55 | /** |
60 | * Identity handle | 56 | * Identity handle |
@@ -62,11 +58,6 @@ | |||
62 | static struct GNUNET_IDENTITY_Handle *identity_handle; | 58 | static struct GNUNET_IDENTITY_Handle *identity_handle; |
63 | 59 | ||
64 | /** | 60 | /** |
65 | * Token expiration interval | ||
66 | */ | ||
67 | static struct GNUNET_TIME_Relative token_expiration_interval; | ||
68 | |||
69 | /** | ||
70 | * Namestore handle | 61 | * Namestore handle |
71 | */ | 62 | */ |
72 | static struct GNUNET_NAMESTORE_Handle *nsh; | 63 | static struct GNUNET_NAMESTORE_Handle *nsh; |
@@ -165,6 +156,15 @@ struct AttributeIterator | |||
165 | */ | 156 | */ |
166 | struct IdpClient | 157 | struct IdpClient |
167 | { | 158 | { |
159 | /** | ||
160 | * DLL | ||
161 | */ | ||
162 | struct IdpClient *prev; | ||
163 | |||
164 | /** | ||
165 | * DLL | ||
166 | */ | ||
167 | struct IdpClient *next; | ||
168 | 168 | ||
169 | /** | 169 | /** |
170 | * The client | 170 | * The client |
@@ -514,13 +514,138 @@ struct EgoEntry | |||
514 | 514 | ||
515 | 515 | ||
516 | /** | 516 | /** |
517 | * Client list | ||
518 | */ | ||
519 | static struct IdpClient *client_list_head = NULL; | ||
520 | |||
521 | /** | ||
522 | * Client list | ||
523 | */ | ||
524 | static struct IdpClient *client_list_tail = NULL; | ||
525 | |||
526 | |||
527 | /** | ||
528 | * Cleanup attribute delete handle | ||
529 | * | ||
530 | * @param adh the attribute to cleanup | ||
531 | */ | ||
532 | static void | ||
533 | cleanup_adh (struct AttributeDeleteHandle *adh) | ||
534 | { | ||
535 | struct TicketRecordsEntry *le; | ||
536 | if (NULL != adh->ns_it) | ||
537 | GNUNET_NAMESTORE_zone_iteration_stop (adh->ns_it); | ||
538 | if (NULL != adh->ns_qe) | ||
539 | GNUNET_NAMESTORE_cancel (adh->ns_qe); | ||
540 | if (NULL != adh->label) | ||
541 | GNUNET_free (adh->label); | ||
542 | if (NULL != adh->claim) | ||
543 | GNUNET_free (adh->claim); | ||
544 | while (NULL != (le = adh->tickets_to_update_head)) { | ||
545 | GNUNET_CONTAINER_DLL_remove (adh->tickets_to_update_head, | ||
546 | adh->tickets_to_update_tail, | ||
547 | le); | ||
548 | if (NULL != le->label) | ||
549 | GNUNET_free (le->label); | ||
550 | if (NULL != le->data) | ||
551 | GNUNET_free (le->data); | ||
552 | GNUNET_free (le); | ||
553 | } | ||
554 | GNUNET_free (adh); | ||
555 | } | ||
556 | |||
557 | |||
558 | /** | ||
559 | * Cleanup attribute store handle | ||
560 | * | ||
561 | * @param handle handle to clean up | ||
562 | */ | ||
563 | static void | ||
564 | cleanup_as_handle (struct AttributeStoreHandle *ash) | ||
565 | { | ||
566 | if (NULL != ash->ns_qe) | ||
567 | GNUNET_NAMESTORE_cancel (ash->ns_qe); | ||
568 | if (NULL != ash->claim) | ||
569 | GNUNET_free (ash->claim); | ||
570 | GNUNET_free (ash); | ||
571 | } | ||
572 | |||
573 | |||
574 | /** | ||
575 | * Cleanup client | ||
576 | * | ||
577 | * @param idp the client to clean up | ||
578 | */ | ||
579 | static void | ||
580 | cleanup_client (struct IdpClient *idp) | ||
581 | { | ||
582 | struct AttributeIterator *ai; | ||
583 | struct TicketIteration *ti; | ||
584 | struct TicketRevocationOperation *rop; | ||
585 | struct TicketIssueOperation *iss; | ||
586 | struct ConsumeTicketOperation *ct; | ||
587 | struct AttributeStoreHandle *as; | ||
588 | struct AttributeDeleteHandle *adh; | ||
589 | |||
590 | while (NULL != (iss = idp->issue_op_head)) { | ||
591 | GNUNET_CONTAINER_DLL_remove (idp->issue_op_head, idp->issue_op_tail, iss); | ||
592 | GNUNET_free (iss); | ||
593 | } | ||
594 | while (NULL != (ct = idp->consume_op_head)) { | ||
595 | GNUNET_CONTAINER_DLL_remove (idp->consume_op_head, | ||
596 | idp->consume_op_tail, | ||
597 | ct); | ||
598 | if (NULL != ct->ch) | ||
599 | RECLAIM_TICKETS_consume_cancel (ct->ch); | ||
600 | GNUNET_free (ct); | ||
601 | } | ||
602 | while (NULL != (as = idp->store_op_head)) { | ||
603 | GNUNET_CONTAINER_DLL_remove (idp->store_op_head, idp->store_op_tail, as); | ||
604 | cleanup_as_handle (as); | ||
605 | } | ||
606 | while (NULL != (adh = idp->delete_op_head)) { | ||
607 | GNUNET_CONTAINER_DLL_remove (idp->delete_op_head, idp->delete_op_tail, adh); | ||
608 | cleanup_adh (adh); | ||
609 | } | ||
610 | |||
611 | while (NULL != (ai = idp->attr_iter_head)) { | ||
612 | GNUNET_CONTAINER_DLL_remove (idp->attr_iter_head, idp->attr_iter_tail, ai); | ||
613 | GNUNET_free (ai); | ||
614 | } | ||
615 | while (NULL != (rop = idp->revoke_op_head)) { | ||
616 | GNUNET_CONTAINER_DLL_remove (idp->revoke_op_head, idp->revoke_op_tail, rop); | ||
617 | if (NULL != rop->rh) | ||
618 | RECLAIM_TICKETS_revoke_cancel (rop->rh); | ||
619 | GNUNET_free (rop); | ||
620 | } | ||
621 | while (NULL != (ti = idp->ticket_iter_head)) { | ||
622 | GNUNET_CONTAINER_DLL_remove (idp->ticket_iter_head, | ||
623 | idp->ticket_iter_tail, | ||
624 | ti); | ||
625 | if (NULL != ti->iter) | ||
626 | RECLAIM_TICKETS_iteration_stop (ti->iter); | ||
627 | GNUNET_free (ti); | ||
628 | } | ||
629 | GNUNET_free (idp); | ||
630 | } | ||
631 | |||
632 | |||
633 | /** | ||
517 | * Cleanup task | 634 | * Cleanup task |
518 | */ | 635 | */ |
519 | static void | 636 | static void |
520 | cleanup () | 637 | cleanup () |
521 | { | 638 | { |
639 | struct IdpClient *cl; | ||
522 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | 640 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); |
523 | 641 | ||
642 | while (NULL != (cl = client_list_head)) | ||
643 | { | ||
644 | GNUNET_CONTAINER_DLL_remove (client_list_head, | ||
645 | client_list_tail, | ||
646 | cl); | ||
647 | cleanup_client (cl); | ||
648 | } | ||
524 | RECLAIM_TICKETS_deinit (); | 649 | RECLAIM_TICKETS_deinit (); |
525 | if (NULL != timeout_task) | 650 | if (NULL != timeout_task) |
526 | GNUNET_SCHEDULER_cancel (timeout_task); | 651 | GNUNET_SCHEDULER_cancel (timeout_task); |
@@ -832,21 +957,6 @@ handle_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm) | |||
832 | * Attribute store | 957 | * Attribute store |
833 | *****************************************/ | 958 | *****************************************/ |
834 | 959 | ||
835 | /** | ||
836 | * Cleanup attribute store handle | ||
837 | * | ||
838 | * @param handle handle to clean up | ||
839 | */ | ||
840 | static void | ||
841 | cleanup_as_handle (struct AttributeStoreHandle *ash) | ||
842 | { | ||
843 | if (NULL != ash->ns_qe) | ||
844 | GNUNET_NAMESTORE_cancel (ash->ns_qe); | ||
845 | if (NULL != ash->claim) | ||
846 | GNUNET_free (ash->claim); | ||
847 | GNUNET_free (ash); | ||
848 | } | ||
849 | |||
850 | 960 | ||
851 | /** | 961 | /** |
852 | * Attribute store result handler | 962 | * Attribute store result handler |
@@ -981,37 +1091,6 @@ handle_attribute_store_message (void *cls, | |||
981 | 1091 | ||
982 | 1092 | ||
983 | /** | 1093 | /** |
984 | * Cleanup attribute delete handle | ||
985 | * | ||
986 | * @param adh the attribute to cleanup | ||
987 | */ | ||
988 | static void | ||
989 | cleanup_adh (struct AttributeDeleteHandle *adh) | ||
990 | { | ||
991 | struct TicketRecordsEntry *le; | ||
992 | if (NULL != adh->ns_it) | ||
993 | GNUNET_NAMESTORE_zone_iteration_stop (adh->ns_it); | ||
994 | if (NULL != adh->ns_qe) | ||
995 | GNUNET_NAMESTORE_cancel (adh->ns_qe); | ||
996 | if (NULL != adh->label) | ||
997 | GNUNET_free (adh->label); | ||
998 | if (NULL != adh->claim) | ||
999 | GNUNET_free (adh->claim); | ||
1000 | while (NULL != (le = adh->tickets_to_update_head)) { | ||
1001 | GNUNET_CONTAINER_DLL_remove (adh->tickets_to_update_head, | ||
1002 | adh->tickets_to_update_tail, | ||
1003 | le); | ||
1004 | if (NULL != le->label) | ||
1005 | GNUNET_free (le->label); | ||
1006 | if (NULL != le->data) | ||
1007 | GNUNET_free (le->data); | ||
1008 | GNUNET_free (le); | ||
1009 | } | ||
1010 | GNUNET_free (adh); | ||
1011 | } | ||
1012 | |||
1013 | |||
1014 | /** | ||
1015 | * Send a deletion success response | 1094 | * Send a deletion success response |
1016 | * | 1095 | * |
1017 | * @param adh our attribute deletion handle | 1096 | * @param adh our attribute deletion handle |
@@ -1623,7 +1702,7 @@ run (void *cls, | |||
1623 | 1702 | ||
1624 | if (GNUNET_OK != RECLAIM_TICKETS_init (cfg)) { | 1703 | if (GNUNET_OK != RECLAIM_TICKETS_init (cfg)) { |
1625 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1704 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1626 | "Unable to initialized TICKETS subsystem.\n"); | 1705 | "Unable to initialize TICKETS subsystem.\n"); |
1627 | GNUNET_SCHEDULER_shutdown (); | 1706 | GNUNET_SCHEDULER_shutdown (); |
1628 | return; | 1707 | return; |
1629 | } | 1708 | } |
@@ -1636,20 +1715,6 @@ run (void *cls, | |||
1636 | 1715 | ||
1637 | identity_handle = GNUNET_IDENTITY_connect (cfg, NULL, NULL); | 1716 | identity_handle = GNUNET_IDENTITY_connect (cfg, NULL, NULL); |
1638 | 1717 | ||
1639 | if (GNUNET_OK | ||
1640 | == GNUNET_CONFIGURATION_get_value_time (cfg, | ||
1641 | "reclaim", | ||
1642 | "TOKEN_EXPIRATION_INTERVAL", | ||
1643 | &token_expiration_interval)) { | ||
1644 | GNUNET_log ( | ||
1645 | GNUNET_ERROR_TYPE_DEBUG, | ||
1646 | "Time window for zone iteration: %s\n", | ||
1647 | GNUNET_STRINGS_relative_time_to_string (token_expiration_interval, | ||
1648 | GNUNET_YES)); | ||
1649 | } else { | ||
1650 | token_expiration_interval = DEFAULT_TOKEN_EXPIRATION_INTERVAL; | ||
1651 | } | ||
1652 | |||
1653 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 1718 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
1654 | } | 1719 | } |
1655 | 1720 | ||
@@ -1667,54 +1732,11 @@ client_disconnect_cb (void *cls, | |||
1667 | void *app_ctx) | 1732 | void *app_ctx) |
1668 | { | 1733 | { |
1669 | struct IdpClient *idp = app_ctx; | 1734 | struct IdpClient *idp = app_ctx; |
1670 | struct AttributeIterator *ai; | ||
1671 | struct TicketIteration *ti; | ||
1672 | struct TicketRevocationOperation *rop; | ||
1673 | struct TicketIssueOperation *iss; | ||
1674 | struct ConsumeTicketOperation *ct; | ||
1675 | struct AttributeStoreHandle *as; | ||
1676 | struct AttributeDeleteHandle *adh; | ||
1677 | |||
1678 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); | 1735 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); |
1679 | 1736 | GNUNET_CONTAINER_DLL_remove (client_list_head, | |
1680 | while (NULL != (iss = idp->issue_op_head)) { | 1737 | client_list_tail, |
1681 | GNUNET_CONTAINER_DLL_remove (idp->issue_op_head, idp->issue_op_tail, iss); | 1738 | idp); |
1682 | GNUNET_free (iss); | 1739 | cleanup_client (idp); |
1683 | } | ||
1684 | while (NULL != (ct = idp->consume_op_head)) { | ||
1685 | GNUNET_CONTAINER_DLL_remove (idp->consume_op_head, | ||
1686 | idp->consume_op_tail, | ||
1687 | ct); | ||
1688 | if (NULL != ct->ch) | ||
1689 | RECLAIM_TICKETS_consume_cancel (ct->ch); | ||
1690 | GNUNET_free (ct); | ||
1691 | } | ||
1692 | while (NULL != (as = idp->store_op_head)) { | ||
1693 | GNUNET_CONTAINER_DLL_remove (idp->store_op_head, idp->store_op_tail, as); | ||
1694 | cleanup_as_handle (as); | ||
1695 | } | ||
1696 | while (NULL != (adh = idp->delete_op_head)) { | ||
1697 | GNUNET_CONTAINER_DLL_remove (idp->delete_op_head, idp->delete_op_tail, adh); | ||
1698 | cleanup_adh (adh); | ||
1699 | } | ||
1700 | |||
1701 | while (NULL != (ai = idp->attr_iter_head)) { | ||
1702 | GNUNET_CONTAINER_DLL_remove (idp->attr_iter_head, idp->attr_iter_tail, ai); | ||
1703 | GNUNET_free (ai); | ||
1704 | } | ||
1705 | while (NULL != (rop = idp->revoke_op_head)) { | ||
1706 | GNUNET_CONTAINER_DLL_remove (idp->revoke_op_head, idp->revoke_op_tail, rop); | ||
1707 | if (NULL != rop->rh) | ||
1708 | RECLAIM_TICKETS_revoke_cancel (rop->rh); | ||
1709 | GNUNET_free (rop); | ||
1710 | } | ||
1711 | while (NULL != (ti = idp->ticket_iter_head)) { | ||
1712 | GNUNET_CONTAINER_DLL_remove (idp->ticket_iter_head, | ||
1713 | idp->ticket_iter_tail, | ||
1714 | ti); | ||
1715 | GNUNET_free (ti); | ||
1716 | } | ||
1717 | GNUNET_free (idp); | ||
1718 | } | 1740 | } |
1719 | 1741 | ||
1720 | 1742 | ||
@@ -1736,6 +1758,9 @@ client_connect_cb (void *cls, | |||
1736 | idp = GNUNET_new (struct IdpClient); | 1758 | idp = GNUNET_new (struct IdpClient); |
1737 | idp->client = client; | 1759 | idp->client = client; |
1738 | idp->mq = mq; | 1760 | idp->mq = mq; |
1761 | GNUNET_CONTAINER_DLL_insert (client_list_head, | ||
1762 | client_list_tail, | ||
1763 | idp); | ||
1739 | return idp; | 1764 | return idp; |
1740 | } | 1765 | } |
1741 | 1766 | ||