GNUnet  0.19.3
gnunet-service-identity.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2013 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your 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  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
33 #include "platform.h"
34 #include "gnunet_util_lib.h"
35 #include "gnunet_constants.h"
36 #include "gnunet_protocols.h"
39 #include "identity.h"
40 
41 
45 struct Ego
46 {
50  struct Ego *next;
51 
55  struct Ego *prev;
56 
61 
65  char *identifier;
66 };
67 
68 
72 static const struct GNUNET_CONFIGURATION_Handle *cfg;
73 
79 
84 
89 
93 static char *ego_directory;
94 
98 static char *subsystem_cfg_file;
99 
103 static struct Ego *ego_head;
104 
108 static struct Ego *ego_tail;
109 
110 
117 static char *
118 get_ego_filename (struct Ego *ego)
119 {
120  char *filename;
121 
123  "%s%s%s",
126  ego->identifier);
127  return filename;
128 }
129 
130 
138 static void
140  struct GNUNET_SERVICE_Client *client,
141  void *app_ctx)
142 {
144  "Client %p disconnected\n",
145  client);
146 }
147 
148 
157 static void *
158 client_connect_cb (void *cls,
159  struct GNUNET_SERVICE_Client *client,
160  struct GNUNET_MQ_Handle *mq)
161 {
162  return client;
163 }
164 
165 
171 static void
172 shutdown_task (void *cls)
173 {
174  struct Ego *e;
175 
176  if (NULL != nc)
177  {
179  nc = NULL;
180  }
181  if (NULL != stats)
182  {
184  stats = NULL;
185  }
187  subsystem_cfg = NULL;
189  subsystem_cfg_file = NULL;
191  ego_directory = NULL;
192  while (NULL != (e = ego_head))
193  {
195  ego_tail,
196  e);
197  GNUNET_free (e->identifier);
198  GNUNET_free (e);
199  }
200 }
201 
202 
209 static void
211  uint32_t result_code)
212 {
213  struct ResultCodeMessage *rcm;
214  struct GNUNET_MQ_Envelope *env;
215 
216  env =
218  rcm->result_code = htonl (result_code);
220  "Sending result %d (%s) to client\n",
221  (int) result_code,
222  GNUNET_ErrorCode_get_hint (result_code));
224 }
225 
226 
233 static struct GNUNET_MQ_Envelope *
235 {
236  struct UpdateMessage *um;
237  struct GNUNET_MQ_Envelope *env;
238  size_t name_len;
239  ssize_t key_len;
240 
241  key_len = GNUNET_IDENTITY_private_key_get_length (&ego->pk);
242  name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
243  env = GNUNET_MQ_msg_extra (um, name_len + key_len,
245  um->name_len = htons (name_len);
246  um->end_of_list = htons (GNUNET_NO);
247  um->key_len = htons (key_len);
248  GNUNET_memcpy (&um[1], ego->identifier, name_len);
250  ((char*) &um[1]) + name_len,
251  key_len);
252  return env;
253 }
254 
255 
265 static void
267  const struct GNUNET_MessageHeader *message)
268 {
269  struct GNUNET_SERVICE_Client *client = cls;
270 
272  "Received START message from client\n");
277  for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
278  {
280  create_update_message (ego));
281  }
282  {
283  struct UpdateMessage *ume;
284  struct GNUNET_MQ_Envelope *env;
285 
286  env = GNUNET_MQ_msg_extra (ume,
287  0,
289  ume->end_of_list = htons (GNUNET_YES);
290  ume->name_len = htons (0);
291  ume->key_len = htons (0);
293  env);
294  }
296 }
297 
298 
307 static int
309  const struct LookupMessage *message)
310 {
312  return GNUNET_OK;
313 }
314 
315 
323 static void
325  const struct LookupMessage *message)
326 {
327  struct GNUNET_SERVICE_Client *client = cls;
328  const char *name;
329  struct GNUNET_MQ_Envelope *env;
330  struct Ego *ego;
331 
333  "Received LOOKUP message from client\n");
334  name = (const char *) &message[1];
335  for (ego = ego_head; NULL != ego; ego = ego->next)
336  {
337  if (0 != strcasecmp (name, ego->identifier))
338  continue;
339  env = create_update_message (ego);
342  return;
343  }
346 }
347 
348 
357 static int
359  const struct LookupMessage *message)
360 {
362  return GNUNET_OK;
363 }
364 
365 
373 static void
375  const struct LookupMessage *message)
376 {
377  struct GNUNET_SERVICE_Client *client = cls;
378  const char *name;
379  struct GNUNET_MQ_Envelope *env;
380  struct Ego *lprefix;
381 
383  "Received LOOKUP_BY_SUFFIX message from client\n");
384  name = (const char *) &message[1];
385  lprefix = NULL;
386  for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
387  {
388  if ((strlen (ego->identifier) <= strlen (name)) &&
389  (0 == strcmp (ego->identifier,
390  &name[strlen (name) - strlen (ego->identifier)])) &&
391  ((strlen (name) == strlen (ego->identifier)) ||
392  ('.' == name[strlen (name) - strlen (ego->identifier) - 1])) &&
393  ((NULL == lprefix) ||
394  (strlen (ego->identifier) > strlen (lprefix->identifier))))
395  {
396  /* found better match, update! */
397  lprefix = ego;
398  }
399  }
400  if (NULL != lprefix)
401  {
402  env = create_update_message (lprefix);
405  return;
406  }
409 }
410 
411 
417 static void
418 notify_listeners (struct Ego *ego)
419 {
420  struct UpdateMessage *um;
421  size_t name_len;
422  ssize_t key_len;
423 
424  name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
426  um = GNUNET_malloc (sizeof(struct UpdateMessage) + name_len + key_len);
428  um->header.size = htons (sizeof(struct UpdateMessage) + name_len + key_len);
429  um->name_len = htons (name_len);
430  um->end_of_list = htons (GNUNET_NO);
431  um->key_len = htons (key_len);
432  GNUNET_memcpy (&um[1], ego->identifier, name_len);
434  ((char*) &um[1]) + name_len,
435  key_len);
437  GNUNET_free (um);
438 }
439 
440 
448 static int
450  const struct CreateRequestMessage *msg)
451 {
452  uint16_t size;
453  uint16_t name_len;
454  size_t key_len;
455  const char *str;
456 
457  size = ntohs (msg->header.size);
458  if (size <= sizeof(struct CreateRequestMessage))
459  {
460  GNUNET_break (0);
461  return GNUNET_SYSERR;
462  }
463  name_len = ntohs (msg->name_len);
464  key_len = ntohs (msg->key_len);
465  if (name_len + key_len + sizeof(struct CreateRequestMessage) != size)
466  {
467  GNUNET_break (0);
468  return GNUNET_SYSERR;
469  }
470  str = (const char *) &msg[1] + key_len;
471  if ('\0' != str[name_len - 1])
472  {
473  GNUNET_break (0);
474  return GNUNET_SYSERR;
475  }
476  return GNUNET_OK;
477 }
478 
479 
486 static void
488  const struct CreateRequestMessage *crm)
489 {
490  struct GNUNET_IDENTITY_PrivateKey private_key;
491  struct GNUNET_SERVICE_Client *client = cls;
492  struct Ego *ego;
493  char *str;
494  char *fn;
495  size_t key_len;
496  size_t kb_read;
497 
498  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n");
499  key_len = ntohs (crm->key_len);
500  if ((GNUNET_SYSERR ==
502  key_len,
503  &private_key,
504  &kb_read)) ||
505  (kb_read != key_len))
506  {
508  return;
509  }
510  str = GNUNET_strdup ((const char *) &crm[1] + key_len);
511  GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1] + key_len, str);
512  for (ego = ego_head; NULL != ego; ego = ego->next)
513  {
514  if (0 == strcmp (ego->identifier, str))
515  {
516  send_result_code (client,
519  GNUNET_free (str);
520  return;
521  }
522  }
523  ego = GNUNET_new (struct Ego);
524  ego->pk = private_key;
525  ego->identifier = GNUNET_strdup (str);
527  ego_tail,
528  ego);
530  fn = get_ego_filename (ego);
531  if (GNUNET_OK !=
533  &private_key,
534  sizeof(struct GNUNET_IDENTITY_PrivateKey),
538  GNUNET_free (fn);
539  GNUNET_free (str);
540  notify_listeners (ego);
542 }
543 
544 
549 {
553  const char *old_name;
554 
558  const char *new_name;
559 };
560 
568 static void
569 handle_ego_rename (void *cls, const char *section)
570 {
571  struct RenameContext *rc = cls;
572  char *id;
573 
575  section,
576  "DEFAULT_IDENTIFIER",
577  &id))
578  return;
579  if (0 != strcmp (id, rc->old_name))
580  {
581  GNUNET_free (id);
582  return;
583  }
585  section,
586  "DEFAULT_IDENTIFIER",
587  rc->new_name);
588  GNUNET_free (id);
589 }
590 
591 
599 static int
600 check_rename_message (void *cls, const struct RenameMessage *msg)
601 {
602  uint16_t size;
603  uint16_t old_name_len;
604  uint16_t new_name_len;
605  const char *old_name;
606  const char *new_name;
607 
608  size = ntohs (msg->header.size);
609  if (size <= sizeof(struct RenameMessage))
610  {
611  GNUNET_break (0);
612  return GNUNET_SYSERR;
613  }
614  old_name_len = ntohs (msg->old_name_len);
615  new_name_len = ntohs (msg->new_name_len);
616  old_name = (const char *) &msg[1];
617  new_name = &old_name[old_name_len];
618  if ((old_name_len + new_name_len + sizeof(struct RenameMessage) != size) ||
619  ('\0' != old_name[old_name_len - 1]) ||
620  ('\0' != new_name[new_name_len - 1]))
621  {
622  GNUNET_break (0);
623  return GNUNET_SYSERR;
624  }
625 
626  return GNUNET_OK;
627 }
628 
629 
637 static void
638 handle_rename_message (void *cls, const struct RenameMessage *rm)
639 {
640  uint16_t old_name_len;
641  struct Ego *ego;
642  char *old_name;
643  char *new_name;
644  struct RenameContext rename_ctx;
645  struct GNUNET_SERVICE_Client *client = cls;
646  char *fn_old;
647  char *fn_new;
648  const char *old_name_tmp;
649 
650  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n");
651  old_name_len = ntohs (rm->old_name_len);
652  old_name_tmp = (const char *) &rm[1];
653  old_name = GNUNET_strdup (old_name_tmp);
654  GNUNET_STRINGS_utf8_tolower (old_name_tmp, old_name);
655  new_name = GNUNET_strdup (&old_name_tmp[old_name_len]);
656  GNUNET_STRINGS_utf8_tolower (&old_name_tmp[old_name_len], new_name);
657 
658  /* check if new name is already in use */
659  for (ego = ego_head; NULL != ego; ego = ego->next)
660  {
661  if (0 == strcmp (ego->identifier, new_name))
662  {
665  GNUNET_free (old_name);
666  GNUNET_free (new_name);
667  return;
668  }
669  }
670 
671  /* locate old name and, if found, perform rename */
672  for (ego = ego_head; NULL != ego; ego = ego->next)
673  {
674  if (0 == strcmp (ego->identifier, old_name))
675  {
676  fn_old = get_ego_filename (ego);
677  GNUNET_free (ego->identifier);
678  rename_ctx.old_name = old_name;
679  rename_ctx.new_name = new_name;
682  &rename_ctx);
683  if (GNUNET_OK !=
685  GNUNET_log (
687  _ ("Failed to write subsystem default identifier map to `%s'.\n"),
689  ego->identifier = GNUNET_strdup (new_name);
690  fn_new = get_ego_filename (ego);
691  if (0 != rename (fn_old, fn_new))
693  GNUNET_free (fn_old);
694  GNUNET_free (fn_new);
695  GNUNET_free (old_name);
696  GNUNET_free (new_name);
697  notify_listeners (ego);
700  return;
701  }
702  }
703 
704  /* failed to locate old name */
706  GNUNET_free (old_name);
707  GNUNET_free (new_name);
709 }
710 
711 
719 static void
720 handle_ego_delete (void *cls, const char *section)
721 {
722  const char *identifier = cls;
723  char *id;
724 
726  section,
727  "DEFAULT_IDENTIFIER",
728  &id))
729  return;
730  if (0 != strcmp (id, identifier))
731  {
732  GNUNET_free (id);
733  return;
734  }
736  section,
737  "DEFAULT_IDENTIFIER",
738  NULL);
739  GNUNET_free (id);
740 }
741 
742 
750 static int
751 check_delete_message (void *cls, const struct DeleteMessage *msg)
752 {
753  uint16_t size;
754  uint16_t name_len;
755  const char *name;
756 
757  size = ntohs (msg->header.size);
758  if (size <= sizeof(struct DeleteMessage))
759  {
760  GNUNET_break (0);
761  return GNUNET_SYSERR;
762  }
763  name = (const char *) &msg[1];
764  name_len = ntohs (msg->name_len);
765  if ((name_len + sizeof(struct DeleteMessage) != size) ||
766  (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
767  {
768  GNUNET_break (0);
769  return GNUNET_SYSERR;
770  }
771  return GNUNET_OK;
772 }
773 
774 
782 static void
783 handle_delete_message (void *cls, const struct DeleteMessage *dm)
784 {
785  struct Ego *ego;
786  char *name;
787  char *fn;
788  struct GNUNET_SERVICE_Client *client = cls;
789 
790  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n");
791  name = GNUNET_strdup ((const char *) &dm[1]);
792  GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name);
793 
794  for (ego = ego_head; NULL != ego; ego = ego->next)
795  {
796  if (0 == strcmp (ego->identifier, name))
797  {
801  ego->identifier);
802  if (GNUNET_OK !=
804  GNUNET_log (
806  _ ("Failed to write subsystem default identifier map to `%s'.\n"),
808  fn = get_ego_filename (ego);
809  if (0 != unlink (fn))
811  GNUNET_free (fn);
812  GNUNET_free (ego->identifier);
813  ego->identifier = NULL;
814  notify_listeners (ego);
815  GNUNET_free (ego);
816  GNUNET_free (name);
819  return;
820  }
821  }
822 
824  GNUNET_free (name);
826 }
827 
828 
829 static int
831  void *buf,
832  size_t buf_size)
833 {
834  int fd;
835  struct stat sb;
836 
837  fd = open (filename,
838  O_RDONLY);
839  if (-1 == fd)
840  {
841  memset (buf,
842  0,
843  buf_size);
844  return GNUNET_SYSERR;
845  }
846  if (0 != fstat (fd,
847  &sb))
848  {
850  "stat",
851  filename);
852  GNUNET_assert (0 == close (fd));
853  memset (buf,
854  0,
855  buf_size);
856  return GNUNET_SYSERR;
857  }
858  if (sb.st_size != buf_size)
859  {
861  "File `%s' has wrong size (%llu), expected %llu bytes\n",
862  filename,
863  (unsigned long long) sb.st_size,
864  (unsigned long long) buf_size);
865  GNUNET_assert (0 == close (fd));
866  memset (buf,
867  0,
868  buf_size);
869  return GNUNET_SYSERR;
870  }
871  if (buf_size !=
872  read (fd,
873  buf,
874  buf_size))
875  {
877  "read",
878  filename);
879  GNUNET_assert (0 == close (fd));
880  memset (buf,
881  0,
882  buf_size);
883  return GNUNET_SYSERR;
884  }
885  GNUNET_assert (0 == close (fd));
886  return GNUNET_OK;
887 }
888 
889 
900 static int
901 process_ego_file (void *cls,
902  const char *filename)
903 {
904  struct Ego *ego;
905  const char *fn;
906 
907  fn = strrchr (filename, (int) DIR_SEPARATOR);
908  if (NULL == fn)
909  {
910  GNUNET_break (0);
911  return GNUNET_OK;
912  }
913  ego = GNUNET_new (struct Ego);
914  if (GNUNET_OK !=
916  &ego->pk,
917  sizeof (ego->pk)))
918  {
919  GNUNET_free (ego);
921  _ ("Failed to parse ego information in `%s'\n"),
922  filename);
923  return GNUNET_OK;
924  }
926  "Loaded ego `%s'\n",
927  fn + 1);
928  ego->identifier = GNUNET_strdup (fn + 1);
930  return GNUNET_OK;
931 }
932 
933 
941 static void
942 run (void *cls,
943  const struct GNUNET_CONFIGURATION_Handle *c,
945 {
946  cfg = c;
949  "identity",
950  "EGODIR",
951  &ego_directory))
952  {
953  GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR");
955  return;
956  }
957  if (GNUNET_OK !=
959  "identity",
960  "SUBSYSTEM_CFG",
962  {
964  "identity",
965  "SUBSYSTEM_CFG");
967  return;
968  }
970  "Loading subsystem configuration `%s'\n",
974  (GNUNET_OK !=
976  {
978  _ (
979  "Failed to parse subsystem identity configuration file `%s'\n"),
982  return;
983  }
984  stats = GNUNET_STATISTICS_create ("identity", cfg);
986  {
988  _ ("Failed to create directory `%s' for storing egos\n"),
989  ego_directory);
990  }
993  NULL);
995 }
996 
997 
1002  "identity",
1004  &run,
1007  NULL,
1008  GNUNET_MQ_hd_fixed_size (start_message,
1010  struct GNUNET_MessageHeader,
1011  NULL),
1012  GNUNET_MQ_hd_var_size (lookup_message,
1014  struct LookupMessage,
1015  NULL),
1016  GNUNET_MQ_hd_var_size (lookup_by_suffix_message,
1018  struct LookupMessage,
1019  NULL),
1022  struct CreateRequestMessage,
1023  NULL),
1024  GNUNET_MQ_hd_var_size (rename_message,
1026  struct RenameMessage,
1027  NULL),
1028  GNUNET_MQ_hd_var_size (delete_message,
1030  struct DeleteMessage,
1031  NULL),
1033 
1034 
1035 /* end of gnunet-service-identity.c */
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
const char * GNUNET_ErrorCode_get_hint(enum GNUNET_ErrorCode ec)
Returns a hint for a given error code.
@ GNUNET_EC_IDENTITY_NOT_FOUND
Ego not found.
@ GNUNET_EC_IDENTITY_NAME_CONFLICT
Identifier already in use for another ego.
@ GNUNET_EC_NONE
No error (success).
static struct Experiment * e
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
static char * filename
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
static void handle_create_message(void *cls, const struct CreateRequestMessage *crm)
Handler for CREATE message from client, creates new identity.
static struct Ego * ego_tail
Tail of DLL of all egos.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
static int check_lookup_message(void *cls, const struct LookupMessage *message)
Handler for LOOKUP message from client, sends information about ONE identity to the client immediatel...
static const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to our current configuration.
static void send_result_code(struct GNUNET_SERVICE_Client *client, uint32_t result_code)
Send a result code back to the client.
static int check_create_message(void *cls, const struct CreateRequestMessage *msg)
Checks a GNUNET_MESSAGE_TYPE_IDENTITY_CREATE message.
static struct GNUNET_NotificationContext * nc
Notification context, simplifies client broadcasts.
static void handle_start_message(void *cls, const struct GNUNET_MessageHeader *message)
Handler for START message from client, sends information about all identities to the client immediate...
static struct GNUNET_MQ_Envelope * create_update_message(struct Ego *ego)
Create an update message with information about the current state of an ego.
static int check_delete_message(void *cls, const struct DeleteMessage *msg)
Checks a GNUNET_MESSAGE_TYPE_IDENTITY_DELETE message.
static void handle_lookup_by_suffix_message(void *cls, const struct LookupMessage *message)
Handler for LOOKUP_BY_SUFFIX message from client, sends information about ONE identity to the client ...
static void shutdown_task(void *cls)
Task run during shutdown.
static char * subsystem_cfg_file
Configuration file name where subsystem information is kept.
static int process_ego_file(void *cls, const char *filename)
Process the given file from the "EGODIR".
static void handle_ego_rename(void *cls, const char *section)
An ego was renamed; rename it in all subsystems where it is currently set as the default.
static char * get_ego_filename(struct Ego *ego)
Get the name of the file we use to store a given ego.
static void handle_rename_message(void *cls, const struct RenameMessage *rm)
Handler for RENAME message from client, creates new identity.
static int read_from_file(const char *filename, void *buf, size_t buf_size)
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
Handle network size estimate clients.
static void handle_lookup_message(void *cls, const struct LookupMessage *message)
Handler for LOOKUP message from client, sends information about ONE identity to the client immediatel...
static char * ego_directory
Directory where we store the identities.
static void notify_listeners(struct Ego *ego)
Send an updated message for the given ego to all listeners.
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
Add a client to our list of active clients.
static void handle_delete_message(void *cls, const struct DeleteMessage *dm)
Handler for DELETE message from client, creates new identity.
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
Called whenever a client is disconnected.
GNUNET_SERVICE_MAIN("identity", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_fixed_size(start_message, GNUNET_MESSAGE_TYPE_IDENTITY_START, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_var_size(lookup_message, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP, struct LookupMessage, NULL), GNUNET_MQ_hd_var_size(lookup_by_suffix_message, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX, struct LookupMessage, NULL), GNUNET_MQ_hd_var_size(create_message, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, struct CreateRequestMessage, NULL), GNUNET_MQ_hd_var_size(rename_message, GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, struct RenameMessage, NULL), GNUNET_MQ_hd_var_size(delete_message, GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, struct DeleteMessage, NULL), GNUNET_MQ_handler_end())
Define "main" method using service macro.
static int check_rename_message(void *cls, const struct RenameMessage *msg)
Checks a GNUNET_MESSAGE_TYPE_IDENTITY_RENAME message.
static void handle_ego_delete(void *cls, const char *section)
An ego was removed, remove it from all subsystems where it is currently set as the default.
static struct Ego * ego_head
Head of DLL of all egos.
static struct GNUNET_CONFIGURATION_Handle * subsystem_cfg
Handle to subsystem configuration which for each subsystem contains the name of the default ego.
static int check_lookup_by_suffix_message(void *cls, const struct LookupMessage *message)
Handler for LOOKUP message from client, sends information about ONE identity to the client immediatel...
static char buf[2048]
Identity service; implements identity management for GNUnet.
Constants for network protocols.
API to create, modify and access statistics.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_SectionIterator iter, void *iter_cls)
Iterate over all sections in the configuration.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:481
enum GNUNET_GenericReturnValue GNUNET_DISK_fn_write(const char *fn, const void *buf, size_t buf_size, enum GNUNET_DISK_AccessPermissions mode)
Write a buffer to a file atomically.
Definition: disk.c:724
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:495
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:813
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
ssize_t GNUNET_IDENTITY_write_private_key_to_buffer(const struct GNUNET_IDENTITY_PrivateKey *key, void *buffer, size_t len)
Writes a GNUNET_IDENTITY_PrivateKey to a compact buffer.
Definition: identity_api.c:933
ssize_t GNUNET_IDENTITY_private_key_get_length(const struct GNUNET_IDENTITY_PrivateKey *key)
Get the compacted length of a GNUNET_IDENTITY_PrivateKey.
Definition: identity_api.c:809
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_read_private_key_from_buffer(const void *buffer, size_t len, struct GNUNET_IDENTITY_PrivateKey *key, size_t *kb_read)
Reads a GNUNET_IDENTITY_PrivateKey from a compact buffer.
Definition: identity_api.c:908
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc)
Destroy the context, force disconnect for all subscribers.
Definition: nc.c:138
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:62
void GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc, const struct GNUNET_MessageHeader *msg, int can_drop)
Send a message to all subscribers of this context.
Definition: nc.c:190
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:77
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
struct GNUNET_NotificationContext * GNUNET_notification_context_create(unsigned int queue_length)
Create a new notification context.
Definition: nc.c:122
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, struct GNUNET_MQ_Handle *mq)
Add a subscriber to the notification context.
Definition: nc.c:161
#define GNUNET_MESSAGE_TYPE_IDENTITY_CREATE
Create new identity (client->service).
#define GNUNET_MESSAGE_TYPE_IDENTITY_START
First message send from identity client to service (to subscribe to updates).
#define GNUNET_MESSAGE_TYPE_IDENTITY_DELETE
Delete identity (client->service).
#define GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP
First message send from identity client to service to lookup a single ego.
#define GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE
Generic response from identity service with success and/or error message.
#define GNUNET_MESSAGE_TYPE_IDENTITY_RENAME
Rename existing identity (client->service).
#define GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX
First message send from identity client to service to lookup a single ego matching the given suffix (...
#define GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE
Update about identity status from service to clients.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1334
void GNUNET_SERVICE_client_mark_monitor(struct GNUNET_SERVICE_Client *c)
Set the 'monitor' flag on this client.
Definition: service.c:2413
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2330
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2443
void GNUNET_SERVICE_client_disable_continue_warning(struct GNUNET_SERVICE_Client *c)
Disable the warning the server issues if a message is not acknowledged in a timely fashion.
Definition: service.c:2273
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2249
@ GNUNET_SERVICE_OPTION_NONE
Use defaults.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:449
Common type definitions for the identity service and API.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define DIR_SEPARATOR
Definition: platform.h:164
#define DIR_SEPARATOR_STR
Definition: platform.h:165
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
const char * name
Client requests creation of an identity.
Definition: identity.h:151
uint16_t key_len
Key length.
Definition: identity.h:165
Client requests deletion of an identity.
Definition: identity.h:204
Information we keep about each ego.
struct Ego * prev
We keep egos in a DLL.
struct GNUNET_IDENTITY_PrivateKey pk
Private key of the ego.
char * identifier
String identifier for the ego.
struct Ego * next
We keep egos in a DLL.
A private key for an identity as per LSD0001.
Handle to a message queue.
Definition: mq.c:87
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
The notification context is the key datastructure for a convenience API used for transmission of noti...
Definition: nc.c:77
Handle to a client that is connected to a service.
Definition: service.c:252
Handle to a service.
Definition: service.c:118
Handle for the service.
Message from client to GNS service to lookup records.
Definition: gns.h:37
Closure for 'handle_ego_rename'.
const char * old_name
Old name.
const char * new_name
New name.
Client requests renaming of an identity.
Definition: identity.h:178
uint16_t old_name_len
Number of characters in the old name including 0-termination, in NBO.
Definition: identity.h:187
Answer from service to client about last operation; GET_DEFAULT maybe answered with this message on f...
Definition: identity.h:81
uint32_t result_code
Status code for the last operation, in NBO.
Definition: identity.h:91
Service informs client about status of a pseudonym.
Definition: identity.h:114
uint16_t end_of_list
Usually GNUNET_NO, GNUNET_YES to signal end of list.
Definition: identity.h:129
uint16_t key_len
Key length.
Definition: identity.h:134
uint16_t name_len
Number of bytes in ego name string including 0-termination, in NBO; 0 if the ego was deleted.
Definition: identity.h:124
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE.
Definition: identity.h:118