gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r8636 - in GNUnet/src/applications/dv_dht: module tools
Date: Tue, 7 Jul 2009 16:39:13 -0600

Author: nevans
Date: 2009-07-07 16:39:13 -0600 (Tue, 07 Jul 2009)
New Revision: 8636

Added:
   GNUnet/src/applications/dv_dht/tools/dv_dht_driver_new.c
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
   GNUnet/src/applications/dv_dht/tools/dv_dht_driver.c
Log:


Modified: GNUnet/src/applications/dv_dht/module/routing.c
===================================================================
--- GNUnet/src/applications/dv_dht/module/routing.c     2009-07-07 20:42:45 UTC 
(rev 8635)
+++ GNUnet/src/applications/dv_dht/module/routing.c     2009-07-07 22:39:13 UTC 
(rev 8636)
@@ -342,6 +342,8 @@
 #if DEBUG_ROUTING
   GNUNET_EncName enc;
   unsigned long long queryuid;
+  unsigned long long *dhtqueryuid_ptr = NULL;
+  unsigned long long dhtqueryuid;
 #endif
 
 #if DEBUG_ROUTING
@@ -359,8 +361,29 @@
       result->hop_count = htonl (ntohl (result->hop_count) + 1);
 #endif
     }
-  else
+  if ((cls == NULL) || (ntohs (result->header.type) != 
GNUNET_P2P_PROTO_DHT_RESULT))
     {
+#if DEBUG_ROUTING
+
+      if ((cls != NULL) && (ntohs (result->header.type) != 
GNUNET_P2P_PROTO_DHT_RESULT))
+      {
+        dhtqueryuid_ptr = cls;
+        dhtqueryuid = *dhtqueryuid_ptr;
+        GNUNET_GE_LOG (coreAPI->ectx,
+               GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
+               GNUNET_GE_BULK,
+               _("cls not null and type is wrong! Got dhtqueryuid of %llu"), 
dhtqueryuid);
+        GNUNET_GE_LOG (coreAPI->ectx,
+               GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
+               GNUNET_GE_BULK,
+               _("got header type of %d or %d, wanted %d"), ntohs 
(result->header.type), result->header.type, GNUNET_P2P_PROTO_DHT_RESULT);
+
+      }
+      else
+      {
+        dhtqueryuid = 0;
+      }
+#endif
       result = GNUNET_malloc (sizeof (DV_DHT_MESSAGE) + size);
       result->header.size = htons (sizeof (DV_DHT_MESSAGE) + size);
       result->header.type = htons (GNUNET_P2P_PROTO_DHT_RESULT);
@@ -371,12 +394,15 @@
       result->key = *key;
       if ((debug_routes) && (dhtlog != NULL))
         {
-          dhtlog->insert_query (&queryuid, 0, DHTLOG_RESULT,
+          dhtlog->insert_query (&queryuid, dhtqueryuid, DHTLOG_RESULT,
                                 ntohl (result->hop_count), GNUNET_NO,
                                 coreAPI->my_identity, key);
         }
 #if DEBUG_ROUTING
-      result->queryuid = htonl (queryuid);
+      if (dhtqueryuid != 0)
+        result->queryuid = htonl (dhtqueryuid);
+      else
+        result->queryuid = htonl (queryuid);
 #endif
       memcpy (&result[1], data, size);
     }
@@ -645,7 +671,7 @@
                      GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
                      GNUNET_GE_BULK,
                      "Failed to add entry in routing table for request.\n");
-      fprintf (stderr, "Failed to add entry in routing table for request.\n");
+
       if ((debug_routes) && (dhtlog != NULL))
         {
           hop_count = ntohl (get->hop_count);
@@ -657,7 +683,14 @@
 #endif
       return GNUNET_OK;         /* could not route */
     }
+
+#if DEBUG_ROUTING
+  queryuid = ntohl (get->queryuid);
+  total = dstore->get (&get->key, ntohl (get->type), &route_result, (void 
*)&queryuid);
+#else
   total = dstore->get (&get->key, ntohl (get->type), &route_result, NULL);
