diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-11-14 17:06:42 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-11-14 17:06:42 +0000 |
commit | 41323384c6bc36f5713cce594258110144d261ef (patch) | |
tree | d83bae5fc0cc2de33c1f9bd8765bc77d910014b9 /src/mesh/mesh_tunnel_tree.c | |
parent | a2dbac31f9731bb72a6d13522545e5e75fdd8d4a (diff) | |
download | gnunet-41323384c6bc36f5713cce594258110144d261ef.tar.gz gnunet-41323384c6bc36f5713cce594258110144d261ef.zip |
Real implementation for getting cost of a path compared to an existing tunnel tree (additional hops)
Diffstat (limited to 'src/mesh/mesh_tunnel_tree.c')
-rw-r--r-- | src/mesh/mesh_tunnel_tree.c | 64 |
1 files changed, 46 insertions, 18 deletions
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c index b43fb2534..2b2e460b5 100644 --- a/src/mesh/mesh_tunnel_tree.c +++ b/src/mesh/mesh_tunnel_tree.c | |||
@@ -200,24 +200,6 @@ path_get_length (struct MeshPeerPath *path) | |||
200 | 200 | ||
201 | 201 | ||
202 | /** | 202 | /** |
203 | * Get the cost of the path relative to the already built tunnel tree | ||
204 | * | ||
205 | * @param t The tunnel tree to which compare | ||
206 | * @param path The individual path to reach a peer | ||
207 | * | ||
208 | * @return Number of hops to reach destination, UINT_MAX in case the peer is not | ||
209 | * in the path | ||
210 | * | ||
211 | * TODO: remove dummy implementation, look into the tunnel tree | ||
212 | */ | ||
213 | unsigned int | ||
214 | path_get_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path) | ||
215 | { | ||
216 | return path_get_length (path); | ||
217 | } | ||
218 | |||
219 | |||
220 | /** | ||
221 | * Destroy the path and free any allocated resources linked to it | 203 | * Destroy the path and free any allocated resources linked to it |
222 | * | 204 | * |
223 | * @param p the path to destroy | 205 | * @param p the path to destroy |
@@ -989,6 +971,52 @@ tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer, | |||
989 | } | 971 | } |
990 | 972 | ||
991 | 973 | ||
974 | |||
975 | /** | ||
976 | * Get the cost of the path relative to the already built tunnel tree. | ||
977 | * | ||
978 | * @param t The tunnel tree to which compare. | ||
979 | * @param path The individual path to reach a peer. It has to start at the | ||
980 | * root of the tree to be comparable. | ||
981 | * | ||
982 | * @return Number of hops to reach destination, UINT_MAX in case the peer is not | ||
983 | * in the path. | ||
984 | * | ||
985 | * TODO: adapt to allow any start / root combination | ||
986 | * TODO: take in account state of the nodes | ||
987 | */ | ||
988 | unsigned int | ||
989 | tree_get_path_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path) | ||
990 | { | ||
991 | struct MeshTunnelTreeNode *n; | ||
992 | struct MeshTunnelTreeNode *p; | ||
993 | unsigned int i; | ||
994 | unsigned int l; | ||
995 | |||
996 | l = path_get_length (path); | ||
997 | p = t->root; | ||
998 | if (t->root->peer != path->peers[0]) | ||
999 | { | ||
1000 | GNUNET_break (0); | ||
1001 | return UINT_MAX; | ||
1002 | } | ||
1003 | for (i = 1; i < l; i++) | ||
1004 | { | ||
1005 | for (n = p->children_head; NULL != n; n = n->next) | ||
1006 | { | ||
1007 | if (path->peers[i] == n->peer) | ||
1008 | { | ||
1009 | break; | ||
1010 | } | ||
1011 | } | ||
1012 | if (NULL == n) | ||
1013 | return l - i; | ||
1014 | p = n; | ||
1015 | } | ||
1016 | return l - i; | ||
1017 | } | ||
1018 | |||
1019 | |||
992 | /** | 1020 | /** |
993 | * Print the tree on stderr | 1021 | * Print the tree on stderr |
994 | * | 1022 | * |