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);
615 * Handle an incoming message of type
616 * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT
619 * @param msg the message we received
620 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
623 check_ticket_result (void *cls, const struct TicketResultMessage *msg)
627 msg_len = ntohs (msg->header.size);
628 if (msg_len < sizeof (struct TicketResultMessage)) {
630 return GNUNET_SYSERR;
637 * Handle an incoming message of type
638 * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT
641 * @param msg the message we received
644 handle_ticket_result (void *cls, const struct TicketResultMessage *msg)
646 struct GNUNET_RECLAIM_Handle *handle = cls;
647 struct GNUNET_RECLAIM_Operation *op;
648 struct GNUNET_RECLAIM_TicketIterator *it;
649 const struct GNUNET_RECLAIM_Ticket *ticket;
650 uint32_t r_id = ntohl (msg->id);
653 for (op = handle->op_head; NULL != op; op = op->next)
654 if (op->r_id == r_id)
656 for (it = handle->ticket_it_head; NULL != it; it = it->next)
657 if (it->r_id == r_id)
659 if ((NULL == op) && (NULL == it))
661 msg_len = ntohs (msg->header.size);
663 GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op);
664 if (msg_len == sizeof (struct TicketResultMessage)) {
665 if (NULL != op->tr_cb)
666 op->tr_cb (op->cls, NULL);
668 ticket = (struct GNUNET_RECLAIM_Ticket *)&msg[1];
669 if (NULL != op->tr_cb)
670 op->tr_cb (op->cls, ticket);
674 } else if (NULL != it) {
675 if (msg_len == sizeof (struct TicketResultMessage)) {
676 if (NULL != it->tr_cb)
677 GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head,
678 handle->ticket_it_tail, it);
679 it->finish_cb (it->finish_cb_cls);
682 ticket = (struct GNUNET_RECLAIM_Ticket *)&msg[1];
683 if (NULL != it->tr_cb)
684 it->tr_cb (it->cls, ticket);
693 * Handle an incoming message of type
694 * #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT
697 * @param msg the message we received
700 handle_revoke_ticket_result (void *cls,
701 const struct RevokeTicketResultMessage *msg)
703 struct GNUNET_RECLAIM_Handle *h = cls;
704 struct GNUNET_RECLAIM_Operation *op;
705 uint32_t r_id = ntohl (msg->id);
708 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing revocation result.\n");
711 for (op = h->op_head; NULL != op; op = op->next)
712 if (op->r_id == r_id)
716 success = ntohl (msg->success);
718 if (NULL != op->rvk_cb) {
719 op->rvk_cb (op->cls, success, NULL);
721 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
730 * Try again to connect to the service.
732 * @param h handle to the reclaim service.
735 reconnect (struct GNUNET_RECLAIM_Handle *h)
737 struct GNUNET_MQ_MessageHandler handlers[] = {
738 GNUNET_MQ_hd_fixed_size (success_response,
739 GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE,
740 struct SuccessResultMessage, h),
741 GNUNET_MQ_hd_var_size (attribute_result,
742 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT,
743 struct AttributeResultMessage, h),
744 GNUNET_MQ_hd_var_size (ticket_result,
745 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT,
746 struct TicketResultMessage, h),
747 GNUNET_MQ_hd_var_size (consume_ticket_result,
748 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT,
749 struct ConsumeTicketResultMessage, h),
750 GNUNET_MQ_hd_fixed_size (revoke_ticket_result,
751 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT,
752 struct RevokeTicketResultMessage, h),
753 GNUNET_MQ_handler_end ()};
754 struct GNUNET_RECLAIM_Operation *op;
756 GNUNET_assert (NULL == h->mq);
757 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to reclaim service.\n");
760 GNUNET_CLIENT_connect (h->cfg, "reclaim", handlers, &mq_error_handler, h);
763 for (op = h->op_head; NULL != op; op = op->next)
764 GNUNET_MQ_send_copy (h->mq, op->env);
769 * Connect to the reclaim service.
771 * @param cfg the configuration to use
772 * @return handle to use
774 struct GNUNET_RECLAIM_Handle *
775 GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
777 struct GNUNET_RECLAIM_Handle *h;
779 h = GNUNET_new (struct GNUNET_RECLAIM_Handle);
791 * Cancel an operation. Note that the operation MAY still
792 * be executed; this merely cancels the continuation; if the request
793 * was already transmitted, the service may still choose to complete
796 * @param op operation to cancel
799 GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op)
801 struct GNUNET_RECLAIM_Handle *h = op->h;
803 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
809 * Disconnect from service
811 * @param h handle to destroy
814 GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h)
816 GNUNET_assert (NULL != h);
818 GNUNET_MQ_destroy (h->mq);
821 if (NULL != h->reconnect_task) {
822 GNUNET_SCHEDULER_cancel (h->reconnect_task);
823 h->reconnect_task = NULL;
825 GNUNET_assert (NULL == h->op_head);
830 * Store an attribute. If the attribute is already present,
831 * it is replaced with the new attribute.
833 * @param h handle to the re:claimID service
834 * @param pkey private key of the identity
835 * @param attr the attribute value
836 * @param exp_interval the relative expiration interval for the attribute
837 * @param cont continuation to call when done
838 * @param cont_cls closure for @a cont
839 * @return handle to abort the request
841 struct GNUNET_RECLAIM_Operation *
842 GNUNET_RECLAIM_attribute_store (
843 struct GNUNET_RECLAIM_Handle *h,
844 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
845 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
846 const struct GNUNET_TIME_Relative *exp_interval,
847 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls)
849 struct GNUNET_RECLAIM_Operation *op;
850 struct AttributeStoreMessage *sam;
853 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
857 op->r_id = h->r_id_gen++;
858 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
859 attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr);
860 op->env = GNUNET_MQ_msg_extra (sam, attr_len,
861 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE);
862 sam->identity = *pkey;
863 sam->id = htonl (op->r_id);
864 sam->exp = GNUNET_htonll (exp_interval->rel_value_us);
866 GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *)&sam[1]);
868 sam->attr_len = htons (attr_len);
870 GNUNET_MQ_send_copy (h->mq, op->env);
876 * Delete an attribute. Tickets used to share this attribute are updated
879 * @param h handle to the re:claimID service
880 * @param pkey Private key of the identity to add an attribute to
881 * @param attr The attribute
882 * @param cont Continuation to call when done
883 * @param cont_cls Closure for @a cont
884 * @return handle Used to to abort the request
886 struct GNUNET_RECLAIM_Operation *
887 GNUNET_RECLAIM_attribute_delete (
888 struct GNUNET_RECLAIM_Handle *h,
889 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
890 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
891 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls)
893 struct GNUNET_RECLAIM_Operation *op;
894 struct AttributeDeleteMessage *dam;
897 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
901 op->r_id = h->r_id_gen++;
902 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
903 attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr);
904 op->env = GNUNET_MQ_msg_extra (dam, attr_len,
905 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE);
906 dam->identity = *pkey;
907 dam->id = htonl (op->r_id);
908 GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *)&dam[1]);
910 dam->attr_len = htons (attr_len);
912 GNUNET_MQ_send_copy (h->mq, op->env);
918 * List all attributes for a local identity.
919 * This MUST lock the `struct GNUNET_RECLAIM_Handle`
920 * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and
921 * #GNUNET_RECLAIM_get_attributes_stop. @a proc will be called once
922 * immediately, and then again after
923 * #GNUNET_RECLAIM_get_attributes_next() is invoked.
925 * On error (disconnect), @a error_cb will be invoked.
926 * On normal completion, @a finish_cb proc will be
929 * @param h Handle to the re:claimID service
930 * @param identity Identity to iterate over
931 * @param error_cb Function to call on error (i.e. disconnect),
932 * the handle is afterwards invalid
933 * @param error_cb_cls Closure for @a error_cb
934 * @param proc Function to call on each attribute
935 * @param proc_cls Closure for @a proc
936 * @param finish_cb Function to call on completion
937 * the handle is afterwards invalid
938 * @param finish_cb_cls Closure for @a finish_cb
939 * @return an iterator Handle to use for iteration
941 struct GNUNET_RECLAIM_AttributeIterator *
942 GNUNET_RECLAIM_get_attributes_start (
943 struct GNUNET_RECLAIM_Handle *h,
944 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
945 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
946 GNUNET_RECLAIM_AttributeResult proc, void *proc_cls,
947 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
949 struct GNUNET_RECLAIM_AttributeIterator *it;
950 struct GNUNET_MQ_Envelope *env;
951 struct AttributeIterationStartMessage *msg;
955 it = GNUNET_new (struct GNUNET_RECLAIM_AttributeIterator);
957 it->error_cb = error_cb;
958 it->error_cb_cls = error_cb_cls;
959 it->finish_cb = finish_cb;
960 it->finish_cb_cls = finish_cb_cls;
962 it->proc_cls = proc_cls;
964 it->identity = *identity;
965 GNUNET_CONTAINER_DLL_insert_tail (h->it_head, h->it_tail, it);
966 env = GNUNET_MQ_msg (msg,
967 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START);
968 msg->id = htonl (rid);
969 msg->identity = *identity;
973 GNUNET_MQ_send (h->mq, env);
979 * Calls the record processor specified in #GNUNET_RECLAIM_get_attributes_start
980 * for the next record.
982 * @param it the iterator
985 GNUNET_RECLAIM_get_attributes_next (struct GNUNET_RECLAIM_AttributeIterator *it)
987 struct GNUNET_RECLAIM_Handle *h = it->h;
988 struct AttributeIterationNextMessage *msg;
989 struct GNUNET_MQ_Envelope *env;
992 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT);
993 msg->id = htonl (it->r_id);
994 GNUNET_MQ_send (h->mq, env);
999 * Stops iteration and releases the handle for further calls. Must
1000 * be called on any iteration that has not yet completed prior to calling
1001 * #GNUNET_RECLAIM_disconnect.
1003 * @param it the iterator
1006 GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it)
1008 struct GNUNET_RECLAIM_Handle *h = it->h;
1009 struct GNUNET_MQ_Envelope *env;
1010 struct AttributeIterationStopMessage *msg;
1012 if (NULL != h->mq) {
1013 env = GNUNET_MQ_msg (msg,
1014 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP);
1015 msg->id = htonl (it->r_id);
1016 GNUNET_MQ_send (h->mq, env);
1023 * Issues a ticket to another relying party. The identity may use
1024 * @GNUNET_RECLAIM_ticket_consume to consume the ticket
1025 * and retrieve the attributes specified in the attribute list.
1027 * @param h the reclaim to use
1028 * @param iss the issuing identity (= the user)
1029 * @param rp the subject of the ticket (= the relying party)
1030 * @param attrs the attributes that the relying party is given access to
1031 * @param cb the callback
1032 * @param cb_cls the callback closure
1033 * @return handle to abort the operation
1035 struct GNUNET_RECLAIM_Operation *
1036 GNUNET_RECLAIM_ticket_issue (
1037 struct GNUNET_RECLAIM_Handle *h,
1038 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
1039 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
1040 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
1041 GNUNET_RECLAIM_TicketCallback cb, void *cb_cls)
1043 struct GNUNET_RECLAIM_Operation *op;
1044 struct IssueTicketMessage *tim;
1047 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1051 op->r_id = h->r_id_gen++;
1052 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1053 attr_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs);
1054 op->env = GNUNET_MQ_msg_extra (tim, attr_len,
1055 GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET);
1056 tim->identity = *iss;
1058 tim->id = htonl (op->r_id);
1060 GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, (char *)&tim[1]);
1062 tim->attr_len = htons (attr_len);
1064 GNUNET_MQ_send_copy (h->mq, op->env);
1070 * Consumes an issued ticket. The ticket is persisted
1071 * and used to retrieve identity information from the issuer
1073 * @param h the reclaim to use
1074 * @param identity the identity that is the subject of the issued ticket (the
1076 * @param ticket the issued ticket to consume
1077 * @param cb the callback to call
1078 * @param cb_cls the callback closure
1079 * @return handle to abort the operation
1081 struct GNUNET_RECLAIM_Operation *
1082 GNUNET_RECLAIM_ticket_consume (
1083 struct GNUNET_RECLAIM_Handle *h,
1084 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1085 const struct GNUNET_RECLAIM_Ticket *ticket,
1086 GNUNET_RECLAIM_AttributeResult cb, void *cb_cls)
1088 struct GNUNET_RECLAIM_Operation *op;
1089 struct ConsumeTicketMessage *ctm;
1091 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1095 op->r_id = h->r_id_gen++;
1096 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1098 GNUNET_MQ_msg_extra (ctm, sizeof (const struct GNUNET_RECLAIM_Ticket),
1099 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET);
1100 ctm->identity = *identity;
1101 ctm->id = htonl (op->r_id);
1103 GNUNET_memcpy ((char *)&ctm[1], ticket,
1104 sizeof (const struct GNUNET_RECLAIM_Ticket));
1107 GNUNET_MQ_send_copy (h->mq, op->env);
1113 * Lists all tickets that have been issued to remote
1114 * identites (relying parties)
1116 * @param h the reclaim to use
1117 * @param identity the issuing identity
1118 * @param error_cb function to call on error (i.e. disconnect),
1119 * the handle is afterwards invalid
1120 * @param error_cb_cls closure for @a error_cb
1121 * @param proc function to call on each ticket; it
1122 * will be called repeatedly with a value (if available)
1123 * @param proc_cls closure for @a proc
1124 * @param finish_cb function to call on completion
1125 * the handle is afterwards invalid
1126 * @param finish_cb_cls closure for @a finish_cb
1127 * @return an iterator handle to use for iteration
1129 struct GNUNET_RECLAIM_TicketIterator *
1130 GNUNET_RECLAIM_ticket_iteration_start (
1131 struct GNUNET_RECLAIM_Handle *h,
1132 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1133 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
1134 GNUNET_RECLAIM_TicketCallback proc, void *proc_cls,
1135 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
1137 struct GNUNET_RECLAIM_TicketIterator *it;
1138 struct GNUNET_MQ_Envelope *env;
1139 struct TicketIterationStartMessage *msg;
1142 rid = h->r_id_gen++;
1143 it = GNUNET_new (struct GNUNET_RECLAIM_TicketIterator);
1145 it->error_cb = error_cb;
1146 it->error_cb_cls = error_cb_cls;
1147 it->finish_cb = finish_cb;
1148 it->finish_cb_cls = finish_cb_cls;
1152 GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head, h->ticket_it_tail, it);
1153 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START);
1154 msg->id = htonl (rid);
1155 msg->identity = *identity;
1159 GNUNET_MQ_send (h->mq, env);
1165 * Calls the ticket processor specified in
1166 * #GNUNET_RECLAIM_ticket_iteration_start for the next record.
1168 * @param it the iterator
1171 GNUNET_RECLAIM_ticket_iteration_next (struct GNUNET_RECLAIM_TicketIterator *it)
1173 struct GNUNET_RECLAIM_Handle *h = it->h;
1174 struct TicketIterationNextMessage *msg;
1175 struct GNUNET_MQ_Envelope *env;
1177 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT);
1178 msg->id = htonl (it->r_id);
1179 GNUNET_MQ_send (h->mq, env);
1184 * Stops iteration and releases the handle for further calls. Must
1185 * be called on any iteration that has not yet completed prior to calling
1186 * #GNUNET_RECLAIM_disconnect.
1188 * @param it the iterator
1191 GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it)
1193 struct GNUNET_RECLAIM_Handle *h = it->h;
1194 struct GNUNET_MQ_Envelope *env;
1195 struct TicketIterationStopMessage *msg;
1197 if (NULL != h->mq) {
1199 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP);
1200 msg->id = htonl (it->r_id);
1201 GNUNET_MQ_send (h->mq, env);
1208 * Revoked an issued ticket. The relying party will be unable to retrieve
1209 * attributes. Other issued tickets remain unaffected.
1210 * This includes tickets issued to other relying parties as well as to
1211 * other tickets issued to the audience specified in this ticket.
1213 * @param h the identity provider to use
1214 * @param identity the issuing identity
1215 * @param ticket the ticket to revoke
1216 * @param cb the callback
1217 * @param cb_cls the callback closure
1218 * @return handle to abort the operation
1220 struct GNUNET_RECLAIM_Operation *
1221 GNUNET_RECLAIM_ticket_revoke (
1222 struct GNUNET_RECLAIM_Handle *h,
1223 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1224 const struct GNUNET_RECLAIM_Ticket *ticket,
1225 GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls)
1227 struct GNUNET_RECLAIM_Operation *op;
1228 struct RevokeTicketMessage *msg;
1231 rid = h->r_id_gen++;
1232 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1237 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1238 op->env = GNUNET_MQ_msg_extra (msg, sizeof (struct GNUNET_RECLAIM_Ticket),
1239 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET);
1240 msg->id = htonl (rid);
1241 msg->identity = *identity;
1242 GNUNET_memcpy (&msg[1], ticket, sizeof (struct GNUNET_RECLAIM_Ticket));
1243 if (NULL != h->mq) {
1244 GNUNET_MQ_send (h->mq, op->env);
1251 /* end of reclaim_api.c */