gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r31318 - gnunet/src/mesh
Date: Thu, 12 Dec 2013 17:25:18 +0100

Author: bartpolot
Date: 2013-12-12 17:25:18 +0100 (Thu, 12 Dec 2013)
New Revision: 31318

Modified:
   gnunet/src/mesh/gnunet-service-mesh_channel.c
   gnunet/src/mesh/gnunet-service-mesh_tunnel.c
Log:
- simplify tunnel delayed queue


Modified: gnunet/src/mesh/gnunet-service-mesh_channel.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_channel.c       2013-12-12 16:24:25 UTC 
(rev 31317)
+++ gnunet/src/mesh/gnunet-service-mesh_channel.c       2013-12-12 16:25:18 UTC 
(rev 31318)
@@ -69,7 +69,7 @@
   /**
    * Tunnel Queue.
    */
-  struct MeshTunnel3Queue *q;
+  struct MeshTunnel3Queue *tq;
 
   /**
    * Message type (DATA/DATA_ACK)
@@ -117,7 +117,7 @@
   /**
    * Tunnel Queue.
    */
-  struct MeshChannelQueue       *q;
+  struct MeshChannelQueue       *chq;
 
     /**
      * When was this message issued (to calculate ACK delay)
@@ -728,15 +728,15 @@
                  struct MeshTunnel3Queue *q,
                  uint16_t type, size_t size)
 {
-  struct MeshChannelQueue *ch_q = cls;
-  struct MeshReliableMessage *copy = ch_q->copy;
+  struct MeshChannelQueue *chq = cls;
+  struct MeshReliableMessage *copy = chq->copy;
   struct MeshChannelReliability *rel;
 
-  switch (ch_q->type)
+  switch (chq->type)
   {
     case GNUNET_MESSAGE_TYPE_MESH_DATA:
       LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! SENT DATA MID %u\n", copy->mid);
-      GNUNET_assert (ch_q == copy->q);
+      GNUNET_assert (chq == copy->chq);
       copy->timestamp = GNUNET_TIME_absolute_get ();
       rel = copy->rel;
       if (GNUNET_SCHEDULER_NO_TASK == rel->retry_task)
@@ -767,16 +767,16 @@
       {
         LOG (GNUNET_ERROR_TYPE_DEBUG, "!! retry task %u\n", rel->retry_task);
       }
-      copy->q = NULL;
+      copy->chq = NULL;
       break;
 
 
     case GNUNET_MESSAGE_TYPE_MESH_DATA_ACK:
     case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE:
     case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK:
-      LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! SENT %s\n", GM_m2s (ch_q->type));
-      rel = ch_q->rel;
-      GNUNET_assert (rel->uniq == ch_q);
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! SENT %s\n", GM_m2s (chq->type));
+      rel = chq->rel;
+      GNUNET_assert (rel->uniq == chq);
       rel->uniq = NULL;
 
       if (MESH_CHANNEL_READY != rel->ch->state
@@ -797,7 +797,7 @@
       GNUNET_break (0);
   }
 
-  GNUNET_free (ch_q);
+  GNUNET_free (chq);
 }
 
 
@@ -935,7 +935,7 @@
     next = copy->next;
     GNUNET_CONTAINER_DLL_remove (rel->head_recv, rel->tail_recv, copy);
     LOG (GNUNET_ERROR_TYPE_DEBUG, " COPYFREE BATCH RECV %p\n", copy);
-    GNUNET_break (NULL == copy->q);
+    GNUNET_break (NULL == copy->chq);
     GNUNET_free (copy);
   }
   for (copy = rel->head_sent; NULL != copy; copy = next)
@@ -943,24 +943,24 @@
     next = copy->next;
     GNUNET_CONTAINER_DLL_remove (rel->head_sent, rel->tail_sent, copy);
     LOG (GNUNET_ERROR_TYPE_DEBUG, " COPYFREE BATCH %p\n", copy);
-    if (NULL != copy->q)
+    if (NULL != copy->chq)
     {
-      if (NULL != copy->q->q)
+      if (NULL != copy->chq->tq)
       {
-        GMT_cancel (copy->q->q);
+        GMT_cancel (copy->chq->tq);
         /* ch_message_sent will free copy->q */
       }
       else
       {
-        GNUNET_free (copy->q);
+        GNUNET_free (copy->chq);
         GNUNET_break (0);
       }
     }
     GNUNET_free (copy);
   }
