-fix time assertion introduce in last patch
[oweals/gnunet.git] / src / transport / plugin_transport_http_client.c
index c093a0312170537d1d5ee37d2afb213da38aa61d..7da92c7430f25e2fbc50347ce5a7237396354dfc 100644 (file)
@@ -155,12 +155,7 @@ struct Session
   /**
    * Address
    */
-  struct HttpAddress *addr;
-
-  /**
-   * Address length
-   */
-  size_t addrlen;
+  struct GNUNET_HELLO_Address *address;
 
   /**
    * ATS network type in NBO
@@ -279,6 +274,39 @@ struct HTTP_Client_Plugin
    */
   char *protocol;
 
+  /**
+   * Proxy configuration: hostname or ip of the proxy server
+   */
+  char *proxy_hostname;
+
+  /**
+   * Username for the proxy server
+   */
+  char *proxy_username;
+
+  /**
+   * Password for the proxy server
+   */
+  char *proxy_password;
+
+  /**
+   * Type of proxy server:
+   *
+   * Valid values as supported by curl:
+   * CURLPROXY_HTTP, CURLPROXY_HTTP_1_0 CURLPROXY_SOCKS4, CURLPROXY_SOCKS5,
+   * CURLPROXY_SOCKS4A, CURLPROXY_SOCKS5_HOSTNAME
+   */
+  curl_proxytype proxytype;
+
+  /**
+   * Use proxy tunneling:
+   * Tunnel all operations through a given HTTP instead of have the proxy
+   * evaluate the HTTP request
+   *
+   * Default: GNUNET_NO, GNUNET_yes experimental
+   */
+  int proxy_use_httpproxytunnel;
+
   /**
    * My options to be included in the address
    */
@@ -474,9 +502,6 @@ http_client_plugin_send (void *cls,
   struct HTTP_Message *msg;
   char *stat_txt;
 
-  GNUNET_assert (plugin != NULL);
-  GNUNET_assert (s != NULL);
-
   /* lookup if session is really existing */
   if (GNUNET_YES != client_exist_session (plugin, s))
   {
@@ -526,7 +551,8 @@ http_client_plugin_send (void *cls,
                      "Session %p/connection %p: unpausing connection\n",
                      s, s->client_put);
     s->put_paused = GNUNET_NO;
-    curl_easy_pause (s->client_put, CURLPAUSE_CONT);
+    if (NULL != s->client_put)
+      curl_easy_pause (s->client_put, CURLPAUSE_CONT);
   }
   else if (GNUNET_YES == s->put_tmp_disconnected)
   {
@@ -543,7 +569,6 @@ http_client_plugin_send (void *cls,
   }
 
   client_schedule (s->plugin, GNUNET_YES);
-  client_reschedule_session_timeout (s);
   return msgbuf_size;
 }
 
@@ -590,7 +615,7 @@ client_delete_session (struct Session *s)
     GNUNET_SERVER_mst_destroy (s->msg_tk);
     s->msg_tk = NULL;
   }
-  GNUNET_free (s->addr);
+  GNUNET_HELLO_address_free (s->address);
   GNUNET_free (s->url);
   GNUNET_free (s);
 }
@@ -619,7 +644,7 @@ http_client_session_disconnect (void *cls,
     return GNUNET_SYSERR;
   }
 
-  if (s->client_put != NULL)
+  if (NULL != s->client_put)
   {
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Session %p/connection %p: disconnecting PUT connection to peer `%s'\n",
@@ -644,12 +669,12 @@ http_client_session_disconnect (void *cls,
     s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
   }
 
-  if (s->client_get != NULL)
+  if (NULL != s->client_get)
   {
-      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
-                       "Session %p/connection %p: disconnecting GET connection to peer `%s'\n",
-                       s, s->client_get, GNUNET_i2s (&s->target));
-
+    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+                     "Session %p/connection %p: disconnecting GET connection to peer `%s'\n",
+                     s, s->client_get,
+                     GNUNET_i2s (&s->target));
     /* remove curl handle from multi handle */
     mret = curl_multi_remove_handle (plugin->curl_multi_handle, s->client_get);
     if (mret != CURLM_OK)
