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 /******************************************************************************/
114 * Send an ACK on the appropriate connection/channel, depending on
115 * the direction and the position of the peer.
117 * @param c Which connection to send the hop-by-hop ACK.
118 * @param ch Channel, if any.
119 * @param fwd Is this a fwd ACK? (will go dest->root)
122 send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd)
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
127 "send ack %s on %p %p\n",
128 fwd ? "FWD" : "BCK", c, ch);
129 if (NULL == c || GMC_is_terminal (c, fwd))
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " getting from all connections\n");
132 buffer = tunnel_get_buffer (NULL == c ? ch->t : c->t, fwd);
136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " getting from one connection\n");
137 buffer = connection_get_buffer (c, fwd);
139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " buffer available: %u\n", buffer);
141 if ( (NULL != ch && channel_is_origin (ch, fwd)) ||
142 (NULL != c && connection_is_origin (c, fwd)) )
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n");
147 GNUNET_assert (NULL != ch);
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " really sending!\n");
149 send_local_ack (ch, fwd);
154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " sending on all connections\n");
155 GNUNET_assert (NULL != ch);
156 channel_send_connections_ack (ch, buffer, fwd);
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " sending on connection\n");
161 connection_send_ack (c, buffer, fwd);
174 /******************************************************************************/
175 /**************** MESH NETWORK HANDLER HELPERS ***********************/
176 /******************************************************************************/
183 /******************************************************************************/
184 /******************** MESH NETWORK HANDLERS **************************/
185 /******************************************************************************/
190 /******************************************************************************/
191 /************************ MAIN FUNCTIONS ****************************/
192 /******************************************************************************/
196 * Task run during shutdown.
202 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n");
212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n");
217 * Process mesh requests.
220 * @param server the initialized server
221 * @param c configuration to use
224 run (void *cls, struct GNUNET_SERVER_Handle *server,
225 const struct GNUNET_CONFIGURATION_Handle *c)
227 struct GNUNET_CRYPTO_EccPrivateKey *pk;
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n");
231 stats = GNUNET_STATISTICS_create ("mesh", c);
233 /* Scheduled the task to clean up when shutdown is called */
234 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
236 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reading key\n");
237 pk = GNUNET_CRYPTO_ecc_key_create_from_configuration (c);
238 GNUNET_assert (NULL != pk);
240 GNUNET_CRYPTO_ecc_key_get_public_for_signature (my_private_key,
241 &my_full_id.public_key);
242 myid = GNUNET_PEER_intern (&my_full_id);
243 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
244 "Mesh for peer [%s] starting\n",
245 GNUNET_i2s (&my_full_id));
247 GML_init (server); /* Local clients */
248 GMC_init (c); /* Connections */
249 GMP_init (c); /* Peers */
250 GMD_init (c, &my_full_id); /* DHT */
251 GMT_init (c, &my_full_id, &my_private_key);
253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh service running\n");
258 * The main function for the mesh service.
260 * @param argc number of arguments from the command line
261 * @param argv command line arguments
262 * @return 0 ok, 1 on error
265 main (int argc, char *const *argv)
270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main()\n");
271 r = GNUNET_SERVICE_run (argc, argv, "mesh", GNUNET_SERVICE_OPTION_NONE, &run,
273 ret = (GNUNET_OK == r) ? 0 : 1;
274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main() END\n");