From e8bc962b2ed43e194ba124537573da236786e82c Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 17 Apr 2010 22:54:36 +0000 Subject: [PATCH] use back-off and higher-frequency re-tries to start with for creating connections --- TODO | 6 ----- src/topology/gnunet-daemon-topology.c | 32 ++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index bca489b25..2054d5df1 100644 --- a/TODO +++ b/TODO @@ -3,12 +3,6 @@ - trust: need *fast* way to check/update trust in peers (async peerinfo would not be right; certainly not with the current API) * TOPOLOGY: [CG] - - needs to re-try connecting after disconnect (currently, it - initially triggers a connection request, but if that connection - fails / goes down, it does not retry in a timely fashion; - cause seems to be the 'greylist_after_attempt' being set to 1h, - which is rather long -- and should probably be adjusted based on - the number of connections / known peers & use some form of back-off) - If the topology daemon crashes, peers that were put on the blacklist with transport will never be removed from it (until transport service dies); we should use the blacklist notification diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index 3a2a421d4..b175d82ae 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c @@ -41,13 +41,25 @@ * For how long do we blacklist a peer after a failed connection * attempt? */ -#define GREYLIST_AFTER_ATTEMPT GNUNET_TIME_UNIT_HOURS +#define GREYLIST_AFTER_ATTEMPT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) /** * For how long do we blacklist a friend after a failed connection * attempt? */ -#define GREYLIST_AFTER_ATTEMPT_FRIEND GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) +#define GREYLIST_AFTER_ATTEMPT_FRIEND GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) + +/** + * For how long do we blacklist anyone under any cirumstances after a failed connection + * attempt? + */ +#define GREYLIST_AFTER_ATTEMPT_MIN GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) + +/** + * For how long do we blacklist anyone under any cirumstances after a failed connection + * attempt? + */ +#define GREYLIST_AFTER_ATTEMPT_MAX GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 18) /** * How often do we at most advertise any HELLO to a peer? @@ -126,6 +138,11 @@ struct Peer */ GNUNET_SCHEDULER_TaskIdentifier greylist_clean_task; + /** + * How often have we tried so far? + */ + unsigned int connect_attempts; + /** * Is this peer listed here because he is a friend? */ @@ -512,7 +529,15 @@ attempt_connect (struct Peer *pos) rem = GREYLIST_AFTER_ATTEMPT_FRIEND; else rem = GREYLIST_AFTER_ATTEMPT; - /* FIXME: do exponential back-off? */ + rem = GNUNET_TIME_relative_multiply (rem, connection_count); + rem = GNUNET_TIME_relative_divide (rem, target_connection_count); + if (pos->connect_attempts > 30) + pos->connect_attempts = 30; + rem = GNUNET_TIME_relative_multiply (rem, 1 << (++pos->connect_attempts)); + rem = GNUNET_TIME_relative_max (rem, + GREYLIST_AFTER_ATTEMPT_MIN); + rem = GNUNET_TIME_relative_min (rem, + GREYLIST_AFTER_ATTEMPT_MAX); pos->greylisted_until = GNUNET_TIME_relative_to_absolute (rem); if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (sched, @@ -857,6 +882,7 @@ connect_notify (void *cls, pos->greylisted_until.value = 0; /* remove greylisting */ } pos->is_connected = GNUNET_YES; + pos->connect_attempts = 0; /* re-set back-off factor */ if (pos->is_friend) { if ( (friend_count == minimum_friend_count - 1) && -- 2.25.1