e1d4dff8279e6ca5ef41007d35d227ef17d92fbc
[oweals/gnunet.git] / src / identity / gnunet-service-identity.c
1 /*
2   This file is part of GNUnet.
3   (C) 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 identity/gnunet-service-identity.c
23  * @brief identity management service
24  * @author Christian Grothoff
25  *
26  * The purpose of this service is to manage private keys that
27  * represent the various egos/pseudonyms/identities of a GNUnet user.
28  *
29  * TODO:
30  * - disk operations
31  */
32 #include "platform.h"
33 #include "gnunet_util_lib.h"
34 #include "gnunet_constants.h"
35 #include "gnunet_protocols.h"
36 #include "gnunet_statistics_service.h"
37 #include "gnunet_identity_service.h"
38 #include "identity.h"
39
40
41 /**
42  * Information we keep about each ego.
43  */
44 struct Ego
45 {
46
47   /**
48    * We keep egos in a DLL.
49    */ 
50   struct Ego *next;
51
52   /**
53    * We keep egos in a DLL.
54    */ 
55   struct Ego *prev;
56
57   /**
58    * Private key of the ego.
59    */
60   struct GNUNET_CRYPTO_EccPrivateKey *pk;
61
62   /**
63    * String identifier for the ego.
64    */
65   char *identifier;
66
67 };
68
69
70 /**
71  * Handle to our current configuration.
72  */
73 static const struct GNUNET_CONFIGURATION_Handle *cfg;
74
75 /**
76  * Handle to subsystem configuration which for each subsystem contains
77  * the name of the default ego.
78  */
79 static struct GNUNET_CONFIGURATION_Handle *subsystem_cfg;
80
81 /**
82  * Handle to the statistics service.
83  */
84 static struct GNUNET_STATISTICS_Handle *stats;
85
86 /**
87  * Notification context, simplifies client broadcasts.
88  */
89 static struct GNUNET_SERVER_NotificationContext *nc;
90
91 /**
92  * Directory where we store the identities.
93  */
94 static char *ego_directory;
95
96 /**
97  * Configuration file name where subsystem information is kept.
98  */
99 static char *subsystem_cfg_file;
100
101 /**
102  * Head of DLL of all egos.
103  */
104 static struct Ego *ego_head;
105
106 /**
107  * Tail of DLL of all egos.
108  */
109 static struct Ego *ego_tail;
110
111
112 /**
113  * Task run during shutdown.
114  *
115  * @param cls unused
116  * @param tc unused
117  */
118 static void
119 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
120 {
121   struct Ego *e;
122
123   if (NULL != nc)
124   {
125     GNUNET_SERVER_notification_context_destroy (nc);
126     nc = NULL;
127   }
128   if (NULL != stats)
129   {
130     GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
131     stats = NULL;
132   }
133   GNUNET_CONFIGURATION_destroy (subsystem_cfg);
134   subsystem_cfg = NULL;
135   GNUNET_free (subsystem_cfg_file);
136   subsystem_cfg_file = NULL;
137   GNUNET_free (ego_directory);
138   ego_directory = NULL;
139   while (NULL != (e = ego_head))
140   {
141     GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e);
142     GNUNET_CRYPTO_ecc_key_free (e->pk);
143     GNUNET_free (e);
144   }
145 }
146
147
148 /**
149  * Send a result code back to the client.
150  *
151  * @param client client that should receive the result code
152  * @param result_code code to transmit
153  * @param emsg error message to include (or NULL for none)
154  */
155 static void
156 send_result_code (struct GNUNET_SERVER_Client *client,
157                   uint32_t result_code,
158                   const char *emsg)
159 {
160   struct GNUNET_IDENTITY_ResultCodeMessage *rcm;
161   size_t elen;
162
163   if (NULL == emsg)
164     elen = 0;
165   else
166     elen = strlen (emsg) + 1;
167   rcm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_ResultCodeMessage) + elen);
168   rcm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
169   rcm->header.size = htons (sizeof (struct GNUNET_IDENTITY_ResultCodeMessage) + elen);
170   rcm->result_code = htonl (result_code);
171   memcpy (&rcm[1], emsg, elen);
172   GNUNET_SERVER_notification_context_unicast (nc, client, &rcm->header, GNUNET_YES);  
173   GNUNET_free (rcm);
174 }
175
176
177 /**
178  * Create an update message with information about the current state of an ego.
179  *
180  * @param ego ego to create message for
181  * @return corresponding update message
182  */
183 static struct GNUNET_IDENTITY_UpdateMessage *
184 create_update_message (struct Ego *ego)
185 {
186   struct GNUNET_IDENTITY_UpdateMessage *um;
187   char *str;
188   uint16_t pk_len;
189   size_t name_len;
190   struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
191
192   name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
193   enc = GNUNET_CRYPTO_ecc_encode_key (ego->pk);
194   pk_len = ntohs (enc->size);
195   um = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + pk_len + name_len);
196   um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
197   um->header.size = htons (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + pk_len + name_len);
198   um->name_len = htons (name_len);
199   um->pk_len = htons (pk_len);
200   str = (char *) &um[1];
201   memcpy (str, enc, pk_len);
202   memcpy (&str[pk_len], ego->identifier, name_len);
203   GNUNET_free (enc);
204   return um;
205 }
206
207
208 /**
209  * Create a set default message with information about the current state of an ego.
210  *
211  * @param ego ego to create message for
212  * @param servicename name of the service to provide in the message
213  * @return corresponding set default message
214  */
215 static struct GNUNET_IDENTITY_SetDefaultMessage *
216 create_set_default_message (struct Ego *ego,
217                             const char *servicename)
218 {
219   struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
220   char *str;
221   uint16_t pk_len;
222   size_t name_len;
223   struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
224
225   name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1);
226   enc = GNUNET_CRYPTO_ecc_encode_key (ego->pk);
227   pk_len = ntohs (enc->size);
228   sdm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + pk_len + name_len);
229   sdm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
230   sdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + pk_len + name_len);
231   sdm->name_len = htons (name_len);
232   sdm->pk_len = htons (pk_len);
233   str = (char *) &sdm[1];
234   memcpy (str, enc, pk_len);
235   memcpy (&str[pk_len], servicename, name_len);
236   GNUNET_free (enc);
237   return sdm;
238 }
239
240
241 /**
242  * Handler for START message from client, sends information
243  * about all identities to the client immediately and 
244  * adds the client to the notification context for future
245  * updates.
246  *
247  * @param cls unused
248  * @param client who sent the message
249  * @param message the message received
250  */
251 static void
252 handle_start_message (void *cls, struct GNUNET_SERVER_Client *client,
253                       const struct GNUNET_MessageHeader *message)
254 {
255   struct GNUNET_IDENTITY_UpdateMessage *um;
256   struct Ego *ego;
257
258   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
259               "Received START message from client\n");
260   GNUNET_SERVER_notification_context_add (nc, client);
261   for (ego = ego_head; NULL != ego; ego = ego->next)
262   {
263     um = create_update_message (ego);
264     GNUNET_SERVER_notification_context_unicast (nc, client, &um->header, GNUNET_YES);
265     GNUNET_free (um);
266   }
267   GNUNET_SERVER_receive_done (client, GNUNET_OK);
268 }
269
270
271 /**
272  * Handler for GET_DEFAULT message from client, returns
273  * default identity for some service.
274  *
275  * @param cls unused
276  * @param client who sent the message
277  * @param message the message received
278  */
279 static void
280 handle_get_default_message (void *cls, struct GNUNET_SERVER_Client *client,
281                             const struct GNUNET_MessageHeader *message)
282 {
283   const struct GNUNET_IDENTITY_GetDefaultMessage *gdm;
284   struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
285   uint16_t size;
286   uint16_t name_len;
287   struct Ego *ego;
288   const char *name;
289   char *identifier;
290
291   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
292               "Received GET_DEFAULT message from client\n");
293   size = ntohs (message->size);
294   if (size <= sizeof (struct GNUNET_IDENTITY_GetDefaultMessage))
295   {
296     GNUNET_break (0);
297     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
298     return;
299   }
300   gdm = (const struct GNUNET_IDENTITY_GetDefaultMessage *) message;
301   name = (const char *) &gdm[1];
302   name_len = ntohs (gdm->name_len);
303   if ( (name_len + sizeof (struct GNUNET_IDENTITY_GetDefaultMessage) != size) ||
304        (0 != ntohs (gdm->reserved)) ||
305        ('\0' != name[name_len - 1]) )
306   {
307     GNUNET_break (0);
308     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
309     return;
310   }
311   if (GNUNET_OK !=
312       GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
313                                              name,
314                                              "DEFAULT_IDENTIFIER",
315                                              &identifier))
316   {
317     send_result_code (client, 1, gettext_noop ("no default known"));
318     GNUNET_SERVER_receive_done (client, GNUNET_OK);   
319     return;
320   }
321   for (ego = ego_head; NULL != ego; ego = ego->next)
322   {
323     if (0 == strcmp (ego->identifier,
324                      identifier))
325     {
326       sdm = create_set_default_message (ego,
327                                         name);
328       GNUNET_SERVER_notification_context_broadcast (nc, &sdm->header, GNUNET_YES);
329       GNUNET_free (sdm);
330       GNUNET_SERVER_receive_done (client, GNUNET_OK);
331       return;
332     }
333   }
334   send_result_code (client, 1, 
335                     gettext_noop ("default configured, but ego unknown (internal error)"));
336   GNUNET_SERVER_receive_done (client, GNUNET_OK);
337 }
338
339
340 /**
341  * Compare the given two private keys for equality.
342  * 
343  * @param pk1 one private key
344  * @param pk2 another private key
345  * @return 0 if the keys are equal
346  */
347 static int
348 key_cmp (const struct GNUNET_CRYPTO_EccPrivateKey *pk1,
349          const struct GNUNET_CRYPTO_EccPrivateKey *pk2)
350 {
351   struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded p1;
352   struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded p2;
353   
354   GNUNET_CRYPTO_ecc_key_get_public (pk1, &p1);
355   GNUNET_CRYPTO_ecc_key_get_public (pk2, &p2);
356   return memcmp (&p1, &p2, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
357 }
358
359
360 /**
361  * Handler for SET_DEFAULT message from client, updates
362  * default identity for some service.
363  *
364  * @param cls unused
365  * @param client who sent the message
366  * @param message the message received
367  */
368 static void
369 handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client,
370                             const struct GNUNET_MessageHeader *message)
371 {
372   const struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
373   uint16_t size;
374   uint16_t name_len;
375   uint16_t pk_len;
376   struct Ego *ego;
377   const char *str;
378   struct GNUNET_CRYPTO_EccPrivateKey *pk;
379
380   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
381               "Received SET_DEFAULT message from client\n");
382   size = ntohs (message->size);
383   if (size <= sizeof (struct GNUNET_IDENTITY_SetDefaultMessage))
384   {
385     GNUNET_break (0);
386     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
387     return;
388   }
389   sdm = (const struct GNUNET_IDENTITY_SetDefaultMessage *) message;
390   name_len = ntohs (sdm->name_len);
391   pk_len = ntohs (sdm->pk_len);
392   str = (const char *) &sdm[1];
393   if ( (name_len + pk_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) != size) ||
394        (NULL == (pk = GNUNET_CRYPTO_ecc_decode_key (str, pk_len, GNUNET_YES))) )
395   {
396     GNUNET_break (0);
397     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
398     return;
399   }
400   str = &str[pk_len];
401   if ('\0' != str[name_len - 1])
402   {
403     GNUNET_break (0);
404     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
405     return;
406   }
407   for (ego = ego_head; NULL != ego; ego = ego->next)
408   {
409     if (0 == key_cmp (ego->pk,
410                       pk))
411     {
412       GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
413                                              str,
414                                              "DEFAULT_IDENTIFIER",
415                                              ego->identifier);
416       /* fixme: write configuration to disk... */
417       send_result_code (client, 0, NULL);
418       GNUNET_SERVER_receive_done (client, GNUNET_OK);
419       GNUNET_CRYPTO_ecc_key_free (pk);
420       return;
421     }
422   }  
423   send_result_code (client, 1, _("Unknown ego specified for service (internal error)"));
424   GNUNET_SERVER_receive_done (client, GNUNET_OK);
425   GNUNET_CRYPTO_ecc_key_free (pk);
426 }
427
428
429 /**
430  * Send an updated message for the given ego to all listeners.
431  *
432  * @param ego ego to send the update for
433  */
434 static void
435 notify_listeners (struct Ego *ego)
436 {
437   struct GNUNET_IDENTITY_UpdateMessage *um;
438
439   um = create_update_message (ego);
440   GNUNET_SERVER_notification_context_broadcast (nc, &um->header, GNUNET_YES);
441   GNUNET_free (um);
442 }
443
444
445 /**
446  * Handler for CREATE message from client, creates
447  * new identity.
448  *
449  * @param cls unused
450  * @param client who sent the message
451  * @param message the message received
452  */
453 static void
454 handle_create_message (void *cls, struct GNUNET_SERVER_Client *client,
455                        const struct GNUNET_MessageHeader *message)
456 {
457   const struct GNUNET_IDENTITY_CreateRequestMessage *crm;
458   uint16_t size;
459   uint16_t name_len;
460   uint16_t pk_len;
461   struct Ego *ego;
462   const char *str;
463   struct GNUNET_CRYPTO_EccPrivateKey *pk;
464
465   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
466               "Received CREATE message from client\n");
467   size = ntohs (message->size);
468   if (size <= sizeof (struct GNUNET_IDENTITY_CreateRequestMessage))
469   {
470     GNUNET_break (0);
471     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
472     return;
473   }
474   crm = (const struct GNUNET_IDENTITY_CreateRequestMessage *) message;
475   name_len = ntohs (crm->name_len);
476   pk_len = ntohs (crm->pk_len);
477   str = (const char *) &crm[1];
478   if ( (name_len + pk_len + sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) != size) ||
479        (NULL == (pk = GNUNET_CRYPTO_ecc_decode_key (str, pk_len, GNUNET_YES))) )
480   {
481     GNUNET_break (0);
482     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
483     return;
484   }
485   str = &str[pk_len];
486   if ('\0' != str[name_len - 1])
487   {
488     GNUNET_break (0);
489     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
490     return;
491   }
492   for (ego = ego_head; NULL != ego; ego = ego->next)
493   {
494     if (0 == strcmp (ego->identifier,
495                      str))
496     {
497       send_result_code (client, 1, gettext_noop ("identifier already in use for another ego"));
498       GNUNET_SERVER_receive_done (client, GNUNET_OK);
499       GNUNET_CRYPTO_ecc_key_free (pk);
500       return;
501     }
502   }
503   ego = GNUNET_new (struct Ego);
504   ego->pk = pk;
505   ego->identifier = GNUNET_strdup (str);
506   GNUNET_CONTAINER_DLL_insert (ego_head,
507                                ego_tail,
508                                ego);
509   send_result_code (client, 0, NULL);
510   /* FIXME: also write to file! */
511   notify_listeners (ego);  
512   GNUNET_SERVER_receive_done (client, GNUNET_OK);
513 }
514
515
516
517 /**
518  * Handler for RENAME message from client, creates
519  * new identity.
520  *
521  * @param cls unused
522  * @param client who sent the message
523  * @param message the message received
524  */
525 static void
526 handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
527                        const struct GNUNET_MessageHeader *message)
528 {
529   const struct GNUNET_IDENTITY_RenameMessage *rm;
530   uint16_t size;
531   uint16_t old_name_len;
532   uint16_t new_name_len;
533   struct Ego *ego;
534   const char *old_name;
535   const char *new_name;
536
537   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
538               "Received RENAME message from client\n");
539   size = ntohs (message->size);
540   if (size <= sizeof (struct GNUNET_IDENTITY_RenameMessage))
541   {
542     GNUNET_break (0);
543     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
544     return;
545   }
546   rm = (const struct GNUNET_IDENTITY_RenameMessage *) message;
547   old_name_len = ntohs (rm->old_name_len);
548   new_name_len = ntohs (rm->new_name_len);
549   old_name = (const char *) &rm[1];
550   new_name = &old_name[old_name_len];
551   if ( (old_name_len + new_name_len + sizeof (struct GNUNET_IDENTITY_RenameMessage) != size) ||
552        ('\0' != old_name[old_name_len - 1]) ||
553        ('\0' != new_name[new_name_len - 1]) )
554   {
555     GNUNET_break (0);
556     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
557     return;
558   }
559   for (ego = ego_head; NULL != ego; ego = ego->next)
560   {
561     if (0 == strcmp (ego->identifier,
562                      old_name))
563     {
564       GNUNET_free (ego->identifier);
565       ego->identifier = GNUNET_strdup (new_name);
566       /* FIXME: also rename file! */
567       notify_listeners (ego);
568       send_result_code (client, 0, NULL);
569       GNUNET_SERVER_receive_done (client, GNUNET_OK);
570       return;
571     }
572   }
573
574   send_result_code (client, 1, gettext_noop ("no matching ego found"));
575   GNUNET_SERVER_receive_done (client, GNUNET_OK);
576 }
577
578
579 /**
580  * Handler for DELETE message from client, creates
581  * new identity.
582  *
583  * @param cls unused
584  * @param client who sent the message
585  * @param message the message received
586  */
587 static void
588 handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client,
589                        const struct GNUNET_MessageHeader *message)
590 {
591   const struct GNUNET_IDENTITY_DeleteMessage *dm;
592   uint16_t size;
593   uint16_t name_len;
594   struct Ego *ego;
595   const char *name;
596
597   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
598               "Received DELETE message from client\n");
599   size = ntohs (message->size);
600   if (size <= sizeof (struct GNUNET_IDENTITY_DeleteMessage))
601   {
602     GNUNET_break (0);
603     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
604     return;
605   }
606   dm = (const struct GNUNET_IDENTITY_DeleteMessage *) message;
607   name = (const char *) &dm[1];
608   name_len = ntohs (dm->name_len);
609   if ( (name_len + sizeof (struct GNUNET_IDENTITY_DeleteMessage) != size) ||
610        (0 != ntohs (dm->reserved)) ||
611        ('\0' != name[name_len - 1]) )
612   {
613     GNUNET_break (0);
614     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
615     return;
616   }
617   for (ego = ego_head; NULL != ego; ego = ego->next)
618   {
619     if (0 == strcmp (ego->identifier,
620                      name))
621     {
622       GNUNET_CONTAINER_DLL_remove (ego_head,
623                                    ego_tail,
624                                    ego);
625       /* FIXME: also delete file! */
626       GNUNET_free (ego->identifier);
627       ego->identifier = NULL;
628       notify_listeners (ego);
629       GNUNET_CRYPTO_ecc_key_free (ego->pk);
630       GNUNET_free (ego);
631       send_result_code (client, 0, NULL);
632       GNUNET_SERVER_receive_done (client, GNUNET_OK);
633       return;
634     }
635   }
636
637   send_result_code (client, 1, gettext_noop ("no matching ego found"));
638   GNUNET_SERVER_receive_done (client, GNUNET_OK);
639 }
640
641
642 /**
643  * Process the given file from the "EGODIR".  Parses the file
644  * and creates the respective 'struct Ego' in memory.
645  *
646  * @param cls NULL
647  * @param filename name of the file to parse
648  * @return GNUNET_OK to continue to iterate,
649  *  GNUNET_NO to stop iteration with no error,
650  *  GNUNET_SYSERR to abort iteration with error!
651  */
652 static int
653 process_ego_file (void *cls,
654                   const char *filename)
655 {
656   GNUNET_break (0); // not implemented
657   return GNUNET_OK;
658 }
659
660
661 /**
662  * Handle network size estimate clients.
663  *
664  * @param cls closure
665  * @param server the initialized server
666  * @param c configuration to use
667  */
668 static void
669 run (void *cls, 
670      struct GNUNET_SERVER_Handle *server,
671      const struct GNUNET_CONFIGURATION_Handle *c)
672 {
673   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
674     {&handle_start_message, NULL,
675      GNUNET_MESSAGE_TYPE_IDENTITY_START, sizeof (struct GNUNET_MessageHeader)},
676     {&handle_get_default_message, NULL,
677      GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, 0},
678     {&handle_set_default_message, NULL,
679      GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, 0},
680     {&handle_create_message, NULL,
681      GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, 0},
682     {&handle_rename_message, NULL,
683      GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, 0},
684     {&handle_delete_message, NULL,
685      GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, 0},
686     {NULL, NULL, 0, 0}
687   };
688
689   cfg = c;
690   if (GNUNET_OK !=
691       GNUNET_CONFIGURATION_get_value_filename (cfg, "identity",
692                                                "EGODIR",
693                                                &ego_directory))
694   {
695     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR");
696     GNUNET_SCHEDULER_shutdown ();
697     return;
698   }
699   if (GNUNET_OK !=
700       GNUNET_CONFIGURATION_get_value_filename (cfg, "identity",
701                                                "SUBSYSTEM_CFG",
702                                                &subsystem_cfg_file))
703   {
704     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "SUBSYSTEM_CFG");
705     GNUNET_SCHEDULER_shutdown ();
706     return;
707   }
708   subsystem_cfg = GNUNET_CONFIGURATION_create ();
709   if ( (GNUNET_YES ==
710         GNUNET_DISK_file_test (subsystem_cfg_file)) &&
711        (GNUNET_OK != 
712         GNUNET_CONFIGURATION_parse (subsystem_cfg,
713                                     subsystem_cfg_file)) )
714   {
715     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
716                 _("Failed to parse subsystem identity configuration file `%s'\n"),
717                 subsystem_cfg_file);
718     GNUNET_SCHEDULER_shutdown ();
719     return;
720   }
721   stats = GNUNET_STATISTICS_create ("identity", cfg);
722   GNUNET_SERVER_add_handlers (server, handlers);
723   nc = GNUNET_SERVER_notification_context_create (server, 1);
724   GNUNET_DISK_directory_scan (ego_directory,
725                               &process_ego_file,
726                               NULL);
727   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
728                                 NULL);
729 }
730
731
732 /**
733  * The main function for the network size estimation service.
734  *
735  * @param argc number of arguments from the command line
736  * @param argv command line arguments
737  * @return 0 ok, 1 on error
738  */
739 int
740 main (int argc, char *const *argv)
741 {
742   return (GNUNET_OK ==
743           GNUNET_SERVICE_run (argc, argv, "identity", 
744                               GNUNET_SERVICE_OPTION_NONE,
745                               &run, NULL)) ? 0 : 1;
746 }
747
748
749 /* end of gnunet-service-identity.c */