aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/gnunet-service-cadet.c')
-rw-r--r--src/cadet/gnunet-service-cadet.c181
1 files changed, 181 insertions, 0 deletions
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c
new file mode 100644
index 000000000..de9aaf7a5
--- /dev/null
+++ b/src/cadet/gnunet-service-cadet.c
@@ -0,0 +1,181 @@
1/*
2 This file is part of GNUnet.
3 (C) 2001-2013 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19*/
20
21/**
22 * @file cadet/gnunet-service-cadet.c
23 * @brief GNUnet CADET service with encryption
24 * @author Bartlomiej Polot
25 *
26 * FIXME in progress:
27 * - rekey - reliability interaction
28 * - channel retransmit timing
29 *
30 * TODO:
31 * - relay corking down to core
32 * - set ttl relative to path length
33 * TODO END
34 *
35 * Dictionary:
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.
42 */
43
44#include "platform.h"
45#include "gnunet_util_lib.h"
46#include "cadet.h"
47#include "gnunet_statistics_service.h"
48
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"
56
57
58/******************************************************************************/
59/*********************** GLOBAL VARIABLES ****************************/
60/******************************************************************************/
61
62/****************************** Global variables ******************************/
63
64/**
65 * Handle to the statistics service.
66 */
67struct GNUNET_STATISTICS_Handle *stats;
68
69/**
70 * Local peer own ID (memory efficient handle).
71 */
72GNUNET_PEER_Id myid;
73
74/**
75 * Local peer own ID (full value).
76 */
77struct GNUNET_PeerIdentity my_full_id;
78
79
80/**
81 * Signal that shutdown is happening: prevent recover measures.
82 */
83int shutting_down;
84
85/*************************** Static global variables **************************/
86
87/**
88 * Own private key.
89 */
90static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
91
92
93/******************************************************************************/
94/************************ MAIN FUNCTIONS ****************************/
95/******************************************************************************/
96
97/**
98 * Task run during shutdown.
99 *
100 * @param cls unused
101 * @param tc unused
102 */
103static void
104shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
105{
106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n");
107
108 shutting_down = GNUNET_YES;
109
110 GML_shutdown ();
111 GMH_shutdown ();
112 GMC_shutdown ();
113 GMT_shutdown ();
114 GMD_shutdown ();
115 GMP_shutdown ();
116
117 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
118 stats = NULL;
119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n");
120}
121
122
123/**
124 * Process cadet requests.
125 *
126 * @param cls closure
127 * @param server the initialized server
128 * @param c configuration to use
129 */
130static void
131run (void *cls, struct GNUNET_SERVER_Handle *server,
132 const struct GNUNET_CONFIGURATION_Handle *c)
133{
134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n");
135
136 stats = GNUNET_STATISTICS_create ("cadet", c);
137
138 /* Scheduled the task to clean up when shutdown is called */
139 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
140 NULL);
141 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reading key\n");
142 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (c);
143 GNUNET_assert (NULL != my_private_key);
144 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_full_id.public_key);
145 myid = GNUNET_PEER_intern (&my_full_id);
146 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
147 "STARTING SERVICE (CADET) for peer [%s]\n",
148 GNUNET_i2s (&my_full_id));
149
150 GML_init (server); /* Local clients */
151 GMH_init (c); /* Hellos */
152 GMC_init (c); /* Connections */
153 GMP_init (c); /* Peers */
154 GMD_init (c); /* DHT */
155 GMT_init (c, my_private_key); /* Tunnels */
156
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cadet service running\n");
158}
159
160
161/**
162 * The main function for the cadet service.
163 *
164 * @param argc number of arguments from the command line
165 * @param argv command line arguments
166 * @return 0 ok, 1 on error
167 */
168int
169main (int argc, char *const *argv)
170{
171 int ret;
172 int r;
173
174 shutting_down = GNUNET_NO;
175 r = GNUNET_SERVICE_run (argc, argv, "cadet", GNUNET_SERVICE_OPTION_NONE, &run,
176 NULL);
177 GNUNET_free (my_private_key);
178 ret = (GNUNET_OK == r) ? 0 : 1;
179
180 return ret;
181}