gnunet-svn
[Top][All Lists]
Advanced

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

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


From: grothoff
Subject: [GNUnet-SVN] r3857 - in GNUnet/src: applications/dht/module applications/fs/module include
Date: Sat, 2 Dec 2006 21:21:16 -0800 (PST)

Author: grothoff
Date: 2006-12-02 21:21:11 -0800 (Sat, 02 Dec 2006)
New Revision: 3857

Added:
   GNUnet/src/applications/dht/module/service.c
   GNUnet/src/applications/dht/module/service.h
Modified:
   GNUnet/src/applications/dht/module/Makefile.am
   GNUnet/src/applications/dht/module/routing.h
   GNUnet/src/applications/fs/module/fs.c
   GNUnet/src/include/gnunet_dht_service.h
Log:
hxing

Modified: GNUnet/src/applications/dht/module/Makefile.am
===================================================================
--- GNUnet/src/applications/dht/module/Makefile.am      2006-12-03 04:37:46 UTC 
(rev 3856)
+++ GNUnet/src/applications/dht/module/Makefile.am      2006-12-03 05:21:11 UTC 
(rev 3857)
@@ -8,7 +8,9 @@
 libgnunetmodule_dht_la_SOURCES = \
   table.c table.h \
   dstore.c dstore.h \
-  routing.c routing.h
+  routing.c routing.h \
+  service.c service.h
+
 libgnunetmodule_dht_la_LIBADD = \
  $(top_builddir)/src/util/crypto/libgnunetutil_crypto.la \
  $(top_builddir)/src/util/containers/libgnunetutil_containers.la \

Modified: GNUnet/src/applications/dht/module/routing.h
===================================================================
--- GNUnet/src/applications/dht/module/routing.h        2006-12-03 04:37:46 UTC 
(rev 3856)
+++ GNUnet/src/applications/dht/module/routing.h        2006-12-03 05:21:11 UTC 
(rev 3857)
@@ -35,9 +35,9 @@
  * Start a DHT get operation.
  */
 void dht_get_start(const HashCode512 * key,
-                 unsigned int type,
-                 ResultHandler handler,
-                 void * cls);
+                  unsigned int type,
+                  ResultHandler handler,
+                  void * cls);
 
 /**
  * Stop a DHT get operation (prevents calls to

Added: GNUnet/src/applications/dht/module/service.c
===================================================================
--- GNUnet/src/applications/dht/module/service.c        2006-12-03 04:37:46 UTC 
(rev 3856)
+++ GNUnet/src/applications/dht/module/service.c        2006-12-03 05:21:11 UTC 
(rev 3857)
@@ -0,0 +1,158 @@
+/*
+      This file is part of GNUnet
+      (C) 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 module/service.c
+ * @brief internal GNUnet DHT service 
+ * @author Christian Grothoff
+ *
+ * TODO: support async get timeout (gap never stops otherwise!)
+ */
+
+#include "platform.h"
+#include "dstore.h"
+#include "table.h"
+#include "routing.h"
+#include "service.h"
+
+/**
+ * Global core API.
+ */
+static CoreAPIForApplication * coreAPI;
+
+typedef struct DHT_GET_RECORD {
+  HashCode512 key;
+  DataProcessor callback;
+  void * cls;
+  DHT_OP_Complete callbackComplete;
+  void * closure;
+  unsigned int type;
+} DHT_GET_RECORD;
+
+static void client_result_converter(const HashCode512 * key,
+                                   unsigned int type,
+                                   unsigned int size,
+                                   const char * data,
+                                   void * cls) {
+  struct DHT_GET_RECORD * get = cls;
+  DataContainer * dc;
+
+  dc = MALLOC(sizeof(DataContainer) + size);
+  dc->size = ntohl(sizeof(DataContainer) + size);
+  memcpy(&dc[1],
+        data,
+        size);
+  get->callback(key,
+               dc,
+               get->cls);
+  FREE(dc);
+}
+
+/**
+ * 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!)
+ *
+ * @param table table to use for the lookup
+ * @param key the key to look up
+ * @param timeout how long to wait until this operation should
+ *        automatically time-out -- FIXME: not yet supported!
+ * @param callback function to call on each result
+ * @param closure extra argument to callback
+ * @return handle to stop the async get
+ */
+static struct DHT_GET_RECORD * 
+dht_get_async_start(unsigned int type,
+                   const HashCode512 * key,
+                   cron_t timeout,
+                   DataProcessor callback,
+                   void * cls,
+                   DHT_OP_Complete callbackComplete,
+                   void * closure) {
+  struct DHT_GET_RECORD * ret;
+
+  ret = MALLOC(sizeof(DHT_GET_RECORD));
+  ret->callback = callback;
+  ret->cls = cls;
+  ret->callbackComplete = callbackComplete;
+  ret->closure = closure;
+  ret->type = type;
+  ret->key = *key;
+  dht_get_start(key,
+               type,
+               &client_result_converter,
+               ret);
+  return ret;
+}
+
+/**
+ * Stop async DHT-get.  Frees associated resources.
+ */
+static int 
+dht_get_async_stop(struct DHT_GET_RECORD * record) {
+  dht_get_stop(&record->key,
+              record->type,
+              &client_result_converter,
+              record);
+  record->callbackComplete(record->closure);
+  FREE(record);
+  return OK;
+}
+
+/**
+ * Provide the DHT service.  The DHT service depends on the RPC
+ * service.
+ *
+ * @param capi the core API
+ * @return NULL on errors, DHT_API otherwise
+ */
+DHT_ServiceAPI * provide_module_dht(CoreAPIForApplication * capi) {
+  static DHT_ServiceAPI api;
+
+  if (OK != init_dht_store(1024 * 1024,
+                          capi))
+    return NULL;
+  if (OK != init_dht_table(capi)) {
+    done_dht_store();
+    return NULL;
+  }
+  if (OK != init_dht_routing(capi)) {
+    done_dht_table();
+    done_dht_store();
+    return NULL;
+  }
+  coreAPI = capi;
+  api.get_start = &dht_get_async_start;
+  api.get_stop = &dht_get_async_stop;
+  api.put = &dht_put;
+  return &api;
+}
+
+/**
+ * Shutdown DHT service.
+ */
+int release_module_dht() {
+  done_dht_routing();
+  done_dht_table();
+  done_dht_store();
+  return OK;
+}
+
+/* end of service.c */

