2 This file is part of GNUnet.
3 (C) 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 identity/gnunet-service-identity.c
23 * @brief identity management service
24 * @author Christian Grothoff
26 * The purpose of this service is to manage private keys that
27 * represent the various egos/pseudonyms/identities of a GNUnet user.
30 #include "gnunet_util_lib.h"
31 #include "gnunet_constants.h"
32 #include "gnunet_protocols.h"
33 #include "gnunet_statistics_service.h"
34 #include "gnunet_identity_service.h"
39 * Information we keep about each ego.
45 * We keep egos in a DLL.
50 * We keep egos in a DLL.
55 * Private key of the ego.
57 struct GNUNET_CRYPTO_EccPrivateKey *pk;
60 * String identifier for the ego.
68 * Handle to our current configuration.
70 static const struct GNUNET_CONFIGURATION_Handle *cfg;
73 * Handle to subsystem configuration which for each subsystem contains
74 * the name of the default ego.
76 static struct GNUNET_CONFIGURATION_Handle *subsystem_cfg;
79 * Handle to the statistics service.
81 static struct GNUNET_STATISTICS_Handle *stats;
84 * Notification context, simplifies client broadcasts.
86 static struct GNUNET_SERVER_NotificationContext *nc;
89 * Directory where we store the identities.
91 static char *ego_directory;
94 * Configuration file name where subsystem information is kept.
96 static char *subsystem_cfg_file;
99 * Head of DLL of all egos.
101 static struct Ego *ego_head;
104 * Tail of DLL of all egos.
106 static struct Ego *ego_tail;
110 * Task run during shutdown.
116 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
122 GNUNET_SERVER_notification_context_destroy (nc);
127 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
130 GNUNET_CONFIGURATION_destroy (subsystem_cfg);
131 subsystem_cfg = NULL;
132 GNUNET_free (subsystem_cfg_file);
133 subsystem_cfg_file = NULL;
134 GNUNET_free (ego_directory);
135 ego_directory = NULL;
136 while (NULL != (e = ego_head))
138 GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e);
139 GNUNET_CRYPTO_ecc_key_free (e->pk);
146 * Handler for START message from client, sends information
147 * about all identities to the client immediately and
148 * adds the client to the notification context for future
152 * @param client who sent the message
153 * @param message the message received
156 handle_start_message (void *cls, struct GNUNET_SERVER_Client *client,
157 const struct GNUNET_MessageHeader *message)
159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
160 "Received START message from client\n");
161 GNUNET_SERVER_notification_context_add (nc, client);
162 GNUNET_break (0); // not implemented!
163 // setup_estimate_message (&em);
164 // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES);
165 GNUNET_SERVER_receive_done (client, GNUNET_OK);
170 * Handler for GET_DEFAULT message from client, returns
171 * default identity for some service.
174 * @param client who sent the message
175 * @param message the message received
178 handle_get_default_message (void *cls, struct GNUNET_SERVER_Client *client,
179 const struct GNUNET_MessageHeader *message)
181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
182 "Received GET_DEFAULT message from client\n");
183 // setup_estimate_message (&em);
184 // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES);
185 GNUNET_break (0); // not implemented!
186 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
191 * Handler for SET_DEFAULT message from client, updates
192 * default identity for some service.
195 * @param client who sent the message
196 * @param message the message received
199 handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client,
200 const struct GNUNET_MessageHeader *message)
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
203 "Received SET_DEFAULT message from client\n");
204 // setup_estimate_message (&em);
205 // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES);
206 GNUNET_break (0); // not implemented!
207 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
212 * Handler for CREATE message from client, creates
216 * @param client who sent the message
217 * @param message the message received
220 handle_create_message (void *cls, struct GNUNET_SERVER_Client *client,
221 const struct GNUNET_MessageHeader *message)
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
224 "Received CREATE message from client\n");
225 // setup_estimate_message (&em);
226 // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES);
227 GNUNET_break (0); // not implemented!
228 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
234 * Handler for RENAME message from client, creates
238 * @param client who sent the message
239 * @param message the message received
242 handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
243 const struct GNUNET_MessageHeader *message)
245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
246 "Received RENAME message from client\n");
247 // setup_estimate_message (&em);
248 // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES);
249 GNUNET_break (0); // not implemented!
250 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
255 * Handler for DELETE message from client, creates
259 * @param client who sent the message
260 * @param message the message received
263 handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client,
264 const struct GNUNET_MessageHeader *message)
266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
267 "Received DELETE message from client\n");
268 // setup_estimate_message (&em);
269 // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES);
270 GNUNET_break (0); // not implemented!
271 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
276 * Handle network size estimate clients.
279 * @param server the initialized server
280 * @param c configuration to use
284 struct GNUNET_SERVER_Handle *server,
285 const struct GNUNET_CONFIGURATION_Handle *c)
287 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
288 {&handle_start_message, NULL,
289 GNUNET_MESSAGE_TYPE_IDENTITY_START, sizeof (struct GNUNET_MessageHeader)},
290 {&handle_get_default_message, NULL,
291 GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, 0},
292 {&handle_set_default_message, NULL,
293 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, 0},
294 {&handle_create_message, NULL,
295 GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, 0},
296 {&handle_rename_message, NULL,
297 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, 0},
298 {&handle_delete_message, NULL,
299 GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, 0},
305 GNUNET_CONFIGURATION_get_value_filename (cfg, "identity",
309 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR");
310 GNUNET_SCHEDULER_shutdown ();
314 GNUNET_CONFIGURATION_get_value_filename (cfg, "identity",
316 &subsystem_cfg_file))
318 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "SUBSYSTEM_CFG");
319 GNUNET_SCHEDULER_shutdown ();
322 subsystem_cfg = GNUNET_CONFIGURATION_create ();
324 GNUNET_DISK_file_test (subsystem_cfg_file)) &&
326 GNUNET_CONFIGURATION_parse (subsystem_cfg,
327 subsystem_cfg_file)) )
329 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
330 _("Failed to parse subsystem identity configuration file `%s'\n"),
332 GNUNET_SCHEDULER_shutdown ();
335 stats = GNUNET_STATISTICS_create ("identity", cfg);
336 GNUNET_SERVER_add_handlers (server, handlers);
337 nc = GNUNET_SERVER_notification_context_create (server, 1);
338 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
344 * The main function for the network size estimation service.
346 * @param argc number of arguments from the command line
347 * @param argv command line arguments
348 * @return 0 ok, 1 on error
351 main (int argc, char *const *argv)
354 GNUNET_SERVICE_run (argc, argv, "identity",
355 GNUNET_SERVICE_OPTION_NONE,
356 &run, NULL)) ? 0 : 1;
360 /* end of gnunet-service-identity.c */