aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/mesh_tunnel_tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh/mesh_tunnel_tree.c')
-rw-r--r--src/mesh/mesh_tunnel_tree.c136
1 files changed, 57 insertions, 79 deletions
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c
index 63f5aef58..98ff9be88 100644
--- a/src/mesh/mesh_tunnel_tree.c
+++ b/src/mesh/mesh_tunnel_tree.c
@@ -181,45 +181,6 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree,
181 struct MeshTunnelTreeNode *parent, 181 struct MeshTunnelTreeNode *parent,
182 struct GNUNET_PeerIdentity *hop); 182 struct GNUNET_PeerIdentity *hop);
183 183
184/**
185 * Find the first peer whom to send a packet to go down this path
186 *
187 * @param t The tunnel tree to use
188 * @param peer The peerinfo of the peer we are trying to reach
189 *
190 * @return peerinfo of the peer who is the first hop in the tunnel
191 * NULL on error
192 */
193struct GNUNET_PeerIdentity *
194path_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
195{
196 struct GNUNET_PeerIdentity id;
197 struct GNUNET_PeerIdentity *r;
198
199 GNUNET_PEER_resolve (peer, &id);
200 r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey);
201 if (NULL == r)
202 {
203 struct MeshTunnelTreeNode *n;
204
205 n = tree_find_peer (t, peer);
206 if (NULL != t->me && NULL != n)
207 {
208 tree_node_update_first_hops (t, n, NULL);
209 r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey);
210 GNUNET_assert (NULL != r);
211 }
212 else
213 {
214 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
215 "Tree structure inconsistent! me: %p, n: %p", t->me, n);
216 GNUNET_break (0);
217 }
218 }
219
220 return r;
221}
222
223 184
224/** 185/**
225 * Get the length of a path 186 * Get the length of a path
@@ -360,8 +321,8 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree,
360 while (aux != tree->me) 321 while (aux != tree->me)
361 { 322 {
362#if MESH_TREE_DEBUG 323#if MESH_TREE_DEBUG
363 GNUNET_PEER_resolve (old->peer, &id); 324 GNUNET_PEER_resolve (aux->peer, &id);
364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: ... its not %s.\n", 325 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: ... checking %s.\n",
365 GNUNET_i2s (&id)); 326 GNUNET_i2s (&id));
366#endif 327#endif
367 old = aux; 328 old = aux;
@@ -483,35 +444,6 @@ tree_new (GNUNET_PEER_Id peer)
483 444
484 445
485/** 446/**
486 * Set own identity in the tree
487 *
488 * @param tree Tree.
489 * @param peer A short peer id of local peer.
490 */
491void
492tree_set_me (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer)
493{
494 tree->me = tree_find_peer (tree, peer);
495}
496
497
498/**
499 * Get the id of the local node of the tree.
500 *
501 * @param tree Tree whose local id we want to now.
502 *
503 * @return Short peer id of local peer.
504 */
505GNUNET_PEER_Id
506tree_get_me (struct MeshTunnelTree *tree)
507{
508 if (NULL != tree->me)
509 return tree->me->peer;
510 else
511 return (GNUNET_PEER_Id) 0;
512}
513
514/**
515 * Set the status of a node. 447 * Set the status of a node.
516 * 448 *
517 * @param tree Tree. 449 * @param tree Tree.
@@ -567,6 +499,46 @@ tree_get_predecessor (struct MeshTunnelTree *tree)
567 499
568 500
569/** 501/**
502 * Find the first peer whom to send a packet to go down this path
503 *
504 * @param t The tunnel tree to use
505 * @param peer The peerinfo of the peer we are trying to reach
506 *
507 * @return peerinfo of the peer who is the first hop in the tunnel
508 * NULL on error
509 */
510struct GNUNET_PeerIdentity *
511tree_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
512{
513 struct GNUNET_PeerIdentity id;
514 struct GNUNET_PeerIdentity *r;
515
516 GNUNET_PEER_resolve (peer, &id);
517 r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey);
518 if (NULL == r)
519 {
520 struct MeshTunnelTreeNode *n;
521
522 n = tree_find_peer (t, peer);
523 if (NULL != t->me && NULL != n)
524 {
525 tree_node_update_first_hops (t, n, NULL);
526 r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey);
527 GNUNET_assert (NULL != r);
528 }
529 else
530 {
531 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
532 "Tree structure inconsistent! me: %p, n: %p", t->me, n);
533 GNUNET_break (0);
534 }
535 }
536
537 return r;
538}
539
540
541/**
570 * Find the given peer in the tree. 542 * Find the given peer in the tree.
571 * 543 *
572 * @param tree Tree where to look for the peer. 544 * @param tree Tree where to look for the peer.
@@ -805,7 +777,6 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
805 struct MeshTunnelTreeNode *n; 777 struct MeshTunnelTreeNode *n;
806 struct MeshTunnelTreeNode *c; 778 struct MeshTunnelTreeNode *c;
807 struct GNUNET_PeerIdentity id; 779 struct GNUNET_PeerIdentity id;
808 GNUNET_PEER_Id myid;
809 int me; 780 int me;
810 unsigned int i; 781 unsigned int i;
811 782
@@ -816,10 +787,6 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
816 GNUNET_i2s (&id)); 787 GNUNET_i2s (&id));
817#endif 788#endif
818 789
819 if (NULL != t->me)
820 myid = t->me->peer;
821 else
822 myid = 0;
823 GNUNET_assert (0 != p->length); 790 GNUNET_assert (0 != p->length);
824 parent = n = t->root; 791 parent = n = t->root;
825 if (n->peer != p->peers[0]) 792 if (n->peer != p->peers[0])
@@ -836,7 +803,7 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
836 * - Length of the path is expected to be log N (size of whole network). 803 * - Length of the path is expected to be log N (size of whole network).
837 * - Each level of the tree is expected to have log n children (size of tree). 804 * - Each level of the tree is expected to have log n children (size of tree).
838 */ 805 */
839 me = t->root->peer == myid ? 0 : -1; 806 me = t->root->peer == 1 ? 0 : -1;
840 for (i = 1; i < p->length; i++) 807 for (i = 1; i < p->length; i++)
841 { 808 {
842#if MESH_TREE_DEBUG 809#if MESH_TREE_DEBUG
@@ -845,7 +812,7 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
845 GNUNET_i2s (&id)); 812 GNUNET_i2s (&id));
846#endif 813#endif
847 parent = n; 814 parent = n;
848 if (p->peers[i] == myid) 815 if (p->peers[i] == 1)
849 me = i; 816 me = i;
850 for (c = n->children_head; NULL != c; c = c->next) 817 for (c = n->children_head; NULL != c; c = c->next)
851 { 818 {
@@ -901,14 +868,19 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
901#endif 868#endif
902 n = tree_node_new (parent, p->peers[i]); 869 n = tree_node_new (parent, p->peers[i]);
903 n->status = MESH_PEER_RELAY; 870 n->status = MESH_PEER_RELAY;
904 if (n->peer == myid) 871 if (n->peer == 1)
872 {
905 t->me = n; 873 t->me = n;
874 me = i;
875 }
906 } 876 }
907 i++; 877 i++;
908 parent = n; 878 parent = n;
909 } 879 }
910 n->status = MESH_PEER_SEARCHING; 880 n->status = MESH_PEER_SEARCHING;
911 881
882 GNUNET_break (-1 != me);
883
912 /* Add info about first hop into hashmap. */ 884 /* Add info about first hop into hashmap. */
913 if (-1 != me && me < p->length - 1) 885 if (-1 != me && me < p->length - 1)
914 { 886 {
@@ -918,9 +890,15 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
918 p->length - 1); 890 p->length - 1);
919#endif 891#endif
920 GNUNET_PEER_resolve (p->peers[me + 1], &id); 892 GNUNET_PEER_resolve (p->peers[me + 1], &id);
921 tree_update_first_hops (t, p->peers[p->length - 1], &id); 893 tree_update_first_hops (t, p->peers[me + 1], &id);
922 } 894 }
923#if MESH_TREE_DEBUG 895#if MESH_TREE_DEBUG
896 else
897 {
898 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
899 "MESH: was last in path, not updating first hops (%d/%u)\n",
900 me, p->length - 1);
901 }
924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n"); 902 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n");
925#endif 903#endif
926 return GNUNET_OK; 904 return GNUNET_OK;