- use proper signedness
[oweals/gnunet.git] / src / transport / plugin_transport_tcp.c
index e22e01cee60130e215fd73840f63b00b97ab5b36..04fac9cdecd841ec540d8438af85946616fa9bc5 100644 (file)
@@ -864,6 +864,21 @@ tcp_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
+tcp_query_keepalive_factor (void *cls)
+{
+  return 3;
+}
+
+
 /**
  * Session was idle, so disconnect it
  *
@@ -1270,7 +1285,6 @@ tcp_plugin_send (void *cls,
                                                     session))
   {
     GNUNET_assert (session->client != NULL);
-    reschedule_session_timeout (session);
     GNUNET_SERVER_client_set_timeout (session->client,
                                       GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
     GNUNET_STATISTICS_update (plugin->env->stats,
@@ -1289,7 +1303,6 @@ tcp_plugin_send (void *cls,
     LOG (GNUNET_ERROR_TYPE_DEBUG,
         "This NAT WAIT session for peer `%s' is not yet ready!\n",
         GNUNET_i2s (&session->target));
-    reschedule_session_timeout (session);
     GNUNET_STATISTICS_update (plugin->env->stats,
                               gettext_noop ("# bytes currently in TCP buffers"),
                               msgbuf_size, GNUNET_NO);
@@ -1405,6 +1418,18 @@ nat_connect_timeout (void *cls,
                           session);
 }
 
+static void
+tcp_plugin_update_session_timeout (void *cls,
+                                  const struct GNUNET_PeerIdentity *peer,
+                                  struct Session *session)
+{
+  struct Plugin *plugin = cls;
+  if (GNUNET_SYSERR == find_session (plugin, session))
+    return;
+
+  reschedule_session_timeout (session);
+}
+
 
 /**
  * Create a new session to transmit data to the target
@@ -1881,7 +1906,7 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type,
     asc (asc_cls, NULL);
     return;
   }
-  ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
+  ppc = GNUNET_new (struct PrettyPrinterContext);
   if (addrlen == sizeof (struct IPv6TcpAddress))
     ppc->ipv6 = GNUNET_YES;
   else
@@ -2499,7 +2524,7 @@ try_connection_reversal (void *cls, const struct sockaddr *addr,
 
   /* FIXME: do we need to track these probe context objects so that
    * we can clean them up on plugin unload? */
-  tcp_probe_ctx = GNUNET_malloc (sizeof (struct TCPProbeContext));
+  tcp_probe_ctx = GNUNET_new (struct TCPProbeContext);
   tcp_probe_ctx->message.header.size =
       htons (sizeof (struct TCP_NAT_ProbeMessage));
   tcp_probe_ctx->message.header.type =
@@ -2665,12 +2690,14 @@ libgnunet_plugin_transport_tcp_init (void *cls)
   api->get_session = &tcp_plugin_get_session;
 
   api->disconnect_session = &tcp_disconnect_session;
+  api->query_keepalive_factor = &tcp_query_keepalive_factor;
   api->disconnect_peer = &tcp_plugin_disconnect;
   api->address_pretty_printer = &tcp_plugin_address_pretty_printer;
   api->check_address = &tcp_plugin_check_address;
   api->address_to_string = &tcp_address_to_string;
   api->string_to_address = &tcp_string_to_address;
   api->get_network = &tcp_get_network;
+  api->update_session_timeout = &tcp_plugin_update_session_timeout;
   plugin->service = service;
   if (NULL != service)
   {