diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-02 21:37:25 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-02 21:37:25 +0000 |
commit | 8c07cc8d5497d769337146660ae835d689c9754d (patch) | |
tree | 0babf74eca341705bfaf8cb484803d8adc4c91a5 /src/datastore | |
parent | 60b8cc395876876e5b477e8a7a9b028734878e26 (diff) | |
download | gnunet-8c07cc8d5497d769337146660ae835d689c9754d.tar.gz gnunet-8c07cc8d5497d769337146660ae835d689c9754d.zip |
use sqlite PRNG also on insertion
Diffstat (limited to 'src/datastore')
-rw-r--r-- | src/datastore/plugin_datastore_sqlite.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index 1e1f4d87b..fb4f2c0d9 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c | |||
@@ -326,13 +326,13 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
326 | (sq_prepare (plugin->dbh, | 326 | (sq_prepare (plugin->dbh, |
327 | "UPDATE gn090 SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?", | 327 | "UPDATE gn090 SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?", |
328 | &plugin->updRepl) != SQLITE_OK) || | 328 | &plugin->updRepl) != SQLITE_OK) || |
329 | #if 1 | 329 | #if 0 |
330 | /* FIXME: this is the O(n) version */ | 330 | /* FIXME: this is the O(n) version */ |
331 | (sq_prepare (plugin->dbh, | 331 | (sq_prepare (plugin->dbh, |
332 | "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn090" | 332 | "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn090" |
333 | " ORDER BY repl DESC, Random() LIMIT 1", | 333 | " ORDER BY repl DESC, Random() LIMIT 1", |
334 | &plugin->selRepl) != SQLITE_OK) || | 334 | &plugin->selRepl) != SQLITE_OK) || |
335 | #elif 0 | 335 | #elif 1 |
336 | /* FIXME: this gives O(n) queries, presumably because the LEFT JOIN generates | 336 | /* FIXME: this gives O(n) queries, presumably because the LEFT JOIN generates |
337 | a temporary table with all matching expressions before the ORDER BY and LIMIT | 337 | a temporary table with all matching expressions before the ORDER BY and LIMIT |
338 | clauses are applied */ | 338 | clauses are applied */ |
@@ -375,7 +375,7 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
375 | (sq_prepare (plugin->dbh, | 375 | (sq_prepare (plugin->dbh, |
376 | "INSERT INTO gn090 (repl, type, prio, " | 376 | "INSERT INTO gn090 (repl, type, prio, " |
377 | "anonLevel, expire, rvalue, hash, vhash, value) " | 377 | "anonLevel, expire, rvalue, hash, vhash, value) " |
378 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", | 378 | "VALUES (?, ?, ?, ?, ?, RANDOM(), ?, ?, ?)", |
379 | &plugin->insertContent) != SQLITE_OK) || | 379 | &plugin->insertContent) != SQLITE_OK) || |
380 | (sq_prepare (plugin->dbh, | 380 | (sq_prepare (plugin->dbh, |
381 | "DELETE FROM gn090 WHERE _ROWID_ = ?", | 381 | "DELETE FROM gn090 WHERE _ROWID_ = ?", |
@@ -524,7 +524,6 @@ sqlite_plugin_put (void *cls, | |||
524 | int ret; | 524 | int ret; |
525 | sqlite3_stmt *stmt; | 525 | sqlite3_stmt *stmt; |
526 | GNUNET_HashCode vhash; | 526 | GNUNET_HashCode vhash; |
527 | uint64_t rvalue; | ||
528 | 527 | ||
529 | if (size > MAX_ITEM_SIZE) | 528 | if (size > MAX_ITEM_SIZE) |
530 | return GNUNET_SYSERR; | 529 | return GNUNET_SYSERR; |
@@ -540,21 +539,19 @@ sqlite_plugin_put (void *cls, | |||
540 | #endif | 539 | #endif |
541 | GNUNET_CRYPTO_hash (data, size, &vhash); | 540 | GNUNET_CRYPTO_hash (data, size, &vhash); |
542 | stmt = plugin->insertContent; | 541 | stmt = plugin->insertContent; |
543 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); | ||
544 | if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, replication)) || | 542 | if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, replication)) || |
545 | (SQLITE_OK != sqlite3_bind_int (stmt, 2, type)) || | 543 | (SQLITE_OK != sqlite3_bind_int (stmt, 2, type)) || |
546 | (SQLITE_OK != sqlite3_bind_int (stmt, 3, priority)) || | 544 | (SQLITE_OK != sqlite3_bind_int (stmt, 3, priority)) || |
547 | (SQLITE_OK != sqlite3_bind_int (stmt, 4, anonymity)) || | 545 | (SQLITE_OK != sqlite3_bind_int (stmt, 4, anonymity)) || |
548 | (SQLITE_OK != sqlite3_bind_int64 (stmt, 5, expiration.abs_value)) || | 546 | (SQLITE_OK != sqlite3_bind_int64 (stmt, 5, expiration.abs_value)) || |
549 | (SQLITE_OK != sqlite3_bind_int64 (stmt, 6, rvalue)) || | ||
550 | (SQLITE_OK != | 547 | (SQLITE_OK != |
551 | sqlite3_bind_blob (stmt, 7, key, sizeof (GNUNET_HashCode), | 548 | sqlite3_bind_blob (stmt, 6, key, sizeof (GNUNET_HashCode), |
552 | SQLITE_TRANSIENT)) || | 549 | SQLITE_TRANSIENT)) || |
553 | (SQLITE_OK != | 550 | (SQLITE_OK != |
554 | sqlite3_bind_blob (stmt, 8, &vhash, sizeof (GNUNET_HashCode), | 551 | sqlite3_bind_blob (stmt, 7, &vhash, sizeof (GNUNET_HashCode), |
555 | SQLITE_TRANSIENT)) | 552 | SQLITE_TRANSIENT)) |
556 | || (SQLITE_OK != | 553 | || (SQLITE_OK != |
557 | sqlite3_bind_blob (stmt, 9, data, size, | 554 | sqlite3_bind_blob (stmt, 8, data, size, |
558 | SQLITE_TRANSIENT))) | 555 | SQLITE_TRANSIENT))) |
559 | { | 556 | { |
560 | LOG_SQLITE (plugin, | 557 | LOG_SQLITE (plugin, |