2 This file is part of GNUnet.
3 Copyright (C) 2001-2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file cadet/gnunet-service-cadet.c
23 * @brief GNUnet CADET service with encryption
24 * @author Bartlomiej Polot
27 * - rekey - reliability interaction
28 * - channel retransmit timing
31 * - relay corking down to core
32 * - set ttl relative to path length
36 * - peer: other cadet instance. If there is direct connection it's a neighbor.
37 * - tunnel: encrypted connection to a peer, neighbor or not.
38 * - channel: connection between two clients, on the same or different peers.
39 * have properties like reliability.
40 * - path: series of directly connected peer from one peer to another.
41 * - connection: path which is being used in a tunnel.
45 #include "gnunet_util_lib.h"
47 #include "gnunet_statistics_service.h"
49 #include "gnunet-service-cadet_local.h"
50 #include "gnunet-service-cadet_channel.h"
51 #include "gnunet-service-cadet_connection.h"
52 #include "gnunet-service-cadet_tunnel.h"
53 #include "gnunet-service-cadet_dht.h"
54 #include "gnunet-service-cadet_peer.h"
55 #include "gnunet-service-cadet_hello.h"
58 /******************************************************************************/
59 /*********************** GLOBAL VARIABLES ****************************/
60 /******************************************************************************/
62 /****************************** Global variables ******************************/
65 * Handle to the statistics service.
67 struct GNUNET_STATISTICS_Handle *stats;
70 * Local peer own ID (memory efficient handle).
75 * Local peer own ID (full value).
77 struct GNUNET_PeerIdentity my_full_id;
81 * Signal that shutdown is happening: prevent recover measures.
85 /*************************** Static global variables **************************/
90 static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
93 /******************************************************************************/
94 /************************ MAIN FUNCTIONS ****************************/
95 /******************************************************************************/
98 * Task run during shutdown.
103 shutdown_task (void *cls)
105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n");
107 shutting_down = GNUNET_YES;
116 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n");
123 * Process cadet requests.
126 * @param server the initialized server
127 * @param c configuration to use
130 run (void *cls, struct GNUNET_SERVER_Handle *server,
131 const struct GNUNET_CONFIGURATION_Handle *c)
133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n");
135 stats = GNUNET_STATISTICS_create ("cadet", c);
137 /* Scheduled the task to clean up when shutdown is called */
138 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
140 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reading key\n");
141 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (c);
142 GNUNET_assert (NULL != my_private_key);
143 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_full_id.public_key);
144 myid = GNUNET_PEER_intern (&my_full_id);
145 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
146 "STARTING SERVICE (cadet) for peer [%s]\n",
147 GNUNET_i2s (&my_full_id));
149 GML_init (server); /* Local clients */
150 GCH_init (c); /* Hellos */
151 GCC_init (c); /* Connections */
152 GCP_init (c); /* Peers */
153 GCD_init (c); /* DHT */
154 GCT_init (c, my_private_key); /* Tunnels */
156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cadet service running\n");
161 * The main function for the cadet service.
163 * @param argc number of arguments from the command line
164 * @param argv command line arguments
165 * @return 0 ok, 1 on error
168 main (int argc, char *const *argv)
172 shutting_down = GNUNET_NO;
173 r = GNUNET_SERVICE_run (argc, argv, "cadet", GNUNET_SERVICE_OPTION_NONE, &run,
175 GNUNET_free (my_private_key);
179 FPRINTF (stderr, "GNUNET_SERVICE_run for CADET has failed!\n");