diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-11-12 00:33:15 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-11-12 00:33:15 +0000 |
commit | 4acf4de35680033d0a05463a7478bbfb4b407a94 (patch) | |
tree | 9b2592f6ba743ba483f21e89b3561efd14e0108a /src/mesh | |
parent | 60a5ec4e8707df05bf0645aff5086f193ae89643 (diff) | |
download | gnunet-4acf4de35680033d0a05463a7478bbfb4b407a94.tar.gz gnunet-4acf4de35680033d0a05463a7478bbfb4b407a94.zip |
Changed tree library: now assumes own short ID == 1, refactored code in library and mesh service, adapted and extended library testcase
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 12 | ||||
-rw-r--r-- | src/mesh/mesh_tunnel_tree.c | 136 | ||||
-rw-r--r-- | src/mesh/mesh_tunnel_tree.h | 47 | ||||
-rw-r--r-- | src/mesh/test_mesh_tree_api.c | 97 |
4 files changed, 146 insertions, 146 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 09eb8df1a..7665909e6 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -1278,7 +1278,7 @@ send_destroy_path (struct MeshTunnel *t, GNUNET_PEER_Id destination) | |||
1278 | { | 1278 | { |
1279 | GNUNET_PEER_resolve (p->peers[i], &pi[i]); | 1279 | GNUNET_PEER_resolve (p->peers[i], &pi[i]); |
1280 | } | 1280 | } |
1281 | send_message (&msg->header, path_get_first_hop (t->tree, destination)); | 1281 | send_message (&msg->header, tree_get_first_hop (t->tree, destination)); |
1282 | } | 1282 | } |
1283 | path_destroy (p); | 1283 | path_destroy (p); |
1284 | } | 1284 | } |
@@ -1888,12 +1888,10 @@ tunnel_add_path (struct MeshTunnel *t, struct MeshPeerPath *p, | |||
1888 | 1888 | ||
1889 | GNUNET_assert (0 != own_pos); | 1889 | GNUNET_assert (0 != own_pos); |
1890 | tree_add_path (t->tree, p, NULL, NULL); | 1890 | tree_add_path (t->tree, p, NULL, NULL); |
1891 | if (tree_get_me (t->tree) == 0) | ||
1892 | tree_set_me (t->tree, p->peers[own_pos]); | ||
1893 | if (own_pos < p->length - 1) | 1891 | if (own_pos < p->length - 1) |
1894 | { | 1892 | { |
1895 | GNUNET_PEER_resolve (p->peers[own_pos + 1], &id); | 1893 | GNUNET_PEER_resolve (p->peers[own_pos + 1], &id); |
1896 | tree_update_first_hops (t->tree, tree_get_me (t->tree), &id); | 1894 | tree_update_first_hops (t->tree, myid, &id); |
1897 | } | 1895 | } |
1898 | } | 1896 | } |
1899 | 1897 | ||
@@ -2019,7 +2017,6 @@ tunnel_send_multicast (struct MeshTunnel *t, | |||
2019 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2017 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2020 | "MESH: sending a multicast packet...\n"); | 2018 | "MESH: sending a multicast packet...\n"); |
2021 | #endif | 2019 | #endif |
2022 | GNUNET_assert (tree_get_me (t->tree) != 0); | ||
2023 | mdata = GNUNET_malloc (sizeof (struct MeshMulticastData)); | 2020 | mdata = GNUNET_malloc (sizeof (struct MeshMulticastData)); |
2024 | mdata->data_len = ntohs (msg->size); | 2021 | mdata->data_len = ntohs (msg->size); |
2025 | mdata->reference_counter = GNUNET_malloc (sizeof (unsigned int)); | 2022 | mdata->reference_counter = GNUNET_malloc (sizeof (unsigned int)); |
@@ -2280,7 +2277,7 @@ send_core_create_path (void *cls, size_t size, void *buf) | |||
2280 | info->peer->core_transmit[info->pos] = | 2277 | info->peer->core_transmit[info->pos] = |
2281 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, | 2278 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, |
2282 | GNUNET_TIME_UNIT_FOREVER_REL, | 2279 | GNUNET_TIME_UNIT_FOREVER_REL, |
2283 | path_get_first_hop (t->tree, | 2280 | tree_get_first_hop (t->tree, |
2284 | peer->id), | 2281 | peer->id), |
2285 | size_needed, &send_core_create_path, | 2282 | size_needed, &send_core_create_path, |
2286 | info); | 2283 | info); |
@@ -2851,7 +2848,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2851 | } | 2848 | } |
2852 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2849 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2853 | "MESH: not for us, retransmitting...\n"); | 2850 | "MESH: not for us, retransmitting...\n"); |
2854 | send_message (message, path_get_first_hop (t->tree, pid)); | 2851 | send_message (message, tree_get_first_hop (t->tree, pid)); |
2855 | return GNUNET_OK; | 2852 | return GNUNET_OK; |
2856 | } | 2853 | } |
2857 | 2854 | ||
@@ -3565,7 +3562,6 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
3565 | return; | 3562 | return; |
3566 | } | 3563 | } |
3567 | t->tree = tree_new (myid); | 3564 | t->tree = tree_new (myid); |
3568 | tree_set_me (t->tree, myid); | ||
3569 | 3565 | ||
3570 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 3566 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3571 | return; | 3567 | return; |
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 | */ | ||
193 | struct GNUNET_PeerIdentity * | ||
194 | path_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 | */ | ||
491 | void | ||
492 | tree_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 | */ | ||
505 | GNUNET_PEER_Id | ||
506 | tree_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 | */ | ||
510 | struct GNUNET_PeerIdentity * | ||
511 | tree_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; |
diff --git a/src/mesh/mesh_tunnel_tree.h b/src/mesh/mesh_tunnel_tree.h index 094a617cb..5060fa1a7 100644 --- a/src/mesh/mesh_tunnel_tree.h +++ b/src/mesh/mesh_tunnel_tree.h | |||
@@ -101,19 +101,6 @@ path_duplicate (struct MeshPeerPath *path); | |||
101 | 101 | ||
102 | 102 | ||
103 | /** | 103 | /** |
104 | * Find the first peer whom to send a packet to go down this path | ||
105 | * | ||
106 | * @param t The tunnel tree to use | ||
107 | * @param peer The peerinfo of the peer we are trying to reach | ||
108 | * | ||
109 | * @return peerinfo of the peer who is the first hop in the tunnel | ||
110 | * NULL on error | ||
111 | */ | ||
112 | struct GNUNET_PeerIdentity * | ||
113 | path_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer); | ||
114 | |||
115 | |||
116 | /** | ||
117 | * Get the length of a path | 104 | * Get the length of a path |
118 | * | 105 | * |
119 | * @param p The path to measure, with the local peer at any point of it | 106 | * @param p The path to measure, with the local peer at any point of it |
@@ -172,27 +159,6 @@ tree_new (GNUNET_PEER_Id peer); | |||
172 | 159 | ||
173 | 160 | ||
174 | /** | 161 | /** |
175 | * Set own identity in the tree | ||
176 | * | ||
177 | * @param tree Tree. | ||
178 | * @param peer A short peer id of local peer. | ||
179 | */ | ||
180 | void | ||
181 | tree_set_me (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer); | ||
182 | |||
183 | |||
184 | /** | ||
185 | * Get the id of the local id of the tree. | ||
186 | * | ||
187 | * @param tree Tree whose local id we want to now. | ||
188 | * | ||
189 | * @return Short peer id of local peer. | ||
190 | */ | ||
191 | GNUNET_PEER_Id | ||
192 | tree_get_me (struct MeshTunnelTree *tree); | ||
193 | |||
194 | |||
195 | /** | ||
196 | * Set the status of a node. | 162 | * Set the status of a node. |
197 | * | 163 | * |
198 | * @param tree Tree. | 164 | * @param tree Tree. |
@@ -226,6 +192,19 @@ tree_get_predecessor (struct MeshTunnelTree *tree); | |||
226 | 192 | ||
227 | 193 | ||
228 | /** | 194 | /** |
195 | * Find the first peer whom to send a packet to go down this path | ||
196 | * | ||
197 | * @param t The tunnel tree to use | ||
198 | * @param peer The peerinfo of the peer we are trying to reach | ||
199 | * | ||
200 | * @return peerinfo of the peer who is the first hop in the tunnel | ||
201 | * NULL on error | ||
202 | */ | ||
203 | struct GNUNET_PeerIdentity * | ||
204 | tree_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer); | ||
205 | |||
206 | |||
207 | /** | ||
229 | * Find the given peer in the tree. | 208 | * Find the given peer in the tree. |
230 | * | 209 | * |
231 | * @param tree Tree where to look for the peer. | 210 | * @param tree Tree where to look for the peer. |
diff --git a/src/mesh/test_mesh_tree_api.c b/src/mesh/test_mesh_tree_api.c index cbe694c11..77fd799bd 100644 --- a/src/mesh/test_mesh_tree_api.c +++ b/src/mesh/test_mesh_tree_api.c | |||
@@ -72,18 +72,21 @@ test_assert (GNUNET_PEER_Id peer_id, enum MeshPeerState status, | |||
72 | unsigned int i; | 72 | unsigned int i; |
73 | int pre_failed; | 73 | int pre_failed; |
74 | 74 | ||
75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Checking peer %u\n", peer_id); | ||
75 | pre_failed = failed; | 76 | pre_failed = failed; |
76 | n = tree_find_peer (tree, peer_id); | 77 | n = tree_find_peer (tree, peer_id); |
77 | if (n->peer != peer_id) | 78 | if (n->peer != peer_id) |
78 | { | 79 | { |
79 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 80 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
80 | "Retrieved peer has wrong ID! (%u, %u)\n", n->peer, peer_id); | 81 | "Retrieved peer has wrong ID! (Got %u, expected %u)\n", |
82 | n->peer, peer_id); | ||
81 | failed++; | 83 | failed++; |
82 | } | 84 | } |
83 | if (n->status != status) | 85 | if (n->status != status) |
84 | { | 86 | { |
85 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 87 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
86 | "Retrieved peer has wrong status! (%u, %u)\n", n->status, | 88 | "Retrieved peer has wrong status! (Got %u, expected %u)\n", |
89 | n->status, | ||
87 | status); | 90 | status); |
88 | failed++; | 91 | failed++; |
89 | } | 92 | } |
@@ -91,15 +94,15 @@ test_assert (GNUNET_PEER_Id peer_id, enum MeshPeerState status, | |||
91 | if (i != children) | 94 | if (i != children) |
92 | { | 95 | { |
93 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 96 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
94 | "Retrieved peer wrong has number of children! (%u, %u)\n", i, | 97 | "Retrieved peer wrong has number of children! (Got %u, expected %u)\n", |
95 | children); | 98 | i, children); |
96 | failed++; | 99 | failed++; |
97 | } | 100 | } |
98 | if (0 != first_hop && | 101 | if (0 != first_hop && |
99 | GNUNET_PEER_search (path_get_first_hop (tree, peer_id)) != first_hop) | 102 | GNUNET_PEER_search (tree_get_first_hop (tree, peer_id)) != first_hop) |
100 | { | 103 | { |
101 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Wrong first hop! (%u, %u)\n", | 104 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Wrong first hop! (Got %u, expected %u)\n", |
102 | GNUNET_PEER_search (path_get_first_hop (tree, peer_id)), | 105 | GNUNET_PEER_search (tree_get_first_hop (tree, peer_id)), |
103 | first_hop); | 106 | first_hop); |
104 | failed++; | 107 | failed++; |
105 | } | 108 | } |
@@ -109,7 +112,7 @@ test_assert (GNUNET_PEER_Id peer_id, enum MeshPeerState status, | |||
109 | 112 | ||
110 | GNUNET_PEER_resolve (peer_id, &id); | 113 | GNUNET_PEER_resolve (peer_id, &id); |
111 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 114 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
112 | "*** Peer %s (%u) has failed %d checks! (real, expected)\n", | 115 | "*** Peer %s (%u) has failed %d checks!\n", |
113 | GNUNET_i2s (&id), peer_id, failed - pre_failed); | 116 | GNUNET_i2s (&id), peer_id, failed - pre_failed); |
114 | } | 117 | } |
115 | } | 118 | } |
@@ -145,7 +148,6 @@ int | |||
145 | main (int argc, char *argv[]) | 148 | main (int argc, char *argv[]) |
146 | { | 149 | { |
147 | struct MeshTunnelTreeNode *node; | 150 | struct MeshTunnelTreeNode *node; |
148 | struct MeshTunnelTreeNode *node2; | ||
149 | struct MeshPeerPath *path; | 151 | struct MeshPeerPath *path; |
150 | struct MeshPeerPath *path1; | 152 | struct MeshPeerPath *path1; |
151 | unsigned int i; | 153 | unsigned int i; |
@@ -201,7 +203,7 @@ main (int argc, char *argv[]) | |||
201 | test_assert (2, MESH_PEER_RELAY, 1, 0); | 203 | test_assert (2, MESH_PEER_RELAY, 1, 0); |
202 | test_assert (1, MESH_PEER_ROOT, 1, 0); | 204 | test_assert (1, MESH_PEER_ROOT, 1, 0); |
203 | 205 | ||
204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n"); | 206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path 1 2 3 5\n"); |
205 | path->length++; | 207 | path->length++; |
206 | path->peers[3] = 5; | 208 | path->peers[3] = 5; |
207 | tree_add_path (tree, path, &cb, NULL); | 209 | tree_add_path (tree, path, &cb, NULL); |
@@ -213,18 +215,17 @@ main (int argc, char *argv[]) | |||
213 | test_assert (2, MESH_PEER_RELAY, 1, 0); | 215 | test_assert (2, MESH_PEER_RELAY, 1, 0); |
214 | test_assert (1, MESH_PEER_ROOT, 1, 0); | 216 | test_assert (1, MESH_PEER_ROOT, 1, 0); |
215 | 217 | ||
216 | node = tree_find_peer (tree, 5); | 218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path (5)\n"); |
217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n"); | 219 | tree_set_status(tree, 5, MESH_PEER_READY); |
218 | node->status = MESH_PEER_READY; | ||
219 | cb_call = 1; | 220 | cb_call = 1; |
220 | node2 = tree_del_path (tree, 5, &cb, NULL); | 221 | node = tree_del_path (tree, 5, &cb, NULL); |
221 | tree_debug (tree); | 222 | tree_debug (tree); |
222 | if (cb_call != 0) | 223 | if (cb_call != 0) |
223 | { | 224 | { |
224 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); | 225 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); |
225 | failed++; | 226 | failed++; |
226 | } | 227 | } |
227 | if (node2->peer != 5) | 228 | if (node->peer != 5) |
228 | { | 229 | { |
229 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); | 230 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); |
230 | failed++; | 231 | failed++; |
@@ -236,7 +237,7 @@ main (int argc, char *argv[]) | |||
236 | test_assert (1, MESH_PEER_ROOT, 1, 0); | 237 | test_assert (1, MESH_PEER_ROOT, 1, 0); |
237 | 238 | ||
238 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n"); | 239 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n"); |
239 | GNUNET_free (node2); | 240 | GNUNET_free (node); |
240 | 241 | ||
241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 242 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
242 | "test: Adding new shorter first path...\n"); | 243 | "test: Adding new shorter first path...\n"); |
@@ -261,30 +262,76 @@ main (int argc, char *argv[]) | |||
261 | GNUNET_free (path); | 262 | GNUNET_free (path); |
262 | tree_destroy (tree); | 263 | tree_destroy (tree); |
263 | 264 | ||
265 | /****************************************************************************/ | ||
266 | |||
264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test:\n"); | 267 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test:\n"); |
265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n"); | 268 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n"); |
266 | for (i = 0; i < 10; i++) | 269 | for (i = 0; i < 10; i++) |
267 | { | 270 | { |
268 | GNUNET_break (i + 1 == GNUNET_PEER_intern (pi[i])); | 271 | GNUNET_break (i + 1 == GNUNET_PEER_intern (pi[i])); |
269 | } | 272 | } |
270 | tree = tree_new (1); | 273 | tree = tree_new (2); |
271 | path = path_new (3); | 274 | path = path_new (8); |
272 | path->peers[0] = 1; | 275 | path->peers[0] = 2; |
273 | path->peers[1] = 2; | 276 | path->peers[1] = 1; |
274 | path->peers[2] = 3; | 277 | path->peers[2] = 3; |
275 | path->length = 3; | 278 | path->length = 3; |
276 | 279 | ||
277 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n"); | 280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 2 1 3\n"); |
278 | tree_add_path (tree, path, &cb, NULL); | 281 | tree_add_path (tree, path, &cb, NULL); |
279 | tree_debug (tree); | 282 | tree_debug (tree); |
280 | tree_set_me (tree, 2); | ||
281 | 283 | ||
282 | test_assert (3, MESH_PEER_SEARCHING, 0, 3); | 284 | test_assert (3, MESH_PEER_SEARCHING, 0, 3); |
283 | test_assert (2, MESH_PEER_RELAY, 1, 0); | 285 | test_assert (1, MESH_PEER_RELAY, 1, 0); |
284 | test_assert (1, MESH_PEER_ROOT, 1, 0); | 286 | test_assert (2, MESH_PEER_ROOT, 1, 0); |
287 | |||
288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding long path: 2 1 4 5 3\n"); | ||
289 | path->peers[2] = 4; | ||
290 | path->peers[3] = 5; | ||
291 | path->peers[4] = 3; | ||
292 | path->length = 5; | ||
293 | tree_add_path (tree, path, &cb, NULL); | ||
294 | tree_debug (tree); | ||
285 | 295 | ||
286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n"); | 296 | test_assert (3, MESH_PEER_SEARCHING, 0, 4); |
297 | test_assert (5, MESH_PEER_RELAY, 1, 4); | ||
298 | test_assert (4, MESH_PEER_RELAY, 1, 4); | ||
299 | test_assert (1, MESH_PEER_RELAY, 1, 0); | ||
300 | test_assert (2, MESH_PEER_ROOT, 1, 0); | ||
301 | |||
302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
303 | "test: Even longer path: 2 6 1 7 8 4 5 3\n"); | ||
304 | path->peers[0] = 2; | ||
305 | path->peers[1] = 6; | ||
306 | path->peers[2] = 1; | ||
307 | path->peers[3] = 7; | ||
308 | path->peers[4] = 8; | ||
309 | path->peers[5] = 4; | ||
310 | path->peers[6] = 5; | ||
311 | path->peers[7] = 3; | ||
312 | path->length = 8; | ||
313 | tree_add_path (tree, path, &cb, NULL); | ||
314 | tree_debug (tree); | ||
315 | |||
316 | test_assert (3, MESH_PEER_SEARCHING, 0, 7); | ||
317 | test_assert (5, MESH_PEER_RELAY, 1, 7); | ||
318 | test_assert (4, MESH_PEER_RELAY, 1, 7); | ||
319 | test_assert (8, MESH_PEER_RELAY, 1, 7); | ||
320 | test_assert (7, MESH_PEER_RELAY, 1, 7); | ||
321 | test_assert (1, MESH_PEER_RELAY, 1, 0); | ||
322 | test_assert (6, MESH_PEER_RELAY, 1, 0); | ||
323 | test_assert (2, MESH_PEER_ROOT, 1, 0); | ||
324 | |||
325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 2 1 3\n"); | ||
326 | path->peers[1] = 1; | ||
327 | path->peers[2] = 3; | ||
328 | path->length = 3; | ||
287 | tree_add_path (tree, path, &cb, NULL); | 329 | tree_add_path (tree, path, &cb, NULL); |
330 | tree_debug (tree); | ||
331 | |||
332 | test_assert (3, MESH_PEER_SEARCHING, 0, 3); | ||
333 | test_assert (1, MESH_PEER_RELAY, 1, 0); | ||
334 | test_assert (2, MESH_PEER_ROOT, 1, 0); | ||
288 | 335 | ||
289 | GNUNET_free (path->peers); | 336 | GNUNET_free (path->peers); |
290 | GNUNET_free (path); | 337 | GNUNET_free (path); |