remove port from transport section because it was getting in the way of making sense...
[oweals/gnunet.git] / src / transport / plugin_transport_tcp.c
index 65aea96e01f087a7ace5e7cdb15b191c5fe71120..8c1d3d3339399447cc771b76c72ab1ff128df3c7 100644 (file)
@@ -37,8 +37,8 @@
 #include "plugin_transport.h"
 #include "transport.h"
 
-#define DEBUG_TCP GNUNET_YES
-#define DEBUG_TCP_NAT GNUNET_YES
+#define DEBUG_TCP GNUNET_NO
+#define DEBUG_TCP_NAT GNUNET_NO
 
 /**
  * How long until we give up on transmitting the welcome message?
@@ -304,6 +304,11 @@ struct Session
    */
   int inbound;
 
+  /**
+   * Was this session created using NAT traversal?
+   */
+  int is_nat;
+
 };
 
 
@@ -585,13 +590,14 @@ create_session (struct Plugin *plugin,
     GNUNET_assert (client == NULL);
 
 #if DEBUG_TCP
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                   "Creating new session for peer `%4s'\n",
                   GNUNET_i2s (target));
 #endif
   ret = GNUNET_malloc (sizeof (struct Session));
   ret->last_activity = GNUNET_TIME_absolute_get ();
   ret->plugin = plugin;
+  ret->is_nat = is_nat;
   if (is_nat != GNUNET_YES) /* If not a NAT WAIT conn, add it to global list */
     {
       ret->next = plugin->sessions;
@@ -1078,11 +1084,11 @@ tcp_plugin_send (void *cls,
            }
          if (session->inbound == GNUNET_YES)
            continue;
-         if (addrlen != session->connect_alen)
+         if ((addrlen != session->connect_alen) && (session->is_nat == GNUNET_NO))
            continue;
-         if (0 != memcmp (session->connect_addr,
+         if ((0 != memcmp (session->connect_addr,
                           addr,
-                          addrlen))
+                          addrlen)) && (session->is_nat == GNUNET_NO))
            continue;
          cand_session = select_better_session (cand_session,
                                                session);       
@@ -1152,12 +1158,12 @@ tcp_plugin_send (void *cls,
         return -1; /* NAT client only works with IPv4 addresses */
 
 
-      if ( (plugin->allow_nat == GNUNET_YES) && (is_natd == GNUNET_YES) &&
+      if ((plugin->allow_nat == GNUNET_YES) && (is_natd == GNUNET_YES) &&
            (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(plugin->nat_wait_conns, &target->hashPubKey)))
         {
 #if DEBUG_TCP_NAT
-          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                           _("Found valid IPv4 NAT address!\n"));
+          GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                           _("Found valid IPv4 NAT address (creating session)!\n"));
 #endif
           session = create_session (plugin,
                                     target,
@@ -1183,7 +1189,7 @@ tcp_plugin_send (void *cls,
 
           GNUNET_assert(GNUNET_CONTAINER_multihashmap_put(plugin->nat_wait_conns, &target->hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) == GNUNET_OK);
 #if DEBUG_TCP_NAT
-          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+          GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                            "Created NAT WAIT connection to `%4s' at `%s'\n",
                            GNUNET_i2s (target),
                            GNUNET_a2s (sb, sbs));
@@ -1213,7 +1219,7 @@ tcp_plugin_send (void *cls,
          return -1;
        }
 #if DEBUG_TCP
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                        "Asked to transmit to `%4s', creating fresh session using address `%s'.\n",
                       GNUNET_i2s (target),
                       GNUNET_a2s (sb, sbs));
@@ -1579,7 +1585,7 @@ handle_tcp_nat_probe (void *cls,
           GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
         {
 #if DEBUG_TCP_NAT
-          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+          GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                            "Found address `%s' for incoming connection %p\n",
                            GNUNET_a2s (vaddr, alen),
                            client);
@@ -1669,6 +1675,12 @@ handle_tcp_welcome (void *cls,
   if (session == NULL)
     {
       GNUNET_SERVER_client_keep (client);
+#if DEBUG_TCP_NAT
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                       "Received %s message from a `%4s/%p', creating session\n",
+                       "WELCOME",
+                       GNUNET_i2s (&wm->clientIdentity), client);
+#endif
       session = create_session (plugin,
                                &wm->clientIdentity, client, GNUNET_NO);
       session->inbound = GNUNET_YES;