[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r6959 - GNUnet/src/applications/dht/tools
From: |
gnunet |
Subject: |
[GNUnet-SVN] r6959 - GNUnet/src/applications/dht/tools |
Date: |
Sat, 31 May 2008 17:52:43 -0600 (MDT) |
Author: nevans
Date: 2008-05-31 17:52:43 -0600 (Sat, 31 May 2008)
New Revision: 6959
Modified:
GNUnet/src/applications/dht/tools/dht_api.c
GNUnet/src/applications/dht/tools/dht_loopback_test.c
GNUnet/src/applications/dht/tools/dht_multipeer_test.c
GNUnet/src/applications/dht/tools/dht_twopeer_test.c
Log:
test cases compile, but don't yet work... coming soon
Modified: GNUnet/src/applications/dht/tools/dht_api.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_api.c 2008-05-31 20:43:32 UTC (rev
6958)
+++ GNUnet/src/applications/dht/tools/dht_api.c 2008-05-31 23:52:43 UTC (rev
6959)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet
- (C) 2004, 2005, 2006, 2007 Christian Grothoff (and other contributing
authors)
+ (C) 2004, 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
@@ -21,55 +21,13 @@
/**
* @file dht/tools/dht_api.c
* @brief DHT-module's core API's implementation.
- * @author Tomi Tukiainen, Christian Grothoff
+ * @author Tomi Tukiainen, Christian Grothoff, Nathan Evans
*/
-#include "platform.h"
-#include "gnunet_protocols.h"
-#include "dht.h"
-#include "gnunet_dht_lib.h"
-#include "gnunet_util.h"
+#include "dht_api.h"
#define DEBUG_DHT_API GNUNET_NO
-/**
- * Data exchanged between main thread and GET thread.
- */
-struct GNUNET_DHT_Context
-{
-
- /**
- * Connection with gnunetd.
- */
- struct GNUNET_ClientServerConnection *sock;
-
- /**
- * Callback to call for each result.
- */
- GNUNET_ResultProcessor processor;
-
- /**
- * Extra argument for processor.
- */
- void *closure;
-
- /**
- * Parent thread that is waiting for the
- * timeout (used to notify if we are exiting
- * early, i.e. because of gnunetd closing the
- * connection or the processor callback requesting
- * it).
- */
- struct GNUNET_ThreadHandle *poll_thread; /*Poll thread instead.. */
-
- /**
- * Are we done (for whichever reason)?
- */
- int aborted;
-
-};
-
-
static void *
poll_thread (void *cls)
{
Modified: GNUnet/src/applications/dht/tools/dht_loopback_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_loopback_test.c 2008-05-31
20:43:32 UTC (rev 6958)
+++ GNUnet/src/applications/dht/tools/dht_loopback_test.c 2008-05-31
23:52:43 UTC (rev 6959)
@@ -22,6 +22,7 @@
* @file applications/dht/tools/dht_loopback_test.c
* @brief DHT testcase using only a single peer
* @author Christian Grothoff
+ * @author Nathan Evans
*/
#include "platform.h"
@@ -75,10 +76,12 @@
char *value;
struct GNUNET_GE_Context *ectx;
struct GNUNET_GC_Configuration *cfg;
- struct GNUNET_ClientServerConnection *sock;
+ struct GNUNET_DHT_Context *ctx;
+ void *unused_cls = NULL;
int left;
int i;
+
ectx = NULL;
cfg = GNUNET_GC_create ();
if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
@@ -101,7 +104,8 @@
ectx,
"NETWORK", "HOST",
"localhost:2087");
- sock = GNUNET_client_connection_create (NULL, cfg);
+ ctx = GNUNET_DHT_context_create(cfg,ectx,&result_callback,unused_cls);
+
/* actual test code */
GNUNET_hash ("key2", 4, &key);
value = GNUNET_malloc (8);
@@ -112,11 +116,9 @@
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
8, value));
i = 'A';
- CHECK (1 == GNUNET_DHT_get (cfg,
- ectx,
+ CHECK (1 == GNUNET_DHT_get_start (ctx,
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key, 2 * GNUNET_CRON_SECONDS, &result_callback,
- &i));
+ &key));
CHECK (err == 0);
GNUNET_hash ("key", 3, &key);
value = GNUNET_malloc (8);
@@ -128,11 +130,9 @@
8, value));
CHECK (err == 0);
i = 'B';
- CHECK (1 == GNUNET_DHT_get (cfg,
- ectx,
+ CHECK (1 == GNUNET_DHT_get_start (ctx,
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key, 2 * GNUNET_CRON_SECONDS, &result_callback,
- &i));
+ &key));
GNUNET_hash ("key2", 4, &key);
CHECK (err == 0);
left = 10;
@@ -140,11 +140,9 @@
{
fprintf (stderr, ".");
i = 'A';
- if (1 == GNUNET_DHT_get (cfg,
- ectx,
+ if (1 == GNUNET_DHT_get_start (ctx,
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key, 2 * GNUNET_CRON_SECONDS,
- &result_callback, &i))
+ &key))
break;
CHECK (err == 0);
left--;
@@ -153,6 +151,8 @@
CHECK (left > 0);
/* end of actual test code */
+GNUNET_DHT_context_destroy(ctx);
+
FAILURE:
#if START_PEERS
GNUNET_TESTING_stop_daemons (peers);
Modified: GNUnet/src/applications/dht/tools/dht_multipeer_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_multipeer_test.c 2008-05-31
20:43:32 UTC (rev 6958)
+++ GNUnet/src/applications/dht/tools/dht_multipeer_test.c 2008-05-31
23:52:43 UTC (rev 6959)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2007 Christian Grothoff (and other contributing authors)
+ (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
@@ -22,6 +22,7 @@
* @file applications/dht/tools/dht_multipeer_test.c
* @brief DHT testcase
* @author Christian Grothoff
+ * @author Nathan Evans
*/
#include "platform.h"
@@ -30,6 +31,7 @@
#include "gnunet_testing_lib.h"
#include "gnunet_stats_lib.h"
#include "gnunet_util.h"
+#include "dht_api.h"
/**
* How many peers should the testcase run? Note that
@@ -44,8 +46,32 @@
#define NUM_ROUNDS 10
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];
+
+#if 0
+ fprintf (stderr, "Got %u %u `%.*s'\n", type, size, size, data);
+#endif
+ memset (expect, (*i), sizeof (expect));
+ 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 (_("# dht connections"), name)))
@@ -72,11 +98,12 @@
struct GNUNET_GE_Context *ectx;
struct GNUNET_GC_Configuration *cfg;
struct GNUNET_ClientServerConnection *sock;
+ struct GNUNET_DHT_Context *ctx_array[NUM_PEERS];
int left;
int i;
int j;
int k;
- int found;
+
char buf[128];
ectx = NULL;
@@ -157,6 +184,7 @@
GNUNET_snprintf (buf, 128, "localhost:%u", 2087 + i * 10);
GNUNET_GC_set_configuration_value_string (cfg,
ectx, "NETWORK", "HOST", buf);
+ ctx_array[i] =
GNUNET_DHT_context_create(cfg,ectx,&result_callback,NULL);
for (j = 0; j < NUM_PEERS; j++)
{
GNUNET_snprintf (buf, 128, "localhost:%u", 2087 + j * 10);
@@ -166,17 +194,14 @@
{
printf (".");
fflush (stdout);
- if (0 < GNUNET_DHT_get (cfg,
- ectx,
+ if (0 < GNUNET_DHT_get_start (ctx_array[i],
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key,
- 15 * GNUNET_CRON_SECONDS, NULL, NULL))
+ &key))
break;
}
if (k < NUM_ROUNDS)
{
printf (" OK!\n");
- found++;
}
else
{
@@ -184,6 +209,11 @@
}
}
}
+
+ for (i = 0; i < NUM_PEERS; i++)
+ {
+ GNUNET_DHT_context_destroy(ctx_array[i]);
+ }
/* end of actual test code */
printf ("Found %u out of %u attempts.\n", found, NUM_PEERS * NUM_PEERS);
FAILURE:
Modified: GNUnet/src/applications/dht/tools/dht_twopeer_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_twopeer_test.c 2008-05-31
20:43:32 UTC (rev 6958)
+++ GNUnet/src/applications/dht/tools/dht_twopeer_test.c 2008-05-31
23:52:43 UTC (rev 6959)
@@ -22,6 +22,7 @@
* @file applications/dht/tools/dht_twopeer_test.c
* @brief DHT testcase
* @author Christian Grothoff
+ * @author Nathan Evans
*/
#include "platform.h"
@@ -30,12 +31,15 @@
#include "gnunet_testing_lib.h"
#include "gnunet_stats_lib.h"
#include "gnunet_util.h"
+#include "dht_api.h"
#define START_PEERS 1
static int ok;
+static int peer1count;
+static int peer2count;
static int
waitForConnect (const char *name, unsigned long long value, void *cls)
@@ -48,6 +52,50 @@
return GNUNET_OK;
}
+static int
+result_callback_peer1 (const GNUNET_HashCode * key,
+ unsigned int type,
+ unsigned int size, const char *data, void *cls)
+{
+ int *i = cls;
+ char expect[8];
+
+#if 0
+ fprintf (stderr, "Got %u %u `%.*s'\n", type, size, size, data);
+#endif
+ memset (expect, (*i), sizeof (expect));
+ if ((8 != size) ||
+ (0 != memcmp (expect, data, size)) ||
+ (type != GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING))
+ {
+ return GNUNET_SYSERR;
+ }
+ peer1count--;
+ return GNUNET_OK;
+}
+
+static int
+result_callback_peer2 (const GNUNET_HashCode * key,
+ unsigned int type,
+ unsigned int size, const char *data, void *cls)
+{
+ int *i = cls;
+ char expect[8];
+
+#if 0
+ fprintf (stderr, "Got %u %u `%.*s'\n", type, size, size, data);
+#endif
+ memset (expect, (*i), sizeof (expect));
+ if ((8 != size) ||
+ (0 != memcmp (expect, data, size)) ||
+ (type != GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING))
+ {
+ return GNUNET_SYSERR;
+ }
+ peer2count--;
+ return GNUNET_OK;
+}
+
#define CHECK(a) do { if (!(a)) { ret = 1; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; } } while(0)
/**
@@ -65,7 +113,8 @@
char *value;
struct GNUNET_GE_Context *ectx;
struct GNUNET_GC_Configuration *cfg;
- struct GNUNET_ClientServerConnection *sock;
+ struct GNUNET_DHT_Context *ctx_peer1;
+ struct GNUNET_DHT_Context *ctx_peer2;
int left;
ectx = NULL;
@@ -95,11 +144,11 @@
}
/* wait for DHT's to find each other! */
- sock = GNUNET_client_connection_create (NULL, cfg);
+ ctx_peer1 = GNUNET_DHT_context_create(cfg,ectx,&result_callback_peer1,NULL);
left = 50; /* how many iterations should we wait? */
printf ("Waiting for peers to DHT-connect (1->2)");
while (GNUNET_OK ==
- GNUNET_STATS_get_statistics (NULL, sock, &waitForConnect, NULL))
+ GNUNET_STATS_get_statistics (NULL, ctx_peer1->sock, &waitForConnect,
NULL))
{
printf (".");
fflush (stdout);
@@ -109,12 +158,12 @@
break;
}
printf (left > 0 ? " OK!\n" : "?\n");
- GNUNET_client_connection_destroy (sock);
if (ok == 0)
{
GNUNET_TESTING_stop_daemons (peers);
fprintf (stderr, "Peers' DHTs failed to DHT-connect!\n");
GNUNET_GC_free (cfg);
+ GNUNET_DHT_context_destroy(ctx_peer1);
return -1;
}
@@ -125,11 +174,11 @@
"localhost:12087");
/* verify that peer2 also sees the other DHT! */
ok = 0;
- sock = GNUNET_client_connection_create (NULL, cfg);
+ ctx_peer2 = GNUNET_DHT_context_create(cfg,ectx,&result_callback_peer2,NULL);
left = 50; /* how many iterations should we wait? */
printf ("Waiting for peers to DHT-connect (2->1)");
while (GNUNET_OK ==
- GNUNET_STATS_get_statistics (NULL, sock, &waitForConnect, NULL))
+ GNUNET_STATS_get_statistics (NULL, ctx_peer2->sock, &waitForConnect,
NULL))
{
printf (".");
fflush (stdout);
@@ -139,12 +188,13 @@
break;
}
printf (left > 0 ? " OK!\n" : "?\n");
- GNUNET_client_connection_destroy (sock);
if (ok == 0)
{
GNUNET_TESTING_stop_daemons (peers);
fprintf (stderr, "Peers' DHTs failed to DHT-connect!\n");
GNUNET_GC_free (cfg);
+ GNUNET_DHT_context_destroy(ctx_peer1);
+ GNUNET_DHT_context_destroy(ctx_peer2);
return -1;
}
@@ -163,11 +213,6 @@
&key,
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
8, value));
- /* switch to peer2 */
- GNUNET_GC_set_configuration_value_string (cfg,
- ectx,
- "NETWORK", "HOST",
- "localhost:12087");
GNUNET_hash ("key", 3, &key);
value = GNUNET_malloc (8);
memset (value, 'B', 8);
@@ -177,44 +222,36 @@
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
8, value));
GNUNET_hash ("key2", 4, &key);
- left = 10;
+ peer2count = 10;
printf ("Getting key 2 from peer 2 (stored at peer 1)");
do
{
printf (".");
fflush (stdout);
- if (1 == GNUNET_DHT_get (cfg,
- ectx,
+ if (GNUNET_OK == GNUNET_DHT_get_start (ctx_peer2,
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key, 2 * GNUNET_CRON_SECONDS, NULL, NULL))
+ &key))
break;
- left--;
}
- while (left > 0);
- printf (left > 0 ? " OK!\n" : "?\n");
+ while (peer2count > 0);
+ printf (peer2count > 0 ? " OK!\n" : "?\n");
- CHECK (left > 0);
- /* switch to peer1 */
- GNUNET_GC_set_configuration_value_string (cfg,
- ectx,
- "NETWORK", "HOST",
- "localhost:2087");
+ CHECK (peer2count > 0);
+
printf ("Getting key 1 from peer 1 (stored at peer 2)");
- left = 10;
+ peer1count = 10;
do
{
printf (".");
fflush (stdout);
- if (1 == GNUNET_DHT_get (cfg,
- ectx,
+ if (GNUNET_OK == GNUNET_DHT_get_start (ctx_peer1,
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key, 2 * GNUNET_CRON_SECONDS, NULL, NULL))
+ &key))
break;
- left--;
}
- while (left > 0);
- printf (left > 0 ? " OK!\n" : "?\n");
- CHECK (left > 0);
+ while (peer1count > 0);
+ printf (peer1count > 0 ? " OK!\n" : "?\n");
+ CHECK (peer1count > 0);
/* end of actual test code */
FAILURE:
@@ -222,6 +259,8 @@
GNUNET_TESTING_stop_daemons (peers);
#endif
GNUNET_GC_free (cfg);
+ GNUNET_DHT_context_destroy(ctx_peer1);
+ GNUNET_DHT_context_destroy(ctx_peer2);
return ret;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r6959 - GNUnet/src/applications/dht/tools,
gnunet <=