[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r8015 - GNUnet/src/applications/dht/tools
From: |
gnunet |
Subject: |
[GNUnet-SVN] r8015 - GNUnet/src/applications/dht/tools |
Date: |
Thu, 25 Dec 2008 23:42:51 -0700 (MST) |
Author: grothoff
Date: 2008-12-25 23:42:51 -0700 (Thu, 25 Dec 2008)
New Revision: 8015
Removed:
GNUnet/src/applications/dht/tools/dht_api.h
Modified:
GNUnet/src/applications/dht/tools/Makefile.am
GNUnet/src/applications/dht/tools/dht-query.c
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:
api cleanup
Modified: GNUnet/src/applications/dht/tools/Makefile.am
===================================================================
--- GNUnet/src/applications/dht/tools/Makefile.am 2008-12-26 06:42:40 UTC
(rev 8014)
+++ GNUnet/src/applications/dht/tools/Makefile.am 2008-12-26 06:42:51 UTC
(rev 8015)
@@ -11,7 +11,7 @@
gnunet-dht-query
libgnunetdht_api_la_SOURCES = \
- dht_api.c dht_api.h
+ dht_api.c
libgnunetdht_api_la_LDFLAGS = \
$(GN_LIB_LDFLAGS)
libgnunetdht_api_la_LIBADD = \
Modified: GNUnet/src/applications/dht/tools/dht-query.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht-query.c 2008-12-26 06:42:40 UTC
(rev 8014)
+++ GNUnet/src/applications/dht/tools/dht-query.c 2008-12-26 06:42:51 UTC
(rev 8015)
@@ -74,9 +74,9 @@
static void
do_get (struct GNUNET_ClientServerConnection *sock, const char *key)
{
- int ret;
+ struct GNUNET_DHT_GetRequest* ret;
GNUNET_HashCode hc;
-
+
GNUNET_hash (key, strlen (key), &hc);
#if DEBUG_DHT_QUERY
GNUNET_GE_LOG (ectx,
@@ -85,12 +85,14 @@
#endif
ret = GNUNET_DHT_get_start (ctx, GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
&hc);
- if (ret == GNUNET_SYSERR)
- printf ("`%s(%s)' failed.\n", "get", key);
+ if (ret == NULL)
+ {
+ printf ("`%s(%s)' failed.\n", "get", key);
+ return;
+ }
GNUNET_thread_sleep (timeout);
- ret = GNUNET_DHT_get_stop (ctx,
- GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING, &hc);
- GNUNET_GE_ASSERT (NULL, ret == GNUNET_OK);
+ GNUNET_DHT_get_stop (ctx,
+ ret);
}
static void
Modified: GNUnet/src/applications/dht/tools/dht_api.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_api.c 2008-12-26 06:42:40 UTC (rev
8014)
+++ GNUnet/src/applications/dht/tools/dht_api.c 2008-12-26 06:42:51 UTC (rev
8015)
@@ -22,38 +22,122 @@
* @file dht/tools/dht_api.c
* @brief DHT-module's core API's implementation.
* @author Tomi Tukiainen, Christian Grothoff, Nathan Evans
- *
- * TODO:
- * - track active requests
- * - automatically re-issue all requests if connection with gnunetd
- * gets re-established
- * - re-establish connections with gnunetd (just like fslib does)
*/
+#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
+/**
+ * Doubly-linked list of get requests.
+ */
+struct GNUNET_DHT_GetRequest
+{
+ struct GNUNET_DHT_GetRequest * prev;
+
+ struct GNUNET_DHT_GetRequest * next;
+
+ CS_dht_request_get_MESSAGE request;
+};
+
+/**
+ * Data exchanged between main thread and GET thread.
+ */
+struct GNUNET_DHT_Context
+{
+
+ /**
+ * Connection with gnunetd.
+ */
+ struct GNUNET_ClientServerConnection *sock;
+
+ /**
+ * Lock for head and tail fields.
+ */
+ struct GNUNET_Mutex * lock;
+
+ /**
+ * Callback to call for each result.
+ */
+ GNUNET_ResultProcessor processor;
+
+ /**
+ * Extra argument for processor.
+ */
+ void *closure;
+
+ /**
+ * Thread polling for replies from gnunetd.
+ */
+ struct GNUNET_ThreadHandle *poll_thread;
+
+ /**
+ * Head of our pending requests.
+ */
+ struct GNUNET_DHT_GetRequest * head;
+
+ /**
+ * Tail of our pending requests.
+ */
+ struct GNUNET_DHT_GetRequest * tail;
+
+ /**
+ * Are we done (for whichever reason)?
+ */
+ int aborted;
+
+ /**
+ * Set to YES if we had a write error and need to
+ * resubmit all of our requests.
+ */
+ int restart;
+
+};
+
+/**
+ * Main loop of the poll thread.
+ *
+ * @param cls the DHT context
+ * @return NULL (always)
+ */
static void *
poll_thread (void *cls)
{
struct GNUNET_DHT_Context *info = cls;
GNUNET_MessageHeader *reply;
CS_dht_request_put_MESSAGE *put;
+ struct GNUNET_DHT_GetRequest *get;
unsigned int size;
while (info->aborted == GNUNET_NO)
{
reply = NULL;
- if (GNUNET_OK != GNUNET_client_connection_read (info->sock, &reply))
- {
- /* FIXME: we need to handle this better,
- if we were not aborted, we need to try
- to reconnect! -- this assertion failure
- is more like a warning to the end-user/developer
- that the code is not yet perfect... */
- GNUNET_GE_BREAK (NULL, info->aborted != GNUNET_NO);
- break;
+ if ( (info->restart == GNUNET_YES) ||
+ (GNUNET_OK != GNUNET_client_connection_read (info->sock, &reply)) )
+ {
+ info->restart = GNUNET_NO;
+ while ( (info->aborted == GNUNET_NO) &&
+ (GNUNET_OK != GNUNET_client_connection_ensure_connected
(info->sock)) )
+ GNUNET_thread_sleep(100 * GNUNET_CRON_MILLISECONDS);
+ if (info->aborted != GNUNET_NO)
+ break;
+ GNUNET_mutex_lock(info->lock);
+ get = info->head;
+ while ( (get != NULL) &&
+ (info->restart == GNUNET_NO) &&
+ (info->aborted == GNUNET_NO) )
+ {
+ if (GNUNET_OK !=
+ GNUNET_client_connection_write (info->sock,
+ &get->request.header))
+ info->restart = GNUNET_YES;
+ get = get->next;
+ }
+ GNUNET_mutex_unlock(info->lock);
+ continue;
}
if ((sizeof (CS_dht_request_put_MESSAGE) > ntohs (reply->size)) ||
(GNUNET_CS_PROTO_DHT_REQUEST_PUT != ntohs (reply->type)))
@@ -77,7 +161,6 @@
GNUNET_free (reply);
}
info->aborted = GNUNET_YES;
- GNUNET_thread_stop_sleep (info->poll_thread);
return NULL;
}
@@ -103,13 +186,19 @@
sock = GNUNET_client_connection_create (ectx, cfg);
if (sock == NULL)
return NULL;
-
ctx = GNUNET_malloc (sizeof (struct GNUNET_DHT_Context));
+ ctx->lock = GNUNET_mutex_create(GNUNET_NO);
ctx->sock = sock;
+ ctx->processor = resultCallback;
ctx->closure = resCallbackClosure;
- ctx->processor = resultCallback;
ctx->poll_thread = GNUNET_thread_create (&poll_thread, ctx, 1024 * 8);
- ctx->aborted = GNUNET_NO;
+ if (ctx->poll_thread == NULL)
+ {
+ GNUNET_client_connection_destroy (sock);
+ GNUNET_mutex_destroy (ctx->lock);
+ GNUNET_free (ctx);
+ return NULL;
+ }
return ctx;
}
@@ -122,48 +211,50 @@
* @param key the key to look up
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
-int
+struct GNUNET_DHT_GetRequest *
GNUNET_DHT_get_start (struct GNUNET_DHT_Context *ctx,
unsigned int type, const GNUNET_HashCode * key)
{
- CS_dht_request_get_MESSAGE req;
+ struct GNUNET_DHT_GetRequest * req;
- if (ctx->sock == NULL)
- return GNUNET_SYSERR;
- req.header.size = htons (sizeof (CS_dht_request_get_MESSAGE));
- req.header.type = htons (GNUNET_CS_PROTO_DHT_REQUEST_GET);
- req.type = htonl (type);
- req.key = *key;
- if (GNUNET_OK != GNUNET_client_connection_write (ctx->sock, &req.header))
- return GNUNET_SYSERR;
- return GNUNET_OK;
+ req = GNUNET_malloc(sizeof(struct GNUNET_DHT_GetRequest));
+ req->request.header.size = htons (sizeof (CS_dht_request_get_MESSAGE));
+ req->request.header.type = htons (GNUNET_CS_PROTO_DHT_REQUEST_GET);
+ req->request.type = htonl (type);
+ req->request.key = *key;
+ GNUNET_mutex_lock(ctx->lock);
+ GNUNET_DLL_insert(ctx->head, ctx->tail, req);
+ GNUNET_mutex_unlock(ctx->lock);
+ if (GNUNET_OK !=
+ GNUNET_client_connection_write (ctx->sock, &req->request.header))
+ ctx->restart = GNUNET_YES;
+ return req;
}
/**
* Stop an asynchronous GET operation on the DHT looking for
* key.
- * @param type the type of key to look up
- * @param key the key to look up
+ *
+ * @param req request to stop
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int
GNUNET_DHT_get_stop (struct GNUNET_DHT_Context *ctx,
- unsigned int type, const GNUNET_HashCode * key)
+ struct GNUNET_DHT_GetRequest * req)
{
+ CS_dht_request_get_MESSAGE creq;
- CS_dht_request_get_MESSAGE req;
-
- if (ctx->sock == NULL)
- return GNUNET_SYSERR;
- req.header.size = htons (sizeof (CS_dht_request_get_MESSAGE));
- req.header.type = htons (GNUNET_CS_PROTO_DHT_REQUEST_GET_END);
- req.type = htonl (type);
- req.key = *key;
- if (GNUNET_OK != GNUNET_client_connection_write (ctx->sock, &req.header))
- return GNUNET_SYSERR;
+ creq.header.size = htons (sizeof (CS_dht_request_get_MESSAGE));
+ creq.header.type = htons (GNUNET_CS_PROTO_DHT_REQUEST_GET_END);
+ creq.type = req->request.type;
+ creq.key = req->request.key;
+ GNUNET_mutex_lock(ctx->lock);
+ GNUNET_DLL_remove(ctx->head, ctx->tail, req);
+ GNUNET_mutex_unlock(ctx->lock);
+ if (GNUNET_OK != GNUNET_client_connection_write (ctx->sock, &creq.header))
+ ctx->restart = GNUNET_YES;
return GNUNET_OK;
-
}
/**
@@ -176,10 +267,16 @@
GNUNET_DHT_context_destroy (struct GNUNET_DHT_Context *ctx)
{
void *unused;
+
+ GNUNET_GE_ASSERT(NULL, ctx->head == NULL);
+ GNUNET_GE_ASSERT(NULL, ctx->tail == NULL);
ctx->aborted = GNUNET_YES;
GNUNET_client_connection_close_forever (ctx->sock);
+ GNUNET_thread_stop_sleep (ctx->poll_thread);
GNUNET_thread_join (ctx->poll_thread, &unused);
GNUNET_client_connection_destroy (ctx->sock);
+ GNUNET_mutex_destroy(ctx->lock);
+ GNUNET_free(ctx);
return GNUNET_OK;
}
Deleted: GNUnet/src/applications/dht/tools/dht_api.h
===================================================================
--- GNUnet/src/applications/dht/tools/dht_api.h 2008-12-26 06:42:40 UTC (rev
8014)
+++ GNUnet/src/applications/dht/tools/dht_api.h 2008-12-26 06:42:51 UTC (rev
8015)
@@ -1,71 +0,0 @@
-/*
- This file is part of GNUnet
- (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
- 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 dht/tools/dht_api.h
- * @brief DHT-module's core API's implementation.
- * @author Nathan Evans
- */
-
-#include "platform.h"
-#include "gnunet_protocols.h"
-#include "dht.h"
-#include "gnunet_dht_lib.h"
-#include "gnunet_util.h"
-
-
-/**
- * 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;
-
-};
-
-/* end of dht_api.h */
Modified: GNUnet/src/applications/dht/tools/dht_loopback_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_loopback_test.c 2008-12-26
06:42:40 UTC (rev 8014)
+++ GNUnet/src/applications/dht/tools/dht_loopback_test.c 2008-12-26
06:42:51 UTC (rev 8015)
@@ -37,6 +37,8 @@
static int err;
+static int found;
+
static int
result_callback (const GNUNET_HashCode * key,
unsigned int type,
@@ -56,6 +58,7 @@
err = 1;
return GNUNET_SYSERR;
}
+ found = 1;
return GNUNET_OK;
}
@@ -77,11 +80,11 @@
struct GNUNET_GE_Context *ectx;
struct GNUNET_GC_Configuration *cfg;
struct GNUNET_DHT_Context *ctx;
- void *unused_cls = NULL;
+ struct GNUNET_DHT_GetRequest * get1;
+ struct GNUNET_DHT_GetRequest * get2;
int left;
int i;
-
ectx = NULL;
cfg = GNUNET_GC_create ();
if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
@@ -104,10 +107,10 @@
ectx,
"NETWORK", "HOST",
"localhost:2087");
- ctx = GNUNET_DHT_context_create (cfg, ectx, &result_callback, unused_cls);
+ ctx = GNUNET_DHT_context_create (cfg, ectx, &result_callback, &i);
CHECK (ctx != NULL);
/* actual test code */
- GNUNET_hash ("key2", 4, &key);
+ GNUNET_hash ("key_for_A", 4, &key);
value = GNUNET_malloc (8);
memset (value, 'A', 8);
CHECK (GNUNET_OK == GNUNET_DHT_put (cfg,
@@ -116,11 +119,10 @@
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
8, value));
i = 'A';
- CHECK (1 == GNUNET_DHT_get_start (ctx,
- GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key));
- CHECK (err == 0);
- GNUNET_hash ("key", 3, &key);
+ CHECK (NULL != (get1 = GNUNET_DHT_get_start (ctx,
+
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+ &key)));
+ GNUNET_hash ("key_for_B", 3, &key);
value = GNUNET_malloc (8);
memset (value, 'B', 8);
CHECK (GNUNET_OK == GNUNET_DHT_put (cfg,
@@ -128,31 +130,26 @@
&key,
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
8, value));
+ left = 10;
+ while ( (found == 0) && (--left >= 0) )
+ GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS);
CHECK (err == 0);
+ CHECK (found != 0);
+ found = 0;
+ GNUNET_DHT_get_stop(ctx, get1);
i = 'B';
- CHECK (1 == GNUNET_DHT_get_start (ctx,
- GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key));
- GNUNET_hash ("key2", 4, &key);
- CHECK (err == 0);
+ CHECK (NULL != (get2 = GNUNET_DHT_get_start (ctx,
+
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+ &key)));
left = 10;
- do
- {
- fprintf (stderr, ".");
- i = 'A';
- if (1 == GNUNET_DHT_get_start (ctx,
- GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key))
- break;
- CHECK (err == 0);
- left--;
- }
- while (left > 0);
- CHECK (left > 0);
+ while ( (found == 0) && (--left >= 0) )
+ GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS);
+ CHECK (err == 0);
+ CHECK (found != 0);
+ GNUNET_DHT_get_stop(ctx, get2);
/* 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-12-26
06:42:40 UTC (rev 8014)
+++ GNUnet/src/applications/dht/tools/dht_multipeer_test.c 2008-12-26
06:42:51 UTC (rev 8015)
@@ -31,7 +31,6 @@
#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
@@ -45,6 +44,11 @@
*/
#define NUM_ROUNDS 100
+/**
+ * How often do we iterate the put-get loop?
+ */
+#define NUM_REPEAT 5
+
static int ok;
static int found;
@@ -97,12 +101,14 @@
struct GNUNET_GE_Context *ectx;
struct GNUNET_GC_Configuration *cfg;
struct GNUNET_ClientServerConnection *sock;
- struct GNUNET_DHT_Context *ctx_array[NUM_PEERS];
+ struct GNUNET_DHT_Context *dctx;
+ struct GNUNET_DHT_GetRequest * get1;
int left;
int i;
int j;
int k;
int c;
+ int r;
int last;
char buf[128];
@@ -137,90 +143,101 @@
}
}
- /* put loop */
- for (i = 0; i < NUM_PEERS; i++)
+ for (r = 0; r < NUM_REPEAT; r++)
{
- GNUNET_snprintf (buf, 128, "localhost:%u", 2087 + i * 10);
- GNUNET_GC_set_configuration_value_string (cfg, ectx, "NETWORK", "HOST",
- buf);
- /* wait for some DHT's to find each other! */
- sock = GNUNET_client_connection_create (NULL, cfg);
- left = 30; /* how many iterations should we wait? */
- printf ("Waiting for peer %u to DHT-connect", i);
- while (GNUNET_OK ==
- GNUNET_STATS_get_statistics (NULL, sock, &waitForConnect, NULL))
- {
- printf (".");
- fflush (stdout);
- sleep (2);
- left--;
- if (left == 0)
- 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);
- return -1;
- }
- GNUNET_hash (buf, strlen (buf), &key);
- value = GNUNET_malloc (8);
- memset (value, 'A' + i, 8);
- CHECK (GNUNET_OK == GNUNET_DHT_put (cfg,
- ectx,
- &key,
-
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- 8, value));
- GNUNET_free (value);
+ if (GNUNET_shutdown_test() == GNUNET_YES)
+ break;
+ /* put 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);
+ GNUNET_GC_set_configuration_value_string (cfg, ectx, "NETWORK",
"HOST",
+ buf);
+ /* wait for some DHT's to find each other! */
+ sock = GNUNET_client_connection_create (NULL, cfg);
+ left = 30; /* how many iterations should we wait? */
+ printf ("Waiting for peer %u to DHT-connect", i);
+ while (GNUNET_OK ==
+ GNUNET_STATS_get_statistics (NULL, sock, &waitForConnect,
NULL))
+ {
+ if (GNUNET_shutdown_test() == GNUNET_YES)
+ break;
+ printf (".");
+ fflush (stdout);
+ GNUNET_thread_sleep (2 * GNUNET_CRON_SECONDS);
+ left--;
+ if (left == 0)
+ 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);
+ return -1;
+ }
+ GNUNET_hash (buf, strlen (buf), &key);
+ value = GNUNET_malloc (8);
+ memset (value, 'A' + i, 8);
+ CHECK (GNUNET_OK == GNUNET_DHT_put (cfg,
+ ectx,
+ &key,
+
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+ 8, value));
+ GNUNET_free (value);
+ }
+
+ /* get loop */
+ found = 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);
+ GNUNET_GC_set_configuration_value_string (cfg,
+ ectx, "NETWORK", "HOST",
buf);
+ dctx = GNUNET_DHT_context_create (cfg, ectx, &result_callback, &c);
+ 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 ("Peer %d gets key %d", i, j);
+ last = found;
+ get1 = GNUNET_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 (0 == (k % 10))
+ printf (".");
+ fflush (stdout);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (last < found)
+ break;
+ }
+ GNUNET_DHT_get_stop (dctx,
+ get1);
+ if (k < NUM_ROUNDS)
+ printf (" OK!\n");
+ else
+ printf ("?\n");
+ }
+ GNUNET_DHT_context_destroy (dctx);
+ }
}
-
- /* get loop */
- found = 0;
- for (i = 0; i < NUM_PEERS; i++)
- {
- 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, &c);
- for (j = 0; j < NUM_PEERS; j++)
- {
- c = 'A' + j;
- GNUNET_snprintf (buf, 128, "localhost:%u", 2087 + j * 10);
- GNUNET_hash (buf, strlen (buf), &key);
- printf ("Peer %d gets key %d", i, j);
- last = found;
- GNUNET_DHT_get_start (ctx_array[i],
- GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key);
- for (k = 0; k < NUM_ROUNDS; k++)
- {
- if (0 == (k % 10))
- printf (".");
- fflush (stdout);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (last < found)
- break;
- }
- GNUNET_DHT_get_stop (ctx_array[i],
- GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING, &key);
- if (k < NUM_ROUNDS)
- printf (" OK!\n");
- else
- printf ("?\n");
- }
- }
-
- 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);
- if (found < NUM_PEERS * NUM_PEERS / 2)
+ printf ("Found %u out of %u attempts.\n", found, NUM_PEERS * NUM_PEERS *
NUM_REPEAT);
+ if (found < NUM_PEERS * NUM_PEERS * NUM_REPEAT / 2)
{
printf
("Not enough results (not even 50%%), marking test as failed!\n");
Modified: GNUnet/src/applications/dht/tools/dht_twopeer_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_twopeer_test.c 2008-12-26
06:42:40 UTC (rev 8014)
+++ GNUnet/src/applications/dht/tools/dht_twopeer_test.c 2008-12-26
06:42:51 UTC (rev 8015)
@@ -31,8 +31,8 @@
#include "gnunet_testing_lib.h"
#include "gnunet_stats_lib.h"
#include "gnunet_util.h"
-#include "dht_api.h"
+
#define START_PEERS 1
#define NUM_ROUNDS 100
@@ -111,6 +111,7 @@
struct GNUNET_GC_Configuration *cfg;
struct GNUNET_DHT_Context *ctx_peer1;
struct GNUNET_DHT_Context *ctx_peer2;
+ struct GNUNET_DHT_GetRequest * get1;
struct GNUNET_ClientServerConnection *sock;
int left;
int k;
@@ -230,9 +231,9 @@
peer2count = 10;
printf ("Getting key 1 from peer 2 (stored at peer 1)");
want = 'A';
- CHECK (GNUNET_OK == GNUNET_DHT_get_start (ctx_peer2,
-
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key));
+ CHECK (NULL != (get1 = GNUNET_DHT_get_start (ctx_peer2,
+
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+ &key)));
for (k = 0; k < NUM_ROUNDS; k++)
{
if (0 == (k % 10))
@@ -243,8 +244,7 @@
break;
}
CHECK (GNUNET_OK == GNUNET_DHT_get_stop (ctx_peer2,
-
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key));
+ get1));
printf (peer2count < 10 ? " OK!\n" : "?\n");
CHECK (peer2count < 10);
@@ -252,9 +252,9 @@
GNUNET_hash ("key 2", 5, &key);
peer1count = 10;
want = 'B';
- CHECK (GNUNET_OK == GNUNET_DHT_get_start (ctx_peer1,
-
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key));
+ CHECK (NULL != (get1 = GNUNET_DHT_get_start (ctx_peer1,
+
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+ &key)));
for (k = 0; k < NUM_ROUNDS; k++)
{
if (0 == (k % 10))
@@ -265,8 +265,7 @@
break;
}
CHECK (GNUNET_OK == GNUNET_DHT_get_stop (ctx_peer1,
-
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key));
+ get1));
printf (peer1count < 10 ? " OK!\n" : "?\n");
CHECK (peer1count < 10);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r8015 - GNUnet/src/applications/dht/tools,
gnunet <=