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
46 struct GNUNET_RECLAIM_Handle *h;
49 * We keep operations in a DLL.
51 struct GNUNET_RECLAIM_Operation *next;
54 * We keep operations in a DLL.
56 struct GNUNET_RECLAIM_Operation *prev;
59 * Message to send to the service.
60 * Allocated at the end of this struct.
62 const struct GNUNET_MessageHeader *msg;
65 * Continuation to invoke after attribute store call
67 GNUNET_RECLAIM_ContinuationWithStatus as_cb;
70 * Attribute result callback
72 GNUNET_RECLAIM_AttributeResult ar_cb;
75 * Revocation result callback
77 GNUNET_RECLAIM_ContinuationWithStatus rvk_cb;
80 * Ticket result callback
82 GNUNET_RECLAIM_TicketCallback tr_cb;
85 * Envelope with the message for this queue entry.
87 struct GNUNET_MQ_Envelope *env;
95 * Closure for @e cont or @e cb.
102 * Handle for a ticket iterator operation
104 struct GNUNET_RECLAIM_TicketIterator
109 struct GNUNET_RECLAIM_TicketIterator *next;
114 struct GNUNET_RECLAIM_TicketIterator *prev;
117 * Main handle to access the idp.
119 struct GNUNET_RECLAIM_Handle *h;
122 * Function to call on completion.
124 GNUNET_SCHEDULER_TaskCallback finish_cb;
127 * Closure for @e finish_cb.
132 * The continuation to call with the results
134 GNUNET_RECLAIM_TicketCallback tr_cb;
137 * Closure for @e tr_cb.
142 * Function to call on errors.
144 GNUNET_SCHEDULER_TaskCallback error_cb;
147 * Closure for @e error_cb.
152 * Envelope of the message to send to the service, if not yet
155 struct GNUNET_MQ_Envelope *env;
158 * The operation id this zone iteration operation has
165 * Handle for a attribute iterator operation
167 struct GNUNET_RECLAIM_AttributeIterator
172 struct GNUNET_RECLAIM_AttributeIterator *next;
177 struct GNUNET_RECLAIM_AttributeIterator *prev;
180 * Main handle to access the service.
182 struct GNUNET_RECLAIM_Handle *h;
185 * Function to call on completion.
187 GNUNET_SCHEDULER_TaskCallback finish_cb;
190 * Closure for @e finish_cb.
195 * The continuation to call with the results
197 GNUNET_RECLAIM_AttributeResult proc;
200 * Closure for @e proc.
205 * Function to call on errors.
207 GNUNET_SCHEDULER_TaskCallback error_cb;
210 * Closure for @e error_cb.
215 * Envelope of the message to send to the service, if not yet
218 struct GNUNET_MQ_Envelope *env;
221 * Private key of the zone.
223 struct GNUNET_CRYPTO_EcdsaPrivateKey identity;
226 * The operation id this zone iteration operation has
233 * Handle to the service.
235 struct GNUNET_RECLAIM_Handle
238 * Configuration to use.
240 const struct GNUNET_CONFIGURATION_Handle *cfg;
243 * Socket (if available).
245 struct GNUNET_CLIENT_Connection *client;
253 * Head of active operations.
255 struct GNUNET_RECLAIM_Operation *op_head;
258 * Tail of active operations.
260 struct GNUNET_RECLAIM_Operation *op_tail;
263 * Head of active iterations
265 struct GNUNET_RECLAIM_AttributeIterator *it_head;
268 * Tail of active iterations
270 struct GNUNET_RECLAIM_AttributeIterator *it_tail;
273 * Head of active iterations
275 struct GNUNET_RECLAIM_TicketIterator *ticket_it_head;
278 * Tail of active iterations
280 struct GNUNET_RECLAIM_TicketIterator *ticket_it_tail;
283 * Currently pending transmission request, or NULL for none.
285 struct GNUNET_CLIENT_TransmitHandle *th;
288 * Task doing exponential back-off trying to reconnect.
290 struct GNUNET_SCHEDULER_Task *reconnect_task;
293 * Time for next connect retry.
295 struct GNUNET_TIME_Relative reconnect_backoff;
298 * Connection to service (if available).
300 struct GNUNET_MQ_Handle *mq;
303 * Request Id generator. Incremented by one for each request.
308 * Are we polling for incoming messages right now?
315 * Try again to connect to the service.
317 * @param h handle to the reclaim service.
320 reconnect (struct GNUNET_RECLAIM_Handle *h);
326 * @param cls the handle
329 reconnect_task (void *cls)
331 struct GNUNET_RECLAIM_Handle *handle = cls;
333 handle->reconnect_task = NULL;
339 * Disconnect from service and then reconnect.
341 * @param handle our service
344 force_reconnect (struct GNUNET_RECLAIM_Handle *handle)
346 GNUNET_MQ_destroy (handle->mq);
348 handle->reconnect_backoff =
349 GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
350 handle->reconnect_task =
351 GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
360 * @param it entry to free
363 free_it (struct GNUNET_RECLAIM_AttributeIterator *it)
365 struct GNUNET_RECLAIM_Handle *h = it->h;
367 GNUNET_CONTAINER_DLL_remove (h->it_head, h->it_tail, it);
369 GNUNET_MQ_discard (it->env);
376 * @param op the operation to free
379 free_op (struct GNUNET_RECLAIM_Operation *op)
384 GNUNET_MQ_discard (op->env);
390 * Generic error handler, called with the appropriate error code and
391 * the same closure specified at the creation of the message queue.
392 * Not every message queue implementation supports an error handler.
394 * @param cls closure with the `struct GNUNET_GNS_Handle *`
395 * @param error error code
398 mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
400 struct GNUNET_RECLAIM_Handle *handle = cls;
402 force_reconnect (handle);
407 * Handle an incoming message of type
408 * #GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE
411 * @param msg the message we received
414 handle_success_response (void *cls, const struct SuccessResultMessage *msg)
416 struct GNUNET_RECLAIM_Handle *h = cls;
417 struct GNUNET_RECLAIM_Operation *op;
418 uint32_t r_id = ntohl (msg->id);
422 for (op = h->op_head; NULL != op; op = op->next)
423 if (op->r_id == r_id)
428 res = ntohl (msg->op_result);
429 LOG (GNUNET_ERROR_TYPE_DEBUG,
430 "Received SUCCESS_RESPONSE with result %d\n",
433 /* TODO: add actual error message to response... */
434 if (GNUNET_SYSERR == res)
435 emsg = _ ("failed to store record\n");
438 if (NULL != op->as_cb)
439 op->as_cb (op->cls, res, emsg);
440 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
446 * Handle an incoming message of type
447 * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT
450 * @param msg the message we received
451 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
454 check_consume_ticket_result (void *cls,
455 const struct ConsumeTicketResultMessage *msg)
460 msg_len = ntohs (msg->header.size);
461 attrs_len = ntohs (msg->attrs_len);
462 if (msg_len != sizeof(struct ConsumeTicketResultMessage) + attrs_len)
465 return GNUNET_SYSERR;
472 * Handle an incoming message of type
473 * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT
476 * @param msg the message we received
479 handle_consume_ticket_result (void *cls,
480 const struct ConsumeTicketResultMessage *msg)
482 struct GNUNET_RECLAIM_Handle *h = cls;
483 struct GNUNET_RECLAIM_Operation *op;
485 uint32_t r_id = ntohl (msg->id);
487 attrs_len = ntohs (msg->attrs_len);
488 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n");
491 for (op = h->op_head; NULL != op; op = op->next)
492 if (op->r_id == r_id)
498 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
499 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
501 GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *) &msg[1], attrs_len);
502 if (NULL != op->ar_cb)
506 op->ar_cb (op->cls, &msg->identity, NULL);
510 for (le = attrs->list_head; NULL != le; le = le->next)
511 op->ar_cb (op->cls, &msg->identity, le->claim);
512 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs);
515 op->ar_cb (op->cls, NULL, NULL);
517 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
519 GNUNET_free_non_null (attrs);
527 * Handle an incoming message of type
528 * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT
531 * @param msg the message we received
532 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
535 check_attribute_result (void *cls, const struct AttributeResultMessage *msg)
540 msg_len = ntohs (msg->header.size);
541 attr_len = ntohs (msg->attr_len);
542 if (msg_len != sizeof(struct AttributeResultMessage) + attr_len)
545 return GNUNET_SYSERR;
552 * Handle an incoming message of type
553 * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT
556 * @param msg the message we received
559 handle_attribute_result (void *cls, const struct AttributeResultMessage *msg)
561 static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy;
562 struct GNUNET_RECLAIM_Handle *h = cls;
563 struct GNUNET_RECLAIM_AttributeIterator *it;
564 struct GNUNET_RECLAIM_Operation *op;
566 uint32_t r_id = ntohl (msg->id);
568 attr_len = ntohs (msg->attr_len);
569 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n");
572 for (it = h->it_head; NULL != it; it = it->next)
573 if (it->r_id == r_id)
575 for (op = h->op_head; NULL != op; op = op->next)
576 if (op->r_id == r_id)
578 if ((NULL == it) && (NULL == op))
582 (memcmp (&msg->identity, &identity_dummy, sizeof(identity_dummy)))))
584 if ((NULL == it) && (NULL == op))
592 if (NULL != it->finish_cb)
593 it->finish_cb (it->finish_cb_cls);
598 if (NULL != op->ar_cb)
599 op->ar_cb (op->cls, NULL, NULL);
600 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
607 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr;
608 attr = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *) &msg[1], attr_len);
611 if (NULL != it->proc)
612 it->proc (it->proc_cls, &msg->identity, attr);
616 if (NULL != op->ar_cb)
617 op->ar_cb (op->cls, &msg->identity, attr);
627 * Handle an incoming message of type
628 * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT
631 * @param msg the message we received
634 handle_ticket_result (void *cls, const struct TicketResultMessage *msg)
636 struct GNUNET_RECLAIM_Handle *handle = cls;
637 struct GNUNET_RECLAIM_Operation *op;
638 struct GNUNET_RECLAIM_TicketIterator *it;
639 uint32_t r_id = ntohl (msg->id);
640 static const struct GNUNET_RECLAIM_Ticket ticket;
642 for (op = handle->op_head; NULL != op; op = op->next)
643 if (op->r_id == r_id)
645 for (it = handle->ticket_it_head; NULL != it; it = it->next)
646 if (it->r_id == r_id)
648 if ((NULL == op) && (NULL == it))
652 GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op);
654 memcmp (&msg->ticket, &ticket, sizeof(struct GNUNET_RECLAIM_Ticket)))
656 if (NULL != op->tr_cb)
657 op->tr_cb (op->cls, NULL);
661 if (NULL != op->tr_cb)
662 op->tr_cb (op->cls, &msg->ticket);
670 memcmp (&msg->ticket, &ticket, sizeof(struct GNUNET_RECLAIM_Ticket)))
672 GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head,
673 handle->ticket_it_tail,
675 it->finish_cb (it->finish_cb_cls);
680 if (NULL != it->tr_cb)
681 it->tr_cb (it->cls, &msg->ticket);
690 * Handle an incoming message of type
691 * #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT
694 * @param msg the message we received
697 handle_revoke_ticket_result (void *cls,
698 const struct RevokeTicketResultMessage *msg)
700 struct GNUNET_RECLAIM_Handle *h = cls;
701 struct GNUNET_RECLAIM_Operation *op;
702 uint32_t r_id = ntohl (msg->id);
705 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing revocation result.\n");
708 for (op = h->op_head; NULL != op; op = op->next)
709 if (op->r_id == r_id)
713 success = ntohl (msg->success);
715 if (NULL != op->rvk_cb)
717 op->rvk_cb (op->cls, success, NULL);
719 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
728 * Try again to connect to the service.
730 * @param h handle to the reclaim service.
733 reconnect (struct GNUNET_RECLAIM_Handle *h)
735 struct GNUNET_MQ_MessageHandler handlers[] =
736 { GNUNET_MQ_hd_fixed_size (success_response,
737 GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE,
738 struct SuccessResultMessage,
740 GNUNET_MQ_hd_var_size (attribute_result,
741 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT,
742 struct AttributeResultMessage,
744 GNUNET_MQ_hd_fixed_size (ticket_result,
745 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT,
746 struct TicketResultMessage,
748 GNUNET_MQ_hd_var_size (consume_ticket_result,
749 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT,
750 struct ConsumeTicketResultMessage,
752 GNUNET_MQ_hd_fixed_size (revoke_ticket_result,
753 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT,
754 struct RevokeTicketResultMessage,
756 GNUNET_MQ_handler_end () };
757 struct GNUNET_RECLAIM_Operation *op;
759 GNUNET_assert (NULL == h->mq);
760 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to reclaim service.\n");
763 GNUNET_CLIENT_connect (h->cfg, "reclaim", handlers, &mq_error_handler, h);
766 for (op = h->op_head; NULL != op; op = op->next)
767 GNUNET_MQ_send_copy (h->mq, op->env);
772 * Connect to the reclaim service.
774 * @param cfg the configuration to use
775 * @return handle to use
777 struct GNUNET_RECLAIM_Handle *
778 GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
780 struct GNUNET_RECLAIM_Handle *h;
782 h = GNUNET_new (struct GNUNET_RECLAIM_Handle);
795 * Cancel an operation. Note that the operation MAY still
796 * be executed; this merely cancels the continuation; if the request
797 * was already transmitted, the service may still choose to complete
800 * @param op operation to cancel
803 GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op)
805 struct GNUNET_RECLAIM_Handle *h = op->h;
807 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
813 * Disconnect from service
815 * @param h handle to destroy
818 GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h)
820 GNUNET_assert (NULL != h);
823 GNUNET_MQ_destroy (h->mq);
826 if (NULL != h->reconnect_task)
828 GNUNET_SCHEDULER_cancel (h->reconnect_task);
829 h->reconnect_task = NULL;
831 GNUNET_assert (NULL == h->op_head);
836 * Store an attribute. If the attribute is already present,
837 * it is replaced with the new attribute.
839 * @param h handle to the re:claimID service
840 * @param pkey private key of the identity
841 * @param attr the attribute value
842 * @param exp_interval the relative expiration interval for the attribute
843 * @param cont continuation to call when done
844 * @param cont_cls closure for @a cont
845 * @return handle to abort the request
847 struct GNUNET_RECLAIM_Operation *
848 GNUNET_RECLAIM_attribute_store (
849 struct GNUNET_RECLAIM_Handle *h,
850 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
851 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
852 const struct GNUNET_TIME_Relative *exp_interval,
853 GNUNET_RECLAIM_ContinuationWithStatus cont,
856 struct GNUNET_RECLAIM_Operation *op;
857 struct AttributeStoreMessage *sam;
860 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
864 op->r_id = h->r_id_gen++;
865 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
866 attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr);
867 op->env = GNUNET_MQ_msg_extra (sam,
869 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE);
870 sam->identity = *pkey;
871 sam->id = htonl (op->r_id);
872 sam->exp = GNUNET_htonll (exp_interval->rel_value_us);
874 GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *) &sam[1]);
876 sam->attr_len = htons (attr_len);
878 GNUNET_MQ_send_copy (h->mq, op->env);
884 * Delete an attribute. Tickets used to share this attribute are updated
887 * @param h handle to the re:claimID service
888 * @param pkey Private key of the identity to add an attribute to
889 * @param attr The attribute
890 * @param cont Continuation to call when done
891 * @param cont_cls Closure for @a cont
892 * @return handle Used to to abort the request
894 struct GNUNET_RECLAIM_Operation *
895 GNUNET_RECLAIM_attribute_delete (
896 struct GNUNET_RECLAIM_Handle *h,
897 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
898 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
899 GNUNET_RECLAIM_ContinuationWithStatus cont,
902 struct GNUNET_RECLAIM_Operation *op;
903 struct AttributeDeleteMessage *dam;
906 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
910 op->r_id = h->r_id_gen++;
911 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
912 attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr);
913 op->env = GNUNET_MQ_msg_extra (dam,
915 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE);
916 dam->identity = *pkey;
917 dam->id = htonl (op->r_id);
918 GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *) &dam[1]);
920 dam->attr_len = htons (attr_len);
922 GNUNET_MQ_send_copy (h->mq, op->env);
928 * List all attributes for a local identity.
929 * This MUST lock the `struct GNUNET_RECLAIM_Handle`
930 * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and
931 * #GNUNET_RECLAIM_get_attributes_stop. @a proc will be called once
932 * immediately, and then again after
933 * #GNUNET_RECLAIM_get_attributes_next() is invoked.
935 * On error (disconnect), @a error_cb will be invoked.
936 * On normal completion, @a finish_cb proc will be
939 * @param h Handle to the re:claimID service
940 * @param identity Identity to iterate over
941 * @param error_cb Function to call on error (i.e. disconnect),
942 * the handle is afterwards invalid
943 * @param error_cb_cls Closure for @a error_cb
944 * @param proc Function to call on each attribute
945 * @param proc_cls Closure for @a proc
946 * @param finish_cb Function to call on completion
947 * the handle is afterwards invalid
948 * @param finish_cb_cls Closure for @a finish_cb
949 * @return an iterator Handle to use for iteration
951 struct GNUNET_RECLAIM_AttributeIterator *
952 GNUNET_RECLAIM_get_attributes_start (
953 struct GNUNET_RECLAIM_Handle *h,
954 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
955 GNUNET_SCHEDULER_TaskCallback error_cb,
957 GNUNET_RECLAIM_AttributeResult proc,
959 GNUNET_SCHEDULER_TaskCallback finish_cb,
962 struct GNUNET_RECLAIM_AttributeIterator *it;
963 struct GNUNET_MQ_Envelope *env;
964 struct AttributeIterationStartMessage *msg;
968 it = GNUNET_new (struct GNUNET_RECLAIM_AttributeIterator);
970 it->error_cb = error_cb;
971 it->error_cb_cls = error_cb_cls;
972 it->finish_cb = finish_cb;
973 it->finish_cb_cls = finish_cb_cls;
975 it->proc_cls = proc_cls;
977 it->identity = *identity;
978 GNUNET_CONTAINER_DLL_insert_tail (h->it_head, h->it_tail, it);
980 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START);
981 msg->id = htonl (rid);
982 msg->identity = *identity;
986 GNUNET_MQ_send (h->mq, env);
992 * Calls the record processor specified in #GNUNET_RECLAIM_get_attributes_start
993 * for the next record.
995 * @param it the iterator
998 GNUNET_RECLAIM_get_attributes_next (struct GNUNET_RECLAIM_AttributeIterator *it)
1000 struct GNUNET_RECLAIM_Handle *h = it->h;
1001 struct AttributeIterationNextMessage *msg;
1002 struct GNUNET_MQ_Envelope *env;
1005 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT);
1006 msg->id = htonl (it->r_id);
1007 GNUNET_MQ_send (h->mq, env);
1012 * Stops iteration and releases the handle for further calls. Must
1013 * be called on any iteration that has not yet completed prior to calling
1014 * #GNUNET_RECLAIM_disconnect.
1016 * @param it the iterator
1019 GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it)
1021 struct GNUNET_RECLAIM_Handle *h = it->h;
1022 struct GNUNET_MQ_Envelope *env;
1023 struct AttributeIterationStopMessage *msg;
1028 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP);
1029 msg->id = htonl (it->r_id);
1030 GNUNET_MQ_send (h->mq, env);
1037 * Issues a ticket to another relying party. The identity may use
1038 * @GNUNET_RECLAIM_ticket_consume to consume the ticket
1039 * and retrieve the attributes specified in the attribute list.
1041 * @param h the reclaim to use
1042 * @param iss the issuing identity (= the user)
1043 * @param rp the subject of the ticket (= the relying party)
1044 * @param attrs the attributes that the relying party is given access to
1045 * @param cb the callback
1046 * @param cb_cls the callback closure
1047 * @return handle to abort the operation
1049 struct GNUNET_RECLAIM_Operation *
1050 GNUNET_RECLAIM_ticket_issue (
1051 struct GNUNET_RECLAIM_Handle *h,
1052 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
1053 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
1054 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
1055 GNUNET_RECLAIM_TicketCallback cb,
1058 struct GNUNET_RECLAIM_Operation *op;
1059 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 */