gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r8356 - in GNUnet/src/applications/dv_dht: module tools


From: gnunet
Subject: [GNUnet-SVN] r8356 - in GNUnet/src/applications/dv_dht: module tools
Date: Sun, 29 Mar 2009 21:00:48 -0600

Author: nevans
Date: 2009-03-29 21:00:48 -0600 (Sun, 29 Mar 2009)
New Revision: 8356

Added:
   GNUnet/src/applications/dv_dht/tools/dv_dht_multi_topology_test.c
   GNUnet/src/applications/dv_dht/tools/dv_test.conf
   GNUnet/src/applications/dv_dht/tools/gnunetd_dv.conf
Modified:
   GNUnet/src/applications/dv_dht/module/routing.c
   GNUnet/src/applications/dv_dht/module/table.c
   GNUnet/src/applications/dv_dht/tools/Makefile.am
Log:
minor cosmetic changes

Modified: GNUnet/src/applications/dv_dht/module/routing.c
===================================================================
--- GNUnet/src/applications/dv_dht/module/routing.c     2009-03-30 02:57:09 UTC 
(rev 8355)
+++ GNUnet/src/applications/dv_dht/module/routing.c     2009-03-30 03:00:48 UTC 
(rev 8356)
@@ -172,7 +172,7 @@
   DV_DHT_MESSAGE get;
 
   /**
-   * Hashcodes of the results that we have send back
+   * Hashcodes of the results that we have sent back
    * so far.
    */
   GNUNET_HashCode *results;
@@ -812,7 +812,7 @@
 /**
  * Perform a DV_DHT put operation.  Note that PUT operations always
  * expire after a period of time and the client is responsible for
- * doing periodic refreshs.  The given expiration time is ONLY used to
+ * doing periodic refreshes.  The given expiration time is ONLY used to
  * ensure that the datum is certainly deleted by that time (it maybe
  * deleted earlier).
  *

Modified: GNUnet/src/applications/dv_dht/module/table.c
===================================================================
--- GNUnet/src/applications/dv_dht/module/table.c       2009-03-30 02:57:09 UTC 
(rev 8355)
+++ GNUnet/src/applications/dv_dht/module/table.c       2009-03-30 03:00:48 UTC 
(rev 8356)
@@ -33,7 +33,7 @@
  * - modules:
  *   + table.c: DV_DHT-peer table, peer discovery cron jobs;
  *     code tries to fill table "as much as possible" over time;
- *     TODO: expose and improve reliabily metrics (to be added later)???
+ *     TODO: expose and improve reliability metrics (to be added later)???
  *     TODO: better randomized neighbor selection in DV_DHT_select_peer???
  *     TODO: add callback for discovery-message padding (use core callback
  *           for extra-available bandwidth)
@@ -434,6 +434,47 @@
   return GNUNET_SYSERR;
 }
 
+
+/*
+ * Find the actual, closest peer in our buckets to target
+ */
+int
+find_closest_peer (GNUNET_PeerIdentity * set,
+                        const GNUNET_HashCode * target)
+{
+  unsigned int largest_distance;
+  unsigned int distance;
+  unsigned int bc;
+  unsigned int ec;
+
+  const PeerBucket *bucket;
+  const PeerInfo *pi;
+  const PeerInfo *chosen;
+  chosen = NULL;
+  GNUNET_mutex_lock (lock);
+  largest_distance = 0;
+  total_distance = 0;
+  for (bc = 0; bc < bucketCount; bc++)
+    {
+      bucket = &buckets[bc];
+      for (ec = 0; ec < bucket->peers_size; ec++)
+        {
+          pi = bucket->peers[ec];
+          if (inverse_distance (target, &pi->id.hashPubKey) > largest_distance)
+            chosen = bucket->peers[ec];
+        }
+    }
+
+  GNUNET_mutex_unlock (lock);
+  if ((largest_distance > 0) && (chosen != NULL))
+  {
+    *set = chosen->id;
+    return GNUNET_OK;
+  }
+  else
+    return GNUNET_SYSERR;
+}
+
 /**
  * Send a discovery message to the other peer.
  *
@@ -513,12 +554,10 @@
       disc.header.type = htons (GNUNET_P2P_PROTO_DHT_DISCOVERY);
       disc.space_available = -1;        /* FIXME */
       dvapi->dv_connections_iterate(&broadcast_dht_discovery_prob, &disc);
