gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r16988 - gnunet/src/mesh
Date: Wed, 21 Sep 2011 14:59:59 +0200

Author: bartpolot
Date: 2011-09-21 14:59:59 +0200 (Wed, 21 Sep 2011)
New Revision: 16988

Modified:
   gnunet/src/mesh/gnunet-service-mesh.c
   gnunet/src/mesh/mesh_tunnel_tree.c
   gnunet/src/mesh/mesh_tunnel_tree.h
   gnunet/src/mesh/test_mesh_path_api.c
Log:
Renamed functions, make valgrind stop complaining about memory leaks by 
explicitly freeing stuff before exit

Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c       2011-09-21 11:39:40 UTC (rev 
16987)
+++ gnunet/src/mesh/gnunet-service-mesh.c       2011-09-21 12:59:59 UTC (rev 
16988)
@@ -1041,7 +1041,7 @@
     }
     p = p->next;
   }
-  tunnel_add_path (t->tree, best_p, &notify_peer_disconnected);
+  tree_add_path (t->tree, best_p, &notify_peer_disconnected);
   if (GNUNET_SCHEDULER_NO_TASK == t->path_refresh_task)
     t->path_refresh_task =
         GNUNET_SCHEDULER_add_delayed (t->tree->refresh, &path_refresh, t);
@@ -2177,7 +2177,7 @@
   p = path_build_from_dht (get_path, put_path);
   path_add_to_peer (peer_info, p);
   tunnel_add_peer(t, peer_info);
-  p = tunnel_get_path_to_peer(t->tree, peer_info->id);
+  p = tree_get_path_to_peer(t->tree, peer_info->id);
 #if MESH_DEBUG
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "MESH: new route for tunnel 0x%x found, has %u hops\n",

Modified: gnunet/src/mesh/mesh_tunnel_tree.c
===================================================================
--- gnunet/src/mesh/mesh_tunnel_tree.c  2011-09-21 11:39:40 UTC (rev 16987)
+++ gnunet/src/mesh/mesh_tunnel_tree.c  2011-09-21 12:59:59 UTC (rev 16988)
@@ -129,7 +129,7 @@
  * @return Pointer to the node of the peer. NULL if not found.
  */
 struct MeshTunnelTreeNode *
