gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r19941 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r19941 - gnunet/src/transport
Date: Wed, 22 Feb 2012 17:15:57 +0100

Author: wachs
Date: 2012-02-22 17:15:57 +0100 (Wed, 22 Feb 2012)
New Revision: 19941

Modified:
   gnunet/src/transport/plugin_transport_udp.c
   gnunet/src/transport/plugin_transport_udp.h
Log:
- separated sending for ipv4 and v6


Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2012-02-22 16:12:41 UTC (rev 
19940)
+++ gnunet/src/transport/plugin_transport_udp.c 2012-02-22 16:15:57 UTC (rev 
19941)
@@ -550,13 +550,13 @@
     s->frag_ctx = NULL;
   }
 
-  udpw = plugin->msg_head;
+  udpw = plugin->ipv4_queue_head;
   while (udpw != NULL)
   {
     next = udpw->next;
     if (udpw->session == s)
     {
-      GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, udpw);
+      GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, 
plugin->ipv4_queue_tail, udpw);
 
       if (udpw->cont != NULL)
         udpw->cont (udpw->cont_cls, &s->target, GNUNET_SYSERR);
@@ -565,6 +565,21 @@
     udpw = next;
   }
 
+  udpw = plugin->ipv6_queue_head;
+  while (udpw != NULL)
+  {
+    next = udpw->next;
+    if (udpw->session == s)
+    {
+      GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, 
plugin->ipv6_queue_tail, udpw);
+
+      if (udpw->cont != NULL)
+        udpw->cont (udpw->cont_cls, &s->target, GNUNET_SYSERR);
+      GNUNET_free (udpw);
+    }
+    udpw = next;
+  }
+
   GNUNET_assert (GNUNET_YES ==
                  GNUNET_CONTAINER_multihashmap_remove (plugin->sessions,
                                                        &s->target.hashPubKey,
@@ -776,6 +791,15 @@
   return s;
 }
 
+static void enqueue (struct Plugin *plugin, struct UDPMessageWrapper * udpw)
+{
+
+  if (udpw->session->addrlen == sizeof (struct sockaddr_in))
+    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);
+}
+
 /**
  * Function that is called with messages created by the fragmentation
  * module.  In the case of the 'proc' callback of the
@@ -809,7 +833,8 @@
   udpw->frag_ctx = frag_ctx;
   memcpy (udpw->udp, msg, msg_len);
 
-  GNUNET_CONTAINER_DLL_insert(plugin->msg_head, plugin->msg_tail, udpw);
+  enqueue (plugin, udpw);
+
 }
 
 
@@ -896,7 +921,7 @@
     memcpy (udpw->udp, udp, sizeof (struct UDPMessage));
     memcpy (&udpw->udp[sizeof (struct UDPMessage)], msgbuf, msgbuf_size);
 
-    GNUNET_CONTAINER_DLL_insert(plugin->msg_head, plugin->msg_tail, udpw);
+    enqueue (plugin, udpw);
   }
   else
   {
@@ -1218,7 +1243,7 @@
   udp_ack->sender = *rc->plugin->env->my_identity;
   memcpy (&udp_ack[1], msg, ntohs (msg->size));
 
-  GNUNET_CONTAINER_DLL_insert(rc->plugin->msg_head, rc->plugin->msg_tail, 
udpw);
+  enqueue (rc->plugin, udpw);
 }
 
 
@@ -1301,16 +1326,33 @@
 #endif
   s->last_expected_delay = GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag);
 
-  struct UDPMessageWrapper * udpw = plugin->msg_head;
-  while (udpw!= NULL)
+  struct UDPMessageWrapper * udpw = NULL;
+  if (s->addrlen == sizeof (struct sockaddr_in6))
   {
-    if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == s->frag_ctx))
+    udpw = plugin->ipv6_queue_head;
+    while (udpw!= NULL)
     {
-      GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, udpw);
-      GNUNET_free (udpw);
+      if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == s->frag_ctx))
+      {
+        GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, 
plugin->ipv6_queue_tail, udpw);
+        GNUNET_free (udpw);
+      }
+      udpw = udpw->next;
     }
-    udpw = udpw->next;
   }
+  if (s->addrlen == sizeof (struct sockaddr_in))
+  {
+    udpw = plugin->ipv4_queue_head;
+    while (udpw!= NULL)
+    {
+      if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == s->frag_ctx))
+      {
+        GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, 
plugin->ipv4_queue_tail, udpw);
+        GNUNET_free (udpw);
+      }
+      udpw = udpw->next;
+    }
+  }
 
   if (s->frag_ctx->cont != NULL)
     s->frag_ctx->cont
@@ -1458,15 +1500,28 @@
 }
 
 size_t
-udp_select_send (struct Plugin *plugin)
+udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
 {
   ssize_t sent;
   size_t slen;
   struct GNUNET_TIME_Absolute max;
   struct GNUNET_TIME_Absolute ;
 
-  struct UDPMessageWrapper *udpw = plugin->msg_head;
+  struct UDPMessageWrapper *udpw = NULL;
+
+  if (sock == plugin->sockv4)
+  {
+    udpw = plugin->ipv4_queue_head;
+  }
+  else if (sock == plugin->sockv6)
+  {
+    udpw = plugin->ipv6_queue_head;
+  }
+  else
+    GNUNET_break (0);
+
   const struct sockaddr * sa = udpw->session->sock_addr;
+  slen = udpw->session->addrlen;
 
   max = GNUNET_TIME_absolute_max(udpw->timeout, GNUNET_TIME_absolute_get());
 
@@ -1496,9 +1551,13 @@
 #endif
       }
 
-      GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, udpw);
+      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);
+
       GNUNET_free (udpw);
-      udpw = plugin->msg_head;
+      udpw = plugin->ipv4_queue_head;
     }
     else
     {
@@ -1528,26 +1587,8 @@
     return 0;
   }
 
-  switch (sa->sa_family)
-  {
-  case AF_INET:
-    if (NULL == plugin->sockv4)
-      return 0;
-    sent =
-        GNUNET_NETWORK_socket_sendto (plugin->sockv4, udpw->udp, 
udpw->msg_size,
-                                      sa, slen = sizeof (struct sockaddr_in));
-    break;
-  case AF_INET6:
-    if (NULL == plugin->sockv6)
-      return 0;
-    sent =
-        GNUNET_NETWORK_socket_sendto (plugin->sockv6, udpw->udp, 
udpw->msg_size,
-                                      sa, slen = sizeof (struct sockaddr_in6));
-    break;
-  default:
-    GNUNET_break (0);
-    return 0;
-  }
+  sent = GNUNET_NETWORK_socket_sendto (sock, udpw->udp, udpw->msg_size, sa, 
slen);
+
   if (GNUNET_SYSERR == sent)
   {
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
@@ -1575,8 +1616,12 @@
       udpw->cont (udpw->cont_cls, &udpw->session->target, GNUNET_OK);
   }
 
-  GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, udpw);
+  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);
   GNUNET_free (udpw);
+  udpw = NULL;
 
   return sent;
 }
@@ -1610,8 +1655,16 @@
 
   if ((tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0)
   {
-    if (plugin->msg_head != NULL)
-      udp_select_send (plugin);
+    if ((NULL != plugin->sockv4) && (plugin->ipv4_queue_head != NULL) &&
+      (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv4)))
+      {
+        udp_select_send (plugin, plugin->sockv4);
+      }
+    if ((NULL != plugin->sockv6) && (plugin->ipv6_queue_head != NULL) &&
+      (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv6)))
+      {
+        udp_select_send (plugin, plugin->sockv6);
+      }
   }
 
   plugin->select_task = GNUNET_SCHEDULER_add_select 
(GNUNET_SCHEDULER_PRIORITY_DEFAULT,
@@ -1990,16 +2043,27 @@
   }
 
   /* Clean up leftover messages */
