use back-off and higher-frequency re-tries to start with for creating connections
authorChristian Grothoff <christian@grothoff.org>
Sat, 17 Apr 2010 22:54:36 +0000 (22:54 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 17 Apr 2010 22:54:36 +0000 (22:54 +0000)
TODO
src/topology/gnunet-daemon-topology.c

diff --git a/TODO b/TODO
index bca489b2506bb78c8b1d14cb64c9d45ea3565df3..2054d5df1ff268a0a7e4be06057b53dcb0fb1d59 100644 (file)
--- 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
index 3a2a421d4538c339f385ec97369d11fd02fabb65..b175d82ae32887247ebd17bfc32a2e7df6f8d691 100644 (file)
  * 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) &&