diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-10-25 17:28:18 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-10-25 17:28:18 +0000 |
commit | 516f27310ed37a5feacf1b25d3df570f1b3116a4 (patch) | |
tree | af6593117add116ab02a7e896ed7dc470f213622 /src/mesh | |
parent | 9c4741e490a1b193feb1a6b925d4cdd84ba7b0c2 (diff) | |
download | gnunet-516f27310ed37a5feacf1b25d3df570f1b3116a4.tar.gz gnunet-516f27310ed37a5feacf1b25d3df570f1b3116a4.zip |
Changed log, fixed crash in tree, caysed #1852 instead
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/mesh_tunnel_tree.c | 100 |
1 files changed, 75 insertions, 25 deletions
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c index 83ce893dc..f3b19beed 100644 --- a/src/mesh/mesh_tunnel_tree.c +++ b/src/mesh/mesh_tunnel_tree.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include "mesh.h" | 27 | #include "mesh.h" |
28 | #include "mesh_tunnel_tree.h" | 28 | #include "mesh_tunnel_tree.h" |
29 | 29 | ||
30 | #define MESH_TREE_DEBUG GNUNET_YES | ||
31 | |||
30 | 32 | ||
31 | /** | 33 | /** |
32 | * Create a new path | 34 | * Create a new path |
@@ -350,36 +352,47 @@ tree_update_first_hops (struct MeshTunnelTree *tree, | |||
350 | struct GNUNET_PeerIdentity id; | 352 | struct GNUNET_PeerIdentity id; |
351 | struct MeshTunnelTreeNode *n; | 353 | struct MeshTunnelTreeNode *n; |
352 | 354 | ||
355 | #if MESH_TREE_DEBUG | ||
356 | GNUNET_PEER_resolve(parent->peer, &id); | ||
353 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 357 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
354 | "tree: Finding first hop for %u.\n", | 358 | "tree: Finding first hop for %s.\n", |
355 | parent->peer); | 359 | GNUNET_i2s (&id)); |
360 | #endif | ||
356 | if (NULL == hop) | 361 | if (NULL == hop) |
357 | { | 362 | { |
358 | struct MeshTunnelTreeNode *aux; | 363 | struct MeshTunnelTreeNode *aux; |
359 | struct MeshTunnelTreeNode *old; | 364 | struct MeshTunnelTreeNode *old; |
360 | 365 | ||
361 | old = parent; | 366 | aux = old = parent; |
362 | aux = old->parent; | ||
363 | while (aux != tree->me) | 367 | while (aux != tree->me) |
364 | { | 368 | { |
369 | #if MESH_TREE_DEBUG | ||
370 | GNUNET_PEER_resolve(old->peer, &id); | ||
365 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 371 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
366 | "tree: ... its not %u.\n", | 372 | "tree: ... its not %s.\n", |
367 | old->peer); | 373 | GNUNET_i2s (&id)); |
374 | #endif | ||
368 | old = aux; | 375 | old = aux; |
369 | aux = aux->parent; | 376 | aux = aux->parent; |
370 | GNUNET_assert(NULL != aux); | 377 | GNUNET_assert(NULL != aux); |
371 | } | 378 | } |
379 | #if MESH_TREE_DEBUG | ||
380 | GNUNET_PEER_resolve(old->peer, &id); | ||
372 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 381 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
373 | "tree: It's %u!!\n", | 382 | "tree: It's %s!\n", |
374 | old->peer); | 383 | GNUNET_i2s (&id)); |
384 | #endif | ||
375 | hop = π | 385 | hop = π |
376 | GNUNET_PEER_resolve(old->peer, hop); | 386 | GNUNET_PEER_resolve(old->peer, hop); |
377 | } | 387 | } |
378 | copy = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); | 388 | copy = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); |
379 | *copy = *hop; | 389 | *copy = *hop; |
380 | GNUNET_PEER_resolve(parent->peer, &id); | 390 | GNUNET_PEER_resolve(parent->peer, &id); |
381 | GNUNET_CONTAINER_multihashmap_put(tree->first_hops, &id.hashPubKey, copy, | 391 | GNUNET_CONTAINER_multihashmap_put( |
382 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 392 | tree->first_hops, |
393 | &id.hashPubKey, | ||
394 | copy, | ||
395 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
383 | 396 | ||
384 | for (n = parent->children_head; NULL != n; n = n->next) | 397 | for (n = parent->children_head; NULL != n; n = n->next) |
385 | { | 398 | { |
@@ -408,8 +421,13 @@ tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id, | |||
408 | struct MeshTunnelTreeNode *node; | 421 | struct MeshTunnelTreeNode *node; |
409 | struct MeshTunnelTreeNode *n; | 422 | struct MeshTunnelTreeNode *n; |
410 | 423 | ||
424 | #if MESH_TREE_DEBUG | ||
425 | struct GNUNET_PeerIdentity id; | ||
426 | GNUNET_PEER_resolve(peer_id, &id); | ||
411 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 427 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
412 | "tree: Deleting path to %u.\n", peer_id); | 428 | "tree: Deleting path to %s.\n", |
429 | GNUNET_i2s (&id)); | ||
430 | #endif | ||
413 | if (peer_id == t->root->peer) | 431 | if (peer_id == t->root->peer) |
414 | return NULL; | 432 | return NULL; |
415 | 433 | ||
@@ -435,16 +453,22 @@ tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id, | |||
435 | 453 | ||
436 | while (MESH_PEER_RELAY == parent->status && NULL == parent->children_head) | 454 | while (MESH_PEER_RELAY == parent->status && NULL == parent->children_head) |
437 | { | 455 | { |
456 | #if MESH_TREE_DEBUG | ||
457 | GNUNET_PEER_resolve(parent->peer, &id); | ||
438 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 458 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
439 | "tree: Deleting node %u.\n", | 459 | "tree: Deleting node %s.\n", |
440 | parent->peer); | 460 | GNUNET_i2s (&id)); |
461 | #endif | ||
441 | n = parent->parent; | 462 | n = parent->parent; |
442 | tree_node_destroy(parent); | 463 | tree_node_destroy(parent); |
443 | parent = n; | 464 | parent = n; |
444 | } | 465 | } |
466 | #if MESH_TREE_DEBUG | ||
467 | GNUNET_PEER_resolve(parent->peer, &id); | ||
445 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 468 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
446 | "tree: Not deleted peer %u.\n", | 469 | "tree: Not deleted peer %s.\n", |
447 | parent->peer); | 470 | GNUNET_i2s (&id)); |
471 | #endif | ||
448 | 472 | ||
449 | tree_mark_peers_disconnected (t, node, cb); | 473 | tree_mark_peers_disconnected (t, node, cb); |
450 | 474 | ||
@@ -522,12 +546,16 @@ tree_add_path (struct MeshTunnelTree *t, | |||
522 | struct GNUNET_PeerIdentity id; | 546 | struct GNUNET_PeerIdentity id; |
523 | GNUNET_PEER_Id myid; | 547 | GNUNET_PEER_Id myid; |
524 | int me; | 548 | int me; |
549 | // int oldnode_is_me; | ||
525 | unsigned int i; | 550 | unsigned int i; |
526 | 551 | ||
552 | #if MESH_TREE_DEBUG | ||
553 | GNUNET_PEER_resolve(p->peers[p->length - 1], &id); | ||
527 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 554 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
528 | "tree: Adding path [%u] towards peer %u.\n", | 555 | "tree: Adding path [%u] towards peer %s.\n", |
529 | p->length, | 556 | p->length, |
530 | p->peers[p->length - 1]); | 557 | GNUNET_i2s (&id)); |
558 | #endif | ||
531 | 559 | ||
532 | if (NULL != t->me) | 560 | if (NULL != t->me) |
533 | myid = t->me->peer; | 561 | myid = t->me->peer; |
@@ -552,9 +580,12 @@ tree_add_path (struct MeshTunnelTree *t, | |||
552 | me = t->root->peer == myid ? 0 : -1; | 580 | me = t->root->peer == myid ? 0 : -1; |
553 | for (i = 1; i < p->length; i++) | 581 | for (i = 1; i < p->length; i++) |
554 | { | 582 | { |
583 | #if MESH_TREE_DEBUG | ||
584 | GNUNET_PEER_resolve(p->peers[i], &id); | ||
555 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 585 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
556 | "tree: Looking for peer %u.\n", | 586 | "tree: Looking for peer %s.\n", |
557 | p->peers[i]); | 587 | GNUNET_i2s (&id)); |
588 | #endif | ||
558 | parent = n; | 589 | parent = n; |
559 | if (p->peers[i] == myid) | 590 | if (p->peers[i] == myid) |
560 | me = i; | 591 | me = i; |
@@ -562,9 +593,12 @@ tree_add_path (struct MeshTunnelTree *t, | |||
562 | { | 593 | { |
563 | if (c->peer == p->peers[i]) | 594 | if (c->peer == p->peers[i]) |
564 | { | 595 | { |
596 | #if MESH_TREE_DEBUG | ||
597 | GNUNET_PEER_resolve(parent->peer, &id); | ||
565 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 598 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
566 | "tree: Found in children of %u.\n", | 599 | "tree: Found in children of %s.\n", |
567 | parent->peer); | 600 | GNUNET_i2s (&id)); |
601 | #endif | ||
568 | n = c; | 602 | n = c; |
569 | break; | 603 | break; |
570 | } | 604 | } |
@@ -574,20 +608,30 @@ tree_add_path (struct MeshTunnelTree *t, | |||
574 | if (parent == n) | 608 | if (parent == n) |
575 | break; | 609 | break; |
576 | } | 610 | } |
611 | #if MESH_TREE_DEBUG | ||
577 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 612 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
578 | "tree: All childen visited.\n"); | 613 | "tree: All childen visited.\n"); |
614 | #endif | ||
579 | /* Add the rest of the path as a branch from parent. */ | 615 | /* Add the rest of the path as a branch from parent. */ |
580 | while (i < p->length) | 616 | while (i < p->length) |
581 | { | 617 | { |
618 | #if MESH_TREE_DEBUG | ||
619 | GNUNET_PEER_resolve(p->peers[i], &id); | ||
620 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
621 | "tree: Adding peer %s.\n", | ||
622 | GNUNET_i2s (&id)); | ||
623 | GNUNET_PEER_resolve(parent->peer, &id); | ||
582 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 624 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
583 | "tree: Adding peer %u, to %u.\n", | 625 | "tree: to %s.\n", |
584 | p->peers[i], | 626 | GNUNET_i2s (&id)); |
585 | parent->peer); | 627 | #endif |
586 | 628 | ||
587 | if (i == p->length - 1 && NULL != oldnode) | 629 | if (i == p->length - 1 && NULL != oldnode) |
588 | { | 630 | { |
631 | #if MESH_TREE_DEBUG | ||
589 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 632 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
590 | "tree: Putting old node into place.\n"); | 633 | "tree: Putting old node into place.\n"); |
634 | #endif | ||
591 | oldnode->parent = parent; | 635 | oldnode->parent = parent; |
592 | GNUNET_CONTAINER_DLL_insert(parent->children_head, | 636 | GNUNET_CONTAINER_DLL_insert(parent->children_head, |
593 | parent->children_tail, | 637 | parent->children_tail, |
@@ -597,7 +641,9 @@ tree_add_path (struct MeshTunnelTree *t, | |||
597 | } | 641 | } |
598 | else | 642 | else |
599 | { | 643 | { |
644 | #if MESH_TREE_DEBUG | ||
600 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n"); | 645 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n"); |
646 | #endif | ||
601 | n = tree_node_new(parent, p->peers[i]); | 647 | n = tree_node_new(parent, p->peers[i]); |
602 | n->t = t->t; | 648 | n->t = t->t; |
603 | n->status = MESH_PEER_RELAY; | 649 | n->status = MESH_PEER_RELAY; |
@@ -610,15 +656,19 @@ tree_add_path (struct MeshTunnelTree *t, | |||
610 | /* Add info about first hop into hashmap. */ | 656 | /* Add info about first hop into hashmap. */ |
611 | if (-1 != me && me < p->length - 1) | 657 | if (-1 != me && me < p->length - 1) |
612 | { | 658 | { |
659 | #if MESH_TREE_DEBUG | ||
613 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 660 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
614 | "MESH: finding first hop (own pos %d/%u)\n", | 661 | "MESH: finding first hop (own pos %d/%u)\n", |
615 | me, p->length - 1); | 662 | me, p->length - 1); |
663 | #endif | ||
616 | GNUNET_PEER_resolve (p->peers[me + 1], &id); | 664 | GNUNET_PEER_resolve (p->peers[me + 1], &id); |
617 | tree_update_first_hops(t, | 665 | tree_update_first_hops(t, |
618 | tree_find_peer(t->root, p->peers[p->length - 1]), | 666 | tree_find_peer(t->root, p->peers[p->length - 1]), |
619 | &id); | 667 | &id); |
620 | } | 668 | } |
669 | #if MESH_TREE_DEBUG | ||
621 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n"); | 670 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n"); |
671 | #endif | ||
622 | return GNUNET_OK; | 672 | return GNUNET_OK; |
623 | } | 673 | } |
624 | 674 | ||