-more logging, avoid duplicate re-scheduling
[oweals/gnunet.git] / src / transport / plugin_transport_tcp.c
index 1e73eda0bc6bcf62ca9fbf79ac711a033c8c86af..38ba2c3cee83ad01ba0e59d9f772377b3402f58e 100644 (file)
@@ -14,8 +14,8 @@
 
   You should have received a copy of the GNU General Public License
   along with GNUnet; see the file COPYING.  If not, write to the
-  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-  Boston, MA 02111-1307, USA.
+  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+  Boston, MA 02110-1301, USA.
  */
 /**
  * @file transport/plugin_transport_tcp.c
@@ -154,7 +154,7 @@ struct IPv4TcpAddress
    * Optional options and flags for this address,
    * see `enum TcpAddressOptions`
    */
-  uint32_t options;
+  uint32_t options GNUNET_PACKED;
 
   /**
    * IPv4 address, in network byte order.
@@ -177,7 +177,7 @@ struct IPv6TcpAddress
    * Optional flags for this address
    * see `enum TcpAddressOptions`
    */
-  uint32_t options;
+  uint32_t options GNUNET_PACKED;
 
   /**
    * IPv6 address.
@@ -248,7 +248,7 @@ struct PendingMessage
 /**
  * Session handle for TCP connections.
  */
