d0916d89c6a55602dcffb466c236c19a58a26189
[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_MessageHeader *mh)
261 {
262   struct TunnelContext *tc = *tunnel_ctx;
263   struct Incoming *incoming;
264   const struct OperationRequestMessage *msg = (const struct OperationRequestMessage *) mh;
265   struct GNUNET_MQ_Envelope *mqm;
266   struct GNUNET_SET_RequestMessage *cmsg;
267   struct Listener *listener;
268   const struct GNUNET_MessageHeader *context_msg;
269
270   if (CONTEXT_INCOMING != tc->type)
271   {
272     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "unexpected operation request\n");
273     tunnel_context_destroy (tc);
274     /* don't kill the whole mesh connection */
275     return GNUNET_OK;
276   }
277
278   incoming = tc->data;
279
280   context_msg = GNUNET_MQ_extract_nested_mh (msg);
281   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "received P2P operation request (op %u, app %s)\n",
282               ntohs (msg->operation), GNUNET_h2s (&msg->app_id));
283   listener = get_listener_by_target (ntohs (msg->operation), &msg->app_id);
284   if (NULL == listener)
285   {
286     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
287                 "set operation request from peer failed: "
288                 "no set with matching application ID and operation type\n");
289     tunnel_context_destroy (tc);
290     /* don't kill the whole mesh connection */
291     return GNUNET_OK;
292   }
293   mqm = GNUNET_MQ_msg_nested_mh (cmsg, GNUNET_MESSAGE_TYPE_SET_REQUEST, context_msg);
294   if (NULL == mqm)
295   {
296     /* FIXME: disconnect the peer */
297     GNUNET_break_op (0);
298     tunnel_context_destroy (tc);
299     /* don't kill the whole mesh connection */
300     return GNUNET_OK;
301   }
302   incoming->accept_id = accept_id++;
303   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "sending request with accept id %u\n", incoming->accept_id);
304   cmsg->accept_id = htonl (incoming->accept_id);
305   cmsg->peer_id = incoming->tc->peer;
306   GNUNET_MQ_send (listener->client_mq, mqm);
307
308   return GNUNET_OK;
309 }
310
311
312 /**
313  * Called when a client wants to create a new set.
314  *
315  * @param cls unused
316  * @param client client that sent the message
317  * @param m message sent by the client
318  */
319 static void
320 handle_client_create (void *cls,
321                       struct GNUNET_SERVER_Client *client,
322                       const struct GNUNET_MessageHeader *m)
323 {
324   struct GNUNET_SET_CreateMessage *msg = (struct GNUNET_SET_CreateMessage *) m;
325   struct Set *set;
326
327   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "client created new set (operation %u)\n",
328               ntohs (msg->operation));
329
330   if (NULL != set_get (client))
331   {
332     GNUNET_break (0);
333     GNUNET_SERVER_client_disconnect (client);
334     return;
335   }
336
337   set = NULL;
338
339   switch (ntohs (msg->operation))
340   {
341     case GNUNET_SET_OPERATION_INTERSECTION:
342       //set = _GSS_intersection_set_create ();
343       break;
344     case GNUNET_SET_OPERATION_UNION:
345       set = _GSS_union_set_create ();
346       break;
347     default:
348       GNUNET_break (0);
349       GNUNET_SERVER_client_disconnect (client);
350       return;
351   }
352
353   GNUNET_assert (NULL != set);
354
355   set->client = client;
356   set->client_mq = GNUNET_MQ_queue_for_server_client (client);
357   GNUNET_CONTAINER_DLL_insert (sets_head, sets_tail, set);
358   GNUNET_SERVER_receive_done (client, GNUNET_OK);
359 }
360
361
362 /**
363  * Called when a client wants to create a new listener.
364  *
365  * @param cls unused
366  * @param client client that sent the message
367  * @param m message sent by the client
368  */
369 static void
370 handle_client_listen (void *cls,
371                       struct GNUNET_SERVER_Client *client,
372                       const struct GNUNET_MessageHeader *m)
373 {
374   struct GNUNET_SET_ListenMessage *msg = (struct GNUNET_SET_ListenMessage *) m;
375   struct Listener *listener;
376
377   if (NULL != get_listener (client))
378   {
379     GNUNET_break (0);
380     GNUNET_SERVER_client_disconnect (client);
381     return;
382   }
383   listener = GNUNET_new (struct Listener);
384   listener->client = client;
385   listener->client_mq = GNUNET_MQ_queue_for_server_client (client);
386   listener->app_id = msg->app_id;
387   listener->operation = ntohs (msg->operation);
388   GNUNET_CONTAINER_DLL_insert_tail (listeners_head, listeners_tail, listener);
389   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "new listener created (op %u, app %s)\n",
390               listener->operation, GNUNET_h2s (&listener->app_id));
391   GNUNET_SERVER_receive_done (client, GNUNET_OK);
392 }
393
394
395 /**
396  * Called when a client wants to remove an element
397  * from the set it inhabits.
398  *
399  * @param cls unused
400  * @param client client that sent the message
401  * @param m message sent by the client
402  */
403 static void
404 handle_client_remove (void *cls,
405                       struct GNUNET_SERVER_Client *client,
406                       const struct GNUNET_MessageHeader *m)
407 {
408   struct Set *set;
409
410   set = set_get (client);
411   if (NULL == set)
412   {
413     GNUNET_break (0);
414     GNUNET_SERVER_client_disconnect (client);
415     return;
416   }
417   switch (set->operation)
418   {
419     case GNUNET_SET_OPERATION_UNION:
420       _GSS_union_remove ((struct GNUNET_SET_ElementMessage *) m, set);
421       break;
422     case GNUNET_SET_OPERATION_INTERSECTION:
423       //_GSS_intersection_remove ((struct GNUNET_SET_ElementMessage *) m, set);
424       break;
425     default:
426       GNUNET_assert (0);
427       break;
428   }
429
430   GNUNET_SERVER_receive_done (client, GNUNET_OK);
431 }
432
433
434
435 /**
436  * Called when the client wants to reject an operation
437  * request from another peer.
438  *
439  * @param cls unused
440  * @param client client that sent the message
441  * @param m message sent by the client
442  */
443 static void
444 handle_client_reject (void *cls,
445                       struct GNUNET_SERVER_Client *client,
446                       const struct GNUNET_MessageHeader *m)
447 {
448   struct Incoming *incoming;
449   struct GNUNET_SET_AcceptRejectMessage *msg = (struct GNUNET_SET_AcceptRejectMessage *) m;
450
451   GNUNET_break (0 == ntohl (msg->request_id));
452
453   incoming = get_incoming (ntohl (msg->accept_reject_id));
454   if (NULL == incoming)
455   {
456     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
457     return;
458   }
459   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "peer request rejected by client\n");
460   incoming_destroy (incoming);
461   GNUNET_SERVER_receive_done (client, GNUNET_OK);
462 }
463
464
465
466 /**
467  * Called when a client wants to add an element to a
468  * set it inhabits.
469  *
470  * @param cls unused
471  * @param client client that sent the message
472  * @param m message sent by the client
473  */
474 static void
475 handle_client_add (void *cls,
476                       struct GNUNET_SERVER_Client *client,
477                       const struct GNUNET_MessageHeader *m)
478 {
479   struct Set *set;
480
481   set = set_get (client);
482   if (NULL == set)
483   {
484     GNUNET_break (0);
485     GNUNET_SERVER_client_disconnect (client);
486     return;
487   }
488   switch (set->operation)
489   {
490     case GNUNET_SET_OPERATION_UNION:
491       _GSS_union_add ((struct GNUNET_SET_ElementMessage *) m, set);
492       break;
493     case GNUNET_SET_OPERATION_INTERSECTION:
494       //_GSS_intersection_add ((struct GNUNET_SET_ElementMessage *) m, set);
495       break;
496     default:
497       GNUNET_assert (0);
498       break;
499   }
500
501   GNUNET_SERVER_receive_done (client, GNUNET_OK);
502 }
503
504
505 /**
506  * Called when a client wants to evaluate a set operation with another peer.
507  *
508  * @param cls unused
509  * @param client client that sent the message
510  * @param m message sent by the client
511  */
512 static void
513 handle_client_evaluate (void *cls,
514                         struct GNUNET_SERVER_Client *client,
515                         const struct GNUNET_MessageHeader *m)
516 {
517   struct Set *set;
518
519   set = set_get (client);
520   if (NULL == set)
521   {
522     GNUNET_break (0);
523     GNUNET_SERVER_client_disconnect (client);
524     return;
525   }
526
527
528   switch (set->operation)
529   {
530     case GNUNET_SET_OPERATION_INTERSECTION:
531       //_GSS_intersection_evaluate ((struct GNUNET_SET_EvaluateMessage *) m, set);
532       break;
533     case GNUNET_SET_OPERATION_UNION:
534       _GSS_union_evaluate ((struct GNUNET_SET_EvaluateMessage *) m, set);
535       break;
536     default:
537       GNUNET_assert (0);
538       break;
539   }
540
541   GNUNET_SERVER_receive_done (client, GNUNET_OK);
542 }
543
544
545 /**
546  * Handle an ack from a client.
547  *
548  * @param cls unused
549  * @param client the client
550  * @param m the message
551  */
552 static void
553 handle_client_ack (void *cls,
554                    struct GNUNET_SERVER_Client *client,
555                    const struct GNUNET_MessageHeader *m)
556 {
557   /* FIXME: implement */
558   GNUNET_SERVER_receive_done (client, GNUNET_OK);
559 }
560
561
562 /**
563  * Handle a request from the client to accept
564  * a set operation that came from a remote peer.
565  *
566  * @param cls unused
567  * @param client the client
568  * @param mh the message
569  */
570 static void
571 handle_client_accept (void *cls,
572                       struct GNUNET_SERVER_Client *client,
573                       const struct GNUNET_MessageHeader *mh)
574 {
575   struct Set *set;
576   struct Incoming *incoming;
577   struct GNUNET_SET_AcceptRejectMessage *msg = (struct GNUNET_SET_AcceptRejectMessage *) mh;
578
579   incoming = get_incoming (ntohl (msg->accept_reject_id));
580
581   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "client accepting %u\n", ntohl (msg->accept_reject_id));
582
583   if (NULL == incoming)
584   {
585
586     GNUNET_break (0);
587     GNUNET_SERVER_client_disconnect (client);
588     return;
589   }
590
591   set = set_get (client);
592
593   if (NULL == set)
594   {
595     GNUNET_break (0);
596     GNUNET_SERVER_client_disconnect (client);
597     return;
598   }
599
600   switch (set->operation)
601   {
602     case GNUNET_SET_OPERATION_INTERSECTION:
603       // _GSS_intersection_accept (msg, set, incoming);
604       break;
605     case GNUNET_SET_OPERATION_UNION:
606       _GSS_union_accept (msg, set, incoming);
607       break;
608     default:
609       GNUNET_assert (0);
610       break;
611   }
612
613   /* note: _GSS_*_accept has to make sure the socket and mq are set to NULL,
614    * otherwise they will be destroyed and disconnected */
615   incoming_destroy (incoming);
616   GNUNET_SERVER_receive_done (client, GNUNET_OK);
617 }
618
619
620 /**
621  * Called to clean up, after a shutdown has been requested.
622  *
623  * @param cls closure
624  * @param tc context information (why was this task triggered now)
625  */
626 static void
627 shutdown_task (void *cls,
628                const struct GNUNET_SCHEDULER_TaskContext *tc)
629 {
630   if (NULL != mesh)
631   {
632     GNUNET_MESH_disconnect (mesh);
633     mesh = NULL;
634   }
635
636   while (NULL != incoming_head)
637   {
638     incoming_destroy (incoming_head);
639   }
640
641   while (NULL != listeners_head)
642   {
643     listener_destroy (listeners_head);
644   }
645
646   while (NULL != sets_head)
647   {
648     set_destroy (sets_head);
649   }
650
651   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "handled shutdown request\n");
652 }
653
654
655
656 /**
657  * Signature of the main function of a task.
658  *
659  * @param cls closure
660  * @param tc context information (why was this task triggered now)
661  */
662 static void
663 incoming_timeout_cb (void *cls,
664                      const struct GNUNET_SCHEDULER_TaskContext *tc)
665 {
666   struct Incoming *incoming = cls;
667
668   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "remote peer timed out");
669   incoming_destroy (incoming);
670 }
671
672
673 /**
674  * Method called whenever another peer has added us to a tunnel
675  * the other peer initiated.
676  * Only called (once) upon reception of data with a message type which was
677  * subscribed to in GNUNET_MESH_connect. A call to GNUNET_MESH_tunnel_destroy
678  * causes te tunnel to be ignored and no further notifications are sent about
679  * the same tunnel.
680  *
681  * @param cls closure
682  * @param tunnel new handle to the tunnel
683  * @param initiator peer that started the tunnel
684  * @param port Port this tunnel is for.
685  * @return initial tunnel context for the tunnel
686  *         (can be NULL -- that's not an error)
687  */
688 static void *
689 tunnel_new_cb (void *cls,
690                struct GNUNET_MESH_Tunnel *tunnel,
691                const struct GNUNET_PeerIdentity *initiator,
692                uint32_t port)
693 {
694   struct Incoming *incoming;
695   struct TunnelContext *tc;
696
697   GNUNET_assert (port == GNUNET_APPLICATION_TYPE_SET);
698   tc = GNUNET_new (struct TunnelContext);
699   incoming = GNUNET_new (struct Incoming);
700   incoming->tc = tc;
701   tc->peer = *initiator;
702   tc->tunnel = tunnel;
703   tc->mq = GNUNET_MESH_mq_create (tunnel);
704   tc->data = incoming;
705   tc->type = CONTEXT_INCOMING;
706   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, incoming_timeout_cb, incoming);
707   GNUNET_CONTAINER_DLL_insert_tail (incoming_head, incoming_tail, incoming);
708
709   return tc;
710 }
711
712
713 /**
714  * Function called whenever a tunnel is destroyed.  Should clean up
715  * any associated state.  This function is NOT called if the client has
716  * explicitly asked for the tunnel to be destroyed using
717  * GNUNET_MESH_tunnel_destroy. It must NOT call GNUNET_MESH_tunnel_destroy on
718  * the tunnel.
719  *
720  * @param cls closure (set from GNUNET_MESH_connect)
721  * @param tunnel connection to the other end (henceforth invalid)
722  * @param tunnel_ctx place where local state associated
723  *                   with the tunnel is stored
724  */
725 static void
726 tunnel_end_cb (void *cls,
727                const struct GNUNET_MESH_Tunnel *tunnel, void *tunnel_ctx)
728 {
729   struct TunnelContext *ctx = tunnel_ctx;
730
731   switch (ctx->type)
732   {
733     case CONTEXT_INCOMING:
734       incoming_destroy ((struct Incoming *) ctx->data);
735       break;
736     case CONTEXT_OPERATION_UNION:
737       _GSS_union_operation_destroy ((struct UnionEvaluateOperation *) ctx->data);
738       break;
739     case CONTEXT_OPERATION_INTERSECTION:
740       GNUNET_assert (0);
741       /* FIXME: cfuchs */
742       break;
743     default:
744       GNUNET_assert (0);
745   }
746
747 }
748
749
750 /**
751  * Function called by the service's run
752  * method to run service-specific setup code.
753  *
754  * @param cls closure
755  * @param server the initialized server
756  * @param cfg configuration to use
757  */
758 static void
759 run (void *cls, struct GNUNET_SERVER_Handle *server,
760      const struct GNUNET_CONFIGURATION_Handle *cfg)
761 {
762   static const struct GNUNET_SERVER_MessageHandler server_handlers[] = {
763     {handle_client_accept, NULL, GNUNET_MESSAGE_TYPE_SET_ACCEPT, 0},
764     {handle_client_ack, NULL, GNUNET_MESSAGE_TYPE_SET_ACK, 0},
765     {handle_client_add, NULL, GNUNET_MESSAGE_TYPE_SET_ADD, 0},
766     {handle_client_create, NULL, GNUNET_MESSAGE_TYPE_SET_CREATE, 0},
767     {handle_client_evaluate, NULL, GNUNET_MESSAGE_TYPE_SET_EVALUATE, 0},
768     {handle_client_listen, NULL, GNUNET_MESSAGE_TYPE_SET_LISTEN, 0},
769     {handle_client_reject, NULL, GNUNET_MESSAGE_TYPE_SET_REJECT, 0},
770     {handle_client_remove, NULL, GNUNET_MESSAGE_TYPE_SET_REMOVE, 0},
771     {NULL, NULL, 0, 0}
772   };
773   static const struct GNUNET_MESH_MessageHandler mesh_handlers[] = {
774     {handle_p2p_operation_request,
775       GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 0},
776     /* messages for the union operation */
777     {_GSS_union_handle_p2p_message,
778       GNUNET_MESSAGE_TYPE_SET_P2P_IBF, 0},
779     {_GSS_union_handle_p2p_message,
780       GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 0},
781     {_GSS_union_handle_p2p_message,
782       GNUNET_MESSAGE_TYPE_SET_P2P_DONE, 0},
783     {_GSS_union_handle_p2p_message,
784       GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENT_REQUESTS, 0},
785     {_GSS_union_handle_p2p_message,
786       GNUNET_MESSAGE_TYPE_SET_P2P_SE, 0},
787     /* FIXME: messages for intersection operation */
788     {NULL, 0, 0}
789   };
790   static const uint32_t mesh_ports[] = {GNUNET_APPLICATION_TYPE_SET, 0};
791
792   configuration = cfg;
793   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
794                                 &shutdown_task, NULL);
795   GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
796   GNUNET_SERVER_add_handlers (server, server_handlers);
797
798   mesh = GNUNET_MESH_connect (cfg, NULL, tunnel_new_cb, tunnel_end_cb,
799                               mesh_handlers, mesh_ports);
800   if (NULL == mesh)
801   {
802     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not connect to mesh\n");
803     return;
804   }
805
806   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "service started\n");
807 }
808
809
810 /**
811  * The main function for the set service.
812  *
813  * @param argc number of arguments from the command line
814  * @param argv command line arguments
815  * @return 0 ok, 1 on error
816  */
817 int
818 main (int argc, char *const *argv)
819 {
820   int ret;
821   ret = GNUNET_SERVICE_run (argc, argv, "set",
822                             GNUNET_SERVICE_OPTION_NONE, &run, NULL);
823   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "exit\n");
824   return (GNUNET_OK == ret) ? 0 : 1;
825 }
826