gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r30399 - gnunet/src/mesh
Date: Thu, 24 Oct 2013 04:04:48 +0200

Author: bartpolot
Date: 2013-10-24 04:04:48 +0200 (Thu, 24 Oct 2013)
New Revision: 30399

Modified:
   gnunet/src/mesh/gnunet-service-mesh_connection.c
   gnunet/src/mesh/gnunet-service-mesh_connection.h
   gnunet/src/mesh/gnunet-service-mesh_peer.c
   gnunet/src/mesh/gnunet-service-mesh_peer.h
   gnunet/src/mesh/gnunet-service-mesh_tunnel.c
Log:
- fix leaks
- refactor to simplify APIs


Modified: gnunet/src/mesh/gnunet-service-mesh_connection.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-23 16:18:28 UTC 
(rev 30398)
+++ gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-24 02:04:48 UTC 
(rev 30399)
@@ -35,7 +35,6 @@
 #include "gnunet-service-mesh_connection.h"
 #include "gnunet-service-mesh_peer.h"
 #include "gnunet-service-mesh_tunnel.h"
-#include "gnunet-service-mesh_channel.h"
 
 
 #define LOG(level, ...) GNUNET_log_from (level,"mesh-con",__VA_ARGS__)
@@ -418,7 +417,7 @@
   msg.ack = htonl (ack);
   msg.cid = c->id;
 
-  GMC_send_prebuilt_message (&msg.header, c, NULL, !fwd);
+  GMC_send_prebuilt_message (&msg.header, c, !fwd);
 }
 
 
@@ -493,7 +492,7 @@
   }
   p->idx = (p->idx + 1) % AVG_MSGS;
 
-//   if (NULL != c->t)
+//   if (NULL != c->t) FIXME
 //   {
 //     c->t->pending_messages--;
 //     if (GNUNET_YES == c->t->destroy && 0 == t->pending_messages)
@@ -517,6 +516,8 @@
 {
   GNUNET_PEER_Id id;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Get prev hop, own pos %u\n", c->own_pos);
+  path_debug (c->path);
   if (0 == c->own_pos || c->path->length < 2)
     id = c->path->peers[0];
   else
@@ -596,7 +597,7 @@
  * or a first CONNECTION_ACK directed to us.
  *
  * @param connection Connection to confirm.
- * @param fwd Should we send it FWD?
+ * @param fwd Should we send it FWD? (root->dest)
  *            (First (~SYNACK) goes BCK, second (~ACK) goes FWD)
  */
 static void
@@ -605,12 +606,12 @@
   struct MeshTunnel3 *t;
 
   t = connection->t;
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection ack\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection %s ACK\n",
+       !fwd ? "FWD" : "BCK");
   GMP_queue_add (get_hop (connection, fwd), NULL,
                  GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK,
                  sizeof (struct GNUNET_MESH_ConnectionACK),
-                 connection, NULL, fwd,
-                 &message_sent, NULL);
+                 connection, fwd, &message_sent, NULL);
   if (MESH_TUNNEL3_NEW == GMT_get_state (t))
     GMT_change_state (t, MESH_TUNNEL3_WAITING);
   if (MESH_CONNECTION_READY != connection->state)
@@ -639,7 +640,7 @@
   msg.cid = c->id;
   msg.peer1 = *id1;
   msg.peer2 = *id2;
-  GMC_send_prebuilt_message (&msg.header, c, NULL, fwd);
+  GMC_send_prebuilt_message (&msg.header, c, fwd);
 }
 
 
@@ -670,7 +671,7 @@
   msg->header.type = htons (type);
   msg->cid = c->id;
 
-  GMC_send_prebuilt_message (&msg->header, c, NULL, fwd);
+  GMC_send_prebuilt_message (&msg->header, c, fwd);
 }
 
 
@@ -846,7 +847,7 @@
   msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_POLL);
   msg.header.size = htons (sizeof (msg));
   LOG (GNUNET_ERROR_TYPE_DEBUG, " *** pid (%u)!\n", fc->last_pid_sent);
