-fixing #2397
[oweals/gnunet.git] / src / dht / test_dht_twopeer.c
index f318f9722e7e2a4bbd89a5773f2fac7c22931fe3..8579013e371a6c50b03c1f571cfce907e32adafe 100644 (file)
@@ -28,8 +28,6 @@
 #include "gnunet_dht_service.h"
 
 /* DEFINES */
-#define VERBOSE GNUNET_NO
-
 #define MAX_GET_ATTEMPTS 10
 
 #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
@@ -87,7 +85,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)
@@ -126,15 +124,24 @@ 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);
@@ -144,6 +151,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);
@@ -159,19 +167,22 @@ 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,
-                     enum GNUNET_BLOCK_Type type, size_t size, const void *data)
+                     const struct GNUNET_HashCode * key,
+                     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;
 
   if (0 !=
-      memcmp (&get_context->peer->hashPubKey, key, sizeof (GNUNET_HashCode)))
+      memcmp (&get_context->peer->hashPubKey, key, sizeof (struct GNUNET_HashCode)))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+    FPRINTF (stderr, "%s",  "??\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 =
@@ -179,7 +190,6 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
                                   "key mismatch in get response!\n");
     return;
   }
-
   if (get_context->retry_task != GNUNET_SCHEDULER_NO_TASK)
   {
     GNUNET_SCHEDULER_cancel (get_context->retry_task);
@@ -209,41 +219,42 @@ 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)
 {
   struct PeerGetContext *get_context = cls;
 
-  if (get_context->get_attempts < MAX_GET_ATTEMPTS)
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Get attempt %u failed, retrying request!\n",
-                get_context->get_attempts);
-  else
+  if (get_context->get_attempts >= MAX_GET_ATTEMPTS)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+    FPRINTF (stderr, "%s",  "?\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;
   }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Get attempt %u failed, retrying request!\n",
+              get_context->get_attempts);
+  FPRINTF (stderr, "%s",  ".");
   get_context->get_attempts++;
   get_context->retry_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                    (GNUNET_TIME_UNIT_SECONDS, 10),
+                                    (GNUNET_TIME_UNIT_SECONDS, 60),
                                     &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);
+                            &get_context->peer->hashPubKey, 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)
 {
@@ -258,6 +269,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)
 {
@@ -267,19 +279,16 @@ 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);
+                            &get_context->peer->hashPubKey, 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,
@@ -291,32 +300,27 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
   if (emsg == NULL)
   {
     total_connections++;
-#if VERBOSE
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "connected peer %s to peer %s, distance %u\n",
                 first_daemon->shortname, second_daemon->shortname, distance);
-#endif
   }
-#if VERBOSE
   else
   {
     failed_connections++;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Failed to connect peer %s to peer %s with error :\n%s\n",
                 first_daemon->shortname, second_daemon->shortname, emsg);
   }
-#endif
 
   if (total_connections == expected_connections)
   {
-#if VERBOSE
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Created %d total connections, which is our target number!  Starting next phase of testing.\n",
                 total_connections);
-#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;
@@ -333,6 +337,7 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
   }
 }
 
+
 static void
 connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -354,6 +359,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,
@@ -361,8 +367,7 @@ 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);
@@ -394,10 +399,8 @@ peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
 
   if (peers_left == 0)
   {
-#if VERBOSE
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "All %d daemons started, now connecting peers!\n", num_peers);
-#endif
     GNUNET_SCHEDULER_cancel (die_task);
     /* Set up task in case topology creation doesn't finish
      * within a reasonable amount of time */
@@ -410,6 +413,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)
@@ -424,7 +428,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   }
 
   if (GNUNET_SYSERR ==
-      GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
+      GNUNET_CONFIGURATION_get_value_number (cfg, "testing_old", "num_peers",
                                              &num_peers))
     num_peers = DEFAULT_NUM_PEERS;
 
@@ -450,9 +454,6 @@ check ()
   char *const argv[] = { "test-dht-twopeer",
     "-c",
     "test_dht_twopeer_data.conf",
-#if VERBOSE
-    "-L", "DEBUG",
-#endif
     NULL
   };
   struct GNUNET_GETOPT_CommandLineOption options[] = {
@@ -475,11 +476,7 @@ main (int argc, char *argv[])
   int ret;
 
   GNUNET_log_setup ("test-dht-twopeer",
-#if VERBOSE
-                    "DEBUG",
-#else
                     "WARNING",
-#endif
                     NULL);
   ret = check ();
   /**