[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r18136 - gnunet/src/mesh
From: |
gnunet |
Subject: |
[GNUnet-SVN] r18136 - gnunet/src/mesh |
Date: |
Mon, 14 Nov 2011 18:06:42 +0100 |
Author: bartpolot
Date: 2011-11-14 18:06:42 +0100 (Mon, 14 Nov 2011)
New Revision: 18136
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_tree_api.c
Log:
Real implementation for getting cost of a path compared to an existing tunnel
tree (additional hops)
Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c 2011-11-14 17:04:48 UTC (rev
18135)
+++ gnunet/src/mesh/gnunet-service-mesh.c 2011-11-14 17:06:42 UTC (rev
18136)
@@ -1477,7 +1477,7 @@
aux = NULL;
for (p = peer_d->path_head; NULL != p; p = p->next)
{
- if ((cost = path_get_cost (peer->tunnels[i]->tree, p)) < best)
+ if ((cost = tree_get_path_cost (peer->tunnels[i]->tree, p)) < best)
{
best = cost;
aux = p;
@@ -1848,10 +1848,10 @@
if (NULL != (p = peer->path_head))
{
best_p = p;
- best_cost = path_get_cost (t->tree, p);
+ best_cost = tree_get_path_cost (t->tree, p);
while (NULL != p)
{
- if ((cost = path_get_cost (t->tree, p)) < best_cost)
+ if ((cost = tree_get_path_cost (t->tree, p)) < best_cost)
{
best_cost = cost;
best_p = p;
@@ -1865,7 +1865,7 @@
}
else
{
- /* Start a DHT get if necessary */
+ /* Start a DHT get */
peer_info_connect (peer, t);
}
}
@@ -3253,8 +3253,6 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Got results from DHT!\n");
GNUNET_PEER_resolve (path_info->peer->id, &pi);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", GNUNET_i2s (&pi));
-// GNUNET_DHT_get_stop(path_info->peer->dhtget);
-// path_info->peer->dhtget = NULL;
p = path_build_from_dht (get_path, get_path_length, put_path,
put_path_length);
@@ -3264,7 +3262,6 @@
tunnel_add_peer (path_info->peer->tunnels[i], path_info->peer);
peer_info_connect (path_info->peer, path_info->t);
}
-// GNUNET_free (path_info);
return;
}
Modified: gnunet/src/mesh/mesh_tunnel_tree.c
===================================================================
--- gnunet/src/mesh/mesh_tunnel_tree.c 2011-11-14 17:04:48 UTC (rev 18135)
+++ gnunet/src/mesh/mesh_tunnel_tree.c 2011-11-14 17:06:42 UTC (rev 18136)
@@ -200,24 +200,6 @@
/**
- * Get the cost of the path relative to the already built tunnel tree
- *
- * @param t The tunnel tree to which compare
- * @param path The individual path to reach a peer
- *
- * @return Number of hops to reach destination, UINT_MAX in case the peer is
not
- * in the path
- *
- * TODO: remove dummy implementation, look into the tunnel tree
- */
-unsigned int
-path_get_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path)
-{
- return path_get_length (path);
-}
-
-
-/**
* Destroy the path and free any allocated resources linked to it
*
* @param p the path to destroy
@@ -989,7 +971,53 @@
}
+
/**
+ * Get the cost of the path relative to the already built tunnel tree.
+ *
+ * @param t The tunnel tree to which compare.
+ * @param path The individual path to reach a peer. It has to start at the
+ * root of the tree to be comparable.
+ *
+ * @return Number of hops to reach destination, UINT_MAX in case the peer is
not
+ * in the path.
+ *
+ * TODO: adapt to allow any start / root combination
+ * TODO: take in account state of the nodes
+ */
+unsigned int
+tree_get_path_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path)
+{
+ struct MeshTunnelTreeNode *n;
+ struct MeshTunnelTreeNode *p;
+ unsigned int i;
+ unsigned int l;
+
+ l = path_get_length (path);
+ p = t->root;
+ if (t->root->peer != path->peers[0])
+ {
+ GNUNET_break (0);
+ return UINT_MAX;
+ }
+ for (i = 1; i < l; i++)
+ {
+ for (n = p->children_head; NULL != n; n = n->next)
+ {
+ if (path->peers[i] == n->peer)
+ {
+ break;
+ }
+ }
+ if (NULL == n)
+ return l - i;
+ p = n;
+ }
+ return l - i;
+}
+
+
+/**
* Print the tree on stderr
*
* @param t The tree
Modified: gnunet/src/mesh/mesh_tunnel_tree.h
===================================================================
--- gnunet/src/mesh/mesh_tunnel_tree.h 2011-11-14 17:04:48 UTC (rev 18135)
+++ gnunet/src/mesh/mesh_tunnel_tree.h 2011-11-14 17:06:42 UTC (rev 18136)
@@ -113,19 +113,6 @@
/**
- * Get the cost of the path relative to the already built tunnel tree
- *
- * @param t The tunnel tree to which compare
- * @param path The individual path to reach a peer
- *
- * @return Number of hops to reach destination, UINT_MAX in case the peer is
not
- * in the path
- */
-unsigned int
-path_get_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path);
-
-
-/**
* Destroy the path and free any allocated resources linked to it
*
* @param p the path to destroy
@@ -324,7 +311,21 @@
tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer,
MeshTreeCallback cb, void *cbcls);
+
/**
+ * Get the cost of the path relative to the already built tunnel tree
+ *
+ * @param t The tunnel tree to which compare
+ * @param path The individual path to reach a peer
+ *
+ * @return Number of hops to reach destination, UINT_MAX in case the peer is
not
+ * in the path
+ */
+unsigned int
+tree_get_path_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path);
+
+
+/**
* Print the tree on stderr
*
* @param t The tree
Modified: gnunet/src/mesh/test_mesh_tree_api.c
===================================================================
--- gnunet/src/mesh/test_mesh_tree_api.c 2011-11-14 17:04:48 UTC (rev
18135)
+++ gnunet/src/mesh/test_mesh_tree_api.c 2011-11-14 17:06:42 UTC (rev
18136)
@@ -215,6 +215,43 @@
test_assert (2, MESH_PEER_RELAY, 1, 0);
test_assert (1, MESH_PEER_ROOT, 1, 0);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Calculating costs...\n");
+ for (i = 1; i < 5; i++)
+ {
+ path->length = i;
+ if (tree_get_path_cost(tree, path) != 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "test: length %u cost failed!\n",
+ i);
+ failed++;
+ }
+ }
+ path->length++;
+ path->peers[4] = 6;
+ if (tree_get_path_cost(tree, path) != 1)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "test: length %u cost failed!\n",
+ i);
+ failed++;
+ }
+ path->peers[3] = 7;
+ if (tree_get_path_cost(tree, path) != 2)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "test: length %u cost failed!\n",
+ i);
+ failed++;
+ }
+ path->length--;
+ if (tree_get_path_cost(tree, path) != 1)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "test: length %u cost failed!\n",
+ i);
+ failed++;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path (5)\n");
tree_set_status(tree, 5, MESH_PEER_READY);
cb_call = 1;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r18136 - gnunet/src/mesh,
gnunet <=