diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-11-21 17:08:39 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-11-21 17:08:39 +0100 |
commit | d237b33a42048e26f409375af65ec275ae0eb027 (patch) | |
tree | 13e65c716a2df41193540f318621d7655962f954 | |
parent | 92c6328195c3bed9abbd56625fcab5952869289c (diff) | |
download | gnunet-d237b33a42048e26f409375af65ec275ae0eb027.tar.gz gnunet-d237b33a42048e26f409375af65ec275ae0eb027.zip |
modernize namestore postgres plugin, a bit
-rw-r--r-- | src/include/gnunet_namestore_plugin.h | 83 | ||||
-rw-r--r-- | src/namestore/Makefile.am | 6 | ||||
-rw-r--r-- | src/namestore/gnunet-namestore-dbtool.c | 55 | ||||
-rw-r--r-- | src/namestore/namestore-0001.sql | 48 | ||||
-rw-r--r-- | src/namestore/namestore-drop.sql | 25 | ||||
-rw-r--r-- | src/namestore/plugin_namestore_postgres.c | 288 | ||||
-rw-r--r-- | src/namestore/plugin_namestore_sqlite.c | 109 | ||||
-rw-r--r-- | src/namestore/test_common.c | 46 | ||||
-rw-r--r-- | src/namestore/test_plugin_namestore.c | 21 |
9 files changed, 362 insertions, 319 deletions
diff --git a/src/include/gnunet_namestore_plugin.h b/src/include/gnunet_namestore_plugin.h index 1df0a5eb0..4f08ccbcf 100644 --- a/src/include/gnunet_namestore_plugin.h +++ b/src/include/gnunet_namestore_plugin.h | |||
@@ -88,12 +88,12 @@ struct GNUNET_NAMESTORE_PluginFunctions | |||
88 | * @param rd array of records with data to store | 88 | * @param rd array of records with data to store |
89 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | 89 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR |
90 | */ | 90 | */ |
91 | int | 91 | enum GNUNET_GenericReturnValue |
92 | (*store_records) (void *cls, | 92 | (*store_records)(void *cls, |
93 | const struct GNUNET_IDENTITY_PrivateKey *zone, | 93 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
94 | const char *label, | 94 | const char *label, |
95 | unsigned int rd_count, | 95 | unsigned int rd_count, |
96 | const struct GNUNET_GNSRECORD_Data *rd); | 96 | const struct GNUNET_GNSRECORD_Data *rd); |
97 | 97 | ||
98 | /** | 98 | /** |
99 | * Lookup records in the datastore for which we are the authority. | 99 | * Lookup records in the datastore for which we are the authority. |
@@ -105,12 +105,12 @@ struct GNUNET_NAMESTORE_PluginFunctions | |||
105 | * @param iter_cls closure for @a iter | 105 | * @param iter_cls closure for @a iter |
106 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR | 106 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR |
107 | */ | 107 | */ |
108 | int | 108 | enum GNUNET_GenericReturnValue |
109 | (*lookup_records) (void *cls, | 109 | (*lookup_records)(void *cls, |
110 | const struct GNUNET_IDENTITY_PrivateKey *zone, | 110 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
111 | const char *label, | 111 | const char *label, |
112 | GNUNET_NAMESTORE_RecordIterator iter, | 112 | GNUNET_NAMESTORE_RecordIterator iter, |
113 | void *iter_cls); | 113 | void *iter_cls); |
114 | 114 | ||
115 | 115 | ||
116 | /** | 116 | /** |
@@ -127,13 +127,13 @@ struct GNUNET_NAMESTORE_PluginFunctions | |||
127 | * @param iter_cls closure for @a iter | 127 | * @param iter_cls closure for @a iter |
128 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error | 128 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error |
129 | */ | 129 | */ |
130 | int | 130 | enum GNUNET_GenericReturnValue |
131 | (*iterate_records) (void *cls, | 131 | (*iterate_records)(void *cls, |
132 | const struct GNUNET_IDENTITY_PrivateKey *zone, | 132 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
133 | uint64_t serial, | 133 | uint64_t serial, |
134 | uint64_t limit, | 134 | uint64_t limit, |
135 | GNUNET_NAMESTORE_RecordIterator iter, | 135 | GNUNET_NAMESTORE_RecordIterator iter, |
136 | void *iter_cls); | 136 | void *iter_cls); |
137 | 137 | ||
138 | 138 | ||
139 | /** | 139 | /** |
@@ -147,12 +147,12 @@ struct GNUNET_NAMESTORE_PluginFunctions | |||
147 | * @param iter_cls closure for @a iter | 147 | * @param iter_cls closure for @a iter |
148 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | 148 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error |
149 | */ | 149 | */ |
150 | int | 150 | enum GNUNET_GenericReturnValue |
151 | (*zone_to_name) (void *cls, | 151 | (*zone_to_name)(void *cls, |
152 | const struct GNUNET_IDENTITY_PrivateKey *zone, | 152 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
153 | const struct GNUNET_IDENTITY_PublicKey *value_zone, | 153 | const struct GNUNET_IDENTITY_PublicKey *value_zone, |
154 | GNUNET_NAMESTORE_RecordIterator iter, | 154 | GNUNET_NAMESTORE_RecordIterator iter, |
155 | void *iter_cls); | 155 | void *iter_cls); |
156 | 156 | ||
157 | /** Transaction-based API draft **/ | 157 | /** Transaction-based API draft **/ |
158 | 158 | ||
@@ -164,7 +164,7 @@ struct GNUNET_NAMESTORE_PluginFunctions | |||
164 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 164 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
165 | */ | 165 | */ |
166 | enum GNUNET_GenericReturnValue | 166 | enum GNUNET_GenericReturnValue |
167 | (*transaction_begin) (void *cls, char **emsg); | 167 | (*transaction_begin)(void *cls, char **emsg); |
168 | 168 | ||
169 | /** | 169 | /** |
170 | * Abort and roll back a transaction in the database | 170 | * Abort and roll back a transaction in the database |
@@ -174,7 +174,7 @@ struct GNUNET_NAMESTORE_PluginFunctions | |||
174 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 174 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
175 | */ | 175 | */ |
176 | enum GNUNET_GenericReturnValue | 176 | enum GNUNET_GenericReturnValue |
177 | (*transaction_rollback) (void *cls, char **emsg); | 177 | (*transaction_rollback)(void *cls, char **emsg); |
178 | 178 | ||
179 | /** | 179 | /** |
180 | * Commit a transaction in the database | 180 | * Commit a transaction in the database |
@@ -184,7 +184,7 @@ struct GNUNET_NAMESTORE_PluginFunctions | |||
184 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 184 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
185 | */ | 185 | */ |
186 | enum GNUNET_GenericReturnValue | 186 | enum GNUNET_GenericReturnValue |
187 | (*transaction_commit) (void *cls, char **emsg); | 187 | (*transaction_commit)(void *cls, char **emsg); |
188 | 188 | ||
189 | /** | 189 | /** |
190 | * Edit records in the datastore for which we are the authority. | 190 | * Edit records in the datastore for which we are the authority. |
@@ -198,35 +198,32 @@ struct GNUNET_NAMESTORE_PluginFunctions | |||
198 | * @param iter_cls closure for @a iter | 198 | * @param iter_cls closure for @a iter |
199 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR | 199 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR |
200 | */ | 200 | */ |
201 | int | 201 | enum GNUNET_GenericReturnValue |
202 | (*edit_records) (void *cls, | 202 | (*edit_records)(void *cls, |
203 | const struct GNUNET_IDENTITY_PrivateKey *zone, | 203 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
204 | const char *label, | 204 | const char *label, |
205 | GNUNET_NAMESTORE_RecordIterator iter, | 205 | GNUNET_NAMESTORE_RecordIterator iter, |
206 | void *iter_cls); | 206 | void *iter_cls); |
207 | 207 | ||
208 | /** | 208 | /** |
209 | * Setup the database. | 209 | * Setup the database. |
210 | * Note that this will also fail if the database is already initialized. | ||
211 | * See reset_database(). | ||
212 | * | 210 | * |
213 | * @param cls closure (internal context for the plugin) | 211 | * @param cls closure (internal context for the plugin) |
214 | * @param emsg error message on failure. Will be allocated, must be freed. | ||
215 | * @return #GNUNET_OK on success, else fails with #GNUNET_SYSERR | 212 | * @return #GNUNET_OK on success, else fails with #GNUNET_SYSERR |
216 | */ | 213 | */ |
217 | int | 214 | enum GNUNET_GenericReturnValue |
218 | (*initialize_database) (void *cls, char **emsg); | 215 | (*create_tables)(void *cls); |
216 | |||
219 | 217 | ||
220 | /** | 218 | /** |
221 | * Re-initializes the database. | 219 | * Drop existing tables. |
222 | * DANGEROUS: All existing data in the dabase will be lost! | 220 | * DANGEROUS: All existing data in the dabase will be lost! |
223 | * | 221 | * |
224 | * @param cls closure (internal context for the plugin) | 222 | * @param cls closure (internal context for the plugin) |
225 | * @param emsg error message on failure. Will be allocated, must be freed. | ||
226 | * @return #GNUNET_OK on success, else fails with #GNUNET_SYSERR | 223 | * @return #GNUNET_OK on success, else fails with #GNUNET_SYSERR |
227 | */ | 224 | */ |
228 | int | 225 | enum GNUNET_GenericReturnValue |
229 | (*reset_database) (void *cls, char **emsg); | 226 | (*drop_tables)(void *cls); |
230 | }; | 227 | }; |
231 | 228 | ||
232 | 229 | ||
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index a0ca32fa4..b4d2b0ff2 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -7,6 +7,12 @@ pkgcfgdir= $(pkgdatadir)/config.d/ | |||
7 | 7 | ||
8 | libexecdir= $(pkglibdir)/libexec/ | 8 | libexecdir= $(pkglibdir)/libexec/ |
9 | 9 | ||
10 | sqldir = $(prefix)/share/gnunet/sql/ | ||
11 | |||
12 | sql_DATA = \ | ||
13 | namestore-0001.sql \ | ||
14 | namestore-drop.sql | ||
15 | |||
10 | pkgcfg_DATA = \ | 16 | pkgcfg_DATA = \ |
11 | namestore.conf | 17 | namestore.conf |
12 | 18 | ||
diff --git a/src/namestore/gnunet-namestore-dbtool.c b/src/namestore/gnunet-namestore-dbtool.c index a1ecf5e71..835d7a228 100644 --- a/src/namestore/gnunet-namestore-dbtool.c +++ b/src/namestore/gnunet-namestore-dbtool.c | |||
@@ -59,6 +59,8 @@ do_shutdown (void *cls) | |||
59 | if (NULL != pluginname) | 59 | if (NULL != pluginname) |
60 | GNUNET_free (pluginname); | 60 | GNUNET_free (pluginname); |
61 | } | 61 | } |
62 | |||
63 | |||
62 | /** | 64 | /** |
63 | * Main function that will be run. | 65 | * Main function that will be run. |
64 | * | 66 | * |
@@ -74,7 +76,6 @@ run (void *cls, | |||
74 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 76 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
75 | { | 77 | { |
76 | char *db_lib_name; | 78 | char *db_lib_name; |
77 | char *emsg; | ||
78 | struct GNUNET_NAMESTORE_PluginFunctions *plugin; | 79 | struct GNUNET_NAMESTORE_PluginFunctions *plugin; |
79 | 80 | ||
80 | (void) cls; | 81 | (void) cls; |
@@ -86,7 +87,8 @@ run (void *cls, | |||
86 | _ ("Superfluous command line arguments (starting with `%s') ignored\n"), | 87 | _ ("Superfluous command line arguments (starting with `%s') ignored\n"), |
87 | args[0]); | 88 | args[0]); |
88 | 89 | ||
89 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, (void *) cfg); | 90 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
91 | (void *) cfg); | ||
90 | if (NULL == pluginname) | 92 | if (NULL == pluginname) |
91 | { | 93 | { |
92 | fprintf (stderr, "No plugin given!\n"); | 94 | fprintf (stderr, "No plugin given!\n"); |
@@ -94,11 +96,15 @@ run (void *cls, | |||
94 | GNUNET_SCHEDULER_shutdown (); | 96 | GNUNET_SCHEDULER_shutdown (); |
95 | return; | 97 | return; |
96 | } | 98 | } |
97 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", pluginname); | 99 | GNUNET_asprintf (&db_lib_name, |
100 | "libgnunet_plugin_namestore_%s", | ||
101 | pluginname); | ||
98 | plugin = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); | 102 | plugin = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); |
99 | if (NULL == plugin) | 103 | if (NULL == plugin) |
100 | { | 104 | { |
101 | fprintf (stderr, "Failed to load %s!\n", db_lib_name); | 105 | fprintf (stderr, |
106 | "Failed to load %s!\n", | ||
107 | db_lib_name); | ||
102 | ret = 1; | 108 | ret = 1; |
103 | GNUNET_SCHEDULER_shutdown (); | 109 | GNUNET_SCHEDULER_shutdown (); |
104 | GNUNET_free (db_lib_name); | 110 | GNUNET_free (db_lib_name); |
@@ -106,34 +112,33 @@ run (void *cls, | |||
106 | } | 112 | } |
107 | if (reset) | 113 | if (reset) |
108 | { | 114 | { |
109 | if (GNUNET_OK != plugin->reset_database (plugin->cls, &emsg)) | 115 | if (GNUNET_OK != |
116 | plugin->drop_tables (plugin->cls)) | ||
110 | { | 117 | { |
111 | // FIXME do we want to return a reason? | 118 | fprintf (stderr, |
112 | fprintf (stderr, "Failed to reset database: %s\n", | 119 | "Failed to reset database\n"); |
113 | emsg); | ||
114 | ret = 1; | 120 | ret = 1; |
115 | GNUNET_free (emsg); | ||
116 | GNUNET_free (db_lib_name); | 121 | GNUNET_free (db_lib_name); |
117 | GNUNET_SCHEDULER_shutdown (); | 122 | GNUNET_SCHEDULER_shutdown (); |
118 | return; | 123 | return; |
119 | } | 124 | } |
120 | } | 125 | } |
121 | else if (init) | 126 | if (init || reset) |
122 | { | 127 | { |
123 | if (GNUNET_OK != plugin->initialize_database (plugin->cls, &emsg)) | 128 | if (GNUNET_OK != |
129 | plugin->create_tables (plugin->cls)) | ||
124 | { | 130 | { |
125 | // FIXME do we want to return a reason? | 131 | fprintf (stderr, |
126 | fprintf (stderr, "Failed to initialize database: %s\n", | 132 | "Failed to initialize database\n"); |
127 | emsg); | ||
128 | ret = 1; | 133 | ret = 1; |
129 | GNUNET_free (emsg); | ||
130 | GNUNET_free (db_lib_name); | 134 | GNUNET_free (db_lib_name); |
131 | GNUNET_SCHEDULER_shutdown (); | 135 | GNUNET_SCHEDULER_shutdown (); |
132 | return; | 136 | return; |
133 | } | 137 | } |
134 | } | 138 | } |
135 | GNUNET_SCHEDULER_shutdown (); | 139 | GNUNET_SCHEDULER_shutdown (); |
136 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, plugin)); | 140 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, |
141 | plugin)); | ||
137 | GNUNET_free (db_lib_name); | 142 | GNUNET_free (db_lib_name); |
138 | } | 143 | } |
139 | 144 | ||
@@ -148,9 +153,10 @@ run (void *cls, | |||
148 | int | 153 | int |
149 | main (int argc, char *const *argv) | 154 | main (int argc, char *const *argv) |
150 | { | 155 | { |
151 | struct GNUNET_GETOPT_CommandLineOption options[] = | 156 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
152 | { GNUNET_GETOPT_option_flag ('i', "init", gettext_noop ( | 157 | GNUNET_GETOPT_option_flag ('i', "init", |
153 | "initialize database"), &init), | 158 | gettext_noop ("initialize database"), |
159 | &init), | ||
154 | GNUNET_GETOPT_option_flag ('r', | 160 | GNUNET_GETOPT_option_flag ('r', |
155 | "reset", | 161 | "reset", |
156 | gettext_noop ( | 162 | gettext_noop ( |
@@ -163,13 +169,18 @@ main (int argc, char *const *argv) | |||
163 | gettext_noop ( | 169 | gettext_noop ( |
164 | "the namestore plugin to work with, e.g. 'sqlite'"), | 170 | "the namestore plugin to work with, e.g. 'sqlite'"), |
165 | &pluginname), | 171 | &pluginname), |
166 | GNUNET_GETOPT_OPTION_END }; | 172 | GNUNET_GETOPT_OPTION_END |
173 | }; | ||
167 | int lret; | 174 | int lret; |
168 | 175 | ||
169 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 176 | if (GNUNET_OK != |
177 | GNUNET_STRINGS_get_utf8_args (argc, argv, | ||
178 | &argc, &argv)) | ||
170 | return 2; | 179 | return 2; |
171 | 180 | ||
172 | GNUNET_log_setup ("gnunet-namestore-dbtool", "WARNING", NULL); | 181 | GNUNET_log_setup ("gnunet-namestore-dbtool", |
182 | "WARNING", | ||
183 | NULL); | ||
173 | if (GNUNET_OK != | 184 | if (GNUNET_OK != |
174 | (lret = GNUNET_PROGRAM_run (argc, | 185 | (lret = GNUNET_PROGRAM_run (argc, |
175 | argv, | 186 | argv, |
diff --git a/src/namestore/namestore-0001.sql b/src/namestore/namestore-0001.sql new file mode 100644 index 000000000..bdfb31976 --- /dev/null +++ b/src/namestore/namestore-0001.sql | |||
@@ -0,0 +1,48 @@ | |||
1 | -- | ||
2 | -- This file is part of GNUnet | ||
3 | -- Copyright (C) 2014--2022 GNUnet e.V. | ||
4 | -- | ||
5 | -- GNUnet is free software; you can redistribute it and/or modify it under the | ||
6 | -- terms of the GNU General Public License as published by the Free Software | ||
7 | -- Foundation; either version 3, or (at your option) any later version. | ||
8 | -- | ||
9 | -- GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | ||
10 | -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
11 | -- A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
12 | -- | ||
13 | -- You should have received a copy of the GNU General Public License along with | ||
14 | -- GNUnet; see the file COPYING. If not, see <http://www.gnu.org/licenses/> | ||
15 | -- | ||
16 | |||
17 | -- Everything in one big transaction | ||
18 | BEGIN; | ||
19 | |||
20 | -- Check patch versioning is in place. | ||
21 | SELECT _v.register_patch('namestore-0001', NULL, NULL); | ||
22 | |||
23 | -------------------- Schema ---------------------------- | ||
24 | |||
25 | CREATE SCHEMA namestore; | ||
26 | COMMENT ON SCHEMA namestore IS 'gnunet-namestore data'; | ||
27 | |||
28 | SET search_path TO namestore; | ||
29 | |||
30 | CREATE TABLE ns098records ( | ||
31 | seq BIGSERIAL PRIMARY KEY, | ||
32 | zone_private_key BYTEA NOT NULL DEFAULT '', | ||
33 | pkey BYTEA DEFAULT '', | ||
34 | rvalue BYTEA NOT NULL DEFAULT '', | ||
35 | record_count INTEGER NOT NULL DEFAULT 0, | ||
36 | record_data BYTEA NOT NULL DEFAULT '', | ||
37 | label TEXT NOT NULL DEFAULT '', | ||
38 | CONSTRAINT zl UNIQUE (zone_private_key,label)); | ||
39 | |||
40 | CREATE INDEX IF NOT EXISTS ir_pkey_reverse | ||
41 | ON ns098records (zone_private_key,pkey); | ||
42 | CREATE INDEX IF NOT EXISTS ir_pkey_iter | ||
43 | ON ns098records (zone_private_key,seq); | ||
44 | CREATE INDEX IF NOT EXISTS ir_label | ||
45 | ON ns098records (label); | ||
46 | |||
47 | |||
48 | COMMIT; | ||
diff --git a/src/namestore/namestore-drop.sql b/src/namestore/namestore-drop.sql new file mode 100644 index 000000000..231417af8 --- /dev/null +++ b/src/namestore/namestore-drop.sql | |||
@@ -0,0 +1,25 @@ | |||
1 | -- | ||
2 | -- This file is part of GNUnet | ||
3 | -- Copyright (C) 2014--2022 GNUnet e.V. | ||
4 | -- | ||
5 | -- GNUnet is free software; you can redistribute it and/or modify it under the | ||
6 | -- terms of the GNU General Public License as published by the Free Software | ||
7 | -- Foundation; either version 3, or (at your option) any later version. | ||
8 | -- | ||
9 | -- GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | ||
10 | -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
11 | -- A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
12 | -- | ||
13 | -- You should have received a copy of the GNU General Public License along with | ||
14 | -- GNUnet; see the file COPYING. If not, see <http://www.gnu.org/licenses/> | ||
15 | -- | ||
16 | |||
17 | -- Everything in one big transaction | ||
18 | BEGIN; | ||
19 | |||
20 | |||
21 | SELECT _v.unregister_patch('namestore-0001'); | ||
22 | |||
23 | DROP SCHEMA namestore CASCADE; | ||
24 | |||
25 | COMMIT; | ||
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index d453bc977..de819f196 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c | |||
@@ -45,165 +45,118 @@ struct Plugin | |||
45 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 45 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Database is prepared and ready | 48 | * Postgres database handle. |
49 | */ | 49 | */ |
50 | int ready; | 50 | struct GNUNET_PQ_Context *dbh; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Postgres database handle. | 53 | * Database is prepared and ready |
54 | */ | 54 | */ |
55 | struct GNUNET_PQ_Context *dbh; | 55 | bool ready; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Initialize the database connections and associated | 60 | * Initialize the database connections and associated data structures (create |
61 | * data structures (create tables and indices | 61 | * tables and indices as needed as well). |
62 | * as needed as well). | ||
63 | * | 62 | * |
64 | * @param plugin the plugin context (state for this module) | 63 | * @param cls the plugin context (state for this module) |
65 | * @return #GNUNET_OK on success | 64 | * @return #GNUNET_OK on success |
66 | */ | 65 | */ |
67 | static int | 66 | static enum GNUNET_GenericReturnValue |
68 | init_database (struct Plugin *plugin, char **emsg, int drop) | 67 | namestore_postgres_create_tables (void *cls) |
69 | { | 68 | { |
70 | struct GNUNET_PQ_ExecuteStatement es_temporary = | 69 | struct Plugin *plugin = cls; |
71 | GNUNET_PQ_make_execute ( | 70 | struct GNUNET_PQ_Context *dbh; |
72 | "CREATE TEMPORARY TABLE ns098records (" | ||
73 | " seq BIGSERIAL PRIMARY KEY," | ||
74 | " zone_private_key BYTEA NOT NULL DEFAULT ''," | ||
75 | " pkey BYTEA DEFAULT ''," | ||
76 | " rvalue BYTEA NOT NULL DEFAULT ''," | ||
77 | " record_count INTEGER NOT NULL DEFAULT 0," | ||
78 | " record_data BYTEA NOT NULL DEFAULT ''," | ||
79 | " label TEXT NOT NULL DEFAULT ''," | ||
80 | " CONSTRAINT zl UNIQUE (zone_private_key,label)" | ||
81 | ")"); | ||
82 | struct GNUNET_PQ_ExecuteStatement es_default = | ||
83 | GNUNET_PQ_make_execute ("CREATE TABLE ns098records (" | ||
84 | " seq BIGSERIAL PRIMARY KEY," | ||
85 | " zone_private_key BYTEA NOT NULL DEFAULT ''," | ||
86 | " pkey BYTEA DEFAULT ''," | ||
87 | " rvalue BYTEA NOT NULL DEFAULT ''," | ||
88 | " record_count INTEGER NOT NULL DEFAULT 0," | ||
89 | " record_data BYTEA NOT NULL DEFAULT ''," | ||
90 | " label TEXT NOT NULL DEFAULT ''," | ||
91 | " CONSTRAINT zl UNIQUE (zone_private_key,label)" | ||
92 | ")"); | ||
93 | const struct GNUNET_PQ_ExecuteStatement *cr; | ||
94 | struct GNUNET_PQ_ExecuteStatement sc = GNUNET_PQ_EXECUTE_STATEMENT_END; | ||
95 | struct GNUNET_PQ_ExecuteStatement es_drop = | ||
96 | GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS ns098records"); | ||
97 | if (GNUNET_YES == | ||
98 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, | ||
99 | "namestore-postgres", | ||
100 | "TEMPORARY_TABLE")) | ||
101 | cr = &es_temporary; | ||
102 | else | ||
103 | cr = &es_default; | ||
104 | 71 | ||
105 | if (GNUNET_YES == | 72 | dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg, |
106 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, | 73 | "namestore-postgres", |
107 | "namestore-postgres", | 74 | "namestore-", |
108 | "ASYNC_COMMIT")) | 75 | NULL, |
109 | sc = GNUNET_PQ_make_try_execute ("SET synchronous_commit TO off"); | 76 | NULL); |
77 | if (NULL == dbh) | ||
78 | return GNUNET_SYSERR; | ||
79 | GNUNET_PQ_disconnect (dbh); | ||
80 | return GNUNET_OK; | ||
81 | } | ||
110 | 82 | ||
83 | |||
84 | /** | ||
85 | * Drop existing namestore tables. | ||
86 | * | ||
87 | * @param cls the plugin context (state for this module) | ||
88 | * @return #GNUNET_OK on success | ||
89 | */ | ||
90 | static enum GNUNET_GenericReturnValue | ||
91 | namestore_postgres_drop_tables (void *cls) | ||
92 | { | ||
93 | struct Plugin *plugin = cls; | ||
94 | struct GNUNET_PQ_Context *dbh; | ||
95 | enum GNUNET_GenericReturnValue ret; | ||
96 | |||
97 | dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg, | ||
98 | "namestore-postgres", | ||
99 | NULL, | ||
100 | NULL, | ||
101 | NULL); | ||
102 | if (NULL == dbh) | ||
111 | { | 103 | { |
112 | struct GNUNET_PQ_ExecuteStatement es[] = { | 104 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
113 | *cr, | 105 | "Failed to connect to database\n"); |
114 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse " | ||
115 | "ON ns098records (zone_private_key,pkey)"), | ||
116 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter " | ||
117 | "ON ns098records (zone_private_key,seq)"), | ||
118 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_label " | ||
119 | "ON ns098records (label)"), | ||
120 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS zone_label " | ||
121 | "ON ns098records (zone_private_key,label)"), | ||
122 | sc, | ||
123 | GNUNET_PQ_EXECUTE_STATEMENT_END | ||
124 | }; | ||
125 | struct GNUNET_PQ_ExecuteStatement es_alt[] = { | ||
126 | es_drop, | ||
127 | *cr, | ||
128 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse " | ||
129 | "ON ns098records (zone_private_key,pkey)"), | ||
130 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter " | ||
131 | "ON ns098records (zone_private_key,seq)"), | ||
132 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_label " | ||
133 | "ON ns098records (label)"), | ||
134 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS zone_label " | ||
135 | "ON ns098records (zone_private_key,label)"), | ||
136 | sc, | ||
137 | GNUNET_PQ_EXECUTE_STATEMENT_END | ||
138 | }; | ||
139 | if (GNUNET_NO == drop) | ||
140 | { | ||
141 | plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg, | ||
142 | "namestore-postgres", | ||
143 | NULL, | ||
144 | es, | ||
145 | NULL); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg, | ||
150 | "namestore-postgres", | ||
151 | NULL, | ||
152 | es_alt, | ||
153 | NULL); | ||
154 | } | ||
155 | } | ||
156 | if (NULL == plugin->dbh) | ||
157 | { | ||
158 | *emsg = GNUNET_strdup ("Failed to connect to PQ database"); | ||
159 | return GNUNET_SYSERR; | 106 | return GNUNET_SYSERR; |
160 | } | 107 | } |
161 | GNUNET_PQ_disconnect (plugin->dbh); | 108 | ret = GNUNET_PQ_exec_sql (dbh, |
162 | plugin->dbh = NULL; | 109 | "namestore-drop"); |
163 | return GNUNET_OK; | 110 | GNUNET_PQ_disconnect (dbh); |
111 | return ret; | ||
164 | } | 112 | } |
165 | 113 | ||
166 | 114 | ||
167 | static int | 115 | static enum GNUNET_GenericReturnValue |
168 | database_prepare (struct Plugin *plugin) | 116 | database_prepare (struct Plugin *plugin) |
169 | { | 117 | { |
170 | enum GNUNET_GenericReturnValue ret; | 118 | enum GNUNET_GenericReturnValue ret; |
171 | if (GNUNET_YES == plugin->ready) | 119 | |
120 | if (plugin->ready) | ||
172 | return GNUNET_OK; | 121 | return GNUNET_OK; |
173 | struct GNUNET_PQ_PreparedStatement ps[] = { | 122 | { |
174 | GNUNET_PQ_make_prepare ("store_records", | 123 | struct GNUNET_PQ_PreparedStatement ps[] = { |
175 | "INSERT INTO ns098records" | 124 | GNUNET_PQ_make_prepare ("store_records", |
176 | " (zone_private_key, pkey, rvalue, record_count, record_data, label)" | 125 | "INSERT INTO namestore.ns098records" |
177 | " VALUES ($1, $2, $3, $4, $5, $6)" | 126 | " (zone_private_key, pkey, rvalue, record_count, record_data, label)" |
178 | " ON CONFLICT ON CONSTRAINT zl" | 127 | " VALUES ($1, $2, $3, $4, $5, $6)" |
179 | " DO UPDATE" | 128 | " ON CONFLICT ON CONSTRAINT zl" |
180 | " SET pkey=$2,rvalue=$3,record_count=$4,record_data=$5" | 129 | " DO UPDATE" |
181 | " WHERE ns098records.zone_private_key = $1" | 130 | " SET pkey=$2,rvalue=$3,record_count=$4,record_data=$5" |
182 | " AND ns098records.label = $6"), | 131 | " WHERE ns098records.zone_private_key = $1" |
183 | GNUNET_PQ_make_prepare ("delete_records", | 132 | " AND ns098records.label = $6"), |
184 | "DELETE FROM ns098records " | 133 | GNUNET_PQ_make_prepare ("delete_records", |
185 | "WHERE zone_private_key=$1 AND label=$2"), | 134 | "DELETE FROM namestore.ns098records " |
186 | GNUNET_PQ_make_prepare ("zone_to_name", | 135 | "WHERE zone_private_key=$1 AND label=$2"), |
187 | "SELECT seq,record_count,record_data,label FROM ns098records" | 136 | GNUNET_PQ_make_prepare ("zone_to_name", |
188 | " WHERE zone_private_key=$1 AND pkey=$2"), | 137 | "SELECT seq,record_count,record_data,label FROM namestore.ns098records" |
189 | GNUNET_PQ_make_prepare ("iterate_zone", | 138 | " WHERE zone_private_key=$1 AND pkey=$2"), |
190 | "SELECT seq,record_count,record_data,label FROM ns098records " | 139 | GNUNET_PQ_make_prepare ("iterate_zone", |
191 | "WHERE zone_private_key=$1 AND seq > $2 ORDER BY seq ASC LIMIT $3"), | 140 | "SELECT seq,record_count,record_data,label FROM namestore.ns098records " |
192 | GNUNET_PQ_make_prepare ("iterate_all_zones", | 141 | "WHERE zone_private_key=$1 AND seq > $2 ORDER BY seq ASC LIMIT $3"), |
193 | "SELECT seq,record_count,record_data,label,zone_private_key" | 142 | GNUNET_PQ_make_prepare ("iterate_all_zones", |
194 | " FROM ns098records WHERE seq > $1 ORDER BY seq ASC LIMIT $2"), | 143 | "SELECT seq,record_count,record_data,label,zone_private_key" |
195 | GNUNET_PQ_make_prepare ("lookup_label", | 144 | " FROM namestore.ns098records WHERE seq > $1 ORDER BY seq ASC LIMIT $2"), |
196 | "SELECT seq,record_count,record_data,label " | 145 | GNUNET_PQ_make_prepare ("lookup_label", |
197 | "FROM ns098records WHERE zone_private_key=$1 AND label=$2"), | 146 | "SELECT seq,record_count,record_data,label " |
198 | GNUNET_PQ_make_prepare ("edit_set", | 147 | "FROM namestore.ns098records WHERE zone_private_key=$1 AND label=$2"), |
199 | "SELECT seq,record_count,record_data,label " | 148 | GNUNET_PQ_make_prepare ("edit_set", |
200 | "FROM ns098records WHERE zone_private_key=$1 AND label=$2 FOR UPDATE NOWAIT"), | 149 | "SELECT seq,record_count,record_data,label " |
201 | GNUNET_PQ_PREPARED_STATEMENT_END | 150 | "FROM namestore.ns098records WHERE zone_private_key=$1 AND label=$2 FOR UPDATE NOWAIT"), |
202 | }; | 151 | GNUNET_PQ_PREPARED_STATEMENT_END |
203 | ret = GNUNET_PQ_prepare_statements (plugin->dbh, ps); | 152 | }; |
153 | |||
154 | ret = GNUNET_PQ_prepare_statements (plugin->dbh, | ||
155 | ps); | ||
156 | } | ||
204 | if (GNUNET_OK != ret) | 157 | if (GNUNET_OK != ret) |
205 | return ret; | 158 | return ret; |
206 | plugin->ready = GNUNET_YES; | 159 | plugin->ready = true; |
207 | return GNUNET_OK; | 160 | return GNUNET_OK; |
208 | } | 161 | } |
209 | 162 | ||
@@ -219,32 +172,37 @@ database_prepare (struct Plugin *plugin) | |||
219 | static enum GNUNET_GenericReturnValue | 172 | static enum GNUNET_GenericReturnValue |
220 | database_connect (struct Plugin *plugin) | 173 | database_connect (struct Plugin *plugin) |
221 | { | 174 | { |
222 | char *emsg; | 175 | struct GNUNET_PQ_ExecuteStatement ess[] = { |
176 | GNUNET_PQ_make_try_execute ("SET synchronous_commit TO off"), | ||
177 | GNUNET_PQ_EXECUTE_STATEMENT_END | ||
178 | }; | ||
179 | struct GNUNET_PQ_ExecuteStatement *es; | ||
180 | |||
181 | if (GNUNET_YES == | ||
182 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, | ||
183 | "namestore-postgres", | ||
184 | "ASYNC_COMMIT")) | ||
185 | es = &ess[0]; | ||
186 | else | ||
187 | es = &ess[1]; | ||
223 | 188 | ||
224 | if (GNUNET_YES == | 189 | if (GNUNET_YES == |
225 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, | 190 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, |
226 | "namestore-postgres", | 191 | "namestore-postgres", |
227 | "INIT_ON_CONNECT")) | 192 | "INIT_ON_CONNECT")) |
228 | { | 193 | { |
229 | /** | ||
230 | * Gracefully fail as this should not be a critical error if the | ||
231 | * database is already created | ||
232 | */ | ||
233 | if (GNUNET_OK != | 194 | if (GNUNET_OK != |
234 | init_database (plugin, | 195 | namestore_postgres_create_tables (plugin)) |
235 | &emsg, | ||
236 | GNUNET_NO)) | ||
237 | { | 196 | { |
238 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 197 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
239 | "Failed to initialize database on connect: `%s'\n", | 198 | "Failed to create tables\n"); |
240 | emsg); | 199 | return GNUNET_SYSERR; |
241 | GNUNET_free (emsg); | ||
242 | } | 200 | } |
243 | } | 201 | } |
244 | plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg, | 202 | plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg, |
245 | "namestore-postgres", | 203 | "namestore-postgres", |
246 | NULL, | 204 | NULL, |
247 | NULL, | 205 | es, |
248 | NULL); | 206 | NULL); |
249 | if (NULL == plugin->dbh) | 207 | if (NULL == plugin->dbh) |
250 | return GNUNET_SYSERR; | 208 | return GNUNET_SYSERR; |
@@ -263,7 +221,7 @@ database_connect (struct Plugin *plugin) | |||
263 | * @param rd array of records with data to store | 221 | * @param rd array of records with data to store |
264 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | 222 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR |
265 | */ | 223 | */ |
266 | static int | 224 | static enum GNUNET_GenericReturnValue |
267 | namestore_postgres_store_records (void *cls, | 225 | namestore_postgres_store_records (void *cls, |
268 | const struct | 226 | const struct |
269 | GNUNET_IDENTITY_PrivateKey *zone_key, | 227 | GNUNET_IDENTITY_PrivateKey *zone_key, |
@@ -495,7 +453,7 @@ parse_result_call_iterator (void *cls, | |||
495 | * @param method the method to use "lookup_record" or "edit_set" | 453 | * @param method the method to use "lookup_record" or "edit_set" |
496 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR | 454 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR |
497 | */ | 455 | */ |
498 | static int | 456 | static enum GNUNET_GenericReturnValue |
499 | lookup_records (void *cls, | 457 | lookup_records (void *cls, |
500 | const struct | 458 | const struct |
501 | GNUNET_IDENTITY_PrivateKey *zone, | 459 | GNUNET_IDENTITY_PrivateKey *zone, |
@@ -545,7 +503,7 @@ lookup_records (void *cls, | |||
545 | * @param iter_cls closure for @a iter | 503 | * @param iter_cls closure for @a iter |
546 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR | 504 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR |
547 | */ | 505 | */ |
548 | static int | 506 | static enum GNUNET_GenericReturnValue |
549 | namestore_postgres_lookup_records (void *cls, | 507 | namestore_postgres_lookup_records (void *cls, |
550 | const struct | 508 | const struct |
551 | GNUNET_IDENTITY_PrivateKey *zone, | 509 | GNUNET_IDENTITY_PrivateKey *zone, |
@@ -591,7 +549,7 @@ namestore_postgres_edit_records (void *cls, | |||
591 | * @param iter_cls closure for @a iter | 549 | * @param iter_cls closure for @a iter |
592 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error | 550 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error |
593 | */ | 551 | */ |
594 | static int | 552 | static enum GNUNET_GenericReturnValue |
595 | namestore_postgres_iterate_records (void *cls, | 553 | namestore_postgres_iterate_records (void *cls, |
596 | const struct | 554 | const struct |
597 | GNUNET_IDENTITY_PrivateKey *zone, | 555 | GNUNET_IDENTITY_PrivateKey *zone, |
@@ -659,7 +617,7 @@ namestore_postgres_iterate_records (void *cls, | |||
659 | * @param iter_cls closure for @a iter | 617 | * @param iter_cls closure for @a iter |
660 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | 618 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error |
661 | */ | 619 | */ |
662 | static int | 620 | static enum GNUNET_GenericReturnValue |
663 | namestore_postgres_zone_to_name (void *cls, | 621 | namestore_postgres_zone_to_name (void *cls, |
664 | const struct | 622 | const struct |
665 | GNUNET_IDENTITY_PrivateKey *zone, | 623 | GNUNET_IDENTITY_PrivateKey *zone, |
@@ -760,30 +718,6 @@ namestore_postgres_transaction_commit (void *cls, | |||
760 | } | 718 | } |
761 | 719 | ||
762 | 720 | ||
763 | static enum GNUNET_GenericReturnValue | ||
764 | namestore_postgres_initialize_database (void *cls, | ||
765 | char **emsg) | ||
766 | { | ||
767 | int ret; | ||
768 | ret = init_database (cls, emsg, GNUNET_NO); | ||
769 | if (GNUNET_SYSERR == ret) | ||
770 | return ret; | ||
771 | return database_connect (cls); | ||
772 | } | ||
773 | |||
774 | |||
775 | static enum GNUNET_GenericReturnValue | ||
776 | namestore_postgres_reset_database (void *cls, | ||
777 | char **emsg) | ||
778 | { | ||
779 | int ret; | ||
780 | ret = init_database (cls, emsg, GNUNET_YES); | ||
781 | if (GNUNET_SYSERR == ret) | ||
782 | return ret; | ||
783 | return database_connect (cls); | ||
784 | } | ||
785 | |||
786 | |||
787 | /** | 721 | /** |
788 | * Shutdown database connection and associate data | 722 | * Shutdown database connection and associate data |
789 | * structures. | 723 | * structures. |
@@ -821,6 +755,8 @@ libgnunet_plugin_namestore_postgres_init (void *cls) | |||
821 | } | 755 | } |
822 | api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions); | 756 | api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions); |
823 | api->cls = plugin; | 757 | api->cls = plugin; |
758 | api->create_tables = &namestore_postgres_create_tables; | ||
759 | api->drop_tables = &namestore_postgres_drop_tables; | ||
824 | api->store_records = &namestore_postgres_store_records; | 760 | api->store_records = &namestore_postgres_store_records; |
825 | api->iterate_records = &namestore_postgres_iterate_records; | 761 | api->iterate_records = &namestore_postgres_iterate_records; |
826 | api->zone_to_name = &namestore_postgres_zone_to_name; | 762 | api->zone_to_name = &namestore_postgres_zone_to_name; |
@@ -828,8 +764,6 @@ libgnunet_plugin_namestore_postgres_init (void *cls) | |||
828 | api->transaction_begin = &namestore_postgres_transaction_begin; | 764 | api->transaction_begin = &namestore_postgres_transaction_begin; |
829 | api->transaction_commit = &namestore_postgres_transaction_commit; | 765 | api->transaction_commit = &namestore_postgres_transaction_commit; |
830 | api->transaction_rollback = &namestore_postgres_transaction_rollback; | 766 | api->transaction_rollback = &namestore_postgres_transaction_rollback; |
831 | api->initialize_database = &namestore_postgres_initialize_database; | ||
832 | api->reset_database = &namestore_postgres_reset_database; | ||
833 | api->edit_records = &namestore_postgres_edit_records; | 767 | api->edit_records = &namestore_postgres_edit_records; |
834 | LOG (GNUNET_ERROR_TYPE_INFO, | 768 | LOG (GNUNET_ERROR_TYPE_INFO, |
835 | "Postgres namestore plugin running\n"); | 769 | "Postgres namestore plugin running\n"); |
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index 1602da4ab..15a6586b5 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c | |||
@@ -50,13 +50,14 @@ | |||
50 | * a failure of the command 'cmd' on file 'filename' | 50 | * a failure of the command 'cmd' on file 'filename' |
51 | * with the message given by strerror(errno). | 51 | * with the message given by strerror(errno). |
52 | */ | 52 | */ |
53 | #define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, \ | 53 | #define LOG_SQLITE(db, level, cmd) do { \ |
54 | "namestore-sqlite", _ ( \ | 54 | GNUNET_log_from (level, \ |
55 | "`%s' failed at %s:%d with error: %s\n"), \ | 55 | "namestore-sqlite", _ ( \ |
56 | cmd, \ | 56 | "`%s' failed at %s:%d with error: %s\n"), \ |
57 | __FILE__, __LINE__, \ | 57 | cmd, \ |
58 | sqlite3_errmsg ( \ | 58 | __FILE__, __LINE__, \ |
59 | db->dbh)); \ | 59 | sqlite3_errmsg ( \ |
60 | db->dbh)); \ | ||
60 | } while (0) | 61 | } while (0) |
61 | 62 | ||
62 | #define LOG(kind, ...) GNUNET_log_from (kind, "namestore-sqlite", __VA_ARGS__) | 63 | #define LOG(kind, ...) GNUNET_log_from (kind, "namestore-sqlite", __VA_ARGS__) |
@@ -75,9 +76,9 @@ struct Plugin | |||
75 | char *fn; | 76 | char *fn; |
76 | 77 | ||
77 | /** | 78 | /** |
78 | * Statements prepared, we are ready to go if GNUNET_YES | 79 | * Statements prepared, we are ready to go if true. |
79 | */ | 80 | */ |
80 | int ready; | 81 | bool ready; |
81 | 82 | ||
82 | /** | 83 | /** |
83 | * Native SQLite database handle. | 84 | * Native SQLite database handle. |
@@ -124,10 +125,10 @@ struct Plugin | |||
124 | * @param plugin the plugin context (state for this module) | 125 | * @param plugin the plugin context (state for this module) |
125 | * @return #GNUNET_OK on success | 126 | * @return #GNUNET_OK on success |
126 | */ | 127 | */ |
127 | static int | 128 | static enum GNUNET_GenericReturnValue |
128 | database_prepare (struct Plugin *plugin) | 129 | database_prepare (struct Plugin *plugin) |
129 | { | 130 | { |
130 | if (GNUNET_YES == plugin->ready) | 131 | if (plugin->ready) |
131 | return GNUNET_OK; | 132 | return GNUNET_OK; |
132 | struct GNUNET_SQ_ExecuteStatement es[] = { | 133 | struct GNUNET_SQ_ExecuteStatement es[] = { |
133 | GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"), | 134 | GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"), |
@@ -264,7 +265,7 @@ database_shutdown (struct Plugin *plugin) | |||
264 | * @param rd array of records with data to store | 265 | * @param rd array of records with data to store |
265 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | 266 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR |
266 | */ | 267 | */ |
267 | static int | 268 | static enum GNUNET_GenericReturnValue |
268 | namestore_sqlite_store_records (void *cls, | 269 | namestore_sqlite_store_records (void *cls, |
269 | const struct | 270 | const struct |
270 | GNUNET_IDENTITY_PrivateKey *zone_key, | 271 | GNUNET_IDENTITY_PrivateKey *zone_key, |
@@ -421,7 +422,7 @@ namestore_sqlite_store_records (void *cls, | |||
421 | * @param iter_cls closure for @a iter | 422 | * @param iter_cls closure for @a iter |
422 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | 423 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error |
423 | */ | 424 | */ |
424 | static int | 425 | static enum GNUNET_GenericReturnValue |
425 | get_records_and_call_iterator (struct Plugin *plugin, | 426 | get_records_and_call_iterator (struct Plugin *plugin, |
426 | sqlite3_stmt *stmt, | 427 | sqlite3_stmt *stmt, |
427 | const struct | 428 | const struct |
@@ -539,7 +540,7 @@ get_records_and_call_iterator (struct Plugin *plugin, | |||
539 | * @param iter_cls closure for @a iter | 540 | * @param iter_cls closure for @a iter |
540 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR | 541 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR |
541 | */ | 542 | */ |
542 | static int | 543 | static enum GNUNET_GenericReturnValue |
543 | namestore_sqlite_lookup_records (void *cls, | 544 | namestore_sqlite_lookup_records (void *cls, |
544 | const struct | 545 | const struct |
545 | GNUNET_IDENTITY_PrivateKey *zone, | 546 | GNUNET_IDENTITY_PrivateKey *zone, |
@@ -591,7 +592,7 @@ namestore_sqlite_lookup_records (void *cls, | |||
591 | * @param iter_cls closure for @a iter | 592 | * @param iter_cls closure for @a iter |
592 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error | 593 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error |
593 | */ | 594 | */ |
594 | static int | 595 | static enum GNUNET_GenericReturnValue |
595 | namestore_sqlite_iterate_records (void *cls, | 596 | namestore_sqlite_iterate_records (void *cls, |
596 | const struct | 597 | const struct |
597 | GNUNET_IDENTITY_PrivateKey *zone, | 598 | GNUNET_IDENTITY_PrivateKey *zone, |
@@ -659,7 +660,7 @@ namestore_sqlite_iterate_records (void *cls, | |||
659 | * @param iter_cls closure for @a iter | 660 | * @param iter_cls closure for @a iter |
660 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | 661 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error |
661 | */ | 662 | */ |
662 | static int | 663 | static enum GNUNET_GenericReturnValue |
663 | namestore_sqlite_zone_to_name (void *cls, | 664 | namestore_sqlite_zone_to_name (void *cls, |
664 | const struct GNUNET_IDENTITY_PrivateKey *zone, | 665 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
665 | const struct | 666 | const struct |
@@ -697,6 +698,7 @@ namestore_sqlite_zone_to_name (void *cls, | |||
697 | iter_cls); | 698 | iter_cls); |
698 | } | 699 | } |
699 | 700 | ||
701 | |||
700 | /** | 702 | /** |
701 | * Begin a transaction for a client. | 703 | * Begin a transaction for a client. |
702 | * This locks the database. SQLite is unable to discern between different | 704 | * This locks the database. SQLite is unable to discern between different |
@@ -726,6 +728,7 @@ namestore_sqlite_transaction_begin (void *cls, | |||
726 | return (SQLITE_OK != rc) ? GNUNET_SYSERR : GNUNET_YES; | 728 | return (SQLITE_OK != rc) ? GNUNET_SYSERR : GNUNET_YES; |
727 | } | 729 | } |
728 | 730 | ||
731 | |||
729 | /** | 732 | /** |
730 | * Commit a transaction for a client. | 733 | * Commit a transaction for a client. |
731 | * This releases the lock on the database. | 734 | * This releases the lock on the database. |
@@ -753,6 +756,7 @@ namestore_sqlite_transaction_rollback (void *cls, | |||
753 | return (SQLITE_OK != rc) ? GNUNET_SYSERR : GNUNET_YES; | 756 | return (SQLITE_OK != rc) ? GNUNET_SYSERR : GNUNET_YES; |
754 | } | 757 | } |
755 | 758 | ||
759 | |||
756 | /** | 760 | /** |
757 | * Roll back a transaction for a client. | 761 | * Roll back a transaction for a client. |
758 | * This releases the lock on the database. | 762 | * This releases the lock on the database. |
@@ -780,14 +784,11 @@ namestore_sqlite_transaction_commit (void *cls, | |||
780 | return (SQLITE_OK != rc) ? GNUNET_SYSERR : GNUNET_YES; | 784 | return (SQLITE_OK != rc) ? GNUNET_SYSERR : GNUNET_YES; |
781 | } | 785 | } |
782 | 786 | ||
787 | |||
783 | static enum GNUNET_GenericReturnValue | 788 | static enum GNUNET_GenericReturnValue |
784 | init_database (void *cls, char **emsg, int drop) | 789 | namestore_sqlite_create_tables (void *cls) |
785 | { | 790 | { |
786 | struct Plugin *plugin = cls; | 791 | struct Plugin *plugin = cls; |
787 | struct GNUNET_SQ_ExecuteStatement es_drop[] = { | ||
788 | GNUNET_SQ_make_execute ("DROP TABLE IF EXISTS ns098records"), | ||
789 | GNUNET_SQ_EXECUTE_STATEMENT_END | ||
790 | }; | ||
791 | struct GNUNET_SQ_ExecuteStatement es[] = { | 792 | struct GNUNET_SQ_ExecuteStatement es[] = { |
792 | GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"), | 793 | GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"), |
793 | GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"), | 794 | GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"), |
@@ -797,7 +798,7 @@ init_database (void *cls, char **emsg, int drop) | |||
797 | GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=NORMAL"), | 798 | GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=NORMAL"), |
798 | GNUNET_SQ_make_try_execute ("PRAGMA journal_mode=WAL"), | 799 | GNUNET_SQ_make_try_execute ("PRAGMA journal_mode=WAL"), |
799 | GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"), | 800 | GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"), |
800 | GNUNET_SQ_make_execute ("CREATE TABLE ns098records (" | 801 | GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records (" |
801 | " uid INTEGER PRIMARY KEY," | 802 | " uid INTEGER PRIMARY KEY," |
802 | " zone_private_key BLOB NOT NULL," | 803 | " zone_private_key BLOB NOT NULL," |
803 | " pkey BLOB," | 804 | " pkey BLOB," |
@@ -812,39 +813,42 @@ init_database (void *cls, char **emsg, int drop) | |||
812 | "ON ns098records (zone_private_key,uid)"), | 813 | "ON ns098records (zone_private_key,uid)"), |
813 | GNUNET_SQ_EXECUTE_STATEMENT_END | 814 | GNUNET_SQ_EXECUTE_STATEMENT_END |
814 | }; | 815 | }; |
815 | if ((GNUNET_YES == drop) && | 816 | |
816 | (GNUNET_OK != GNUNET_SQ_exec_statements (plugin->dbh, | ||
817 | es_drop))) | ||
818 | { | ||
819 | GNUNET_asprintf (emsg, | ||
820 | _ ("Failed to drop database with: `%s'\n"), | ||
821 | sqlite3_errmsg (plugin->dbh)); | ||
822 | return GNUNET_SYSERR; | ||
823 | } | ||
824 | if (GNUNET_OK != | 817 | if (GNUNET_OK != |
825 | GNUNET_SQ_exec_statements (plugin->dbh, | 818 | GNUNET_SQ_exec_statements (plugin->dbh, |
826 | es)) | 819 | es)) |
827 | { | 820 | { |
828 | GNUNET_asprintf (emsg, | 821 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
829 | _ ("Failed to setup database with: `%s'\n"), | 822 | "Failed to setup database with: `%s'\n", |
830 | sqlite3_errmsg (plugin->dbh)); | 823 | sqlite3_errmsg (plugin->dbh)); |
831 | return GNUNET_SYSERR; | 824 | return GNUNET_SYSERR; |
832 | } | 825 | } |
833 | return GNUNET_OK; | 826 | return GNUNET_OK; |
834 | } | 827 | } |
835 | 828 | ||
836 | enum GNUNET_GenericReturnValue | ||
837 | namestore_sqlite_initialize_database (void *cls, char **emsg) | ||
838 | { | ||
839 | return init_database (cls, emsg, GNUNET_NO); | ||
840 | } | ||
841 | 829 | ||
842 | enum GNUNET_GenericReturnValue | 830 | static enum GNUNET_GenericReturnValue |
843 | namestore_sqlite_reset_database (void *cls, char **emsg) | 831 | namestore_sqlite_drop_tables (void *cls) |
844 | { | 832 | { |
845 | return init_database (cls, emsg, GNUNET_YES); | 833 | struct Plugin *plugin = cls; |
834 | struct GNUNET_SQ_ExecuteStatement es_drop[] = { | ||
835 | GNUNET_SQ_make_execute ("DROP TABLE IF EXISTS ns098records"), | ||
836 | GNUNET_SQ_EXECUTE_STATEMENT_END | ||
837 | }; | ||
838 | |||
839 | if (GNUNET_OK != | ||
840 | GNUNET_SQ_exec_statements (plugin->dbh, | ||
841 | es_drop)) | ||
842 | { | ||
843 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
844 | "Failed to drop database with: `%s'\n", | ||
845 | sqlite3_errmsg (plugin->dbh)); | ||
846 | return GNUNET_SYSERR; | ||
847 | } | ||
848 | return GNUNET_OK; | ||
846 | } | 849 | } |
847 | 850 | ||
851 | |||
848 | /** | 852 | /** |
849 | * Initialize the database connections and associated | 853 | * Initialize the database connections and associated |
850 | * data structures (create tables and indices | 854 | * data structures (create tables and indices |
@@ -853,11 +857,10 @@ namestore_sqlite_reset_database (void *cls, char **emsg) | |||
853 | * @param plugin the plugin context (state for this module) | 857 | * @param plugin the plugin context (state for this module) |
854 | * @return #GNUNET_OK on success | 858 | * @return #GNUNET_OK on success |
855 | */ | 859 | */ |
856 | static int | 860 | static enum GNUNET_GenericReturnValue |
857 | database_connect (struct Plugin *plugin) | 861 | database_connect (struct Plugin *plugin) |
858 | { | 862 | { |
859 | char *sqlite_filename; | 863 | char *sqlite_filename; |
860 | char *emsg; | ||
861 | 864 | ||
862 | if (GNUNET_OK != | 865 | if (GNUNET_OK != |
863 | GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, | 866 | GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, |
@@ -902,17 +905,9 @@ database_connect (struct Plugin *plugin) | |||
902 | "namestore-sqlite", | 905 | "namestore-sqlite", |
903 | "INIT_ON_CONNECT")) | 906 | "INIT_ON_CONNECT")) |
904 | { | 907 | { |
905 | /** | 908 | if (GNUNET_OK != |
906 | * Gracefully fail as this should not be a critical error if the | 909 | namestore_sqlite_create_tables (plugin)) |
907 | * database is already created | 910 | return GNUNET_SYSERR; |
908 | */ | ||
909 | if (GNUNET_OK != init_database (plugin, &emsg, GNUNET_NO)) | ||
910 | { | ||
911 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
912 | "Failed to initialize database on connect: `%s'\n", | ||
913 | emsg); | ||
914 | GNUNET_free (emsg); | ||
915 | } | ||
916 | } | 911 | } |
917 | return GNUNET_OK; | 912 | return GNUNET_OK; |
918 | } | 913 | } |
@@ -949,8 +944,8 @@ libgnunet_plugin_namestore_sqlite_init (void *cls) | |||
949 | api->transaction_begin = &namestore_sqlite_transaction_begin; | 944 | api->transaction_begin = &namestore_sqlite_transaction_begin; |
950 | api->transaction_commit = &namestore_sqlite_transaction_commit; | 945 | api->transaction_commit = &namestore_sqlite_transaction_commit; |
951 | api->transaction_rollback = &namestore_sqlite_transaction_rollback; | 946 | api->transaction_rollback = &namestore_sqlite_transaction_rollback; |
952 | api->initialize_database = &namestore_sqlite_initialize_database; | 947 | api->create_tables = &namestore_sqlite_create_tables; |
953 | api->reset_database = &namestore_sqlite_reset_database; | 948 | api->drop_tables = &namestore_sqlite_drop_tables; |
954 | /** | 949 | /** |
955 | * NOTE: Since SQlite does not support SELECT ... FOR UPDATE this is | 950 | * NOTE: Since SQlite does not support SELECT ... FOR UPDATE this is |
956 | * just an alias to lookup_records. The BEGIN IMMEDIATE mechanic currently | 951 | * just an alias to lookup_records. The BEGIN IMMEDIATE mechanic currently |
diff --git a/src/namestore/test_common.c b/src/namestore/test_common.c index fbcb51399..4f3a3562b 100644 --- a/src/namestore/test_common.c +++ b/src/namestore/test_common.c | |||
@@ -31,35 +31,52 @@ TNC_test_plugin (const char *cfg_name) | |||
31 | { | 31 | { |
32 | char *database; | 32 | char *database; |
33 | char *db_lib_name; | 33 | char *db_lib_name; |
34 | char *emsg; | ||
35 | struct GNUNET_NAMESTORE_PluginFunctions *db; | 34 | struct GNUNET_NAMESTORE_PluginFunctions *db; |
36 | struct GNUNET_CONFIGURATION_Handle *cfg; | 35 | struct GNUNET_CONFIGURATION_Handle *cfg; |
37 | 36 | ||
38 | cfg = GNUNET_CONFIGURATION_create (); | 37 | cfg = GNUNET_CONFIGURATION_create (); |
39 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_name)) | 38 | if (GNUNET_OK != |
39 | GNUNET_CONFIGURATION_load (cfg, | ||
40 | cfg_name)) | ||
40 | { | 41 | { |
41 | GNUNET_break (0); | 42 | GNUNET_break (0); |
42 | GNUNET_CONFIGURATION_destroy (cfg); | 43 | GNUNET_CONFIGURATION_destroy (cfg); |
43 | return GNUNET_SYSERR; | 44 | return GNUNET_SYSERR; |
44 | } | 45 | } |
45 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | 46 | if (GNUNET_OK != |
46 | "namestore", | 47 | GNUNET_CONFIGURATION_get_value_string (cfg, |
47 | "database", | 48 | "namestore", |
48 | &database)) | 49 | "database", |
50 | &database)) | ||
49 | { | 51 | { |
50 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n"); | 52 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
53 | "No database backend configured\n"); | ||
51 | GNUNET_CONFIGURATION_destroy (cfg); | 54 | GNUNET_CONFIGURATION_destroy (cfg); |
52 | return GNUNET_SYSERR; | 55 | return GNUNET_SYSERR; |
53 | } | 56 | } |
54 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database); | 57 | GNUNET_asprintf (&db_lib_name, |
58 | "libgnunet_plugin_namestore_%s", | ||
59 | database); | ||
55 | GNUNET_free (database); | 60 | GNUNET_free (database); |
56 | db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); | 61 | db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); |
57 | if (NULL != db) | 62 | if (NULL == db) |
63 | { | ||
64 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
65 | "Failed to load plugin `%s'\n", | ||
66 | db_lib_name); | ||
67 | } | ||
68 | else | ||
58 | { | 69 | { |
59 | if (GNUNET_OK != db->reset_database (db->cls, &emsg)) | 70 | if (GNUNET_OK != db->create_tables (db->cls)) |
60 | { | 71 | { |
61 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error resetting database: %s\n", emsg); | 72 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
62 | GNUNET_free (emsg); | 73 | "Error creating tables\n"); |
74 | return GNUNET_SYSERR; | ||
75 | } | ||
76 | if (GNUNET_OK != db->drop_tables (db->cls)) | ||
77 | { | ||
78 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
79 | "Error dropping tables\n"); | ||
63 | return GNUNET_SYSERR; | 80 | return GNUNET_SYSERR; |
64 | } | 81 | } |
65 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); | 82 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); |
@@ -71,13 +88,15 @@ TNC_test_plugin (const char *cfg_name) | |||
71 | return GNUNET_YES; | 88 | return GNUNET_YES; |
72 | } | 89 | } |
73 | 90 | ||
91 | |||
74 | /** | 92 | /** |
75 | * General setup logic for starting the tests. Obtains the @a | 93 | * General setup logic for starting the tests. Obtains the @a |
76 | * plugin_name and initializes the @a cfg_name. | 94 | * plugin_name and initializes the @a cfg_name. |
77 | */ | 95 | */ |
78 | #define SETUP_CFG2(file_template, plugin_name, cfg_name) \ | 96 | #define SETUP_CFG2(file_template, plugin_name, cfg_name) \ |
79 | do \ | 97 | do \ |
80 | { \ | 98 | { \ |
99 | GNUNET_log_setup (__FILE__, "WARNING", NULL); \ | ||
81 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); \ | 100 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); \ |
82 | GNUNET_asprintf (&cfg_name, file_template, plugin_name); \ | 101 | GNUNET_asprintf (&cfg_name, file_template, plugin_name); \ |
83 | if (! TNC_test_plugin (cfg_name)) \ | 102 | if (! TNC_test_plugin (cfg_name)) \ |
@@ -94,6 +113,7 @@ TNC_test_plugin (const char *cfg_name) | |||
94 | #define SETUP_CFG(plugin_name, cfg_name) \ | 113 | #define SETUP_CFG(plugin_name, cfg_name) \ |
95 | do \ | 114 | do \ |
96 | { \ | 115 | { \ |
116 | GNUNET_log_setup (__FILE__, "WARNING", NULL); \ | ||
97 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); \ | 117 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); \ |
98 | GNUNET_asprintf (&cfg_name, "test_namestore_api_%s.conf", plugin_name); \ | 118 | GNUNET_asprintf (&cfg_name, "test_namestore_api_%s.conf", plugin_name); \ |
99 | if (! TNC_test_plugin (cfg_name)) \ | 119 | if (! TNC_test_plugin (cfg_name)) \ |
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c index e35542ff0..24af148bf 100644 --- a/src/namestore/test_plugin_namestore.c +++ b/src/namestore/test_plugin_namestore.c | |||
@@ -66,23 +66,30 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
66 | { | 66 | { |
67 | struct GNUNET_NAMESTORE_PluginFunctions *ret; | 67 | struct GNUNET_NAMESTORE_PluginFunctions *ret; |
68 | char *libname; | 68 | char *libname; |
69 | char *emsg; | ||
70 | 69 | ||
71 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 70 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
72 | _ ("Loading `%s' namestore plugin\n"), | 71 | "Loading `%s' namestore plugin\n", |
73 | plugin_name); | 72 | plugin_name); |
74 | GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); | 73 | GNUNET_asprintf (&libname, |
74 | "libgnunet_plugin_namestore_%s", | ||
75 | plugin_name); | ||
75 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void *) cfg))) | 76 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void *) cfg))) |
76 | { | 77 | { |
77 | fprintf (stderr, "Failed to load plugin `%s'!\n", plugin_name); | 78 | fprintf (stderr, |
79 | "Failed to load plugin `%s'!\n", | ||
80 | plugin_name); | ||
78 | GNUNET_free (libname); | 81 | GNUNET_free (libname); |
79 | return NULL; | 82 | return NULL; |
80 | } | 83 | } |
81 | GNUNET_free (libname); | 84 | GNUNET_free (libname); |
82 | if (GNUNET_OK != ret->reset_database (ret->cls, &emsg)) | 85 | if (GNUNET_OK != ret->drop_tables (ret->cls)) |
86 | { | ||
87 | GNUNET_break (0); | ||
88 | return NULL; | ||
89 | } | ||
90 | if (GNUNET_OK != ret->create_tables (ret->cls)) | ||
83 | { | 91 | { |
84 | fprintf (stderr, "Error resetting database: %s\n", emsg); | 92 | GNUNET_break (0); |
85 | GNUNET_free (emsg); | ||
86 | return NULL; | 93 | return NULL; |
87 | } | 94 | } |
88 | return ret; | 95 | return ret; |