-struct Session
+struct GNUNET_ATS_Session
 {
   /**
    * To whom are we talking to (set to our identity
@@ -536,7 +536,7 @@ struct Plugin
  */
 static void
 notify_session_monitor (struct Plugin *plugin,
-                        struct Session *session,
+                        struct GNUNET_ATS_Session *session,
                         enum GNUNET_TRANSPORT_SessionState state)
 {
   struct GNUNET_TRANSPORT_SessionInfo info;
@@ -807,12 +807,12 @@ tcp_plugin_string_to_address (void *cls,
  * @param client which client to find the session handle for
  * @return NULL if no matching session exists
  */
-static struct Session *
+static struct GNUNET_ATS_Session *
 lookup_session_by_client (struct Plugin *plugin,
                           struct GNUNET_SERVER_Client *client)
 {
   return GNUNET_SERVER_client_get_user_context (client,
-                                                struct Session);
+                                                struct GNUNET_ATS_Session);
 }
 
 
@@ -827,7 +827,7 @@ lookup_session_by_client (struct Plugin *plugin,
  */
 static int
 tcp_plugin_disconnect_session (void *cls,
-                               struct Session *session)
+                               struct GNUNET_ATS_Session *session)
 {
   struct Plugin *plugin = cls;
   struct PendingMessage *pm;
@@ -924,8 +924,7 @@ tcp_plugin_disconnect_session (void *cls,
   if (NULL != session->receive_delay_task)
   {
     GNUNET_SCHEDULER_cancel (session->receive_delay_task);
-    if (NULL != session->client)
-      GNUNET_SERVER_receive_done (session->client, GNUNET_SYSERR);
+    session->receive_delay_task = NULL;
   }
   if (NULL != session->client)
   {
@@ -957,14 +956,14 @@ tcp_plugin_query_keepalive_factor (void *cls)
 /**
  * Session was idle for too long, so disconnect it
  *
- * @param cls the `struct Session` of the idle session
+ * @param cls the `struct GNUNET_ATS_Session` of the idle session
  * @param tc scheduler context
  */
 static void
 session_timeout (void *cls,
                  const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  struct Session *s = cls;
+  struct GNUNET_ATS_Session *s = cls;
   struct GNUNET_TIME_Relative left;
 
   s->timeout_task = NULL;
@@ -998,7 +997,7 @@ session_timeout (void *cls,
  * @param s session to increment timeout for
  */
 static void
-reschedule_session_timeout (struct Session *s)
+reschedule_session_timeout (struct GNUNET_ATS_Session *s)
 {
   GNUNET_assert (NULL != s->timeout_task);
   s->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
@@ -1017,14 +1016,14 @@ reschedule_session_timeout (struct Session *s)
  *               the session
  * @return new session object
  */
-static struct Session *
+static struct GNUNET_ATS_Session *
 create_session (struct Plugin *plugin,
                 const struct GNUNET_HELLO_Address *address,
                 enum GNUNET_ATS_Network_Type scope,
                 struct GNUNET_SERVER_Client *client,
                 int is_nat)
 {
-  struct Session *session;
+  struct GNUNET_ATS_Session *session;
   struct PendingMessage *pm;
 
   if (GNUNET_YES != is_nat)
@@ -1038,7 +1037,7 @@ create_session (struct Plugin *plugin,
        tcp_plugin_address_to_string (plugin,
                                      address->address,
                                      address->address_length));
-  session = GNUNET_new (struct Session);
+  session = GNUNET_new (struct GNUNET_ATS_Session);
   session->last_activity = GNUNET_TIME_absolute_get ();
   session->plugin = plugin;
   session->is_nat = is_nat;
@@ -1051,7 +1050,7 @@ create_session (struct Plugin *plugin,
   session->address = GNUNET_HELLO_address_copy (address);
   session->target = address->peer;
   session->expecting_welcome = GNUNET_YES;
-  session->scope = GNUNET_ATS_NET_UNSPECIFIED;
+  session->scope = scope;
   pm = GNUNET_malloc (sizeof (struct PendingMessage) +
                      sizeof (struct WelcomeMessage));
   pm->msg = (const char *) &pm[1];
@@ -1103,7 +1102,7 @@ create_session (struct Plugin *plugin,
  * @param session for which session should we do this
  */
 static void
-process_pending_messages (struct Session *session);
+process_pending_messages (struct GNUNET_ATS_Session *session);
 
 
 /**
@@ -1122,7 +1121,7 @@ do_transmit (void *cls,
             size_t size,
             void *buf)
 {
-  struct Session *session = cls;
+  struct GNUNET_ATS_Session *session = cls;
   struct GNUNET_PeerIdentity pid;
   struct Plugin *plugin;
   struct PendingMessage *pos;
@@ -1276,7 +1275,7 @@ do_transmit (void *cls,
  * @param session for which session should we do this
  */
 static void
-process_pending_messages (struct Session *session)
+process_pending_messages (struct GNUNET_ATS_Session *session)
 {
   struct PendingMessage *pm;
 
@@ -1286,11 +1285,12 @@ process_pending_messages (struct Session *session)
   if (NULL == (pm = session->pending_messages_head))
     return;
 
-  session->transmit_handle = GNUNET_SERVER_notify_transmit_ready (session->client,
-                                                                  pm->message_size,
-                                                                  GNUNET_TIME_absolute_get_remaining (pm->timeout),
-                                                                  &do_transmit,
-                                                                  session);
+  session->transmit_handle
+    = GNUNET_SERVER_notify_transmit_ready (session->client,
+                                           pm->message_size,
+                                           GNUNET_TIME_absolute_get_remaining (pm->timeout),
+                                           &do_transmit,
+                                           session);
 }
 
 
@@ -1323,7 +1323,7 @@ process_pending_messages (struct Session *session)
  */
 static ssize_t
 tcp_plugin_send (void *cls,
-                 struct Session *session,
+                 struct GNUNET_ATS_Session *session,
                  const char *msgbuf,
                  size_t msgbuf_size,
                  unsigned int priority,
@@ -1413,7 +1413,7 @@ tcp_plugin_send (void *cls,
 /**
  * Closure for #session_lookup_it().
  */
-struct SessionItCtx
+struct GNUNET_ATS_SessionItCtx
 {
   /**
    * Address we are looking for.
@@ -1423,7 +1423,7 @@ struct SessionItCtx
   /**
    * Where to store the session (if we found it).
    */
-  struct Session *result;
+  struct GNUNET_ATS_Session *result;
 
 };
 
@@ -1431,9 +1431,9 @@ struct SessionItCtx
 /**
  * Look for a session by address.
  *
- * @param cls the `struct SessionItCtx`
+ * @param cls the `struct GNUNET_ATS_SessionItCtx`
  * @param key unused
- * @param value a `struct Session`
+ * @param value a `struct GNUNET_ATS_Session`
  * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session
  */
 static int
@@ -1441,8 +1441,8 @@ session_lookup_it (void *cls,
                    const struct GNUNET_PeerIdentity *key,
                    void *value)
 {
-  struct SessionItCtx *si_ctx = cls;
-  struct Session *session = value;
+  struct GNUNET_ATS_SessionItCtx *si_ctx = cls;
+  struct GNUNET_ATS_Session *session = value;
 
   if (0 !=
       GNUNET_HELLO_address_cmp (si_ctx->address,
@@ -1456,14 +1456,14 @@ session_lookup_it (void *cls,
 /**
  * Task cleaning up a NAT connection attempt after timeout
  *
- * @param cls the `struct Session`
+ * @param cls the `struct GNUNET_ATS_Session`
  * @param tc scheduler context (unused)
  */
 static void
 nat_connect_timeout (void *cls,
                      const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  struct Session *session = cls;
+  struct GNUNET_ATS_Session *session = cls;
 
   session->nat_connection_timeout = NULL;
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1489,7 +1489,7 @@ nat_connect_timeout (void *cls,
 static void
 tcp_plugin_update_session_timeout (void *cls,
                                    const struct GNUNET_PeerIdentity *peer,
-                                   struct Session *session)
+                                   struct GNUNET_ATS_Session *session)
 {
   reschedule_session_timeout (session);
 }
@@ -1499,14 +1499,14 @@ tcp_plugin_update_session_timeout (void *cls,
  * Task to signal the server that we can continue
  * receiving from the TCP client now.
  *
- * @param cls the `struct Session *`
+ * @param cls the `struct GNUNET_ATS_Session *`
  * @param tc task context (unused)
  */
 static void
 delayed_done (void *cls,
               const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  struct Session *session = cls;
+  struct GNUNET_ATS_Session *session = cls;
 
   session->receive_delay_task = NULL;
   reschedule_session_timeout (session);
@@ -1528,7 +1528,7 @@ delayed_done (void *cls,
 static void
 tcp_plugin_update_inbound_delay (void *cls,
                                  const struct GNUNET_PeerIdentity *peer,
-                                 struct Session *session,
+                                 struct GNUNET_ATS_Session *session,
                                  struct GNUNET_TIME_Relative delay)
 {
   if (NULL == session->receive_delay_task)
@@ -1554,12 +1554,12 @@ tcp_plugin_update_inbound_delay (void *cls,
  * @param address the address to use
  * @return the session if the address is valid, NULL otherwise
  */
-static struct Session *
+static struct GNUNET_ATS_Session *
 tcp_plugin_get_session (void *cls,
                         const struct GNUNET_HELLO_Address *address)
 {
   struct Plugin *plugin = cls;
-  struct Session *session = NULL;
+  struct GNUNET_ATS_Session *session = NULL;
   int af;
   const void *sb;
   size_t sbs;
@@ -1596,7 +1596,7 @@ tcp_plugin_get_session (void *cls,
       GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap,
                                               &address->peer))
   {
-    struct SessionItCtx si_ctx;
+    struct GNUNET_ATS_SessionItCtx si_ctx;
 
     si_ctx.address = address;
     si_ctx.result = NULL;
@@ -1812,7 +1812,7 @@ tcp_plugin_get_session (void *cls,
  *
  * @param cls the `struct Plugin *`
  * @param key the peer which the session belongs to (unused)
- * @param value the `struct Session`
+ * @param value the `struct GNUNET_ATS_Session`
  * @return #GNUNET_YES (continue to iterate)
  */
 static int
@@ -1821,7 +1821,7 @@ session_disconnect_it (void *cls,
                        void *value)
 {
   struct Plugin *plugin = cls;
-  struct Session *session = value;
+  struct GNUNET_ATS_Session *session = value;
 
   GNUNET_STATISTICS_update (session->plugin->env->stats,
                             gettext_noop ("# transport-service disconnect requests for TCP"),
@@ -1887,6 +1887,9 @@ append_port (void *cls,
   struct Plugin *plugin = ppc->plugin;
   char *ret;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "append_port called with hostname `%s'\n",
+              hostname);
   if (NULL == hostname)
   {
     /* Final call, done */
@@ -1982,6 +1985,9 @@ tcp_plugin_address_pretty_printer (void *cls,
   else
   {
     /* invalid address */
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         _("Unexpected address length: %u bytes\n"),
+         (unsigned int) addrlen);
     asc (asc_cls, NULL, GNUNET_SYSERR);
     asc (asc_cls, NULL, GNUNET_OK);
     return;
@@ -1996,6 +2002,8 @@ tcp_plugin_address_pretty_printer (void *cls,
   ppc->asc_cls = asc_cls;
   ppc->port = port;
   ppc->options = options;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Starting DNS reverse lookup\n");
   ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb,
                                                        sbs,
                                                        ! numeric,
@@ -2127,7 +2135,7 @@ handle_tcp_nat_probe (void *cls,
                       const struct GNUNET_MessageHeader *message)
 {
   struct Plugin *plugin = cls;
-  struct Session *session;
+  struct GNUNET_ATS_Session *session;
   const struct TCP_NAT_ProbeMessage *tcp_nat_probe;
   size_t alen;
   void *vaddr;
@@ -2147,7 +2155,8 @@ handle_tcp_nat_probe (void *cls,
   if (ntohs (message->size) != sizeof(struct TCP_NAT_ProbeMessage))
   {
     GNUNET_break_op(0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    GNUNET_SERVER_receive_done (client,
+                                GNUNET_SYSERR);
     return;
   }
 
@@ -2156,7 +2165,8 @@ handle_tcp_nat_probe (void *cls,
           sizeof(struct GNUNET_PeerIdentity)))
   {
     /* refuse connections from ourselves */
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    GNUNET_SERVER_receive_done (client,
+                                GNUNET_SYSERR);
     return;
   }
 
@@ -2166,7 +2176,8 @@ handle_tcp_nat_probe (void *cls,
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Did NOT find session for NAT probe!\n");
-    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    GNUNET_SERVER_receive_done (client,
+                                GNUNET_OK);
     return;
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2235,7 +2246,8 @@ handle_tcp_nat_probe (void *cls,
     LOG(GNUNET_ERROR_TYPE_DEBUG,
         "Bad address for incoming connection!\n");
     GNUNET_free(vaddr);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    GNUNET_SERVER_receive_done (client,
+                                GNUNET_SYSERR);
     tcp_plugin_disconnect_session (plugin,
                                    session);
     return;
@@ -2269,7 +2281,7 @@ handle_tcp_welcome (void *cls,
   struct Plugin *plugin = cls;
   const struct WelcomeMessage *wm = (const struct WelcomeMessage *) message;
   struct GNUNET_HELLO_Address *address;
-  struct Session *session;
+  struct GNUNET_ATS_Session *session;
   size_t alen;
   void *vaddr;
   struct IPv4TcpAddress t4;
@@ -2354,6 +2366,8 @@ handle_tcp_welcome (void *cls,
       {
         GNUNET_break (0);
         GNUNET_free_non_null (vaddr);
+        GNUNET_SERVER_receive_done (client,
+                                    GNUNET_SYSERR);
         return;
       }
       session = create_session (plugin,
@@ -2363,6 +2377,7 @@ handle_tcp_welcome (void *cls,
                                                                alen),
                                 client,
                                 GNUNET_NO);
+      GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != session->scope);
       GNUNET_HELLO_address_free (address);
       LOG (GNUNET_ERROR_TYPE_DEBUG,
            "Creating new%s session %p for peer `%s' client %p\n",
@@ -2384,15 +2399,14 @@ handle_tcp_welcome (void *cls,
                                   session->address,
                                   session,
                                   session->scope);
-      notify_session_monitor (plugin,
-                              session,
-                              GNUNET_TRANSPORT_SS_INIT);
     }
     else
     {
       LOG(GNUNET_ERROR_TYPE_DEBUG,
           "Did not obtain TCP socket address for incoming connection\n");
       GNUNET_break(0);
+      GNUNET_SERVER_receive_done (client,
+                                  GNUNET_SYSERR);
       return;
     }
   }
@@ -2400,7 +2414,8 @@ handle_tcp_welcome (void *cls,
   if (session->expecting_welcome != GNUNET_YES)
   {
     GNUNET_break_op(0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    GNUNET_SERVER_receive_done (client,
+                                GNUNET_SYSERR);
     GNUNET_break(0);
     return;
   }
@@ -2410,7 +2425,8 @@ handle_tcp_welcome (void *cls,
   process_pending_messages (session);
   GNUNET_SERVER_client_set_timeout (client,
                                     GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
-  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+  GNUNET_SERVER_receive_done (client,
+                              GNUNET_OK);
 }
 
 
@@ -2428,7 +2444,7 @@ handle_tcp_data (void *cls,
                  const struct GNUNET_MessageHeader *message)
 {
   struct Plugin *plugin = cls;
-  struct Session *session;
+  struct GNUNET_ATS_Session *session;
   struct GNUNET_TIME_Relative delay;
   uint16_t type;
 
@@ -2504,17 +2520,21 @@ handle_tcp_data (void *cls,
   reschedule_session_timeout (session);
   if (0 == delay.rel_value_us)
   {
-    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    GNUNET_SERVER_receive_done (client,
+                                GNUNET_OK);
   }
   else
   {
-    LOG(GNUNET_ERROR_TYPE_DEBUG,
-        "Throttling receiving from `%s' for %s\n",
-        GNUNET_i2s (&session->target),
-        GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "Throttling receiving from `%s' for %s\n",
+         GNUNET_i2s (&session->target),
+         GNUNET_STRINGS_relative_time_to_string (delay,
+                                                 GNUNET_YES));
     GNUNET_SERVER_disable_receive_done_warning (client);
+    GNUNET_assert (NULL == session->receive_delay_task);
     session->receive_delay_task = GNUNET_SCHEDULER_add_delayed (delay,
-        &delayed_done, session);
+                                                                &delayed_done,
+                                                                session);
   }
 }
 
@@ -2533,7 +2553,17 @@ connect_notify (void *cls,
 {
   struct Plugin *plugin = cls;
 
+  if (NULL == client)
+    return;
   plugin->cur_connections++;
+  GNUNET_STATISTICS_set (plugin->env->stats,
+                         gettext_noop ("# TCP server connections active"),
+                         plugin->cur_connections,
+                         GNUNET_NO);
+  GNUNET_STATISTICS_update (plugin->env->stats,
+                           gettext_noop ("# TCP server connect events"),
+                           1,
+                           GNUNET_NO);
   if (plugin->cur_connections != plugin->max_connections)
     return;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -2559,11 +2589,14 @@ disconnect_notify (void *cls,
                    struct GNUNET_SERVER_Client *client)
 {
   struct Plugin *plugin = cls;
-  struct Session *session;
+  struct GNUNET_ATS_Session *session;
 
   if (NULL == client)
     return;
-  session = lookup_session_by_client (plugin, client);
+  GNUNET_assert (plugin->cur_connections >= 1);
+  plugin->cur_connections--;
+  session = lookup_session_by_client (plugin,
+                                      client);
   if (NULL == session)
     return; /* unknown, nothing to do */
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2581,8 +2614,10 @@ disconnect_notify (void *cls,
                               GNUNET_NO);
     GNUNET_SERVER_resume (plugin->server); /* Resume server  */
   }
-  GNUNET_assert (plugin->cur_connections >= 1);
-  plugin->cur_connections--;
+  GNUNET_STATISTICS_set (plugin->env->stats,
+                         gettext_noop ("# TCP server connections active"),
+                         plugin->cur_connections,
+                         GNUNET_NO);
   GNUNET_STATISTICS_update (session->plugin->env->stats,
                             gettext_noop ("# network-level TCP disconnect events"),
                             1,
@@ -2692,19 +2727,79 @@ try_connection_reversal (void *cls,
  */
 static enum GNUNET_ATS_Network_Type
 tcp_plugin_get_network (void *cls,
-                        struct Session *session)
+                        struct GNUNET_ATS_Session *session)
 {
   return session->scope;
 }
 
 
+/**
+ * Function obtain the network type for an address.
+ *
+ * @param cls closure (`struct Plugin *`)
+ * @param address the address
+ * @return the network type
+ */
+static enum GNUNET_ATS_Network_Type
+tcp_plugin_get_network_for_address (void *cls,
+                                    const struct GNUNET_HELLO_Address *address)
+{
+  struct Plugin *plugin = cls;
+  size_t addrlen;
+  struct sockaddr_in a4;
+  struct sockaddr_in6 a6;
+  const struct IPv4TcpAddress *t4;
+  const struct IPv6TcpAddress *t6;
+  const void *sb;
+  size_t sbs;
+
+  addrlen = address->address_length;
+  if (addrlen == sizeof(struct IPv6TcpAddress))
+  {
+    GNUNET_assert (NULL != address->address); /* make static analysis happy */
+    t6 = address->address;
+    memset (&a6, 0, sizeof(a6));
+#if HAVE_SOCKADDR_IN_SIN_LEN
+    a6.sin6_len = sizeof (a6);
+#endif
+    a6.sin6_family = AF_INET6;
+    a6.sin6_port = t6->t6_port;
+    memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr));
+    sb = &a6;
+    sbs = sizeof(a6);
+  }
+  else if (addrlen == sizeof(struct IPv4TcpAddress))
+  {
+    GNUNET_assert (NULL != address->address); /* make static analysis happy */
+    t4 = address->address;
+    memset (&a4, 0, sizeof(a4));
+#if HAVE_SOCKADDR_IN_SIN_LEN
+    a4.sin_len = sizeof (a4);
+#endif
+    a4.sin_family = AF_INET;
+    a4.sin_port = t4->t4_port;
+    a4.sin_addr.s_addr = t4->ipv4_addr;
+    sb = &a4;
+    sbs = sizeof(a4);
+  }
+  else
+  {
+    GNUNET_break (0);
+    return GNUNET_ATS_NET_UNSPECIFIED;
+  }
+  return plugin->env->get_address_type (plugin->env->cls,
+                                        sb,
+                                        sbs);
+}
+
+
 /**
  * Return information about the given session to the
  * monitor callback.
  *
  * @param cls the `struct Plugin` with the monitor callback (`sic`)
  * @param peer peer we send information about
- * @param value our `struct Session` to send information about
+ * @param value our `struct GNUNET_ATS_Session` to send information about
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
@@ -2713,7 +2808,7 @@ send_session_info_iter (void *cls,
                         void *value)
 {
   struct Plugin *plugin = cls;
-  struct Session *session = value;
+  struct GNUNET_ATS_Session *session = value;
 
   notify_session_monitor (plugin,
                           session,
@@ -2925,7 +3020,7 @@ libgnunet_plugin_transport_tcp_init (void *cls)
                              (const struct sockaddr **) addrs, addrlens,
                              &tcp_nat_port_map_callback,
                              &try_connection_reversal,
-                             plugin);
+                             plugin, NULL);
     for (ret = ret_s -1; ret >= 0; ret--)
       GNUNET_free (addrs[ret]);
     GNUNET_free_non_null (addrs);
@@ -2941,7 +3036,8 @@ libgnunet_plugin_transport_tcp_init (void *cls)
                                        NULL,
                                        NULL,
                                        &try_connection_reversal,
-                                       plugin);
+                                       plugin,
+                                       NULL);
   }
   api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
   api->cls = plugin;
@@ -2955,6 +3051,7 @@ libgnunet_plugin_transport_tcp_init (void *cls)
   api->address_to_string = &tcp_plugin_address_to_string;
   api->string_to_address = &tcp_plugin_string_to_address;
   api->get_network = &tcp_plugin_get_network;
+  api->get_network_for_address = &tcp_plugin_get_network_for_address;
   api->update_session_timeout = &tcp_plugin_update_session_timeout;
   api->update_inbound_delay = &tcp_plugin_update_inbound_delay;
   api->setup_monitor = &tcp_plugin_setup_monitor;
@@ -3078,7 +3175,7 @@ libgnunet_plugin_transport_tcp_done (void *cls)
     GNUNET_SERVICE_stop (plugin->service);
   else
     GNUNET_SERVER_destroy (plugin->server);
-  GNUNET_free(plugin->handlers);
+  GNUNET_free (plugin->handlers);
   if (NULL != plugin->nat)
     GNUNET_NAT_unregister (plugin->nat);
   while (NULL != (tcp_probe = plugin->probe_head))
@@ -3087,12 +3184,13 @@ libgnunet_plugin_transport_tcp_done (void *cls)
                                  plugin->probe_tail,
                                  tcp_probe);
     GNUNET_CONNECTION_destroy (tcp_probe->sock);
-    GNUNET_free(tcp_probe);
+    GNUNET_free (tcp_probe);
   }
   GNUNET_CONTAINER_multipeermap_destroy (plugin->nat_wait_conns);
   GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap);
-  GNUNET_free(plugin);
-  GNUNET_free(api);
+  GNUNET_break (0 == plugin->cur_connections);
+  GNUNET_free (plugin);
+  GNUNET_free (api);
   return NULL;
 }