gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r8830 - GNUnet/src/applications/testing
Date: Mon, 17 Aug 2009 17:35:00 -0600

Author: nevans
Date: 2009-08-17 17:34:59 -0600 (Mon, 17 Aug 2009)
New Revision: 8830

Modified:
   GNUnet/src/applications/testing/remote.c
   GNUnet/src/applications/testing/remote.h
   GNUnet/src/applications/testing/remotetopologies.c
Log:
Improvements for efficiency (runtime speed) in testing code.  Removed redundant 
client to server communication when creating topologies.  Took out redundant 
peer connecting code, which reduces the number of attempted connects by half.  
Also created threads for connecting nodes to improve speed but need to further 
test to make sure it actually helps

Modified: GNUnet/src/applications/testing/remote.c
===================================================================
--- GNUnet/src/applications/testing/remote.c    2009-08-16 09:31:25 UTC (rev 
8829)
+++ GNUnet/src/applications/testing/remote.c    2009-08-17 23:34:59 UTC (rev 
8830)
@@ -27,12 +27,37 @@
 #include "remote.h"
 #include "remotetopologies.c"
 
+#define GET_MASK 1
+#define PUT_MASK 2
+#define DROP_MASK 4
+#define MAX_CONNECT_THREADS 10
+
+struct ConnectedEntry
+{
+  struct ConnectedEntry *next;
+  GNUNET_HashCode key;
+};
+
+struct threadInfo
+{
+  struct threadInfo *next;
+  struct GNUNET_ThreadHandle *thread;
+};
+
+static struct GNUNET_Mutex *connectMutex;
+struct GNUNET_MultiHashMap *connected;
+
 /* Yes this is ugly, but for now it is nice to
  * have a linked list and an array
  */
 static struct GNUNET_REMOTE_host_list *head;
 static struct GNUNET_REMOTE_host_list **list_as_array;
 
+static int threadCount;
+static int totalConnections;
+static int connectFailures;
+
+static FILE *globalDotFile;
 /**
  * Starts a single gnunet daemon on a remote machine
  *
@@ -318,7 +343,9 @@
   unsigned long long topology;
 
   unsigned long long malicious_getters;
+  unsigned long long malicious_get_frequency;
   unsigned long long malicious_putters;
+  unsigned long long malicious_put_frequency;
   unsigned long long malicious_droppers;
 
   unsigned long long extra_daemons;
@@ -330,6 +357,7 @@
   unsigned int i;
   unsigned int j;
   unsigned int pos;
+  unsigned short malicious_mask;
   int temp_remote_config_path_length;
   int temp_host_string_length;
   int friend_location_length;
@@ -423,6 +451,16 @@
                                             "MYSQL_PORT",
                                             1, -1, 3306, &mysql_port);
 
+  GNUNET_GC_get_configuration_value_number (newcfg, "MULTIPLE_SERVER_TESTING",
+                                            "MALICIOUS_GET_FREQUENCY",
+                                            0, -1, 0,
+                                            &malicious_get_frequency);
+
+  GNUNET_GC_get_configuration_value_number (newcfg, "MULTIPLE_SERVER_TESTING",
+                                            "MALICIOUS_PUT_FREQUENCY",
+                                            0, -1, 0,
+                                            &malicious_put_frequency);
+
   GNUNET_GC_get_configuration_value_string (newcfg, "MULTIPLE_SERVER_TESTING",
                                             "REMOTE_CONFIG_PATH", "/tmp/",
                                             &remote_config_path);
@@ -487,12 +525,6 @@
           break;
         }
 
-      GNUNET_GC_set_configuration_value_number (basecfg, NULL, "NETWORK",
-                                                "PORT", starting_port);
-      GNUNET_GC_set_configuration_value_number (basecfg, NULL, "TCP",
-                                                "PORT", starting_port + 1);
-      GNUNET_GC_set_configuration_value_number (basecfg, NULL, "UDP",
-                                                "PORT", starting_port + 1);
       GNUNET_GC_set_configuration_value_string (basecfg, NULL, "NETWORK",
                                                 "TRUSTED", control_host);
       GNUNET_GC_set_configuration_value_string (basecfg, NULL, "PATHS",
@@ -529,9 +561,9 @@
 
       for (j = 0; j < daemons_per_machine; ++j)
         {
-
+          malicious_mask = 0;
           /*
-           * Indicates that the first node should be set as a malicious getter
+           * Indicates that this node should be set as a malicious getter
            */
           if ((malicious_getters > 0)
               && ((((count_started + 1) % (int) malicious_getter_num) == 0)))
