gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r17102 - gnunet/src/dht


From: gnunet
Subject: [GNUnet-SVN] r17102 - gnunet/src/dht
Date: Thu, 29 Sep 2011 15:37:19 +0200

Author: grothoff
Date: 2011-09-29 15:37:19 +0200 (Thu, 29 Sep 2011)
New Revision: 17102

Modified:
   gnunet/src/dht/test_dht_multipeer.c
   gnunet/src/dht/test_dht_multipeer_data.conf
Log:
cleaning up testcase some

Modified: gnunet/src/dht/test_dht_multipeer.c
===================================================================
--- gnunet/src/dht/test_dht_multipeer.c 2011-09-29 11:51:25 UTC (rev 17101)
+++ gnunet/src/dht/test_dht_multipeer.c 2011-09-29 13:37:19 UTC (rev 17102)
@@ -208,7 +208,7 @@
  */
 static unsigned int failed_connections;
 
-enum GNUNET_DHT_RouteOption route_option;
+static enum GNUNET_DHT_RouteOption route_option;
 
 /* Task handle to use to schedule test failure */
 static GNUNET_SCHEDULER_TaskIdentifier die_task;
@@ -299,9 +299,12 @@
 static void
 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n",
-              (char *) cls);
+  const char *emsg = cls;
 
+  fprintf (stderr, 
+          "Failing test with error: `%s'!\n",
+          emsg);
+
   struct TestPutContext *test_put = all_puts;
   struct TestGetContext *test_get = all_gets;
 
@@ -329,34 +332,7 @@
   ok = 1;
 }
 
-/**
- * Task to release DHT handle associated with GET request.
- */
-static void
-get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct TestGetContext *test_get = cls;
 
-  outstanding_gets--;           /* GET is really finished */
-  GNUNET_DHT_disconnect (test_get->dht_handle);
-  test_get->dht_handle = NULL;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n",
-              gets_completed, gets_failed);
-  if ((gets_completed == num_gets) && (outstanding_gets == 0))  /* All gets 
successful */
-  {
-    GNUNET_SCHEDULER_cancel (die_task);
-    //GNUNET_SCHEDULER_add_delayed 
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &get_topology, 
NULL);
-    die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
-  }
-  else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 
0))       /* Had some failures */
-  {
-    GNUNET_SCHEDULER_cancel (die_task);
-    die_task =
-        GNUNET_SCHEDULER_add_now (&end_badly, "not all gets succeeded!\n");
-  }
-}
-
 /**
  * Task to release get handle.
  */
@@ -367,10 +343,11 @@
   GNUNET_HashCode search_key;   /* Key stored under */
   char original_data[TEST_DATA_SIZE];   /* Made up data to store */
 
+  test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
   memset (original_data, test_get->uid, sizeof (original_data));
   GNUNET_CRYPTO_hash (original_data, TEST_DATA_SIZE, &search_key);
 
-  if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
+  if (test_get->succeeded != GNUNET_YES)
   {
     gets_failed++;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -379,9 +356,29 @@
   }
   GNUNET_assert (test_get->get_handle != NULL);
   GNUNET_DHT_get_stop (test_get->get_handle);
-  GNUNET_SCHEDULER_add_now (&get_stop_finished, test_get);
   test_get->get_handle = NULL;
-  test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
+
+  outstanding_gets--;           /* GET is really finished */
+  GNUNET_DHT_disconnect (test_get->dht_handle);
+  test_get->dht_handle = NULL;
+
+  fprintf (stderr,
+          "%llu gets succeeded, %llu gets failed!\n",
+          gets_completed, gets_failed);
+  if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0))   
    /* Had some failures */
+  {
+      GNUNET_SCHEDULER_cancel (die_task);
+      die_task =
+        GNUNET_SCHEDULER_add_now (&end_badly, "not all gets succeeded");
+      return;
+  }
+
+  if ( (gets_completed == num_gets) && (outstanding_gets == 0) )  /* All gets 
successful */
+  {
+    GNUNET_SCHEDULER_cancel (die_task);
+    //GNUNET_SCHEDULER_add_delayed 
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &get_topology, 
NULL);
+    die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
+  }
 }
 
 /**
@@ -439,14 +436,14 @@
   }
   else
   {
+    fprintf (stderr, "GET successful!\n");
     gets_completed++;
     test_get->succeeded = GNUNET_YES;
   }
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
   GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
-  GNUNET_SCHEDULER_add_continuation (&get_stop_task, test_get,
-                                     GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+  test_get->disconnect_task = GNUNET_SCHEDULER_add_now (&get_stop_task, 
test_get);
 }
 
 
@@ -555,20 +552,64 @@
 }
 
 
+
 /**
- * Set up some all of the put and get operations we want
- * to do.  Allocate data structure for each, add to list,
- * then call actual insert functions.
+ * This function is called whenever a connection attempt is finished between 
two of
+ * the started peers (started with GNUNET_TESTING_daemons_start).  The total
+ * number of times this function is called should equal the number returned
+ * from the GNUNET_TESTING_connect_topology call.
+ *
+ * The emsg variable is NULL on success (peers connected), and non-NULL on
+ * failure (peers failed to connect).
  */
 static void
-setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
+                   const struct GNUNET_PeerIdentity *second, uint32_t distance,
+                   const struct GNUNET_CONFIGURATION_Handle *first_cfg,
+                   const struct GNUNET_CONFIGURATION_Handle *second_cfg,
+                   struct GNUNET_TESTING_Daemon *first_daemon,
+                   struct GNUNET_TESTING_Daemon *second_daemon,
+                   const char *emsg)
 {
-  int i;
+  unsigned long long i;
   uint32_t temp_daemon;
   struct TestPutContext *test_put;
   struct TestGetContext *test_get;
   int remember[num_puts][num_peers];
 
+  if (emsg == NULL)
+  {
+    total_connections++;
+#if VERBOSE > 1
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "connected peer %s to peer %s, distance %u\n",
+                first_daemon->shortname, second_daemon->shortname, distance);
+#endif
+  }
+  else
+  {
+    failed_connections++;
+    fprintf (stderr,
+            "Failed to connect peer %s to peer %s with error :\n%s\n",
+            first_daemon->shortname, second_daemon->shortname, emsg);
+    GNUNET_SCHEDULER_cancel (die_task);
+    die_task =
+      GNUNET_SCHEDULER_add_now (&end_badly,
+                               "from topology_callback (connections failed)");
+    return;
+  }
+  if (total_connections < expected_connections)
+    return;
+  fprintf (stderr,
+          "Created topology with %u connections\n",
+          total_connections);
+  GNUNET_SCHEDULER_cancel (die_task);
+  die_task =
+    GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
+                                 "from setup puts/gets");
+  fprintf (stderr, 
+          "Issuing %llu PUTs at random locations\n", 
+          num_puts);
   for (i = 0; i < num_puts; i++)
   {
     test_put = GNUNET_malloc (sizeof (struct TestPutContext));
@@ -576,10 +617,16 @@
     temp_daemon =
         GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
     test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_daemon);
+    
     test_put->next = all_puts;
     all_puts = test_put;
   }
+  GNUNET_SCHEDULER_add_now (&do_put, all_puts);
 
+  fprintf (stderr, 
+          "Issuing %llu GETs at random locations for random PUT data\n",
+          num_gets);
+  memset (remember, 0, sizeof (remember));
   for (i = 0; i < num_gets; i++)
   {
     test_get = GNUNET_malloc (sizeof (struct TestGetContext));
@@ -596,80 +643,19 @@
     all_gets = test_get;
   }
 
-  GNUNET_SCHEDULER_add_now (&do_put, all_puts);
+
 }
 
 
-/**
- * This function is called whenever a connection attempt is finished between 
two of
- * the started peers (started with GNUNET_TESTING_daemons_start).  The total
- * number of times this function is called should equal the number returned
- * from the GNUNET_TESTING_connect_topology call.
- *
- * The emsg variable is NULL on success (peers connected), and non-NULL on
- * failure (peers failed to connect).
- */
 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,
-                   const struct GNUNET_CONFIGURATION_Handle *second_cfg,
-                   struct GNUNET_TESTING_Daemon *first_daemon,
-                   struct GNUNET_TESTING_Daemon *second_daemon,
-                   const char *emsg)
-{
-  if (emsg == NULL)
-  {
-    total_connections++;
-#if VERBOSE > 1
-    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,
-                "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 setup puts/gets");
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                  (GNUNET_TIME_UNIT_SECONDS, 2),
-                                  &setup_puts_and_gets, NULL);
-  }
-  else if (total_connections + failed_connections == expected_connections)
-  {
-    GNUNET_SCHEDULER_cancel (die_task);
-    die_task =
-        GNUNET_SCHEDULER_add_now (&end_badly,
-                                  "from topology_callback (too many failed 
connections)");
-  }
-}
-
-static void
 peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
                         const struct GNUNET_CONFIGURATION_Handle *cfg,
                         struct GNUNET_TESTING_Daemon *d, const char *emsg)
 {
   if (emsg != NULL)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Failed to start daemon with error: `%s'\n", emsg);
+    fprintf (stderr,
+            "Failed to start daemon with error: `%s'\n", emsg);
     return;
   }
   GNUNET_assert (id != NULL);
@@ -680,69 +666,44 @@
 #endif
 
   peers_left--;
-  if (peers_left == 0)
-  {
+  if (peers_left > 0)
+    return;
 
 #if VERBOSE
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "All %d daemons started, now connecting peers!\n", num_peers);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "All %d daemons started, now connecting peers!\n", num_peers);
 #endif
-
-    expected_connections = -1;
-    if ((pg != NULL) && (peers_left == 0))
+  
+  expected_connections = -1;
+  if ((pg != NULL) && (peers_left == 0))
     {
       expected_connections =
-          GNUNET_TESTING_connect_topology (pg, connection_topology,
-                                           connect_topology_option,
-                                           connect_topology_option_modifier,
-                                           TIMEOUT, num_peers, NULL, NULL);
+       GNUNET_TESTING_connect_topology (pg, connection_topology,
+                                        connect_topology_option,
+                                        connect_topology_option_modifier,
+                                        TIMEOUT, num_peers, NULL, NULL);
 #if VERBOSE
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n",
                   expected_connections);
 #endif
     }
-
-    GNUNET_SCHEDULER_cancel (die_task);
-    if (expected_connections == GNUNET_SYSERR)
+  
+  GNUNET_SCHEDULER_cancel (die_task);
+  if (expected_connections == GNUNET_SYSERR)
     {
       die_task =
-          GNUNET_SCHEDULER_add_now (&end_badly,
-                                    "from connect topology (bad return)");
+       GNUNET_SCHEDULER_add_now (&end_badly,
+                                 "from connect topology (bad return)");
     }
-    else
+  else
     {
       die_task =
-          GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
-                                        "from connect topology (timeout)");
+       GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
+                                     "from connect topology (timeout)");
     }
-    ok = 0;
-  }
+  ok = 0;
 }
 
-static void
-create_topology ()
-{
-  peers_left = num_peers;       /* Reset counter */
-  GNUNET_SCHEDULER_cancel (die_task);
-  if (GNUNET_TESTING_create_topology
-      (pg, topology, blacklist_topology, blacklist_transports) != 
GNUNET_SYSERR)
-  {
-#if VERBOSE
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Topology set up, now starting peers!\n");
-#endif
-    GNUNET_TESTING_daemons_continue_startup (pg);
-    die_task =
-        GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
-                                      "from continue startup (timeout)");
-  }
-  else
-  {
-    die_task =
-        GNUNET_SCHEDULER_add_now (&end_badly,
-                                  "from create topology (bad return)");
-  }
-}
 
 /**
  * Callback indicating that the hostkey was created for a peer.
@@ -758,8 +719,9 @@
 {
   if (emsg != NULL)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Hostkey callback received error: %s\n", emsg);
+    fprintf (stderr,
+            "Hostkey callback received error: %s\n", emsg);
+    return;
   }
 
 #if VERBOSE > 1
@@ -779,11 +741,30 @@
     GNUNET_SCHEDULER_cancel (die_task);
     /* Set up task in case topology creation doesn't finish
      * within a reasonable amount of time */
+    ok = 0;
     die_task =
         GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
                                       "from create_topology");
-    GNUNET_SCHEDULER_add_now (&create_topology, NULL);
-    ok = 0;
+    peers_left = num_peers;       /* Reset counter */
+    GNUNET_SCHEDULER_cancel (die_task);
+    if (GNUNET_TESTING_create_topology
+       (pg, topology, blacklist_topology, blacklist_transports) != 
GNUNET_SYSERR)
+      {
+#if VERBOSE
+       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                   "Topology set up, now starting peers!\n");
+#endif
+       GNUNET_TESTING_daemons_continue_startup (pg);
+       die_task =
+         GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
+                                       "from continue startup (timeout)");
+      }
+    else
+      {
+       die_task =
+         GNUNET_SCHEDULER_add_now (&end_badly,
+                                   "from create topology (bad return)");
+      }
   }
 }
 
@@ -809,6 +790,7 @@
       GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
                                              &test_directory))
   {
+    GNUNET_break (0);
     ok = 404;
     return;
   }
@@ -917,7 +899,9 @@
                                      SECONDS_PER_PEER_START * num_peers),
                                     &end_badly,
                                     "didn't generate all hostkeys within a 
reasonable amount of time!!!");
-
+  fprintf (stderr, 
+          "Starting P2P network with %llu peers\n",
+          peers_left);
   pg = GNUNET_TESTING_daemons_start (cfg, peers_left,   /* Total number of 
peers */
                                      peers_left,        /* Number of 
outstanding connections */
                                      peers_left,        /* Number of parallel 
ssh connections, or peers being started at once */
@@ -930,6 +914,7 @@
 
 }
 
+
 static int
 check ()
 {

Modified: gnunet/src/dht/test_dht_multipeer_data.conf
===================================================================
--- gnunet/src/dht/test_dht_multipeer_data.conf 2011-09-29 11:51:25 UTC (rev 
17101)
+++ gnunet/src/dht/test_dht_multipeer_data.conf 2011-09-29 13:37:19 UTC (rev 
17102)
@@ -76,8 +76,8 @@
 [DHT_TESTING]
 MYSQL_LOGGING_EXTENDED = NO
 MYSQL_LOGGING = NO
-NUM_GETS = 1
-NUM_PUTS = 1
+NUM_GETS = 5
+NUM_PUTS = 5
 
 [TESTING]
 TOPOLOGY = FROM_FILE




reply via email to

[Prev in Thread] Current Thread [Next in Thread]