- use proper signedness
[oweals/gnunet.git] / src / transport / plugin_transport_http_server.c
index 72562607da1105ecc3039e3a518247d822410070..15c0323c6e70b366b5cc7d3e3fd0a34124a66b71 100644 (file)
@@ -605,7 +605,6 @@ http_server_plugin_send (void *cls,
     server_reschedule (session->plugin,
                        session->server_send->mhd_daemon,
                        GNUNET_YES);
-    server_reschedule_session_timeout (session);
   }
   return bytes_sent;
 }
@@ -886,6 +885,34 @@ http_server_plugin_disconnect_session (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_server_query_keepalive_factor (void *cls)
+{
+  return 3;
+}
+
+static void
+http_server_plugin_update_session_timeout (void *cls,
+                                  const struct GNUNET_PeerIdentity *peer,
+                                  struct Session *session)
+{
+  struct HTTP_Server_Plugin *plugin = cls;
+
+  if (GNUNET_NO == server_exist_session (plugin, session))
+      return;
+
+  server_reschedule_session_timeout (session);
+}
+
+
 /**
  * Tell MHD that the connection should timeout after @a to seconds.
  *
@@ -2192,7 +2219,7 @@ server_add_address (void *cls, int add_remove, const struct sockaddr *addr,
   struct HTTP_Server_Plugin *plugin = cls;
   struct HttpAddressWrapper *w = NULL;
 
-  w = GNUNET_malloc (sizeof (struct HttpAddressWrapper));
+  w = GNUNET_new (struct HttpAddressWrapper);
   w->address = http_common_address_from_socket (plugin->protocol, addr, addrlen);
   if (NULL == w->address)
   {
@@ -2742,7 +2769,7 @@ server_configure_plugin (struct HTTP_Server_Plugin *plugin)
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Binding %s plugin to specific IPv4 address: `%s'\n",
                      plugin->protocol, bind4_address);
-    plugin->server_addr_v4 = GNUNET_malloc (sizeof (struct sockaddr_in));
+    plugin->server_addr_v4 = GNUNET_new (struct sockaddr_in);
     if (1 != inet_pton (AF_INET, bind4_address,
                         &plugin->server_addr_v4->sin_addr))
     {
@@ -2773,7 +2800,7 @@ server_configure_plugin (struct HTTP_Server_Plugin *plugin)
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Binding %s plugin to specific IPv6 address: `%s'\n",
                      plugin->protocol, bind6_address);
-    plugin->server_addr_v6 = GNUNET_malloc (sizeof (struct sockaddr_in6));
+    plugin->server_addr_v6 = GNUNET_new (struct sockaddr_in6);
     if (1 !=
         inet_pton (AF_INET6, bind6_address, &plugin->server_addr_v6->sin6_addr))
     {
@@ -3037,16 +3064,17 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
   return NULL;
 }
 
-const char *http_plugin_address_to_string (void *cls,
-                                           const void *addr,
-                                           size_t addrlen)
+
+static const char *
+http_plugin_address_to_string (void *cls,
+                               const void *addr,
+                               size_t addrlen)
 {
 #if BUILD_HTTPS
-       return http_common_plugin_address_to_string (cls, PLUGIN_NAME, addr, addrlen);
+  return http_common_plugin_address_to_string (cls, PLUGIN_NAME, addr, addrlen);
 #else
-       return http_common_plugin_address_to_string (cls, PLUGIN_NAME, addr, addrlen);
+  return http_common_plugin_address_to_string (cls, PLUGIN_NAME, addr, addrlen);
 #endif
-
 }
 
 
@@ -3079,9 +3107,6 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
   struct GNUNET_TRANSPORT_PluginFunctions *api;
   struct HTTP_Server_Plugin *plugin;
 
-  plugin = GNUNET_new (struct HTTP_Server_Plugin);
-  plugin->env = env;
-
   if (NULL == env->receive)
   {
     /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
@@ -3093,12 +3118,14 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
     api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
     return api;
   }
-
+  plugin = GNUNET_new (struct HTTP_Server_Plugin);
+  plugin->env = env;
   api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
   api->cls = plugin;
   api->send = &http_server_plugin_send;
   api->disconnect_peer = &http_server_plugin_disconnect_peer;
   api->disconnect_session = &http_server_plugin_disconnect_session;
+  api->query_keepalive_factor = &http_server_query_keepalive_factor;
   api->check_address = &http_server_plugin_address_suggested;
   api->get_session = &http_server_plugin_get_session;
 
@@ -3106,7 +3133,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_server_get_network;
-
+  api->update_session_timeout = &http_server_plugin_update_session_timeout;
 #if BUILD_HTTPS
   plugin->name = "transport-https_server";
   plugin->protocol = "https";
@@ -3118,8 +3145,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
   /* Configure plugin */
   if (GNUNET_SYSERR == server_configure_plugin (plugin))
   {
-      LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
-      return NULL;
+    LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
+    return NULL;
   }
 
   /* Check IPv6 support */
@@ -3132,8 +3159,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
 
   if (GNUNET_SYSERR == server_start (plugin))
   {
-      LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
-      return NULL;
+    LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
+    return NULL;
   }
   return api;
 }