-fix NPE
[oweals/gnunet.git] / src / transport / gnunet-service-transport_clients.c
index f00f7c93f403e4c44c59a4cbe5fa86ee220e8078..8c1ca61e5bfa6754089f39899489278d9f932964 100644 (file)
@@ -688,6 +688,11 @@ struct SendTransmitContinuationContext
    * Peer that was the target.
    */
   struct GNUNET_PeerIdentity target;
+
+  /**
+   * At what time did we receive the message?
+   */
+  struct GNUNET_TIME_Absolute send_time;
 };
 
 
@@ -708,16 +713,45 @@ handle_send_transmit_continuation (void *cls,
 {
   struct SendTransmitContinuationContext *stcc = cls;
   struct SendOkMessage send_ok_msg;
+  struct GNUNET_TIME_Relative delay;
+  const struct GNUNET_HELLO_Address *addr;
 
-  send_ok_msg.header.size = htons (sizeof (send_ok_msg));
-  send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
-  send_ok_msg.bytes_msg = htonl (bytes_payload);
-  send_ok_msg.bytes_physical = htonl (bytes_on_wire);
-  send_ok_msg.success = htonl (success);
-  send_ok_msg.peer = stcc->target;
-  GST_clients_unicast (stcc->client,
-                       &send_ok_msg.header,
-                       GNUNET_NO);
+  delay = GNUNET_TIME_absolute_get_duration (stcc->send_time);
+  addr = GST_neighbour_get_current_address (&stcc->target);
+  if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
+                GNUNET_STRINGS_relative_time_to_string (delay,
+                                                        GNUNET_YES),
+                (unsigned int) bytes_payload,
+                (unsigned int) bytes_on_wire,
+                GNUNET_i2s (&stcc->target),
+                success,
+                (NULL != addr) ? addr->transport_name : "%");
+  else
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
+                GNUNET_STRINGS_relative_time_to_string (delay,
+                                                        GNUNET_YES),
+                (unsigned int) bytes_payload,
+                (unsigned int) bytes_on_wire,
+                GNUNET_i2s (&stcc->target),
+                success,
+                (NULL != addr) ? addr->transport_name : "%");
+
+  if (GST_neighbours_test_connected (&stcc->target))
+  {
+    /* Only send confirmation if we are still connected */
+    send_ok_msg.header.size = htons (sizeof (send_ok_msg));
+    send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
+    send_ok_msg.bytes_msg = htonl (bytes_payload);
+    send_ok_msg.bytes_physical = htonl (bytes_on_wire);
+    send_ok_msg.success = htonl (success);
+    send_ok_msg.peer = stcc->target;
+    GST_clients_unicast (stcc->client,
+                         &send_ok_msg.header,
+                         GNUNET_NO);
+  }
   GNUNET_SERVER_client_drop (stcc->client);
   GNUNET_free (stcc);
 }
@@ -796,6 +830,7 @@ clients_handle_send (void *cls,
   stcc = GNUNET_new (struct SendTransmitContinuationContext);
   stcc->target = obm->peer;
   stcc->client = client;
+  stcc->send_time = GNUNET_TIME_absolute_get ();
   GNUNET_SERVER_client_keep (client);
   GST_manipulation_send (&obm->peer,
                          obmm,
@@ -1395,7 +1430,7 @@ clients_handle_monitor_validation (void *cls,
  */
 static void
 plugin_session_info_cb (void *cls,
-                       struct Session *session,
+                       struct GNUNET_ATS_Session *session,
                        const struct GNUNET_TRANSPORT_SessionInfo *info)
 {
   struct TransportPluginMonitorMessage *msg;