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 = GNUNET_SCHEDULER_add_delayed (
354 handle->reconnect_backoff, &reconnect_task, handle);
361 * @param it entry to free
364 free_it (struct GNUNET_RECLAIM_AttributeIterator *it)
366 struct GNUNET_RECLAIM_Handle *h = it->h;
368 GNUNET_CONTAINER_DLL_remove (h->it_head, h->it_tail, it);
370 GNUNET_MQ_discard (it->env);
377 * @param op the operation to free
380 free_op (struct GNUNET_RECLAIM_Operation *op)
385 GNUNET_MQ_discard (op->env);
391 * Generic error handler, called with the appropriate error code and
392 * the same closure specified at the creation of the message queue.
393 * Not every message queue implementation supports an error handler.
395 * @param cls closure with the `struct GNUNET_GNS_Handle *`
396 * @param error error code
399 mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
401 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, "Received SUCCESS_RESPONSE with result %d\n",
432 /* TODO: add actual error message to response... */
433 if (GNUNET_SYSERR == res)
434 emsg = _ ("failed to store record\n");
437 if (NULL != op->as_cb)
438 op->as_cb (op->cls, res, emsg);
439 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
445 * Handle an incoming message of type
446 * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT
449 * @param msg the message we received
450 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
453 check_consume_ticket_result (void *cls,
454 const struct ConsumeTicketResultMessage *msg)
459 msg_len = ntohs (msg->header.size);
460 attrs_len = ntohs (msg->attrs_len);
461 if (msg_len != sizeof (struct ConsumeTicketResultMessage) + attrs_len) {
463 return GNUNET_SYSERR;
470 * Handle an incoming message of type
471 * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT
474 * @param msg the message we received
477 handle_consume_ticket_result (void *cls,
478 const struct ConsumeTicketResultMessage *msg)
480 struct GNUNET_RECLAIM_Handle *h = cls;
481 struct GNUNET_RECLAIM_Operation *op;
483 uint32_t r_id = ntohl (msg->id);
485 attrs_len = ntohs (msg->attrs_len);
486 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n");
489 for (op = h->op_head; NULL != op; op = op->next)
490 if (op->r_id == r_id)
496 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
497 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
499 GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *)&msg[1], attrs_len);
500 if (NULL != op->ar_cb) {
502 op->ar_cb (op->cls, &msg->identity, NULL);
504 for (le = attrs->list_head; NULL != le; le = le->next)
505 op->ar_cb (op->cls, &msg->identity, le->claim);
506 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs);
508 op->ar_cb (op->cls, NULL, NULL);
510 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
519 * Handle an incoming message of type
520 * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT
523 * @param msg the message we received
524 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
527 check_attribute_result (void *cls, const struct AttributeResultMessage *msg)
532 msg_len = ntohs (msg->header.size);
533 attr_len = ntohs (msg->attr_len);
534 if (msg_len != sizeof (struct AttributeResultMessage) + attr_len) {
536 return GNUNET_SYSERR;
543 * Handle an incoming message of type
544 * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT
547 * @param msg the message we received
550 handle_attribute_result (void *cls, const struct AttributeResultMessage *msg)
552 static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy;
553 struct GNUNET_RECLAIM_Handle *h = cls;
554 struct GNUNET_RECLAIM_AttributeIterator *it;
555 struct GNUNET_RECLAIM_Operation *op;
557 uint32_t r_id = ntohl (msg->id);
559 attr_len = ntohs (msg->attr_len);
560 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n");
563 for (it = h->it_head; NULL != it; it = it->next)
564 if (it->r_id == r_id)
566 for (op = h->op_head; NULL != op; op = op->next)
567 if (op->r_id == r_id)
569 if ((NULL == it) && (NULL == op))
573 (memcmp (&msg->identity, &identity_dummy, sizeof (identity_dummy))))) {
574 if ((NULL == it) && (NULL == op)) {
580 if (NULL != it->finish_cb)
581 it->finish_cb (it->finish_cb_cls);
585 if (NULL != op->ar_cb)
586 op->ar_cb (op->cls, NULL, NULL);
587 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
594 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr;
595 attr = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *)&msg[1], attr_len);
597 if (NULL != it->proc)
598 it->proc (it->proc_cls, &msg->identity, attr);
599 } else if (NULL != op) {
600 if (NULL != op->ar_cb)
601 op->ar_cb (op->cls, &msg->identity, attr);
611 * Handle an incoming message of type
612 * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT
615 * @param msg the message we received
616 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
619 check_ticket_result (void *cls, const struct TicketResultMessage *msg)
623 msg_len = ntohs (msg->header.size);
624 if (msg_len < sizeof (struct TicketResultMessage)) {
626 return GNUNET_SYSERR;
633 * Handle an incoming message of type
634 * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT
637 * @param msg the message we received
640 handle_ticket_result (void *cls, const struct TicketResultMessage *msg)
642 struct GNUNET_RECLAIM_Handle *handle = cls;
643 struct GNUNET_RECLAIM_Operation *op;
644 struct GNUNET_RECLAIM_TicketIterator *it;
645 const struct GNUNET_RECLAIM_Ticket *ticket;
646 uint32_t r_id = ntohl (msg->id);
649 for (op = handle->op_head; NULL != op; op = op->next)
650 if (op->r_id == r_id)
652 for (it = handle->ticket_it_head; NULL != it; it = it->next)
653 if (it->r_id == r_id)
655 if ((NULL == op) && (NULL == it))
657 msg_len = ntohs (msg->header.size);
659 GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op);
660 if (msg_len == sizeof (struct TicketResultMessage)) {
661 if (NULL != op->tr_cb)
662 op->tr_cb (op->cls, NULL);
664 ticket = (struct GNUNET_RECLAIM_Ticket *)&msg[1];
665 if (NULL != op->tr_cb)
666 op->tr_cb (op->cls, ticket);
670 } else if (NULL != it) {
671 if (msg_len == sizeof (struct TicketResultMessage)) {
672 if (NULL != it->tr_cb)
673 GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head,
674 handle->ticket_it_tail, it);
675 it->finish_cb (it->finish_cb_cls);
678 ticket = (struct GNUNET_RECLAIM_Ticket *)&msg[1];
679 if (NULL != it->tr_cb)
680 it->tr_cb (it->cls, ticket);
689 * Handle an incoming message of type
690 * #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT
693 * @param msg the message we received
696 handle_revoke_ticket_result (void *cls,
697 const struct RevokeTicketResultMessage *msg)
699 struct GNUNET_RECLAIM_Handle *h = cls;
700 struct GNUNET_RECLAIM_Operation *op;
701 uint32_t r_id = ntohl (msg->id);
704 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing revocation result.\n");
707 for (op = h->op_head; NULL != op; op = op->next)
708 if (op->r_id == r_id)
712 success = ntohl (msg->success);
714 if (NULL != op->rvk_cb) {
715 op->rvk_cb (op->cls, success, NULL);
717 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
726 * Try again to connect to the service.
728 * @param h handle to the reclaim service.
731 reconnect (struct GNUNET_RECLAIM_Handle *h)
733 struct GNUNET_MQ_MessageHandler handlers[] = {
734 GNUNET_MQ_hd_fixed_size (success_response,
735 GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE,
736 struct SuccessResultMessage, h),
737 GNUNET_MQ_hd_var_size (attribute_result,
738 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT,
739 struct AttributeResultMessage, h),
740 GNUNET_MQ_hd_var_size (ticket_result,
741 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT,
742 struct TicketResultMessage, h),
743 GNUNET_MQ_hd_var_size (consume_ticket_result,
744 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT,
745 struct ConsumeTicketResultMessage, h),
746 GNUNET_MQ_hd_fixed_size (revoke_ticket_result,
747 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT,
748 struct RevokeTicketResultMessage, h),
749 GNUNET_MQ_handler_end ()};
750 struct GNUNET_RECLAIM_Operation *op;
752 GNUNET_assert (NULL == h->mq);
753 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to reclaim service.\n");
756 GNUNET_CLIENT_connect (h->cfg, "reclaim", handlers, &mq_error_handler, h);
759 for (op = h->op_head; NULL != op; op = op->next)
760 GNUNET_MQ_send_copy (h->mq, op->env);
765 * Connect to the reclaim service.
767 * @param cfg the configuration to use
768 * @return handle to use
770 struct GNUNET_RECLAIM_Handle *
771 GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
773 struct GNUNET_RECLAIM_Handle *h;
775 h = GNUNET_new (struct GNUNET_RECLAIM_Handle);
787 * Cancel an operation. Note that the operation MAY still
788 * be executed; this merely cancels the continuation; if the request
789 * was already transmitted, the service may still choose to complete
792 * @param op operation to cancel
795 GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op)
797 struct GNUNET_RECLAIM_Handle *h = op->h;
799 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
805 * Disconnect from service
807 * @param h handle to destroy
810 GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h)
812 GNUNET_assert (NULL != h);
814 GNUNET_MQ_destroy (h->mq);
817 if (NULL != h->reconnect_task) {
818 GNUNET_SCHEDULER_cancel (h->reconnect_task);
819 h->reconnect_task = NULL;
821 GNUNET_assert (NULL == h->op_head);
826 * Store an attribute. If the attribute is already present,
827 * it is replaced with the new attribute.
829 * @param h handle to the re:claimID service
830 * @param pkey private key of the identity
831 * @param attr the attribute value
832 * @param exp_interval the relative expiration interval for the attribute
833 * @param cont continuation to call when done
834 * @param cont_cls closure for @a cont
835 * @return handle to abort the request
837 struct GNUNET_RECLAIM_Operation *
838 GNUNET_RECLAIM_attribute_store (
839 struct GNUNET_RECLAIM_Handle *h,
840 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
841 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
842 const struct GNUNET_TIME_Relative *exp_interval,
843 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls)
845 struct GNUNET_RECLAIM_Operation *op;
846 struct AttributeStoreMessage *sam;
849 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
853 op->r_id = h->r_id_gen++;
854 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
855 attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr);
856 op->env = GNUNET_MQ_msg_extra (sam, attr_len,
857 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE);
858 sam->identity = *pkey;
859 sam->id = htonl (op->r_id);
860 sam->exp = GNUNET_htonll (exp_interval->rel_value_us);
862 GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *)&sam[1]);
864 sam->attr_len = htons (attr_len);
866 GNUNET_MQ_send_copy (h->mq, op->env);
872 * Delete an attribute. Tickets used to share this attribute are updated
875 * @param h handle to the re:claimID service
876 * @param pkey Private key of the identity to add an attribute to
877 * @param attr The attribute
878 * @param cont Continuation to call when done
879 * @param cont_cls Closure for @a cont
880 * @return handle Used to to abort the request
882 struct GNUNET_RECLAIM_Operation *
883 GNUNET_RECLAIM_attribute_delete (
884 struct GNUNET_RECLAIM_Handle *h,
885 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
886 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
887 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls)
889 struct GNUNET_RECLAIM_Operation *op;
890 struct AttributeDeleteMessage *dam;
893 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
897 op->r_id = h->r_id_gen++;
898 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
899 attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr);
900 op->env = GNUNET_MQ_msg_extra (dam, attr_len,
901 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE);
902 dam->identity = *pkey;
903 dam->id = htonl (op->r_id);
904 GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *)&dam[1]);
906 dam->attr_len = htons (attr_len);
908 GNUNET_MQ_send_copy (h->mq, op->env);
914 * List all attributes for a local identity.
915 * This MUST lock the `struct GNUNET_RECLAIM_Handle`
916 * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and
917 * #GNUNET_RECLAIM_get_attributes_stop. @a proc will be called once
918 * immediately, and then again after
919 * #GNUNET_RECLAIM_get_attributes_next() is invoked.
921 * On error (disconnect), @a error_cb will be invoked.
922 * On normal completion, @a finish_cb proc will be
925 * @param h Handle to the re:claimID service
926 * @param identity Identity to iterate over
927 * @param error_cb Function to call on error (i.e. disconnect),
928 * the handle is afterwards invalid
929 * @param error_cb_cls Closure for @a error_cb
930 * @param proc Function to call on each attribute
931 * @param proc_cls Closure for @a proc
932 * @param finish_cb Function to call on completion
933 * the handle is afterwards invalid
934 * @param finish_cb_cls Closure for @a finish_cb
935 * @return an iterator Handle to use for iteration
937 struct GNUNET_RECLAIM_AttributeIterator *
938 GNUNET_RECLAIM_get_attributes_start (
939 struct GNUNET_RECLAIM_Handle *h,
940 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
941 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
942 GNUNET_RECLAIM_AttributeResult proc, void *proc_cls,
943 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
945 struct GNUNET_RECLAIM_AttributeIterator *it;
946 struct GNUNET_MQ_Envelope *env;
947 struct AttributeIterationStartMessage *msg;
951 it = GNUNET_new (struct GNUNET_RECLAIM_AttributeIterator);
953 it->error_cb = error_cb;
954 it->error_cb_cls = error_cb_cls;
955 it->finish_cb = finish_cb;
956 it->finish_cb_cls = finish_cb_cls;
958 it->proc_cls = proc_cls;
960 it->identity = *identity;
961 GNUNET_CONTAINER_DLL_insert_tail (h->it_head, h->it_tail, it);
962 env = GNUNET_MQ_msg (msg,
963 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START);
964 msg->id = htonl (rid);
965 msg->identity = *identity;
969 GNUNET_MQ_send (h->mq, env);
975 * Calls the record processor specified in #GNUNET_RECLAIM_get_attributes_start
976 * for the next record.
978 * @param it the iterator
981 GNUNET_RECLAIM_get_attributes_next (struct GNUNET_RECLAIM_AttributeIterator *it)
983 struct GNUNET_RECLAIM_Handle *h = it->h;
984 struct AttributeIterationNextMessage *msg;
985 struct GNUNET_MQ_Envelope *env;
988 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT);
989 msg->id = htonl (it->r_id);
990 GNUNET_MQ_send (h->mq, env);
995 * Stops iteration and releases the handle for further calls. Must
996 * be called on any iteration that has not yet completed prior to calling
997 * #GNUNET_RECLAIM_disconnect.
999 * @param it the iterator
1002 GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it)
1004 struct GNUNET_RECLAIM_Handle *h = it->h;
1005 struct GNUNET_MQ_Envelope *env;
1006 struct AttributeIterationStopMessage *msg;
1008 if (NULL != h->mq) {
1009 env = GNUNET_MQ_msg (msg,
1010 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP);
1011 msg->id = htonl (it->r_id);
1012 GNUNET_MQ_send (h->mq, env);
1019 * Issues a ticket to another relying party. The identity may use
1020 * @GNUNET_RECLAIM_ticket_consume to consume the ticket
1021 * and retrieve the attributes specified in the attribute list.
1023 * @param h the reclaim to use
1024 * @param iss the issuing identity (= the user)
1025 * @param rp the subject of the ticket (= the relying party)
1026 * @param attrs the attributes that the relying party is given access to
1027 * @param cb the callback
1028 * @param cb_cls the callback closure
1029 * @return handle to abort the operation
1031 struct GNUNET_RECLAIM_Operation *
1032 GNUNET_RECLAIM_ticket_issue (
1033 struct GNUNET_RECLAIM_Handle *h,
1034 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
1035 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
1036 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
1037 GNUNET_RECLAIM_TicketCallback cb, void *cb_cls)
1039 struct GNUNET_RECLAIM_Operation *op;
1040 struct IssueTicketMessage *tim;
1043 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1047 op->r_id = h->r_id_gen++;
1048 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1049 attr_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs);
1050 op->env = GNUNET_MQ_msg_extra (tim, attr_len,
1051 GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET);
1052 tim->identity = *iss;
1054 tim->id = htonl (op->r_id);
1056 GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, (char *)&tim[1]);
1058 tim->attr_len = htons (attr_len);
1060 GNUNET_MQ_send_copy (h->mq, op->env);
1066 * Consumes an issued ticket. The ticket is persisted
1067 * and used to retrieve identity information from the issuer
1069 * @param h the reclaim to use
1070 * @param identity the identity that is the subject of the issued ticket (the
1072 * @param ticket the issued ticket to consume
1073 * @param cb the callback to call
1074 * @param cb_cls the callback closure
1075 * @return handle to abort the operation
1077 struct GNUNET_RECLAIM_Operation *
1078 GNUNET_RECLAIM_ticket_consume (
1079 struct GNUNET_RECLAIM_Handle *h,
1080 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1081 const struct GNUNET_RECLAIM_Ticket *ticket,
1082 GNUNET_RECLAIM_AttributeResult cb, void *cb_cls)
1084 struct GNUNET_RECLAIM_Operation *op;
1085 struct ConsumeTicketMessage *ctm;
1087 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1091 op->r_id = h->r_id_gen++;
1092 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1094 GNUNET_MQ_msg_extra (ctm, sizeof (const struct GNUNET_RECLAIM_Ticket),
1095 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET);
1096 ctm->identity = *identity;
1097 ctm->id = htonl (op->r_id);
1099 GNUNET_memcpy ((char *)&ctm[1], ticket,
1100 sizeof (const struct GNUNET_RECLAIM_Ticket));
1103 GNUNET_MQ_send_copy (h->mq, op->env);
1109 * Lists all tickets that have been issued to remote
1110 * identites (relying parties)
1112 * @param h the reclaim to use
1113 * @param identity the issuing identity
1114 * @param error_cb function to call on error (i.e. disconnect),
1115 * the handle is afterwards invalid
1116 * @param error_cb_cls closure for @a error_cb
1117 * @param proc function to call on each ticket; it
1118 * will be called repeatedly with a value (if available)
1119 * @param proc_cls closure for @a proc
1120 * @param finish_cb function to call on completion
1121 * the handle is afterwards invalid
1122 * @param finish_cb_cls closure for @a finish_cb
1123 * @return an iterator handle to use for iteration
1125 struct GNUNET_RECLAIM_TicketIterator *
1126 GNUNET_RECLAIM_ticket_iteration_start (
1127 struct GNUNET_RECLAIM_Handle *h,
1128 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1129 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
1130 GNUNET_RECLAIM_TicketCallback proc, void *proc_cls,
1131 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
1133 struct GNUNET_RECLAIM_TicketIterator *it;
1134 struct GNUNET_MQ_Envelope *env;
1135 struct TicketIterationStartMessage *msg;
1138 rid = h->r_id_gen++;
1139 it = GNUNET_new (struct GNUNET_RECLAIM_TicketIterator);
1141 it->error_cb = error_cb;
1142 it->error_cb_cls = error_cb_cls;
1143 it->finish_cb = finish_cb;
1144 it->finish_cb_cls = finish_cb_cls;
1148 GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head, h->ticket_it_tail, it);
1149 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START);
1150 msg->id = htonl (rid);
1151 msg->identity = *identity;
1155 GNUNET_MQ_send (h->mq, env);
1161 * Calls the ticket processor specified in
1162 * #GNUNET_RECLAIM_ticket_iteration_start for the next record.
1164 * @param it the iterator
1167 GNUNET_RECLAIM_ticket_iteration_next (struct GNUNET_RECLAIM_TicketIterator *it)
1169 struct GNUNET_RECLAIM_Handle *h = it->h;
1170 struct TicketIterationNextMessage *msg;
1171 struct GNUNET_MQ_Envelope *env;
1173 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT);
1174 msg->id = htonl (it->r_id);
1175 GNUNET_MQ_send (h->mq, env);
1180 * Stops iteration and releases the handle for further calls. Must
1181 * be called on any iteration that has not yet completed prior to calling
1182 * #GNUNET_RECLAIM_disconnect.
1184 * @param it the iterator
1187 GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it)
1189 struct GNUNET_RECLAIM_Handle *h = it->h;
1190 struct GNUNET_MQ_Envelope *env;
1191 struct TicketIterationStopMessage *msg;
1193 if (NULL != h->mq) {
1195 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP);
1196 msg->id = htonl (it->r_id);
1197 GNUNET_MQ_send (h->mq, env);
1204 * Revoked an issued ticket. The relying party will be unable to retrieve
1205 * attributes. Other issued tickets remain unaffected.
1206 * This includes tickets issued to other relying parties as well as to
1207 * other tickets issued to the audience specified in this ticket.
1209 * @param h the identity provider to use
1210 * @param identity the issuing identity
1211 * @param ticket the ticket to revoke
1212 * @param cb the callback
1213 * @param cb_cls the callback closure
1214 * @return handle to abort the operation
1216 struct GNUNET_RECLAIM_Operation *
1217 GNUNET_RECLAIM_ticket_revoke (
1218 struct GNUNET_RECLAIM_Handle *h,
1219 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1220 const struct GNUNET_RECLAIM_Ticket *ticket,
1221 GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls)
1223 struct GNUNET_RECLAIM_Operation *op;
1224 struct RevokeTicketMessage *msg;
1227 rid = h->r_id_gen++;
1228 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1233 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1234 op->env = GNUNET_MQ_msg_extra (msg, sizeof (struct GNUNET_RECLAIM_Ticket),
1235 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET);
1236 msg->id = htonl (rid);
1237 msg->identity = *identity;
1238 GNUNET_memcpy (&msg[1], ticket, sizeof (struct GNUNET_RECLAIM_Ticket));
1239 if (NULL != h->mq) {
1240 GNUNET_MQ_send (h->mq, op->env);
1247 /* end of reclaim_api.c */