@@ -663,7 +688,7 @@ http_client_session_disconnect (void *cls,
   }
 
   msg = s->msg_head;
-  while (msg != NULL)
+  while (NULL != msg)
   {
     t = msg->next;
     if (NULL != msg->transmit_cont)
@@ -678,14 +703,13 @@ http_client_session_disconnect (void *cls,
   GNUNET_assert (plugin->cur_connections >= 2);
   plugin->cur_connections -= 2;
   GNUNET_STATISTICS_set (plugin->env->stats,
-      HTTP_STAT_STR_CONNECTIONS,
-      plugin->cur_connections,
-      GNUNET_NO);
-
+                         HTTP_STAT_STR_CONNECTIONS,
+                         plugin->cur_connections,
+                         GNUNET_NO);
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                    "Session %p: notifying transport about ending session\n",s);
 
-  plugin->env->session_end (plugin->env->cls, &s->target, s);
+  plugin->env->session_end (plugin->env->cls, s->address, s);
   client_delete_session (s);
 
   /* Re-schedule since handles have changed */
@@ -700,6 +724,21 @@ http_client_session_disconnect (void *cls,
 }
 
 
+/**
+ * Function that is called to get the keepalive factor.
+ * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
+ * calculate the interval between keepalive packets.
+ *
+ * @param cls closure with the `struct Plugin`
+ * @return keepalive factor
+ */
+static unsigned int
+http_client_query_keepalive_factor (void *cls)
+{
+  return 3;
+}
+
+
 /**
  * Function that can be used to force the plugin to disconnect
  * from the given peer and cancel all previous transmissions
@@ -750,10 +789,11 @@ client_lookup_session (struct HTTP_Client_Plugin *plugin,
   struct Session *pos;
 
   for (pos = plugin->head; NULL != pos; pos = pos->next)
+  {
     if ((0 == memcmp (&address->peer, &pos->target, sizeof (struct GNUNET_PeerIdentity))) &&
-        (address->address_length == pos->addrlen) &&
-        (0 == memcmp (address->address, pos->addr, pos->addrlen)))
+        (0 == GNUNET_HELLO_address_cmp(address, pos->address)))
       return pos;
+  }
   return NULL;
 }
 
@@ -770,7 +810,8 @@ client_put_disconnect (void *cls,
                    s, s->client_put);
   s->put_paused = GNUNET_NO;
   s->put_tmp_disconnecting = GNUNET_YES;
-  curl_easy_pause (s->client_put, CURLPAUSE_CONT);
+  if (NULL != s->client_put)
+    curl_easy_pause (s->client_put, CURLPAUSE_CONT);
   client_schedule (s->plugin, GNUNET_YES);
 }
 
@@ -847,8 +888,6 @@ client_send_cb (void *stream, size_t size, size_t nmemb, void *cls)
   GNUNET_STATISTICS_update (plugin->env->stats,
                             stat_txt, len, GNUNET_NO);
   GNUNET_free (stat_txt);
-
-  client_reschedule_session_timeout (s);
   return len;
 }
 
@@ -878,8 +917,10 @@ client_wake_up (void *cls,
                    "Session %p/connection %p: Waking up GET handle\n",
                    s,
                    s->client_get);
-  if (s->client_get != NULL)
+  s->put_paused = GNUNET_NO;
+  if (NULL != s->client_get)
     curl_easy_pause (s->client_get, CURLPAUSE_CONT);
+
 }
 
 
@@ -911,17 +952,15 @@ client_receive_mst_cb (void *cls, void *client,
   atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE);
   atsi.value = s->ats_address_network_type;
   GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED));
-  delay = s->plugin->env->receive (plugin->env->cls, &s->target, message,
-                                   s, (const char *) s->addr, s->addrlen);
 
+  delay = s->plugin->env->receive (plugin->env->cls, s->address, s, message);
   plugin->env->update_address_metrics (plugin->env->cls,
-                                      &s->target,
-                                      s->addr,
-                                      s->addrlen,
-                                      s,
+                                      s->address, s,
                                       &atsi, 1);
 
-  GNUNET_asprintf (&stat_txt, "# bytes received via %s_client", plugin->protocol);
+  GNUNET_asprintf (&stat_txt,
+                   "# bytes received via %s_client",
+                   plugin->protocol);
   GNUNET_STATISTICS_update (plugin->env->stats,
                             stat_txt, ntohs(message->size), GNUNET_NO);
   GNUNET_free (stat_txt);
@@ -935,8 +974,8 @@ client_receive_mst_cb (void *cls, void *client,
                      "Client: peer `%s' address `%s' next read delayed for %s\n",
                      GNUNET_i2s (&s->target),
                      http_common_plugin_address_to_string (NULL,
-                                                          s->plugin->protocol,
-                                                          s->addr, s->addrlen),
+                       s->plugin->protocol, s->address->address,
+                       s->address->address_length),
                      GNUNET_STRINGS_relative_time_to_string (delay,
                                                             GNUNET_YES));
   }
@@ -1146,25 +1185,31 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
       GNUNET_assert (s != NULL);
       if (msg->msg == CURLMSG_DONE)
       {
-        curl_easy_getinfo (easy_h, CURLINFO_RESPONSE_CODE, &http_statuscode);
+        GNUNET_break (CURLE_OK == curl_easy_getinfo (easy_h,
+            CURLINFO_RESPONSE_CODE, &http_statuscode));
         if (easy_h == s->client_put)
         {
             if  ((0 != msg->data.result) || (http_statuscode != 200))
             {
-                GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
-                  "Session %p/connection %p: PUT connection to `%s' ended with status %i reason %i: `%s'\n",
-                  s, msg->easy_handle, GNUNET_i2s (&s->target),
-                  http_statuscode,
-                  msg->data.result,
-                  curl_easy_strerror (msg->data.result));
+                GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+                                 plugin->name,
+                                 "Session %p/connection %p: PUT connection to `%s' ended with status %i reason %i: `%s'\n",
+                                 s, msg->easy_handle,
+                                 GNUNET_i2s (&s->target),
+                                 http_statuscode,
+                                 msg->data.result,
+                                 curl_easy_strerror (msg->data.result));
             }
             else
-              GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
-                "Session %p/connection %p: PUT connection to `%s' ended normal\n",
-                s, msg->easy_handle, GNUNET_i2s (&s->target));
-            if (s->client_get == NULL)
+              GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+                               plugin->name,
+                               "Session %p/connection %p: PUT connection to `%s' ended normal\n",
+                               s, msg->easy_handle,
+                               GNUNET_i2s (&s->target));
+            if (NULL == s->client_get)
             {
               /* Disconnect other transmission direction and tell transport */
