new operation queue for limiting overlay connects
[oweals/gnunet.git] / src / transport / plugin_transport_udp.c
index 0ecc8154012b3f9bbb2c57ee8c130adb93afc28c..1519fb80e1b15d6f6e028a1083c9b939d150fef6 100644 (file)
@@ -423,6 +423,8 @@ schedule_select (struct Plugin *plugin)
 
   if (NULL != plugin->sockv4)
   {
+    /* Find a message ready to send:
+     * Flow delay from other peer is expired or not set (0) */
     min_delay = GNUNET_TIME_UNIT_FOREVER_REL;
     for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next)
       min_delay = GNUNET_TIME_relative_min (min_delay,
@@ -430,6 +432,10 @@ schedule_select (struct Plugin *plugin)
     
     if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
       GNUNET_SCHEDULER_cancel(plugin->select_task);
+
+    /* Schedule with:
+     * - write active set if message is ready
+     * - timeout minimum delay */
     plugin->select_task =
       GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
                                   (0 == min_delay.rel_value) ? GNUNET_TIME_UNIT_FOREVER_REL : min_delay,
@@ -690,16 +696,15 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result)
       "Calling continuation for %u byte message to `%s' with result %s\n",
       udpw->payload_size, GNUNET_i2s (&udpw->session->target),
       (GNUNET_OK == result) ? "OK" : "SYSERR");
-  if (NULL != udpw->cont)
-  {
-    /* Call continuation for fragmented message */
-    /*
-     * Transport continuation for unfragmented message
-     * send_next_fragment for fragmented message
-     */
-    if (NULL == udpw->frag_ctx)
-    {
-        /* Not fragmented message */
+
+  if (NULL == udpw->frag_ctx)
+  {
+      /* Not fragmented message */
+      if (GNUNET_OK == result)
+      {
+        GNUNET_STATISTICS_update (plugin->env->stats,
+                                  "# unfragmented messages transmit with success via UDP",
+                                  1, GNUNET_NO);
         if (udpw->msg_size >= udpw->payload_size)
         {
             GNUNET_STATISTICS_update (plugin->env->stats,
@@ -709,19 +714,28 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result)
         GNUNET_STATISTICS_update (plugin->env->stats,
                               "# bytes payload transmitted via UDP",
                               udpw->payload_size, GNUNET_NO);
-
-        udpw->cont (udpw->cont_cls, &udpw->session->target, result,
-                    udpw->payload_size, udpw->msg_size);
-    }
-    else if (GNUNET_OK == result)
-    {
-        /* Fragmented message: only call next_fragment continuation on success */
+      }
+      else
+      {
+          GNUNET_STATISTICS_update (plugin->env->stats,
+                                    "# unfragmented messages transmit with failure via UDP",
+                                    1, GNUNET_NO);
+      }
+      if (NULL != udpw->cont)
         udpw->cont (udpw->cont_cls, &udpw->session->target, result,
-                    udpw->payload_size, udpw->msg_size);
-    }
-
+                  udpw->payload_size, udpw->msg_size);
+  }
+  else
+  {
+      /* Fragmented message */
+      if (GNUNET_OK == result)
+      {
+          /* Fragmented message: only call next_fragment continuation on success */
+          if (NULL != udpw->cont)
+            udpw->cont (udpw->cont_cls, &udpw->session->target, result,
+                      udpw->payload_size, udpw->msg_size);
+      }
   }
-
 }
 
 
@@ -819,6 +833,23 @@ free_session (struct Session *s)
 }
 
 