-tunnel_find_peer (struct MeshTunnelTreeNode *root, GNUNET_PEER_Id peer_id)
+tree_find_peer (struct MeshTunnelTreeNode *root, GNUNET_PEER_Id peer_id)
 {
   struct MeshTunnelTreeNode *n;
   unsigned int i;
@@ -138,7 +138,7 @@
     return root;
   for (i = 0; i < root->nchildren; i++)
   {
-    n = tunnel_find_peer (&root->children[i], peer_id);
+    n = tree_find_peer (&root->children[i], peer_id);
     if (NULL != n)
       return n;
   }
@@ -153,7 +153,7 @@
  * @param cb Callback to use to notify about disconnected peers.
  */
 void
-tunnel_mark_peers_disconnected (struct MeshTunnelTreeNode *parent,
+tree_mark_peers_disconnected (struct MeshTunnelTreeNode *parent,
                                 MeshNodeDisconnectCB cb)
 {
   unsigned int i;
@@ -165,7 +165,7 @@
   parent->status = MESH_PEER_RECONNECTING;
   for (i = 0; i < parent->nchildren; i++)
   {
-    tunnel_mark_peers_disconnected (&parent->children[i], cb);
+    tree_mark_peers_disconnected (&parent->children[i], cb);
   }
 //   struct GNUNET_MESH_PeerControl msg;
 //   if (NULL == parent->t->client)
@@ -195,7 +195,7 @@
  * @return pointer to the pathless node, NULL on error
  */
 struct MeshTunnelTreeNode *
-tunnel_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id,
+tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id,
                  MeshNodeDisconnectCB cb)
 {
   struct MeshTunnelTreeNode *parent;
@@ -204,7 +204,7 @@
 
   if (peer_id == t->root->peer)
     return NULL;
-  node = n = tunnel_find_peer (t->me, peer_id);
+  node = n = tree_find_peer (t->me, peer_id);
   if (NULL == n)
     return NULL;
   parent = n->parent;
@@ -222,7 +222,7 @@
   parent->nchildren--;
   parent->children = GNUNET_realloc (parent->children, parent->nchildren);
 
-  tunnel_mark_peers_disconnected (node, cb);
+  tree_mark_peers_disconnected (node, cb);
 
   return node;
 }
@@ -239,13 +239,13 @@
  *         Path must be destroyed afterwards.
  */
 struct MeshPeerPath *
-tunnel_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
+tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
 {
   struct MeshTunnelTreeNode *n;
   struct MeshPeerPath *p;
   GNUNET_PEER_Id myid = t->me->peer;
 
-  n = tunnel_find_peer(t->me, peer);
+  n = tree_find_peer(t->me, peer);
   p = GNUNET_malloc(sizeof(struct MeshPeerPath));
 
   /* Building the path (inverted!) */
@@ -280,7 +280,7 @@
  * - do not disconnect peers until new path is created & connected
  */
 int
-tunnel_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
+tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
                  MeshNodeDisconnectCB cb)
 {
   struct MeshTunnelTreeNode *parent;
@@ -302,7 +302,7 @@
   }
   if (1 == p->length)
     return GNUNET_OK;
-  oldnode = tunnel_del_path (t, p->peers[p->length - 1], cb);
+  oldnode = tree_del_path (t, p->peers[p->length - 1], cb);
   /* Look for the first node that is not already present in the tree
    *
    * Assuming that the tree is somewhat balanced, O(log n * log N).
@@ -371,3 +371,55 @@
   }
   return GNUNET_OK;
 }
+
+
+/**
+ * Destroy the node and all children
+ * 
+ * @param n Parent node to be destroyed
+ */
+void
+tree_node_destroy (struct MeshTunnelTreeNode *n)
+{
+  unsigned int i;
+
+  if (n->nchildren == 0) return;
+  for (i = 0; i < n->nchildren; i++)
+  {
+    tree_node_destroy(&n->children[i]);
+  }
+  GNUNET_free(n->children);
+}
+
+
+/**
+ * Iterator over hash map peer entries and frees all data in it.
+ * Used prior to destroying a hashmap. Makes you miss anonymous functions in C.
+ *
+ * @param cls closure
+ * @param key current key code (will no longer contain valid data!!)
+ * @param value value in the hash map (treated as void *)
+ * @return GNUNET_YES if we should continue to iterate, GNUNET_NO if not.
+ */
+static int
+iterate_free (void *cls, const GNUNET_HashCode * key, void *value)
+{
+  GNUNET_free(value);
+  return GNUNET_YES;
+}
+
+
+/**
+ * Destroy the whole tree and free all used memory and Peer_Ids
+ * 
+ * @param t Tree to be destroyed
+ */
+void
+tree_destroy (struct MeshTunnelTree *t)
+{
+  tree_node_destroy(t->root);
+  GNUNET_free(t->root);
+  GNUNET_CONTAINER_multihashmap_iterate(t->first_hops, &iterate_free, NULL);
+  GNUNET_CONTAINER_multihashmap_destroy(t->first_hops);
+  
+}
\ No newline at end of file

Modified: gnunet/src/mesh/mesh_tunnel_tree.h
===================================================================
--- gnunet/src/mesh/mesh_tunnel_tree.h  2011-09-21 11:39:40 UTC (rev 16987)
+++ gnunet/src/mesh/mesh_tunnel_tree.h  2011-09-21 12:59:59 UTC (rev 16988)
@@ -19,7 +19,7 @@
 */
 
 /**
- * @file mesh/mesh_tunnel_tree.h
+ * @file mesh/mesh_tree_tree.h
  * @brief Tunnel tree handling functions
  * @author Bartlomiej Polot
  */
@@ -208,7 +208,7 @@
  * @return Pointer to the node of the peer. NULL if not found.
  */
 struct MeshTunnelTreeNode *
-tunnel_find_peer (struct MeshTunnelTreeNode *root, GNUNET_PEER_Id peer_id);
+tree_find_peer (struct MeshTunnelTreeNode *root, GNUNET_PEER_Id peer_id);
 
 
 /**
@@ -218,7 +218,7 @@
  * @param cb Callback to use to notify about disconnected peers
  */
 void
-tunnel_mark_peers_disconnected (struct MeshTunnelTreeNode *parent,
+tree_mark_peers_disconnected (struct MeshTunnelTreeNode *parent,
                                 MeshNodeDisconnectCB cb);
 
 
@@ -234,7 +234,7 @@
  * @return pointer to the pathless node, NULL on error
  */
 struct MeshTunnelTreeNode *
-tunnel_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id,
+tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id,
                  MeshNodeDisconnectCB cb);
 
 
@@ -249,7 +249,7 @@
  *         Path must be destroyed afterwards.
  */
 struct MeshPeerPath *
-tunnel_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer);
+tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer);
 
 
 /**
@@ -263,5 +263,13 @@
  *         GNUNET_SYSERR in case of error.
  */
 int