+              /* FIXME? */
             }
             curl_multi_remove_handle (plugin->curl_multi_handle, easy_h);
             curl_easy_cleanup (easy_h);
@@ -1227,8 +1272,8 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 static int
 client_connect_get (struct Session *s)
 {
-
   CURLMcode mret;
+
   /* create get connection */
   s->client_get = curl_easy_init ();
   s->get.s = s;
@@ -1240,16 +1285,21 @@ client_connect_get (struct Session *s)
 #endif
 #if BUILD_HTTPS
   curl_easy_setopt (s->client_get, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
-  if (HTTP_OPTIONS_VERIFY_CERTIFICATE ==
-      (ntohl (s->addr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE))
-  {
-    curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 1L);
-    curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 2L);
-  }
-  else
   {
-    curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0);
-    curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0);
+    struct HttpAddress *ha;
+    ha = (struct HttpAddress *) s->address->address;
+
+    if (HTTP_OPTIONS_VERIFY_CERTIFICATE ==
+        (ntohl (ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE))
+    {
+      curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 1L);
+      curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 2L);
+    }
+    else
+    {
+      curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0);
+      curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0);
+    }
   }
   curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
   curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS);
@@ -1258,6 +1308,21 @@ client_connect_get (struct Session *s)
   curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP);
 #endif
 