+static void
+dequeue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw)
+{
+  GNUNET_STATISTICS_update (plugin->env->stats,
+                            "# bytes currently in UDP buffers",
+                            -udpw->msg_size, GNUNET_NO);
+  GNUNET_STATISTICS_update (plugin->env->stats,
+                            "# msgs currently in UDP buffers",
+                            -1, GNUNET_NO);
+  if (udpw->session->addrlen == sizeof (struct sockaddr_in))
+    GNUNET_CONTAINER_DLL_remove (plugin->ipv4_queue_head,
+                                 plugin->ipv4_queue_tail, udpw);
+  if (udpw->session->addrlen == sizeof (struct sockaddr_in6))
+    GNUNET_CONTAINER_DLL_remove (plugin->ipv6_queue_head,
+                                 plugin->ipv6_queue_tail, udpw);
+}
+
 /**
  * Functions with this signature are called whenever we need
  * to close a session due to a disconnect or failure to
@@ -845,7 +876,7 @@ disconnect_session (struct Session *s)
     next = udpw->next;
     if (udpw->session == s)
     {
-      GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
+      dequeue (plugin, udpw);
       call_continuation(udpw, GNUNET_SYSERR);
       GNUNET_free (udpw);
     }
@@ -856,7 +887,7 @@ disconnect_session (struct Session *s)
     next = udpw->next;
     if (udpw->session == s)
     {
-      GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
+      dequeue (plugin, udpw);
       call_continuation(udpw, GNUNET_SYSERR);
       GNUNET_free (udpw);
     }
@@ -1058,6 +1089,8 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
   s->target = *target;
   s->sock_addr = (const struct sockaddr *) &s[1];
   s->last_expected_delay = GNUNET_TIME_UNIT_SECONDS;
+  s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO_ABS;
+  s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO;
   start_session_timeout (s);
   return s;
 }
@@ -1186,12 +1219,10 @@ udp_plugin_get_session (void *cls,
                                                     &s->target.hashPubKey,
                                                     s,
                                                     GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
-
   GNUNET_STATISTICS_set(plugin->env->stats,
                         "# UDP sessions active",
                         GNUNET_CONTAINER_multihashmap_size(plugin->sessions),
                         GNUNET_NO);
-
   return s;
 }
 
@@ -1199,14 +1230,22 @@ udp_plugin_get_session (void *cls,
 static void 
 enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw)
 {
-
+  GNUNET_STATISTICS_update (plugin->env->stats,
+                            "# bytes currently in UDP buffers",
+                            udpw->msg_size, GNUNET_NO);
+  GNUNET_STATISTICS_update (plugin->env->stats,
+                            "# msgs currently in UDP buffers",
+                            1, GNUNET_NO);
   if (udpw->session->addrlen == sizeof (struct sockaddr_in))
-    GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
+    GNUNET_CONTAINER_DLL_insert (plugin->ipv4_queue_head,
+                                 plugin->ipv4_queue_tail, udpw);
   if (udpw->session->addrlen == sizeof (struct sockaddr_in6))
-    GNUNET_CONTAINER_DLL_insert(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
+    GNUNET_CONTAINER_DLL_insert (plugin->ipv6_queue_head,
+                                 plugin->ipv6_queue_tail, udpw);
 }
 
 
+
 /**
  * Fragment message was transmitted via UDP, let fragmentation know
  * to send the next fragment now.
@@ -1298,6 +1337,7 @@ udp_plugin_send (void *cls,
 {
   struct Plugin *plugin = cls;
   size_t udpmlen = msgbuf_size + sizeof (struct UDPMessage);
+  struct UDP_FragmentationContext * frag_ctx;
   struct UDP_MessageWrapper * udpw;
   struct UDPMessage *udp;
   char mbuf[udpmlen];
@@ -1324,14 +1364,10 @@ udp_plugin_send (void *cls,
        GNUNET_i2s (&s->target),
        GNUNET_a2s(s->sock_addr, s->addrlen));
   
-  GNUNET_STATISTICS_update (plugin->env->stats,
-                            "# bytes currently in UDP buffers",
-                            msgbuf_size, GNUNET_NO);
   GNUNET_STATISTICS_update (plugin->env->stats,
                             "# bytes payload asked to transmit via UDP",
                             msgbuf_size, GNUNET_NO);
 
-
   /* Message */
   udp = (struct UDPMessage *) mbuf;
   udp->header.size = htons (udpmlen);
@@ -1342,6 +1378,10 @@ udp_plugin_send (void *cls,
   reschedule_session_timeout(s);
   if (udpmlen <= UDP_MTU)
   {
+    /* unfragmented message */
+    GNUNET_STATISTICS_update (plugin->env->stats,
+                              "# unfragmented messages asked to transmit via UDP",
+                              1, GNUNET_NO);
     udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + udpmlen);
     udpw->session = s;
     udpw->msg_buf = (char *) &udpw[1];
@@ -1357,20 +1397,21 @@ udp_plugin_send (void *cls,
   }
   else
   {
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "UDP has to fragment message\n");
+    /* fragmented message */
+    GNUNET_STATISTICS_update (plugin->env->stats,
+                              "# fragmented messages asked to transmit via UDP",
+                              1, GNUNET_NO);
     if  (s->frag_ctx != NULL)
       return GNUNET_SYSERR;
     memcpy (&udp[1], msgbuf, msgbuf_size);
-    struct UDP_FragmentationContext * frag_ctx = GNUNET_malloc(sizeof (struct UDP_FragmentationContext));
-
+    frag_ctx = GNUNET_malloc (sizeof (struct UDP_FragmentationContext));
     frag_ctx->plugin = plugin;
     frag_ctx->session = s;
     frag_ctx->cont = cont;
     frag_ctx->cont_cls = cont_cls;
     frag_ctx->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to);
     frag_ctx->payload_size = msgbuf_size; /* unfragmented message size without UDP overhead */
