DHT and datacache API refinements
authorChristian Grothoff <christian@grothoff.org>
Sun, 26 Jul 2009 21:47:30 +0000 (21:47 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 26 Jul 2009 21:47:30 +0000 (21:47 +0000)
src/datacache/perf_datacache_api.c
src/datacache/plugin_datacache_sqlite.c
src/datacache/test_datacache_api.c
src/include/gnunet_datacache_lib.h
src/include/gnunet_dht_service.h

index aa008a33229de32c7917010dde6d9cdab04ce449..aa11fe122eb059c6d512456f121002603e9fdafa 100644 (file)
@@ -38,6 +38,7 @@ static unsigned int found;
 
 static int
 checkIt (void *cls,
+        struct GNUNET_TIME_Absolute exp,
         const GNUNET_HashCode * key,
          uint32_t size, 
         const char *data, 
index 51bbf60d7302c063a023c2da1302366f592fa632..5493dbb905916df3cc90b5ba0e37edd1a832c642 100644 (file)
@@ -170,6 +170,7 @@ sqlite_plugin_get (void *cls,
   struct Plugin *plugin = cls;
   sqlite3_stmt *stmt;
   struct GNUNET_TIME_Absolute now;
+  struct GNUNET_TIME_Absolute exp;
   unsigned int size;
   const char *dat;
   unsigned int cnt;
@@ -218,7 +219,7 @@ sqlite_plugin_get (void *cls,
       off = (off + 1) % total;
       GNUNET_snprintf (scratch, 
                       sizeof(scratch),
-                       "SELECT value FROM ds090 WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET %u",
+                       "SELECT value,expire FROM ds090 WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET %u",
                        off);
       if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
         {
@@ -236,8 +237,10 @@ sqlite_plugin_get (void *cls,
         break;
       size = sqlite3_column_bytes (stmt, 0);
       dat = sqlite3_column_blob (stmt, 0);
+      exp.value = sqlite3_column_int64 (stmt, 1);
       cnt++;
       if (GNUNET_OK != iter (iter_cls,
+                            exp,
                             key, 
                             size,
                             dat,
index 5207fa2a5dd0df4c4b05d6c3ab8a86aea5b4c862..8a5a356d264217bdb6e0f38152f604ebb308356b 100644 (file)
@@ -35,6 +35,7 @@ static int ok;
 
 static int
 checkIt (void *cls,
+        struct GNUNET_TIME_Absolute exp,
         const GNUNET_HashCode * key,
          uint32_t size, 
         const char *data, 
index 8eb724bfa2cfe9417dedfe4d228def70b94d7579..3bd76df3284a0ef5e228a8dfff0f0fc65886d14c 100644 (file)
@@ -74,6 +74,7 @@ void GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h);
  * An iterator over a set of items stored in the datacache.
  *
  * @param cls closure
+ * @param exp when will the content expire?
  * @param key key for the content
  * @param size number of bytes in data
  * @param data content stored
@@ -81,6 +82,7 @@ void GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h);
  * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort
  */
 typedef int (*GNUNET_DATACACHE_Iterator) (void *cls,
+                                         struct GNUNET_TIME_Absolute exp,
                                          const GNUNET_HashCode * key,
                                          uint32_t size,
                                          const char *data,
index 8dcbc19c53a0ca2137cf6272c0d70535c6a7aab1..0dab0bcbceea91a816daea4e4004ca9aeed65e2f 100644 (file)
@@ -37,10 +37,59 @@ extern "C"
 #endif
 #endif
 
-// FIXME: document
+
+/**
+ * Connection to the DHT service.
+ */
+struct GNUNET_DHT_Handle;
+
+
+/**
+ * Initialize the connection with the DHT service.
+ * 
+ * @param cfg configuration to use
+ * @param sched scheduler to use
+ * @return NULL on error
+ */
+struct GNUNET_DHT_Handle *
+GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                   struct GNUNET_SCHEDULER_Handle *sched);
+
+
+/**
+ * Shutdown connection with the DHT service.
+ *
+ * @param h connection to shut down
+ */
+void
+GNUNET_DHT_connect (struct GNUNET_DHT_Handle *h);
+
+
+/**
+ * Handle to control a GET operation.
+ */
 struct GNUNET_DHT_GetHandle;
 
 
+/**
+ * Iterator called on each result obtained for a GET
+ * operation.
+ *
+ * @param cls closure
+ * @param exp when will this value expire
+ * @param key key of the result
+ * @param type type of the result
+ * @param size number of bytes in data
+ * @param data pointer to the result data
+ */
+typedef void (*GNUNET_DHT_Iterator)(void *cls,
+                                   struct GNUNET_TIME_Absolute exp,
+                                   const GNUNET_HashCode * key,
+                                   uint32_t type,
+                                   uint32_t size,
+                                   const void *data);
+                     
+
 /**
  * Perform an asynchronous GET operation on the DHT identified.
  *
@@ -60,23 +109,38 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *h,
 
 /**
  * Stop async DHT-get.  Frees associated resources.
+ *
+ * @param record GET operation to stop.
  */
-int GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *record);
+void
+GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *record);
 
 
-// FIXME: add continuation? expiration?
 /**
  * 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 h handle to DHT service
  * @param key the key to store under
+ * @param type type of the value
+ * @param size number of bytes in data; must be less than 64k
+ * @param data the data to store
+ * @param exp desired expiration time for the value
+ * @param cont continuation to call when done; 
+ *             reason will be TIMEOUT on error,
+ *             reason will be PREREQ_DONE on success
+ * @param cont_cls closure for cont
+ * 
  */
 int GNUNET_DHT_put (struct GNUNET_DHT_Handle *h, 
                    const GNUNET_HashCode * key,
-                   uint32_t type, 
+                   uint32_t type,                  
                    uint32_t size, 
-                   const char *data);
+                   const char *data,
+                   struct GNUNET_TIME_Relative exp,
+                   GNUNET_SCHEDULER_Task cont,
+                   void *cont_cls);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */