aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_validation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-05 14:27:52 +0000
committerChristian Grothoff <christian@grothoff.org>2015-01-05 14:27:52 +0000
commit1859c7baeba4dc594a79da78a40f93f5aff4a236 (patch)
tree579e0b9f5c24ea25ce040d80011759c0eb41dc23 /src/transport/gnunet-service-transport_validation.c
parent4b46e4a593dfe2738d087f3cb18535053af773b5 (diff)
downloadgnunet-1859c7baeba4dc594a79da78a40f93f5aff4a236.tar.gz
gnunet-1859c7baeba4dc594a79da78a40f93f5aff4a236.zip
-stylistic fixes, also, only block re-validation for 2s IF we actually did send a PING, not if we didn't find the plugin
Diffstat (limited to 'src/transport/gnunet-service-transport_validation.c')
-rw-r--r--src/transport/gnunet-service-transport_validation.c73
1 files changed, 48 insertions, 25 deletions
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index a6a591c84..a15d7a094 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -206,12 +206,12 @@ struct ValidationEntry
206 /** 206 /**
207 * ID of task that will clean up this entry if nothing happens. 207 * ID of task that will clean up this entry if nothing happens.
208 */ 208 */
209 struct GNUNET_SCHEDULER_Task * timeout_task; 209 struct GNUNET_SCHEDULER_Task *timeout_task;
210 210
211 /** 211 /**
212 * ID of task that will trigger address revalidation. 212 * ID of task that will trigger address revalidation.
213 */ 213 */
214 struct GNUNET_SCHEDULER_Task * revalidation_task; 214 struct GNUNET_SCHEDULER_Task *revalidation_task;
215 215
216 /** 216 /**
217 * At what time did we send the latest validation request (PING)? 217 * At what time did we send the latest validation request (PING)?
@@ -426,7 +426,7 @@ cleanup_validation_entry (void *cls,
426{ 426{
427 struct ValidationEntry *ve = value; 427 struct ValidationEntry *ve = value;
428 428
429 ve->next_validation = GNUNET_TIME_absolute_get_zero_(); 429 ve->next_validation = GNUNET_TIME_UNIT_ZERO_ABS;
430 ve->valid_until = GNUNET_TIME_UNIT_ZERO_ABS; 430 ve->valid_until = GNUNET_TIME_UNIT_ZERO_ABS;
431 431
432 /* Notify about deleted entry */ 432 /* Notify about deleted entry */
@@ -451,13 +451,17 @@ cleanup_validation_entry (void *cls,
451 GNUNET_SCHEDULER_cancel (ve->revalidation_task); 451 GNUNET_SCHEDULER_cancel (ve->revalidation_task);
452 ve->revalidation_task = NULL; 452 ve->revalidation_task = NULL;
453 } 453 }
454 if ((GNUNET_YES == ve->expecting_pong) && 454 if ( (GNUNET_YES == ve->expecting_pong) &&
455 (validations_running > 0)) 455 (validations_running > 0) )
456 { 456 {
457 validations_running --; 457 validations_running --;
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 458 GNUNET_STATISTICS_set (GST_stats,
459 "Validation finished, %u validation processes running\n", 459 gettext_noop ("# validations running"),
460 validations_running); 460 validations_running,
461 GNUNET_NO);
462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
463 "Validation finished, %u validation processes running\n",
464 validations_running);
461 } 465 }
462 GNUNET_free (ve); 466 GNUNET_free (ve);
463 return GNUNET_OK; 467 return GNUNET_OK;
@@ -537,11 +541,6 @@ transmit_ping_if_allowed (void *cls,
537 GST_plugins_a2s (ve->address), 541 GST_plugins_a2s (ve->address),
538 ve->address->transport_name); 542 ve->address->transport_name);
539 543
540 next = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
541 validation_delay);
542 if (next.abs_value_us > validation_next.abs_value_us)
543 validation_next = next; /* We're going to send a PING so delay next validation */
544
545 slen = strlen (ve->address->transport_name) + 1; 544 slen = strlen (ve->address->transport_name) + 1;
546 hello = GST_hello_get (); 545 hello = GST_hello_get ();
547 hsize = ntohs (hello->size); 546 hsize = ntohs (hello->size);
@@ -559,8 +558,7 @@ transmit_ping_if_allowed (void *cls,
559 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 558 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
560 { 559 {
561 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 560 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
562 _ 561 _("Not transmitting `%s' with `%s', message too big (%u bytes!). This should not happen.\n"),
563 ("Not transmitting `%s' with `%s', message too big (%u bytes!). This should not happen.\n"),
564 "HELLO", "PING", (unsigned int) tsize); 562 "HELLO", "PING", (unsigned int) tsize);
565 /* message too big (!?), get rid of HELLO */ 563 /* message too big (!?), get rid of HELLO */
566 hsize = 0; 564 hsize = 0;
@@ -580,15 +578,21 @@ transmit_ping_if_allowed (void *cls,
580 memcpy (&message_buf[sizeof (struct TransportPingMessage) + slen + hsize], 578 memcpy (&message_buf[sizeof (struct TransportPingMessage) + slen + hsize],
581 ve->address->address, ve->address->address_length); 579 ve->address->address, ve->address->address_length);
582 papi = GST_plugins_find (ve->address->transport_name); 580 papi = GST_plugins_find (ve->address->transport_name);
583 if (papi == NULL) 581 if (NULL == papi)
582 {
584 ret = -1; 583 ret = -1;
584 GNUNET_STATISTICS_update (GST_stats,
585 gettext_noop ("# validations not attempted (no plugin)"),
586 1,
587 GNUNET_NO);
588 }
585 else 589 else
586 { 590 {
587 GNUNET_assert (NULL != papi->send); 591 GNUNET_assert (NULL != papi->send);
588 GNUNET_assert (NULL != papi->get_session); 592 GNUNET_assert (NULL != papi->get_session);
589 struct Session * session = papi->get_session(papi->cls, ve->address); 593 struct Session * session = papi->get_session(papi->cls, ve->address);
590 594
591 if (session != NULL) 595 if (NULL != session)
592 { 596 {
593 ret = papi->send (papi->cls, session, 597 ret = papi->send (papi->cls, session,
594 message_buf, tsize, 598 message_buf, tsize,
@@ -618,18 +622,24 @@ transmit_ping_if_allowed (void *cls,
618 } 622 }
619 if (-1 != ret) 623 if (-1 != ret)
620 { 624 {
625 next = GNUNET_TIME_relative_to_absolute (validation_delay);
626 validation_next = GNUNET_MAX (next,
627 validation_next);
621 ve->send_time = GNUNET_TIME_absolute_get (); 628 ve->send_time = GNUNET_TIME_absolute_get ();
622 GNUNET_STATISTICS_update (GST_stats, 629 GNUNET_STATISTICS_update (GST_stats,
623 gettext_noop 630 gettext_noop ("# PING for validation (without HELLO) sent"),
624 ("# PING without HELLO messages sent"), 1, 631 1,
625 GNUNET_NO); 632 GNUNET_NO);
626
627 ve->network = network; 633 ve->network = network;
628 ve->expecting_pong = GNUNET_YES; 634 ve->expecting_pong = GNUNET_YES;
629 validations_running++; 635 validations_running++;
630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 636 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
631 "Validation started, %u validation processes running\n", 637 "Validation started, %u validation processes running\n",
632 validations_running); 638 validations_running);
639 GNUNET_STATISTICS_set (GST_stats,
640 gettext_noop ("# validations running"),
641 validations_running,
642 GNUNET_NO);
633 /* Notify about PING sent */ 643 /* Notify about PING sent */
634 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE); 644 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE);
635 } 645 }
@@ -678,8 +688,9 @@ revalidate_address (void *cls,
678 GNUNET_YES), 688 GNUNET_YES),
679 GST_plugins_a2s (ve->address)); 689 GST_plugins_a2s (ve->address));
680 ve->revalidation_task = 690 ve->revalidation_task =
681 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve); 691 GNUNET_SCHEDULER_add_delayed (delay,
682 ve->next_validation = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay); 692 &revalidate_address, ve);
693 ve->next_validation = GNUNET_TIME_relative_to_absolute (delay);
683 return; 694 return;
684 } 695 }
685 blocked_for = GNUNET_TIME_absolute_get_remaining(validation_next); 696 blocked_for = GNUNET_TIME_absolute_get_remaining(validation_next);
@@ -694,7 +705,7 @@ revalidate_address (void *cls,
694 GST_plugins_a2s (ve->address)); 705 GST_plugins_a2s (ve->address));
695 ve->revalidation_task = 706 ve->revalidation_task =
696 GNUNET_SCHEDULER_add_delayed (blocked_for, &revalidate_address, ve); 707 GNUNET_SCHEDULER_add_delayed (blocked_for, &revalidate_address, ve);
697 ve->next_validation = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), blocked_for); 708 ve->next_validation = GNUNET_TIME_relative_to_absolute (blocked_for);
698 return; 709 return;
699 } 710 }
700 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay); 711 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay);
@@ -715,7 +726,7 @@ revalidate_address (void *cls,
715 GST_plugins_a2s (ve->address)); 726 GST_plugins_a2s (ve->address));
716 ve->revalidation_task = 727 ve->revalidation_task =
717 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve); 728 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
718 ve->next_validation = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay); 729 ve->next_validation = GNUNET_TIME_relative_to_absolute (delay);
719 730
720 /* start PINGing by checking blacklist */ 731 /* start PINGing by checking blacklist */
721 GNUNET_STATISTICS_update (GST_stats, 732 GNUNET_STATISTICS_update (GST_stats,
@@ -884,6 +895,10 @@ GST_validation_start (unsigned int max_fds)
884 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2); 895 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2);
885 validations_fast_start_threshold = (max_fds / 2); 896 validations_fast_start_threshold = (max_fds / 2);
886 validations_running = 0; 897 validations_running = 0;
898 GNUNET_STATISTICS_set (GST_stats,
899 gettext_noop ("# validations running"),
900 validations_running,
901 GNUNET_NO);
887 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 902 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
888 "Validation uses a fast start threshold of %u connections and a delay between of %s\n ", 903 "Validation uses a fast start threshold of %u connections and a delay between of %s\n ",
889 validations_fast_start_threshold, 904 validations_fast_start_threshold,
@@ -1450,6 +1465,10 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1450 GNUNET_i2s (sender), 1465 GNUNET_i2s (sender),
1451 tname, 1466 tname,
1452 GST_plugins_a2s (ve->address)); 1467 GST_plugins_a2s (ve->address));
1468 GNUNET_STATISTICS_update (GST_stats,
1469 gettext_noop ("# validations succeeded"),
1470 1,
1471 GNUNET_NO);
1453 /* validity achieved, remember it! */ 1472 /* validity achieved, remember it! */
1454 ve->expecting_pong = GNUNET_NO; 1473 ve->expecting_pong = GNUNET_NO;
1455 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); 1474 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
@@ -1468,6 +1487,10 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1468 if (validations_running > 0) 1487 if (validations_running > 0)
1469 { 1488 {
1470 validations_running --; 1489 validations_running --;
1490 GNUNET_STATISTICS_set (GST_stats,
1491 gettext_noop ("# validations running"),
1492 validations_running,
1493 GNUNET_NO);
1471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1472 "Validation finished, %u validation processes running\n", 1495 "Validation finished, %u validation processes running\n",
1473 validations_running); 1496 validations_running);