gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r8842 - GNUnet/src/applications/testing


From: gnunet
Subject: [GNUnet-SVN] r8842 - GNUnet/src/applications/testing
Date: Sat, 22 Aug 2009 16:09:38 -0600

Author: nevans
Date: 2009-08-22 16:09:38 -0600 (Sat, 22 Aug 2009)
New Revision: 8842

Modified:
   GNUnet/src/applications/testing/remote.c
   GNUnet/src/applications/testing/remote.h
   GNUnet/src/applications/testing/remotetopologies.c
Log:
better handling of total connections desired, old school small world topology

Modified: GNUnet/src/applications/testing/remote.c
===================================================================
--- GNUnet/src/applications/testing/remote.c    2009-08-22 17:57:31 UTC (rev 
8841)
+++ GNUnet/src/applications/testing/remote.c    2009-08-22 22:09:38 UTC (rev 
8842)
@@ -311,6 +311,7 @@
   char *ssh_username;
   char *control_host;
   char *percentage_string;
+  char *logNModifier_string;
   char *remote_config_path;
   char *remote_gnunetd_path;
   char *remote_pid_path;
@@ -358,6 +359,7 @@
   int ret;
   char *ipk_dir;
   double percentage;
+  double logNModifier;
 
   double malicious_getter_num;
   double malicious_putter_num;
@@ -410,6 +412,11 @@
   percentage = atof (percentage_string);
 
   GNUNET_GC_get_configuration_value_string (newcfg, "MULTIPLE_SERVER_TESTING",
+                                            "LOGNMODIFIER", "1.0",
+                                            &logNModifier_string);
+  logNModifier = atof (logNModifier_string);
+
+  GNUNET_GC_get_configuration_value_string (newcfg, "MULTIPLE_SERVER_TESTING",
                                             "CONTROL_HOST", "localhost",
                                             &control_host);
 
@@ -1058,7 +1065,7 @@
     }
   ret =
     GNUNET_REMOTE_create_topology (type_of_topology, number_of_daemons,
-                                   dotOutFile, percentage);
+                                   dotOutFile, percentage, logNModifier);
   if (dotOutFile != NULL)
     {
       fprintf (dotOutFile, "}\n");
@@ -1206,7 +1213,7 @@
 int
 GNUNET_REMOTE_create_topology (GNUNET_REMOTE_TOPOLOGIES type,
                                int number_of_daemons, FILE * dotOutFile,
-                               double percentage)
+                               double percentage, double logNModifier)
 {
   FILE *temp_friend_handle;
   int ret;
@@ -1240,8 +1247,8 @@
       fprintf (stderr, _("Creating small world topology\n"));
 #endif
       ret =
-        GNUNET_REMOTE_connect_small_world (number_of_daemons, list_as_array,
-                                           dotOutFile, percentage);
+        GNUNET_REMOTE_connect_small_world_ring (number_of_daemons, 
list_as_array,
+                                           dotOutFile, percentage, 
logNModifier);
       break;
     case GNUNET_REMOTE_RING:
 #if VERBOSE

Modified: GNUnet/src/applications/testing/remote.h
===================================================================
--- GNUnet/src/applications/testing/remote.h    2009-08-22 17:57:31 UTC (rev 
8841)
+++ GNUnet/src/applications/testing/remote.h    2009-08-22 22:09:38 UTC (rev 
8842)
@@ -99,7 +99,7 @@
 int
 GNUNET_REMOTE_create_topology (GNUNET_REMOTE_TOPOLOGIES type,
                                int number_of_daemons, FILE * dotOufFile,
-                               double percentage);
+                               double percentage, double logNModifier);
 
 GNUNET_PeerIdentity *GNUNET_REMOTE_get_daemon_information (char *hostname,
                                                            unsigned short

Modified: GNUnet/src/applications/testing/remotetopologies.c
===================================================================
--- GNUnet/src/applications/testing/remotetopologies.c  2009-08-22 17:57:31 UTC 
(rev 8841)
+++ GNUnet/src/applications/testing/remotetopologies.c  2009-08-22 22:09:38 UTC 
(rev 8842)
@@ -300,7 +300,7 @@
 }
 
 int
