- fix coverity
[oweals/gnunet.git] / src / transport / plugin_transport_udp.c
index 0bcfcb46bee56812a2c039a5755322ca415861be..a999897cc00dca618a8c0b867663ff1c22a4cf38 100644 (file)
@@ -1,6 +1,6 @@
 /*
  This file is part of GNUnet
- Copyright (C) 2010-2015 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2010-2015 GNUnet e.V.
 
  GNUnet is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
@@ -728,11 +728,9 @@ udp_plugin_get_network_for_address (void *cls,
  * Then reschedule this function to be called again once more is available.
  *
  * @param cls the plugin handle
- * @param tc the scheduling context (for rescheduling this function again)
  */
 static void
-udp_plugin_select_v4 (void *cls,
-                      const struct GNUNET_SCHEDULER_TaskContext *tc);
+udp_plugin_select_v4 (void *cls);
 
 
 /**
@@ -741,11 +739,9 @@ udp_plugin_select_v4 (void *cls,
  * Then reschedule this function to be called again once more is available.
  *
  * @param cls the plugin handle
- * @param tc the scheduling context (for rescheduling this function again)
  */
 static void
-udp_plugin_select_v6 (void *cls,
-                      const struct GNUNET_SCHEDULER_TaskContext *tc);
+udp_plugin_select_v6 (void *cls);
 
 
 /**
@@ -787,7 +783,7 @@ schedule_select_v4 (struct Plugin *plugin)
                     "Calculated flow delay for UDPv4 at %s for %s\n",
                     GNUNET_STRINGS_relative_time_to_string (min_delay,
                                                             GNUNET_YES),
-                    GNUNET_i2s (&udpw->session->target));
+                    GNUNET_i2s (&min_udpw->session->target));
       }
       else
       {
@@ -795,7 +791,7 @@ schedule_select_v4 (struct Plugin *plugin)
                     "Calculated flow delay for UDPv4 at %s for %s\n",
                     GNUNET_STRINGS_relative_time_to_string (min_delay,
                                                             GNUNET_YES),
-                    GNUNET_i2s (&udpw->session->target));
+                    GNUNET_i2s (&min_udpw->session->target));
       }
     }
     plugin->select_task_v4
@@ -844,7 +840,7 @@ schedule_select_v6 (struct Plugin *plugin)
                     "Calculated flow delay for UDPv6 at %s for %s\n",
                     GNUNET_STRINGS_relative_time_to_string (min_delay,
                                                             GNUNET_YES),
-                    GNUNET_i2s (&udpw->session->target));
+                    GNUNET_i2s (&min_udpw->session->target));
       }
       else
       {
@@ -852,7 +848,7 @@ schedule_select_v6 (struct Plugin *plugin)
                     "Calculated flow delay for UDPv6 at %s for %s\n",
                     GNUNET_STRINGS_relative_time_to_string (min_delay,
                                                             GNUNET_YES),
-                    GNUNET_i2s (&udpw->session->target));
+                    GNUNET_i2s (&min_udpw->session->target));
       }
     }
     plugin->select_task_v6
@@ -1825,6 +1821,10 @@ qc_fragment_sent (void *cls,
   GNUNET_assert (NULL != udpw->frag_ctx);
   if (GNUNET_OK == result)
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Fragment of message with %u bytes transmitted to %s\n",
+                (unsigned int) udpw->payload_size,
+                GNUNET_i2s (&udpw->session->target));
     GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag);
     GNUNET_STATISTICS_update (plugin->env->stats,
                               "# UDP, fragmented msgs, fragments, sent, success",
@@ -1837,6 +1837,10 @@ qc_fragment_sent (void *cls,
   }
   else
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Failed to transmit fragment of message with %u bytes to %s\n",
+                (unsigned int) udpw->payload_size,
+                GNUNET_i2s (&udpw->session->target));
     fragmented_message_done (udpw->frag_ctx,
                              GNUNET_SYSERR);
     GNUNET_STATISTICS_update (plugin->env->stats,
@@ -1892,6 +1896,10 @@ enqueue_fragment (void *cls,
           msg_len);
   enqueue (plugin,
            udpw);
+  if (session->address->address_length == sizeof (struct IPv4UdpAddress))
+    schedule_select_v4 (plugin);
+  else
+    schedule_select_v6 (plugin);
 }
 
 
@@ -2102,6 +2110,10 @@ udp_plugin_send (void *cls,
                               "# UDP, unfragmented bytes payload queued total",
                               msgbuf_size,
                               GNUNET_NO);
+    if (s->address->address_length == sizeof (struct IPv4UdpAddress))
+      schedule_select_v4 (plugin);
+    else
+      schedule_select_v6 (plugin);
   }
   else
   {
@@ -2167,10 +2179,6 @@ udp_plugin_send (void *cls,
   notify_session_monitor (s->plugin,
                           s,
                           GNUNET_TRANSPORT_SS_UPDATE);
-  if (s->address->address_length == sizeof (struct IPv4UdpAddress))
-    schedule_select_v4 (plugin);
-  else
-    schedule_select_v6 (plugin);
   return udpmlen;
 }
 
@@ -2554,11 +2562,9 @@ udp_disconnect (void *cls,
  * Session was idle, so disconnect it.
  *
  * @param cls the `struct GNUNET_ATS_Session` to time out
- * @param tc scheduler context
  */
 static void
-session_timeout (void *cls,
-                 const struct GNUNET_SCHEDULER_TaskContext *tc)
+session_timeout (void *cls)
 {
   struct GNUNET_ATS_Session *s = cls;
   struct Plugin *plugin = s->plugin;
@@ -3133,7 +3139,7 @@ udp_select_read (struct Plugin *plugin,
   if (size != ntohs (msg->size))
   {
     LOG (GNUNET_ERROR_TYPE_WARNING,
-         "UDP malformed message header from %s\n",
+         "UDP malformed message (size %u) header from %s\n",
          (unsigned int) size,
          GNUNET_a2s (sa,
                      fromlen));
@@ -3504,19 +3510,17 @@ udp_select_send (struct Plugin *plugin,
  * Then reschedule this function to be called again once more is available.
  *
  * @param cls the plugin handle
- * @param tc the scheduling context
  */
 static void
-udp_plugin_select_v4 (void *cls,
-                      const struct GNUNET_SCHEDULER_TaskContext *tc)
+udp_plugin_select_v4 (void *cls)
 {
   struct Plugin *plugin = cls;
-
+  const struct GNUNET_SCHEDULER_TaskContext *tc;
+  
   plugin->select_task_v4 = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   if (NULL == plugin->sockv4)
     return;
+  tc = GNUNET_SCHEDULER_get_task_context ();
   if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
       (GNUNET_NETWORK_fdset_isset (tc->read_ready,
                                    plugin->sockv4)))
@@ -3534,19 +3538,17 @@ udp_plugin_select_v4 (void *cls,
  * Then reschedule this function to be called again once more is available.
  *
  * @param cls the plugin handle
- * @param tc the scheduling context
  */
 static void
-udp_plugin_select_v6 (void *cls,
-                      const struct GNUNET_SCHEDULER_TaskContext *tc)
+udp_plugin_select_v6 (void *cls)
 {
   struct Plugin *plugin = cls;
+  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   plugin->select_task_v6 = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   if (NULL == plugin->sockv6)
     return;
+  tc = GNUNET_SCHEDULER_get_task_context ();
   if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
        (GNUNET_NETWORK_fdset_isset (tc->read_ready,
                                     plugin->sockv6)) )