aboutsummaryrefslogtreecommitdiff
path: root/src/topology/gnunet-daemon-topology.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-07-17 08:35:20 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-07-17 08:35:20 +0000
commit6053799e5d05b8d5c6c664b66e48f367b3dd6578 (patch)
treec9d1f7a6d0d6fc9f4bb2804867499b032351c93c /src/topology/gnunet-daemon-topology.c
parent05e2e90dc4b9c9118c42e4ad4ab6f1333597045d (diff)
downloadgnunet-6053799e5d05b8d5c6c664b66e48f367b3dd6578.tar.gz
gnunet-6053799e5d05b8d5c6c664b66e48f367b3dd6578.zip
per peer back-off for transport connect attempts
Diffstat (limited to 'src/topology/gnunet-daemon-topology.c')
-rw-r--r--src/topology/gnunet-daemon-topology.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c
index 147e7332a..640b0fbc0 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.c
@@ -127,6 +127,11 @@ struct Peer
127 struct GNUNET_TIME_Absolute filter_expiration; 127 struct GNUNET_TIME_Absolute filter_expiration;
128 128
129 /** 129 /**
130 * When should try next connection attempt?
131 */
132 struct GNUNET_TIME_Absolute next_connect_attempt;
133
134 /**
130 * ID of task we use to wait for the time to send the next HELLO 135 * ID of task we use to wait for the time to send the next HELLO
131 * to this peer. 136 * to this peer.
132 */ 137 */
@@ -246,7 +251,7 @@ static unsigned int friend_count;
246 * is rather simple. 251 * is rather simple.
247 * 252 *
248 * @param cls closure 253 * @param cls closure
249 * @param pid peer to approve or disapproave 254 * @param pid peer to approve or disapprove
250 * @return GNUNET_OK if the connection is allowed 255 * @return GNUNET_OK if the connection is allowed
251 */ 256 */
252static int 257static int
@@ -384,6 +389,12 @@ attempt_connect (struct Peer *pos)
384 rem = GNUNET_TIME_relative_max (rem, GREYLIST_AFTER_ATTEMPT_MIN); 389 rem = GNUNET_TIME_relative_max (rem, GREYLIST_AFTER_ATTEMPT_MIN);
385 rem = GNUNET_TIME_relative_min (rem, GREYLIST_AFTER_ATTEMPT_MAX); 390 rem = GNUNET_TIME_relative_min (rem, GREYLIST_AFTER_ATTEMPT_MAX);
386 pos->greylisted_until = GNUNET_TIME_relative_to_absolute (rem); 391 pos->greylisted_until = GNUNET_TIME_relative_to_absolute (rem);
392
393 pos->next_connect_attempt = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
394 GNUNET_TIME_relative_multiply (MAX_CONNECT_FREQUENCY_DELAY, pos->connect_attempts));
395 pos->next_connect_attempt = GNUNET_TIME_absolute_min (pos->next_connect_attempt,
396 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), MIN_CONNECT_FREQUENCY_DELAY));
397
387 if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK) 398 if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK)
388 GNUNET_SCHEDULER_cancel (pos->greylist_clean_task); 399 GNUNET_SCHEDULER_cancel (pos->greylist_clean_task);
389 pos->greylist_clean_task = 400 pos->greylist_clean_task =
@@ -415,7 +426,14 @@ do_attempt_connect (void *cls,
415 if (GNUNET_YES == pos->is_connected) 426 if (GNUNET_YES == pos->is_connected)
416 return; 427 return;
417 428
418 delay = GNUNET_TIME_absolute_get_remaining (next_connect_attempt); 429 /* Try next connection attempt, when:
430 * - topology allows the next transport connection attempt
431 * and
432 * - the next connection event for this peer is allowed
433 */
434 delay = GNUNET_TIME_relative_max (GNUNET_TIME_absolute_get_remaining (next_connect_attempt),
435 GNUNET_TIME_absolute_get_remaining (pos->next_connect_attempt));
436
419 if (delay.rel_value_us > 0) 437 if (delay.rel_value_us > 0)
420 { 438 {
421 pos->attempt_connect_task = GNUNET_SCHEDULER_add_delayed (delay, 439 pos->attempt_connect_task = GNUNET_SCHEDULER_add_delayed (delay,
@@ -494,6 +512,7 @@ make_peer (const struct GNUNET_PeerIdentity *peer,
494 ret = GNUNET_new (struct Peer); 512 ret = GNUNET_new (struct Peer);
495 ret->pid = *peer; 513 ret->pid = *peer;
496 ret->is_friend = is_friend; 514 ret->is_friend = is_friend;
515 ret->next_connect_attempt = GNUNET_TIME_absolute_get();
497 if (hello != NULL) 516 if (hello != NULL)
498 { 517 {
499 ret->hello = GNUNET_malloc (GNUNET_HELLO_size (hello)); 518 ret->hello = GNUNET_malloc (GNUNET_HELLO_size (hello));
@@ -727,6 +746,7 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
727 } 746 }
728 pos->is_connected = GNUNET_YES; 747 pos->is_connected = GNUNET_YES;
729 pos->connect_attempts = 0; /* re-set back-off factor */ 748 pos->connect_attempts = 0; /* re-set back-off factor */
749 pos->next_connect_attempt = GNUNET_TIME_absolute_get(); /* re-set back-off factor */
730 if (pos->is_friend) 750 if (pos->is_friend)
731 { 751 {
732 if ((friend_count == minimum_friend_count - 1) && 752 if ((friend_count == minimum_friend_count - 1) &&