wip
[oweals/gnunet.git] / src / transport / plugin_transport_tcp.c
index 627cb6b9b4da69a5271d52ad2d88981fcd5aa9f3..9dc67dcdf4eb098305c64658889e0fa9a2493da6 100644 (file)
@@ -1099,7 +1099,7 @@ disconnect_session (struct Session *session)
        GNUNET_SERVER_receive_done (session->client,
                                    GNUNET_SYSERR);     
     }
-  if (session->client != NULL) 
+  else if (session->client != NULL)
     GNUNET_SERVER_client_drop (session->client);
   GNUNET_STATISTICS_update (session->plugin->env->stats,
                            gettext_noop ("# TCP sessions active"),
@@ -1150,7 +1150,7 @@ select_better_session (struct Session *s1,
  * gnunet-nat-client to send dummy ICMP responses.
  *
  * @param plugin the plugin for this transport
- * @param addr the address of the peer (IPv4-only)
+ * @param sa the address of the peer (IPv4-only)
  */
 static void
 run_gnunet_nat_client (struct Plugin *plugin, 
@@ -1195,6 +1195,8 @@ run_gnunet_nat_client (struct Plugin *plugin,
                                  inet4,
                                  port_as_string, 
                                  NULL);
+  if (NULL == proc)
+    return;
   /* we know that the gnunet-nat-client will terminate virtually
      instantly */
   GNUNET_OS_process_wait (proc);
@@ -2020,6 +2022,7 @@ delayed_done (void *cls,
   session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK;
   delay = session->plugin->env->receive (session->plugin->env->cls,
                                         &session->target,
+                                        NULL,
                                         NULL, 0,
                                         session,
                                         NULL, 0);
@@ -2076,7 +2079,14 @@ handle_tcp_data (void *cls,
                            gettext_noop ("# bytes received via TCP"),
                            ntohs (message->size),
                            GNUNET_NO);
-  delay = plugin->env->receive (plugin->env->cls, &session->target, message, 1,
+  struct GNUNET_TRANSPORT_ATS_Information distance[2];
+  distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+  distance[0].value = htonl (1);
+  distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
+  distance[1].value = htonl (0);
+  delay = plugin->env->receive (plugin->env->cls, &session->target, message,
+                               (const struct GNUNET_TRANSPORT_ATS_Information *) &distance,
+                               2,
                                session,
                                (GNUNET_YES == session->inbound) ? NULL : session->connect_addr,
                                (GNUNET_YES == session->inbound) ? 0 : session->connect_alen);
@@ -2326,7 +2336,7 @@ tcp_plugin_server_read (void *cls,
   struct TCPProbeContext *tcp_probe_ctx;
   struct GNUNET_CONNECTION_Handle *sock;
 
-  if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
+  if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
     return;
   memset (mybuf, 0, sizeof(mybuf));
   bytes = GNUNET_DISK_file_read(plugin->server_stdout_handle, 
@@ -2340,6 +2350,7 @@ tcp_plugin_server_read (void *cls,
                       "Finished reading from server stdout with code: %d\n", 
                       bytes);
 #endif
+      /* FIXME: consider process_wait here? */
       return;
     }
 
@@ -2361,7 +2372,6 @@ tcp_plugin_server_read (void *cls,
   /* construct socket address of sender */
   memset (&sin_addr, 0, sizeof (sin_addr));
   sin_addr.sin_family = AF_INET;
-  sin_addr.sin_port = htons((uint16_t) port);
 #if HAVE_SOCKADDR_IN_SIN_LEN
   sin_addr.sin_len = sizeof (sin_addr);
 #endif
@@ -2381,7 +2391,7 @@ tcp_plugin_server_read (void *cls,
                                          plugin);
       return;
     }
-
+  sin_addr.sin_port = htons((uint16_t) port);
 #if DEBUG_TCP_NAT
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
                   "tcp",
@@ -3010,7 +3020,8 @@ libgnunet_plugin_transport_tcp_done (void *cls)
       GNUNET_free (tcp_probe);
     }
 
-  if (plugin->behind_nat == GNUNET_YES)
+  if ((plugin->behind_nat == GNUNET_YES) &&
+      (plugin->enable_nat_server == GNUNET_YES))
     {
       if (0 != GNUNET_OS_process_kill (plugin->server_proc, SIGTERM))
         GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");