-  if (NULL != rel->uniq && NULL != rel->uniq->q)
+  if (NULL != rel->uniq && NULL != rel->uniq->tq)
   {
-    GMT_cancel (rel->uniq->q);
+    GMT_cancel (rel->uniq->tq);
     /* ch_message_sent is called freeing uniq */
   }
   if (GNUNET_SCHEDULER_NO_TASK != rel->retry_task)
@@ -1088,9 +1088,9 @@
     LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! batch free, ignoring timing\n");
   }
   rel->ch->pending_messages--;
-  if (NULL != copy->q)
+  if (NULL != copy->chq)
   {
-    GMT_cancel (copy->q->q);
+    GMT_cancel (copy->chq->tq);
     /* copy->q is set to NULL by ch_message_sent */
   }
   GNUNET_CONTAINER_DLL_remove (rel->head_sent, rel->tail_sent, copy);
@@ -1147,7 +1147,7 @@
   }
   else if (NULL != rel->uniq)
   {
-    GMT_cancel (rel->uniq->q);
+    GMT_cancel (rel->uniq->tq);
     /* ch_message_sent will free and NULL uniq */
   }
   else
@@ -2021,7 +2021,7 @@
     {
       GNUNET_SCHEDULER_cancel (rel->retry_task);
       rel->retry_task = GNUNET_SCHEDULER_NO_TASK;
-      if (NULL != rel->head_sent && NULL == rel->head_sent->q)
+      if (NULL != rel->head_sent && NULL == rel->head_sent->chq)
       {
         struct GNUNET_TIME_Absolute new_target;
         struct GNUNET_TIME_Relative delay;
@@ -2233,7 +2233,7 @@
                             struct MeshChannel *ch, int fwd,
                             void *existing_copy)
 {
-  struct MeshChannelQueue *q;
+  struct MeshChannelQueue *chq;
   uint16_t type;
 
   type = ntohs (message->type);
@@ -2253,14 +2253,14 @@
 
       if (GNUNET_YES == ch->reliable)
       {
-        q = GNUNET_new (struct MeshChannelQueue);
-        q->type = type;
+        chq = GNUNET_new (struct MeshChannelQueue);
+        chq->type = type;
         if (NULL == existing_copy)
-          q->copy = channel_save_copy (ch, message, fwd);
+          chq->copy = channel_save_copy (ch, message, fwd);
         else
         {
-          q->copy = (struct MeshReliableMessage *) existing_copy;
-          if (NULL != q->copy->q)
+          chq->copy = (struct MeshReliableMessage *) existing_copy;
+          if (NULL != chq->copy->chq)
           {
             /* Last retransmission was queued but not yet sent!
              * This retransmission was scheduled by a ch_message_sent which
@@ -2271,7 +2271,7 @@
              * retransmission leaves the peer and ch_message_sent starts
              * the timer for the next one.
              */
-            GNUNET_free (q);
+            GNUNET_free (chq);
             LOG (GNUNET_ERROR_TYPE_DEBUG,
                  "  exisitng copy not yet transmitted!\n");
             return;
@@ -2279,15 +2279,15 @@
           LOG (GNUNET_ERROR_TYPE_DEBUG,
                "  using existing copy: %p {r:%p q:%p t:%u}\n",
                existing_copy,
-               q->copy->rel, q->copy->q, q->copy->type);
+               chq->copy->rel, chq->copy->chq, chq->copy->type);
         }
-        LOG (GNUNET_ERROR_TYPE_DEBUG, "  new q: %p\n", q);
-        q->copy->q = q;
-        q->q = GMT_send_prebuilt_message (message, ch->t,
+        LOG (GNUNET_ERROR_TYPE_DEBUG, "  new chq: %p\n", chq);
+            chq->copy->chq = chq;
+            chq->tq = GMT_send_prebuilt_message (message, ch->t,
                                           NULL != existing_copy,
-                                          &ch_message_sent, q);
+                                          &ch_message_sent, chq);
         /* q itself is stored in copy */
-        GNUNET_assert (NULL != q->q || GNUNET_NO != ch->destroy);
+        GNUNET_assert (NULL != chq->tq || GNUNET_NO != ch->destroy);
       }
       else
       {
@@ -2306,24 +2306,25 @@
       /* fall-trough */
     case GNUNET_MESSAGE_TYPE_MESH_DATA_ACK:
     case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE:
-      q = GNUNET_new (struct MeshChannelQueue);
-      q->type = type;
-      q->rel = fwd ? ch->root_rel : ch->dest_rel;
-      if (NULL != q->rel->uniq)
+      chq = GNUNET_new (struct MeshChannelQueue);
+      chq->type = type;
+      chq->rel = fwd ? ch->root_rel : ch->dest_rel;
+      if (NULL != chq->rel->uniq)
       {
-        if (NULL != q->rel->uniq->q)
+        if (NULL != chq->rel->uniq->tq)
         {
-          GMT_cancel (q->rel->uniq->q);
+          GMT_cancel (chq->rel->uniq->tq);
           /* ch_message_sent is called, freeing and NULLing uniq */
         }
         else
         {
-          GNUNET_free (q->rel->uniq);
+          GNUNET_break (0);
+          GNUNET_free (chq->rel->uniq);
         }
       }
-      q->q = GMT_send_prebuilt_message (message, ch->t, GNUNET_YES,
-                                        &ch_message_sent, q);
-      q->rel->uniq = q;
+      chq->tq = GMT_send_prebuilt_message (message, ch->t, GNUNET_YES,
+                                           &ch_message_sent, chq);
+      chq->rel->uniq = chq;
       break;
 
 

Modified: gnunet/src/mesh/gnunet-service-mesh_tunnel.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_tunnel.c        2013-12-12 16:24:25 UTC 
(rev 31317)
+++ gnunet/src/mesh/gnunet-service-mesh_tunnel.c        2013-12-12 16:25:18 UTC 
(rev 31318)
@@ -162,9 +162,10 @@
    */
   struct MeshTunnel3 *t;
 
-  struct MeshTunnel3Queue *q;
-  GMT_sent cont;
-  void *cont_cls;
+  /**
+   * Tunnel queue given to the channel to cancel request. Update on 
send_queued.
+   */
+  struct MeshTunnel3Queue *tq;
 
   /**
    * Message to send.
@@ -181,12 +182,12 @@
   /**
    * Connection queue handle, to cancel if necessary.
    */
-  struct MeshConnectionQueue *q;
+  struct MeshConnectionQueue *cq;
 
   /**
    * Handle in case message hasn't been given to a connection yet.
    */
-  struct MeshTunnelDelayed *tq;
+  struct MeshTunnelDelayed *tqd;
 
   /**
    * Continuation to call once sent.
@@ -653,8 +654,7 @@
  * @param msg Message itself (copy will be made).
  */
 static struct MeshTunnelDelayed *
-queue_data (struct MeshTunnel3 *t, const struct GNUNET_MessageHeader *msg,
-            GMT_sent cont, void *cont_cls)
+queue_data (struct MeshTunnel3 *t, const struct GNUNET_MessageHeader *msg)
 {
   struct MeshTunnelDelayed *tq;
   uint16_t size = ntohs (msg->size);
@@ -670,8 +670,6 @@
   tq = GNUNET_malloc (sizeof (struct MeshTunnelDelayed) + size);
 
   tq->t = t;
-  tq->cont = cont;
-  tq->cont_cls = cont_cls;
   memcpy (&tq[1], msg, size);
   GNUNET_CONTAINER_DLL_insert_tail (t->tq_head, t->tq_tail, tq);
   return tq;
@@ -700,11 +698,10 @@
                        GMT_sent cont, void *cont_cls,
                        struct MeshTunnel3Queue *existing_q)
 {
-  struct MeshTunnel3Queue *q;
+  struct MeshTunnel3Queue *tq;
   struct MeshConnection *c;
   struct GNUNET_MESH_Encrypted *msg;
   size_t size = ntohs (message->size);
-  size_t encrypted_size;
   char cbuf[sizeof (struct GNUNET_MESH_Encrypted) + size];
   uint32_t iv;
   uint16_t type;
@@ -715,10 +712,12 @@
   if (GNUNET_NO == is_ready (t))
   {
     GNUNET_assert (NULL == existing_q);
-    q = GNUNET_new (struct MeshTunnel3Queue);
-    q->tq = queue_data (t, message, cont, cont_cls);
-    q->tq->q = q;
-    return q;
+    tq = GNUNET_new (struct MeshTunnel3Queue);
+    tq->tqd = queue_data (t, message);
+    tq->tqd->tq = tq;
+    tq->cont = cont;
+    tq->cont_cls = cont_cls;
+    return tq;
   }
 
   GNUNET_assert (GNUNET_NO == GMT_is_loopback (t));
@@ -727,9 +726,8 @@
   msg = (struct GNUNET_MESH_Encrypted *) cbuf;
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED);
   msg->iv = iv;
-  encrypted_size = t_encrypt (t, &msg[1], message, size, iv);
-  msg->header.size = htons (sizeof (struct GNUNET_MESH_Encrypted)
-  + encrypted_size);
+  GNUNET_assert (t_encrypt (t, &msg[1], message, size, iv) == size);
+  msg->header.size = htons (sizeof (struct GNUNET_MESH_Encrypted) + size);
   c = tunnel_get_connection (t);
   if (NULL == c)
   {
@@ -762,19 +760,19 @@
   }
   if (NULL == existing_q)
   {
-    q = GNUNET_new (struct MeshTunnel3Queue); /* FIXME valgrind: leak*/
+    tq = GNUNET_new (struct MeshTunnel3Queue); /* FIXME valgrind: leak*/
   }
   else
   {
-    q = existing_q;
-    q->tq = NULL;
+    tq = existing_q;
+    tq->tqd = NULL;
   }
-  q->q = GMC_send_prebuilt_message (&msg->header, c, fwd, force,
-                                    &message_sent, q);
-  q->cont = cont;
-  q->cont_cls = cont_cls;
+  tq->cq = GMC_send_prebuilt_message (&msg->header, c, fwd, force,
+                                  &message_sent, tq);
+  tq->cont = cont;
+  tq->cont_cls = cont_cls;
 
-  return q;
+  return tq;
 }
 
 
@@ -786,7 +784,7 @@
 static void
 send_queued_data (struct MeshTunnel3 *t)
 {
-  struct MeshTunnelDelayed *tq;
+  struct MeshTunnelDelayed *tqd;
   struct MeshTunnelDelayed *next;
   unsigned int room;
 
@@ -810,18 +808,17 @@
   room = GMT_get_connections_buffer (t);
   LOG (GNUNET_ERROR_TYPE_DEBUG, "  buffer space: %u\n", room);
   LOG (GNUNET_ERROR_TYPE_DEBUG, "  tq head: %p\n", t->tq_head);
-  for (tq = t->tq_head; NULL != tq && room > 0; tq = next)
+  for (tqd = t->tq_head; NULL != tqd && room > 0; tqd = next)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, " sending queued data\n");
-    next = tq->next;
+    next = tqd->next;
     room--;
-    send_prebuilt_message ((struct GNUNET_MessageHeader *) &tq[1],
-                           tq->t, GNUNET_YES, tq->cont, tq->cont_cls, tq->q);
-    unqueue_data (tq);
+    send_prebuilt_message ((struct GNUNET_MessageHeader *) &tqd[1],
+                               tqd->t, GNUNET_YES,
+                           tqd->tq->cont, tqd->tq->cont_cls, tqd->tq);
+    unqueue_data (tqd);
   }
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "GMT_send_queued_data end\n",
-       GMP_2s (t->peer));
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "GMT_send_queued_data end\n", GMP_2s 
(t->peer));
 }
 
 
@@ -2274,14 +2271,14 @@
 void
 GMT_cancel (struct MeshTunnel3Queue *q)
 {
-  if (NULL != q->q)
+  if (NULL != q->cq)
   {
-    GMC_cancel (q->q);
+    GMC_cancel (q->cq);
     /* message_sent() will be called and free q */
   }
-  else if (NULL != q->tq)
+  else if (NULL != q->tqd)
   {
-    unqueue_data (q->tq);
+    unqueue_data (q->tqd);
   }
   else
   {




reply via email to

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