- Fixed test_monitor testcase crsh
authorBart Polot <bart@net.in.tum.de>
Mon, 20 Feb 2012 12:28:18 +0000 (12:28 +0000)
committerBart Polot <bart@net.in.tum.de>
Mon, 20 Feb 2012 12:28:18 +0000 (12:28 +0000)
src/dht/test_dht_monitor.c

index 06489ff15ca0eb300087928b86f9c398093edb0e..8e3bd95eff7271175099c7a02d3a32b63560fd14 100644 (file)
@@ -122,9 +122,6 @@ struct GNUNET_DHT_GetHandle *get_h_far;
 const char *id_origin = "FC74";
 const char *id_far = "2UVH";
 
-unsigned int i_origin;
-unsigned int i_far;
-
 struct GNUNET_TESTING_Daemon *d_far;
 struct GNUNET_TESTING_Daemon *o;
 
@@ -249,7 +246,7 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
               GNUNET_h2s_full (&d_far->id.hashPubKey));
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test:        from %s\n",
               GNUNET_h2s_full (&o->id.hashPubKey));
-  get_h_far = GNUNET_DHT_get_start (hs[i_origin], GNUNET_TIME_UNIT_FOREVER_REL,        /* timeout */
+  get_h_far = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL,        /* timeout */
                                     GNUNET_BLOCK_TYPE_TEST,     /* type */
                                     &d_far->id.hashPubKey,      /*key to search */
                                     4U, /* replication level */
@@ -262,11 +259,23 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 }
 
 
+/**
+ * Periodic function used to put the ID of the far peer in the DHT.
+ * 
+ * @param cls Closure (not used).
+ * @param tc Task context.
+ */
 static void
 put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct GNUNET_TESTING_Daemon *d;
 
+  if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+  {
+    put_task = GNUNET_SCHEDULER_NO_TASK;
+    return;
+  }
+
   d = GNUNET_TESTING_daemon_get (pg, 4);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting into DHT: %s\n",
               GNUNET_h2s_full (&d->id.hashPubKey));
@@ -327,14 +336,17 @@ monitor_dht_cb (void *cls,
 
 /**
  * peergroup_ready: start test when all peers are connected
+ *
  * @param cls closure
  * @param emsg error message
  */
 static void
 peergroup_ready (void *cls, const char *emsg)
 {
+  struct GNUNET_TESTING_Daemon *d;
   char *buf;
   int buf_len;
+  unsigned int i;
 
   if (emsg != NULL)
   {
@@ -372,6 +384,14 @@ peergroup_ready (void *cls, const char *emsg)
   o = GNUNET_TESTING_daemon_get (pg, 0);
   d_far = GNUNET_TESTING_daemon_get (pg, 4);
 
+  for (i = 0; i < num_peers; i++)
+  {
+    d = GNUNET_TESTING_daemon_get (pg, i);
+    hs[i] = GNUNET_DHT_connect (d->cfg, 32);
+    mhs[i] = GNUNET_DHT_monitor_start(hs[i], GNUNET_BLOCK_TYPE_ANY, NULL,
+                                      &monitor_dht_cb, (void *)(long)i);
+  }
+
   if ((NULL == o) || (NULL == d_far))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,