From f591bfdc7b28e93b9412c2d9e031c8848ce90f55 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 21 Sep 2011 01:35:02 +0000 Subject: [PATCH] Added testcase code, fixed minor bugs --- src/mesh/Makefile.am | 2 +- src/mesh/gnunet-service-mesh.c | 2 +- src/mesh/mesh_tunnel_tree.c | 1 + src/mesh/test_mesh_path_api.c | 168 +++++++++++++++++++++++++++++++-- 4 files changed, 163 insertions(+), 10 deletions(-) diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am index 26f4de7a5..a79958832 100644 --- a/src/mesh/Makefile.am +++ b/src/mesh/Makefile.am @@ -65,7 +65,7 @@ test_mesh_api_DEPENDENCIES = \ $(top_builddir)/src/util/libgnunetutil.la test_mesh_path_api_SOURCES = \ - test_mesh_path_api.c + test_mesh_path_api.c mesh_tunnel_tree.c test_mesh_path_api_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/dht/libgnunetdht.la diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 811553e08..f927c3666 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -1004,7 +1004,7 @@ tunnel_get (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid) void -notify_peer_disconnected (struct MeshTunnelTreeNode *n) +notify_peer_disconnected (const struct MeshTunnelTreeNode *n) { } diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c index e838cefc1..ad9e9032a 100644 --- a/src/mesh/mesh_tunnel_tree.c +++ b/src/mesh/mesh_tunnel_tree.c @@ -357,6 +357,7 @@ tunnel_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, i++; parent = n; } + n->status = MESH_PEER_SEARCHING; /* Add info about first hop into hashmap. */ if (me < p->length - 1) diff --git a/src/mesh/test_mesh_path_api.c b/src/mesh/test_mesh_path_api.c index cc0cbc558..9bff42686 100644 --- a/src/mesh/test_mesh_path_api.c +++ b/src/mesh/test_mesh_path_api.c @@ -34,8 +34,23 @@ #define VERBOSE 1 +int failed; +int cb_call; + +void +cb (const struct MeshTunnelTreeNode *n) +{ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Desconnected %u\n", n->peer); + if(0 == cb_call) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n"); + failed++; + } + cb_call--; +} + /** - * Convert an integer int oa peer identity + * Convert an integer int to a peer identity */ static struct GNUNET_PeerIdentity * get_pi (uint32_t id) @@ -47,12 +62,19 @@ get_pi (uint32_t id) return pi; } + int main (int argc, char *argv[]) { - struct GNUNET_PeerIdentity* pi; - int result; + struct GNUNET_PeerIdentity* pi[10]; + struct MeshTunnelTreeNode *node; + struct MeshTunnelTreeNode *node2; + struct MeshTunnelTree *tree; + struct MeshPeerPath *path[10]; + unsigned int i; + failed = 0; + cb_call = 0; GNUNET_log_setup ("test_mesh_api_path", #if VERBOSE "DEBUG", @@ -60,15 +82,145 @@ main (int argc, char *argv[]) "WARNING", #endif NULL); + for (i = 0; i < 10; i++) + { + pi[i] = get_pi(i); + GNUNET_break (i != GNUNET_PEER_intern(pi[i])); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", i, + GNUNET_h2s(&pi[i]->hashPubKey)); + } + tree = GNUNET_malloc(sizeof(struct MeshTunnelTree)); + tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32); + tree->root = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode)); + tree->root->peer = 0; + tree->me = tree->root; + path[0] = GNUNET_malloc(sizeof(struct MeshPeerPath)); + path[0]->peers = GNUNET_malloc(sizeof(GNUNET_PEER_Id) * 4); + path[0]->peers[0] = 0; + path[0]->peers[1] = 1; + path[0]->peers[2] = 2; + path[0]->peers[3] = 3; + path[0]->length = 4; + + tunnel_add_path(tree, path[0], &cb); + path[1] = tunnel_get_path_to_peer(tree, 3); + if (path[0]->length != path[1]->length || + memcmp(path[0]->peers, path[1]->peers, path[0]->length) != 0) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n"); + failed++; + } + path_destroy(path[1]); + node = tunnel_find_peer(tree->root, 3); + if (node->peer != 3) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); + failed++; + } + if (node->status != MESH_PEER_SEARCHING) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); + failed++; + } + + node = tunnel_find_peer(tree->root, 2); + if (node->peer != 2) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); + failed++; + } + if (node->status != MESH_PEER_RELAY) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); + failed++; + } + if (node->nchildren != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); + failed++; + } + + path[0]->length--; + tunnel_add_path(tree, path[0], &cb); + + node = tunnel_find_peer(tree->root, 2); + if (node->peer != 2) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); + failed++; + } + if (node->status != MESH_PEER_SEARCHING) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); + failed++; + } + if (node->nchildren != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); + failed++; + } + + path[0]->length = 4; + path[0]->peers[3] = 4; + tunnel_add_path(tree, path[0], &cb); - pi = get_pi(1); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer 1: %s\n", GNUNET_h2s(&pi->hashPubKey)); + node = tunnel_find_peer(tree->root, 2); + if (node->peer != 2) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); + failed++; + } + if (node->status != MESH_PEER_SEARCHING) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); + failed++; + } + if (node->nchildren != 2) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); + failed++; + } - result = GNUNET_OK; + node = tunnel_find_peer(tree->root, 4); + if (node->peer != 4) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); + failed++; + } + node->status = MESH_PEER_READY; + cb_call = 1; + node2 = tunnel_del_path(tree, 4, &cb); + if (cb_call != 0) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); + failed++; + } + if (node2->peer != 4) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); + failed++; + } +// GNUNET_free(node2); FIXME destroy + node = tunnel_find_peer(tree->root, 2); + if (node->peer != 2) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); + failed++; + } + if (node->status != MESH_PEER_SEARCHING) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); + failed++; + } + if (node->nchildren != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); + failed++; + } - if (GNUNET_SYSERR == result) + if (failed > 0) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test failed\n"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed); return 1; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test ok\n"); -- 2.25.1