aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-07-26 21:47:30 +0000
committerChristian Grothoff <christian@grothoff.org>2009-07-26 21:47:30 +0000
commit138b0402c39ff1c8e725bc1fe3f96e0d7e82dd70 (patch)
tree74d69e9699cdfd40c1c07d43247401a693583fd6 /src
parent004df66e9aafab7fa042661cf1bb7879de5064be (diff)
downloadgnunet-138b0402c39ff1c8e725bc1fe3f96e0d7e82dd70.tar.gz
gnunet-138b0402c39ff1c8e725bc1fe3f96e0d7e82dd70.zip
DHT and datacache API refinements
Diffstat (limited to 'src')
-rw-r--r--src/datacache/perf_datacache_api.c1
-rw-r--r--src/datacache/plugin_datacache_sqlite.c5
-rw-r--r--src/datacache/test_datacache_api.c1
-rw-r--r--src/include/gnunet_datacache_lib.h2
-rw-r--r--src/include/gnunet_dht_service.h74
5 files changed, 77 insertions, 6 deletions
diff --git a/src/datacache/perf_datacache_api.c b/src/datacache/perf_datacache_api.c
index aa008a332..aa11fe122 100644
--- a/src/datacache/perf_datacache_api.c
+++ b/src/datacache/perf_datacache_api.c
@@ -38,6 +38,7 @@ static unsigned int found;
38 38
39static int 39static int
40checkIt (void *cls, 40checkIt (void *cls,
41 struct GNUNET_TIME_Absolute exp,
41 const GNUNET_HashCode * key, 42 const GNUNET_HashCode * key,
42 uint32_t size, 43 uint32_t size,
43 const char *data, 44 const char *data,
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index 51bbf60d7..5493dbb90 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -170,6 +170,7 @@ sqlite_plugin_get (void *cls,
170 struct Plugin *plugin = cls; 170 struct Plugin *plugin = cls;
171 sqlite3_stmt *stmt; 171 sqlite3_stmt *stmt;
172 struct GNUNET_TIME_Absolute now; 172 struct GNUNET_TIME_Absolute now;
173 struct GNUNET_TIME_Absolute exp;
173 unsigned int size; 174 unsigned int size;
174 const char *dat; 175 const char *dat;
175 unsigned int cnt; 176 unsigned int cnt;
@@ -218,7 +219,7 @@ sqlite_plugin_get (void *cls,
218 off = (off + 1) % total; 219 off = (off + 1) % total;
219 GNUNET_snprintf (scratch, 220 GNUNET_snprintf (scratch,
220 sizeof(scratch), 221 sizeof(scratch),
221 "SELECT value FROM ds090 WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET %u", 222 "SELECT value,expire FROM ds090 WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET %u",
222 off); 223 off);
223 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) 224 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
224 { 225 {
@@ -236,8 +237,10 @@ sqlite_plugin_get (void *cls,
236 break; 237 break;
237 size = sqlite3_column_bytes (stmt, 0); 238 size = sqlite3_column_bytes (stmt, 0);
238 dat = sqlite3_column_blob (stmt, 0); 239 dat = sqlite3_column_blob (stmt, 0);
240 exp.value = sqlite3_column_int64 (stmt, 1);
239 cnt++; 241 cnt++;
240 if (GNUNET_OK != iter (iter_cls, 242 if (GNUNET_OK != iter (iter_cls,
243 exp,
241 key, 244 key,
242 size, 245 size,
243 dat, 246 dat,
diff --git a/src/datacache/test_datacache_api.c b/src/datacache/test_datacache_api.c
index 5207fa2a5..8a5a356d2 100644
--- a/src/datacache/test_datacache_api.c
+++ b/src/datacache/test_datacache_api.c
@@ -35,6 +35,7 @@ static int ok;
35 35
36static int 36static int
37checkIt (void *cls, 37checkIt (void *cls,
38 struct GNUNET_TIME_Absolute exp,
38 const GNUNET_HashCode * key, 39 const GNUNET_HashCode * key,
39 uint32_t size, 40 uint32_t size,
40 const char *data, 41 const char *data,
diff --git a/src/include/gnunet_datacache_lib.h b/src/include/gnunet_datacache_lib.h
index 8eb724bfa..3bd76df32 100644
--- a/src/include/gnunet_datacache_lib.h
+++ b/src/include/gnunet_datacache_lib.h
@@ -74,6 +74,7 @@ void GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h);
74 * An iterator over a set of items stored in the datacache. 74 * An iterator over a set of items stored in the datacache.
75 * 75 *
76 * @param cls closure 76 * @param cls closure
77 * @param exp when will the content expire?
77 * @param key key for the content 78 * @param key key for the content
78 * @param size number of bytes in data 79 * @param size number of bytes in data
79 * @param data content stored 80 * @param data content stored
@@ -81,6 +82,7 @@ void GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h);
81 * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort 82 * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort
82 */ 83 */
83typedef int (*GNUNET_DATACACHE_Iterator) (void *cls, 84typedef int (*GNUNET_DATACACHE_Iterator) (void *cls,
85 struct GNUNET_TIME_Absolute exp,
84 const GNUNET_HashCode * key, 86 const GNUNET_HashCode * key,
85 uint32_t size, 87 uint32_t size,
86 const char *data, 88 const char *data,
diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h
index 8dcbc19c5..0dab0bcbc 100644
--- a/src/include/gnunet_dht_service.h
+++ b/src/include/gnunet_dht_service.h
@@ -37,11 +37,60 @@ extern "C"
37#endif 37#endif
38#endif 38#endif
39 39
40// FIXME: document 40
41/**
42 * Connection to the DHT service.
43 */
44struct GNUNET_DHT_Handle;
45
46
47/**
48 * Initialize the connection with the DHT service.
49 *
50 * @param cfg configuration to use
51 * @param sched scheduler to use
52 * @return NULL on error
53 */
54struct GNUNET_DHT_Handle *
55GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
56 struct GNUNET_SCHEDULER_Handle *sched);
57
58
59/**
60 * Shutdown connection with the DHT service.
61 *
62 * @param h connection to shut down
63 */
64void
65GNUNET_DHT_connect (struct GNUNET_DHT_Handle *h);
66
67
68/**
69 * Handle to control a GET operation.
70 */
41struct GNUNET_DHT_GetHandle; 71struct GNUNET_DHT_GetHandle;
42 72
43 73
44/** 74/**
75 * Iterator called on each result obtained for a GET
76 * operation.
77 *
78 * @param cls closure
79 * @param exp when will this value expire
80 * @param key key of the result
81 * @param type type of the result
82 * @param size number of bytes in data
83 * @param data pointer to the result data
84 */
85typedef void (*GNUNET_DHT_Iterator)(void *cls,
86 struct GNUNET_TIME_Absolute exp,
87 const GNUNET_HashCode * key,
88 uint32_t type,
89 uint32_t size,
90 const void *data);
91
92
93/**
45 * Perform an asynchronous GET operation on the DHT identified. 94 * Perform an asynchronous GET operation on the DHT identified.
46 * 95 *
47 * @param type expected type of the response object 96 * @param type expected type of the response object
@@ -60,23 +109,38 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *h,
60 109
61/** 110/**
62 * Stop async DHT-get. Frees associated resources. 111 * Stop async DHT-get. Frees associated resources.
112 *
113 * @param record GET operation to stop.
63 */ 114 */
64int GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *record); 115void
116GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *record);
65 117
66 118
67// FIXME: add continuation? expiration?
68/** 119/**
69 * Perform a PUT operation on the DHT identified by 'table' storing 120 * Perform a PUT operation on the DHT identified by 'table' storing
70 * a binding of 'key' to 'value'. The peer does not have to be part 121 * a binding of 'key' to 'value'. The peer does not have to be part
71 * of the table (if so, we will attempt to locate a peer that is!) 122 * of the table (if so, we will attempt to locate a peer that is!)
72 * 123 *
124 * @param h handle to DHT service
73 * @param key the key to store under 125 * @param key the key to store under
126 * @param type type of the value
127 * @param size number of bytes in data; must be less than 64k
128 * @param data the data to store
129 * @param exp desired expiration time for the value
130 * @param cont continuation to call when done;
131 * reason will be TIMEOUT on error,
132 * reason will be PREREQ_DONE on success
133 * @param cont_cls closure for cont
134 *
74 */ 135 */
75int GNUNET_DHT_put (struct GNUNET_DHT_Handle *h, 136int GNUNET_DHT_put (struct GNUNET_DHT_Handle *h,
76 const GNUNET_HashCode * key, 137 const GNUNET_HashCode * key,
77 uint32_t type, 138 uint32_t type,
78 uint32_t size, 139 uint32_t size,
79 const char *data); 140 const char *data,
141 struct GNUNET_TIME_Relative exp,
142 GNUNET_SCHEDULER_Task cont,
143 void *cont_cls);
80 144
81 145
82#if 0 /* keep Emacsens' auto-indent happy */ 146#if 0 /* keep Emacsens' auto-indent happy */