-GNUNET_REMOTE_connect_small_world (int number_of_daemons,
+GNUNET_REMOTE_connect_small_world (unsigned int number_of_daemons,
                                    struct GNUNET_REMOTE_host_list
                                    **list_as_array, FILE * dotOutFile,
                                    double percentage)
@@ -427,6 +427,98 @@
   return GNUNET_OK;
 }
 
+int
+GNUNET_REMOTE_connect_small_world_ring (unsigned int number_of_daemons,
+                                   struct GNUNET_REMOTE_host_list
+                                   **list_as_array, FILE * dotOutFile,
+                                   double percentage, double logNModifier)
+{
+  unsigned int i, j;
+  int nodeToConnect;
+  unsigned int natLog;
+  unsigned int randomPeer;
+  double random;
+  unsigned int totalConnections, smallWorldConnections;
+  int connsPerPeer;
+  int distance;
+  natLog = log (number_of_daemons);
+  connsPerPeer = ceil(natLog * logNModifier);
+  int max;
+  int min;
+  unsigned int useAnd;
+
+  if (connsPerPeer % 2 == 1)
+    connsPerPeer += 1;
+
+  srand((unsigned int)GNUNET_get_time());
+  smallWorldConnections = 0;
+  totalConnections = 0;
+  for (i = 0; i < number_of_daemons; i++)
+  {
+    useAnd = 0;
+    max = i + connsPerPeer/2;
+    min = i - connsPerPeer/2;
+
+    if (max > number_of_daemons - 1)
+    {
+      max = max - number_of_daemons;
+      useAnd = 1;
+    }
+
+    if (min < 0)
+    {
+      min = number_of_daemons - 1 + min;
+      useAnd = 1;
+    }
+#if VERBOSE
+        fprintf (stderr, _("For peer %d, number must be less than %d or 
greater than %d (%d)\n"), i, min, max, useAnd);
+#endif
+    for (j = 0; j < connsPerPeer/2; j++)
+    {
+      random = ((double) rand() / RAND_MAX);
+      if (random < percentage)
+      {
+        /* Connect to uniformly selected random peer */
+        randomPeer = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 
number_of_daemons);
+        while ((((randomPeer < max) && (randomPeer > min)) && (useAnd == 0)) 
|| (((randomPeer > min) || (randomPeer < max)) && (useAnd == 1)))
+        {
+#if VERBOSE
+          fprintf (stderr, _("NOT connecting node %u to %u (already existing 
connection!)\n"), i, randomPeer);
+#endif
+          randomPeer = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 
number_of_daemons);
+        }
+#if VERBOSE
+        fprintf (stderr, _("connecting node (rewire) %u to %u\n"), i, 
randomPeer);
+#endif
+        smallWorldConnections += addNodeRefs(list_as_array[i], 
list_as_array[randomPeer]);
+      }
+      else
+      {
+        nodeToConnect = i + j + 1;
+        if (nodeToConnect > number_of_daemons - 1)
+          {
+            nodeToConnect = nodeToConnect - number_of_daemons;
+          }
+#if VERBOSE
+        fprintf (stderr, _("connecting node %u to %u\n"), i, nodeToConnect);
+#endif
+        totalConnections += addNodeRefs(list_as_array[i], 
list_as_array[nodeToConnect]);
+      }
+    }
+
+  }
+
+  totalConnections += smallWorldConnections;
+#if VERBOSE
+  fprintf (stderr, _("Total connections added for small world: %d!\n"),
+           smallWorldConnections);
+  fprintf (stderr, _("Total connections: %d!\n"),
+           totalConnections);
+#endif
+
+  return GNUNET_OK;
+}
+
 /**
 * Establish a connection between two GNUnet daemons
 *





reply via email to

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