aboutsummaryrefslogtreecommitdiff
path: root/src/namecache
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-03-08 16:27:21 +0100
committerChristian Grothoff <christian@grothoff.org>2018-03-08 16:43:05 +0100
commitb52546aa5836a260fa9fca2edb5287d48cc44a2f (patch)
treeb8c08e9fe4a7cb762bcfbbcbffa6a6cee06aa50c /src/namecache
parent02a56bb50dbdda2c38c197e76a27d7ed03ec3083 (diff)
downloadgnunet-b52546aa5836a260fa9fca2edb5287d48cc44a2f.tar.gz
gnunet-b52546aa5836a260fa9fca2edb5287d48cc44a2f.zip
enforce query is primary key
Diffstat (limited to 'src/namecache')
-rw-r--r--src/namecache/plugin_namecache_sqlite.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/src/namecache/plugin_namecache_sqlite.c b/src/namecache/plugin_namecache_sqlite.c
index 2f7b2a981..669729f37 100644
--- a/src/namecache/plugin_namecache_sqlite.c
+++ b/src/namecache/plugin_namecache_sqlite.c
@@ -23,7 +23,6 @@
23 * @brief sqlite-based namecache backend 23 * @brief sqlite-based namecache backend
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26
27#include "platform.h" 26#include "platform.h"
28#include "gnunet_sq_lib.h" 27#include "gnunet_sq_lib.h"
29#include "gnunet_namecache_plugin.h" 28#include "gnunet_namecache_plugin.h"
@@ -106,16 +105,23 @@ struct Plugin
106 * @return 0 on success 105 * @return 0 on success
107 */ 106 */
108static int 107static int
109sq_prepare (sqlite3 * dbh, const char *zSql, sqlite3_stmt ** ppStmt) 108sq_prepare (sqlite3 *dbh,
109 const char *zSql,
110 sqlite3_stmt **ppStmt)
110{ 111{
111 char *dummy; 112 char *dummy;
112 int result; 113 int result;
113 114
114 result = 115 result = sqlite3_prepare_v2 (dbh,
115 sqlite3_prepare_v2 (dbh, zSql, strlen (zSql), ppStmt, 116 zSql,
116 (const char **) &dummy); 117 strlen (zSql),
118 ppStmt,
119 (const char **) &dummy);
117 LOG (GNUNET_ERROR_TYPE_DEBUG, 120 LOG (GNUNET_ERROR_TYPE_DEBUG,
118 "Prepared `%s' / %p: %d\n", zSql, *ppStmt, result); 121 "Prepared `%s' / %p: %d\n",
122 zSql,
123 *ppStmt,
124 result);
119 return result; 125 return result;
120} 126}
121 127
@@ -168,16 +174,21 @@ database_setup (struct Plugin *plugin)
168#endif 174#endif
169 175
170 if (GNUNET_OK != 176 if (GNUNET_OK !=
171 GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, "namecache-sqlite", 177 GNUNET_CONFIGURATION_get_value_filename (plugin->cfg,
172 "FILENAME", &afsdir)) 178 "namecache-sqlite",
179 "FILENAME",
180 &afsdir))
173 { 181 {
174 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 182 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
175 "namecache-sqlite", "FILENAME"); 183 "namecache-sqlite",
184 "FILENAME");
176 return GNUNET_SYSERR; 185 return GNUNET_SYSERR;
177 } 186 }
178 if (GNUNET_OK != GNUNET_DISK_file_test (afsdir)) 187 if (GNUNET_OK !=
188 GNUNET_DISK_file_test (afsdir))
179 { 189 {
180 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir)) 190 if (GNUNET_OK !=
191 GNUNET_DISK_directory_create_for_file (afsdir))
181 { 192 {
182 GNUNET_break (0); 193 GNUNET_break (0);
183 GNUNET_free (afsdir); 194 GNUNET_free (afsdir);
@@ -188,7 +199,8 @@ database_setup (struct Plugin *plugin)
188 plugin->fn = afsdir; 199 plugin->fn = afsdir;
189 200
190 /* Open database and precompile statements */ 201 /* Open database and precompile statements */
191 if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK) 202 if (SQLITE_OK !=
203 sqlite3_open (plugin->fn, &plugin->dbh))
192 { 204 {
193 LOG (GNUNET_ERROR_TYPE_ERROR, 205 LOG (GNUNET_ERROR_TYPE_ERROR,
194 _("Unable to initialize SQLite: %s.\n"), 206 _("Unable to initialize SQLite: %s.\n"),
@@ -229,9 +241,9 @@ database_setup (struct Plugin *plugin)
229 (sqlite3_exec 241 (sqlite3_exec
230 (plugin->dbh, 242 (plugin->dbh,
231 "CREATE TABLE ns096blocks (" 243 "CREATE TABLE ns096blocks ("
232 " query BLOB NOT NULL DEFAULT ''," 244 " query BLOB NOT NULL PRIMARY KEY,"
233 " block BLOB NOT NULL DEFAULT ''," 245 " block BLOB NOT NULL,"
234 " expiration_time INT8 NOT NULL DEFAULT 0" 246 " expiration_time INT8 NOT NULL"
235 ")", 247 ")",
236 NULL, NULL, NULL) != SQLITE_OK)) 248 NULL, NULL, NULL) != SQLITE_OK))
237 { 249 {
@@ -399,6 +411,10 @@ namecache_sqlite_cache_block (void *cls,
399 GNUNET_CRYPTO_hash (&block->derived_key, 411 GNUNET_CRYPTO_hash (&block->derived_key,
400 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), 412 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
401 &query); 413 &query);
414 fprintf (stderr,
415 "Caching new version of block %s (expires %llu)\n",
416 GNUNET_h2s (&query),
417 (unsigned long long) expiration.abs_value_us);
402 expiration = GNUNET_TIME_absolute_ntoh (block->expiration_time); 418 expiration = GNUNET_TIME_absolute_ntoh (block->expiration_time);
403 if (block_size > 64 * 65536) 419 if (block_size > 64 * 65536)
404 { 420 {