2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file mesh/test_mesh_path.c
23 * @brief test mesh path: test of path management api
24 * @author Bartlomiej Polot
28 #include "gnunet_common.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_dht_service.h"
31 #include "gnunet_mesh_service_new.h"
33 #include "mesh_tunnel_tree.h"
39 struct GNUNET_PeerIdentity* pi[10];
40 struct MeshTunnelTree *tree;
43 cb (const struct MeshTunnelTreeNode *n)
45 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Desconnected %u\n", n->peer);
48 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n");
60 for (i = 0; i < 10; i++)
69 * Convert an integer int to a peer identity
71 static struct GNUNET_PeerIdentity *
74 struct GNUNET_PeerIdentity *pi;
76 pi = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
77 pi->hashPubKey.bits[0] = id;
83 main (int argc, char *argv[])
85 struct MeshTunnelTreeNode *node;
86 struct MeshTunnelTreeNode *node2;
87 struct MeshPeerPath *path;
88 struct MeshPeerPath *path1;
93 GNUNET_log_setup ("test_mesh_api_path",
100 for (i = 0; i < 10; i++)
103 GNUNET_break (i != GNUNET_PEER_intern(pi[i]));
104 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", i,
105 GNUNET_h2s(&pi[i]->hashPubKey));
107 tree = GNUNET_malloc(sizeof(struct MeshTunnelTree));
108 tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32);
109 tree->root = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode));
110 tree->root->peer = 0;
111 tree->me = tree->root;
112 path = GNUNET_malloc(sizeof(struct MeshPeerPath));
113 path->peers = GNUNET_malloc(sizeof(GNUNET_PEER_Id) * 4);
120 tree_add_path(tree, path, &cb);
122 path1 = tree_get_path_to_peer(tree, 3);
123 if (path->length != path1->length ||
124 memcmp(path->peers, path1->peers, path->length) != 0)
126 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n");
130 node = tree_find_peer(tree->root, 3);
133 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
136 if (node->status != MESH_PEER_SEARCHING)
138 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
141 node->status = MESH_PEER_READY;
142 if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1)
144 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
149 node = tree_find_peer(tree->root, 2);
152 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
155 if (node->status != MESH_PEER_RELAY)
157 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
160 if (node->nchildren != 1)
162 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
165 if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1)
167 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
171 node = tree_find_peer(tree->root, 1);
174 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
177 if (node->status != MESH_PEER_RELAY)
179 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
182 if (node->nchildren != 1)
184 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
189 tree_add_path(tree, path, &cb);
191 node = tree_find_peer(tree->root, 2);
194 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
197 if (node->status != MESH_PEER_SEARCHING)
199 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
202 if (node->nchildren != 1)
204 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
207 if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1)
209 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
212 if (GNUNET_PEER_search(path_get_first_hop(tree, 2)) != 1)
214 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
218 node = tree_find_peer(tree->root, 1);
221 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
224 if (node->status != MESH_PEER_RELAY)
226 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
229 if (node->nchildren != 1)
231 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
237 tree_add_path(tree, path, &cb);
239 node = tree_find_peer(tree->root, 2);
242 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
245 if (node->status != MESH_PEER_SEARCHING)
247 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
250 if (node->nchildren != 2)
252 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
255 if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1)
257 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
260 if (GNUNET_PEER_search(path_get_first_hop(tree, 4)) != 1)
262 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
266 node = tree_find_peer(tree->root, 1);
269 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
272 if (node->status != MESH_PEER_RELAY)
274 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
277 if (node->nchildren != 1)
279 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
283 node = tree_find_peer(tree->root, 4);
286 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
289 node->status = MESH_PEER_READY;
291 node2 = tree_del_path(tree, 4, &cb);
294 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
297 if (node2->peer != 4)
299 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
302 // GNUNET_free(node2); FIXME destroy
303 node = tree_find_peer(tree->root, 2);
306 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
309 if (node->status != MESH_PEER_SEARCHING)
311 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
314 if (node->nchildren != 1)
316 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
323 tree_add_path(tree, path, cb);
326 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
329 node = tree_find_peer(tree->root, 2);
332 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
335 if (node->status != MESH_PEER_SEARCHING)
337 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
340 if (node->nchildren != 0)
342 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
345 node = tree_find_peer(tree->root, 3);
348 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
351 if (node->status != MESH_PEER_SEARCHING)
353 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
356 if (node->nchildren != 0)
358 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
361 if (GNUNET_PEER_search(path_get_first_hop(tree, 2)) != 1)
363 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
366 if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 3)
368 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
375 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed);
378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test ok\n");