+#endif
+
   if (total > MAX_RESULTS)
     {
 #if DEBUG_ROUTING

Modified: GNUnet/src/applications/dv_dht/module/table.c
===================================================================
--- GNUnet/src/applications/dv_dht/module/table.c       2009-07-07 20:42:45 UTC 
(rev 8635)
+++ GNUnet/src/applications/dv_dht/module/table.c       2009-07-07 22:39:13 UTC 
(rev 8636)
@@ -611,7 +611,7 @@
                      GNUNET_GE_BULK,
                      "closest peer inverse distance is %u, mine is %u\n",
                      inverse_distance(target, &closest.hashPubKey), 
inverse_distance(target, &coreAPI->my_identity->hashPubKey));
-  if (inverse_distance(target, &coreAPI->my_identity->hashPubKey) > 
inverse_distance(target, &closest.hashPubKey))
+  if (inverse_distance(target, &coreAPI->my_identity->hashPubKey) >= 
inverse_distance(target, &closest.hashPubKey))
   {
     return GNUNET_YES;
   }

Modified: GNUnet/src/applications/dv_dht/tools/Makefile.am
===================================================================
--- GNUnet/src/applications/dv_dht/tools/Makefile.am    2009-07-07 20:42:45 UTC 
(rev 8635)
+++ GNUnet/src/applications/dv_dht/tools/Makefile.am    2009-07-07 22:39:13 UTC 
(rev 8636)
@@ -27,7 +27,8 @@
   $(GN_LIBINTL)
 
 bin_PROGRAMS = \
-  dv_dht_driver
+  dv_dht_driver \
+  dv_dht_driver_new
 
 
 dv_dht_driver_SOURCES = \
@@ -39,6 +40,15 @@
   $(top_builddir)/src/applications/dv_dht/tools/libgnunetdvdhtapi.la \
   $(top_builddir)/src/util/libgnunetutil.la
 
+dv_dht_driver_new_SOURCES = \
+  dv_dht_driver_new.c
+dv_dht_driver_new_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
+
 check_PROGRAMS = \
   dv_dht_loopback_test \
   dv_dht_twopeer_test \

Modified: GNUnet/src/applications/dv_dht/tools/dv_dht_driver.c
===================================================================
--- GNUnet/src/applications/dv_dht/tools/dv_dht_driver.c        2009-07-07 
20:42:45 UTC (rev 8635)
+++ GNUnet/src/applications/dv_dht/tools/dv_dht_driver.c        2009-07-07 
22:39:13 UTC (rev 8636)
@@ -156,7 +156,7 @@
 #define CHECK(a) do { if (!(a)) { ret = 1; GNUNET_GE_BREAK(ectx, 0); goto 
FAILURE; } } while(0)
 
 int
-new_do_testing (int argc, char *const *argv)
+do_testing (int argc, char *const *argv)
 {
   struct GNUNET_REMOTE_TESTING_DaemonContext *peers;
   struct GNUNET_REMOTE_TESTING_DaemonContext *peer_array[num_peers];
@@ -186,7 +186,7 @@
     }
   else
     {
-      ret = sqlapi->insert_trial (&trialuid, num_peers, topology);
+      ret = sqlapi->insert_trial (&trialuid, num_peers, topology, put_items, 
get_requests, 1);
     }
 
   if (ret != GNUNET_OK)
@@ -329,300 +329,6 @@
   return ret;
 }
 
