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
28 #include "gnunet_util_lib.h"
30 #include "gnunet_constants.h"
31 #include "gnunet_mq_lib.h"
32 #include "gnunet_protocols.h"
33 #include "gnunet_reclaim_attribute_lib.h"
34 #include "gnunet_reclaim_service.h"
37 #define LOG(kind, ...) GNUNET_log_from (kind, "reclaim-api", __VA_ARGS__)
41 * Handle for an operation with the service.
43 struct GNUNET_RECLAIM_Operation
49 struct GNUNET_RECLAIM_Handle *h;
52 * We keep operations in a DLL.
54 struct GNUNET_RECLAIM_Operation *next;
57 * We keep operations in a DLL.
59 struct GNUNET_RECLAIM_Operation *prev;
62 * Message to send to the service.
63 * Allocated at the end of this struct.
65 const struct GNUNET_MessageHeader *msg;
68 * Continuation to invoke after attribute store call
70 GNUNET_RECLAIM_ContinuationWithStatus as_cb;
73 * Attribute result callback
75 GNUNET_RECLAIM_AttributeResult ar_cb;
78 * Revocation result callback
80 GNUNET_RECLAIM_ContinuationWithStatus rvk_cb;
83 * Ticket result callback
85 GNUNET_RECLAIM_TicketCallback tr_cb;
88 * Envelope with the message for this queue entry.
90 struct GNUNET_MQ_Envelope *env;
98 * Closure for @e cont or @e cb.
105 * Handle for a ticket iterator operation
107 struct GNUNET_RECLAIM_TicketIterator
113 struct GNUNET_RECLAIM_TicketIterator *next;
118 struct GNUNET_RECLAIM_TicketIterator *prev;
121 * Main handle to access the idp.
123 struct GNUNET_RECLAIM_Handle *h;
126 * Function to call on completion.
128 GNUNET_SCHEDULER_TaskCallback finish_cb;
131 * Closure for @e finish_cb.
136 * The continuation to call with the results
138 GNUNET_RECLAIM_TicketCallback tr_cb;
141 * Closure for @e tr_cb.
146 * Function to call on errors.
148 GNUNET_SCHEDULER_TaskCallback error_cb;
151 * Closure for @e error_cb.
156 * Envelope of the message to send to the service, if not yet
159 struct GNUNET_MQ_Envelope *env;
162 * The operation id this zone iteration operation has
169 * Handle for a attribute iterator operation
171 struct GNUNET_RECLAIM_AttributeIterator
177 struct GNUNET_RECLAIM_AttributeIterator *next;
182 struct GNUNET_RECLAIM_AttributeIterator *prev;
185 * Main handle to access the service.
187 struct GNUNET_RECLAIM_Handle *h;
190 * Function to call on completion.
192 GNUNET_SCHEDULER_TaskCallback finish_cb;
195 * Closure for @e finish_cb.
200 * The continuation to call with the results
202 GNUNET_RECLAIM_AttributeResult proc;
205 * Closure for @e proc.
210 * Function to call on errors.
212 GNUNET_SCHEDULER_TaskCallback error_cb;
215 * Closure for @e error_cb.
220 * Envelope of the message to send to the service, if not yet
223 struct GNUNET_MQ_Envelope *env;
226 * Private key of the zone.
228 struct GNUNET_CRYPTO_EcdsaPrivateKey identity;
231 * The operation id this zone iteration operation has
238 * Handle to the service.
240 struct GNUNET_RECLAIM_Handle
243 * Configuration to use.
245 const struct GNUNET_CONFIGURATION_Handle *cfg;
248 * Socket (if available).
250 struct GNUNET_CLIENT_Connection *client;
258 * Head of active operations.
260 struct GNUNET_RECLAIM_Operation *op_head;
263 * Tail of active operations.
265 struct GNUNET_RECLAIM_Operation *op_tail;
268 * Head of active iterations
270 struct GNUNET_RECLAIM_AttributeIterator *it_head;
273 * Tail of active iterations
275 struct GNUNET_RECLAIM_AttributeIterator *it_tail;
278 * Head of active iterations
280 struct GNUNET_RECLAIM_TicketIterator *ticket_it_head;
283 * Tail of active iterations
285 struct GNUNET_RECLAIM_TicketIterator *ticket_it_tail;
288 * Currently pending transmission request, or NULL for none.
290 struct GNUNET_CLIENT_TransmitHandle *th;
293 * Task doing exponential back-off trying to reconnect.
295 struct GNUNET_SCHEDULER_Task *reconnect_task;
298 * Time for next connect retry.
300 struct GNUNET_TIME_Relative reconnect_backoff;
303 * Connection to service (if available).
305 struct GNUNET_MQ_Handle *mq;
308 * Request Id generator. Incremented by one for each request.
313 * Are we polling for incoming messages right now?
320 * Try again to connect to the service.
322 * @param h handle to the reclaim service.
325 reconnect (struct GNUNET_RECLAIM_Handle *h);
331 * @param cls the handle
334 reconnect_task (void *cls)
336 struct GNUNET_RECLAIM_Handle *handle = cls;
338 handle->reconnect_task = NULL;
344 * Disconnect from service and then reconnect.
346 * @param handle our service
349 force_reconnect (struct GNUNET_RECLAIM_Handle *handle)
351 GNUNET_MQ_destroy (handle->mq);
353 handle->reconnect_backoff =
354 GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
355 handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (
356 handle->reconnect_backoff, &reconnect_task, handle);
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, "Received SUCCESS_RESPONSE with result %d\n",
434 /* TODO: add actual error message to response... */
435 if (GNUNET_SYSERR == res)
436 emsg = _ ("failed to store record\n");
439 if (NULL != op->as_cb)
440 op->as_cb (op->cls, res, emsg);
441 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
447 * Handle an incoming message of type
448 * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT
451 * @param msg the message we received
452 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
455 check_consume_ticket_result (void *cls,
456 const struct ConsumeTicketResultMessage *msg)
461 msg_len = ntohs (msg->header.size);
462 attrs_len = ntohs (msg->attrs_len);
463 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) {
504 op->ar_cb (op->cls, &msg->identity, NULL);
506 for (le = attrs->list_head; NULL != le; le = le->next)
507 op->ar_cb (op->cls, &msg->identity, le->claim);
508 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs);
512 op->ar_cb (op->cls, NULL, NULL);
513 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
523 * Handle an incoming message of type
524 * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT
527 * @param msg the message we received
528 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
531 check_attribute_result (void *cls, const struct AttributeResultMessage *msg)
536 msg_len = ntohs (msg->header.size);
537 attr_len = ntohs (msg->attr_len);
538 if (msg_len != sizeof (struct AttributeResultMessage) + attr_len) {
540 return GNUNET_SYSERR;
547 * Handle an incoming message of type
548 * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT
551 * @param msg the message we received
554 handle_attribute_result (void *cls, const struct AttributeResultMessage *msg)
556 static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy;
557 struct GNUNET_RECLAIM_Handle *h = cls;
558 struct GNUNET_RECLAIM_AttributeIterator *it;
559 struct GNUNET_RECLAIM_Operation *op;
561 uint32_t r_id = ntohl (msg->id);
563 attr_len = ntohs (msg->attr_len);
564 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n");
567 for (it = h->it_head; NULL != it; it = it->next)
568 if (it->r_id == r_id)
570 for (op = h->op_head; NULL != op; op = op->next)
571 if (op->r_id == r_id)
573 if ((NULL == it) && (NULL == op))
577 (memcmp (&msg->identity, &identity_dummy, sizeof (identity_dummy))))) {
578 if ((NULL == it) && (NULL == op)) {
584 if (NULL != it->finish_cb)
585 it->finish_cb (it->finish_cb_cls);
589 if (NULL != op->ar_cb)
590 op->ar_cb (op->cls, NULL, NULL);
591 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
598 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr;
599 attr = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *)&msg[1], attr_len);
601 if (NULL != it->proc)
602 it->proc (it->proc_cls, &msg->identity, attr);
603 } else if (NULL != op) {
604 if (NULL != op->ar_cb)
605 op->ar_cb (op->cls, &msg->identity, attr);
614 * Handle an incoming message of type
615 * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT
618 * @param msg the message we received
619 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
622 check_ticket_result (void *cls, const struct TicketResultMessage *msg)
626 msg_len = ntohs (msg->header.size);
627 if (msg_len < sizeof (struct TicketResultMessage)) {
629 return GNUNET_SYSERR;
636 * Handle an incoming message of type
637 * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT
640 * @param msg the message we received
643 handle_ticket_result (void *cls, const struct TicketResultMessage *msg)
645 struct GNUNET_RECLAIM_Handle *handle = cls;
646 struct GNUNET_RECLAIM_Operation *op;
647 struct GNUNET_RECLAIM_TicketIterator *it;
648 const struct GNUNET_RECLAIM_Ticket *ticket;
649 uint32_t r_id = ntohl (msg->id);
652 for (op = handle->op_head; NULL != op; op = op->next)
653 if (op->r_id == r_id)
655 for (it = handle->ticket_it_head; NULL != it; it = it->next)
656 if (it->r_id == r_id)
658 if ((NULL == op) && (NULL == it))
660 msg_len = ntohs (msg->header.size);
662 GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op);
663 if (msg_len == sizeof (struct TicketResultMessage)) {
664 if (NULL != op->tr_cb)
665 op->tr_cb (op->cls, NULL);
667 ticket = (struct GNUNET_RECLAIM_Ticket *)&msg[1];
668 if (NULL != op->tr_cb)
669 op->tr_cb (op->cls, ticket);
673 } else if (NULL != it) {
674 if (msg_len == sizeof (struct TicketResultMessage)) {
675 if (NULL != it->tr_cb)
676 GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head,
677 handle->ticket_it_tail, it);
678 it->finish_cb (it->finish_cb_cls);
681 ticket = (struct GNUNET_RECLAIM_Ticket *)&msg[1];
682 if (NULL != it->tr_cb)
683 it->tr_cb (it->cls, ticket);
692 * Handle an incoming message of type
693 * #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT
696 * @param msg the message we received
699 handle_revoke_ticket_result (void *cls,
700 const struct RevokeTicketResultMessage *msg)
702 struct GNUNET_RECLAIM_Handle *h = cls;
703 struct GNUNET_RECLAIM_Operation *op;
704 uint32_t r_id = ntohl (msg->id);
707 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing revocation result.\n");
710 for (op = h->op_head; NULL != op; op = op->next)
711 if (op->r_id == r_id)
715 success = ntohl (msg->success);
717 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, h),
740 GNUNET_MQ_hd_var_size (attribute_result,
741 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT,
742 struct AttributeResultMessage, h),
743 GNUNET_MQ_hd_var_size (ticket_result,
744 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT,
745 struct TicketResultMessage, h),
746 GNUNET_MQ_hd_var_size (consume_ticket_result,
747 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT,
748 struct ConsumeTicketResultMessage, h),
749 GNUNET_MQ_hd_fixed_size (revoke_ticket_result,
750 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT,
751 struct RevokeTicketResultMessage, h),
752 GNUNET_MQ_handler_end ()};
753 struct GNUNET_RECLAIM_Operation *op;
755 GNUNET_assert (NULL == h->mq);
756 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to reclaim service.\n");
759 GNUNET_CLIENT_connect (h->cfg, "reclaim", handlers, &mq_error_handler, h);
762 for (op = h->op_head; NULL != op; op = op->next)
763 GNUNET_MQ_send_copy (h->mq, op->env);
768 * Connect to the reclaim service.
770 * @param cfg the configuration to use
771 * @return handle to use
773 struct GNUNET_RECLAIM_Handle *
774 GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
776 struct GNUNET_RECLAIM_Handle *h;
778 h = GNUNET_new (struct GNUNET_RECLAIM_Handle);
790 * Cancel an operation. Note that the operation MAY still
791 * be executed; this merely cancels the continuation; if the request
792 * was already transmitted, the service may still choose to complete
795 * @param op operation to cancel
798 GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op)
800 struct GNUNET_RECLAIM_Handle *h = op->h;
802 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
808 * Disconnect from service
810 * @param h handle to destroy
813 GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h)
815 GNUNET_assert (NULL != h);
817 GNUNET_MQ_destroy (h->mq);
820 if (NULL != h->reconnect_task) {
821 GNUNET_SCHEDULER_cancel (h->reconnect_task);
822 h->reconnect_task = NULL;
824 GNUNET_assert (NULL == h->op_head);
829 * Store an attribute. If the attribute is already present,
830 * it is replaced with the new attribute.
832 * @param h handle to the re:claimID service
833 * @param pkey private key of the identity
834 * @param attr the attribute value
835 * @param exp_interval the relative expiration interval for the attribute
836 * @param cont continuation to call when done
837 * @param cont_cls closure for @a cont
838 * @return handle to abort the request
840 struct GNUNET_RECLAIM_Operation *
841 GNUNET_RECLAIM_attribute_store (
842 struct GNUNET_RECLAIM_Handle *h,
843 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
844 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
845 const struct GNUNET_TIME_Relative *exp_interval,
846 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls)
848 struct GNUNET_RECLAIM_Operation *op;
849 struct AttributeStoreMessage *sam;
852 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
856 op->r_id = h->r_id_gen++;
857 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
858 attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr);
859 op->env = GNUNET_MQ_msg_extra (sam, attr_len,
860 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE);
861 sam->identity = *pkey;
862 sam->id = htonl (op->r_id);
863 sam->exp = GNUNET_htonll (exp_interval->rel_value_us);
865 GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *)&sam[1]);
867 sam->attr_len = htons (attr_len);
869 GNUNET_MQ_send_copy (h->mq, op->env);
875 * Delete an attribute. Tickets used to share this attribute are updated
878 * @param h handle to the re:claimID service
879 * @param pkey Private key of the identity to add an attribute to
880 * @param attr The attribute
881 * @param cont Continuation to call when done
882 * @param cont_cls Closure for @a cont
883 * @return handle Used to to abort the request
885 struct GNUNET_RECLAIM_Operation *
886 GNUNET_RECLAIM_attribute_delete (
887 struct GNUNET_RECLAIM_Handle *h,
888 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
889 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
890 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls)
892 struct GNUNET_RECLAIM_Operation *op;
893 struct AttributeDeleteMessage *dam;
896 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
900 op->r_id = h->r_id_gen++;
901 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
902 attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr);
903 op->env = GNUNET_MQ_msg_extra (dam, attr_len,
904 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE);
905 dam->identity = *pkey;
906 dam->id = htonl (op->r_id);
907 GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *)&dam[1]);
909 dam->attr_len = htons (attr_len);
911 GNUNET_MQ_send_copy (h->mq, op->env);
917 * List all attributes for a local identity.
918 * This MUST lock the `struct GNUNET_RECLAIM_Handle`
919 * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and
920 * #GNUNET_RECLAIM_get_attributes_stop. @a proc will be called once
921 * immediately, and then again after
922 * #GNUNET_RECLAIM_get_attributes_next() is invoked.
924 * On error (disconnect), @a error_cb will be invoked.
925 * On normal completion, @a finish_cb proc will be
928 * @param h Handle to the re:claimID service
929 * @param identity Identity to iterate over
930 * @param error_cb Function to call on error (i.e. disconnect),
931 * the handle is afterwards invalid
932 * @param error_cb_cls Closure for @a error_cb
933 * @param proc Function to call on each attribute
934 * @param proc_cls Closure for @a proc
935 * @param finish_cb Function to call on completion
936 * the handle is afterwards invalid
937 * @param finish_cb_cls Closure for @a finish_cb
938 * @return an iterator Handle to use for iteration
940 struct GNUNET_RECLAIM_AttributeIterator *
941 GNUNET_RECLAIM_get_attributes_start (
942 struct GNUNET_RECLAIM_Handle *h,
943 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
944 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
945 GNUNET_RECLAIM_AttributeResult proc, void *proc_cls,
946 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
948 struct GNUNET_RECLAIM_AttributeIterator *it;
949 struct GNUNET_MQ_Envelope *env;
950 struct AttributeIterationStartMessage *msg;
954 it = GNUNET_new (struct GNUNET_RECLAIM_AttributeIterator);
956 it->error_cb = error_cb;
957 it->error_cb_cls = error_cb_cls;
958 it->finish_cb = finish_cb;
959 it->finish_cb_cls = finish_cb_cls;
961 it->proc_cls = proc_cls;
963 it->identity = *identity;
964 GNUNET_CONTAINER_DLL_insert_tail (h->it_head, h->it_tail, it);
965 env = GNUNET_MQ_msg (msg,
966 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START);
967 msg->id = htonl (rid);
968 msg->identity = *identity;
972 GNUNET_MQ_send (h->mq, env);
978 * Calls the record processor specified in #GNUNET_RECLAIM_get_attributes_start
979 * for the next record.
981 * @param it the iterator
984 GNUNET_RECLAIM_get_attributes_next (struct GNUNET_RECLAIM_AttributeIterator *it)
986 struct GNUNET_RECLAIM_Handle *h = it->h;
987 struct AttributeIterationNextMessage *msg;
988 struct GNUNET_MQ_Envelope *env;
991 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT);
992 msg->id = htonl (it->r_id);
993 GNUNET_MQ_send (h->mq, env);
998 * Stops iteration and releases the handle for further calls. Must
999 * be called on any iteration that has not yet completed prior to calling
1000 * #GNUNET_RECLAIM_disconnect.
1002 * @param it the iterator
1005 GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it)
1007 struct GNUNET_RECLAIM_Handle *h = it->h;
1008 struct GNUNET_MQ_Envelope *env;
1009 struct AttributeIterationStopMessage *msg;
1011 if (NULL != h->mq) {
1012 env = GNUNET_MQ_msg (msg,
1013 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP);
1014 msg->id = htonl (it->r_id);
1015 GNUNET_MQ_send (h->mq, env);
1022 * Issues a ticket to another relying party. The identity may use
1023 * @GNUNET_RECLAIM_ticket_consume to consume the ticket
1024 * and retrieve the attributes specified in the attribute list.
1026 * @param h the reclaim to use
1027 * @param iss the issuing identity (= the user)
1028 * @param rp the subject of the ticket (= the relying party)
1029 * @param attrs the attributes that the relying party is given access to
1030 * @param cb the callback
1031 * @param cb_cls the callback closure
1032 * @return handle to abort the operation
1034 struct GNUNET_RECLAIM_Operation *
1035 GNUNET_RECLAIM_ticket_issue (
1036 struct GNUNET_RECLAIM_Handle *h,
1037 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
1038 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
1039 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
1040 GNUNET_RECLAIM_TicketCallback cb, void *cb_cls)
1042 struct GNUNET_RECLAIM_Operation *op;
1043 struct IssueTicketMessage *tim;
1046 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1050 op->r_id = h->r_id_gen++;
1051 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1052 attr_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs);
1053 op->env = GNUNET_MQ_msg_extra (tim, attr_len,
1054 GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET);
1055 tim->identity = *iss;
1057 tim->id = htonl (op->r_id);
1059 GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, (char *)&tim[1]);
1061 tim->attr_len = htons (attr_len);
1063 GNUNET_MQ_send_copy (h->mq, op->env);
1069 * Consumes an issued ticket. The ticket is persisted
1070 * and used to retrieve identity information from the issuer
1072 * @param h the reclaim to use
1073 * @param identity the identity that is the subject of the issued ticket (the
1075 * @param ticket the issued ticket to consume
1076 * @param cb the callback to call
1077 * @param cb_cls the callback closure
1078 * @return handle to abort the operation
1080 struct GNUNET_RECLAIM_Operation *
1081 GNUNET_RECLAIM_ticket_consume (
1082 struct GNUNET_RECLAIM_Handle *h,
1083 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1084 const struct GNUNET_RECLAIM_Ticket *ticket,
1085 GNUNET_RECLAIM_AttributeResult cb, void *cb_cls)
1087 struct GNUNET_RECLAIM_Operation *op;
1088 struct ConsumeTicketMessage *ctm;
1090 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1094 op->r_id = h->r_id_gen++;
1095 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1097 GNUNET_MQ_msg_extra (ctm, sizeof (const struct GNUNET_RECLAIM_Ticket),
1098 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET);
1099 ctm->identity = *identity;
1100 ctm->id = htonl (op->r_id);
1102 GNUNET_memcpy ((char *)&ctm[1], ticket,
1103 sizeof (const struct GNUNET_RECLAIM_Ticket));
1106 GNUNET_MQ_send_copy (h->mq, op->env);
1112 * Lists all tickets that have been issued to remote
1113 * identites (relying parties)
1115 * @param h the reclaim to use
1116 * @param identity the issuing identity
1117 * @param error_cb function to call on error (i.e. disconnect),
1118 * the handle is afterwards invalid
1119 * @param error_cb_cls closure for @a error_cb
1120 * @param proc function to call on each ticket; it
1121 * will be called repeatedly with a value (if available)
1122 * @param proc_cls closure for @a proc
1123 * @param finish_cb function to call on completion
1124 * the handle is afterwards invalid
1125 * @param finish_cb_cls closure for @a finish_cb
1126 * @return an iterator handle to use for iteration
1128 struct GNUNET_RECLAIM_TicketIterator *
1129 GNUNET_RECLAIM_ticket_iteration_start (
1130 struct GNUNET_RECLAIM_Handle *h,
1131 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1132 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
1133 GNUNET_RECLAIM_TicketCallback proc, void *proc_cls,
1134 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
1136 struct GNUNET_RECLAIM_TicketIterator *it;
1137 struct GNUNET_MQ_Envelope *env;
1138 struct TicketIterationStartMessage *msg;
1141 rid = h->r_id_gen++;
1142 it = GNUNET_new (struct GNUNET_RECLAIM_TicketIterator);
1144 it->error_cb = error_cb;
1145 it->error_cb_cls = error_cb_cls;
1146 it->finish_cb = finish_cb;
1147 it->finish_cb_cls = finish_cb_cls;
1151 GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head, h->ticket_it_tail, it);
1152 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START);
1153 msg->id = htonl (rid);
1154 msg->identity = *identity;
1158 GNUNET_MQ_send (h->mq, env);
1164 * Calls the ticket processor specified in
1165 * #GNUNET_RECLAIM_ticket_iteration_start for the next record.
1167 * @param it the iterator
1170 GNUNET_RECLAIM_ticket_iteration_next (struct GNUNET_RECLAIM_TicketIterator *it)
1172 struct GNUNET_RECLAIM_Handle *h = it->h;
1173 struct TicketIterationNextMessage *msg;
1174 struct GNUNET_MQ_Envelope *env;
1176 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT);
1177 msg->id = htonl (it->r_id);
1178 GNUNET_MQ_send (h->mq, env);
1183 * Stops iteration and releases the handle for further calls. Must
1184 * be called on any iteration that has not yet completed prior to calling
1185 * #GNUNET_RECLAIM_disconnect.
1187 * @param it the iterator
1190 GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it)
1192 struct GNUNET_RECLAIM_Handle *h = it->h;
1193 struct GNUNET_MQ_Envelope *env;
1194 struct TicketIterationStopMessage *msg;
1196 if (NULL != h->mq) {
1198 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP);
1199 msg->id = htonl (it->r_id);
1200 GNUNET_MQ_send (h->mq, env);
1207 * Revoked an issued ticket. The relying party will be unable to retrieve
1208 * attributes. Other issued tickets remain unaffected.
1209 * This includes tickets issued to other relying parties as well as to
1210 * other tickets issued to the audience specified in this ticket.
1212 * @param h the identity provider to use
1213 * @param identity the issuing identity
1214 * @param ticket the ticket to revoke
1215 * @param cb the callback
1216 * @param cb_cls the callback closure
1217 * @return handle to abort the operation
1219 struct GNUNET_RECLAIM_Operation *
1220 GNUNET_RECLAIM_ticket_revoke (
1221 struct GNUNET_RECLAIM_Handle *h,
1222 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1223 const struct GNUNET_RECLAIM_Ticket *ticket,
1224 GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls)
1226 struct GNUNET_RECLAIM_Operation *op;
1227 struct RevokeTicketMessage *msg;
1230 rid = h->r_id_gen++;
1231 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1236 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1237 op->env = GNUNET_MQ_msg_extra (msg, sizeof (struct GNUNET_RECLAIM_Ticket),
1238 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET);
1239 msg->id = htonl (rid);
1240 msg->identity = *identity;
1241 GNUNET_memcpy (&msg[1], ticket, sizeof (struct GNUNET_RECLAIM_Ticket));
1242 if (NULL != h->mq) {
1243 GNUNET_MQ_send (h->mq, op->env);
1250 /* end of reclaim_api.c */