-    frag_ctx->on_wire_size = 0;
+    frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */
     frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats,
               UDP_MTU,
               &plugin->tracker,
@@ -1667,6 +1708,7 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
        delay);
   udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize);
   udpw->msg_size = msize;
+  udpw->payload_size = 0;
   udpw->session = s;
   udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
   udpw->msg_buf = (char *)&udpw[1];
@@ -1677,6 +1719,10 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
   udp_ack->sender = *rc->plugin->env->my_identity;
   memcpy (&udp_ack[1], msg, ntohs (msg->size));
 
+  GNUNET_STATISTICS_update (plugin->env->stats,
+                            "# messages ACKs transmitted via UDP",
+                            1, GNUNET_NO);
+
   enqueue (rc->plugin, udpw);
 }
 
@@ -1767,7 +1813,7 @@ read_process_ack (struct Plugin *plugin,
       tmp = udpw->next;
       if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == s->frag_ctx))
       {
-        GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
+        dequeue (plugin, udpw);
         GNUNET_free (udpw);
       }
       udpw = tmp;
@@ -1781,7 +1827,7 @@ read_process_ack (struct Plugin *plugin,
       tmp = udpw->next;
       if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == s->frag_ctx))
       {
-        GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
+        dequeue (plugin, udpw);
         GNUNET_free (udpw);
       }
       udpw = tmp;
@@ -1799,7 +1845,6 @@ read_process_ack (struct Plugin *plugin,
                             s->frag_ctx->on_wire_size - s->frag_ctx->payload_size, GNUNET_NO);
   }
 
-
   if (s->frag_ctx->cont != NULL)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1959,146 +2004,160 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
   }
 }
 
