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
453 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT 272
454 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ANY 273
455 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ALL 274
456 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD 275
457 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL 276
458 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE 277
459 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL 278
460 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TRANSMIT_READY 279
461 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATED 280
462 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROYED 281
463 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA 282
464 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST 283
466 static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
467 {&handle_local_new_client, NULL, GNUNET_MESSAGE_TYPE_LOCAL_CONNECT, 0},
468 {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ANY, 0},
469 {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ALL, 0},
470 {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, 0},
471 {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL, 0},
472 {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, sizeof(struct GNUNET_MESH_ConnectPeerByType)},
473 {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL, sizeof(struct GNUNET_MESH_Control)},
474 {&handle_local_network_traffic, NULL, GNUNET_MESSAGE_TYPE_LOCAL_TRANSMIT_READY, sizeof(struct GNUNET_MESH_Control)},
475 {&handle_local_network_traffic, NULL, GNUNET_MESSAGE_TYPE_LOCAL_DATA, 0}, /* FIXME needed? */
476 {&handle_local_network_traffic, NULL, GNUNET_MESSAGE_TYPE_LOCAL_DATA_BROADCAST, 0}, /* FIXME needed? */
482 * To be called on core init/fail.
484 * @param cls service closure
485 * @param server handle to the server for this service
486 * @param identity the public identity of this peer
487 * @param publicKey the public key of this peer
490 core_init (void *cls,
491 struct GNUNET_CORE_Handle *server,
492 const struct GNUNET_PeerIdentity *identity,
493 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
499 * Method called whenever a given peer connects.
502 * @param peer peer identity this notification is about
503 * @param atsi performance data for the connection
506 core_connect (void *cls,
507 const struct GNUNET_PeerIdentity *peer,
508 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
514 * Method called whenever a peer disconnects.
517 * @param peer peer identity this notification is about
520 core_disconnect (void *cls,
522 GNUNET_PeerIdentity *peer)
528 * Process mesh requests. FIXME NON FUNCTIONAL, COPIED FROM DHT!!
531 * @param server the initialized server
532 * @param c configuration to use
536 struct GNUNET_SERVER_Handle *server,
537 const struct GNUNET_CONFIGURATION_Handle *c)
539 struct GNUNET_TIME_Relative next_send_time;
540 unsigned long long temp_config_num;
541 char *converge_modifier_buf;
542 GNUNET_CORE_Handle *core;
544 GNUNET_SERVER_add_handlers (server, plugin_handlers);
545 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
546 core = GNUNET_CORE_connect (c, /* Main configuration */
548 NULL, /* Closure passed to MESH functions */
549 &core_init, /* Call core_init once connected */
550 &core_connect, /* Handle connects */
551 &core_disconnect, /* remove peers on disconnects */
552 NULL, /* Do we care about "status" updates? */
553 NULL, /* Don't want notified about all incoming messages */
554 GNUNET_NO, /* For header only inbound notification */
555 NULL, /* Don't want notified about all outbound messages */
556 GNUNET_NO, /* For header only outbound notification */
557 core_handlers); /* Register these handlers */
564 * The main function for the mesh service.
566 * @param argc number of arguments from the command line
567 * @param argv command line arguments
568 * @return 0 ok, 1 on error
571 main (int argc, char *const *argv)
576 GNUNET_SERVICE_run (argc,
579 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;