-      /*coreAPI->p2p_connections_iterate (&broadcast_dht_discovery_prob, 
&disc);*/
     }
   else
     {
       dvapi->dv_connections_iterate(&broadcast_dht_discovery_prob, NULL);
-      /*coreAPI->p2p_connections_iterate (&broadcast_dht_discovery_prob, 
NULL);*/
     }
 }
 

Modified: GNUnet/src/applications/dv_dht/tools/Makefile.am
===================================================================
--- GNUnet/src/applications/dv_dht/tools/Makefile.am    2009-03-30 02:57:09 UTC 
(rev 8355)
+++ GNUnet/src/applications/dv_dht/tools/Makefile.am    2009-03-30 03:00:48 UTC 
(rev 8356)
@@ -32,7 +32,8 @@
 check_PROGRAMS = \
   dv_dht_loopback_test \
   dv_dht_twopeer_test \
-  dv_dht_multipeer_test 
+  dv_dht_multipeer_test \
+  dv_dht_multi_topology_test
 
 TESTS = $(check_PROGRAMS)
 
@@ -59,6 +60,17 @@
   $(top_builddir)/src/applications/testing/libgnunettestingapi.la \
   $(top_builddir)/src/applications/dv_dht/tools/libgnunetdvdhtapi.la \
   $(top_builddir)/src/util/libgnunetutil.la 
+  
+dv_dht_multi_topology_test_SOURCES = \
+  dv_dht_multi_topology_test.c 
+dv_dht_multi_topology_test_LDADD = \
+  $(top_builddir)/src/applications/stats/libgnunetstatsapi.la \
+  $(top_builddir)/src/applications/testing/libgnunettestingapi.la \
+  $(top_builddir)/src/applications/testing/libgnunetremoteapi.la \
+  $(top_builddir)/src/applications/dv_dht/tools/libgnunetdvdhtapi.la \
+  $(top_builddir)/src/util/libgnunetutil.la 
 
 EXTRA_DIST = \
-  check.conf 
+  check.conf \
+  dv_test.conf \
+  gnunetd_dv.conf

Added: GNUnet/src/applications/dv_dht/tools/dv_dht_multi_topology_test.c
===================================================================
--- GNUnet/src/applications/dv_dht/tools/dv_dht_multi_topology_test.c           
                (rev 0)
