bf04c8bf43d0fa1490143298c06bd78857a9b1f2
[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 2, 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  * Configuration of our local peer.
32  * (Not declared 'static' as also needed in gnunet-service-set_union.c)
33  */
34 const struct GNUNET_CONFIGURATION_Handle *configuration;
35
36 /**
37  * Handle to the mesh service, used
38  * to listen for and connect to remote peers.
39  * (Not declared 'static' as also needed in gnunet-service-set_union.c)
40  */
41 struct GNUNET_MESH_Handle *mesh;
42
43 /**
44  * Sets are held in a doubly linked list.
45  */
46 static struct Set *sets_head;
47
48 /**
49  * Sets are held in a doubly linked list.
50  */
51 static struct Set *sets_tail;
52
53 /**
54  * Listeners are held in a doubly linked list.
55  */
56 static struct Listener *listeners_head;
57
58 /**
59  * Listeners are held in a doubly linked list.
60  */
61 static struct Listener *listeners_tail;
62
63 /**
64  * Incoming sockets from remote peers are
65  * held in a doubly linked list.
66  */
67 static struct Incoming *incoming_head;
68
69 /**
70  * Incoming sockets from remote peers are
71  * held in a doubly linked list.
72  */
73 static struct Incoming *incoming_tail;
74
75 /**
76  * Counter for allocating unique IDs for clients,
77  * used to identify incoming operation requests from remote peers,
78  * that the client can choose to accept or refuse.
79  */
80 static uint32_t accept_id = 1;
81
82
83 /**
84  * Get set that is owned by the given client, if any.
85  *
86  * @param client client to look for
87  * @return set that the client owns, NULL if the client
88  *         does not own a set
89  */
90 static struct Set *
91 set_get (struct GNUNET_SERVER_Client *client)
92 {
93   struct Set *set;
94   for (set = sets_head; NULL != set; set = set->next)
95     if (set->client == client)
96       return set;
97   return NULL;
98 }
99
100
101 /**
102  * Get the listener associated to a client, if any.
103  *
104  * @param client the client
105  * @return listener associated with the client, NULL
106  *         if there isn't any
107  */
108 static struct Listener *
109 get_listener (struct GNUNET_SERVER_Client *client)
110 {
111   struct Listener *listener;
112   for (listener = listeners_head; NULL != listener; listener = listener->next)
113     if (listener->client == client)
114       return listener;
115   return NULL;
116 }
117
118
119 /**
120  * Get the incoming socket associated with the given id.
121  *
122  * @param id id to look for
123  * @return the incoming socket associated with the id,
124  *         or NULL if there is none
125  */
126 static struct Incoming *
127 get_incoming (uint32_t id)
128 {
129   struct Incoming *incoming;
130   for (incoming = incoming_head; NULL != incoming; incoming = incoming->next)
131     if (incoming->accept_id == id)
132       return incoming;
133   return NULL;
134 }
135
136
137 /**
138  * Destroy a listener, free all resources associated with it.
139  *
140  * @param listener listener to destroy
141  */
142 static void
143 listener_destroy (struct Listener *listener)
144 {
145   if (NULL != listener->client_mq)
146   {
147     GNUNET_MQ_destroy (listener->client_mq);
148     listener->client_mq = NULL;
149   }
150   GNUNET_CONTAINER_DLL_remove (listeners_head, listeners_tail, listener);
151   GNUNET_free (listener);
152 }
153
154
155 /**
156  * Destroy a set, and free all resources associated with it.
157  *
158  * @param set the set to destroy
159  */
160 static void
161 set_destroy (struct Set *set)
162 {
163   switch (set->operation)
164   {
165     case GNUNET_SET_OPERATION_INTERSECTION:
166       GNUNET_assert (0);
167       break;
168     case GNUNET_SET_OPERATION_UNION:
169       _GSS_union_set_destroy (set);
170       break;
171     default:
172       GNUNET_assert (0);
173       break;
174   }
175   GNUNET_CONTAINER_DLL_remove (sets_head, sets_tail, set);
176   GNUNET_free (set);
177 }
178
179
180 /**
181  * Clean up after a client after it is
182  * disconnected (either by us or by itself)
183  *
184  * @param cls closure, unused
185  * @param client the client to clean up after
186  */
187 static void
188 handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
189 {
190   struct Set *set;
191   struct Listener *listener;
192
193   set = set_get (client);
194   if (NULL != set)
195     set_destroy (set);
196   listener = get_listener (client);
197   if (NULL != listener)
198     listener_destroy (listener);
199 }
200
201
202 /**
203  * Destroy an incoming request from a remote peer
204  *
205  * @param incoming remote request to destroy
206  */
207 static void
208 incoming_destroy (struct Incoming *incoming)
209 {
210   if (NULL != incoming->tc)
211   {
212     GNUNET_free (incoming->tc);
213     GNUNET_assert (NULL != incoming->tc->tunnel);
214     GNUNET_MESH_tunnel_destroy (incoming->tc->tunnel);
215     incoming->tc = NULL;
216   }
217   GNUNET_CONTAINER_DLL_remove (incoming_head, incoming_tail, incoming);
218   GNUNET_free (incoming);
219 }
220
221
222 static struct Listener *
223 get_listener_by_target (enum GNUNET_SET_OperationType op,
224                         const struct GNUNET_HashCode *app_id)
225 {
226   struct Listener *l;
227
228   for (l = listeners_head; NULL != l; l = l->next)
229   {
230     if (l->operation != op)
231       continue;
232     if (0 != GNUNET_CRYPTO_hash_cmp (app_id, &l->app_id))
233       continue;
234     return l;
235   }
236   return NULL;
237 }
238
239
240
241 static void
242 tunnel_context_destroy (struct TunnelContext *tc)
243 {
244   GNUNET_free (tc);
245   /* FIXME destroy the rest */
246 }
247
248
249 /**
250  * Handle a request for a set operation from
251  * another peer.
252  *
253  * @param cls the incoming socket
254  * @param mh the message
255  */
256 static int
257 handle_p2p_operation_request (void *cls,
258                               struct GNUNET_MESH_Tunnel *tunnel,
259                               void **tunnel_ctx,
260                               const struct GNUNET_PeerIdentity *sender,
261                               const struct GNUNET_MessageHeader *mh)
262 {
263   struct TunnelContext *tc = *tunnel_ctx;
264   struct Incoming *incoming;
265   const struct OperationRequestMessage *msg = (const struct OperationRequestMessage *) mh;
266   struct GNUNET_MQ_Envelope *mqm;
267   struct GNUNET_SET_RequestMessage *cmsg;
268   struct Listener *listener;
269   const struct GNUNET_MessageHeader *context_msg;
270
271   if (CONTEXT_INCOMING != tc->type)
272   {
273     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "unexpected operation request\n");
274     tunnel_context_destroy (tc);
275     /* don't kill the whole mesh connection */
276     return GNUNET_OK;
277   }
278
279   incoming = tc->data;
280
281   context_msg = GNUNET_MQ_extract_nested_mh (msg);
282   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "received P2P operation request (op %u, app %s)\n",
283               ntohs (msg->operation), GNUNET_h2s (&msg->app_id));
284   listener = get_listener_by_target (ntohs (msg->operation), &msg->app_id);
285   if (NULL == listener)
286   {
287     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
288                 "set operation request from peer failed: "
289                 "no set with matching application ID and operation type\n");
290     tunnel_context_destroy (tc);
291     /* don't kill the whole mesh connection */
292     return GNUNET_OK;
293   }
294   mqm = GNUNET_MQ_msg_nested_mh (cmsg, GNUNET_MESSAGE_TYPE_SET_REQUEST, context_msg);
295   if (NULL == mqm)
296   {
297     /* FIXME: disconnect the peer */
298     GNUNET_break_op (0);
299     tunnel_context_destroy (tc);
300     /* don't kill the whole mesh connection */
301     return GNUNET_OK;
302   }
303   incoming->accept_id = accept_id++;
304   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "sending request with accept id %u\n", incoming->accept_id);
305   cmsg->accept_id = htonl (incoming->accept_id);
306   cmsg->peer_id = incoming->tc->peer;
307   GNUNET_MQ_send (listener->client_mq, mqm);
308
309   return GNUNET_OK;
310 }
311
312
313 /**
314  * Called when a client wants to create a new set.
315  *
316  * @param cls unused
317  * @param client client that sent the message
318  * @param m message sent by the client
319  */
320 static void
321 handle_client_create (void *cls,
322                       struct GNUNET_SERVER_Client *client,
323                       const struct GNUNET_MessageHeader *m)
324 {
325   struct GNUNET_SET_CreateMessage *msg = (struct GNUNET_SET_CreateMessage *) m;
326   struct Set *set;
327
328   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "client created new set (operation %u)\n",
329               ntohs (msg->operation));
330
331   if (NULL != set_get (client))
332   {
333     GNUNET_break (0);
334     GNUNET_SERVER_client_disconnect (client);
335     return;
336   }
337
338   set = NULL;
339
340   switch (ntohs (msg->operation))
341   {
342     case GNUNET_SET_OPERATION_INTERSECTION:
343       set = _GSS_intersection_set_create ();
344       break;
345     case GNUNET_SET_OPERATION_UNION:
346       set = _GSS_union_set_create ();
347       break;
348     default:
349       GNUNET_break (0);
350       GNUNET_SERVER_client_disconnect (client);
351       return;
352   }
353
354   GNUNET_assert (NULL != set);
355
356   set->client = client;
357   set->client_mq = GNUNET_MQ_queue_for_server_client (client);
358   GNUNET_CONTAINER_DLL_insert (sets_head, sets_tail, set);
359   GNUNET_SERVER_receive_done (client, GNUNET_OK);
360 }
361
362
363 /**
364  * Called when a client wants to create a new listener.
365  *
366  * @param cls unused
367  * @param client client that sent the message
368  * @param m message sent by the client
369  */
370 static void
371 handle_client_listen (void *cls,
372                       struct GNUNET_SERVER_Client *client,
373                       const struct GNUNET_MessageHeader *m)
374 {
375   struct GNUNET_SET_ListenMessage *msg = (struct GNUNET_SET_ListenMessage *) m;
376   struct Listener *listener;
377
378   if (NULL != get_listener (client))
379   {
380     GNUNET_break (0);
381     GNUNET_SERVER_client_disconnect (client);
382     return;
383   }
384   listener = GNUNET_new (struct Listener);
385   listener->client = client;
386   listener->client_mq = GNUNET_MQ_queue_for_server_client (client);
387   listener->app_id = msg->app_id;
388   listener->operation = ntohs (msg->operation);
389   GNUNET_CONTAINER_DLL_insert_tail (listeners_head, listeners_tail, listener);
390   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "new listener created (op %u, app %s)\n",
391               listener->operation, GNUNET_h2s (&listener->app_id));
392   GNUNET_SERVER_receive_done (client, GNUNET_OK);
393 }
394
395
396 /**
397  * Called when a client wants to remove an element
398  * from the set it inhabits.
399  *
400  * @param cls unused
401  * @param client client that sent the message
402  * @param m message sent by the client
403  */
404 static void
405 handle_client_remove (void *cls,
406                       struct GNUNET_SERVER_Client *client,
407                       const struct GNUNET_MessageHeader *m)
408 {
409   struct Set *set;
410
411   set = set_get (client);
412   if (NULL == set)
413   {
414     GNUNET_break (0);
415     GNUNET_SERVER_client_disconnect (client);
416     return;
417   }
418   switch (set->operation)
419   {
420     case GNUNET_SET_OPERATION_UNION:
421       _GSS_union_remove ((struct GNUNET_SET_ElementMessage *) m, set);
422       break;
423     case GNUNET_SET_OPERATION_INTERSECTION:
424       _GSS_intersection_remove ((struct GNUNET_SET_ElementMessage *) m, set);
425       break;
426     default:
427       GNUNET_assert (0);
428       break;
429   }
430
431   GNUNET_SERVER_receive_done (client, GNUNET_OK);
432 }
433
434
435
436 /**
437  * Called when the client wants to reject an operation
438  * request from another peer.
439  *
440  * @param cls unused
441  * @param client client that sent the message
442  * @param m message sent by the client
443  */
444 static void
445 handle_client_reject (void *cls,
446                       struct GNUNET_SERVER_Client *client,
447                       const struct GNUNET_MessageHeader *m)
448 {
449   struct Incoming *incoming;
450   struct GNUNET_SET_AcceptRejectMessage *msg = (struct GNUNET_SET_AcceptRejectMessage *) m;
451
452   GNUNET_break (0 == ntohl (msg->request_id));
453
454   incoming = get_incoming (ntohl (msg->accept_reject_id));
455   if (NULL == incoming)
456   {
457     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
458     return;
459   }
460   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "peer request rejected by client\n");
461   incoming_destroy (incoming);
462   GNUNET_SERVER_receive_done (client, GNUNET_OK);
463 }
464
465
466
467 /**
468  * Called when a client wants to add an element to a
469  * set it inhabits.
470  *
471  * @param cls unused
472  * @param client client that sent the message
473  * @param m message sent by the client
474  */
475 static void
476 handle_client_add (void *cls,
477                       struct GNUNET_SERVER_Client *client,
478                       const struct GNUNET_MessageHeader *m)
479 {
480   struct Set *set;
481
482   set = set_get (client);
483   if (NULL == set)
484   {
485     GNUNET_break (0);
486     GNUNET_SERVER_client_disconnect (client);
487     return;
488   }
489   switch (set->operation)
490   {
491     case GNUNET_SET_OPERATION_UNION:
492       _GSS_union_add ((struct GNUNET_SET_ElementMessage *) m, set);
493       break;
494     case GNUNET_SET_OPERATION_INTERSECTION:
495       _GSS_intersection_add ((struct GNUNET_SET_ElementMessage *) m, set);
496       break;
497     default:
498       GNUNET_assert (0);
499       break;
500   }
501
502   GNUNET_SERVER_receive_done (client, GNUNET_OK);
503 }
504
505
506 /**
507  * Called when a client wants to evaluate a set operation with another peer.
508  *
509  * @param cls unused
510  * @param client client that sent the message
511  * @param m message sent by the client
512  */
513 static void
514 handle_client_evaluate (void *cls,
515                         struct GNUNET_SERVER_Client *client,
516                         const struct GNUNET_MessageHeader *m)
517 {
518   struct Set *set;
519
520   set = set_get (client);
521   if (NULL == set)
522   {
523     GNUNET_break (0);
524     GNUNET_SERVER_client_disconnect (client);
525     return;
526   }
527
528
529   switch (set->operation)
530   {
531     case GNUNET_SET_OPERATION_INTERSECTION:
532       _GSS_intersection_evaluate ((struct GNUNET_SET_EvaluateMessage *) m, set);
533       break;
534     case GNUNET_SET_OPERATION_UNION:
535       _GSS_union_evaluate ((struct GNUNET_SET_EvaluateMessage *) m, set);
536       break;
537     default:
538       GNUNET_assert (0);
539       break;
540   }
541
542   GNUNET_SERVER_receive_done (client, GNUNET_OK);
543 }
544
545
546 /**
547  * Handle an ack from a client.
548  *
549  * @param cls unused
550  * @param client the client
551  * @param m the message
552  */
553 static void
554 handle_client_ack (void *cls,
555                    struct GNUNET_SERVER_Client *client,
556                    const struct GNUNET_MessageHeader *m)
557 {
558   /* FIXME: implement */
559   GNUNET_SERVER_receive_done (client, GNUNET_OK);
560 }
561
562
563 /**
564  * Handle a request from the client to accept
565  * a set operation that came from a remote peer.
566  *
567  * @param cls unused
568  * @param client the client
569  * @param mh the message
570  */
571 static void
572 handle_client_accept (void *cls,
573                       struct GNUNET_SERVER_Client *client,
574                       const struct GNUNET_MessageHeader *mh)
575 {
576   struct Set *set;
577   struct Incoming *incoming;
578   struct GNUNET_SET_AcceptRejectMessage *msg = (struct GNUNET_SET_AcceptRejectMessage *) mh;
579
580   incoming = get_incoming (ntohl (msg->accept_reject_id));
581
582   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "client accepting %u\n", ntohl (msg->accept_reject_id));
583
584   if (NULL == incoming)
585   {
586
587     GNUNET_break (0);
588     GNUNET_SERVER_client_disconnect (client);
589     return;
590   }
591
592   set = set_get (client);
593
594   if (NULL == set)
595   {
596     GNUNET_break (0);
597     GNUNET_SERVER_client_disconnect (client);
598     return;
599   }
600
601   switch (set->operation)
602   {
603     case GNUNET_SET_OPERATION_INTERSECTION:
604       _GSS_intersection_accept (msg, set, incoming);
605       break;
606     case GNUNET_SET_OPERATION_UNION:
607       _GSS_union_accept (msg, set, incoming);
608       break;
609     default:
610       GNUNET_assert (0);
611       break;
612   }
613
614   /* note: _GSS_*_accept has to make sure the socket and mq are set to NULL,
615    * otherwise they will be destroyed and disconnected */
616   incoming_destroy (incoming);
617   GNUNET_SERVER_receive_done (client, GNUNET_OK);
618 }
619
620
621 /**
622  * Called to clean up, after a shutdown has been requested.
623  *
624  * @param cls closure
625  * @param tc context information (why was this task triggered now)
626  */
627 static void
628 shutdown_task (void *cls,
629                const struct GNUNET_SCHEDULER_TaskContext *tc)
630 {
631   if (NULL != mesh)
632   {
633     GNUNET_MESH_disconnect (mesh);
634     mesh = NULL;
635   }
636
637   while (NULL != incoming_head)
638   {
639     incoming_destroy (incoming_head);
640   }
641
642   while (NULL != listeners_head)
643   {
644     listener_destroy (listeners_head);
645   }
646
647   while (NULL != sets_head)
648   {
649     set_destroy (sets_head);
650   }
651
652   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "handled shutdown request\n");
653 }
654
655
656
657 /**
658  * Signature of the main function of a task.
659  *
660  * @param cls closure
661  * @param tc context information (why was this task triggered now)
662  */
663 static void
664 incoming_timeout_cb (void *cls,
665                      const struct GNUNET_SCHEDULER_TaskContext *tc)
666 {
667   struct Incoming *incoming = cls;
668
669   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "remote peer timed out");
670   incoming_destroy (incoming);
671 }
672
673
674 /**
675  * Method called whenever another peer has added us to a tunnel
676  * the other peer initiated.
677  * Only called (once) upon reception of data with a message type which was
678  * subscribed to in GNUNET_MESH_connect. A call to GNUNET_MESH_tunnel_destroy
679  * causes te tunnel to be ignored and no further notifications are sent about
680  * the same tunnel.
681  *
682  * @param cls closure
683  * @param tunnel new handle to the tunnel
684  * @param initiator peer that started the tunnel
685  * @param port Port this tunnel is for.
686  * @return initial tunnel context for the tunnel
687  *         (can be NULL -- that's not an error)
688  */
689 static void *
690 tunnel_new_cb (void *cls,
691                struct GNUNET_MESH_Tunnel *tunnel,
692                const struct GNUNET_PeerIdentity *initiator,
693                uint32_t port)
694 {
695   struct Incoming *incoming;
696   struct TunnelContext *tc;
697
698   GNUNET_assert (port == GNUNET_APPLICATION_TYPE_SET);
699   tc = GNUNET_new (struct TunnelContext);
700   incoming = GNUNET_new (struct Incoming);
701   incoming->tc = tc;
702   tc->peer = *initiator;
703   tc->tunnel = tunnel;
704   tc->mq = GNUNET_MESH_mq_create (tunnel);
705   tc->data = incoming;
706   tc->type = CONTEXT_INCOMING;
707   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, incoming_timeout_cb, incoming);
708   GNUNET_CONTAINER_DLL_insert_tail (incoming_head, incoming_tail, incoming);
709
710   return tc;
711 }
712
713
714 /**
715  * Function called whenever a tunnel is destroyed.  Should clean up
716  * any associated state.  This function is NOT called if the client has
717  * explicitly asked for the tunnel to be destroyed using
718  * GNUNET_MESH_tunnel_destroy. It must NOT call GNUNET_MESH_tunnel_destroy on
719  * the tunnel.
720  *
721  * @param cls closure (set from GNUNET_MESH_connect)
722  * @param tunnel connection to the other end (henceforth invalid)
723  * @param tunnel_ctx place where local state associated
724  *                   with the tunnel is stored
725  */
726 static void
727 tunnel_end_cb (void *cls,
728                const struct GNUNET_MESH_Tunnel *tunnel, void *tunnel_ctx)
729 {
730   struct TunnelContext *ctx = tunnel_ctx;
731
732   switch (ctx->type)
733   {
734     case CONTEXT_INCOMING:
735       incoming_destroy ((struct Incoming *) ctx->data);
736       break;
737     case CONTEXT_OPERATION_UNION:
738       _GSS_union_operation_destroy ((struct UnionEvaluateOperation *) ctx->data);
739       break;
740     case CONTEXT_OPERATION_INTERSECTION:
741       GNUNET_assert (0);
742       /* FIXME: cfuchs */
743       break;
744     default:
745       GNUNET_assert (0);
746   }
747
748 }
749
750
751 /**
752  * Function called by the service's run
753  * method to run service-specific setup code.
754  *
755  * @param cls closure
756  * @param server the initialized server
757  * @param cfg configuration to use
758  */
759 static void
760 run (void *cls, struct GNUNET_SERVER_Handle *server,
761      const struct GNUNET_CONFIGURATION_Handle *cfg)
762 {
763   static const struct GNUNET_SERVER_MessageHandler server_handlers[] = {
764     {handle_client_accept, NULL, GNUNET_MESSAGE_TYPE_SET_ACCEPT, 0},
765     {handle_client_ack, NULL, GNUNET_MESSAGE_TYPE_SET_ACK, 0},
766     {handle_client_add, NULL, GNUNET_MESSAGE_TYPE_SET_ADD, 0},
767     {handle_client_create, NULL, GNUNET_MESSAGE_TYPE_SET_CREATE, 0},
768     {handle_client_evaluate, NULL, GNUNET_MESSAGE_TYPE_SET_EVALUATE, 0},
769     {handle_client_listen, NULL, GNUNET_MESSAGE_TYPE_SET_LISTEN, 0},
770     {handle_client_reject, NULL, GNUNET_MESSAGE_TYPE_SET_REJECT, 0},
771     {handle_client_remove, NULL, GNUNET_MESSAGE_TYPE_SET_REMOVE, 0},
772     {NULL, NULL, 0, 0}
773   };
774   static const struct GNUNET_MESH_MessageHandler mesh_handlers[] = {
775     {handle_p2p_operation_request,
776       GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 0},
777     /* messages for the union operation */
778     {_GSS_union_handle_p2p_message,
779       GNUNET_MESSAGE_TYPE_SET_P2P_IBF, 0},
780     {_GSS_union_handle_p2p_message,
781       GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 0},
782     {_GSS_union_handle_p2p_message,
783       GNUNET_MESSAGE_TYPE_SET_P2P_DONE, 0},
784     {_GSS_union_handle_p2p_message,
785       GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENT_REQUESTS, 0},
786     {_GSS_union_handle_p2p_message,
787       GNUNET_MESSAGE_TYPE_SET_P2P_SE, 0},
788     /* FIXME: messages for intersection operation */
789     {NULL, 0, 0}
790   };
791   static const uint32_t mesh_ports[] = {GNUNET_APPLICATION_TYPE_SET, 0};
792
793   configuration = cfg;
794   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
795                                 &shutdown_task, NULL);
796   GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
797   GNUNET_SERVER_add_handlers (server, server_handlers);
798
799   mesh = GNUNET_MESH_connect (cfg, NULL, tunnel_new_cb, tunnel_end_cb,
800                               mesh_handlers, mesh_ports);
801   if (NULL == mesh)
802   {
803     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not connect to mesh\n");
804     return;
805   }
806
807   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "service started\n");
808 }
809
810
811 /**
812  * The main function for the set service.
813  *
814  * @param argc number of arguments from the command line
815  * @param argv command line arguments
816  * @return 0 ok, 1 on error
817  */
818 int
819 main (int argc, char *const *argv)
820 {
821   int ret;
822   ret = GNUNET_SERVICE_run (argc, argv, "set",
823                             GNUNET_SERVICE_OPTION_NONE, &run, NULL);
824   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "exit\n");
825   return (GNUNET_OK == ret) ? 0 : 1;
826 }
827