2 This file is part of GNUnet.
3 (C) 2012, 2013 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.
23 * @brief api for the set service
24 * @author Florian Dold
27 #include "gnunet_util_lib.h"
28 #include "gnunet_protocols.h"
29 #include "gnunet_client_lib.h"
30 #include "gnunet_set_service.h"
34 #define LOG(kind,...) GNUNET_log_from (kind, "set-api",__VA_ARGS__)
37 * Opaque handle to a set.
39 struct GNUNET_SET_Handle
42 * Client connected to the set service.
44 struct GNUNET_CLIENT_Connection *client;
47 * Message queue for 'client'.
49 struct GNUNET_MQ_Handle *mq;
52 * Linked list of operations on the set.
54 struct GNUNET_SET_OperationHandle *ops_head;
57 * Linked list of operations on the set.
59 struct GNUNET_SET_OperationHandle *ops_tail;
62 * Should the set be destroyed once all operations are gone?
64 int destroy_requested;
67 * Has the set become invalid (e.g. service died)?
72 * Callback for the current iteration over the set,
73 * NULL if no iterator is active.
75 GNUNET_SET_ElementIterator iterator;
78 * Closure for 'iterator'
85 * Opaque handle to a set operation request from another peer.
87 struct GNUNET_SET_Request
90 * Id of the request, used to identify the request when
91 * accepting/rejecting it.
96 * Has the request been accepted already?
97 * GNUNET_YES/GNUNET_NO
104 * Handle to an operation.
105 * Only known to the service after commiting
106 * the handle with a set.
108 struct GNUNET_SET_OperationHandle
111 * Function to be called when we have a result,
114 GNUNET_SET_ResultIterator result_cb;
117 * Closure for result_cb.
122 * Local set used for the operation,
123 * NULL if no set has been provided by conclude yet.
125 struct GNUNET_SET_Handle *set;
128 * Request ID to identify the operation within the set.
133 * Message sent to the server on calling conclude,
134 * NULL if conclude has been called.
136 struct GNUNET_MQ_Envelope *conclude_mqm;
139 * Address of the request if in the conclude message,
140 * used to patch the request id into the message when the set is known.
142 uint32_t *request_id_addr;
145 * Handles are kept in a linked list.
147 struct GNUNET_SET_OperationHandle *prev;
150 * Handles are kept in a linked list.
152 struct GNUNET_SET_OperationHandle *next;
157 * Opaque handle to a listen operation.
159 struct GNUNET_SET_ListenHandle
162 * Connection to the service.
164 struct GNUNET_CLIENT_Connection *client;
167 * Message queue for the client.
169 struct GNUNET_MQ_Handle* mq;
172 * Configuration handle for the listener, stored
173 * here to be able to reconnect transparently on
174 * connection failure.
176 const struct GNUNET_CONFIGURATION_Handle *cfg;
179 * Function to call on a new incoming request,
182 GNUNET_SET_ListenCallback listen_cb;
185 * Closure for listen_cb.
190 * Operation we listen for.
192 enum GNUNET_SET_OperationType operation;
195 * Application ID we listen for.
197 struct GNUNET_HashCode app_id;
200 * Time to wait until we try to reconnect on failure.
202 struct GNUNET_TIME_Relative reconnect_backoff;
205 * Task for reconnecting when the listener fails.
207 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
211 /* forward declaration */
213 listen_connect (void *cls,
214 const struct GNUNET_SCHEDULER_TaskContext *tc);
218 * Handle element for iteration over the set.
221 * @param mh the message
224 handle_iter_element (void *cls, const struct GNUNET_MessageHeader *mh)
226 struct GNUNET_SET_Handle *set = cls;
227 struct GNUNET_SET_Element element;
228 const struct GNUNET_SET_IterResponseMessage *msg =
229 (const struct GNUNET_SET_IterResponseMessage *) mh;
230 struct GNUNET_SET_IterAckMessage *ack_msg;
231 struct GNUNET_MQ_Envelope *ev;
233 if (NULL == set->iterator)
236 element.size = ntohs (mh->size) - sizeof (struct GNUNET_SET_IterResponseMessage);
237 element.type = htons (msg->element_type);
238 element.data = &msg[1];
239 set->iterator (set->iterator_cls, &element);
240 ev = GNUNET_MQ_msg (ack_msg, GNUNET_MESSAGE_TYPE_SET_ITER_ACK);
241 ack_msg->send_more = htonl (1);
242 GNUNET_MQ_send (set->mq, ev);
247 * Handle element for iteration over the set.
250 * @param mh the message
253 handle_iter_done (void *cls, const struct GNUNET_MessageHeader *mh)
255 struct GNUNET_SET_Handle *set = cls;
257 if (NULL == set->iterator)
260 set->iterator (set->iterator_cls, NULL);
265 * Handle result message for a set operation.
268 * @param mh the message
271 handle_result (void *cls, const struct GNUNET_MessageHeader *mh)
273 const struct GNUNET_SET_ResultMessage *msg;
274 struct GNUNET_SET_Handle *set = cls;
275 struct GNUNET_SET_OperationHandle *oh;
276 struct GNUNET_SET_Element e;
277 enum GNUNET_SET_Status result_status;
279 msg = (const struct GNUNET_SET_ResultMessage *) mh;
280 GNUNET_assert (NULL != set);
281 GNUNET_assert (NULL != set->mq);
283 result_status = ntohs (msg->result_status);
285 oh = GNUNET_MQ_assoc_get (set->mq, ntohl (msg->request_id));
286 // 'oh' can be NULL if we canceled the operation, but the service
287 // did not get the cancel message yet.
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ignoring result from canceled operation\n");
293 /* status is not STATUS_OK => there's no attached element,
294 * and this is the last result message we get */
295 if (GNUNET_SET_STATUS_OK != result_status)
297 GNUNET_MQ_assoc_remove (set->mq, ntohl (msg->request_id));
298 GNUNET_CONTAINER_DLL_remove (oh->set->ops_head, oh->set->ops_tail, oh);
299 if (GNUNET_YES == oh->set->destroy_requested)
300 GNUNET_SET_destroy (oh->set);
301 if (NULL != oh->result_cb)
302 oh->result_cb (oh->result_cls, NULL, result_status);
308 e.size = ntohs (mh->size) - sizeof (struct GNUNET_SET_ResultMessage);
309 e.type = msg->element_type;
310 if (NULL != oh->result_cb)
311 oh->result_cb (oh->result_cls, &e, result_status);
316 * Handle request message for a listen operation
318 * @param cls the listen handle
319 * @param mh the message
322 handle_request (void *cls, const struct GNUNET_MessageHeader *mh)
324 const struct GNUNET_SET_RequestMessage *msg = (const struct GNUNET_SET_RequestMessage *) mh;
325 struct GNUNET_SET_ListenHandle *lh = cls;
326 struct GNUNET_SET_Request *req;
327 struct GNUNET_MessageHeader *context_msg;
329 LOG (GNUNET_ERROR_TYPE_DEBUG, "processing operation request\n");
330 req = GNUNET_new (struct GNUNET_SET_Request);
331 req->accept_id = ntohl (msg->accept_id);
332 context_msg = GNUNET_MQ_extract_nested_mh (msg);
333 /* calling GNUNET_SET_accept in the listen cb will set req->accepted */
334 lh->listen_cb (lh->listen_cls, &msg->peer_id, context_msg, req);
336 /* we got another request => reset the backoff */
337 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
339 if (GNUNET_NO == req->accepted)
341 struct GNUNET_MQ_Envelope *mqm;
342 struct GNUNET_SET_AcceptRejectMessage *amsg;
344 mqm = GNUNET_MQ_msg (amsg, GNUNET_MESSAGE_TYPE_SET_REJECT);
345 /* no request id, as we refused */
346 amsg->request_id = htonl (0);
347 amsg->accept_reject_id = msg->accept_id;
348 GNUNET_MQ_send (lh->mq, mqm);
349 LOG (GNUNET_ERROR_TYPE_DEBUG, "rejecting request\n");
353 LOG (GNUNET_ERROR_TYPE_DEBUG, "processed op request from service\n");
355 /* the accept-case is handled in GNUNET_SET_accept,
356 * as we have the accept message available there */
361 handle_client_listener_error (void *cls, enum GNUNET_MQ_Error error)
363 struct GNUNET_SET_ListenHandle *lh = cls;
365 LOG (GNUNET_ERROR_TYPE_DEBUG, "listener broke down, re-connecting\n");
366 GNUNET_CLIENT_disconnect (lh->client);
368 GNUNET_MQ_destroy (lh->mq);
371 lh->reconnect_task = GNUNET_SCHEDULER_add_delayed (lh->reconnect_backoff, listen_connect, lh);
372 lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (lh->reconnect_backoff);
377 * Destroy the set handle if no operations are left, mark the set
378 * for destruction otherwise.
380 * @param set set handle to destroy
383 set_destroy (struct GNUNET_SET_Handle *set)
385 if (NULL != set->ops_head)
387 set->destroy_requested = GNUNET_YES;
390 LOG (GNUNET_ERROR_TYPE_DEBUG, "Really destroying set\n");
391 GNUNET_CLIENT_disconnect (set->client);
393 GNUNET_MQ_destroy (set->mq);
403 * Cancel the given set operation. We need to send an explicit cancel message,
404 * as all operations one one set communicate using one handle.
406 * In contrast to GNUNET_SET_operation_cancel, this function indicates whether
407 * the set of the operation has been destroyed because all operations are done and
408 * the set's destruction was requested before.
410 * @param oh set operation to cancel
411 * @return GNUNET_YES if the set of the operation was destroyed
414 set_operation_cancel (struct GNUNET_SET_OperationHandle *oh)
418 if (NULL != oh->conclude_mqm)
419 GNUNET_MQ_discard (oh->conclude_mqm);
421 /* is the operation already commited? */
424 struct GNUNET_SET_OperationHandle *h_assoc;
425 struct GNUNET_SET_CancelMessage *m;
426 struct GNUNET_MQ_Envelope *mqm;
428 GNUNET_CONTAINER_DLL_remove (oh->set->ops_head, oh->set->ops_tail, oh);
429 h_assoc = GNUNET_MQ_assoc_remove (oh->set->mq, oh->request_id);
430 GNUNET_assert ((h_assoc == NULL) || (h_assoc == oh));
431 mqm = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_SET_CANCEL);
432 m->request_id = htonl (oh->request_id);
433 GNUNET_MQ_send (oh->set->mq, mqm);
435 if (GNUNET_YES == oh->set->destroy_requested)
437 LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying set after operation cancel\n");
438 ret = set_destroy (oh->set);
449 * Cancel the given set operation. We need to send an explicit cancel message,
450 * as all operations one one set communicate using one handle.
452 * @param oh set operation to cancel
455 GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh)
457 (void) set_operation_cancel (oh);
462 handle_client_set_error (void *cls, enum GNUNET_MQ_Error error)
464 struct GNUNET_SET_Handle *set = cls;
466 LOG (GNUNET_ERROR_TYPE_DEBUG, "handling client set error\n");
468 while (NULL != set->ops_head)
470 if (NULL != set->ops_head->result_cb)
471 set->ops_head->result_cb (set->ops_head->result_cls, NULL,
472 GNUNET_SET_STATUS_FAILURE);
473 if (GNUNET_YES == set_operation_cancel (set->ops_head))
474 return; /* stop if the set is destroyed */
476 set->invalid = GNUNET_YES;
481 * Create an empty set, supporting the specified operation.
483 * @param cfg configuration to use for connecting to the
485 * @param op operation supported by the set
486 * Note that the operation has to be specified
487 * beforehand, as certain set operations need to maintain
488 * data structures spefific to the operation
489 * @return a handle to the set
491 struct GNUNET_SET_Handle *
492 GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
493 enum GNUNET_SET_OperationType op)
495 struct GNUNET_SET_Handle *set;
496 struct GNUNET_MQ_Envelope *mqm;
497 struct GNUNET_SET_CreateMessage *msg;
498 static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
499 {handle_result, GNUNET_MESSAGE_TYPE_SET_RESULT, 0},
500 {handle_iter_element, GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT, 0},
501 {handle_iter_done, GNUNET_MESSAGE_TYPE_SET_ITER_DONE, 0},
502 GNUNET_MQ_HANDLERS_END
505 set = GNUNET_new (struct GNUNET_SET_Handle);
506 set->client = GNUNET_CLIENT_connect ("set", cfg);
507 LOG (GNUNET_ERROR_TYPE_DEBUG, "set client created\n");
508 GNUNET_assert (NULL != set->client);
509 set->mq = GNUNET_MQ_queue_for_connection_client (set->client, mq_handlers,
510 handle_client_set_error, set);
511 GNUNET_assert (NULL != set->mq);
512 mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_CREATE);
513 msg->operation = htons (op);
514 GNUNET_MQ_send (set->mq, mqm);
520 * Add an element to the given set.
521 * After the element has been added (in the sense of being
522 * transmitted to the set service), cont will be called.
523 * Calls to add_element can be queued
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;
548 mqm = GNUNET_MQ_msg_extra (msg, element->size, GNUNET_MESSAGE_TYPE_SET_ADD);
549 msg->element_type = element->type;
550 memcpy (&msg[1], element->data, element->size);
551 GNUNET_MQ_notify_sent (mqm, cont, cont_cls);
552 GNUNET_MQ_send (set->mq, mqm);
558 * Remove an element to the given set.
559 * After the element has been removed (in the sense of the
560 * request being transmitted to the set service), cont will be called.
561 * Calls to remove_element can be queued
563 * @param set set to remove element from
564 * @param element element to remove from the set
565 * @param cont continuation called after the element has been removed
566 * @param cont_cls closure for cont
567 * @return GNUNET_OK on success, GNUNET_SYSERR if the
568 * set is invalid (e.g. the set service crashed)
571 GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set,
572 const struct GNUNET_SET_Element *element,
573 GNUNET_SET_Continuation cont,
576 struct GNUNET_MQ_Envelope *mqm;
577 struct GNUNET_SET_ElementMessage *msg;
579 if (GNUNET_YES == set->invalid)
583 return GNUNET_SYSERR;
586 mqm = GNUNET_MQ_msg_extra (msg, element->size, GNUNET_MESSAGE_TYPE_SET_REMOVE);
587 msg->element_type = element->type;
588 memcpy (&msg[1], element->data, element->size);
589 GNUNET_MQ_notify_sent (mqm, cont, cont_cls);
590 GNUNET_MQ_send (set->mq, mqm);
596 * Destroy the set handle, and free all associated resources.
598 * @param set set handle to destroy
601 GNUNET_SET_destroy (struct GNUNET_SET_Handle *set)
603 (void) set_destroy (set);
608 * Prepare a set operation to be evaluated with another peer.
609 * The evaluation will not start until the client provides
610 * a local set with GNUNET_SET_commit.
612 * @param other_peer peer with the other set
613 * @param app_id hash for the application using the set
614 * @param context_msg additional information for the request
615 * @param salt salt used for the set operation; sometimes set operations
616 * fail due to hash collisions, using a different salt for each operation
617 * makes it harder for an attacker to exploit this
618 * @param result_mode specified how results will be returned,
619 * see 'GNUNET_SET_ResultMode'.
620 * @param result_cb called on error or success
621 * @param result_cls closure for result_cb
622 * @return a handle to cancel the operation
624 struct GNUNET_SET_OperationHandle *
625 GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer,
626 const struct GNUNET_HashCode *app_id,
627 const struct GNUNET_MessageHeader *context_msg,
629 enum GNUNET_SET_ResultMode result_mode,
630 GNUNET_SET_ResultIterator result_cb,
633 struct GNUNET_MQ_Envelope *mqm;
634 struct GNUNET_SET_OperationHandle *oh;
635 struct GNUNET_SET_EvaluateMessage *msg;
637 oh = GNUNET_new (struct GNUNET_SET_OperationHandle);
638 oh->result_cb = result_cb;
639 oh->result_cls = result_cls;
641 mqm = GNUNET_MQ_msg_nested_mh (msg, GNUNET_MESSAGE_TYPE_SET_EVALUATE, context_msg);
643 msg->app_id = *app_id;
644 msg->result_mode = htons (result_mode);
645 msg->target_peer = *other_peer;
647 oh->conclude_mqm = mqm;
648 oh->request_id_addr = &msg->request_id;
655 * Connect to the set service in order to listen
658 * @param cls the listen handle to connect
659 * @param tc task context if invoked as a task, NULL otherwise
662 listen_connect (void *cls,
663 const struct GNUNET_SCHEDULER_TaskContext *tc)
665 struct GNUNET_MQ_Envelope *mqm;
666 struct GNUNET_SET_ListenMessage *msg;
667 struct GNUNET_SET_ListenHandle *lh = cls;
668 static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
669 {handle_request, GNUNET_MESSAGE_TYPE_SET_REQUEST},
670 GNUNET_MQ_HANDLERS_END
673 if ((tc != NULL) &&(tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
675 LOG (GNUNET_ERROR_TYPE_DEBUG, "listener not reconnecting due to shutdown\n");
679 lh->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
681 GNUNET_assert (NULL == lh->client);
682 lh->client = GNUNET_CLIENT_connect ("set", lh->cfg);
683 if (NULL == lh->client)
685 LOG (GNUNET_ERROR_TYPE_ERROR,
686 "could not connect to set (wrong configuration?), giving up listening\n");
689 GNUNET_assert (NULL == lh->mq);
690 lh->mq = GNUNET_MQ_queue_for_connection_client (lh->client, mq_handlers,
691 handle_client_listener_error, lh);
692 mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_LISTEN);
693 msg->operation = htonl (lh->operation);
694 msg->app_id = lh->app_id;
695 GNUNET_MQ_send (lh->mq, mqm);
700 * Wait for set operation requests for the given application id
702 * @param cfg configuration to use for connecting to
703 * the set service, needs to be valid for the lifetime of the listen handle
704 * @param operation operation we want to listen for
705 * @param app_id id of the application that handles set operation requests
706 * @param listen_cb called for each incoming request matching the operation
708 * @param listen_cls handle for listen_cb
709 * @return a handle that can be used to cancel the listen operation
711 struct GNUNET_SET_ListenHandle *
712 GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg,
713 enum GNUNET_SET_OperationType operation,
714 const struct GNUNET_HashCode *app_id,
715 GNUNET_SET_ListenCallback listen_cb,
718 struct GNUNET_SET_ListenHandle *lh;
720 lh = GNUNET_new (struct GNUNET_SET_ListenHandle);
721 lh->listen_cb = listen_cb;
722 lh->listen_cls = listen_cls;
724 lh->operation = operation;
725 lh->app_id = *app_id;
726 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
727 listen_connect (lh, NULL);
733 * Cancel the given listen operation.
735 * @param lh handle for the listen operation
738 GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh)
740 LOG (GNUNET_ERROR_TYPE_DEBUG, "canceling listener\n");
741 /* listener's connection may have failed, thus mq/client could be NULL */
744 GNUNET_MQ_destroy (lh->mq);
747 if (NULL != lh->client)
749 GNUNET_CLIENT_disconnect (lh->client);
752 if (GNUNET_SCHEDULER_NO_TASK != lh->reconnect_task)
754 GNUNET_SCHEDULER_cancel (lh->reconnect_task);
755 lh->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
762 * Accept a request we got via #GNUNET_SET_listen. Must be called during
763 * #GNUNET_SET_listen, as the 'struct GNUNET_SET_Request' becomes invalid
765 * Call #GNUNET_SET_commit to provide the local set to use for the operation,
766 * and to begin the exchange with the remote peer.
768 * @param request request to accept
769 * @param result_mode specified how results will be returned,
770 * see 'GNUNET_SET_ResultMode'.
771 * @param result_cb callback for the results
772 * @param result_cls closure for result_cb
773 * @return a handle to cancel the operation
775 struct GNUNET_SET_OperationHandle *
776 GNUNET_SET_accept (struct GNUNET_SET_Request *request,
777 enum GNUNET_SET_ResultMode result_mode,
778 GNUNET_SET_ResultIterator result_cb,
781 struct GNUNET_MQ_Envelope *mqm;
782 struct GNUNET_SET_OperationHandle *oh;
783 struct GNUNET_SET_AcceptRejectMessage *msg;
785 GNUNET_assert (NULL != request);
786 GNUNET_assert (GNUNET_NO == request->accepted);
787 request->accepted = GNUNET_YES;
789 oh = GNUNET_new (struct GNUNET_SET_OperationHandle);
790 oh->result_cb = result_cb;
791 oh->result_cls = result_cls;
793 mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_ACCEPT);
794 msg->accept_reject_id = htonl (request->accept_id);
795 msg->result_mode = htons (result_mode);
797 oh->conclude_mqm = mqm;
798 oh->request_id_addr = &msg->request_id;
805 * Commit a set to be used with a set operation.
806 * This function is called once we have fully constructed
807 * the set that we want to use for the operation. At this
808 * time, the P2P protocol can then begin to exchange the
809 * set information and call the result callback with the
810 * result information.
812 * @param oh handle to the set operation
813 * @param set the set to use for the operation
814 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the
815 * set is invalid (e.g. the set service crashed)
818 GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh,
819 struct GNUNET_SET_Handle *set)
821 GNUNET_assert (NULL == oh->set);
822 if (GNUNET_YES == set->invalid)
823 return GNUNET_SYSERR;
824 GNUNET_assert (NULL != oh->conclude_mqm);
826 GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, oh);
827 oh->request_id = GNUNET_MQ_assoc_add (set->mq, oh);
828 *oh->request_id_addr = htonl (oh->request_id);
829 GNUNET_MQ_send (set->mq, oh->conclude_mqm);
830 oh->conclude_mqm = NULL;
831 oh->request_id_addr = NULL;
837 * Iterate over all elements in the given set.
838 * Note that this operation involves transferring every element of the set
839 * from the service to the client, and is thus costly.
841 * @param set the set to iterate over
842 * @param iter the iterator to call for each element
843 * @param cls closure for @a iter
844 * @return #GNUNET_YES if the iteration started successfuly,
845 * #GNUNET_NO if another iteration is active
846 * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected)
849 GNUNET_SET_iterate (struct GNUNET_SET_Handle *set, GNUNET_SET_ElementIterator iter, void *cls)
851 struct GNUNET_MQ_Envelope *ev;
854 GNUNET_assert (NULL != iter);
856 if (GNUNET_YES == set->invalid)
857 return GNUNET_SYSERR;
858 if (NULL != set->iterator)
861 LOG (GNUNET_ERROR_TYPE_DEBUG, "iterating set\n");
863 set->iterator = iter;
864 set->iterator_cls = cls;
865 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST);
866 GNUNET_MQ_send (set->mq, ev);
870 /* end of set_api.c */