+  if (s->plugin->proxy_hostname != NULL)
+  {
+    curl_easy_setopt (s->client_get, CURLOPT_PROXY, s->plugin->proxy_hostname);
+    curl_easy_setopt (s->client_get, CURLOPT_PROXYTYPE, s->plugin->proxytype);
+    if (NULL != s->plugin->proxy_username)
+      curl_easy_setopt (s->client_get, CURLOPT_PROXYUSERNAME,
+          s->plugin->proxy_username);
+    if (NULL != s->plugin->proxy_password)
+      curl_easy_setopt (s->client_get, CURLOPT_PROXYPASSWORD,
+          s->plugin->proxy_password);
+    if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
+      curl_easy_setopt (s->client_get, CURLOPT_HTTPPROXYTUNNEL,
+          s->plugin->proxy_use_httpproxytunnel);
+  }
+
   curl_easy_setopt (s->client_get, CURLOPT_URL, s->url);
   //curl_easy_setopt (s->client_get, CURLOPT_HEADERFUNCTION, &curl_get_header_cb);
   //curl_easy_setopt (s->client_get, CURLOPT_WRITEHEADER, ps);
@@ -1269,7 +1334,7 @@ client_connect_get (struct Session *s)
   curl_easy_setopt (s->client_get, CURLOPT_TIMEOUT, 0);
   curl_easy_setopt (s->client_get, CURLOPT_PRIVATE, s);
   curl_easy_setopt (s->client_get, CURLOPT_CONNECTTIMEOUT_MS,
-                    (long) HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL);
+                    (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL));
   curl_easy_setopt (s->client_get, CURLOPT_BUFFERSIZE,
                     2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
 #if CURL_TCP_NODELAY
@@ -1320,23 +1385,43 @@ client_connect_put (struct Session *s)
 #endif
 #if BUILD_HTTPS
   curl_easy_setopt (s->client_put, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
-  if (HTTP_OPTIONS_VERIFY_CERTIFICATE ==
-      (ntohl (s->addr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE))
   {
-    curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 1L);
-    curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 2L);
-  }
-  else
-  {
-    curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0);
-    curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0);
+    struct HttpAddress *ha;
+    ha = (struct HttpAddress *) s->address->address;
+
+    if (HTTP_OPTIONS_VERIFY_CERTIFICATE ==
+        (ntohl (ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE))
+    {
+      curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 1L);
+      curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 2L);
+    }
+    else
+    {
+      curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0);
+      curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0);
+    }
   }
-  curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
-  curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS);
+  curl_easy_setopt (s->client_put, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
+  curl_easy_setopt (s->client_put, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS);
 #else
-  curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTP);
-  curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP);
+  curl_easy_setopt (s->client_put, CURLOPT_PROTOCOLS, CURLPROTO_HTTP);
+  curl_easy_setopt (s->client_put, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP);
 #endif
+  if (s->plugin->proxy_hostname != NULL)
+  {
+    curl_easy_setopt (s->client_put, CURLOPT_PROXY, s->plugin->proxy_hostname);
+    curl_easy_setopt (s->client_put, CURLOPT_PROXYTYPE, s->plugin->proxytype);
+    if (NULL != s->plugin->proxy_username)
+      curl_easy_setopt (s->client_put, CURLOPT_PROXYUSERNAME,
+          s->plugin->proxy_username);
+    if (NULL != s->plugin->proxy_password)
+      curl_easy_setopt (s->client_put, CURLOPT_PROXYPASSWORD,
+          s->plugin->proxy_password);
+    if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
+      curl_easy_setopt (s->client_put, CURLOPT_HTTPPROXYTUNNEL,
+          s->plugin->proxy_use_httpproxytunnel);
+  }
+
   curl_easy_setopt (s->client_put, CURLOPT_URL, s->url);
   curl_easy_setopt (s->client_put, CURLOPT_UPLOAD, 1L);
   //curl_easy_setopt (s->client_put, CURLOPT_HEADERFUNCTION, &client_curl_header);
