gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r11094 - gnunet/src/testing


From: gnunet
Subject: [GNUnet-SVN] r11094 - gnunet/src/testing
Date: Wed, 28 Apr 2010 14:58:35 +0200

Author: nevans
Date: 2010-04-28 14:58:35 +0200 (Wed, 28 Apr 2010)
New Revision: 11094

Modified:
   gnunet/src/testing/test_testing_topology.c
   gnunet/src/testing/testing_group.c
Log:
testing bugfix, add scale free topology

Modified: gnunet/src/testing/test_testing_topology.c
===================================================================
--- gnunet/src/testing/test_testing_topology.c  2010-04-28 12:40:41 UTC (rev 
11093)
+++ gnunet/src/testing/test_testing_topology.c  2010-04-28 12:58:35 UTC (rev 
11094)
@@ -116,6 +116,9 @@
   /* Identifier for this message, so we don't disconnect other peers! */
   uint32_t uid;
 
+  /* Task for disconnecting cores, allow task to be cancelled on shutdown */
+  GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
+
 };
 
 static struct TestMessageContext *test_messages;
@@ -147,6 +150,10 @@
         }
       free_pos = pos;
       pos = pos->next;
+      if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+        {
+          GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
+        }
       GNUNET_free(free_pos);
     }
 #if VERBOSE
@@ -194,6 +201,7 @@
   /* Set handles to NULL so test case can be ended properly */
   pos->peer1handle = NULL;
   pos->peer2handle = NULL;
+  pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
   /* Decrement total connections so new can be established */
   total_server_connections -= 2;
 }
@@ -225,7 +233,7 @@
     }
   else
     {
-      GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos);
+      pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, 
&disconnect_cores, pos);
     }
 
   return GNUNET_OK;
@@ -443,6 +451,7 @@
       temp_context->peer2 = second_daemon;
       temp_context->next = test_messages;
       temp_context->uid = total_connections;
+      temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
       test_messages = temp_context;
 
       expected_messages++;

Modified: gnunet/src/testing/testing_group.c
===================================================================
--- gnunet/src/testing/testing_group.c  2010-04-28 12:40:41 UTC (rev 11093)
+++ gnunet/src/testing/testing_group.c  2010-04-28 12:58:35 UTC (rev 11094)
@@ -82,10 +82,15 @@
    */
   struct GNUNET_TESTING_Daemon *daemon;
 
-  /*
+  /**
    * Linked list of peer connections (simply indexes of PeerGroup)
    */
   struct PeerConnection *connected_peers;
+
+  /**
+   * Total number of connections this peer has
+   */
+  int num_connections;
 };
 
 
@@ -332,6 +337,7 @@
       new_first->daemon = pg->peers[second].daemon;
       new_first->next = pg->peers[first].connected_peers;
       pg->peers[first].connected_peers = new_first;
+      pg->peers[first].num_connections++;
       added++;
     }
 
@@ -341,12 +347,52 @@
       new_second->daemon = pg->peers[first].daemon;
       new_second->next = pg->peers[second].connected_peers;
       pg->peers[second].connected_peers = new_second;
+      pg->peers[first].num_connections++;
       added++;
     }
 
   return added;
 }
 
+static int
+create_scale_free (struct GNUNET_TESTING_PeerGroup *pg)
+{
+
+  int total_connections;
+  int outer_count;
+  int i;
+  int previous_total_connections;
+  double random;
+  double probability;
+
+  GNUNET_assert(pg->total > 1);
+
+  /* Add a connection between the first two nodes */
+  total_connections = add_connections(pg, 0, 1);
+
+  for (outer_count = 1; outer_count < pg->total - 1; outer_count++)
+    {
+      previous_total_connections = total_connections;
+      for (i = 0; i < outer_count; i++)
+        {
+          probability = pg->peers[i].num_connections / 
previous_total_connections;
+          random = ((double) 
GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
+                                                      (uint64_t)-1LL)) / ( 
(double) (uint64_t) -1LL);
+          if (random < probability)
+            {
+#if VERBOSE_TESTING
+              GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                          "Connecting peer %d to peer %d\n",
+                          outer_count, i);
+#endif
+              total_connections += add_connections(pg, outer_count, i);
+            }
+        }
+    }
+
+  return total_connections;
+}
+
 int
 create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg)
 {
@@ -1076,52 +1122,59 @@
         case GNUNET_TESTING_TOPOLOGY_CLIQUE:
 #if VERBOSE_TESTING
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                      _("Creating clique topology (may take a bit!)\n"));
+                      _("Creating clique topology\n"));
 #endif
           num_connections = create_clique (pg);
           break;
         case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING:
 #if VERBOSE_TESTING
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                      _("Creating small world (ring) topology (may take a 
bit!)\n"));
+                      _("Creating small world (ring) topology\n"));
 #endif
           num_connections = create_small_world_ring (pg);
           break;
         case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD:
 #if VERBOSE_TESTING
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                      _("Creating small world (2d-torus) topology (may take a 
bit!)\n"));
+                      _("Creating small world (2d-torus) topology\n"));
 #endif
           num_connections = create_small_world (pg);
           break;
         case GNUNET_TESTING_TOPOLOGY_RING:
 #if VERBOSE_TESTING
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                      _("Creating ring topology (may take a bit!)\n"));
+                      _("Creating ring topology\n"));
 #endif
           num_connections = create_ring (pg);
           break;
         case GNUNET_TESTING_TOPOLOGY_2D_TORUS:
 #if VERBOSE_TESTING
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                      _("Creating 2d torus topology (may take a bit!)\n"));
+                      _("Creating 2d torus topology\n"));
 #endif
           num_connections = create_2d_torus (pg);
           break;
         case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI:
 #if VERBOSE_TESTING
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                      _("Creating Erdos-Renyi topology (may take a bit!)\n"));
+                      _("Creating Erdos-Renyi topology\n"));
 #endif
           num_connections = create_erdos_renyi (pg);
           break;
         case GNUNET_TESTING_TOPOLOGY_INTERNAT:
 #if VERBOSE_TESTING
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                      _("Creating InterNAT topology (may take a bit!)\n"));
+                      _("Creating InterNAT topology\n"));
 #endif
           num_connections = create_nated_internet (pg);
           break;
+        case GNUNET_TESTING_TOPOLOGY_SCALE_FREE:
+#if VERBOSE_TESTING
+          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                      _("Creating Scale Free topology\n"));
+#endif
+          num_connections = create_scale_free (pg);
+          break;
         case GNUNET_TESTING_TOPOLOGY_NONE:
           num_connections = 0;
           break;





reply via email to

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