2 This file is part of GNUnet.
3 (C) 2001-2013 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-enc.c
23 * @brief GNUnet MESH service with encryption
24 * @author Bartlomiej Polot
27 * - when sending in-order buffered data, wait for client ACKs
30 * - set connection IDs independently from tunnel, tunnel has no ID
33 * - relay corking down to core
34 * - set ttl relative to path length
38 * - peer: other mesh instance. If there is direct connection it's a neighbor.
39 * - tunnel: encrypted connection to a peer, neighbor or not.
40 * - channel: connection between two clients, on the same or different peers.
41 * have properties like reliability.
42 * - path: series of directly connected peer from one peer to another.
43 * - connection: path which is being used in a tunnel.
47 #include "gnunet_util_lib.h"
49 #include "block_mesh.h"
50 #include "gnunet_statistics_service.h"
52 #include "gnunet-service-mesh_local.h"
53 #include "gnunet-service-mesh_channel.h"
54 #include "gnunet-service-mesh_connection.h"
55 #include "gnunet-service-mesh_tunnel.h"
56 #include "gnunet-service-mesh_dht.h"
57 #include "gnunet-service-mesh_peer.h"
60 /******************************************************************************/
61 /************************ DATA STRUCTURES ****************************/
62 /******************************************************************************/
66 /******************************************************************************/
67 /************************ DEBUG FUNCTIONS ****************************/
68 /******************************************************************************/
71 /******************************************************************************/
72 /*********************** GLOBAL VARIABLES ****************************/
73 /******************************************************************************/
75 /************************** Configuration parameters **************************/
79 /*************************** Static global variables **************************/
82 * Handle to the statistics service.
84 static struct GNUNET_STATISTICS_Handle *stats;
87 * Local peer own ID (memory efficient handle).
89 static GNUNET_PEER_Id myid;
92 * Local peer own ID (full value).
94 static struct GNUNET_PeerIdentity my_full_id;
99 static struct GNUNET_CRYPTO_EccPrivateKey *my_private_key;
102 /******************************************************************************/
103 /*********************** DECLARATIONS **************************/
104 /******************************************************************************/
107 /******************************************************************************/
108 /****************** GENERAL HELPER FUNCTIONS ************************/
109 /******************************************************************************/
113 * Get the static string for a peer ID.
117 * @return Static string for it's ID.
120 peer2s (const struct MeshPeer *peer)
124 return GNUNET_i2s (GNUNET_PEER_resolve2 (peer->id));
130 * Send an ACK on the appropriate connection/channel, depending on
131 * the direction and the position of the peer.
133 * @param c Which connection to send the hop-by-hop ACK.
134 * @param ch Channel, if any.
135 * @param fwd Is this a fwd ACK? (will go dest->root)
138 send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd)
142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
143 "send ack %s on %p %p\n",
144 fwd ? "FWD" : "BCK", c, ch);
145 if (NULL == c || GMC_is_terminal (c, fwd))
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " getting from all connections\n");
148 buffer = tunnel_get_buffer (NULL == c ? ch->t : c->t, fwd);
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " getting from one connection\n");
153 buffer = connection_get_buffer (c, fwd);
155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " buffer available: %u\n", buffer);
157 if ( (NULL != ch && channel_is_origin (ch, fwd)) ||
158 (NULL != c && connection_is_origin (c, fwd)) )
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n");
163 GNUNET_assert (NULL != ch);
164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " really sending!\n");
165 send_local_ack (ch, fwd);
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " sending on all connections\n");
171 GNUNET_assert (NULL != ch);
172 channel_send_connections_ack (ch, buffer, fwd);
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " sending on connection\n");
177 connection_send_ack (c, buffer, fwd);
190 /******************************************************************************/
191 /**************** MESH NETWORK HANDLER HELPERS ***********************/
192 /******************************************************************************/
199 /******************************************************************************/
200 /******************** MESH NETWORK HANDLERS **************************/
201 /******************************************************************************/
206 /******************************************************************************/
207 /************************ MAIN FUNCTIONS ****************************/
208 /******************************************************************************/
212 * Task run during shutdown.
218 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n");
228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n");
233 * Process mesh requests.
236 * @param server the initialized server
237 * @param c configuration to use
240 run (void *cls, struct GNUNET_SERVER_Handle *server,
241 const struct GNUNET_CONFIGURATION_Handle *c)
243 struct GNUNET_CRYPTO_EccPrivateKey *pk;
245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n");
247 stats = GNUNET_STATISTICS_create ("mesh", c);
249 /* Scheduled the task to clean up when shutdown is called */
250 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
252 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reading key\n");
253 pk = GNUNET_CRYPTO_ecc_key_create_from_configuration (c);
254 GNUNET_assert (NULL != pk);
256 GNUNET_CRYPTO_ecc_key_get_public_for_signature (my_private_key,
257 &my_full_id.public_key);
258 myid = GNUNET_PEER_intern (&my_full_id);
259 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
260 "Mesh for peer [%s] starting\n",
261 GNUNET_i2s (&my_full_id));
263 GML_init (server); /* Local clients */
264 GMC_init (c); /* Connections */
265 GMP_init (c); /* Peers */
266 GMD_init (c, &my_full_id); /* DHT */
267 GMT_init (c, &my_full_id, &my_private_key);
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh service running\n");
274 * The main function for the mesh service.
276 * @param argc number of arguments from the command line
277 * @param argv command line arguments
278 * @return 0 ok, 1 on error
281 main (int argc, char *const *argv)
286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main()\n");
287 r = GNUNET_SERVICE_run (argc, argv, "mesh", GNUNET_SERVICE_OPTION_NONE, &run,
289 ret = (GNUNET_OK == r) ? 0 : 1;
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main() END\n");