GNUnet  0.11.x
identity_api.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2013, 2016 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 
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_constants.h"
29 #include "gnunet_protocols.h"
31 #include "identity.h"
32 
33 #define LOG(kind, ...) GNUNET_log_from (kind, "identity-api", __VA_ARGS__)
34 
35 
40 {
45 
50 
55 
60  const struct GNUNET_MessageHeader *msg;
61 
67 
73 
78 
84 
88  void *cls;
89 };
90 
91 
96 {
101 
106 
112 
117 
121  void *cb_cls;
122 
127 
132 
137 
141  struct GNUNET_TIME_Relative reconnect_delay;
142 
147 };
148 
149 
155 struct GNUNET_IDENTITY_Ego *
157 {
158  static struct GNUNET_IDENTITY_Ego anon;
159  static int setup;
160  struct GNUNET_CRYPTO_EcdsaPublicKey pub;
161 
162  if (setup)
163  return &anon;
166  &pub);
167  GNUNET_CRYPTO_hash (&anon.pk,
168  sizeof(anon.pk),
169  &anon.id);
170  setup = 1;
171  return &anon;
172 }
173 
174 
180 static void
181 reconnect (void *cls);
182 
183 
192 static int
193 free_ego (void *cls,
194  const struct GNUNET_HashCode *key,
195  void *value)
196 {
197  struct GNUNET_IDENTITY_Handle *h = cls;
198  struct GNUNET_IDENTITY_Ego *ego = value;
199 
200  if (NULL != h->cb)
201  h->cb (h->cb_cls, ego,
202  &ego->ctx,
203  NULL);
204  GNUNET_free (ego->name);
207  key,
208  value));
209  GNUNET_free (ego);
210  return GNUNET_OK;
211 }
212 
213 
219 static void
221 {
223 
224  GNUNET_assert (NULL == h->reconnect_task);
225 
226  if (NULL != h->mq)
227  {
228  GNUNET_MQ_destroy (h->mq);
229  h->mq = NULL;
230  }
231  while (NULL != (op = h->op_head))
232  {
234  h->op_tail,
235  op);
236  if (NULL != op->cont)
237  op->cont (op->cls,
238  "Error in communication with the identity service");
239  else if (NULL != op->cb)
240  op->cb (op->cls, NULL, NULL, NULL);
241  else if (NULL != op->create_cont)
242  op->create_cont (op->cls,
243  NULL,
244  "Failed to communicate with the identity service");
245  GNUNET_free (op);
246  }
248  &free_ego,
249  h);
251  "Scheduling task to reconnect to identity service in %s.\n",
253  GNUNET_YES));
254  h->reconnect_task =
256  &reconnect,
257  h);
259 }
260 
261 
270 static void
272  enum GNUNET_MQ_Error error)
273 {
274  struct GNUNET_IDENTITY_Handle *h = cls;
275 
276  reschedule_connect (h);
277 }
278 
279 
288 static int
290  const struct ResultCodeMessage *rcm)
291 {
292  if (sizeof(*rcm) != htons (rcm->header.size))
294  return GNUNET_OK;
295 }
296 
297 
304 static void
306  const struct ResultCodeMessage *rcm)
307 {
308  struct GNUNET_IDENTITY_Handle *h = cls;
310  uint16_t size = ntohs (rcm->header.size) - sizeof(*rcm);
311  const char *str = (0 == size) ? NULL : (const char *) &rcm[1];
312 
313  op = h->op_head;
314  if (NULL == op)
315  {
316  GNUNET_break (0);
317  reschedule_connect (h);
318  return;
319  }
321  if (NULL != op->cont)
322  op->cont (op->cls, str);
323  else if (NULL != op->cb)
324  op->cb (op->cls, NULL, NULL, NULL);
325  else if (NULL != op->create_cont)
326  op->create_cont (op->cls, (NULL == str) ? &op->pk : NULL, str);
327  GNUNET_free (op);
328 }
329 
330 
338 static int
340  const struct UpdateMessage *um)
341 {
342  uint16_t size = ntohs (um->header.size);
343  uint16_t name_len = ntohs (um->name_len);
344  const char *str = (const char *) &um[1];
345 
346  if ((size != name_len + sizeof(struct UpdateMessage)) ||
347  ((0 != name_len) && ('\0' != str[name_len - 1])))
348  {
349  GNUNET_break (0);
350  return GNUNET_SYSERR;
351  }
352  return GNUNET_OK;
353 }
354 
355 
362 static void
364  const struct UpdateMessage *um)
365 {
366  struct GNUNET_IDENTITY_Handle *h = cls;
367  uint16_t name_len = ntohs (um->name_len);
368  const char *str = (0 == name_len) ? NULL : (const char *) &um[1];
369  struct GNUNET_HashCode id;
370  struct GNUNET_IDENTITY_Ego *ego;
371 
372  if (GNUNET_YES == ntohs (um->end_of_list))
373  {
374  /* end of initial list of data */
375  if (NULL != h->cb)
376  h->cb (h->cb_cls, NULL, NULL, NULL);
377  return;
378  }
380  sizeof (um->private_key),
381  &id);
383  &id);
384  if (NULL == ego)
385  {
386  /* ego was created */
387  if (NULL == str)
388  {
389  /* deletion of unknown ego? not allowed */
390  GNUNET_break (0);
391  reschedule_connect (h);
392  return;
393  }
394  ego = GNUNET_new (struct GNUNET_IDENTITY_Ego);
395  ego->pub_initialized = GNUNET_NO;
396  ego->pk = um->private_key;
397  ego->name = GNUNET_strdup (str);
398  ego->id = id;
401  h->egos,
402  &ego->id,
403  ego,
405  }
406  if (NULL == str)
407  {
408  /* ego was deleted */
411  &ego->id,
412  ego));
413  }
414  else
415  {
416  /* ego changed name */
417  GNUNET_free (ego->name);
418  ego->name = GNUNET_strdup (str);
419  }
420  /* inform application about change */
421  if (NULL != h->cb)
422  h->cb (h->cb_cls,
423  ego,
424  &ego->ctx,
425  str);
426  /* complete deletion */
427  if (NULL == str)
428  {
429  GNUNET_free (ego->name);
430  GNUNET_free (ego);
431  }
432 }
433 
434 
443 static int
445  const struct SetDefaultMessage *sdm)
446 {
447  uint16_t size = ntohs (sdm->header.size) - sizeof(*sdm);
448  uint16_t name_len = ntohs (sdm->name_len);
449  const char *str = (const char *) &sdm[1];
450 
451  if ((size != name_len) || ((0 != name_len) && ('\0' != str[name_len - 1])))
452  {
453  GNUNET_break (0);
454  return GNUNET_SYSERR;
455  }
456  GNUNET_break (0 == ntohs (sdm->reserved));
457  return GNUNET_OK;
458 }
459 
460 
468 static void
470  const struct SetDefaultMessage *sdm)
471 {
472  struct GNUNET_IDENTITY_Handle *h = cls;
474  struct GNUNET_HashCode id;
475  struct GNUNET_IDENTITY_Ego *ego;
476 
478  sizeof(sdm->private_key),
479  &id);
481  &id);
482  if (NULL == ego)
483  {
484  GNUNET_break (0);
485  reschedule_connect (h);
486  return;
487  }
488  op = h->op_head;
489  if (NULL == op)
490  {
491  GNUNET_break (0);
492  reschedule_connect (h);
493  return;
494  }
496  "Received SET_DEFAULT message from identity service\n");
498  h->op_tail,
499  op);
500  if (NULL != op->cb)
501  op->cb (op->cls,
502  ego,
503  &ego->ctx,
504  ego->name);
505  GNUNET_free (op);
506 }
507 
508 
514 static void
515 reconnect (void *cls)
516 {
517  struct GNUNET_IDENTITY_Handle *h = cls;
518  struct GNUNET_MQ_MessageHandler handlers[] = {
519  GNUNET_MQ_hd_var_size (identity_result_code,
521  struct ResultCodeMessage,
522  h),
523  GNUNET_MQ_hd_var_size (identity_update,
525  struct UpdateMessage,
526  h),
527  GNUNET_MQ_hd_var_size (identity_set_default,
529  struct SetDefaultMessage,
530  h),
532  };
533  struct GNUNET_MQ_Envelope *env;
534  struct GNUNET_MessageHeader *msg;
535 
536  h->reconnect_task = NULL;
538  "Connecting to identity service.\n");
539  GNUNET_assert (NULL == h->mq);
540  h->mq = GNUNET_CLIENT_connect (h->cfg,
541  "identity",
542  handlers,
544  h);
545  if (NULL == h->mq)
546  return;
547  if (NULL != h->cb)
548  {
549  env = GNUNET_MQ_msg (msg,
551  GNUNET_MQ_send (h->mq,
552  env);
553  }
554 }
555 
556 
565 struct GNUNET_IDENTITY_Handle *
568  void *cb_cls)
569 {
570  struct GNUNET_IDENTITY_Handle *h;
571 
572  h = GNUNET_new (struct GNUNET_IDENTITY_Handle);
573  h->cfg = cfg;
574  h->cb = cb;
575  h->cb_cls = cb_cls;
577  GNUNET_YES);
578  reconnect (h);
579  if (NULL == h->mq)
580  {
581  GNUNET_free (h);
582  return NULL;
583  }
584  return h;
585 }
586 
587 
594 const struct GNUNET_CRYPTO_EcdsaPrivateKey *
596 {
597  return &ego->pk;
598 }
599 
600 
607 void
610 {
611  if (GNUNET_NO == ego->pub_initialized)
612  {
614  &ego->pub);
616  }
617  *pk = ego->pub;
618 }
619 
620 
633  const char *service_name,
635  void *cb_cls)
636 {
638  struct GNUNET_MQ_Envelope *env;
639  struct GetDefaultMessage *gdm;
640  size_t slen;
641 
642  if (NULL == h->mq)
643  return NULL;
644  GNUNET_assert (NULL != h->cb);
645  slen = strlen (service_name) + 1;
646  if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct GetDefaultMessage))
647  {
648  GNUNET_break (0);
649  return NULL;
650  }
652  op->h = h;
653  op->cb = cb;
654  op->cls = cb_cls;
656  env =
658  gdm->name_len = htons (slen);
659  gdm->reserved = htons (0);
660  GNUNET_memcpy (&gdm[1], service_name, slen);
661  GNUNET_MQ_send (h->mq, env);
662  return op;
663 }
664 
665 
678  const char *service_name,
679  struct GNUNET_IDENTITY_Ego *ego,
681  void *cont_cls)
682 {
684  struct GNUNET_MQ_Envelope *env;
685  struct SetDefaultMessage *sdm;
686  size_t slen;
687 
688  if (NULL == h->mq)
689  return NULL;
690  GNUNET_assert (NULL != h->cb);
691  slen = strlen (service_name) + 1;
692  if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct SetDefaultMessage))
693  {
694  GNUNET_break (0);
695  return NULL;
696  }
698  op->h = h;
699  op->cont = cont;
700  op->cls = cont_cls;
702  env =
704  sdm->name_len = htons (slen);
705  sdm->reserved = htons (0);
706  sdm->private_key = ego->pk;
707  GNUNET_memcpy (&sdm[1], service_name, slen);
708  GNUNET_MQ_send (h->mq, env);
709  return op;
710 }
711 
712 
725  const char *name,
726  const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey,
728  void *cont_cls)
729 {
731  struct GNUNET_MQ_Envelope *env;
732  struct CreateRequestMessage *crm;
733  size_t slen;
734 
735  if (NULL == h->mq)
736  return NULL;
737  slen = strlen (name) + 1;
738  if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct CreateRequestMessage))
739  {
740  GNUNET_break (0);
741  return NULL;
742  }
744  op->h = h;
745  op->create_cont = cont;
746  op->cls = cont_cls;
749  crm->name_len = htons (slen);
750  crm->reserved = htons (0);
751  if (NULL == privkey)
753  else
754  crm->private_key = *privkey;
755  op->pk = crm->private_key;
756  GNUNET_memcpy (&crm[1], name, slen);
757  GNUNET_MQ_send (h->mq, env);
758  return op;
759 }
760 
761 
774  const char *old_name,
775  const char *new_name,
777  void *cb_cls)
778 {
780  struct GNUNET_MQ_Envelope *env;
781  struct RenameMessage *grm;
782  size_t slen_old;
783  size_t slen_new;
784  char *dst;
785 
786  if (NULL == h->mq)
787  return NULL;
788  slen_old = strlen (old_name) + 1;
789  slen_new = strlen (new_name) + 1;
790  if ((slen_old >= GNUNET_MAX_MESSAGE_SIZE) ||
791  (slen_new >= GNUNET_MAX_MESSAGE_SIZE) ||
792  (slen_old + slen_new >=
793  GNUNET_MAX_MESSAGE_SIZE - sizeof(struct RenameMessage)))
794  {
795  GNUNET_break (0);
796  return NULL;
797  }
799  op->h = h;
800  op->cont = cb;
801  op->cls = cb_cls;
803  env = GNUNET_MQ_msg_extra (grm,
804  slen_old + slen_new,
806  grm->old_name_len = htons (slen_old);
807  grm->new_name_len = htons (slen_new);
808  dst = (char *) &grm[1];
809  GNUNET_memcpy (dst, old_name, slen_old);
810  GNUNET_memcpy (&dst[slen_old], new_name, slen_new);
811  GNUNET_MQ_send (h->mq, env);
812  return op;
813 }
814 
815 
827  const char *name,
829  void *cb_cls)
830 {
832  struct GNUNET_MQ_Envelope *env;
833  struct DeleteMessage *gdm;
834  size_t slen;
835 
836  if (NULL == h->mq)
837  return NULL;
838  slen = strlen (name) + 1;
839  if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct DeleteMessage))
840  {
841  GNUNET_break (0);
842  return NULL;
843  }
845  op->h = h;
846  op->cont = cb;
847  op->cls = cb_cls;
850  gdm->name_len = htons (slen);
851  gdm->reserved = htons (0);
852  GNUNET_memcpy (&gdm[1], name, slen);
853  GNUNET_MQ_send (h->mq, env);
854  return op;
855 }
856 
857 
866 void
868 {
869  op->cont = NULL;
870  op->cb = NULL;
871  op->create_cont = NULL;
872  memset (&op->pk,
873  0,
874  sizeof (op->pk));
875 }
876 
877 
883 void
885 {
887 
888  GNUNET_assert (NULL != h);
889  if (h->reconnect_task != NULL)
890  {
892  h->reconnect_task = NULL;
893  }
894  if (NULL != h->egos)
895  {
897  &free_ego,
898  h);
900  h->egos = NULL;
901  }
902  while (NULL != (op = h->op_head))
903  {
904  GNUNET_break (NULL == op->cont);
906  memset (&op->pk,
907  0,
908  sizeof (op->pk));
909  GNUNET_free (op);
910  }
911  if (NULL != h->mq)
912  {
913  GNUNET_MQ_destroy (h->mq);
914  h->mq = NULL;
915  }
916  GNUNET_free (h);
917 }
918 
919 
920 /* end of identity_api.c */
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
Definition: identity_api.c:566
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_CONTAINER_MultiHashMap * egos
Hash map from the hash of the private key to the respective GNUNET_IDENTITY_Ego handle.
Definition: identity_api.c:111
static void handle_identity_update(void *cls, const struct UpdateMessage *um)
Handle identity update message.
Definition: identity_api.c:363
uint16_t reserved
Always zero.
Definition: identity.h:179
struct GNUNET_CRYPTO_EcdsaPrivateKey private_key
The private key.
Definition: identity.h:154
#define GNUNET_MESSAGE_TYPE_IDENTITY_START
First message send from identity client to service (to subscribe to updates).
const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_CRYPTO_ecdsa_key_get_anonymous(void)
Get the shared private key we use for anonymous users.
Definition: crypto_ecc.c:569
struct GNUNET_CRYPTO_EcdsaPrivateKey pk
Private key associated with this ego.
Definition: identity.h:255
void GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op)
Cancel an identity operation.
Definition: identity_api.c:867
#define GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT
Client sets default identity; or service informs about default identity.
const struct GNUNET_MessageHeader * msg
Message to send to the identity service.
Definition: identity_api.c:60
Used from service to client as a result to the GET_DEFAULT message, used from client to service to SE...
Definition: identity.h:134
struct GNUNET_TIME_Relative reconnect_delay
Time for next connect retry.
Definition: identity_api.c:141
#define GNUNET_MESSAGE_TYPE_IDENTITY_DELETE
Delete identity (client->service).
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
void(* GNUNET_IDENTITY_Callback)(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
Method called to inform about the egos of this peer.
Common type definitions for the identity service and API.
static void handle_identity_result_code(void *cls, const struct ResultCodeMessage *rcm)
We received a result code from the service.
Definition: identity_api.c:305
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1063
void(* GNUNET_IDENTITY_CreateContinuation)(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, const char *emsg)
Function called once the requested operation has been completed.
uint16_t reserved
Always zero.
Definition: identity.h:123
GNUNET_MQ_Error
Error codes for the queue.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE.
Definition: identity.h:82
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_delete(struct GNUNET_IDENTITY_Handle *h, const char *name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Delete an existing identity.
Definition: identity_api.c:826
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
Definition: identity_api.c:271
uint16_t name_len
Number of bytes in service name string including 0-termination, in NBO.
Definition: identity.h:144
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE.
Definition: identity.h:47
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint16_t name_len
Number of bytes in service name string including 0-termination, in NBO.
Definition: identity.h:118
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_set(struct GNUNET_IDENTITY_Handle *h, const char *service_name, struct GNUNET_IDENTITY_Ego *ego, GNUNET_IDENTITY_Continuation cont, void *cont_cls)
Set the preferred/default identity for a service.
Definition: identity_api.c:677
const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:595
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *h, const char *name, const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey, GNUNET_IDENTITY_CreateContinuation cont, void *cont_cls)
Create a new identity with the given name.
Definition: identity_api.c:724
uint16_t old_name_len
Number of characters in the old name including 0-termination, in NBO.
Definition: identity.h:204
Client requests renaming of an identity.
Definition: identity.h:194
struct GNUNET_CRYPTO_EcdsaPrivateKey private_key
The private key.
Definition: identity.h:98
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t reserved
Always zero.
Definition: identity.h:235
struct GNUNET_IDENTITY_Operation * op_tail
Tail of active operations.
Definition: identity_api.c:131
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_get(struct GNUNET_IDENTITY_Handle *h, const char *service_name, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Obtain the identity that is currently preferred/default for a service.
Definition: identity_api.c:632
#define GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE
Update about identity status from service to clients.
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Private ECC key encoded for transmission.
static int check_identity_result_code(void *cls, const struct ResultCodeMessage *rcm)
We received a result code from the service.
Definition: identity_api.c:289
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
uint16_t name_len
Number of bytes in identity name string including 0-termination, in NBO.
Definition: identity.h:174
Internal representation of the hash map.
struct GNUNET_CRYPTO_EcdsaPrivateKey private_key
The private key.
Definition: identity.h:184
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Handle for an operation with the identity service.
Definition: identity_api.c:39
char * name
Current name associated with this ego.
Definition: identity.h:266
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
static void reconnect(void *cls)
Try again to connect to the identity service.
Definition: identity_api.c:515
uint16_t reserved
Always zero.
Definition: identity.h:149
#define LOG(kind,...)
Definition: identity_api.c:33
#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:52
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1269
Handle for an ego.
Definition: identity.h:245
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
static char * value
Value of the record to add/remove.
GNUNET_IDENTITY_CreateContinuation create_cont
Continuation to invoke with the result of the transmission; cb and cb will be NULL in this case...
Definition: identity_api.c:72
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
Handle for the service.
Definition: identity_api.c:95
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task doing exponential back-off trying to reconnect.
Definition: identity_api.c:136
Client requests creation of an identity.
Definition: identity.h:164
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:702
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
static int check_identity_update(void *cls, const struct UpdateMessage *um)
Check validity of identity update message.
Definition: identity_api.c:339
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: identity_api.c:100
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:884
GNUNET_IDENTITY_Continuation cont
Continuation to invoke with the result of the transmission; cb and create_cont will be NULL in this c...
Definition: identity_api.c:66
struct GNUNET_IDENTITY_Operation * op_head
Head of active operations.
Definition: identity_api.c:126
static void reschedule_connect(struct GNUNET_IDENTITY_Handle *h)
Reschedule a connect attempt to the service.
Definition: identity_api.c:220
A 512-bit hashcode.
Message handler for a specific message type.
struct GNUNET_HashCode id
Hash of the private key of this ego.
Definition: identity.h:250
Client requests deletion of an identity.
Definition: identity.h:220
There must only be one value per key; storing a value should fail if a value under the same key alrea...
void * ctx
Client context associated with this ego.
Definition: identity.h:271
#define GNUNET_MESSAGE_TYPE_IDENTITY_CREATE
Create new identity (client->service).
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Definition: peer.c:67
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:176
struct GNUNET_IDENTITY_Operation * next
We keep operations in a DLL.
Definition: identity_api.c:49
struct GNUNET_CRYPTO_EcdsaPrivateKey pk
Private key to return to create_cont, or NULL.
Definition: identity_api.c:77
struct GNUNET_IDENTITY_Handle * h
Main identity handle.
Definition: identity_api.c:44
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT.
Definition: identity.h:139
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
struct GNUNET_IDENTITY_Ego * GNUNET_IDENTITY_ego_get_anonymous()
Obtain the ego representing &#39;anonymous&#39; users.
Definition: identity_api.c:156
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:88
Handle to a message queue.
Definition: mq.c:85
uint16_t new_name_len
Number of characters in the new name including 0-termination, in NBO.
Definition: identity.h:209
static void handle_identity_set_default(void *cls, const struct SetDefaultMessage *sdm)
Type of a function to call when we receive a message from the service.
Definition: identity_api.c:469
static int free_ego(void *cls, const struct GNUNET_HashCode *key, void *value)
Free ego from hash map.
Definition: identity_api.c:193
configuration data
Definition: configuration.c:84
const char * name
struct GNUNET_IDENTITY_Operation * prev
We keep operations in a DLL.
Definition: identity_api.c:54
void GNUNET_CRYPTO_ecdsa_key_create(struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:524
uint16_t end_of_list
Usually GNUNET_NO, GNUNET_YES to signal end of list.
Definition: identity.h:93
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
void * cls
Closure for cont or cb.
Definition: identity_api.c:88
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
#define GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT
Client requests to know default identity for a subsystem.
bool pub_initialized
Set to true once pub was initialized.
Definition: identity.h:276
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_MESSAGE_TYPE_IDENTITY_RENAME
Rename existing identity (client->service).
uint16_t name_len
Number of characters in the name including 0-termination, in NBO.
Definition: identity.h:230
Header for all communications.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_rename(struct GNUNET_IDENTITY_Handle *h, const char *old_name, const char *new_name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Renames an existing identity.
Definition: identity_api.c:773
#define GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE
Generic response from identity service with success and/or error message.
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:355
void * cb_cls
Closure for cb.
Definition: identity_api.c:121
Client requests knowledge about default identity for a subsystem from identity service.
Definition: identity.h:108
struct GNUNET_MQ_Handle * mq
Connection to service.
Definition: identity_api.c:105
static int check_identity_set_default(void *cls, const struct SetDefaultMessage *sdm)
Function called when we receive a set default message from the service.
Definition: identity_api.c:444
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void(* GNUNET_IDENTITY_Continuation)(void *cls, const char *emsg)
Function called once the requested operation has been completed.
GNUNET_IDENTITY_Callback cb
Function to call when we receive updates.
Definition: identity_api.c:116
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_CRYPTO_EcdsaPublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:608
GNUNET_IDENTITY_Callback cb
Continuation to invoke with the result of the transmission for &#39;get&#39; operations (cont and create_cont...
Definition: identity_api.c:83
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
struct GNUNET_CRYPTO_EcdsaPublicKey pub
Public key associated with this ego.
Definition: identity.h:261
Answer from service to client about last operation; GET_DEFAULT maybe answered with this message on f...
Definition: identity.h:42
Service informs client about status of a pseudonym.
Definition: identity.h:77
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
int in_receive
Are we polling for incoming messages right now?
Definition: identity_api.c:146
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972