-  struct UDPMessageWrapper *udpw = plugin->msg_head;
+  struct UDPMessageWrapper * updw;
+  udpw = plugin->ipv4_queue_head;
   while (udpw != NULL)
   {
     struct UDPMessageWrapper *tmp = udpw->next;
-    GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, udpw);
+    GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, 
plugin->ipv4_queue_tail, udpw);
     if (udpw->cont != NULL)
       udpw->cont (udpw->cont_cls, &udpw->session->target, GNUNET_SYSERR);
     GNUNET_free (udpw);
     udpw = tmp;
   }
+  udpw = plugin->ipv6_queue_head;
+  while (udpw != NULL)
+  {
+    struct UDPMessageWrapper *tmp = udpw->next;
+    GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, 
plugin->ipv6_queue_tail, udpw);
+    if (udpw->cont != NULL)
+      udpw->cont (udpw->cont_cls, &udpw->session->target, GNUNET_SYSERR);
+    GNUNET_free (udpw);
+    udpw = tmp;
+  }
 
   /* Clean up sessions */
 #if DEBUG_UDP

Modified: gnunet/src/transport/plugin_transport_udp.h
===================================================================
--- gnunet/src/transport/plugin_transport_udp.h 2012-02-22 16:12:41 UTC (rev 
19940)
+++ gnunet/src/transport/plugin_transport_udp.h 2012-02-22 16:15:57 UTC (rev 
19941)
@@ -251,9 +251,11 @@
    */
   uint16_t aport;
 
-  struct UDPMessageWrapper *msg_head;
-  struct UDPMessageWrapper *msg_tail;
+  struct UDPMessageWrapper *ipv4_queue_head;
+  struct UDPMessageWrapper *ipv4_queue_tail;
 
+  struct UDPMessageWrapper *ipv6_queue_head;
+  struct UDPMessageWrapper *ipv6_queue_tail;
 };
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]