gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r8005 - in GNUnet/src/applications/dht: module tools
Date: Sun, 14 Dec 2008 12:56:24 -0700 (MST)

Author: grothoff
Date: 2008-12-14 12:56:24 -0700 (Sun, 14 Dec 2008)
New Revision: 8005

Added:
   GNUnet/src/applications/dht/tools/dht_expiration_test.c
Modified:
   GNUnet/src/applications/dht/module/routing.c
   GNUnet/src/applications/dht/tools/Makefile.am
Log:
expriation test

Modified: GNUnet/src/applications/dht/module/routing.c
===================================================================
--- GNUnet/src/applications/dht/module/routing.c        2008-12-14 19:55:50 UTC 
(rev 8004)
+++ GNUnet/src/applications/dht/module/routing.c        2008-12-14 19:56:24 UTC 
(rev 8005)
@@ -77,7 +77,8 @@
 /**
  * How long do we keep content after receiving a PUT request for it?
  */
-#define CONTENT_LIFETIME (12 * GNUNET_CRON_HOURS)
+#define CONTENT_LIFETIME (5 * GNUNET_CRON_SECONDS)
+// (12 * GNUNET_CRON_HOURS)
 
 /**
  * @brief record used for sending response back
@@ -248,7 +249,7 @@
  * where to send it next.
  */
 static int
