- Improved test to count only relevant messages, completed info transmitted from...
authorBart Polot <bart@net.in.tum.de>
Thu, 5 Jan 2012 21:16:52 +0000 (21:16 +0000)
committerBart Polot <bart@net.in.tum.de>
Thu, 5 Jan 2012 21:16:52 +0000 (21:16 +0000)
src/dht/gnunet-service-dht_clients.c
src/dht/test_dht_monitor.c

index 2c013b38f1a8be981052a2f36a3a53ee71f372e1..a5ac0c32b1ac00ac6be087666949c3352404173c 100644 (file)
@@ -1091,11 +1091,19 @@ GDS_CLIENTS_process_monitor (uint16_t mtype,
       mmsg->header.size = htons (msize - sizeof (struct PendingMessage));
       mmsg->header.type = htons (mtype);
       mmsg->expiration = GNUNET_TIME_absolute_hton(exp);
+      memcpy (&mmsg->key, key, sizeof (GNUNET_HashCode));
+      mmsg->put_path_length = htonl(putl);
+      mmsg->get_path_length = htonl(getl);
       path = (struct GNUNET_PeerIdentity *) &mmsg[1];
-      memcpy (path, put_path, putl * sizeof (struct GNUNET_PeerIdentity));
-      path = &path[putl];
-      memcpy (path, get_path, getl * sizeof (struct GNUNET_PeerIdentity));
-      memcpy (&path[getl], data, size);
+      if (putl > 0)
+      {
+        memcpy (path, put_path, putl * sizeof (struct GNUNET_PeerIdentity));
+        path = &path[putl];
+      }
+      if (getl > 0)
+        memcpy (path, get_path, getl * sizeof (struct GNUNET_PeerIdentity));
+      if (size > 0)
+        memcpy (&path[getl], data, size);
       add_pending_message (m->client, pm);
     }
   }
index ae1cf3ecf1e5663b103b2aeb1f0ec27a942e0e85..37e270d926a25d93687be32f3cd6c2d12db34dd4 100644 (file)
@@ -130,6 +130,8 @@ struct GNUNET_TESTING_Daemon *o;
 
 unsigned int monitor_counter;
 
+int in_test;
+
 /**
  * Check whether peers successfully shut down.
  */
@@ -241,6 +243,7 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
 static void
 do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  in_test = GNUNET_YES;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n");
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n",
               GNUNET_h2s_full (&d_far->id.hashPubKey));
@@ -308,11 +311,16 @@ monitor_dht_cb (void *cls,
                 const void *data,
                 size_t size)
 {
+  const char *s_key;
+
+  s_key = GNUNET_h2s(key);
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "%u got a message of type %u for key %s\n",
-              cls, mtype, GNUNET_h2s (key));
-  if (mtype == GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET ||
-      mtype == GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT)
+              cls, mtype, s_key);
+
+  if ((mtype == GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET ||
+       mtype == GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT) &&
+      strncmp (s_key, id_far, 4) == 0 && in_test == GNUNET_YES)
     monitor_counter++;
 }
 
@@ -566,6 +574,7 @@ main (int xargc, char *xargv[])
     NULL
   };
 
+  in_test = GNUNET_NO;
   GNUNET_PROGRAM_run (sizeof (argv) / sizeof (char *) - 1, argv,
                       "test_dht_monitor",
                       gettext_noop ("Test dht monitoring in a small 2D torus."),