gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r13046 - gnunet/src/testing
Date: Tue, 21 Sep 2010 14:57:16 +0200

Author: nevans
Date: 2010-09-21 14:57:16 +0200 (Tue, 21 Sep 2010)
New Revision: 13046

Modified:
   gnunet/src/testing/test_testing_topology.c
   gnunet/src/testing/testing_group.c
Log:
additional topology creation option, for adding closest underlay capable peers 
to topology

Modified: gnunet/src/testing/test_testing_topology.c
===================================================================
--- gnunet/src/testing/test_testing_topology.c  2010-09-21 12:55:24 UTC (rev 
13045)
+++ gnunet/src/testing/test_testing_topology.c  2010-09-21 12:57:16 UTC (rev 
13046)
@@ -26,7 +26,7 @@
 #include "gnunet_core_service.h"
 #include "gnunet_os_lib.h"
 
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
 
 #define DELAY_FOR_LOGGING GNUNET_NO
 
@@ -270,7 +270,6 @@
 
 static void stats_finished (void *cls, int result)
 {
-  fprintf(stderr, "Finished getting all peers statistics!\n");
   GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
 }
 
@@ -292,7 +291,7 @@
                          uint64_t value,
                          int is_persistent)
 {
-  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s:%s -- %llu\n", 
GNUNET_i2s(peer), subsystem, name, value);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n", GNUNET_i2s(peer), 
subsystem, name, value);
   return GNUNET_OK;
 }
 

Modified: gnunet/src/testing/testing_group.c
===================================================================
--- gnunet/src/testing/testing_group.c  2010-09-21 12:55:24 UTC (rev 13045)
+++ gnunet/src/testing/testing_group.c  2010-09-21 12:57:16 UTC (rev 13046)
@@ -32,6 +32,8 @@
 
 #define VERBOSE_TESTING GNUNET_NO
 
+#define VERBOSE_TOPOLOGY GNUNET_YES
+
 #define DEBUG_CHURN GNUNET_NO
 
 /**
@@ -726,6 +728,13 @@
       "CONNECT_DFS",
       
       /**
+       * Find the N closest peers to each allowed peer in the
+       * topology and make sure a connection to those peers
+       * exists in the connect topology.
+       */
+      "CONNECT_CLOSEST",
+
+      /**
        * No options specified.
        */
       "CONNECT_NONE",
@@ -1609,7 +1618,9 @@
 
 /**
  * Create a topology given a peer group (set of running peers)
- * and a connection processor.
+ * and a connection processor.  This particular function creates
+ * the connections for a 2d-torus, plus additional "closest"
+ * connections per peer.
  *
  * @param pg the peergroup to create the topology on
  * @param proc the connection processor to call to actually set
@@ -2669,8 +2680,8 @@
  */
 static int
 random_connect_iterator (void *cls,
-                  const GNUNET_HashCode * key,
-                  void *value)
+                         const GNUNET_HashCode * key,
+                         void *value)
 {
   struct RandomContext *random_ctx = cls;
   double random_number;
@@ -2870,7 +2881,97 @@
   return count;
 }
 
+
+struct FindClosestContext
+{
+  /**
+   * The currently known closest peer.
+   */
+  struct GNUNET_TESTING_Daemon *closest;
+
+  /**
+   * The info for the peer we are adding connections for.
+   */
+  struct PeerData *curr_peer;
+
+  /**
+   * The distance (bits) between the current
+   * peer and the currently known closest.
+   */
+  unsigned int closest_dist;
+
+  /**
+   * The offset of the closest known peer in
+   * the peer group.
+   */
+  unsigned int closest_num;
+};
+
 /**
+ * Iterator over hash map entries of the allowed
+ * peer connections.  Find the closest, not already
+ * connected peer and return it.
+ *
+ * @param cls closure (struct FindClosestContext)
+ * @param key current key code (hash of offset in pg)
+ * @param value value in the hash map - a GNUNET_TESTING_Daemon
+ * @return GNUNET_YES if we should continue to
+ *         iterate,
+ *         GNUNET_NO if not.
+ */
+static
+int find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value)
+{
+  struct FindClosestContext *closest_ctx = cls;
+  struct GNUNET_TESTING_Daemon *daemon = value;
+
+  if (((closest_ctx->closest == NULL) ||
+       (GNUNET_CRYPTO_hash_matching_bits(&daemon->id.hashPubKey, 
&closest_ctx->curr_peer->daemon->id.hashPubKey) > closest_ctx->closest_dist))
+      && (GNUNET_YES != 
GNUNET_CONTAINER_multihashmap_contains(closest_ctx->curr_peer->connect_peers, 
key)))
+    {
+      closest_ctx->closest_dist = 
GNUNET_CRYPTO_hash_matching_bits(&daemon->id.hashPubKey, 
&closest_ctx->curr_peer->daemon->id.hashPubKey);
+      closest_ctx->closest = daemon;
+      uid_from_hash(key, &closest_ctx->closest_num);
+    }
+  return GNUNET_YES;
+}
+
+/**
+ * From the set of connections possible, choose at num connections per
+ * peer based on depth which are closest out of those allowed.  Guaranteed
+ * to add num peers to connect to, provided there are that many peers
+ * in the underlay topology to connect to.
+ *
+ * @param pg the peergroup we are dealing with
+ * @param num how many connections at least should each peer have (if 
possible)?
+ * @param proc processor to actually add the connections
+ */
+void
+add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, 
GNUNET_TESTING_ConnectionProcessor proc)
+{
+  struct FindClosestContext closest_ctx;
+  uint32_t pg_iter;
+  uint32_t i;
+
+  for (i = 0; i < num; i++) /* Each time find a closest peer (from those 
available) */
+    {
+      for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
+        {
+          closest_ctx.curr_peer = &pg->peers[pg_iter];
+          closest_ctx.closest = NULL;
+          closest_ctx.closest_dist = 0;
+          closest_ctx.closest_num = 0;
+          
GNUNET_CONTAINER_multihashmap_iterate(pg->peers[pg_iter].allowed_peers, 
&find_closest_peers, &closest_ctx);
+          if (closest_ctx.closest != NULL)
+            {
+              GNUNET_assert((0 <= closest_ctx.closest_num) && 
(closest_ctx.closest_num < pg->total));
+              proc(pg, pg_iter, closest_ctx.closest_num);
+            }
+        }
+    }
+}
+
+/**
  * From the set of connections possible, choose at least num connections per
  * peer based on depth first traversal of peer connections.  If DFS leaves
  * peers unconnected, ensure those peers get connections.
@@ -3293,6 +3394,13 @@
 #endif
       perform_dfs(pg, (int)option_modifier);
       break;
+    case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST:
+#if VERBOSE_TOPOLOGY
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  _("Finding additional %u closest peers each (if 
possible)\n"), (unsigned int)option_modifier);
+#endif
+      add_closest(pg, (unsigned int)option_modifier, &add_actual_connections);
+      break;
     case GNUNET_TESTING_TOPOLOGY_OPTION_NONE:
       break;
     case GNUNET_TESTING_TOPOLOGY_OPTION_ALL:




reply via email to

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