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 /******************************************************************************/
114 /**************** MESH NETWORK HANDLER HELPERS ***********************/
115 /******************************************************************************/
119 /******************************************************************************/
120 /******************** MESH NETWORK HANDLERS **************************/
121 /******************************************************************************/
124 /******************************************************************************/
125 /************************ MAIN FUNCTIONS ****************************/
126 /******************************************************************************/
130 * Task run during shutdown.
136 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n");
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n");
151 * Process mesh requests.
154 * @param server the initialized server
155 * @param c configuration to use
158 run (void *cls, struct GNUNET_SERVER_Handle *server,
159 const struct GNUNET_CONFIGURATION_Handle *c)
161 struct GNUNET_CRYPTO_EccPrivateKey *pk;
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n");
165 stats = GNUNET_STATISTICS_create ("mesh", c);
167 /* Scheduled the task to clean up when shutdown is called */
168 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
170 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reading key\n");
171 pk = GNUNET_CRYPTO_ecc_key_create_from_configuration (c);
172 GNUNET_assert (NULL != pk);
174 GNUNET_CRYPTO_ecc_key_get_public_for_signature (my_private_key,
175 &my_full_id.public_key);
176 myid = GNUNET_PEER_intern (&my_full_id);
177 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
178 "Mesh for peer [%s] starting\n",
179 GNUNET_i2s (&my_full_id));
181 GML_init (server); /* Local clients */
182 GMC_init (c); /* Connections */
183 GMP_init (c); /* Peers */
184 GMD_init (c, &my_full_id); /* DHT */
185 GMT_init (c, &my_full_id, my_private_key);
187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh service running\n");
192 * The main function for the mesh service.
194 * @param argc number of arguments from the command line
195 * @param argv command line arguments
196 * @return 0 ok, 1 on error
199 main (int argc, char *const *argv)
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main()\n");
205 r = GNUNET_SERVICE_run (argc, argv, "mesh", GNUNET_SERVICE_OPTION_NONE, &run,
207 ret = (GNUNET_OK == r) ? 0 : 1;
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main() END\n");