aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/mesh_tunnel_tree.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-09-26 12:24:41 +0000
committerBart Polot <bart@net.in.tum.de>2011-09-26 12:24:41 +0000
commit535d51c21e7ed8b8e1f9bec144c54f177de6b2f5 (patch)
treea824b52be525a48289f2191c638f4d5c9d26d138 /src/mesh/mesh_tunnel_tree.c
parentaa390e34b0b9e793e1c9f82a606ad0c10fcc84ca (diff)
downloadgnunet-535d51c21e7ed8b8e1f9bec144c54f177de6b2f5.tar.gz
gnunet-535d51c21e7ed8b8e1f9bec144c54f177de6b2f5.zip
Added new api in the tree module to handle core or remote disconnections
Added reconnecting mechanism to find new paths in case of peer disconnection
Diffstat (limited to 'src/mesh/mesh_tunnel_tree.c')
-rw-r--r--src/mesh/mesh_tunnel_tree.c109
1 files changed, 106 insertions, 3 deletions
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c
index 748683a34..9c8d5e97d 100644
--- a/src/mesh/mesh_tunnel_tree.c
+++ b/src/mesh/mesh_tunnel_tree.c
@@ -386,9 +386,22 @@ tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id,
386 struct MeshTunnelTreeNode *node; 386 struct MeshTunnelTreeNode *node;
387 struct MeshTunnelTreeNode *n; 387 struct MeshTunnelTreeNode *n;
388 388
389 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting path to %u.\n", peer_id); 389 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
390 "tree: Deleting path to %u.\n", peer_id);
390 if (peer_id == t->root->peer) 391 if (peer_id == t->root->peer)
391 return NULL; 392 return NULL;
393
394 for (n = t->disconnected_head; NULL != n; n = n->next)
395 {
396 if (n->peer == peer_id)
397 {
398 /* Was already pathless, waiting for reconnection */
399 GNUNET_CONTAINER_DLL_remove (t->disconnected_head,
400 t->disconnected_tail,
401 n);
402 return n;
403 }
404 }
392 n = tree_find_peer (t->me, peer_id); 405 n = tree_find_peer (t->me, peer_id);
393 if (NULL == n) 406 if (NULL == n)
394 return NULL; 407 return NULL;
@@ -470,8 +483,9 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
470 * - do not disconnect peers until new path is created & connected 483 * - do not disconnect peers until new path is created & connected
471 */ 484 */
472int 485int
473tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, 486tree_add_path (struct MeshTunnelTree *t,
474 MeshNodeDisconnectCB cb) 487 const struct MeshPeerPath *p,
488 MeshNodeDisconnectCB cb)
475{ 489{
476 struct MeshTunnelTreeNode *parent; 490 struct MeshTunnelTreeNode *parent;
477 struct MeshTunnelTreeNode *oldnode; 491 struct MeshTunnelTreeNode *oldnode;
@@ -589,6 +603,95 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
589 603
590 604
591/** 605/**
606 * Notifies a tree that a connection it might be using is broken.
607 * Marks all peers down the paths as disconnected and notifies the client.
608 *
609 * @param t Tree to use.
610 * @param p1 Short id of one of the peers (order unimportant)
611 * @param p2 Short id of one of the peers (order unimportant)
612 * @param cb Function to call for every peer that is marked as disconnected.
613 *
614 * @return Short ID of the first disconnected peer in the tree.
615 */
616GNUNET_PEER_Id
617tree_notify_connection_broken (struct MeshTunnelTree *t,
618 GNUNET_PEER_Id p1,
619 GNUNET_PEER_Id p2,
620 MeshNodeDisconnectCB cb)
621{
622 struct MeshTunnelTreeNode *n;
623 struct MeshTunnelTreeNode *c;
624
625 n = tree_find_peer(t->me, p1);
626 if (NULL == n)
627 return 0;
628 if (NULL != n->parent && n->parent->peer == p2)
629 {
630 tree_mark_peers_disconnected(t, n, cb);
631 GNUNET_CONTAINER_DLL_remove(n->parent->children_head,
632 n->parent->children_tail,
633 n);
634 GNUNET_CONTAINER_DLL_insert(t->disconnected_head,
635 t->disconnected_tail,
636 n);
637 return p1;
638 }
639 for (c = n->children_head; NULL != c; c = c->next)
640 {
641 if (c->peer == p2)
642 {
643 tree_mark_peers_disconnected(t, c, cb);
644 GNUNET_CONTAINER_DLL_remove(n->children_head,
645 n->children_tail,
646 c);
647 GNUNET_CONTAINER_DLL_insert(t->disconnected_head,
648 t->disconnected_tail,
649 c);
650 return p2;
651 }
652 }
653 return 0;
654}
655
656
657/**
658 * Deletes a peer from a tunnel, marking its children as disconnected.
659 *
660 * @param t Tunnel tree to use.
661 * @param peer Short ID of the peer to remove from the tunnel tree.
662 * @param cb Callback to notify client of disconnected peers.
663 *
664 * @return GNUNET_OK or GNUNET_SYSERR
665 */
666int
667tree_del_peer (struct MeshTunnelTree *t,
668 GNUNET_PEER_Id peer,
669 MeshNodeDisconnectCB cb)
670{
671 struct MeshTunnelTreeNode *n;
672 struct MeshTunnelTreeNode *c;
673 struct MeshTunnelTreeNode *aux;
674
675 n = tree_del_path(t, peer, cb);
676 c = n->children_head;
677 while (NULL != c)
678 {
679 aux = c->next;
680 GNUNET_CONTAINER_DLL_remove(n->children_head,
681 n->children_tail,
682 c);
683 GNUNET_CONTAINER_DLL_insert(t->disconnected_head,
684 t->disconnected_tail,
685 c);
686 cb (c);
687 c = aux;
688 }
689 tree_node_destroy(n);
690 return GNUNET_OK;
691}
692
693
694/**
592 * Print the tree on stderr 695 * Print the tree on stderr
593 * 696 *
594 * @param t The tree 697 * @param t The tree