- fix error messages
[oweals/gnunet.git] / src / transport / plugin_transport_http_client.c
index c093a0312170537d1d5ee37d2afb213da38aa61d..ba7fd45a3850d13a9950758eae038aca034ebf47 100644 (file)
@@ -474,9 +474,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 +523,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 +541,6 @@ http_client_plugin_send (void *cls,
   }
 
   client_schedule (s->plugin, GNUNET_YES);
-  client_reschedule_session_timeout (s);
   return msgbuf_size;
 }
 
@@ -619,7 +616,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 +641,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 +660,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,10 +675,9 @@ 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);
 
@@ -700,6 +696,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
@@ -770,7 +781,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 +859,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 +888,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);
+
 }
 
 
@@ -921,7 +933,9 @@ client_receive_mst_cb (void *cls, void *client,
                                       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);
@@ -1269,7 +1283,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
@@ -1349,7 +1363,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
@@ -1744,6 +1758,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 +1802,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 +1810,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";