WiP
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh.c
1 /*
2      This file is part of GNUnet.
3      (C) 2001 - 2011 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 mesh/gnunet-service-mesh.c
23  * @brief GNUnet MESH service
24  * @author Bartlomiej Polot
25  *
26  * STRUCTURE:
27  * - MESH NETWORK MESSAGES
28  * - DATA STRUCTURES
29  * - GLOBAL VARIABLES
30  * - MESH NETWORK HANDLES
31  * - MESH LOCAL HANDLES
32  * - MAIN FUNCTIONS (main & run)
33  * 
34  * TODO:
35  * - soft stateing (keep-alive (CHANGE?) / timeout / disconnect) -- not a message issue
36  * - error reporting (CREATE/CHANGE/ADD/DEL?) -- new message!
37  * - partial disconnect reporting -- same as error reporting?
38  * - add vs create? change vs. keep-alive? same msg or different ones? -- thinking...
39  * - speed requirement specification (change?) in mesh API -- API call
40  */
41
42 #include "platform.h"
43 #include "gnunet_common.h"
44 #include "gnunet_util_lib.h"
45 #include "gnunet_peer_lib.h"
46 #include "gnunet_core_service.h"
47 #include "gnunet_protocols.h"
48 #include "mesh.h"
49
50
51 /******************************************************************************/
52 /********************      MESH NETWORK MESSAGES     **************************/
53 /******************************************************************************/
54
55 /**
56  * Message for mesh path management
57  */
58 struct GNUNET_MESH_ManipulatePath
59 {
60     /**
61      * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_[CREATE|CHANGE|ADD|DEL]
62      *
63      * Size: sizeof(struct GNUNET_MESH_ManipulatePath) +
64      *       path_length * sizeof (struct GNUNET_PeerIdentity)
65      */
66     struct GNUNET_MessageHeader header;
67
68     /**
69      * Global id of the tunnel this path belongs to,
70      * unique in conjunction with the origin.
71      */
72     uint32_t tid GNUNET_PACKED;
73
74     /**
75      * Information about speed requirements.  If the tunnel cannot sustain the 
76      * minimum bandwidth, packets are to be dropped.
77      */
78     uint32_t speed_min GNUNET_PACKED;
79
80     /**
81      * 64-bit alignment.
82      */
83     uint32_t reserved GNUNET_PACKED;
84
85     /**
86      * path_length structs defining the *whole* path from the origin [0] to the
87      * final destination [path_length-1].
88      */
89     /* struct GNUNET_PeerIdentity peers[path_length]; */
90 };
91
92 /**
93  * Message for mesh data traffic to all tunnel targets.
94  */
95 struct GNUNET_MESH_OriginMulticast
96 {
97     /**
98      * Type: GNUNET_MESSAGE_TYPE_DATA_MULTICAST
99      */
100     struct GNUNET_MessageHeader header;
101
102     /**
103      * TID of the tunnel
104      */
105     uint32_t tid GNUNET_PACKED;
106
107     /**
108      * OID of the tunnel
109      */
110     struct GNUNET_PeerIdentity oid;
111
112     /**
113      * Payload follows
114      */
115 };
116
117
118 /**
119  * Message for mesh data traffic to a particular destination from origin.
120  */
121 struct GNUNET_MESH_DataMessageFromOrigin
122 {
123     /**
124      * Type: GNUNET_MESSAGE_TYPE_DATA_MESSAGE_FROM_ORIGIN
125      */
126     struct GNUNET_MessageHeader header;
127
128     /**
129      * TID of the tunnel
130      */
131     uint32_t tid GNUNET_PACKED;
132
133     /**
134      * OID of the tunnel
135      */
136     struct GNUNET_PeerIdentity oid;
137
138     /**
139      * Destination.
140      */
141     struct GNUNET_PeerIdentity destination;
142
143     /**
144      * Payload follows
145      */
146 };
147
148
149 /**
150  * Message for mesh data traffic from a tunnel participant to origin.
151  */
152 struct GNUNET_MESH_DataMessageToOrigin
153 {
154     /**
155      * Type: GNUNET_MESSAGE_TYPE_DATA_MESSAGE_TO_ORIGIN
156      */
157     struct GNUNET_MessageHeader header;
158
159     /**
160      * TID of the tunnel
161      */
162     uint32_t tid GNUNET_PACKED;
163
164     /**
165      * OID of the tunnel
166      */
167     struct GNUNET_PeerIdentity oid;
168
169     /**
170      * Sender of the message.
171      */
172     struct GNUNET_PeerIdentity sender;
173
174     /**
175      * Payload follows
176      */
177 };
178
179 /**
180  * Message for mesh flow control
181  */
182 struct GNUNET_MESH_SpeedNotify
183 {
184     /**
185      * Type: GNUNET_MESSAGE_TYPE_DATA_SPEED_NOTIFY
186      */
187     struct GNUNET_MessageHeader header;
188
189     /**
190      * TID of the tunnel
191      */
192     uint32_t tid GNUNET_PACKED;
193
194     /**
195      * OID of the tunnel
196      */
197     struct GNUNET_PeerIdentity oid;
198
199     /**
200      * Slowest link down the path (above minimum speed requirement).
201      */
202     uint32_t speed_min;
203
204 };
205
206 /******************************************************************************/
207 /************************      DATA STRUCTURES     ****************************/
208 /******************************************************************************/
209
210 /**
211  * All the states a peer participating in a tunnel can be in.
212  */
213 enum PeerState
214 {
215     /**
216      * Request sent, not yet answered.
217      */
218     MESH_PEER_WAITING,
219
220     /**
221      * Peer connected and ready to accept data
222      */
223     MESH_PEER_READY,
224
225     /**
226      * Peer connected previosly but not responding
227      */
228     MESH_PEER_RECONNECTING,
229
230 };
231
232 /**
233  * Struct containing all information regarding a given peer
234  */
235 struct PeerInfo
236 {
237     /**
238      * ID of the peer
239      */
240     GNUNET_PEER_Id              id;
241
242     /**
243      * Is the peer reachable? Is the peer even connected?
244      */
245     enum PeerState              state;
246
247     /**
248      * Who to send the data to --- FIXME what about multiple (alternate) paths?
249      */
250     GNUNET_PEER_Id              first_hop;
251
252     /**
253      * Max data rate to this peer
254      */
255     uint32_t                    max_speed;
256 };
257
258
259 typedef uint32_t MESH_PathID;
260 /**
261  * Information regarding a path
262  */
263 struct Path
264 {
265     /**
266      * Double linked list
267      */
268     struct Path                 *next;
269     struct Path                 *prev;
270
271     /**
272      * Id of the path, in case it's needed
273      */
274     MESH_PathID                 id;
275
276     /**
277      * Whether the path is serving traffic in a tunnel or is a backup
278      */
279     int                         in_use;
280
281     /**
282      * List of all the peers that form the path from origin to target
283      */
284     GNUNET_PEER_Id              *peers;
285 };
286
287 struct MESH_queue
288 {
289     /**
290      * Double linked list
291      */
292     struct MESH_queue          *next;
293     struct MESH_queue          *prev;
294
295     /**
296      * Size of the message to transmit
297      */
298     unsigned int                size;
299     
300     /**
301      * How old is the data?
302      */
303     struct GNUNET_TIME_Absolute timestamp;
304     
305     /**
306      * Data itself
307      */
308     struct GNUNET_MessageHeader *data;
309 };
310
311
312 struct Client; /* FWD declaration */
313 /**
314  * Struct containing all information regarding a tunnel
315  * For an intermediate node the improtant info used will be:
316  * - OID        \ To identify
317  * - TID        / the tunnel
318  * - paths[0]   | To know where to send it next
319  * - metainfo: ready, speeds, accounting
320  * For an end node more fields will be needed (client-handling)
321  */
322 struct MESH_tunnel
323 {
324
325     /**
326      * Double linked list
327      */
328     struct MESH_tunnel          *next;
329     struct MESH_tunnel          *prev;
330
331     /**
332      * Origin ID: Node that created the tunnel
333      */
334     GNUNET_PEER_Id              oid;
335
336     /**
337      * Tunnel number (unique for a given oid)
338      */
339     MESH_TunnelID               tid;
340
341     /**
342      * Minimal speed for this tunnel in kb/s
343      */
344     uint32_t                    speed_min;
345
346     /**
347      * Maximal speed for this tunnel in kb/s
348      */
349     uint32_t                    speed_max;
350
351     /**
352      * Last time the tunnel was used
353      */
354     struct GNUNET_TIME_Absolute timestamp;
355
356     /**
357      * Peers in the tunnel, for future optimizations
358      */
359     struct PeerInfo             *peers_head;
360     struct PeerInfo             *peers_tail;
361
362     /**
363      * Number of peers that are connected and potentially ready to receive data
364      */
365     unsigned int                peers_ready;
366
367     /**
368      * Number of peers that have been added to the tunnel
369      */
370     unsigned int                peers_total;
371
372     /**
373      * Paths (used and backup)
374      */
375     struct Path                 *paths_head;
376     struct Path                 *paths_tail;
377
378     /**
379      * If this tunnel was created by a local client, what's its handle?
380      */
381     struct Client               *client;
382
383     /**
384      * Messages ready to transmit
385      */
386     struct MESH_queue           *out_head;
387     struct MESH_queue           *out_tail;
388
389     /**
390      * Messages received and not processed
391      */
392     struct MESH_queue           *in_head;
393     struct MESH_queue           *in_tail;
394
395 };
396
397 /**
398  * Struct containing information about a client of the service
399  */
400 struct Client
401 {
402     /**
403      * Double linked list
404      */
405     struct Client               *next;
406     struct Client               *prev;
407
408     /**
409      * Tunnels that belong to this client, for convenience on disconnect
410      */
411     struct MESH_tunnel          *tunnels_head;
412     struct MESH_tunnel          *tunnels_tail;
413
414     /**
415      * Handle to communicate with the client
416      */
417     struct GNUNET_SERVER_Client *handle;
418
419     /**
420      * Messages that this client has declared interest in
421      */
422     GNUNET_MESH_ApplicationType *messages_subscribed;
423     unsigned int                subscription_counter;
424
425 };
426
427 /******************************************************************************/
428 /***********************      GLOBAL VARIABLES     ****************************/
429 /******************************************************************************/
430
431 /**
432  * All the clients
433  */
434 static struct Client            *clients_head;
435 static struct Client            *clients_tail;
436
437 /**
438  * All the tunnels
439  */
440 static struct MESH_tunnel       *tunnels_head;
441 static struct MESH_tunnel       *tunnels_tail;
442
443 /**
444  * All the paths (for future path optimization)
445  */
446 // static struct Path             *paths_head;
447 // static struct Path             *paths_tail;
448
449 /******************************************************************************/
450 /********************      MESH NETWORK HANDLERS     **************************/
451 /******************************************************************************/
452
453 /**
454  * Core handler for path creation
455  * struct GNUNET_CORE_MessageHandler
456  *
457  * @param cls closure
458  * @param message message
459  * @param peer peer identity this notification is about
460  * @param atsi performance data
461  * @return GNUNET_OK to keep the connection open,
462  *         GNUNET_SYSERR to close it (signal serious error)
463  *
464  */
465 static int
466 handle_mesh_path_create (void *cls,
467                               const struct GNUNET_PeerIdentity *peer,
468                               const struct GNUNET_MessageHeader *message,
469                               const struct GNUNET_TRANSPORT_ATS_Information
470                               *atsi)
471 {
472   /*
473    * EXAMPLE OF USING THE API
474    * NOT ACTUAL CODE!!!!!
475    */
476   /*client *c;
477   tunnel *t;
478
479   t = new;
480   GNUNET_CONTAINER_DLL_insert (c->my_tunnels_head,
481                                c->my_tunnels_tail,
482                                t);
483
484   while (NULL != (t = c->my_tunnels_head))
485     {
486       GNUNET_CONTAINER_DLL_remove (c->my_tunnels_head,
487                                    c->my_tunnels_tail,
488                                    t);
489       GNUNET_free (t);
490     }
491   */
492
493
494     /* Extract path */
495     /* Find origin & self */
496     /* Search for origin in local tunnels */
497     /* Create tunnel / add path */
498     /* Retransmit to next link in chain, if any (core_notify + callback) */
499     return GNUNET_OK;
500 }
501
502 /**
503  * Core handler for mesh network traffic
504  *
505  * @param cls closure
506  * @param message message
507  * @param peer peer identity this notification is about
508  * @param atsi performance data
509  * @return GNUNET_OK to keep the connection open,
510  *         GNUNET_SYSERR to close it (signal serious error)
511  */
512 static int
513 handle_mesh_network_traffic (void *cls,
514                              const struct GNUNET_PeerIdentity *peer,
515                              const struct GNUNET_MessageHeader *message,
516                              const struct GNUNET_TRANSPORT_ATS_Information
517                              *atsi)
518 {
519     if(GNUNET_MESSAGE_TYPE_MESH_DATA_GO == ntohs(message->type)) {
520         /* Retransmit to next in path of tunnel identified by message */
521         return GNUNET_OK;
522     } else { /* GNUNET_MESSAGE_TYPE_MESH_DATA_BACK */
523         /* Retransmit to previous in path of tunnel identified by message */
524         return GNUNET_OK;
525     }
526 }
527
528 /**
529  * Functions to handle messages from core
530  */
531 static struct GNUNET_CORE_MessageHandler core_handlers[] = {
532   {&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0},
533   {&handle_mesh_network_traffic, GNUNET_MESSAGE_TYPE_MESH_DATA_GO, 0},
534   {&handle_mesh_network_traffic, GNUNET_MESSAGE_TYPE_MESH_DATA_BACK, 0},
535   {NULL, 0, 0}
536 };
537
538
539
540 /******************************************************************************/
541 /*********************       MESH LOCAL HANDLES      **************************/
542 /******************************************************************************/
543
544 /**
545  * Handler for client disconnection
546  *
547  * @param cls closure
548  * @param client identification of the client; NULL
549  *        for the last call when the server is destroyed
550  */
551 static void
552 handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
553 {
554     struct Client       *c, *next;
555     struct MESH_tunnel  *t;
556
557     /* If there are no clients registered, something is wrong... or is it?
558      * FIXME: what happens if a client connects, doesn't send a MESH_Connect
559      * and disconnects? Does the service get a disconnect notification anyway?
560      */
561     GNUNET_assert(NULL != clients_head);
562     for (c = clients_head; c != clients_head; c = next) {
563         if (c->handle == client) {
564             GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c);
565             while (NULL != (t = c->tunnels_head)) {
566                 GNUNET_CONTAINER_DLL_remove (c->tunnels_head, c->tunnels_tail, t);
567                 GNUNET_CONTAINER_DLL_remove (tunnels_head, tunnels_tail, t);
568                 /* TODO free paths and other tunnel dynamic structures */
569                 GNUNET_free (t);
570             }
571             GNUNET_free (c->messages_subscribed);
572             next = c->next;
573             GNUNET_free (c);
574         } else {
575             next = c->next;
576         }
577     }
578
579     return;
580 }
581
582 /**
583  * Handler for new clients
584  * 
585  * @param cls closure
586  * @param client identification of the client
587  * @param message the actual message, which includes messages the client wants
588  */
589 static void
590 handle_local_new_client (void *cls,
591                          struct GNUNET_SERVER_Client *client,
592                          const struct GNUNET_MessageHeader *message)
593 {
594     struct Client               *c;
595     unsigned int                payload_size;
596
597     /* Check data sanity */
598     payload_size = message->size - sizeof(struct GNUNET_MessageHeader);
599     if (0 != payload_size % sizeof(GNUNET_MESH_ApplicationType)) {
600         GNUNET_break(0);
601         GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
602         return;
603     }
604
605     /* Create new client structure */
606     c = GNUNET_malloc(sizeof(struct Client));
607     c->handle = client;
608     c->tunnels_head = NULL;
609     c->tunnels_tail = NULL;
610     if(payload_size != 0) {
611         c->messages_subscribed = GNUNET_malloc(payload_size);
612         memcpy(c->messages_subscribed, &message[1], payload_size);
613     } else {
614         c->messages_subscribed = NULL;
615     }
616     c->subscription_counter = payload_size/sizeof(GNUNET_MESH_ApplicationType);
617
618     /* Insert new client in DLL */
619     GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
620
621     GNUNET_SERVER_receive_done(client, GNUNET_OK);
622 }
623
624 /**
625  * Handler for requests of new tunnels
626  * 
627  * @param cls closure
628  * @param client identification of the client
629  * @param message the actual message
630  */
631 static void
632 handle_local_tunnel_create (void *cls,
633                             struct GNUNET_SERVER_Client *client,
634                             const struct GNUNET_MessageHeader *message)
635 {
636     struct Client                       *c;
637     struct GNUNET_MESH_TunnelMessage    *tunnel_msg;
638     struct MESH_tunnel                  *t;
639
640     /* Sanity check for client registration */
641     /* TODO: refactor into new function */
642     for (c = clients_head; c != clients_head; c = c->next) {
643         if(c->handle == client) break;
644     }
645     if(c->handle != client) { /* Client hasn't registered, not a good thing */
646         GNUNET_break(0);
647         GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
648         return;
649     }
650
651     /* Message sanity check */
652     if(sizeof(struct GNUNET_MESH_TunnelMessage) != ntohs(message->size)) {
653         GNUNET_break(0);
654         GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
655         return;
656     }
657
658     tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message;
659     /* Sanity check for tunnel numbering */
660     if(0 == (ntohl(tunnel_msg->tunnel_id) & 0x80000000)) {
661             GNUNET_break(0);
662             GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
663             return;
664         }
665     /* Sanity check for duplicate tunnel IDs */
666     for (t = tunnels_head; t != tunnels_head; t = t->next) {
667         if(t->tid == ntohl(tunnel_msg->tunnel_id)) {
668             GNUNET_break(0);
669             GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
670             return;
671         }
672     }
673     /* FIXME: calloc? is NULL != 0 on any platform? */
674     t = GNUNET_malloc(sizeof(MESH_tunnel));
675     t->tid = ntohl(tunnel_msg->tunnel_id);
676     /* FIXME: t->oid = selfid;*/
677     t->peers_ready = 0;
678     t->peers_total = 0;
679     t->peers_head = NULL;
680     t->peers_tail = NULL;
681     t->paths_head = NULL;
682     t->paths_tail = NULL;
683     t->in_head = NULL;
684     t->in_tail = NULL;
685     t->out_head = NULL;
686     t->out_tail = NULL;
687     
688     GNUNET_SERVER_receive_done(client, GNUNET_OK);
689     return;
690 }
691
692 /**
693  * Handler for requests of deleting tunnels
694  * 
695  * @param cls closure
696  * @param client identification of the client
697  * @param message the actual message
698  */
699 static void
700 handle_local_tunnel_destroy (void *cls,
701                              struct GNUNET_SERVER_Client *client,
702                              const struct GNUNET_MessageHeader *message)
703 {
704     return;
705 }
706
707 /**
708  * Handler for connection requests to new peers
709  * 
710  * @param cls closure
711  * @param client identification of the client
712  * @param message the actual message
713  */
714 static void
715 handle_local_connect (void *cls,
716                          struct GNUNET_SERVER_Client *client,
717                          const struct GNUNET_MessageHeader *message)
718 {
719     return;
720 }
721
722 /**
723  * Handler for client traffic
724  * 
725  * @param cls closure
726  * @param client identification of the client
727  * @param message the actual message
728  */
729 static void
730 handle_local_network_traffic (void *cls,
731                          struct GNUNET_SERVER_Client *client,
732                          const struct GNUNET_MessageHeader *message)
733 {
734     return;
735 }
736
737 /**
738  * Functions to handle messages from clients
739  */
740 static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
741   {&handle_local_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0},
742   {&handle_local_tunnel_create, NULL,
743    GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE, 0},
744   {&handle_local_tunnel_destroy, NULL,
745    GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY, 0},
746   {&handle_local_connect, NULL,
747    GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, 0},
748   {&handle_local_connect, NULL,
749    GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL, 0},
750   {&handle_local_connect, NULL,
751    GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE,
752    sizeof(struct GNUNET_MESH_ConnectPeerByType)},
753   {&handle_local_connect, NULL,
754    GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL, 0},
755   {&handle_local_network_traffic, NULL,
756    GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0}, /* FIXME needed? */
757   {&handle_local_network_traffic, NULL,
758    GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST, 0}, /* FIXME needed? */
759   {NULL, NULL, 0, 0}
760 };
761
762
763 /**
764  * To be called on core init/fail.
765  *
766  * @param cls service closure
767  * @param server handle to the server for this service
768  * @param identity the public identity of this peer
769  * @param publicKey the public key of this peer
770  */
771 static void
772 core_init (void *cls,
773            struct GNUNET_CORE_Handle *server,
774            const struct GNUNET_PeerIdentity *identity,
775            const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
776 {
777     return;
778 }
779
780 /**
781  * Method called whenever a given peer connects.
782  *
783  * @param cls closure
784  * @param peer peer identity this notification is about
785  * @param atsi performance data for the connection
786  */
787 static void
788 core_connect (void *cls,
789               const struct GNUNET_PeerIdentity *peer,
790               const struct GNUNET_TRANSPORT_ATS_Information *atsi)
791 {
792     return;
793 }
794
795 /**
796  * Method called whenever a peer disconnects.
797  *
798  * @param cls closure
799  * @param peer peer identity this notification is about
800  */
801 static void
802 core_disconnect (void *cls,
803                 const struct
804                 GNUNET_PeerIdentity *peer)
805 {
806     return;
807 }
808
809 /******************************************************************************/
810 /************************      MAIN FUNCTIONS      ****************************/
811 /******************************************************************************/
812
813 /**
814  * Process mesh requests. FIXME NON FUNCTIONAL, SKELETON
815  *
816  * @param cls closure
817  * @param server the initialized server
818  * @param c configuration to use
819  */
820 static void
821 run (void *cls,
822      struct GNUNET_SERVER_Handle *server,
823      const struct GNUNET_CONFIGURATION_Handle *c)
824 {
825   struct GNUNET_CORE_Handle *core;
826
827   GNUNET_SERVER_add_handlers (server, plugin_handlers);
828   GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
829   core = GNUNET_CORE_connect (c,                        /* Main configuration */
830                             32,                                 /* queue size */
831                             NULL,         /* Closure passed to MESH functions */
832                             &core_init,      /* Call core_init once connected */
833                             &core_connect,                 /* Handle connects */
834                             &core_disconnect,  /* remove peers on disconnects */
835                             NULL,       /* Do we care about "status" updates? */
836                             NULL, /* Don't notify about all incoming messages */
837                             GNUNET_NO,     /* For header only in notification */
838                             NULL, /* Don't notify about all outbound messages */
839                             GNUNET_NO,    /* For header-only out notification */
840                             core_handlers);        /* Register these handlers */
841
842   if (core == NULL)
843     return;
844 }
845
846 /**
847  * The main function for the mesh service.
848  *
849  * @param argc number of arguments from the command line
850  * @param argv command line arguments
851  * @return 0 ok, 1 on error
852  */
853 int
854 main (int argc, char *const *argv)
855 {
856     int ret;
857
858     ret = (GNUNET_OK ==
859            GNUNET_SERVICE_run (argc,
860                                argv,
861                                "mesh",
862                                GNUNET_SERVICE_OPTION_NONE,
863                                &run, NULL)) ? 0 : 1;
864     return ret;
865     }