[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r8321 - in GNUnet/src/applications/dht: module tools
From: |
gnunet |
Subject: |
[GNUnet-SVN] r8321 - in GNUnet/src/applications/dht: module tools |
Date: |
Wed, 11 Mar 2009 14:44:50 -0600 |
Author: nevans
Date: 2009-03-11 14:44:50 -0600 (Wed, 11 Mar 2009)
New Revision: 8321
Added:
GNUnet/src/applications/dht/tools/dv_dht-query.c
GNUnet/src/applications/dht/tools/dv_dht_api.c
GNUnet/src/applications/dht/tools/dv_dht_expiration_test.c
GNUnet/src/applications/dht/tools/dv_dht_forwarding_test.c
GNUnet/src/applications/dht/tools/dv_dht_loopback_test.c
GNUnet/src/applications/dht/tools/dv_dht_multipeer_test.c
GNUnet/src/applications/dht/tools/dv_dht_twopeer_test.c
Removed:
GNUnet/src/applications/dht/tools/dht-query.c
GNUnet/src/applications/dht/tools/dht_api.c
GNUnet/src/applications/dht/tools/dht_expiration_test.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
Modified:
GNUnet/src/applications/dht/module/Makefile.am
GNUnet/src/applications/dht/module/cs.c
GNUnet/src/applications/dht/module/routing.c
GNUnet/src/applications/dht/module/routing.h
GNUnet/src/applications/dht/module/service.c
GNUnet/src/applications/dht/module/service.h
GNUnet/src/applications/dht/module/table.c
GNUnet/src/applications/dht/module/table.h
GNUnet/src/applications/dht/tools/Makefile.am
Log:
dv_dht implementation
Modified: GNUnet/src/applications/dht/module/Makefile.am
===================================================================
--- GNUnet/src/applications/dht/module/Makefile.am 2009-03-10 10:27:04 UTC
(rev 8320)
+++ GNUnet/src/applications/dht/module/Makefile.am 2009-03-11 20:44:50 UTC
(rev 8321)
@@ -7,16 +7,16 @@
plugindir = $(libdir)/GNUnet
plugin_LTLIBRARIES = \
- libgnunetmodule_dht.la
+ libgnunetmodule_dv_dht.la
-libgnunetmodule_dht_la_SOURCES = \
+libgnunetmodule_dv_dht_la_SOURCES = \
cs.c \
routing.c routing.h \
service.c service.h \
table.c table.h
-libgnunetmodule_dht_la_LDFLAGS = \
+libgnunetmodule_dv_dht_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
-libgnunetmodule_dht_la_LIBADD = -lm \
+libgnunetmodule_dv_dht_la_LIBADD = -lm \
$(top_builddir)/src/applications/rpc/libgnunetrpcutil.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL)
Modified: GNUnet/src/applications/dht/module/cs.c
===================================================================
--- GNUnet/src/applications/dht/module/cs.c 2009-03-10 10:27:04 UTC (rev
8320)
+++ GNUnet/src/applications/dht/module/cs.c 2009-03-11 20:44:50 UTC (rev
8321)
@@ -20,17 +20,17 @@
/**
* @file module/cs.c
- * @brief DHT application protocol using the DHT service.
- * This is merely for the dht-client library. The code
+ * @brief DV_DHT application protocol using the DV_DHT service.
+ * This is merely for the dv_dht-client library. The code
* of this file is mostly converting from and to TCP messages.
- * @author Marko Räihä, Christian Grothoff
+ * @author Marko R., Christian Grothoff, Nathan Evans
*/
#include "platform.h"
#include "gnunet_core.h"
#include "gnunet_protocols.h"
#include "dht.h"
-#include "gnunet_dht_service.h"
+#include "gnunet_dv_dht_service.h"
#include "service.h"
#define DEBUG_CS GNUNET_NO
@@ -41,30 +41,30 @@
static GNUNET_CoreAPIForPlugins *coreAPI;
/**
- * Reference to the DHT service API.
+ * Reference to the DV_DHT service API.
*/
-static GNUNET_DHT_ServiceAPI *dhtAPI;
+static GNUNET_DV_DHT_ServiceAPI *dv_dhtAPI;
/**
* Type of the linked list that is used by CS to
* keep track of clients and their pending GET
* requests.
*/
-struct DHT_CLIENT_GET_RECORD
+struct DV_DHT_CLIENT_GET_RECORD
{
- struct DHT_CLIENT_GET_RECORD *next;
+ struct DV_DHT_CLIENT_GET_RECORD *next;
struct GNUNET_ClientHandle *client;
- struct GNUNET_DHT_GetHandle *get_record;
+ struct GNUNET_DV_DHT_GetHandle *get_record;
};
/**
* Linked list of active GET requests.
*/
-static struct DHT_CLIENT_GET_RECORD *getRecords;
+static struct DV_DHT_CLIENT_GET_RECORD *getRecords;
/**
* Lock.
@@ -72,7 +72,7 @@
static struct GNUNET_Mutex *lock;
/**
- * CS handler for inserting <key,value>-pair into DHT-table.
+ * CS handler for inserting <key,value>-pair into DV_DHT-table.
*/
static int
csPut (struct GNUNET_ClientHandle *client,
@@ -89,8 +89,8 @@
req = (const CS_dht_request_put_MESSAGE *) message;
size = ntohs (req->header.size) - sizeof (CS_dht_request_put_MESSAGE);
GNUNET_GE_ASSERT (NULL, size < GNUNET_MAX_BUFFER_SIZE);
- dhtAPI->put (&req->key, ntohl (req->type), size, (const char *) &req[1]);
- return coreAPI->cs_send_value (client, GNUNET_OK);
+ dv_dhtAPI->put (&req->key, ntohl (req->type), size, (const char *) &req[1]);
+ return coreAPI->cs_send_value (client, GNUNET_OK);
}
static int
@@ -98,7 +98,7 @@
unsigned int type,
unsigned int size, const char *value, void *cls)
{
- struct DHT_CLIENT_GET_RECORD *record = cls;
+ struct DV_DHT_CLIENT_GET_RECORD *record = cls;
CS_dht_request_put_MESSAGE *msg;
size_t n;
@@ -110,7 +110,7 @@
}
msg = GNUNET_malloc (n);
msg->header.size = htons (n);
- msg->header.type = htons (GNUNET_CS_PROTO_DHT_REQUEST_PUT);
+ msg->header.type = htons (GNUNET_CS_PROTO_DV_DHT_REQUEST_PUT);
msg->type = htonl (type);
msg->key = *key;
memcpy (&msg[1], value, size);
@@ -128,14 +128,14 @@
}
/**
- * CS handler for getting key from DHT.
+ * CS handler for getting key from DV_DHT.
*/
static int
csGet (struct GNUNET_ClientHandle *client,
const GNUNET_MessageHeader * message)
{
const CS_dht_request_get_MESSAGE *get;
- struct DHT_CLIENT_GET_RECORD *cpc;
+ struct DV_DHT_CLIENT_GET_RECORD *cpc;
if (ntohs (message->size) != sizeof (CS_dht_request_get_MESSAGE))
{
@@ -143,9 +143,9 @@
return GNUNET_SYSERR;
}
get = (const CS_dht_request_get_MESSAGE *) message;
- cpc = GNUNET_malloc (sizeof (struct DHT_CLIENT_GET_RECORD));
+ cpc = GNUNET_malloc (sizeof (struct DV_DHT_CLIENT_GET_RECORD));
cpc->client = client;
- cpc->get_record = dhtAPI->get_start (ntohl (get->type),
+ cpc->get_record = dv_dhtAPI->get_start (ntohl (get->type),
&get->key, &get_result, cpc);
GNUNET_mutex_lock (lock);
cpc->next = getRecords;
@@ -155,15 +155,15 @@
}
/**
- * CS handler for stopping existing get from DHT.
+ * CS handler for stopping existing get from DV_DHT.
*/
static int
csGetEnd (struct GNUNET_ClientHandle *client,
const GNUNET_MessageHeader * message)
{
const CS_dht_request_get_MESSAGE *get;
- struct DHT_CLIENT_GET_RECORD *pos;
- struct DHT_CLIENT_GET_RECORD *prev;
+ struct DV_DHT_CLIENT_GET_RECORD *pos;
+ struct DV_DHT_CLIENT_GET_RECORD *prev;
if (ntohs (message->size) != sizeof (CS_dht_request_get_MESSAGE))
{
@@ -194,7 +194,7 @@
else
prev->next = pos->next;
GNUNET_mutex_unlock (lock);
- dhtAPI->get_stop (pos->get_record);
+ dv_dhtAPI->get_stop (pos->get_record);
GNUNET_free (pos);
return GNUNET_OK;
@@ -207,9 +207,9 @@
static void
csClientExit (struct GNUNET_ClientHandle *client)
{
- struct GNUNET_DHT_GetHandle *gr;
- struct DHT_CLIENT_GET_RECORD *pos;
- struct DHT_CLIENT_GET_RECORD *prev;
+ struct GNUNET_DV_DHT_GetHandle *gr;
+ struct DV_DHT_CLIENT_GET_RECORD *pos;
+ struct DV_DHT_CLIENT_GET_RECORD *prev;
GNUNET_mutex_lock (lock);
pos = getRecords;
@@ -224,7 +224,7 @@
else
prev->next = pos->next;
GNUNET_mutex_unlock (lock);
- dhtAPI->get_stop (gr);
+ dv_dhtAPI->get_stop (gr);
GNUNET_free (pos);
GNUNET_mutex_lock (lock);
pos = getRecords;
@@ -237,29 +237,29 @@
}
int
-initialize_module_dht (GNUNET_CoreAPIForPlugins * capi)
+initialize_module_dv_dht (GNUNET_CoreAPIForPlugins * capi)
{
int status;
- dhtAPI = capi->service_request ("dht");
- if (dhtAPI == NULL)
+ dv_dhtAPI = capi->service_request ("dv_dht");
+ if (dv_dhtAPI == NULL)
return GNUNET_SYSERR;
coreAPI = capi;
GNUNET_GE_LOG (coreAPI->ectx,
GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
_("`%s' registering client handlers: %d %d\n"),
- "dht", GNUNET_CS_PROTO_DHT_REQUEST_PUT,
- GNUNET_CS_PROTO_DHT_REQUEST_GET);
+ "dv_dht", GNUNET_CS_PROTO_DV_DHT_REQUEST_PUT,
+ GNUNET_CS_PROTO_DV_DHT_REQUEST_GET);
status = GNUNET_OK;
lock = GNUNET_mutex_create (GNUNET_NO);
if (GNUNET_SYSERR ==
- capi->cs_handler_register (GNUNET_CS_PROTO_DHT_REQUEST_PUT, &csPut))
+ capi->cs_handler_register (GNUNET_CS_PROTO_DV_DHT_REQUEST_PUT, &csPut))
status = GNUNET_SYSERR;
if (GNUNET_SYSERR ==
- capi->cs_handler_register (GNUNET_CS_PROTO_DHT_REQUEST_GET, &csGet))
+ capi->cs_handler_register (GNUNET_CS_PROTO_DV_DHT_REQUEST_GET, &csGet))
status = GNUNET_SYSERR;
if (GNUNET_SYSERR ==
- capi->cs_handler_register (GNUNET_CS_PROTO_DHT_REQUEST_GET_END,
+ capi->cs_handler_register (GNUNET_CS_PROTO_DV_DHT_REQUEST_GET_END,
&csGetEnd))
status = GNUNET_SYSERR;
if (GNUNET_SYSERR == capi->cs_disconnect_handler_register (&csClientExit))
@@ -268,22 +268,22 @@
0 == GNUNET_GC_set_configuration_value_string (capi->cfg,
capi->ectx,
"ABOUT",
- "dht",
+ "dv_dht",
gettext_noop
- ("Enables
efficient non-anonymous routing")));
+ ("Enables
distance vector dht operation")));
return status;
}
/**
* Find the record, remove it from the linked list
- * and cancel the operation with the DHT API.
+ * and cancel the operation with the DV_DHT API.
*/
static void
kill_record (void *cls)
{
- struct DHT_CLIENT_GET_RECORD *record = cls;
- struct DHT_CLIENT_GET_RECORD *pos;
- struct DHT_CLIENT_GET_RECORD *prev;
+ struct DV_DHT_CLIENT_GET_RECORD *record = cls;
+ struct DV_DHT_CLIENT_GET_RECORD *pos;
+ struct DV_DHT_CLIENT_GET_RECORD *prev;
GNUNET_mutex_lock (lock);
pos = getRecords;
@@ -305,7 +305,7 @@
else
prev->next = pos->next;
GNUNET_mutex_unlock (lock);
- dhtAPI->get_stop (record->get_record);
+ dv_dhtAPI->get_stop (record->get_record);
GNUNET_free (record);
}
@@ -313,20 +313,20 @@
* Unregisters handlers, cleans memory structures etc when node exits.
*/
int
-done_module_dht ()
+done_module_dv_dht ()
{
int status;
status = GNUNET_OK;
GNUNET_GE_LOG (coreAPI->ectx,
GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
- "DHT: shutdown\n");
+ "DV_DHT: shutdown\n");
if (GNUNET_OK !=
- coreAPI->cs_handler_unregister (GNUNET_CS_PROTO_DHT_REQUEST_PUT,
+ coreAPI->cs_handler_unregister (GNUNET_CS_PROTO_DV_DHT_REQUEST_PUT,
&csPut))
status = GNUNET_SYSERR;
if (GNUNET_OK !=
- coreAPI->cs_handler_unregister (GNUNET_CS_PROTO_DHT_REQUEST_GET,
+ coreAPI->cs_handler_unregister (GNUNET_CS_PROTO_DV_DHT_REQUEST_GET,
&csGet))
status = GNUNET_SYSERR;
if (GNUNET_OK != coreAPI->cs_disconnect_handler_unregister (&csClientExit))
@@ -334,8 +334,8 @@
while (getRecords != NULL)
kill_record (getRecords);
- coreAPI->service_release (dhtAPI);
- dhtAPI = NULL;
+ coreAPI->service_release (dv_dhtAPI);
+ dv_dhtAPI = NULL;
coreAPI = NULL;
GNUNET_mutex_destroy (lock);
return status;
Modified: GNUnet/src/applications/dht/module/routing.c
===================================================================
--- GNUnet/src/applications/dht/module/routing.c 2009-03-10 10:27:04 UTC
(rev 8320)
+++ GNUnet/src/applications/dht/module/routing.c 2009-03-11 20:44:50 UTC
(rev 8321)
@@ -20,7 +20,7 @@
/**
* @file module/routing.c
- * @brief state for active DHT routing operations
+ * @brief state for active DV_DHT routing operations
* @author Christian Grothoff
*
* TODO:
@@ -34,29 +34,30 @@
#include "gnunet_protocols.h"
#include "gnunet_core.h"
#include "gnunet_stats_service.h"
+#include "gnunet_dv_service.h"
#define DEBUG_ROUTING GNUNET_NO
/**
- * What is the request priority for DHT operations?
+ * What is the request priority for DV_DHT operations?
*/
-#define DHT_PRIORITY 0
+#define DV_DHT_PRIORITY 0
/**
- * What is the estimated per-hop delay for DHT operations
+ * What is the estimated per-hop delay for DV_DHT operations
* (this is how much we will request from the GNUnet core);
* Must not be zero!
*/
-#define DHT_DELAY (500 * GNUNET_CRON_MILLISECONDS)
+#define DV_DHT_DELAY (500 * GNUNET_CRON_MILLISECONDS)
/**
- * What is the maximum number of results returned by any DHT
+ * What is the maximum number of results returned by any DV_DHT
* operation?
*/
#define MAX_RESULTS 64
/**
- * How many peers should a DHT GET request reach on averge?
+ * How many peers should a DV_DHT GET request reach on averge?
*
* Larger factors will result in more aggressive routing of GET
* operations (each peer will either forward to GET_TRIES peers that
@@ -65,7 +66,7 @@
#define GET_TRIES 7
/**
- * At how many peers should a DHT PUT request be replicated
+ * At how many peers should a DV_DHT PUT request be replicated
* on average?
*
* Larger factors will result in more replication and
@@ -83,13 +84,13 @@
/**
* @brief record used for sending response back
*/
-typedef struct DHT_Source_Route
+typedef struct DV_DHT_Source_Route
{
/**
* This is a linked list.
*/
- struct DHT_Source_Route *next;
+ struct DV_DHT_Source_Route *next;
/**
* Source of the request. Replies should be forwarded to
@@ -111,10 +112,10 @@
*/
GNUNET_CronTime expire;
-} DHT_Source_Route;
+} DV_DHT_Source_Route;
/**
- * @brief message send for DHT get, put or result.
+ * @brief message send for DV_DHT get, put or result.
* PUT and RESULT messages are followed by
* the content. "header.type" distinguishes
* the three types of messages.
@@ -146,12 +147,12 @@
*/
GNUNET_HashCode key;
-} DHT_MESSAGE;
+} DV_DHT_MESSAGE;
/**
- * Entry in the DHT routing table.
+ * Entry in the DV_DHT routing table.
*/
-typedef struct DHTQueryRecord
+typedef struct DV_DHTQueryRecord
{
/**
@@ -163,12 +164,12 @@
/**
* Information about where to send the results back to.
*/
- DHT_Source_Route *sources;
+ DV_DHT_Source_Route *sources;
/**
* GET message of this record (what we are forwarding).
*/
- DHT_MESSAGE get;
+ DV_DHT_MESSAGE get;
/**
* Hashcodes of the results that we have send back
@@ -181,12 +182,12 @@
*/
unsigned int result_count;
-} DHTQueryRecord;
+} DV_DHTQueryRecord;
/**
* Linked list of active records.
*/
-static DHTQueryRecord *records;
+static DV_DHTQueryRecord *records;
/**
* Size of records
@@ -200,6 +201,8 @@
static GNUNET_Dstore_ServiceAPI *dstore;
+static GNUNET_DV_ServiceAPI *dvapi;
+
static struct GNUNET_Mutex *lock;
static GNUNET_CoreAPIForPlugins *coreAPI;
@@ -227,7 +230,7 @@
unsigned int target_value;
unsigned int diameter;
- diameter = GNUNET_DHT_estimate_network_diameter ();
+ diameter = GNUNET_DV_DHT_estimate_network_diameter ();
if (hop_count > (diameter + 1) * 2)
return 0;
target_count =
@@ -253,16 +256,16 @@
unsigned int type,
unsigned int size, const char *data, void *cls)
{
- DHTQueryRecord *q;
+ DV_DHTQueryRecord *q;
unsigned int i;
unsigned int j;
int found;
GNUNET_HashCode hc;
- DHT_MESSAGE *result;
+ DV_DHT_MESSAGE *result;
unsigned int routed;
unsigned int tracked;
- DHT_Source_Route *pos;
- DHT_Source_Route *prev;
+ DV_DHT_Source_Route *pos;
+ DV_DHT_Source_Route *prev;
GNUNET_CronTime now;
#if DEBUG_ROUTING
GNUNET_EncName enc;
@@ -280,12 +283,12 @@
}
else
{
- result = GNUNET_malloc (sizeof (DHT_MESSAGE) + size);
- result->header.size = htons (sizeof (DHT_MESSAGE) + size);
+ 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);
result->type = htonl (type);
result->hop_count = htonl (0);
- result->network_size = htonl (GNUNET_DHT_estimate_network_diameter ());
+ result->network_size = htonl (GNUNET_DV_DHT_estimate_network_diameter
());
result->key = *key;
memcpy (&result[1], data, size);
}
@@ -357,9 +360,10 @@
GNUNET_GE_DEVELOPER,
"Routing result to `%s'\n", &enc);
#endif
- coreAPI->ciphertext_send (&pos->source,
- &result->header, DHT_PRIORITY,
- DHT_DELAY);
+ dvapi->dv_send(&pos->source,
+ &result->header, DV_DHT_PRIORITY,
+ DV_DHT_DELAY);
+
if (stats != NULL)
stats->change (stat_replies_routed, 1);
}
@@ -398,23 +402,23 @@
*/
static int
add_route (const GNUNET_PeerIdentity * sender,
- GNUNET_ResultProcessor handler, void *cls, const DHT_MESSAGE * get)
+ GNUNET_ResultProcessor handler, void *cls, const DV_DHT_MESSAGE *
get)
{
- DHTQueryRecord *q;
+ DV_DHTQueryRecord *q;
unsigned int i;
unsigned int rt_pos;
unsigned int diameter;
GNUNET_CronTime expire;
GNUNET_CronTime now;
unsigned int hops;
- struct DHT_Source_Route *pos;
+ struct DV_DHT_Source_Route *pos;
hops = ntohl (get->hop_count);
- diameter = GNUNET_DHT_estimate_network_diameter ();
+ diameter = GNUNET_DV_DHT_estimate_network_diameter ();
if (hops > 2 * diameter)
return GNUNET_SYSERR;
now = GNUNET_get_time ();
- expire = now + DHT_DELAY * diameter * 4;
+ expire = now + DV_DHT_DELAY * diameter * 4;
GNUNET_mutex_lock (lock);
rt_pos = rt_size;
for (i = 0; i < rt_size; i++)
@@ -458,7 +462,7 @@
if (q->expire < expire)
q->expire = expire;
q->get = *get;
- pos = GNUNET_malloc (sizeof (DHT_Source_Route));
+ pos = GNUNET_malloc (sizeof (DV_DHT_Source_Route));
pos->next = q->sources;
q->sources = pos;
if (sender != NULL)
@@ -487,8 +491,8 @@
const GNUNET_MessageHeader * msg)
{
GNUNET_PeerIdentity next[GET_TRIES + 1];
- const DHT_MESSAGE *get;
- DHT_MESSAGE aget;
+ const DV_DHT_MESSAGE *get;
+ DV_DHT_MESSAGE aget;
unsigned int target_value;
unsigned int hop_count;
int total;
@@ -499,19 +503,19 @@
GNUNET_EncName henc;
#endif
- if (ntohs (msg->size) != sizeof (DHT_MESSAGE))
+ if (ntohs (msg->size) != sizeof (DV_DHT_MESSAGE))
{
GNUNET_GE_BREAK (NULL, 0);
return GNUNET_SYSERR;
}
- get = (const DHT_MESSAGE *) msg;
+ get = (const DV_DHT_MESSAGE *) msg;
#if DEBUG_ROUTING
GNUNET_hash_to_enc (&get->key, &enc);
if (sender != NULL)
GNUNET_hash_to_enc (&sender->hashPubKey, &henc);
GNUNET_GE_LOG (coreAPI->ectx,
GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_DEVELOPER,
- "Received DHT GET for key `%s' from `%s'.\n", &enc,
+ "Received DV_DHT GET for key `%s' from `%s'.\n", &enc,
sender == NULL ? "me" : (char *) &henc);
#endif
if (stats != NULL)
@@ -544,7 +548,7 @@
aget.hop_count = htonl (1 + hop_count);
aget.network_size =
htonl (ntohl (get->network_size) +
- GNUNET_DHT_estimate_network_diameter ());
+ GNUNET_DV_DHT_estimate_network_diameter ());
if (target_value > GET_TRIES)
target_value = GET_TRIES;
j = 0;
@@ -553,7 +557,7 @@
for (i = 0; i < target_value; i++)
{
if (GNUNET_OK !=
- GNUNET_DHT_select_peer (&next[j], &get->key, &next[0], j))
+ GNUNET_DV_DHT_select_peer (&next[j], &get->key, &next[0], j))
{
#if DEBUG_ROUTING
GNUNET_GE_LOG (coreAPI->ectx,
@@ -569,10 +573,10 @@
GNUNET_GE_LOG (coreAPI->ectx,
GNUNET_GE_DEBUG | GNUNET_GE_REQUEST |
GNUNET_GE_DEVELOPER,
- "Forwarding DHT GET request to peer `%s'.\n", &enc);
+ "Forwarding DV_DHT GET request to peer `%s'.\n", &enc);
#endif
- coreAPI->ciphertext_send (&next[j], &aget.header, DHT_PRIORITY,
- DHT_DELAY);
+ dvapi->dv_send(&next[j], &aget.header, DV_DHT_PRIORITY,
+ DV_DHT_DELAY);
j++;
}
return GNUNET_OK;
@@ -586,8 +590,8 @@
const GNUNET_MessageHeader * msg)
{
GNUNET_PeerIdentity next[PUT_TRIES + 1];
- const DHT_MESSAGE *put;
- DHT_MESSAGE *aput;
+ const DV_DHT_MESSAGE *put;
+ DV_DHT_MESSAGE *aput;
GNUNET_CronTime now;
unsigned int hop_count;
unsigned int target_value;
@@ -598,19 +602,19 @@
GNUNET_EncName enc;
#endif
- if (ntohs (msg->size) < sizeof (DHT_MESSAGE))
+ if (ntohs (msg->size) < sizeof (DV_DHT_MESSAGE))
{
GNUNET_GE_BREAK (NULL, 0);
return GNUNET_SYSERR;
}
if (stats != NULL)
stats->change (stat_put_requests_received, 1);
- put = (const DHT_MESSAGE *) msg;
+ put = (const DV_DHT_MESSAGE *) msg;
#if DEBUG_ROUTING
GNUNET_hash_to_enc (&put->key, &enc);
GNUNET_GE_LOG (coreAPI->ectx,
GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_DEVELOPER,
- "Received DHT PUT for key `%s'.\n", &enc);
+ "Received DV_DHT PUT for key `%s'.\n", &enc);
#endif
store = 0;
hop_count = htons (put->hop_count);
@@ -620,7 +624,7 @@
aput->hop_count = htons (hop_count + 1);
aput->network_size =
htonl (ntohl (put->network_size) +
- GNUNET_DHT_estimate_network_diameter ());
+ GNUNET_DV_DHT_estimate_network_diameter ());
if (target_value > PUT_TRIES)
target_value = PUT_TRIES;
j = 0;
@@ -629,7 +633,7 @@
for (i = 0; i < target_value; i++)
{
if (GNUNET_OK !=
- GNUNET_DHT_select_peer (&next[j], &put->key, &next[0], j))
+ GNUNET_DV_DHT_select_peer (&next[j], &put->key, &next[0], j))
{
#if DEBUG_ROUTING
GNUNET_GE_LOG (coreAPI->ectx,
@@ -650,10 +654,10 @@
GNUNET_GE_LOG (coreAPI->ectx,
GNUNET_GE_DEBUG | GNUNET_GE_REQUEST |
GNUNET_GE_DEVELOPER,
- "Forwarding DHT PUT request to peer `%s'.\n", &enc);
+ "Forwarding DV_DHT PUT request to peer `%s'.\n", &enc);
#endif
- coreAPI->ciphertext_send (&next[j], &aput->header, DHT_PRIORITY,
- DHT_DELAY);
+ dvapi->dv_send (&next[j], &aput->header, DV_DHT_PRIORITY,
+ DV_DHT_DELAY);
j++;
}
GNUNET_free (aput);
@@ -665,13 +669,13 @@
GNUNET_GE_DEBUG | GNUNET_GE_REQUEST |
GNUNET_GE_DEVELOPER,
"Decided to cache data `%.*s' locally until %llu (for
%llu ms)\n",
- ntohs (put->header.size) - sizeof (DHT_MESSAGE),
+ ntohs (put->header.size) - sizeof (DV_DHT_MESSAGE),
&put[1], CONTENT_LIFETIME + now, CONTENT_LIFETIME);
#endif
dstore->put (&put->key,
ntohl (put->type),
CONTENT_LIFETIME + now,
- ntohs (put->header.size) - sizeof (DHT_MESSAGE),
+ ntohs (put->header.size) - sizeof (DV_DHT_MESSAGE),
(const char *) &put[1]);
}
else
@@ -695,56 +699,56 @@
handle_result (const GNUNET_PeerIdentity * sender,
const GNUNET_MessageHeader * msg)
{
- const DHT_MESSAGE *result;
+ const DV_DHT_MESSAGE *result;
#if DEBUG_ROUTING
GNUNET_EncName enc;
#endif
- if (ntohs (msg->size) < sizeof (DHT_MESSAGE))
+ if (ntohs (msg->size) < sizeof (DV_DHT_MESSAGE))
{
GNUNET_GE_BREAK (NULL, 0);
return GNUNET_SYSERR;
}
if (stats != NULL)
stats->change (stat_results_received, 1);
- result = (const DHT_MESSAGE *) msg;
+ result = (const DV_DHT_MESSAGE *) msg;
#if DEBUG_ROUTING
GNUNET_hash_to_enc (&result->key, &enc);
GNUNET_GE_LOG (coreAPI->ectx,
GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_DEVELOPER,
- "Received REMOTE DHT RESULT for key `%s'.\n", &enc);
+ "Received REMOTE DV_DHT RESULT for key `%s'.\n", &enc);
#endif
route_result (&result->key,
ntohl (result->type),
- ntohs (result->header.size) - sizeof (DHT_MESSAGE),
+ ntohs (result->header.size) - sizeof (DV_DHT_MESSAGE),
(const char *) &result[1], (void *) msg);
return GNUNET_OK;
}
/**
- * Start a DHT get operation.
+ * Start a DV_DHT get operation.
*/
int
-GNUNET_DHT_get_start (const GNUNET_HashCode * key,
+GNUNET_DV_DHT_get_start (const GNUNET_HashCode * key,
unsigned int type, GNUNET_ResultProcessor handler,
void *cls)
{
- DHT_MESSAGE get;
+ DV_DHT_MESSAGE get;
#if DEBUG_ROUTING
GNUNET_EncName enc;
#endif
- get.header.size = htons (sizeof (DHT_MESSAGE));
+ get.header.size = htons (sizeof (DV_DHT_MESSAGE));
get.header.type = htons (GNUNET_P2P_PROTO_DHT_GET);
get.type = htonl (type);
get.hop_count = htonl (0);
- get.network_size = htonl (GNUNET_DHT_estimate_network_diameter ());
+ get.network_size = htonl (GNUNET_DV_DHT_estimate_network_diameter ());
get.key = *key;
#if DEBUG_ROUTING
GNUNET_hash_to_enc (&get.key, &enc);
GNUNET_GE_LOG (coreAPI->ectx,
GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_DEVELOPER,
- "Initiating DHT GET (based on local request) for key `%s'.\n",
+ "Initiating DV_DHT GET (based on local request) for key
`%s'.\n",
&enc);
#endif
if (GNUNET_OK != add_route (NULL, handler, cls, &get))
@@ -754,17 +758,17 @@
}
/**
- * Stop a DHT get operation (prevents calls to
+ * Stop a DV_DHT get operation (prevents calls to
* the given iterator).
*/
int
-GNUNET_DHT_get_stop (const GNUNET_HashCode * key,
+GNUNET_DV_DHT_get_stop (const GNUNET_HashCode * key,
unsigned int type, GNUNET_ResultProcessor handler,
void *cls)
{
unsigned int i;
- struct DHT_Source_Route *pos;
- struct DHT_Source_Route *prev;
+ struct DV_DHT_Source_Route *pos;
+ struct DV_DHT_Source_Route *prev;
int done;
done = GNUNET_NO;
@@ -806,7 +810,7 @@
}
/**
- * Perform a DHT put operation. Note that PUT operations always
+ * Perform a DV_DHT put operation. Note that PUT operations always
* expire after a period of time and the client is responsible for
* doing periodic refreshs. The given expiration time is ONLY used to
* ensure that the datum is certainly deleted by that time (it maybe
@@ -815,18 +819,18 @@
* @param expiration_time absolute expiration time
*/
int
-GNUNET_DHT_put (const GNUNET_HashCode * key,
+GNUNET_DV_DHT_put (const GNUNET_HashCode * key,
unsigned int type, unsigned int size, const char *data)
{
- DHT_MESSAGE *put;
+ DV_DHT_MESSAGE *put;
- put = GNUNET_malloc (sizeof (DHT_MESSAGE) + size);
- put->header.size = htons (sizeof (DHT_MESSAGE) + size);
+ put = GNUNET_malloc (sizeof (DV_DHT_MESSAGE) + size);
+ put->header.size = htons (sizeof (DV_DHT_MESSAGE) + size);
put->header.type = htons (GNUNET_P2P_PROTO_DHT_PUT);
put->key = *key;
put->type = htonl (type);
put->hop_count = htonl (0);
- put->network_size = htonl (GNUNET_DHT_estimate_network_diameter ());
+ put->network_size = htonl (GNUNET_DV_DHT_estimate_network_diameter ());
memcpy (&put[1], data, size);
handle_put (NULL, &put->header);
GNUNET_free (put);
@@ -850,13 +854,13 @@
}
/**
- * Initialize routing DHT component.
+ * Initialize routing DV_DHT component.
*
* @param capi the core API
* @return GNUNET_OK on success
*/
int
-GNUNET_DHT_init_routing (GNUNET_CoreAPIForPlugins * capi)
+GNUNET_DV_DHT_init_routing (GNUNET_CoreAPIForPlugins * capi)
{
unsigned long long rts;
@@ -869,6 +873,9 @@
dstore = coreAPI->service_request ("dstore");
if (dstore == NULL)
return GNUNET_SYSERR;
+ dvapi = coreAPI->service_request ("dv");
+ if (dvapi == NULL)
+ return GNUNET_SYSERR;
GNUNET_array_grow (records, rt_size, rts);
lock = GNUNET_mutex_create (GNUNET_NO);
@@ -876,21 +883,21 @@
if (stats != NULL)
{
stat_replies_routed =
- stats->create (gettext_noop ("# dht replies routed"));
+ stats->create (gettext_noop ("# dv_dht replies routed"));
stat_requests_routed =
- stats->create (gettext_noop ("# dht requests routed"));
+ stats->create (gettext_noop ("# dv_dht requests routed"));
stat_get_requests_received =
- stats->create (gettext_noop ("# dht get requests received"));
+ stats->create (gettext_noop ("# dv_dht get requests received"));
stat_put_requests_received =
- stats->create (gettext_noop ("# dht put requests received"));
+ stats->create (gettext_noop ("# dv_dht put requests received"));
stat_results_received =
- stats->create (gettext_noop ("# dht results received"));
+ stats->create (gettext_noop ("# dv_dht results received"));
}
GNUNET_GE_LOG (coreAPI->ectx,
GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
_("`%s' registering p2p handlers: %d %d %d\n"),
- "dht", GNUNET_P2P_PROTO_DHT_GET, GNUNET_P2P_PROTO_DHT_PUT,
+ "dv_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,
&handle_get);
@@ -898,23 +905,23 @@
&handle_put);
coreAPI->p2p_ciphertext_handler_register (GNUNET_P2P_PROTO_DHT_RESULT,
&handle_result);
- coreAPI->send_callback_register (sizeof (DHT_MESSAGE), 0,
+ coreAPI->send_callback_register (sizeof (DV_DHT_MESSAGE), 0,
&extra_get_callback);
return GNUNET_OK;
}
/**
- * Shutdown routing DHT component.
+ * Shutdown routing DV_DHT component.
*
* @return GNUNET_OK on success
*/
int
-GNUNET_DHT_done_routing ()
+GNUNET_DV_DHT_done_routing ()
{
unsigned int i;
- struct DHT_Source_Route *pos;
+ struct DV_DHT_Source_Route *pos;
- coreAPI->send_callback_unregister (sizeof (DHT_MESSAGE),
+ coreAPI->send_callback_unregister (sizeof (DV_DHT_MESSAGE),
&extra_get_callback);
coreAPI->p2p_ciphertext_handler_unregister (GNUNET_P2P_PROTO_DHT_GET,
&handle_get);
Modified: GNUnet/src/applications/dht/module/routing.h
===================================================================
--- GNUnet/src/applications/dht/module/routing.h 2009-03-10 10:27:04 UTC
(rev 8320)
+++ GNUnet/src/applications/dht/module/routing.h 2009-03-11 20:44:50 UTC
(rev 8321)
@@ -20,55 +20,55 @@
/**
* @file module/routing.h
- * @brief state for active DHT routing operations
+ * @brief state for active DV_DHT routing operations
* @author Christian Grothoff
*/
-#ifndef DHT_ROUTING_H
-#define DHT_ROUTING_H
+#ifndef DV_DHT_ROUTING_H
+#define DV_DHT_ROUTING_H
#include "gnunet_util.h"
#include "gnunet_core.h"
#include "gnunet_dstore_service.h"
/**
- * Start a DHT get operation.
+ * Start a DV_DHT get operation.
*/
-int GNUNET_DHT_get_start (const GNUNET_HashCode * key,
+int GNUNET_DV_DHT_get_start (const GNUNET_HashCode * key,
unsigned int type, GNUNET_ResultProcessor handler,
void *cls);
/**
- * Stop a DHT get operation (prevents calls to
+ * Stop a DV_DHT get operation (prevents calls to
* the given iterator).
*/
-int GNUNET_DHT_get_stop (const GNUNET_HashCode * key,
+int GNUNET_DV_DHT_get_stop (const GNUNET_HashCode * key,
unsigned int type, GNUNET_ResultProcessor handler,
void *cls);
/**
- * Perform a DHT put operation. Note that PUT operations always
+ * Perform a DV_DHT put operation. Note that PUT operations always
* expire after a period of time and the client is responsible for
* doing periodic refreshs.
*
* @param expiration_time absolute expiration time
*/
-int GNUNET_DHT_put (const GNUNET_HashCode * key,
+int GNUNET_DV_DHT_put (const GNUNET_HashCode * key,
unsigned int type, unsigned int size, const char *data);
/**
- * Initialize routing DHT component.
+ * Initialize routing DV_DHT component.
*
* @param capi the core API
* @return GNUNET_OK on success
*/
-int GNUNET_DHT_init_routing (GNUNET_CoreAPIForPlugins * capi);
+int GNUNET_DV_DHT_init_routing (GNUNET_CoreAPIForPlugins * capi);
/**
- * Shutdown routing DHT component.
+ * Shutdown routing DV_DHT component.
*
* @return GNUNET_OK on success
*/
-int GNUNET_DHT_done_routing (void);
+int GNUNET_DV_DHT_done_routing (void);
#endif
Modified: GNUnet/src/applications/dht/module/service.c
===================================================================
--- GNUnet/src/applications/dht/module/service.c 2009-03-10 10:27:04 UTC
(rev 8320)
+++ GNUnet/src/applications/dht/module/service.c 2009-03-11 20:44:50 UTC
(rev 8321)
@@ -20,13 +20,13 @@
/**
* @file module/service.c
- * @brief internal GNUnet DHT service
+ * @brief internal GNUnet DV_DHT service
* @author Christian Grothoff
*/
#include "platform.h"
#include "table.h"
#include "routing.h"
-#include "gnunet_dht_service.h"
+#include "gnunet_dv_dht_service.h"
#include "service.h"
/**
@@ -35,7 +35,7 @@
static GNUNET_CoreAPIForPlugins *coreAPI;
/**
- * Perform an asynchronous GET operation on the DHT identified by
+ * Perform an asynchronous GET operation on the DV_DHT identified by
* 'table' using 'key' as the key. The peer does not have to be part
* of the table (if so, we will attempt to locate a peer that is!).
*
@@ -50,19 +50,19 @@
* @param cls extra argument to callback
* @return handle to stop the async get
*/
-static struct GNUNET_DHT_GetHandle *
-dht_get_async_start (unsigned int type,
+static struct GNUNET_DV_DHT_GetHandle *
+dv_dht_get_async_start (unsigned int type,
const GNUNET_HashCode * key,
GNUNET_ResultProcessor callback, void *cls)
{
- struct GNUNET_DHT_GetHandle *ret;
+ struct GNUNET_DV_DHT_GetHandle *ret;
- ret = GNUNET_malloc (sizeof (struct GNUNET_DHT_GetHandle));
+ ret = GNUNET_malloc (sizeof (struct GNUNET_DV_DHT_GetHandle));
ret->key = *key;
ret->callback = callback;
ret->cls = cls;
ret->type = type;
- if (GNUNET_OK != GNUNET_DHT_get_start (key, type, callback, cls))
+ if (GNUNET_OK != GNUNET_DV_DHT_get_start (key, type, callback, cls))
{
GNUNET_free (ret);
return NULL;
@@ -71,55 +71,55 @@
}
/**
- * Stop async DHT-get. Frees associated resources.
+ * Stop async DV_DHT-get. Frees associated resources.
*/
static int
-dht_get_async_stop (struct GNUNET_DHT_GetHandle *record)
+dv_dht_get_async_stop (struct GNUNET_DV_DHT_GetHandle *record)
{
- GNUNET_DHT_get_stop (&record->key, record->type, record->callback,
+ GNUNET_DV_DHT_get_stop (&record->key, record->type, record->callback,
record->cls);
GNUNET_free (record);
return GNUNET_OK;
}
/**
- * Provide the DHT service. The DHT service depends on the RPC
- * service.
+ * Provide the DV DV_DHT service. The DV DV_DHT service depends on the
+ * RPC and DV services.
*
* @param capi the core API
- * @return NULL on errors, DHT_API otherwise
+ * @return NULL on errors, DV_DHT_API otherwise
*/
-GNUNET_DHT_ServiceAPI *
-provide_module_dht (GNUNET_CoreAPIForPlugins * capi)
+GNUNET_DV_DHT_ServiceAPI *
+provide_module_dv_dht (GNUNET_CoreAPIForPlugins * capi)
{
- static GNUNET_DHT_ServiceAPI api;
+ static GNUNET_DV_DHT_ServiceAPI api;
- if (GNUNET_OK != GNUNET_DHT_table_init (capi))
+ if (GNUNET_OK != GNUNET_DV_DHT_table_init (capi))
{
GNUNET_GE_BREAK (capi->ectx, 0);
return NULL;
}
- if (GNUNET_OK != GNUNET_DHT_init_routing (capi))
+ if (GNUNET_OK != GNUNET_DV_DHT_init_routing (capi))
{
GNUNET_GE_BREAK (capi->ectx, 0);
- GNUNET_DHT_table_done ();
+ GNUNET_DV_DHT_table_done ();
return NULL;
}
coreAPI = capi;
- api.get_start = &dht_get_async_start;
- api.get_stop = &dht_get_async_stop;
- api.put = &GNUNET_DHT_put;
+ api.get_start = &dv_dht_get_async_start;
+ api.get_stop = &dv_dht_get_async_stop;
+ api.put = &GNUNET_DV_DHT_put;
return &api;
}
/**
- * Shutdown DHT service.
+ * Shutdown DV_DHT service.
*/
int
-release_module_dht ()
+release_module_dv_dht ()
{
- GNUNET_DHT_done_routing ();
- GNUNET_DHT_table_done ();
+ GNUNET_DV_DHT_done_routing ();
+ GNUNET_DV_DHT_table_done ();
return GNUNET_OK;
}
Modified: GNUnet/src/applications/dht/module/service.h
===================================================================
--- GNUnet/src/applications/dht/module/service.h 2009-03-10 10:27:04 UTC
(rev 8320)
+++ GNUnet/src/applications/dht/module/service.h 2009-03-11 20:44:50 UTC
(rev 8321)
@@ -20,7 +20,7 @@
/**
* @file module/service.h
- * @brief internal GNUnet DHT service
+ * @brief internal GNUnet DV_DHT service
* @author Christian Grothoff
*/
@@ -30,7 +30,7 @@
/**
* Handle used to track GET activity.
*/
-struct GNUNET_DHT_GetHandle
+struct GNUNET_DV_DHT_GetHandle
{
/**
* Key that we are looking for.
Modified: GNUnet/src/applications/dht/module/table.c
===================================================================
--- GNUnet/src/applications/dht/module/table.c 2009-03-10 10:27:04 UTC (rev
8320)
+++ GNUnet/src/applications/dht/module/table.c 2009-03-11 20:44:50 UTC (rev
8321)
@@ -20,10 +20,10 @@
/**
* @file module/table.c
- * @brief maintains table of DHT connections of this peer
+ * @brief maintains table of DV_DHT connections of this peer
* @author Christian Grothoff
*
- * New DHT infrastructure plan:
+ * New DV_DHT infrastructure plan:
* - no RPC, pure async messaging
* - stateful routing; needed for retry and reply routing
* - no per-table storage; instead global,
@@ -31,18 +31,18 @@
* - no delete operation, just get/put + expiration
* - no "put" confirmation, try a get to confirm important put!
* - modules:
- * + table.c: DHT-peer table, peer discovery cron jobs;
+ * + table.c: DV_DHT-peer table, peer discovery cron jobs;
* code tries to fill table "as much as possible" over time;
* TODO: expose and improve reliabily metrics (to be added later)???
- * TODO: better randomized neighbor selection in DHT_select_peer???
+ * TODO: better randomized neighbor selection in DV_DHT_select_peer???
* TODO: add callback for discovery-message padding (use core callback
* for extra-available bandwidth)
* TODO: add LAN tunnels for increased connectivity choices
* + routing.c: tracking of get/put operations, retry, reply handling
* code tries best-match routing among entries in table
- * + service.c: provide DHT services to rest of GNUnet process
+ * + service.c: provide DV_DHT services to rest of GNUnet process
* (i.e. register datastore with shared data, get/put operations)
- * + cs.c: services to out-of-process DHT clients (via dht-lib)
+ * + cs.c: services to out-of-process DV_DHT clients (via dv_dht-lib)
*/
#include "platform.h"
@@ -50,14 +50,15 @@
#include "table.h"
#include "gnunet_protocols.h"
#include "gnunet_util.h"
-#include "gnunet_dht_service.h"
+#include "gnunet_dv_dht_service.h"
#include "gnunet_stats_service.h"
#include "gnunet_identity_service.h"
#include "gnunet_pingpong_service.h"
+#include "gnunet_dv_service.h"
/**
- * How often should the cron job for maintaining the DHT
+ * How often should the cron job for maintaining the DV_DHT
* run?
*/
#define MAINTAIN_FREQUENCY 1500 * GNUNET_CRON_MILLISECONDS
@@ -74,7 +75,7 @@
#define MAINTAIN_PEER_TIMEOUT MAINTAIN_FREQUENCY * MAINTAIN_CHANCE * 4
/**
- * What is the maximum number of known DHT-enabled peers
+ * What is the maximum number of known DV_DHT-enabled peers
* advertised for each DISCOVERY message?
*/
#define MAINTAIN_ADV_CAP 8
@@ -155,6 +156,8 @@
*/
static GNUNET_CoreAPIForPlugins *coreAPI;
+static GNUNET_DV_ServiceAPI *dvapi;
+
/**
* The buckets (Kademlia style routing table).
*/
@@ -201,7 +204,7 @@
/**
* The struct is followed by zero or more
* PeerIdentities that the sender knows to
- * be participating in the DHT.
+ * be participating in the DV_DHT.
*/
typedef struct
{
@@ -210,11 +213,11 @@
unsigned int space_available;
-} P2P_DHT_Discovery;
+} P2P_DV_DHT_Discovery;
/**
* Request for a HELLO for another peer that is participating in the
- * DHT. Receiver is expected to send back a HELLO for the peer that
+ * DV_DHT. Receiver is expected to send back a HELLO for the peer that
* is being requested.
*/
typedef struct
@@ -226,7 +229,7 @@
GNUNET_PeerIdentity peer;
-} P2P_DHT_ASK_HELLO;
+} P2P_DV_DHT_ASK_HELLO;
/**
* Compute a (rough) estimate of the networks diameter.
@@ -234,7 +237,7 @@
* @return estimated network diameter
*/
unsigned int
-GNUNET_DHT_estimate_network_diameter ()
+GNUNET_DV_DHT_estimate_network_diameter ()
{
unsigned int i;
for (i = bucketCount - 1; i > 0; i--)
@@ -288,7 +291,7 @@
/**
* Find the PeerInfo for the given peer. Returns NULL if peer is not
- * in our DHT routing table.
+ * in our DV_DHT routing table.
*/
static PeerInfo *
findPeerEntryInBucket (PeerBucket * bucket, const GNUNET_PeerIdentity * peer)
@@ -306,7 +309,7 @@
/**
* Find the PeerInfo for the given peer. Returns NULL if peer is not
- * in our DHT routing table.
+ * in our DV_DHT routing table.
*/
static PeerInfo *
findPeerEntry (const GNUNET_PeerIdentity * peer)
@@ -352,7 +355,7 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int
-GNUNET_DHT_select_peer (GNUNET_PeerIdentity * set,
+GNUNET_DV_DHT_select_peer (GNUNET_PeerIdentity * set,
const GNUNET_HashCode * target,
const GNUNET_PeerIdentity * blocked,
unsigned int blocked_size)
@@ -434,12 +437,12 @@
/**
* Send a discovery message to the other peer.
*
- * @param cls NULL or pre-build discovery message
+ * @param cls NULL or pre-built discovery message
*/
static void
broadcast_dht_discovery (const GNUNET_PeerIdentity * other, void *cls)
{
- P2P_DHT_Discovery *disco = cls;
+ P2P_DV_DHT_Discovery *disco = cls;
unsigned int pc;
unsigned int i;
GNUNET_PeerIdentity *pos;
@@ -448,7 +451,7 @@
stats->change (stat_dht_advertisements, 1);
if (disco != NULL)
{
- coreAPI->ciphertext_send (other,
+ dvapi->dv_send (other,
&disco->header,
GNUNET_EXTREME_PRIORITY / 4,
MAINTAIN_FREQUENCY * MAINTAIN_CHANCE / 2);
@@ -461,7 +464,7 @@
pc = 1;
disco =
GNUNET_malloc (pc * sizeof (GNUNET_PeerIdentity) +
- sizeof (P2P_DHT_Discovery));
+ sizeof (P2P_DV_DHT_Discovery));
disco->header.type = htons (GNUNET_P2P_PROTO_DHT_DISCOVERY);
disco->space_available = -1; /* FIXME */
pos = (GNUNET_PeerIdentity *) & disco[1];
@@ -476,14 +479,14 @@
while (i < pc)
{
if (GNUNET_OK !=
- GNUNET_DHT_select_peer (&pos[i], &other->hashPubKey, pos, i))
+ GNUNET_DV_DHT_select_peer (&pos[i], &other->hashPubKey, pos, i))
pc--;
else
i++;
}
disco->header.size =
- htons (pc * sizeof (GNUNET_PeerIdentity) + sizeof (P2P_DHT_Discovery));
- coreAPI->ciphertext_send (other, &disco->header, 0,
+ htons (pc * sizeof (GNUNET_PeerIdentity) + sizeof (P2P_DV_DHT_Discovery));
+ dvapi->dv_send (other, &disco->header, 0,
MAINTAIN_FREQUENCY * MAINTAIN_CHANCE / 2);
GNUNET_free (disco);
}
@@ -497,23 +500,25 @@
}
/**
- * Cron job to maintain DHT routing table.
+ * Cron job to maintain DV_DHT routing table.
*/
static void
maintain_dht_job (void *unused)
{
- P2P_DHT_Discovery disc;
+ P2P_DV_DHT_Discovery disc;
if (total_peers == 0)
{
- disc.header.size = htons (sizeof (P2P_DHT_Discovery));
+ disc.header.size = htons (sizeof (P2P_DV_DHT_Discovery));
disc.header.type = htons (GNUNET_P2P_PROTO_DHT_DISCOVERY);
disc.space_available = -1; /* FIXME */
- coreAPI->p2p_connections_iterate (&broadcast_dht_discovery_prob, &disc);
+ dvapi->dv_connections_iterate(&broadcast_dht_discovery_prob, &disc);
+ /*coreAPI->p2p_connections_iterate (&broadcast_dht_discovery_prob,
&disc);*/
}
else
{
- coreAPI->p2p_connections_iterate (&broadcast_dht_discovery_prob, NULL);
+ dvapi->dv_connections_iterate(&broadcast_dht_discovery_prob, NULL);
+ /*coreAPI->p2p_connections_iterate (&broadcast_dht_discovery_prob,
NULL);*/
}
}
@@ -559,7 +564,7 @@
* Check if pi is still up and running. May also try
* to confirm that the peer is still live.
*
- * @return GNUNET_YES if the peer should be removed from the DHT table
+ * @return GNUNET_YES if the peer should be removed from the DV_DHT table
*/
static int
checkExpired (PeerInfo * pi)
@@ -603,7 +608,7 @@
}
/**
- * Consider adding the given peer to the DHT.
+ * Consider adding the given peer to the DV_DHT.
*/
static void
considerPeer (const GNUNET_PeerIdentity * sender,
@@ -611,7 +616,7 @@
{
PeerInfo *pi;
PeerBucket *bucket;
- P2P_DHT_ASK_HELLO ask;
+ P2P_DV_DHT_ASK_HELLO ask;
GNUNET_MessageHello *hello;
bucket = findBucketFor (peer);
@@ -630,11 +635,11 @@
if (hello == NULL)
{
/* if identity not known, ask sender for HELLO of other peer */
- ask.header.size = htons (sizeof (P2P_DHT_ASK_HELLO));
+ ask.header.size = htons (sizeof (P2P_DV_DHT_ASK_HELLO));
ask.header.type = htons (sizeof (GNUNET_P2P_PROTO_DHT_ASK_HELLO));
ask.reserved = 0;
ask.peer = *peer;
- coreAPI->ciphertext_send (sender, &ask.header, 0, /* FIXME: priority */
+ dvapi->dv_send (sender, &ask.header, 0, /* FIXME: priority */
5 * GNUNET_CRON_SECONDS);
return;
}
@@ -668,24 +673,24 @@
{
unsigned int pc;
unsigned int i;
- const P2P_DHT_Discovery *disco;
+ const P2P_DV_DHT_Discovery *disco;
const GNUNET_PeerIdentity *peers;
pc =
(ntohs (msg->size) -
- sizeof (P2P_DHT_Discovery)) / sizeof (GNUNET_PeerIdentity);
+ sizeof (P2P_DV_DHT_Discovery)) / sizeof (GNUNET_PeerIdentity);
if (pc > MAINTAIN_ADV_CAP * 8)
{
GNUNET_GE_BREAK_OP (coreAPI->ectx, 0);
return GNUNET_SYSERR; /* far too big */
}
if (ntohs (msg->size) !=
- sizeof (P2P_DHT_Discovery) + pc * sizeof (GNUNET_PeerIdentity))
+ sizeof (P2P_DV_DHT_Discovery) + pc * sizeof (GNUNET_PeerIdentity))
{
GNUNET_GE_BREAK_OP (coreAPI->ectx, 0);
return GNUNET_SYSERR; /* malformed */
}
- disco = (const P2P_DHT_Discovery *) msg;
+ disco = (const P2P_DV_DHT_Discovery *) msg;
if (stats != NULL)
stats->change (stat_dht_discoveries, 1);
if (pc == 0)
@@ -709,15 +714,15 @@
handleAskHello (const GNUNET_PeerIdentity * sender,
const GNUNET_MessageHeader * msg)
{
- const P2P_DHT_ASK_HELLO *ask;
+ const P2P_DV_DHT_ASK_HELLO *ask;
GNUNET_MessageHello *hello;
- if (ntohs (msg->size) != sizeof (P2P_DHT_ASK_HELLO))
+ if (ntohs (msg->size) != sizeof (P2P_DV_DHT_ASK_HELLO))
{
GNUNET_GE_BREAK_OP (coreAPI->ectx, 0);
return GNUNET_SYSERR;
}
- ask = (const P2P_DHT_ASK_HELLO *) msg;
+ ask = (const P2P_DV_DHT_ASK_HELLO *) msg;
if (NULL == findBucketFor (&ask->peer))
return GNUNET_OK;
hello =
@@ -726,7 +731,7 @@
GNUNET_NO);
if (hello == NULL)
return GNUNET_OK;
- coreAPI->ciphertext_send (sender, &hello->header, 0,
+ dvapi->dv_send (sender, &hello->header, 0,
5 * GNUNET_CRON_SECONDS);
GNUNET_free (hello);
return GNUNET_OK;
@@ -753,19 +758,19 @@
}
/**
- * Initialize table DHT component.
+ * Initialize table DV_DHT component.
*
* @param capi the core API
* @return GNUNET_OK on success
*/
int
-GNUNET_DHT_table_init (GNUNET_CoreAPIForPlugins * capi)
+GNUNET_DV_DHT_table_init (GNUNET_CoreAPIForPlugins * capi)
{
unsigned long long i;
coreAPI = capi;
/* use less than 50% of peer's ideal number of
- connections for DHT table size */
+ connections for DV_DHT table size */
i = coreAPI->core_slots_count () / MAINTAIN_BUCKET_SIZE / 2;
if (i < 4)
i = 4;
@@ -777,16 +782,18 @@
}
lock = capi->global_lock_get ();
stats = capi->service_request ("stats");
+ dvapi = capi->service_request ("dv");
+ GNUNET_GE_ASSERT (coreAPI->ectx, dvapi != NULL);
if (stats != NULL)
{
stat_dht_total_peers =
- stats->create (gettext_noop ("# dht connections"));
+ stats->create (gettext_noop ("# dv_dht connections"));
stat_dht_discoveries =
- stats->create (gettext_noop ("# dht discovery messages received"));
+ stats->create (gettext_noop ("# dv_dht discovery messages received"));
stat_dht_route_looks =
- stats->create (gettext_noop ("# dht route host lookups performed"));
+ stats->create (gettext_noop ("# dv_dht route host lookups performed"));
stat_dht_advertisements =
- stats->create (gettext_noop ("# dht discovery messages sent"));
+ stats->create (gettext_noop ("# dv_dht discovery messages sent"));
}
identity = coreAPI->service_request ("identity");
GNUNET_GE_ASSERT (coreAPI->ectx, identity != NULL);
@@ -804,12 +811,12 @@
}
/**
- * Shutdown table DHT component.
+ * Shutdown table DV_DHT component.
*
* @return GNUNET_OK on success
*/
int
-GNUNET_DHT_table_done ()
+GNUNET_DV_DHT_table_done ()
{
unsigned int i;
unsigned int j;
Modified: GNUnet/src/applications/dht/module/table.h
===================================================================
--- GNUnet/src/applications/dht/module/table.h 2009-03-10 10:27:04 UTC (rev
8320)
+++ GNUnet/src/applications/dht/module/table.h 2009-03-11 20:44:50 UTC (rev
8321)
@@ -20,12 +20,12 @@
/**
* @file module/table.h
- * @brief DHT connection table internal API
+ * @brief DV_DHT connection table internal API
* @author Christian Grothoff
*/
-#ifndef DHT_TABLE_H
-#define DHT_TABLE_H
+#ifndef DV_DHT_TABLE_H
+#define DV_DHT_TABLE_H
#include "gnunet_util.h"
#include "gnunet_core.h"
@@ -42,7 +42,7 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
-int GNUNET_DHT_select_peer (GNUNET_PeerIdentity * set,
+int GNUNET_DV_DHT_select_peer (GNUNET_PeerIdentity * set,
const GNUNET_HashCode * target,
const GNUNET_PeerIdentity * blocked,
unsigned int blocked_size);
@@ -52,21 +52,21 @@
*
* @return estimated network diameter
*/
-unsigned int GNUNET_DHT_estimate_network_diameter (void);
+unsigned int GNUNET_DV_DHT_estimate_network_diameter (void);
/**
- * Initialize table DHT component.
+ * Initialize table DV_DHT component.
*
* @param capi the core API
* @return GNUNET_OK on success
*/
-int GNUNET_DHT_table_init (GNUNET_CoreAPIForPlugins * capi);
+int GNUNET_DV_DHT_table_init (GNUNET_CoreAPIForPlugins * capi);
/**
- * Shutdown table DHT component.
+ * Shutdown table DV_DHT component.
*
* @return GNUNET_OK on success
*/
-int GNUNET_DHT_table_done (void);
+int GNUNET_DV_DHT_table_done (void);
#endif
Modified: GNUnet/src/applications/dht/tools/Makefile.am
===================================================================
--- GNUnet/src/applications/dht/tools/Makefile.am 2009-03-10 10:27:04 UTC
(rev 8320)
+++ GNUnet/src/applications/dht/tools/Makefile.am 2009-03-11 20:44:50 UTC
(rev 8321)
@@ -5,24 +5,24 @@
endif
lib_LTLIBRARIES = \
- libgnunetdhtapi.la
+ libgnunetdvdhtapi.la
noinst_PROGRAMS = \
- gnunet-dht-query
+ gnunet-dv-dht-query
-libgnunetdhtapi_la_SOURCES = \
- dht_api.c
-libgnunetdhtapi_la_LDFLAGS = \
+libgnunetdvdhtapi_la_SOURCES = \
+ dv_dht_api.c
+libgnunetdvdhtapi_la_LDFLAGS = \
$(GN_LIB_LDFLAGS)
-libgnunetdhtapi_la_LIBADD = \
+libgnunetdvdhtapi_la_LIBADD = \
$(top_builddir)/src/applications/stats/libgnunetstatsapi.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL)
-gnunet_dht_query_SOURCES = \
- dht-query.c
-gnunet_dht_query_LDADD = \
- $(top_builddir)/src/applications/dht/tools/libgnunetdhtapi.la \
+gnunet_dv_dht_query_SOURCES = \
+ dv_dht-query.c
+gnunet_dv_dht_query_LDADD = \
+ $(top_builddir)/src/applications/dv_dht/tools/libgnunetdvdhtapi.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL)
@@ -30,18 +30,18 @@
check_PROGRAMS = \
- dht_loopback_test \
- dht_twopeer_test \
- dht_multipeer_test
+ dv_dht_loopback_test \
+ dv_dht_twopeer_test \
+ dv_dht_multipeer_test
TESTS = $(check_PROGRAMS)
-dht_loopback_test_SOURCES = \
- dht_loopback_test.c
-dht_loopback_test_LDADD = \
+dv_dht_loopback_test_SOURCES = \
+ dv_dht_loopback_test.c
+dv_dht_loopback_test_LDADD = \
$(top_builddir)/src/applications/stats/libgnunetstatsapi.la \
$(top_builddir)/src/applications/testing/libgnunettestingapi.la \
- $(top_builddir)/src/applications/dht/tools/libgnunetdhtapi.la \
+ $(top_builddir)/src/applications/dv_dht/tools/libgnunetdvdhtapi.la \
$(top_builddir)/src/util/libgnunetutil.la
# This test requires an API change before we can
@@ -51,23 +51,23 @@
#dht_expiration_test_LDADD = \
# $(top_builddir)/src/applications/stats/libgnunetstatsapi.la \
# $(top_builddir)/src/applications/testing/libgnunettestingapi.la \
-# $(top_builddir)/src/applications/dht/tools/libgnunetdhtapi.la \
+# $(top_builddir)/src/applications/dv_dht/tools/libgnunetdvdhtapi.la \
# $(top_builddir)/src/util/libgnunetutil.la
-dht_twopeer_test_SOURCES = \
- dht_twopeer_test.c
-dht_twopeer_test_LDADD = \
+dv_dht_twopeer_test_SOURCES = \
+ dv_dht_twopeer_test.c
+dv_dht_twopeer_test_LDADD = \
$(top_builddir)/src/applications/stats/libgnunetstatsapi.la \
$(top_builddir)/src/applications/testing/libgnunettestingapi.la \
- $(top_builddir)/src/applications/dht/tools/libgnunetdhtapi.la \
+ $(top_builddir)/src/applications/dv_dht/tools/libgnunetdvdhtapi.la \
$(top_builddir)/src/util/libgnunetutil.la
-dht_multipeer_test_SOURCES = \
- dht_multipeer_test.c
-dht_multipeer_test_LDADD = \
+dv_dht_multipeer_test_SOURCES = \
+ dv_dht_multipeer_test.c
+dv_dht_multipeer_test_LDADD = \
$(top_builddir)/src/applications/stats/libgnunetstatsapi.la \
$(top_builddir)/src/applications/testing/libgnunettestingapi.la \
- $(top_builddir)/src/applications/dht/tools/libgnunetdhtapi.la \
+ $(top_builddir)/src/applications/dv_dht/tools/libgnunetdvdhtapi.la \
$(top_builddir)/src/util/libgnunetutil.la
EXTRA_DIST = \
Deleted: GNUnet/src/applications/dht/tools/dht-query.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht-query.c 2009-03-10 10:27:04 UTC
(rev 8320)
+++ GNUnet/src/applications/dht/tools/dht-query.c 2009-03-11 20:44:50 UTC
(rev 8321)
@@ -1,191 +0,0 @@
-/*
- This file is part of GNUnet
- (C) 2004, 2005, 2006 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-query.c
- * @brief perform DHT operations (insert, lookup)
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_directories.h"
-#include "gnunet_protocols.h"
-#include "gnunet_util.h"
-#include "gnunet_dht_lib.h"
-
-#define DEBUG_DHT_QUERY GNUNET_NO
-
-/**
- * How long should a "GET" run (or how long should
- * content last on the network).
- */
-static GNUNET_CronTime timeout = 30 * GNUNET_CRON_SECONDS;
-
-static struct GNUNET_GE_Context *ectx;
-
-static struct GNUNET_GC_Configuration *cfg;
-
-static char *cfgFilename = GNUNET_DEFAULT_CLIENT_CONFIG_FILE;
-
-struct GNUNET_DHT_Context *ctx;
-
-/**
- * All gnunet-dht-query command line options
- */
-static struct GNUNET_CommandLineOption gnunetqueryOptions[] = {
- GNUNET_COMMAND_LINE_OPTION_CFG_FILE (&cfgFilename), /* -c */
- GNUNET_COMMAND_LINE_OPTION_HELP (gettext_noop ("Query (get KEY, put KEY
VALUE) DHT table.")), /* -h */
- GNUNET_COMMAND_LINE_OPTION_HOSTNAME, /* -H */
- GNUNET_COMMAND_LINE_OPTION_LOGGING, /* -L */
- {'T', "timeout", "TIME",
- gettext_noop ("allow TIME ms to process a GET command"),
- 1, &GNUNET_getopt_configure_set_ulong, &timeout},
- GNUNET_COMMAND_LINE_OPTION_VERSION (PACKAGE_VERSION), /* -v */
- GNUNET_COMMAND_LINE_OPTION_VERBOSE,
- GNUNET_COMMAND_LINE_OPTION_END,
-};
-
-static int
-printCallback (const GNUNET_HashCode * hash,
- unsigned int type,
- unsigned int size, const char *data, void *unused)
-{
- printf ("%s: `%.*s'\n", "get", size, data);
- return GNUNET_OK;
-}
-
-static void
-do_get (struct GNUNET_ClientServerConnection *sock, const char *key)
-{
- struct GNUNET_DHT_GetRequest *ret;
- GNUNET_HashCode hc;
-
- GNUNET_hash (key, strlen (key), &hc);
-#if DEBUG_DHT_QUERY
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
- "Issuing `%s(%s)' command.\n", "get", key);
-#endif
- ret = GNUNET_DHT_get_start (ctx, GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &hc);
- if (ret == NULL)
- {
- printf ("`%s(%s)' failed.\n", "get", key);
- return;
- }
- GNUNET_thread_sleep (timeout);
- GNUNET_DHT_get_stop (ctx, ret);
-}
-
-static void
-do_put (struct GNUNET_ClientServerConnection *sock,
- const char *key, const char *value)
-{
- GNUNET_HashCode hc;
-
- GNUNET_hash (key, strlen (key), &hc);
-#if DEBUG_DHT_QUERY
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
- _("Issuing `%s(%s,%s)' command.\n"), "put", key, value);
-#endif
- if (GNUNET_OK ==
- GNUNET_DHT_put (cfg, ectx, &hc, GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- strlen (value), value))
- {
- printf ("`%s(%s,%s)' succeeded\n", "put", key, value);
- }
- else
- {
- printf ("`%s(%s,%s)' failed.\n", "put", key, value);
- }
-}
-
-int
-main (int argc, char *const *argv)
-{
- int i;
- struct GNUNET_ClientServerConnection *handle;
-
- i = GNUNET_init (argc,
- argv,
- "gnunet-dht-query",
- &cfgFilename, gnunetqueryOptions, &ectx, &cfg);
- if (i == -1)
- {
- GNUNET_fini (ectx, cfg);
- return -1;
- }
-
- handle = GNUNET_client_connection_create (ectx, cfg);
-
- ctx = GNUNET_DHT_context_create (cfg, ectx, &printCallback, NULL);
- if (handle == NULL)
- {
- fprintf (stderr, _("Failed to connect to gnunetd.\n"));
- GNUNET_GC_free (cfg);
- GNUNET_GE_free_context (ectx);
- return 1;
- }
-
- while (i < argc)
- {
- if (0 == strcmp ("get", argv[i]))
- {
- if (i + 2 > argc)
- {
- fprintf (stderr,
- _("Command `%s' requires an argument (`%s').\n"),
- "get", "key");
- break;
- }
- else
- {
- do_get (handle, argv[i + 1]);
- i += 2;
- }
- continue;
- }
- if (0 == strcmp ("put", argv[i]))
- {
- if (i + 3 > argc)
- {
- fprintf (stderr,
- _
- ("Command `%s' requires two arguments (`%s' and
`%s').\n"),
- "put", "key", "value");
- break;
- }
- else
- {
- do_put (handle, argv[i + 1], argv[i + 2]);
- i += 3;
- }
- continue;
- }
- fprintf (stderr, _("Unsupported command `%s'. Aborting.\n"), argv[i]);
- break;
- }
- GNUNET_client_connection_destroy (handle);
- GNUNET_fini (ectx, cfg);
- return 0;
-}
-
-/* end of dht-query.c */
Deleted: GNUnet/src/applications/dht/tools/dht_api.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_api.c 2009-03-10 10:27:04 UTC (rev
8320)
+++ GNUnet/src/applications/dht/tools/dht_api.c 2009-03-11 20:44:50 UTC (rev
8321)
@@ -1,357 +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.c
- * @brief DHT-module's core API's implementation.
- * @author Tomi Tukiainen, Christian Grothoff, Nathan Evans
- */
-#include "platform.h"
-#include "gnunet_protocols.h"
-#include "dht.h"
-#include "gnunet_dht_lib.h"
-#include "gnunet_stats_lib.h"
-#include "gnunet_util.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 ((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)))
- {
- fprintf (stderr,
- "Received message of type %u and size %u\n",
- ntohs (reply->type), ntohs (reply->size));
- GNUNET_GE_BREAK (NULL, 0);
- GNUNET_free (reply);
- break; /* invalid reply */
- }
- size = ntohs (reply->size) - sizeof (CS_dht_request_put_MESSAGE);
- put = (CS_dht_request_put_MESSAGE *) reply;
- if ((info->processor != NULL) &&
- (GNUNET_OK != info->processor (&put->key,
- ntohl (put->type),
- size,
- (const char *) &put[1],
- info->closure)))
- info->aborted = GNUNET_YES;
- GNUNET_free (reply);
- }
- info->aborted = GNUNET_YES;
- return NULL;
-}
-
-/**
- * Set up a context for performing asynchronous DHT operations.
- *
- * @param resultCallback function to call for results,
- * the operation also aborts if the callback returns
- * GNUNET_SYSERR
- * @return NULL on error
- */
-struct GNUNET_DHT_Context *
-GNUNET_DHT_context_create (struct GNUNET_GC_Configuration
- *cfg,
- struct GNUNET_GE_Context
- *ectx,
- GNUNET_ResultProcessor
- resultCallback, void *resCallbackClosure)
-{
- struct GNUNET_DHT_Context *ctx;
- struct GNUNET_ClientServerConnection *sock;
-
- 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->poll_thread = GNUNET_thread_create (&poll_thread, ctx, 1024 * 8);
- if (ctx->poll_thread == NULL)
- {
- GNUNET_client_connection_destroy (sock);
- GNUNET_mutex_destroy (ctx->lock);
- GNUNET_free (ctx);
- return NULL;
- }
- return ctx;
-}
-
-
-/**
- * Start 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
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-struct GNUNET_DHT_GetRequest *
-GNUNET_DHT_get_start (struct GNUNET_DHT_Context *ctx,
- unsigned int type, const GNUNET_HashCode * key)
-{
- struct GNUNET_DHT_GetRequest *req;
-
- 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 req request to stop
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-int
-GNUNET_DHT_get_stop (struct GNUNET_DHT_Context *ctx,
- struct GNUNET_DHT_GetRequest *req)
-{
- CS_dht_request_get_MESSAGE creq;
-
- 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;
- GNUNET_free (req);
- return GNUNET_OK;
-}
-
-/**
- * Destroy a previously created context for DHT operations.
- *
- * @param ctx context to destroy
- * @return GNUNET_SYSERR on error
- */
-int
-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;
-}
-
-/**
- * Perform a synchronous put operation. The peer does not have
- * to be part of the table!
- *
- * @param table table to use for the lookup
- * @param key the key to store
- * @param value what to store
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-int
-GNUNET_DHT_put (struct GNUNET_GC_Configuration *cfg,
- struct GNUNET_GE_Context *ectx,
- const GNUNET_HashCode * key,
- unsigned int type, unsigned int size, const char *value)
-{
- struct GNUNET_ClientServerConnection *sock;
- CS_dht_request_put_MESSAGE *req;
- int ret;
- int ret2;
-
-#if DEBUG_DHT_API
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
- "DHT_LIB_put called with value '%.*s'\n", size, value);
-#endif
- sock = GNUNET_client_connection_create (ectx, cfg);
- if (sock == NULL)
- return GNUNET_SYSERR;
- req = GNUNET_malloc (sizeof (CS_dht_request_put_MESSAGE) + size);
- req->header.size = htons (sizeof (CS_dht_request_put_MESSAGE) + size);
- req->header.type = htons (GNUNET_CS_PROTO_DHT_REQUEST_PUT);
- req->key = *key;
- req->type = htonl (type);
- memcpy (&req[1], value, size);
- ret = GNUNET_client_connection_write (sock, &req->header);
- if ( (GNUNET_OK != GNUNET_client_connection_read_result (sock, &ret2)) ||
- (ret2 != GNUNET_OK) )
- ret = GNUNET_SYSERR;
- GNUNET_client_connection_destroy (sock);
- GNUNET_free (req);
- return ret;
-}
-
-static int
-waitForConnect (const char *name, unsigned long long value, void *cls)
-{
- unsigned long long * ok = cls;
- if ((value > 0) && (0 == strcmp (_("# dht connections"), name)))
- {
- *ok = value;
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-/**
- * Check if this peer has DHT connections to
- * any other peer.
- *
- * @param sock connection to gnunetd
- * @return number of connections
- */
-unsigned long long
-GNUNET_DHT_test_connected(struct GNUNET_ClientServerConnection *sock)
-{
- unsigned long long ret;
-
- GNUNET_STATS_get_statistics (NULL, sock, &waitForConnect, &ret);
- return ret;
-}
-
-
-/* end of dht_api.c */
Deleted: GNUnet/src/applications/dht/tools/dht_expiration_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_expiration_test.c 2009-03-10
10:27:04 UTC (rev 8320)
+++ GNUnet/src/applications/dht/tools/dht_expiration_test.c 2009-03-11
20:44:50 UTC (rev 8321)
@@ -1,122 +0,0 @@
-/*
- 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 */
Deleted: GNUnet/src/applications/dht/tools/dht_loopback_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_loopback_test.c 2009-03-10
10:27:04 UTC (rev 8320)
+++ GNUnet/src/applications/dht/tools/dht_loopback_test.c 2009-03-11
20:44:50 UTC (rev 8321)
@@ -1,162 +0,0 @@
-/*
- 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_loopback_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 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))
- {
- err = 1;
- return GNUNET_SYSERR;
- }
- found = 1;
- return GNUNET_OK;
-}
-
-#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;
- 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"))
- {
- 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, &i);
- CHECK (ctx != NULL);
- /* actual test code */
- GNUNET_hash ("key_for_A", 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));
- i = 'A';
- 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,
- ectx,
- &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 (NULL != (get2 = GNUNET_DHT_get_start (ctx,
-
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- &key)));
- left = 10;
- 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);
-#endif
- GNUNET_free (value);
- GNUNET_GC_free (cfg);
- return ret;
-}
-
-/* end of dht_loopback_test.c */
Deleted: GNUnet/src/applications/dht/tools/dht_multipeer_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_multipeer_test.c 2009-03-10
10:27:04 UTC (rev 8320)
+++ GNUnet/src/applications/dht/tools/dht_multipeer_test.c 2009-03-11
20:44:50 UTC (rev 8321)
@@ -1,274 +0,0 @@
-/*
- 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/dht/tools/dht_multipeer_test.c
- * @brief DHT testcase
- * @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"
-
-/**
- * How many peers should the testcase run? Note that
- * we create a clique topology so the cost is quadratic!
- */
-#define NUM_PEERS 8
-
-/**
- * How many times will we try the DHT-GET operation before
- * giving up for good?
- */
-#define NUM_ROUNDS 20
-
-/**
- * How often do we iterate the put-get loop?
- */
-#define NUM_REPEAT 5
-
-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];
-
- memset (expect, (*i), sizeof (expect));
-#if 0
- fprintf (stderr, "Got %u %u `%.*s' (want `%.*s')\n", type, size, size, data,
- sizeof (expect), expect);
-#endif
- 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)))
- {
- 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)
-
-/**
- * Testcase to test DHT routing (many peers).
- * @return 0: ok, -1: error
- */
-int
-main (int argc, const char **argv)
-{
- struct GNUNET_TESTING_DaemonContext *peers;
- int ret = 0;
- GNUNET_HashCode key;
- char value[8];
- struct GNUNET_GE_Context *ectx;
- struct GNUNET_GC_Configuration *cfg;
- struct GNUNET_ClientServerConnection *sock;
- 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];
-
- ectx = NULL;
- cfg = GNUNET_GC_create ();
- if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
- {
- GNUNET_GC_free (cfg);
- return -1;
- }
- printf ("Starting %u peers...\n", NUM_PEERS);
- peers = GNUNET_TESTING_start_daemons ("tcp",
- "advertising dht stats",
- "/tmp/gnunet-dht-multi-test",
- 2087, 10, NUM_PEERS);
- if (peers == NULL)
- {
- GNUNET_GC_free (cfg);
- return -1;
- }
- for (i = 0; i < NUM_PEERS; i++)
- {
- for (j = 0; j < i; j++)
- {
- if (GNUNET_OK != GNUNET_TESTING_connect_daemons (2087 + 10 * i,
- 2087 + 10 * j))
- {
- GNUNET_TESTING_stop_daemons (peers);
- fprintf (stderr, "Failed to connect the peers!\n");
- GNUNET_GC_free (cfg);
- return -1;
- }
- }
- }
- found = 0;
- for (r = 0; r < NUM_REPEAT; r++)
- {
- if (r > 0)
- {
- printf ("Found %u out of %u attempts.\n", found,
- NUM_PEERS * NUM_PEERS * r);
- if (found >= NUM_PEERS * NUM_PEERS * r / 2)
- break; /* good enough */
- }
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- /* put loop */
- printf ("Waiting for DHT connections of peer");
- 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);
- 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? */
- 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);
- 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);
- memset (value, 'A' + i, sizeof (value));
- CHECK (GNUNET_OK == GNUNET_DHT_put (cfg,
- ectx,
- &key,
-
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- sizeof (value), value));
- }
- printf ("\n");
- /* get 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);
- dctx = GNUNET_DHT_context_create (cfg, ectx, &result_callback, &c);
- 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", j);
- fflush (stdout);
- 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 (9 == (k % 10))
- {
- printf (".");
- fflush (stdout);
- }
- fflush (stdout);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (last < found)
- break;
- }
- GNUNET_DHT_get_stop (dctx, get1);
- if (k == NUM_ROUNDS)
- {
- printf ("?");
- fflush (stdout);
- }
- }
- GNUNET_DHT_context_destroy (dctx);
- printf ("\n");
- }
- }
- /* end of actual test code */
- if (r == NUM_REPEAT)
- printf ("Found %u out of %u 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;
- }
-FAILURE:
- GNUNET_TESTING_stop_daemons (peers);
- GNUNET_GC_free (cfg);
- return ret;
-}
-
-/* end of dht_multipeer_test.c */
Deleted: GNUnet/src/applications/dht/tools/dht_twopeer_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_twopeer_test.c 2009-03-10
10:27:04 UTC (rev 8320)
+++ GNUnet/src/applications/dht/tools/dht_twopeer_test.c 2009-03-11
20:44:50 UTC (rev 8321)
@@ -1,229 +0,0 @@
-/*
- 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/dht_twopeer_test.c
- * @brief DHT testcase
- * @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
-
-#define NUM_ROUNDS 100
-
-#define CHECK(a) do { if (!(a)) { ret = 1; GNUNET_GE_BREAK(NULL, 0); goto
FAILURE; } } while(0)
-
-struct PeerData
-{
- struct GNUNET_GC_Configuration *cfg;
- struct GNUNET_DHT_Context *ctx_peer;
- struct GNUNET_ClientServerConnection *sock;
- int peercount;
- int expect_i;
-};
-
-static int
-test_connected(struct GNUNET_ClientServerConnection *sock)
-{
- int left = 50;
- unsigned long long have;
- while (0 == (have = GNUNET_DHT_test_connected(sock)))
- {
- printf ("."); fflush (stdout);
- sleep (2);
- left--;
- if (left == 0)
- break;
- }
- printf ((have > 0) ? " OK!\n" : "?\n");
- return have > 0;
-}
-
-static int
-result_callback (const GNUNET_HashCode * key,
- unsigned int type,
- unsigned int size, const char *data, void *cls)
-{
- struct PeerData * pd = cls;
- char expect[8];
-
-#if 0
- fprintf (stderr, "Got %u %u `%.*s'\n", type, size, size, data);
-#endif
- memset (expect, pd->expect_i, sizeof (expect));
- if ((8 != size) ||
- (0 != memcmp (expect, data, size)) ||
- (type != GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING))
- return GNUNET_SYSERR;
- pd->peercount--;
- return GNUNET_OK;
-}
-
-static int
-setup_peer(struct PeerData * pd,
- const char * pstr)
-{
- int ret = 0;
- pd->cfg = GNUNET_GC_create ();
- CHECK (-1 != GNUNET_GC_parse_configuration (pd->cfg, "check.conf"));
- GNUNET_GC_set_configuration_value_string (pd->cfg,
- NULL,
- "NETWORK", "HOST",
- "localhost:22087");
- pd->sock = GNUNET_client_connection_create (NULL, pd->cfg);
- pd->ctx_peer =
- GNUNET_DHT_context_create (pd->cfg, NULL, &result_callback, pd);
- FAILURE:
- return ret;
-}
-
-static void
-free_peer (struct PeerData * pd)
-{
- if (NULL != pd->ctx_peer)
- GNUNET_DHT_context_destroy (pd->ctx_peer);
- if (NULL != pd->sock)
- GNUNET_client_connection_destroy (pd->sock);
- if (NULL != pd->cfg)
- GNUNET_GC_free (pd->cfg);
-}
-
-static int
-put_at_peer(struct PeerData * pd,
- const char * keys,
- int val)
-{
- int ret = 0;
- char value[8];
- GNUNET_HashCode key;
-
- GNUNET_hash (keys, 5, &key);
- memset (value, val, sizeof (value));
- CHECK (GNUNET_OK == GNUNET_DHT_put (pd->cfg,
- NULL,
- &key,
- GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
- sizeof (value), value));
- FAILURE:
- return ret;
-}
-
-static int
-get_at_peer(struct PeerData * pd,
- const char * keys,
- int want)
-{
- int ret = 0;
- GNUNET_HashCode key;
- struct GNUNET_DHT_GetRequest *get;
- int k;
-
- GNUNET_hash (keys, 5, &key);
- pd->peercount = 10;
- pd->expect_i = want;
- CHECK (NULL != (get = GNUNET_DHT_get_start (pd->ctx_peer,
-
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 (pd->peercount < 10)
- break;
- }
- CHECK (GNUNET_OK == GNUNET_DHT_get_stop (pd->ctx_peer, get));
- printf (pd->peercount < 10 ? " OK!\n" : "?\n");
- CHECK (pd->peercount < 10);
- FAILURE:
- return ret;
-}
-
-
-/**
- * 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;
- struct PeerData p1;
- struct PeerData p2;
-
- memset(&p1, 0, sizeof(struct PeerData));
- memset(&p2, 0, sizeof(struct PeerData));
-#if START_PEERS
- fprintf (stderr, "Starting peers...\n");
- peers = GNUNET_TESTING_start_daemons ("tcp",
- "advertising dht stats",
- "/tmp/gnunet-dht-two-test",
- 22087, 10, 2);
- CHECK (peers != NULL);
-#endif
- CHECK(0 == setup_peer(&p1, "localhost:22087"));
- CHECK(0 == setup_peer(&p2, "localhost:22097"));
- fprintf (stderr, "Connecting peers...\n");
- CHECK (GNUNET_OK == GNUNET_TESTING_connect_daemons (22087, 22097));
-
-
- /* wait for DHT's to find each other! */
- /* verify that peer2 also sees the other DHT! */
- printf ("Waiting for peers to DHT-connect (1->2)");
- CHECK (test_connected(p1.sock));
- printf ("Waiting for peers to DHT-connect (2->1)");
- CHECK (test_connected(p2.sock));
-
- /* actual test code */
- CHECK (0 == put_at_peer (&p1, "key 1", 'A'));
- CHECK (0 == put_at_peer (&p2, "key 2", 'B'));
- printf ("DHT get (1->1)");
- CHECK (0 == get_at_peer (&p1, "key 1", 'A'));
- printf ("DHT get (2->2");
- CHECK (0 == get_at_peer (&p2, "key 2", 'B'));
- printf ("DHT get (1->2)");
- CHECK (0 == get_at_peer (&p1, "key 2", 'B'));
- printf ("DHT get (2->1)");
- CHECK (0 == get_at_peer (&p2, "key 1", 'A'));
- /* end of actual test code */
-
-FAILURE:
-#if START_PEERS
- GNUNET_TESTING_stop_daemons (peers);
-#endif
- free_peer(&p1);
- free_peer(&p2);
- return ret;
-}
-
-/* end of dht_twopeer_test.c */
Added: GNUnet/src/applications/dht/tools/dv_dht-query.c
===================================================================
--- GNUnet/src/applications/dht/tools/dv_dht-query.c
(rev 0)
+++ GNUnet/src/applications/dht/tools/dv_dht-query.c 2009-03-11 20:44:50 UTC
(rev 8321)
@@ -0,0 +1,191 @@
+/*
+ This file is part of GNUnet
+ (C) 2004, 2005, 2006 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 dv_dht-query.c
+ * @brief perform DV_DHT operations (insert, lookup)
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_directories.h"
+#include "gnunet_protocols.h"
+#include "gnunet_util.h"
+#include "gnunet_dv_dht_lib.h"
+
+#define DEBU_DV_DHT_QUERY GNUNET_NO
+
+/**
+ * How long should a "GET" run (or how long should
+ * content last on the network).
+ */
+static GNUNET_CronTime timeout = 30 * GNUNET_CRON_SECONDS;
+
+static struct GNUNET_GE_Context *ectx;
+
+static struct GNUNET_GC_Configuration *cfg;
+
+static char *cfgFilename = GNUNET_DEFAULT_CLIENT_CONFIG_FILE;
+
+struct GNUNET_DV_DHT_Context *ctx;
+
+/**
+ * All gnunet-dht-query command line options
+ */
+static struct GNUNET_CommandLineOption gnunetqueryOptions[] = {
+ GNUNET_COMMAND_LINE_OPTION_CFG_FILE (&cfgFilename), /* -c */
+ GNUNET_COMMAND_LINE_OPTION_HELP (gettext_noop ("Query (get KEY, put KEY
VALUE) DV_DHT table.")), /* -h */
+ GNUNET_COMMAND_LINE_OPTION_HOSTNAME, /* -H */
+ GNUNET_COMMAND_LINE_OPTION_LOGGING, /* -L */
+ {'T', "timeout", "TIME",
+ gettext_noop ("allow TIME ms to process a GET command"),
+ 1, &GNUNET_getopt_configure_set_ulong, &timeout},
+ GNUNET_COMMAND_LINE_OPTION_VERSION (PACKAGE_VERSION), /* -v */
+ GNUNET_COMMAND_LINE_OPTION_VERBOSE,
+ GNUNET_COMMAND_LINE_OPTION_END,
+};
+
+static int
+printCallback (const GNUNET_HashCode * hash,
+ unsigned int type,
+ unsigned int size, const char *data, void *unused)
+{
+ printf ("%s: `%.*s'\n", "get", size, data);
+ return GNUNET_OK;
+}
+
+static void
+do_get (struct GNUNET_ClientServerConnection *sock, const char *key)
+{
+ struct GNUNET_DV_DHT_GetRequest *ret;
+ GNUNET_HashCode hc;
+
+ GNUNET_hash (key, strlen (key), &hc);
+#if DEBU_DV_DHT_QUERY
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
+ "Issuing `%s(%s)' command.\n", "get", key);
+#endif
+ ret = GNUNET_DV_DHT_get_start (ctx, GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+ &hc);
+ if (ret == NULL)
+ {
+ printf ("`%s(%s)' failed.\n", "get", key);
+ return;
+ }
+ GNUNET_thread_sleep (timeout);
+ GNUNET_DV_DHT_get_stop (ctx, ret);
+}
+
+static void
+do_put (struct GNUNET_ClientServerConnection *sock,
+ const char *key, const char *value)
+{
+ GNUNET_HashCode hc;
+
+ GNUNET_hash (key, strlen (key), &hc);
+#if DEBU_DV_DHT_QUERY
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
+ _("Issuing `%s(%s,%s)' command.\n"), "put", key, value);
+#endif
+ if (GNUNET_OK ==
+ GNUNET_DV_DHT_put (cfg, ectx, &hc,
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+ strlen (value), value))
+ {
+ printf ("`%s(%s,%s)' succeeded\n", "put", key, value);
+ }
+ else
+ {
+ printf ("`%s(%s,%s)' failed.\n", "put", key, value);
+ }
+}
+
+int
+main (int argc, char *const *argv)
+{
+ int i;
+ struct GNUNET_ClientServerConnection *handle;
+
+ i = GNUNET_init (argc,
+ argv,
+ "gnunet-dht-query",
+ &cfgFilename, gnunetqueryOptions, &ectx, &cfg);
+ if (i == -1)
+ {
+ GNUNET_fini (ectx, cfg);
+ return -1;
+ }
+
+ handle = GNUNET_client_connection_create (ectx, cfg);
+
+ ctx = GNUNET_DV_DHT_context_create (cfg, ectx, &printCallback, NULL);
+ if (handle == NULL)
+ {
+ fprintf (stderr, _("Failed to connect to gnunetd.\n"));
+ GNUNET_GC_free (cfg);
+ GNUNET_GE_free_context (ectx);
+ return 1;
+ }
+
+ while (i < argc)
+ {
+ if (0 == strcmp ("get", argv[i]))
+ {
+ if (i + 2 > argc)
+ {
+ fprintf (stderr,
+ _("Command `%s' requires an argument (`%s').\n"),
+ "get", "key");
+ break;
+ }
+ else
+ {
+ do_get (handle, argv[i + 1]);
+ i += 2;
+ }
+ continue;
+ }
+ if (0 == strcmp ("put", argv[i]))
+ {
+ if (i + 3 > argc)
+ {
+ fprintf (stderr,
+ _
+ ("Command `%s' requires two arguments (`%s' and
`%s').\n"),
+ "put", "key", "value");
+ break;
+ }
+ else
+ {
+ do_put (handle, argv[i + 1], argv[i + 2]);
+ i += 3;
+ }
+ continue;
+ }
+ fprintf (stderr, _("Unsupported command `%s'. Aborting.\n"), argv[i]);
+ break;
+ }
+ GNUNET_client_connection_destroy (handle);
+ GNUNET_fini (ectx, cfg);
+ return 0;
+}
+
+/* end of dv_dht-query.c */
Added: GNUnet/src/applications/dht/tools/dv_dht_api.c
===================================================================
--- GNUnet/src/applications/dht/tools/dv_dht_api.c
(rev 0)
+++ GNUnet/src/applications/dht/tools/dv_dht_api.c 2009-03-11 20:44:50 UTC
(rev 8321)
@@ -0,0 +1,357 @@
+/*
+ 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 dv_dht/tools/dht_api.c
+ * @brief DV_DHT-module's core API's implementation.
+ * @author Tomi Tukiainen, Christian Grothoff, Nathan Evans
+ */
+#include "platform.h"
+#include "gnunet_protocols.h"
+#include "dht.h"
+#include "gnunet_dv_dht_lib.h"
+#include "gnunet_stats_lib.h"
+#include "gnunet_util.h"
+
+#define DEBUG_DV_DHT_API GNUNET_NO
+
+/**
+ * Doubly-linked list of get requests.
+ */
+struct GNUNET_DV_DHT_GetRequest
+{
+ struct GNUNET_DV_DHT_GetRequest *prev;
+
+ struct GNUNET_DV_DHT_GetRequest *next;
+
+ CS_dht_request_get_MESSAGE request;
+};
+
+/**
+ * Data exchanged between main thread and GET thread.
+ */
+struct GNUNET_DV_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_DV_DHT_GetRequest *head;
+
+ /**
+ * Tail of our pending requests.
+ */
+ struct GNUNET_DV_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 DV_DHT context
+ * @return NULL (always)
+ */
+static void *
+poll_thread (void *cls)
+{
+ struct GNUNET_DV_DHT_Context *info = cls;
+ GNUNET_MessageHeader *reply;
+ CS_dht_request_put_MESSAGE *put;
+ struct GNUNET_DV_DHT_GetRequest *get;
+ unsigned int size;
+
+ while (info->aborted == GNUNET_NO)
+ {
+ reply = NULL;
+ 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_DV_DHT_REQUEST_PUT != ntohs (reply->type)))
+ {
+ fprintf (stderr,
+ "Received message of type %u and size %u\n",
+ ntohs (reply->type), ntohs (reply->size));
+ GNUNET_GE_BREAK (NULL, 0);
+ GNUNET_free (reply);
+ break; /* invalid reply */
+ }
+ size = ntohs (reply->size) - sizeof (CS_dht_request_put_MESSAGE);
+ put = (CS_dht_request_put_MESSAGE *) reply;
+ if ((info->processor != NULL) &&
+ (GNUNET_OK != info->processor (&put->key,
+ ntohl (put->type),
+ size,
+ (const char *) &put[1],
+ info->closure)))
+ info->aborted = GNUNET_YES;
+ GNUNET_free (reply);
+ }
+ info->aborted = GNUNET_YES;
+ return NULL;
+}
+
+/**
+ * Set up a context for performing asynchronous DV_DHT operations.
+ *
+ * @param resultCallback function to call for results,
+ * the operation also aborts if the callback returns
+ * GNUNET_SYSERR
+ * @return NULL on error
+ */
+struct GNUNET_DV_DHT_Context *
+GNUNET_DV_DHT_context_create (struct GNUNET_GC_Configuration
+ *cfg,
+ struct GNUNET_GE_Context
+ *ectx,
+ GNUNET_ResultProcessor
+ resultCallback, void *resCallbackClosure)
+{
+ struct GNUNET_DV_DHT_Context *ctx;
+ struct GNUNET_ClientServerConnection *sock;
+
+ sock = GNUNET_client_connection_create (ectx, cfg);
+ if (sock == NULL)
+ return NULL;
+ ctx = GNUNET_malloc (sizeof (struct GNUNET_DV_DHT_Context));
+ ctx->lock = GNUNET_mutex_create (GNUNET_NO);
+ ctx->sock = sock;
+ ctx->processor = resultCallback;
+ ctx->closure = resCallbackClosure;
+ ctx->poll_thread = GNUNET_thread_create (&poll_thread, ctx, 1024 * 8);
+ if (ctx->poll_thread == NULL)
+ {
+ GNUNET_client_connection_destroy (sock);
+ GNUNET_mutex_destroy (ctx->lock);
+ GNUNET_free (ctx);
+ return NULL;
+ }
+ return ctx;
+}
+
+
+/**
+ * Start an asynchronous GET operation on the DV_DHT looking for
+ * key.
+ *
+ * @param type the type of key to look up
+ * @param key the key to look up
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+struct GNUNET_DV_DHT_GetRequest *
+GNUNET_DV_DHT_get_start (struct GNUNET_DV_DHT_Context *ctx,
+ unsigned int type, const GNUNET_HashCode * key)
+{
+ struct GNUNET_DV_DHT_GetRequest *req;
+
+ req = GNUNET_malloc (sizeof (struct GNUNET_DV_DHT_GetRequest));
+ req->request.header.size = htons (sizeof (CS_dht_request_get_MESSAGE));
+ req->request.header.type = htons (GNUNET_CS_PROTO_DV_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 DV_DHT looking for
+ * key.
+ *
+ * @param req request to stop
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int
+GNUNET_DV_DHT_get_stop (struct GNUNET_DV_DHT_Context *ctx,
+ struct GNUNET_DV_DHT_GetRequest *req)
+{
+ CS_dht_request_get_MESSAGE creq;
+
+ creq.header.size = htons (sizeof (CS_dht_request_get_MESSAGE));
+ creq.header.type = htons (GNUNET_CS_PROTO_DV_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;
+ GNUNET_free (req);
+ return GNUNET_OK;
+}
+
+/**
+ * Destroy a previously created context for DV_DHT operations.
+ *
+ * @param ctx context to destroy
+ * @return GNUNET_SYSERR on error
+ */
+int
+GNUNET_DV_DHT_context_destroy (struct GNUNET_DV_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;
+}
+
+/**
+ * Perform a synchronous put operation. The peer does not have
+ * to be part of the table!
+ *
+ * @param table table to use for the lookup
+ * @param key the key to store
+ * @param value what to store
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int
+GNUNET_DV_DHT_put (struct GNUNET_GC_Configuration *cfg,
+ struct GNUNET_GE_Context *ectx,
+ const GNUNET_HashCode * key,
+ unsigned int type, unsigned int size, const char *value)
+{
+ struct GNUNET_ClientServerConnection *sock;
+ CS_dht_request_put_MESSAGE *req;
+ int ret;
+ int ret2;
+
+#if DEBUG_DV_DHT_API
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
+ "DV_DHT_LIB_put called with value '%.*s'\n", size, value);
+#endif
+ sock = GNUNET_client_connection_create (ectx, cfg);
+ if (sock == NULL)
+ return GNUNET_SYSERR;
+ req = GNUNET_malloc (sizeof (CS_dht_request_put_MESSAGE) + size);
+ req->header.size = htons (sizeof (CS_dht_request_put_MESSAGE) + size);
+ req->header.type = htons (GNUNET_CS_PROTO_DV_DHT_REQUEST_PUT);
+ req->key = *key;
+ req->type = htonl (type);
+ memcpy (&req[1], value, size);
+ ret = GNUNET_client_connection_write (sock, &req->header);
+ if ((GNUNET_OK != GNUNET_client_connection_read_result (sock, &ret2)) ||
+ (ret2 != GNUNET_OK))
+ ret = GNUNET_SYSERR;
+ GNUNET_client_connection_destroy (sock);
+ GNUNET_free (req);
+ return ret;
+}
+
+static int
+waitForConnect (const char *name, unsigned long long value, void *cls)
+{
+ unsigned long long *ok = cls;
+ if ((value > 0) && (0 == strcmp (_("# dv_dht connections"), name)))
+ {
+ *ok = value;
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+/**
+ * Check if this peer has DV_DHT connections to
+ * any other peer.
+ *
+ * @param sock connection to gnunetd
+ * @return number of connections
+ */
+unsigned long long
+GNUNET_DV_DHT_test_connected (struct GNUNET_ClientServerConnection *sock)
+{
+ unsigned long long ret;
+
+ GNUNET_STATS_get_statistics (NULL, sock, &waitForConnect, &ret);
+ return ret;
+}
+
+
+/* end of dv_dht_api.c */
Added: GNUnet/src/applications/dht/tools/dv_dht_expiration_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dv_dht_expiration_test.c
(rev 0)
+++ GNUnet/src/applications/dht/tools/dv_dht_expiration_test.c 2009-03-11
20:44:50 UTC (rev 8321)
@@ -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 DV_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 DV_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_DV_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 dv dv_dht stats",
+ "/tmp/gnunet-dv-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_DV_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_DV_DHT_put (cfg,
+ ectx,
+ &key,
+
GNUNET_ECRS_BLOCKTYP_DV_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_DV_DHT_get_start (ctx,
+ GNUNET_ECRS_BLOCKTYP_DV_DHT_STRING2STRING,
+ &key));
+ GNUNET_thread_sleep (15 * GNUNET_CRON_SECONDS);
+ GNUNET_DV_DHT_context_destroy (ctx);
+
+FAILURE:
+#if START_PEERS
+ GNUNET_TESTING_stop_daemons (peers);
+#endif
+ GNUNET_GC_free (cfg);
+ return err;
+}
+
+/* end of dv_dht_expiration_test.c */
Added: GNUnet/src/applications/dht/tools/dv_dht_forwarding_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dv_dht_forwarding_test.c
(rev 0)
+++ GNUnet/src/applications/dht/tools/dv_dht_forwarding_test.c 2009-03-11
20:44:50 UTC (rev 8321)
@@ -0,0 +1,274 @@
+/*
+ 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/dht/tools/dht_multipeer_test.c
+ * @brief DV_DHT testcase
+ * @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"
+
+/**
+ * How many peers should the testcase run? Note that
+ * we create a clique topology so the cost is quadratic!
+ */
+#define NUM_PEERS 8
+
+/**
+ * How many times will we try the DV_DHT-GET operation before
+ * giving up for good?
+ */
+#define NUM_ROUNDS 20
+
+/**
+ * How often do we iterate the put-get loop?
+ */
+#define NUM_REPEAT 5
+
+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];
+
+ memset (expect, (*i), sizeof (expect));
+#if 0
+ fprintf (stderr, "Got %u %u `%.*s' (want `%.*s')\n", type, size, size, data,
+ sizeof (expect), expect);
+#endif
+ 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 (_("# 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)
+
+/**
+ * Testcase to test DV_DHT routing (many peers).
+ * @return 0: ok, -1: error
+ */
+int
+main (int argc, const char **argv)
+{
+ struct GNUNET_TESTING_DaemonContext *peers;
+ int ret = 0;
+ GNUNET_HashCode key;
+ char value[8];
+ struct GNUNET_GE_Context *ectx;
+ struct GNUNET_GC_Configuration *cfg;
+ struct GNUNET_ClientServerConnection *sock;
+ 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 last;
+ char buf[128];
+
+ ectx = NULL;
+ cfg = GNUNET_GC_create ();
+ if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
+ {
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
+ printf ("Starting %u peers...\n", NUM_PEERS);
+ peers = GNUNET_TESTING_start_daemons ("tcp",
+ "advertising dv dv_dht stats",
+ "/tmp/gnunet-dv-dht-multi-test",
+ 2087, 10, NUM_PEERS);
+ if (peers == NULL)
+ {
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
+ for (i = 0; i < NUM_PEERS; i++)
+ {
+ for (j = 0; j < i; j++)
+ {
+ if (GNUNET_OK != GNUNET_TESTING_connect_daemons (2087 + 10 * i,
+ 2087 + 10 * j))
+ {
+ GNUNET_TESTING_stop_daemons (peers);
+ fprintf (stderr, "Failed to connect the peers!\n");
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
+ }
+ }
+ found = 0;
+ for (r = 0; r < NUM_REPEAT; r++)
+ {
+ if (r > 0)
+ {
+ printf ("Found %u out of %u attempts.\n", found,
+ NUM_PEERS * NUM_PEERS * r);
+ if (found >= NUM_PEERS * NUM_PEERS * r / 2)
+ break; /* good enough */
+ }
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ /* put loop */
+ printf ("Waiting for DV_DHT connections of peer");
+ 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);
+ GNUNET_GC_set_configuration_value_string (cfg, ectx, "NETWORK",
+ "HOST", buf);
+ /* wait for some DV_DHT's to find each other! */
+ sock = GNUNET_client_connection_create (NULL, cfg);
+ 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);
+ GNUNET_TESTING_stop_daemons (peers);
+ 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 (cfg,
+ ectx,
+ &key,
+
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+ sizeof (value), value));
+ }
+ printf ("\n");
+ /* get 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);
+ dctx = GNUNET_DV_DHT_context_create (cfg, ectx, &result_callback,
&c);
+ 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", j);
+ fflush (stdout);
+ last = found;
+ get1 = GNUNET_DV_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 (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);
+ }
+ }
+ GNUNET_DV_DHT_context_destroy (dctx);
+ printf ("\n");
+ }
+ }
+ /* end of actual test code */
+ if (r == NUM_REPEAT)
+ printf ("Found %u out of %u 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;
+ }
+FAILURE:
+ GNUNET_TESTING_stop_daemons (peers);
+ GNUNET_GC_free (cfg);
+ return ret;
+}
+
+/* end of dv_dht_multipeer_test.c */
Added: GNUnet/src/applications/dht/tools/dv_dht_loopback_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dv_dht_loopback_test.c
(rev 0)
+++ GNUnet/src/applications/dht/tools/dv_dht_loopback_test.c 2009-03-11
20:44:50 UTC (rev 8321)
@@ -0,0 +1,162 @@
+/*
+ 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/dv_dht/tools/dv_dht_loopback_test.c
+ * @brief DV_DHT testcase using only a single peer
+ * @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"
+
+
+#define START_PEERS 1
+
+static int err;
+
+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))
+ {
+ err = 1;
+ return GNUNET_SYSERR;
+ }
+ found = 1;
+ return GNUNET_OK;
+}
+
+#define CHECK(a) do { if (!(a)) { ret = 1; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; } } while(0)
+
+/**
+ * Testcase to test DV_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_DV_DHT_Context *ctx;
+ struct GNUNET_DV_DHT_GetRequest *get1;
+ struct GNUNET_DV_DHT_GetRequest *get2;
+ int left;
+ int i;
+
+ 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 dv_dht stats",
+ "/tmp/gnunet-dv-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_DV_DHT_context_create (cfg, ectx, &result_callback, &i);
+ CHECK (ctx != NULL);
+ /* actual test code */
+ GNUNET_hash ("key_for_A", 4, &key);
+ value = GNUNET_malloc (8);
+ memset (value, 'A', 8);
+ CHECK (GNUNET_OK == GNUNET_DV_DHT_put (cfg,
+ ectx,
+ &key,
+ GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+ 8, value));
+ i = 'A';
+ CHECK (NULL != (get1 = GNUNET_DV_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_DV_DHT_put (cfg,
+ ectx,
+ &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_DV_DHT_get_stop (ctx, get1);
+ i = 'B';
+ CHECK (NULL != (get2 = GNUNET_DV_DHT_get_start (ctx,
+
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+ &key)));
+ left = 10;
+ while ((found == 0) && (--left >= 0))
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ CHECK (err == 0);
+ CHECK (found != 0);
+ GNUNET_DV_DHT_get_stop (ctx, get2);
+ /* end of actual test code */
+
+ GNUNET_DV_DHT_context_destroy (ctx);
+FAILURE:
+#if START_PEERS
+ GNUNET_TESTING_stop_daemons (peers);
+#endif
+ GNUNET_free (value);
+ GNUNET_GC_free (cfg);
+ return ret;
+}
+
+/* end of dv_dht_loopback_test.c */
Added: GNUnet/src/applications/dht/tools/dv_dht_multipeer_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dv_dht_multipeer_test.c
(rev 0)
+++ GNUnet/src/applications/dht/tools/dv_dht_multipeer_test.c 2009-03-11
20:44:50 UTC (rev 8321)
@@ -0,0 +1,274 @@
+/*
+ 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/dht/tools/dht_multipeer_test.c
+ * @brief DV_DHT testcase
+ * @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"
+
+/**
+ * How many peers should the testcase run? Note that
+ * we create a clique topology so the cost is quadratic!
+ */
+#define NUM_PEERS 8
+
+/**
+ * How many times will we try the DV_DHT-GET operation before
+ * giving up for good?
+ */
+#define NUM_ROUNDS 20
+
+/**
+ * How often do we iterate the put-get loop?
+ */
+#define NUM_REPEAT 5
+
+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];
+
+ memset (expect, (*i), sizeof (expect));
+#if 0
+ fprintf (stderr, "Got %u %u `%.*s' (want `%.*s')\n", type, size, size, data,
+ sizeof (expect), expect);
+#endif
+ 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 (_("# 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)
+
+/**
+ * Testcase to test DV_DHT routing (many peers).
+ * @return 0: ok, -1: error
+ */
+int
+main (int argc, const char **argv)
+{
+ struct GNUNET_TESTING_DaemonContext *peers;
+ int ret = 0;
+ GNUNET_HashCode key;
+ char value[8];
+ struct GNUNET_GE_Context *ectx;
+ struct GNUNET_GC_Configuration *cfg;
+ struct GNUNET_ClientServerConnection *sock;
+ 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 last;
+ char buf[128];
+
+ ectx = NULL;
+ cfg = GNUNET_GC_create ();
+ if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
+ {
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
+ printf ("Starting %u peers...\n", NUM_PEERS);
+ peers = GNUNET_TESTING_start_daemons ("tcp",
+ "advertising dv dv_dht stats",
+ "/tmp/gnunet-dv-dht-multi-test",
+ 2087, 10, NUM_PEERS);
+ if (peers == NULL)
+ {
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
+ for (i = 0; i < NUM_PEERS; i++)
+ {
+ for (j = 0; j < i; j++)
+ {
+ if (GNUNET_OK != GNUNET_TESTING_connect_daemons (2087 + 10 * i,
+ 2087 + 10 * j))
+ {
+ GNUNET_TESTING_stop_daemons (peers);
+ fprintf (stderr, "Failed to connect the peers!\n");
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
+ }
+ }
+ found = 0;
+ for (r = 0; r < NUM_REPEAT; r++)
+ {
+ if (r > 0)
+ {
+ printf ("Found %u out of %u attempts.\n", found,
+ NUM_PEERS * NUM_PEERS * r);
+ if (found >= NUM_PEERS * NUM_PEERS * r / 2)
+ break; /* good enough */
+ }
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ /* put loop */
+ printf ("Waiting for DV_DHT connections of peer");
+ 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);
+ GNUNET_GC_set_configuration_value_string (cfg, ectx, "NETWORK",
+ "HOST", buf);
+ /* wait for some DV_DHT's to find each other! */
+ sock = GNUNET_client_connection_create (NULL, cfg);
+ 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);
+ GNUNET_TESTING_stop_daemons (peers);
+ 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 (cfg,
+ ectx,
+ &key,
+
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+ sizeof (value), value));
+ }
+ printf ("\n");
+ /* get 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);
+ dctx = GNUNET_DV_DHT_context_create (cfg, ectx, &result_callback,
&c);
+ 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", j);
+ fflush (stdout);
+ last = found;
+ get1 = GNUNET_DV_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 (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);
+ }
+ }
+ GNUNET_DV_DHT_context_destroy (dctx);
+ printf ("\n");
+ }
+ }
+ /* end of actual test code */
+ if (r == NUM_REPEAT)
+ printf ("Found %u out of %u 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;
+ }
+FAILURE:
+ GNUNET_TESTING_stop_daemons (peers);
+ GNUNET_GC_free (cfg);
+ return ret;
+}
+
+/* end of dv_dht_multipeer_test.c */
Added: GNUnet/src/applications/dht/tools/dv_dht_twopeer_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dv_dht_twopeer_test.c
(rev 0)
+++ GNUnet/src/applications/dht/tools/dv_dht_twopeer_test.c 2009-03-11
20:44:50 UTC (rev 8321)
@@ -0,0 +1,225 @@
+/*
+ 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/dht_twopeer_test.c
+ * @brief DV_DHT testcase
+ * @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"
+
+
+#define START_PEERS 1
+
+#define NUM_ROUNDS 100
+
+#define CHECK(a) do { if (!(a)) { ret = 1; GNUNET_GE_BREAK(NULL, 0); goto
FAILURE; } } while(0)
+
+struct PeerData
+{
+ struct GNUNET_GC_Configuration *cfg;
+ struct GNUNET_DV_DHT_Context *ctx_peer;
+ struct GNUNET_ClientServerConnection *sock;
+ int peercount;
+ int expect_i;
+};
+
+static int
+test_connected (struct GNUNET_ClientServerConnection *sock)
+{
+ int left = 50;
+ unsigned long long have;
+ while (0 == (have = GNUNET_DV_DHT_test_connected (sock)))
+ {
+ printf (".");
+ fflush (stdout);
+ sleep (2);
+ left--;
+ if (left == 0)
+ break;
+ }
+ printf ((have > 0) ? " OK!\n" : "?\n");
+ return have > 0;
+}
+
+static int
+result_callback (const GNUNET_HashCode * key,
+ unsigned int type,
+ unsigned int size, const char *data, void *cls)
+{
+ struct PeerData *pd = cls;
+ char expect[8];
+
+#if 0
+ fprintf (stderr, "Got %u %u `%.*s'\n", type, size, size, data);
+#endif
+ memset (expect, pd->expect_i, sizeof (expect));
+ if ((8 != size) ||
+ (0 != memcmp (expect, data, size)) ||
+ (type != GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING))
+ return GNUNET_SYSERR;
+ pd->peercount--;
+ return GNUNET_OK;
+}
+
+static int
+setup_peer (struct PeerData *pd, const char *pstr)
+{
+ int ret = 0;
+ pd->cfg = GNUNET_GC_create ();
+ CHECK (-1 != GNUNET_GC_parse_configuration (pd->cfg, "check.conf"));
+ GNUNET_GC_set_configuration_value_string (pd->cfg,
+ NULL,
+ "NETWORK", "HOST",
+ "localhost:22087");
+ pd->sock = GNUNET_client_connection_create (NULL, pd->cfg);
+ pd->ctx_peer =
+ GNUNET_DV_DHT_context_create (pd->cfg, NULL, &result_callback, pd);
+FAILURE:
+ return ret;
+}
+
+static void
+free_peer (struct PeerData *pd)
+{
+ if (NULL != pd->ctx_peer)
+ GNUNET_DV_DHT_context_destroy (pd->ctx_peer);
+ if (NULL != pd->sock)
+ GNUNET_client_connection_destroy (pd->sock);
+ if (NULL != pd->cfg)
+ GNUNET_GC_free (pd->cfg);
+}
+
+static int
+put_at_peer (struct PeerData *pd, const char *keys, int val)
+{
+ int ret = 0;
+ char value[8];
+ GNUNET_HashCode key;
+
+ GNUNET_hash (keys, 5, &key);
+ memset (value, val, sizeof (value));
+ CHECK (GNUNET_OK == GNUNET_DV_DHT_put (pd->cfg,
+ NULL,
+ &key,
+ GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
+ sizeof (value), value));
+FAILURE:
+ return ret;
+}
+
+static int
+get_at_peer (struct PeerData *pd, const char *keys, int want)
+{
+ int ret = 0;
+ GNUNET_HashCode key;
+ struct GNUNET_DV_DHT_GetRequest *get;
+ int k;
+
+ GNUNET_hash (keys, 5, &key);
+ pd->peercount = 10;
+ pd->expect_i = want;
+ CHECK (NULL != (get = GNUNET_DV_DHT_get_start (pd->ctx_peer,
+
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 (pd->peercount < 10)
+ break;
+ }
+ CHECK (GNUNET_OK == GNUNET_DV_DHT_get_stop (pd->ctx_peer, get));
+ printf (pd->peercount < 10 ? " OK!\n" : "?\n");
+ CHECK (pd->peercount < 10);
+FAILURE:
+ return ret;
+}
+
+
+/**
+ * Testcase to test DV_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;
+ struct PeerData p1;
+ struct PeerData p2;
+
+ memset (&p1, 0, sizeof (struct PeerData));
+ memset (&p2, 0, sizeof (struct PeerData));
+#if START_PEERS
+ fprintf (stderr, "Starting peers...\n");
+ peers = GNUNET_TESTING_start_daemons ("tcp",
+ "advertising dv dv_dht stats",
+ "/tmp/gnunet-dv-dht-two-test",
+ 22087, 10, 2);
+ CHECK (peers != NULL);
+#endif
+ CHECK (0 == setup_peer (&p1, "localhost:22087"));
+ CHECK (0 == setup_peer (&p2, "localhost:22097"));
+ fprintf (stderr, "Connecting peers...\n");
+ CHECK (GNUNET_OK == GNUNET_TESTING_connect_daemons (22087, 22097));
+
+
+ /* wait for DV_DHT's to find each other! */
+ /* verify that peer2 also sees the other DV_DHT! */
+ printf ("Waiting for peers to DV_DHT-connect (1->2)");
+ CHECK (test_connected (p1.sock));
+ printf ("Waiting for peers to DV_DHT-connect (2->1)");
+ CHECK (test_connected (p2.sock));
+
+ /* actual test code */
+ CHECK (0 == put_at_peer (&p1, "key 1", 'A'));
+ CHECK (0 == put_at_peer (&p2, "key 2", 'B'));
+ printf ("DV_DHT get (1->1)");
+ CHECK (0 == get_at_peer (&p1, "key 1", 'A'));
+ printf ("DV_DHT get (2->2");
+ CHECK (0 == get_at_peer (&p2, "key 2", 'B'));
+ printf ("DV_DHT get (1->2)");
+ CHECK (0 == get_at_peer (&p1, "key 2", 'B'));
+ printf ("DV_DHT get (2->1)");
+ CHECK (0 == get_at_peer (&p2, "key 1", 'A'));
+ /* end of actual test code */
+
+FAILURE:
+#if START_PEERS
+ GNUNET_TESTING_stop_daemons (peers);
+#endif
+ free_peer (&p1);
+ free_peer (&p2);
+ return ret;
+}
+
+/* end of dv_dht_twopeer_test.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r8321 - in GNUnet/src/applications/dht: module tools,
gnunet <=