diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-10-11 13:45:37 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-10-11 13:45:37 +0000 |
commit | 7e5d16c7dc211c0682b38deaa3bfa108b0b07bb3 (patch) | |
tree | 38ae8a2c7cdddf39b8b245de641189fcdf3ad233 /src/psycstore | |
parent | 70f367c6e35a8bfdd229771a48d48b0e6b3874f9 (diff) | |
download | gnunet-7e5d16c7dc211c0682b38deaa3bfa108b0b07bb3.tar.gz gnunet-7e5d16c7dc211c0682b38deaa3bfa108b0b07bb3.zip |
proper bail out if plugin loading fails
Diffstat (limited to 'src/psycstore')
-rw-r--r-- | src/psycstore/plugin_psycstore_mysql.c | 135 | ||||
-rw-r--r-- | src/psycstore/test_plugin_psycstore.c | 4 |
2 files changed, 73 insertions, 66 deletions
diff --git a/src/psycstore/plugin_psycstore_mysql.c b/src/psycstore/plugin_psycstore_mysql.c index d857262d6..73f55186b 100644 --- a/src/psycstore/plugin_psycstore_mysql.c +++ b/src/psycstore/plugin_psycstore_mysql.c | |||
@@ -101,7 +101,6 @@ struct Plugin | |||
101 | */ | 101 | */ |
102 | struct GNUNET_MYSQL_StatementHandle *insert_channel_key; | 102 | struct GNUNET_MYSQL_StatementHandle *insert_channel_key; |
103 | 103 | ||
104 | |||
105 | /** | 104 | /** |
106 | * Precompiled SQL for slave_key_store() | 105 | * Precompiled SQL for slave_key_store() |
107 | */ | 106 | */ |
@@ -268,50 +267,58 @@ mysql_prepare (struct GNUNET_MYSQL_Context *mc, | |||
268 | * as needed as well). | 267 | * as needed as well). |
269 | * | 268 | * |
270 | * @param plugin the plugin context (state for this module) | 269 | * @param plugin the plugin context (state for this module) |
271 | * @return GNUNET_OK on success | 270 | * @return #GNUNET_OK on success |
272 | */ | 271 | */ |
273 | static int | 272 | static int |
274 | database_setup (struct Plugin *plugin) | 273 | database_setup (struct Plugin *plugin) |
275 | { | 274 | { |
276 | /* Open database and precompile statements */ | 275 | /* Open database and precompile statements */ |
277 | plugin->mc = GNUNET_MYSQL_context_create (plugin->cfg, "psycstore-mysql"); | 276 | plugin->mc = GNUNET_MYSQL_context_create (plugin->cfg, |
277 | "psycstore-mysql"); | ||
278 | 278 | ||
279 | if (NULL == plugin->mc) | 279 | if (NULL == plugin->mc) |
280 | { | 280 | { |
281 | LOG(GNUNET_ERROR_TYPE_ERROR, | 281 | LOG (GNUNET_ERROR_TYPE_ERROR, |
282 | _("Unable to initialize Mysql.\n")); | 282 | _("Unable to initialize Mysql.\n")); |
283 | return GNUNET_SYSERR; | 283 | return GNUNET_SYSERR; |
284 | } | 284 | } |
285 | 285 | ||
286 | /* Create tables */ | 286 | #define STMT_RUN(sql) \ |
287 | 287 | if (GNUNET_OK != \ | |
288 | GNUNET_MYSQL_statement_run (plugin->mc, | 288 | GNUNET_MYSQL_statement_run (plugin->mc, \ |
289 | "CREATE TABLE IF NOT EXISTS channels (\n" | 289 | sql)) \ |
290 | " id INT AUTO_INCREMENT,\n" | 290 | { \ |
291 | " pub_key BLOB,\n" | 291 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ |
292 | " max_state_message_id INT,\n" | 292 | _("Failed to run SQL statement `%s'\n"), \ |
293 | " state_hash_message_id INT,\n" | 293 | sql); \ |
294 | " PRIMARY KEY(id),\n" | 294 | return GNUNET_SYSERR; \ |
295 | " UNIQUE KEY(pub_key(5))\n" | 295 | } |
296 | ");"); | ||
297 | |||
298 | GNUNET_MYSQL_statement_run (plugin->mc, | ||
299 | "CREATE TABLE IF NOT EXISTS slaves (\n" | ||
300 | " id INT AUTO_INCREMENT,\n" | ||
301 | " pub_key BLOB,\n" | ||
302 | " PRIMARY KEY(id),\n" | ||
303 | " UNIQUE KEY(pub_key(5))\n" | ||
304 | ");"); | ||
305 | 296 | ||
306 | GNUNET_MYSQL_statement_run (plugin->mc, | 297 | /* Create tables */ |
307 | "CREATE TABLE IF NOT EXISTS membership (\n" | 298 | STMT_RUN ("CREATE TABLE IF NOT EXISTS channels (\n" |
308 | " channel_id INT NOT NULL REFERENCES channels(id),\n" | 299 | " id INT AUTO_INCREMENT,\n" |
309 | " slave_id INT NOT NULL REFERENCES slaves(id),\n" | 300 | " pub_key BLOB,\n" |
310 | " did_join INT NOT NULL,\n" | 301 | " max_state_message_id INT,\n" |
311 | " announced_at BIGINT UNSIGNED NOT NULL,\n" | 302 | " state_hash_message_id INT,\n" |
312 | " effective_since BIGINT UNSIGNED NOT NULL,\n" | 303 | " PRIMARY KEY(id),\n" |
313 | " group_generation BIGINT UNSIGNED NOT NULL\n" | 304 | " UNIQUE KEY(pub_key(5))\n" |
314 | ");"); | 305 | ");"); |
306 | |||
307 | STMT_RUN ("CREATE TABLE IF NOT EXISTS slaves (\n" | ||
308 | " id INT AUTO_INCREMENT,\n" | ||
309 | " pub_key BLOB,\n" | ||
310 | " PRIMARY KEY(id),\n" | ||
311 | " UNIQUE KEY(pub_key(5))\n" | ||
312 | ");"); | ||
313 | |||
314 | STMT_RUN ("CREATE TABLE IF NOT EXISTS membership (\n" | ||
315 | " channel_id INT NOT NULL REFERENCES channels(id),\n" | ||
316 | " slave_id INT NOT NULL REFERENCES slaves(id),\n" | ||
317 | " did_join INT NOT NULL,\n" | ||
318 | " announced_at BIGINT UNSIGNED NOT NULL,\n" | ||
319 | " effective_since BIGINT UNSIGNED NOT NULL,\n" | ||
320 | " group_generation BIGINT UNSIGNED NOT NULL\n" | ||
321 | ");"); | ||
315 | 322 | ||
316 | /*** FIX because IF NOT EXISTS doesn't work ***/ | 323 | /*** FIX because IF NOT EXISTS doesn't work ***/ |
317 | GNUNET_MYSQL_statement_run (plugin->mc, | 324 | GNUNET_MYSQL_statement_run (plugin->mc, |
@@ -319,39 +326,37 @@ database_setup (struct Plugin *plugin) | |||
319 | "ON membership (channel_id, slave_id);"); | 326 | "ON membership (channel_id, slave_id);"); |
320 | 327 | ||
321 | /** @todo messages table: add method_name column */ | 328 | /** @todo messages table: add method_name column */ |
322 | GNUNET_MYSQL_statement_run (plugin->mc, | 329 | STMT_RUN ("CREATE TABLE IF NOT EXISTS messages (\n" |
323 | "CREATE TABLE IF NOT EXISTS messages (\n" | 330 | " channel_id INT NOT NULL REFERENCES channels(id),\n" |
324 | " channel_id INT NOT NULL REFERENCES channels(id),\n" | 331 | " hop_counter BIGINT UNSIGNED NOT NULL,\n" |
325 | " hop_counter BIGINT UNSIGNED NOT NULL,\n" | 332 | " signature BLOB,\n" |
326 | " signature BLOB,\n" | 333 | " purpose BLOB,\n" |
327 | " purpose BLOB,\n" | 334 | " fragment_id BIGINT UNSIGNED NOT NULL,\n" |
328 | " fragment_id BIGINT UNSIGNED NOT NULL,\n" | 335 | " fragment_offset BIGINT UNSIGNED NOT NULL,\n" |
329 | " fragment_offset BIGINT UNSIGNED NOT NULL,\n" | ||
330 | " message_id BIGINT UNSIGNED NOT NULL,\n" | 336 | " message_id BIGINT UNSIGNED NOT NULL,\n" |
331 | " group_generation BIGINT UNSIGNED NOT NULL,\n" | 337 | " group_generation BIGINT UNSIGNED NOT NULL,\n" |
332 | " multicast_flags BIGINT UNSIGNED NOT NULL,\n" | 338 | " multicast_flags BIGINT UNSIGNED NOT NULL,\n" |
333 | " psycstore_flags BIGINT UNSIGNED NOT NULL,\n" | 339 | " psycstore_flags BIGINT UNSIGNED NOT NULL,\n" |
334 | " data BLOB,\n" | 340 | " data BLOB,\n" |
335 | " PRIMARY KEY (channel_id, fragment_id),\n" | 341 | " PRIMARY KEY (channel_id, fragment_id),\n" |
336 | " UNIQUE KEY(channel_id, message_id, fragment_offset)\n" | 342 | " UNIQUE KEY(channel_id, message_id, fragment_offset)\n" |
337 | ");"); | 343 | ");"); |
338 | 344 | ||
339 | GNUNET_MYSQL_statement_run (plugin->mc, | 345 | STMT_RUN ("CREATE TABLE IF NOT EXISTS state (\n" |
340 | "CREATE TABLE IF NOT EXISTS state (\n" | 346 | " channel_id INT NOT NULL REFERENCES channels(id),\n" |
341 | " channel_id INT NOT NULL REFERENCES channels(id),\n" | 347 | " name TEXT NOT NULL,\n" |
342 | " name TEXT NOT NULL,\n" | 348 | " value_current BLOB,\n" |
343 | " value_current BLOB,\n" | 349 | " value_signed BLOB,\n" |
344 | " value_signed BLOB,\n" | 350 | " PRIMARY KEY (channel_id, name(5))\n" |
345 | " PRIMARY KEY (channel_id, name(5))\n" | 351 | ");"); |
346 | ");"); | 352 | |
347 | 353 | STMT_RUN ("CREATE TABLE IF NOT EXISTS state_sync (\n" | |
348 | GNUNET_MYSQL_statement_run (plugin->mc, | 354 | " channel_id INT NOT NULL REFERENCES channels(id),\n" |
349 | "CREATE TABLE IF NOT EXISTS state_sync (\n" | 355 | " name TEXT NOT NULL,\n" |
350 | " channel_id INT NOT NULL REFERENCES channels(id),\n" | 356 | " value BLOB,\n" |
351 | " name TEXT NOT NULL,\n" | 357 | " PRIMARY KEY (channel_id, name(5))\n" |
352 | " value BLOB,\n" | 358 | ");"); |
353 | " PRIMARY KEY (channel_id, name(5))\n" | 359 | #undef STMT_RUN |
354 | ");"); | ||
355 | 360 | ||
356 | /* Prepare statements */ | 361 | /* Prepare statements */ |
357 | mysql_prepare (plugin->mc, | 362 | mysql_prepare (plugin->mc, |
diff --git a/src/psycstore/test_plugin_psycstore.c b/src/psycstore/test_plugin_psycstore.c index c1a456e60..d24405cc2 100644 --- a/src/psycstore/test_plugin_psycstore.c +++ b/src/psycstore/test_plugin_psycstore.c | |||
@@ -173,6 +173,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
173 | "%s", | 173 | "%s", |
174 | "Failed to initialize PSYCstore. " | 174 | "Failed to initialize PSYCstore. " |
175 | "Database likely not setup, skipping test.\n"); | 175 | "Database likely not setup, skipping test.\n"); |
176 | ok = 77; | ||
176 | return; | 177 | return; |
177 | } | 178 | } |
178 | 179 | ||
@@ -511,7 +512,8 @@ main (int argc, char *argv[]) | |||
511 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, | 512 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, |
512 | "test-plugin-psycstore", "nohelp", options, &run, NULL); | 513 | "test-plugin-psycstore", "nohelp", options, &run, NULL); |
513 | 514 | ||
514 | if (ok != 0) | 515 | if ( (0 != ok) && |
516 | (77 != ok) ) | ||
515 | FPRINTF (stderr, "Missed some testcases: %d\n", ok); | 517 | FPRINTF (stderr, "Missed some testcases: %d\n", ok); |
516 | 518 | ||
517 | #if ! DEBUG_PSYCSTORE | 519 | #if ! DEBUG_PSYCSTORE |