Added: GNUnet/src/applications/dht/module/service.h
===================================================================
--- GNUnet/src/applications/dht/module/service.h        2006-12-03 04:37:46 UTC 
(rev 3856)
+++ GNUnet/src/applications/dht/module/service.h        2006-12-03 05:21:11 UTC 
(rev 3857)
@@ -0,0 +1,38 @@
+/*
+      This file is part of GNUnet
+      (C) 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 module/service.h
+ * @brief internal GNUnet DHT service 
+ * @author Christian Grothoff
+ */
+
+#ifndef DHT_SERVICE_H
+#define DHT_SERVICE_H
+
+#include "gnunet_util.h"
+#include "gnunet_core.h"
+#include "gnunet_dht_service.h"
+
+DHT_ServiceAPI * provide_module_dht(CoreAPIForApplication * capi);
+
+int release_module_dht(void);
+
+#endif

Modified: GNUnet/src/applications/fs/module/fs.c
===================================================================
--- GNUnet/src/applications/fs/module/fs.c      2006-12-03 04:37:46 UTC (rev 
3856)
+++ GNUnet/src/applications/fs/module/fs.c      2006-12-03 05:21:11 UTC (rev 
3857)
@@ -235,11 +235,6 @@
   FREE(cls);
 }
 
-static void put_complete_callback(DHT_PUT_CLS * cls) {
-  dht->put_stop(cls->rec);
-  FREE(cls);
-}
-
 /**
  * Stop processing a query.
  *
@@ -286,13 +281,13 @@
                                                const MESSAGE_HEADER * req) {
   const CS_fs_request_insert_MESSAGE * ri;
   Datastore_Value * datum;
-  int ret;
+  struct GE_Context * cectx;
   HashCode512 query;
+  int ret;
   unsigned int type;
 #if DEBUG_FS
   EncName enc;
 #endif
-  struct GE_Context * cectx;
 
   cectx = coreAPI->createClientLogContext(GE_USER | GE_EVENTKIND | 
GE_ROUTEKIND,
                                          sock);
@@ -348,7 +343,6 @@
     unsigned int size;
     cron_t now;
     cron_t et;
-    DHT_PUT_CLS * cls;
 
     size = sizeof(GapWrapper) +
       ntohs(ri->header.size) - sizeof(CS_fs_request_insert_MESSAGE) -
@@ -370,15 +364,13 @@
     memcpy(&gw[1],
           &ri[1],
           size - sizeof(GapWrapper));
-    cls = MALLOC(sizeof(DHT_PUT_CLS));
-    cls->rec = dht->put_start(&dht_table,
-                             &query,
-                             15 * cronSECONDS, /* FIXME 0.7.1: better timeout 
for DHT PUT operation */
-                             &gw->dc,
-                             (DHT_OP_Complete) &put_complete_callback,
-                             cls);
+    dht->put(&query,
+            0, /* FIXME 0.7.1: type? */
+            size,
+            et,
+            (const char*) gw);
+    FREE(gw);
   }