-  GMC_send_prebuilt_message (&msg.header, c, NULL, fc == &c->fwd_fc);
+  GMC_send_prebuilt_message (&msg.header, c, fc == &c->fwd_fc);
   fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time);
   fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time,
                                                 &connection_poll, fc);
@@ -1141,7 +1142,7 @@
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  Retransmitting.\n");
     GMP_add_path (dest_peer, path_duplicate (path), GNUNET_NO);
     GMP_add_path_to_origin (orig_peer, path, GNUNET_NO);
-    GMC_send_prebuilt_message (message, c, NULL, GNUNET_YES);
+    GMC_send_prebuilt_message (message, c, GNUNET_YES);
   }
   return GNUNET_OK;
 }
@@ -1238,7 +1239,7 @@
   }
 
   LOG (GNUNET_ERROR_TYPE_DEBUG, "  not for us, retransmitting...\n");
-  GMC_send_prebuilt_message (message, c, NULL, fwd);
+  GMC_send_prebuilt_message (message, c, fwd);
   return GNUNET_OK;
 }
 
@@ -1287,7 +1288,7 @@
   }
   else
   {
-    GMC_send_prebuilt_message (message, c, NULL, fwd);
+    GMC_send_prebuilt_message (message, c, fwd);
     c->destroy = GNUNET_YES;
   }
 
@@ -1338,7 +1339,7 @@
     GNUNET_break_op (0);
     return GNUNET_OK;
   }
-  GMC_send_prebuilt_message (message, c, NULL, fwd);
+  GMC_send_prebuilt_message (message, c, fwd);
   c->destroy = GNUNET_YES;
 
   return GNUNET_OK;
@@ -1467,7 +1468,7 @@
   }
   GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO);
 
-  GMC_send_prebuilt_message (&msg->header, c, NULL, fwd);
+  GMC_send_prebuilt_message (&msg->header, c, fwd);
 
   return GNUNET_OK;
 }
@@ -1689,7 +1690,7 @@
     return GNUNET_OK;
 
   GNUNET_STATISTICS_update (stats, "# keepalives forwarded", 1, GNUNET_NO);
-  GMC_send_prebuilt_message (message, c, NULL, fwd);
+  GMC_send_prebuilt_message (message, c, fwd);
 
   return GNUNET_OK;
 }
@@ -1867,6 +1868,10 @@
   GNUNET_STATISTICS_update (stats, "# connections", -1, GNUNET_NO);
   if (NULL != c->t)
     GMT_remove_connection (c->t, c);
+
+  if (GNUNET_NO == GMC_is_origin (c, GNUNET_YES))
+    path_destroy (c->path);
+
   GNUNET_free (c);
 }
 
@@ -2021,14 +2026,19 @@
     GMC_destroy (c);
     return;
   }
-  send_broken (c, &my_full_id, GMP_get_id (peer), fwd);
-  connection_cancel_queues (c, !fwd);
+  if (GNUNET_NO == c->destroy)
+    send_broken (c, &my_full_id, GMP_get_id (peer), fwd);
 
   /* Connection will have at least one pending message
    * (the one we just scheduled), so no point in checking whether to
    * destroy immediately. */
   c->destroy = GNUNET_YES;
 
+  /**
+   * Cancel all queues, if no message is left, connection will be destroyed.
+   */
+  connection_cancel_queues (c, !fwd);
+
   return;
 }
 
@@ -2094,13 +2104,11 @@
  * @param message Message to send. Function makes a copy of it.
  *                If message is not hop-by-hop, decrements TTL of copy.
  * @param c Connection on which this message is transmitted.
- * @param ch Channel on which this message is transmitted, or NULL.
  * @param fwd Is this a fwd message?
  */
 void
 GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
                            struct MeshConnection *c,
-                           struct MeshChannel *ch,
                            int fwd)
 {
   struct MeshFlowControl *fc;
@@ -2199,7 +2207,7 @@
 
   c->pending_messages++;
 
-  GMP_queue_add (get_hop (c, fwd), data, type, size, c, ch, fwd,
+  GMP_queue_add (get_hop (c, fwd), data, type, size, c, fwd,
                  &message_sent, NULL);
 }
 
@@ -2221,8 +2229,7 @@
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n");
   GMP_queue_add (get_next_hop (connection), NULL,
                  GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE,
-                 size, connection, NULL,
-                 GNUNET_YES, &message_sent, NULL);
+                 size, connection, GNUNET_YES, &message_sent, NULL);
   state = GMT_get_state (connection->t);
   if (MESH_TUNNEL3_SEARCHING == state || MESH_TUNNEL3_NEW == state)
     GMT_change_state (connection->t, MESH_TUNNEL3_WAITING);
