[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r6934 - in GNUnet/src/applications/dht: module tools
From: |
gnunet |
Subject: |
[GNUnet-SVN] r6934 - in GNUnet/src/applications/dht: module tools |
Date: |
Fri, 30 May 2008 17:09:27 -0600 (MDT) |
Author: nevans
Date: 2008-05-30 17:09:26 -0600 (Fri, 30 May 2008)
New Revision: 6934
Modified:
GNUnet/src/applications/dht/module/cs.c
GNUnet/src/applications/dht/module/service.c
GNUnet/src/applications/dht/tools/dht_api.c
Log:
it builds...
Modified: GNUnet/src/applications/dht/module/cs.c
===================================================================
--- GNUnet/src/applications/dht/module/cs.c 2008-05-30 23:08:44 UTC (rev
6933)
+++ GNUnet/src/applications/dht/module/cs.c 2008-05-30 23:09:26 UTC (rev
6934)
@@ -23,7 +23,7 @@
* @brief DHT application protocol using the DHT service.
* This is merely for the 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äihä, Christian Grothoff
*/
#include "platform.h"
@@ -31,6 +31,7 @@
#include "gnunet_protocols.h"
#include "dht.h"
#include "gnunet_dht_service.h"
+#include "service.h"
#define DEBUG_CS GNUNET_NO
@@ -172,6 +173,58 @@
}
/**
+ * CS handler for stopping existing get from 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;
+
+ if (ntohs (message->size) != sizeof (CS_dht_request_get_MESSAGE))
+ {
+ GNUNET_GE_BREAK (NULL, 0);
+ return GNUNET_SYSERR;
+ }
+#if DEBUG_CS
+ GNUNET_GE_LOG (coreAPI->ectx,
+ GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
+ "`%s' at %s:%d processes get\n", __FUNCTION__, __FILE__,
+ __LINE__);
+#endif
+
+ get = (const CS_dht_request_get_MESSAGE *) message;
+ GNUNET_mutex_lock (lock);
+ pos = getRecords;
+ prev = NULL;
+ while (pos != NULL)
+ {
+ if ((memcmp(pos->client,client,sizeof(client)) == 0) &&
+ (memcmp(&pos->get_record->key,&get->key,sizeof(GNUNET_HashCode))) &&
+ (ntohs(get->type) == pos->get_record->type))
+ break;
+ prev = pos;
+ pos = pos->next;
+ }
+ if (pos == NULL)
+ {
+ GNUNET_mutex_unlock (lock);
+ return GNUNET_OK;
+ }
+ if (prev == NULL)
+ getRecords = pos->next;
+ else
+ prev->next = pos->next;
+ GNUNET_mutex_unlock (lock);
+ dhtAPI->get_stop (pos->get_record);
+ GNUNET_free (pos);
+
+ return GNUNET_OK;
+}
+
+/**
* CS handler for handling exiting client. Triggers
* get_stop for all operations that rely on this client.
*/
@@ -229,6 +282,9 @@
if (GNUNET_SYSERR ==
capi->cs_handler_register (GNUNET_CS_PROTO_DHT_REQUEST_GET, &csGet))
status = GNUNET_SYSERR;
+ if (GNUNET_SYSERR ==
+ capi->cs_handler_register (GNUNET_CS_PROTO_DHT_REQUEST_GET_END,
&csGetEnd))
+ status = GNUNET_SYSERR;
if (GNUNET_SYSERR == capi->cs_disconnect_handler_register (&csClientExit))
status = GNUNET_SYSERR;
GNUNET_GE_ASSERT (capi->ectx,
Modified: GNUnet/src/applications/dht/module/service.c
===================================================================
--- GNUnet/src/applications/dht/module/service.c 2008-05-30 23:08:44 UTC
(rev 6933)
+++ GNUnet/src/applications/dht/module/service.c 2008-05-30 23:09:26 UTC
(rev 6934)
@@ -23,12 +23,11 @@
* @brief internal GNUnet DHT service
* @author Christian Grothoff
*/
-
-#include "platform.h"
+
#include "table.h"
#include "routing.h"
#include "gnunet_dht_service.h"
-#include "gnunet_util.h"
+#include "service.h"
/**
* Global core API.
@@ -36,33 +35,6 @@
static GNUNET_CoreAPIForPlugins *coreAPI;
/**
- * Handle used to track GET activity.
- */
-struct GNUNET_DHT_GetHandle
-{
- /**
- * Key that we are looking for.
- */
- GNUNET_HashCode key;
-
- /**
- * Function to call for each result.
- */
- GNUNET_ResultProcessor callback;
-
- /**
- * Extra argument to callback.
- */
- void *cls;
-
- /**
- * Type of the content that we are looking for.
- */
- unsigned int type;
-
-};
-
-/**
* Perform an asynchronous GET operation on the 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!).
Modified: GNUnet/src/applications/dht/tools/dht_api.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_api.c 2008-05-30 23:08:44 UTC (rev
6933)
+++ GNUnet/src/applications/dht/tools/dht_api.c 2008-05-30 23:09:26 UTC (rev
6934)
@@ -35,7 +35,7 @@
/**
* Data exchanged between main thread and GET thread.
*/
-typedef struct
+struct GNUNET_DHT_Context
{
/**
@@ -60,20 +60,20 @@
* connection or the processor callback requesting
* it).
*/
- struct GNUNET_ThreadHandle *parent; /*Poll thread instead.. */
+ struct GNUNET_ThreadHandle *poll_thread; /*Poll thread instead.. */
/**
* Are we done (for whichever reason)?
*/
int aborted;
-} GetInfo; /*Change name */
+};
static void *
poll_thread (void *cls)
{
- GetInfo *info = cls;
+ GNUNET_DHT_Context *info = cls;
GNUNET_MessageHeader *reply;
CS_dht_request_put_MESSAGE *put;
unsigned int size;
@@ -109,81 +109,114 @@
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->sock = sock;
+ ctx->closure = resCallbackClosure;
+ ctx->processor = resultCallback;
+ ctx->poll_thread = GNUNET_thread_create (&poll_thread, ctx, 1024 * 8); /*
Should this be here, or will we create on the first request? */
+ ctx->aborted = GNUNET_NO;
+ return NULL;
+}
+
/**
- * Perform a synchronous GET operation on the DHT identified by
- * 'table' using 'key' as the key; store the result in 'result'. If
- * result->dataLength == 0 the result size is unlimited and
- * result->data needs to be allocated; otherwise result->data refers
- * to dataLength bytes and the result is to be stored at that
- * location; dataLength is to be set to the actual size of the
- * result.
+ * Start an asynchronous GET operation on the DHT looking for
+ * key.
*
- * The peer does not have to be part of the table!
- *
- * @param table table to use for the lookup
+ * @param type the type of key to look up
* @param key the key to look up
- * @param timeout how long to wait until this operation should
- * automatically time-out
- * @param maxResults maximum number of results to obtain, size of the results
array
- * @param results where to store the results (on success)
- * @return number of results on success, GNUNET_SYSERR on error (i.e. timeout)
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
-int
-GNUNET_DHT_get (struct GNUNET_GC_Configuration *cfg,
- struct GNUNET_GE_Context *ectx,
- unsigned int type,
- const GNUNET_HashCode * key,
- GNUNET_CronTime timeout, GNUNET_ResultProcessor processor,
- void *closure)
+int GNUNET_DHT_get_start (struct GNUNET_DHT_Context *ctx,
+ unsigned int type, const GNUNET_HashCode * key)
{
- /*Lots of changes, get rid of timeouts, split into requisite functions */
- struct GNUNET_ClientServerConnection *sock;
CS_dht_request_get_MESSAGE req;
- struct GNUNET_ThreadHandle *thread;
- GNUNET_CronTime start;
- GNUNET_CronTime now;
- GNUNET_CronTime delta;
- GetInfo info;
- void *unused;
-
- sock = GNUNET_client_connection_create (ectx, cfg);
- if (sock == NULL)
+
+ if (ctx->sock == NULL)
return GNUNET_SYSERR;
req.header.size = htons (sizeof (CS_dht_request_get_MESSAGE));
req.header.type = htons (GNUNET_CS_PROTO_DHT_REQUEST_GET);
req.type = htonl (type);
req.key = *key;
- if (GNUNET_OK != GNUNET_client_connection_write (sock, &req.header))
+ if (GNUNET_OK != GNUNET_client_connection_write (ctx->sock, &req.header))
{
- GNUNET_client_connection_destroy (sock);
return GNUNET_SYSERR;
- }
- info.sock = sock;
- info.processor = processor;
- info.closure = closure;
- info.parent = GNUNET_thread_get_self ();
- info.aborted = GNUNET_NO;
- info.total = 0;
- thread = GNUNET_thread_create (&poll_thread, &info, 1024 * 8);
- start = GNUNET_get_time ();
- while ((start + timeout > (now = GNUNET_get_time ())) &&
- (GNUNET_shutdown_test () == GNUNET_NO)
- && (info.aborted == GNUNET_NO))
+ }
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * Stop an asynchronous GET operation on the DHT looking for
+ * key.
+ * @param type the type of key to look up
+ * @param key the key to look up
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int GNUNET_DHT_get_stop (struct GNUNET_DHT_Context *ctx,
+ unsigned int type, const GNUNET_HashCode * key)
+{
+
+ CS_dht_request_get_MESSAGE req;
+
+ if (ctx->sock == NULL)
+ return GNUNET_SYSERR;
+ req.header.size = htons (sizeof (CS_dht_request_get_MESSAGE));
+ req.header.type = htons (GNUNET_CS_PROTO_DHT_REQUEST_GET_END);
+ req.type = htonl (type);
+ req.key = *key;
+ if (GNUNET_OK != GNUNET_client_connection_write (ctx->sock, &req.header))
{
- delta = (start + timeout) - now;
- if (delta > 100 * GNUNET_CRON_MILLISECONDS)
- delta = 100 * GNUNET_CRON_MILLISECONDS; /* in case we miss SIGINT
- on CTRL-C */
- GNUNET_thread_sleep (delta);
- }
- info.aborted = GNUNET_YES;
- GNUNET_client_connection_close_forever (sock);
- GNUNET_thread_join (thread, &unused);
- GNUNET_thread_release_self (info.parent);
+ return GNUNET_SYSERR;
+ }
+
+ 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;
+ ctx->aborted = GNUNET_YES;
+ GNUNET_client_connection_close_forever (ctx->sock);
+ GNUNET_thread_join (ctx->poll_thread, &unused);
GNUNET_client_connection_destroy (sock);
- return info.total;
-}
+ return GNUNET_OK;
+}
/**
* Perform a synchronous put operation. The peer does not have
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r6934 - in GNUnet/src/applications/dht: module tools,
gnunet <=