diff options
Diffstat (limited to 'src/mesh/mesh_tunnel_tree.c')
-rw-r--r-- | src/mesh/mesh_tunnel_tree.c | 334 |
1 files changed, 145 insertions, 189 deletions
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c index 332a022c1..cfe6a46a8 100644 --- a/src/mesh/mesh_tunnel_tree.c +++ b/src/mesh/mesh_tunnel_tree.c | |||
@@ -119,11 +119,11 @@ path_new (unsigned int length) | |||
119 | { | 119 | { |
120 | struct MeshPeerPath *p; | 120 | struct MeshPeerPath *p; |
121 | 121 | ||
122 | p = GNUNET_malloc (sizeof(struct MeshPeerPath)); | 122 | p = GNUNET_malloc (sizeof (struct MeshPeerPath)); |
123 | if (length > 0) | 123 | if (length > 0) |
124 | { | 124 | { |
125 | p->length = length; | 125 | p->length = length; |
126 | p->peers = GNUNET_malloc (length * sizeof(GNUNET_PEER_Id)); | 126 | p->peers = GNUNET_malloc (length * sizeof (GNUNET_PEER_Id)); |
127 | } | 127 | } |
128 | return p; | 128 | return p; |
129 | } | 129 | } |
@@ -160,10 +160,10 @@ path_duplicate (struct MeshPeerPath *path) | |||
160 | struct MeshPeerPath *aux; | 160 | struct MeshPeerPath *aux; |
161 | unsigned int i; | 161 | unsigned int i; |
162 | 162 | ||
163 | aux = path_new(path->length); | 163 | aux = path_new (path->length); |
164 | memcpy (aux->peers, path->peers, path->length * sizeof(GNUNET_PEER_Id)); | 164 | memcpy (aux->peers, path->peers, path->length * sizeof (GNUNET_PEER_Id)); |
165 | for (i = 0; i < path->length; i++) | 165 | for (i = 0; i < path->length; i++) |
166 | GNUNET_PEER_change_rc(path->peers[i], 1); | 166 | GNUNET_PEER_change_rc (path->peers[i], 1); |
167 | return aux; | 167 | return aux; |
168 | } | 168 | } |
169 | 169 | ||
@@ -202,18 +202,17 @@ path_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer) | |||
202 | { | 202 | { |
203 | struct MeshTunnelTreeNode *n; | 203 | struct MeshTunnelTreeNode *n; |
204 | 204 | ||
205 | n = tree_find_peer(t, peer); | 205 | n = tree_find_peer (t, peer); |
206 | if (NULL != t->me && NULL != n) | 206 | if (NULL != t->me && NULL != n) |
207 | { | 207 | { |
208 | tree_node_update_first_hops(t, n, NULL); | 208 | tree_node_update_first_hops (t, n, NULL); |
209 | r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey); | 209 | r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey); |
210 | GNUNET_assert (NULL != r); | 210 | GNUNET_assert (NULL != r); |
211 | } | 211 | } |
212 | else | 212 | else |
213 | { | 213 | { |
214 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 214 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
215 | "Tree structure inconsistent! me: %p, n: %p", | 215 | "Tree structure inconsistent! me: %p, n: %p", t->me, n); |
216 | t->me, n); | ||
217 | GNUNET_break (0); | 216 | GNUNET_break (0); |
218 | } | 217 | } |
219 | } | 218 | } |
@@ -287,18 +286,17 @@ path_destroy (struct MeshPeerPath *p) | |||
287 | * @return Newly allocated node | 286 | * @return Newly allocated node |
288 | */ | 287 | */ |
289 | static struct MeshTunnelTreeNode * | 288 | static struct MeshTunnelTreeNode * |
290 | tree_node_new(struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer) | 289 | tree_node_new (struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer) |
291 | { | 290 | { |
292 | struct MeshTunnelTreeNode *node; | 291 | struct MeshTunnelTreeNode *node; |
293 | 292 | ||
294 | node = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode)); | 293 | node = GNUNET_malloc (sizeof (struct MeshTunnelTreeNode)); |
295 | node->peer = peer; | 294 | node->peer = peer; |
296 | GNUNET_PEER_change_rc(peer, 1); | 295 | GNUNET_PEER_change_rc (peer, 1); |
297 | node->parent = parent; | 296 | node->parent = parent; |
298 | if (NULL != parent) | 297 | if (NULL != parent) |
299 | GNUNET_CONTAINER_DLL_insert(parent->children_head, | 298 | GNUNET_CONTAINER_DLL_insert (parent->children_head, parent->children_tail, |
300 | parent->children_tail, | 299 | node); |
301 | node); | ||
302 | 300 | ||
303 | return node; | 301 | return node; |
304 | } | 302 | } |
@@ -313,8 +311,7 @@ tree_node_new(struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer) | |||
313 | * @return Pointer to the node of the peer. NULL if not found. | 311 | * @return Pointer to the node of the peer. NULL if not found. |
314 | */ | 312 | */ |
315 | static struct MeshTunnelTreeNode * | 313 | static struct MeshTunnelTreeNode * |
316 | tree_node_find_peer (struct MeshTunnelTreeNode *parent, | 314 | tree_node_find_peer (struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer_id) |
317 | GNUNET_PEER_Id peer_id) | ||
318 | { | 315 | { |
319 | struct MeshTunnelTreeNode *n; | 316 | struct MeshTunnelTreeNode *n; |
320 | struct MeshTunnelTreeNode *r; | 317 | struct MeshTunnelTreeNode *r; |
@@ -350,10 +347,9 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree, | |||
350 | struct MeshTunnelTreeNode *n; | 347 | struct MeshTunnelTreeNode *n; |
351 | 348 | ||
352 | #if MESH_TREE_DEBUG | 349 | #if MESH_TREE_DEBUG |
353 | GNUNET_PEER_resolve(parent->peer, &id); | 350 | GNUNET_PEER_resolve (parent->peer, &id); |
354 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 351 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Finding first hop for %s.\n", |
355 | "tree: Finding first hop for %s.\n", | 352 | GNUNET_i2s (&id)); |
356 | GNUNET_i2s (&id)); | ||
357 | #endif | 353 | #endif |
358 | if (NULL == hop) | 354 | if (NULL == hop) |
359 | { | 355 | { |
@@ -364,35 +360,31 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree, | |||
364 | while (aux != tree->me) | 360 | while (aux != tree->me) |
365 | { | 361 | { |
366 | #if MESH_TREE_DEBUG | 362 | #if MESH_TREE_DEBUG |
367 | GNUNET_PEER_resolve(old->peer, &id); | 363 | GNUNET_PEER_resolve (old->peer, &id); |
368 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 364 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: ... its not %s.\n", |
369 | "tree: ... its not %s.\n", | 365 | GNUNET_i2s (&id)); |
370 | GNUNET_i2s (&id)); | ||
371 | #endif | 366 | #endif |
372 | old = aux; | 367 | old = aux; |
373 | aux = aux->parent; | 368 | aux = aux->parent; |
374 | GNUNET_assert(NULL != aux); | 369 | GNUNET_assert (NULL != aux); |
375 | } | 370 | } |
376 | #if MESH_TREE_DEBUG | 371 | #if MESH_TREE_DEBUG |
377 | GNUNET_PEER_resolve(old->peer, &id); | 372 | GNUNET_PEER_resolve (old->peer, &id); |
378 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: It's %s!\n", |
379 | "tree: It's %s!\n", | 374 | GNUNET_i2s (&id)); |
380 | GNUNET_i2s (&id)); | ||
381 | #endif | 375 | #endif |
382 | hop = π | 376 | hop = π |
383 | GNUNET_PEER_resolve(old->peer, hop); | 377 | GNUNET_PEER_resolve (old->peer, hop); |
384 | } | 378 | } |
385 | GNUNET_PEER_resolve(parent->peer, &id); | 379 | GNUNET_PEER_resolve (parent->peer, &id); |
386 | copy = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey); | 380 | copy = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey); |
387 | if (NULL == copy) | 381 | if (NULL == copy) |
388 | copy = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); | 382 | copy = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
389 | *copy = *hop; | 383 | *copy = *hop; |
390 | 384 | ||
391 | (void) GNUNET_CONTAINER_multihashmap_put( | 385 | (void) GNUNET_CONTAINER_multihashmap_put (tree->first_hops, &id.hashPubKey, |
392 | tree->first_hops, | 386 | copy, |
393 | &id.hashPubKey, | 387 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
394 | copy, | ||
395 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | ||
396 | 388 | ||
397 | for (n = parent->children_head; NULL != n; n = n->next) | 389 | for (n = parent->children_head; NULL != n; n = n->next) |
398 | { | 390 | { |
@@ -402,34 +394,34 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree, | |||
402 | 394 | ||
403 | 395 | ||
404 | static void | 396 | static void |
405 | tree_node_debug(struct MeshTunnelTreeNode *n, uint16_t level) | 397 | tree_node_debug (struct MeshTunnelTreeNode *n, uint16_t level) |
406 | { | 398 | { |
407 | struct MeshTunnelTreeNode *c; | 399 | struct MeshTunnelTreeNode *c; |
408 | struct GNUNET_PeerIdentity id;; | 400 | struct GNUNET_PeerIdentity id;; |
409 | uint16_t i; | 401 | uint16_t i; |
410 | 402 | ||
411 | for (i = 0; i < level; i++) | 403 | for (i = 0; i < level; i++) |
412 | fprintf(stderr, " "); | 404 | fprintf (stderr, " "); |
413 | if (n->status == MESH_PEER_READY) | 405 | if (n->status == MESH_PEER_READY) |
414 | fprintf(stderr, "#"); | 406 | fprintf (stderr, "#"); |
415 | if (n->status == MESH_PEER_SEARCHING) | 407 | if (n->status == MESH_PEER_SEARCHING) |
416 | fprintf(stderr, "+"); | 408 | fprintf (stderr, "+"); |
417 | if (n->status == MESH_PEER_RELAY) | 409 | if (n->status == MESH_PEER_RELAY) |
418 | fprintf(stderr, "-"); | 410 | fprintf (stderr, "-"); |
419 | if (n->status == MESH_PEER_RECONNECTING) | 411 | if (n->status == MESH_PEER_RECONNECTING) |
420 | fprintf(stderr, "*"); | 412 | fprintf (stderr, "*"); |
421 | 413 | ||
422 | GNUNET_PEER_resolve(n->peer, &id); | 414 | GNUNET_PEER_resolve (n->peer, &id); |
423 | fprintf(stderr, "%s, [%u, %p] ", GNUNET_i2s (&id), n->peer, n); | 415 | fprintf (stderr, "%s, [%u, %p] ", GNUNET_i2s (&id), n->peer, n); |
424 | if (NULL != n->parent) | 416 | if (NULL != n->parent) |
425 | { | 417 | { |
426 | GNUNET_PEER_resolve(n->parent->peer, &id); | 418 | GNUNET_PEER_resolve (n->parent->peer, &id); |
427 | fprintf(stderr, "(-> %s [%u])\n", GNUNET_i2s(&id), n->parent->peer); | 419 | fprintf (stderr, "(-> %s [%u])\n", GNUNET_i2s (&id), n->parent->peer); |
428 | } | 420 | } |
429 | else | 421 | else |
430 | fprintf(stderr, "(root)\n"); | 422 | fprintf (stderr, "(root)\n"); |
431 | for (c = n->children_head; NULL != c; c = c->next) | 423 | for (c = n->children_head; NULL != c; c = c->next) |
432 | tree_node_debug(c, level + 1); | 424 | tree_node_debug (c, level + 1); |
433 | } | 425 | } |
434 | 426 | ||
435 | 427 | ||
@@ -443,30 +435,27 @@ tree_node_destroy (struct MeshTunnelTreeNode *parent) | |||
443 | { | 435 | { |
444 | struct MeshTunnelTreeNode *n; | 436 | struct MeshTunnelTreeNode *n; |
445 | struct MeshTunnelTreeNode *next; | 437 | struct MeshTunnelTreeNode *next; |
438 | |||
446 | #if MESH_TREE_DEBUG | 439 | #if MESH_TREE_DEBUG |
447 | struct GNUNET_PeerIdentity id; | 440 | struct GNUNET_PeerIdentity id; |
448 | 441 | ||
449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 442 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying node %u\n", |
450 | "tree: Destroying node %u\n", | ||
451 | parent->peer); | 443 | parent->peer); |
452 | GNUNET_PEER_resolve (parent->peer, &id); | 444 | GNUNET_PEER_resolve (parent->peer, &id); |
453 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 445 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: (%s)\n", GNUNET_i2s (&id)); |
454 | "tree: (%s)\n", | ||
455 | GNUNET_i2s (&id)); | ||
456 | #endif | 446 | #endif |
457 | n = parent->children_head; | 447 | n = parent->children_head; |
458 | while (NULL != n) | 448 | while (NULL != n) |
459 | { | 449 | { |
460 | next = n->next; | 450 | next = n->next; |
461 | tree_node_destroy(n); | 451 | tree_node_destroy (n); |
462 | n = next; | 452 | n = next; |
463 | } | 453 | } |
464 | GNUNET_PEER_change_rc(parent->peer, -1); | 454 | GNUNET_PEER_change_rc (parent->peer, -1); |
465 | if (NULL != parent->parent) | 455 | if (NULL != parent->parent) |
466 | GNUNET_CONTAINER_DLL_remove(parent->parent->children_head, | 456 | GNUNET_CONTAINER_DLL_remove (parent->parent->children_head, |
467 | parent->parent->children_tail, | 457 | parent->parent->children_tail, parent); |
468 | parent); | 458 | GNUNET_free (parent); |
469 | GNUNET_free(parent); | ||
470 | } | 459 | } |
471 | 460 | ||
472 | 461 | ||
@@ -484,9 +473,9 @@ tree_new (GNUNET_PEER_Id peer) | |||
484 | { | 473 | { |
485 | struct MeshTunnelTree *tree; | 474 | struct MeshTunnelTree *tree; |
486 | 475 | ||
487 | tree = GNUNET_malloc(sizeof (struct MeshTunnelTree)); | 476 | tree = GNUNET_malloc (sizeof (struct MeshTunnelTree)); |
488 | tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32); | 477 | tree->first_hops = GNUNET_CONTAINER_multihashmap_create (32); |
489 | tree->root = tree_node_new(NULL, peer); | 478 | tree->root = tree_node_new (NULL, peer); |
490 | tree->root->status = MESH_PEER_ROOT; | 479 | tree->root->status = MESH_PEER_ROOT; |
491 | 480 | ||
492 | return tree; | 481 | return tree; |
@@ -502,7 +491,7 @@ tree_new (GNUNET_PEER_Id peer) | |||
502 | void | 491 | void |
503 | tree_set_me (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer) | 492 | tree_set_me (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer) |
504 | { | 493 | { |
505 | tree->me = tree_find_peer(tree, peer); | 494 | tree->me = tree_find_peer (tree, peer); |
506 | } | 495 | } |
507 | 496 | ||
508 | 497 | ||
@@ -529,13 +518,12 @@ tree_get_me (struct MeshTunnelTree *tree) | |||
529 | * @param peer A short peer id of local peer. | 518 | * @param peer A short peer id of local peer. |
530 | */ | 519 | */ |
531 | void | 520 | void |
532 | tree_set_status (struct MeshTunnelTree *tree, | 521 | tree_set_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer, |
533 | GNUNET_PEER_Id peer, | ||
534 | enum MeshPeerState status) | 522 | enum MeshPeerState status) |
535 | { | 523 | { |
536 | struct MeshTunnelTreeNode *n; | 524 | struct MeshTunnelTreeNode *n; |
537 | 525 | ||
538 | n = tree_find_peer(tree, peer); | 526 | n = tree_find_peer (tree, peer); |
539 | if (NULL == n) | 527 | if (NULL == n) |
540 | return; | 528 | return; |
541 | n->status = status; | 529 | n->status = status; |
@@ -554,7 +542,7 @@ tree_get_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer) | |||
554 | { | 542 | { |
555 | struct MeshTunnelTreeNode *n; | 543 | struct MeshTunnelTreeNode *n; |
556 | 544 | ||
557 | n = tree_find_peer(tree, peer); | 545 | n = tree_find_peer (tree, peer); |
558 | if (NULL == n) | 546 | if (NULL == n) |
559 | return MESH_PEER_INVALID; | 547 | return MESH_PEER_INVALID; |
560 | return n->status; | 548 | return n->status; |
@@ -589,7 +577,7 @@ tree_get_predecessor (struct MeshTunnelTree *tree) | |||
589 | struct MeshTunnelTreeNode * | 577 | struct MeshTunnelTreeNode * |
590 | tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id) | 578 | tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id) |
591 | { | 579 | { |
592 | return tree_node_find_peer(tree->root, peer_id); | 580 | return tree_node_find_peer (tree->root, peer_id); |
593 | } | 581 | } |
594 | 582 | ||
595 | 583 | ||
@@ -603,8 +591,7 @@ tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id) | |||
603 | static void | 591 | static void |
604 | tree_mark_peers_disconnected (struct MeshTunnelTree *tree, | 592 | tree_mark_peers_disconnected (struct MeshTunnelTree *tree, |
605 | struct MeshTunnelTreeNode *parent, | 593 | struct MeshTunnelTreeNode *parent, |
606 | MeshTreeCallback cb, | 594 | MeshTreeCallback cb, void *cbcls) |
607 | void *cbcls) | ||
608 | { | 595 | { |
609 | struct GNUNET_PeerIdentity *pi; | 596 | struct GNUNET_PeerIdentity *pi; |
610 | struct GNUNET_PeerIdentity id; | 597 | struct GNUNET_PeerIdentity id; |
@@ -622,24 +609,23 @@ tree_mark_peers_disconnected (struct MeshTunnelTree *tree, | |||
622 | } | 609 | } |
623 | 610 | ||
624 | /* Remove and free info about first hop */ | 611 | /* Remove and free info about first hop */ |
625 | GNUNET_PEER_resolve(parent->peer, &id); | 612 | GNUNET_PEER_resolve (parent->peer, &id); |
626 | pi = GNUNET_CONTAINER_multihashmap_get(tree->first_hops, &id.hashPubKey); | 613 | pi = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey); |
627 | GNUNET_CONTAINER_multihashmap_remove_all(tree->first_hops, &id.hashPubKey); | 614 | GNUNET_CONTAINER_multihashmap_remove_all (tree->first_hops, &id.hashPubKey); |
628 | if (NULL != pi) | 615 | if (NULL != pi) |
629 | GNUNET_free(pi); | 616 | GNUNET_free (pi); |
630 | } | 617 | } |
631 | 618 | ||
632 | 619 | ||
633 | /** | 620 | /** |
634 | * Iterate over all children of the local node. | 621 | * Iterate over all children of the local node. |
635 | * | 622 | * |
636 | * @param tree Tree to use. Must have "me" set. | 623 | * @param tree Tree to use. Must have "me" set. |
637 | * @param cb Callback to call over each child. | 624 | * @param cb Callback to call over each child. |
638 | * @param cls Closure. | 625 | * @param cls Closure. |
639 | */ | 626 | */ |
640 | void | 627 | void |
641 | tree_iterate_children (struct MeshTunnelTree *tree, | 628 | tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb, |
642 | MeshTreeCallback cb, | ||
643 | void *cls) | 629 | void *cls) |
644 | { | 630 | { |
645 | struct MeshTunnelTreeNode *n; | 631 | struct MeshTunnelTreeNode *n; |
@@ -665,13 +651,10 @@ tree_iterate_children (struct MeshTunnelTree *tree, | |||
665 | * If not known, NULL to find out and pass on children. | 651 | * If not known, NULL to find out and pass on children. |
666 | */ | 652 | */ |
667 | void | 653 | void |
668 | tree_update_first_hops (struct MeshTunnelTree *tree, | 654 | tree_update_first_hops (struct MeshTunnelTree *tree, GNUNET_PEER_Id parent_id, |
669 | GNUNET_PEER_Id parent_id, | ||
670 | struct GNUNET_PeerIdentity *hop) | 655 | struct GNUNET_PeerIdentity *hop) |
671 | { | 656 | { |
672 | tree_node_update_first_hops(tree, | 657 | tree_node_update_first_hops (tree, tree_find_peer (tree, parent_id), hop); |
673 | tree_find_peer(tree, parent_id), | ||
674 | hop); | ||
675 | } | 658 | } |
676 | 659 | ||
677 | 660 | ||
@@ -689,10 +672,8 @@ tree_update_first_hops (struct MeshTunnelTree *tree, | |||
689 | * NULL when not found | 672 | * NULL when not found |
690 | */ | 673 | */ |
691 | struct MeshTunnelTreeNode * | 674 | struct MeshTunnelTreeNode * |
692 | tree_del_path (struct MeshTunnelTree *t, | 675 | tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id, |
693 | GNUNET_PEER_Id peer_id, | 676 | MeshTreeCallback cb, void *cbcls) |
694 | MeshTreeCallback cb, | ||
695 | void *cbcls) | ||
696 | { | 677 | { |
697 | struct MeshTunnelTreeNode *parent; | 678 | struct MeshTunnelTreeNode *parent; |
698 | struct MeshTunnelTreeNode *node; | 679 | struct MeshTunnelTreeNode *node; |
@@ -700,10 +681,10 @@ tree_del_path (struct MeshTunnelTree *t, | |||
700 | 681 | ||
701 | #if MESH_TREE_DEBUG | 682 | #if MESH_TREE_DEBUG |
702 | struct GNUNET_PeerIdentity id; | 683 | struct GNUNET_PeerIdentity id; |
703 | GNUNET_PEER_resolve(peer_id, &id); | 684 | |
704 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 685 | GNUNET_PEER_resolve (peer_id, &id); |
705 | "tree: Deleting path to %s.\n", | 686 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting path to %s.\n", |
706 | GNUNET_i2s (&id)); | 687 | GNUNET_i2s (&id)); |
707 | #endif | 688 | #endif |
708 | if (peer_id == t->root->peer) | 689 | if (peer_id == t->root->peer) |
709 | return NULL; | 690 | return NULL; |
@@ -713,8 +694,7 @@ tree_del_path (struct MeshTunnelTree *t, | |||
713 | if (n->peer == peer_id) | 694 | if (n->peer == peer_id) |
714 | { | 695 | { |
715 | /* Was already pathless, waiting for reconnection */ | 696 | /* Was already pathless, waiting for reconnection */ |
716 | GNUNET_CONTAINER_DLL_remove (t->disconnected_head, | 697 | GNUNET_CONTAINER_DLL_remove (t->disconnected_head, t->disconnected_tail, |
717 | t->disconnected_tail, | ||
718 | n); | 698 | n); |
719 | return n; | 699 | return n; |
720 | } | 700 | } |
@@ -725,26 +705,24 @@ tree_del_path (struct MeshTunnelTree *t, | |||
725 | node = n; | 705 | node = n; |
726 | 706 | ||
727 | parent = n->parent; | 707 | parent = n->parent; |
728 | GNUNET_CONTAINER_DLL_remove(parent->children_head, parent->children_tail, n); | 708 | GNUNET_CONTAINER_DLL_remove (parent->children_head, parent->children_tail, n); |
729 | n->parent = NULL; | 709 | n->parent = NULL; |
730 | 710 | ||
731 | while (MESH_PEER_RELAY == parent->status && NULL == parent->children_head) | 711 | while (MESH_PEER_RELAY == parent->status && NULL == parent->children_head) |
732 | { | 712 | { |
733 | #if MESH_TREE_DEBUG | 713 | #if MESH_TREE_DEBUG |
734 | GNUNET_PEER_resolve(parent->peer, &id); | 714 | GNUNET_PEER_resolve (parent->peer, &id); |
735 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting node %s.\n", |
736 | "tree: Deleting node %s.\n", | 716 | GNUNET_i2s (&id)); |
737 | GNUNET_i2s (&id)); | ||
738 | #endif | 717 | #endif |
739 | n = parent->parent; | 718 | n = parent->parent; |
740 | tree_node_destroy(parent); | 719 | tree_node_destroy (parent); |
741 | parent = n; | 720 | parent = n; |
742 | } | 721 | } |
743 | #if MESH_TREE_DEBUG | 722 | #if MESH_TREE_DEBUG |
744 | GNUNET_PEER_resolve(parent->peer, &id); | 723 | GNUNET_PEER_resolve (parent->peer, &id); |
745 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 724 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Not deleted peer %s.\n", |
746 | "tree: Not deleted peer %s.\n", | 725 | GNUNET_i2s (&id)); |
747 | GNUNET_i2s (&id)); | ||
748 | #endif | 726 | #endif |
749 | 727 | ||
750 | tree_mark_peers_disconnected (t, node, cb, cbcls); | 728 | tree_mark_peers_disconnected (t, node, cb, cbcls); |
@@ -764,30 +742,30 @@ tree_del_path (struct MeshTunnelTree *t, | |||
764 | * Path must be destroyed afterwards. | 742 | * Path must be destroyed afterwards. |
765 | */ | 743 | */ |
766 | struct MeshPeerPath * | 744 | struct MeshPeerPath * |
767 | tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer) | 745 | tree_get_path_to_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer) |
768 | { | 746 | { |
769 | struct MeshTunnelTreeNode *n; | 747 | struct MeshTunnelTreeNode *n; |
770 | struct MeshPeerPath *p; | 748 | struct MeshPeerPath *p; |
771 | GNUNET_PEER_Id myid = t->me->peer; | 749 | GNUNET_PEER_Id myid = t->me->peer; |
772 | 750 | ||
773 | n = tree_find_peer(t, peer); | 751 | n = tree_find_peer (t, peer); |
774 | if (NULL == n) | 752 | if (NULL == n) |
775 | return NULL; | 753 | return NULL; |
776 | p = path_new(0); | 754 | p = path_new (0); |
777 | 755 | ||
778 | /* Building the path (inverted!) */ | 756 | /* Building the path (inverted!) */ |
779 | while (n->peer != myid) | 757 | while (n->peer != myid) |
780 | { | 758 | { |
781 | GNUNET_array_append(p->peers, p->length, n->peer); | 759 | GNUNET_array_append (p->peers, p->length, n->peer); |
782 | GNUNET_PEER_change_rc(n->peer, 1); | 760 | GNUNET_PEER_change_rc (n->peer, 1); |
783 | n = n->parent; | 761 | n = n->parent; |
784 | if (NULL == n) | 762 | if (NULL == n) |
785 | return NULL; | 763 | return NULL; |
786 | } | 764 | } |
787 | GNUNET_array_append(p->peers, p->length, myid); | 765 | GNUNET_array_append (p->peers, p->length, myid); |
788 | GNUNET_PEER_change_rc(myid, 1); | 766 | GNUNET_PEER_change_rc (myid, 1); |
789 | 767 | ||
790 | path_invert(p); | 768 | path_invert (p); |
791 | 769 | ||
792 | return p; | 770 | return p; |
793 | } | 771 | } |
@@ -816,10 +794,8 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer) | |||
816 | * - do not disconnect peers until new path is created & connected | 794 | * - do not disconnect peers until new path is created & connected |
817 | */ | 795 | */ |
818 | int | 796 | int |
819 | tree_add_path (struct MeshTunnelTree *t, | 797 | tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, |
820 | const struct MeshPeerPath *p, | 798 | MeshTreeCallback cb, void *cbcls) |
821 | MeshTreeCallback cb, | ||
822 | void *cbcls) | ||
823 | { | 799 | { |
824 | struct MeshTunnelTreeNode *parent; | 800 | struct MeshTunnelTreeNode *parent; |
825 | struct MeshTunnelTreeNode *oldnode; | 801 | struct MeshTunnelTreeNode *oldnode; |
@@ -831,18 +807,17 @@ tree_add_path (struct MeshTunnelTree *t, | |||
831 | unsigned int i; | 807 | unsigned int i; |
832 | 808 | ||
833 | #if MESH_TREE_DEBUG | 809 | #if MESH_TREE_DEBUG |
834 | GNUNET_PEER_resolve(p->peers[p->length - 1], &id); | 810 | GNUNET_PEER_resolve (p->peers[p->length - 1], &id); |
835 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 811 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
836 | "tree: Adding path [%u] towards peer %s.\n", | 812 | "tree: Adding path [%u] towards peer %s.\n", p->length, |
837 | p->length, | 813 | GNUNET_i2s (&id)); |
838 | GNUNET_i2s (&id)); | ||
839 | #endif | 814 | #endif |
840 | 815 | ||
841 | if (NULL != t->me) | 816 | if (NULL != t->me) |
842 | myid = t->me->peer; | 817 | myid = t->me->peer; |
843 | else | 818 | else |
844 | myid = 0; | 819 | myid = 0; |
845 | GNUNET_assert(0 != p->length); | 820 | GNUNET_assert (0 != p->length); |
846 | parent = n = t->root; | 821 | parent = n = t->root; |
847 | if (n->peer != p->peers[0]) | 822 | if (n->peer != p->peers[0]) |
848 | { | 823 | { |
@@ -862,10 +837,9 @@ tree_add_path (struct MeshTunnelTree *t, | |||
862 | for (i = 1; i < p->length; i++) | 837 | for (i = 1; i < p->length; i++) |
863 | { | 838 | { |
864 | #if MESH_TREE_DEBUG | 839 | #if MESH_TREE_DEBUG |
865 | GNUNET_PEER_resolve(p->peers[i], &id); | 840 | GNUNET_PEER_resolve (p->peers[i], &id); |
866 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 841 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Looking for peer %s.\n", |
867 | "tree: Looking for peer %s.\n", | 842 | GNUNET_i2s (&id)); |
868 | GNUNET_i2s (&id)); | ||
869 | #endif | 843 | #endif |
870 | parent = n; | 844 | parent = n; |
871 | if (p->peers[i] == myid) | 845 | if (p->peers[i] == myid) |
@@ -875,10 +849,9 @@ tree_add_path (struct MeshTunnelTree *t, | |||
875 | if (c->peer == p->peers[i]) | 849 | if (c->peer == p->peers[i]) |
876 | { | 850 | { |
877 | #if MESH_TREE_DEBUG | 851 | #if MESH_TREE_DEBUG |
878 | GNUNET_PEER_resolve(parent->peer, &id); | 852 | GNUNET_PEER_resolve (parent->peer, &id); |
879 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 853 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
880 | "tree: Found in children of %s.\n", | 854 | "tree: Found in children of %s.\n", GNUNET_i2s (&id)); |
881 | GNUNET_i2s (&id)); | ||
882 | #endif | 855 | #endif |
883 | n = c; | 856 | n = c; |
884 | break; | 857 | break; |
@@ -890,45 +863,40 @@ tree_add_path (struct MeshTunnelTree *t, | |||
890 | break; | 863 | break; |
891 | } | 864 | } |
892 | #if MESH_TREE_DEBUG | 865 | #if MESH_TREE_DEBUG |
893 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 866 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: All childen visited.\n"); |
894 | "tree: All childen visited.\n"); | ||
895 | #endif | 867 | #endif |
896 | /* Add the rest of the path as a branch from parent. */ | 868 | /* Add the rest of the path as a branch from parent. */ |
897 | while (i < p->length) | 869 | while (i < p->length) |
898 | { | 870 | { |
899 | #if MESH_TREE_DEBUG | 871 | #if MESH_TREE_DEBUG |
900 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 872 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Adding peer %u to %u.\n", |
901 | "tree: Adding peer %u to %u.\n", | 873 | p->peers[i], parent->peer); |
902 | p->peers[i], parent->peer); | 874 | GNUNET_PEER_resolve (p->peers[i], &id); |
903 | GNUNET_PEER_resolve(p->peers[i], &id); | 875 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Adding peer %s.\n", |
904 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 876 | GNUNET_i2s (&id)); |
905 | "tree: Adding peer %s.\n", | 877 | GNUNET_PEER_resolve (parent->peer, &id); |
906 | GNUNET_i2s (&id)); | 878 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: to %s.\n", |
907 | GNUNET_PEER_resolve(parent->peer, &id); | 879 | GNUNET_i2s (&id)); |
908 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
909 | "tree: to %s.\n", | ||
910 | GNUNET_i2s (&id)); | ||
911 | #endif | 880 | #endif |
912 | 881 | ||
913 | if (i == p->length - 1 && NULL != oldnode) | 882 | if (i == p->length - 1 && NULL != oldnode) |
914 | { | 883 | { |
915 | #if MESH_TREE_DEBUG | 884 | #if MESH_TREE_DEBUG |
916 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 885 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
917 | "tree: Putting old node into place.\n"); | 886 | "tree: Putting old node into place.\n"); |
918 | #endif | 887 | #endif |
919 | oldnode->parent = parent; | 888 | oldnode->parent = parent; |
920 | GNUNET_CONTAINER_DLL_insert(parent->children_head, | 889 | GNUNET_CONTAINER_DLL_insert (parent->children_head, parent->children_tail, |
921 | parent->children_tail, | 890 | oldnode); |
922 | oldnode); | ||
923 | tree_node_update_first_hops (t, oldnode, NULL); | 891 | tree_node_update_first_hops (t, oldnode, NULL); |
924 | n = oldnode; | 892 | n = oldnode; |
925 | } | 893 | } |
926 | else | 894 | else |
927 | { | 895 | { |
928 | #if MESH_TREE_DEBUG | 896 | #if MESH_TREE_DEBUG |
929 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n"); | 897 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n"); |
930 | #endif | 898 | #endif |
931 | n = tree_node_new(parent, p->peers[i]); | 899 | n = tree_node_new (parent, p->peers[i]); |
932 | n->status = MESH_PEER_RELAY; | 900 | n->status = MESH_PEER_RELAY; |
933 | if (n->peer == myid) | 901 | if (n->peer == myid) |
934 | t->me = n; | 902 | t->me = n; |
@@ -943,16 +911,14 @@ tree_add_path (struct MeshTunnelTree *t, | |||
943 | { | 911 | { |
944 | #if MESH_TREE_DEBUG | 912 | #if MESH_TREE_DEBUG |
945 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 913 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
946 | "MESH: finding first hop (own pos %d/%u)\n", | 914 | "MESH: finding first hop (own pos %d/%u)\n", me, |
947 | me, p->length - 1); | 915 | p->length - 1); |
948 | #endif | 916 | #endif |
949 | GNUNET_PEER_resolve (p->peers[me + 1], &id); | 917 | GNUNET_PEER_resolve (p->peers[me + 1], &id); |
950 | tree_update_first_hops(t, | 918 | tree_update_first_hops (t, p->peers[p->length - 1], &id); |
951 | p->peers[p->length - 1], | ||
952 | &id); | ||
953 | } | 919 | } |
954 | #if MESH_TREE_DEBUG | 920 | #if MESH_TREE_DEBUG |
955 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n"); | 921 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n"); |
956 | #endif | 922 | #endif |
957 | return GNUNET_OK; | 923 | return GNUNET_OK; |
958 | } | 924 | } |
@@ -971,40 +937,32 @@ tree_add_path (struct MeshTunnelTree *t, | |||
971 | * @return Short ID of the first disconnected peer in the tree. | 937 | * @return Short ID of the first disconnected peer in the tree. |
972 | */ | 938 | */ |
973 | GNUNET_PEER_Id | 939 | GNUNET_PEER_Id |
974 | tree_notify_connection_broken (struct MeshTunnelTree *t, | 940 | tree_notify_connection_broken (struct MeshTunnelTree *t, GNUNET_PEER_Id p1, |
975 | GNUNET_PEER_Id p1, | 941 | GNUNET_PEER_Id p2, MeshTreeCallback cb, |
976 | GNUNET_PEER_Id p2, | ||
977 | MeshTreeCallback cb, | ||
978 | void *cbcls) | 942 | void *cbcls) |
979 | { | 943 | { |
980 | struct MeshTunnelTreeNode *n; | 944 | struct MeshTunnelTreeNode *n; |
981 | struct MeshTunnelTreeNode *c; | 945 | struct MeshTunnelTreeNode *c; |
982 | 946 | ||
983 | n = tree_find_peer(t, p1); | 947 | n = tree_find_peer (t, p1); |
984 | if (NULL == n) | 948 | if (NULL == n) |
985 | return 0; | 949 | return 0; |
986 | if (NULL != n->parent && n->parent->peer == p2) | 950 | if (NULL != n->parent && n->parent->peer == p2) |
987 | { | 951 | { |
988 | tree_mark_peers_disconnected(t, n, cb, cbcls); | 952 | tree_mark_peers_disconnected (t, n, cb, cbcls); |
989 | GNUNET_CONTAINER_DLL_remove(n->parent->children_head, | 953 | GNUNET_CONTAINER_DLL_remove (n->parent->children_head, |
990 | n->parent->children_tail, | 954 | n->parent->children_tail, n); |
991 | n); | 955 | GNUNET_CONTAINER_DLL_insert (t->disconnected_head, t->disconnected_tail, n); |
992 | GNUNET_CONTAINER_DLL_insert(t->disconnected_head, | ||
993 | t->disconnected_tail, | ||
994 | n); | ||
995 | return p1; | 956 | return p1; |
996 | } | 957 | } |
997 | for (c = n->children_head; NULL != c; c = c->next) | 958 | for (c = n->children_head; NULL != c; c = c->next) |
998 | { | 959 | { |
999 | if (c->peer == p2) | 960 | if (c->peer == p2) |
1000 | { | 961 | { |
1001 | tree_mark_peers_disconnected(t, c, cb, cbcls); | 962 | tree_mark_peers_disconnected (t, c, cb, cbcls); |
1002 | GNUNET_CONTAINER_DLL_remove(n->children_head, | 963 | GNUNET_CONTAINER_DLL_remove (n->children_head, n->children_tail, c); |
1003 | n->children_tail, | 964 | GNUNET_CONTAINER_DLL_insert (t->disconnected_head, t->disconnected_tail, |
1004 | c); | 965 | c); |
1005 | GNUNET_CONTAINER_DLL_insert(t->disconnected_head, | ||
1006 | t->disconnected_tail, | ||
1007 | c); | ||
1008 | return p2; | 966 | return p2; |
1009 | } | 967 | } |
1010 | } | 968 | } |
@@ -1026,21 +984,19 @@ tree_notify_connection_broken (struct MeshTunnelTree *t, | |||
1026 | * @return GNUNET_OK or GNUNET_SYSERR | 984 | * @return GNUNET_OK or GNUNET_SYSERR |
1027 | */ | 985 | */ |
1028 | int | 986 | int |
1029 | tree_del_peer (struct MeshTunnelTree *t, | 987 | tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer, |
1030 | GNUNET_PEER_Id peer, | 988 | MeshTreeCallback cb, void *cbcls) |
1031 | MeshTreeCallback cb, | ||
1032 | void *cbcls) | ||
1033 | { | 989 | { |
1034 | struct MeshTunnelTreeNode *n; | 990 | struct MeshTunnelTreeNode *n; |
1035 | 991 | ||
1036 | n = tree_del_path(t, peer, cb, cbcls); | 992 | n = tree_del_path (t, peer, cb, cbcls); |
1037 | if (NULL == n) | 993 | if (NULL == n) |
1038 | { | 994 | { |
1039 | GNUNET_break (0); | 995 | GNUNET_break (0); |
1040 | return GNUNET_YES; | 996 | return GNUNET_YES; |
1041 | } | 997 | } |
1042 | GNUNET_break_op (NULL == n->children_head); | 998 | GNUNET_break_op (NULL == n->children_head); |
1043 | tree_node_destroy(n); | 999 | tree_node_destroy (n); |
1044 | if (NULL == t->root->children_head && t->me != t->root) | 1000 | if (NULL == t->root->children_head && t->me != t->root) |
1045 | { | 1001 | { |
1046 | tree_node_destroy (t->root); | 1002 | tree_node_destroy (t->root); |
@@ -1057,9 +1013,9 @@ tree_del_peer (struct MeshTunnelTree *t, | |||
1057 | * @param t The tree | 1013 | * @param t The tree |
1058 | */ | 1014 | */ |
1059 | void | 1015 | void |
1060 | tree_debug(struct MeshTunnelTree *t) | 1016 | tree_debug (struct MeshTunnelTree *t) |
1061 | { | 1017 | { |
1062 | tree_node_debug(t->root, 0); | 1018 | tree_node_debug (t->root, 0); |
1063 | } | 1019 | } |
1064 | 1020 | ||
1065 | 1021 | ||
@@ -1075,14 +1031,14 @@ tree_debug(struct MeshTunnelTree *t) | |||
1075 | static int | 1031 | static int |
1076 | iterate_free (void *cls, const GNUNET_HashCode * key, void *value) | 1032 | iterate_free (void *cls, const GNUNET_HashCode * key, void *value) |
1077 | { | 1033 | { |
1078 | GNUNET_free(value); | 1034 | GNUNET_free (value); |
1079 | return GNUNET_YES; | 1035 | return GNUNET_YES; |
1080 | } | 1036 | } |
1081 | 1037 | ||
1082 | 1038 | ||
1083 | /** | 1039 | /** |
1084 | * Destroy the whole tree and free all used memory and Peer_Ids | 1040 | * Destroy the whole tree and free all used memory and Peer_Ids |
1085 | * | 1041 | * |
1086 | * @param t Tree to be destroyed | 1042 | * @param t Tree to be destroyed |
1087 | */ | 1043 | */ |
1088 | void | 1044 | void |
@@ -1091,8 +1047,8 @@ tree_destroy (struct MeshTunnelTree *t) | |||
1091 | #if MESH_TREE_DEBUG | 1047 | #if MESH_TREE_DEBUG |
1092 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying tree\n"); | 1048 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying tree\n"); |
1093 | #endif | 1049 | #endif |
1094 | tree_node_destroy(t->root); | 1050 | tree_node_destroy (t->root); |
1095 | GNUNET_CONTAINER_multihashmap_iterate(t->first_hops, &iterate_free, NULL); | 1051 | GNUNET_CONTAINER_multihashmap_iterate (t->first_hops, &iterate_free, NULL); |
1096 | GNUNET_CONTAINER_multihashmap_destroy(t->first_hops); | 1052 | GNUNET_CONTAINER_multihashmap_destroy (t->first_hops); |
1097 | GNUNET_free(t); | 1053 | GNUNET_free (t); |
1098 | } | 1054 | } |