@@ -2256,9 +2263,9 @@
               GMC_2s (c));
 
   if (GNUNET_NO == GMC_is_terminal (c, GNUNET_YES))
-    GMC_send_prebuilt_message (&msg.header, c, NULL, GNUNET_YES);
+    GMC_send_prebuilt_message (&msg.header, c, GNUNET_YES);
   if (GNUNET_NO == GMC_is_terminal (c, GNUNET_NO))
-    GMC_send_prebuilt_message (&msg.header, c, NULL, GNUNET_NO);
+    GMC_send_prebuilt_message (&msg.header, c, GNUNET_NO);
   c->destroy = GNUNET_YES;
 }
 

Modified: gnunet/src/mesh/gnunet-service-mesh_connection.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_connection.h    2013-10-23 16:18:28 UTC 
(rev 30398)
+++ gnunet/src/mesh/gnunet-service-mesh_connection.h    2013-10-24 02:04:48 UTC 
(rev 30399)
@@ -223,6 +223,8 @@
  * @param t Tunnel this connection belongs to (or NULL);
  * @param p Path this connection has to use.
  * @param own_pos Own position in the @c p path.
+ *
+ * @return Newly created connection, NULL in case of error (own id not in 
path).
  */
 struct MeshConnection *
 GMC_new (const struct GNUNET_HashCode *cid,
@@ -398,13 +400,11 @@
  * @param message Message to send. Function makes a copy of it.
  *                If message is not hop-by-hop, decrements TTL of copy.
  * @param c Connection on which this message is transmitted.
- * @param ch Channel on which this message is transmitted, or NULL.
  * @param fwd Is this a fwd message?
  */
 void
 GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
                            struct MeshConnection *c,
-                           struct MeshChannel *ch,
                            int fwd);
 
 /**

Modified: gnunet/src/mesh/gnunet-service-mesh_peer.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_peer.c  2013-10-23 16:18:28 UTC (rev 
30398)
+++ gnunet/src/mesh/gnunet-service-mesh_peer.c  2013-10-24 02:04:48 UTC (rev 
30399)
@@ -30,7 +30,6 @@
 #include "gnunet-service-mesh_peer.h"
 #include "gnunet-service-mesh_dht.h"
 #include "gnunet-service-mesh_connection.h"
-#include "gnunet-service-mesh_local.h"
 #include "gnunet-service-mesh_tunnel.h"
 #include "mesh_path.h"
 
@@ -71,11 +70,6 @@
   int fwd;
 
     /**
-     * Channel this message belongs to, if known.
-     */
-  struct MeshChannel *ch;
-
-    /**
      * Pointer to info stucture used as cls.
      */
   void *cls;
@@ -967,14 +961,13 @@
  * @param type Type of the message, 0 for a raw message.
  * @param size Size of the message.
  * @param c Connection this message belongs to (cannot be NULL).
- * @param ch Channel this message belongs to, if applicable (otherwise NULL).
  * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
  * @param cont Continuation to be called once CORE has taken the message.
  * @param cont_cls Closure for @c cont.
  */
 void
 GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
-               struct MeshConnection *c, struct MeshChannel *ch, int fwd,
+               struct MeshConnection *c, int fwd,
                GMP_sent cont, void *cont_cls)
 {
   struct MeshPeerQueue *queue;
@@ -982,8 +975,9 @@
   int call_core;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-              "queue add %s %s (%u) on c %p, ch %p\n",
-              fwd ? "FWD" : "BCK",  GNUNET_MESH_DEBUG_M2S (type), size, c, ch);
+       "queue add %s %s towards %s (size %u) on c %p (%s)\n",
+       fwd ? "FWD" : "BCK",  GNUNET_MESH_DEBUG_M2S (type), GMP_2s(peer),
+       size, c, GMC_2s (c));
   GNUNET_assert (NULL != c);
 
   if (NULL == peer->connections)
