diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-05-25 15:54:02 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-05-25 15:54:02 +0000 |
commit | 1957f1e22f6b9a1d9e289812cada03afa3fff747 (patch) | |
tree | d9257840ca8379c63aa28f0ef9f5588b136bcf6c /src/core | |
parent | 2779e988e669631cb977f41ee06da682aa4b7fbf (diff) | |
download | gnunet-1957f1e22f6b9a1d9e289812cada03afa3fff747.tar.gz gnunet-1957f1e22f6b9a1d9e289812cada03afa3fff747.zip |
send SET_KEY and PING message together to transport, nicer handling of SET_KEY duplication
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/gnunet-service-core.c | 132 |
1 files changed, 81 insertions, 51 deletions
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 86f664ced..bb7a506cb 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -362,6 +362,17 @@ struct MessageEntry | |||
362 | unsigned int priority; | 362 | unsigned int priority; |
363 | 363 | ||
364 | /** | 364 | /** |
365 | * If this is a SET_KEY message, what was our connection status when this | ||
366 | * message was queued? | ||
367 | */ | ||
368 | enum PeerStateMachine sender_status; | ||
369 | |||
370 | /** | ||
371 | * Is this a SET_KEY message? | ||
372 | */ | ||
373 | int is_setkey; | ||
374 | |||
375 | /** | ||
365 | * How long is the message? (number of bytes following | 376 | * How long is the message? (number of bytes following |
366 | * the "struct MessageEntry", but not including the | 377 | * the "struct MessageEntry", but not including the |
367 | * size of "struct MessageEntry" itself!) | 378 | * size of "struct MessageEntry" itself!) |
@@ -381,11 +392,6 @@ struct MessageEntry | |||
381 | */ | 392 | */ |
382 | int8_t got_slack; | 393 | int8_t got_slack; |
383 | 394 | ||
384 | /** | ||
385 | * Is this a SETKEY message? | ||
386 | */ | ||
387 | int is_setkey; | ||
388 | |||
389 | }; | 395 | }; |
390 | 396 | ||
391 | 397 | ||
@@ -2276,7 +2282,15 @@ notify_transport_connect_done (void *cls, size_t size, void *buf) | |||
2276 | GNUNET_i2s (&n->peer)); | 2282 | GNUNET_i2s (&n->peer)); |
2277 | return 0; | 2283 | return 0; |
2278 | } | 2284 | } |
2279 | send_key (n); | 2285 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2286 | _("TRANSPORT connection to peer `%4s' is up, trying to establish CORE connection\n"), | ||
2287 | GNUNET_i2s (&n->peer)); | ||
2288 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) | ||
2289 | GNUNET_SCHEDULER_cancel (sched, | ||
2290 | n->retry_set_key_task); | ||
2291 | n->retry_set_key_task = GNUNET_SCHEDULER_add_now (sched, | ||
2292 | &set_key_retry_task, | ||
2293 | n); | ||
2280 | return 0; | 2294 | return 0; |
2281 | } | 2295 | } |
2282 | 2296 | ||
@@ -2383,13 +2397,16 @@ process_hello_retry_send_key (void *cls, | |||
2383 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; | 2397 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; |
2384 | } | 2398 | } |
2385 | GNUNET_STATISTICS_update (stats, | 2399 | GNUNET_STATISTICS_update (stats, |
2386 | gettext_noop ("# SETKEY messages deferred (need public key)"), | 2400 | gettext_noop ("# SET_KEY messages deferred (need public key)"), |
2387 | -1, | 2401 | -1, |
2388 | GNUNET_NO); | 2402 | GNUNET_NO); |
2389 | send_key (n); | 2403 | send_key (n); |
2390 | } | 2404 | } |
2391 | else | 2405 | else |
2392 | { | 2406 | { |
2407 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2408 | _("Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n"), | ||
2409 | GNUNET_i2s (&n->peer)); | ||
2393 | GNUNET_STATISTICS_update (stats, | 2410 | GNUNET_STATISTICS_update (stats, |
2394 | gettext_noop ("# Delayed connecting due to lack of public key"), | 2411 | gettext_noop ("# Delayed connecting due to lack of public key"), |
2395 | 1, | 2412 | 1, |
@@ -2479,7 +2496,7 @@ send_key (struct Neighbour *n) | |||
2479 | if (NULL == n->th) | 2496 | if (NULL == n->th) |
2480 | { | 2497 | { |
2481 | GNUNET_STATISTICS_update (stats, | 2498 | GNUNET_STATISTICS_update (stats, |
2482 | gettext_noop ("# Asking transport to connect (for SETKEY)"), | 2499 | gettext_noop ("# Asking transport to connect (for SET_KEY)"), |
2483 | 1, | 2500 | 1, |
2484 | GNUNET_NO); | 2501 | GNUNET_NO); |
2485 | n->th = GNUNET_TRANSPORT_notify_transmit_ready (transport, | 2502 | n->th = GNUNET_TRANSPORT_notify_transmit_ready (transport, |
@@ -2518,24 +2535,59 @@ send_key (struct Neighbour *n) | |||
2518 | { | 2535 | { |
2519 | if (GNUNET_YES == pos->is_setkey) | 2536 | if (GNUNET_YES == pos->is_setkey) |
2520 | { | 2537 | { |
2538 | if (pos->sender_status == n->status) | ||
2539 | { | ||
2540 | #if DEBUG_CORE | ||
2541 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2542 | "`%s' message for `%4s' queued already\n", | ||
2543 | "SET_KEY", | ||
2544 | GNUNET_i2s (&n->peer)); | ||
2545 | #endif | ||
2546 | goto trigger_processing; | ||
2547 | } | ||
2548 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, | ||
2549 | n->encrypted_tail, | ||
2550 | pos); | ||
2551 | GNUNET_free (pos); | ||
2521 | #if DEBUG_CORE | 2552 | #if DEBUG_CORE |
2522 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2553 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2523 | "%s message for `%s' already in the queue, not adding another one\n", | 2554 | "Removing queued `%s' message for `%4s', will create a new one\n", |
2524 | "SETKEY", | 2555 | "SET_KEY", |
2525 | GNUNET_i2s (&n->peer)); | 2556 | GNUNET_i2s (&n->peer)); |
2526 | #endif | 2557 | #endif |
2527 | return; | 2558 | break; |
2528 | } | 2559 | } |
2529 | pos = pos->next; | 2560 | pos = pos->next; |
2530 | } | 2561 | } |
2531 | 2562 | ||
2563 | /* update status */ | ||
2564 | switch (n->status) | ||
2565 | { | ||
2566 | case PEER_STATE_DOWN: | ||
2567 | n->status = PEER_STATE_KEY_SENT; | ||
2568 | break; | ||
2569 | case PEER_STATE_KEY_SENT: | ||
2570 | break; | ||
2571 | case PEER_STATE_KEY_RECEIVED: | ||
2572 | break; | ||
2573 | case PEER_STATE_KEY_CONFIRMED: | ||
2574 | break; | ||
2575 | default: | ||
2576 | GNUNET_break (0); | ||
2577 | break; | ||
2578 | } | ||
2579 | |||
2580 | |||
2532 | /* first, set key message */ | 2581 | /* first, set key message */ |
2533 | me = GNUNET_malloc (sizeof (struct MessageEntry) + | 2582 | me = GNUNET_malloc (sizeof (struct MessageEntry) + |
2534 | sizeof (struct SetKeyMessage)); | 2583 | sizeof (struct SetKeyMessage) + |
2584 | sizeof (struct PingMessage)); | ||
2535 | me->deadline = GNUNET_TIME_relative_to_absolute (MAX_SET_KEY_DELAY); | 2585 | me->deadline = GNUNET_TIME_relative_to_absolute (MAX_SET_KEY_DELAY); |
2536 | me->priority = SET_KEY_PRIORITY; | 2586 | me->priority = SET_KEY_PRIORITY; |
2537 | me->size = sizeof (struct SetKeyMessage); | 2587 | me->size = sizeof (struct SetKeyMessage) + sizeof (struct PingMessage); |
2538 | me->is_setkey = GNUNET_YES; | 2588 | me->is_setkey = GNUNET_YES; |
2589 | me->got_slack = GNUNET_YES; /* do not defer this one! */ | ||
2590 | me->sender_status = n->status; | ||
2539 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, | 2591 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, |
2540 | n->encrypted_tail, | 2592 | n->encrypted_tail, |
2541 | n->encrypted_tail, | 2593 | n->encrypted_tail, |
@@ -2561,19 +2613,8 @@ send_key (struct Neighbour *n) | |||
2561 | &sm->encrypted_key)); | 2613 | &sm->encrypted_key)); |
2562 | GNUNET_assert (GNUNET_OK == | 2614 | GNUNET_assert (GNUNET_OK == |
2563 | GNUNET_CRYPTO_rsa_sign (my_private_key, &sm->purpose, | 2615 | GNUNET_CRYPTO_rsa_sign (my_private_key, &sm->purpose, |
2564 | &sm->signature)); | 2616 | &sm->signature)); |
2565 | 2617 | pm = (struct PingMessage *) &sm[1]; | |
2566 | /* second, encrypted PING message */ | ||
2567 | me = GNUNET_malloc (sizeof (struct MessageEntry) + | ||
2568 | sizeof (struct PingMessage)); | ||
2569 | me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PING_DELAY); | ||
2570 | me->priority = PING_PRIORITY; | ||
2571 | me->size = sizeof (struct PingMessage); | ||
2572 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, | ||
2573 | n->encrypted_tail, | ||
2574 | n->encrypted_tail, | ||
2575 | me); | ||
2576 | pm = (struct PingMessage *) &me[1]; | ||
2577 | pm->header.size = htons (sizeof (struct PingMessage)); | 2618 | pm->header.size = htons (sizeof (struct PingMessage)); |
2578 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); | 2619 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); |
2579 | pp.challenge = htonl (n->ping_challenge); | 2620 | pp.challenge = htonl (n->ping_challenge); |
@@ -2592,24 +2633,8 @@ send_key (struct Neighbour *n) | |||
2592 | &pm->challenge, | 2633 | &pm->challenge, |
2593 | sizeof (struct PingMessage) - | 2634 | sizeof (struct PingMessage) - |
2594 | sizeof (struct GNUNET_MessageHeader)); | 2635 | sizeof (struct GNUNET_MessageHeader)); |
2595 | /* update status */ | ||
2596 | switch (n->status) | ||
2597 | { | ||
2598 | case PEER_STATE_DOWN: | ||
2599 | n->status = PEER_STATE_KEY_SENT; | ||
2600 | break; | ||
2601 | case PEER_STATE_KEY_SENT: | ||
2602 | break; | ||
2603 | case PEER_STATE_KEY_RECEIVED: | ||
2604 | break; | ||
2605 | case PEER_STATE_KEY_CONFIRMED: | ||
2606 | break; | ||
2607 | default: | ||
2608 | GNUNET_break (0); | ||
2609 | break; | ||
2610 | } | ||
2611 | GNUNET_STATISTICS_update (stats, | 2636 | GNUNET_STATISTICS_update (stats, |
2612 | gettext_noop ("# SETKEY and PING messages created"), | 2637 | gettext_noop ("# SET_KEY and PING messages created"), |
2613 | 1, | 2638 | 1, |
2614 | GNUNET_NO); | 2639 | GNUNET_NO); |
2615 | #if DEBUG_CORE | 2640 | #if DEBUG_CORE |
@@ -2618,6 +2643,7 @@ send_key (struct Neighbour *n) | |||
2618 | (unsigned long long) GNUNET_TIME_absolute_get_remaining (me->deadline).value, | 2643 | (unsigned long long) GNUNET_TIME_absolute_get_remaining (me->deadline).value, |
2619 | "SET_KEY"); | 2644 | "SET_KEY"); |
2620 | #endif | 2645 | #endif |
2646 | trigger_processing: | ||
2621 | /* trigger queue processing */ | 2647 | /* trigger queue processing */ |
2622 | process_encrypted_neighbour_queue (n); | 2648 | process_encrypted_neighbour_queue (n); |
2623 | if ( (n->status != PEER_STATE_KEY_CONFIRMED) && | 2649 | if ( (n->status != PEER_STATE_KEY_CONFIRMED) && |
@@ -2677,11 +2703,10 @@ process_hello_retry_handle_set_key (void *cls, | |||
2677 | } | 2703 | } |
2678 | else | 2704 | else |
2679 | { | 2705 | { |
2680 | #if DEBUG_CORE | 2706 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2707 | _("Ignoring `%s' message due to lack of public key for peer `%4s' (failed to obtain one).\n"), |
2682 | "Ignoring `%s' message due to lack of public key for peer (failed to obtain one).\n", | 2708 | "SET_KEY", |
2683 | "SET_KEY"); | 2709 | GNUNET_i2s (&n->peer)); |
2684 | #endif | ||
2685 | } | 2710 | } |
2686 | GNUNET_free (sm); | 2711 | GNUNET_free (sm); |
2687 | return; | 2712 | return; |
@@ -2962,7 +2987,7 @@ handle_set_key (struct Neighbour *n, const struct SetKeyMessage *m) | |||
2962 | GNUNET_TIME_UNIT_MINUTES, | 2987 | GNUNET_TIME_UNIT_MINUTES, |
2963 | &process_hello_retry_handle_set_key, n); | 2988 | &process_hello_retry_handle_set_key, n); |
2964 | GNUNET_STATISTICS_update (stats, | 2989 | GNUNET_STATISTICS_update (stats, |
2965 | gettext_noop ("# SETKEY messages deferred (need public key)"), | 2990 | gettext_noop ("# SET_KEY messages deferred (need public key)"), |
2966 | 1, | 2991 | 1, |
2967 | GNUNET_NO); | 2992 | GNUNET_NO); |
2968 | return; | 2993 | return; |
@@ -3017,7 +3042,7 @@ handle_set_key (struct Neighbour *n, const struct SetKeyMessage *m) | |||
3017 | return; | 3042 | return; |
3018 | } | 3043 | } |
3019 | GNUNET_STATISTICS_update (stats, | 3044 | GNUNET_STATISTICS_update (stats, |
3020 | gettext_noop ("# SETKEY messages decrypted"), | 3045 | gettext_noop ("# SET_KEY messages decrypted"), |
3021 | 1, | 3046 | 1, |
3022 | GNUNET_NO); | 3047 | GNUNET_NO); |
3023 | n->decrypt_key = k; | 3048 | n->decrypt_key = k; |
@@ -3574,7 +3599,12 @@ neighbour_quota_update (void *cls, | |||
3574 | unsigned long long distributable; | 3599 | unsigned long long distributable; |
3575 | uint64_t need_per_peer; | 3600 | uint64_t need_per_peer; |
3576 | uint64_t need_per_second; | 3601 | uint64_t need_per_second; |
3577 | 3602 | ||
3603 | #if DEBUG_CORE | ||
3604 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3605 | "Neighbour quota update calculation running for peer `%4s'\n" | ||
3606 | GNUNET_i2s (&n->peer)); | ||
3607 | #endif | ||
3578 | n->quota_update_task = GNUNET_SCHEDULER_NO_TASK; | 3608 | n->quota_update_task = GNUNET_SCHEDULER_NO_TASK; |
3579 | /* calculate relative preference among all neighbours; | 3609 | /* calculate relative preference among all neighbours; |
3580 | divides by a bit more to avoid division by zero AND to | 3610 | divides by a bit more to avoid division by zero AND to |