aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-05-02 00:08:38 +0200
committerChristian Grothoff <christian@grothoff.org>2020-05-02 00:08:38 +0200
commitf38bc10411d68d2246919d57d043ee8bf0ca804a (patch)
treed28ac8f609fe78dc0bb1ffdcc81e417198dc5c00
parentd3ec11c5a2dc7521efbd308e273dccc26c0e4bb4 (diff)
downloadgnunet-f38bc10411d68d2246919d57d043ee8bf0ca804a.tar.gz
gnunet-f38bc10411d68d2246919d57d043ee8bf0ca804a.zip
fix gnunet-identity performance
-rw-r--r--src/identity/gnunet-identity.c68
-rw-r--r--src/identity/gnunet-service-identity.c102
-rw-r--r--src/identity/identity.h15
-rw-r--r--src/identity/identity_api.c133
-rw-r--r--src/include/gnunet_identity_service.h2
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)
143 * Test if we are finished yet. 143 * Test if we are finished yet.
144 */ 144 */
145static void 145static void
146test_finished () 146test_finished (void)
147{ 147{
148 if ((NULL == create_op) && (NULL == delete_op) && (NULL == set_op) && 148 if ( (NULL == create_op) &&
149 (NULL == set_subsystem) && (! list) && (! monitor)) 149 (NULL == delete_op) &&
150 (NULL == set_op) &&
151 (NULL == set_subsystem) &&
152 (! list) &&
153 (! monitor))
150 { 154 {
151 if (TIMEOUT_STATUS_CODE == global_ret) 155 if (TIMEOUT_STATUS_CODE == global_ret)
152 global_ret = 0; 156 global_ret = 0;
@@ -162,7 +166,8 @@ test_finished ()
162 * @param emsg NULL on success, otherwise an error message 166 * @param emsg NULL on success, otherwise an error message
163 */ 167 */
164static void 168static void
165delete_finished (void *cls, const char *emsg) 169delete_finished (void *cls,
170 const char *emsg)
166{ 171{
167 struct GNUNET_IDENTITY_Operation **op = cls; 172 struct GNUNET_IDENTITY_Operation **op = cls;
168 173
@@ -190,7 +195,9 @@ create_finished (void *cls,
190 *op = NULL; 195 *op = NULL;
191 if (NULL == pk) 196 if (NULL == pk)
192 { 197 {
193 fprintf (stderr, _ ("Failed to create ego: %s\n"), emsg); 198 fprintf (stderr,
199 _ ("Failed to create ego: %s\n"),
200 emsg);
194 global_ret = 1; 201 global_ret = 1;
195 } 202 }
196 else if (verbose) 203 else if (verbose)
@@ -280,16 +287,25 @@ print_ego (void *cls,
280 char *s; 287 char *s;
281 char *privs; 288 char *privs;
282 289
283 if ((NULL != set_ego) && (NULL != set_subsystem) && (NULL != ego) && 290 if ( (NULL != set_ego) &&
284 (NULL != identifier) && (0 == strcmp (identifier, set_ego))) 291 (NULL != set_subsystem) &&
292 (NULL != ego) &&
293 (NULL != identifier) &&
294 (0 == strcmp (identifier, set_ego)))
285 { 295 {
286 set_op = GNUNET_IDENTITY_set (sh, set_subsystem, ego, &set_done, NULL); 296 set_op = GNUNET_IDENTITY_set (sh,
297 set_subsystem,
298 ego,
299 &set_done,
300 NULL);
287 GNUNET_free (set_subsystem); 301 GNUNET_free (set_subsystem);
288 set_subsystem = NULL; 302 set_subsystem = NULL;
289 GNUNET_free (set_ego); 303 GNUNET_free (set_ego);
290 set_ego = NULL; 304 set_ego = NULL;
291 } 305 }
292 if ((NULL == ego) && (NULL != set_ego) && (NULL != set_subsystem)) 306 if ( (NULL == ego) &&
307 (NULL != set_ego) &&
308 (NULL != set_subsystem) )
293 { 309 {
294 fprintf (stderr, 310 fprintf (stderr,
295 "Could not set ego to `%s' for subsystem `%s', ego not known\n", 311 "Could not set ego to `%s' for subsystem `%s', ego not known\n",
@@ -308,9 +324,12 @@ print_ego (void *cls,
308 } 324 }
309 if (! (list | monitor)) 325 if (! (list | monitor))
310 return; 326 return;
311 if ((NULL == ego) || (NULL == identifier)) 327 if ( (NULL == ego) ||
328 (NULL == identifier) )
312 return; 329 return;
313 if ((NULL != set_ego) && (0 != strcmp (identifier, set_ego))) 330 if ( (NULL != set_ego) &&
331 (0 != strcmp (identifier,
332 set_ego)) )
314 return; 333 return;
315 GNUNET_IDENTITY_ego_get_public_key (ego, &pk); 334 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
316 s = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); 335 s = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
@@ -358,18 +377,26 @@ run (void *cls,
358 return; 377 return;
359 } 378 }
360 sh = GNUNET_IDENTITY_connect (cfg, 379 sh = GNUNET_IDENTITY_connect (cfg,
361 (monitor | list) || (NULL != set_ego) || 380 (monitor | list) ||
381 (NULL != set_ego) ||
362 (NULL != set_subsystem) 382 (NULL != set_subsystem)
363 ? &print_ego 383 ? &print_ego
364 : NULL, 384 : NULL,
365 NULL); 385 NULL);
366 if (NULL != delete_ego) 386 if (NULL != delete_ego)
367 delete_op = 387 delete_op =
368 GNUNET_IDENTITY_delete (sh, delete_ego, &delete_finished, &delete_op); 388 GNUNET_IDENTITY_delete (sh,
389 delete_ego,
390 &delete_finished,
391 &delete_op);
369 if (NULL != create_ego) 392 if (NULL != create_ego)
370 create_op = 393 create_op =
371 GNUNET_IDENTITY_create (sh, create_ego, &create_finished, &create_op); 394 GNUNET_IDENTITY_create (sh,
372 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 395 create_ego,
396 &create_finished,
397 &create_op);
398 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
399 NULL);
373 test_finished (); 400 test_finished ();
374} 401}
375 402
@@ -384,8 +411,8 @@ run (void *cls,
384int 411int
385main (int argc, char *const *argv) 412main (int argc, char *const *argv)
386{ 413{
387 struct GNUNET_GETOPT_CommandLineOption options[] = 414 struct GNUNET_GETOPT_CommandLineOption options[] = {
388 { GNUNET_GETOPT_option_string ('C', 415 GNUNET_GETOPT_option_string ('C',
389 "create", 416 "create",
390 "NAME", 417 "NAME",
391 gettext_noop ("create ego NAME"), 418 gettext_noop ("create ego NAME"),
@@ -426,10 +453,13 @@ main (int argc, char *const *argv)
426 "set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"), 453 "set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"),
427 &set_subsystem), 454 &set_subsystem),
428 GNUNET_GETOPT_option_verbose (&verbose), 455 GNUNET_GETOPT_option_verbose (&verbose),
429 GNUNET_GETOPT_OPTION_END }; 456 GNUNET_GETOPT_OPTION_END
457 };
430 int res; 458 int res;
431 459
432 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 460 if (GNUNET_OK !=
461 GNUNET_STRINGS_get_utf8_args (argc, argv,
462 &argc, &argv))
433 return 4; 463 return 4;
434 global_ret = TIMEOUT_STATUS_CODE; /* timeout */ 464 global_ret = TIMEOUT_STATUS_CODE; /* timeout */
435 res = GNUNET_PROGRAM_run (argc, 465 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,
140 struct GNUNET_SERVICE_Client *client, 140 struct GNUNET_SERVICE_Client *client,
141 void *app_ctx) 141 void *app_ctx)
142{ 142{
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); 143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
144 "Client %p disconnected\n",
145 client);
144} 146}
145 147
146 148
@@ -189,7 +191,9 @@ shutdown_task (void *cls)
189 ego_directory = NULL; 191 ego_directory = NULL;
190 while (NULL != (e = ego_head)) 192 while (NULL != (e = ego_head))
191 { 193 {
192 GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e); 194 GNUNET_CONTAINER_DLL_remove (ego_head,
195 ego_tail,
196 e);
193 GNUNET_free (e->identifier); 197 GNUNET_free (e->identifier);
194 GNUNET_free (e); 198 GNUNET_free (e);
195 } 199 }
@@ -260,7 +264,8 @@ create_update_message (struct Ego *ego)
260 * @return corresponding set default message 264 * @return corresponding set default message
261 */ 265 */
262static struct GNUNET_MQ_Envelope * 266static struct GNUNET_MQ_Envelope *
263create_set_default_message (struct Ego *ego, const char *servicename) 267create_set_default_message (struct Ego *ego,
268 const char *servicename)
264{ 269{
265 struct SetDefaultMessage *sdm; 270 struct SetDefaultMessage *sdm;
266 struct GNUNET_MQ_Envelope *env; 271 struct GNUNET_MQ_Envelope *env;
@@ -288,26 +293,34 @@ create_set_default_message (struct Ego *ego, const char *servicename)
288 * @param message the message received 293 * @param message the message received
289 */ 294 */
290static void 295static void
291handle_start_message (void *cls, const struct GNUNET_MessageHeader *message) 296handle_start_message (void *cls,
297 const struct GNUNET_MessageHeader *message)
292{ 298{
293 struct GNUNET_SERVICE_Client *client = cls; 299 struct GNUNET_SERVICE_Client *client = cls;
294 struct UpdateMessage *ume;
295 struct GNUNET_MQ_Envelope *env;
296 struct Ego *ego;
297 300
298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); 301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
302 "Received START message from client\n");
299 GNUNET_SERVICE_client_mark_monitor (client); 303 GNUNET_SERVICE_client_mark_monitor (client);
300 GNUNET_SERVICE_client_disable_continue_warning (client); 304 GNUNET_SERVICE_client_disable_continue_warning (client);
301 GNUNET_notification_context_add (nc, GNUNET_SERVICE_client_get_mq (client)); 305 GNUNET_notification_context_add (nc,
302 for (ego = ego_head; NULL != ego; ego = ego->next) 306 GNUNET_SERVICE_client_get_mq (client));
307 for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
303 { 308 {
304 env = create_update_message (ego); 309 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
305 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 310 create_update_message (ego));
311 }
312 {
313 struct UpdateMessage *ume;
314 struct GNUNET_MQ_Envelope *env;
315
316 env = GNUNET_MQ_msg_extra (ume,
317 0,
318 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
319 ume->end_of_list = htons (GNUNET_YES);
320 ume->name_len = htons (0);
321 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
322 env);
306 } 323 }
307 env = GNUNET_MQ_msg_extra (ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
308 ume->end_of_list = htons (GNUNET_YES);
309 ume->name_len = htons (0);
310 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
311 GNUNET_SERVICE_client_continue (client); 324 GNUNET_SERVICE_client_continue (client);
312} 325}
313 326
@@ -321,7 +334,8 @@ handle_start_message (void *cls, const struct GNUNET_MessageHeader *message)
321 * @return #GNUNET_SYSERR if message was ill-formed 334 * @return #GNUNET_SYSERR if message was ill-formed
322 */ 335 */
323static int 336static int
324check_lookup_message (void *cls, const struct LookupMessage *message) 337check_lookup_message (void *cls,
338 const struct LookupMessage *message)
325{ 339{
326 GNUNET_MQ_check_zero_termination (message); 340 GNUNET_MQ_check_zero_termination (message);
327 return GNUNET_OK; 341 return GNUNET_OK;
@@ -336,14 +350,16 @@ check_lookup_message (void *cls, const struct LookupMessage *message)
336 * @param message the message received 350 * @param message the message received
337 */ 351 */
338static void 352static void
339handle_lookup_message (void *cls, const struct LookupMessage *message) 353handle_lookup_message (void *cls,
354 const struct LookupMessage *message)
340{ 355{
341 struct GNUNET_SERVICE_Client *client = cls; 356 struct GNUNET_SERVICE_Client *client = cls;
342 const char *name; 357 const char *name;
343 struct GNUNET_MQ_Envelope *env; 358 struct GNUNET_MQ_Envelope *env;
344 struct Ego *ego; 359 struct Ego *ego;
345 360
346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n"); 361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
362 "Received LOOKUP message from client\n");
347 name = (const char *) &message[1]; 363 name = (const char *) &message[1];
348 for (ego = ego_head; NULL != ego; ego = ego->next) 364 for (ego = ego_head; NULL != ego; ego = ego->next)
349 { 365 {
@@ -368,7 +384,8 @@ handle_lookup_message (void *cls, const struct LookupMessage *message)
368 * @return #GNUNET_SYSERR if message was ill-formed 384 * @return #GNUNET_SYSERR if message was ill-formed
369 */ 385 */
370static int 386static int
371check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) 387check_lookup_by_suffix_message (void *cls,
388 const struct LookupMessage *message)
372{ 389{
373 GNUNET_MQ_check_zero_termination (message); 390 GNUNET_MQ_check_zero_termination (message);
374 return GNUNET_OK; 391 return GNUNET_OK;
@@ -383,7 +400,8 @@ check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
383 * @param message the message received 400 * @param message the message received
384 */ 401 */
385static void 402static void
386handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) 403handle_lookup_by_suffix_message (void *cls,
404 const struct LookupMessage *message)
387{ 405{
388 struct GNUNET_SERVICE_Client *client = cls; 406 struct GNUNET_SERVICE_Client *client = cls;
389 const char *name; 407 const char *name;
@@ -428,7 +446,8 @@ handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
428 * @return #GNUNET_OK if @a msg is well-formed 446 * @return #GNUNET_OK if @a msg is well-formed
429 */ 447 */
430static int 448static int
431check_get_default_message (void *cls, const struct GetDefaultMessage *msg) 449check_get_default_message (void *cls,
450 const struct GetDefaultMessage *msg)
432{ 451{
433 uint16_t size; 452 uint16_t size;
434 uint16_t name_len; 453 uint16_t name_len;
@@ -461,31 +480,32 @@ check_get_default_message (void *cls, const struct GetDefaultMessage *msg)
461 * @param message the message received 480 * @param message the message received
462 */ 481 */
463static void 482static void
464handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm) 483handle_get_default_message (void *cls,
484 const struct GetDefaultMessage *gdm)
465{ 485{
466 struct GNUNET_MQ_Envelope *env; 486 struct GNUNET_MQ_Envelope *env;
467 struct GNUNET_SERVICE_Client *client = cls; 487 struct GNUNET_SERVICE_Client *client = cls;
468 struct Ego *ego;
469 char *name; 488 char *name;
470 char *identifier; 489 char *identifier;
471 490
472
473 name = GNUNET_strdup ((const char *) &gdm[1]); 491 name = GNUNET_strdup ((const char *) &gdm[1]);
474 GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1], name); 492 GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1],
493 name);
475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
476 "Received GET_DEFAULT for service `%s' from client\n", 495 "Received GET_DEFAULT for service `%s' from client\n",
477 name); 496 name);
478 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, 497 if (GNUNET_OK !=
479 name, 498 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
480 "DEFAULT_IDENTIFIER", 499 name,
481 &identifier)) 500 "DEFAULT_IDENTIFIER",
501 &identifier))
482 { 502 {
483 send_result_code (client, 1, gettext_noop ("no default known")); 503 send_result_code (client, 1, gettext_noop ("no default known"));
484 GNUNET_SERVICE_client_continue (client); 504 GNUNET_SERVICE_client_continue (client);
485 GNUNET_free (name); 505 GNUNET_free (name);
486 return; 506 return;
487 } 507 }
488 for (ego = ego_head; NULL != ego; ego = ego->next) 508 for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
489 { 509 {
490 if (0 == strcmp (ego->identifier, identifier)) 510 if (0 == strcmp (ego->identifier, identifier))
491 { 511 {
@@ -498,7 +518,9 @@ handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm)
498 } 518 }
499 } 519 }
500 GNUNET_free (identifier); 520 GNUNET_free (identifier);
501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name); 521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
522 "Failed to find ego `%s'\n",
523 name);
502 GNUNET_free (name); 524 GNUNET_free (name);
503 send_result_code (client, 525 send_result_code (client,
504 1, 526 1,
@@ -531,7 +553,8 @@ key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1,
531 * @return #GNUNET_OK if @a msg is well-formed 553 * @return #GNUNET_OK if @a msg is well-formed
532 */ 554 */
533static int 555static int
534check_set_default_message (void *cls, const struct SetDefaultMessage *msg) 556check_set_default_message (void *cls,
557 const struct SetDefaultMessage *msg)
535{ 558{
536 uint16_t size; 559 uint16_t size;
537 uint16_t name_len; 560 uint16_t name_len;
@@ -569,7 +592,8 @@ check_set_default_message (void *cls, const struct SetDefaultMessage *msg)
569 * @param message the message received 592 * @param message the message received
570 */ 593 */
571static void 594static void
572handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm) 595handle_set_default_message (void *cls,
596 const struct SetDefaultMessage *sdm)
573{ 597{
574 struct Ego *ego; 598 struct Ego *ego;
575 struct GNUNET_SERVICE_Client *client = cls; 599 struct GNUNET_SERVICE_Client *client = cls;
@@ -642,7 +666,8 @@ notify_listeners (struct Ego *ego)
642 * @return #GNUNET_OK if @a msg is well-formed 666 * @return #GNUNET_OK if @a msg is well-formed
643 */ 667 */
644static int 668static int
645check_create_message (void *cls, const struct CreateRequestMessage *msg) 669check_create_message (void *cls,
670 const struct CreateRequestMessage *msg)
646{ 671{
647 uint16_t size; 672 uint16_t size;
648 uint16_t name_len; 673 uint16_t name_len;
@@ -680,7 +705,8 @@ check_create_message (void *cls, const struct CreateRequestMessage *msg)
680 * @param message the message received 705 * @param message the message received
681 */ 706 */
682static void 707static void
683handle_create_message (void *cls, const struct CreateRequestMessage *crm) 708handle_create_message (void *cls,
709 const struct CreateRequestMessage *crm)
684{ 710{
685 struct GNUNET_SERVICE_Client *client = cls; 711 struct GNUNET_SERVICE_Client *client = cls;
686 struct Ego *ego; 712 struct Ego *ego;
@@ -706,7 +732,9 @@ handle_create_message (void *cls, const struct CreateRequestMessage *crm)
706 ego = GNUNET_new (struct Ego); 732 ego = GNUNET_new (struct Ego);
707 ego->pk = crm->private_key; 733 ego->pk = crm->private_key;
708 ego->identifier = GNUNET_strdup (str); 734 ego->identifier = GNUNET_strdup (str);
709 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); 735 GNUNET_CONTAINER_DLL_insert (ego_head,
736 ego_tail,
737 ego);
710 send_result_code (client, 0, NULL); 738 send_result_code (client, 0, NULL);
711 fn = get_ego_filename (ego); 739 fn = get_ego_filename (ego);
712 (void) GNUNET_DISK_directory_create_for_file (fn); 740 (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
@@ -245,11 +245,22 @@ GNUNET_NETWORK_STRUCT_END
245struct GNUNET_IDENTITY_Ego 245struct GNUNET_IDENTITY_Ego
246{ 246{
247 /** 247 /**
248 * Hash of the private key of this ego.
249 */
250 struct GNUNET_HashCode id;
251
252 /**
248 * Private key associated with this ego. 253 * Private key associated with this ego.
249 */ 254 */
250 struct GNUNET_CRYPTO_EcdsaPrivateKey pk; 255 struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
251 256
252 /** 257 /**
258 * Public key associated with this ego. Initialized on demand.
259 * Always use #GNUNET_IDENTITY_ego_get_public_key() to obtain.
260 */
261 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
262
263 /**
253 * Current name associated with this ego. 264 * Current name associated with this ego.
254 */ 265 */
255 char *name; 266 char *name;
@@ -260,9 +271,9 @@ struct GNUNET_IDENTITY_Ego
260 void *ctx; 271 void *ctx;
261 272
262 /** 273 /**
263 * Hash of the public key of this ego. 274 * Set to true once @e pub was initialized
264 */ 275 */
265 struct GNUNET_HashCode id; 276 bool pub_initialized;
266}; 277};
267 278
268 279
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
105 struct GNUNET_MQ_Handle *mq; 105 struct GNUNET_MQ_Handle *mq;
106 106
107 /** 107 /**
108 * Hash map from the hash of the public key to the 108 * Hash map from the hash of the private key to the
109 * respective `GNUNET_IDENTITY_Ego` handle. 109 * respective `GNUNET_IDENTITY_Ego` handle.
110 */ 110 */
111 struct GNUNET_CONTAINER_MultiHashMap *egos; 111 struct GNUNET_CONTAINER_MultiHashMap *egos;
@@ -190,16 +190,22 @@ reconnect (void *cls);
190 * @return #GNUNET_OK (continue to iterate) 190 * @return #GNUNET_OK (continue to iterate)
191 */ 191 */
192static int 192static int
193free_ego (void *cls, const struct GNUNET_HashCode *key, void *value) 193free_ego (void *cls,
194 const struct GNUNET_HashCode *key,
195 void *value)
194{ 196{
195 struct GNUNET_IDENTITY_Handle *h = cls; 197 struct GNUNET_IDENTITY_Handle *h = cls;
196 struct GNUNET_IDENTITY_Ego *ego = value; 198 struct GNUNET_IDENTITY_Ego *ego = value;
197 199
198 if (NULL != h->cb) 200 if (NULL != h->cb)
199 h->cb (h->cb_cls, ego, &ego->ctx, NULL); 201 h->cb (h->cb_cls, ego,
202 &ego->ctx,
203 NULL);
200 GNUNET_free (ego->name); 204 GNUNET_free (ego->name);
201 GNUNET_assert (GNUNET_YES == 205 GNUNET_assert (GNUNET_YES ==
202 GNUNET_CONTAINER_multihashmap_remove (h->egos, key, value)); 206 GNUNET_CONTAINER_multihashmap_remove (h->egos,
207 key,
208 value));
203 GNUNET_free (ego); 209 GNUNET_free (ego);
204 return GNUNET_OK; 210 return GNUNET_OK;
205} 211}
@@ -224,9 +230,12 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h)
224 } 230 }
225 while (NULL != (op = h->op_head)) 231 while (NULL != (op = h->op_head))
226 { 232 {
227 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); 233 GNUNET_CONTAINER_DLL_remove (h->op_head,
234 h->op_tail,
235 op);
228 if (NULL != op->cont) 236 if (NULL != op->cont)
229 op->cont (op->cls, "Error in communication with the identity service"); 237 op->cont (op->cls,
238 "Error in communication with the identity service");
230 else if (NULL != op->cb) 239 else if (NULL != op->cb)
231 op->cb (op->cls, NULL, NULL, NULL); 240 op->cb (op->cls, NULL, NULL, NULL);
232 else if (NULL != op->create_cont) 241 else if (NULL != op->create_cont)
@@ -235,12 +244,17 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h)
235 "Failed to communicate with the identity service"); 244 "Failed to communicate with the identity service");
236 GNUNET_free (op); 245 GNUNET_free (op);
237 } 246 }
238 GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h); 247 GNUNET_CONTAINER_multihashmap_iterate (h->egos,
248 &free_ego,
249 h);
239 LOG (GNUNET_ERROR_TYPE_DEBUG, 250 LOG (GNUNET_ERROR_TYPE_DEBUG,
240 "Scheduling task to reconnect to identity service in %s.\n", 251 "Scheduling task to reconnect to identity service in %s.\n",
241 GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); 252 GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay,
253 GNUNET_YES));
242 h->reconnect_task = 254 h->reconnect_task =
243 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); 255 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
256 &reconnect,
257 h);
244 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); 258 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
245} 259}
246 260
@@ -254,7 +268,8 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h)
254 * @param error error code 268 * @param error error code
255 */ 269 */
256static void 270static void
257mq_error_handler (void *cls, enum GNUNET_MQ_Error error) 271mq_error_handler (void *cls,
272 enum GNUNET_MQ_Error error)
258{ 273{
259 struct GNUNET_IDENTITY_Handle *h = cls; 274 struct GNUNET_IDENTITY_Handle *h = cls;
260 275
@@ -271,7 +286,8 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
271 * @return #GNUNET_OK if the message is well-formed 286 * @return #GNUNET_OK if the message is well-formed
272 */ 287 */
273static int 288static int
274check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) 289check_identity_result_code (void *cls,
290 const struct ResultCodeMessage *rcm)
275{ 291{
276 if (sizeof(*rcm) != htons (rcm->header.size)) 292 if (sizeof(*rcm) != htons (rcm->header.size))
277 GNUNET_MQ_check_zero_termination (rcm); 293 GNUNET_MQ_check_zero_termination (rcm);
@@ -286,7 +302,8 @@ check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
286 * @param rcm result message received 302 * @param rcm result message received
287 */ 303 */
288static void 304static void
289handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) 305handle_identity_result_code (void *cls,
306 const struct ResultCodeMessage *rcm)
290{ 307{
291 struct GNUNET_IDENTITY_Handle *h = cls; 308 struct GNUNET_IDENTITY_Handle *h = cls;
292 struct GNUNET_IDENTITY_Operation *op; 309 struct GNUNET_IDENTITY_Operation *op;
@@ -319,7 +336,8 @@ handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
319 * @return #GNUNET_OK if the message is well-formed 336 * @return #GNUNET_OK if the message is well-formed
320 */ 337 */
321static int 338static int
322check_identity_update (void *cls, const struct UpdateMessage *um) 339check_identity_update (void *cls,
340 const struct UpdateMessage *um)
323{ 341{
324 uint16_t size = ntohs (um->header.size); 342 uint16_t size = ntohs (um->header.size);
325 uint16_t name_len = ntohs (um->name_len); 343 uint16_t name_len = ntohs (um->name_len);
@@ -342,12 +360,12 @@ check_identity_update (void *cls, const struct UpdateMessage *um)
342 * @param um message received 360 * @param um message received
343 */ 361 */
344static void 362static void
345handle_identity_update (void *cls, const struct UpdateMessage *um) 363handle_identity_update (void *cls,
364 const struct UpdateMessage *um)
346{ 365{
347 struct GNUNET_IDENTITY_Handle *h = cls; 366 struct GNUNET_IDENTITY_Handle *h = cls;
348 uint16_t name_len = ntohs (um->name_len); 367 uint16_t name_len = ntohs (um->name_len);
349 const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; 368 const char *str = (0 == name_len) ? NULL : (const char *) &um[1];
350 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
351 struct GNUNET_HashCode id; 369 struct GNUNET_HashCode id;
352 struct GNUNET_IDENTITY_Ego *ego; 370 struct GNUNET_IDENTITY_Ego *ego;
353 371
@@ -358,9 +376,11 @@ handle_identity_update (void *cls, const struct UpdateMessage *um)
358 h->cb (h->cb_cls, NULL, NULL, NULL); 376 h->cb (h->cb_cls, NULL, NULL, NULL);
359 return; 377 return;
360 } 378 }
361 GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub); 379 GNUNET_CRYPTO_hash (&um->private_key,
362 GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id); 380 sizeof (um->private_key),
363 ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id); 381 &id);
382 ego = GNUNET_CONTAINER_multihashmap_get (h->egos,
383 &id);
364 if (NULL == ego) 384 if (NULL == ego)
365 { 385 {
366 /* ego was created */ 386 /* ego was created */
@@ -385,9 +405,10 @@ handle_identity_update (void *cls, const struct UpdateMessage *um)
385 if (NULL == str) 405 if (NULL == str)
386 { 406 {
387 /* ego was deleted */ 407 /* ego was deleted */
388 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (h->egos, 408 GNUNET_assert (GNUNET_YES ==
389 &ego->id, 409 GNUNET_CONTAINER_multihashmap_remove (h->egos,
390 ego)); 410 &ego->id,
411 ego));
391 } 412 }
392 else 413 else
393 { 414 {
@@ -397,7 +418,10 @@ handle_identity_update (void *cls, const struct UpdateMessage *um)
397 } 418 }
398 /* inform application about change */ 419 /* inform application about change */
399 if (NULL != h->cb) 420 if (NULL != h->cb)
400 h->cb (h->cb_cls, ego, &ego->ctx, str); 421 h->cb (h->cb_cls,
422 ego,
423 &ego->ctx,
424 str);
401 /* complete deletion */ 425 /* complete deletion */
402 if (NULL == str) 426 if (NULL == str)
403 { 427 {
@@ -416,7 +440,8 @@ handle_identity_update (void *cls, const struct UpdateMessage *um)
416 * @return #GNUNET_OK if the message is well-formed 440 * @return #GNUNET_OK if the message is well-formed
417 */ 441 */
418static int 442static int
419check_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) 443check_identity_set_default (void *cls,
444 const struct SetDefaultMessage *sdm)
420{ 445{
421 uint16_t size = ntohs (sdm->header.size) - sizeof(*sdm); 446 uint16_t size = ntohs (sdm->header.size) - sizeof(*sdm);
422 uint16_t name_len = ntohs (sdm->name_len); 447 uint16_t name_len = ntohs (sdm->name_len);
@@ -440,17 +465,19 @@ check_identity_set_default (void *cls, const struct SetDefaultMessage *sdm)
440 * @param sdm message received 465 * @param sdm message received
441 */ 466 */
442static void 467static void
443handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) 468handle_identity_set_default (void *cls,
469 const struct SetDefaultMessage *sdm)
444{ 470{
445 struct GNUNET_IDENTITY_Handle *h = cls; 471 struct GNUNET_IDENTITY_Handle *h = cls;
446 struct GNUNET_IDENTITY_Operation *op; 472 struct GNUNET_IDENTITY_Operation *op;
447 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
448 struct GNUNET_HashCode id; 473 struct GNUNET_HashCode id;
449 struct GNUNET_IDENTITY_Ego *ego; 474 struct GNUNET_IDENTITY_Ego *ego;
450 475
451 GNUNET_CRYPTO_ecdsa_key_get_public (&sdm->private_key, &pub); 476 GNUNET_CRYPTO_hash (&sdm->private_key,
452 GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id); 477 sizeof(sdm->private_key),
453 ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id); 478 &id);
479 ego = GNUNET_CONTAINER_multihashmap_get (h->egos,
480 &id);
454 if (NULL == ego) 481 if (NULL == ego)
455 { 482 {
456 GNUNET_break (0); 483 GNUNET_break (0);
@@ -466,9 +493,14 @@ handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm)
466 } 493 }
467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
468 "Received SET_DEFAULT message from identity service\n"); 495 "Received SET_DEFAULT message from identity service\n");
469 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); 496 GNUNET_CONTAINER_DLL_remove (h->op_head,
497 h->op_tail,
498 op);
470 if (NULL != op->cb) 499 if (NULL != op->cb)
471 op->cb (op->cls, ego, &ego->ctx, ego->name); 500 op->cb (op->cls,
501 ego,
502 &ego->ctx,
503 ego->name);
472 GNUNET_free (op); 504 GNUNET_free (op);
473} 505}
474 506
@@ -482,8 +514,8 @@ static void
482reconnect (void *cls) 514reconnect (void *cls)
483{ 515{
484 struct GNUNET_IDENTITY_Handle *h = cls; 516 struct GNUNET_IDENTITY_Handle *h = cls;
485 struct GNUNET_MQ_MessageHandler handlers[] = 517 struct GNUNET_MQ_MessageHandler handlers[] = {
486 { GNUNET_MQ_hd_var_size (identity_result_code, 518 GNUNET_MQ_hd_var_size (identity_result_code,
487 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, 519 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE,
488 struct ResultCodeMessage, 520 struct ResultCodeMessage,
489 h), 521 h),
@@ -495,21 +527,28 @@ reconnect (void *cls)
495 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, 527 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
496 struct SetDefaultMessage, 528 struct SetDefaultMessage,
497 h), 529 h),
498 GNUNET_MQ_handler_end () }; 530 GNUNET_MQ_handler_end ()
531 };
499 struct GNUNET_MQ_Envelope *env; 532 struct GNUNET_MQ_Envelope *env;
500 struct GNUNET_MessageHeader *msg; 533 struct GNUNET_MessageHeader *msg;
501 534
502 h->reconnect_task = NULL; 535 h->reconnect_task = NULL;
503 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to identity service.\n"); 536 LOG (GNUNET_ERROR_TYPE_DEBUG,
537 "Connecting to identity service.\n");
504 GNUNET_assert (NULL == h->mq); 538 GNUNET_assert (NULL == h->mq);
505 h->mq = 539 h->mq = GNUNET_CLIENT_connect (h->cfg,
506 GNUNET_CLIENT_connect (h->cfg, "identity", handlers, &mq_error_handler, h); 540 "identity",
541 handlers,
542 &mq_error_handler,
543 h);
507 if (NULL == h->mq) 544 if (NULL == h->mq)
508 return; 545 return;
509 if (NULL != h->cb) 546 if (NULL != h->cb)
510 { 547 {
511 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_IDENTITY_START); 548 env = GNUNET_MQ_msg (msg,
512 GNUNET_MQ_send (h->mq, env); 549 GNUNET_MESSAGE_TYPE_IDENTITY_START);
550 GNUNET_MQ_send (h->mq,
551 env);
513 } 552 }
514} 553}
515 554
@@ -533,7 +572,8 @@ GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
533 h->cfg = cfg; 572 h->cfg = cfg;
534 h->cb = cb; 573 h->cb = cb;
535 h->cb_cls = cb_cls; 574 h->cb_cls = cb_cls;
536 h->egos = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES); 575 h->egos = GNUNET_CONTAINER_multihashmap_create (16,
576 GNUNET_YES);
537 reconnect (h); 577 reconnect (h);
538 if (NULL == h->mq) 578 if (NULL == h->mq)
539 { 579 {
@@ -564,11 +604,16 @@ GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego)
564 * @param pk set to ego's public key 604 * @param pk set to ego's public key
565 */ 605 */
566void 606void
567GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, 607GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego,
568 struct GNUNET_CRYPTO_EcdsaPublicKey *pk) 608 struct GNUNET_CRYPTO_EcdsaPublicKey *pk)
569{ 609{
570 GNUNET_CRYPTO_ecdsa_key_get_public (&ego->pk, 610 if (! ego->pub_initialized)
571 pk); 611 {
612 GNUNET_CRYPTO_ecdsa_key_get_public (&ego->pk,
613 &ego->pub);
614 ego->pub_initialized = true;
615 }
616 *pk = ego->pub;
572} 617}
573 618
574 619
@@ -842,7 +887,9 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h)
842 } 887 }
843 if (NULL != h->egos) 888 if (NULL != h->egos)
844 { 889 {
845 GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h); 890 GNUNET_CONTAINER_multihashmap_iterate (h->egos,
891 &free_ego,
892 h);
846 GNUNET_CONTAINER_multihashmap_destroy (h->egos); 893 GNUNET_CONTAINER_multihashmap_destroy (h->egos);
847 h->egos = NULL; 894 h->egos = NULL;
848 } 895 }
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);
99 * @param pk set to ego's public key 99 * @param pk set to ego's public key
100 */ 100 */
101void 101void
102GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, 102GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego,
103 struct GNUNET_CRYPTO_EcdsaPublicKey *pk); 103 struct GNUNET_CRYPTO_EcdsaPublicKey *pk);
104 104
105 105