diff options
-rw-r--r-- | src/datastore/plugin_datastore_mysql.c | 8 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_postgres.c | 24 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_sqlite.c | 16 |
3 files changed, 32 insertions, 16 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c index ec263a035..db547cb30 100644 --- a/src/datastore/plugin_datastore_mysql.c +++ b/src/datastore/plugin_datastore_mysql.c | |||
@@ -194,7 +194,7 @@ struct Plugin | |||
194 | /** | 194 | /** |
195 | * Prepared statements. | 195 | * Prepared statements. |
196 | */ | 196 | */ |
197 | #define INSERT_ENTRY "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?)" | 197 | #define INSERT_ENTRY "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)" |
198 | struct GNUNET_MysqlStatementHandle *insert_entry; | 198 | struct GNUNET_MysqlStatementHandle *insert_entry; |
199 | 199 | ||
200 | #define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?" | 200 | #define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?" |
@@ -860,6 +860,7 @@ mysql_plugin_put (void *cls, | |||
860 | unsigned long hashSize; | 860 | unsigned long hashSize; |
861 | unsigned long hashSize2; | 861 | unsigned long hashSize2; |
862 | unsigned long lsize; | 862 | unsigned long lsize; |
863 | unsigned long rvalue; | ||
863 | GNUNET_HashCode vhash; | 864 | GNUNET_HashCode vhash; |
864 | 865 | ||
865 | if (size > MAX_DATUM_SIZE) | 866 | if (size > MAX_DATUM_SIZE) |
@@ -871,6 +872,7 @@ mysql_plugin_put (void *cls, | |||
871 | hashSize2 = sizeof (GNUNET_HashCode); | 872 | hashSize2 = sizeof (GNUNET_HashCode); |
872 | lsize = size; | 873 | lsize = size; |
873 | GNUNET_CRYPTO_hash (data, size, &vhash); | 874 | GNUNET_CRYPTO_hash (data, size, &vhash); |
875 | rvalue = (unsigned long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); | ||
874 | if (GNUNET_OK != | 876 | if (GNUNET_OK != |
875 | prepared_statement_run (plugin, | 877 | prepared_statement_run (plugin, |
876 | plugin->insert_entry, | 878 | plugin->insert_entry, |
@@ -880,6 +882,7 @@ mysql_plugin_put (void *cls, | |||
880 | MYSQL_TYPE_LONG, &ipriority, GNUNET_YES, | 882 | MYSQL_TYPE_LONG, &ipriority, GNUNET_YES, |
881 | MYSQL_TYPE_LONG, &ianonymity, GNUNET_YES, | 883 | MYSQL_TYPE_LONG, &ianonymity, GNUNET_YES, |
882 | MYSQL_TYPE_LONGLONG, &lexpiration, GNUNET_YES, | 884 | MYSQL_TYPE_LONGLONG, &lexpiration, GNUNET_YES, |
885 | MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, | ||
883 | MYSQL_TYPE_BLOB, key, hashSize, &hashSize, | 886 | MYSQL_TYPE_BLOB, key, hashSize, &hashSize, |
884 | MYSQL_TYPE_BLOB, &vhash, hashSize2, &hashSize2, | 887 | MYSQL_TYPE_BLOB, &vhash, hashSize2, &hashSize2, |
885 | MYSQL_TYPE_BLOB, data, lsize, &lsize, | 888 | MYSQL_TYPE_BLOB, data, lsize, &lsize, |
@@ -1441,6 +1444,7 @@ libgnunet_plugin_datastore_mysql_init (void *cls) | |||
1441 | " prio INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1444 | " prio INT(11) UNSIGNED NOT NULL DEFAULT 0," |
1442 | " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1445 | " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0," |
1443 | " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," | 1446 | " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," |
1447 | " rvalue BIGINT UNSIGNED NOT NULL," | ||
1444 | " hash BINARY(64) NOT NULL DEFAULT ''," | 1448 | " hash BINARY(64) NOT NULL DEFAULT ''," |
1445 | " vhash BINARY(64) NOT NULL DEFAULT ''," | 1449 | " vhash BINARY(64) NOT NULL DEFAULT ''," |
1446 | " value BLOB NOT NULL DEFAULT ''," | 1450 | " value BLOB NOT NULL DEFAULT ''," |
@@ -1451,7 +1455,7 @@ libgnunet_plugin_datastore_mysql_init (void *cls) | |||
1451 | " INDEX idx_hash_vhash (hash(64),vhash(64))," | 1455 | " INDEX idx_hash_vhash (hash(64),vhash(64))," |
1452 | " INDEX idx_hash_type_uid (hash(64),type,uid)," | 1456 | " INDEX idx_hash_type_uid (hash(64),type,uid)," |
1453 | " INDEX idx_prio (prio)," | 1457 | " INDEX idx_prio (prio)," |
1454 | " INDEX idx_repl (repl)," | 1458 | " INDEX idx_repl_rvalue (repl,rvalue)," |
1455 | " INDEX idx_expire_prio (expire,prio)," | 1459 | " INDEX idx_expire_prio (expire,prio)," |
1456 | " INDEX idx_anonLevel_uid (anonLevel,uid)" | 1460 | " INDEX idx_anonLevel_uid (anonLevel,uid)" |
1457 | ") ENGINE=InnoDB") || | 1461 | ") ENGINE=InnoDB") || |
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c index 30a6c20da..9d60100cf 100644 --- a/src/datastore/plugin_datastore_postgres.c +++ b/src/datastore/plugin_datastore_postgres.c | |||
@@ -190,6 +190,7 @@ init_connection (struct Plugin *plugin) | |||
190 | " prio INTEGER NOT NULL DEFAULT 0," | 190 | " prio INTEGER NOT NULL DEFAULT 0," |
191 | " anonLevel INTEGER NOT NULL DEFAULT 0," | 191 | " anonLevel INTEGER NOT NULL DEFAULT 0," |
192 | " expire BIGINT NOT NULL DEFAULT 0," | 192 | " expire BIGINT NOT NULL DEFAULT 0," |
193 | " rvalue BIGINT NOT NULL DEFAULT 0," | ||
193 | " hash BYTEA NOT NULL DEFAULT ''," | 194 | " hash BYTEA NOT NULL DEFAULT ''," |
194 | " vhash BYTEA NOT NULL DEFAULT ''," | 195 | " vhash BYTEA NOT NULL DEFAULT ''," |
195 | " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS"); | 196 | " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS"); |
@@ -218,14 +219,18 @@ init_connection (struct Plugin *plugin) | |||
218 | || (GNUNET_OK != | 219 | || (GNUNET_OK != |
219 | pq_exec (plugin, "CREATE INDEX idx_expire ON gn090 (expire)", __LINE__)) | 220 | pq_exec (plugin, "CREATE INDEX idx_expire ON gn090 (expire)", __LINE__)) |
220 | || (GNUNET_OK != | 221 | || (GNUNET_OK != |
221 | pq_exec (plugin, "CREATE INDEX idx_comb3 ON gn090 (prio,anonLevel)", | 222 | pq_exec (plugin, "CREATE INDEX idx_prio_anon ON gn090 (prio,anonLevel)", |
222 | __LINE__)) | 223 | __LINE__)) |
223 | || (GNUNET_OK != | 224 | || (GNUNET_OK != |
224 | pq_exec | 225 | pq_exec |
225 | (plugin, "CREATE INDEX idx_comb4 ON gn090 (prio,hash,anonLevel)", | 226 | (plugin, "CREATE INDEX idx_prio_hash_anon ON gn090 (prio,hash,anonLevel)", |
226 | __LINE__)) | 227 | __LINE__)) |
227 | || (GNUNET_OK != | 228 | || (GNUNET_OK != |
228 | pq_exec (plugin, "CREATE INDEX idx_comb7 ON gn090 (expire,hash)", | 229 | pq_exec |
230 | (plugin, "CREATE INDEX idx_repl_rvalue ON gn090 (repl,rvalue)", | ||
231 | __LINE__)) | ||
232 | || (GNUNET_OK != | ||
233 | pq_exec (plugin, "CREATE INDEX idx_expire_hash ON gn090 (expire,hash)", | ||
229 | __LINE__))) | 234 | __LINE__))) |
230 | { | 235 | { |
231 | PQclear (ret); | 236 | PQclear (ret); |
@@ -305,9 +310,9 @@ init_connection (struct Plugin *plugin) | |||
305 | (GNUNET_OK != | 310 | (GNUNET_OK != |
306 | pq_prepare (plugin, | 311 | pq_prepare (plugin, |
307 | "put", | 312 | "put", |
308 | "INSERT INTO gn090 (repl, type, prio, anonLevel, expire, hash, vhash, value) " | 313 | "INSERT INTO gn090 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) " |
309 | "VALUES ($1, $2, $3, $4, $5, $6, $7, $8)", | 314 | "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", |
310 | 8, | 315 | 9, |
311 | __LINE__)) || | 316 | __LINE__)) || |
312 | (GNUNET_OK != | 317 | (GNUNET_OK != |
313 | pq_prepare (plugin, | 318 | pq_prepare (plugin, |
@@ -472,12 +477,14 @@ postgres_plugin_put (void *cls, | |||
472 | uint32_t banon = htonl (anonymity); | 477 | uint32_t banon = htonl (anonymity); |
473 | uint32_t brepl = htonl (replication); | 478 | uint32_t brepl = htonl (replication); |
474 | uint64_t bexpi = GNUNET_TIME_absolute_hton (expiration).abs_value__; | 479 | uint64_t bexpi = GNUNET_TIME_absolute_hton (expiration).abs_value__; |
480 | uint64_t rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); | ||
475 | const char *paramValues[] = { | 481 | const char *paramValues[] = { |
476 | (const char *) &brepl, | 482 | (const char *) &brepl, |
477 | (const char *) &btype, | 483 | (const char *) &btype, |
478 | (const char *) &bprio, | 484 | (const char *) &bprio, |
479 | (const char *) &banon, | 485 | (const char *) &banon, |
480 | (const char *) &bexpi, | 486 | (const char *) &bexpi, |
487 | (const char *) &rvalue, | ||
481 | (const char *) key, | 488 | (const char *) key, |
482 | (const char *) &vhash, | 489 | (const char *) &vhash, |
483 | (const char *) data | 490 | (const char *) data |
@@ -488,15 +495,16 @@ postgres_plugin_put (void *cls, | |||
488 | sizeof (bprio), | 495 | sizeof (bprio), |
489 | sizeof (banon), | 496 | sizeof (banon), |
490 | sizeof (bexpi), | 497 | sizeof (bexpi), |
498 | sizeof (rvalue), | ||
491 | sizeof (GNUNET_HashCode), | 499 | sizeof (GNUNET_HashCode), |
492 | sizeof (GNUNET_HashCode), | 500 | sizeof (GNUNET_HashCode), |
493 | size | 501 | size |
494 | }; | 502 | }; |
495 | const int paramFormats[] = { 1, 1, 1, 1, 1, 1, 1, 1 }; | 503 | const int paramFormats[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 }; |
496 | 504 | ||
497 | GNUNET_CRYPTO_hash (data, size, &vhash); | 505 | GNUNET_CRYPTO_hash (data, size, &vhash); |
498 | ret = PQexecPrepared (plugin->dbh, | 506 | ret = PQexecPrepared (plugin->dbh, |
499 | "put", 8, paramValues, paramLengths, paramFormats, 1); | 507 | "put", 9, paramValues, paramLengths, paramFormats, 1); |
500 | if (GNUNET_OK != check_result (plugin, ret, | 508 | if (GNUNET_OK != check_result (plugin, ret, |
501 | PGRES_COMMAND_OK, | 509 | PGRES_COMMAND_OK, |
502 | "PQexecPrepared", "put", __LINE__)) | 510 | "PQexecPrepared", "put", __LINE__)) |
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index 3267869d5..613b6a1a7 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c | |||
@@ -178,7 +178,7 @@ create_indices (sqlite3 * dbh) | |||
178 | NULL, NULL, NULL); | 178 | NULL, NULL, NULL); |
179 | sqlite3_exec (dbh, "CREATE INDEX idx_expire ON gn090 (expire)", | 179 | sqlite3_exec (dbh, "CREATE INDEX idx_expire ON gn090 (expire)", |
180 | NULL, NULL, NULL); | 180 | NULL, NULL, NULL); |
181 | sqlite3_exec (dbh, "CREATE INDEX idx_repl ON gn090 (repl)", | 181 | sqlite3_exec (dbh, "CREATE INDEX idx_repl_rvalue ON gn090 (repl,rvalue)", |
182 | NULL, NULL, NULL); | 182 | NULL, NULL, NULL); |
183 | } | 183 | } |
184 | 184 | ||
@@ -292,6 +292,7 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
292 | " prio INT4 NOT NULL DEFAULT 0," | 292 | " prio INT4 NOT NULL DEFAULT 0," |
293 | " anonLevel INT4 NOT NULL DEFAULT 0," | 293 | " anonLevel INT4 NOT NULL DEFAULT 0," |
294 | " expire INT8 NOT NULL DEFAULT 0," | 294 | " expire INT8 NOT NULL DEFAULT 0," |
295 | " rvalue INT8 NOT NULL," | ||
295 | " hash TEXT NOT NULL DEFAULT ''," | 296 | " hash TEXT NOT NULL DEFAULT ''," |
296 | " vhash TEXT NOT NULL DEFAULT ''," | 297 | " vhash TEXT NOT NULL DEFAULT ''," |
297 | " value BLOB NOT NULL DEFAULT '')", NULL, NULL, | 298 | " value BLOB NOT NULL DEFAULT '')", NULL, NULL, |
@@ -328,8 +329,8 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
328 | &plugin->selZeroAnon) != SQLITE_OK) || | 329 | &plugin->selZeroAnon) != SQLITE_OK) || |
329 | (sq_prepare (plugin->dbh, | 330 | (sq_prepare (plugin->dbh, |
330 | "INSERT INTO gn090 (repl, type, prio, " | 331 | "INSERT INTO gn090 (repl, type, prio, " |
331 | "anonLevel, expire, hash, vhash, value) " | 332 | "anonLevel, expire, rvalue, hash, vhash, value) " |
332 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?)", | 333 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", |
333 | &plugin->insertContent) != SQLITE_OK) || | 334 | &plugin->insertContent) != SQLITE_OK) || |
334 | (sq_prepare (plugin->dbh, | 335 | (sq_prepare (plugin->dbh, |
335 | "DELETE FROM gn090 WHERE _ROWID_ = ?", | 336 | "DELETE FROM gn090 WHERE _ROWID_ = ?", |
@@ -469,6 +470,7 @@ sqlite_plugin_put (void *cls, | |||
469 | int ret; | 470 | int ret; |
470 | sqlite3_stmt *stmt; | 471 | sqlite3_stmt *stmt; |
471 | GNUNET_HashCode vhash; | 472 | GNUNET_HashCode vhash; |
473 | uint64_t rvalue; | ||
472 | 474 | ||
473 | if (size > MAX_ITEM_SIZE) | 475 | if (size > MAX_ITEM_SIZE) |
474 | return GNUNET_SYSERR; | 476 | return GNUNET_SYSERR; |
@@ -484,19 +486,21 @@ sqlite_plugin_put (void *cls, | |||
484 | #endif | 486 | #endif |
485 | GNUNET_CRYPTO_hash (data, size, &vhash); | 487 | GNUNET_CRYPTO_hash (data, size, &vhash); |
486 | stmt = plugin->insertContent; | 488 | stmt = plugin->insertContent; |
489 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); | ||
487 | if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, replication)) || | 490 | if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, replication)) || |
488 | (SQLITE_OK != sqlite3_bind_int (stmt, 2, type)) || | 491 | (SQLITE_OK != sqlite3_bind_int (stmt, 2, type)) || |
489 | (SQLITE_OK != sqlite3_bind_int (stmt, 3, priority)) || | 492 | (SQLITE_OK != sqlite3_bind_int (stmt, 3, priority)) || |
490 | (SQLITE_OK != sqlite3_bind_int (stmt, 4, anonymity)) || | 493 | (SQLITE_OK != sqlite3_bind_int (stmt, 4, anonymity)) || |
491 | (SQLITE_OK != sqlite3_bind_int64 (stmt, 5, expiration.abs_value)) || | 494 | (SQLITE_OK != sqlite3_bind_int64 (stmt, 5, expiration.abs_value)) || |
495 | (SQLITE_OK != sqlite3_bind_int64 (stmt, 6, rvalue)) || | ||
492 | (SQLITE_OK != | 496 | (SQLITE_OK != |
493 | sqlite3_bind_blob (stmt, 6, key, sizeof (GNUNET_HashCode), | 497 | sqlite3_bind_blob (stmt, 7, key, sizeof (GNUNET_HashCode), |
494 | SQLITE_TRANSIENT)) || | 498 | SQLITE_TRANSIENT)) || |
495 | (SQLITE_OK != | 499 | (SQLITE_OK != |
496 | sqlite3_bind_blob (stmt, 7, &vhash, sizeof (GNUNET_HashCode), | 500 | sqlite3_bind_blob (stmt, 8, &vhash, sizeof (GNUNET_HashCode), |
497 | SQLITE_TRANSIENT)) | 501 | SQLITE_TRANSIENT)) |
498 | || (SQLITE_OK != | 502 | || (SQLITE_OK != |
499 | sqlite3_bind_blob (stmt, 8, data, size, | 503 | sqlite3_bind_blob (stmt, 9, data, size, |
500 | SQLITE_TRANSIENT))) | 504 | SQLITE_TRANSIENT))) |
501 | { | 505 | { |
502 | LOG_SQLITE (plugin, | 506 | LOG_SQLITE (plugin, |