-routeResult (const GNUNET_HashCode * key,
+route_result (const GNUNET_HashCode * key,
              unsigned int type,
              unsigned int size, const char *data, void *cls)
 {
@@ -396,7 +397,7 @@
  * @return GNUNET_OK if route was added, GNUNET_SYSERR if not
  */
 static int
-addRoute (const GNUNET_PeerIdentity * sender,
+add_route (const GNUNET_PeerIdentity * sender,
           GNUNET_ResultProcessor handler, void *cls, const DHT_MESSAGE * get)
 {
   DHTQueryRecord *q;
@@ -482,7 +483,7 @@
  * Handle GET message.
  */
 static int
-handleGet (const GNUNET_PeerIdentity * sender,
+handle_get (const GNUNET_PeerIdentity * sender,
            const GNUNET_MessageHeader * msg)
 {
   GNUNET_PeerIdentity next[GET_TRIES + 1];
@@ -515,7 +516,7 @@
 #endif
   if (stats != NULL)
     stats->change (stat_get_requests_received, 1);
-  if ((sender != NULL) && (GNUNET_OK != addRoute (sender, NULL, NULL, get)))
+  if ((sender != NULL) && (GNUNET_OK != add_route (sender, NULL, NULL, get)))
     {
 #if DEBUG_ROUTING
       GNUNET_GE_LOG (coreAPI->ectx,
@@ -525,7 +526,7 @@
 #endif
       return GNUNET_OK;         /* could not route */
     }
-  total = dstore->get (&get->key, ntohl (get->type), &routeResult, NULL);
+  total = dstore->get (&get->key, ntohl (get->type), &route_result, NULL);
   if (total > MAX_RESULTS)
     {
 #if DEBUG_ROUTING
@@ -581,7 +582,7 @@
  * Handle PUT message.
  */
 static int
-handlePut (const GNUNET_PeerIdentity * sender,
+handle_put (const GNUNET_PeerIdentity * sender,
            const GNUNET_MessageHeader * msg)
 {
   GNUNET_PeerIdentity next[PUT_TRIES + 1];
@@ -691,7 +692,7 @@
  * Handle RESULT message.
  */
 static int
-handleResult (const GNUNET_PeerIdentity * sender,
+handle_result (const GNUNET_PeerIdentity * sender,
               const GNUNET_MessageHeader * msg)
 {
   const DHT_MESSAGE *result;
@@ -713,7 +714,7 @@
                  GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_DEVELOPER,
                  "Received REMOTE DHT RESULT for key `%s'.\n", &enc);
 #endif
-  routeResult (&result->key,
+  route_result (&result->key,
                ntohl (result->type),
                ntohs (result->header.size) - sizeof (DHT_MESSAGE),
                (const char *) &result[1], (void *) msg);
@@ -746,9 +747,9 @@
                  "Initiating DHT GET (based on local request) for key `%s'.\n",
                  &enc);
 #endif
-  if (GNUNET_OK != addRoute (NULL, handler, cls, &get))
+  if (GNUNET_OK != add_route (NULL, handler, cls, &get))
     return GNUNET_SYSERR;
-  handleGet (NULL, &get.header);
+  handle_get (NULL, &get.header);
   return GNUNET_OK;
 }
 
@@ -827,7 +828,7 @@
   put->hop_count = htonl (0);
   put->network_size = htonl (GNUNET_DHT_estimate_network_diameter ());
   memcpy (&put[1], data, size);
-  handlePut (NULL, &put->header);
+  handle_put (NULL, &put->header);
   GNUNET_free (put);
   return GNUNET_OK;
 }
@@ -892,11 +893,11 @@
                  "dht", GNUNET_P2P_PROTO_DHT_GET, GNUNET_P2P_PROTO_DHT_PUT,
                  GNUNET_P2P_PROTO_DHT_RESULT);
   coreAPI->p2p_ciphertext_handler_register (GNUNET_P2P_PROTO_DHT_GET,
-                                            &handleGet);
+                                            &handle_get);
   coreAPI->p2p_ciphertext_handler_register (GNUNET_P2P_PROTO_DHT_PUT,
-                                            &handlePut);
+                                            &handle_put);
   coreAPI->p2p_ciphertext_handler_register (GNUNET_P2P_PROTO_DHT_RESULT,
-                                            &handleResult);
+                                            &handle_result);
   coreAPI->send_callback_register (sizeof (DHT_MESSAGE), 0,
                                    &extra_get_callback);
   return GNUNET_OK;
@@ -916,11 +917,11 @@
   coreAPI->send_callback_unregister (sizeof (DHT_MESSAGE),
                                      &extra_get_callback);
   coreAPI->p2p_ciphertext_handler_unregister (GNUNET_P2P_PROTO_DHT_GET,
-                                              &handleGet);
+                                              &handle_get);
   coreAPI->p2p_ciphertext_handler_unregister (GNUNET_P2P_PROTO_DHT_PUT,
-                                              &handlePut);
+                                              &handle_put);
   coreAPI->p2p_ciphertext_handler_unregister (GNUNET_P2P_PROTO_DHT_RESULT,
-                                              &handleResult);
+                                              &handle_result);
   if (stats != NULL)
     {
       coreAPI->service_release (stats);

Modified: GNUnet/src/applications/dht/tools/Makefile.am
===================================================================
--- GNUnet/src/applications/dht/tools/Makefile.am       2008-12-14 19:55:50 UTC 
(rev 8004)
+++ GNUnet/src/applications/dht/tools/Makefile.am       2008-12-14 19:56:24 UTC 
(rev 8005)
@@ -43,6 +43,16 @@
   $(top_builddir)/src/applications/dht/tools/libgnunetdht_api.la \
   $(top_builddir)/src/util/libgnunetutil.la 
 
+# This test requires an API change before we can
+# integrate it by default...
+#dht_expiration_test_SOURCES = \
+#  dht_expiration_test.c 
+#dht_expiration_test_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/libgnunetutil.la 
+
 dht_twopeer_test_SOURCES = \
   dht_twopeer_test.c 
 dht_twopeer_test_LDADD = \

Added: GNUnet/src/applications/dht/tools/dht_expiration_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_expiration_test.c                     
        (rev 0)
+++ GNUnet/src/applications/dht/tools/dht_expiration_test.c     2008-12-14 
19:56:24 UTC (rev 8005)
@@ -0,0 +1,122 @@
+/*
+     This file is part of GNUnet.
+     (C) 2005, 2006, 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_expiration_test.c
+ * @brief DHT testcase using only a single peer
+ * @author Christian Grothoff
+ * @author Nathan Evans
+ */
+
+#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.h"
+
+
+#define START_PEERS 1
+
+static int err;
+
+static int
+result_callback (const GNUNET_HashCode * key,
+                 unsigned int type,
+                 unsigned int size, const char *data, void *cls)
+{
+  fprintf (stderr, "Got %u %u `%.*s'\n", type, size, size, data);
+  err = 1;
+  return GNUNET_SYSERR;
+}
+
+#define CHECK(a) do { if (!(a)) { ret = 1; GNUNET_GE_BREAK(ectx, 0); goto 
FAILURE; } } while(0)
+
+/**
+ * Testcase to test DHT routing (2 peers only).
+ * @return 0: ok, -1: error
+ */
+int
+main (int argc, const char **argv)
+{
+#if START_PEERS
+  struct GNUNET_TESTING_DaemonContext *peers;
+#endif
+  int ret = 0;
+  GNUNET_HashCode key;
+  char *value;
+  struct GNUNET_GE_Context *ectx;
+  struct GNUNET_GC_Configuration *cfg;
+  struct GNUNET_DHT_Context *ctx;
+  void *unused_cls = NULL;
+
+
+  ectx = NULL;
+  cfg = GNUNET_GC_create ();
+  if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
+    {
+      GNUNET_GC_free (cfg);
+      return -1;
+    }
+#if START_PEERS
+  peers = GNUNET_TESTING_start_daemons ("nat",
+                                        "advertising dht stats",
+                                        "/tmp/gnunet-dht-loopback-test",
+                                        2087, 10000, 1);
+  if (peers == NULL)
+    {
+      GNUNET_GC_free (cfg);
+      return -1;
+    }
+#endif
+  GNUNET_GC_set_configuration_value_string (cfg,
+                                            ectx,
+                                            "NETWORK", "HOST",
+                                            "localhost:2087");
+  ctx = GNUNET_DHT_context_create (cfg, ectx, &result_callback, unused_cls);
+  CHECK (ctx != NULL);
+  /* actual test code */
+  GNUNET_hash ("expired_key", 4, &key);
+  value = GNUNET_malloc (8);
+  memset (value, 'A', 8);
+  CHECK (GNUNET_OK == GNUNET_DHT_put (cfg,
+                                      ectx,
+                                      &key,
+                                      GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+                                      8, value));
+  /* FIXME: this value has to be >> than the expiration
+     time (which is currently fixed to 12h, so we can not
+     really do this test in practice... */
+  GNUNET_thread_sleep(60 * GNUNET_CRON_SECONDS);
+  CHECK (1 == GNUNET_DHT_get_start (ctx,
+                                    GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+                                    &key));
+  GNUNET_thread_sleep(15 * GNUNET_CRON_SECONDS);
+  GNUNET_DHT_context_destroy (ctx);
+
+FAILURE:
+#if START_PEERS
+  GNUNET_TESTING_stop_daemons (peers);
+#endif
+  GNUNET_GC_free (cfg);
+  return err;
+}
+
+/* end of dht_expiration_test.c */





reply via email to

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