In Windows, pipes, files and the console have to be accessed
[oweals/gnunet.git] / src / vpn / vpn_api.c
index 3f8d0452393b8872df0884412bfbddd08fdb095c..e4da5fae00daed53ca5b15ae14e919a9a8b6f823 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.
    */
@@ -115,7 +120,7 @@ struct GNUNET_VPN_RedirectionRequest
   /**
    * For service redirection, service descriptor.
    */
-  GNUNET_HashCode serv;                     
+  struct GNUNET_HashCode serv;              
 
   /**
    * At what time should the created service mapping expire?
@@ -214,6 +219,9 @@ receive_response (void *cls,
     reconnect (vh);
     return;
   }  
+  GNUNET_CLIENT_receive (vh->client,
+                        &receive_response, vh,
+                        GNUNET_TIME_UNIT_FOREVER_REL);      
   for (rr = vh->rr_head; NULL != rr; rr = rr->next)
   {
     if (rr->request_id == rm->request_id)
@@ -228,9 +236,6 @@ receive_response (void *cls,
       break;
     }
   }
-  GNUNET_CLIENT_receive (vh->client,
-                        &receive_response, vh,
-                        GNUNET_TIME_UNIT_FOREVER_REL);      
 }
 
 
@@ -261,9 +266,13 @@ transmit_request (void *cls,
   while ( (NULL != rr) &&
          (0 != rr->request_id) )
     rr = rr->next;
-  if ( (NULL == rr) ||
-       (0 == size) )
+  if (NULL == rr) 
+    return 0;
+  if (0 == size) 
+  {
+    reconnect (vh);
     return 0;
+  }
 
   /* if first request, start receive loop */
   if (0 == vh->request_id_gen)
@@ -364,9 +373,10 @@ connect_task (void *cls,
 {
   struct GNUNET_VPN_Handle *vh = cls;
   
+  vh->rt = GNUNET_SCHEDULER_NO_TASK;
   vh->client = GNUNET_CLIENT_connect ("vpn", vh->cfg);
   GNUNET_assert (NULL != vh->client);
-  GNUNET_assert (NULL != vh->th);
+  GNUNET_assert (NULL == vh->th);
   if (NULL != vh->rr_head) 
     vh->th = GNUNET_CLIENT_notify_transmit_ready (vh->client,
                                                  sizeof (struct RedirectToServiceRequestMessage),
@@ -392,12 +402,15 @@ reconnect (struct GNUNET_VPN_Handle *vh)
     GNUNET_CLIENT_notify_transmit_ready_cancel (vh->th);
     vh->th = NULL;
   }  
-  GNUNET_CLIENT_disconnect (vh->client, GNUNET_NO);
+  GNUNET_CLIENT_disconnect (vh->client);
   vh->client = NULL;
   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);
 }
@@ -451,7 +464,7 @@ GNUNET_VPN_redirect_to_peer (struct GNUNET_VPN_Handle *vh,
                             int result_af,
                             uint8_t protocol,
                             const struct GNUNET_PeerIdentity *peer,
-                            const GNUNET_HashCode *serv,
+                            const struct GNUNET_HashCode *serv,
                             int nac,
                             struct GNUNET_TIME_Absolute expiration_time,
                             GNUNET_VPN_AllocationCallback cb,
@@ -578,7 +591,7 @@ GNUNET_VPN_disconnect (struct GNUNET_VPN_Handle *vh)
   }
   if (NULL != vh->client)
   {
-    GNUNET_CLIENT_disconnect (vh->client, GNUNET_NO);
+    GNUNET_CLIENT_disconnect (vh->client);
     vh->client = NULL;
   }
   if (GNUNET_SCHEDULER_NO_TASK != vh->rt)