+++ GNUnet/src/applications/dv_dht/tools/dv_dht_multi_topology_test.c   
2009-03-30 03:00:48 UTC (rev 8356)
@@ -0,0 +1,276 @@
+/*
+     This file is part of GNUnet.
+     (C) 2007, 2008 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file applications/dht/tools/dht_multipeer_test.c
+ * @brief DV_DHT testcase
+ * @author Christian Grothoff
+ * @author Nathan Evans
+ */
+
+#include "platform.h"
+#include "gnunet_protocols.h"
+#include "gnunet_dv_dht_lib.h"
+#include "gnunet_testing_lib.h"
+#include "gnunet_stats_lib.h"
+#include "gnunet_util.h"
+#include "gnunet_remote_lib.h"
+
+/**
+ * How many peers should the testcase run?  Note that
+ * we create a clique topology so the cost is quadratic!
+ */
+#define NUM_PEERS 8
+
+/**
+ * How many times will we try the DV_DHT-GET operation before
+ * giving up for good?
+ */
+#define NUM_ROUNDS 20
+
+/**
+ * How often do we iterate the put-get loop?
+ */
+#define NUM_REPEAT 5
+
+static int ok;
+static int found;
+
+static int
+result_callback (const GNUNET_HashCode * key,
+                 unsigned int type,
+                 unsigned int size, const char *data, void *cls)
+{
+  int *i = cls;
+  char expect[8];
+
+  memset (expect, (*i), sizeof (expect));
+#if 0
+  fprintf (stderr, "Got %u %u `%.*s' (want `%.*s')\n", type, size, size, data,
+           sizeof (expect), expect);
+#endif
+  if ((8 != size) ||
+      (0 != memcmp (expect, data, size)) ||
+      (type != GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING))
+    return GNUNET_SYSERR;
+  found++;
+  return GNUNET_OK;
+}
+
+
+static int
+waitForConnect (const char *name, unsigned long long value, void *cls)
+{
+  if ((value > 0) && (0 == strcmp (_("# dv_dht connections"), name)))
+    {
+      ok = 1;
+      return GNUNET_SYSERR;
+    }
+  return GNUNET_OK;
+}
+
+#define CHECK(a) do { if (!(a)) { ret = 1; GNUNET_GE_BREAK(ectx, 0); goto 
FAILURE; } } while(0)
+
+/**
+ * Testcase to test DV_DHT routing (many peers).
+ * @return 0: ok, -1: error
+ */
+int
+main (int argc, const char **argv)
+{
+  struct GNUNET_REMOTE_TESTING_DaemonContext *peers;
+  struct GNUNET_REMOTE_TESTING_DaemonContext *peer_array[NUM_PEERS];
+  struct GNUNET_REMOTE_TESTING_DaemonContext *pos;
+  int ret = 0;
+  GNUNET_HashCode key;
+  char value[8];
+  struct GNUNET_GE_Context *ectx;
+  struct GNUNET_GC_Configuration *cfg;
+  struct GNUNET_ClientServerConnection *sock;
+  struct GNUNET_DV_DHT_Context *dctx;
+  struct GNUNET_DV_DHT_GetRequest *get1;
+  int left;
+  int i;
+  int j;
+  int k;
+  int c;
+  int r;
+  int last;
+  char buf[128];
+
+  ectx = NULL;
+  cfg = GNUNET_GC_create ();
+  if (-1 == GNUNET_GC_parse_configuration (cfg, "dv_test.conf"))
+    {
+      GNUNET_GC_free (cfg);
+      return -1;
+    }
+  GNUNET_GC_set_configuration_value_string (cfg, NULL,
+                                          "MULTIPLE_SERVER_TESTING",
+                                          "DOT_OUTPUT", "topology.dot");
+  printf ("Starting %u peers...\n", NUM_PEERS);
+  peers = GNUNET_REMOTE_start_daemons (cfg, NUM_PEERS);
+  if (peers == NULL)
+    {
+      GNUNET_GC_free (cfg);
+      return -1;
+    }
+  pos = peers;
+  for (i = 0; i < NUM_PEERS; i++)
+  {
+    peer_array[i] = pos;
+    pos = pos->next;
+  }
+
+  found = 0;
+  for (r = 0; r < NUM_REPEAT; r++)
+    {
+      if (r > 0)
+        {
+          printf ("Found %u out of %u attempts.\n", found,
+                  NUM_PEERS * NUM_PEERS * r);
+          if (found >= NUM_PEERS * NUM_PEERS * r / 2)
+            break;              /* good enough */
+        }
+      if (GNUNET_shutdown_test () == GNUNET_YES)
+        break;
+      /* put loop */
+      printf ("Waiting for DV_DHT connections of peer");
+      for (i = 0; i < NUM_PEERS; i++)
+        {
+          if (GNUNET_shutdown_test () == GNUNET_YES)
+            break;
+          ok = 0;
+          printf (" %d", i);
+          fflush (stdout);
+          GNUNET_snprintf (buf, sizeof (buf), "localhost:%u", 2087 + i * 10);
+          /* wait for some DV_DHT's to find each other! */
+          sock = GNUNET_client_connection_create (NULL, peer_array[i]->config);
+          left = 30;            /* how many iterations should we wait? */
+          while (GNUNET_OK ==
+                 GNUNET_STATS_get_statistics (NULL, sock, &waitForConnect,
+                                              NULL))
+            {
+              if (GNUNET_shutdown_test () == GNUNET_YES)
+                break;
+              if (9 == left % 10)
+                printf (".");
+              fflush (stdout);
+              GNUNET_thread_sleep (2 * GNUNET_CRON_SECONDS);
+              left--;
+              if (left == 0)
+                break;
+            }
+          GNUNET_client_connection_destroy (sock);
+          if (ok == 0)
+            {
+              printf ("ERROR!\n");
+              fflush (stdout);
+              pos = peers;
+              while (pos != NULL)
+                {
+                  GNUNET_REMOTE_kill_daemon (pos);
+                  pos = pos->next;
+                }
+              fprintf (stderr, "Peers' DV_DHTs failed to DV_DHT-connect!\n");
+              GNUNET_GC_free (cfg);
+              return -1;
+            }
+          GNUNET_hash (buf, strlen (buf), &key);
+          memset (value, 'A' + i, sizeof (value));
+          CHECK (GNUNET_OK == GNUNET_DV_DHT_put (peer_array[i]->config,
+                                              ectx,
+                                              &key,
+                                              
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+                                              sizeof (value), value));
+        }
+      printf ("\n");
+      /* get loop */
+      for (i = 0; i < NUM_PEERS; i++)
+        {
+          if (GNUNET_shutdown_test () == GNUNET_YES)
+            break;
+          GNUNET_snprintf (buf, sizeof (buf), "localhost:%u", 2087 + i * 10);
+
+          dctx = GNUNET_DV_DHT_context_create (peer_array[i]->config, ectx, 
&result_callback, &c);
+          printf ("Peer %d gets key", i);
+          fflush (stdout);
+          for (j = 0; j < NUM_PEERS; j++)
+            {
+              if (GNUNET_shutdown_test () == GNUNET_YES)
+                break;
+              c = 'A' + j;
+              GNUNET_snprintf (buf, sizeof (buf), "localhost:%u",
+                               2087 + j * 10);
+              GNUNET_hash (buf, strlen (buf), &key);
+              printf (" %d", j);
+              fflush (stdout);
+              last = found;
+              get1 = GNUNET_DV_DHT_get_start (dctx,
+                                           
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+                                           &key);
+              GNUNET_GE_ASSERT (NULL, get1 != NULL);
+              for (k = 0; k < NUM_ROUNDS; k++)
+                {
+                  if (GNUNET_shutdown_test () == GNUNET_YES)
+                    break;
+                  if (9 == (k % 10))
+                    {
+                      printf (".");
+                      fflush (stdout);
+                    }
+                  fflush (stdout);
+                  GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+                  if (last < found)
+                    break;
+                }
+              GNUNET_DV_DHT_get_stop (dctx, get1);
+              if (k == NUM_ROUNDS)
+                {
+                  printf ("?");
+                  fflush (stdout);
+                }
+            }
+          GNUNET_DV_DHT_context_destroy (dctx);
+          printf ("\n");
+        }
+    }
+  /* end of actual test code */
+  if (r == NUM_REPEAT)
+    printf ("Found %u out of %u attempts.\n", found,
+            NUM_PEERS * NUM_PEERS * r);
+  if (found < NUM_PEERS * NUM_PEERS * r / 2)
+    {
+      printf
+        ("Not enough results (not even 50%%), marking test as failed!\n");
+      ret = 1;
+    }
+FAILURE:
+  pos = peers;
+  while (pos != NULL)
+    {
+      GNUNET_REMOTE_kill_daemon (pos);
+      pos = pos->next;
+    }
+  GNUNET_GC_free (cfg);
+  return ret;
+}
+
+/* end of dv_dht_multipeer_test.c */