@@ -1349,7 +1434,7 @@ client_connect_put (struct Session *s)
   curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT, 0);
   curl_easy_setopt (s->client_put, CURLOPT_PRIVATE, s);
   curl_easy_setopt (s->client_put, CURLOPT_CONNECTTIMEOUT_MS,
-                    (long) HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL);
+                    (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL));
   curl_easy_setopt (s->client_put, CURLOPT_BUFFERSIZE,
                     2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
 #if CURL_TCP_NODELAY
@@ -1389,8 +1474,7 @@ client_connect (struct Session *s)
 
   /* create url */
   if (NULL == http_common_plugin_address_to_string (NULL,
-                                                    plugin->protocol,
-                                                    s->addr, s->addrlen))
+        plugin->protocol, s->address->address, s->address->address_length))
   {
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
                      plugin->name,
@@ -1400,7 +1484,8 @@ client_connect (struct Session *s)
   }
 
   GNUNET_asprintf (&s->url, "%s/%s;%u",
-                  http_common_plugin_address_to_url (NULL, s->addr, s->addrlen),
+                  http_common_plugin_address_to_url (NULL, s->address->address,
+                      s->address->address_length),
                   GNUNET_i2s_full (plugin->env->my_identity),
                   plugin->last_tag);
 
@@ -1413,7 +1498,8 @@ client_connect (struct Session *s)
   if ((GNUNET_SYSERR == client_connect_get (s)) ||
       (GNUNET_SYSERR == client_connect_put (s)))
   {
-    GNUNET_break (0);
+    plugin->env->session_end (plugin->env->cls, s->address, s);
+    client_delete_session (s);
     return GNUNET_SYSERR;
   }
 
@@ -1553,9 +1639,7 @@ http_client_plugin_get_session (void *cls,
   s = GNUNET_new (struct Session);
   s->target = address->peer;
   s->plugin = plugin;
-  s->addr = GNUNET_malloc (address->address_length);
-  memcpy (s->addr, address->address, address->address_length);
-  s->addrlen = address->address_length;
+  s->address = GNUNET_HELLO_address_copy (address);
   s->ats_address_network_type = ats.value;
   s->put_paused = GNUNET_NO;
   s->put_tmp_disconnecting = GNUNET_NO;
@@ -1565,8 +1649,9 @@ http_client_plugin_get_session (void *cls,
                                                    s);
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                    "Created new session %p for `%s' address `%s''\n",
-                   s,
-                   http_common_plugin_address_to_string (NULL, plugin->protocol, s->addr, s->addrlen),
+                   s, http_common_plugin_address_to_string (NULL,
+                       plugin->protocol, s->address->address,
+                       s->address->address_length),
                    GNUNET_i2s (&s->target));
 
   /* add new session */
@@ -1577,7 +1662,9 @@ http_client_plugin_get_session (void *cls,
   {
     GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
                      "Cannot connect to peer `%s' address `%s''\n",
-                     http_common_plugin_address_to_string (NULL, plugin->protocol, s->addr, s->addrlen),
+                     http_common_plugin_address_to_string (NULL,
+                                            plugin->protocol, s->address->address,
+                                            s->address->address_length),
                      GNUNET_i2s (&s->target));
     client_delete_session (s);
     return NULL;
@@ -1704,6 +1791,10 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
                    _("Shutdown for plugin `%s' complete\n"),
                    plugin->name);
 
+  GNUNET_free_non_null (plugin->proxy_hostname);
+  GNUNET_free_non_null (plugin->proxy_username);
+  GNUNET_free_non_null (plugin->proxy_password);
+
   GNUNET_free (plugin);
   GNUNET_free (api);
   return NULL;
@@ -1720,6 +1811,8 @@ static int
 client_configure_plugin (struct HTTP_Client_Plugin *plugin)
 {
   unsigned long long max_connections;
+  char *proxy_type;
+
 
   /* Optional parameters */
   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg,
@@ -1731,6 +1824,78 @@ client_configure_plugin (struct HTTP_Client_Plugin *plugin)
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                    _("Maximum number of connections is %u\n"),
                    plugin->max_connections);
