diff options
author | Gabor X Toth <*@tg-x.net> | 2016-10-12 21:54:30 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2016-10-12 21:54:30 +0000 |
commit | b44b31bd94d3a7479e1ab2bf76acd82030455703 (patch) | |
tree | c49e4725ecf389c18b7a65c01e2b8182fa66dcc0 /src/psycstore | |
parent | 7b230386d0b65d4d0e7eded214290d122e96e974 (diff) | |
download | gnunet-b44b31bd94d3a7479e1ab2bf76acd82030455703.tar.gz gnunet-b44b31bd94d3a7479e1ab2bf76acd82030455703.zip |
psycstore: fix postgres
Diffstat (limited to 'src/psycstore')
-rw-r--r-- | src/psycstore/plugin_psycstore_mysql.c | 14 | ||||
-rw-r--r-- | src/psycstore/plugin_psycstore_postgres.c | 136 | ||||
-rw-r--r-- | src/psycstore/plugin_psycstore_sqlite.c | 6 |
3 files changed, 61 insertions, 95 deletions
diff --git a/src/psycstore/plugin_psycstore_mysql.c b/src/psycstore/plugin_psycstore_mysql.c index 71f2eb5b8..01a0282c8 100644 --- a/src/psycstore/plugin_psycstore_mysql.c +++ b/src/psycstore/plugin_psycstore_mysql.c | |||
@@ -296,18 +296,18 @@ database_setup (struct Plugin *plugin) | |||
296 | /* Create tables */ | 296 | /* Create tables */ |
297 | STMT_RUN ("CREATE TABLE IF NOT EXISTS channels (\n" | 297 | STMT_RUN ("CREATE TABLE IF NOT EXISTS channels (\n" |
298 | " id BIGINT UNSIGNED AUTO_INCREMENT,\n" | 298 | " id BIGINT UNSIGNED AUTO_INCREMENT,\n" |
299 | " pub_key BLOB,\n" | 299 | " pub_key BLOB(23),\n" |
300 | " max_state_message_id BIGINT UNSIGNED,\n" | 300 | " max_state_message_id BIGINT UNSIGNED,\n" |
301 | " state_hash_message_id BIGINT UNSIGNED,\n" | 301 | " state_hash_message_id BIGINT UNSIGNED,\n" |
302 | " PRIMARY KEY(id),\n" | 302 | " PRIMARY KEY(id),\n" |
303 | " UNIQUE KEY(pub_key(5))\n" | 303 | " UNIQUE KEY(pub_key(32))\n" |
304 | ");"); | 304 | ");"); |
305 | 305 | ||
306 | STMT_RUN ("CREATE TABLE IF NOT EXISTS slaves (\n" | 306 | STMT_RUN ("CREATE TABLE IF NOT EXISTS slaves (\n" |
307 | " id BIGINT UNSIGNED AUTO_INCREMENT,\n" | 307 | " id BIGINT UNSIGNED AUTO_INCREMENT,\n" |
308 | " pub_key BLOB,\n" | 308 | " pub_key BLOB(32),\n" |
309 | " PRIMARY KEY(id),\n" | 309 | " PRIMARY KEY(id),\n" |
310 | " UNIQUE KEY(pub_key(5))\n" | 310 | " UNIQUE KEY(pub_key(32))\n" |
311 | ");"); | 311 | ");"); |
312 | 312 | ||
313 | STMT_RUN ("CREATE TABLE IF NOT EXISTS membership (\n" | 313 | STMT_RUN ("CREATE TABLE IF NOT EXISTS membership (\n" |
@@ -521,7 +521,7 @@ database_setup (struct Plugin *plugin) | |||
521 | PREP ("SELECT name, value_current\n" | 521 | PREP ("SELECT name, value_current\n" |
522 | "FROM state\n" | 522 | "FROM state\n" |
523 | "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n" | 523 | "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n" |
524 | " AND (name = ? OR substr(name, 1, ?) = ? || '_');", | 524 | " AND (name = ? OR substr(name, 1, ?) = ?);", |
525 | &plugin->select_state_prefix); | 525 | &plugin->select_state_prefix); |
526 | 526 | ||
527 | PREP ("SELECT name, value_signed\n" | 527 | PREP ("SELECT name, value_signed\n" |
@@ -905,7 +905,7 @@ static int | |||
905 | message_add_flags (void *cls, | 905 | message_add_flags (void *cls, |
906 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, | 906 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, |
907 | uint64_t message_id, | 907 | uint64_t message_id, |
908 | uint64_t psycstore_flags) | 908 | uint32_t psycstore_flags) |
909 | { | 909 | { |
910 | struct Plugin *plugin = cls; | 910 | struct Plugin *plugin = cls; |
911 | struct GNUNET_MYSQL_StatementHandle *stmt = plugin->update_message_flags; | 911 | struct GNUNET_MYSQL_StatementHandle *stmt = plugin->update_message_flags; |
@@ -914,7 +914,7 @@ message_add_flags (void *cls, | |||
914 | int ret = GNUNET_SYSERR; | 914 | int ret = GNUNET_SYSERR; |
915 | 915 | ||
916 | struct GNUNET_MY_QueryParam params_update[] = { | 916 | struct GNUNET_MY_QueryParam params_update[] = { |
917 | GNUNET_MY_query_param_uint64 (&psycstore_flags), | 917 | GNUNET_MY_query_param_uint32 (&psycstore_flags), |
918 | GNUNET_MY_query_param_auto_from_type (channel_key), | 918 | GNUNET_MY_query_param_auto_from_type (channel_key), |
919 | GNUNET_MY_query_param_uint64 (&message_id), | 919 | GNUNET_MY_query_param_uint64 (&message_id), |
920 | GNUNET_MY_query_param_end | 920 | GNUNET_MY_query_param_end |
diff --git a/src/psycstore/plugin_psycstore_postgres.c b/src/psycstore/plugin_psycstore_postgres.c index 5bbb3c447..3439856b9 100644 --- a/src/psycstore/plugin_psycstore_postgres.c +++ b/src/psycstore/plugin_psycstore_postgres.c | |||
@@ -100,7 +100,7 @@ database_setup (struct Plugin *plugin) | |||
100 | GNUNET_POSTGRES_exec(plugin->dbh, | 100 | GNUNET_POSTGRES_exec(plugin->dbh, |
101 | "CREATE TABLE IF NOT EXISTS channels (\n" | 101 | "CREATE TABLE IF NOT EXISTS channels (\n" |
102 | " id SERIAL,\n" | 102 | " id SERIAL,\n" |
103 | " pub_key BYTEA,\n" | 103 | " pub_key BYTEA(32),\n" |
104 | " max_state_message_id BIGINT,\n" | 104 | " max_state_message_id BIGINT,\n" |
105 | " state_hash_message_id BIGINT,\n" | 105 | " state_hash_message_id BIGINT,\n" |
106 | " PRIMARY KEY(id)\n" | 106 | " PRIMARY KEY(id)\n" |
@@ -109,8 +109,7 @@ database_setup (struct Plugin *plugin) | |||
109 | (GNUNET_OK != | 109 | (GNUNET_OK != |
110 | GNUNET_POSTGRES_exec(plugin->dbh, | 110 | GNUNET_POSTGRES_exec(plugin->dbh, |
111 | "CREATE UNIQUE INDEX IF NOT EXISTS channel_pub_key_idx \n" | 111 | "CREATE UNIQUE INDEX IF NOT EXISTS channel_pub_key_idx \n" |
112 | " ON channels (substring(pub_key from 1 for 5)\n" | 112 | " ON channels (pub_key)")) || |
113 | ")")) || | ||
114 | 113 | ||
115 | (GNUNET_OK != | 114 | (GNUNET_OK != |
116 | GNUNET_POSTGRES_exec(plugin->dbh, | 115 | GNUNET_POSTGRES_exec(plugin->dbh, |
@@ -122,15 +121,14 @@ database_setup (struct Plugin *plugin) | |||
122 | GNUNET_POSTGRES_exec(plugin->dbh, | 121 | GNUNET_POSTGRES_exec(plugin->dbh, |
123 | "CREATE TABLE IF NOT EXISTS slaves (\n" | 122 | "CREATE TABLE IF NOT EXISTS slaves (\n" |
124 | " id SERIAL,\n" | 123 | " id SERIAL,\n" |
125 | " pub_key BYTEA,\n" | 124 | " pub_key BYTEA(32),\n" |
126 | " PRIMARY KEY(id)\n" | 125 | " PRIMARY KEY(id)\n" |
127 | ")" "WITH OIDS")) || | 126 | ")" "WITH OIDS")) || |
128 | 127 | ||
129 | (GNUNET_OK != | 128 | (GNUNET_OK != |
130 | GNUNET_POSTGRES_exec(plugin->dbh, | 129 | GNUNET_POSTGRES_exec(plugin->dbh, |
131 | "CREATE UNIQUE INDEX IF NOT EXISTS slaves_pub_key_idx \n" | 130 | "CREATE UNIQUE INDEX IF NOT EXISTS slaves_pub_key_idx \n" |
132 | " ON slaves (substring(pub_key from 1 for 5)\n" | 131 | " ON slaves (pub_key)")) || |
133 | ")")) || | ||
134 | 132 | ||
135 | (GNUNET_OK != | 133 | (GNUNET_OK != |
136 | GNUNET_POSTGRES_exec(plugin->dbh, | 134 | GNUNET_POSTGRES_exec(plugin->dbh, |
@@ -143,7 +141,7 @@ database_setup (struct Plugin *plugin) | |||
143 | "CREATE TABLE IF NOT EXISTS membership (\n" | 141 | "CREATE TABLE IF NOT EXISTS membership (\n" |
144 | " channel_id BIGINT NOT NULL REFERENCES channels(id),\n" | 142 | " channel_id BIGINT NOT NULL REFERENCES channels(id),\n" |
145 | " slave_id BIGINT NOT NULL REFERENCES slaves(id),\n" | 143 | " slave_id BIGINT NOT NULL REFERENCES slaves(id),\n" |
146 | " did_join BIGINT NOT NULL,\n" | 144 | " did_join INT NOT NULL,\n" |
147 | " announced_at BIGINT NOT NULL,\n" | 145 | " announced_at BIGINT NOT NULL,\n" |
148 | " effective_since BIGINT NOT NULL,\n" | 146 | " effective_since BIGINT NOT NULL,\n" |
149 | " group_generation BIGINT NOT NULL\n" | 147 | " group_generation BIGINT NOT NULL\n" |
@@ -159,7 +157,7 @@ database_setup (struct Plugin *plugin) | |||
159 | GNUNET_POSTGRES_exec(plugin->dbh, | 157 | GNUNET_POSTGRES_exec(plugin->dbh, |
160 | "CREATE TABLE IF NOT EXISTS messages (\n" | 158 | "CREATE TABLE IF NOT EXISTS messages (\n" |
161 | " channel_id BIGINT NOT NULL REFERENCES channels(id),\n" | 159 | " channel_id BIGINT NOT NULL REFERENCES channels(id),\n" |
162 | " hop_counter BIGINT NOT NULL,\n" | 160 | " hop_counter INT NOT NULL,\n" |
163 | " signature BYTEA,\n" | 161 | " signature BYTEA,\n" |
164 | " purpose BYTEA,\n" | 162 | " purpose BYTEA,\n" |
165 | " fragment_id BIGINT NOT NULL,\n" | 163 | " fragment_id BIGINT NOT NULL,\n" |
@@ -179,29 +177,17 @@ database_setup (struct Plugin *plugin) | |||
179 | " channel_id BIGINT NOT NULL REFERENCES channels(id),\n" | 177 | " channel_id BIGINT NOT NULL REFERENCES channels(id),\n" |
180 | " name TEXT NOT NULL,\n" | 178 | " name TEXT NOT NULL,\n" |
181 | " value_current BYTEA,\n" | 179 | " value_current BYTEA,\n" |
182 | " value_signed BYTEA\n" | 180 | " value_signed BYTEA,\n" |
181 | " PRIMARY KEY (channel_id, name)\n" | ||
183 | ")" "WITH OIDS")) || | 182 | ")" "WITH OIDS")) || |
184 | |||
185 | (GNUNET_OK != | ||
186 | GNUNET_POSTGRES_exec(plugin->dbh, | ||
187 | "CREATE UNIQUE INDEX IF NOT EXISTS state_uniq_idx \n" | ||
188 | " ON state (channel_id, substring(name from 1 for 5)\n" | ||
189 | ")")) || | ||
190 | |||
191 | (GNUNET_OK != | 183 | (GNUNET_OK != |
192 | GNUNET_POSTGRES_exec(plugin->dbh, | 184 | GNUNET_POSTGRES_exec(plugin->dbh, |
193 | "CREATE TABLE IF NOT EXISTS state_sync (\n" | 185 | "CREATE TABLE IF NOT EXISTS state_sync (\n" |
194 | " channel_id BIGINT NOT NULL REFERENCES channels(id),\n" | 186 | " channel_id BIGINT NOT NULL REFERENCES channels(id),\n" |
195 | " name TEXT NOT NULL,\n" | 187 | " name TEXT NOT NULL,\n" |
196 | " value BYTEA,\n" | 188 | " value BYTEA,\n" |
197 | " PRIMARY KEY (channel_id)\n" | 189 | " PRIMARY KEY (channel_id, name)\n" |
198 | ")" "WITH OIDS")) || | 190 | ")" "WITH OIDS"))) |
199 | |||
200 | (GNUNET_OK != | ||
201 | GNUNET_POSTGRES_exec(plugin->dbh, | ||
202 | "CREATE UNIQUE INDEX IF NOT EXISTS state_sync_name_idx \n" | ||
203 | " ON state_sync (substring(name from 1 for 5)\n" | ||
204 | ")"))) | ||
205 | { | 191 | { |
206 | PQfinish (plugin->dbh); | 192 | PQfinish (plugin->dbh); |
207 | plugin->dbh = NULL; | 193 | plugin->dbh = NULL; |
@@ -370,7 +356,7 @@ database_setup (struct Plugin *plugin) | |||
370 | "LEFT JOIN (SELECT channel_id, name, value_signed\n" | 356 | "LEFT JOIN (SELECT channel_id, name, value_signed\n" |
371 | " FROM state) AS old\n" | 357 | " FROM state) AS old\n" |
372 | "ON new.channel_id = old.channel_id AND new.name = old.name\n" | 358 | "ON new.channel_id = old.channel_id AND new.name = old.name\n" |
373 | "ON CONFLICT ( channel_id, substring(name from 1 for 5) )\n" | 359 | "ON CONFLICT (channel_id, name)\n" |
374 | " DO UPDATE SET value_current = EXCLUDED.value_current,\n" | 360 | " DO UPDATE SET value_current = EXCLUDED.value_current,\n" |
375 | " value_signed = EXCLUDED.value_signed", 3)) || | 361 | " value_signed = EXCLUDED.value_signed", 3)) || |
376 | 362 | ||
@@ -422,7 +408,7 @@ database_setup (struct Plugin *plugin) | |||
422 | "SELECT name, value_current\n" | 408 | "SELECT name, value_current\n" |
423 | "FROM state\n" | 409 | "FROM state\n" |
424 | "WHERE channel_id = get_chan_id($1)\n" | 410 | "WHERE channel_id = get_chan_id($1)\n" |
425 | " AND (name = $2 OR substr(name, 1, $3) = $4 || '_')", 4)) || | 411 | " AND (name = $2 OR substr(name, 1, $3) = $4)", 4)) || |
426 | 412 | ||
427 | (GNUNET_OK != GNUNET_POSTGRES_prepare (plugin->dbh, | 413 | (GNUNET_OK != GNUNET_POSTGRES_prepare (plugin->dbh, |
428 | "select_state_signed", | 414 | "select_state_signed", |
@@ -764,7 +750,7 @@ fragment_store (void *cls, | |||
764 | uint64_t message_id = GNUNET_ntohll (msg->message_id); | 750 | uint64_t message_id = GNUNET_ntohll (msg->message_id); |
765 | uint64_t group_generation = GNUNET_ntohll (msg->group_generation); | 751 | uint64_t group_generation = GNUNET_ntohll (msg->group_generation); |
766 | 752 | ||
767 | uint64_t hop_counter = ntohl(msg->hop_counter); | 753 | uint32_t hop_counter = ntohl(msg->hop_counter); |
768 | uint32_t flags = ntohl(msg->flags); | 754 | uint32_t flags = ntohl(msg->flags); |
769 | 755 | ||
770 | if (fragment_id > INT64_MAX || fragment_offset > INT64_MAX || | 756 | if (fragment_id > INT64_MAX || fragment_offset > INT64_MAX || |
@@ -783,7 +769,7 @@ fragment_store (void *cls, | |||
783 | 769 | ||
784 | struct GNUNET_PQ_QueryParam params_insert[] = { | 770 | struct GNUNET_PQ_QueryParam params_insert[] = { |
785 | GNUNET_PQ_query_param_auto_from_type (channel_key), | 771 | GNUNET_PQ_query_param_auto_from_type (channel_key), |
786 | GNUNET_PQ_query_param_uint64 (&hop_counter), | 772 | GNUNET_PQ_query_param_uint32 (&hop_counter), |
787 | GNUNET_PQ_query_param_auto_from_type (&msg->signature), | 773 | GNUNET_PQ_query_param_auto_from_type (&msg->signature), |
788 | GNUNET_PQ_query_param_auto_from_type (&msg->purpose), | 774 | GNUNET_PQ_query_param_auto_from_type (&msg->purpose), |
789 | GNUNET_PQ_query_param_uint64 (&fragment_id), | 775 | GNUNET_PQ_query_param_uint64 (&fragment_id), |
@@ -819,15 +805,13 @@ static int | |||
819 | message_add_flags (void *cls, | 805 | message_add_flags (void *cls, |
820 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, | 806 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, |
821 | uint64_t message_id, | 807 | uint64_t message_id, |
822 | uint64_t psycstore_flags) | 808 | uint32_t psycstore_flags) |
823 | { | 809 | { |
824 | PGresult *res; | 810 | PGresult *res; |
825 | struct Plugin *plugin = cls; | 811 | struct Plugin *plugin = cls; |
826 | 812 | ||
827 | int ret = GNUNET_SYSERR; | ||
828 | |||
829 | struct GNUNET_PQ_QueryParam params_update[] = { | 813 | struct GNUNET_PQ_QueryParam params_update[] = { |
830 | GNUNET_PQ_query_param_uint64 (&psycstore_flags), | 814 | GNUNET_PQ_query_param_uint32 (&psycstore_flags), |
831 | GNUNET_PQ_query_param_auto_from_type (channel_key), | 815 | GNUNET_PQ_query_param_auto_from_type (channel_key), |
832 | GNUNET_PQ_query_param_uint64 (&message_id), | 816 | GNUNET_PQ_query_param_uint64 (&message_id), |
833 | GNUNET_PQ_query_param_end | 817 | GNUNET_PQ_query_param_end |
@@ -838,10 +822,10 @@ message_add_flags (void *cls, | |||
838 | res, | 822 | res, |
839 | PGRES_COMMAND_OK, | 823 | PGRES_COMMAND_OK, |
840 | "PQexecPrepared","update_message_flags")) | 824 | "PQexecPrepared","update_message_flags")) |
841 | return ret; | 825 | return GNUNET_SYSERR; |
842 | 826 | ||
843 | PQclear (res); | 827 | PQclear (res); |
844 | return ret; | 828 | return GNUNET_OK; |
845 | } | 829 | } |
846 | 830 | ||
847 | 831 | ||
@@ -850,7 +834,8 @@ fragment_row (struct Plugin *plugin, | |||
850 | const char *stmt, | 834 | const char *stmt, |
851 | PGresult *res, | 835 | PGresult *res, |
852 | GNUNET_PSYCSTORE_FragmentCallback cb, | 836 | GNUNET_PSYCSTORE_FragmentCallback cb, |
853 | void *cb_cls) | 837 | void *cb_cls, |
838 | uint64_t *returned_fragments) | ||
854 | { | 839 | { |
855 | uint32_t hop_counter; | 840 | uint32_t hop_counter; |
856 | void *signature = NULL; | 841 | void *signature = NULL; |
@@ -862,14 +847,13 @@ fragment_row (struct Plugin *plugin, | |||
862 | uint64_t fragment_offset; | 847 | uint64_t fragment_offset; |
863 | uint64_t message_id; | 848 | uint64_t message_id; |
864 | uint64_t group_generation; | 849 | uint64_t group_generation; |
865 | uint64_t flags; | 850 | uint32_t flags; |
866 | void *buf; | 851 | void *buf; |
867 | size_t buf_size; | 852 | size_t buf_size; |
868 | int ret = GNUNET_SYSERR; | 853 | int ret = GNUNET_SYSERR; |
869 | struct GNUNET_MULTICAST_MessageHeader *mp; | 854 | struct GNUNET_MULTICAST_MessageHeader *mp; |
870 | 855 | ||
871 | uint64_t msg_flags; | 856 | uint32_t msg_flags; |
872 | unsigned int cnt; | ||
873 | 857 | ||
874 | struct GNUNET_PQ_ResultSpec results[] = { | 858 | struct GNUNET_PQ_ResultSpec results[] = { |
875 | GNUNET_PQ_result_spec_uint32 ("hop_counter", &hop_counter), | 859 | GNUNET_PQ_result_spec_uint32 ("hop_counter", &hop_counter), |
@@ -879,8 +863,8 @@ fragment_row (struct Plugin *plugin, | |||
879 | GNUNET_PQ_result_spec_uint64 ("fragment_offset", &fragment_offset), | 863 | GNUNET_PQ_result_spec_uint64 ("fragment_offset", &fragment_offset), |
880 | GNUNET_PQ_result_spec_uint64 ("message_id", &message_id), | 864 | GNUNET_PQ_result_spec_uint64 ("message_id", &message_id), |
881 | GNUNET_PQ_result_spec_uint64 ("group_generation", &group_generation), | 865 | GNUNET_PQ_result_spec_uint64 ("group_generation", &group_generation), |
882 | GNUNET_PQ_result_spec_uint64 ("multicast_flags", &msg_flags), | 866 | GNUNET_PQ_result_spec_uint32 ("multicast_flags", &msg_flags), |
883 | GNUNET_PQ_result_spec_uint64 ("psycstore_flags", &flags), | 867 | GNUNET_PQ_result_spec_uint32 ("psycstore_flags", &flags), |
884 | GNUNET_PQ_result_spec_variable_size ("data", &buf, &buf_size), | 868 | GNUNET_PQ_result_spec_variable_size ("data", &buf, &buf_size), |
885 | GNUNET_PQ_result_spec_end | 869 | GNUNET_PQ_result_spec_end |
886 | }; | 870 | }; |
@@ -895,15 +879,12 @@ fragment_row (struct Plugin *plugin, | |||
895 | return GNUNET_SYSERR; | 879 | return GNUNET_SYSERR; |
896 | } | 880 | } |
897 | 881 | ||
898 | cnt = PQntuples (res); | 882 | int nrows = PQntuples (res); |
899 | if (cnt == 0) | 883 | for (int row = 0; row < nrows; row++) |
900 | { | 884 | { |
901 | ret = GNUNET_NO; | 885 | if (GNUNET_OK != GNUNET_PQ_extract_result (res, results, row)) |
902 | } | 886 | { |
903 | else | 887 | break; |
904 | { | ||
905 | if (GNUNET_OK != GNUNET_PQ_extract_result(res, results, 0)) { | ||
906 | return GNUNET_SYSERR; | ||
907 | } | 888 | } |
908 | 889 | ||
909 | mp = GNUNET_malloc (sizeof (*mp) + buf_size); | 890 | mp = GNUNET_malloc (sizeof (*mp) + buf_size); |
@@ -928,6 +909,8 @@ fragment_row (struct Plugin *plugin, | |||
928 | buf_size); | 909 | buf_size); |
929 | GNUNET_PQ_cleanup_result(results); | 910 | GNUNET_PQ_cleanup_result(results); |
930 | ret = cb (cb_cls, mp, (enum GNUNET_PSYCSTORE_MessageFlags) flags); | 911 | ret = cb (cb_cls, mp, (enum GNUNET_PSYCSTORE_MessageFlags) flags); |
912 | if (NULL != returned_fragments) | ||
913 | (*returned_fragments)++; | ||
931 | } | 914 | } |
932 | 915 | ||
933 | return ret; | 916 | return ret; |
@@ -956,8 +939,7 @@ fragment_select (struct Plugin *plugin, | |||
956 | ret = GNUNET_NO; | 939 | ret = GNUNET_NO; |
957 | else | 940 | else |
958 | { | 941 | { |
959 | ret = fragment_row (plugin, stmt, res, cb, cb_cls); | 942 | ret = fragment_row (plugin, stmt, res, cb, cb_cls, returned_fragments); |
960 | (*returned_fragments)++; | ||
961 | } | 943 | } |
962 | PQclear (res); | 944 | PQclear (res); |
963 | } | 945 | } |
@@ -1044,6 +1026,9 @@ message_get (void *cls, | |||
1044 | struct Plugin *plugin = cls; | 1026 | struct Plugin *plugin = cls; |
1045 | *returned_fragments = 0; | 1027 | *returned_fragments = 0; |
1046 | 1028 | ||
1029 | if (0 == fragment_limit) | ||
1030 | fragment_limit = INT64_MAX; | ||
1031 | |||
1047 | struct GNUNET_PQ_QueryParam params_select[] = { | 1032 | struct GNUNET_PQ_QueryParam params_select[] = { |
1048 | GNUNET_PQ_query_param_auto_from_type (channel_key), | 1033 | GNUNET_PQ_query_param_auto_from_type (channel_key), |
1049 | GNUNET_PQ_query_param_uint64 (&first_message_id), | 1034 | GNUNET_PQ_query_param_uint64 (&first_message_id), |
@@ -1122,7 +1107,7 @@ message_get_fragment (void *cls, | |||
1122 | if (PQntuples (res) == 0) | 1107 | if (PQntuples (res) == 0) |
1123 | ret = GNUNET_NO; | 1108 | ret = GNUNET_NO; |
1124 | else | 1109 | else |
1125 | ret = fragment_row (plugin, stmt, res, cb, cb_cls); | 1110 | ret = fragment_row (plugin, stmt, res, cb, cb_cls, NULL); |
1126 | 1111 | ||
1127 | PQclear (res); | 1112 | PQclear (res); |
1128 | } | 1113 | } |
@@ -1164,14 +1149,13 @@ counters_message_get (void *cls, | |||
1164 | } | 1149 | } |
1165 | 1150 | ||
1166 | struct GNUNET_PQ_ResultSpec results_select[] = { | 1151 | struct GNUNET_PQ_ResultSpec results_select[] = { |
1167 | GNUNET_PQ_result_spec_uint64 ("max_fragment_id", max_fragment_id), | 1152 | GNUNET_PQ_result_spec_uint64 ("fragment_id", max_fragment_id), |
1168 | GNUNET_PQ_result_spec_uint64 ("max_message_id", max_message_id), | 1153 | GNUNET_PQ_result_spec_uint64 ("message_id", max_message_id), |
1169 | GNUNET_PQ_result_spec_uint64 ("max_group_generation", max_group_generation), | 1154 | GNUNET_PQ_result_spec_uint64 ("group_generation", max_group_generation), |
1170 | GNUNET_PQ_result_spec_end | 1155 | GNUNET_PQ_result_spec_end |
1171 | }; | 1156 | }; |
1172 | 1157 | ||
1173 | if (GNUNET_OK != GNUNET_PQ_extract_result (res, | 1158 | if (GNUNET_OK != GNUNET_PQ_extract_result (res, results_select, 0)) |
1174 | results_select, 0)) | ||
1175 | { | 1159 | { |
1176 | PQclear (res); | 1160 | PQclear (res); |
1177 | return GNUNET_SYSERR; | 1161 | return GNUNET_SYSERR; |
@@ -1221,8 +1205,7 @@ counters_state_get (void *cls, | |||
1221 | GNUNET_PQ_result_spec_end | 1205 | GNUNET_PQ_result_spec_end |
1222 | }; | 1206 | }; |
1223 | 1207 | ||
1224 | ret = GNUNET_PQ_extract_result (res, | 1208 | ret = GNUNET_PQ_extract_result (res, results_select, 0); |
1225 | results_select, 0); | ||
1226 | 1209 | ||
1227 | if (GNUNET_OK != ret) | 1210 | if (GNUNET_OK != ret) |
1228 | { | 1211 | { |
@@ -1540,8 +1523,7 @@ state_get (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, | |||
1540 | ret = GNUNET_NO; | 1523 | ret = GNUNET_NO; |
1541 | } | 1524 | } |
1542 | 1525 | ||
1543 | ret = GNUNET_PQ_extract_result (res, | 1526 | ret = GNUNET_PQ_extract_result (res, results, 0); |
1544 | results, 0); | ||
1545 | 1527 | ||
1546 | if (GNUNET_OK != ret) | 1528 | if (GNUNET_OK != ret) |
1547 | { | 1529 | { |
@@ -1573,7 +1555,7 @@ state_get_prefix (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_ | |||
1573 | { | 1555 | { |
1574 | PGresult *res; | 1556 | PGresult *res; |
1575 | struct Plugin *plugin = cls; | 1557 | struct Plugin *plugin = cls; |
1576 | int ret = GNUNET_SYSERR; | 1558 | int ret = GNUNET_NO; |
1577 | 1559 | ||
1578 | const char *stmt = "select_state_prefix"; | 1560 | const char *stmt = "select_state_prefix"; |
1579 | 1561 | ||
@@ -1606,18 +1588,11 @@ state_get_prefix (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_ | |||
1606 | return GNUNET_SYSERR; | 1588 | return GNUNET_SYSERR; |
1607 | } | 1589 | } |
1608 | 1590 | ||
1609 | do | 1591 | int nrows = PQntuples (res); |
1592 | for (int row = 0; row < nrows; row++) | ||
1610 | { | 1593 | { |
1611 | if (PQntuples (res) == 0) | 1594 | if (GNUNET_OK != GNUNET_PQ_extract_result (res, results, row)) |
1612 | { | 1595 | { |
1613 | PQclear (res); | ||
1614 | ret = GNUNET_NO; | ||
1615 | break; | ||
1616 | } | ||
1617 | |||
1618 | if (GNUNET_OK != GNUNET_PQ_extract_result (res, results, 0)) | ||
1619 | { | ||
1620 | PQclear (res); | ||
1621 | break; | 1596 | break; |
1622 | } | 1597 | } |
1623 | 1598 | ||
@@ -1626,7 +1601,6 @@ state_get_prefix (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_ | |||
1626 | value_size); | 1601 | value_size); |
1627 | GNUNET_PQ_cleanup_result(results); | 1602 | GNUNET_PQ_cleanup_result(results); |
1628 | } | 1603 | } |
1629 | while (ret == GNUNET_YES); | ||
1630 | 1604 | ||
1631 | PQclear (res); | 1605 | PQclear (res); |
1632 | 1606 | ||
@@ -1648,7 +1622,7 @@ state_get_signed (void *cls, | |||
1648 | { | 1622 | { |
1649 | PGresult *res; | 1623 | PGresult *res; |
1650 | struct Plugin *plugin = cls; | 1624 | struct Plugin *plugin = cls; |
1651 | int ret = GNUNET_SYSERR; | 1625 | int ret = GNUNET_NO; |
1652 | 1626 | ||
1653 | const char *stmt = "select_state_signed"; | 1627 | const char *stmt = "select_state_signed"; |
1654 | 1628 | ||
@@ -1676,18 +1650,11 @@ state_get_signed (void *cls, | |||
1676 | return GNUNET_SYSERR; | 1650 | return GNUNET_SYSERR; |
1677 | } | 1651 | } |
1678 | 1652 | ||
1679 | do | 1653 | int nrows = PQntuples (res); |
1654 | for (int row = 0; row < nrows; row++) | ||
1680 | { | 1655 | { |
1681 | if (PQntuples (res) == 0) | 1656 | if (GNUNET_OK != GNUNET_PQ_extract_result (res, results, row)) |
1682 | { | 1657 | { |
1683 | PQclear (res); | ||
1684 | ret = GNUNET_NO; | ||
1685 | break; | ||
1686 | } | ||
1687 | |||
1688 | if (GNUNET_OK != GNUNET_PQ_extract_result (res, results, 0)) | ||
1689 | { | ||
1690 | PQclear (res); | ||
1691 | break; | 1658 | break; |
1692 | } | 1659 | } |
1693 | 1660 | ||
@@ -1695,9 +1662,8 @@ state_get_signed (void *cls, | |||
1695 | value_signed, | 1662 | value_signed, |
1696 | value_size); | 1663 | value_size); |
1697 | 1664 | ||
1698 | GNUNET_PQ_cleanup_result(results); | 1665 | GNUNET_PQ_cleanup_result (results); |
1699 | } | 1666 | } |
1700 | while (ret == GNUNET_YES); | ||
1701 | 1667 | ||
1702 | PQclear (res); | 1668 | PQclear (res); |
1703 | 1669 | ||
diff --git a/src/psycstore/plugin_psycstore_sqlite.c b/src/psycstore/plugin_psycstore_sqlite.c index e6f795971..4d21696ce 100644 --- a/src/psycstore/plugin_psycstore_sqlite.c +++ b/src/psycstore/plugin_psycstore_sqlite.c | |||
@@ -599,7 +599,7 @@ database_setup (struct Plugin *plugin) | |||
599 | "SELECT name, value_current\n" | 599 | "SELECT name, value_current\n" |
600 | "FROM state\n" | 600 | "FROM state\n" |
601 | "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n" | 601 | "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n" |
602 | " AND (name = ? OR substr(name, 1, ?) = ? || '_');", | 602 | " AND (name = ? OR substr(name, 1, ?) = ?);", |
603 | &plugin->select_state_prefix); | 603 | &plugin->select_state_prefix); |
604 | 604 | ||
605 | sql_prepare (plugin->dbh, | 605 | sql_prepare (plugin->dbh, |
@@ -998,7 +998,7 @@ static int | |||
998 | message_add_flags (void *cls, | 998 | message_add_flags (void *cls, |
999 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, | 999 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, |
1000 | uint64_t message_id, | 1000 | uint64_t message_id, |
1001 | uint64_t psycstore_flags) | 1001 | uint32_t psycstore_flags) |
1002 | { | 1002 | { |
1003 | struct Plugin *plugin = cls; | 1003 | struct Plugin *plugin = cls; |
1004 | sqlite3_stmt *stmt = plugin->update_message_flags; | 1004 | sqlite3_stmt *stmt = plugin->update_message_flags; |
@@ -1773,7 +1773,7 @@ state_get_prefix (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_ | |||
1773 | if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key, | 1773 | if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key, |
1774 | sizeof (*channel_key), SQLITE_STATIC) | 1774 | sizeof (*channel_key), SQLITE_STATIC) |
1775 | || SQLITE_OK != sqlite3_bind_text (stmt, 2, name, name_len, SQLITE_STATIC) | 1775 | || SQLITE_OK != sqlite3_bind_text (stmt, 2, name, name_len, SQLITE_STATIC) |
1776 | || SQLITE_OK != sqlite3_bind_int (stmt, 3, name_len + 1) | 1776 | || SQLITE_OK != sqlite3_bind_int (stmt, 3, name_len) |
1777 | || SQLITE_OK != sqlite3_bind_text (stmt, 4, name, name_len, SQLITE_STATIC)) | 1777 | || SQLITE_OK != sqlite3_bind_text (stmt, 4, name, name_len, SQLITE_STATIC)) |
1778 | { | 1778 | { |
1779 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1779 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |