Alter config files to use hostkeys from file instead of generating during testing
[oweals/gnunet.git] / src / testing / testing_group.c
index 69e2392d139afe3f5dd74a796def061895e599ab..905fbcf80daea2b083091496ff757f8d93c7dcd7 100644 (file)
 
 #define MAX_OUTSTANDING_CONNECTIONS 200
 
+/* Maximum time to delay connect attempt */
+#define MAX_CONNECT_DELAY 300
+
 #define MAX_CONCURRENT_HOSTKEYS 500
 
 #define MAX_CONCURRENT_STARTING 200
 
 #define MAX_CONCURRENT_SHUTDOWN 200
 
-#define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 180)
+#define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
 
-#define CONNECT_ATTEMPTS 30
+#define CONNECT_ATTEMPTS 12
 
 /**
  * Which list of peers do we need to modify?
@@ -696,6 +699,11 @@ struct ConnectContext
    * Higher level topology connection context.
    */
   struct ConnectTopologyContext *ct_ctx;
+
+  /**
+   * Whether this connection has been accounted for in the schedule_connect call.
+   */
+  int counted;
 };
 
 struct UnblacklistContext
@@ -834,6 +842,13 @@ uid_from_hash (const GNUNET_HashCode * hash, uint32_t * uid)
  */
 static int outstanding_connects;
 
+/**
+ * Number of connects we have scheduled at the same
+ * time, the more we already have scheduled the longer
+ * we should wait before calling schedule_connect again.
+ */
+static int outstanding_scheduled_connects;
+
 /**
  * Get a topology from a string input.
  *
@@ -1237,6 +1252,7 @@ remove_connections (struct GNUNET_TESTING_PeerGroup *pg,
     break;
   default:
     GNUNET_break(0);
+    return 0;
   }
 
   first_iter = *first_list;
@@ -1325,7 +1341,6 @@ add_connections (struct GNUNET_TESTING_PeerGroup *pg,
   switch (list)
   {
   case ALLOWED:
-    GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Adding to ALLOWED\n");
     first_list = &pg->peers[first].allowed_peers_head;
     second_list = &pg->peers[second].allowed_peers_head;
     first_tail = &pg->peers[first].allowed_peers_tail;
@@ -1351,6 +1366,7 @@ add_connections (struct GNUNET_TESTING_PeerGroup *pg,
     break;
   default:
     GNUNET_break(0);
+    return 0;
   }
 
   add_first = GNUNET_YES;
@@ -1397,7 +1413,6 @@ add_connections (struct GNUNET_TESTING_PeerGroup *pg,
   if (add_first)
     {
 #if OLD
-      GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Adding peer %d to %d\n", second, first);
       new_first = GNUNET_malloc (sizeof (struct PeerConnection));
       new_first->index = second;
       GNUNET_CONTAINER_DLL_insert(*first_list, *first_tail, new_first);
@@ -1821,7 +1836,11 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg,
       connect_attempts += proc (pg, i, nodeToConnect, list);
 
       if (i < cols)
-        nodeToConnect = (rows * cols) - cols + i;
+        {
+          nodeToConnect = (rows * cols) - cols + i;
+          if (nodeToConnect >= pg->total)
+            nodeToConnect -= cols;
+        }
       else
         nodeToConnect = i - cols;
 
@@ -2016,7 +2035,11 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg,
 
       /* Second connect to the node immediately above */
       if (i < cols)
-        nodeToConnect = (rows * cols) - cols + i;
+        {
+          nodeToConnect = (rows * cols) - cols + i;
+          if (nodeToConnect >= pg->total)
+            nodeToConnect -= cols;
+        }
       else
         nodeToConnect = i - cols;
 
@@ -2828,8 +2851,14 @@ schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                   _
                   ("Delaying connect, we have too many outstanding connections!\n"));
 #endif
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                    (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+      if (GNUNET_NO == connect_context->counted)
+        {
+          connect_context->counted = GNUNET_YES;
+          outstanding_scheduled_connects++;
+        }
+      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add (GNUNET_TIME_relative_multiply
+                                    (GNUNET_TIME_UNIT_MILLISECONDS, 100), GNUNET_TIME_relative_multiply
+                                        (GNUNET_TIME_UNIT_MILLISECONDS, outstanding_scheduled_connects * 2)),
                                     &schedule_connect, connect_context);
     }
   else
@@ -2840,6 +2869,7 @@ schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                   outstanding_connects);
 #endif
       outstanding_connects++;
+      outstanding_scheduled_connects--;
       GNUNET_TESTING_daemons_connect (connect_context->first,
                                       connect_context->second,
                                       CONNECT_TIMEOUT,
@@ -3014,7 +3044,14 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
           connect_context->first = pg->peers[pg_iter].daemon;
           connect_context->second = pg->peers[connection_iter->index].daemon;
           connect_context->ct_ctx = ct_ctx;
-          GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
+          if (total < MAX_OUTSTANDING_CONNECTIONS)
+            {
+              GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
+            }
+          else
+            {
+              GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 1000 * (total / MAX_OUTSTANDING_CONNECTIONS)), &schedule_connect, connect_context);
+            }
           connection_iter = connection_iter->next;
           total++;
         }
@@ -3152,7 +3189,7 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
         num_connections = create_from_file (pg, filename, &add_connections, ALLOWED);
       else
       {
-        GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Missing configuration option TESTING:TOPOLOGY_FILE for creating topology from file!");
+        GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Missing configuration option TESTING:TOPOLOGY_FILE for creating topology from file!\n");
         num_connections = 0;
       }
       break;
@@ -4866,7 +4903,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
       else
         proc = GNUNET_OS_start_process (NULL, NULL, "ssh",
                                             "ssh", arg, "mkdir -p", baseservicehome,  NULL);
-      GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Creating remote dir with command ssh %s %s %s\n", arg, " mkdir -p ", baseservicehome);
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating remote dir with command ssh %s %s %s\n", arg, " mkdir -p ", baseservicehome);
       GNUNET_OS_process_wait(proc);
     }
   GNUNET_free(baseservicehome);
@@ -4875,7 +4912,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                                           &hostkeys_file))
     {
       if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file))
-        GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Couldn't read hostkeys file!");
+        GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Couldn't read hostkeys file!\n");
       else
         {
           /* Check hostkey file size, read entire thing into memory */
@@ -4890,7 +4927,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
           if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES))
             fs = 0;
 
-          GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found file size %llu for hostkeys, expect hostkeys to be size %d\n", fs, HOSTKEYFILESIZE);
+          GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Found file size %llu for hostkeys, expect hostkeys to be size %d\n", fs, HOSTKEYFILESIZE);
 
           if (fs % HOSTKEYFILESIZE != 0)
             {
@@ -4899,7 +4936,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
           else
             {
               total_hostkeys = fs / HOSTKEYFILESIZE;
-              GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Will read %llu hostkeys from file\n", total_hostkeys);
+              GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Will read %llu hostkeys from file\n", total_hostkeys);
               pg->hostkey_data = GNUNET_malloc_large (fs);
               GNUNET_assert (fs == GNUNET_DISK_file_read (fd, pg->hostkey_data, fs));
               GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fd));