+
+  /* Read proxy configuration */
+  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+      plugin->name, "PROXY", &plugin->proxy_hostname))
+  {
+    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+                     "Found proxy host: `%s'\n",
+                     plugin->proxy_hostname);
+    /* proxy username */
+    if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+        plugin->name, "PROXY_USERNAME", &plugin->proxy_username))
+    {
+      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+                       "Found proxy username name: `%s'\n",
+                       plugin->proxy_username);
+    }
+
+    /* proxy password */
+    if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+        plugin->name, "PROXY_PASSWORD", &plugin->proxy_password))
+    {
+      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+                       "Found proxy password name: `%s'\n",
+                       plugin->proxy_password);
+    }
+
+    /* proxy type */
+    if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+        plugin->name, "PROXY_TYPE", &proxy_type))
+    {
+      GNUNET_STRINGS_utf8_toupper (proxy_type, proxy_type);
+
+      if (0 == strcmp(proxy_type, "HTTP"))
+        plugin->proxytype = CURLPROXY_HTTP;
+      else if (0 == strcmp(proxy_type, "SOCKS4"))
+        plugin->proxytype = CURLPROXY_SOCKS4;
+      else if (0 == strcmp(proxy_type, "SOCKS5"))
+        plugin->proxytype = CURLPROXY_SOCKS5;
+      else if (0 == strcmp(proxy_type, "SOCKS4A"))
+        plugin->proxytype = CURLPROXY_SOCKS4A;
+      else if (0 == strcmp(proxy_type, "SOCKS5_HOSTNAME "))
+        plugin->proxytype = CURLPROXY_SOCKS5_HOSTNAME ;
+      else
+      {
+        GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+             _("Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
+             proxy_type);
+
+        GNUNET_free (proxy_type);
+        GNUNET_free (plugin->proxy_hostname);
+        plugin->proxy_hostname = NULL;
+        GNUNET_free_non_null (plugin->proxy_username);
+        plugin->proxy_username = NULL;
+        GNUNET_free_non_null (plugin->proxy_password);
+        plugin->proxy_password = NULL;
+
+        return GNUNET_SYSERR;
+      }
+
+      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+                       "Found proxy type: `%s'\n", proxy_type);
+    }
+
+    /* proxy http tunneling */
+    if (GNUNET_SYSERR == (plugin->proxy_use_httpproxytunnel = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
+        plugin->name, "PROXY_HTTP_TUNNELING")))
+      plugin->proxy_use_httpproxytunnel = GNUNET_NO;
+
+    GNUNET_free_non_null (proxy_type);
+  }
+
+
   return GNUNET_OK;
 }
 
@@ -1744,6 +1909,22 @@ http_plugin_address_to_string (void *cls,
 }
 
 
+static void
+http_client_plugin_update_session_timeout (void *cls,
+                                  const struct GNUNET_PeerIdentity *peer,
+                                  struct Session *session)
+{
+  struct HTTP_Client_Plugin *plugin = cls;
+
+  /* lookup if session is really existing */
+  if (GNUNET_YES != client_exist_session (plugin, session))
+  {
+    GNUNET_break (0);
+    return;
+  }
+  client_reschedule_session_timeout (session);
+}
+
 /**
  * Entry point for the plugin.
  */
@@ -1772,6 +1953,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
   api->cls = plugin;
   api->send = &http_client_plugin_send;
   api->disconnect_session = &http_client_session_disconnect;
+  api->query_keepalive_factor = &http_client_query_keepalive_factor;
   api->disconnect_peer = &http_client_peer_disconnect;
   api->check_address = &http_client_plugin_address_suggested;
   api->get_session = &http_client_plugin_get_session;
@@ -1779,6 +1961,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
   api->string_to_address = &http_common_plugin_string_to_address;
   api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
   api->get_network = &http_client_get_network;
+  api->update_session_timeout = &http_client_plugin_update_session_timeout;
 
 #if BUILD_HTTPS
   plugin->name = "transport-https_client";