-use proper backoff to make VPN connect/start faster
authorChristian Grothoff <christian@grothoff.org>
Wed, 25 Jan 2012 20:26:21 +0000 (20:26 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 25 Jan 2012 20:26:21 +0000 (20:26 +0000)
src/vpn/vpn_api.c

index 494c6d8573262a8648faf2b629ff1aff910055af..81282960ece83000b5a8d90c0097eec8942881f3 100644 (file)
@@ -63,6 +63,11 @@ struct GNUNET_VPN_Handle
    */
   GNUNET_SCHEDULER_TaskIdentifier rt;
 
+  /**
+   * How long do we wait until we try to reconnect?
+   */
+  struct GNUNET_TIME_Relative backoff;
+
   /**
    * ID of the last request that was submitted to the service.
    */
@@ -402,7 +407,10 @@ reconnect (struct GNUNET_VPN_Handle *vh)
   vh->request_id_gen = 0;
   for (rr = vh->rr_head; NULL != rr; rr = rr->next)
     rr->request_id = 0;
-  vh->rt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+  vh->backoff = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS,
+                                         GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (vh->backoff, 2),
+                                                                   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)));
+  vh->rt = GNUNET_SCHEDULER_add_delayed (vh->backoff,
                                         &connect_task, 
                                         vh);
 }