diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-05-02 00:08:38 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-05-02 00:08:38 +0200 |
commit | f38bc10411d68d2246919d57d043ee8bf0ca804a (patch) | |
tree | d28ac8f609fe78dc0bb1ffdcc81e417198dc5c00 /src/identity/identity_api.c | |
parent | d3ec11c5a2dc7521efbd308e273dccc26c0e4bb4 (diff) | |
download | gnunet-f38bc10411d68d2246919d57d043ee8bf0ca804a.tar.gz gnunet-f38bc10411d68d2246919d57d043ee8bf0ca804a.zip |
fix gnunet-identity performance
Diffstat (limited to 'src/identity/identity_api.c')
-rw-r--r-- | src/identity/identity_api.c | 133 |
1 files changed, 90 insertions, 43 deletions
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 | */ |
192 | static int | 192 | static int |
193 | free_ego (void *cls, const struct GNUNET_HashCode *key, void *value) | 193 | free_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 | */ |
256 | static void | 270 | static void |
257 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 271 | mq_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 | */ |
273 | static int | 288 | static int |
274 | check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | 289 | check_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 | */ |
288 | static void | 304 | static void |
289 | handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | 305 | handle_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 | */ |
321 | static int | 338 | static int |
322 | check_identity_update (void *cls, const struct UpdateMessage *um) | 339 | check_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 | */ |
344 | static void | 362 | static void |
345 | handle_identity_update (void *cls, const struct UpdateMessage *um) | 363 | handle_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 | */ |
418 | static int | 442 | static int |
419 | check_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) | 443 | check_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 | */ |
442 | static void | 467 | static void |
443 | handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) | 468 | handle_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 | |||
482 | reconnect (void *cls) | 514 | reconnect (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 | */ |
566 | void | 606 | void |
567 | GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, | 607 | GNUNET_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 | } |