Added testcase code, fixed minor bugs
authorBart Polot <bart@net.in.tum.de>
Wed, 21 Sep 2011 01:35:02 +0000 (01:35 +0000)
committerBart Polot <bart@net.in.tum.de>
Wed, 21 Sep 2011 01:35:02 +0000 (01:35 +0000)
src/mesh/Makefile.am
src/mesh/gnunet-service-mesh.c
src/mesh/mesh_tunnel_tree.c
src/mesh/test_mesh_path_api.c

index 26f4de7a56c9657f0a1d3bb1c50b3ccc345c4924..a7995883297e9f856504bc93274d295fc5c71e58 100644 (file)
@@ -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
index 811553e0807e7ff36b1070a0358f4df488534275..f927c36661c2beff36afb0f9d19c64215d76a50f 100644 (file)
@@ -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)
 {
   
 }
index e838cefc105e3a10d9b4d18ad6965c04c0872649..ad9e9032abce45719da517242ff12038cf184d16 100644 (file)
@@ -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)
index cc0cbc558b59375b614807b267582f27a6f2f952..9bff4268668da92f9c669ebabbb7cd907460b402 100644 (file)
 
 #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");