-
-static size_t
-udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
+static struct UDP_MessageWrapper *
+remove_timeout_messages_and_select (struct UDP_MessageWrapper *head,
+                                    struct GNUNET_NETWORK_Handle *sock)
 {
-  ssize_t sent;
-  size_t slen;
-  struct GNUNET_TIME_Absolute max;
   struct UDP_MessageWrapper *udpw = NULL;
-  static int network_down_error;
-
-  if (sock == plugin->sockv4)
-  {
-    udpw = plugin->ipv4_queue_head;
-  }
-  else if (sock == plugin->sockv6)
-  {
-    udpw = plugin->ipv6_queue_head;
-  }
-  else
-  {
-    GNUNET_break (0);
-    return 0;
-  }
-
-  const struct sockaddr * sa = udpw->session->sock_addr;
-  slen = udpw->session->addrlen;
-
-  max = GNUNET_TIME_absolute_max (udpw->timeout, GNUNET_TIME_absolute_get());
+  struct GNUNET_TIME_Relative remaining;
 
+  udpw = head;
   while (udpw != NULL)
   {
-    if (max.abs_value != udpw->timeout.abs_value)
+    /* Find messages with timeout */
+    remaining = GNUNET_TIME_absolute_get_remaining (udpw->timeout);
+    if (GNUNET_TIME_UNIT_ZERO.rel_value == remaining.rel_value)
     {
       /* Message timed out */
-      call_continuation(udpw, GNUNET_SYSERR);
-      if (udpw->frag_ctx != NULL)
+      call_continuation (udpw, GNUNET_SYSERR);
+      if (NULL == udpw->frag_ctx)
       {
+        /* Not fragmented message */
         LOG (GNUNET_ERROR_TYPE_DEBUG,
-            "Fragment for message for peer `%s' with size %u timed out\n",
-            GNUNET_i2s(&udpw->session->target), udpw->frag_ctx->payload_size);
-        udpw->session->last_expected_delay = GNUNET_FRAGMENT_context_destroy (udpw->frag_ctx->frag);
-        GNUNET_free (udpw->frag_ctx);
-        udpw->session->frag_ctx = NULL;
+             "Message for peer `%s' with size %u timed out\n",
+             GNUNET_i2s(&udpw->session->target), udpw->payload_size);
       }
       else
       {
-        LOG (GNUNET_ERROR_TYPE_DEBUG, 
-            "Message for peer `%s' with size %u timed out\n",
-            GNUNET_i2s(&udpw->session->target), udpw->payload_size);
+          /* Fragmented message */
+          LOG (GNUNET_ERROR_TYPE_DEBUG,
+               "Fragment for message for peer `%s' with size %u timed out\n",
+               GNUNET_i2s(&udpw->session->target), udpw->frag_ctx->payload_size);
+          udpw->session->last_expected_delay = GNUNET_FRAGMENT_context_destroy (udpw->frag_ctx->frag);
+          GNUNET_free (udpw->frag_ctx);
+          udpw->session->frag_ctx = NULL;
       }
 
+      GNUNET_STATISTICS_update (plugin->env->stats,
+                                "# messages dismissed due to timeout",
+                                1, GNUNET_NO);
+      /* Remove message */
       if (sock == plugin->sockv4)
       {
-        GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
+        dequeue (plugin, udpw);
         GNUNET_free (udpw);
         udpw = plugin->ipv4_queue_head;
       }
-      else if (sock == plugin->sockv6)
+      if (sock == plugin->sockv6)
       {
-        GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
+        dequeue (plugin, udpw);
         GNUNET_free (udpw);
         udpw = plugin->ipv6_queue_head;
       }
     }
     else
     {
-      struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_remaining (udpw->session->flow_delay_from_other_peer);
-      if (delta.rel_value == 0)
+      /* Message did not time out, check flow delay */
+      remaining = GNUNET_TIME_absolute_get_remaining (udpw->session->flow_delay_from_other_peer);
+      if (GNUNET_TIME_UNIT_ZERO.rel_value == remaining.rel_value)
       {
         /* this message is not delayed */
         LOG (GNUNET_ERROR_TYPE_DEBUG, 
-            "Message for peer `%s' (%u bytes) is not delayed \n",
-            GNUNET_i2s(&udpw->session->target), udpw->payload_size);
-        break;
+             "Message for peer `%s' (%u bytes) is not delayed \n",
+             GNUNET_i2s(&udpw->session->target), udpw->payload_size);
+        break; /* Found message to send, break */
       }
       else
       {
-        /* this message is delayed, try next */
+        /* Message is delayed, try next */
         LOG (GNUNET_ERROR_TYPE_DEBUG,
-            "Message for peer `%s' (%u bytes) is delayed for %llu \n",
-            GNUNET_i2s(&udpw->session->target), udpw->payload_size, delta);
+             "Message for peer `%s' (%u bytes) is delayed for %llu \n",
+             GNUNET_i2s(&udpw->session->target), udpw->payload_size, remaining.rel_value);
         udpw = udpw->next;
       }
     }
   }
+  return udpw;
+}
 
