use exponential back-off of 1ms to 1s for (connect) retries by clients
authorChristian Grothoff <christian@grothoff.org>
Tue, 10 Nov 2009 20:26:10 +0000 (20:26 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 10 Nov 2009 20:26:10 +0000 (20:26 +0000)
src/util/client.c

index 4dedb55f3e200c290bc4803d8451dcdbf6340f10..4b84937bfafa64212b547c85b408dd3000b3cda9 100644 (file)
@@ -78,7 +78,7 @@ struct GNUNET_CLIENT_TransmitHandle
   GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
 
   /**
-   * Timeout.
+   * Timeout for the operation overall.
    */
   struct GNUNET_TIME_Absolute timeout;
 
@@ -215,6 +215,12 @@ struct GNUNET_CLIENT_Connection
    */
   struct GNUNET_TIME_Absolute receive_timeout;
 
+  /**
+   * Current value for our incremental back-off (for
+   * connect re-tries).
+   */
+  struct GNUNET_TIME_Relative back_off;
+
   /**
    * Number of bytes in received_buf that are valid.
    */
@@ -307,6 +313,7 @@ GNUNET_CLIENT_connect (struct GNUNET_SCHEDULER_Handle *sched,
   ret->sched = sched;
   ret->service_name = GNUNET_strdup (service_name);
   ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
+  ret->back_off = GNUNET_TIME_UNIT_MILLISECONDS;
   return ret;
 }
 
@@ -768,7 +775,10 @@ client_notify (void *cls, size_t size, void *buf)
       th->sock->sock = do_connect (th->sock->sched,
                                    th->sock->service_name, th->sock->cfg);
       GNUNET_assert (NULL != th->sock->sock);
-      delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_SECONDS);
+      delay = GNUNET_TIME_relative_min (delay, th->sock->back_off);
+      th->sock->back_off 
+       = GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (th->sock->back_off, 2),
+                                   GNUNET_TIME_UNIT_SECONDS);
 #if DEBUG_CLIENT
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Transmission failed %u times, trying again in %llums.\n",