gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r19572 - gnunet/src/transport
Date: Tue, 31 Jan 2012 16:35:00 +0100

Author: wachs
Date: 2012-01-31 16:35:00 +0100 (Tue, 31 Jan 2012)
New Revision: 19572

Modified:
   gnunet/src/transport/plugin_transport_udp_new.c
Log:
- implemented andtested timeout mechanism


Modified: gnunet/src/transport/plugin_transport_udp_new.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp_new.c     2012-01-31 13:46:10 UTC 
(rev 19571)
+++ gnunet/src/transport/plugin_transport_udp_new.c     2012-01-31 15:35:00 UTC 
(rev 19572)
@@ -216,6 +216,9 @@
   struct GNUNET_FRAGMENT_Context * frag;
   struct Session * session;
 
+  struct GNUNET_TIME_Absolute timeout;
+
+
   /**
    * Function to call upon completion of the transmission.
    */
@@ -237,6 +240,9 @@
   struct UDPMessageWrapper *next;
   struct UDPMessage *udp;
   size_t msg_size;
+
+  struct GNUNET_TIME_Absolute timeout;
+
   /**
    * Function to call upon completion of the transmission.
    */
@@ -774,8 +780,8 @@
   udpw->msg_size = msg_len;
   udpw->cont = frag_ctx->cont;
   udpw->cont_cls = frag_ctx->cont_cls;
+  udpw->timeout = frag_ctx->timeout;
   udpw->frag = frag_ctx;
-
   memcpy (udpw->udp, msg, msg_len);
 
   GNUNET_CONTAINER_DLL_insert(plugin->msg_head, plugin->msg_tail, udpw);
@@ -858,9 +864,11 @@
     udpw->session = s;
     udpw->udp = (struct UDPMessage *) &udpw[1];
     udpw->msg_size = mlen;
+    udpw->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to);
     udpw->cont = cont;
     udpw->cont_cls = cont_cls;
     udpw->frag = NULL;
+
     memcpy (udpw->udp, udp, sizeof (struct UDPMessage));
     memcpy (&udpw->udp[1], msgbuf, msgbuf_size);
 
@@ -877,6 +885,7 @@
     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->bytes_to_send = mlen;
     frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats,
               UDP_MTU,
@@ -1313,10 +1322,52 @@
 {
   ssize_t sent;
   size_t slen;
+  struct GNUNET_TIME_Absolute max;
+  struct GNUNET_TIME_Absolute ;
 
   struct UDPMessageWrapper *udpw = plugin->msg_head;
   const struct sockaddr * sa = udpw->session->sock_addr;
 
+  max = GNUNET_TIME_absolute_max(udpw->timeout, GNUNET_TIME_absolute_get());
+
+  while (udpw != NULL)
+  {
+    if (max.abs_value != udpw->timeout.abs_value)
+    {
+      /* Message timed out */
+
+      if (udpw->cont != NULL)
+        udpw->cont (udpw->cont_cls, &udpw->session->target, GNUNET_SYSERR);
+      if (udpw->frag != NULL)
+      {
+#if DEBUG_UDP
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fragmendted message for peer 
`%s' with size %u timed out\n",
+            GNUNET_i2s(&udpw->session->target), udpw->frag->bytes_to_send);
+#endif
+        GNUNET_FRAGMENT_context_destroy(udpw->frag->frag);
+      }
+      else
+      {
+#if DEBUG_UDP
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message for peer `%s' with size 
%u timed out\n",
+            GNUNET_i2s(&udpw->session->target), udpw->msg_size);
+#endif
+      }
+
+      GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, udpw);
+      GNUNET_free (udpw);
+      udpw = plugin->msg_head;
+    }
+    else
+      break;
+  }
+
+  if (udpw == NULL)
+  {
+    /* No message left */
+    return 0;
+  }
+
   switch (sa->sa_family)
   {
   case AF_INET:




reply via email to

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