aboutsummaryrefslogtreecommitdiff
path: root/src/peerstore/plugin_peerstore_sqlite.c
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2014-12-15 00:32:17 +0000
committerDavid Barksdale <amatus.amongus@gmail.com>2014-12-15 00:32:17 +0000
commitbd94aa6fe80a7687c3727ebcdb3ba5185d3b8b11 (patch)
tree02c23cc57494a495c9da5f8e88e282a376ba4016 /src/peerstore/plugin_peerstore_sqlite.c
parent6c8fa85819a2b02b3c4a175a08c1779283eda209 (diff)
downloadgnunet-bd94aa6fe80a7687c3727ebcdb3ba5185d3b8b11.tar.gz
gnunet-bd94aa6fe80a7687c3727ebcdb3ba5185d3b8b11.zip
Implement asynchronous peerstore plugin API
Resolves #3506
Diffstat (limited to 'src/peerstore/plugin_peerstore_sqlite.c')
-rw-r--r--src/peerstore/plugin_peerstore_sqlite.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/peerstore/plugin_peerstore_sqlite.c b/src/peerstore/plugin_peerstore_sqlite.c
index fc644d9b7..cd402aaae 100644
--- a/src/peerstore/plugin_peerstore_sqlite.c
+++ b/src/peerstore/plugin_peerstore_sqlite.c
@@ -160,10 +160,15 @@ peerstore_sqlite_delete_records (void *cls, const char *sub_system,
160 * 160 *
161 * @param cls closure (internal context for the plugin) 161 * @param cls closure (internal context for the plugin)
162 * @param now time to use as reference 162 * @param now time to use as reference
163 * @return number of records deleted 163 * @param cont continuation called with the number of records expired
164 * @param cont_cls continuation closure
165 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and cont is not
166 * called
164 */ 167 */
165static int 168static int
166peerstore_sqlite_expire_records (void *cls, struct GNUNET_TIME_Absolute now) 169peerstore_sqlite_expire_records (void *cls, struct GNUNET_TIME_Absolute now,
170 GNUNET_PEERSTORE_Continuation cont,
171 void *cont_cls)
167{ 172{
168 struct Plugin *plugin = cls; 173 struct Plugin *plugin = cls;
169 sqlite3_stmt *stmt = plugin->expire_peerstoredata; 174 sqlite3_stmt *stmt = plugin->expire_peerstoredata;
@@ -183,9 +188,13 @@ peerstore_sqlite_expire_records (void *cls, struct GNUNET_TIME_Absolute now)
183 { 188 {
184 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 189 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
185 "sqlite3_reset"); 190 "sqlite3_reset");
186 return 0; 191 return GNUNET_SYSERR;
187 } 192 }
188 return sqlite3_changes (plugin->dbh); 193 if (NULL != cont)
194 {
195 cont (cont_cls, sqlite3_changes (plugin->dbh));
196 }
197 return GNUNET_OK;
189} 198}
190 199
191 200
@@ -197,9 +206,11 @@ peerstore_sqlite_expire_records (void *cls, struct GNUNET_TIME_Absolute now)
197 * @param sub_system name of sub system 206 * @param sub_system name of sub system
198 * @param peer Peer identity (can be NULL) 207 * @param peer Peer identity (can be NULL)
199 * @param key entry key string (can be NULL) 208 * @param key entry key string (can be NULL)
200 * @param iter function to call with the result 209 * @param iter function to call asynchronously with the results, terminated
210 * by a NULL result
201 * @param iter_cls closure for @a iter 211 * @param iter_cls closure for @a iter
202 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 212 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and iter is not
213 * called
203 */ 214 */
204static int 215static int
205peerstore_sqlite_iterate_records (void *cls, const char *sub_system, 216peerstore_sqlite_iterate_records (void *cls, const char *sub_system,
@@ -296,8 +307,10 @@ peerstore_sqlite_iterate_records (void *cls, const char *sub_system,
296 "sqlite3_reset"); 307 "sqlite3_reset");
297 err = 1; 308 err = 1;
298 } 309 }
299 if (err) 310 if (NULL != iter)
300 return GNUNET_SYSERR; 311 {
312 iter (iter_cls, NULL, err ? "sqlite error" : NULL);
313 }
301 return GNUNET_OK; 314 return GNUNET_OK;
302} 315}
303 316
@@ -315,14 +328,18 @@ peerstore_sqlite_iterate_records (void *cls, const char *sub_system,
315 * @param size size of value to be stored 328 * @param size size of value to be stored
316 * @param expiry absolute time after which the record is (possibly) deleted 329 * @param expiry absolute time after which the record is (possibly) deleted
317 * @param options options related to the store operation 330 * @param options options related to the store operation
318 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 331 * @param cont continuation called when record is stored
332 * @param cont_cls continuation closure
333 * @return #GNUNET_OK on success, else #GNUNET_SYSERR and cont is not called
319 */ 334 */
320static int 335static int
321peerstore_sqlite_store_record (void *cls, const char *sub_system, 336peerstore_sqlite_store_record (void *cls, const char *sub_system,
322 const struct GNUNET_PeerIdentity *peer, 337 const struct GNUNET_PeerIdentity *peer,
323 const char *key, const void *value, size_t size, 338 const char *key, const void *value, size_t size,
324 struct GNUNET_TIME_Absolute expiry, 339 struct GNUNET_TIME_Absolute expiry,
325 enum GNUNET_PEERSTORE_StoreOption options) 340 enum GNUNET_PEERSTORE_StoreOption options,
341 GNUNET_PEERSTORE_Continuation cont,
342 void *cont_cls)
326{ 343{
327 struct Plugin *plugin = cls; 344 struct Plugin *plugin = cls;
328 sqlite3_stmt *stmt = plugin->insert_peerstoredata; 345 sqlite3_stmt *stmt = plugin->insert_peerstoredata;
@@ -355,6 +372,10 @@ peerstore_sqlite_store_record (void *cls, const char *sub_system,
355 "sqlite3_reset"); 372 "sqlite3_reset");
356 return GNUNET_SYSERR; 373 return GNUNET_SYSERR;
357 } 374 }
375 if (NULL != cont)
376 {
377 cont (cont_cls, GNUNET_OK);
378 }
358 return GNUNET_OK; 379 return GNUNET_OK;
359} 380}
360 381