aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/peerstore/gnunet-service-peerstore.c6
-rw-r--r--src/peerstore/peerstore_api.c39
-rw-r--r--src/peerstore/plugin_peerstore_sqlite.c61
3 files changed, 39 insertions, 67 deletions
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c
index b78276922..c410630c9 100644
--- a/src/peerstore/gnunet-service-peerstore.c
+++ b/src/peerstore/gnunet-service-peerstore.c
@@ -67,6 +67,8 @@ shutdown_task (void *cls,
67 GNUNET_free (db_lib_name); 67 GNUNET_free (db_lib_name);
68 db_lib_name = NULL; 68 db_lib_name = NULL;
69 } 69 }
70
71 GNUNET_SCHEDULER_shutdown();
70} 72}
71 73
72/** 74/**
@@ -78,6 +80,8 @@ cleanup_expired_records(void *cls,
78{ 80{
79 int deleted; 81 int deleted;
80 82
83 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
84 return;
81 GNUNET_assert(NULL != db); 85 GNUNET_assert(NULL != db);
82 deleted = db->expire_records(db->cls, GNUNET_TIME_absolute_get()); 86 deleted = db->expire_records(db->cls, GNUNET_TIME_absolute_get());
83 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", deleted); 87 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", deleted);
@@ -266,7 +270,7 @@ run (void *cls,
266 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not load database backend `%s'\n", db_lib_name); 270 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not load database backend `%s'\n", db_lib_name);
267 else 271 else
268 { 272 {
269 cleanup_expired_records(NULL, NULL); 273 GNUNET_SCHEDULER_add_now(&cleanup_expired_records, NULL);
270 GNUNET_SERVER_add_handlers (server, handlers); 274 GNUNET_SERVER_add_handlers (server, handlers);
271 GNUNET_SERVER_disconnect_notify (server, 275 GNUNET_SERVER_disconnect_notify (server,
272 &handle_client_disconnect, 276 &handle_client_disconnect,
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c
index d6acd2daf..57c631852 100644
--- a/src/peerstore/peerstore_api.c
+++ b/src/peerstore/peerstore_api.c
@@ -161,6 +161,12 @@ struct GNUNET_PEERSTORE_IterateContext
161 */ 161 */
162 int request_sent; 162 int request_sent;
163 163
164 /**
165 * Task identifier for the function called
166 * on iterate request timeout
167 */
168 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
169
164}; 170};
165 171
166/******************************************************************************/ 172/******************************************************************************/
@@ -432,7 +438,7 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
432 GNUNET_PEERSTORE_Continuation cont, 438 GNUNET_PEERSTORE_Continuation cont,
433 void *cont_cls) 439 void *cont_cls)
434{ 440{
435 struct GNUNET_MQ_Envelope *ev; 441 struct GNUNET_MQ_Envelope *ev; //FIXME: add 'replace' flag in store function (similar to multihashmap)
436 struct GNUNET_PEERSTORE_StoreContext *sc; 442 struct GNUNET_PEERSTORE_StoreContext *sc;
437 443
438 LOG (GNUNET_ERROR_TYPE_DEBUG, 444 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -452,7 +458,7 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
452 sc->h = h; 458 sc->h = h;
453 sc->request_sent = GNUNET_NO; 459 sc->request_sent = GNUNET_NO;
454 GNUNET_CONTAINER_DLL_insert(h->store_head, h->store_tail, sc); 460 GNUNET_CONTAINER_DLL_insert(h->store_head, h->store_tail, sc);
455 GNUNET_MQ_notify_sent(ev, &store_request_sent, ev); 461 GNUNET_MQ_notify_sent(ev, &store_request_sent, sc);
456 GNUNET_MQ_send(h->mq, ev); 462 GNUNET_MQ_send(h->mq, ev);
457 return sc; 463 return sc;
458 464
@@ -499,8 +505,7 @@ void handle_iterate_result (void *cls, const struct GNUNET_MessageHeader *msg)
499 msg_type = ntohs(msg->type); 505 msg_type = ntohs(msg->type);
500 if(GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END == msg_type) 506 if(GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END == msg_type)
501 { 507 {
502 GNUNET_CONTAINER_DLL_remove(ic->h->iterate_head, ic->h->iterate_tail, ic); 508 GNUNET_PEERSTORE_iterate_cancel(ic);
503 GNUNET_free(ic);
504 if(NULL != callback) 509 if(NULL != callback)
505 callback(callback_cls, NULL, NULL); 510 callback(callback_cls, NULL, NULL);
506 return; 511 return;
@@ -533,6 +538,19 @@ void iterate_request_sent (void *cls)
533} 538}
534 539
535/** 540/**
541 * Called when the iterate request is timedout
542 *
543 * @param cls a 'struct GNUNET_PEERSTORE_IterateContext *'
544 */
545void iterate_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
546{
547 struct GNUNET_PEERSTORE_IterateContext *ic = cls;
548
549 ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
550 GNUNET_PEERSTORE_iterate_cancel(ic);
551}
552
553/**
536 * Cancel an iterate request 554 * Cancel an iterate request
537 * Please do not call after the iterate request is done 555 * Please do not call after the iterate request is done
538 * 556 *
@@ -541,7 +559,12 @@ void iterate_request_sent (void *cls)
541void 559void
542GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) 560GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic)
543{ 561{
544 LOG(GNUNET_ERROR_TYPE_DEBUG, "User request cancel of iterate request.\n"); 562 LOG(GNUNET_ERROR_TYPE_DEBUG, "Canceling iterate request.\n");
563 if(GNUNET_SCHEDULER_NO_TASK != ic->timeout_task)
564 {
565 GNUNET_SCHEDULER_cancel(ic->timeout_task);
566 ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
567 }
545 if(GNUNET_NO == ic->request_sent) 568 if(GNUNET_NO == ic->request_sent)
546 { 569 {
547 if(NULL != ic->ev) 570 if(NULL != ic->ev)
@@ -566,13 +589,14 @@ GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic)
566 * @param timeout time after which the iterate request is canceled 589 * @param timeout time after which the iterate request is canceled
567 * @param callback function called with each matching record, all NULL's on end 590 * @param callback function called with each matching record, all NULL's on end
568 * @param callback_cls closure for @a callback 591 * @param callback_cls closure for @a callback
592 * @return Handle to iteration request
569 */ 593 */
570struct GNUNET_PEERSTORE_IterateContext * 594struct GNUNET_PEERSTORE_IterateContext *
571GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, 595GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
572 char *sub_system, 596 char *sub_system,
573 const struct GNUNET_PeerIdentity *peer, 597 const struct GNUNET_PeerIdentity *peer,
574 const char *key, 598 const char *key,
575 struct GNUNET_TIME_Relative timeout, //FIXME: handle timeout 599 struct GNUNET_TIME_Relative timeout,
576 GNUNET_PEERSTORE_Processor callback, void *callback_cls) 600 GNUNET_PEERSTORE_Processor callback, void *callback_cls)
577{ 601{
578 struct GNUNET_MQ_Envelope *ev; 602 struct GNUNET_MQ_Envelope *ev;
@@ -594,8 +618,9 @@ GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
594 GNUNET_CONTAINER_DLL_insert(h->iterate_head, h->iterate_tail, ic); 618 GNUNET_CONTAINER_DLL_insert(h->iterate_head, h->iterate_tail, ic);
595 LOG(GNUNET_ERROR_TYPE_DEBUG, 619 LOG(GNUNET_ERROR_TYPE_DEBUG,
596 "Sending an iterate request for sub system `%s'\n", sub_system); 620 "Sending an iterate request for sub system `%s'\n", sub_system);
597 GNUNET_MQ_notify_sent(ev, &iterate_request_sent, ev); 621 GNUNET_MQ_notify_sent(ev, &iterate_request_sent, ic);
598 GNUNET_MQ_send(h->mq, ev); 622 GNUNET_MQ_send(h->mq, ev);
623 ic->timeout_task = GNUNET_SCHEDULER_add_delayed(timeout, &iterate_timeout, ic);
599 return ic; 624 return ic;
600} 625}
601 626
diff --git a/src/peerstore/plugin_peerstore_sqlite.c b/src/peerstore/plugin_peerstore_sqlite.c
index ead2aade6..8d35466de 100644
--- a/src/peerstore/plugin_peerstore_sqlite.c
+++ b/src/peerstore/plugin_peerstore_sqlite.c
@@ -51,6 +51,8 @@
51 51
52#define LOG(kind,...) GNUNET_log_from (kind, "peerstore-sqlite", __VA_ARGS__) 52#define LOG(kind,...) GNUNET_log_from (kind, "peerstore-sqlite", __VA_ARGS__)
53 53
54//FIXME: Indexes
55
54/** 56/**
55 * Context for all functions in this plugin. 57 * Context for all functions in this plugin.
56 */ 58 */
@@ -98,11 +100,6 @@ struct Plugin
98 sqlite3_stmt *select_peerstoredata_by_all; 100 sqlite3_stmt *select_peerstoredata_by_all;
99 101
100 /** 102 /**
101 * Precompiled SQL for selecting from peerstoredata
102 */
103 sqlite3_stmt *select_peerstoredata_by_all_and_value;
104
105 /**
106 * Precompiled SQL for deleting expired records from peerstoredata 103 * Precompiled SQL for deleting expired records from peerstoredata
107 */ 104 */
108 sqlite3_stmt *expire_peerstoredata; 105 sqlite3_stmt *expire_peerstoredata;
@@ -237,42 +234,6 @@ peerstore_sqlite_iterate_records (void *cls,
237} 234}
238 235
239/** 236/**
240 * Checks if a record with the given information
241 * already exists
242 *
243 * @return #GNUNET_YES / #GNUNET_NO
244 *
245static int
246check_existing(void *cls,
247 const char *sub_system,
248 const struct GNUNET_PeerIdentity *peer,
249 const char *key,
250 const void *value,
251 size_t size)
252{
253 struct Plugin *plugin = cls;
254 sqlite3_stmt *stmt = plugin->select_peerstoredata_by_all_and_value;
255 int sret;
256
257 if(SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 1, SQLITE_STATIC)
258 || SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct GNUNET_PeerIdentity), SQLITE_STATIC)
259 || SQLITE_OK != sqlite3_bind_text(stmt, 3, key, strlen(key) + 1, SQLITE_STATIC)
260 || SQLITE_OK != sqlite3_bind_blob(stmt, 4, value, size, SQLITE_STATIC))
261 {
262 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
263 "sqlite3_bind");
264 sqlite3_reset(stmt);
265 return GNUNET_NO;
266 }
267 sret = sqlite3_step (stmt);
268 sqlite3_reset(stmt);
269 if(SQLITE_ROW == sret)
270 return GNUNET_YES;
271 return GNUNET_NO;
272
273}*/
274
275/**
276 * Store a record in the peerstore. 237 * Store a record in the peerstore.
277 * Key is the combination of sub system and peer identity. 238 * Key is the combination of sub system and peer identity.
278 * One key can store multiple values. 239 * One key can store multiple values.
@@ -296,17 +257,6 @@ peerstore_sqlite_store_record(void *cls,
296 struct Plugin *plugin = cls; 257 struct Plugin *plugin = cls;
297 sqlite3_stmt *stmt = plugin->insert_peerstoredata; 258 sqlite3_stmt *stmt = plugin->insert_peerstoredata;
298 259
299 //FIXME: check if value exists with the same key first
300 /*if(GNUNET_YES == check_existing(cls,
301 sub_system,
302 peer,
303 key,
304 value,
305 size))
306 {
307
308 }*/
309
310 if(SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 1, SQLITE_STATIC) 260 if(SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 1, SQLITE_STATIC)
311 || SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct GNUNET_PeerIdentity), SQLITE_STATIC) 261 || SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct GNUNET_PeerIdentity), SQLITE_STATIC)
312 || SQLITE_OK != sqlite3_bind_text(stmt, 3, key, strlen(key) + 1, SQLITE_STATIC) 262 || SQLITE_OK != sqlite3_bind_text(stmt, 3, key, strlen(key) + 1, SQLITE_STATIC)
@@ -466,13 +416,6 @@ database_setup (struct Plugin *plugin)
466 " AND key = ?", 416 " AND key = ?",
467 &plugin->select_peerstoredata_by_all); 417 &plugin->select_peerstoredata_by_all);
468 sql_prepare(plugin->dbh, 418 sql_prepare(plugin->dbh,
469 "SELECT * FROM peerstoredata"
470 " WHERE sub_system = ?"
471 " AND peer_id = ?"
472 " AND key = ?"
473 " AND value = ?",
474 &plugin->select_peerstoredata_by_all_and_value);
475 sql_prepare(plugin->dbh,
476 "DELETE FROM peerstoredata" 419 "DELETE FROM peerstoredata"
477 " WHERE expiry < ?", 420 " WHERE expiry < ?",
478 &plugin->expire_peerstoredata); 421 &plugin->expire_peerstoredata);