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
28 #include "gnunet_common.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_core_service.h"
31 #include <netinet/in.h>
34 * All the states a peer participating in a tunnel can be in.
39 * Request sent, not yet answered.
44 * Peer connected and ready to accept data
49 * Peer connected previosly but not responding
51 MESH_PEER_UNAVAILABLE,
54 * Peer requested but not ever connected
60 * Struct containing all information regarding a given peer
67 struct GNUNET_PeerIdentity id;
70 * Is the peer reachable? Is the peer even connected?
72 struct PeerState state;
75 * Who to send the data to
80 * Max data rate to this peer
86 * Information regarding a path
91 * Id of the path, in case it's needed
96 * Whether the path is serving traffic in a tunnel or is a backup
101 * List of all the peers that form the path from origin to target
107 * Struct containing all information regarding a tunnel
108 * For an intermediate node the improtant info used will be:
109 * - OID \ To identify
111 * - paths[0] | To know where to send it next
112 * - metainfo: ready, speeds, accounting
113 * For an end node more fields will be needed (client-handling)
118 * Origin ID: Node that created the tunnel
120 struct GNUNET_PeerIdentity oid;
123 * Tunnel number (unique for a given oid)
128 * Whether the tunnel is in state to transmit data
133 * Minimal speed for this tunnel in kb/s
138 * Maximal speed for this tunnel in kb/s
143 * Last time the tunnel was used
145 struct GNUNET_TIME_Absolute timestamp;
148 * Peers in the tunnel, for future optimizations
150 struct PeerInfo *peers;
153 * Paths (used and backup)
158 * Messages ready to transmit
160 struct GNUNET_MessageHeader *msg_out;
163 * Messages received and not processed
165 struct GNUNET_MessageHeader *msg_in;
168 * FIXME Clients. Is anyone to be notified for traffic here?
173 * So, I'm an endpoint. Why am I receiveing traffic?
174 * Who is interested in this? How to communicate with them?
179 * FIXME add structures needed to handle client connections
185 * Handler for requests of creating new path
188 * @param client the client this message is from
189 * @param message the message received
192 handle_mesh_path_create (void *cls,
193 struct GNUNET_SERVER_Client *client,
194 const struct GNUNET_MessageHeader *message)
200 * Handler for client disconnection
203 * @param client identification of the client; NULL
204 * for the last call when the server is destroyed
207 handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
209 /* Remove client from list, delete all timers and queues associated */
214 * Core handler for mesh network traffic
217 * @param message message
218 * @param peer peer identity this notification is about
219 * @param atsi performance data
223 handle_mesh_network_traffic (void *cls,
224 const struct GNUNET_PeerIdentity *peer,
225 const struct GNUNET_MessageHeader *message,
226 const struct GNUNET_TRANSPORT_ATS_Information
229 if(GNUNET_MESSAGE_TYPE_MESH_DATA_GO == ntohs(message->type)) {
230 /* Retransmit to next in path of tunnel identified by message */
232 } else { /* GNUNET_MESSAGE_TYPE_MESH_DATA_BACK */
233 /* Retransmit to previous in path of tunnel identified by message */
239 * Functions to handle messages from core
241 static struct GNUNET_CORE_MessageHandler core_handlers[] = {
242 {&handle_mesh_network_traffic, GNUNET_MESSAGE_TYPE_MESH_DATA_GO, 0},
243 {&handle_mesh_network_traffic, GNUNET_MESSAGE_TYPE_MESH_DATA_BACK, 0},
248 * Functions to handle messages from clients
250 static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
251 {&handle_mesh_path_create, NULL, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0},
256 * Process mesh requests. FIXME NON FUNCTIONAL, COPIED FROM DHT!!
259 * @param server the initialized server
260 * @param c configuration to use
264 struct GNUNET_SERVER_Handle *server,
265 const struct GNUNET_CONFIGURATION_Handle *c)
267 struct GNUNET_TIME_Relative next_send_time;
268 unsigned long long temp_config_num;
269 char *converge_modifier_buf;
270 GNUNET_CORE_Handle *coreAPI;
272 GNUNET_SERVER_add_handlers (server, plugin_handlers);
273 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
274 coreAPI = GNUNET_CORE_connect (c, /* Main configuration */
276 NULL, /* Closure passed to DHT functions */
277 NULL, /* Call core_init once connected */
278 NULL, /* Handle connects */
279 NULL, /* remove peers on disconnects */
280 NULL, /* Do we care about "status" updates? */
281 NULL, /* Don't want notified about all incoming messages */
282 GNUNET_NO, /* For header only inbound notification */
283 NULL, /* Don't want notified about all outbound messages */
284 GNUNET_NO, /* For header only outbound notification */
285 core_handlers); /* Register these handlers */
292 * The main function for the mesh service.
294 * @param argc number of arguments from the command line
295 * @param argv command line arguments
296 * @return 0 ok, 1 on error
299 main (int argc, char *const *argv)
304 GNUNET_SERVICE_run (argc,
307 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;