gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r32938 - gnunet/src/mesh


From: gnunet
Subject: [GNUnet-SVN] r32938 - gnunet/src/mesh
Date: Mon, 7 Apr 2014 19:55:01 +0200

Author: bartpolot
Date: 2014-04-07 19:55:01 +0200 (Mon, 07 Apr 2014)
New Revision: 32938

Modified:
   gnunet/src/mesh/gnunet-service-mesh_channel.c
Log:
- refactor, check for existing copy

Modified: gnunet/src/mesh/gnunet-service-mesh_channel.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_channel.c       2014-04-07 17:39:43 UTC 
(rev 32937)
+++ gnunet/src/mesh/gnunet-service-mesh_channel.c       2014-04-07 17:55:01 UTC 
(rev 32938)
@@ -357,6 +357,30 @@
 
 
 /**
+ * Save a copy of the data message for later retransmission.
+ *
+ * @param msg Message to copy.
+ * @param mid Message ID.
+ * @param rel Reliability data for retransmission.
+ */
+static struct MeshReliableMessage *
+copy_message (const struct GNUNET_MESH_Data *msg, uint32_t mid,
+              struct MeshChannelReliability *rel)
+{
+  struct MeshReliableMessage *copy;
+  uint16_t size;
+
+  size = ntohs (msg->header.size);
+  copy = GNUNET_malloc (sizeof (*copy) + size);
+  copy->mid = mid;
+  copy->rel = rel;
+  copy->type = GNUNET_MESSAGE_TYPE_MESH_DATA;
+  memcpy (&copy[1], msg, size);
+
+  return copy;
+}
+
+/**
  * We have received a message out of order, or the client is not ready.
  * Buffer it until we receive an ACK from the client or the missing
  * message from the channel.
@@ -371,19 +395,11 @@
   struct MeshReliableMessage *copy;
   struct MeshReliableMessage *prev;
   uint32_t mid;
-  uint16_t size;
 
-  size = ntohs (msg->header.size);
   mid = ntohl (msg->mid);
 
   LOG (GNUNET_ERROR_TYPE_DEBUG, "add_buffered_data %u\n", mid);
 
-  copy = GNUNET_malloc (sizeof (*copy) + size);
-  copy->mid = mid;
-  copy->rel = rel;
-  copy->type = GNUNET_MESSAGE_TYPE_MESH_DATA;
-  memcpy (&copy[1], msg, size);
-
   rel->n_recv++;
 
   // FIXME do something better than O(n), although n < 64...
@@ -391,17 +407,24 @@
   for (prev = rel->head_recv; NULL != prev; prev = prev->next)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, " prev %u\n", prev->mid);
-    if (GM_is_pid_bigger (prev->mid, mid))
+    if (prev->mid == mid)
     {
+      LOG (GNUNET_ERROR_TYPE_DEBUG, " already there!\n");
+      return;
+    }
+    else if (GM_is_pid_bigger (prev->mid, mid))
+    {
       LOG (GNUNET_ERROR_TYPE_DEBUG, " bingo!\n");
+      copy = copy_message (msg, mid, rel);
       GNUNET_CONTAINER_DLL_insert_before (rel->head_recv, rel->tail_recv,
                                           prev, copy);
       return;
     }
   }
-    LOG (GNUNET_ERROR_TYPE_DEBUG, " insert at tail!\n");
-    GNUNET_CONTAINER_DLL_insert_tail (rel->head_recv, rel->tail_recv, copy);
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "add_buffered_data END\n");
+  copy = copy_message (msg, mid, rel);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, " insert at tail!\n");
+  GNUNET_CONTAINER_DLL_insert_tail (rel->head_recv, rel->tail_recv, copy);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "add_buffered_data END\n");
 }
 
 
@@ -797,7 +820,6 @@
       }
       break;
 
-
     default:
       GNUNET_break (0);
   }




reply via email to

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