@@ -540,6 +572,16 @@
                                                         "DHT",
                                                         "MALICIOUS_GETTER",
                                                         "YES");
+
+              if (malicious_get_frequency > 0)
+                {
+                  GNUNET_GC_set_configuration_value_number (basecfg, NULL,
+                                                            "DHT",
+                                                            
"MALICIOUS_GET_FREQUENCY",
+                                                            
malicious_get_frequency);
+
+                }
+              malicious_mask |= GET_MASK;
             }
           else
             {
@@ -550,7 +592,7 @@
             }
 
           /*
-           * Indicates that the first node should be set as a malicious putter
+           * Indicates that this node should be set as a malicious putter
            */
           if ((malicious_putters > 0)
               && ((((count_started + 1) % (int) malicious_putter_num) == 0)))
@@ -559,6 +601,15 @@
                                                         "DHT",
                                                         "MALICIOUS_PUTTER",
                                                         "YES");
+              if (malicious_put_frequency > 0)
+                {
+                  GNUNET_GC_set_configuration_value_number (basecfg, NULL,
+                                                            "DHT",
+                                                            
"MALICIOUS_PUT_FREQUENCY",
+                                                            
malicious_put_frequency);
+
+                }
+              malicious_mask |= PUT_MASK;
             }
           else
             {
@@ -569,7 +620,7 @@
             }
 
           /*
-           * Indicates that the first node should be set as a malicious dropper
+           * Indicates that this node should be set as a malicious dropper
            */
           if ((malicious_droppers > 0)
               && ((((count_started + 1) % (int) malicious_dropper_num) == 0)))
@@ -578,6 +629,7 @@
                                                         "DHT",
                                                         "MALICIOUS_DROPPER",
                                                         "YES");
+              malicious_mask |= DROP_MASK;
             }
           else
             {
@@ -690,6 +742,7 @@
               next_peer->username = GNUNET_strdup (ssh_username);
               next_peer->port = starting_port + (j * port_increment);
               next_peer->pid = GNUNET_strdup (temp_pid_file);
+              next_peer->malicious_val = malicious_mask;
               tempcfg = GNUNET_GC_create ();
               GNUNET_snprintf (host, 128, "%s:%u", next_peer->hostname,
                                next_peer->port);
@@ -711,6 +764,9 @@
               temp_pos->port = (unsigned short) temp_port;
               temp_pos->next = head;
               temp_pos->pid = get_pid (new_ret_peers);
+              temp_pos->peer =
+                GNUNET_REMOTE_get_daemon_information (next_peer->hostname,
+                                                      next_peer->port);
               head = temp_pos;
               array_of_pointers[count_started] = temp_pos;
               count_started++;
@@ -724,7 +780,7 @@
 
           if ((i < extra_daemons) && (j == daemons_per_machine - 1))
             {
-
+              malicious_mask = 0;
               basecfg = GNUNET_GC_create ();
 
               if (-1 == GNUNET_GC_parse_configuration (basecfg, base_config))
@@ -734,7 +790,7 @@
                 }
 
               /*
-               * Indicates that the first node should be set as a malicious 
getter
+               * Indicates that this node should be set as a malicious getter
                */
               if ((malicious_getters > 0)
                   &&
@@ -744,6 +800,15 @@
                                                             "DHT",
                                                             "MALICIOUS_GETTER",
                                                             "YES");
+                  if (malicious_get_frequency > 0)
+                    {
+                      GNUNET_GC_set_configuration_value_number (basecfg, NULL,
+                                                                "DHT",
+                                                                
"MALICIOUS_GET_FREQUENCY",
+                                                                
malicious_get_frequency);
+
+                    }
+                  malicious_mask |= GET_MASK;
                 }
               else
                 {
@@ -754,7 +819,7 @@
                 }
 
               /*
-               * Indicates that the first node should be set as a malicious 
putter
+               * Indicates that this node should be set as a malicious putter
                */
               if ((malicious_putters > 0)
                   &&
@@ -764,6 +829,15 @@
                                                             "DHT",
                                                             "MALICIOUS_PUTTER",
                                                             "YES");