@@ -1010,7 +1004,6 @@
   queue->size = size;
   queue->peer = peer;
   queue->c = c;
-  queue->ch = ch;
   queue->fwd = fwd;
   queue->callback = cont;
   queue->callback_cls = cont_cls;
@@ -1447,36 +1440,42 @@
  * Add the path to the peer and update the path used to reach it in case this
  * is the shortest.
  *
- * @param peer_info Destination peer to add the path to.
+ * @param peer Destination peer to add the path to.
  * @param path New path to add. Last peer must be the peer in arg 1.
  *             Path will be either used of freed if already known.
  * @param trusted Do we trust that this path is real?
+ *
+ * @return path if path was taken, pointer to existing duplicate if exists
+ *         NULL on error.
  */
-void
-GMP_add_path (struct MeshPeer *peer_info, struct MeshPeerPath *path,
+struct MeshPeerPath *
+GMP_add_path (struct MeshPeer *peer, struct MeshPeerPath *path,
               int trusted)
 {
   struct MeshPeerPath *aux;
   unsigned int l;
   unsigned int l2;
 
-  if ((NULL == peer_info) || (NULL == path))
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "adding path [%u] to peer %s\n",
+       path->length, GMP_2s (peer));
+
+  if ((NULL == peer) || (NULL == path))
   {
     GNUNET_break (0);
     path_destroy (path);
-    return;
+    return NULL;
   }
-  if (path->peers[path->length - 1] != peer_info->id)
+  if (path->peers[path->length - 1] != peer->id)
   {
     GNUNET_break (0);
     path_destroy (path);
-    return;
+    return NULL;
   }
   if (2 >= path->length && GNUNET_NO == trusted)
   {
     /* Only allow CORE to tell us about direct paths */
     path_destroy (path);
-    return;
+    return NULL;
   }
   for (l = 1; l < path->length; l++)
   {
@@ -1487,45 +1486,47 @@
       {
         path->peers[l2] = path->peers[l + l2];
       }
-            path->length -= l;
-            l = 1;
-            path->peers =
-                      GNUNET_realloc (path->peers, path->length * sizeof 
(GNUNET_PEER_Id));
+      path->length -= l;
+      l = 1;
+      path->peers = GNUNET_realloc (path->peers,
+                                    path->length * sizeof (GNUNET_PEER_Id));
     }
   }
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "adding path [%u] to peer %s\n",
-              path->length, GMP_2s (peer_info));
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "adding path [%u]\n", path->length);
 
   l = path_get_length (path);
   if (0 == l)
   {
     path_destroy (path);
-    return;
+    return NULL;
   }
 
-  GNUNET_assert (peer_info->id == path->peers[path->length - 1]);
-  for (aux = peer_info->path_head; aux != NULL; aux = aux->next)
+  GNUNET_assert (peer->id == path->peers[path->length - 1]);
+  for (aux = peer->path_head; aux != NULL; aux = aux->next)
   {
     l2 = path_get_length (aux);
     if (l2 > l)
     {
-      GNUNET_CONTAINER_DLL_insert_before (peer_info->path_head,
-                                          peer_info->path_tail, aux, path);
-      return;
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "  added\n");
+      GNUNET_CONTAINER_DLL_insert_before (peer->path_head,
+                                          peer->path_tail, aux, path);
+      return path;
     }
-        else
-        {
-          if (l2 == l && memcmp (path->peers, aux->peers, l) == 0)
-          {
-            path_destroy (path);
-            return;
-          }
-        }
+    else
+    {
+      if (l2 == l && memcmp (path->peers, aux->peers, l) == 0)
+      {
+        LOG (GNUNET_ERROR_TYPE_DEBUG, "  already known\n");
+        path_destroy (path);
+        return aux;
+      }
+    }
   }
-  GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head, peer_info->path_tail,
+  GNUNET_CONTAINER_DLL_insert_tail (peer->path_head, peer->path_tail,
                                     path);
-  return;
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "  added last\n");
+  return path;
 }
 
 
