From f38bc10411d68d2246919d57d043ee8bf0ca804a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 2 May 2020 00:08:38 +0200 Subject: [PATCH] fix gnunet-identity performance --- src/identity/gnunet-identity.c | 68 +++++++++---- src/identity/gnunet-service-identity.c | 102 ++++++++++++------- src/identity/identity.h | 15 ++- src/identity/identity_api.c | 133 +++++++++++++++++-------- src/include/gnunet_identity_service.h | 2 +- 5 files changed, 218 insertions(+), 102 deletions(-) diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c index 8445a0ee5..fd73048c4 100644 --- a/src/identity/gnunet-identity.c +++ b/src/identity/gnunet-identity.c @@ -143,10 +143,14 @@ shutdown_task (void *cls) * Test if we are finished yet. */ static void -test_finished () +test_finished (void) { - if ((NULL == create_op) && (NULL == delete_op) && (NULL == set_op) && - (NULL == set_subsystem) && (! list) && (! monitor)) + if ( (NULL == create_op) && + (NULL == delete_op) && + (NULL == set_op) && + (NULL == set_subsystem) && + (! list) && + (! monitor)) { if (TIMEOUT_STATUS_CODE == global_ret) global_ret = 0; @@ -162,7 +166,8 @@ test_finished () * @param emsg NULL on success, otherwise an error message */ static void -delete_finished (void *cls, const char *emsg) +delete_finished (void *cls, + const char *emsg) { struct GNUNET_IDENTITY_Operation **op = cls; @@ -190,7 +195,9 @@ create_finished (void *cls, *op = NULL; if (NULL == pk) { - fprintf (stderr, _ ("Failed to create ego: %s\n"), emsg); + fprintf (stderr, + _ ("Failed to create ego: %s\n"), + emsg); global_ret = 1; } else if (verbose) @@ -280,16 +287,25 @@ print_ego (void *cls, char *s; char *privs; - if ((NULL != set_ego) && (NULL != set_subsystem) && (NULL != ego) && - (NULL != identifier) && (0 == strcmp (identifier, set_ego))) + if ( (NULL != set_ego) && + (NULL != set_subsystem) && + (NULL != ego) && + (NULL != identifier) && + (0 == strcmp (identifier, set_ego))) { - set_op = GNUNET_IDENTITY_set (sh, set_subsystem, ego, &set_done, NULL); + set_op = GNUNET_IDENTITY_set (sh, + set_subsystem, + ego, + &set_done, + NULL); GNUNET_free (set_subsystem); set_subsystem = NULL; GNUNET_free (set_ego); set_ego = NULL; } - if ((NULL == ego) && (NULL != set_ego) && (NULL != set_subsystem)) + if ( (NULL == ego) && + (NULL != set_ego) && + (NULL != set_subsystem) ) { fprintf (stderr, "Could not set ego to `%s' for subsystem `%s', ego not known\n", @@ -308,9 +324,12 @@ print_ego (void *cls, } if (! (list | monitor)) return; - if ((NULL == ego) || (NULL == identifier)) + if ( (NULL == ego) || + (NULL == identifier) ) return; - if ((NULL != set_ego) && (0 != strcmp (identifier, set_ego))) + if ( (NULL != set_ego) && + (0 != strcmp (identifier, + set_ego)) ) return; GNUNET_IDENTITY_ego_get_public_key (ego, &pk); s = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); @@ -358,18 +377,26 @@ run (void *cls, return; } sh = GNUNET_IDENTITY_connect (cfg, - (monitor | list) || (NULL != set_ego) || + (monitor | list) || + (NULL != set_ego) || (NULL != set_subsystem) ? &print_ego : NULL, NULL); if (NULL != delete_ego) delete_op = - GNUNET_IDENTITY_delete (sh, delete_ego, &delete_finished, &delete_op); + GNUNET_IDENTITY_delete (sh, + delete_ego, + &delete_finished, + &delete_op); if (NULL != create_ego) create_op = - GNUNET_IDENTITY_create (sh, create_ego, &create_finished, &create_op); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); + GNUNET_IDENTITY_create (sh, + create_ego, + &create_finished, + &create_op); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, + NULL); test_finished (); } @@ -384,8 +411,8 @@ run (void *cls, int main (int argc, char *const *argv) { - struct GNUNET_GETOPT_CommandLineOption options[] = - { GNUNET_GETOPT_option_string ('C', + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_option_string ('C', "create", "NAME", gettext_noop ("create ego NAME"), @@ -426,10 +453,13 @@ main (int argc, char *const *argv) "set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"), &set_subsystem), GNUNET_GETOPT_option_verbose (&verbose), - GNUNET_GETOPT_OPTION_END }; + GNUNET_GETOPT_OPTION_END + }; int res; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != + GNUNET_STRINGS_get_utf8_args (argc, argv, + &argc, &argv)) return 4; global_ret = TIMEOUT_STATUS_CODE; /* timeout */ res = GNUNET_PROGRAM_run (argc, diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index 42ad94df1..bdacf3ba0 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c @@ -140,7 +140,9 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Client %p disconnected\n", + client); } @@ -189,7 +191,9 @@ shutdown_task (void *cls) ego_directory = NULL; while (NULL != (e = ego_head)) { - GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e); + GNUNET_CONTAINER_DLL_remove (ego_head, + ego_tail, + e); GNUNET_free (e->identifier); GNUNET_free (e); } @@ -260,7 +264,8 @@ create_update_message (struct Ego *ego) * @return corresponding set default message */ static struct GNUNET_MQ_Envelope * -create_set_default_message (struct Ego *ego, const char *servicename) +create_set_default_message (struct Ego *ego, + const char *servicename) { struct SetDefaultMessage *sdm; struct GNUNET_MQ_Envelope *env; @@ -288,26 +293,34 @@ create_set_default_message (struct Ego *ego, const char *servicename) * @param message the message received */ static void -handle_start_message (void *cls, const struct GNUNET_MessageHeader *message) +handle_start_message (void *cls, + const struct GNUNET_MessageHeader *message) { struct GNUNET_SERVICE_Client *client = cls; - struct UpdateMessage *ume; - struct GNUNET_MQ_Envelope *env; - struct Ego *ego; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received START message from client\n"); GNUNET_SERVICE_client_mark_monitor (client); GNUNET_SERVICE_client_disable_continue_warning (client); - GNUNET_notification_context_add (nc, GNUNET_SERVICE_client_get_mq (client)); - for (ego = ego_head; NULL != ego; ego = ego->next) + GNUNET_notification_context_add (nc, + GNUNET_SERVICE_client_get_mq (client)); + for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next) { - env = create_update_message (ego); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); + GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), + create_update_message (ego)); + } + { + struct UpdateMessage *ume; + struct GNUNET_MQ_Envelope *env; + + env = GNUNET_MQ_msg_extra (ume, + 0, + GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); + ume->end_of_list = htons (GNUNET_YES); + ume->name_len = htons (0); + GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), + env); } - env = GNUNET_MQ_msg_extra (ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); - ume->end_of_list = htons (GNUNET_YES); - ume->name_len = htons (0); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); GNUNET_SERVICE_client_continue (client); } @@ -321,7 +334,8 @@ handle_start_message (void *cls, const struct GNUNET_MessageHeader *message) * @return #GNUNET_SYSERR if message was ill-formed */ static int -check_lookup_message (void *cls, const struct LookupMessage *message) +check_lookup_message (void *cls, + const struct LookupMessage *message) { GNUNET_MQ_check_zero_termination (message); return GNUNET_OK; @@ -336,14 +350,16 @@ check_lookup_message (void *cls, const struct LookupMessage *message) * @param message the message received */ static void -handle_lookup_message (void *cls, const struct LookupMessage *message) +handle_lookup_message (void *cls, + const struct LookupMessage *message) { struct GNUNET_SERVICE_Client *client = cls; const char *name; struct GNUNET_MQ_Envelope *env; struct Ego *ego; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received LOOKUP message from client\n"); name = (const char *) &message[1]; for (ego = ego_head; NULL != ego; ego = ego->next) { @@ -368,7 +384,8 @@ handle_lookup_message (void *cls, const struct LookupMessage *message) * @return #GNUNET_SYSERR if message was ill-formed */ static int -check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) +check_lookup_by_suffix_message (void *cls, + const struct LookupMessage *message) { GNUNET_MQ_check_zero_termination (message); return GNUNET_OK; @@ -383,7 +400,8 @@ check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) * @param message the message received */ static void -handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) +handle_lookup_by_suffix_message (void *cls, + const struct LookupMessage *message) { struct GNUNET_SERVICE_Client *client = cls; const char *name; @@ -428,7 +446,8 @@ handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) * @return #GNUNET_OK if @a msg is well-formed */ static int -check_get_default_message (void *cls, const struct GetDefaultMessage *msg) +check_get_default_message (void *cls, + const struct GetDefaultMessage *msg) { uint16_t size; uint16_t name_len; @@ -461,31 +480,32 @@ check_get_default_message (void *cls, const struct GetDefaultMessage *msg) * @param message the message received */ static void -handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm) +handle_get_default_message (void *cls, + const struct GetDefaultMessage *gdm) { struct GNUNET_MQ_Envelope *env; struct GNUNET_SERVICE_Client *client = cls; - struct Ego *ego; char *name; char *identifier; - name = GNUNET_strdup ((const char *) &gdm[1]); - GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1], name); + GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1], + name); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received GET_DEFAULT for service `%s' from client\n", name); - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, - name, - "DEFAULT_IDENTIFIER", - &identifier)) + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, + name, + "DEFAULT_IDENTIFIER", + &identifier)) { send_result_code (client, 1, gettext_noop ("no default known")); GNUNET_SERVICE_client_continue (client); GNUNET_free (name); return; } - for (ego = ego_head; NULL != ego; ego = ego->next) + for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next) { if (0 == strcmp (ego->identifier, identifier)) { @@ -498,7 +518,9 @@ handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm) } } GNUNET_free (identifier); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Failed to find ego `%s'\n", + name); GNUNET_free (name); send_result_code (client, 1, @@ -531,7 +553,8 @@ key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1, * @return #GNUNET_OK if @a msg is well-formed */ static int -check_set_default_message (void *cls, const struct SetDefaultMessage *msg) +check_set_default_message (void *cls, + const struct SetDefaultMessage *msg) { uint16_t size; uint16_t name_len; @@ -569,7 +592,8 @@ check_set_default_message (void *cls, const struct SetDefaultMessage *msg) * @param message the message received */ static void -handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm) +handle_set_default_message (void *cls, + const struct SetDefaultMessage *sdm) { struct Ego *ego; struct GNUNET_SERVICE_Client *client = cls; @@ -642,7 +666,8 @@ notify_listeners (struct Ego *ego) * @return #GNUNET_OK if @a msg is well-formed */ static int -check_create_message (void *cls, const struct CreateRequestMessage *msg) +check_create_message (void *cls, + const struct CreateRequestMessage *msg) { uint16_t size; uint16_t name_len; @@ -680,7 +705,8 @@ check_create_message (void *cls, const struct CreateRequestMessage *msg) * @param message the message received */ static void -handle_create_message (void *cls, const struct CreateRequestMessage *crm) +handle_create_message (void *cls, + const struct CreateRequestMessage *crm) { struct GNUNET_SERVICE_Client *client = cls; struct Ego *ego; @@ -706,7 +732,9 @@ handle_create_message (void *cls, const struct CreateRequestMessage *crm) ego = GNUNET_new (struct Ego); ego->pk = crm->private_key; ego->identifier = GNUNET_strdup (str); - GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); + GNUNET_CONTAINER_DLL_insert (ego_head, + ego_tail, + ego); send_result_code (client, 0, NULL); fn = get_ego_filename (ego); (void) GNUNET_DISK_directory_create_for_file (fn); diff --git a/src/identity/identity.h b/src/identity/identity.h index 2303bf214..ef638fa36 100644 --- a/src/identity/identity.h +++ b/src/identity/identity.h @@ -244,11 +244,22 @@ GNUNET_NETWORK_STRUCT_END */ struct GNUNET_IDENTITY_Ego { + /** + * Hash of the private key of this ego. + */ + struct GNUNET_HashCode id; + /** * Private key associated with this ego. */ struct GNUNET_CRYPTO_EcdsaPrivateKey pk; + /** + * Public key associated with this ego. Initialized on demand. + * Always use #GNUNET_IDENTITY_ego_get_public_key() to obtain. + */ + struct GNUNET_CRYPTO_EcdsaPublicKey pub; + /** * Current name associated with this ego. */ @@ -260,9 +271,9 @@ struct GNUNET_IDENTITY_Ego void *ctx; /** - * Hash of the public key of this ego. + * Set to true once @e pub was initialized */ - struct GNUNET_HashCode id; + bool pub_initialized; }; diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c index 9176acc27..9269e1c79 100644 --- a/src/identity/identity_api.c +++ b/src/identity/identity_api.c @@ -105,7 +105,7 @@ struct GNUNET_IDENTITY_Handle struct GNUNET_MQ_Handle *mq; /** - * Hash map from the hash of the public key to the + * Hash map from the hash of the private key to the * respective `GNUNET_IDENTITY_Ego` handle. */ struct GNUNET_CONTAINER_MultiHashMap *egos; @@ -190,16 +190,22 @@ reconnect (void *cls); * @return #GNUNET_OK (continue to iterate) */ static int -free_ego (void *cls, const struct GNUNET_HashCode *key, void *value) +free_ego (void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_IDENTITY_Handle *h = cls; struct GNUNET_IDENTITY_Ego *ego = value; if (NULL != h->cb) - h->cb (h->cb_cls, ego, &ego->ctx, NULL); + h->cb (h->cb_cls, ego, + &ego->ctx, + NULL); GNUNET_free (ego->name); GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (h->egos, key, value)); + GNUNET_CONTAINER_multihashmap_remove (h->egos, + key, + value)); GNUNET_free (ego); return GNUNET_OK; } @@ -224,9 +230,12 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h) } while (NULL != (op = h->op_head)) { - GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); + GNUNET_CONTAINER_DLL_remove (h->op_head, + h->op_tail, + op); if (NULL != op->cont) - op->cont (op->cls, "Error in communication with the identity service"); + op->cont (op->cls, + "Error in communication with the identity service"); else if (NULL != op->cb) op->cb (op->cls, NULL, NULL, NULL); else if (NULL != op->create_cont) @@ -235,12 +244,17 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h) "Failed to communicate with the identity service"); GNUNET_free (op); } - GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h); + GNUNET_CONTAINER_multihashmap_iterate (h->egos, + &free_ego, + h); LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling task to reconnect to identity service in %s.\n", - GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); + GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, + GNUNET_YES)); h->reconnect_task = - GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); + GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, + &reconnect, + h); h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); } @@ -254,7 +268,8 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h) * @param error error code */ static void -mq_error_handler (void *cls, enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_IDENTITY_Handle *h = cls; @@ -271,7 +286,8 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) * @return #GNUNET_OK if the message is well-formed */ static int -check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) +check_identity_result_code (void *cls, + const struct ResultCodeMessage *rcm) { if (sizeof(*rcm) != htons (rcm->header.size)) GNUNET_MQ_check_zero_termination (rcm); @@ -286,7 +302,8 @@ check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) * @param rcm result message received */ static void -handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) +handle_identity_result_code (void *cls, + const struct ResultCodeMessage *rcm) { struct GNUNET_IDENTITY_Handle *h = cls; struct GNUNET_IDENTITY_Operation *op; @@ -319,7 +336,8 @@ handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) * @return #GNUNET_OK if the message is well-formed */ static int -check_identity_update (void *cls, const struct UpdateMessage *um) +check_identity_update (void *cls, + const struct UpdateMessage *um) { uint16_t size = ntohs (um->header.size); uint16_t name_len = ntohs (um->name_len); @@ -342,12 +360,12 @@ check_identity_update (void *cls, const struct UpdateMessage *um) * @param um message received */ static void -handle_identity_update (void *cls, const struct UpdateMessage *um) +handle_identity_update (void *cls, + const struct UpdateMessage *um) { struct GNUNET_IDENTITY_Handle *h = cls; uint16_t name_len = ntohs (um->name_len); const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; - struct GNUNET_CRYPTO_EcdsaPublicKey pub; struct GNUNET_HashCode id; struct GNUNET_IDENTITY_Ego *ego; @@ -358,9 +376,11 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) h->cb (h->cb_cls, NULL, NULL, NULL); return; } - GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub); - GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id); - ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id); + GNUNET_CRYPTO_hash (&um->private_key, + sizeof (um->private_key), + &id); + ego = GNUNET_CONTAINER_multihashmap_get (h->egos, + &id); if (NULL == ego) { /* ego was created */ @@ -385,9 +405,10 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) if (NULL == str) { /* ego was deleted */ - GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (h->egos, - &ego->id, - ego)); + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove (h->egos, + &ego->id, + ego)); } else { @@ -397,7 +418,10 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) } /* inform application about change */ if (NULL != h->cb) - h->cb (h->cb_cls, ego, &ego->ctx, str); + h->cb (h->cb_cls, + ego, + &ego->ctx, + str); /* complete deletion */ if (NULL == str) { @@ -416,7 +440,8 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) * @return #GNUNET_OK if the message is well-formed */ static int -check_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) +check_identity_set_default (void *cls, + const struct SetDefaultMessage *sdm) { uint16_t size = ntohs (sdm->header.size) - sizeof(*sdm); uint16_t name_len = ntohs (sdm->name_len); @@ -440,17 +465,19 @@ check_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) * @param sdm message received */ static void -handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) +handle_identity_set_default (void *cls, + const struct SetDefaultMessage *sdm) { struct GNUNET_IDENTITY_Handle *h = cls; struct GNUNET_IDENTITY_Operation *op; - struct GNUNET_CRYPTO_EcdsaPublicKey pub; struct GNUNET_HashCode id; struct GNUNET_IDENTITY_Ego *ego; - GNUNET_CRYPTO_ecdsa_key_get_public (&sdm->private_key, &pub); - GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id); - ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id); + GNUNET_CRYPTO_hash (&sdm->private_key, + sizeof(sdm->private_key), + &id); + ego = GNUNET_CONTAINER_multihashmap_get (h->egos, + &id); if (NULL == ego) { GNUNET_break (0); @@ -466,9 +493,14 @@ handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received SET_DEFAULT message from identity service\n"); - GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); + GNUNET_CONTAINER_DLL_remove (h->op_head, + h->op_tail, + op); if (NULL != op->cb) - op->cb (op->cls, ego, &ego->ctx, ego->name); + op->cb (op->cls, + ego, + &ego->ctx, + ego->name); GNUNET_free (op); } @@ -482,8 +514,8 @@ static void reconnect (void *cls) { struct GNUNET_IDENTITY_Handle *h = cls; - struct GNUNET_MQ_MessageHandler handlers[] = - { GNUNET_MQ_hd_var_size (identity_result_code, + struct GNUNET_MQ_MessageHandler handlers[] = { + GNUNET_MQ_hd_var_size (identity_result_code, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, struct ResultCodeMessage, h), @@ -495,21 +527,28 @@ reconnect (void *cls) GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, struct SetDefaultMessage, h), - GNUNET_MQ_handler_end () }; + GNUNET_MQ_handler_end () + }; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *msg; h->reconnect_task = NULL; - LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to identity service.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Connecting to identity service.\n"); GNUNET_assert (NULL == h->mq); - h->mq = - GNUNET_CLIENT_connect (h->cfg, "identity", handlers, &mq_error_handler, h); + h->mq = GNUNET_CLIENT_connect (h->cfg, + "identity", + handlers, + &mq_error_handler, + h); if (NULL == h->mq) return; if (NULL != h->cb) { - env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_IDENTITY_START); - GNUNET_MQ_send (h->mq, env); + env = GNUNET_MQ_msg (msg, + GNUNET_MESSAGE_TYPE_IDENTITY_START); + GNUNET_MQ_send (h->mq, + env); } } @@ -533,7 +572,8 @@ GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, h->cfg = cfg; h->cb = cb; h->cb_cls = cb_cls; - h->egos = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES); + h->egos = GNUNET_CONTAINER_multihashmap_create (16, + GNUNET_YES); reconnect (h); if (NULL == h->mq) { @@ -564,11 +604,16 @@ GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego) * @param pk set to ego's public key */ void -GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, +GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_CRYPTO_EcdsaPublicKey *pk) { - GNUNET_CRYPTO_ecdsa_key_get_public (&ego->pk, - pk); + if (! ego->pub_initialized) + { + GNUNET_CRYPTO_ecdsa_key_get_public (&ego->pk, + &ego->pub); + ego->pub_initialized = true; + } + *pk = ego->pub; } @@ -842,7 +887,9 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h) } if (NULL != h->egos) { - GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h); + GNUNET_CONTAINER_multihashmap_iterate (h->egos, + &free_ego, + h); GNUNET_CONTAINER_multihashmap_destroy (h->egos); h->egos = NULL; } diff --git a/src/include/gnunet_identity_service.h b/src/include/gnunet_identity_service.h index e09e2f196..af5beb5f7 100644 --- a/src/include/gnunet_identity_service.h +++ b/src/include/gnunet_identity_service.h @@ -99,7 +99,7 @@ GNUNET_IDENTITY_ego_get_anonymous (void); * @param pk set to ego's public key */ void -GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, +GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_CRYPTO_EcdsaPublicKey *pk); -- 2.25.1