aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-10-27 20:28:29 +0000
committerBart Polot <bart@net.in.tum.de>2011-10-27 20:28:29 +0000
commit83a2993fd05ff8bff76b7aaf36a61a86983713db (patch)
tree549d6a8f81d49c4df3a2f2f64f7171b142d31ba4 /src
parentf8acae3eb63f3cd32650f31a2da4b9fdf903f756 (diff)
downloadgnunet-83a2993fd05ff8bff76b7aaf36a61a86983713db.tar.gz
gnunet-83a2993fd05ff8bff76b7aaf36a61a86983713db.zip
Fixed testcase and small bugs in tree
Diffstat (limited to 'src')
-rw-r--r--src/mesh/mesh_tunnel_tree.c34
-rw-r--r--src/mesh/test_mesh_path_api.c10
2 files changed, 32 insertions, 12 deletions
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c
index a80cbb0c0..c58260601 100644
--- a/src/mesh/mesh_tunnel_tree.c
+++ b/src/mesh/mesh_tunnel_tree.c
@@ -200,6 +200,7 @@ static void
200tree_node_debug(struct MeshTunnelTreeNode *n, uint16_t level) 200tree_node_debug(struct MeshTunnelTreeNode *n, uint16_t level)
201{ 201{
202 struct MeshTunnelTreeNode *c; 202 struct MeshTunnelTreeNode *c;
203 struct GNUNET_PeerIdentity id;;
203 uint16_t i; 204 uint16_t i;
204 205
205 for (i = 0; i < level; i++) 206 for (i = 0; i < level; i++)
@@ -213,9 +214,13 @@ tree_node_debug(struct MeshTunnelTreeNode *n, uint16_t level)
213 if (n->status == MESH_PEER_RECONNECTING) 214 if (n->status == MESH_PEER_RECONNECTING)
214 fprintf(stderr, "*"); 215 fprintf(stderr, "*");
215 216
216 fprintf(stderr, "%u [%p] ", n->peer, n); 217 GNUNET_PEER_resolve(n->peer, &id);
218 fprintf(stderr, "%s, [%u, %p] ", GNUNET_i2s (&id), n->peer, n);
217 if (NULL != n->parent) 219 if (NULL != n->parent)
218 fprintf(stderr, "(-> %u)\n", n->parent->peer); 220 {
221 GNUNET_PEER_resolve(n->parent->peer, &id);
222 fprintf(stderr, "(-> %s [%u])\n", GNUNET_i2s(&id), n->parent->peer);
223 }
219 else 224 else
220 fprintf(stderr, "(root)\n"); 225 fprintf(stderr, "(root)\n");
221 for (c = n->children_head; NULL != c; c = c->next) 226 for (c = n->children_head; NULL != c; c = c->next)
@@ -233,7 +238,17 @@ tree_node_destroy (struct MeshTunnelTreeNode *parent)
233{ 238{
234 struct MeshTunnelTreeNode *n; 239 struct MeshTunnelTreeNode *n;
235 struct MeshTunnelTreeNode *next; 240 struct MeshTunnelTreeNode *next;
241#if MESH_TREE_DEBUG
242 struct GNUNET_PeerIdentity id;
236 243
244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
245 "tree: Destroying node %u\n",
246 parent->peer);
247 GNUNET_PEER_resolve (parent->peer, &id);
248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
249 "tree: (%s)\n",
250 GNUNET_i2s (&id));
251#endif
237 n = parent->children_head; 252 n = parent->children_head;
238 while (NULL != n) 253 while (NULL != n)
239 { 254 {
@@ -321,11 +336,12 @@ tree_mark_peers_disconnected (struct MeshTunnelTree *tree,
321 { 336 {
322 tree_mark_peers_disconnected (tree, n, cb); 337 tree_mark_peers_disconnected (tree, n, cb);
323 } 338 }
324 if (MESH_PEER_READY == parent->status && NULL != cb) 339 if (MESH_PEER_READY == parent->status)
325 { 340 {
326 cb (parent); 341 if (NULL != cb)
342 cb (parent);
343 parent->status = MESH_PEER_RECONNECTING;
327 } 344 }
328 parent->status = MESH_PEER_RECONNECTING;
329 345
330 /* Remove and free info about first hop */ 346 /* Remove and free info about first hop */
331 GNUNET_PEER_resolve(parent->peer, &id); 347 GNUNET_PEER_resolve(parent->peer, &id);
@@ -416,8 +432,9 @@ tree_update_first_hops (struct MeshTunnelTree *tree,
416 * NULL when not found 432 * NULL when not found
417 */ 433 */
418struct MeshTunnelTreeNode * 434struct MeshTunnelTreeNode *
419tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id, 435tree_del_path (struct MeshTunnelTree *t,
420 MeshNodeDisconnectCB cb) 436 GNUNET_PEER_Id peer_id,
437 MeshNodeDisconnectCB cb)
421{ 438{
422 struct MeshTunnelTreeNode *parent; 439 struct MeshTunnelTreeNode *parent;
423 struct MeshTunnelTreeNode *node; 440 struct MeshTunnelTreeNode *node;
@@ -797,6 +814,9 @@ iterate_free (void *cls, const GNUNET_HashCode * key, void *value)
797void 814void
798tree_destroy (struct MeshTunnelTree *t) 815tree_destroy (struct MeshTunnelTree *t)
799{ 816{
817#if MESH_TREE_DEBUG
818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying tree\n");
819#endif
800 tree_node_destroy(t->root); 820 tree_node_destroy(t->root);
801 GNUNET_CONTAINER_multihashmap_iterate(t->first_hops, &iterate_free, NULL); 821 GNUNET_CONTAINER_multihashmap_iterate(t->first_hops, &iterate_free, NULL);
802 GNUNET_CONTAINER_multihashmap_destroy(t->first_hops); 822 GNUNET_CONTAINER_multihashmap_destroy(t->first_hops);
diff --git a/src/mesh/test_mesh_path_api.c b/src/mesh/test_mesh_path_api.c
index 9a983f298..58bc6bd20 100644
--- a/src/mesh/test_mesh_path_api.c
+++ b/src/mesh/test_mesh_path_api.c
@@ -101,8 +101,9 @@ main (int argc, char *argv[])
101 for (i = 0; i < 10; i++) 101 for (i = 0; i < 10; i++)
102 { 102 {
103 pi[i] = get_pi(i); 103 pi[i] = get_pi(i);
104 GNUNET_break (i != GNUNET_PEER_intern(pi[i])); 104 GNUNET_break (i + 1 == GNUNET_PEER_intern(pi[i]));
105 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", i, 105 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n",
106 i + 1,
106 GNUNET_h2s(&pi[i]->hashPubKey)); 107 GNUNET_h2s(&pi[i]->hashPubKey));
107 } 108 }
108 tree = GNUNET_malloc(sizeof(struct MeshTunnelTree)); 109 tree = GNUNET_malloc(sizeof(struct MeshTunnelTree));
@@ -188,7 +189,6 @@ main (int argc, char *argv[])
188 189
189 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n"); 190 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n");
190 path->length--; 191 path->length--;
191 tree_debug(tree);
192 tree_add_path(tree, path, &cb); 192 tree_add_path(tree, path, &cb);
193 tree_debug(tree); 193 tree_debug(tree);
194 194
@@ -377,7 +377,7 @@ main (int argc, char *argv[])
377 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); 377 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
378 failed++; 378 failed++;
379 } 379 }
380 if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1) 380 if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 2)
381 { 381 {
382 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); 382 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
383 failed++; 383 failed++;
@@ -395,7 +395,7 @@ main (int argc, char *argv[])
395 return 1; 395 return 1;
396 } 396 }
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: OK\n"); 397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: OK\n");
398 path_destroy(path); 398 GNUNET_free (path);
399 finish(); 399 finish();
400 400
401 return 0; 401 return 0;