2 This file is part of GNUnet.
3 (C) 2012-2014 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @brief api for the set service
23 * @author Florian Dold
26 #include "gnunet_util_lib.h"
27 #include "gnunet_protocols.h"
28 #include "gnunet_client_lib.h"
29 #include "gnunet_set_service.h"
33 #define LOG(kind,...) GNUNET_log_from (kind, "set-api",__VA_ARGS__)
36 * Opaque handle to a set.
38 struct GNUNET_SET_Handle
41 * Client connected to the set service.
43 struct GNUNET_CLIENT_Connection *client;
46 * Message queue for @e client.
48 struct GNUNET_MQ_Handle *mq;
51 * Linked list of operations on the set.
53 struct GNUNET_SET_OperationHandle *ops_head;
56 * Linked list of operations on the set.
58 struct GNUNET_SET_OperationHandle *ops_tail;
61 * Callback for the current iteration over the set,
62 * NULL if no iterator is active.
64 GNUNET_SET_ElementIterator iterator;
67 * Closure for @e iterator
72 * Should the set be destroyed once all operations are gone?
74 int destroy_requested;
77 * Has the set become invalid (e.g. service died)?
84 * Handle for a set operation request from another peer.
86 struct GNUNET_SET_Request
89 * Id of the request, used to identify the request when
90 * accepting/rejecting it.
95 * Has the request been accepted already?
96 * #GNUNET_YES/#GNUNET_NO
103 * Handle to an operation. Only known to the service after committing
104 * the handle with a set.
106 struct GNUNET_SET_OperationHandle
109 * Function to be called when we have a result,
112 GNUNET_SET_ResultIterator result_cb;
115 * Closure for @e result_cb.
120 * Local set used for the operation,
121 * NULL if no set has been provided by conclude yet.
123 struct GNUNET_SET_Handle *set;
126 * Message sent to the server on calling conclude,
127 * NULL if conclude has been called.
129 struct GNUNET_MQ_Envelope *conclude_mqm;
132 * Address of the request if in the conclude message,
133 * used to patch the request id into the message when the set is known.
135 uint32_t *request_id_addr;
138 * Handles are kept in a linked list.
140 struct GNUNET_SET_OperationHandle *prev;
143 * Handles are kept in a linked list.
145 struct GNUNET_SET_OperationHandle *next;
148 * Request ID to identify the operation within the set.
155 * Opaque handle to a listen operation.
157 struct GNUNET_SET_ListenHandle
160 * Connection to the service.
162 struct GNUNET_CLIENT_Connection *client;
165 * Message queue for the client.
167 struct GNUNET_MQ_Handle* mq;
170 * Configuration handle for the listener, stored
171 * here to be able to reconnect transparently on
172 * connection failure.
174 const struct GNUNET_CONFIGURATION_Handle *cfg;
177 * Function to call on a new incoming request,
180 GNUNET_SET_ListenCallback listen_cb;
183 * Closure for @e listen_cb.
188 * Application ID we listen for.
190 struct GNUNET_HashCode app_id;
193 * Time to wait until we try to reconnect on failure.
195 struct GNUNET_TIME_Relative reconnect_backoff;
198 * Task for reconnecting when the listener fails.
200 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
203 * Operation we listen for.
205 enum GNUNET_SET_OperationType operation;
210 * Handle element for iteration over the set. Notifies the
211 * iterator and sends an acknowledgement to the service.
214 * @param mh the message
217 handle_iter_element (void *cls,
218 const struct GNUNET_MessageHeader *mh)
220 struct GNUNET_SET_Handle *set = cls;
221 GNUNET_SET_ElementIterator iter = set->iterator;
222 struct GNUNET_SET_Element element;
223 const struct GNUNET_SET_IterResponseMessage *msg;
224 struct GNUNET_SET_IterAckMessage *ack_msg;
225 struct GNUNET_MQ_Envelope *ev;
228 msize = ntohs (mh->size);
229 if (msize < sizeof (sizeof (struct GNUNET_SET_IterResponseMessage)))
231 /* message malformed */
233 set->iterator = NULL;
234 iter (set->iterator_cls,
240 msg = (const struct GNUNET_SET_IterResponseMessage *) mh;
241 element.size = msize - sizeof (struct GNUNET_SET_IterResponseMessage);
242 element.element_type = htons (msg->element_type);
243 element.data = &msg[1];
244 iter (set->iterator_cls,
247 ev = GNUNET_MQ_msg (ack_msg,
248 GNUNET_MESSAGE_TYPE_SET_ITER_ACK);
249 ack_msg->send_more = htonl ((NULL != iter));
250 GNUNET_MQ_send (set->mq, ev);
255 * Handle message signalling conclusion of iteration over the set.
256 * Notifies the iterator that we are done.
259 * @param mh the message
262 handle_iter_done (void *cls,
263 const struct GNUNET_MessageHeader *mh)
265 struct GNUNET_SET_Handle *set = cls;
266 GNUNET_SET_ElementIterator iter = set->iterator;
270 set->iterator = NULL;
271 iter (set->iterator_cls,
277 * Handle result message for a set operation.
280 * @param mh the message
283 handle_result (void *cls,
284 const struct GNUNET_MessageHeader *mh)
286 struct GNUNET_SET_Handle *set = cls;
287 const struct GNUNET_SET_ResultMessage *msg;
288 struct GNUNET_SET_OperationHandle *oh;
289 struct GNUNET_SET_Element e;
290 enum GNUNET_SET_Status result_status;
292 msg = (const struct GNUNET_SET_ResultMessage *) mh;
293 GNUNET_assert (NULL != set->mq);
294 result_status = ntohs (msg->result_status);
295 oh = GNUNET_MQ_assoc_get (set->mq,
296 ntohl (msg->request_id));
299 /* 'oh' can be NULL if we canceled the operation, but the service
300 did not get the cancel message yet. */
301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
302 "Ignoring result from canceled operation\n");
305 if (GNUNET_SET_STATUS_OK != result_status)
307 /* status is not STATUS_OK => there's no attached element,
308 * and this is the last result message we get */
309 GNUNET_MQ_assoc_remove (set->mq, ntohl (msg->request_id));
310 GNUNET_CONTAINER_DLL_remove (set->ops_head,
313 if ( (GNUNET_YES == set->destroy_requested) &&
314 (NULL == set->ops_head) )
315 GNUNET_SET_destroy (set);
316 if (NULL != oh->result_cb)
317 oh->result_cb (oh->result_cls,
324 e.size = ntohs (mh->size) - sizeof (struct GNUNET_SET_ResultMessage);
325 e.element_type = msg->element_type;
326 if (NULL != oh->result_cb)
327 oh->result_cb (oh->result_cls,
334 * Handle request message for a listen operation
336 * @param cls the listen handle
337 * @param mh the message
340 handle_request (void *cls,
341 const struct GNUNET_MessageHeader *mh)
343 const struct GNUNET_SET_RequestMessage *msg = (const struct GNUNET_SET_RequestMessage *) mh;
344 struct GNUNET_SET_ListenHandle *lh = cls;
345 struct GNUNET_SET_Request *req;
346 const struct GNUNET_MessageHeader *context_msg;
348 LOG (GNUNET_ERROR_TYPE_DEBUG,
349 "processing operation request\n");
350 req = GNUNET_new (struct GNUNET_SET_Request);
351 req->accept_id = ntohl (msg->accept_id);
352 context_msg = GNUNET_MQ_extract_nested_mh (msg);
353 /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */
354 lh->listen_cb (lh->listen_cls, &msg->peer_id, context_msg, req);
356 /* we got another request => reset the backoff */
357 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
359 if (GNUNET_NO == req->accepted)
361 struct GNUNET_MQ_Envelope *mqm;
362 struct GNUNET_SET_RejectMessage *rmsg;
364 mqm = GNUNET_MQ_msg (rmsg,
365 GNUNET_MESSAGE_TYPE_SET_REJECT);
366 rmsg->accept_reject_id = msg->accept_id;
367 GNUNET_MQ_send (lh->mq, mqm);
368 LOG (GNUNET_ERROR_TYPE_DEBUG,
369 "rejecting request\n");
373 LOG (GNUNET_ERROR_TYPE_DEBUG,
374 "processed op request from service\n");
376 /* the accept-case is handled in GNUNET_SET_accept,
377 * as we have the accept message available there */
382 * Destroy the given set operation.
384 * @param oh set operation to destroy
387 set_operation_destroy (struct GNUNET_SET_OperationHandle *oh)
389 struct GNUNET_SET_Handle *set = oh->set;
390 struct GNUNET_SET_OperationHandle *h_assoc;
392 if (NULL != oh->conclude_mqm)
393 GNUNET_MQ_discard (oh->conclude_mqm);
394 /* is the operation already commited? */
397 GNUNET_CONTAINER_DLL_remove (set->ops_head,
400 h_assoc = GNUNET_MQ_assoc_remove (set->mq,
402 GNUNET_assert ((NULL == h_assoc) || (h_assoc == oh));
409 * Cancel the given set operation. We need to send an explicit cancel
410 * message, as all operations one one set communicate using one
413 * @param oh set operation to cancel
416 GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh)
418 struct GNUNET_SET_Handle *set = oh->set;
419 struct GNUNET_SET_CancelMessage *m;
420 struct GNUNET_MQ_Envelope *mqm;
424 mqm = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_SET_CANCEL);
425 m->request_id = htonl (oh->request_id);
426 GNUNET_MQ_send (set->mq, mqm);
428 set_operation_destroy (oh);
429 if ( (NULL != set) &&
430 (GNUNET_YES == set->destroy_requested) &&
431 (NULL == set->ops_head) )
433 LOG (GNUNET_ERROR_TYPE_DEBUG,
434 "Destroying set after operation cancel\n");
435 GNUNET_SET_destroy (set);
441 * We encountered an error communicating with the set service while
442 * performing a set operation. Report to the application.
444 * @param cls the `struct GNUNET_SET_Handle`
445 * @param error error code
448 handle_client_set_error (void *cls,
449 enum GNUNET_MQ_Error error)
451 struct GNUNET_SET_Handle *set = cls;
453 LOG (GNUNET_ERROR_TYPE_DEBUG,
454 "Handling client set error\n");
455 while (NULL != set->ops_head)
457 if (NULL != set->ops_head->result_cb)
458 set->ops_head->result_cb (set->ops_head->result_cls,
460 GNUNET_SET_STATUS_FAILURE);
461 set_operation_destroy (set->ops_head);
463 set->invalid = GNUNET_YES;
464 if (GNUNET_YES == set->destroy_requested)
466 LOG (GNUNET_ERROR_TYPE_DEBUG,
467 "Destroying set after operation failure\n");
468 GNUNET_SET_destroy (set);
474 * Create an empty set, supporting the specified operation.
476 * @param cfg configuration to use for connecting to the
478 * @param op operation supported by the set
479 * Note that the operation has to be specified
480 * beforehand, as certain set operations need to maintain
481 * data structures spefific to the operation
482 * @return a handle to the set
484 struct GNUNET_SET_Handle *
485 GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
486 enum GNUNET_SET_OperationType op)
488 static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
489 { &handle_result, GNUNET_MESSAGE_TYPE_SET_RESULT, 0},
490 { &handle_iter_element, GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT, 0},
492 GNUNET_MESSAGE_TYPE_SET_ITER_DONE,
493 sizeof (struct GNUNET_MessageHeader) },
494 GNUNET_MQ_HANDLERS_END
496 struct GNUNET_SET_Handle *set;
497 struct GNUNET_MQ_Envelope *mqm;
498 struct GNUNET_SET_CreateMessage *msg;
500 set = GNUNET_new (struct GNUNET_SET_Handle);
501 set->client = GNUNET_CLIENT_connect ("set", cfg);
502 if (NULL == set->client)
507 set->mq = GNUNET_MQ_queue_for_connection_client (set->client,
509 &handle_client_set_error, set);
510 GNUNET_assert (NULL != set->mq);
511 mqm = GNUNET_MQ_msg (msg,
512 GNUNET_MESSAGE_TYPE_SET_CREATE);
513 msg->operation = htonl (op);
514 GNUNET_MQ_send (set->mq, mqm);
520 * Add an element to the given set. After the element has been added
521 * (in the sense of being transmitted to the set service), @a cont
522 * will be called. Multiple calls to GNUNET_SET_add_element() can be
525 * @param set set to add element to
526 * @param element element to add to the set
527 * @param cont continuation called after the element has been added
528 * @param cont_cls closure for @a cont
529 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the
530 * set is invalid (e.g. the set service crashed)
533 GNUNET_SET_add_element (struct GNUNET_SET_Handle *set,
534 const struct GNUNET_SET_Element *element,
535 GNUNET_SET_Continuation cont,
538 struct GNUNET_MQ_Envelope *mqm;
539 struct GNUNET_SET_ElementMessage *msg;
541 if (GNUNET_YES == set->invalid)
545 return GNUNET_SYSERR;
547 mqm = GNUNET_MQ_msg_extra (msg, element->size,
548 GNUNET_MESSAGE_TYPE_SET_ADD);
549 msg->element_type = element->element_type;
553 GNUNET_MQ_notify_sent (mqm,
555 GNUNET_MQ_send (set->mq, mqm);
561 * Remove an element to the given set. After the element has been
562 * removed (in the sense of the request being transmitted to the set
563 * service), @a cont will be called. Multiple calls to
564 * GNUNET_SET_remove_element() can be queued
566 * @param set set to remove element from
567 * @param element element to remove from the set
568 * @param cont continuation called after the element has been removed
569 * @param cont_cls closure for @a cont
570 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the
571 * set is invalid (e.g. the set service crashed)
574 GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set,
575 const struct GNUNET_SET_Element *element,
576 GNUNET_SET_Continuation cont,
579 struct GNUNET_MQ_Envelope *mqm;
580 struct GNUNET_SET_ElementMessage *msg;
582 if (GNUNET_YES == set->invalid)
586 return GNUNET_SYSERR;
588 mqm = GNUNET_MQ_msg_extra (msg,
590 GNUNET_MESSAGE_TYPE_SET_REMOVE);
591 msg->element_type = element->element_type;
595 GNUNET_MQ_notify_sent (mqm,
597 GNUNET_MQ_send (set->mq, mqm);
603 * Destroy the set handle if no operations are left, mark the set
604 * for destruction otherwise.
606 * @param set set handle to destroy
609 GNUNET_SET_destroy (struct GNUNET_SET_Handle *set)
611 if (NULL != set->ops_head)
613 LOG (GNUNET_ERROR_TYPE_DEBUG,
614 "Set operations are pending, delaying set destruction\n");
615 set->destroy_requested = GNUNET_YES;
618 LOG (GNUNET_ERROR_TYPE_DEBUG,
619 "Really destroying set\n");
620 if (NULL != set->client)
622 GNUNET_CLIENT_disconnect (set->client);
627 GNUNET_MQ_destroy (set->mq);
635 * Prepare a set operation to be evaluated with another peer.
636 * The evaluation will not start until the client provides
637 * a local set with #GNUNET_SET_commit().
639 * @param other_peer peer with the other set
640 * @param app_id hash for the application using the set
641 * @param context_msg additional information for the request
642 * @param result_mode specified how results will be returned,
643 * see `enum GNUNET_SET_ResultMode`.
644 * @param result_cb called on error or success
645 * @param result_cls closure for @e result_cb
646 * @return a handle to cancel the operation
648 struct GNUNET_SET_OperationHandle *
649 GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer,
650 const struct GNUNET_HashCode *app_id,
651 const struct GNUNET_MessageHeader *context_msg,
652 enum GNUNET_SET_ResultMode result_mode,
653 GNUNET_SET_ResultIterator result_cb,
656 struct GNUNET_MQ_Envelope *mqm;
657 struct GNUNET_SET_OperationHandle *oh;
658 struct GNUNET_SET_EvaluateMessage *msg;
660 oh = GNUNET_new (struct GNUNET_SET_OperationHandle);
661 oh->result_cb = result_cb;
662 oh->result_cls = result_cls;
663 mqm = GNUNET_MQ_msg_nested_mh (msg,
664 GNUNET_MESSAGE_TYPE_SET_EVALUATE,
666 msg->app_id = *app_id;
667 msg->result_mode = htonl (result_mode);
668 msg->target_peer = *other_peer;
669 oh->conclude_mqm = mqm;
670 oh->request_id_addr = &msg->request_id;
677 * Connect to the set service in order to listen for requests.
679 * @param cls the `struct GNUNET_SET_ListenHandle *` to connect
680 * @param tc task context if invoked as a task, NULL otherwise
683 listen_connect (void *cls,
684 const struct GNUNET_SCHEDULER_TaskContext *tc);
688 * Our connection with the set service encountered an error,
689 * re-initialize with exponential back-off.
691 * @param cls the `struct GNUNET_SET_ListenHandle *`
692 * @param error reason for the disconnect
695 handle_client_listener_error (void *cls,
696 enum GNUNET_MQ_Error error)
698 struct GNUNET_SET_ListenHandle *lh = cls;
700 LOG (GNUNET_ERROR_TYPE_DEBUG,
701 "Listener broke down (%d), re-connecting\n",
703 GNUNET_CLIENT_disconnect (lh->client);
705 GNUNET_MQ_destroy (lh->mq);
707 lh->reconnect_task = GNUNET_SCHEDULER_add_delayed (lh->reconnect_backoff,
708 &listen_connect, lh);
709 lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (lh->reconnect_backoff);
714 * Connect to the set service in order to listen for requests.
716 * @param cls the `struct GNUNET_SET_ListenHandle *` to connect
717 * @param tc task context if invoked as a task, NULL otherwise
720 listen_connect (void *cls,
721 const struct GNUNET_SCHEDULER_TaskContext *tc)
723 static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
724 { &handle_request, GNUNET_MESSAGE_TYPE_SET_REQUEST },
725 GNUNET_MQ_HANDLERS_END
727 struct GNUNET_SET_ListenHandle *lh = cls;
728 struct GNUNET_MQ_Envelope *mqm;
729 struct GNUNET_SET_ListenMessage *msg;
732 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) )
734 LOG (GNUNET_ERROR_TYPE_DEBUG,
735 "Listener not reconnecting due to shutdown\n");
738 lh->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
740 GNUNET_assert (NULL == lh->client);
741 lh->client = GNUNET_CLIENT_connect ("set", lh->cfg);
742 if (NULL == lh->client)
744 GNUNET_assert (NULL == lh->mq);
745 lh->mq = GNUNET_MQ_queue_for_connection_client (lh->client, mq_handlers,
746 &handle_client_listener_error, lh);
747 mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_LISTEN);
748 msg->operation = htonl (lh->operation);
749 msg->app_id = lh->app_id;
750 GNUNET_MQ_send (lh->mq, mqm);
755 * Wait for set operation requests for the given application id
757 * @param cfg configuration to use for connecting to
758 * the set service, needs to be valid for the lifetime of the listen handle
759 * @param operation operation we want to listen for
760 * @param app_id id of the application that handles set operation requests
761 * @param listen_cb called for each incoming request matching the operation
763 * @param listen_cls handle for @a listen_cb
764 * @return a handle that can be used to cancel the listen operation
766 struct GNUNET_SET_ListenHandle *
767 GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg,
768 enum GNUNET_SET_OperationType operation,
769 const struct GNUNET_HashCode *app_id,
770 GNUNET_SET_ListenCallback listen_cb,
773 struct GNUNET_SET_ListenHandle *lh;
775 lh = GNUNET_new (struct GNUNET_SET_ListenHandle);
776 lh->listen_cb = listen_cb;
777 lh->listen_cls = listen_cls;
779 lh->operation = operation;
780 lh->app_id = *app_id;
781 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
782 listen_connect (lh, NULL);
783 if (NULL == lh->client)
793 * Cancel the given listen operation.
795 * @param lh handle for the listen operation
798 GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh)
800 LOG (GNUNET_ERROR_TYPE_DEBUG,
801 "Canceling listener\n");
804 GNUNET_MQ_destroy (lh->mq);
807 if (NULL != lh->client)
809 GNUNET_CLIENT_disconnect (lh->client);
812 if (GNUNET_SCHEDULER_NO_TASK != lh->reconnect_task)
814 GNUNET_SCHEDULER_cancel (lh->reconnect_task);
815 lh->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
822 * Accept a request we got via #GNUNET_SET_listen. Must be called during
823 * #GNUNET_SET_listen, as the 'struct GNUNET_SET_Request' becomes invalid
825 * Call #GNUNET_SET_commit to provide the local set to use for the operation,
826 * and to begin the exchange with the remote peer.
828 * @param request request to accept
829 * @param result_mode specified how results will be returned,
830 * see `enum GNUNET_SET_ResultMode`.
831 * @param result_cb callback for the results
832 * @param result_cls closure for @a result_cb
833 * @return a handle to cancel the operation
835 struct GNUNET_SET_OperationHandle *
836 GNUNET_SET_accept (struct GNUNET_SET_Request *request,
837 enum GNUNET_SET_ResultMode result_mode,
838 GNUNET_SET_ResultIterator result_cb,
841 struct GNUNET_MQ_Envelope *mqm;
842 struct GNUNET_SET_OperationHandle *oh;
843 struct GNUNET_SET_AcceptMessage *msg;
845 GNUNET_assert (GNUNET_NO == request->accepted);
846 request->accepted = GNUNET_YES;
847 mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_ACCEPT);
848 msg->accept_reject_id = htonl (request->accept_id);
849 msg->result_mode = htonl (result_mode);
850 oh = GNUNET_new (struct GNUNET_SET_OperationHandle);
851 oh->result_cb = result_cb;
852 oh->result_cls = result_cls;
853 oh->conclude_mqm = mqm;
854 oh->request_id_addr = &msg->request_id;
860 * Commit a set to be used with a set operation.
861 * This function is called once we have fully constructed
862 * the set that we want to use for the operation. At this
863 * time, the P2P protocol can then begin to exchange the
864 * set information and call the result callback with the
865 * result information.
867 * @param oh handle to the set operation
868 * @param set the set to use for the operation
869 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the
870 * set is invalid (e.g. the set service crashed)
873 GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh,
874 struct GNUNET_SET_Handle *set)
876 GNUNET_assert (NULL == oh->set);
877 if (GNUNET_YES == set->invalid)
878 return GNUNET_SYSERR;
879 GNUNET_assert (NULL != oh->conclude_mqm);
881 GNUNET_CONTAINER_DLL_insert (set->ops_head,
884 oh->request_id = GNUNET_MQ_assoc_add (set->mq, oh);
885 *oh->request_id_addr = htonl (oh->request_id);
886 GNUNET_MQ_send (set->mq, oh->conclude_mqm);
887 oh->conclude_mqm = NULL;
888 oh->request_id_addr = NULL;
894 * Iterate over all elements in the given set. Note that this
895 * operation involves transferring every element of the set from the
896 * service to the client, and is thus costly.
898 * @param set the set to iterate over
899 * @param iter the iterator to call for each element
900 * @param iter_cls closure for @a iter
901 * @return #GNUNET_YES if the iteration started successfuly,
902 * #GNUNET_NO if another iteration is active
903 * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected)
906 GNUNET_SET_iterate (struct GNUNET_SET_Handle *set,
907 GNUNET_SET_ElementIterator iter,
910 struct GNUNET_MQ_Envelope *ev;
912 GNUNET_assert (NULL != iter);
913 if (GNUNET_YES == set->invalid)
914 return GNUNET_SYSERR;
915 if (NULL != set->iterator)
917 LOG (GNUNET_ERROR_TYPE_DEBUG,
918 "Iterating over set\n");
919 set->iterator = iter;
920 set->iterator_cls = iter_cls;
921 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST);
922 GNUNET_MQ_send (set->mq, ev);
926 /* end of set_api.c */