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"
41 cb (const struct MeshTunnelTreeNode *n)
43 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Desconnected %u\n", n->peer);
46 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n");
53 * Convert an integer int to a peer identity
55 static struct GNUNET_PeerIdentity *
58 struct GNUNET_PeerIdentity *pi;
60 pi = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
61 pi->hashPubKey.bits[0] = id;
67 main (int argc, char *argv[])
69 struct GNUNET_PeerIdentity* pi[10];
70 struct MeshTunnelTreeNode *node;
71 struct MeshTunnelTreeNode *node2;
72 struct MeshTunnelTree *tree;
73 struct MeshPeerPath *path[10];
78 GNUNET_log_setup ("test_mesh_api_path",
85 for (i = 0; i < 10; i++)
88 GNUNET_break (i != GNUNET_PEER_intern(pi[i]));
89 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", i,
90 GNUNET_h2s(&pi[i]->hashPubKey));
92 tree = GNUNET_malloc(sizeof(struct MeshTunnelTree));
93 tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32);
94 tree->root = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode));
96 tree->me = tree->root;
97 path[0] = GNUNET_malloc(sizeof(struct MeshPeerPath));
98 path[0]->peers = GNUNET_malloc(sizeof(GNUNET_PEER_Id) * 4);
99 path[0]->peers[0] = 0;
100 path[0]->peers[1] = 1;
101 path[0]->peers[2] = 2;
102 path[0]->peers[3] = 3;
105 tunnel_add_path(tree, path[0], &cb);
106 path[1] = tunnel_get_path_to_peer(tree, 3);
107 if (path[0]->length != path[1]->length ||
108 memcmp(path[0]->peers, path[1]->peers, path[0]->length) != 0)
110 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n");
113 path_destroy(path[1]);
114 node = tunnel_find_peer(tree->root, 3);
117 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
120 if (node->status != MESH_PEER_SEARCHING)
122 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
126 node = tunnel_find_peer(tree->root, 2);
129 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
132 if (node->status != MESH_PEER_RELAY)
134 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
137 if (node->nchildren != 1)
139 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
144 tunnel_add_path(tree, path[0], &cb);
146 node = tunnel_find_peer(tree->root, 2);
149 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
152 if (node->status != MESH_PEER_SEARCHING)
154 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
157 if (node->nchildren != 1)
159 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
164 path[0]->peers[3] = 4;
165 tunnel_add_path(tree, path[0], &cb);
167 node = tunnel_find_peer(tree->root, 2);
170 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
173 if (node->status != MESH_PEER_SEARCHING)
175 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
178 if (node->nchildren != 2)
180 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
184 node = tunnel_find_peer(tree->root, 4);
187 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
190 node->status = MESH_PEER_READY;
192 node2 = tunnel_del_path(tree, 4, &cb);
195 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
198 if (node2->peer != 4)
200 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
203 // GNUNET_free(node2); FIXME destroy
204 node = tunnel_find_peer(tree->root, 2);
207 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
210 if (node->status != MESH_PEER_SEARCHING)
212 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
215 if (node->nchildren != 1)
217 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
223 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed);
226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test ok\n");