Fixed bugs, added debug messages, extended unicast testcase
authorBart Polot <bart@net.in.tum.de>
Wed, 12 Oct 2011 07:10:07 +0000 (07:10 +0000)
committerBart Polot <bart@net.in.tum.de>
Wed, 12 Oct 2011 07:10:07 +0000 (07:10 +0000)
src/mesh/gnunet-service-mesh.c
src/mesh/test_mesh_small_unicast.c

index dfec4157fe2db4c273ac340027e050503673c924..026c8b8828fe01c790ccde2216ea534599ddaaa0 100644 (file)
@@ -1427,6 +1427,8 @@ tunnel_add_path (struct MeshTunnel *t,
 {
   GNUNET_assert (0 != own_pos);
   tree_add_path(t->tree, p, NULL);
+  if (NULL == t->tree->me)
+    t->tree->me = tree_find_peer(t->tree->root, p->peers[own_pos]);
 }
 
 
@@ -2243,10 +2245,14 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
                       const struct GNUNET_TRANSPORT_ATS_Information *atsi)
 {
   struct GNUNET_MESH_PathACK *msg;
+  struct GNUNET_PeerIdentity id;
   struct MeshTunnelTreeNode *n;
   struct MeshPeerInfo *peer_info;
   struct MeshTunnel *t;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "MESH: Received a path ACK msg [%s]\n",
+              GNUNET_i2s(&my_full_id));
   msg = (struct GNUNET_MESH_PathACK *) message;
   t = tunnel_get (&msg->oid, msg->tid);
   if (NULL == t)
@@ -2258,6 +2264,8 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
   /* Message for us? */
   if (0 == memcmp (&msg->oid, &my_full_id, sizeof (struct GNUNET_PeerIdentity)))
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "MESH:   It's for us!\n");
     if (NULL == t->client)
     {
       GNUNET_break_op (0);
@@ -2279,7 +2287,10 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
     send_client_peer_connected(t, peer_info->id);
     return GNUNET_OK;
   }
-
+  
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "MESH:   not for us, retransmitting...\n");
+  GNUNET_PEER_resolve(t->tree->me->parent->peer, &id);
   peer_info = peer_info_get (&msg->oid);
   if (NULL == peer_info)
   {
@@ -2291,8 +2302,7 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
   memcpy (msg, message, sizeof (struct GNUNET_MESH_PathACK));
   GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
                                      GNUNET_TIME_UNIT_FOREVER_REL,
-                                     path_get_first_hop (t->tree,
-                                                         peer_info->id),
+                                     &id,
                                      sizeof (struct GNUNET_MESH_PathACK),
                                      &send_core_data_raw, msg);
   return GNUNET_OK;
@@ -3303,20 +3313,26 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
   struct MeshPeerInfo *peer_info;
   struct MeshPeerPath *path;
 
+#if MESH_DEBUG_CONNECTION
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n");
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH:      %s\n",
               GNUNET_h2s(&my_full_id.hashPubKey));
+#endif
   peer_info = peer_info_get (peer);
   if (myid == peer_info->id)
   {
+#if MESH_DEBUG_CONNECTION
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH:      (self)\n");
+#endif
     return;
   }
+#if MESH_DEBUG_CONNECTION
   else
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH:      %s\n",
                 GNUNET_h2s(&peer->hashPubKey));
   }
+#endif
   path = path_new (2);
   path->peers[0] = myid;
   path->peers[1] = peer_info->id;
@@ -3338,7 +3354,9 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
   struct MeshPeerInfo *pi;
   unsigned int i;
 
+#if MESH_DEBUG_CONNECTION
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer disconnected\n");
+#endif
   pi = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
   if (NULL == pi)
   {
@@ -3350,10 +3368,12 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
     peer_info_cancel_transmission(pi, i);
   }
   path_remove_from_peer (pi, pi->id, myid);
+#if MESH_DEBUG_CONNECTION
   if (myid == pi->id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH:      (self)\n");
   }
+#endif
   return;
 }
 
index 871aa0c2587bc6d7e1c576ea3affa2c3746ed5a2..5660dc0b049ae38866ecc3760ef9cb44dd87ab64 100644 (file)
@@ -47,15 +47,18 @@ struct StatsContext
 };
 
 
-// static struct MeshPeer *peer_head;
-//
-// static struct MeshPeer *peer_tail;
-
 /**
  * How long until we give up on connecting the peers?
  */
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1500)
 
+/**
+ * Time to wait for stuff that should be rather fast
+ */
+#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
+
+#define OK_GOAL 2
+
 static int ok;
 
 /**
@@ -147,7 +150,7 @@ shutdown_callback (void *cls, const char *emsg)
 #if VERBOSE
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Shutdown of peers failed!\n");
 #endif
-    ok++;
+    ok--;
   }
   else
   {
@@ -220,9 +223,11 @@ incoming_tunnel (void *cls,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "test: Incoming tunnel from %s\n",
               GNUNET_i2s(initiator));
+  ok++;
   GNUNET_SCHEDULER_cancel (disconnect_task);
-  disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_mesh_peers, NULL);
-  ok = 0;
+  disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME,
+                                                 &disconnect_mesh_peers,
+                                                 NULL);
   return NULL;
 }
 
@@ -258,6 +263,8 @@ dh (void *cls, const struct GNUNET_PeerIdentity *peer)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "test: peer %s disconnected\n",
               GNUNET_i2s(peer));
+  if (memcmp(&d2->id, peer, sizeof(d2->id)))
+    ok++;
   return;
 }
 
@@ -428,7 +435,7 @@ peergroup_ready (void *cls, const char *emsg)
                 "test: Peergroup callback called with error, aborting test!\n");
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "test: Error from testing: `%s'\n", emsg);
-    ok++;
+    ok--;
     GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
     return;
   }
@@ -529,7 +536,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   unsigned long long temp_wait;
   struct GNUNET_TESTING_Host *hosts;
 
-  ok = 1;
+  ok = 0;
   testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
 
   GNUNET_log_setup ("test_mesh_small_unicast",
@@ -662,11 +669,12 @@ main (int argc, char *argv[])
 #if REMOVE_DIR
   GNUNET_DISK_directory_remove ("/tmp/test_mesh_small_unicast");
 #endif
-  if (0 != ok)
+  if (OK_GOAL != ok)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: FAILED!\n");
+    return 1;
   }
-  return ok;
+  return 0;
 }
 
 /* end of test_mesh_small_unicast.c */