@@ -1539,16 +1540,19 @@
  * @param path New path to add after being inversed.
  *             Path will be either used or freed.
  * @param trusted Do we trust that this path is real?
+ *
+ * @return path if path was taken, pointer to existing duplicate if exists
+ *         NULL on error.
  */
-void
+struct MeshPeerPath *
 GMP_add_path_to_origin (struct MeshPeer *peer,
                         struct MeshPeerPath *path,
                         int trusted)
 {
   if (NULL == path)
-    return;
+    return NULL;
   path_invert (path);
-  GMP_add_path (peer, path, trusted);
+  return GMP_add_path (peer, path, trusted);
 }
 
 

Modified: gnunet/src/mesh/gnunet-service-mesh_peer.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_peer.h  2013-10-23 16:18:28 UTC (rev 
30398)
+++ gnunet/src/mesh/gnunet-service-mesh_peer.h  2013-10-24 02:04:48 UTC (rev 
30399)
@@ -123,14 +123,13 @@
  * @param type Type of the message, 0 for a raw message.
  * @param size Size of the message.
  * @param c Connection this message belongs to (cannot be NULL).
- * @param ch Channel this message belongs to, if applicable (otherwise NULL).
  * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
  * @param cont Continuation to be called once CORE has taken the message.
  * @param cont_cls Closure for @c cont.
  */
 void
 GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
-               struct MeshConnection *c, struct MeshChannel *ch, int fwd,
+               struct MeshConnection *c, int fwd,
                GMP_sent cont, void *cont_cls);
 
 /**
@@ -194,12 +193,15 @@
  * Add the path to the peer and update the path used to reach it in case this
  * is the shortest.
  *
- * @param peer_info Destination peer to add the path to.
+ * @param peer Destination peer to add the path to.
  * @param path New path to add. Last peer must be the peer in arg 1.
  *             Path will be either used of freed if already known.
  * @param trusted Do we trust that this path is real?
+ *
+ * @return path if path was taken, pointer to existing duplicate if exists
+ *         NULL on error.
  */
-void
+struct MeshPeerPath *
 GMP_add_path (struct MeshPeer *peer, struct MeshPeerPath *p, int trusted);
 
 /**
@@ -212,8 +214,11 @@
  * @param path New path to add after being inversed.
  *             Path will be either used or freed.
  * @param trusted Do we trust that this path is real?
+ *
+ * @return path if path was taken, pointer to existing duplicate if exists
+ *         NULL on error.
  */
-void
+struct MeshPeerPath *
 GMP_add_path_to_origin (struct MeshPeer *peer,
                         struct MeshPeerPath *path,
                         int trusted);

Modified: gnunet/src/mesh/gnunet-service-mesh_tunnel.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_tunnel.c        2013-10-23 16:18:28 UTC 
(rev 30398)
+++ gnunet/src/mesh/gnunet-service-mesh_tunnel.c        2013-10-24 02:04:48 UTC 
(rev 30399)
@@ -118,11 +118,6 @@
   MESH_ChannelNumber next_chid;
 
   /**
-   * Pending message count.
-   */
-  int pending_messages;
-
-  /**
    * Destroy flag: if true, destroy on last message.
    */
   int destroy;
@@ -848,10 +843,7 @@
     GMC_send_destroy (iter->c);
   }
 
-  if (0 == t->pending_messages)
-    GMT_destroy (t);
-  else
-    t->destroy = GNUNET_YES;
+  t->destroy = GNUNET_YES;
 }
 
 
@@ -1249,7 +1241,7 @@
   uint64_t iv;
   uint16_t type;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "GMT Send on Tunnel %s\n", GMP_2s (t->peer));
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "GMT Send on Tunnel %s\n", GMT_2s (t));
 
   iv = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, UINT64_MAX);
   msg = (struct GNUNET_MESH_Encrypted *) cbuf;
@@ -1280,8 +1272,7 @@
   }
   msg->reserved = 0;
 
-  t->pending_messages++;
-  GMC_send_prebuilt_message (&msg->header, c, ch, fwd);
+  GMC_send_prebuilt_message (&msg->header, c, fwd);
 }
 
 /**




reply via email to

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