diff options
Diffstat (limited to 'src/datastore/plugin_datastore_mysql.c')
-rw-r--r-- | src/datastore/plugin_datastore_mysql.c | 315 |
1 files changed, 137 insertions, 178 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c index a9b039981..63b065b0c 100644 --- a/src/datastore/plugin_datastore_mysql.c +++ b/src/datastore/plugin_datastore_mysql.c | |||
@@ -314,8 +314,8 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
314 | 314 | ||
315 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 315 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
316 | _("Trying to use file `%s' for MySQL configuration.\n"), cnffile); | 316 | _("Trying to use file `%s' for MySQL configuration.\n"), cnffile); |
317 | if ((0 != STAT (cnffile, &st)) || | 317 | if ((0 != STAT (cnffile, &st)) || (0 != ACCESS (cnffile, R_OK)) || |
318 | (0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode))) | 318 | (!S_ISREG (st.st_mode))) |
319 | { | 319 | { |
320 | if (configured == GNUNET_YES) | 320 | if (configured == GNUNET_YES) |
321 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 321 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -383,16 +383,16 @@ iopen (struct Plugin *plugin) | |||
383 | reconnect = 0; | 383 | reconnect = 0; |
384 | mysql_options (plugin->dbf, MYSQL_OPT_RECONNECT, &reconnect); | 384 | mysql_options (plugin->dbf, MYSQL_OPT_RECONNECT, &reconnect); |
385 | timeout = 120; /* in seconds */ | 385 | timeout = 120; /* in seconds */ |
386 | mysql_options (plugin->dbf, | 386 | mysql_options (plugin->dbf, MYSQL_OPT_CONNECT_TIMEOUT, |
387 | MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout); | 387 | (const void *) &timeout); |
388 | mysql_options (plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8"); | 388 | mysql_options (plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8"); |
389 | timeout = 60; /* in seconds */ | 389 | timeout = 60; /* in seconds */ |
390 | mysql_options (plugin->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout); | 390 | mysql_options (plugin->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout); |
391 | mysql_options (plugin->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout); | 391 | mysql_options (plugin->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout); |
392 | mysql_dbname = NULL; | 392 | mysql_dbname = NULL; |
393 | if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, | 393 | if (GNUNET_YES == |
394 | "datastore-mysql", | 394 | GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql", |
395 | "DATABASE")) | 395 | "DATABASE")) |
396 | GNUNET_assert (GNUNET_OK == | 396 | GNUNET_assert (GNUNET_OK == |
397 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | 397 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, |
398 | "datastore-mysql", | 398 | "datastore-mysql", |
@@ -401,8 +401,9 @@ iopen (struct Plugin *plugin) | |||
401 | else | 401 | else |
402 | mysql_dbname = GNUNET_strdup ("gnunet"); | 402 | mysql_dbname = GNUNET_strdup ("gnunet"); |
403 | mysql_user = NULL; | 403 | mysql_user = NULL; |
404 | if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, | 404 | if (GNUNET_YES == |
405 | "datastore-mysql", "USER")) | 405 | GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql", |
406 | "USER")) | ||
406 | { | 407 | { |
407 | GNUNET_assert (GNUNET_OK == | 408 | GNUNET_assert (GNUNET_OK == |
408 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | 409 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, |
@@ -410,9 +411,9 @@ iopen (struct Plugin *plugin) | |||
410 | "USER", &mysql_user)); | 411 | "USER", &mysql_user)); |
411 | } | 412 | } |
412 | mysql_password = NULL; | 413 | mysql_password = NULL; |
413 | if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, | 414 | if (GNUNET_YES == |
414 | "datastore-mysql", | 415 | GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql", |
415 | "PASSWORD")) | 416 | "PASSWORD")) |
416 | { | 417 | { |
417 | GNUNET_assert (GNUNET_OK == | 418 | GNUNET_assert (GNUNET_OK == |
418 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | 419 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, |
@@ -421,8 +422,9 @@ iopen (struct Plugin *plugin) | |||
421 | &mysql_password)); | 422 | &mysql_password)); |
422 | } | 423 | } |
423 | mysql_server = NULL; | 424 | mysql_server = NULL; |
424 | if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, | 425 | if (GNUNET_YES == |
425 | "datastore-mysql", "HOST")) | 426 | GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql", |
427 | "HOST")) | ||
426 | { | 428 | { |
427 | GNUNET_assert (GNUNET_OK == | 429 | GNUNET_assert (GNUNET_OK == |
428 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | 430 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, |
@@ -431,8 +433,9 @@ iopen (struct Plugin *plugin) | |||
431 | &mysql_server)); | 433 | &mysql_server)); |
432 | } | 434 | } |
433 | mysql_port = 0; | 435 | mysql_port = 0; |
434 | if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, | 436 | if (GNUNET_YES == |
435 | "datastore-mysql", "PORT")) | 437 | GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql", |
438 | "PORT")) | ||
436 | { | 439 | { |
437 | GNUNET_assert (GNUNET_OK == | 440 | GNUNET_assert (GNUNET_OK == |
438 | GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, | 441 | GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, |
@@ -441,11 +444,9 @@ iopen (struct Plugin *plugin) | |||
441 | } | 444 | } |
442 | 445 | ||
443 | GNUNET_assert (mysql_dbname != NULL); | 446 | GNUNET_assert (mysql_dbname != NULL); |
444 | mysql_real_connect (plugin->dbf, | 447 | mysql_real_connect (plugin->dbf, mysql_server, mysql_user, mysql_password, |
445 | mysql_server, | 448 | mysql_dbname, (unsigned int) mysql_port, NULL, |
446 | mysql_user, mysql_password, | 449 | CLIENT_IGNORE_SIGPIPE); |
447 | mysql_dbname, | ||
448 | (unsigned int) mysql_port, NULL, CLIENT_IGNORE_SIGPIPE); | ||
449 | GNUNET_free_non_null (mysql_server); | 450 | GNUNET_free_non_null (mysql_server); |
450 | GNUNET_free_non_null (mysql_user); | 451 | GNUNET_free_non_null (mysql_user); |
451 | GNUNET_free_non_null (mysql_password); | 452 | GNUNET_free_non_null (mysql_password); |
@@ -524,8 +525,7 @@ prepare_statement (struct Plugin *plugin, | |||
524 | } | 525 | } |
525 | if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query))) | 526 | if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query))) |
526 | { | 527 | { |
527 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 528 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", |
528 | "mysql", | ||
529 | _("Failed to prepare statement `%s'\n"), ret->query); | 529 | _("Failed to prepare statement `%s'\n"), ret->query); |
530 | LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", plugin); | 530 | LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", plugin); |
531 | mysql_stmt_close (ret->statement); | 531 | mysql_stmt_close (ret->statement); |
@@ -549,8 +549,8 @@ prepare_statement (struct Plugin *plugin, | |||
549 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | 549 | * @return GNUNET_SYSERR on error, GNUNET_OK on success |
550 | */ | 550 | */ |
551 | static int | 551 | static int |
552 | init_params (struct Plugin *plugin, | 552 | init_params (struct Plugin *plugin, struct GNUNET_MysqlStatementHandle *s, |
553 | struct GNUNET_MysqlStatementHandle *s, va_list ap) | 553 | va_list ap) |
554 | { | 554 | { |
555 | MYSQL_BIND qbind[MAX_PARAM]; | 555 | MYSQL_BIND qbind[MAX_PARAM]; |
556 | unsigned int pc; | 556 | unsigned int pc; |
@@ -611,8 +611,8 @@ init_params (struct Plugin *plugin, | |||
611 | { | 611 | { |
612 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 612 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
613 | _("`%s' failed at %s:%d with error: %s\n"), | 613 | _("`%s' failed at %s:%d with error: %s\n"), |
614 | "mysql_stmt_bind_param", | 614 | "mysql_stmt_bind_param", __FILE__, __LINE__, |
615 | __FILE__, __LINE__, mysql_stmt_error (s->statement)); | 615 | mysql_stmt_error (s->statement)); |
616 | iclose (plugin); | 616 | iclose (plugin); |
617 | return GNUNET_SYSERR; | 617 | return GNUNET_SYSERR; |
618 | } | 618 | } |
@@ -620,8 +620,8 @@ init_params (struct Plugin *plugin, | |||
620 | { | 620 | { |
621 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 621 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
622 | _("`%s' for `%s' failed at %s:%d with error: %s\n"), | 622 | _("`%s' for `%s' failed at %s:%d with error: %s\n"), |
623 | "mysql_stmt_execute", | 623 | "mysql_stmt_execute", s->query, __FILE__, __LINE__, |
624 | s->query, __FILE__, __LINE__, mysql_stmt_error (s->statement)); | 624 | mysql_stmt_error (s->statement)); |
625 | iclose (plugin); | 625 | iclose (plugin); |
626 | return GNUNET_SYSERR; | 626 | return GNUNET_SYSERR; |
627 | } | 627 | } |
@@ -671,8 +671,8 @@ prepared_statement_run_select_va (struct Plugin *plugin, | |||
671 | { | 671 | { |
672 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 672 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
673 | _("`%s' failed at %s:%d with error: %s\n"), | 673 | _("`%s' failed at %s:%d with error: %s\n"), |
674 | "mysql_stmt_bind_result", | 674 | "mysql_stmt_bind_result", __FILE__, __LINE__, |
675 | __FILE__, __LINE__, mysql_stmt_error (s->statement)); | 675 | mysql_stmt_error (s->statement)); |
676 | iclose (plugin); | 676 | iclose (plugin); |
677 | return GNUNET_SYSERR; | 677 | return GNUNET_SYSERR; |
678 | } | 678 | } |
@@ -682,8 +682,7 @@ prepared_statement_run_select_va (struct Plugin *plugin, | |||
682 | if (ret != 0) | 682 | if (ret != 0) |
683 | { | 683 | { |
684 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 684 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
685 | _("`%s' failed at %s:%d with error: %s\n"), | 685 | _("`%s' failed at %s:%d with error: %s\n"), "mysql_stmt_fetch", |
686 | "mysql_stmt_fetch", | ||
687 | __FILE__, __LINE__, mysql_stmt_error (s->statement)); | 686 | __FILE__, __LINE__, mysql_stmt_error (s->statement)); |
688 | iclose (plugin); | 687 | iclose (plugin); |
689 | return GNUNET_SYSERR; | 688 | return GNUNET_SYSERR; |
@@ -710,8 +709,8 @@ prepared_statement_run_select_va (struct Plugin *plugin, | |||
710 | static int | 709 | static int |
711 | prepared_statement_run_select (struct Plugin *plugin, | 710 | prepared_statement_run_select (struct Plugin *plugin, |
712 | struct GNUNET_MysqlStatementHandle *s, | 711 | struct GNUNET_MysqlStatementHandle *s, |
713 | unsigned int result_size, | 712 | unsigned int result_size, MYSQL_BIND * results, |
714 | MYSQL_BIND * results, ...) | 713 | ...) |
715 | { | 714 | { |
716 | va_list ap; | 715 | va_list ap; |
717 | int ret; | 716 | int ret; |
@@ -774,13 +773,12 @@ do_delete_entry (struct Plugin *plugin, unsigned long long uid) | |||
774 | int ret; | 773 | int ret; |
775 | 774 | ||
776 | #if DEBUG_MYSQL | 775 | #if DEBUG_MYSQL |
777 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 776 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting value %llu from gn090 table\n", |
778 | "Deleting value %llu from gn090 table\n", uid); | 777 | uid); |
779 | #endif | 778 | #endif |
780 | ret = prepared_statement_run (plugin, | 779 | ret = |
781 | plugin->delete_entry_by_uid, | 780 | prepared_statement_run (plugin, plugin->delete_entry_by_uid, NULL, |
782 | NULL, | 781 | MYSQL_TYPE_LONGLONG, &uid, GNUNET_YES, -1); |
783 | MYSQL_TYPE_LONGLONG, &uid, GNUNET_YES, -1); | ||
784 | if (ret >= 0) | 782 | if (ret >= 0) |
785 | return GNUNET_OK; | 783 | return GNUNET_OK; |
786 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 784 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -831,14 +829,9 @@ mysql_plugin_estimate_size (void *cls) | |||
831 | * @return GNUNET_OK on success | 829 | * @return GNUNET_OK on success |
832 | */ | 830 | */ |
833 | static int | 831 | static int |
834 | mysql_plugin_put (void *cls, | 832 | mysql_plugin_put (void *cls, const GNUNET_HashCode * key, uint32_t size, |
835 | const GNUNET_HashCode * key, | 833 | const void *data, enum GNUNET_BLOCK_Type type, |
836 | uint32_t size, | 834 | uint32_t priority, uint32_t anonymity, uint32_t replication, |
837 | const void *data, | ||
838 | enum GNUNET_BLOCK_Type type, | ||
839 | uint32_t priority, | ||
840 | uint32_t anonymity, | ||
841 | uint32_t replication, | ||
842 | struct GNUNET_TIME_Absolute expiration, char **msg) | 835 | struct GNUNET_TIME_Absolute expiration, char **msg) |
843 | { | 836 | { |
844 | struct Plugin *plugin = cls; | 837 | struct Plugin *plugin = cls; |
@@ -864,9 +857,7 @@ mysql_plugin_put (void *cls, | |||
864 | lsize = size; | 857 | lsize = size; |
865 | GNUNET_CRYPTO_hash (data, size, &vhash); | 858 | GNUNET_CRYPTO_hash (data, size, &vhash); |
866 | if (GNUNET_OK != | 859 | if (GNUNET_OK != |
867 | prepared_statement_run (plugin, | 860 | prepared_statement_run (plugin, plugin->insert_entry, NULL, |
868 | plugin->insert_entry, | ||
869 | NULL, | ||
870 | MYSQL_TYPE_LONG, &irepl, GNUNET_YES, | 861 | MYSQL_TYPE_LONG, &irepl, GNUNET_YES, |
871 | MYSQL_TYPE_LONG, &type, GNUNET_YES, | 862 | MYSQL_TYPE_LONG, &type, GNUNET_YES, |
872 | MYSQL_TYPE_LONG, &ipriority, GNUNET_YES, | 863 | MYSQL_TYPE_LONG, &ipriority, GNUNET_YES, |
@@ -912,9 +903,8 @@ mysql_plugin_put (void *cls, | |||
912 | * @return GNUNET_OK on success | 903 | * @return GNUNET_OK on success |
913 | */ | 904 | */ |
914 | static int | 905 | static int |
915 | mysql_plugin_update (void *cls, | 906 | mysql_plugin_update (void *cls, uint64_t uid, int delta, |
916 | uint64_t uid, | 907 | struct GNUNET_TIME_Absolute expire, char **msg) |
917 | int delta, struct GNUNET_TIME_Absolute expire, char **msg) | ||
918 | { | 908 | { |
919 | struct Plugin *plugin = cls; | 909 | struct Plugin *plugin = cls; |
920 | unsigned long long vkey = uid; | 910 | unsigned long long vkey = uid; |
@@ -926,17 +916,16 @@ mysql_plugin_update (void *cls, | |||
926 | "Updating value %llu adding %d to priority and maxing exp at %llu\n", | 916 | "Updating value %llu adding %d to priority and maxing exp at %llu\n", |
927 | vkey, delta, lexpire); | 917 | vkey, delta, lexpire); |
928 | #endif | 918 | #endif |
929 | ret = prepared_statement_run (plugin, | 919 | ret = |
930 | plugin->update_entry, | 920 | prepared_statement_run (plugin, plugin->update_entry, NULL, |
931 | NULL, | 921 | MYSQL_TYPE_LONG, &delta, GNUNET_NO, |
932 | MYSQL_TYPE_LONG, &delta, GNUNET_NO, | 922 | MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES, |
933 | MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES, | 923 | MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES, |
934 | MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES, | 924 | MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES, -1); |
935 | MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES, -1); | ||
936 | if (ret != GNUNET_OK) | 925 | if (ret != GNUNET_OK) |
937 | { | 926 | { |
938 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 927 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to update value %llu\n", |
939 | "Failed to update value %llu\n", vkey); | 928 | vkey); |
940 | } | 929 | } |
941 | return ret; | 930 | return ret; |
942 | } | 931 | } |
@@ -953,8 +942,7 @@ mysql_plugin_update (void *cls, | |||
953 | * @param ... arguments to initialize stmt | 942 | * @param ... arguments to initialize stmt |
954 | */ | 943 | */ |
955 | static void | 944 | static void |
956 | execute_select (struct Plugin *plugin, | 945 | execute_select (struct Plugin *plugin, struct GNUNET_MysqlStatementHandle *stmt, |
957 | struct GNUNET_MysqlStatementHandle *stmt, | ||
958 | PluginDatumProcessor proc, void *proc_cls, ...) | 946 | PluginDatumProcessor proc, void *proc_cls, ...) |
959 | { | 947 | { |
960 | va_list ap; | 948 | va_list ap; |
@@ -1020,8 +1008,9 @@ execute_select (struct Plugin *plugin, | |||
1020 | #endif | 1008 | #endif |
1021 | GNUNET_assert (size < MAX_DATUM_SIZE); | 1009 | GNUNET_assert (size < MAX_DATUM_SIZE); |
1022 | expiration.abs_value = exp; | 1010 | expiration.abs_value = exp; |
1023 | ret = proc (proc_cls, | 1011 | ret = |
1024 | &key, size, value, type, priority, anonymity, expiration, uid); | 1012 | proc (proc_cls, &key, size, value, type, priority, anonymity, expiration, |
1013 | uid); | ||
1025 | if (ret == GNUNET_NO) | 1014 | if (ret == GNUNET_NO) |
1026 | { | 1015 | { |
1027 | do_delete_entry (plugin, uid); | 1016 | do_delete_entry (plugin, uid); |
@@ -1051,12 +1040,10 @@ execute_select (struct Plugin *plugin, | |||
1051 | * @param proc_cls closure for proc | 1040 | * @param proc_cls closure for proc |
1052 | */ | 1041 | */ |
1053 | static void | 1042 | static void |
1054 | mysql_plugin_get_key (void *cls, | 1043 | mysql_plugin_get_key (void *cls, uint64_t offset, const GNUNET_HashCode * key, |
1055 | uint64_t offset, | ||
1056 | const GNUNET_HashCode * key, | ||
1057 | const GNUNET_HashCode * vhash, | 1044 | const GNUNET_HashCode * vhash, |
1058 | enum GNUNET_BLOCK_Type type, | 1045 | enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, |
1059 | PluginDatumProcessor proc, void *proc_cls) | 1046 | void *proc_cls) |
1060 | { | 1047 | { |
1061 | struct Plugin *plugin = cls; | 1048 | struct Plugin *plugin = cls; |
1062 | int ret; | 1049 | int ret; |
@@ -1081,22 +1068,21 @@ mysql_plugin_get_key (void *cls, | |||
1081 | { | 1068 | { |
1082 | ret = | 1069 | ret = |
1083 | prepared_statement_run_select (plugin, | 1070 | prepared_statement_run_select (plugin, |
1084 | plugin-> | 1071 | plugin->count_entry_by_hash_vhash_and_type, |
1085 | count_entry_by_hash_vhash_and_type, 1, | 1072 | 1, cbind, MYSQL_TYPE_BLOB, key, |
1086 | cbind, MYSQL_TYPE_BLOB, key, hashSize, | 1073 | hashSize, &hashSize, MYSQL_TYPE_BLOB, |
1087 | &hashSize, MYSQL_TYPE_BLOB, vhash, | 1074 | vhash, hashSize2, &hashSize2, |
1088 | hashSize2, &hashSize2, MYSQL_TYPE_LONG, | 1075 | MYSQL_TYPE_LONG, &type, GNUNET_YES, |
1089 | &type, GNUNET_YES, -1); | 1076 | -1); |
1090 | } | 1077 | } |
1091 | else | 1078 | else |
1092 | { | 1079 | { |
1093 | ret = | 1080 | ret = |
1094 | prepared_statement_run_select (plugin, | 1081 | prepared_statement_run_select (plugin, |
1095 | plugin->count_entry_by_hash_and_type, | 1082 | plugin->count_entry_by_hash_and_type, |
1096 | 1, cbind, | 1083 | 1, cbind, MYSQL_TYPE_BLOB, key, |
1097 | MYSQL_TYPE_BLOB, key, hashSize, | 1084 | hashSize, &hashSize, MYSQL_TYPE_LONG, |
1098 | &hashSize, MYSQL_TYPE_LONG, &type, | 1085 | &type, GNUNET_YES, -1); |
1099 | GNUNET_YES, -1); | ||
1100 | } | 1086 | } |
1101 | } | 1087 | } |
1102 | else | 1088 | else |
@@ -1106,19 +1092,16 @@ mysql_plugin_get_key (void *cls, | |||
1106 | ret = | 1092 | ret = |
1107 | prepared_statement_run_select (plugin, | 1093 | prepared_statement_run_select (plugin, |
1108 | plugin->count_entry_by_hash_and_vhash, | 1094 | plugin->count_entry_by_hash_and_vhash, |
1109 | 1, cbind, | 1095 | 1, cbind, MYSQL_TYPE_BLOB, key, |
1110 | MYSQL_TYPE_BLOB, key, hashSize, | 1096 | hashSize, &hashSize, MYSQL_TYPE_BLOB, |
1111 | &hashSize, MYSQL_TYPE_BLOB, vhash, | 1097 | vhash, hashSize2, &hashSize2, -1); |
1112 | hashSize2, &hashSize2, -1); | ||
1113 | 1098 | ||
1114 | } | 1099 | } |
1115 | else | 1100 | else |
1116 | { | 1101 | { |
1117 | ret = | 1102 | ret = |
1118 | prepared_statement_run_select (plugin, | 1103 | prepared_statement_run_select (plugin, plugin->count_entry_by_hash, 1, |
1119 | plugin->count_entry_by_hash, | 1104 | cbind, MYSQL_TYPE_BLOB, key, hashSize, |
1120 | 1, cbind, | ||
1121 | MYSQL_TYPE_BLOB, key, hashSize, | ||
1122 | &hashSize, -1); | 1105 | &hashSize, -1); |
1123 | } | 1106 | } |
1124 | } | 1107 | } |
@@ -1131,48 +1114,40 @@ mysql_plugin_get_key (void *cls, | |||
1131 | off = (unsigned long long) offset; | 1114 | off = (unsigned long long) offset; |
1132 | #if DEBUG_MYSQL | 1115 | #if DEBUG_MYSQL |
1133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1134 | "Obtaining %llu/%lld result for GET `%s'\n", | 1117 | "Obtaining %llu/%lld result for GET `%s'\n", off, total, |
1135 | off, total, GNUNET_h2s (key)); | 1118 | GNUNET_h2s (key)); |
1136 | #endif | 1119 | #endif |
1137 | 1120 | ||
1138 | if (type != GNUNET_BLOCK_TYPE_ANY) | 1121 | if (type != GNUNET_BLOCK_TYPE_ANY) |
1139 | { | 1122 | { |
1140 | if (NULL != vhash) | 1123 | if (NULL != vhash) |
1141 | { | 1124 | { |
1142 | execute_select (plugin, | 1125 | execute_select (plugin, plugin->select_entry_by_hash_vhash_and_type, proc, |
1143 | plugin->select_entry_by_hash_vhash_and_type, | 1126 | proc_cls, MYSQL_TYPE_BLOB, key, hashSize, &hashSize, |
1144 | proc, proc_cls, | ||
1145 | MYSQL_TYPE_BLOB, key, hashSize, &hashSize, | ||
1146 | MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize, | 1127 | MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize, |
1147 | MYSQL_TYPE_LONG, &type, GNUNET_YES, | 1128 | MYSQL_TYPE_LONG, &type, GNUNET_YES, MYSQL_TYPE_LONGLONG, |
1148 | MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); | 1129 | &off, GNUNET_YES, -1); |
1149 | } | 1130 | } |
1150 | else | 1131 | else |
1151 | { | 1132 | { |
1152 | execute_select (plugin, | 1133 | execute_select (plugin, plugin->select_entry_by_hash_and_type, proc, |
1153 | plugin->select_entry_by_hash_and_type, | 1134 | proc_cls, MYSQL_TYPE_BLOB, key, hashSize, &hashSize, |
1154 | proc, proc_cls, | 1135 | MYSQL_TYPE_LONG, &type, GNUNET_YES, MYSQL_TYPE_LONGLONG, |
1155 | MYSQL_TYPE_BLOB, key, hashSize, &hashSize, | 1136 | &off, GNUNET_YES, -1); |
1156 | MYSQL_TYPE_LONG, &type, GNUNET_YES, | ||
1157 | MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); | ||
1158 | } | 1137 | } |
1159 | } | 1138 | } |
1160 | else | 1139 | else |
1161 | { | 1140 | { |
1162 | if (NULL != vhash) | 1141 | if (NULL != vhash) |
1163 | { | 1142 | { |
1164 | execute_select (plugin, | 1143 | execute_select (plugin, plugin->select_entry_by_hash_and_vhash, proc, |
1165 | plugin->select_entry_by_hash_and_vhash, | 1144 | proc_cls, MYSQL_TYPE_BLOB, key, hashSize, &hashSize, |
1166 | proc, proc_cls, | ||
1167 | MYSQL_TYPE_BLOB, key, hashSize, &hashSize, | ||
1168 | MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize, | 1145 | MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize, |
1169 | MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); | 1146 | MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); |
1170 | } | 1147 | } |
1171 | else | 1148 | else |
1172 | { | 1149 | { |
1173 | execute_select (plugin, | 1150 | execute_select (plugin, plugin->select_entry_by_hash, proc, proc_cls, |
1174 | plugin->select_entry_by_hash, | ||
1175 | proc, proc_cls, | ||
1176 | MYSQL_TYPE_BLOB, key, hashSize, &hashSize, | 1151 | MYSQL_TYPE_BLOB, key, hashSize, &hashSize, |
1177 | MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); | 1152 | MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); |
1178 | } | 1153 | } |
@@ -1191,8 +1166,7 @@ mysql_plugin_get_key (void *cls, | |||
1191 | * @param proc_cls closure for iter | 1166 | * @param proc_cls closure for iter |
1192 | */ | 1167 | */ |
1193 | static void | 1168 | static void |
1194 | mysql_plugin_get_zero_anonymity (void *cls, | 1169 | mysql_plugin_get_zero_anonymity (void *cls, uint64_t offset, |
1195 | uint64_t offset, | ||
1196 | enum GNUNET_BLOCK_Type type, | 1170 | enum GNUNET_BLOCK_Type type, |
1197 | PluginDatumProcessor proc, void *proc_cls) | 1171 | PluginDatumProcessor proc, void *proc_cls) |
1198 | { | 1172 | { |
@@ -1201,13 +1175,10 @@ mysql_plugin_get_zero_anonymity (void *cls, | |||
1201 | (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1175 | (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1202 | UINT64_MAX); | 1176 | UINT64_MAX); |
1203 | 1177 | ||
1204 | execute_select (plugin, | 1178 | execute_select (plugin, plugin->zero_iter, proc, proc_cls, MYSQL_TYPE_LONG, |
1205 | plugin->zero_iter, | 1179 | &type, GNUNET_YES, MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, |
1206 | proc, proc_cls, | 1180 | MYSQL_TYPE_LONG, &type, GNUNET_YES, MYSQL_TYPE_LONGLONG, |
1207 | MYSQL_TYPE_LONG, &type, GNUNET_YES, | 1181 | &rvalue, GNUNET_YES, -1); |
1208 | MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, | ||
1209 | MYSQL_TYPE_LONG, &type, GNUNET_YES, | ||
1210 | MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, -1); | ||
1211 | } | 1182 | } |
1212 | 1183 | ||
1213 | 1184 | ||
@@ -1255,14 +1226,10 @@ struct ReplCtx | |||
1255 | * GNUNET_NO to delete the item and continue (if supported) | 1226 | * GNUNET_NO to delete the item and continue (if supported) |
1256 | */ | 1227 | */ |
1257 | static int | 1228 | static int |
1258 | repl_proc (void *cls, | 1229 | repl_proc (void *cls, const GNUNET_HashCode * key, uint32_t size, |
1259 | const GNUNET_HashCode * key, | 1230 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
1260 | uint32_t size, | 1231 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
1261 | const void *data, | 1232 | uint64_t uid) |
1262 | enum GNUNET_BLOCK_Type type, | ||
1263 | uint32_t priority, | ||
1264 | uint32_t anonymity, | ||
1265 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
1266 | { | 1233 | { |
1267 | struct ReplCtx *rc = cls; | 1234 | struct ReplCtx *rc = cls; |
1268 | struct Plugin *plugin = rc->plugin; | 1235 | struct Plugin *plugin = rc->plugin; |
@@ -1270,15 +1237,15 @@ repl_proc (void *cls, | |||
1270 | int ret; | 1237 | int ret; |
1271 | int iret; | 1238 | int iret; |
1272 | 1239 | ||
1273 | ret = rc->proc (rc->proc_cls, | 1240 | ret = |
1274 | key, size, data, type, priority, anonymity, expiration, uid); | 1241 | rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity, |
1242 | expiration, uid); | ||
1275 | if (NULL != key) | 1243 | if (NULL != key) |
1276 | { | 1244 | { |
1277 | oid = (unsigned long long) uid; | 1245 | oid = (unsigned long long) uid; |
1278 | iret = prepared_statement_run (plugin, | 1246 | iret = |
1279 | plugin->dec_repl, | 1247 | prepared_statement_run (plugin, plugin->dec_repl, NULL, |
1280 | NULL, | 1248 | MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1); |
1281 | MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1); | ||
1282 | if (iret == GNUNET_SYSERR) | 1249 | if (iret == GNUNET_SYSERR) |
1283 | { | 1250 | { |
1284 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1251 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -1302,8 +1269,8 @@ repl_proc (void *cls, | |||
1302 | * @param proc_cls closure for proc | 1269 | * @param proc_cls closure for proc |
1303 | */ | 1270 | */ |
1304 | static void | 1271 | static void |
1305 | mysql_plugin_get_replication (void *cls, | 1272 | mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc, |
1306 | PluginDatumProcessor proc, void *proc_cls) | 1273 | void *proc_cls) |
1307 | { | 1274 | { |
1308 | struct Plugin *plugin = cls; | 1275 | struct Plugin *plugin = cls; |
1309 | struct ReplCtx rc; | 1276 | struct ReplCtx rc; |
@@ -1382,26 +1349,22 @@ struct ExpiCtx | |||
1382 | * GNUNET_NO to delete the item and continue (if supported) | 1349 | * GNUNET_NO to delete the item and continue (if supported) |
1383 | */ | 1350 | */ |
1384 | static int | 1351 | static int |
1385 | expi_proc (void *cls, | 1352 | expi_proc (void *cls, const GNUNET_HashCode * key, uint32_t size, |
1386 | const GNUNET_HashCode * key, | 1353 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
1387 | uint32_t size, | 1354 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
1388 | const void *data, | 1355 | uint64_t uid) |
1389 | enum GNUNET_BLOCK_Type type, | ||
1390 | uint32_t priority, | ||
1391 | uint32_t anonymity, | ||
1392 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
1393 | { | 1356 | { |
1394 | struct ExpiCtx *rc = cls; | 1357 | struct ExpiCtx *rc = cls; |
1395 | struct Plugin *plugin = rc->plugin; | 1358 | struct Plugin *plugin = rc->plugin; |
1396 | 1359 | ||
1397 | if (NULL == key) | 1360 | if (NULL == key) |
1398 | { | 1361 | { |
1399 | execute_select (plugin, | 1362 | execute_select (plugin, plugin->select_priority, rc->proc, rc->proc_cls, |
1400 | plugin->select_priority, rc->proc, rc->proc_cls, -1); | 1363 | -1); |
1401 | return GNUNET_SYSERR; | 1364 | return GNUNET_SYSERR; |
1402 | } | 1365 | } |
1403 | return rc->proc (rc->proc_cls, | 1366 | return rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity, |
1404 | key, size, data, type, priority, anonymity, expiration, uid); | 1367 | expiration, uid); |
1405 | } | 1368 | } |
1406 | 1369 | ||
1407 | 1370 | ||
@@ -1414,8 +1377,8 @@ expi_proc (void *cls, | |||
1414 | * @param proc_cls closure for proc | 1377 | * @param proc_cls closure for proc |
1415 | */ | 1378 | */ |
1416 | static void | 1379 | static void |
1417 | mysql_plugin_get_expiration (void *cls, | 1380 | mysql_plugin_get_expiration (void *cls, PluginDatumProcessor proc, |
1418 | PluginDatumProcessor proc, void *proc_cls) | 1381 | void *proc_cls) |
1419 | { | 1382 | { |
1420 | struct Plugin *plugin = cls; | 1383 | struct Plugin *plugin = cls; |
1421 | long long nt; | 1384 | long long nt; |
@@ -1425,9 +1388,8 @@ mysql_plugin_get_expiration (void *cls, | |||
1425 | rc.proc = proc; | 1388 | rc.proc = proc; |
1426 | rc.proc_cls = proc_cls; | 1389 | rc.proc_cls = proc_cls; |
1427 | nt = (long long) GNUNET_TIME_absolute_get ().abs_value; | 1390 | nt = (long long) GNUNET_TIME_absolute_get ().abs_value; |
1428 | execute_select (plugin, | 1391 | execute_select (plugin, plugin->select_expiration, expi_proc, &rc, |
1429 | plugin->select_expiration, | 1392 | MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES, -1); |
1430 | expi_proc, &rc, MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES, -1); | ||
1431 | 1393 | ||
1432 | } | 1394 | } |
1433 | 1395 | ||
@@ -1473,28 +1435,25 @@ libgnunet_plugin_datastore_mysql_init (void *cls) | |||
1473 | } | 1435 | } |
1474 | #define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) ) | 1436 | #define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) ) |
1475 | #define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b))) | 1437 | #define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b))) |
1476 | if (MRUNS ("CREATE TABLE IF NOT EXISTS gn090 (" | 1438 | if (MRUNS |
1477 | " repl INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1439 | ("CREATE TABLE IF NOT EXISTS gn090 (" |
1478 | " type INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1440 | " repl INT(11) UNSIGNED NOT NULL DEFAULT 0," |
1479 | " prio INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1441 | " type INT(11) UNSIGNED NOT NULL DEFAULT 0," |
1480 | " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1442 | " prio INT(11) UNSIGNED NOT NULL DEFAULT 0," |
1481 | " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," | 1443 | " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0," |
1482 | " rvalue BIGINT UNSIGNED NOT NULL," | 1444 | " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," |
1483 | " hash BINARY(64) NOT NULL DEFAULT ''," | 1445 | " rvalue BIGINT UNSIGNED NOT NULL," |
1484 | " vhash BINARY(64) NOT NULL DEFAULT ''," | 1446 | " hash BINARY(64) NOT NULL DEFAULT ''," |
1485 | " value BLOB NOT NULL DEFAULT ''," | 1447 | " vhash BINARY(64) NOT NULL DEFAULT ''," |
1486 | " uid BIGINT NOT NULL AUTO_INCREMENT," | 1448 | " value BLOB NOT NULL DEFAULT ''," " uid BIGINT NOT NULL AUTO_INCREMENT," |
1487 | " PRIMARY KEY (uid)," | 1449 | " PRIMARY KEY (uid)," " INDEX idx_hash (hash(64))," |
1488 | " INDEX idx_hash (hash(64))," | 1450 | " INDEX idx_hash_uid (hash(64),uid)," |
1489 | " INDEX idx_hash_uid (hash(64),uid)," | 1451 | " INDEX idx_hash_vhash (hash(64),vhash(64))," |
1490 | " INDEX idx_hash_vhash (hash(64),vhash(64))," | 1452 | " INDEX idx_hash_type_uid (hash(64),type,rvalue)," |
1491 | " INDEX idx_hash_type_uid (hash(64),type,rvalue)," | 1453 | " INDEX idx_prio (prio)," " INDEX idx_repl_rvalue (repl,rvalue)," |
1492 | " INDEX idx_prio (prio)," | 1454 | " INDEX idx_expire (expire)," |
1493 | " INDEX idx_repl_rvalue (repl,rvalue)," | 1455 | " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)" |
1494 | " INDEX idx_expire (expire)," | 1456 | ") ENGINE=InnoDB") || MRUNS ("SET AUTOCOMMIT = 1") || |
1495 | " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)" | ||
1496 | ") ENGINE=InnoDB") || | ||
1497 | MRUNS ("SET AUTOCOMMIT = 1") || | ||
1498 | PINIT (plugin->insert_entry, INSERT_ENTRY) || | 1457 | PINIT (plugin->insert_entry, INSERT_ENTRY) || |
1499 | PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) || | 1458 | PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) || |
1500 | PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) || | 1459 | PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) || |
@@ -1537,8 +1496,8 @@ libgnunet_plugin_datastore_mysql_init (void *cls) | |||
1537 | api->get_expiration = &mysql_plugin_get_expiration; | 1496 | api->get_expiration = &mysql_plugin_get_expiration; |
1538 | api->get_zero_anonymity = &mysql_plugin_get_zero_anonymity; | 1497 | api->get_zero_anonymity = &mysql_plugin_get_zero_anonymity; |
1539 | api->drop = &mysql_plugin_drop; | 1498 | api->drop = &mysql_plugin_drop; |
1540 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | 1499 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql", |
1541 | "mysql", _("Mysql database running\n")); | 1500 | _("Mysql database running\n")); |
1542 | return api; | 1501 | return api; |
1543 | } | 1502 | } |
1544 | 1503 | ||