-  if (udpw == NULL)
-  {
-    /* No message left */
-    return 0;
-  }
+
+static void
+analyze_send_error (struct Plugin *plugin,
+                    const struct sockaddr * sa,
+                    socklen_t slen,
+                    int error)
+{
+  static int network_down_error;
+  struct GNUNET_ATS_Information type;
+
+ type = plugin->env->get_address_type (plugin->env->cls,sa, slen);
+ if (((GNUNET_ATS_NET_LAN == ntohl(type.value)) || (GNUNET_ATS_NET_WAN == ntohl(type.value))) &&
+     ((ENETUNREACH == errno) || (ENETDOWN == errno)))
+ {
+   if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in)))
+   {
+     /* IPv4: "Network unreachable" or "Network down"
+      *
+      * This indicates we do not have connectivity
+      */
+     LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
+         _("UDP could not transmit message to `%s': "
+           "Network seems down, please check your network configuration\n"),
+         GNUNET_a2s (sa, slen));
+   }
+   if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in6)))
+   {
+     /* IPv6: "Network unreachable" or "Network down"
+      *
+      * This indicates that this system is IPv6 enabled, but does not
+      * have a valid global IPv6 address assigned or we do not have
+      * connectivity
+      */
+
+    LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
+        _("UDP could not transmit message to `%s': "
+          "Please check your network configuration and disable IPv6 if your "
+          "connection does not have a global IPv6 address\n"),
+        GNUNET_a2s (sa, slen));
+   }
+ }
+ else
+ {
+   LOG (GNUNET_ERROR_TYPE_WARNING,
+      "UDP could not transmit message to `%s': `%s'\n",
+      GNUNET_a2s (sa, slen), STRERROR (error));
+ }
+}
+
+static size_t
+udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
+{
+  const struct sockaddr * sa;
+  ssize_t sent;
+  socklen_t slen;
+
+  struct UDP_MessageWrapper *udpw = NULL;
+
+  /* Find message to send */
+  udpw = remove_timeout_messages_and_select ((sock == plugin->sockv4) ? plugin->ipv4_queue_head : plugin->ipv6_queue_head,
+                                             sock);
+  if (NULL == udpw)
+    return 0; /* No message to send */
+
+  sa = udpw->session->sock_addr;
+  slen = udpw->session->addrlen;
 
   sent = GNUNET_NETWORK_socket_sendto (sock, udpw->msg_buf, udpw->msg_size, sa, slen);
 
   if (GNUNET_SYSERR == sent)
   {
-    const struct GNUNET_ATS_Information type = plugin->env->get_address_type
-        (plugin->env->cls,sa, slen);
-
-    if (((GNUNET_ATS_NET_LAN == ntohl(type.value)) || (GNUNET_ATS_NET_WAN == ntohl(type.value))) &&
-        ((ENETUNREACH == errno) || (ENETDOWN == errno)))
-    {
-      if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in)))
-      {
-        /* IPv4: "Network unreachable" or "Network down"
-         *
-         * This indicates we do not have connectivity
-         */
-        LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
-            _("UDP could not transmit message to `%s': "
-              "Network seems down, please check your network configuration\n"),
-            GNUNET_a2s (sa, slen));
-      }
-      if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in6)))
-      {
-        /* IPv6: "Network unreachable" or "Network down"
-         *
-         * This indicates that this system is IPv6 enabled, but does not
-         * have a valid global IPv6 address assigned or we do not have
-         * connectivity
-         */
-
-       LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
-           _("UDP could not transmit message to `%s': "
-            "Please check your network configuration and disable IPv6 if your "
-            "connection does not have a global IPv6 address\n"),
-          GNUNET_a2s (sa, slen));
-      }
-    }
-    else
-    {
-      LOG (GNUNET_ERROR_TYPE_WARNING,
-         "UDP could not transmit %u-byte message to `%s': `%s'\n",
-         (unsigned int) (udpw->payload_size), GNUNET_a2s (sa, slen),
-         STRERROR (errno));
-    }
+    /* Failure */
+    analyze_send_error (plugin, sa, slen, errno);
     call_continuation(udpw, GNUNET_SYSERR);
   }
   else
   {
+    /* Success */
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "UDP transmitted %u-byte message to  `%s' `%s' (%d: %s)\n",
          (unsigned int) (udpw->msg_size), GNUNET_i2s(&udpw->session->target) ,GNUNET_a2s (sa, slen), (int) sent,
@@ -2107,21 +2166,10 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
                               "# bytes transmitted via UDP",
                               sent, GNUNET_NO);
     if (NULL != udpw->frag_ctx)
-    {
         udpw->frag_ctx->on_wire_size += udpw->msg_size;
-    }
     call_continuation (udpw, GNUNET_OK);
-    network_down_error = GNUNET_NO;
   }
-
-  GNUNET_STATISTICS_update (plugin->env->stats,
-                            "# bytes currently in UDP buffers",
-                            -udpw->msg_size, GNUNET_NO);
-
-  if (sock == plugin->sockv4)
-    GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
-  else if (sock == plugin->sockv6)
-    GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
+  dequeue (plugin, udpw);
   GNUNET_free (udpw);
   udpw = NULL;
 
@@ -2588,18 +2636,20 @@ libgnunet_plugin_transport_udp_done (void *cls)
   while (udpw != NULL)
   {
     struct UDP_MessageWrapper *tmp = udpw->next;
-    GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
+    dequeue (plugin, udpw);
     call_continuation(udpw, GNUNET_SYSERR);
     GNUNET_free (udpw);
+
     udpw = tmp;
   }
   udpw = plugin->ipv6_queue_head;
   while (udpw != NULL)
   {
     struct UDP_MessageWrapper *tmp = udpw->next;
-    GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
+    dequeue (plugin, udpw);
     call_continuation(udpw, GNUNET_SYSERR);
     GNUNET_free (udpw);
+
     udpw = tmp;
   }