-
   FREE(datum);
   GE_free_context(cectx);
   return coreAPI->sendValueToClient(sock,
@@ -1088,9 +1080,7 @@
 
     cls = MALLOC(sizeof(DHT_GET_CLS));
     cls->prio = ntohl(rs->prio);
-    cls->rec = dht->get_start(&dht_table,
-                             type,
-                             keyCount,
+    cls->rec = dht->get_start(type,
                              &rs->query[0],
                              ntohll(rs->expiration),
                              (DataProcessor) &get_result_callback,

Modified: GNUnet/src/include/gnunet_dht_service.h
===================================================================
--- GNUnet/src/include/gnunet_dht_service.h     2006-12-03 04:37:46 UTC (rev 
3856)
+++ GNUnet/src/include/gnunet_dht_service.h     2006-12-03 05:21:11 UTC (rev 
3857)
@@ -42,11 +42,8 @@
 #endif
 #endif
 
-
 struct DHT_GET_RECORD;
 
-struct DHT_PUT_RECORD;
-
 /**
  * DHT operation 'complete' (i.e timed out).
  */
@@ -70,10 +67,8 @@
    * @param closure extra argument to callback
    * @return handle to stop the async get
    */
-  struct DHT_GET_RECORD * (*get_start)(const DHT_TableId * table,
-                                      unsigned int type,
-                                      unsigned int keyCount,
-                                      const HashCode512 * keys,
+  struct DHT_GET_RECORD * (*get_start)(unsigned int type,
+                                      const HashCode512 * key,
                                       cron_t timeout,
                                       DataProcessor callback,
                                       void * cls,
@@ -86,31 +81,18 @@
   int (*get_stop)(struct DHT_GET_RECORD * record);
 
   /**
-   * Perform an asynchronous PUT operation on the DHT identified by
-   * 'table' storing a binding of 'key' to 'value'.  The peer does not
-   * have to be part of the table (if so, we will attempt to locate a
-   * peer that is!)
+   * Perform a PUT operation on the DHT identified by 'table' storing
+   * a binding of 'key' to 'value'.  The peer does not have to be part
+   * of the table (if so, we will attempt to locate a peer that is!)
    *
-   * @param table table to use for the lookup
-   * @param key the key to look up
-   * @param timeout how long to wait until this operation should
-   *        automatically time-out
-   * @param callback function to call on successful completion
-   * @param closure extra argument to callback
-   * @return handle to stop the async put
+   * @param key the key to store under
    */
-  struct DHT_PUT_RECORD * (*put_start)(const DHT_TableId * table,
-                                      const HashCode512 * key,
-                                      cron_t timeout,
-                                      const DataContainer * value,
-                                      DHT_OP_Complete callback,
-                                      void * closure);
+  void (*put)(const HashCode512 * key,
+             unsigned int type,
+             unsigned int size,
+             cron_t expire,
+             const char * data);
 
-  /**
-   * Stop async DHT-put.  Frees associated resources.
-   */
-  int (*put_stop)(struct DHT_PUT_RECORD * record);
-
 } DHT_ServiceAPI;
 
 #if 0 /* keep Emacsens' auto-indent happy */





reply via email to

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