diff options
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 11 | ||||
-rw-r--r-- | src/mesh/mesh_tunnel_tree.c | 64 | ||||
-rw-r--r-- | src/mesh/mesh_tunnel_tree.h | 27 | ||||
-rw-r--r-- | src/mesh/test_mesh_tree_api.c | 37 |
4 files changed, 101 insertions, 38 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 14dd5d1fd..bcf6a400b 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -1477,7 +1477,7 @@ peer_info_remove_path (struct MeshPeerInfo *peer, GNUNET_PEER_Id p1, | |||
1477 | aux = NULL; | 1477 | aux = NULL; |
1478 | for (p = peer_d->path_head; NULL != p; p = p->next) | 1478 | for (p = peer_d->path_head; NULL != p; p = p->next) |
1479 | { | 1479 | { |
1480 | if ((cost = path_get_cost (peer->tunnels[i]->tree, p)) < best) | 1480 | if ((cost = tree_get_path_cost (peer->tunnels[i]->tree, p)) < best) |
1481 | { | 1481 | { |
1482 | best = cost; | 1482 | best = cost; |
1483 | aux = p; | 1483 | aux = p; |
@@ -1848,10 +1848,10 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer) | |||
1848 | if (NULL != (p = peer->path_head)) | 1848 | if (NULL != (p = peer->path_head)) |
1849 | { | 1849 | { |
1850 | best_p = p; | 1850 | best_p = p; |
1851 | best_cost = path_get_cost (t->tree, p); | 1851 | best_cost = tree_get_path_cost (t->tree, p); |
1852 | while (NULL != p) | 1852 | while (NULL != p) |
1853 | { | 1853 | { |
1854 | if ((cost = path_get_cost (t->tree, p)) < best_cost) | 1854 | if ((cost = tree_get_path_cost (t->tree, p)) < best_cost) |
1855 | { | 1855 | { |
1856 | best_cost = cost; | 1856 | best_cost = cost; |
1857 | best_p = p; | 1857 | best_p = p; |
@@ -1865,7 +1865,7 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer) | |||
1865 | } | 1865 | } |
1866 | else | 1866 | else |
1867 | { | 1867 | { |
1868 | /* Start a DHT get if necessary */ | 1868 | /* Start a DHT get */ |
1869 | peer_info_connect (peer, t); | 1869 | peer_info_connect (peer, t); |
1870 | } | 1870 | } |
1871 | } | 1871 | } |
@@ -3253,8 +3253,6 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
3253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Got results from DHT!\n"); | 3253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Got results from DHT!\n"); |
3254 | GNUNET_PEER_resolve (path_info->peer->id, &pi); | 3254 | GNUNET_PEER_resolve (path_info->peer->id, &pi); |
3255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", GNUNET_i2s (&pi)); | 3255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", GNUNET_i2s (&pi)); |
3256 | // GNUNET_DHT_get_stop(path_info->peer->dhtget); | ||
3257 | // path_info->peer->dhtget = NULL; | ||
3258 | 3256 | ||
3259 | p = path_build_from_dht (get_path, get_path_length, put_path, | 3257 | p = path_build_from_dht (get_path, get_path_length, put_path, |
3260 | put_path_length); | 3258 | put_path_length); |
@@ -3264,7 +3262,6 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
3264 | tunnel_add_peer (path_info->peer->tunnels[i], path_info->peer); | 3262 | tunnel_add_peer (path_info->peer->tunnels[i], path_info->peer); |
3265 | peer_info_connect (path_info->peer, path_info->t); | 3263 | peer_info_connect (path_info->peer, path_info->t); |
3266 | } | 3264 | } |
3267 | // GNUNET_free (path_info); | ||
3268 | 3265 | ||
3269 | return; | 3266 | return; |
3270 | } | 3267 | } |
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 | * |
diff --git a/src/mesh/mesh_tunnel_tree.h b/src/mesh/mesh_tunnel_tree.h index 5060fa1a7..dd31661ac 100644 --- a/src/mesh/mesh_tunnel_tree.h +++ b/src/mesh/mesh_tunnel_tree.h | |||
@@ -113,19 +113,6 @@ path_get_length (struct MeshPeerPath *p); | |||
113 | 113 | ||
114 | 114 | ||
115 | /** | 115 | /** |
116 | * Get the cost of the path relative to the already built tunnel tree | ||
117 | * | ||
118 | * @param t The tunnel tree to which compare | ||
119 | * @param path The individual path to reach a peer | ||
120 | * | ||
121 | * @return Number of hops to reach destination, UINT_MAX in case the peer is not | ||
122 | * in the path | ||
123 | */ | ||
124 | unsigned int | ||
125 | path_get_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path); | ||
126 | |||
127 | |||
128 | /** | ||
129 | * Destroy the path and free any allocated resources linked to it | 116 | * Destroy the path and free any allocated resources linked to it |
130 | * | 117 | * |
131 | * @param p the path to destroy | 118 | * @param p the path to destroy |
@@ -324,6 +311,20 @@ int | |||
324 | tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer, | 311 | tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer, |
325 | MeshTreeCallback cb, void *cbcls); | 312 | MeshTreeCallback cb, void *cbcls); |
326 | 313 | ||
314 | |||
315 | /** | ||
316 | * Get the cost of the path relative to the already built tunnel tree | ||
317 | * | ||
318 | * @param t The tunnel tree to which compare | ||
319 | * @param path The individual path to reach a peer | ||
320 | * | ||
321 | * @return Number of hops to reach destination, UINT_MAX in case the peer is not | ||
322 | * in the path | ||
323 | */ | ||
324 | unsigned int | ||
325 | tree_get_path_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path); | ||
326 | |||
327 | |||
327 | /** | 328 | /** |
328 | * Print the tree on stderr | 329 | * Print the tree on stderr |
329 | * | 330 | * |
diff --git a/src/mesh/test_mesh_tree_api.c b/src/mesh/test_mesh_tree_api.c index 77fd799bd..6ad5e9189 100644 --- a/src/mesh/test_mesh_tree_api.c +++ b/src/mesh/test_mesh_tree_api.c | |||
@@ -215,6 +215,43 @@ main (int argc, char *argv[]) | |||
215 | test_assert (2, MESH_PEER_RELAY, 1, 0); | 215 | test_assert (2, MESH_PEER_RELAY, 1, 0); |
216 | test_assert (1, MESH_PEER_ROOT, 1, 0); | 216 | test_assert (1, MESH_PEER_ROOT, 1, 0); |
217 | 217 | ||
218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Calculating costs...\n"); | ||
219 | for (i = 1; i < 5; i++) | ||
220 | { | ||
221 | path->length = i; | ||
222 | if (tree_get_path_cost(tree, path) != 0) | ||
223 | { | ||
224 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
225 | "test: length %u cost failed!\n", | ||
226 | i); | ||
227 | failed++; | ||
228 | } | ||
229 | } | ||
230 | path->length++; | ||
231 | path->peers[4] = 6; | ||
232 | if (tree_get_path_cost(tree, path) != 1) | ||
233 | { | ||
234 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
235 | "test: length %u cost failed!\n", | ||
236 | i); | ||
237 | failed++; | ||
238 | } | ||
239 | path->peers[3] = 7; | ||
240 | if (tree_get_path_cost(tree, path) != 2) | ||
241 | { | ||
242 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
243 | "test: length %u cost failed!\n", | ||
244 | i); | ||
245 | failed++; | ||
246 | } | ||
247 | path->length--; | ||
248 | if (tree_get_path_cost(tree, path) != 1) | ||
249 | { | ||
250 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
251 | "test: length %u cost failed!\n", | ||
252 | i); | ||
253 | failed++; | ||
254 | } | ||
218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path (5)\n"); | 255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path (5)\n"); |
219 | tree_set_status(tree, 5, MESH_PEER_READY); | 256 | tree_set_status(tree, 5, MESH_PEER_READY); |
220 | cb_call = 1; | 257 | cb_call = 1; |