-some fixes for monkey
[oweals/gnunet.git] / src / transport / plugin_transport_tcp.c
index a426215692e7b74f2d1090872e33ac1dbb4a6264..208ddad68220de4cc67f3d9fe4869b4fb5f1edab 100644 (file)
@@ -223,6 +223,11 @@ struct PendingMessage
  */
 struct Session
 {
+  /**
+   * To whom are we talking to (set to our identity
+   * if we are still waiting for the welcome message)
+   */
+  struct GNUNET_PeerIdentity target;
 
   /**
    * API requirement.
@@ -261,12 +266,6 @@ struct Session
    */
   struct GNUNET_SERVER_TransmitHandle *transmit_handle;
 
-  /**
-   * To whom are we talking to (set to our identity
-   * if we are still waiting for the welcome message)
-   */
-  struct GNUNET_PeerIdentity target;
-
   /**
    * ID of task used to delay receiving more to throttle sender.
    */
@@ -488,8 +487,9 @@ plugin_tcp_access_check (void *cls,
 {
   struct Plugin *plugin = cls;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Accepting new incoming TCP connection\n");
+  LOG (GNUNET_ERROR_TYPE_ERROR,
+       "Accepting new incoming TCP connection from `%s'\n",
+       GNUNET_a2s (addr, addrlen));
   if (0 == plugin->max_connections)
     return GNUNET_NO;
   plugin->max_connections--;
@@ -542,7 +542,7 @@ tcp_nat_port_map_callback (void *cls, int add_remove,
     return;
   }
   /* modify our published address list */
-  plugin->env->notify_address (plugin->env->cls, add_remove, arg, args);
+  plugin->env->notify_address (plugin->env->cls, add_remove, arg, args, "tcp");
 }
 
 
@@ -1403,7 +1403,7 @@ tcp_plugin_get_session (void *cls,
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, 
         "Failed to create connection to `%4s' at `%s'\n",
-        GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs));
+        GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs));
     return NULL;
   }
   plugin->max_connections--;
@@ -1707,7 +1707,7 @@ handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client,
   const struct sockaddr_in *s4;
   const struct sockaddr_in6 *s6;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "received NAT probe\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received NAT probe\n");
 
   /* We have received a TCP NAT probe, meaning we (hopefully) initiated
    * a connection to this peer by running gnunet-nat-client.  This peer
@@ -2189,8 +2189,8 @@ session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Session %p was idle for %llu, disconnecting\n",
-             s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
+             "Session %p was idle for %llu ms, disconnecting\n",
+             s, (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
   /* call session destroy function */
   disconnect_session(s);
 }
@@ -2207,10 +2207,9 @@ start_session_timeout (struct Session *s)
   s->timeout_task =  GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
                                                    &session_timeout,
                                                    s);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
-             "Timeout for session %p set to %llu\n",
-             s, 
-             GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Timeout for session %p set to %llu ms\n",
+             s,  (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
 }
 
 
@@ -2221,21 +2220,15 @@ static void
 reschedule_session_timeout (struct Session *s)
 {
   GNUNET_assert (NULL != s);
-  if (GNUNET_SCHEDULER_NO_TASK == s->timeout_task)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
-               "Timeout for peer `%s' %s not scheduled\n",
-               GNUNET_i2s (&s->target), 
-               tcp_address_to_string(NULL, s->addr, s->addrlen));
-    return;
-  }
+  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task);
+
   GNUNET_SCHEDULER_cancel (s->timeout_task);
   s->timeout_task =  GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
                                                    &session_timeout,
                                                    s);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout rescheduled for session %p set to %llu\n",
-             s,
-             (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Timeout rescheduled for session %p set to %llu ms\n",
+             s, (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
 }
 
 
@@ -2246,19 +2239,14 @@ static void
 stop_session_timeout (struct Session *s)
 {
   GNUNET_assert (NULL != s);
+
   if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task)
   {
     GNUNET_SCHEDULER_cancel (s->timeout_task);
     s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
-               "Timeout rescheduled for session %p canceled\n",
-               s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
-  }
-  else
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
-               "Timeout for session %p was not active\n",
-               s);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Timeout stopped for session %p canceled\n",
+                s, (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
   }
 }