2 This file is part of GNUnet.
3 Copyright (C) 2016 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 * @file reclaim/reclaim_api.c
23 * @brief api to interact with the reclaim service
24 * @author Martin Schanzenbach
27 #include "gnunet_util_lib.h"
28 #include "gnunet_constants.h"
29 #include "gnunet_mq_lib.h"
30 #include "gnunet_protocols.h"
31 #include "gnunet_reclaim_attribute_lib.h"
32 #include "gnunet_reclaim_service.h"
35 #define LOG(kind, ...) GNUNET_log_from (kind, "reclaim-api", __VA_ARGS__)
39 * Handle for an operation with the service.
41 struct GNUNET_RECLAIM_Operation
47 struct GNUNET_RECLAIM_Handle *h;
50 * We keep operations in a DLL.
52 struct GNUNET_RECLAIM_Operation *next;
55 * We keep operations in a DLL.
57 struct GNUNET_RECLAIM_Operation *prev;
60 * Message to send to the service.
61 * Allocated at the end of this struct.
63 const struct GNUNET_MessageHeader *msg;
66 * Continuation to invoke after attribute store call
68 GNUNET_RECLAIM_ContinuationWithStatus as_cb;
71 * Attribute result callback
73 GNUNET_RECLAIM_AttributeResult ar_cb;
76 * Revocation result callback
78 GNUNET_RECLAIM_ContinuationWithStatus rvk_cb;
81 * Ticket result callback
83 GNUNET_RECLAIM_TicketCallback tr_cb;
86 * Envelope with the message for this queue entry.
88 struct GNUNET_MQ_Envelope *env;
96 * Closure for @e cont or @e cb.
103 * Handle for a ticket iterator operation
105 struct GNUNET_RECLAIM_TicketIterator
111 struct GNUNET_RECLAIM_TicketIterator *next;
116 struct GNUNET_RECLAIM_TicketIterator *prev;
119 * Main handle to access the idp.
121 struct GNUNET_RECLAIM_Handle *h;
124 * Function to call on completion.
126 GNUNET_SCHEDULER_TaskCallback finish_cb;
129 * Closure for @e finish_cb.
134 * The continuation to call with the results
136 GNUNET_RECLAIM_TicketCallback tr_cb;
139 * Closure for @e tr_cb.
144 * Function to call on errors.
146 GNUNET_SCHEDULER_TaskCallback error_cb;
149 * Closure for @e error_cb.
154 * Envelope of the message to send to the service, if not yet
157 struct GNUNET_MQ_Envelope *env;
160 * The operation id this zone iteration operation has
167 * Handle for a attribute iterator operation
169 struct GNUNET_RECLAIM_AttributeIterator
175 struct GNUNET_RECLAIM_AttributeIterator *next;
180 struct GNUNET_RECLAIM_AttributeIterator *prev;
183 * Main handle to access the service.
185 struct GNUNET_RECLAIM_Handle *h;
188 * Function to call on completion.
190 GNUNET_SCHEDULER_TaskCallback finish_cb;
193 * Closure for @e finish_cb.
198 * The continuation to call with the results
200 GNUNET_RECLAIM_AttributeResult proc;
203 * Closure for @e proc.
208 * Function to call on errors.
210 GNUNET_SCHEDULER_TaskCallback error_cb;
213 * Closure for @e error_cb.
218 * Envelope of the message to send to the service, if not yet
221 struct GNUNET_MQ_Envelope *env;
224 * Private key of the zone.
226 struct GNUNET_CRYPTO_EcdsaPrivateKey identity;
229 * The operation id this zone iteration operation has
236 * Handle to the service.
238 struct GNUNET_RECLAIM_Handle
241 * Configuration to use.
243 const struct GNUNET_CONFIGURATION_Handle *cfg;
246 * Socket (if available).
248 struct GNUNET_CLIENT_Connection *client;
256 * Head of active operations.
258 struct GNUNET_RECLAIM_Operation *op_head;
261 * Tail of active operations.
263 struct GNUNET_RECLAIM_Operation *op_tail;
266 * Head of active iterations
268 struct GNUNET_RECLAIM_AttributeIterator *it_head;
271 * Tail of active iterations
273 struct GNUNET_RECLAIM_AttributeIterator *it_tail;
276 * Head of active iterations
278 struct GNUNET_RECLAIM_TicketIterator *ticket_it_head;
281 * Tail of active iterations
283 struct GNUNET_RECLAIM_TicketIterator *ticket_it_tail;
286 * Currently pending transmission request, or NULL for none.
288 struct GNUNET_CLIENT_TransmitHandle *th;
291 * Task doing exponential back-off trying to reconnect.
293 struct GNUNET_SCHEDULER_Task *reconnect_task;
296 * Time for next connect retry.
298 struct GNUNET_TIME_Relative reconnect_backoff;
301 * Connection to service (if available).
303 struct GNUNET_MQ_Handle *mq;
306 * Request Id generator. Incremented by one for each request.
311 * Are we polling for incoming messages right now?
318 * Try again to connect to the service.
320 * @param h handle to the reclaim service.
323 reconnect (struct GNUNET_RECLAIM_Handle *h);
329 * @param cls the handle
332 reconnect_task (void *cls)
334 struct GNUNET_RECLAIM_Handle *handle = cls;
336 handle->reconnect_task = NULL;
342 * Disconnect from service and then reconnect.
344 * @param handle our service
347 force_reconnect (struct GNUNET_RECLAIM_Handle *handle)
349 GNUNET_MQ_destroy (handle->mq);
351 handle->reconnect_backoff =
352 GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
353 handle->reconnect_task =
354 GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
363 * @param it entry to free
366 free_it (struct GNUNET_RECLAIM_AttributeIterator *it)
368 struct GNUNET_RECLAIM_Handle *h = it->h;
370 GNUNET_CONTAINER_DLL_remove (h->it_head, h->it_tail, it);
372 GNUNET_MQ_discard (it->env);
379 * @param op the operation to free
382 free_op (struct GNUNET_RECLAIM_Operation *op)
387 GNUNET_MQ_discard (op->env);
393 * Generic error handler, called with the appropriate error code and
394 * the same closure specified at the creation of the message queue.
395 * Not every message queue implementation supports an error handler.
397 * @param cls closure with the `struct GNUNET_GNS_Handle *`
398 * @param error error code
401 mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
403 struct GNUNET_RECLAIM_Handle *handle = cls;
404 force_reconnect (handle);
409 * Handle an incoming message of type
410 * #GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE
413 * @param msg the message we received
416 handle_success_response (void *cls, const struct SuccessResultMessage *msg)
418 struct GNUNET_RECLAIM_Handle *h = cls;
419 struct GNUNET_RECLAIM_Operation *op;
420 uint32_t r_id = ntohl (msg->id);
424 for (op = h->op_head; NULL != op; op = op->next)
425 if (op->r_id == r_id)
430 res = ntohl (msg->op_result);
431 LOG (GNUNET_ERROR_TYPE_DEBUG,
432 "Received SUCCESS_RESPONSE with result %d\n",
435 /* TODO: add actual error message to response... */
436 if (GNUNET_SYSERR == res)
437 emsg = _ ("failed to store record\n");
440 if (NULL != op->as_cb)
441 op->as_cb (op->cls, res, emsg);
442 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
448 * Handle an incoming message of type
449 * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT
452 * @param msg the message we received
453 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
456 check_consume_ticket_result (void *cls,
457 const struct ConsumeTicketResultMessage *msg)
462 msg_len = ntohs (msg->header.size);
463 attrs_len = ntohs (msg->attrs_len);
464 if (msg_len != sizeof (struct ConsumeTicketResultMessage) + attrs_len)
467 return GNUNET_SYSERR;
474 * Handle an incoming message of type
475 * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT
478 * @param msg the message we received
481 handle_consume_ticket_result (void *cls,
482 const struct ConsumeTicketResultMessage *msg)
484 struct GNUNET_RECLAIM_Handle *h = cls;
485 struct GNUNET_RECLAIM_Operation *op;
487 uint32_t r_id = ntohl (msg->id);
489 attrs_len = ntohs (msg->attrs_len);
490 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n");
493 for (op = h->op_head; NULL != op; op = op->next)
494 if (op->r_id == r_id)
500 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
501 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
503 GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *) &msg[1], attrs_len);
504 if (NULL != op->ar_cb)
508 op->ar_cb (op->cls, &msg->identity, NULL);
512 for (le = attrs->list_head; NULL != le; le = le->next)
513 op->ar_cb (op->cls, &msg->identity, le->claim);
514 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs);
517 op->ar_cb (op->cls, NULL, NULL);
519 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
521 GNUNET_free_non_null (attrs);
529 * Handle an incoming message of type
530 * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT
533 * @param msg the message we received
534 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
537 check_attribute_result (void *cls, const struct AttributeResultMessage *msg)
542 msg_len = ntohs (msg->header.size);
543 attr_len = ntohs (msg->attr_len);
544 if (msg_len != sizeof (struct AttributeResultMessage) + attr_len)
547 return GNUNET_SYSERR;
554 * Handle an incoming message of type
555 * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT
558 * @param msg the message we received
561 handle_attribute_result (void *cls, const struct AttributeResultMessage *msg)
563 static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy;
564 struct GNUNET_RECLAIM_Handle *h = cls;
565 struct GNUNET_RECLAIM_AttributeIterator *it;
566 struct GNUNET_RECLAIM_Operation *op;
568 uint32_t r_id = ntohl (msg->id);
570 attr_len = ntohs (msg->attr_len);
571 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n");
574 for (it = h->it_head; NULL != it; it = it->next)
575 if (it->r_id == r_id)
577 for (op = h->op_head; NULL != op; op = op->next)
578 if (op->r_id == r_id)
580 if ((NULL == it) && (NULL == op))
584 (memcmp (&msg->identity, &identity_dummy, sizeof (identity_dummy)))))
586 if ((NULL == it) && (NULL == op))
594 if (NULL != it->finish_cb)
595 it->finish_cb (it->finish_cb_cls);
600 if (NULL != op->ar_cb)
601 op->ar_cb (op->cls, NULL, NULL);
602 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
609 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr;
610 attr = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *) &msg[1], attr_len);
613 if (NULL != it->proc)
614 it->proc (it->proc_cls, &msg->identity, attr);
618 if (NULL != op->ar_cb)
619 op->ar_cb (op->cls, &msg->identity, attr);
629 * Handle an incoming message of type
630 * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT
633 * @param msg the message we received
636 handle_ticket_result (void *cls, const struct TicketResultMessage *msg)
638 struct GNUNET_RECLAIM_Handle *handle = cls;
639 struct GNUNET_RECLAIM_Operation *op;
640 struct GNUNET_RECLAIM_TicketIterator *it;
641 uint32_t r_id = ntohl (msg->id);
642 static const struct GNUNET_RECLAIM_Ticket ticket;
643 for (op = handle->op_head; NULL != op; op = op->next)
644 if (op->r_id == r_id)
646 for (it = handle->ticket_it_head; NULL != it; it = it->next)
647 if (it->r_id == r_id)
649 if ((NULL == op) && (NULL == it))
653 GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op);
655 memcmp (&msg->ticket, &ticket, sizeof (struct GNUNET_RECLAIM_Ticket)))
657 if (NULL != op->tr_cb)
658 op->tr_cb (op->cls, NULL);
662 if (NULL != op->tr_cb)
663 op->tr_cb (op->cls, &msg->ticket);
671 memcmp (&msg->ticket, &ticket, sizeof (struct GNUNET_RECLAIM_Ticket)))
673 GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head,
674 handle->ticket_it_tail,
676 it->finish_cb (it->finish_cb_cls);
681 if (NULL != it->tr_cb)
682 it->tr_cb (it->cls, &msg->ticket);
691 * Handle an incoming message of type
692 * #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT
695 * @param msg the message we received
698 handle_revoke_ticket_result (void *cls,
699 const struct RevokeTicketResultMessage *msg)
701 struct GNUNET_RECLAIM_Handle *h = cls;
702 struct GNUNET_RECLAIM_Operation *op;
703 uint32_t r_id = ntohl (msg->id);
706 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing revocation result.\n");
709 for (op = h->op_head; NULL != op; op = op->next)
710 if (op->r_id == r_id)
714 success = ntohl (msg->success);
716 if (NULL != op->rvk_cb)
718 op->rvk_cb (op->cls, success, NULL);
720 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
729 * Try again to connect to the service.
731 * @param h handle to the reclaim service.
734 reconnect (struct GNUNET_RECLAIM_Handle *h)
736 struct GNUNET_MQ_MessageHandler handlers[] =
737 {GNUNET_MQ_hd_fixed_size (success_response,
738 GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE,
739 struct SuccessResultMessage,
741 GNUNET_MQ_hd_var_size (attribute_result,
742 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT,
743 struct AttributeResultMessage,
745 GNUNET_MQ_hd_fixed_size (ticket_result,
746 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT,
747 struct TicketResultMessage,
749 GNUNET_MQ_hd_var_size (consume_ticket_result,
750 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT,
751 struct ConsumeTicketResultMessage,
753 GNUNET_MQ_hd_fixed_size (revoke_ticket_result,
754 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT,
755 struct RevokeTicketResultMessage,
757 GNUNET_MQ_handler_end ()};
758 struct GNUNET_RECLAIM_Operation *op;
760 GNUNET_assert (NULL == h->mq);
761 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to reclaim service.\n");
764 GNUNET_CLIENT_connect (h->cfg, "reclaim", handlers, &mq_error_handler, h);
767 for (op = h->op_head; NULL != op; op = op->next)
768 GNUNET_MQ_send_copy (h->mq, op->env);
773 * Connect to the reclaim service.
775 * @param cfg the configuration to use
776 * @return handle to use
778 struct GNUNET_RECLAIM_Handle *
779 GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
781 struct GNUNET_RECLAIM_Handle *h;
783 h = GNUNET_new (struct GNUNET_RECLAIM_Handle);
796 * Cancel an operation. Note that the operation MAY still
797 * be executed; this merely cancels the continuation; if the request
798 * was already transmitted, the service may still choose to complete
801 * @param op operation to cancel
804 GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op)
806 struct GNUNET_RECLAIM_Handle *h = op->h;
808 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
814 * Disconnect from service
816 * @param h handle to destroy
819 GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h)
821 GNUNET_assert (NULL != h);
824 GNUNET_MQ_destroy (h->mq);
827 if (NULL != h->reconnect_task)
829 GNUNET_SCHEDULER_cancel (h->reconnect_task);
830 h->reconnect_task = NULL;
832 GNUNET_assert (NULL == h->op_head);
837 * Store an attribute. If the attribute is already present,
838 * it is replaced with the new attribute.
840 * @param h handle to the re:claimID service
841 * @param pkey private key of the identity
842 * @param attr the attribute value
843 * @param exp_interval the relative expiration interval for the attribute
844 * @param cont continuation to call when done
845 * @param cont_cls closure for @a cont
846 * @return handle to abort the request
848 struct GNUNET_RECLAIM_Operation *
849 GNUNET_RECLAIM_attribute_store (
850 struct GNUNET_RECLAIM_Handle *h,
851 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
852 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
853 const struct GNUNET_TIME_Relative *exp_interval,
854 GNUNET_RECLAIM_ContinuationWithStatus cont,
857 struct GNUNET_RECLAIM_Operation *op;
858 struct AttributeStoreMessage *sam;
861 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
865 op->r_id = h->r_id_gen++;
866 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
867 attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr);
868 op->env = GNUNET_MQ_msg_extra (sam,
870 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE);
871 sam->identity = *pkey;
872 sam->id = htonl (op->r_id);
873 sam->exp = GNUNET_htonll (exp_interval->rel_value_us);
875 GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *) &sam[1]);
877 sam->attr_len = htons (attr_len);
879 GNUNET_MQ_send_copy (h->mq, op->env);
885 * Delete an attribute. Tickets used to share this attribute are updated
888 * @param h handle to the re:claimID service
889 * @param pkey Private key of the identity to add an attribute to
890 * @param attr The attribute
891 * @param cont Continuation to call when done
892 * @param cont_cls Closure for @a cont
893 * @return handle Used to to abort the request
895 struct GNUNET_RECLAIM_Operation *
896 GNUNET_RECLAIM_attribute_delete (
897 struct GNUNET_RECLAIM_Handle *h,
898 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
899 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
900 GNUNET_RECLAIM_ContinuationWithStatus cont,
903 struct GNUNET_RECLAIM_Operation *op;
904 struct AttributeDeleteMessage *dam;
907 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
911 op->r_id = h->r_id_gen++;
912 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
913 attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr);
914 op->env = GNUNET_MQ_msg_extra (dam,
916 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE);
917 dam->identity = *pkey;
918 dam->id = htonl (op->r_id);
919 GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *) &dam[1]);
921 dam->attr_len = htons (attr_len);
923 GNUNET_MQ_send_copy (h->mq, op->env);
929 * List all attributes for a local identity.
930 * This MUST lock the `struct GNUNET_RECLAIM_Handle`
931 * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and
932 * #GNUNET_RECLAIM_get_attributes_stop. @a proc will be called once
933 * immediately, and then again after
934 * #GNUNET_RECLAIM_get_attributes_next() is invoked.
936 * On error (disconnect), @a error_cb will be invoked.
937 * On normal completion, @a finish_cb proc will be
940 * @param h Handle to the re:claimID service
941 * @param identity Identity to iterate over
942 * @param error_cb Function to call on error (i.e. disconnect),
943 * the handle is afterwards invalid
944 * @param error_cb_cls Closure for @a error_cb
945 * @param proc Function to call on each attribute
946 * @param proc_cls Closure for @a proc
947 * @param finish_cb Function to call on completion
948 * the handle is afterwards invalid
949 * @param finish_cb_cls Closure for @a finish_cb
950 * @return an iterator Handle to use for iteration
952 struct GNUNET_RECLAIM_AttributeIterator *
953 GNUNET_RECLAIM_get_attributes_start (
954 struct GNUNET_RECLAIM_Handle *h,
955 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
956 GNUNET_SCHEDULER_TaskCallback error_cb,
958 GNUNET_RECLAIM_AttributeResult proc,
960 GNUNET_SCHEDULER_TaskCallback finish_cb,
963 struct GNUNET_RECLAIM_AttributeIterator *it;
964 struct GNUNET_MQ_Envelope *env;
965 struct AttributeIterationStartMessage *msg;
969 it = GNUNET_new (struct GNUNET_RECLAIM_AttributeIterator);
971 it->error_cb = error_cb;
972 it->error_cb_cls = error_cb_cls;
973 it->finish_cb = finish_cb;
974 it->finish_cb_cls = finish_cb_cls;
976 it->proc_cls = proc_cls;
978 it->identity = *identity;
979 GNUNET_CONTAINER_DLL_insert_tail (h->it_head, h->it_tail, it);
981 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START);
982 msg->id = htonl (rid);
983 msg->identity = *identity;
987 GNUNET_MQ_send (h->mq, env);
993 * Calls the record processor specified in #GNUNET_RECLAIM_get_attributes_start
994 * for the next record.
996 * @param it the iterator
999 GNUNET_RECLAIM_get_attributes_next (struct GNUNET_RECLAIM_AttributeIterator *it)
1001 struct GNUNET_RECLAIM_Handle *h = it->h;
1002 struct AttributeIterationNextMessage *msg;
1003 struct GNUNET_MQ_Envelope *env;
1006 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT);
1007 msg->id = htonl (it->r_id);
1008 GNUNET_MQ_send (h->mq, env);
1013 * Stops iteration and releases the handle for further calls. Must
1014 * be called on any iteration that has not yet completed prior to calling
1015 * #GNUNET_RECLAIM_disconnect.
1017 * @param it the iterator
1020 GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it)
1022 struct GNUNET_RECLAIM_Handle *h = it->h;
1023 struct GNUNET_MQ_Envelope *env;
1024 struct AttributeIterationStopMessage *msg;
1029 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP);
1030 msg->id = htonl (it->r_id);
1031 GNUNET_MQ_send (h->mq, env);
1038 * Issues a ticket to another relying party. The identity may use
1039 * @GNUNET_RECLAIM_ticket_consume to consume the ticket
1040 * and retrieve the attributes specified in the attribute list.
1042 * @param h the reclaim to use
1043 * @param iss the issuing identity (= the user)
1044 * @param rp the subject of the ticket (= the relying party)
1045 * @param attrs the attributes that the relying party is given access to
1046 * @param cb the callback
1047 * @param cb_cls the callback closure
1048 * @return handle to abort the operation
1050 struct GNUNET_RECLAIM_Operation *
1051 GNUNET_RECLAIM_ticket_issue (
1052 struct GNUNET_RECLAIM_Handle *h,
1053 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
1054 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
1055 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
1056 GNUNET_RECLAIM_TicketCallback cb,
1059 struct GNUNET_RECLAIM_Operation *op;
1060 struct IssueTicketMessage *tim;
1062 fprintf (stderr, "Issuing ticket\n");
1063 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1067 op->r_id = h->r_id_gen++;
1068 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1069 attr_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs);
1070 op->env = GNUNET_MQ_msg_extra (tim,
1072 GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET);
1073 tim->identity = *iss;
1075 tim->id = htonl (op->r_id);
1077 GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, (char *) &tim[1]);
1079 tim->attr_len = htons (attr_len);
1081 GNUNET_MQ_send_copy (h->mq, op->env);
1087 * Consumes an issued ticket. The ticket is persisted
1088 * and used to retrieve identity information from the issuer
1090 * @param h the reclaim to use
1091 * @param identity the identity that is the subject of the issued ticket (the
1093 * @param ticket the issued ticket to consume
1094 * @param cb the callback to call
1095 * @param cb_cls the callback closure
1096 * @return handle to abort the operation
1098 struct GNUNET_RECLAIM_Operation *
1099 GNUNET_RECLAIM_ticket_consume (
1100 struct GNUNET_RECLAIM_Handle *h,
1101 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1102 const struct GNUNET_RECLAIM_Ticket *ticket,
1103 GNUNET_RECLAIM_AttributeResult cb,
1106 struct GNUNET_RECLAIM_Operation *op;
1107 struct ConsumeTicketMessage *ctm;
1109 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1113 op->r_id = h->r_id_gen++;
1114 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1115 op->env = GNUNET_MQ_msg (ctm, GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET);
1116 ctm->identity = *identity;
1117 ctm->id = htonl (op->r_id);
1118 ctm->ticket = *ticket;
1120 GNUNET_MQ_send_copy (h->mq, op->env);
1126 * Lists all tickets that have been issued to remote
1127 * identites (relying parties)
1129 * @param h the reclaim to use
1130 * @param identity the issuing identity
1131 * @param error_cb function to call on error (i.e. disconnect),
1132 * the handle is afterwards invalid
1133 * @param error_cb_cls closure for @a error_cb
1134 * @param proc function to call on each ticket; it
1135 * will be called repeatedly with a value (if available)
1136 * @param proc_cls closure for @a proc
1137 * @param finish_cb function to call on completion
1138 * the handle is afterwards invalid
1139 * @param finish_cb_cls closure for @a finish_cb
1140 * @return an iterator handle to use for iteration
1142 struct GNUNET_RECLAIM_TicketIterator *
1143 GNUNET_RECLAIM_ticket_iteration_start (
1144 struct GNUNET_RECLAIM_Handle *h,
1145 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1146 GNUNET_SCHEDULER_TaskCallback error_cb,
1148 GNUNET_RECLAIM_TicketCallback proc,
1150 GNUNET_SCHEDULER_TaskCallback finish_cb,
1151 void *finish_cb_cls)
1153 struct GNUNET_RECLAIM_TicketIterator *it;
1154 struct GNUNET_MQ_Envelope *env;
1155 struct TicketIterationStartMessage *msg;
1158 rid = h->r_id_gen++;
1159 it = GNUNET_new (struct GNUNET_RECLAIM_TicketIterator);
1161 it->error_cb = error_cb;
1162 it->error_cb_cls = error_cb_cls;
1163 it->finish_cb = finish_cb;
1164 it->finish_cb_cls = finish_cb_cls;
1168 GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head, h->ticket_it_tail, it);
1169 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START);
1170 msg->id = htonl (rid);
1171 msg->identity = *identity;
1175 GNUNET_MQ_send (h->mq, env);
1181 * Calls the ticket processor specified in
1182 * #GNUNET_RECLAIM_ticket_iteration_start for the next record.
1184 * @param it the iterator
1187 GNUNET_RECLAIM_ticket_iteration_next (struct GNUNET_RECLAIM_TicketIterator *it)
1189 struct GNUNET_RECLAIM_Handle *h = it->h;
1190 struct TicketIterationNextMessage *msg;
1191 struct GNUNET_MQ_Envelope *env;
1193 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT);
1194 msg->id = htonl (it->r_id);
1195 GNUNET_MQ_send (h->mq, env);
1200 * Stops iteration and releases the handle for further calls. Must
1201 * be called on any iteration that has not yet completed prior to calling
1202 * #GNUNET_RECLAIM_disconnect.
1204 * @param it the iterator
1207 GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it)
1209 struct GNUNET_RECLAIM_Handle *h = it->h;
1210 struct GNUNET_MQ_Envelope *env;
1211 struct TicketIterationStopMessage *msg;
1216 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP);
1217 msg->id = htonl (it->r_id);
1218 GNUNET_MQ_send (h->mq, env);
1225 * Revoked an issued ticket. The relying party will be unable to retrieve
1226 * attributes. Other issued tickets remain unaffected.
1227 * This includes tickets issued to other relying parties as well as to
1228 * other tickets issued to the audience specified in this ticket.
1230 * @param h the identity provider to use
1231 * @param identity the issuing identity
1232 * @param ticket the ticket to revoke
1233 * @param cb the callback
1234 * @param cb_cls the callback closure
1235 * @return handle to abort the operation
1237 struct GNUNET_RECLAIM_Operation *
1238 GNUNET_RECLAIM_ticket_revoke (
1239 struct GNUNET_RECLAIM_Handle *h,
1240 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1241 const struct GNUNET_RECLAIM_Ticket *ticket,
1242 GNUNET_RECLAIM_ContinuationWithStatus cb,
1245 struct GNUNET_RECLAIM_Operation *op;
1246 struct RevokeTicketMessage *msg;
1249 rid = h->r_id_gen++;
1250 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1255 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1256 op->env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET);
1257 msg->id = htonl (rid);
1258 msg->identity = *identity;
1259 msg->ticket = *ticket;
1262 GNUNET_MQ_send (h->mq, op->env);
1269 /* end of reclaim_api.c */