-#if 0
-
-
-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;
-}
-
-int
-do_testing (int argc, char *const *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;
-
-  struct GNUNET_ClientServerConnection *sock;
-  struct GNUNET_DV_DHT_keys *keys = NULL;
-  struct GNUNET_DV_DHT_keys *key_pos;
-  struct GNUNET_DV_DHT_keys *temp_key_pos;
-  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 l;
-  int last;
-  int key_count;
-  unsigned long long trialuid;
-
-  key_count = 0;
-  if (sqlapi == NULL)
-    {
-      return GNUNET_SYSERR;
-    }
-  else
-    {
-      ret = sqlapi->insert_trial (&trialuid, num_peers, topology);
-    }
-
-  if (ret != GNUNET_OK)
-    return GNUNET_SYSERR;
-  printf ("Starting %u peers for trial %llu...\n", (unsigned int) num_peers, 
trialuid);
-  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;
-    }
-
-  for (i = 0; i < num_peers; i++)
-  {
-    for (r = 0; r < num_peers; r++)
-    {
-      key_pos = GNUNET_malloc(sizeof(struct GNUNET_DV_DHT_keys));
-      for (l = 0; l < 8; l++)
-      {
-        key_pos->data[l] = rand();
-      }
-      GNUNET_hash (key_pos->data, 8, &key_pos->key);
-      if (keys == NULL)
-      {
-        keys = key_pos;
-        key_pos->next = NULL;
-      }
-      else
-      {
-        key_pos->next = keys;
-        keys = key_pos;
-      }
-    }
-  }
-  sleep (30);
-  found = 0;
-  for (r = 0; r < settle_time; r++)
-    {
-      fprintf (stderr, "After %d minutes\n", r);
-      for (i = 0; i < num_peers; i++)
-        {
-          if (GNUNET_shutdown_test () == GNUNET_YES)
-            break;
-          fprintf (stderr, "Peer %d: ", i);
-          sock =
-            GNUNET_client_connection_create (NULL, peer_array[i]->config);
-          GNUNET_STATS_get_statistics (NULL, sock, &getPeers, NULL);
-          GNUNET_thread_sleep (2 * GNUNET_CRON_SECONDS);
-          GNUNET_client_connection_destroy (sock);
-
-        }
-      if (GNUNET_shutdown_test () == GNUNET_YES)
-        break;
-      sleep (60);
-    }
-
-
-  for (i = 0; i < num_peers; i++)
-  {
-    if (GNUNET_shutdown_test () == GNUNET_YES)
-      break;
-    fprintf (stderr, "Peer %d: ", i);
-    sock =
-      GNUNET_client_connection_create (NULL, peer_array[i]->config);
-    GNUNET_STATS_get_statistics (NULL, sock, &getPeers, NULL);
-    GNUNET_thread_sleep (2 * GNUNET_CRON_SECONDS);
-    GNUNET_client_connection_destroy (sock);
-  }
-      if (GNUNET_shutdown_test () != GNUNET_YES)
-      {
-      /* put loop */
-      printf ("Waiting for DV_DHT connections of peer");
-      key_pos = keys;
-      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));
-
-          memset (value, 'A' + i, sizeof (value));*/
-          for (j = 0; j < num_peers; j++)
-          {
-            fprintf(stdout, "Inserting key %d at peer %d\n", key_count, i);
-            CHECK (GNUNET_OK == GNUNET_DV_DHT_put (peer_array[i]->config,
-                                                 ectx,
-                                                 &key_pos->key,
-                                                 
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
-                                                 sizeof (key_pos->data), 
key_pos->data));
-            if (key_pos->next != NULL)
-            {
-              key_pos = key_pos->next;
-              key_count++;
-            }
-            else
-            {
-              key_pos = keys;
-              key_count = 0;
-            }
-          }
-        }
-      printf ("\n");
-      /* get loop */
-      key_pos = keys;
-      key_count = 0;
-      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, keys);
-          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", key_count);
-              fflush (stdout);
-              last = found;
-              get1 = GNUNET_DV_DHT_get_start (dctx,
-                                              
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
-                                              &key_pos->key); /* Used to be 
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);
-                }
-
-              if (key_pos->next != NULL)
-              {
-                key_pos = key_pos->next;
-                key_count++;
-              }
-              else
-              {
-                key_pos = keys;
-                key_count = 0;
-              }
-            }
-          GNUNET_DV_DHT_context_destroy (dctx);
-          printf ("\n");
-          printf ("Found %u out of %llu attempts.\n", new_found,
-            num_peers);
-          new_found = 0;
-        }
-  /* end of actual test code */
-  if (r == num_repeat)
-    printf ("Found %u out of %llu 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;
-    }
-FAILURE2:
-  pos = peers;
-  while (pos != NULL)
-    {
-      GNUNET_REMOTE_kill_daemon (pos);
-      pos = pos->next;
-    }
-  ret = sqlapi->update_trial (trialuid);
-  key_pos = keys;
-  while(key_pos != NULL)
-  {
-    temp_key_pos = key_pos->next;
-    GNUNET_free(key_pos);
-    key_pos = temp_key_pos;
-  }
-  return ret;
-}
-#endif
-
 /**
  * Driver for testing DV_DHT routing (many peers).
  * @return 0: ok, -1: error
@@ -720,7 +426,7 @@
     }
   else
     {
-      ret = new_do_testing (argc, argv);
+      ret = do_testing (argc, argv);
     }
   done =
     GNUNET_plugin_resolve_function (plugin, "release_module_", GNUNET_YES);

Added: GNUnet/src/applications/dv_dht/tools/dv_dht_driver_new.c
===================================================================
--- GNUnet/src/applications/dv_dht/tools/dv_dht_driver_new.c                    
        (rev 0)
+++ GNUnet/src/applications/dv_dht/tools/dv_dht_driver_new.c    2009-07-07 
22:39:13 UTC (rev 8636)
@@ -0,0 +1,426 @@
+/*
+     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/dv_dht/tools/dv_dht_driver.c
+ * @brief DV_DHT Driver for testing DHT
+ * @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"
+#include "gnunet_dhtlog_service.h"
+
+
+struct GNUNET_DV_DHT_keys
+{
+  char data[8];
+  GNUNET_HashCode key;
+};
+
+static char *configFile = "dv_test.conf";
+static GNUNET_CoreAPIForPlugins capi;
+static struct GNUNET_GE_Context *ectx;
+static struct GNUNET_GC_Configuration *cfg;
+static GNUNET_ServicePluginInitializationMethod init;
+static GNUNET_ServicePluginShutdownMethod done;
+static GNUNET_dhtlog_ServiceAPI *sqlapi;
+static struct GNUNET_Mutex *lock;
+
+static unsigned long long topology;
+static unsigned long long num_peers;
+static unsigned long long num_repeat;
+static unsigned long long num_rounds;
+static unsigned long long settle_time;
+static unsigned long long put_items;
+static unsigned long long get_requests;
+static unsigned long long concurrent_requests;
+static unsigned long long requests_per_second;
+static unsigned long long requests_wait_time;
+
+static char *dotOutFileName = NULL;
+
+static struct GNUNET_CommandLineOption gnunetDHTDriverOptions[] = {
+  GNUNET_COMMAND_LINE_OPTION_CFG_FILE (&configFile),    /* -c */
+  GNUNET_COMMAND_LINE_OPTION_HELP (gettext_noop ("Run tests on DHT")),  /* -h 
*/
+  GNUNET_COMMAND_LINE_OPTION_VERSION (PACKAGE_VERSION), /* -v */
+  {'O', "output", "DOT_OUTPUT",
+   gettext_noop
+   ("set output file for a dot input file which represents the graph of the 
connected nodes"),
+   1, &GNUNET_getopt_configure_set_string, &dotOutFileName},
+  GNUNET_COMMAND_LINE_OPTION_VERBOSE,
+  GNUNET_COMMAND_LINE_OPTION_END,
+};
+
+/**
+ * How many peers should the testcase run (default)?
+ */
+#define DEFAULT_NUM_PEERS 15
+
+/**
+ * How many times will we try the DV_DHT-GET operation before
+ * giving up for good (default)?
+ */
+#define DEFAULT_NUM_ROUNDS 200
+
+/**
+ * How often do we iterate the put-get loop (default)?
+ */
+#define DEFAULT_NUM_REPEAT 5
+
+static int ok;
+static int found;
+static int new_found;
+
+static void *
+rs (const char *name)
+{
+  return NULL;
+}
+
+static int
+rsx (void *s)
+{
+  return GNUNET_OK;
+}
+
+static int
+result_callback (const GNUNET_HashCode * key,
+                 unsigned int type,
+                 unsigned int size, const char *data, void *cls)
+{
+  struct GNUNET_DV_DHT_keys *key_data = cls;
+#if 0
+  fprintf (stderr, "Got %u %u `%.*s' (want `%.*s')\n", type, size, size, data,
+           sizeof (expect), expect);
+
+  if ((8 != size) ||
+      (0 != memcmp (key_data->data, data, size)) ||
+      (type != GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING))
+    return GNUNET_SYSERR;
+#endif
+  if ((8 != size) ||
+      (0 != memcmp (key_data->data, data, size)) ||
+      (type != GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING))
+    return GNUNET_SYSERR;
+  else
+  {
+    GNUNET_mutex_lock(lock);
+    found++;
+    new_found++;
+    GNUNET_mutex_unlock(lock);
+    return GNUNET_OK;
+  }
+}
+
+static int
+getPeers (const char *name, unsigned long long value, void *cls)
+{
+  if ((value > 0) && (strstr (name, _("# dv")) != NULL))
+    {
+      fprintf (stderr, "%s : %llu\n", name, value);
+    }
+
+  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)
+
+int
+new_do_testing (int argc, char *const *argv)
+{
+  struct GNUNET_REMOTE_TESTING_DaemonContext *peers;
+  struct GNUNET_REMOTE_TESTING_DaemonContext *peer_array[num_peers];
+  struct GNUNET_DV_DHT_Context *dctx[concurrent_requests];
+  struct GNUNET_DV_DHT_GetRequest *gets[concurrent_requests];
+  struct GNUNET_DV_DHT_keys keys[put_items];
+  struct GNUNET_REMOTE_TESTING_DaemonContext *pos;
+  int ret = 0;
+
+  struct GNUNET_ClientServerConnection *sock;
+
+  int i;
+  int k;
+  int r;
+  int l;
+  int j;
+
+  int key_count;
+
+  int random_peers[concurrent_requests];
+  int random_peer;
+  int random_key;
+  unsigned long long trialuid;
+
+  key_count = 0;
+  if (sqlapi == NULL)
+    {
+      return GNUNET_SYSERR;
+    }
+  else
+    {
+      ret = sqlapi->insert_trial (&trialuid, num_peers, topology, put_items, 
get_requests, concurrent_requests);
+    }
+
+  if (ret != GNUNET_OK)
+    return GNUNET_SYSERR;
+  printf ("Starting %u peers for trial %llu...\n", (unsigned int) num_peers, 
trialuid);
+  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;
+  }
+
+  for (i = 0; i < put_items; i++)
+  {
+    for (l = 0; l < 8; l++)
+    {
+      keys[i].data[l] = rand();
+    }
+    GNUNET_hash (keys[i].data, 8, &keys[i].key);
+  }
+  sleep (30);
+  found = 0;
+
+  for (r = 0; r < settle_time; r++)
+  {
+    fprintf (stderr, "After %d minutes\n", r);
+    for (i = 0; i < num_peers; i++)
+    {
+      if (GNUNET_shutdown_test () == GNUNET_YES)
+        break;
+      fprintf (stderr, "Peer %d: ", i);
+      sock =
+        GNUNET_client_connection_create (NULL, peer_array[i]->config);
+      GNUNET_STATS_get_statistics (NULL, sock, &getPeers, NULL);
+      GNUNET_thread_sleep (2 * GNUNET_CRON_SECONDS);
+      GNUNET_client_connection_destroy (sock);
+    }
+    if (GNUNET_shutdown_test () == GNUNET_YES)
+      break;
+    sleep (60);
+  }
+
+  for (i = 0; i < put_items; i++)
+  {
+    random_peer = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, num_peers);
+    //random_key = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, put_items);
+    fprintf(stdout, "Inserting key %d at peer %d\n", i, random_peer);
+    CHECK (GNUNET_OK == GNUNET_DV_DHT_put (peer_array[random_peer]->config,
+                                         ectx,
+                                         &keys[i].key,
+                                         
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+                                         sizeof (keys[i].data), keys[i].data));
+    GNUNET_thread_sleep (100 * GNUNET_CRON_MILLISECONDS);
+  }
+  fprintf(stdout, "Inserted %llu items\n", put_items);
+
+  for (i = 0; i < get_requests / concurrent_requests; i ++)
+  {
+    new_found = 0;
+    for (j = 0; j < concurrent_requests; j++)
+    {
+      random_peers[j] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 
num_peers);
+      random_key = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, put_items);
+      /*random_key = (i + 1) * (j + 1) - 1;*/
+      dctx[j] = GNUNET_DV_DHT_context_create 
(peer_array[random_peers[j]]->config, ectx,
+                                         &result_callback, &keys[random_key]);
+      fprintf(stdout, "Searching for key %d from peer %d\n", random_key, 
random_peers[j]);
+      gets[j] = GNUNET_DV_DHT_get_start (dctx[j],
+                                        
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+                                        &keys[random_key].key);
+      GNUNET_GE_ASSERT (NULL, gets[j] != NULL);
+    }
+
+    for (k = 0; k < DEFAULT_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);
+    }
+
+    for (j = 0; j < concurrent_requests; j++)
+    {
+      GNUNET_DV_DHT_get_stop (dctx[j], gets[j]);
+      GNUNET_DV_DHT_context_destroy(dctx[j]);
+    }
+    printf ("Found %u out of %llu attempts.\n", new_found,
+            concurrent_requests);
+
+  }
+  printf ("Found %u out of %llu attempts.\n", found,
+            get_requests);
+
+FAILURE:
+  pos = peers;
+  while (pos != NULL)
+    {
+      GNUNET_REMOTE_kill_daemon (pos);
+      pos = pos->next;
+    }
+
+  ret = sqlapi->update_trial (trialuid);
+  return ret;
+}
+
+
+/**
+ * Driver for testing DV_DHT routing (many peers).
+ * @return 0: ok, -1: error
+ */
+int
+main (int argc, char *const *argv)
+{
+  int ret = 0;
+  struct GNUNET_PluginHandle *plugin;
+  struct GNUNET_GC_Configuration *driverConfig;
+
+  ectx = NULL;
+  cfg = GNUNET_GC_create ();
+  lock = GNUNET_mutex_create(GNUNET_YES);
+  ret =
+    GNUNET_init (argc, argv, "dvdhtdriver", &configFile,
+                 gnunetDHTDriverOptions, &ectx, &driverConfig);
+
+  if (ret == -1)
+    {
+      GNUNET_fini (ectx, cfg);
+      return -1;
+    }
+
+  if (-1 == GNUNET_GC_parse_configuration (cfg, configFile))
+    {
+      GNUNET_GC_free (cfg);
+      return -1;
+    }
+  if (dotOutFileName != NULL)
+    {
+      GNUNET_GC_set_configuration_value_string (cfg, NULL,
+                                                "MULTIPLE_SERVER_TESTING",
+                                                "DOT_OUTPUT", dotOutFileName);
+    }
+
+  GNUNET_GC_get_configuration_value_number (cfg,
+                                            "MULTIPLE_SERVER_TESTING",
+                                            "TOPOLOGY", 0, -1, 0, &topology);
+
+  GNUNET_GC_get_configuration_value_number (cfg,
+                                            "MULTIPLE_SERVER_TESTING",
+                                            "NUM_PEERS",
+                                            1,
+                                            -1,
+                                            DEFAULT_NUM_PEERS, &num_peers);
+
+  GNUNET_GC_get_configuration_value_number (cfg,
+                                            "MULTIPLE_SERVER_TESTING",
+                                            "SETTLE_TIME",
+                                            0,
+                                            -1,
+                                            0, &settle_time);
+
+  GNUNET_GC_get_configuration_value_number (cfg,
+                                            "MULTIPLE_SERVER_TESTING",
+                                            "CONCURRENT_REQUESTS",
+                                            1,
+                                            -1,
+                                            5, &concurrent_requests);
+
+  GNUNET_GC_get_configuration_value_number (cfg,
+                                            "MULTIPLE_SERVER_TESTING",
+                                            "PUT_ITEMS",
+                                            1,
+                                            -1,
+                                            100, &put_items);
+
+  GNUNET_GC_get_configuration_value_number (cfg,
+                                            "MULTIPLE_SERVER_TESTING",
+                                            "GET_REQUESTS",
+                                            1,
+                                            -1,
+                                            100, &get_requests);
+
+  GNUNET_GC_get_configuration_value_number (cfg,
+                                            "MULTIPLE_SERVER_TESTING",
+                                            "NUM_ROUNDS",
+                                            1,
+                                            -1,
+                                            DEFAULT_NUM_ROUNDS, &num_rounds);
+
+  GNUNET_GC_get_configuration_value_number (cfg,
+                                            "MULTIPLE_SERVER_TESTING",
+                                            "NUM_REPEAT",
+                                            1,
+                                            -1,
+                                            DEFAULT_NUM_REPEAT, &num_repeat);
+
+  memset (&capi, 0, sizeof (GNUNET_CoreAPIForPlugins));
+  capi.cfg = cfg;
+  capi.service_request = &rs;
+  capi.service_release = &rsx;
+
+  plugin = GNUNET_plugin_load (NULL, "libgnunetmodule_", "dhtlog_mysql");
+  init =
+    GNUNET_plugin_resolve_function (plugin, "provide_module_", GNUNET_YES);
+  sqlapi = init (&capi);
+  if (sqlapi == NULL)
+    {
+      ret = GNUNET_SYSERR;
+    }
+  else
+    {
+      ret = new_do_testing (argc, argv);
+    }
+  done =
+    GNUNET_plugin_resolve_function (plugin, "release_module_", GNUNET_YES);
+  if (done != NULL)
+    done ();
+
+  fprintf(stdout, "# Inserts: %llu\n# Gets: %llu\nSettle time: %llu\n# Nodes: 
%llu\n# Concurrent: %llu\n# Wait time: %d\n# Successful: %d\n",
+          put_items, get_requests, settle_time, num_peers, 
concurrent_requests, DEFAULT_NUM_ROUNDS, found);
+  GNUNET_plugin_unload (plugin);
+  GNUNET_mutex_destroy(lock);
+  return ret;
+}
+
+/* end of dv_dht_driver.c */





reply via email to

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