print stat
[oweals/gnunet.git] / src / dht / test_dht_twopeer.c
index df95555cf7a767ce25f3c7d560f3626151336b54..9f13f5136498671eed47a69e9e12d71df39e3c02 100644 (file)
@@ -87,7 +87,7 @@ static struct GNUNET_DHT_Handle *peer2dht;
 /**
  * Check whether peers successfully shut down.
  */
-void
+static void
 shutdown_callback (void *cls, const char *emsg)
 {
   if (emsg != NULL)
@@ -105,7 +105,6 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GNUNET_assert (peer2dht != NULL);
   GNUNET_DHT_disconnect (peer1dht);
   GNUNET_DHT_disconnect (peer2dht);
-  fprintf (stderr, "Testing STOP! - finished\n");
   GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
   pg = NULL;
   ok = 0;
@@ -120,7 +119,6 @@ end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   if (peer2dht != NULL)
     GNUNET_DHT_disconnect (peer2dht);
 
-  fprintf (stderr, "Testing STOP - Badly!\n");
   if (pg != NULL)
   {
     GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
@@ -128,15 +126,26 @@ end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   }
 
   if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK)
+  {
     GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task);
+    curr_get_ctx.retry_task = GNUNET_SCHEDULER_NO_TASK;
+  }
 }
 
+
 static void
 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  const char *emsg = cls;
+
+  fprintf (stderr,
+          "Error: %s\n",
+          emsg);
   if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK)
+  {
     GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task);
-
+    curr_get_ctx.retry_task = GNUNET_SCHEDULER_NO_TASK;
+  }
   if (curr_get_ctx.get_handle != NULL)
   {
     GNUNET_DHT_get_stop (curr_get_ctx.get_handle);
@@ -146,6 +155,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   ok = 1;
 }
 
+
 /* Forward declaration */
 static void
 do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
@@ -161,11 +171,13 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
  * @param size number of bytes in data
  * @param data pointer to the result data
  */
-void
+static void
 get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
                      const GNUNET_HashCode * key,
-                     const struct GNUNET_PeerIdentity *const *get_path,
-                     const struct GNUNET_PeerIdentity *const *put_path,
+                     const struct GNUNET_PeerIdentity *get_path,
+                    unsigned int get_path_length,
+                     const struct GNUNET_PeerIdentity *put_path,
+                    unsigned int put_path_length,
                      enum GNUNET_BLOCK_Type type, size_t size, const void *data)
 {
   struct PeerGetContext *get_context = cls;
@@ -173,7 +185,8 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
   if (0 !=
       memcmp (&get_context->peer->hashPubKey, key, sizeof (GNUNET_HashCode)))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+    fprintf (stderr, "??\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Key returned is not the same key as was searched for!\n");
     GNUNET_SCHEDULER_cancel (die_task);
     die_task =
@@ -181,7 +194,7 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
                                   "key mismatch in get response!\n");
     return;
   }
-
+  fprintf (stderr, "!\n");
   if (get_context->retry_task != GNUNET_SCHEDULER_NO_TASK)
   {
     GNUNET_SCHEDULER_cancel (get_context->retry_task);
@@ -211,6 +224,7 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
 static void
 stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
 
+
 static void
 get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -222,15 +236,17 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                 get_context->get_attempts);
   else
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+    fprintf (stderr, "?\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Too many attempts failed, ending test!\n",
                 get_context->get_attempts);
     GNUNET_SCHEDULER_cancel (die_task);
     die_task =
         GNUNET_SCHEDULER_add_now (&end_badly,
-                                  "key mismatch in get response!\n");
+                                  "GET attempt failed, ending test!\n");
     return;
   }
+  fprintf (stderr, ".");
   get_context->get_attempts++;
   get_context->retry_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
@@ -242,10 +258,11 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                             (GNUNET_TIME_UNIT_SECONDS, 5),
                             GNUNET_BLOCK_TYPE_DHT_HELLO,
                             &get_context->peer->hashPubKey,
-                            DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL,
-                            0, NULL, 0, &get_result_iterator, get_context);
+                            1, GNUNET_DHT_RO_NONE, NULL,
+                            0, &get_result_iterator, get_context);
 }
 
+
 static void
 stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -260,6 +277,7 @@ stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GNUNET_SCHEDULER_add_now (&get_stop_finished, get_context);
 }
 
+
 static void
 do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -269,19 +287,18 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                     (GNUNET_TIME_UNIT_SECONDS, 10),
                                     &stop_retry_get, get_context);
-
   get_context->get_handle =
       GNUNET_DHT_get_start (get_context->dht_handle,
                             GNUNET_TIME_relative_multiply
                             (GNUNET_TIME_UNIT_SECONDS, 5),
                             GNUNET_BLOCK_TYPE_DHT_HELLO,
                             &get_context->peer->hashPubKey,
-                            DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL,
-                            0, NULL, 0, &get_result_iterator, get_context);
+                            1, GNUNET_DHT_RO_FIND_PEER, NULL,
+                            0, &get_result_iterator, get_context);
 }
 
 
-void
+static void
 topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
                    const struct GNUNET_PeerIdentity *second, uint32_t distance,
                    const struct GNUNET_CONFIGURATION_Handle *first_cfg,
@@ -318,7 +335,8 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
 #endif
     GNUNET_SCHEDULER_cancel (die_task);
     die_task =
-        GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "from test gets");
+        GNUNET_SCHEDULER_add_delayed (TIMEOUT, 
+                                     &end_badly, "Timeout trying to GET");
 
     curr_get_ctx.dht_handle = peer1dht;
     curr_get_ctx.peer = &peer2id;
@@ -335,6 +353,7 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
   }
 }
 
+
 static void
 connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -356,6 +375,7 @@ connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                                       "from connect topology (timeout)");
 }
 
+
 static void
 peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
                         const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -363,8 +383,9 @@ peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
 {
   if (emsg != NULL)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Failed to start daemon with error: `%s'\n", emsg);
+    fprintf (stderr,
+            "Failed to start daemon: `%s'\n", 
+            emsg);
     return;
   }
   GNUNET_assert (id != NULL);
@@ -412,6 +433,7 @@ peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
   }
 }
 
+
 static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)