aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_validation.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-02-04 15:40:56 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-02-04 15:40:56 +0000
commit9f5dbc004450cbd34644380fb2f7d3972504f0bd (patch)
tree5a3eb9318f0b5123cadcb5b411a4d69140748dd2 /src/transport/gnunet-service-transport_validation.c
parent9b591a03f71042c8b00f9ba55c303d738a0c2363 (diff)
downloadgnunet-9f5dbc004450cbd34644380fb2f7d3972504f0bd.tar.gz
gnunet-9f5dbc004450cbd34644380fb2f7d3972504f0bd.zip
throttling validations
Diffstat (limited to 'src/transport/gnunet-service-transport_validation.c')
-rw-r--r--src/transport/gnunet-service-transport_validation.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index f76f888a6..3598a3494 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -308,6 +308,16 @@ static struct GNUNET_PEERINFO_NotifyContext *pnc;
308 308
309 309
310/** 310/**
311 * Minimum delay between to validations
312 */
313static struct GNUNET_TIME_Relative validation_delay;
314
315/**
316 * When is next validation allowed
317 */
318static struct GNUNET_TIME_Absolute validation_next;
319
320/**
311 * Context for the validation entry match function. 321 * Context for the validation entry match function.
312 */ 322 */
313struct ValidationEntryMatchContext 323struct ValidationEntryMatchContext
@@ -433,6 +443,7 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid,
433 struct ValidationEntry *ve = cls; 443 struct ValidationEntry *ve = cls;
434 struct TransportPingMessage ping; 444 struct TransportPingMessage ping;
435 struct GNUNET_TRANSPORT_PluginFunctions *papi; 445 struct GNUNET_TRANSPORT_PluginFunctions *papi;
446 struct GNUNET_TIME_Absolute next;
436 const struct GNUNET_MessageHeader *hello; 447 const struct GNUNET_MessageHeader *hello;
437 ssize_t ret; 448 ssize_t ret;
438 size_t tsize; 449 size_t tsize;
@@ -440,9 +451,21 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid,
440 uint16_t hsize; 451 uint16_t hsize;
441 452
442 ve->bc = NULL; 453 ve->bc = NULL;
454
455 if (GNUNET_NO == result)
456 {
457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Blacklist denies to send PING to `%s' %s %s\n",
458 GNUNET_i2s (pid), GST_plugins_a2s (ve->address), ve->address->transport_name);
459 return;
460 }
461
443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting plain PING to `%s' %s %s\n", 462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting plain PING to `%s' %s %s\n",
444 GNUNET_i2s (pid), GST_plugins_a2s (ve->address), ve->address->transport_name); 463 GNUNET_i2s (pid), GST_plugins_a2s (ve->address), ve->address->transport_name);
445 464
465 next = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), validation_delay);
466 if (next.abs_value > validation_next.abs_value)
467 validation_next = next; /* We're going to send a PING so delay next validation */
468
446 slen = strlen (ve->address->transport_name) + 1; 469 slen = strlen (ve->address->transport_name) + 1;
447 hello = GST_hello_get (); 470 hello = GST_hello_get ();
448 hsize = ntohs (hello->size); 471 hsize = ntohs (hello->size);
@@ -529,6 +552,7 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
529 struct ValidationEntry *ve = cls; 552 struct ValidationEntry *ve = cls;
530 struct GNUNET_TIME_Relative canonical_delay; 553 struct GNUNET_TIME_Relative canonical_delay;
531 struct GNUNET_TIME_Relative delay; 554 struct GNUNET_TIME_Relative delay;
555 struct GNUNET_TIME_Relative blocked_for;
532 struct GST_BlacklistCheck *bc; 556 struct GST_BlacklistCheck *bc;
533 uint32_t rdelay; 557 uint32_t rdelay;
534 558
@@ -553,6 +577,14 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
553 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve); 577 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
554 return; 578 return;
555 } 579 }
580 blocked_for = GNUNET_TIME_absolute_get_remaining(validation_next);
581 if ((blocked_for.rel_value) > 0)
582 {
583 /* Validations are blocked, have to wait for blocked_for ms */
584 ve->revalidation_task =
585 GNUNET_SCHEDULER_add_delayed (blocked_for, &revalidate_address, ve);
586 return;
587 }
556 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay); 588 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay);
557 589
558 /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */ 590 /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */
@@ -707,10 +739,15 @@ process_peerinfo_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
707 739
708/** 740/**
709 * Start the validation subsystem. 741 * Start the validation subsystem.
742 *
743 * @param max_fds maximum number of fds to use
710 */ 744 */
711void 745void
712GST_validation_start () 746GST_validation_start (unsigned int max_fds)
713{ 747{
748 validation_next = GNUNET_TIME_absolute_get();
749 validation_delay.rel_value = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value) / max_fds;
750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Delay between validations: %u ms\n ", validation_delay.rel_value);
714 validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE, 751 validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE,
715 GNUNET_NO); 752 GNUNET_NO);
716 pnc = GNUNET_PEERINFO_notify (GST_cfg, &process_peerinfo_hello, NULL); 753 pnc = GNUNET_PEERINFO_notify (GST_cfg, &process_peerinfo_hello, NULL);