gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r4847 - in GNUnet/src/applications/dht: module tools


From: gnunet
Subject: [GNUnet-SVN] r4847 - in GNUnet/src/applications/dht: module tools
Date: Mon, 28 May 2007 20:34:18 -0600 (MDT)

Author: grothoff
Date: 2007-05-28 20:34:18 -0600 (Mon, 28 May 2007)
New Revision: 4847

Added:
   GNUnet/src/applications/dht/tools/dhttest.c
Modified:
   GNUnet/src/applications/dht/module/cs.c
   GNUnet/src/applications/dht/tools/Makefile.am
   GNUnet/src/applications/dht/tools/dhttest2.c
Log:
fixing bugs, adding more extensive dht testcase

Modified: GNUnet/src/applications/dht/module/cs.c
===================================================================
--- GNUnet/src/applications/dht/module/cs.c     2007-05-29 02:06:26 UTC (rev 
4846)
+++ GNUnet/src/applications/dht/module/cs.c     2007-05-29 02:34:18 UTC (rev 
4847)
@@ -97,9 +97,9 @@
   return OK;
 }
 
- int get_result(const HashCode512 * key,
-                     const DataContainer * value,
-                     void * cls) {
+int get_result(const HashCode512 * key,
+              const DataContainer * value,
+              void * cls) {
   DHT_CLIENT_GET_RECORD * record = cls;
   CS_dht_request_put_MESSAGE * msg;
   size_t n;
@@ -143,8 +143,9 @@
 static void get_timeout(void * cls) {
   DHT_CLIENT_GET_RECORD * record = cls;
   int i;
+  int found;
 
-  dhtAPI->get_stop(record->get_record);
+  found = NO;
   MUTEX_LOCK(lock);
   for (i=getRecordsSize-1;i>=0;i--)
     if (getRecords[i] == record) {
@@ -152,10 +153,14 @@
       GROW(getRecords,
           getRecordsSize,
           getRecordsSize-1);
+      found = YES;
       break;
     }
   MUTEX_UNLOCK(lock);
-  FREE(record);
+  if (found == YES) {
+    dhtAPI->get_stop(record->get_record);
+    FREE(record);
+  }
 }
 
 /**
@@ -201,20 +206,23 @@
  * get_stop for all operations that rely on this client.
  */
 static void csClientExit(struct ClientHandle * client) {
-  unsigned int i;
+  int i;
   struct DHT_GET_RECORD * gr;
-
+  DHT_CLIENT_GET_RECORD * cgr;
   MUTEX_LOCK(lock);
   for (i=0;i<getRecordsSize;i++) {
-    if (getRecords[i]->client == client) {
-      gr = getRecords[i]->get_record;
+    cgr = getRecords[i]; 
+    if (cgr->client == client) {
+      gr = cgr->get_record;
       getRecords[i] = getRecords[getRecordsSize-1];
       GROW(getRecords,
           getRecordsSize,
           getRecordsSize-1);
       MUTEX_UNLOCK(lock);
       dhtAPI->get_stop(gr);
+      FREE(cgr);
       MUTEX_LOCK(lock);
+      i--;
     }
   }
   MUTEX_UNLOCK(lock);

Modified: GNUnet/src/applications/dht/tools/Makefile.am
===================================================================
--- GNUnet/src/applications/dht/tools/Makefile.am       2007-05-29 02:06:26 UTC 
(rev 4846)
+++ GNUnet/src/applications/dht/tools/Makefile.am       2007-05-29 02:34:18 UTC 
(rev 4847)
@@ -25,7 +25,8 @@
 
 
 check_PROGRAMS = \
-  dhttest2 
+  dhttest2 \
+  dhttest
 
 TESTS = $(check_PROGRAMS)
 
@@ -39,5 +40,15 @@
   $(top_builddir)/src/util/network_client/libgnunetutil_network_client.la \
   $(top_builddir)/src/util/libgnunetutil.la 
 
+dhttest_SOURCES = \
+  dhttest.c 
+dhttest_LDADD = \
+  $(top_builddir)/src/applications/stats/libgnunetstats_api.la \
+  $(top_builddir)/src/applications/testing/libgnunettesting_api.la \
+  $(top_builddir)/src/applications/dht/tools/libgnunetdht_api.la \
+  $(top_builddir)/src/util/config_impl/libgnunetutil_config.la \
+  $(top_builddir)/src/util/network_client/libgnunetutil_network_client.la \
+  $(top_builddir)/src/util/libgnunetutil.la 
+
 EXTRA_DIST = \
   check.conf 

Added: GNUnet/src/applications/dht/tools/dhttest.c
===================================================================
--- GNUnet/src/applications/dht/tools/dhttest.c                         (rev 0)
+++ GNUnet/src/applications/dht/tools/dhttest.c 2007-05-29 02:34:18 UTC (rev 
4847)
@@ -0,0 +1,204 @@
+/*
+     This file is part of GNUnet.
+     (C) 2005, 2006, 2007 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/dhttest.c
+ * @brief DHT testcase
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_protocols.h"
+#include "gnunet_dht_lib.h"
+#include "gnunet_testing_lib.h"
+#include "gnunet_stats_lib.h"
+#include "gnunet_util_config_impl.h"
+#include "gnunet_util_network_client.h"
+#include "gnunet_util_cron.h"
+
+#define NUM_PEERS 12
+
+#define NUM_ROUNDS 4
+
+static int ok;
+
+static int waitForConnect(const char * name,
+                         unsigned long long value,
+                         void * cls) {
+  if ( (value > 0) &&
+       (0 == strcmp(_("# dht connections"),
+                   name)) ) {
+    ok = 1;
+    return SYSERR;
+  }
+  return OK;
+}
+
+#define CHECK(a) do { if (!(a)) { ret = 1; GE_BREAK(ectx, 0); goto FAILURE; } 
} while(0)
+
+/**
+ * Testcase to test gap routing (2 peers only).
+ * @return 0: ok, -1: error
+ */
+int main(int argc,
+        const char ** argv) {
+  struct DaemonContext * peers;
+  int ret = 0;
+  HashCode512 key;
+  DataContainer * value;
+  struct GE_Context * ectx;
+  struct GC_Configuration * cfg;
+  struct ClientServerConnection * sock;
+  int left;
+  int i;
+  int j;
+  int k;
+  int found;
+  char buf[128];
+ 
+  ectx = NULL;
+  cfg = GC_create_C_impl();
+  if (-1 == GC_parse_configuration(cfg,
+                                  "check.conf")) {
+    GC_free(cfg);
+    return -1;
+  }
+  peers = gnunet_testing_start_daemons("tcp",
+                                      "advertising dht stats",
+                                      "/tmp/gnunet-dht-test",
+                                      2087,
+                                      10,
+                                      NUM_PEERS);
+  if (peers == NULL) {
+    GC_free(cfg);
+    return -1;
+  }
+  for (i=0;i<NUM_PEERS;i++) {
+    for (j=0;j<i;j++) {
+      if (OK != gnunet_testing_connect_daemons(2087 + 10*i,
+                                              2087 + 10*j)) {
+       gnunet_testing_stop_daemons(peers);
+       fprintf(stderr,
+               "Failed to connect the peers!\n");
+       GC_free(cfg);
+       return -1;
+      }
+    }
+  }
+
+  /* wait for some DHT's to find each other! */
+  sock = client_connection_create(NULL,
+                                 cfg);
+  left = 30; /* how many iterations should we wait? */
+  while (OK == STATS_getStatistics(NULL,
+                                  sock,
+                                  &waitForConnect,
+                                  NULL)) {
+    printf("Waiting for peers to DHT-connect (%u iterations left)...\n",
+          left);
+    sleep(5);
+    left--;
+    if (left == 0) 
+      break;    
+  }
+  connection_destroy(sock);
+  if (ok == 0) {
+    gnunet_testing_stop_daemons(peers);
+    fprintf(stderr,
+           "Peers' DHTs failed to DHT-connect!\n");
+    GC_free(cfg);
+    return -1;
+  }
+
+  /* put loop */
+  for (i=0;i<NUM_PEERS;i++) {
+    SNPRINTF(buf,
+            128,
+            "localhost:%u",
+            2087 + i * 10);
+    GC_set_configuration_value_string(cfg,
+                                     ectx,
+                                     "NETWORK",
+                                     "HOST",
+                                     buf);
+    hash(buf, 4, &key);
+    value = MALLOC(8);
+    value->size = ntohl(8);
+    memset(&value[1],
+          'A' + i,
+          4);
+    CHECK(OK == DHT_LIB_put(cfg,
+                           ectx,
+                           &key,
+                           DHT_STRING2STRING_BLOCK,
+                           get_time() + 15 * cronMINUTES,
+                           value));
+  }
+
+  /* get loops */
+  for (k=0;k<NUM_ROUNDS;k++) {
+    found = 0;
+    for (i=0;i<NUM_PEERS;i++) {
+      SNPRINTF(buf,
+              128,
+              "localhost:%u",
+              2087 + i * 10);
+      GC_set_configuration_value_string(cfg,
+                                       ectx,
+                                       "NETWORK",
+                                       "HOST",
+                                       buf);
+      for (j=0;j<NUM_PEERS;j++) {
+       SNPRINTF(buf,
+                128,
+                "localhost:%u",
+                2087 + j * 10);
+       hash(buf, 4, &key);
+       fprintf(stderr,
+               "Peer %d gets key %d", i, j);
+       if (0 < DHT_LIB_get(cfg,
+                           ectx,
+                           DHT_STRING2STRING_BLOCK,
+                            &key,
+                           5 * cronSECONDS,
+                           NULL,
+                           NULL)) {
+         fprintf(stderr,
+                 " - found!\n");
+         found++;
+       } else
+         fprintf(stderr,
+                 " - NOT found!\n");
+      }
+    }
+    /* end of actual test code */
+    fprintf(stderr,
+           "Found %u out of %u attempts in round %u.\n",
+           found, 
+           NUM_PEERS * NUM_PEERS,
+           k);
+  }
+ FAILURE:
+  gnunet_testing_stop_daemons(peers);
+  GC_free(cfg);
+  return ret;
+}
+
+/* end of dhttest.c */


Property changes on: GNUnet/src/applications/dht/tools/dhttest.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: GNUnet/src/applications/dht/tools/dhttest2.c
===================================================================
--- GNUnet/src/applications/dht/tools/dhttest2.c        2007-05-29 02:06:26 UTC 
(rev 4846)
+++ GNUnet/src/applications/dht/tools/dhttest2.c        2007-05-29 02:34:18 UTC 
(rev 4847)
@@ -19,7 +19,7 @@
 */
 
 /**
- * @file applications/dht/tools/dhttest.c
+ * @file applications/dht/tools/dhttest2.c
  * @brief DHT testcase
  * @author Christian Grothoff
  */





reply via email to

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