2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @author Martin Schanzenbach
23 * @file src/reclaim/gnunet-service-reclaim_tickets.c
24 * @brief reclaim tickets
28 #include "gnunet-service-reclaim_tickets.h"
30 #define DEFAULT_TICKET_REFRESH_INTERVAL GNUNET_TIME_UNIT_HOURS
32 struct ParallelLookup;
36 * A reference to a ticket stored in GNS
38 struct TicketReference
43 struct TicketReference *next;
48 struct TicketReference *prev;
53 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
58 struct GNUNET_RECLAIM_Ticket ticket;
62 struct RECLAIM_TICKETS_ConsumeHandle
67 struct GNUNET_RECLAIM_Ticket ticket;
72 struct GNUNET_GNS_LookupRequest *lookup_request;
77 struct GNUNET_CRYPTO_EcdsaPrivateKey identity;
82 struct GNUNET_CRYPTO_EcdsaPublicKey identity_pub;
87 struct ParallelLookup *parallel_lookups_head;
92 struct ParallelLookup *parallel_lookups_tail;
97 struct GNUNET_SCHEDULER_Task *kill_task;
102 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
107 struct GNUNET_TIME_Absolute lookup_start_time;
112 RECLAIM_TICKETS_ConsumeCallback cb;
121 * Handle for a parallel GNS lookup job
123 struct ParallelLookup
126 struct ParallelLookup *next;
129 struct ParallelLookup *prev;
131 /* The GNS request */
132 struct GNUNET_GNS_LookupRequest *lookup_request;
134 /* The handle the return to */
135 struct RECLAIM_TICKETS_ConsumeHandle *handle;
140 struct GNUNET_TIME_Absolute lookup_start_time;
142 /* The label to look up */
148 * Ticket issue request handle
150 struct TicketIssueHandle
153 * Attributes to issue
155 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
160 struct GNUNET_CRYPTO_EcdsaPrivateKey identity;
165 struct GNUNET_RECLAIM_Ticket ticket;
170 struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
175 RECLAIM_TICKETS_TicketResult cb;
186 struct RECLAIM_TICKETS_Iterator
189 * Namestore queue entry
191 struct GNUNET_NAMESTORE_ZoneIterator *ns_it;
196 RECLAIM_TICKETS_TicketIter cb;
205 struct RevokedAttributeEntry
210 struct RevokedAttributeEntry *next;
215 struct RevokedAttributeEntry *prev;
218 * Old ID of the attribute
223 * New ID of the attribute
230 * Ticket revocation request handle
232 struct RECLAIM_TICKETS_RevokeHandle
237 struct GNUNET_CRYPTO_EcdsaPrivateKey identity;
242 RECLAIM_TICKETS_RevokeCallback cb;
252 struct GNUNET_RECLAIM_Ticket ticket;
257 struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
262 struct GNUNET_NAMESTORE_ZoneIterator *ns_it;
267 struct RevokedAttributeEntry *attrs_head;
272 struct RevokedAttributeEntry *attrs_tail;
275 * Current attribute to move
277 struct RevokedAttributeEntry *move_attr;
280 * Number of attributes in ticket
282 unsigned int ticket_attrs;
287 struct TicketRecordsEntry *tickets_to_update_head;
292 struct TicketRecordsEntry *tickets_to_update_tail;
296 * Ticket expiration interval
298 static struct GNUNET_TIME_Relative ticket_refresh_interval;
300 /* Namestore handle */
301 static struct GNUNET_NAMESTORE_Handle *nsh;
304 static struct GNUNET_GNS_Handle *gns;
306 /* Handle to the statistics service */
307 static struct GNUNET_STATISTICS_Handle *stats;
310 move_attrs (struct RECLAIM_TICKETS_RevokeHandle *rh);
313 move_attrs_cont (void *cls)
315 move_attrs ((struct RECLAIM_TICKETS_RevokeHandle *) cls);
319 * Cleanup revoke handle
321 * @param rh the ticket revocation handle
324 cleanup_rvk (struct RECLAIM_TICKETS_RevokeHandle *rh)
326 struct RevokedAttributeEntry *ae;
327 struct TicketRecordsEntry *le;
328 if (NULL != rh->ns_qe)
329 GNUNET_NAMESTORE_cancel (rh->ns_qe);
330 if (NULL != rh->ns_it)
331 GNUNET_NAMESTORE_zone_iteration_stop (rh->ns_it);
332 while (NULL != (ae = rh->attrs_head))
334 GNUNET_CONTAINER_DLL_remove (rh->attrs_head, rh->attrs_tail, ae);
337 while (NULL != (le = rh->tickets_to_update_head))
339 GNUNET_CONTAINER_DLL_remove (rh->tickets_to_update_head,
340 rh->tickets_to_update_head,
342 if (NULL != le->data)
343 GNUNET_free (le->data);
344 if (NULL != le->label)
345 GNUNET_free (le->label);
352 del_attr_finished (void *cls, int32_t success, const char *emsg)
354 struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
356 if (GNUNET_SYSERR == success)
358 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
359 "Error removing attribute: %s\n",
361 rvk->cb (rvk->cb_cls, GNUNET_SYSERR);
365 rvk->move_attr = rvk->move_attr->next;
366 GNUNET_SCHEDULER_add_now (&move_attrs_cont, rvk);
370 move_attr_finished (void *cls, int32_t success, const char *emsg)
372 struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
375 if (GNUNET_SYSERR == success)
377 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error moving attribute: %s\n", emsg);
378 rvk->cb (rvk->cb_cls, GNUNET_SYSERR);
382 label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->old_id,
384 GNUNET_assert (NULL != label);
385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing attribute %s\n", label);
386 rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
398 rvk_move_attr_cb (void *cls,
399 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
401 unsigned int rd_count,
402 const struct GNUNET_GNSRECORD_Data *rd)
404 struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
405 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
406 struct GNUNET_GNSRECORD_Data new_rd;
407 struct RevokedAttributeEntry *le;
413 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
414 "The attribute %s no longer exists!\n",
417 rvk->move_attr = le->next;
418 GNUNET_CONTAINER_DLL_remove (rvk->attrs_head, rvk->attrs_tail, le);
420 GNUNET_SCHEDULER_add_now (&move_attrs_cont, rvk);
423 /** find a new place for this attribute **/
424 rvk->move_attr->new_id =
425 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX);
427 claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd->data, rd->data_size);
428 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
429 "Attribute to update: Name=%s, ID=%" PRIu64 "\n",
432 claim->id = rvk->move_attr->new_id;
433 new_rd.data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (claim);
434 attr_data = GNUNET_malloc (rd->data_size);
435 new_rd.data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize (claim, attr_data);
436 new_rd.data = attr_data;
437 new_label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id,
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label);
440 rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
447 GNUNET_free (new_label);
449 GNUNET_free (attr_data);
454 rvk_ticket_update (void *cls,
455 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
457 unsigned int rd_count,
458 const struct GNUNET_GNSRECORD_Data *rd)
460 struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
461 struct TicketRecordsEntry *le;
462 struct RevokedAttributeEntry *ae;
463 int has_changed = GNUNET_NO;
465 /** Let everything point to the old record **/
466 for (int i = 0; i < rd_count; i++)
468 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type)
470 for (ae = rvk->attrs_head; NULL != ae; ae = ae->next)
472 if (0 != memcmp (rd[i].data, &ae->old_id, sizeof (uint64_t)))
474 has_changed = GNUNET_YES;
477 if (GNUNET_YES == has_changed)
480 if (GNUNET_YES == has_changed)
482 le = GNUNET_new (struct TicketRecordsEntry);
483 le->data_size = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
484 le->data = GNUNET_malloc (le->data_size);
485 le->rd_count = rd_count;
486 le->label = GNUNET_strdup (label);
487 GNUNET_GNSRECORD_records_serialize (rd_count, rd, le->data_size, le->data);
488 GNUNET_CONTAINER_DLL_insert (rvk->tickets_to_update_head,
489 rvk->tickets_to_update_tail,
492 GNUNET_NAMESTORE_zone_iterator_next (rvk->ns_it, 1);
497 process_tickets (void *cls);
501 ticket_processed (void *cls, int32_t success, const char *emsg)
503 struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
505 GNUNET_SCHEDULER_add_now (&process_tickets, rvk);
509 process_tickets (void *cls)
511 struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
512 struct TicketRecordsEntry *le;
513 struct RevokedAttributeEntry *ae;
514 if (NULL == rvk->tickets_to_update_head)
516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
517 "Finished updatding tickets, success\n");
518 rvk->cb (rvk->cb_cls, GNUNET_OK);
522 le = rvk->tickets_to_update_head;
523 GNUNET_CONTAINER_DLL_remove (rvk->tickets_to_update_head,
524 rvk->tickets_to_update_tail,
526 struct GNUNET_GNSRECORD_Data rd[le->rd_count];
527 if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize (le->data_size,
532 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
533 "Unable to deserialize ticket record(s)\n");
534 rvk->cb (rvk->cb_cls, GNUNET_SYSERR);
538 for (int i = 0; i < le->rd_count; i++)
540 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type)
542 for (ae = rvk->attrs_head; NULL != ae; ae = ae->next)
544 if (0 != memcmp (rd[i].data, &ae->old_id, sizeof (uint64_t)))
546 rd[i].data = &ae->new_id;
549 rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
556 GNUNET_free (le->label);
557 GNUNET_free (le->data);
562 rvk_ticket_update_finished (void *cls)
564 struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
566 GNUNET_SCHEDULER_add_now (&process_tickets, rvk);
571 rvk_ns_iter_err (void *cls)
573 struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
575 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
576 "Namestore error on revocation (id=%" PRIu64 "\n",
577 rvk->move_attr->old_id);
578 rvk->cb (rvk->cb_cls, GNUNET_SYSERR);
584 rvk_ns_err (void *cls)
586 struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
588 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
589 "Namestore error on revocation (id=%" PRIu64 "\n",
590 rvk->move_attr->old_id);
591 rvk->cb (rvk->cb_cls, GNUNET_SYSERR);
597 move_attrs (struct RECLAIM_TICKETS_RevokeHandle *rvk)
601 if (NULL == rvk->move_attr)
603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished moving attributes\n");
605 GNUNET_NAMESTORE_zone_iteration_start (nsh,
611 &rvk_ticket_update_finished,
615 label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->old_id,
617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Moving attribute %s\n", label);
619 rvk->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh,
631 remove_ticket_cont (void *cls, int32_t success, const char *emsg)
633 struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
635 if (GNUNET_SYSERR == success)
637 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg);
638 rvk->cb (rvk->cb_cls, GNUNET_SYSERR);
642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted ticket\n");
643 if (0 == rvk->ticket_attrs)
645 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
646 "No attributes to move... strange\n");
647 rvk->cb (rvk->cb_cls, GNUNET_OK);
651 rvk->move_attr = rvk->attrs_head;
657 revoke_attrs_cb (void *cls,
658 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
660 unsigned int rd_count,
661 const struct GNUNET_GNSRECORD_Data *rd)
664 struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
665 struct RevokedAttributeEntry *le;
667 for (int i = 0; i < rd_count; i++)
669 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type)
671 le = GNUNET_new (struct RevokedAttributeEntry);
672 le->old_id = *((uint64_t *) rd[i].data);
673 GNUNET_CONTAINER_DLL_insert (rvk->attrs_head, rvk->attrs_tail, le);
677 /** Now, remove ticket **/
678 rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
689 rvk_attrs_err_cb (void *cls)
691 struct RECLAIM_TICKETS_RevokeHandle *rvk = cls;
692 rvk->cb (rvk->cb_cls, GNUNET_SYSERR);
697 struct RECLAIM_TICKETS_RevokeHandle *
698 RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket,
699 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
700 RECLAIM_TICKETS_RevokeCallback cb,
703 struct RECLAIM_TICKETS_RevokeHandle *rvk;
706 rvk = GNUNET_new (struct RECLAIM_TICKETS_RevokeHandle);
708 rvk->cb_cls = cb_cls;
709 rvk->identity = *identity;
710 rvk->ticket = *ticket;
711 GNUNET_CRYPTO_ecdsa_key_get_public (&rvk->identity, &rvk->ticket.identity);
712 /** Get shared attributes **/
713 label = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t));
714 GNUNET_assert (NULL != label);
715 rvk->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh,
727 RECLAIM_TICKETS_revoke_cancel (struct RECLAIM_TICKETS_RevokeHandle *rh)
731 /*******************************
733 *******************************/
736 * Cleanup ticket consume handle
737 * @param cth the handle to clean up
740 cleanup_cth (struct RECLAIM_TICKETS_ConsumeHandle *cth)
742 struct ParallelLookup *lu;
743 if (NULL != cth->lookup_request)
744 GNUNET_GNS_lookup_cancel (cth->lookup_request);
745 if (NULL != cth->kill_task)
746 GNUNET_SCHEDULER_cancel (cth->kill_task);
747 while (NULL != (lu = cth->parallel_lookups_head))
749 if (NULL != lu->lookup_request)
750 GNUNET_GNS_lookup_cancel (lu->lookup_request);
751 GNUNET_free_non_null (lu->label);
752 GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head,
753 cth->parallel_lookups_tail,
758 if (NULL != cth->attrs)
759 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (cth->attrs);
765 process_parallel_lookup_result (void *cls,
767 const struct GNUNET_GNSRECORD_Data *rd)
769 struct ParallelLookup *parallel_lookup = cls;
770 struct RECLAIM_TICKETS_ConsumeHandle *cth = parallel_lookup->handle;
771 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *attr_le;
772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
773 "Parallel lookup finished (count=%u)\n",
776 GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head,
777 cth->parallel_lookups_tail,
779 GNUNET_free (parallel_lookup->label);
781 GNUNET_STATISTICS_update (stats,
782 "attribute_lookup_time_total",
783 GNUNET_TIME_absolute_get_duration (
784 parallel_lookup->lookup_start_time)
787 GNUNET_STATISTICS_update (stats, "attribute_lookups_count", 1, GNUNET_YES);
790 GNUNET_free (parallel_lookup);
792 GNUNET_break (0); // TODO
793 if (rd->record_type == GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR)
795 attr_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
797 GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd->data, rd->data_size);
798 GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head,
799 cth->attrs->list_tail,
802 if (NULL != cth->parallel_lookups_head)
803 return; // Wait for more
804 /* Else we are done */
806 cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL);
812 abort_parallel_lookups (void *cls)
814 struct RECLAIM_TICKETS_ConsumeHandle *cth = cls;
815 struct ParallelLookup *lu;
816 struct ParallelLookup *tmp;
818 cth->kill_task = NULL;
819 for (lu = cth->parallel_lookups_head; NULL != lu;)
821 GNUNET_GNS_lookup_cancel (lu->lookup_request);
822 GNUNET_free (lu->label);
824 GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head,
825 cth->parallel_lookups_tail,
830 cth->cb (cth->cb_cls, NULL, NULL, GNUNET_SYSERR, "Aborted");
835 lookup_authz_cb (void *cls,
837 const struct GNUNET_GNSRECORD_Data *rd)
839 struct RECLAIM_TICKETS_ConsumeHandle *cth = cls;
840 struct ParallelLookup *parallel_lookup;
843 cth->lookup_request = NULL;
845 GNUNET_STATISTICS_update (stats,
846 "reclaim_authz_lookup_time_total",
847 GNUNET_TIME_absolute_get_duration (
848 cth->lookup_start_time)
851 GNUNET_STATISTICS_update (stats,
852 "reclaim_authz_lookups_count",
856 for (int i = 0; i < rd_count; i++)
858 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type)
860 lbl = GNUNET_STRINGS_data_to_string_alloc (rd[i].data, rd[i].data_size);
861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute ref found %s\n", lbl);
862 parallel_lookup = GNUNET_new (struct ParallelLookup);
863 parallel_lookup->handle = cth;
864 parallel_lookup->label = lbl;
865 parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get ();
866 parallel_lookup->lookup_request =
867 GNUNET_GNS_lookup (gns,
869 &cth->ticket.identity,
870 GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR,
871 GNUNET_GNS_LO_DEFAULT,
872 &process_parallel_lookup_result,
874 GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head,
875 cth->parallel_lookups_tail,
878 if (NULL != cth->parallel_lookups_head)
880 cth->kill_task = GNUNET_SCHEDULER_add_delayed (
881 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 3),
882 &abort_parallel_lookups,
886 cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL);
891 struct RECLAIM_TICKETS_ConsumeHandle *
892 RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id,
893 const struct GNUNET_RECLAIM_Ticket *ticket,
894 RECLAIM_TICKETS_ConsumeCallback cb,
897 struct RECLAIM_TICKETS_ConsumeHandle *cth;
899 cth = GNUNET_new (struct RECLAIM_TICKETS_ConsumeHandle);
902 GNUNET_CRYPTO_ecdsa_key_get_public (&cth->identity, &cth->identity_pub);
903 cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
904 cth->ticket = *ticket;
906 cth->cb_cls = cb_cls;
908 GNUNET_STRINGS_data_to_string_alloc (&cth->ticket.rnd, sizeof (uint64_t));
909 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
910 "Looking for AuthZ info under %s\n",
912 cth->lookup_start_time = GNUNET_TIME_absolute_get ();
913 cth->lookup_request =
914 GNUNET_GNS_lookup (gns,
916 &cth->ticket.identity,
917 GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF,
918 GNUNET_GNS_LO_DEFAULT,
926 RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth)
933 /*******************************
935 *******************************/
938 * Cleanup ticket consume handle
939 * @param handle the handle to clean up
942 cleanup_issue_handle (struct TicketIssueHandle *handle)
944 if (NULL != handle->ns_qe)
945 GNUNET_NAMESTORE_cancel (handle->ns_qe);
946 GNUNET_free (handle);
951 store_ticket_issue_cont (void *cls, int32_t success, const char *emsg)
953 struct TicketIssueHandle *handle = cls;
955 handle->ns_qe = NULL;
956 if (GNUNET_SYSERR == success)
958 handle->cb (handle->cb_cls,
961 "Error storing AuthZ ticket in GNS");
964 handle->cb (handle->cb_cls, &handle->ticket, GNUNET_OK, NULL);
965 cleanup_issue_handle (handle);
970 issue_ticket (struct TicketIssueHandle *ih)
972 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
973 struct GNUNET_GNSRECORD_Data *attrs_record;
978 for (le = ih->attrs->list_head; NULL != le; le = le->next)
982 GNUNET_malloc (list_len * sizeof (struct GNUNET_GNSRECORD_Data));
984 for (le = ih->attrs->list_head; NULL != le; le = le->next)
986 attrs_record[i].data = &le->claim->id;
987 attrs_record[i].data_size = sizeof (le->claim->id);
988 //FIXME: Should this be the attribute expiration time or ticket refresh intv
989 attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us;
990 attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF;
991 attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
994 attrs_record[i].data = &ih->ticket;
995 attrs_record[i].data_size = sizeof (struct GNUNET_RECLAIM_Ticket);
996 attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us;
997 attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET;
998 attrs_record[i].flags =
999 GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION | GNUNET_GNSRECORD_RF_PRIVATE;
1002 GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd, sizeof (uint64_t));
1004 ih->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
1009 &store_ticket_issue_cont,
1011 GNUNET_free (attrs_record);
1012 GNUNET_free (label);
1017 RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1018 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
1019 const struct GNUNET_CRYPTO_EcdsaPublicKey *audience,
1020 RECLAIM_TICKETS_TicketResult cb,
1023 struct TicketIssueHandle *tih;
1024 tih = GNUNET_new (struct TicketIssueHandle);
1026 tih->cb_cls = cb_cls;
1027 tih->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup (attrs);
1028 tih->identity = *identity;
1029 GNUNET_CRYPTO_ecdsa_key_get_public (identity, &tih->ticket.identity);
1031 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX);
1032 tih->ticket.audience = *audience;
1036 /************************************
1038 ************************************/
1041 cleanup_iter (struct RECLAIM_TICKETS_Iterator *iter)
1043 if (NULL != iter->ns_it)
1044 GNUNET_NAMESTORE_zone_iteration_stop (iter->ns_it);
1050 collect_tickets_cb (void *cls,
1051 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1053 unsigned int rd_count,
1054 const struct GNUNET_GNSRECORD_Data *rd)
1056 struct RECLAIM_TICKETS_Iterator *iter = cls;
1058 for (int i = 0; i < rd_count; i++)
1060 if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET != rd[i].record_type)
1062 iter->cb (iter->cb_cls, (struct GNUNET_RECLAIM_Ticket *) rd[i].data);
1065 GNUNET_NAMESTORE_zone_iterator_next (iter->ns_it, 1);
1070 collect_tickets_finished_cb (void *cls)
1072 struct RECLAIM_TICKETS_Iterator *iter = cls;
1074 iter->cb (iter->cb_cls, NULL);
1075 cleanup_iter (iter);
1080 collect_tickets_error_cb (void *cls)
1082 struct RECLAIM_TICKETS_Iterator *iter = cls;
1084 iter->cb (iter->cb_cls, NULL);
1085 cleanup_iter (iter);
1090 RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter)
1092 GNUNET_NAMESTORE_zone_iterator_next (iter->ns_it, 1);
1097 RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter)
1099 GNUNET_NAMESTORE_zone_iteration_stop (iter->ns_it);
1100 cleanup_iter (iter);
1104 struct RECLAIM_TICKETS_Iterator *
1105 RECLAIM_TICKETS_iteration_start (
1106 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1107 RECLAIM_TICKETS_TicketIter cb,
1110 struct RECLAIM_TICKETS_Iterator *iter;
1112 iter = GNUNET_new (struct RECLAIM_TICKETS_Iterator);
1114 iter->cb_cls = cb_cls;
1116 GNUNET_NAMESTORE_zone_iteration_start (nsh,
1118 &collect_tickets_error_cb,
1120 &collect_tickets_cb,
1122 &collect_tickets_finished_cb,
1129 RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c)
1131 // Get ticket expiration time (relative) from config
1133 GNUNET_CONFIGURATION_get_value_time (c,
1135 "TICKET_REFRESH_INTERVAL",
1136 &ticket_refresh_interval))
1138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1139 "Configured refresh interval for tickets: %s\n",
1140 GNUNET_STRINGS_relative_time_to_string (ticket_refresh_interval,
1145 ticket_refresh_interval = DEFAULT_TICKET_REFRESH_INTERVAL;
1147 // Connect to identity and namestore services
1148 nsh = GNUNET_NAMESTORE_connect (c);
1151 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
1152 "error connecting to namestore");
1153 return GNUNET_SYSERR;
1155 gns = GNUNET_GNS_connect (c);
1158 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to gns");
1159 return GNUNET_SYSERR;
1161 stats = GNUNET_STATISTICS_create ("reclaim", c);
1166 RECLAIM_TICKETS_deinit (void)
1169 GNUNET_NAMESTORE_disconnect (nsh);
1172 GNUNET_GNS_disconnect (gns);
1176 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);