2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public Liceidentity 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 Liceidentity for more details.
15 You should have received a copy of the GNU General Public Liceidentity
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file identity/identity_api.c
23 * @brief api to interact with the identity service
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_constants.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_identity_service.h"
33 #define LOG(kind,...) GNUNET_log_from (kind, "identity-api",__VA_ARGS__)
38 struct GNUNET_IDENTITY_Ego
41 * Private key associated with this ego.
43 struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
46 * Current name associated with this ego.
51 * Client context associated with this ego.
56 * Hash of the public key of this ego.
58 struct GNUNET_HashCode id;
63 * Handle for an operation with the identity service.
65 struct GNUNET_IDENTITY_Operation
69 * Main identity handle.
71 struct GNUNET_IDENTITY_Handle *h;
74 * We keep operations in a DLL.
76 struct GNUNET_IDENTITY_Operation *next;
79 * We keep operations in a DLL.
81 struct GNUNET_IDENTITY_Operation *prev;
84 * Message to send to the identity service.
85 * Allocated at the end of this struct.
87 const struct GNUNET_MessageHeader *msg;
90 * Continuation to invoke with the result of the transmission; @e cb
91 * will be NULL in this case.
93 GNUNET_IDENTITY_Continuation cont;
96 * Continuation to invoke with the result of the transmission for
97 * 'get' operations (@e cont will be NULL in this case).
99 GNUNET_IDENTITY_Callback cb;
102 * Closure for @e cont or @e cb.
110 * Handle for the service.
112 struct GNUNET_IDENTITY_Handle
115 * Configuration to use.
117 const struct GNUNET_CONFIGURATION_Handle *cfg;
120 * Socket (if available).
122 struct GNUNET_CLIENT_Connection *client;
125 * Hash map from the hash of the public key to the
126 * respective 'GNUNET_IDENTITY_Ego' handle.
128 struct GNUNET_CONTAINER_MultiHashMap *egos;
131 * Function to call when we receive updates.
133 GNUNET_IDENTITY_Callback cb;
141 * Head of active operations.
143 struct GNUNET_IDENTITY_Operation *op_head;
146 * Tail of active operations.
148 struct GNUNET_IDENTITY_Operation *op_tail;
151 * Currently pending transmission request, or NULL for none.
153 struct GNUNET_CLIENT_TransmitHandle *th;
156 * Task doing exponential back-off trying to reconnect.
158 struct GNUNET_SCHEDULER_Task * reconnect_task;
161 * Time for next connect retry.
163 struct GNUNET_TIME_Relative reconnect_delay;
166 * Are we polling for incoming messages right now?
174 * Obtain the ego representing 'anonymous' users.
176 * @return handle for the anonymous user, must not be freed
178 const struct GNUNET_IDENTITY_Ego *
179 GNUNET_IDENTITY_ego_get_anonymous ()
181 static struct GNUNET_IDENTITY_Ego anon;
182 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
186 anon.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) GNUNET_CRYPTO_ecdsa_key_get_anonymous ();
187 GNUNET_CRYPTO_ecdsa_key_get_public (anon.pk,
189 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &anon.id);
195 * Try again to connect to the identity service.
197 * @param cls handle to the identity service.
200 reconnect (void *cls);
204 * Reschedule a connect attempt to the service.
206 * @param h transport service to reconnect
209 reschedule_connect (struct GNUNET_IDENTITY_Handle *h)
211 GNUNET_assert (h->reconnect_task == NULL);
215 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
218 if (NULL != h->client)
220 GNUNET_CLIENT_disconnect (h->client);
223 h->in_receive = GNUNET_NO;
224 LOG (GNUNET_ERROR_TYPE_DEBUG,
225 "Scheduling task to reconnect to identity service in %s.\n",
226 GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES));
228 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
229 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
234 * Type of a function to call when we receive a message
238 * @param msg message received, NULL on timeout or fatal error
241 message_handler (void *cls,
242 const struct GNUNET_MessageHeader *msg)
244 struct GNUNET_IDENTITY_Handle *h = cls;
245 struct GNUNET_IDENTITY_Operation *op;
246 struct GNUNET_IDENTITY_Ego *ego;
247 const struct GNUNET_IDENTITY_ResultCodeMessage *rcm;
248 const struct GNUNET_IDENTITY_UpdateMessage *um;
249 const struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
250 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
251 struct GNUNET_HashCode id;
258 reschedule_connect (h);
261 LOG (GNUNET_ERROR_TYPE_DEBUG,
262 "Received message of type %d from identity service\n",
264 size = ntohs (msg->size);
265 switch (ntohs (msg->type))
267 case GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE:
268 if (size < sizeof (struct GNUNET_IDENTITY_ResultCodeMessage))
271 reschedule_connect (h);
274 rcm = (const struct GNUNET_IDENTITY_ResultCodeMessage *) msg;
275 str = (const char *) &rcm[1];
276 if ( (size > sizeof (struct GNUNET_IDENTITY_ResultCodeMessage)) &&
277 ('\0' != str[size - sizeof (struct GNUNET_IDENTITY_ResultCodeMessage) - 1]) )
280 reschedule_connect (h);
283 if (size == sizeof (struct GNUNET_IDENTITY_ResultCodeMessage))
287 GNUNET_CONTAINER_DLL_remove (h->op_head,
290 GNUNET_CLIENT_receive (h->client, &message_handler, h,
291 GNUNET_TIME_UNIT_FOREVER_REL);
292 if (NULL != op->cont)
295 else if (NULL != op->cb)
296 op->cb (op->cls, NULL, NULL, NULL);
299 case GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE:
300 if (size < sizeof (struct GNUNET_IDENTITY_UpdateMessage))
303 reschedule_connect (h);
306 um = (const struct GNUNET_IDENTITY_UpdateMessage *) msg;
307 name_len = ntohs (um->name_len);
309 str = (const char *) &um[1];
310 if ( (size != name_len + sizeof (struct GNUNET_IDENTITY_UpdateMessage)) ||
312 ('\0' != str[name_len - 1])) )
315 reschedule_connect (h);
318 if (GNUNET_YES == ntohs (um->end_of_list))
320 /* end of initial list of data */
321 GNUNET_CLIENT_receive (h->client, &message_handler, h,
322 GNUNET_TIME_UNIT_FOREVER_REL);
324 h->cb (h->cb_cls, NULL, NULL, NULL);
327 GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key,
329 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id);
333 str = (const char *) &um[1];
334 ego = GNUNET_CONTAINER_multihashmap_get (h->egos,
338 /* ego was created */
341 /* deletion of unknown ego? not allowed */
343 reschedule_connect (h);
346 ego = GNUNET_new (struct GNUNET_IDENTITY_Ego);
347 ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
348 *ego->pk = um->private_key;
349 ego->name = GNUNET_strdup (str);
351 GNUNET_assert (GNUNET_YES ==
352 GNUNET_CONTAINER_multihashmap_put (h->egos,
355 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
359 /* ego was deleted */
360 GNUNET_assert (GNUNET_YES ==
361 GNUNET_CONTAINER_multihashmap_remove (h->egos,
367 /* ego changed name */
368 GNUNET_free (ego->name);
369 ego->name = GNUNET_strdup (str);
371 GNUNET_CLIENT_receive (h->client, &message_handler, h,
372 GNUNET_TIME_UNIT_FOREVER_REL);
373 /* inform application about change */
381 GNUNET_free (ego->pk);
382 GNUNET_free (ego->name);
386 case GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT:
387 if (size < sizeof (struct GNUNET_IDENTITY_SetDefaultMessage))
390 reschedule_connect (h);
393 sdm = (const struct GNUNET_IDENTITY_SetDefaultMessage *) msg;
394 GNUNET_break (0 == ntohs (sdm->reserved));
395 name_len = ntohs (sdm->name_len);
396 str = (const char *) &sdm[1];
397 if ( (size != name_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage)) ||
399 ('\0' != str[name_len - 1]) ) )
402 reschedule_connect (h);
405 /* Note: we know which service this should be for, so we're not
406 really using 'str' henceforth */
407 GNUNET_CRYPTO_ecdsa_key_get_public (&sdm->private_key,
409 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id);
410 ego = GNUNET_CONTAINER_multihashmap_get (h->egos,
415 reschedule_connect (h);
422 reschedule_connect (h);
425 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
426 "Received SET_DEFAULT message from identity service\n");
427 GNUNET_CONTAINER_DLL_remove (h->op_head,
430 GNUNET_CLIENT_receive (h->client, &message_handler, h,
431 GNUNET_TIME_UNIT_FOREVER_REL);
441 reschedule_connect (h);
448 * Schedule transmission of the next message from our queue.
450 * @param h identity handle
453 transmit_next (struct GNUNET_IDENTITY_Handle *h);
457 * Transmit next message to service.
459 * @param cls the `struct GNUNET_IDENTITY_Handle`.
460 * @param size number of bytes available in @a buf
461 * @param buf where to copy the message
462 * @return number of bytes copied to buf
465 send_next_message (void *cls,
469 struct GNUNET_IDENTITY_Handle *h = cls;
470 struct GNUNET_IDENTITY_Operation *op = h->op_head;
476 ret = ntohs (op->msg->size);
479 reschedule_connect (h);
482 LOG (GNUNET_ERROR_TYPE_DEBUG,
483 "Sending message of type %d to identity service\n",
484 ntohs (op->msg->type));
485 memcpy (buf, op->msg, ret);
486 if ( (NULL == op->cont) &&
489 GNUNET_CONTAINER_DLL_remove (h->op_head,
495 if (GNUNET_NO == h->in_receive)
497 h->in_receive = GNUNET_YES;
498 GNUNET_CLIENT_receive (h->client,
500 GNUNET_TIME_UNIT_FOREVER_REL);
507 * Schedule transmission of the next message from our queue.
509 * @param h identity handle
512 transmit_next (struct GNUNET_IDENTITY_Handle *h)
514 struct GNUNET_IDENTITY_Operation *op = h->op_head;
516 GNUNET_assert (NULL == h->th);
519 if (NULL == h->client)
521 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
522 ntohs (op->msg->size),
523 GNUNET_TIME_UNIT_FOREVER_REL,
531 * Try again to connect to the identity service.
533 * @param cls handle to the identity service.
536 reconnect (void *cls)
538 struct GNUNET_IDENTITY_Handle *h = cls;
539 struct GNUNET_IDENTITY_Operation *op;
540 struct GNUNET_MessageHeader msg;
542 h->reconnect_task = NULL;
543 LOG (GNUNET_ERROR_TYPE_DEBUG,
544 "Connecting to identity service.\n");
545 GNUNET_assert (NULL == h->client);
546 h->client = GNUNET_CLIENT_connect ("identity", h->cfg);
547 GNUNET_assert (NULL != h->client);
548 if ( (NULL == h->op_head) ||
549 (GNUNET_MESSAGE_TYPE_IDENTITY_START != ntohs (h->op_head->msg->type)) )
551 op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) +
552 sizeof (struct GNUNET_MessageHeader));
554 op->msg = (const struct GNUNET_MessageHeader *) &op[1];
555 msg.size = htons (sizeof (msg));
556 msg.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_START);
557 memcpy (&op[1], &msg, sizeof (msg));
558 GNUNET_CONTAINER_DLL_insert (h->op_head,
563 GNUNET_assert (NULL != h->th);
568 * Connect to the identity service.
570 * @param cfg the configuration to use
571 * @param cb function to call on all identity events, can be NULL
572 * @param cb_cls closure for @a cb
573 * @return handle to use
575 struct GNUNET_IDENTITY_Handle *
576 GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
577 GNUNET_IDENTITY_Callback cb,
580 struct GNUNET_IDENTITY_Handle *h;
582 h = GNUNET_new (struct GNUNET_IDENTITY_Handle);
586 h->egos = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES);
587 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
588 h->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, h);
594 * Obtain the ECC key associated with a ego.
597 * @return associated ECC key, valid as long as the ego is valid
599 const struct GNUNET_CRYPTO_EcdsaPrivateKey *
600 GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego)
607 * Get the identifier (public key) of an ego.
609 * @param ego identity handle with the private key
610 * @param pk set to ego's public key
613 GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego,
614 struct GNUNET_CRYPTO_EcdsaPublicKey *pk)
616 GNUNET_CRYPTO_ecdsa_key_get_public (ego->pk,
622 * Obtain the identity that is currently preferred/default
625 * @param id identity service to query
626 * @param service_name for which service is an identity wanted
627 * @param cb function to call with the result (will only be called once)
628 * @param cb_cls closure for @a cb
629 * @return handle to abort the operation
631 struct GNUNET_IDENTITY_Operation *
632 GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *id,
633 const char *service_name,
634 GNUNET_IDENTITY_Callback cb,
637 struct GNUNET_IDENTITY_Operation *op;
638 struct GNUNET_IDENTITY_GetDefaultMessage *gdm;
641 slen = strlen (service_name) + 1;
642 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_GetDefaultMessage))
647 op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) +
648 sizeof (struct GNUNET_IDENTITY_GetDefaultMessage) +
653 gdm = (struct GNUNET_IDENTITY_GetDefaultMessage *) &op[1];
654 gdm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT);
655 gdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_GetDefaultMessage) +
657 gdm->name_len = htons (slen);
658 gdm->reserved = htons (0);
659 memcpy (&gdm[1], service_name, slen);
660 op->msg = &gdm->header;
661 GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
671 * Set the preferred/default identity for a service.
673 * @param id identity service to inform
674 * @param service_name for which service is an identity set
675 * @param ego new default identity to be set for this service
676 * @param cont function to call once the operation finished
677 * @param cont_cls closure for @a cont
678 * @return handle to abort the operation
680 struct GNUNET_IDENTITY_Operation *
681 GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *id,
682 const char *service_name,
683 struct GNUNET_IDENTITY_Ego *ego,
684 GNUNET_IDENTITY_Continuation cont,
687 struct GNUNET_IDENTITY_Operation *op;
688 struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
691 slen = strlen (service_name) + 1;
692 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_SetDefaultMessage))
697 op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) +
698 sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) +
703 sdm = (struct GNUNET_IDENTITY_SetDefaultMessage *) &op[1];
704 sdm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
705 sdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) +
707 sdm->name_len = htons (slen);
708 sdm->reserved = htons (0);
709 sdm->private_key = *ego->pk;
710 memcpy (&sdm[1], service_name, slen);
711 op->msg = &sdm->header;
712 GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
722 * Create a new identity with the given name.
724 * @param id identity service to use
725 * @param name desired name
726 * @param cont function to call with the result (will only be called once)
727 * @param cont_cls closure for @a cont
728 * @return handle to abort the operation
730 struct GNUNET_IDENTITY_Operation *
731 GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
733 GNUNET_IDENTITY_Continuation cont,
736 struct GNUNET_IDENTITY_Operation *op;
737 struct GNUNET_IDENTITY_CreateRequestMessage *crm;
738 struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
741 slen = strlen (name) + 1;
742 pk = GNUNET_CRYPTO_ecdsa_key_create ();
744 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_CreateRequestMessage))
750 op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) +
751 sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) +
756 crm = (struct GNUNET_IDENTITY_CreateRequestMessage *) &op[1];
757 crm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_CREATE);
758 crm->header.size = htons (sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) +
760 crm->name_len = htons (slen);
761 crm->reserved = htons (0);
762 crm->private_key = *pk;
763 memcpy (&crm[1], name, slen);
764 op->msg = &crm->header;
765 GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
776 * Renames an existing identity.
778 * @param id identity service to use
779 * @param old_name old name
780 * @param new_name desired new name
781 * @param cb function to call with the result (will only be called once)
782 * @param cb_cls closure for @a cb
783 * @return handle to abort the operation
785 struct GNUNET_IDENTITY_Operation *
786 GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *id,
787 const char *old_name,
788 const char *new_name,
789 GNUNET_IDENTITY_Continuation cb,
792 struct GNUNET_IDENTITY_Operation *op;
793 struct GNUNET_IDENTITY_RenameMessage *grm;
798 slen_old = strlen (old_name) + 1;
799 slen_new = strlen (new_name) + 1;
800 if ( (slen_old >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
801 (slen_new >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
802 (slen_old + slen_new >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_RenameMessage)) )
807 op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) +
808 sizeof (struct GNUNET_IDENTITY_RenameMessage) +
809 slen_old + slen_new);
813 grm = (struct GNUNET_IDENTITY_RenameMessage *) &op[1];
814 grm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_RENAME);
815 grm->header.size = htons (sizeof (struct GNUNET_IDENTITY_RenameMessage) +
816 slen_old + slen_new);
817 grm->old_name_len = htons (slen_old);
818 grm->new_name_len = htons (slen_new);
819 dst = (char *) &grm[1];
820 memcpy (dst, old_name, slen_old);
821 memcpy (&dst[slen_old], new_name, slen_new);
822 op->msg = &grm->header;
823 GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
833 * Delete an existing identity.
835 * @param id identity service to use
836 * @param name name of the identity to delete
837 * @param cb function to call with the result (will only be called once)
838 * @param cb_cls closure for @a cb
839 * @return handle to abort the operation
841 struct GNUNET_IDENTITY_Operation *
842 GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *id,
844 GNUNET_IDENTITY_Continuation cb,
847 struct GNUNET_IDENTITY_Operation *op;
848 struct GNUNET_IDENTITY_DeleteMessage *gdm;
851 slen = strlen (name) + 1;
852 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_DeleteMessage))
857 op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) +
858 sizeof (struct GNUNET_IDENTITY_DeleteMessage) +
863 gdm = (struct GNUNET_IDENTITY_DeleteMessage *) &op[1];
864 gdm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_DELETE);
865 gdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_DeleteMessage) +
867 gdm->name_len = htons (slen);
868 gdm->reserved = htons (0);
869 memcpy (&gdm[1], name, slen);
870 op->msg = &gdm->header;
871 GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
881 * Cancel an identity operation. Note that the operation MAY still
882 * be executed; this merely cancels the continuation; if the request
883 * was already transmitted, the service may still choose to complete
886 * @param op operation to cancel
889 GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op)
891 struct GNUNET_IDENTITY_Handle *h = op->h;
893 if ( (h->op_head != op) ||
894 (NULL == h->client) )
896 /* request not active, can simply remove */
897 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
898 "Client aborted non-head operation, simply removing it\n");
899 GNUNET_CONTAINER_DLL_remove (h->op_head,
907 /* request active but not yet with service, can still abort */
908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
909 "Client aborted head operation prior to transmission, aborting it\n");
910 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
912 GNUNET_CONTAINER_DLL_remove (h->op_head,
919 /* request active with service, simply ensure continuations are not called */
920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
921 "Client aborted active request, NULLing continuation\n");
928 * Free ego from hash map.
930 * @param cls identity service handle
932 * @param value ego to free
933 * @return #GNUNET_OK (continue to iterate)
937 const struct GNUNET_HashCode *key,
940 struct GNUNET_IDENTITY_Handle *h = cls;
941 struct GNUNET_IDENTITY_Ego *ego = value;
948 GNUNET_free (ego->pk);
949 GNUNET_free (ego->name);
956 * Disconnect from identity service
958 * @param h handle to destroy
961 GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h)
963 struct GNUNET_IDENTITY_Operation *op;
965 GNUNET_assert (NULL != h);
966 if (h->reconnect_task != NULL)
968 GNUNET_SCHEDULER_cancel (h->reconnect_task);
969 h->reconnect_task = NULL;
973 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
978 GNUNET_CONTAINER_multihashmap_iterate (h->egos,
981 GNUNET_CONTAINER_multihashmap_destroy (h->egos);
984 while (NULL != (op = h->op_head))
986 GNUNET_break (NULL == op->cont);
987 GNUNET_CONTAINER_DLL_remove (h->op_head,
992 if (NULL != h->client)
994 GNUNET_CLIENT_disconnect (h->client);
1000 /* end of identity_api.c */