aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/plugin_namestore_sqlite.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-02 12:15:35 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-02 12:15:35 +0000
commit42b829bb6005f07403370931509d0f83b4235e15 (patch)
treedc70bfbb15271f45443e2d2267bfb3cb3fa490b1 /src/namestore/plugin_namestore_sqlite.c
parent98bbddca603be552e75903ac6ac5f44b9388977c (diff)
downloadgnunet-42b829bb6005f07403370931509d0f83b4235e15.tar.gz
gnunet-42b829bb6005f07403370931509d0f83b4235e15.zip
-address #3050, refresh encrypted blocks from plaintext blocks during iteration, compute block expiration time correctly
Diffstat (limited to 'src/namestore/plugin_namestore_sqlite.c')
-rw-r--r--src/namestore/plugin_namestore_sqlite.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index 4c040cc97..134b65395 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -77,6 +77,11 @@ struct Plugin
77 sqlite3_stmt *cache_block; 77 sqlite3_stmt *cache_block;
78 78
79 /** 79 /**
80 * Precompiled SQL for deleting an older block
81 */
82 sqlite3_stmt *delete_block;
83
84 /**
80 * Precompiled SQL for looking up a block 85 * Precompiled SQL for looking up a block
81 */ 86 */
82 sqlite3_stmt *lookup_block; 87 sqlite3_stmt *lookup_block;
@@ -305,6 +310,10 @@ database_setup (struct Plugin *plugin)
305 &plugin->expire_blocks) != SQLITE_OK) || 310 &plugin->expire_blocks) != SQLITE_OK) ||
306 (sq_prepare 311 (sq_prepare
307 (plugin->dbh, 312 (plugin->dbh,
313 "DELETE FROM ns096blocks WHERE query=? AND expiration_time<=?",
314 &plugin->delete_block) != SQLITE_OK) ||
315 (sq_prepare
316 (plugin->dbh,
308 "SELECT block FROM ns096blocks WHERE query=? ORDER BY expiration_time DESC LIMIT 1", 317 "SELECT block FROM ns096blocks WHERE query=? ORDER BY expiration_time DESC LIMIT 1",
309 &plugin->lookup_block) != SQLITE_OK) || 318 &plugin->lookup_block) != SQLITE_OK) ||
310 (sq_prepare 319 (sq_prepare
@@ -357,6 +366,8 @@ database_shutdown (struct Plugin *plugin)
357 sqlite3_finalize (plugin->lookup_block); 366 sqlite3_finalize (plugin->lookup_block);
358 if (NULL != plugin->expire_blocks) 367 if (NULL != plugin->expire_blocks)
359 sqlite3_finalize (plugin->expire_blocks); 368 sqlite3_finalize (plugin->expire_blocks);
369 if (NULL != plugin->delete_block)
370 sqlite3_finalize (plugin->delete_block);
360 if (NULL != plugin->store_records) 371 if (NULL != plugin->store_records)
361 sqlite3_finalize (plugin->store_records); 372 sqlite3_finalize (plugin->store_records);
362 if (NULL != plugin->delete_records) 373 if (NULL != plugin->delete_records)
@@ -470,6 +481,41 @@ namestore_sqlite_cache_block (void *cls,
470 GNUNET_break (0); 481 GNUNET_break (0);
471 return GNUNET_SYSERR; 482 return GNUNET_SYSERR;
472 } 483 }
484
485 /* delete old version of the block */
486 if ( (SQLITE_OK !=
487 sqlite3_bind_blob (plugin->delete_block, 1,
488 &query, sizeof (struct GNUNET_HashCode),
489 SQLITE_STATIC)) ||
490 (SQLITE_OK !=
491 sqlite3_bind_int64 (plugin->delete_block,
492 2, dval)) )
493 {
494 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
495 "sqlite3_bind_XXXX");
496 if (SQLITE_OK != sqlite3_reset (plugin->delete_block))
497 LOG_SQLITE (plugin,
498 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
499 "sqlite3_reset");
500 return GNUNET_SYSERR;
501 }
502 n = sqlite3_step (plugin->delete_block);
503 switch (n)
504 {
505 case SQLITE_DONE:
506 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Old block deleted\n");
507 break;
508 case SQLITE_BUSY:
509 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
510 "sqlite3_step");
511 break;
512 default:
513 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
514 "sqlite3_step");
515 break;
516 }
517
518 /* insert new version of the block */
473 if ((SQLITE_OK != 519 if ((SQLITE_OK !=
474 sqlite3_bind_blob (plugin->cache_block, 1, 520 sqlite3_bind_blob (plugin->cache_block, 1,
475 &query, sizeof (struct GNUNET_HashCode), 521 &query, sizeof (struct GNUNET_HashCode),