+                  if (malicious_put_frequency > 0)
+                    {
+                      GNUNET_GC_set_configuration_value_number (basecfg, NULL,
+                                                                "DHT",
+                                                                
"MALICIOUS_PUT_FREQUENCY",
+                                                                
malicious_put_frequency);
+
+                    }
+                  malicious_mask |= PUT_MASK;
                 }
               else
                 {
@@ -774,7 +848,7 @@
                 }
 
               /*
-               * Indicates that the first node should be set as a malicious 
dropper
+               * Indicates that this node should be set as a malicious dropper
                */
               if ((malicious_droppers > 0)
                   &&
@@ -785,6 +859,7 @@
                                                             "DHT",
                                                             
"MALICIOUS_DROPPER",
                                                             "YES");
+                  malicious_mask |= DROP_MASK;
                 }
               else
                 {
@@ -945,6 +1020,7 @@
                     starting_port + ((j + 1) * port_increment);
                   next_peer->username = GNUNET_strdup (ssh_username);
                   next_peer->pid = GNUNET_strdup (temp_pid_file);
+                  next_peer->malicious_val = malicious_mask;
                   tempcfg = GNUNET_GC_create ();
                   GNUNET_snprintf (host, 128, "%s:%u", next_peer->hostname,
                                    next_peer->port);
@@ -966,6 +1042,9 @@
                   temp_pos->port = (unsigned short) temp_port;
                   temp_pos->next = head;
                   temp_pos->pid = get_pid (new_ret_peers);
+                  temp_pos->peer =
+                    GNUNET_REMOTE_get_daemon_information (next_peer->hostname,
+                                                          next_peer->port);
                   head = temp_pos;
                   array_of_pointers[count_started] = temp_pos;
                   count_started++;
@@ -1006,6 +1085,130 @@
   return ret;
 }
 