-tunnel_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
-                 MeshNodeDisconnectCB cb);
\ No newline at end of file
+tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
+                 MeshNodeDisconnectCB cb);
+
+/**
+ * Destroy the whole tree and free all used memory and Peer_Ids
+ * 
+ * @param t Tree to be destroyed
+ */
+void
+tree_destroy (struct MeshTunnelTree *t);
\ No newline at end of file

Modified: gnunet/src/mesh/test_mesh_path_api.c
===================================================================
--- gnunet/src/mesh/test_mesh_path_api.c        2011-09-21 11:39:40 UTC (rev 
16987)
+++ gnunet/src/mesh/test_mesh_path_api.c        2011-09-21 12:59:59 UTC (rev 
16988)
@@ -61,10 +61,7 @@
   {
     GNUNET_free(pi[i]);
   }
-  if (tree->root->nchildren > 0)
-    GNUNET_free(tree->root->children);
-  GNUNET_free(tree->root);
-  GNUNET_free(tree);
+  tree_destroy(tree);
   exit(0);
 }
 
@@ -120,8 +117,8 @@
   path[0]->length = 4;
 
   finish();
-  tunnel_add_path(tree, path[0], &cb);
-  path[1] = tunnel_get_path_to_peer(tree, 3);
+  tree_add_path(tree, path[0], &cb);
+  path[1] = tree_get_path_to_peer(tree, 3);
   if (path[0]->length != path[1]->length ||
       memcmp(path[0]->peers, path[1]->peers, path[0]->length) != 0)
   {
@@ -129,7 +126,7 @@
     failed++;
   }
   path_destroy(path[1]);
-  node = tunnel_find_peer(tree->root, 3);
+  node = tree_find_peer(tree->root, 3);
   if (node->peer != 3)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
@@ -148,7 +145,7 @@
   }
   return 0;
 
-  node = tunnel_find_peer(tree->root, 2);
+  node = tree_find_peer(tree->root, 2);
   if (node->peer != 2)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
@@ -170,7 +167,7 @@
     failed++;
   }
 
-  node = tunnel_find_peer(tree->root, 1);
+  node = tree_find_peer(tree->root, 1);
   if (node->peer != 1)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
@@ -188,9 +185,9 @@
   }
 
   path[0]->length--;
-  tunnel_add_path(tree, path[0], &cb);
+  tree_add_path(tree, path[0], &cb);
 
-  node = tunnel_find_peer(tree->root, 2);
+  node = tree_find_peer(tree->root, 2);
   if (node->peer != 2)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
@@ -217,7 +214,7 @@
     failed++;
   }
 
-  node = tunnel_find_peer(tree->root, 1);
+  node = tree_find_peer(tree->root, 1);
   if (node->peer != 1)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
@@ -236,9 +233,9 @@
 
   path[0]->length++;
   path[0]->peers[3] = 4;
-  tunnel_add_path(tree, path[0], &cb);
+  tree_add_path(tree, path[0], &cb);
 
-  node = tunnel_find_peer(tree->root, 2);
+  node = tree_find_peer(tree->root, 2);
   if (node->peer != 2)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
@@ -265,7 +262,7 @@
     failed++;
   }
 
-  node = tunnel_find_peer(tree->root, 1);
+  node = tree_find_peer(tree->root, 1);
   if (node->peer != 1)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
@@ -282,7 +279,7 @@
     failed++;
   }
 
-  node = tunnel_find_peer(tree->root, 4);
+  node = tree_find_peer(tree->root, 4);
   if (node->peer != 4)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
@@ -290,7 +287,7 @@
   }
   node->status = MESH_PEER_READY;
   cb_call = 1;
-  node2 = tunnel_del_path(tree, 4, &cb);
+  node2 = tree_del_path(tree, 4, &cb);
   if (cb_call != 0)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
@@ -302,7 +299,7 @@
     failed++;
   }
 //   GNUNET_free(node2); FIXME destroy
-  node = tunnel_find_peer(tree->root, 2);
+  node = tree_find_peer(tree->root, 2);
   if (node->peer != 2)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
@@ -322,13 +319,13 @@
   path[0]->length = 2;
   path[0]->peers[1] = 3;
   cb_call = 1;
-  tunnel_add_path(tree, path[0], cb);
+  tree_add_path(tree, path[0], cb);
   if (cb_call != 0)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
     failed++;
   }
-  node = tunnel_find_peer(tree->root, 2);
+  node = tree_find_peer(tree->root, 2);
   if (node->peer != 2)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
@@ -344,7 +341,7 @@
     GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
     failed++;
   }
-  node = tunnel_find_peer(tree->root, 3);
+  node = tree_find_peer(tree->root, 3);
   if (node->peer != 3)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");




reply via email to

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