2 This file is part of GNUnet.
3 (C) 2001 - 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file mesh/gnunet-service-mesh.c
23 * @brief GNUnet MESH service
24 * @author Bartlomiej Polot
27 * - soft stateing (keep-alive (CHANGE?) / timeout / disconnect) -- not a message issue
28 * - error reporting (CREATE/CHANGE/ADD/DEL?) -- new message!
29 * - partial disconnect reporting -- same as error reporting?
30 * - add vs create? change vs. keep-alive? same msg or different ones? -- thinking...
31 * - speed requirement specification (change?) in mesh API -- API call
35 #include "gnunet_common.h"
36 #include "gnunet_util_lib.h"
37 #include "gnunet_core_service.h"
38 #include <netinet/in.h>
41 /******************************************************************************/
42 /******************** MESH NETWORK MESSAGES **************************/
43 /******************************************************************************/
46 * Message for mesh path management
48 struct GNUNET_MESH_ManipulatePath
51 * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_[CREATE|CHANGE|ADD|DEL]
53 * Size: sizeof(struct GNUNET_MESH_ManipulatePath) + path_length * sizeof (struct GNUNET_PeerIdentity)
55 struct GNUNET_MessageHeader header;
58 * Id of the tunnel this path belongs to, unique in conjunction with the origin.
60 uint32_t tid GNUNET_PACKED;
63 * Information about speed requirements. If the tunnel cannot sustain the
64 * minimum bandwidth, packets are to be dropped.
66 uint32_t speed_min GNUNET_PACKED;
69 * path_length structs defining the *whole* path from the origin [0] to the
70 * final destination [path_length-1].
72 // struct GNUNET_PeerIdentity peers[path_length];
76 * Message for mesh data traffic to all tunnel targets.
78 struct GNUNET_MESH_OriginMulticast
81 * Type: GNUNET_MESSAGE_TYPE_DATA_MULTICAST
83 struct GNUNET_MessageHeader header;
88 uint32_t tid GNUNET_PACKED;
93 struct GNUNET_PeerIdentity oid;
96 * FIXME: Some form of authentication
107 * Message for mesh data traffic to a particular destination from origin.
109 struct GNUNET_MESH_DataMessageFromOrigin
112 * Type: GNUNET_MESSAGE_TYPE_DATA_MESSAGE_FROM_ORIGIN
114 struct GNUNET_MessageHeader header;
119 uint32_t tid GNUNET_PACKED;
124 struct GNUNET_PeerIdentity oid;
129 struct GNUNET_PeerIdentity destination;
132 * FIXME: Some form of authentication
143 * Message for mesh data traffic from a tunnel participant to origin.
145 struct GNUNET_MESH_DataMessageToOrigin
148 * Type: GNUNET_MESSAGE_TYPE_DATA_MESSAGE_TO_ORIGIN
150 struct GNUNET_MessageHeader header;
155 uint32_t tid GNUNET_PACKED;
160 struct GNUNET_PeerIdentity oid;
163 * Sender of the message.
165 struct GNUNET_PeerIdentity sender;
168 * FIXME: Some form of authentication
178 * Message for mesh flow control
180 struct GNUNET_MESH_SpeedNotify
183 * Type: GNUNET_MESSAGE_TYPE_DATA_SPEED_NOTIFY
185 struct GNUNET_MessageHeader header;
190 uint32_t tid GNUNET_PACKED;
195 struct GNUNET_PeerIdentity oid;
198 * Slowest link down the path (above minimum speed requirement).
204 /******************************************************************************/
205 /************************ DATA STRUCTURES ****************************/
206 /******************************************************************************/
209 * All the states a peer participating in a tunnel can be in.
214 * Request sent, not yet answered.
219 * Peer connected and ready to accept data
224 * Peer connected previosly but not responding
226 MESH_PEER_UNAVAILABLE,
229 * Peer requested but not ever connected
231 MESH_PEER_UNREACHABLE
235 * Struct containing all information regarding a given peer
242 struct GNUNET_PeerIdentity id;
245 * Is the peer reachable? Is the peer even connected?
247 struct PeerState state;
250 * Who to send the data to
255 * Max data rate to this peer
261 * Information regarding a path
266 * Id of the path, in case it's needed
271 * Whether the path is serving traffic in a tunnel or is a backup
276 * List of all the peers that form the path from origin to target
282 * Struct containing all information regarding a tunnel
283 * For an intermediate node the improtant info used will be:
284 * - OID \ To identify
286 * - paths[0] | To know where to send it next
287 * - metainfo: ready, speeds, accounting
288 * For an end node more fields will be needed (client-handling)
293 * Origin ID: Node that created the tunnel
295 struct GNUNET_PeerIdentity oid;
298 * Tunnel number (unique for a given oid)
303 * Whether the tunnel is in state to transmit data
308 * Minimal speed for this tunnel in kb/s
313 * Maximal speed for this tunnel in kb/s
318 * Last time the tunnel was used
320 struct GNUNET_TIME_Absolute timestamp;
323 * Peers in the tunnel, for future optimizations
325 struct PeerInfo *peers;
328 * Paths (used and backup)
333 * Messages ready to transmit
335 struct GNUNET_MessageHeader *msg_out;
338 * Messages received and not processed
340 struct GNUNET_MessageHeader *msg_in;
343 * FIXME Clients. Is anyone to be notified for traffic here?
348 * So, I'm an endpoint. Why am I receiveing traffic?
349 * Who is interested in this? How to communicate with them?
354 * FIXME add structures needed to handle client connections
360 * Handler for requests of creating new path
361 * type: struct GNUNET_CORE_MessageHandler
364 * @param client the client this message is from
365 * @param message the message received
368 handle_mesh_path_create (void *cls,
369 struct GNUNET_SERVER_Client *client,
370 const struct GNUNET_MessageHeader *message)
376 * Handler for client disconnection
379 * @param client identification of the client; NULL
380 * for the last call when the server is destroyed
383 handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
385 /* Remove client from list, delete all timers and queues associated */
390 * Core handler for path creation
391 * struct GNUNET_CORE_MessageHandler
394 * @param message message
395 * @param peer peer identity this notification is about
396 * @param atsi performance data
400 handle_mesh_path_create (void *cls,
401 const struct GNUNET_PeerIdentity *peer,
402 const struct GNUNET_MessageHeader *message,
403 const struct GNUNET_TRANSPORT_ATS_Information
407 /* Find origin & self */
408 /* Search for origin in local tunnels */
409 /* Create tunnel / add path */
410 /* Retransmit to next link in chain, if any (core_notify + callback) */
415 * Core handler for mesh network traffic
418 * @param message message
419 * @param peer peer identity this notification is about
420 * @param atsi performance data
424 handle_mesh_network_traffic (void *cls,
425 const struct GNUNET_PeerIdentity *peer,
426 const struct GNUNET_MessageHeader *message,
427 const struct GNUNET_TRANSPORT_ATS_Information
430 if(GNUNET_MESSAGE_TYPE_MESH_DATA_GO == ntohs(message->type)) {
431 /* Retransmit to next in path of tunnel identified by message */
433 } else { /* GNUNET_MESSAGE_TYPE_MESH_DATA_BACK */
434 /* Retransmit to previous in path of tunnel identified by message */
440 * Functions to handle messages from core
442 static struct GNUNET_CORE_MessageHandler core_handlers[] = {
443 {&handle_mesh_path_create, NULL, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0},
444 {&handle_mesh_network_traffic, GNUNET_MESSAGE_TYPE_MESH_DATA_GO, 0},
445 {&handle_mesh_network_traffic, GNUNET_MESSAGE_TYPE_MESH_DATA_BACK, 0},
450 * Functions to handle messages from clients
452 static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
453 {&handle_local_path_create, NULL, GNUNET_MESSAGE_TYPE_LOCAL_PATH_CREATE, 0},
454 {&handle_local_network_traffic, GNUNET_MESSAGE_TYPE_LOCAL_DATA_GO, 0},
455 {&handle_local_network_traffic, GNUNET_MESSAGE_TYPE_LOCAL_DATA_BACK, 0},
460 * Process mesh requests. FIXME NON FUNCTIONAL, COPIED FROM DHT!!
463 * @param server the initialized server
464 * @param c configuration to use
468 struct GNUNET_SERVER_Handle *server,
469 const struct GNUNET_CONFIGURATION_Handle *c)
471 struct GNUNET_TIME_Relative next_send_time;
472 unsigned long long temp_config_num;
473 char *converge_modifier_buf;
474 GNUNET_CORE_Handle *coreAPI;
476 GNUNET_SERVER_add_handlers (server, plugin_handlers);
477 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
478 coreAPI = GNUNET_CORE_connect (c, /* Main configuration */
480 NULL, /* Closure passed to DHT functions */
481 NULL, /* Call core_init once connected */
482 NULL, /* Handle connects */
483 NULL, /* remove peers on disconnects */
484 NULL, /* Do we care about "status" updates? */
485 NULL, /* Don't want notified about all incoming messages */
486 GNUNET_NO, /* For header only inbound notification */
487 NULL, /* Don't want notified about all outbound messages */
488 GNUNET_NO, /* For header only outbound notification */
489 core_handlers); /* Register these handlers */
496 * The main function for the mesh service.
498 * @param argc number of arguments from the command line
499 * @param argv command line arguments
500 * @return 0 ok, 1 on error
503 main (int argc, char *const *argv)
508 GNUNET_SERVICE_run (argc,
511 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;