+static void *
+connect_peer_thread (void *cls)
+{
+  struct GNUNET_REMOTE_host_list *pos = cls;
+  struct GNUNET_REMOTE_friends_list *friend_pos;
+  struct ConnectedEntry *tempEntry;
+  struct ConnectedEntry *tempFriendEntry;
+  struct ConnectedEntry *tempEntryPos;
+
+  int ret;
+  int pid1;
+  int pid2;
+  int match;
+
+  tempEntry = NULL;
+  tempFriendEntry = NULL;
+
+  GNUNET_mutex_lock (connectMutex);
+#if VERBOSE
+  fprintf (stdout, "Starting thread %d\n", threadCount);
+#endif
+  threadCount++;
+  GNUNET_mutex_unlock (connectMutex);
+  friend_pos = pos->friend_entries;
+  while (friend_pos != NULL)
+    {
+      GNUNET_mutex_lock (connectMutex);
+      match = GNUNET_NO;
+      if (GNUNET_YES ==
+          GNUNET_multi_hash_map_contains (connected, &pos->peer->hashPubKey))
+        {
+          tempEntryPos =
+            GNUNET_multi_hash_map_get (connected, &pos->peer->hashPubKey);
+          while (tempEntryPos != NULL)
+            {
+              if (memcmp
+                  (&tempEntryPos->key,
+                   &friend_pos->hostentry->peer->hashPubKey,
+                   sizeof (GNUNET_HashCode)) == 0)
+                match = GNUNET_YES;
+
+              tempEntryPos = tempEntryPos->next;
+            }
+        }
+      GNUNET_mutex_unlock (connectMutex);
+
+      if (match == GNUNET_YES)
+        {
+#if VERBOSE
+          fprintf (stderr,
+                   _
+                   ("NOT connecting peer %s:%d pid=%d to peer %s:%d pid=%d 
(already connected!)\n"),
+                   pos->hostname, pos->port, pid1,
+                   friend_pos->hostentry->hostname,
+                   friend_pos->hostentry->port, pid2);
+#endif
+          friend_pos = friend_pos->next;
+          continue;
+        }
+
+      pid1 = pos->pid;
+      pid2 = friend_pos->hostentry->pid;
+#if VERBOSE
+      fprintf (stderr,
+               _
+               ("connecting peer %s:%d pid=%d to peer %s:%d pid=%d\n"),
+               pos->hostname, pos->port, pid1,
+               friend_pos->hostentry->hostname,
+               friend_pos->hostentry->port, pid2);
+#endif
+      ret = GNUNET_REMOTE_connect_daemons (pos->hostname, pos->port,
+                                           friend_pos->hostentry->
+                                           hostname,
+                                           friend_pos->hostentry->
+                                           port, globalDotFile);
+      if (ret != GNUNET_OK)
+        {
+          GNUNET_mutex_lock (connectMutex);
+          connectFailures++;
+          GNUNET_mutex_unlock (connectMutex);
+        }
+      if (connectFailures > totalConnections / 2)
+        break;
+
+      if (ret == GNUNET_OK)
+        {
+          GNUNET_mutex_lock (connectMutex);
+          tempEntryPos = GNUNET_malloc (sizeof (struct ConnectedEntry));
+          memcpy (&tempEntryPos->key,
+                  &friend_pos->hostentry->peer->hashPubKey,
+                  sizeof (GNUNET_HashCode));
+          tempEntryPos->next = tempEntry;
+          GNUNET_multi_hash_map_put (connected, &pos->peer->hashPubKey,
+                                     tempEntryPos,
+                                     GNUNET_MultiHashMapOption_REPLACE);
+
+          tempFriendEntry =
+            GNUNET_multi_hash_map_get (connected,
+                                       &friend_pos->hostentry->peer->
+                                       hashPubKey);
+          tempEntryPos = GNUNET_malloc (sizeof (struct ConnectedEntry));
+          memcpy (&tempEntryPos->key, &pos->peer->hashPubKey,
+                  sizeof (GNUNET_HashCode));
+          tempEntryPos->next = tempFriendEntry;
+          GNUNET_multi_hash_map_put (connected,
+                                     &friend_pos->hostentry->peer->hashPubKey,
+                                     tempEntryPos,
+                                     GNUNET_MultiHashMapOption_REPLACE);
+          GNUNET_mutex_unlock (connectMutex);
+        }
+
+      friend_pos = friend_pos->next;
+    }
+
+  GNUNET_mutex_lock (connectMutex);
+  threadCount--;
+#if VERBOSE
+  fprintf (stdout, "Exiting thread %d\n", threadCount);
+#endif
+  GNUNET_mutex_unlock (connectMutex);
+
+  return NULL;
+}
+
 int
 GNUNET_REMOTE_create_topology (GNUNET_REMOTE_TOPOLOGIES type,
                                int number_of_daemons, FILE * dotOutFile,
@@ -1015,14 +1218,19 @@
   int ret;
   struct GNUNET_REMOTE_host_list *pos;
   struct GNUNET_REMOTE_friends_list *friend_pos;
+  struct threadInfo *threadHead;
+  struct threadInfo *connectThreadPos;
+
   int unused;
   char *cmd;
   int length;
-  int totalConnections;
-  int connectFailures;
-  int pid1;
-  int pid2;
+
+  void *unusedVoid;
+  globalDotFile = dotOutFile;
   ret = GNUNET_OK;
+  connected = GNUNET_multi_hash_map_create (number_of_daemons * 3);
+  threadHead = NULL;
+
   switch (type)
     {
     case GNUNET_REMOTE_CLIQUE:
@@ -1077,7 +1285,6 @@
   totalConnections = 0;
   if (ret == GNUNET_OK)
     {
-
       pos = head;
       while (pos != NULL)
         {
@@ -1138,39 +1345,44 @@
        * the two are connected, the second doesn't really need to try to 
connect
        * to the first later, but this IS simple.  If performance becomes a 
problem
        * with MANY conns, we'll see...
+       *
+       * 8-2009 - it is now a problem (-:  Options:
+       *  1. Use hashmap and list of previously connected peers (cuts down 
number of attempts by half)
+       *  2. Use multiple threads for connecting.  Start X threads, one per 
peer with max of Y and connect that peers friends.
+       *  3. Combine both of these ideas into new fun way of doing stuff.
+       *
+       *  Okay, Combined both solutions for a fix... Just need to test on large
+       *  scale testbed (lab) to confirm it actually helps.
        */
+      connectMutex = GNUNET_mutex_create (GNUNET_YES);
       connectFailures = 0;
+
       while ((pos != NULL) && (ret == GNUNET_OK))
         {
-          friend_pos = pos->friend_entries;
-          while (friend_pos != NULL)
+          while (threadCount >= MAX_CONNECT_THREADS)
             {
-              pid1 = pos->pid;
-              pid2 = friend_pos->hostentry->pid;
-#if VERBOSE
-              fprintf (stderr,
-                       _
-                       ("connecting peer %s:%d pid=%d to peer %s:%d pid=%d\n"),
-                       pos->hostname, pos->port, pid1,
-                       friend_pos->hostentry->hostname,
-                       friend_pos->hostentry->port, pid2);
-#endif
-              ret = GNUNET_REMOTE_connect_daemons (pos->hostname, pos->port,
-                                                   friend_pos->hostentry->
-                                                   hostname,
-                                                   friend_pos->hostentry->
-                                                   port, dotOutFile);
-              if (ret != GNUNET_OK)
-                {
-                  connectFailures++;
-                }
-              if (connectFailures > totalConnections / 2)
-                break;
-              friend_pos = friend_pos->next;
+              GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS);
             }
+          connectThreadPos = GNUNET_malloc (sizeof (struct threadInfo));
+          connectThreadPos->thread =
+            GNUNET_thread_create (&connect_peer_thread, pos, 1024 * 128);
+          connectThreadPos->next = threadHead;
+          threadHead = connectThreadPos;
+
           pos = pos->next;
         }
 
+      connectThreadPos = threadHead;
+      while (connectThreadPos != NULL)
+        {
+#if VERBOSE
+          fprintf (stdout, "Joining thread...\n");
+#endif
+          GNUNET_thread_join (connectThreadPos->thread, &unusedVoid);
+          connectThreadPos = connectThreadPos->next;
+        }
+
+      GNUNET_mutex_destroy (connectMutex);
     }
   else
     {
@@ -1183,6 +1395,8 @@
   fprintf (stderr, _("Total connections: %d!\n"), totalConnections);
   fprintf (stderr, _("Total failed connections: %d!\n"), connectFailures);
 #endif
+
+  GNUNET_multi_hash_map_destroy (connected);
   if (ret != GNUNET_OK)
     return ret;
   else

Modified: GNUnet/src/applications/testing/remote.h
===================================================================
--- GNUnet/src/applications/testing/remote.h    2009-08-16 09:31:25 UTC (rev 
8829)
+++ GNUnet/src/applications/testing/remote.h    2009-08-17 23:34:59 UTC (rev 
8830)
@@ -47,6 +47,7 @@
   char *username;
   unsigned short port;
   pid_t pid;
+  GNUNET_PeerIdentity *peer;
 };
 
 /* Simple linked list to store friends lists for each node,

Modified: GNUnet/src/applications/testing/remotetopologies.c
===================================================================
--- GNUnet/src/applications/testing/remotetopologies.c  2009-08-16 09:31:25 UTC 
(rev 8829)
+++ GNUnet/src/applications/testing/remotetopologies.c  2009-08-17 23:34:59 UTC 
(rev 8830)
@@ -44,13 +44,15 @@
 #endif
 
 static int
-addNodeRefs (GNUNET_EncName * node1enc, GNUNET_EncName * node2enc,
-             struct GNUNET_REMOTE_host_list *node1pos,
+addNodeRefs (struct GNUNET_REMOTE_host_list *node1pos,
              struct GNUNET_REMOTE_host_list *node2pos)
 {
   struct GNUNET_REMOTE_friends_list *node1temp;
   struct GNUNET_REMOTE_friends_list *node2temp;
 
+  GNUNET_EncName node1enc;
+  GNUNET_EncName node2enc;
+
   struct GNUNET_REMOTE_friends_list *node1iter;
   struct GNUNET_REMOTE_friends_list *node2iter;
   int added;
@@ -60,16 +62,19 @@
   node1iter = node1pos->friend_entries;
   node2iter = node2pos->friend_entries;
 
+  GNUNET_hash_to_enc (&node1pos->peer->hashPubKey, &node1enc);
+  GNUNET_hash_to_enc (&node2pos->peer->hashPubKey, &node2enc);
+
   while (node2iter != NULL)
     {
-      if (memcmp (node2iter->nodeid, node1enc, sizeof (GNUNET_EncName)) == 0)
+      if (memcmp (node2iter->nodeid, &node1enc, sizeof (GNUNET_EncName)) == 0)
         addNode2 = 0;
       node2iter = node2iter->next;
     }
 
   while (node1iter != NULL)
     {
-      if (memcmp (node1iter->nodeid, node2enc, sizeof (GNUNET_EncName)) == 0)
+      if (memcmp (node1iter->nodeid, &node2enc, sizeof (GNUNET_EncName)) == 0)
         addNode1 = 0;
       node1iter = node1iter->next;
     }
@@ -78,7 +83,7 @@
     {
       node1temp = GNUNET_malloc (sizeof (struct GNUNET_REMOTE_friends_list));
       node1temp->nodeid = GNUNET_malloc (sizeof (GNUNET_EncName));
-      memcpy (node1temp->nodeid, node2enc, sizeof (GNUNET_EncName));
+      memcpy (node1temp->nodeid, &node2enc, sizeof (GNUNET_EncName));
       node1temp->next = node1pos->friend_entries;
       node1temp->hostentry = node2pos;
       node1pos->friend_entries = node1temp;
@@ -90,7 +95,7 @@
       node2temp = GNUNET_malloc (sizeof (struct GNUNET_REMOTE_friends_list));
       node2temp->hostentry = node1pos;
       node2temp->nodeid = GNUNET_malloc (sizeof (GNUNET_EncName));
-      memcpy (node2temp->nodeid, node1enc, sizeof (GNUNET_EncName));
+      memcpy (node2temp->nodeid, &node1enc, sizeof (GNUNET_EncName));
       node2temp->next = node2pos->friend_entries;
       node2pos->friend_entries = node2temp;
       added++;
@@ -110,11 +115,7 @@
   unsigned int cutoff;
   struct GNUNET_REMOTE_host_list *pos = main_list;
   struct GNUNET_REMOTE_host_list *iter_pos = main_list;
-  GNUNET_EncName *node1;
-  GNUNET_EncName *node2;
 
-  node1 = GNUNET_malloc (sizeof (GNUNET_EncName));
-  node2 = GNUNET_malloc (sizeof (GNUNET_EncName));
   cutoff = (unsigned int) (nat_percentage * number_of_daemons);
 
   count = 0;
@@ -141,15 +142,7 @@
 
           if (GNUNET_YES == can_connect)
             {
-              if (GNUNET_OK ==
-                  GNUNET_REMOTE_get_daemons_information (pos->hostname,
-                                                         pos->port,
-                                                         iter_pos->hostname,
-                                                         iter_pos->port,
-                                                         &node1, &node2))
-                {
-                  addNodeRefs (node1, node2, pos, iter_pos);
-                }
+              addNodeRefs (pos, iter_pos);
             }
           iter_pos = iter_pos->next;
           inner_count++;
@@ -158,9 +151,6 @@
       count++;
     }
 
-  GNUNET_free (node1);
-  GNUNET_free (node2);
-
   return GNUNET_OK;
 }
 
@@ -173,42 +163,27 @@
   double temp_rand;
   struct GNUNET_REMOTE_host_list *pos = main_list;
   struct GNUNET_REMOTE_host_list *iter_pos = main_list;
-  GNUNET_EncName *node1;
-  GNUNET_EncName *node2;
 
-  node1 = GNUNET_malloc (sizeof (GNUNET_EncName));
-  node2 = GNUNET_malloc (sizeof (GNUNET_EncName));
-
-
   while ((pos != NULL) && (pos->next != NULL))
     {
       iter_pos = pos->next;
       while (iter_pos != NULL)
         {
-          if (GNUNET_OK ==
-              GNUNET_REMOTE_get_daemons_information (pos->hostname, pos->port,
-                                                     iter_pos->hostname,
-                                                     iter_pos->port, &node1,
-                                                     &node2))
-            {
-              temp_rand = ((double) RANDOM () / RAND_MAX);
+          temp_rand = ((double) RANDOM () / RAND_MAX);
 #if VERBOSE
-              fprintf (stderr, _("rand is %f probability is %f\n"), temp_rand,
-                       probability);
+          fprintf (stderr, _("rand is %f probability is %f\n"), temp_rand,
+                   probability);
 #endif
-              if (temp_rand < probability)
-                {
-                  addNodeRefs (node1, node2, pos, iter_pos);
-                }
+          if (temp_rand < probability)
+            {
+              addNodeRefs (pos, iter_pos);
             }
+
           iter_pos = iter_pos->next;
         }
       pos = pos->next;
     }
 
-  GNUNET_free (node1);
-  GNUNET_free (node2);
-
   return GNUNET_OK;
 }
 
@@ -218,33 +193,18 @@
 {
   struct GNUNET_REMOTE_host_list *pos = main_list;
   struct GNUNET_REMOTE_host_list *iter_pos = main_list;
-  GNUNET_EncName *node1;
-  GNUNET_EncName *node2;
 
-  node1 = GNUNET_malloc (sizeof (GNUNET_EncName));
-  node2 = GNUNET_malloc (sizeof (GNUNET_EncName));
-
   while ((pos != NULL) && (pos->next != NULL))
     {
       iter_pos = pos->next;
       while (iter_pos != NULL)
         {
-          if (GNUNET_OK ==
-              GNUNET_REMOTE_get_daemons_information (pos->hostname, pos->port,
-                                                     iter_pos->hostname,
-                                                     iter_pos->port, &node1,
-                                                     &node2))
-            {
-              addNodeRefs (node1, node2, pos, iter_pos);
-            }
+          addNodeRefs (pos, iter_pos);
           iter_pos = iter_pos->next;
         }
       pos = pos->next;
     }
 
-  GNUNET_free (node1);
-  GNUNET_free (node2);
-
   return GNUNET_OK;
 }
 
@@ -254,36 +214,16 @@
 {
   struct GNUNET_REMOTE_host_list *pos = main_list;
   struct GNUNET_REMOTE_host_list *iter_pos = main_list;
-  GNUNET_EncName *node1;
-  GNUNET_EncName *node2;
-  node1 = GNUNET_malloc (sizeof (GNUNET_EncName));
-  node2 = GNUNET_malloc (sizeof (GNUNET_EncName));
 
   while (pos->next != NULL)
     {
       iter_pos = pos->next;
-      if (GNUNET_OK ==
-          GNUNET_REMOTE_get_daemons_information (pos->hostname, pos->port,
-                                                 iter_pos->hostname,
-                                                 iter_pos->port, &node1,
-                                                 &node2))
-        {
-          addNodeRefs (node1, node2, pos, iter_pos);
-        }
+      addNodeRefs (pos, iter_pos);
       pos = pos->next;
     }
   iter_pos = main_list;
-  if (GNUNET_OK ==
-      GNUNET_REMOTE_get_daemons_information (pos->hostname, pos->port,
-                                             iter_pos->hostname,
-                                             iter_pos->port, &node1, &node2))
-    {
-      addNodeRefs (node1, node2, pos, iter_pos);
-    }
+  addNodeRefs (pos, iter_pos);
 
-  GNUNET_free (node1);
-  GNUNET_free (node2);
-
   return GNUNET_OK;
 }
 
@@ -299,12 +239,6 @@
   unsigned int toggle = 1;
   unsigned int nodeToConnect;
 
-  GNUNET_EncName *node1;
-  GNUNET_EncName *node2;
-
-  node1 = GNUNET_malloc (sizeof (GNUNET_EncName));
-  node2 = GNUNET_malloc (sizeof (GNUNET_EncName));
-
   square = floor (sqrt (number_of_daemons));
   rows = square;
   cols = square;
@@ -343,16 +277,8 @@
 #if VERBOSE
       fprintf (stderr, _("connecting node %u to %u\n"), i, nodeToConnect);
 #endif
-      GNUNET_REMOTE_get_daemons_information (list_as_array[i]->hostname,
-                                             list_as_array[i]->port,
-                                             list_as_array
-                                             [nodeToConnect]->hostname,
-                                             list_as_array
-                                             [nodeToConnect]->port, &node1,
-                                             &node2);
 
-      addNodeRefs (node1, node2, list_as_array[i],
-                   list_as_array[nodeToConnect]);
+      addNodeRefs (list_as_array[i], list_as_array[nodeToConnect]);
 
       /* Second connect to the node immediately above */
       if (i < cols)
@@ -365,22 +291,11 @@
 #if VERBOSE
           fprintf (stderr, _("connecting node %u to %u\n"), i, nodeToConnect);
 #endif
-          GNUNET_REMOTE_get_daemons_information (list_as_array[i]->hostname,
-                                                 list_as_array[i]->port,
-                                                 list_as_array
-                                                 [nodeToConnect]->hostname,
-                                                 list_as_array
-                                                 [nodeToConnect]->port,
-                                                 &node1, &node2);
-
-          addNodeRefs (node1, node2, list_as_array[i],
-                       list_as_array[nodeToConnect]);
+          addNodeRefs (list_as_array[i], list_as_array[nodeToConnect]);
         }
 
     }
 
-  GNUNET_free (node1);
-  GNUNET_free (node2);
   return GNUNET_OK;
 }
 
@@ -405,12 +320,6 @@
   double probability, random;
   unsigned int totalConnections, smallWorldConnections;
 
-  GNUNET_EncName *node1;
-  GNUNET_EncName *node2;
-
-  node1 = GNUNET_malloc (sizeof (GNUNET_EncName));
-  node2 = GNUNET_malloc (sizeof (GNUNET_EncName));
-
   square = floor (sqrt (number_of_daemons));
   rows = square;
   cols = square;
@@ -451,14 +360,7 @@
 #if VERBOSE
       fprintf (stderr, _("connecting node %u to %u\n"), i, nodeToConnect);
 #endif
-      GNUNET_REMOTE_get_daemons_information (list_as_array[i]->hostname,
-                                             list_as_array[i]->port,
-                                             list_as_array
-                                             [nodeToConnect]->hostname,
-                                             list_as_array
-                                             [nodeToConnect]->port, &node1,
-                                             &node2);
-      totalConnections += addNodeRefs (node1, node2, list_as_array[i],
+      totalConnections += addNodeRefs (list_as_array[i],
                                        list_as_array[nodeToConnect]);
 
       if (i < cols)
@@ -471,14 +373,7 @@
 #if VERBOSE
           fprintf (stderr, _("connecting node %u to %u\n"), i, nodeToConnect);
 #endif
-          GNUNET_REMOTE_get_daemons_information (list_as_array[i]->hostname,
-                                                 list_as_array[i]->port,
-                                                 list_as_array
-                                                 [nodeToConnect]->hostname,
-                                                 list_as_array
-                                                 [nodeToConnect]->port,
-                                                 &node1, &node2);
-          totalConnections += addNodeRefs (node1, node2, list_as_array[i],
+          totalConnections += addNodeRefs (list_as_array[i],
                                            list_as_array[nodeToConnect]);
         }
 
@@ -489,7 +384,7 @@
   fprintf (stderr, _("natural log of %d is %d, will run %d iterations\n"),
            number_of_daemons, natLog, (int) (natLog * percentage));
   fprintf (stderr, _("Total connections added thus far: %d!\n"),
-           smallWorldConnections);
+           totalConnections);
 #endif
   smallWorldConnections = 0;
   for (i = 0; i < (int) (natLog * percentage); i++)
@@ -516,19 +411,8 @@
                   /* If random < probability, then connect the two nodes */
                   if (random < probability)
                     {
-                      GNUNET_REMOTE_get_daemons_information (list_as_array
-                                                             [j]->hostname,
-                                                             list_as_array
-                                                             [j]->port,
-                                                             list_as_array
-                                                             [k]->hostname,
-                                                             list_as_array
-                                                             [k]->port,
-                                                             &node1, &node2);
-
                       smallWorldConnections +=
-                        addNodeRefs (node1, node2, list_as_array[j],
-                                     list_as_array[k]);
+                        addNodeRefs (list_as_array[j], list_as_array[k]);
                     }
                 }
             }
@@ -539,8 +423,7 @@
   fprintf (stderr, _("Total connections added for small world: %d!\n"),
            smallWorldConnections);
 #endif
-  GNUNET_free (node1);
-  GNUNET_free (node2);
+
   return GNUNET_OK;
 }
 





reply via email to

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