new timeout tests for WLAN and bluetooth
[oweals/gnunet.git] / src / set / gnunet-service-set.c
1 /*
2       This file is part of GNUnet
3       (C) 2013 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @file set/gnunet-service-set.c
23  * @brief two-peer set operations
24  * @author Florian Dold
25  */
26 #include "gnunet-service-set.h"
27 #include "set_protocol.h"
28
29
30 /**
31  * State of an operation where the peer has connected to us, but is not yet
32  * evaluating a set operation.  Once the peer has sent a concrete request, and
33  * the client has accepted or rejected it, this information will be deleted
34  * and replaced by the real set operation state.
35  */
36 struct OperationState
37 {
38   /**
39    * The identity of the requesting peer.  Needs to
40    * be stored here as the op spec might not have been created yet.
41    */
42   struct GNUNET_PeerIdentity peer;
43
44   /**
45    * Unique request id for the request from
46    * a remote peer, sent to the client, which will
47    * accept or reject the request.
48    * Set to '0' iff the request has not been
49    * suggested yet.
50    */
51   uint32_t suggest_id;
52
53   /**
54    * Timeout task, if the incoming peer has not been accepted
55    * after the timeout, it will be disconnected.
56    */
57   GNUNET_SCHEDULER_TaskIdentifier timeout_task;
58 };
59
60
61 /**
62  * A listener is inhabited by a client, and
63  * waits for evaluation requests from remote peers.
64  */
65 struct Listener
66 {
67   /**
68    * Listeners are held in a doubly linked list.
69    */
70   struct Listener *next;
71
72   /**
73    * Listeners are held in a doubly linked list.
74    */
75   struct Listener *prev;
76
77   /**
78    * Client that owns the listener.
79    * Only one client may own a listener.
80    */
81   struct GNUNET_SERVER_Client *client;
82
83   /**
84    * Message queue for the client
85    */
86   struct GNUNET_MQ_Handle *client_mq;
87
88   /**
89    * The type of the operation.
90    */
91   enum GNUNET_SET_OperationType operation;
92
93   /**
94    * Application ID for the operation, used to distinguish
95    * multiple operations of the same type with the same peer.
96    */
97   struct GNUNET_HashCode app_id;
98 };
99
100
101 /**
102  * Configuration of our local peer.
103  */
104 static const struct GNUNET_CONFIGURATION_Handle *configuration;
105
106 /**
107  * Handle to the mesh service, used
108  * to listen for and connect to remote peers.
109  */
110 static struct GNUNET_MESH_Handle *mesh;
111
112 /**
113  * Sets are held in a doubly linked list.
114  */
115 static struct Set *sets_head;
116
117 /**
118  * Sets are held in a doubly linked list.
119  */
120 static struct Set *sets_tail;
121
122 /**
123  * Listeners are held in a doubly linked list.
124  */
125 static struct Listener *listeners_head;
126
127 /**
128  * Listeners are held in a doubly linked list.
129  */
130 static struct Listener *listeners_tail;
131
132 /**
133  * Incoming sockets from remote peers are
134  * held in a doubly linked list.
135  */
136 static struct Operation *incoming_head;
137
138 /**
139  * Incoming sockets from remote peers are
140  * held in a doubly linked list.
141  */
142 static struct Operation *incoming_tail;
143
144 /**
145  * Counter for allocating unique IDs for clients,
146  * used to identify incoming operation requests from remote peers,
147  * that the client can choose to accept or refuse.
148  */
149 static uint32_t suggest_id = 1;
150
151
152 /**
153  * Get set that is owned by the given client, if any.
154  *
155  * @param client client to look for
156  * @return set that the client owns, NULL if the client
157  *         does not own a set
158  */
159 static struct Set *
160 set_get (struct GNUNET_SERVER_Client *client)
161 {
162   struct Set *set;
163
164   for (set = sets_head; NULL != set; set = set->next)
165     if (set->client == client)
166       return set;
167   return NULL;
168 }
169
170
171 /**
172  * Get the listener associated with the given client, if any.
173  *
174  * @param client the client
175  * @return listener associated with the client, NULL
176  *         if there isn't any
177  */
178 static struct Listener *
179 listener_get (struct GNUNET_SERVER_Client *client)
180 {
181   struct Listener *listener;
182
183   for (listener = listeners_head; NULL != listener; listener = listener->next)
184     if (listener->client == client)
185       return listener;
186   return NULL;
187 }
188
189
190 /**
191  * Get the incoming socket associated with the given id.
192  *
193  * @param id id to look for
194  * @return the incoming socket associated with the id,
195  *         or NULL if there is none
196  */
197 static struct Operation *
198 get_incoming (uint32_t id)
199 {
200   struct Operation *op;
201
202   for (op = incoming_head; NULL != op; op = op->next)
203     if (op->state->suggest_id == id)
204     {
205       // FIXME: remove this assertion once the corresponding bug is gone!
206       GNUNET_assert (GNUNET_YES == op->is_incoming);
207       return op;
208     }
209   return NULL;
210 }
211
212
213 /**
214  * Destroy a listener, free all resources associated with it.
215  *
216  * @param listener listener to destroy
217  */
218 static void
219 listener_destroy (struct Listener *listener)
220 {
221   /* If the client is not dead yet, destroy it.
222    * The client's destroy callback will destroy the listener again. */
223   if (NULL != listener->client)
224   {
225     struct GNUNET_SERVER_Client *client = listener->client;
226     listener->client = NULL;
227     GNUNET_SERVER_client_disconnect (client);
228     return;
229   }
230   if (NULL != listener->client_mq)
231   {
232     GNUNET_MQ_destroy (listener->client_mq);
233     listener->client_mq = NULL;
234   }
235   GNUNET_CONTAINER_DLL_remove (listeners_head, listeners_tail, listener);
236   GNUNET_free (listener);
237 }
238
239
240 /**
241  * Collect and destroy elements that are not needed anymore, because
242  * their lifetime (as determined by their generation) does not overlap with any active
243  * set operation.
244  *
245  * We hereby replace the old element hashmap with a new one, instead of removing elements.
246  */
247 void
248 collect_generation_garbage (struct Set *set)
249 {
250   struct GNUNET_CONTAINER_MultiHashMapIterator *iter;
251   struct ElementEntry *ee;
252   struct GNUNET_CONTAINER_MultiHashMap *new_elements;
253   int res;
254   struct Operation *op;
255
256   new_elements = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
257   iter = GNUNET_CONTAINER_multihashmap_iterator_create (set->elements);
258   while (GNUNET_OK ==
259          (res = GNUNET_CONTAINER_multihashmap_iterator_next (iter, NULL, (const void **) &ee)))
260   {
261     if (GNUNET_NO == ee->removed)
262       goto still_needed;
263     for (op = set->ops_head; NULL != op; op = op->next)
264       if ((op->generation_created >= ee->generation_added) &&
265           (op->generation_created < ee->generation_removed))
266         goto still_needed;
267     GNUNET_free (ee);
268     continue;
269 still_needed:
270     // we don't expect collisions, thus the replace option
271     GNUNET_CONTAINER_multihashmap_put (new_elements, &ee->element_hash, ee,
272                                        GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
273   }
274   GNUNET_CONTAINER_multihashmap_iterator_destroy (iter);
275   GNUNET_CONTAINER_multihashmap_destroy (set->elements);
276   set->elements = new_elements;
277 }
278
279
280 /**
281  * Destroy the given operation.  Call the implementation-specific cancel function
282  * of the operation.  Disconnects from the remote peer.
283  * Does not disconnect the client, as there may be multiple operations per set.
284  *
285  * @param op operation to destroy
286  */
287 void
288 _GSS_operation_destroy (struct Operation *op)
289 {
290   struct Set *set;
291   struct GNUNET_MESH_Channel *channel;
292
293   if (NULL == op->vt)
294     return;
295
296   set = op->spec->set;
297
298   GNUNET_assert (GNUNET_NO == op->is_incoming);
299   GNUNET_assert (NULL != op->spec);
300   GNUNET_CONTAINER_DLL_remove (op->spec->set->ops_head,
301                                op->spec->set->ops_tail,
302                                op);
303
304   op->vt->cancel (op);
305   op->vt = NULL;
306
307   if (NULL != op->spec)
308   {
309     if (NULL != op->spec->context_msg)
310     {
311       GNUNET_free (op->spec->context_msg);
312       op->spec->context_msg = NULL;
313     }
314     GNUNET_free (op->spec);
315     op->spec = NULL;
316   }
317
318   if (NULL != op->mq)
319   {
320     GNUNET_MQ_destroy (op->mq);
321     op->mq = NULL;
322   }
323
324   if (NULL != (channel = op->channel))
325   {
326     op->channel = NULL;
327     GNUNET_MESH_channel_destroy (channel);
328   }
329
330   collect_generation_garbage (set);
331
332   /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL,
333    * there was a channel end handler that will free 'op' on the call stack. */
334 }
335
336
337 /**
338  * Iterator over hash map entries to free
339  * element entries.
340  *
341  * @param cls closure
342  * @param key current key code
343  * @param value a `struct ElementEntry *` to be free'd
344  * @return #GNUNET_YES if we should continue to
345  *         iterate,
346  *         #GNUNET_NO if not.
347  */
348 static int
349 destroy_elements_iterator (void *cls,
350                            const struct GNUNET_HashCode * key,
351                            void *value)
352 {
353   struct ElementEntry *ee = value;
354
355   GNUNET_free (ee);
356   return GNUNET_YES;
357 }
358
359
360 /**
361  * Destroy a set, and free all resources associated with it.
362  *
363  * @param set the set to destroy
364  */
365 static void
366 set_destroy (struct Set *set)
367 {
368   /* If the client is not dead yet, destroy it.
369    * The client's destroy callback will destroy the set again.
370    * We do this so that the channel end handler still has a valid set handle
371    * to destroy. */
372   if (NULL != set->client)
373   {
374     struct GNUNET_SERVER_Client *client = set->client;
375     set->client = NULL;
376     GNUNET_SERVER_client_disconnect (client);
377     return;
378   }
379   GNUNET_assert (NULL != set->state);
380   while (NULL != set->ops_head)
381     _GSS_operation_destroy (set->ops_head);
382   set->vt->destroy_set (set->state);
383   set->state = NULL;
384   if (NULL != set->client_mq)
385   {
386     GNUNET_MQ_destroy (set->client_mq);
387     set->client_mq = NULL;
388   }
389   if (NULL != set->iter)
390   {
391     GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter);
392     set->iter = NULL;
393   }
394   GNUNET_CONTAINER_DLL_remove (sets_head, sets_tail, set);
395   if (NULL != set->elements)
396   {
397     // free all elements in the hashtable, before destroying the table
398     GNUNET_CONTAINER_multihashmap_iterate (set->elements,
399                                            destroy_elements_iterator, NULL);
400     GNUNET_CONTAINER_multihashmap_destroy (set->elements);
401     set->elements = NULL;
402   }
403   GNUNET_free (set);
404 }
405
406
407 /**
408  * Clean up after a client has disconnected
409  *
410  * @param cls closure, unused
411  * @param client the client to clean up after
412  */
413 static void
414 handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
415 {
416   struct Set *set;
417   struct Listener *listener;
418
419   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
420               "client disconnected, cleaning up\n");
421   set = set_get (client);
422   if (NULL != set)
423   {
424     set->client = NULL;
425     set_destroy (set);
426     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
427                 "(client's set destroyed)\n");
428   }
429   listener = listener_get (client);
430   if (NULL != listener)
431   {
432     listener->client = NULL;
433     listener_destroy (listener);
434     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
435                 "(client's listener destroyed)\n");
436   }
437 }
438
439
440 /**
441  * Destroy an incoming request from a remote peer
442  *
443  * @param incoming remote request to destroy
444  */
445 static void
446 incoming_destroy (struct Operation *incoming)
447 {
448   GNUNET_assert (GNUNET_YES == incoming->is_incoming);
449   GNUNET_CONTAINER_DLL_remove (incoming_head, incoming_tail, incoming);
450   if (GNUNET_SCHEDULER_NO_TASK != incoming->state->timeout_task)
451   {
452     GNUNET_SCHEDULER_cancel (incoming->state->timeout_task);
453     incoming->state->timeout_task = GNUNET_SCHEDULER_NO_TASK;
454   }
455   GNUNET_assert (NULL != incoming->state);
456   GNUNET_free (incoming->state);
457   // make sure that the tunnel end handler will not
458   // destroy us again
459   incoming->vt = NULL;
460   incoming->state = NULL;
461 }
462
463
464 /**
465  * remove & free state of the operation from the incoming list
466  *
467  * @param incoming the element to remove
468  */
469 static void
470 incoming_retire (struct Operation *incoming)
471 {
472   GNUNET_assert (GNUNET_YES == incoming->is_incoming);
473   incoming->is_incoming = GNUNET_NO;
474   GNUNET_assert (NULL != incoming->state);
475   GNUNET_free (incoming->state);
476   incoming->state = NULL;
477   GNUNET_CONTAINER_DLL_remove (incoming_head, incoming_tail, incoming);
478 }
479
480
481 /**
482  * Find a listener that is interested in the given operation type
483  * and application id.
484  *
485  * @param op operation type to look for
486  * @param app_id application id to look for
487  * @return a matching listener, or NULL if no listener matches the
488  *         given operation and application id
489  */
490 static struct Listener *
491 listener_get_by_target (enum GNUNET_SET_OperationType op,
492                         const struct GNUNET_HashCode *app_id)
493 {
494   struct Listener *l;
495
496   for (l = listeners_head; NULL != l; l = l->next)
497   {
498     if (l->operation != op)
499       continue;
500     if (0 != GNUNET_CRYPTO_hash_cmp (app_id, &l->app_id))
501       continue;
502     return l;
503   }
504   return NULL;
505 }
506
507
508 /**
509  * Suggest the given request to the listener. The listening client can then
510  * accept or reject the remote request.
511  *
512  * @param incoming the incoming peer with the request to suggest
513  * @param listener the listener to suggest the request to
514  */
515 static void
516 incoming_suggest (struct Operation *incoming, struct Listener *listener)
517 {
518   struct GNUNET_MQ_Envelope *mqm;
519   struct GNUNET_SET_RequestMessage *cmsg;
520   
521   GNUNET_assert (GNUNET_YES == incoming->is_incoming);
522   GNUNET_assert (NULL != incoming->state);
523   GNUNET_assert (NULL != incoming->spec);
524   GNUNET_assert (0 == incoming->state->suggest_id);
525   incoming->state->suggest_id = suggest_id++;
526
527   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != incoming->state->timeout_task);
528   GNUNET_SCHEDULER_cancel (incoming->state->timeout_task);
529   incoming->state->timeout_task = GNUNET_SCHEDULER_NO_TASK;
530
531   mqm = GNUNET_MQ_msg_nested_mh (cmsg, GNUNET_MESSAGE_TYPE_SET_REQUEST,
532                                  incoming->spec->context_msg);
533   GNUNET_assert (NULL != mqm);
534   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "suggesting request with accept id %u\n",
535               incoming->state->suggest_id);
536   cmsg->accept_id = htonl (incoming->state->suggest_id);
537   cmsg->peer_id = incoming->spec->peer;
538   GNUNET_MQ_send (listener->client_mq, mqm);
539 }
540
541
542 /**
543  * Handle a request for a set operation from
544  * another peer.
545  *
546  * This msg is expected as the first and only msg handled through the
547  * non-operation bound virtual table, acceptance of this operation replaces
548  * our virtual table and subsequent msgs would be routed differently.
549  *
550  * @param op the operation state
551  * @param mh the received message
552  * @return #GNUNET_OK if the channel should be kept alive,
553  *         #GNUNET_SYSERR to destroy the channel
554  */
555 static int
556 handle_incoming_msg (struct Operation *op,
557                      const struct GNUNET_MessageHeader *mh)
558 {
559   const struct OperationRequestMessage *msg = (const struct OperationRequestMessage *) mh;
560   struct Listener *listener;
561   struct OperationSpecification *spec;
562
563   GNUNET_assert (GNUNET_YES == op->is_incoming);
564
565   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got op request\n");
566
567   if (GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST != ntohs (mh->type))
568   {
569     GNUNET_break_op (0);
570     return GNUNET_SYSERR;
571   }
572
573   /* double operation request */
574   if (NULL != op->spec)
575   {
576     GNUNET_break_op (0);
577     return GNUNET_SYSERR;
578   }
579
580   spec = GNUNET_new (struct OperationSpecification);
581   spec->context_msg = GNUNET_MQ_extract_nested_mh (msg);
582   // for simplicity we just backup the context msg instead of rebuilding it later on
583   if (NULL != spec->context_msg)
584     spec->context_msg = GNUNET_copy_message (spec->context_msg);
585   spec->operation = ntohl (msg->operation);
586   spec->app_id = msg->app_id;
587   spec->salt = ntohl (msg->salt);
588   spec->peer = op->state->peer;
589   spec->remote_element_count = ntohl (msg->element_count);
590
591   op->spec = spec;
592
593   if ( (NULL != spec->context_msg) &&
594        (ntohs (spec->context_msg->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE) )
595   {
596     GNUNET_break_op (0);
597     return GNUNET_SYSERR;
598   }
599
600   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "received P2P operation request (op %u, app %s)\n",
601               ntohl (msg->operation), GNUNET_h2s (&msg->app_id));
602   listener = listener_get_by_target (ntohl (msg->operation), &msg->app_id);
603   if (NULL == listener)
604   {
605     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
606                 "no listener matches incoming request, waiting with timeout\n");
607     return GNUNET_OK;
608   }
609   incoming_suggest (op, listener);
610   return GNUNET_OK;
611 }
612
613
614 /**
615  * Send the next element of a set to the set's client.  The next element is given by
616  * the set's current hashmap iterator.  The set's iterator will be set to NULL if there
617  * are no more elements in the set.  The caller must ensure that the set's iterator is
618  * valid.
619  *
620  * @param set set that should send its next element to its client
621  */
622 static void
623 send_client_element (struct Set *set)
624 {
625   int ret;
626   struct ElementEntry *ee;
627   struct GNUNET_MQ_Envelope *ev;
628
629   GNUNET_assert (NULL != set->iter);
630   ret = GNUNET_CONTAINER_multihashmap_iterator_next (set->iter, NULL, (const void **) &ee);
631   if (GNUNET_NO == ret)
632   {
633     ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_DONE);
634     GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter);
635     set->iter = NULL;
636   }
637   else
638   {
639     struct GNUNET_SET_IterResponseMessage *msg;
640
641     GNUNET_assert (NULL != ee);
642     ev = GNUNET_MQ_msg_extra (msg, ee->element.size, GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT);
643     memcpy (&msg[1], ee->element.data, ee->element.size);
644     msg->element_type = ee->element.type;
645   }
646   GNUNET_MQ_send (set->client_mq, ev);
647 }
648
649
650 /**
651  * Called when a client wants to iterate the elements of a set.
652  *
653  * @param cls unused
654  * @param client client that sent the message
655  * @param m message sent by the client
656  */
657 static void
658 handle_client_iterate (void *cls,
659                        struct GNUNET_SERVER_Client *client,
660                        const struct GNUNET_MessageHeader *m)
661 {
662   struct Set *set;
663
664   // iterate over a non existing set
665   set = set_get (client);
666   if (NULL == set)
667   {
668     GNUNET_break (0);
669     GNUNET_SERVER_client_disconnect (client);
670     return;
671   }
672
673   // only one concurrent iterate-action per set
674   if (NULL != set->iter)
675   {
676     GNUNET_break (0);
677     GNUNET_SERVER_client_disconnect (client);
678     return;
679   }
680   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "iterating union set with %u elements\n",
681               GNUNET_CONTAINER_multihashmap_size (set->elements));
682   GNUNET_SERVER_receive_done (client, GNUNET_OK);
683   set->iter = GNUNET_CONTAINER_multihashmap_iterator_create (set->elements);
684   send_client_element (set);
685 }
686
687
688 /**
689  * Called when a client wants to create a new set.
690  *
691  * @param cls unused
692  * @param client client that sent the message
693  * @param m message sent by the client
694  */
695 static void
696 handle_client_create_set (void *cls,
697                           struct GNUNET_SERVER_Client *client,
698                           const struct GNUNET_MessageHeader *m)
699 {
700   const struct GNUNET_SET_CreateMessage *msg;
701   struct Set *set;
702
703   msg = (const struct GNUNET_SET_CreateMessage *) m;
704   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
705               "client created new set (operation %u)\n",
706               ntohs (msg->operation));
707
708   // max. one set per client!
709   if (NULL != set_get (client))
710   {
711     GNUNET_break (0);
712     GNUNET_SERVER_client_disconnect (client);
713     return;
714   }
715
716   set = GNUNET_new (struct Set);
717
718   switch (ntohs (msg->operation))
719   {
720   case GNUNET_SET_OPERATION_INTERSECTION:
721     // FIXME: implement intersection vt
722     // set->vt = _GSS_intersection_vt ();
723     break;
724   case GNUNET_SET_OPERATION_UNION:
725     set->vt = _GSS_union_vt ();
726     break;
727   default:
728     GNUNET_free (set);
729     GNUNET_break (0);
730     GNUNET_SERVER_client_disconnect (client);
731     return;
732   }
733
734   set->state = set->vt->create ();
735   set->elements = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
736   set->client = client;
737   set->client_mq = GNUNET_MQ_queue_for_server_client (client);
738   GNUNET_CONTAINER_DLL_insert (sets_head, sets_tail, set);
739   GNUNET_SERVER_receive_done (client, GNUNET_OK);
740 }
741
742
743 /**
744  * Called when a client wants to create a new listener.
745  *
746  * @param cls unused
747  * @param client client that sent the message
748  * @param m message sent by the client
749  */
750 static void
751 handle_client_listen (void *cls,
752                       struct GNUNET_SERVER_Client *client,
753                       const struct GNUNET_MessageHeader *m)
754 {
755   const struct GNUNET_SET_ListenMessage *msg;
756   struct Listener *listener;
757   struct Operation *op;
758
759   msg = (const struct GNUNET_SET_ListenMessage *) m;
760   /* max. one per client! */
761   if (NULL != listener_get (client))
762   {
763     GNUNET_break (0);
764     GNUNET_SERVER_client_disconnect (client);
765     return;
766   }
767
768   listener = GNUNET_new (struct Listener);
769   listener->client = client;
770   listener->client_mq = GNUNET_MQ_queue_for_server_client (client);
771   listener->app_id = msg->app_id;
772   listener->operation = ntohl (msg->operation);
773   GNUNET_CONTAINER_DLL_insert_tail (listeners_head, listeners_tail, listener);
774   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
775               "new listener created (op %u, app %s)\n",
776               listener->operation,
777               GNUNET_h2s (&listener->app_id));
778
779   /* check for incoming requests the listener is interested in */
780   for (op = incoming_head; NULL != op; op = op->next)
781   {
782     if (NULL == op->spec)
783     {
784       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
785                   "request has no spec yet\n");
786       continue;
787     }
788     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
789                 "considering (op: %u, app: %s, suggest: %u)\n",
790                 op->spec->operation,
791                 GNUNET_h2s (&op->spec->app_id),
792                 op->state->suggest_id);
793
794     /* don't consider the incoming request if it has been already suggested to a listener */
795     if (0 != op->state->suggest_id)
796       continue;
797     if (listener->operation != op->spec->operation)
798       continue;
799     if (0 != GNUNET_CRYPTO_hash_cmp (&listener->app_id, &op->spec->app_id))
800       continue;
801     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
802                 "request suggested\n");
803     incoming_suggest (op, listener);
804   }
805   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
806               "considered all incoming requests\n");
807   GNUNET_SERVER_receive_done (client, GNUNET_OK);
808 }
809
810
811 /**
812  * Called when the listening client rejects an operation
813  * request by another peer.
814  *
815  * @param cls unused
816  * @param client client that sent the message
817  * @param m message sent by the client
818  */
819 static void
820 handle_client_reject (void *cls,
821                       struct GNUNET_SERVER_Client *client,
822                       const struct GNUNET_MessageHeader *m)
823 {
824   struct Operation *incoming;
825   const struct GNUNET_SET_AcceptRejectMessage *msg;
826
827   msg = (const struct GNUNET_SET_AcceptRejectMessage *) m;
828   GNUNET_break (0 == ntohl (msg->request_id));
829
830   // no matching incoming operation for this reject
831   incoming = get_incoming (ntohl (msg->accept_reject_id));
832   if (NULL == incoming)
833   {
834     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
835     return;
836   }
837   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
838               "peer request rejected by client\n");
839
840   GNUNET_MESH_channel_destroy (incoming->channel);
841   //channel destruction handler called immediately upon destruction
842   GNUNET_SERVER_receive_done (client, GNUNET_OK);
843 }
844
845
846 /**
847  * Called when a client wants to add/remove an element to/from a
848  * set it inhabits.
849  *
850  * @param cls unused
851  * @param client client that sent the message
852  * @param m message sent by the client
853  */
854 static void
855 handle_client_add_remove (void *cls,
856                           struct GNUNET_SERVER_Client *client,
857                           const struct GNUNET_MessageHeader *m)
858 {
859   struct Set *set;
860   const struct GNUNET_SET_ElementMessage *msg;
861   struct GNUNET_SET_Element el;
862   struct ElementEntry *ee;
863
864   // client without a set requested an operation
865   set = set_get (client);
866   if (NULL == set)
867   {
868     GNUNET_break (0);
869     GNUNET_SERVER_client_disconnect (client);
870     return;
871   }
872   GNUNET_SERVER_receive_done (client, GNUNET_OK);
873   msg = (const struct GNUNET_SET_ElementMessage *) m;
874   el.size = ntohs (m->size) - sizeof *msg;
875   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
876               "client ins/rem element of size %u\n", el.size);
877   el.data = &msg[1];
878   if (GNUNET_MESSAGE_TYPE_SET_REMOVE == ntohs (m->type))
879   {
880     struct GNUNET_HashCode hash;
881
882     GNUNET_CRYPTO_hash (el.data, el.size, &hash);
883     ee = GNUNET_CONTAINER_multihashmap_get (set->elements, &hash);
884     if (NULL == ee)
885     {
886       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
887                   "client tried to remove non-existing element\n");
888       return;
889     }
890     if (GNUNET_YES == ee->removed)
891     {
892       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
893                   "client tried to remove element twice\n");
894       return;
895     }
896     ee->removed = GNUNET_YES;
897     ee->generation_removed = set->current_generation;
898     set->vt->remove (set->state, ee);
899   }
900   else
901   {
902     struct ElementEntry *ee_dup;
903
904     ee = GNUNET_malloc (el.size + sizeof *ee);
905     ee->element.size = el.size;
906     memcpy (&ee[1], el.data, el.size);
907     ee->element.data = &ee[1];
908     ee->generation_added = set->current_generation;
909     ee->remote = GNUNET_NO;
910     GNUNET_CRYPTO_hash (ee->element.data, el.size, &ee->element_hash);
911     ee_dup = GNUNET_CONTAINER_multihashmap_get (set->elements,
912                                                 &ee->element_hash);
913     if (NULL != ee_dup)
914     {
915       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
916                   "element inserted twice, ignoring\n");
917       GNUNET_free (ee);
918       return;
919     }
920     GNUNET_CONTAINER_multihashmap_put (set->elements, &ee->element_hash, ee,
921                                        GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
922     set->vt->add (set->state, ee);
923   }
924 }
925
926
927 /**
928  * Called when a client wants to evaluate a set operation with another peer.
929  *
930  * @param cls unused
931  * @param client client that sent the message
932  * @param m message sent by the client
933  */
934 static void
935 handle_client_evaluate (void *cls,
936                         struct GNUNET_SERVER_Client *client,
937                         const struct GNUNET_MessageHeader *m)
938 {
939   struct Set *set;
940   const struct GNUNET_SET_EvaluateMessage *msg;
941   struct OperationSpecification *spec;
942   struct Operation *op;
943
944   set = set_get (client);
945   if (NULL == set)
946   {
947     GNUNET_break (0);
948     GNUNET_SERVER_client_disconnect (client);
949     return;
950   }
951
952   msg = (const struct GNUNET_SET_EvaluateMessage *) m;
953   spec = GNUNET_new (struct OperationSpecification);
954   spec->operation = set->operation;
955   spec->app_id = msg->app_id;
956   spec->salt = ntohl (msg->salt);
957   spec->peer = msg->target_peer;
958   spec->set = set;
959   spec->result_mode = ntohs (msg->result_mode);
960   spec->client_request_id = ntohl (msg->request_id);
961   spec->context_msg = GNUNET_MQ_extract_nested_mh (msg);
962
963   // for simplicity we just backup the context msg instead of rebuilding it later on
964   if (NULL != spec->context_msg)
965     spec->context_msg = GNUNET_copy_message (spec->context_msg);
966
967   op = GNUNET_new (struct Operation);
968   op->spec = spec;
969   op->generation_created = set->current_generation++;
970   op->vt = set->vt;
971   GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op);
972
973   op->channel = GNUNET_MESH_channel_create (mesh, op, &msg->target_peer,
974                                             GNUNET_APPLICATION_TYPE_SET,
975                                             GNUNET_MESH_OPTION_RELIABLE);
976
977   op->mq = GNUNET_MESH_mq_create (op->channel);
978
979   set->vt->evaluate (op);
980   GNUNET_SERVER_receive_done (client, GNUNET_OK);
981 }
982
983
984 /**
985  * Handle an ack from a client, and send the next element.
986  *
987  * @param cls unused
988  * @param client the client
989  * @param m the message
990  */
991 static void
992 handle_client_iter_ack (void *cls,
993                    struct GNUNET_SERVER_Client *client,
994                    const struct GNUNET_MessageHeader *m)
995 {
996   struct Set *set;
997
998   // client without a set requested an operation
999   set = set_get (client);
1000   if (NULL == set)
1001   {
1002     GNUNET_break (0);
1003     GNUNET_SERVER_client_disconnect (client);
1004     return;
1005   }
1006
1007   // client sent an ack, but we were not expecting one
1008   if (NULL == set->iter)
1009   {
1010     GNUNET_break (0);
1011     GNUNET_SERVER_client_disconnect (client);
1012     return;
1013   }
1014
1015   GNUNET_SERVER_receive_done (client, GNUNET_OK);
1016   send_client_element (set);
1017 }
1018
1019
1020 /**
1021  * Handle a request from the client to
1022  * cancel a running set operation.
1023  *
1024  * @param cls unused
1025  * @param client the client
1026  * @param mh the message
1027  */
1028 static void
1029 handle_client_cancel (void *cls,
1030                       struct GNUNET_SERVER_Client *client,
1031                       const struct GNUNET_MessageHeader *mh)
1032 {
1033   const struct GNUNET_SET_CancelMessage *msg =
1034       (const struct GNUNET_SET_CancelMessage *) mh;
1035   struct Set *set;
1036   struct Operation *op;
1037   int found;
1038
1039   // client without a set requested an operation
1040   set = set_get (client);
1041   if (NULL == set)
1042   {
1043     GNUNET_break (0);
1044     GNUNET_SERVER_client_disconnect (client);
1045     return;
1046   }
1047   found = GNUNET_NO;
1048   for (op = set->ops_head; NULL != op; op = op->next)
1049   {
1050     if (op->spec->client_request_id == msg->request_id)
1051     {
1052       found = GNUNET_YES;
1053       break;
1054     }
1055   }
1056
1057   if (GNUNET_NO == found)
1058   {
1059     GNUNET_break (0);
1060     GNUNET_SERVER_client_disconnect (client);
1061     return;
1062   }
1063
1064   _GSS_operation_destroy (op);
1065 }
1066
1067
1068 /**
1069  * Handle a request from the client to accept
1070  * a set operation that came from a remote peer.
1071  * We forward the accept to the associated operation for handling
1072  *
1073  * @param cls unused
1074  * @param client the client
1075  * @param mh the message
1076  */
1077 static void
1078 handle_client_accept (void *cls,
1079                       struct GNUNET_SERVER_Client *client,
1080                       const struct GNUNET_MessageHeader *mh)
1081 {
1082   struct Set *set;
1083   const struct GNUNET_SET_AcceptRejectMessage *msg;
1084   struct Operation *op;
1085
1086   msg = (const struct GNUNET_SET_AcceptRejectMessage *) mh;
1087   op = get_incoming (ntohl (msg->accept_reject_id));
1088
1089   // incoming operation does not exist
1090   if (NULL == op)
1091   {
1092     GNUNET_break (0);
1093     GNUNET_SERVER_client_disconnect (client);
1094     return;
1095   }
1096
1097   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1098               "client accepting %u\n",
1099               ntohl (msg->accept_reject_id));
1100
1101   GNUNET_assert (GNUNET_YES == op->is_incoming);
1102
1103   // client without a set requested an operation
1104   set = set_get (client);
1105
1106   if (NULL == set)
1107   {
1108     GNUNET_break (0);
1109     GNUNET_SERVER_client_disconnect (client);
1110     return;
1111   }
1112
1113   op->spec->set = set;
1114
1115   incoming_retire (op);
1116
1117   GNUNET_assert (NULL != op->spec->set);
1118   GNUNET_assert (NULL != op->spec->set->vt);
1119
1120   GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op);
1121
1122   op->spec->client_request_id = ntohl (msg->request_id);
1123   op->spec->result_mode = ntohs (msg->result_mode);
1124   op->generation_created = set->current_generation++;
1125   op->vt = op->spec->set->vt;
1126   GNUNET_assert (NULL != op->vt->accept);
1127   set->vt->accept (op);
1128   GNUNET_SERVER_receive_done (client, GNUNET_OK);
1129 }
1130
1131
1132 /**
1133  * Called to clean up, after a shutdown has been requested.
1134  *
1135  * @param cls closure
1136  * @param tc context information (why was this task triggered now)
1137  */
1138 static void
1139 shutdown_task (void *cls,
1140                const struct GNUNET_SCHEDULER_TaskContext *tc)
1141 {
1142   while (NULL != incoming_head)
1143     incoming_destroy (incoming_head);
1144
1145   while (NULL != listeners_head)
1146     listener_destroy (listeners_head);
1147
1148   while (NULL != sets_head)
1149     set_destroy (sets_head);
1150
1151   /* it's important to destroy mesh at the end, as all channels
1152    * must be destroyed before the mesh handle! */
1153   if (NULL != mesh)
1154   {
1155     GNUNET_MESH_disconnect (mesh);
1156     mesh = NULL;
1157   }
1158   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1159               "handled shutdown request\n");
1160 }
1161
1162
1163 /**
1164  * Timeout happens iff:
1165  *  - we suggested an operation to our listener,
1166  *    but did not receive a response in time
1167  *  - we got the channel from a peer but no #GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST
1168  *  - shutdown (obviously)
1169  *
1170  * @param cls channel context
1171  * @param tc context information (why was this task triggered now)
1172  */
1173 static void
1174 incoming_timeout_cb (void *cls,
1175                      const struct GNUNET_SCHEDULER_TaskContext *tc)
1176 {
1177   struct Operation *incoming = cls;
1178
1179   incoming->state->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1180   GNUNET_assert (GNUNET_YES == incoming->is_incoming);
1181   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1182     return;
1183   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1184               "remote peer timed out\n");
1185   incoming_destroy (incoming);
1186 }
1187
1188
1189 /**
1190  * Terminates an incoming operation in case we have not yet received an
1191  * operation request. Called by the channel destruction handler.
1192  *
1193  * @param op the channel context
1194  */
1195 static void
1196 handle_incoming_disconnect (struct Operation *op)
1197 {
1198   GNUNET_assert (GNUNET_YES == op->is_incoming);
1199   incoming_destroy (op);
1200   op->vt = NULL;
1201 }
1202
1203
1204 /**
1205  * Method called whenever another peer has added us to a channel
1206  * the other peer initiated.
1207  * Only called (once) upon reception of data with a message type which was
1208  * subscribed to in GNUNET_MESH_connect().
1209  *
1210  * The channel context represents the operation itself and gets added to a DLL,
1211  * from where it gets looked up when our local listener client responds
1212  * to a proposed/suggested operation or connects and associates with this operation.
1213  *
1214  * @param cls closure
1215  * @param channel new handle to the channel
1216  * @param initiator peer that started the channel
1217  * @param port Port this channel is for.
1218  * @param options Unused.
1219  * @return initial channel context for the channel
1220  *         (can be NULL -- that's not an error)
1221  */
1222 static void *
1223 channel_new_cb (void *cls,
1224                struct GNUNET_MESH_Channel *channel,
1225                const struct GNUNET_PeerIdentity *initiator,
1226                uint32_t port, enum GNUNET_MESH_ChannelOption options)
1227 {
1228   struct Operation *incoming;
1229   static const struct SetVT incoming_vt = {
1230     .msg_handler = handle_incoming_msg,
1231     .peer_disconnect = handle_incoming_disconnect
1232   };
1233
1234   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1235               "new incoming channel\n");
1236
1237   if (GNUNET_APPLICATION_TYPE_SET != port)
1238   {
1239     GNUNET_break (0);
1240     GNUNET_MESH_channel_destroy (channel);
1241     return NULL;
1242   }
1243
1244   incoming = GNUNET_new (struct Operation);
1245   incoming->is_incoming = GNUNET_YES;
1246   incoming->state = GNUNET_new (struct OperationState);
1247   incoming->state->peer = *initiator;
1248   incoming->channel = channel;
1249   incoming->mq = GNUNET_MESH_mq_create (incoming->channel);
1250   incoming->vt = &incoming_vt;
1251   incoming->state->timeout_task =
1252       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1253                                     &incoming_timeout_cb, incoming);
1254   GNUNET_CONTAINER_DLL_insert_tail (incoming_head, incoming_tail, incoming);
1255
1256   return incoming;
1257 }
1258
1259
1260 /**
1261  * Function called whenever a channel is destroyed.  Should clean up
1262  * any associated state.  It must NOT call
1263  * GNUNET_MESH_channel_destroy() on the channel.
1264  *
1265  * The peer_disconnect function is part of a a virtual table set initially either
1266  * when a peer creates a new channel with us (channel_new_cb), or once we create
1267  * a new channel ourselves (evaluate).
1268  *
1269  * Once we know the exact type of operation (union/intersection), the vt is
1270  * replaced with an operation specific instance (_GSS_[op]_vt).
1271  *
1272  * @param cls closure (set from GNUNET_MESH_connect())
1273  * @param channel connection to the other end (henceforth invalid)
1274  * @param channel_ctx place where local state associated
1275  *                   with the channel is stored
1276  */
1277 static void
1278 channel_end_cb (void *cls,
1279                 const struct GNUNET_MESH_Channel *channel, void *channel_ctx)
1280 {
1281   struct Operation *op = channel_ctx;
1282
1283   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1284               "channel end cb called\n");
1285   op->channel = NULL;
1286   /* the vt can be null if a client already requested canceling op. */
1287   if (NULL != op->vt)
1288   {
1289     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1290                 "calling peer disconnect due to channel end\n");
1291     op->vt->peer_disconnect (op);
1292   }
1293
1294   if (GNUNET_YES == op->keep)
1295     return;
1296
1297   /* mesh will never call us with the context again! */
1298   GNUNET_free (channel_ctx);
1299   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1300               "channel end cb finished\n");
1301 }
1302
1303
1304 /**
1305  * Functions with this signature are called whenever a message is
1306  * received via a mesh channel.
1307  *
1308  * The msg_handler is a virtual table set in initially either when a peer
1309  * creates a new channel with us (channel_new_cb), or once we create a new channel
1310  * ourselves (evaluate).
1311  *
1312  * Once we know the exact type of operation (union/intersection), the vt is
1313  * replaced with an operation specific instance (_GSS_[op]_vt).
1314  *
1315  * @param cls Closure (set from GNUNET_MESH_connect()).
1316  * @param channel Connection to the other end.
1317  * @param channel_ctx Place to store local state associated with the channel.
1318  * @param message The actual message.
1319  * @return #GNUNET_OK to keep the channel open,
1320  *         #GNUNET_SYSERR to close it (signal serious error).
1321  */
1322 static int
1323 dispatch_p2p_message (void *cls,
1324                       struct GNUNET_MESH_Channel *channel,
1325                       void **channel_ctx,
1326                       const struct GNUNET_MessageHeader *message)
1327 {
1328   struct Operation *op = *channel_ctx;
1329   int ret;
1330
1331   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1332               "dispatching mesh message (type: %u)\n",
1333               ntohs (message->type));
1334   /* do this before the handler, as the handler might kill the channel */
1335   GNUNET_MESH_receive_done (channel);
1336   ret = op->vt->msg_handler (op, message);
1337   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1338               "handled mesh message (type: %u)\n",
1339               ntohs (message->type));
1340   return ret;
1341 }
1342
1343
1344 /**
1345  * Function called by the service's run
1346  * method to run service-specific setup code.
1347  *
1348  * @param cls closure
1349  * @param server the initialized server
1350  * @param cfg configuration to use
1351  */
1352 static void
1353 run (void *cls, struct GNUNET_SERVER_Handle *server,
1354      const struct GNUNET_CONFIGURATION_Handle *cfg)
1355 {
1356   static const struct GNUNET_SERVER_MessageHandler server_handlers[] = {
1357     {handle_client_accept, NULL, GNUNET_MESSAGE_TYPE_SET_ACCEPT,
1358         sizeof (struct GNUNET_SET_AcceptRejectMessage)},
1359     {handle_client_iter_ack, NULL, GNUNET_MESSAGE_TYPE_SET_ITER_ACK, 0},
1360     {handle_client_add_remove, NULL, GNUNET_MESSAGE_TYPE_SET_ADD, 0},
1361     {handle_client_create_set, NULL, GNUNET_MESSAGE_TYPE_SET_CREATE,
1362         sizeof (struct GNUNET_SET_CreateMessage)},
1363     {handle_client_iterate, NULL, GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST,
1364         sizeof (struct GNUNET_MessageHeader)},
1365     {handle_client_evaluate, NULL, GNUNET_MESSAGE_TYPE_SET_EVALUATE, 0},
1366     {handle_client_listen, NULL, GNUNET_MESSAGE_TYPE_SET_LISTEN,
1367         sizeof (struct GNUNET_SET_ListenMessage)},
1368     {handle_client_reject, NULL, GNUNET_MESSAGE_TYPE_SET_REJECT,
1369         sizeof (struct GNUNET_SET_AcceptRejectMessage)},
1370     {handle_client_add_remove, NULL, GNUNET_MESSAGE_TYPE_SET_REMOVE, 0},
1371     {handle_client_cancel, NULL, GNUNET_MESSAGE_TYPE_SET_CANCEL,
1372         sizeof (struct GNUNET_SET_CancelMessage)},
1373     {NULL, NULL, 0, 0}
1374   };
1375   static const struct GNUNET_MESH_MessageHandler mesh_handlers[] = {
1376     {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 0},
1377     {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, 0},
1378     {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 0},
1379     {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_DONE, 0},
1380     {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENT_REQUESTS, 0},
1381     {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, 0},
1382     {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, 0},
1383     {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, 0},
1384     {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF_PART, 0},
1385     {NULL, 0, 0}
1386   };
1387   static const uint32_t mesh_ports[] = {GNUNET_APPLICATION_TYPE_SET, 0};
1388
1389   configuration = cfg;
1390   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1391                                 &shutdown_task, NULL);
1392   GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
1393   GNUNET_SERVER_add_handlers (server, server_handlers);
1394
1395   mesh = GNUNET_MESH_connect (cfg, NULL, channel_new_cb, channel_end_cb,
1396                               mesh_handlers, mesh_ports);
1397   if (NULL == mesh)
1398   {
1399     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1400                 _("Could not connect to mesh service\n"));
1401     return;
1402   }
1403 }
1404
1405
1406 /**
1407  * The main function for the set service.
1408  *
1409  * @param argc number of arguments from the command line
1410  * @param argv command line arguments
1411  * @return 0 ok, 1 on error
1412  */
1413 int
1414 main (int argc, char *const *argv)
1415 {
1416   int ret;
1417
1418   ret = GNUNET_SERVICE_run (argc, argv, "set",
1419                             GNUNET_SERVICE_OPTION_NONE, &run, NULL);
1420   return (GNUNET_OK == ret) ? 0 : 1;
1421 }
1422
1423 /* end of gnunet-service-set.c */
1424