Added: GNUnet/src/applications/dv_dht/tools/dv_test.conf
===================================================================
--- GNUnet/src/applications/dv_dht/tools/dv_test.conf                           
(rev 0)
+++ GNUnet/src/applications/dv_dht/tools/dv_test.conf   2009-03-30 03:00:48 UTC 
(rev 8356)
@@ -0,0 +1,7 @@
+[MULTIPLE_SERVER_TESTING]
+CONTROL_HOST=127.0.0.0/8;
+HOSTNAMES=localhost
+STARTING_PORT=31387
+PORT_INCREMENT=2
+BASE_CONFIG=gnunetd_dv.conf
+TOPOLOGY=2

Added: GNUnet/src/applications/dv_dht/tools/gnunetd_dv.conf
===================================================================
--- GNUnet/src/applications/dv_dht/tools/gnunetd_dv.conf                        
        (rev 0)
+++ GNUnet/src/applications/dv_dht/tools/gnunetd_dv.conf        2009-03-30 
03:00:48 UTC (rev 8356)
@@ -0,0 +1,96 @@
+[Meta]
+ADVANCED = YES
+EXPERIMENTAL = YES
+
+[PATHS]
+GNUNETD_HOME =
+
+[GNUNETD]
+APPLICATIONS = advertising getoption stats tracekit dv_tbench dv dv_dht
+TRANSPORTS = udp tcp nat
+HOSTS = $GNUNETD_HOME/data/hosts/
+HTTP-PROXY = 
+FDLIMIT = 1024
+PIDFILE = $GNUNETD_HOME/pid/
+AUTOSTART = NO
+HELLOEXPIRES = 1440
+PRIVATE-NETWORK = NO
+LIMIT-ALLOW = 
+LIMIT-DENY = 
+KEEPLOG = 3
+LOGFILE = $GNUNETD_HOME/daemon-logs
+
+[MODULES]
+sqstore = sqstore_sqlite
+dstore = dstore_sqlite
+topology = topology_default
+
+[NETWORK]
+PORT = 2087
+TRUSTED = 127.0.0.0/8;
+DISABLE-ADVERTISEMENTS = NO
+HELLOEXCHANGE = YES
+DISABLE-AUTOCONNECT = NO
+INTERFACE = eth1
+
+[F2F]
+FRIENDS-ONLY = YES
+#MINIMUM = 0
+FRIENDS = $GNUNETD_HOME/friends
+
+[FS]
+DIR = $GNUNETD_HOME/data/fs
+INDEX-DIRECTORY = $GNUNETD_HOME/data/shared
+QUOTA = 1024
+ACTIVEMIGRATION = NO
+
+[TCPSERVER]
+DISABLE = NO
+
+[LOGGING]
+DEVELOPER = NO
+
+[LOAD]
+MAXNETDOWNBPSTOTAL = 50000
+MAXNETUPBPSTOTAL = 50000
+HARDUPLIMIT = 0
+MAXCPULOAD = 100
+MAXIOLOAD = 50
+HARDCPULIMIT = 0
+BASICLIMITING = YES
+INTERFACES = eth0
+
+[GNUNETD-EXPERIMENTAL]
+PADDING = NO
+
+[NAT]
+LIMITED = AUTO
+
+[TCP]
+PORT = 2086
+UPNP = YES
+BLACKLIST = 
+WHITELIST = 
+
+[UDP]
+PORT = 2086
+UPNP = YES
+MTU = 1472
+BLACKLIST = 
+WHITELIST = 
+
+[GAP]
+TABLESIZE = 65536
+
+[DHT]
+TABLESIZE = 1024
+
+[DSTORE]
+QUOTA = 1
+
+[MYSQL]
+CONFIG = /etc/my.cnf
+DATABASE = gnunet
+
+[TESTING]
+WEAKRANDOM = YES





reply via email to

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