diff options
Diffstat (limited to 'src/peerstore')
-rw-r--r-- | src/peerstore/gnunet-peerstore.c | 39 | ||||
-rw-r--r-- | src/peerstore/gnunet-service-peerstore.c | 446 | ||||
-rw-r--r-- | src/peerstore/peerstore.h | 12 | ||||
-rw-r--r-- | src/peerstore/peerstore_api.c | 541 | ||||
-rw-r--r-- | src/peerstore/peerstore_common.c | 154 | ||||
-rw-r--r-- | src/peerstore/peerstore_common.h | 30 | ||||
-rw-r--r-- | src/peerstore/perf_peerstore_store.c | 68 | ||||
-rw-r--r-- | src/peerstore/plugin_peerstore_flat.c | 520 | ||||
-rw-r--r-- | src/peerstore/plugin_peerstore_sqlite.c | 699 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_iterate.c | 194 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_store.c | 208 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_sync.c | 96 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_watch.c | 84 | ||||
-rw-r--r-- | src/peerstore/test_plugin_peerstore.c | 205 |
14 files changed, 1641 insertions, 1655 deletions
diff --git a/src/peerstore/gnunet-peerstore.c b/src/peerstore/gnunet-peerstore.c index 9d95655b4..891676ebd 100644 --- a/src/peerstore/gnunet-peerstore.c +++ b/src/peerstore/gnunet-peerstore.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file peerstore/gnunet-peerstore.c | 22 | * @file peerstore/gnunet-peerstore.c |
@@ -41,13 +41,13 @@ static struct GNUNET_PEERSTORE_Handle *peerstore_handle; | |||
41 | * @param cls unused | 41 | * @param cls unused |
42 | */ | 42 | */ |
43 | static void | 43 | static void |
44 | shutdown_task (void *cls) | 44 | shutdown_task(void *cls) |
45 | { | 45 | { |
46 | if (NULL != peerstore_handle) | 46 | if (NULL != peerstore_handle) |
47 | { | 47 | { |
48 | GNUNET_PEERSTORE_disconnect (peerstore_handle, GNUNET_YES); | 48 | GNUNET_PEERSTORE_disconnect(peerstore_handle, GNUNET_YES); |
49 | peerstore_handle = NULL; | 49 | peerstore_handle = NULL; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | 53 | ||
@@ -60,15 +60,15 @@ shutdown_task (void *cls) | |||
60 | * @param cfg configuration | 60 | * @param cfg configuration |
61 | */ | 61 | */ |
62 | static void | 62 | static void |
63 | run (void *cls, | 63 | run(void *cls, |
64 | char *const *args, | 64 | char *const *args, |
65 | const char *cfgfile, | 65 | const char *cfgfile, |
66 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 66 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
67 | { | 67 | { |
68 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 68 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, |
69 | NULL); | 69 | NULL); |
70 | peerstore_handle = GNUNET_PEERSTORE_connect (cfg); | 70 | peerstore_handle = GNUNET_PEERSTORE_connect(cfg); |
71 | GNUNET_assert (NULL != peerstore_handle); | 71 | GNUNET_assert(NULL != peerstore_handle); |
72 | ret = 0; | 72 | ret = 0; |
73 | } | 73 | } |
74 | 74 | ||
@@ -81,15 +81,16 @@ run (void *cls, | |||
81 | * @return 0 ok, 1 on error | 81 | * @return 0 ok, 1 on error |
82 | */ | 82 | */ |
83 | int | 83 | int |
84 | main (int argc, char *const *argv) | 84 | main(int argc, char *const *argv) |
85 | { | 85 | { |
86 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 86 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
87 | GNUNET_GETOPT_OPTION_END | 87 | GNUNET_GETOPT_OPTION_END |
88 | }; | 88 | }; |
89 | |||
89 | return (GNUNET_OK == | 90 | return (GNUNET_OK == |
90 | GNUNET_PROGRAM_run (argc, argv, "gnunet-peerstore [options [value]]", | 91 | GNUNET_PROGRAM_run(argc, argv, "gnunet-peerstore [options [value]]", |
91 | gettext_noop ("peerstore"), options, &run, | 92 | gettext_noop("peerstore"), options, &run, |
92 | NULL)) ? ret : 1; | 93 | NULL)) ? ret : 1; |
93 | } | 94 | } |
94 | 95 | ||
95 | /* end of gnunet-peerstore.c */ | 96 | /* end of gnunet-peerstore.c */ |
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index ed1c35535..02ac03e01 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file peerstore/gnunet-service-peerstore.c | 22 | * @file peerstore/gnunet-service-peerstore.c |
@@ -75,25 +75,25 @@ static unsigned int num_clients; | |||
75 | * Perform the actual shutdown operations | 75 | * Perform the actual shutdown operations |
76 | */ | 76 | */ |
77 | static void | 77 | static void |
78 | do_shutdown () | 78 | do_shutdown() |
79 | { | 79 | { |
80 | if (NULL != db_lib_name) | 80 | if (NULL != db_lib_name) |
81 | { | 81 | { |
82 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); | 82 | GNUNET_break(NULL == GNUNET_PLUGIN_unload(db_lib_name, db)); |
83 | GNUNET_free (db_lib_name); | 83 | GNUNET_free(db_lib_name); |
84 | db_lib_name = NULL; | 84 | db_lib_name = NULL; |
85 | } | 85 | } |
86 | if (NULL != watchers) | 86 | if (NULL != watchers) |
87 | { | 87 | { |
88 | GNUNET_CONTAINER_multihashmap_destroy (watchers); | 88 | GNUNET_CONTAINER_multihashmap_destroy(watchers); |
89 | watchers = NULL; | 89 | watchers = NULL; |
90 | } | 90 | } |
91 | if (NULL != expire_task) | 91 | if (NULL != expire_task) |
92 | { | 92 | { |
93 | GNUNET_SCHEDULER_cancel (expire_task); | 93 | GNUNET_SCHEDULER_cancel(expire_task); |
94 | expire_task = NULL; | 94 | expire_task = NULL; |
95 | } | 95 | } |
96 | GNUNET_SCHEDULER_shutdown (); | 96 | GNUNET_SCHEDULER_shutdown(); |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
@@ -103,42 +103,42 @@ do_shutdown () | |||
103 | * @param cls unused | 103 | * @param cls unused |
104 | */ | 104 | */ |
105 | static void | 105 | static void |
106 | shutdown_task (void *cls) | 106 | shutdown_task(void *cls) |
107 | { | 107 | { |
108 | in_shutdown = GNUNET_YES; | 108 | in_shutdown = GNUNET_YES; |
109 | if (0 == num_clients) /* Only when no connected clients. */ | 109 | if (0 == num_clients) /* Only when no connected clients. */ |
110 | do_shutdown (); | 110 | do_shutdown(); |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | /* Forward declaration */ | 114 | /* Forward declaration */ |
115 | static void | 115 | static void |
116 | expire_records_continuation (void *cls, int success); | 116 | expire_records_continuation(void *cls, int success); |
117 | 117 | ||
118 | 118 | ||
119 | /** | 119 | /** |
120 | * Deletes any expired records from storage | 120 | * Deletes any expired records from storage |
121 | */ | 121 | */ |
122 | static void | 122 | static void |
123 | cleanup_expired_records (void *cls) | 123 | cleanup_expired_records(void *cls) |
124 | { | 124 | { |
125 | int ret; | 125 | int ret; |
126 | 126 | ||
127 | expire_task = NULL; | 127 | expire_task = NULL; |
128 | GNUNET_assert (NULL != db); | 128 | GNUNET_assert(NULL != db); |
129 | ret = db->expire_records (db->cls, | 129 | ret = db->expire_records(db->cls, |
130 | GNUNET_TIME_absolute_get (), | 130 | GNUNET_TIME_absolute_get(), |
131 | &expire_records_continuation, | 131 | &expire_records_continuation, |
132 | NULL); | 132 | NULL); |
133 | if (GNUNET_OK != ret) | 133 | if (GNUNET_OK != ret) |
134 | { | 134 | { |
135 | GNUNET_assert (NULL == expire_task); | 135 | GNUNET_assert(NULL == expire_task); |
136 | expire_task = GNUNET_SCHEDULER_add_delayed ( | 136 | expire_task = GNUNET_SCHEDULER_add_delayed( |
137 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 137 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
138 | EXPIRED_RECORDS_CLEANUP_INTERVAL), | 138 | EXPIRED_RECORDS_CLEANUP_INTERVAL), |
139 | &cleanup_expired_records, | 139 | &cleanup_expired_records, |
140 | NULL); | 140 | NULL); |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
@@ -149,14 +149,14 @@ cleanup_expired_records (void *cls) | |||
149 | * @param success count of records deleted or #GNUNET_SYSERR | 149 | * @param success count of records deleted or #GNUNET_SYSERR |
150 | */ | 150 | */ |
151 | static void | 151 | static void |
152 | expire_records_continuation (void *cls, int success) | 152 | expire_records_continuation(void *cls, int success) |
153 | { | 153 | { |
154 | if (success > 0) | 154 | if (success > 0) |
155 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success); | 155 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success); |
156 | GNUNET_assert (NULL == expire_task); | 156 | GNUNET_assert(NULL == expire_task); |
157 | expire_task = GNUNET_SCHEDULER_add_delayed ( | 157 | expire_task = GNUNET_SCHEDULER_add_delayed( |
158 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 158 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
159 | EXPIRED_RECORDS_CLEANUP_INTERVAL), | 159 | EXPIRED_RECORDS_CLEANUP_INTERVAL), |
160 | &cleanup_expired_records, | 160 | &cleanup_expired_records, |
161 | NULL); | 161 | NULL); |
162 | } | 162 | } |
@@ -171,9 +171,9 @@ expire_records_continuation (void *cls, int success) | |||
171 | * @return | 171 | * @return |
172 | */ | 172 | */ |
173 | static void * | 173 | static void * |
174 | client_connect_cb (void *cls, | 174 | client_connect_cb(void *cls, |
175 | struct GNUNET_SERVICE_Client *client, | 175 | struct GNUNET_SERVICE_Client *client, |
176 | struct GNUNET_MQ_Handle *mq) | 176 | struct GNUNET_MQ_Handle *mq) |
177 | { | 177 | { |
178 | num_clients++; | 178 | num_clients++; |
179 | return client; | 179 | return client; |
@@ -189,14 +189,14 @@ client_connect_cb (void *cls, | |||
189 | * @return #GNUNET_OK to continue iterating | 189 | * @return #GNUNET_OK to continue iterating |
190 | */ | 190 | */ |
191 | static int | 191 | static int |
192 | client_disconnect_it (void *cls, const struct GNUNET_HashCode *key, void *value) | 192 | client_disconnect_it(void *cls, const struct GNUNET_HashCode *key, void *value) |
193 | { | 193 | { |
194 | if (value == cls) | 194 | if (value == cls) |
195 | { | 195 | { |
196 | GNUNET_assert (GNUNET_YES == | 196 | GNUNET_assert(GNUNET_YES == |
197 | GNUNET_CONTAINER_multihashmap_remove (watchers, key, value)); | 197 | GNUNET_CONTAINER_multihashmap_remove(watchers, key, value)); |
198 | num_clients++; | 198 | num_clients++; |
199 | } | 199 | } |
200 | return GNUNET_OK; | 200 | return GNUNET_OK; |
201 | } | 201 | } |
202 | 202 | ||
@@ -208,18 +208,18 @@ client_disconnect_it (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
208 | * @param client identification of the client | 208 | * @param client identification of the client |
209 | */ | 209 | */ |
210 | static void | 210 | static void |
211 | client_disconnect_cb (void *cls, | 211 | client_disconnect_cb(void *cls, |
212 | struct GNUNET_SERVICE_Client *client, | 212 | struct GNUNET_SERVICE_Client *client, |
213 | void *app_cls) | 213 | void *app_cls) |
214 | { | 214 | { |
215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning up.\n"); | 215 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning up.\n"); |
216 | if (NULL != watchers) | 216 | if (NULL != watchers) |
217 | GNUNET_CONTAINER_multihashmap_iterate (watchers, | 217 | GNUNET_CONTAINER_multihashmap_iterate(watchers, |
218 | &client_disconnect_it, | 218 | &client_disconnect_it, |
219 | client); | 219 | client); |
220 | num_clients--; | 220 | num_clients--; |
221 | if ((0 == num_clients) && in_shutdown) | 221 | if ((0 == num_clients) && in_shutdown) |
222 | do_shutdown (); | 222 | do_shutdown(); |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
@@ -232,35 +232,35 @@ client_disconnect_cb (void *cls, | |||
232 | * @return #GNUNET_YES to continue iteration | 232 | * @return #GNUNET_YES to continue iteration |
233 | */ | 233 | */ |
234 | static void | 234 | static void |
235 | record_iterator (void *cls, | 235 | record_iterator(void *cls, |
236 | const struct GNUNET_PEERSTORE_Record *record, | 236 | const struct GNUNET_PEERSTORE_Record *record, |
237 | const char *emsg) | 237 | const char *emsg) |
238 | { | 238 | { |
239 | struct GNUNET_PEERSTORE_Record *cls_record = cls; | 239 | struct GNUNET_PEERSTORE_Record *cls_record = cls; |
240 | struct GNUNET_MQ_Envelope *env; | 240 | struct GNUNET_MQ_Envelope *env; |
241 | 241 | ||
242 | if (NULL == record) | 242 | if (NULL == record) |
243 | { | ||
244 | /* No more records */ | ||
245 | struct GNUNET_MessageHeader *endmsg; | ||
246 | |||
247 | env = GNUNET_MQ_msg (endmsg, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); | ||
248 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), env); | ||
249 | if (NULL == emsg) | ||
250 | { | ||
251 | GNUNET_SERVICE_client_continue (cls_record->client); | ||
252 | } | ||
253 | else | ||
254 | { | 243 | { |
255 | GNUNET_break (0); | 244 | /* No more records */ |
256 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to iterate: %s\n", emsg); | 245 | struct GNUNET_MessageHeader *endmsg; |
257 | GNUNET_SERVICE_client_drop (cls_record->client); | 246 | |
247 | env = GNUNET_MQ_msg(endmsg, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); | ||
248 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(cls_record->client), env); | ||
249 | if (NULL == emsg) | ||
250 | { | ||
251 | GNUNET_SERVICE_client_continue(cls_record->client); | ||
252 | } | ||
253 | else | ||
254 | { | ||
255 | GNUNET_break(0); | ||
256 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to iterate: %s\n", emsg); | ||
257 | GNUNET_SERVICE_client_drop(cls_record->client); | ||
258 | } | ||
259 | PEERSTORE_destroy_record(cls_record); | ||
260 | return; | ||
258 | } | 261 | } |
259 | PEERSTORE_destroy_record (cls_record); | ||
260 | return; | ||
261 | } | ||
262 | 262 | ||
263 | env = PEERSTORE_create_record_mq_envelope ( | 263 | env = PEERSTORE_create_record_mq_envelope( |
264 | record->sub_system, | 264 | record->sub_system, |
265 | &record->peer, | 265 | &record->peer, |
266 | record->key, | 266 | record->key, |
@@ -269,7 +269,7 @@ record_iterator (void *cls, | |||
269 | record->expiry, | 269 | record->expiry, |
270 | 0, | 270 | 0, |
271 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); | 271 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); |
272 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), env); | 272 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(cls_record->client), env); |
273 | } | 273 | } |
274 | 274 | ||
275 | 275 | ||
@@ -283,14 +283,14 @@ record_iterator (void *cls, | |||
283 | * @return #GNUNET_YES to continue iterating | 283 | * @return #GNUNET_YES to continue iterating |
284 | */ | 284 | */ |
285 | static int | 285 | static int |
286 | watch_notifier_it (void *cls, const struct GNUNET_HashCode *key, void *value) | 286 | watch_notifier_it(void *cls, const struct GNUNET_HashCode *key, void *value) |
287 | { | 287 | { |
288 | struct GNUNET_PEERSTORE_Record *record = cls; | 288 | struct GNUNET_PEERSTORE_Record *record = cls; |
289 | struct GNUNET_SERVICE_Client *client = value; | 289 | struct GNUNET_SERVICE_Client *client = value; |
290 | struct GNUNET_MQ_Envelope *env; | 290 | struct GNUNET_MQ_Envelope *env; |
291 | 291 | ||
292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); | 292 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); |
293 | env = PEERSTORE_create_record_mq_envelope ( | 293 | env = PEERSTORE_create_record_mq_envelope( |
294 | record->sub_system, | 294 | record->sub_system, |
295 | &record->peer, | 295 | &record->peer, |
296 | record->key, | 296 | record->key, |
@@ -299,7 +299,7 @@ watch_notifier_it (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
299 | record->expiry, | 299 | record->expiry, |
300 | 0, | 300 | 0, |
301 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); | 301 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); |
302 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 302 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
303 | return GNUNET_YES; | 303 | return GNUNET_YES; |
304 | } | 304 | } |
305 | 305 | ||
@@ -310,15 +310,15 @@ watch_notifier_it (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
310 | * @param record changed record to update watchers with | 310 | * @param record changed record to update watchers with |
311 | */ | 311 | */ |
312 | static void | 312 | static void |
313 | watch_notifier (struct GNUNET_PEERSTORE_Record *record) | 313 | watch_notifier(struct GNUNET_PEERSTORE_Record *record) |
314 | { | 314 | { |
315 | struct GNUNET_HashCode keyhash; | 315 | struct GNUNET_HashCode keyhash; |
316 | 316 | ||
317 | PEERSTORE_hash_key (record->sub_system, &record->peer, record->key, &keyhash); | 317 | PEERSTORE_hash_key(record->sub_system, &record->peer, record->key, &keyhash); |
318 | GNUNET_CONTAINER_multihashmap_get_multiple (watchers, | 318 | GNUNET_CONTAINER_multihashmap_get_multiple(watchers, |
319 | &keyhash, | 319 | &keyhash, |
320 | &watch_notifier_it, | 320 | &watch_notifier_it, |
321 | record); | 321 | record); |
322 | } | 322 | } |
323 | 323 | ||
324 | 324 | ||
@@ -329,20 +329,20 @@ watch_notifier (struct GNUNET_PEERSTORE_Record *record) | |||
329 | * @param hm the actual message | 329 | * @param hm the actual message |
330 | */ | 330 | */ |
331 | static void | 331 | static void |
332 | handle_watch_cancel (void *cls, const struct StoreKeyHashMessage *hm) | 332 | handle_watch_cancel(void *cls, const struct StoreKeyHashMessage *hm) |
333 | { | 333 | { |
334 | struct GNUNET_SERVICE_Client *client = cls; | 334 | struct GNUNET_SERVICE_Client *client = cls; |
335 | 335 | ||
336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n"); | 336 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n"); |
337 | if (GNUNET_OK != | 337 | if (GNUNET_OK != |
338 | GNUNET_CONTAINER_multihashmap_remove (watchers, &hm->keyhash, client)) | 338 | GNUNET_CONTAINER_multihashmap_remove(watchers, &hm->keyhash, client)) |
339 | { | 339 | { |
340 | GNUNET_break (0); | 340 | GNUNET_break(0); |
341 | GNUNET_SERVICE_client_drop (client); | 341 | GNUNET_SERVICE_client_drop(client); |
342 | return; | 342 | return; |
343 | } | 343 | } |
344 | num_clients++; | 344 | num_clients++; |
345 | GNUNET_SERVICE_client_continue (client); | 345 | GNUNET_SERVICE_client_continue(client); |
346 | } | 346 | } |
347 | 347 | ||
348 | 348 | ||
@@ -353,18 +353,18 @@ handle_watch_cancel (void *cls, const struct StoreKeyHashMessage *hm) | |||
353 | * @param hm the actual message | 353 | * @param hm the actual message |
354 | */ | 354 | */ |
355 | static void | 355 | static void |
356 | handle_watch (void *cls, const struct StoreKeyHashMessage *hm) | 356 | handle_watch(void *cls, const struct StoreKeyHashMessage *hm) |
357 | { | 357 | { |
358 | struct GNUNET_SERVICE_Client *client = cls; | 358 | struct GNUNET_SERVICE_Client *client = cls; |
359 | 359 | ||
360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n"); | 360 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n"); |
361 | num_clients--; /* do not count watchers */ | 361 | num_clients--; /* do not count watchers */ |
362 | GNUNET_SERVICE_client_mark_monitor (client); | 362 | GNUNET_SERVICE_client_mark_monitor(client); |
363 | GNUNET_CONTAINER_multihashmap_put (watchers, | 363 | GNUNET_CONTAINER_multihashmap_put(watchers, |
364 | &hm->keyhash, | 364 | &hm->keyhash, |
365 | client, | 365 | client, |
366 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 366 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
367 | GNUNET_SERVICE_client_continue (client); | 367 | GNUNET_SERVICE_client_continue(client); |
368 | } | 368 | } |
369 | 369 | ||
370 | 370 | ||
@@ -376,23 +376,23 @@ handle_watch (void *cls, const struct StoreKeyHashMessage *hm) | |||
376 | * @return #GNUNET_OK if @a srm is well-formed | 376 | * @return #GNUNET_OK if @a srm is well-formed |
377 | */ | 377 | */ |
378 | static int | 378 | static int |
379 | check_iterate (void *cls, const struct StoreRecordMessage *srm) | 379 | check_iterate(void *cls, const struct StoreRecordMessage *srm) |
380 | { | 380 | { |
381 | struct GNUNET_PEERSTORE_Record *record; | 381 | struct GNUNET_PEERSTORE_Record *record; |
382 | 382 | ||
383 | record = PEERSTORE_parse_record_message (srm); | 383 | record = PEERSTORE_parse_record_message(srm); |
384 | if (NULL == record) | 384 | if (NULL == record) |
385 | { | 385 | { |
386 | GNUNET_break (0); | 386 | GNUNET_break(0); |
387 | return GNUNET_SYSERR; | 387 | return GNUNET_SYSERR; |
388 | } | 388 | } |
389 | if (NULL == record->sub_system) | 389 | if (NULL == record->sub_system) |
390 | { | 390 | { |
391 | GNUNET_break (0); | 391 | GNUNET_break(0); |
392 | PEERSTORE_destroy_record (record); | 392 | PEERSTORE_destroy_record(record); |
393 | return GNUNET_SYSERR; | 393 | return GNUNET_SYSERR; |
394 | } | 394 | } |
395 | PEERSTORE_destroy_record (record); | 395 | PEERSTORE_destroy_record(record); |
396 | return GNUNET_OK; | 396 | return GNUNET_OK; |
397 | } | 397 | } |
398 | 398 | ||
@@ -404,30 +404,30 @@ check_iterate (void *cls, const struct StoreRecordMessage *srm) | |||
404 | * @param srm the actual message | 404 | * @param srm the actual message |
405 | */ | 405 | */ |
406 | static void | 406 | static void |
407 | handle_iterate (void *cls, const struct StoreRecordMessage *srm) | 407 | handle_iterate(void *cls, const struct StoreRecordMessage *srm) |
408 | { | 408 | { |
409 | struct GNUNET_SERVICE_Client *client = cls; | 409 | struct GNUNET_SERVICE_Client *client = cls; |
410 | struct GNUNET_PEERSTORE_Record *record; | 410 | struct GNUNET_PEERSTORE_Record *record; |
411 | 411 | ||
412 | record = PEERSTORE_parse_record_message (srm); | 412 | record = PEERSTORE_parse_record_message(srm); |
413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 413 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
414 | "Iterate request: ss `%s', peer `%s', key `%s'\n", | 414 | "Iterate request: ss `%s', peer `%s', key `%s'\n", |
415 | record->sub_system, | 415 | record->sub_system, |
416 | GNUNET_i2s (&record->peer), | 416 | GNUNET_i2s(&record->peer), |
417 | (NULL == record->key) ? "NULL" : record->key); | 417 | (NULL == record->key) ? "NULL" : record->key); |
418 | record->client = client; | 418 | record->client = client; |
419 | if (GNUNET_OK != | 419 | if (GNUNET_OK != |
420 | db->iterate_records (db->cls, | 420 | db->iterate_records(db->cls, |
421 | record->sub_system, | 421 | record->sub_system, |
422 | (ntohs (srm->peer_set)) ? &record->peer : NULL, | 422 | (ntohs(srm->peer_set)) ? &record->peer : NULL, |
423 | record->key, | 423 | record->key, |
424 | &record_iterator, | 424 | &record_iterator, |
425 | record)) | 425 | record)) |
426 | { | 426 | { |
427 | GNUNET_break (0); | 427 | GNUNET_break(0); |
428 | GNUNET_SERVICE_client_drop (client); | 428 | GNUNET_SERVICE_client_drop(client); |
429 | PEERSTORE_destroy_record (record); | 429 | PEERSTORE_destroy_record(record); |
430 | } | 430 | } |
431 | } | 431 | } |
432 | 432 | ||
433 | 433 | ||
@@ -438,21 +438,21 @@ handle_iterate (void *cls, const struct StoreRecordMessage *srm) | |||
438 | * @param success result | 438 | * @param success result |
439 | */ | 439 | */ |
440 | static void | 440 | static void |
441 | store_record_continuation (void *cls, int success) | 441 | store_record_continuation(void *cls, int success) |
442 | { | 442 | { |
443 | struct GNUNET_PEERSTORE_Record *record = cls; | 443 | struct GNUNET_PEERSTORE_Record *record = cls; |
444 | 444 | ||
445 | if (GNUNET_OK == success) | 445 | if (GNUNET_OK == success) |
446 | { | 446 | { |
447 | watch_notifier (record); | 447 | watch_notifier(record); |
448 | GNUNET_SERVICE_client_continue (record->client); | 448 | GNUNET_SERVICE_client_continue(record->client); |
449 | } | 449 | } |
450 | else | 450 | else |
451 | { | 451 | { |
452 | GNUNET_break (0); | 452 | GNUNET_break(0); |
453 | GNUNET_SERVICE_client_drop (record->client); | 453 | GNUNET_SERVICE_client_drop(record->client); |
454 | } | 454 | } |
455 | PEERSTORE_destroy_record (record); | 455 | PEERSTORE_destroy_record(record); |
456 | } | 456 | } |
457 | 457 | ||
458 | 458 | ||
@@ -464,23 +464,23 @@ store_record_continuation (void *cls, int success) | |||
464 | * @return #GNUNET_OK if @a srm is well-formed | 464 | * @return #GNUNET_OK if @a srm is well-formed |
465 | */ | 465 | */ |
466 | static int | 466 | static int |
467 | check_store (void *cls, const struct StoreRecordMessage *srm) | 467 | check_store(void *cls, const struct StoreRecordMessage *srm) |
468 | { | 468 | { |
469 | struct GNUNET_PEERSTORE_Record *record; | 469 | struct GNUNET_PEERSTORE_Record *record; |
470 | 470 | ||
471 | record = PEERSTORE_parse_record_message (srm); | 471 | record = PEERSTORE_parse_record_message(srm); |
472 | if (NULL == record) | 472 | if (NULL == record) |
473 | { | 473 | { |
474 | GNUNET_break (0); | 474 | GNUNET_break(0); |
475 | return GNUNET_SYSERR; | 475 | return GNUNET_SYSERR; |
476 | } | 476 | } |
477 | if ((NULL == record->sub_system) || (NULL == record->key)) | 477 | if ((NULL == record->sub_system) || (NULL == record->key)) |
478 | { | 478 | { |
479 | GNUNET_break (0); | 479 | GNUNET_break(0); |
480 | PEERSTORE_destroy_record (record); | 480 | PEERSTORE_destroy_record(record); |
481 | return GNUNET_SYSERR; | 481 | return GNUNET_SYSERR; |
482 | } | 482 | } |
483 | PEERSTORE_destroy_record (record); | 483 | PEERSTORE_destroy_record(record); |
484 | return GNUNET_OK; | 484 | return GNUNET_OK; |
485 | } | 485 | } |
486 | 486 | ||
@@ -492,36 +492,36 @@ check_store (void *cls, const struct StoreRecordMessage *srm) | |||
492 | * @param srm the actual message | 492 | * @param srm the actual message |
493 | */ | 493 | */ |
494 | static void | 494 | static void |
495 | handle_store (void *cls, const struct StoreRecordMessage *srm) | 495 | handle_store(void *cls, const struct StoreRecordMessage *srm) |
496 | { | 496 | { |
497 | struct GNUNET_SERVICE_Client *client = cls; | 497 | struct GNUNET_SERVICE_Client *client = cls; |
498 | struct GNUNET_PEERSTORE_Record *record; | 498 | struct GNUNET_PEERSTORE_Record *record; |
499 | 499 | ||
500 | record = PEERSTORE_parse_record_message (srm); | 500 | record = PEERSTORE_parse_record_message(srm); |
501 | GNUNET_log ( | 501 | GNUNET_log( |
502 | GNUNET_ERROR_TYPE_INFO, | 502 | GNUNET_ERROR_TYPE_INFO, |
503 | "Received a store request. Sub system `%s' Peer `%s Key `%s' Options: %u.\n", | 503 | "Received a store request. Sub system `%s' Peer `%s Key `%s' Options: %u.\n", |
504 | record->sub_system, | 504 | record->sub_system, |
505 | GNUNET_i2s (&record->peer), | 505 | GNUNET_i2s(&record->peer), |
506 | record->key, | 506 | record->key, |
507 | (uint32_t) ntohl (srm->options)); | 507 | (uint32_t)ntohl(srm->options)); |
508 | record->client = client; | 508 | record->client = client; |
509 | if (GNUNET_OK != db->store_record (db->cls, | 509 | if (GNUNET_OK != db->store_record(db->cls, |
510 | record->sub_system, | 510 | record->sub_system, |
511 | &record->peer, | 511 | &record->peer, |
512 | record->key, | 512 | record->key, |
513 | record->value, | 513 | record->value, |
514 | record->value_size, | 514 | record->value_size, |
515 | record->expiry, | 515 | record->expiry, |
516 | ntohl (srm->options), | 516 | ntohl(srm->options), |
517 | &store_record_continuation, | 517 | &store_record_continuation, |
518 | record)) | 518 | record)) |
519 | { | 519 | { |
520 | GNUNET_break (0); | 520 | GNUNET_break(0); |
521 | PEERSTORE_destroy_record (record); | 521 | PEERSTORE_destroy_record(record); |
522 | GNUNET_SERVICE_client_drop (client); | 522 | GNUNET_SERVICE_client_drop(client); |
523 | return; | 523 | return; |
524 | } | 524 | } |
525 | } | 525 | } |
526 | 526 | ||
527 | 527 | ||
@@ -533,69 +533,69 @@ handle_store (void *cls, const struct StoreRecordMessage *srm) | |||
533 | * @param service the initialized service | 533 | * @param service the initialized service |
534 | */ | 534 | */ |
535 | static void | 535 | static void |
536 | run (void *cls, | 536 | run(void *cls, |
537 | const struct GNUNET_CONFIGURATION_Handle *c, | 537 | const struct GNUNET_CONFIGURATION_Handle *c, |
538 | struct GNUNET_SERVICE_Handle *service) | 538 | struct GNUNET_SERVICE_Handle *service) |
539 | { | 539 | { |
540 | char *database; | 540 | char *database; |
541 | 541 | ||
542 | in_shutdown = GNUNET_NO; | 542 | in_shutdown = GNUNET_NO; |
543 | cfg = c; | 543 | cfg = c; |
544 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | 544 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, |
545 | "peerstore", | 545 | "peerstore", |
546 | "DATABASE", | 546 | "DATABASE", |
547 | &database)) | 547 | &database)) |
548 | { | 548 | { |
549 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 549 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
550 | "peerstore", | 550 | "peerstore", |
551 | "DATABASE"); | 551 | "DATABASE"); |
552 | GNUNET_SCHEDULER_shutdown (); | 552 | GNUNET_SCHEDULER_shutdown(); |
553 | return; | 553 | return; |
554 | } | 554 | } |
555 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_peerstore_%s", database); | 555 | GNUNET_asprintf(&db_lib_name, "libgnunet_plugin_peerstore_%s", database); |
556 | db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); | 556 | db = GNUNET_PLUGIN_load(db_lib_name, (void *)cfg); |
557 | GNUNET_free (database); | 557 | GNUNET_free(database); |
558 | if (NULL == db) | 558 | if (NULL == db) |
559 | { | 559 | { |
560 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 560 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
561 | _ ("Could not load database backend `%s'\n"), | 561 | _("Could not load database backend `%s'\n"), |
562 | db_lib_name); | 562 | db_lib_name); |
563 | GNUNET_SCHEDULER_shutdown (); | 563 | GNUNET_SCHEDULER_shutdown(); |
564 | return; | 564 | return; |
565 | } | 565 | } |
566 | watchers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); | 566 | watchers = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); |
567 | expire_task = GNUNET_SCHEDULER_add_now (&cleanup_expired_records, NULL); | 567 | expire_task = GNUNET_SCHEDULER_add_now(&cleanup_expired_records, NULL); |
568 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 568 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
569 | } | 569 | } |
570 | 570 | ||
571 | 571 | ||
572 | /** | 572 | /** |
573 | * Define "main" method using service macro. | 573 | * Define "main" method using service macro. |
574 | */ | 574 | */ |
575 | GNUNET_SERVICE_MAIN ( | 575 | GNUNET_SERVICE_MAIN( |
576 | "peerstore", | 576 | "peerstore", |
577 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, | 577 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, |
578 | &run, | 578 | &run, |
579 | &client_connect_cb, | 579 | &client_connect_cb, |
580 | &client_disconnect_cb, | 580 | &client_disconnect_cb, |
581 | NULL, | 581 | NULL, |
582 | GNUNET_MQ_hd_var_size (store, | 582 | GNUNET_MQ_hd_var_size(store, |
583 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, | 583 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, |
584 | struct StoreRecordMessage, | 584 | struct StoreRecordMessage, |
585 | NULL), | 585 | NULL), |
586 | GNUNET_MQ_hd_var_size (iterate, | 586 | GNUNET_MQ_hd_var_size(iterate, |
587 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, | 587 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, |
588 | struct StoreRecordMessage, | 588 | struct StoreRecordMessage, |
589 | NULL), | 589 | NULL), |
590 | GNUNET_MQ_hd_fixed_size (watch, | 590 | GNUNET_MQ_hd_fixed_size(watch, |
591 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, | 591 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, |
592 | struct StoreKeyHashMessage, | 592 | struct StoreKeyHashMessage, |
593 | NULL), | 593 | NULL), |
594 | GNUNET_MQ_hd_fixed_size (watch_cancel, | 594 | GNUNET_MQ_hd_fixed_size(watch_cancel, |
595 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, | 595 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, |
596 | struct StoreKeyHashMessage, | 596 | struct StoreKeyHashMessage, |
597 | NULL), | 597 | NULL), |
598 | GNUNET_MQ_handler_end ()); | 598 | GNUNET_MQ_handler_end()); |
599 | 599 | ||
600 | 600 | ||
601 | /* end of gnunet-service-peerstore.c */ | 601 | /* end of gnunet-service-peerstore.c */ |
diff --git a/src/peerstore/peerstore.h b/src/peerstore/peerstore.h index 15881e6c8..de5e5908d 100644 --- a/src/peerstore/peerstore.h +++ b/src/peerstore/peerstore.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -33,9 +33,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
33 | /** | 33 | /** |
34 | * Message carrying a PEERSTORE record message | 34 | * Message carrying a PEERSTORE record message |
35 | */ | 35 | */ |
36 | struct StoreRecordMessage | 36 | struct StoreRecordMessage { |
37 | { | ||
38 | |||
39 | /** | 37 | /** |
40 | * GNUnet message header | 38 | * GNUnet message header |
41 | */ | 39 | */ |
@@ -81,16 +79,13 @@ struct StoreRecordMessage | |||
81 | uint32_t /* enum GNUNET_PEERSTORE_StoreOption */ options GNUNET_PACKED; | 79 | uint32_t /* enum GNUNET_PEERSTORE_StoreOption */ options GNUNET_PACKED; |
82 | 80 | ||
83 | /* Followed by key and value */ | 81 | /* Followed by key and value */ |
84 | |||
85 | }; | 82 | }; |
86 | 83 | ||
87 | 84 | ||
88 | /** | 85 | /** |
89 | * Message carrying record key hash | 86 | * Message carrying record key hash |
90 | */ | 87 | */ |
91 | struct StoreKeyHashMessage | 88 | struct StoreKeyHashMessage { |
92 | { | ||
93 | |||
94 | /** | 89 | /** |
95 | * GNUnet message header | 90 | * GNUnet message header |
96 | */ | 91 | */ |
@@ -105,7 +100,6 @@ struct StoreKeyHashMessage | |||
105 | * Hash of a record key | 100 | * Hash of a record key |
106 | */ | 101 | */ |
107 | struct GNUNET_HashCode keyhash; | 102 | struct GNUNET_HashCode keyhash; |
108 | |||
109 | }; | 103 | }; |
110 | 104 | ||
111 | GNUNET_NETWORK_STRUCT_END | 105 | GNUNET_NETWORK_STRUCT_END |
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c index 64bc3ae72..3ce2c5533 100644 --- a/src/peerstore/peerstore_api.c +++ b/src/peerstore/peerstore_api.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file peerstore/peerstore_api.c | 21 | * @file peerstore/peerstore_api.c |
22 | * @brief API for peerstore | 22 | * @brief API for peerstore |
@@ -28,7 +28,7 @@ | |||
28 | #include "peerstore.h" | 28 | #include "peerstore.h" |
29 | #include "peerstore_common.h" | 29 | #include "peerstore_common.h" |
30 | 30 | ||
31 | #define LOG(kind, ...) GNUNET_log_from (kind, "peerstore-api", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from(kind, "peerstore-api", __VA_ARGS__) |
32 | 32 | ||
33 | /******************************************************************************/ | 33 | /******************************************************************************/ |
34 | /************************ DATA STRUCTURES ****************************/ | 34 | /************************ DATA STRUCTURES ****************************/ |
@@ -37,9 +37,7 @@ | |||
37 | /** | 37 | /** |
38 | * Handle to the PEERSTORE service. | 38 | * Handle to the PEERSTORE service. |
39 | */ | 39 | */ |
40 | struct GNUNET_PEERSTORE_Handle | 40 | struct GNUNET_PEERSTORE_Handle { |
41 | { | ||
42 | |||
43 | /** | 41 | /** |
44 | * Our configuration. | 42 | * Our configuration. |
45 | */ | 43 | */ |
@@ -94,8 +92,7 @@ struct GNUNET_PEERSTORE_Handle | |||
94 | /** | 92 | /** |
95 | * Context for a store request | 93 | * Context for a store request |
96 | */ | 94 | */ |
97 | struct GNUNET_PEERSTORE_StoreContext | 95 | struct GNUNET_PEERSTORE_StoreContext { |
98 | { | ||
99 | /** | 96 | /** |
100 | * Kept in a DLL. | 97 | * Kept in a DLL. |
101 | */ | 98 | */ |
@@ -160,8 +157,7 @@ struct GNUNET_PEERSTORE_StoreContext | |||
160 | /** | 157 | /** |
161 | * Context for a iterate request | 158 | * Context for a iterate request |
162 | */ | 159 | */ |
163 | struct GNUNET_PEERSTORE_IterateContext | 160 | struct GNUNET_PEERSTORE_IterateContext { |
164 | { | ||
165 | /** | 161 | /** |
166 | * Kept in a DLL. | 162 | * Kept in a DLL. |
167 | */ | 163 | */ |
@@ -211,8 +207,7 @@ struct GNUNET_PEERSTORE_IterateContext | |||
211 | /** | 207 | /** |
212 | * Context for a watch request | 208 | * Context for a watch request |
213 | */ | 209 | */ |
214 | struct GNUNET_PEERSTORE_WatchContext | 210 | struct GNUNET_PEERSTORE_WatchContext { |
215 | { | ||
216 | /** | 211 | /** |
217 | * Kept in a DLL. | 212 | * Kept in a DLL. |
218 | */ | 213 | */ |
@@ -254,7 +249,7 @@ struct GNUNET_PEERSTORE_WatchContext | |||
254 | * @param cls a `struct GNUNET_PEERSTORE_Handle *h` | 249 | * @param cls a `struct GNUNET_PEERSTORE_Handle *h` |
255 | */ | 250 | */ |
256 | static void | 251 | static void |
257 | reconnect (void *cls); | 252 | reconnect(void *cls); |
258 | 253 | ||
259 | 254 | ||
260 | /** | 255 | /** |
@@ -263,32 +258,32 @@ reconnect (void *cls); | |||
263 | * @param h peerstore handle to disconnect | 258 | * @param h peerstore handle to disconnect |
264 | */ | 259 | */ |
265 | static void | 260 | static void |
266 | disconnect (struct GNUNET_PEERSTORE_Handle *h) | 261 | disconnect(struct GNUNET_PEERSTORE_Handle *h) |
267 | { | 262 | { |
268 | struct GNUNET_PEERSTORE_IterateContext *next; | 263 | struct GNUNET_PEERSTORE_IterateContext *next; |
269 | 264 | ||
270 | for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic; | 265 | for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic; |
271 | ic = next) | 266 | ic = next) |
272 | { | ||
273 | next = ic->next; | ||
274 | if (GNUNET_YES == ic->iterating) | ||
275 | { | 267 | { |
276 | GNUNET_PEERSTORE_Processor icb; | 268 | next = ic->next; |
277 | void *icb_cls; | 269 | if (GNUNET_YES == ic->iterating) |
278 | 270 | { | |
279 | icb = ic->callback; | 271 | GNUNET_PEERSTORE_Processor icb; |
280 | icb_cls = ic->callback_cls; | 272 | void *icb_cls; |
281 | GNUNET_PEERSTORE_iterate_cancel (ic); | 273 | |
282 | if (NULL != icb) | 274 | icb = ic->callback; |
283 | icb (icb_cls, NULL, "Iteration canceled due to reconnection"); | 275 | icb_cls = ic->callback_cls; |
276 | GNUNET_PEERSTORE_iterate_cancel(ic); | ||
277 | if (NULL != icb) | ||
278 | icb(icb_cls, NULL, "Iteration canceled due to reconnection"); | ||
279 | } | ||
284 | } | 280 | } |
285 | } | ||
286 | 281 | ||
287 | if (NULL != h->mq) | 282 | if (NULL != h->mq) |
288 | { | 283 | { |
289 | GNUNET_MQ_destroy (h->mq); | 284 | GNUNET_MQ_destroy(h->mq); |
290 | h->mq = NULL; | 285 | h->mq = NULL; |
291 | } | 286 | } |
292 | } | 287 | } |
293 | 288 | ||
294 | 289 | ||
@@ -299,16 +294,16 @@ disconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
299 | * @param h peerstore to reconnect | 294 | * @param h peerstore to reconnect |
300 | */ | 295 | */ |
301 | static void | 296 | static void |
302 | disconnect_and_schedule_reconnect (struct GNUNET_PEERSTORE_Handle *h) | 297 | disconnect_and_schedule_reconnect(struct GNUNET_PEERSTORE_Handle *h) |
303 | { | 298 | { |
304 | GNUNET_assert (NULL == h->reconnect_task); | 299 | GNUNET_assert(NULL == h->reconnect_task); |
305 | disconnect (h); | 300 | disconnect(h); |
306 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 301 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
307 | "Scheduling task to reconnect to PEERSTORE service in %s.\n", | 302 | "Scheduling task to reconnect to PEERSTORE service in %s.\n", |
308 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); | 303 | GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES)); |
309 | h->reconnect_task = | 304 | h->reconnect_task = |
310 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); | 305 | GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); |
311 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); | 306 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); |
312 | } | 307 | } |
313 | 308 | ||
314 | 309 | ||
@@ -318,7 +313,7 @@ disconnect_and_schedule_reconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
318 | * @param cls a `struct GNUNET_PEERSTORE_StoreContext *` | 313 | * @param cls a `struct GNUNET_PEERSTORE_StoreContext *` |
319 | */ | 314 | */ |
320 | static void | 315 | static void |
321 | store_request_sent (void *cls) | 316 | store_request_sent(void *cls) |
322 | { | 317 | { |
323 | struct GNUNET_PEERSTORE_StoreContext *sc = cls; | 318 | struct GNUNET_PEERSTORE_StoreContext *sc = cls; |
324 | GNUNET_PEERSTORE_Continuation cont; | 319 | GNUNET_PEERSTORE_Continuation cont; |
@@ -326,9 +321,9 @@ store_request_sent (void *cls) | |||
326 | 321 | ||
327 | cont = sc->cont; | 322 | cont = sc->cont; |
328 | cont_cls = sc->cont_cls; | 323 | cont_cls = sc->cont_cls; |
329 | GNUNET_PEERSTORE_store_cancel (sc); | 324 | GNUNET_PEERSTORE_store_cancel(sc); |
330 | if (NULL != cont) | 325 | if (NULL != cont) |
331 | cont (cont_cls, GNUNET_OK); | 326 | cont(cont_cls, GNUNET_OK); |
332 | } | 327 | } |
333 | 328 | ||
334 | 329 | ||
@@ -341,14 +336,14 @@ store_request_sent (void *cls) | |||
341 | * Function called when we had trouble talking to the service. | 336 | * Function called when we had trouble talking to the service. |
342 | */ | 337 | */ |
343 | static void | 338 | static void |
344 | handle_client_error (void *cls, enum GNUNET_MQ_Error error) | 339 | handle_client_error(void *cls, enum GNUNET_MQ_Error error) |
345 | { | 340 | { |
346 | struct GNUNET_PEERSTORE_Handle *h = cls; | 341 | struct GNUNET_PEERSTORE_Handle *h = cls; |
347 | 342 | ||
348 | LOG (GNUNET_ERROR_TYPE_ERROR, | 343 | LOG(GNUNET_ERROR_TYPE_ERROR, |
349 | "Received an error notification from MQ of type: %d\n", | 344 | "Received an error notification from MQ of type: %d\n", |
350 | error); | 345 | error); |
351 | disconnect_and_schedule_reconnect (h); | 346 | disconnect_and_schedule_reconnect(h); |
352 | } | 347 | } |
353 | 348 | ||
354 | 349 | ||
@@ -361,16 +356,16 @@ handle_client_error (void *cls, enum GNUNET_MQ_Error error) | |||
361 | * @return #GNUNET_YES (continue to iterate) | 356 | * @return #GNUNET_YES (continue to iterate) |
362 | */ | 357 | */ |
363 | static int | 358 | static int |
364 | rewatch_it (void *cls, const struct GNUNET_HashCode *key, void *value) | 359 | rewatch_it(void *cls, const struct GNUNET_HashCode *key, void *value) |
365 | { | 360 | { |
366 | struct GNUNET_PEERSTORE_Handle *h = cls; | 361 | struct GNUNET_PEERSTORE_Handle *h = cls; |
367 | struct GNUNET_PEERSTORE_WatchContext *wc = value; | 362 | struct GNUNET_PEERSTORE_WatchContext *wc = value; |
368 | struct StoreKeyHashMessage *hm; | 363 | struct StoreKeyHashMessage *hm; |
369 | struct GNUNET_MQ_Envelope *ev; | 364 | struct GNUNET_MQ_Envelope *ev; |
370 | 365 | ||
371 | ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); | 366 | ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); |
372 | hm->keyhash = wc->keyhash; | 367 | hm->keyhash = wc->keyhash; |
373 | GNUNET_MQ_send (h->mq, ev); | 368 | GNUNET_MQ_send(h->mq, ev); |
374 | return GNUNET_YES; | 369 | return GNUNET_YES; |
375 | } | 370 | } |
376 | 371 | ||
@@ -384,11 +379,11 @@ rewatch_it (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
384 | * @return #GNUNET_YES to continue iteration | 379 | * @return #GNUNET_YES to continue iteration |
385 | */ | 380 | */ |
386 | static int | 381 | static int |
387 | destroy_watch (void *cls, const struct GNUNET_HashCode *key, void *value) | 382 | destroy_watch(void *cls, const struct GNUNET_HashCode *key, void *value) |
388 | { | 383 | { |
389 | struct GNUNET_PEERSTORE_WatchContext *wc = value; | 384 | struct GNUNET_PEERSTORE_WatchContext *wc = value; |
390 | 385 | ||
391 | GNUNET_PEERSTORE_watch_cancel (wc); | 386 | GNUNET_PEERSTORE_watch_cancel(wc); |
392 | return GNUNET_YES; | 387 | return GNUNET_YES; |
393 | } | 388 | } |
394 | 389 | ||
@@ -401,14 +396,14 @@ destroy_watch (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
401 | * @param h Handle to the service. | 396 | * @param h Handle to the service. |
402 | */ | 397 | */ |
403 | static void | 398 | static void |
404 | final_disconnect (struct GNUNET_PEERSTORE_Handle *h) | 399 | final_disconnect(struct GNUNET_PEERSTORE_Handle *h) |
405 | { | 400 | { |
406 | if (NULL != h->mq) | 401 | if (NULL != h->mq) |
407 | { | 402 | { |
408 | GNUNET_MQ_destroy (h->mq); | 403 | GNUNET_MQ_destroy(h->mq); |
409 | h->mq = NULL; | 404 | h->mq = NULL; |
410 | } | 405 | } |
411 | GNUNET_free (h); | 406 | GNUNET_free(h); |
412 | } | 407 | } |
413 | 408 | ||
414 | 409 | ||
@@ -419,19 +414,19 @@ final_disconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
419 | * @return NULL on error | 414 | * @return NULL on error |
420 | */ | 415 | */ |
421 | struct GNUNET_PEERSTORE_Handle * | 416 | struct GNUNET_PEERSTORE_Handle * |
422 | GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | 417 | GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) |
423 | { | 418 | { |
424 | struct GNUNET_PEERSTORE_Handle *h; | 419 | struct GNUNET_PEERSTORE_Handle *h; |
425 | 420 | ||
426 | h = GNUNET_new (struct GNUNET_PEERSTORE_Handle); | 421 | h = GNUNET_new(struct GNUNET_PEERSTORE_Handle); |
427 | h->cfg = cfg; | 422 | h->cfg = cfg; |
428 | h->disconnecting = GNUNET_NO; | 423 | h->disconnecting = GNUNET_NO; |
429 | reconnect (h); | 424 | reconnect(h); |
430 | if (NULL == h->mq) | 425 | if (NULL == h->mq) |
431 | { | 426 | { |
432 | GNUNET_free (h); | 427 | GNUNET_free(h); |
433 | return NULL; | 428 | return NULL; |
434 | } | 429 | } |
435 | return h; | 430 | return h; |
436 | } | 431 | } |
437 | 432 | ||
@@ -445,36 +440,36 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
445 | * @param sync_first send any pending STORE requests before disconnecting | 440 | * @param sync_first send any pending STORE requests before disconnecting |
446 | */ | 441 | */ |
447 | void | 442 | void |
448 | GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first) | 443 | GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h, int sync_first) |
449 | { | 444 | { |
450 | struct GNUNET_PEERSTORE_IterateContext *ic; | 445 | struct GNUNET_PEERSTORE_IterateContext *ic; |
451 | struct GNUNET_PEERSTORE_StoreContext *sc; | 446 | struct GNUNET_PEERSTORE_StoreContext *sc; |
452 | 447 | ||
453 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting.\n"); | 448 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting.\n"); |
454 | if (NULL != h->watches) | 449 | if (NULL != h->watches) |
455 | { | 450 | { |
456 | GNUNET_CONTAINER_multihashmap_iterate (h->watches, &destroy_watch, NULL); | 451 | GNUNET_CONTAINER_multihashmap_iterate(h->watches, &destroy_watch, NULL); |
457 | GNUNET_CONTAINER_multihashmap_destroy (h->watches); | 452 | GNUNET_CONTAINER_multihashmap_destroy(h->watches); |
458 | h->watches = NULL; | 453 | h->watches = NULL; |
459 | } | 454 | } |
460 | while (NULL != (ic = h->iterate_head)) | 455 | while (NULL != (ic = h->iterate_head)) |
461 | { | 456 | { |
462 | GNUNET_break (0); | 457 | GNUNET_break(0); |
463 | GNUNET_PEERSTORE_iterate_cancel (ic); | 458 | GNUNET_PEERSTORE_iterate_cancel(ic); |
464 | } | 459 | } |
465 | if (NULL != h->store_head) | 460 | if (NULL != h->store_head) |
466 | { | ||
467 | if (GNUNET_YES == sync_first) | ||
468 | { | 461 | { |
469 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 462 | if (GNUNET_YES == sync_first) |
470 | "Delaying disconnection due to pending store requests.\n"); | 463 | { |
471 | h->disconnecting = GNUNET_YES; | 464 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
472 | return; | 465 | "Delaying disconnection due to pending store requests.\n"); |
466 | h->disconnecting = GNUNET_YES; | ||
467 | return; | ||
468 | } | ||
469 | while (NULL != (sc = h->store_head)) | ||
470 | GNUNET_PEERSTORE_store_cancel(sc); | ||
473 | } | 471 | } |
474 | while (NULL != (sc = h->store_head)) | 472 | final_disconnect(h); |
475 | GNUNET_PEERSTORE_store_cancel (sc); | ||
476 | } | ||
477 | final_disconnect (h); | ||
478 | } | 473 | } |
479 | 474 | ||
480 | 475 | ||
@@ -489,17 +484,17 @@ GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first) | |||
489 | * @param sc Store request context | 484 | * @param sc Store request context |
490 | */ | 485 | */ |
491 | void | 486 | void |
492 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | 487 | GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc) |
493 | { | 488 | { |
494 | struct GNUNET_PEERSTORE_Handle *h = sc->h; | 489 | struct GNUNET_PEERSTORE_Handle *h = sc->h; |
495 | 490 | ||
496 | GNUNET_CONTAINER_DLL_remove (sc->h->store_head, sc->h->store_tail, sc); | 491 | GNUNET_CONTAINER_DLL_remove(sc->h->store_head, sc->h->store_tail, sc); |
497 | GNUNET_free (sc->sub_system); | 492 | GNUNET_free(sc->sub_system); |
498 | GNUNET_free (sc->value); | 493 | GNUNET_free(sc->value); |
499 | GNUNET_free (sc->key); | 494 | GNUNET_free(sc->key); |
500 | GNUNET_free (sc); | 495 | GNUNET_free(sc); |
501 | if ((GNUNET_YES == h->disconnecting) && (NULL == h->store_head)) | 496 | if ((GNUNET_YES == h->disconnecting) && (NULL == h->store_head)) |
502 | final_disconnect (h); | 497 | final_disconnect(h); |
503 | } | 498 | } |
504 | 499 | ||
505 | 500 | ||
@@ -520,41 +515,41 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | |||
520 | * @param cont_cls Closure for @a cont | 515 | * @param cont_cls Closure for @a cont |
521 | */ | 516 | */ |
522 | struct GNUNET_PEERSTORE_StoreContext * | 517 | struct GNUNET_PEERSTORE_StoreContext * |
523 | GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | 518 | GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, |
524 | const char *sub_system, | 519 | const char *sub_system, |
525 | const struct GNUNET_PeerIdentity *peer, | 520 | const struct GNUNET_PeerIdentity *peer, |
526 | const char *key, | 521 | const char *key, |
527 | const void *value, | 522 | const void *value, |
528 | size_t size, | 523 | size_t size, |
529 | struct GNUNET_TIME_Absolute expiry, | 524 | struct GNUNET_TIME_Absolute expiry, |
530 | enum GNUNET_PEERSTORE_StoreOption options, | 525 | enum GNUNET_PEERSTORE_StoreOption options, |
531 | GNUNET_PEERSTORE_Continuation cont, | 526 | GNUNET_PEERSTORE_Continuation cont, |
532 | void *cont_cls) | 527 | void *cont_cls) |
533 | { | 528 | { |
534 | struct GNUNET_MQ_Envelope *ev; | 529 | struct GNUNET_MQ_Envelope *ev; |
535 | struct GNUNET_PEERSTORE_StoreContext *sc; | 530 | struct GNUNET_PEERSTORE_StoreContext *sc; |
536 | 531 | ||
537 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 532 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
538 | "Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n", | 533 | "Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n", |
539 | size, | 534 | size, |
540 | sub_system, | 535 | sub_system, |
541 | GNUNET_i2s (peer), | 536 | GNUNET_i2s(peer), |
542 | key); | 537 | key); |
543 | ev = | 538 | ev = |
544 | PEERSTORE_create_record_mq_envelope (sub_system, | 539 | PEERSTORE_create_record_mq_envelope(sub_system, |
545 | peer, | 540 | peer, |
546 | key, | 541 | key, |
547 | value, | 542 | value, |
548 | size, | 543 | size, |
549 | expiry, | 544 | expiry, |
550 | options, | 545 | options, |
551 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); | 546 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); |
552 | sc = GNUNET_new (struct GNUNET_PEERSTORE_StoreContext); | 547 | sc = GNUNET_new(struct GNUNET_PEERSTORE_StoreContext); |
553 | 548 | ||
554 | sc->sub_system = GNUNET_strdup (sub_system); | 549 | sc->sub_system = GNUNET_strdup(sub_system); |
555 | sc->peer = *peer; | 550 | sc->peer = *peer; |
556 | sc->key = GNUNET_strdup (key); | 551 | sc->key = GNUNET_strdup(key); |
557 | sc->value = GNUNET_memdup (value, size); | 552 | sc->value = GNUNET_memdup(value, size); |
558 | sc->size = size; | 553 | sc->size = size; |
559 | sc->expiry = expiry; | 554 | sc->expiry = expiry; |
560 | sc->options = options; | 555 | sc->options = options; |
@@ -562,9 +557,9 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | |||
562 | sc->cont_cls = cont_cls; | 557 | sc->cont_cls = cont_cls; |
563 | sc->h = h; | 558 | sc->h = h; |
564 | 559 | ||
565 | GNUNET_CONTAINER_DLL_insert_tail (h->store_head, h->store_tail, sc); | 560 | GNUNET_CONTAINER_DLL_insert_tail(h->store_head, h->store_tail, sc); |
566 | GNUNET_MQ_notify_sent (ev, &store_request_sent, sc); | 561 | GNUNET_MQ_notify_sent(ev, &store_request_sent, sc); |
567 | GNUNET_MQ_send (h->mq, ev); | 562 | GNUNET_MQ_send(h->mq, ev); |
568 | return sc; | 563 | return sc; |
569 | } | 564 | } |
570 | 565 | ||
@@ -581,7 +576,7 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | |||
581 | * @param msg message received | 576 | * @param msg message received |
582 | */ | 577 | */ |
583 | static void | 578 | static void |
584 | handle_iterate_end (void *cls, const struct GNUNET_MessageHeader *msg) | 579 | handle_iterate_end(void *cls, const struct GNUNET_MessageHeader *msg) |
585 | { | 580 | { |
586 | struct GNUNET_PEERSTORE_Handle *h = cls; | 581 | struct GNUNET_PEERSTORE_Handle *h = cls; |
587 | struct GNUNET_PEERSTORE_IterateContext *ic; | 582 | struct GNUNET_PEERSTORE_IterateContext *ic; |
@@ -590,18 +585,18 @@ handle_iterate_end (void *cls, const struct GNUNET_MessageHeader *msg) | |||
590 | 585 | ||
591 | ic = h->iterate_head; | 586 | ic = h->iterate_head; |
592 | if (NULL == ic) | 587 | if (NULL == ic) |
593 | { | 588 | { |
594 | LOG (GNUNET_ERROR_TYPE_ERROR, | 589 | LOG(GNUNET_ERROR_TYPE_ERROR, |
595 | _ ("Unexpected iteration response, this should not happen.\n")); | 590 | _("Unexpected iteration response, this should not happen.\n")); |
596 | disconnect_and_schedule_reconnect (h); | 591 | disconnect_and_schedule_reconnect(h); |
597 | return; | 592 | return; |
598 | } | 593 | } |
599 | callback = ic->callback; | 594 | callback = ic->callback; |
600 | callback_cls = ic->callback_cls; | 595 | callback_cls = ic->callback_cls; |
601 | ic->iterating = GNUNET_NO; | 596 | ic->iterating = GNUNET_NO; |
602 | GNUNET_PEERSTORE_iterate_cancel (ic); | 597 | GNUNET_PEERSTORE_iterate_cancel(ic); |
603 | if (NULL != callback) | 598 | if (NULL != callback) |
604 | callback (callback_cls, NULL, NULL); | 599 | callback(callback_cls, NULL, NULL); |
605 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 600 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
606 | } | 601 | } |
607 | 602 | ||
@@ -614,7 +609,7 @@ handle_iterate_end (void *cls, const struct GNUNET_MessageHeader *msg) | |||
614 | * @param msg message received | 609 | * @param msg message received |
615 | */ | 610 | */ |
616 | static int | 611 | static int |
617 | check_iterate_result (void *cls, const struct StoreRecordMessage *msg) | 612 | check_iterate_result(void *cls, const struct StoreRecordMessage *msg) |
618 | { | 613 | { |
619 | /* we defer validation to #handle_iterate_result */ | 614 | /* we defer validation to #handle_iterate_result */ |
620 | return GNUNET_OK; | 615 | return GNUNET_OK; |
@@ -628,7 +623,7 @@ check_iterate_result (void *cls, const struct StoreRecordMessage *msg) | |||
628 | * @param msg message received | 623 | * @param msg message received |
629 | */ | 624 | */ |
630 | static void | 625 | static void |
631 | handle_iterate_result (void *cls, const struct StoreRecordMessage *msg) | 626 | handle_iterate_result(void *cls, const struct StoreRecordMessage *msg) |
632 | { | 627 | { |
633 | struct GNUNET_PEERSTORE_Handle *h = cls; | 628 | struct GNUNET_PEERSTORE_Handle *h = cls; |
634 | struct GNUNET_PEERSTORE_IterateContext *ic; | 629 | struct GNUNET_PEERSTORE_IterateContext *ic; |
@@ -638,29 +633,29 @@ handle_iterate_result (void *cls, const struct StoreRecordMessage *msg) | |||
638 | 633 | ||
639 | ic = h->iterate_head; | 634 | ic = h->iterate_head; |
640 | if (NULL == ic) | 635 | if (NULL == ic) |
641 | { | 636 | { |
642 | LOG (GNUNET_ERROR_TYPE_ERROR, | 637 | LOG(GNUNET_ERROR_TYPE_ERROR, |
643 | _ ("Unexpected iteration response, this should not happen.\n")); | 638 | _("Unexpected iteration response, this should not happen.\n")); |
644 | disconnect_and_schedule_reconnect (h); | 639 | disconnect_and_schedule_reconnect(h); |
645 | return; | 640 | return; |
646 | } | 641 | } |
647 | ic->iterating = GNUNET_YES; | 642 | ic->iterating = GNUNET_YES; |
648 | callback = ic->callback; | 643 | callback = ic->callback; |
649 | callback_cls = ic->callback_cls; | 644 | callback_cls = ic->callback_cls; |
650 | if (NULL == callback) | 645 | if (NULL == callback) |
651 | return; | 646 | return; |
652 | record = PEERSTORE_parse_record_message (msg); | 647 | record = PEERSTORE_parse_record_message(msg); |
653 | if (NULL == record) | 648 | if (NULL == record) |
654 | { | 649 | { |
655 | callback (callback_cls, | 650 | callback(callback_cls, |
656 | NULL, | 651 | NULL, |
657 | _ ("Received a malformed response from service.")); | 652 | _("Received a malformed response from service.")); |
658 | } | 653 | } |
659 | else | 654 | else |
660 | { | 655 | { |
661 | callback (callback_cls, record, NULL); | 656 | callback(callback_cls, record, NULL); |
662 | PEERSTORE_destroy_record (record); | 657 | PEERSTORE_destroy_record(record); |
663 | } | 658 | } |
664 | } | 659 | } |
665 | 660 | ||
666 | 661 | ||
@@ -671,15 +666,15 @@ handle_iterate_result (void *cls, const struct StoreRecordMessage *msg) | |||
671 | * @param ic Iterate request context as returned by GNUNET_PEERSTORE_iterate() | 666 | * @param ic Iterate request context as returned by GNUNET_PEERSTORE_iterate() |
672 | */ | 667 | */ |
673 | void | 668 | void |
674 | GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) | 669 | GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic) |
675 | { | 670 | { |
676 | if (GNUNET_NO == ic->iterating) | 671 | if (GNUNET_NO == ic->iterating) |
677 | { | 672 | { |
678 | GNUNET_CONTAINER_DLL_remove (ic->h->iterate_head, ic->h->iterate_tail, ic); | 673 | GNUNET_CONTAINER_DLL_remove(ic->h->iterate_head, ic->h->iterate_tail, ic); |
679 | GNUNET_free (ic->sub_system); | 674 | GNUNET_free(ic->sub_system); |
680 | GNUNET_free_non_null (ic->key); | 675 | GNUNET_free_non_null(ic->key); |
681 | GNUNET_free (ic); | 676 | GNUNET_free(ic); |
682 | } | 677 | } |
683 | else | 678 | else |
684 | ic->callback = NULL; | 679 | ic->callback = NULL; |
685 | } | 680 | } |
@@ -697,39 +692,39 @@ GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) | |||
697 | * @return Handle to iteration request | 692 | * @return Handle to iteration request |
698 | */ | 693 | */ |
699 | struct GNUNET_PEERSTORE_IterateContext * | 694 | struct GNUNET_PEERSTORE_IterateContext * |
700 | GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, | 695 | GNUNET_PEERSTORE_iterate(struct GNUNET_PEERSTORE_Handle *h, |
701 | const char *sub_system, | 696 | const char *sub_system, |
702 | const struct GNUNET_PeerIdentity *peer, | 697 | const struct GNUNET_PeerIdentity *peer, |
703 | const char *key, | 698 | const char *key, |
704 | GNUNET_PEERSTORE_Processor callback, | 699 | GNUNET_PEERSTORE_Processor callback, |
705 | void *callback_cls) | 700 | void *callback_cls) |
706 | { | 701 | { |
707 | struct GNUNET_MQ_Envelope *ev; | 702 | struct GNUNET_MQ_Envelope *ev; |
708 | struct GNUNET_PEERSTORE_IterateContext *ic; | 703 | struct GNUNET_PEERSTORE_IterateContext *ic; |
709 | 704 | ||
710 | ev = | 705 | ev = |
711 | PEERSTORE_create_record_mq_envelope (sub_system, | 706 | PEERSTORE_create_record_mq_envelope(sub_system, |
712 | peer, | 707 | peer, |
713 | key, | 708 | key, |
714 | NULL, | 709 | NULL, |
715 | 0, | 710 | 0, |
716 | GNUNET_TIME_UNIT_FOREVER_ABS, | 711 | GNUNET_TIME_UNIT_FOREVER_ABS, |
717 | 0, | 712 | 0, |
718 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); | 713 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); |
719 | ic = GNUNET_new (struct GNUNET_PEERSTORE_IterateContext); | 714 | ic = GNUNET_new(struct GNUNET_PEERSTORE_IterateContext); |
720 | ic->callback = callback; | 715 | ic->callback = callback; |
721 | ic->callback_cls = callback_cls; | 716 | ic->callback_cls = callback_cls; |
722 | ic->h = h; | 717 | ic->h = h; |
723 | ic->sub_system = GNUNET_strdup (sub_system); | 718 | ic->sub_system = GNUNET_strdup(sub_system); |
724 | if (NULL != peer) | 719 | if (NULL != peer) |
725 | ic->peer = *peer; | 720 | ic->peer = *peer; |
726 | if (NULL != key) | 721 | if (NULL != key) |
727 | ic->key = GNUNET_strdup (key); | 722 | ic->key = GNUNET_strdup(key); |
728 | GNUNET_CONTAINER_DLL_insert_tail (h->iterate_head, h->iterate_tail, ic); | 723 | GNUNET_CONTAINER_DLL_insert_tail(h->iterate_head, h->iterate_tail, ic); |
729 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 724 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
730 | "Sending an iterate request for sub system `%s'\n", | 725 | "Sending an iterate request for sub system `%s'\n", |
731 | sub_system); | 726 | sub_system); |
732 | GNUNET_MQ_send (h->mq, ev); | 727 | GNUNET_MQ_send(h->mq, ev); |
733 | return ic; | 728 | return ic; |
734 | } | 729 | } |
735 | 730 | ||
@@ -745,7 +740,7 @@ GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, | |||
745 | * @param msg message received | 740 | * @param msg message received |
746 | */ | 741 | */ |
747 | static int | 742 | static int |
748 | check_watch_record (void *cls, const struct StoreRecordMessage *msg) | 743 | check_watch_record(void *cls, const struct StoreRecordMessage *msg) |
749 | { | 744 | { |
750 | /* we defer validation to #handle_watch_result */ | 745 | /* we defer validation to #handle_watch_result */ |
751 | return GNUNET_OK; | 746 | return GNUNET_OK; |
@@ -759,35 +754,35 @@ check_watch_record (void *cls, const struct StoreRecordMessage *msg) | |||
759 | * @param msg message received | 754 | * @param msg message received |
760 | */ | 755 | */ |
761 | static void | 756 | static void |
762 | handle_watch_record (void *cls, const struct StoreRecordMessage *msg) | 757 | handle_watch_record(void *cls, const struct StoreRecordMessage *msg) |
763 | { | 758 | { |
764 | struct GNUNET_PEERSTORE_Handle *h = cls; | 759 | struct GNUNET_PEERSTORE_Handle *h = cls; |
765 | struct GNUNET_PEERSTORE_Record *record; | 760 | struct GNUNET_PEERSTORE_Record *record; |
766 | struct GNUNET_HashCode keyhash; | 761 | struct GNUNET_HashCode keyhash; |
767 | struct GNUNET_PEERSTORE_WatchContext *wc; | 762 | struct GNUNET_PEERSTORE_WatchContext *wc; |
768 | 763 | ||
769 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a watch record from service.\n"); | 764 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Received a watch record from service.\n"); |
770 | record = PEERSTORE_parse_record_message (msg); | 765 | record = PEERSTORE_parse_record_message(msg); |
771 | if (NULL == record) | 766 | if (NULL == record) |
772 | { | 767 | { |
773 | disconnect_and_schedule_reconnect (h); | 768 | disconnect_and_schedule_reconnect(h); |
774 | return; | 769 | return; |
775 | } | 770 | } |
776 | PEERSTORE_hash_key (record->sub_system, &record->peer, record->key, &keyhash); | 771 | PEERSTORE_hash_key(record->sub_system, &record->peer, record->key, &keyhash); |
777 | // FIXME: what if there are multiple watches for the same key? | 772 | // FIXME: what if there are multiple watches for the same key? |
778 | wc = GNUNET_CONTAINER_multihashmap_get (h->watches, &keyhash); | 773 | wc = GNUNET_CONTAINER_multihashmap_get(h->watches, &keyhash); |
779 | if (NULL == wc) | 774 | if (NULL == wc) |
780 | { | 775 | { |
781 | LOG (GNUNET_ERROR_TYPE_ERROR, | 776 | LOG(GNUNET_ERROR_TYPE_ERROR, |
782 | _ ("Received a watch result for a non existing watch.\n")); | 777 | _("Received a watch result for a non existing watch.\n")); |
783 | PEERSTORE_destroy_record (record); | 778 | PEERSTORE_destroy_record(record); |
784 | disconnect_and_schedule_reconnect (h); | 779 | disconnect_and_schedule_reconnect(h); |
785 | return; | 780 | return; |
786 | } | 781 | } |
787 | if (NULL != wc->callback) | 782 | if (NULL != wc->callback) |
788 | wc->callback (wc->callback_cls, record, NULL); | 783 | wc->callback(wc->callback_cls, record, NULL); |
789 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 784 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
790 | PEERSTORE_destroy_record (record); | 785 | PEERSTORE_destroy_record(record); |
791 | } | 786 | } |
792 | 787 | ||
793 | 788 | ||
@@ -797,67 +792,67 @@ handle_watch_record (void *cls, const struct StoreRecordMessage *msg) | |||
797 | * @param cls a `struct GNUNET_PEERSTORE_Handle *` | 792 | * @param cls a `struct GNUNET_PEERSTORE_Handle *` |
798 | */ | 793 | */ |
799 | static void | 794 | static void |
800 | reconnect (void *cls) | 795 | reconnect(void *cls) |
801 | { | 796 | { |
802 | struct GNUNET_PEERSTORE_Handle *h = cls; | 797 | struct GNUNET_PEERSTORE_Handle *h = cls; |
803 | struct GNUNET_MQ_MessageHandler mq_handlers[] = | 798 | struct GNUNET_MQ_MessageHandler mq_handlers[] = |
804 | {GNUNET_MQ_hd_fixed_size (iterate_end, | 799 | { GNUNET_MQ_hd_fixed_size(iterate_end, |
805 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, | 800 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, |
806 | struct GNUNET_MessageHeader, | 801 | struct GNUNET_MessageHeader, |
807 | h), | ||
808 | GNUNET_MQ_hd_var_size (iterate_result, | ||
809 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, | ||
810 | struct StoreRecordMessage, | ||
811 | h), | 802 | h), |
812 | GNUNET_MQ_hd_var_size (watch_record, | 803 | GNUNET_MQ_hd_var_size(iterate_result, |
813 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, | 804 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, |
814 | struct StoreRecordMessage, | 805 | struct StoreRecordMessage, |
815 | h), | 806 | h), |
816 | GNUNET_MQ_handler_end ()}; | 807 | GNUNET_MQ_hd_var_size(watch_record, |
808 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, | ||
809 | struct StoreRecordMessage, | ||
810 | h), | ||
811 | GNUNET_MQ_handler_end() }; | ||
817 | struct GNUNET_MQ_Envelope *ev; | 812 | struct GNUNET_MQ_Envelope *ev; |
818 | 813 | ||
819 | h->reconnect_task = NULL; | 814 | h->reconnect_task = NULL; |
820 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n"); | 815 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n"); |
821 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 816 | h->mq = GNUNET_CLIENT_connect(h->cfg, |
822 | "peerstore", | 817 | "peerstore", |
823 | mq_handlers, | 818 | mq_handlers, |
824 | &handle_client_error, | 819 | &handle_client_error, |
825 | h); | 820 | h); |
826 | if (NULL == h->mq) | 821 | if (NULL == h->mq) |
827 | return; | 822 | return; |
828 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 823 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
829 | "Resending pending requests after reconnect.\n"); | 824 | "Resending pending requests after reconnect.\n"); |
830 | if (NULL != h->watches) | 825 | if (NULL != h->watches) |
831 | GNUNET_CONTAINER_multihashmap_iterate (h->watches, &rewatch_it, h); | 826 | GNUNET_CONTAINER_multihashmap_iterate(h->watches, &rewatch_it, h); |
832 | for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic; | 827 | for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic; |
833 | ic = ic->next) | 828 | ic = ic->next) |
834 | { | 829 | { |
835 | ev = | 830 | ev = |
836 | PEERSTORE_create_record_mq_envelope (ic->sub_system, | 831 | PEERSTORE_create_record_mq_envelope(ic->sub_system, |
837 | &ic->peer, | 832 | &ic->peer, |
838 | ic->key, | 833 | ic->key, |
839 | NULL, | 834 | NULL, |
840 | 0, | 835 | 0, |
841 | GNUNET_TIME_UNIT_FOREVER_ABS, | 836 | GNUNET_TIME_UNIT_FOREVER_ABS, |
842 | 0, | 837 | 0, |
843 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); | 838 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); |
844 | GNUNET_MQ_send (h->mq, ev); | 839 | GNUNET_MQ_send(h->mq, ev); |
845 | } | 840 | } |
846 | for (struct GNUNET_PEERSTORE_StoreContext *sc = h->store_head; NULL != sc; | 841 | for (struct GNUNET_PEERSTORE_StoreContext *sc = h->store_head; NULL != sc; |
847 | sc = sc->next) | 842 | sc = sc->next) |
848 | { | 843 | { |
849 | ev = | 844 | ev = |
850 | PEERSTORE_create_record_mq_envelope (sc->sub_system, | 845 | PEERSTORE_create_record_mq_envelope(sc->sub_system, |
851 | &sc->peer, | 846 | &sc->peer, |
852 | sc->key, | 847 | sc->key, |
853 | sc->value, | 848 | sc->value, |
854 | sc->size, | 849 | sc->size, |
855 | sc->expiry, | 850 | sc->expiry, |
856 | sc->options, | 851 | sc->options, |
857 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); | 852 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); |
858 | GNUNET_MQ_notify_sent (ev, &store_request_sent, sc); | 853 | GNUNET_MQ_notify_sent(ev, &store_request_sent, sc); |
859 | GNUNET_MQ_send (h->mq, ev); | 854 | GNUNET_MQ_send(h->mq, ev); |
860 | } | 855 | } |
861 | } | 856 | } |
862 | 857 | ||
863 | 858 | ||
@@ -867,20 +862,20 @@ reconnect (void *cls) | |||
867 | * @param wc handle to the watch request | 862 | * @param wc handle to the watch request |
868 | */ | 863 | */ |
869 | void | 864 | void |
870 | GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc) | 865 | GNUNET_PEERSTORE_watch_cancel(struct GNUNET_PEERSTORE_WatchContext *wc) |
871 | { | 866 | { |
872 | struct GNUNET_PEERSTORE_Handle *h = wc->h; | 867 | struct GNUNET_PEERSTORE_Handle *h = wc->h; |
873 | struct GNUNET_MQ_Envelope *ev; | 868 | struct GNUNET_MQ_Envelope *ev; |
874 | struct StoreKeyHashMessage *hm; | 869 | struct StoreKeyHashMessage *hm; |
875 | 870 | ||
876 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Canceling watch.\n"); | 871 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Canceling watch.\n"); |
877 | ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL); | 872 | ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL); |
878 | hm->keyhash = wc->keyhash; | 873 | hm->keyhash = wc->keyhash; |
879 | GNUNET_MQ_send (h->mq, ev); | 874 | GNUNET_MQ_send(h->mq, ev); |
880 | GNUNET_assert ( | 875 | GNUNET_assert( |
881 | GNUNET_YES == | 876 | GNUNET_YES == |
882 | GNUNET_CONTAINER_multihashmap_remove (h->watches, &wc->keyhash, wc)); | 877 | GNUNET_CONTAINER_multihashmap_remove(h->watches, &wc->keyhash, wc)); |
883 | GNUNET_free (wc); | 878 | GNUNET_free(wc); |
884 | } | 879 | } |
885 | 880 | ||
886 | 881 | ||
@@ -897,37 +892,37 @@ GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc) | |||
897 | * @return Handle to watch request | 892 | * @return Handle to watch request |
898 | */ | 893 | */ |
899 | struct GNUNET_PEERSTORE_WatchContext * | 894 | struct GNUNET_PEERSTORE_WatchContext * |
900 | GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h, | 895 | GNUNET_PEERSTORE_watch(struct GNUNET_PEERSTORE_Handle *h, |
901 | const char *sub_system, | 896 | const char *sub_system, |
902 | const struct GNUNET_PeerIdentity *peer, | 897 | const struct GNUNET_PeerIdentity *peer, |
903 | const char *key, | 898 | const char *key, |
904 | GNUNET_PEERSTORE_Processor callback, | 899 | GNUNET_PEERSTORE_Processor callback, |
905 | void *callback_cls) | 900 | void *callback_cls) |
906 | { | 901 | { |
907 | struct GNUNET_MQ_Envelope *ev; | 902 | struct GNUNET_MQ_Envelope *ev; |
908 | struct StoreKeyHashMessage *hm; | 903 | struct StoreKeyHashMessage *hm; |
909 | struct GNUNET_PEERSTORE_WatchContext *wc; | 904 | struct GNUNET_PEERSTORE_WatchContext *wc; |
910 | 905 | ||
911 | ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); | 906 | ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); |
912 | PEERSTORE_hash_key (sub_system, peer, key, &hm->keyhash); | 907 | PEERSTORE_hash_key(sub_system, peer, key, &hm->keyhash); |
913 | wc = GNUNET_new (struct GNUNET_PEERSTORE_WatchContext); | 908 | wc = GNUNET_new(struct GNUNET_PEERSTORE_WatchContext); |
914 | wc->callback = callback; | 909 | wc->callback = callback; |
915 | wc->callback_cls = callback_cls; | 910 | wc->callback_cls = callback_cls; |
916 | wc->h = h; | 911 | wc->h = h; |
917 | wc->keyhash = hm->keyhash; | 912 | wc->keyhash = hm->keyhash; |
918 | if (NULL == h->watches) | 913 | if (NULL == h->watches) |
919 | h->watches = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO); | 914 | h->watches = GNUNET_CONTAINER_multihashmap_create(5, GNUNET_NO); |
920 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( | 915 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( |
921 | h->watches, | 916 | h->watches, |
922 | &wc->keyhash, | 917 | &wc->keyhash, |
923 | wc, | 918 | wc, |
924 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 919 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
925 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 920 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
926 | "Sending a watch request for subsystem `%s', peer `%s', key `%s'.\n", | 921 | "Sending a watch request for subsystem `%s', peer `%s', key `%s'.\n", |
927 | sub_system, | 922 | sub_system, |
928 | GNUNET_i2s (peer), | 923 | GNUNET_i2s(peer), |
929 | key); | 924 | key); |
930 | GNUNET_MQ_send (h->mq, ev); | 925 | GNUNET_MQ_send(h->mq, ev); |
931 | return wc; | 926 | return wc; |
932 | } | 927 | } |
933 | 928 | ||
diff --git a/src/peerstore/peerstore_common.c b/src/peerstore/peerstore_common.c index 0e2cc0514..7fceb1ec0 100644 --- a/src/peerstore/peerstore_common.c +++ b/src/peerstore/peerstore_common.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -30,10 +30,10 @@ | |||
30 | * | 30 | * |
31 | */ | 31 | */ |
32 | void | 32 | void |
33 | PEERSTORE_hash_key (const char *sub_system, | 33 | PEERSTORE_hash_key(const char *sub_system, |
34 | const struct GNUNET_PeerIdentity *peer, | 34 | const struct GNUNET_PeerIdentity *peer, |
35 | const char *key, | 35 | const char *key, |
36 | struct GNUNET_HashCode *ret) | 36 | struct GNUNET_HashCode *ret) |
37 | { | 37 | { |
38 | size_t sssize; | 38 | size_t sssize; |
39 | size_t psize; | 39 | size_t psize; |
@@ -42,19 +42,19 @@ PEERSTORE_hash_key (const char *sub_system, | |||
42 | void *block; | 42 | void *block; |
43 | void *blockptr; | 43 | void *blockptr; |
44 | 44 | ||
45 | sssize = strlen (sub_system) + 1; | 45 | sssize = strlen(sub_system) + 1; |
46 | psize = sizeof (struct GNUNET_PeerIdentity); | 46 | psize = sizeof(struct GNUNET_PeerIdentity); |
47 | ksize = strlen (key) + 1; | 47 | ksize = strlen(key) + 1; |
48 | totalsize = sssize + psize + ksize; | 48 | totalsize = sssize + psize + ksize; |
49 | block = GNUNET_malloc (totalsize); | 49 | block = GNUNET_malloc(totalsize); |
50 | blockptr = block; | 50 | blockptr = block; |
51 | GNUNET_memcpy (blockptr, sub_system, sssize); | 51 | GNUNET_memcpy(blockptr, sub_system, sssize); |
52 | blockptr += sssize; | 52 | blockptr += sssize; |
53 | GNUNET_memcpy (blockptr, peer, psize); | 53 | GNUNET_memcpy(blockptr, peer, psize); |
54 | blockptr += psize; | 54 | blockptr += psize; |
55 | GNUNET_memcpy (blockptr, key, ksize); | 55 | GNUNET_memcpy(blockptr, key, ksize); |
56 | GNUNET_CRYPTO_hash (block, totalsize, ret); | 56 | GNUNET_CRYPTO_hash(block, totalsize, ret); |
57 | GNUNET_free (block); | 57 | GNUNET_free(block); |
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
@@ -72,14 +72,14 @@ PEERSTORE_hash_key (const char *sub_system, | |||
72 | * @return pointer to record message struct | 72 | * @return pointer to record message struct |
73 | */ | 73 | */ |
74 | struct GNUNET_MQ_Envelope * | 74 | struct GNUNET_MQ_Envelope * |
75 | PEERSTORE_create_record_mq_envelope (const char *sub_system, | 75 | PEERSTORE_create_record_mq_envelope(const char *sub_system, |
76 | const struct GNUNET_PeerIdentity *peer, | 76 | const struct GNUNET_PeerIdentity *peer, |
77 | const char *key, | 77 | const char *key, |
78 | const void *value, | 78 | const void *value, |
79 | size_t value_size, | 79 | size_t value_size, |
80 | struct GNUNET_TIME_Absolute expiry, | 80 | struct GNUNET_TIME_Absolute expiry, |
81 | enum GNUNET_PEERSTORE_StoreOption options, | 81 | enum GNUNET_PEERSTORE_StoreOption options, |
82 | uint16_t msg_type) | 82 | uint16_t msg_type) |
83 | { | 83 | { |
84 | struct StoreRecordMessage *srm; | 84 | struct StoreRecordMessage *srm; |
85 | struct GNUNET_MQ_Envelope *ev; | 85 | struct GNUNET_MQ_Envelope *ev; |
@@ -88,32 +88,32 @@ PEERSTORE_create_record_mq_envelope (const char *sub_system, | |||
88 | size_t msg_size; | 88 | size_t msg_size; |
89 | void *dummy; | 89 | void *dummy; |
90 | 90 | ||
91 | GNUNET_assert (NULL != sub_system); | 91 | GNUNET_assert(NULL != sub_system); |
92 | ss_size = strlen (sub_system) + 1; | 92 | ss_size = strlen(sub_system) + 1; |
93 | if (NULL == key) | 93 | if (NULL == key) |
94 | key_size = 0; | 94 | key_size = 0; |
95 | else | 95 | else |
96 | key_size = strlen (key) + 1; | 96 | key_size = strlen(key) + 1; |
97 | msg_size = ss_size + key_size + value_size; | 97 | msg_size = ss_size + key_size + value_size; |
98 | ev = GNUNET_MQ_msg_extra (srm, msg_size, msg_type); | 98 | ev = GNUNET_MQ_msg_extra(srm, msg_size, msg_type); |
99 | srm->key_size = htons (key_size); | 99 | srm->key_size = htons(key_size); |
100 | srm->expiry = GNUNET_TIME_absolute_hton (expiry); | 100 | srm->expiry = GNUNET_TIME_absolute_hton(expiry); |
101 | if (NULL == peer) | 101 | if (NULL == peer) |
102 | srm->peer_set = htons (GNUNET_NO); | 102 | srm->peer_set = htons(GNUNET_NO); |
103 | else | 103 | else |
104 | { | 104 | { |
105 | srm->peer_set = htons (GNUNET_YES); | 105 | srm->peer_set = htons(GNUNET_YES); |
106 | srm->peer = *peer; | 106 | srm->peer = *peer; |
107 | } | 107 | } |
108 | srm->sub_system_size = htons (ss_size); | 108 | srm->sub_system_size = htons(ss_size); |
109 | srm->value_size = htons (value_size); | 109 | srm->value_size = htons(value_size); |
110 | srm->options = htonl (options); | 110 | srm->options = htonl(options); |
111 | dummy = &srm[1]; | 111 | dummy = &srm[1]; |
112 | GNUNET_memcpy (dummy, sub_system, ss_size); | 112 | GNUNET_memcpy(dummy, sub_system, ss_size); |
113 | dummy += ss_size; | 113 | dummy += ss_size; |
114 | GNUNET_memcpy (dummy, key, key_size); | 114 | GNUNET_memcpy(dummy, key, key_size); |
115 | dummy += key_size; | 115 | dummy += key_size; |
116 | GNUNET_memcpy (dummy, value, value_size); | 116 | GNUNET_memcpy(dummy, value, value_size); |
117 | return ev; | 117 | return ev; |
118 | } | 118 | } |
119 | 119 | ||
@@ -125,7 +125,7 @@ PEERSTORE_create_record_mq_envelope (const char *sub_system, | |||
125 | * @return Pointer to record or NULL if error | 125 | * @return Pointer to record or NULL if error |
126 | */ | 126 | */ |
127 | struct GNUNET_PEERSTORE_Record * | 127 | struct GNUNET_PEERSTORE_Record * |
128 | PEERSTORE_parse_record_message (const struct StoreRecordMessage *srm) | 128 | PEERSTORE_parse_record_message(const struct StoreRecordMessage *srm) |
129 | { | 129 | { |
130 | struct GNUNET_PEERSTORE_Record *record; | 130 | struct GNUNET_PEERSTORE_Record *record; |
131 | uint16_t req_size; | 131 | uint16_t req_size; |
@@ -134,39 +134,39 @@ PEERSTORE_parse_record_message (const struct StoreRecordMessage *srm) | |||
134 | uint16_t value_size; | 134 | uint16_t value_size; |
135 | char *dummy; | 135 | char *dummy; |
136 | 136 | ||
137 | req_size = ntohs (srm->header.size) - sizeof (*srm); | 137 | req_size = ntohs(srm->header.size) - sizeof(*srm); |
138 | ss_size = ntohs (srm->sub_system_size); | 138 | ss_size = ntohs(srm->sub_system_size); |
139 | key_size = ntohs (srm->key_size); | 139 | key_size = ntohs(srm->key_size); |
140 | value_size = ntohs (srm->value_size); | 140 | value_size = ntohs(srm->value_size); |
141 | if (ss_size + key_size + value_size != req_size) | 141 | if (ss_size + key_size + value_size != req_size) |
142 | { | 142 | { |
143 | GNUNET_break (0); | 143 | GNUNET_break(0); |
144 | return NULL; | 144 | return NULL; |
145 | } | 145 | } |
146 | record = GNUNET_new (struct GNUNET_PEERSTORE_Record); | 146 | record = GNUNET_new(struct GNUNET_PEERSTORE_Record); |
147 | if (GNUNET_YES == ntohs (srm->peer_set)) | 147 | if (GNUNET_YES == ntohs(srm->peer_set)) |
148 | { | 148 | { |
149 | record->peer = srm->peer; | 149 | record->peer = srm->peer; |
150 | } | 150 | } |
151 | record->expiry = GNUNET_TIME_absolute_ntoh (srm->expiry); | 151 | record->expiry = GNUNET_TIME_absolute_ntoh(srm->expiry); |
152 | dummy = (char *) &srm[1]; | 152 | dummy = (char *)&srm[1]; |
153 | if (ss_size > 0) | 153 | if (ss_size > 0) |
154 | { | 154 | { |
155 | record->sub_system = GNUNET_strdup (dummy); | 155 | record->sub_system = GNUNET_strdup(dummy); |
156 | dummy += ss_size; | 156 | dummy += ss_size; |
157 | } | 157 | } |
158 | if (key_size > 0) | 158 | if (key_size > 0) |
159 | { | 159 | { |
160 | record->key = GNUNET_strdup (dummy); | 160 | record->key = GNUNET_strdup(dummy); |
161 | dummy += key_size; | 161 | dummy += key_size; |
162 | } | 162 | } |
163 | if (value_size > 0) | 163 | if (value_size > 0) |
164 | { | 164 | { |
165 | record->value = GNUNET_malloc (value_size); | 165 | record->value = GNUNET_malloc(value_size); |
166 | GNUNET_memcpy (record->value, | 166 | GNUNET_memcpy(record->value, |
167 | dummy, | 167 | dummy, |
168 | value_size); | 168 | value_size); |
169 | } | 169 | } |
170 | record->value_size = value_size; | 170 | record->value_size = value_size; |
171 | return record; | 171 | return record; |
172 | } | 172 | } |
@@ -178,16 +178,16 @@ PEERSTORE_parse_record_message (const struct StoreRecordMessage *srm) | |||
178 | * @param record | 178 | * @param record |
179 | */ | 179 | */ |
180 | void | 180 | void |
181 | PEERSTORE_destroy_record (struct GNUNET_PEERSTORE_Record *record) | 181 | PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record) |
182 | { | 182 | { |
183 | if (NULL != record->sub_system) | 183 | if (NULL != record->sub_system) |
184 | GNUNET_free (record->sub_system); | 184 | GNUNET_free(record->sub_system); |
185 | if (NULL != record->key) | 185 | if (NULL != record->key) |
186 | GNUNET_free (record->key); | 186 | GNUNET_free(record->key); |
187 | if (NULL != record->value) | 187 | if (NULL != record->value) |
188 | { | 188 | { |
189 | GNUNET_free (record->value); | 189 | GNUNET_free(record->value); |
190 | record->value = 0; | 190 | record->value = 0; |
191 | } | 191 | } |
192 | GNUNET_free (record); | 192 | GNUNET_free(record); |
193 | } | 193 | } |
diff --git a/src/peerstore/peerstore_common.h b/src/peerstore/peerstore_common.h index 1e3f228b8..6379f61a6 100644 --- a/src/peerstore/peerstore_common.h +++ b/src/peerstore/peerstore_common.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -31,10 +31,10 @@ | |||
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | void | 33 | void |
34 | PEERSTORE_hash_key (const char *sub_system, | 34 | PEERSTORE_hash_key(const char *sub_system, |
35 | const struct GNUNET_PeerIdentity *peer, | 35 | const struct GNUNET_PeerIdentity *peer, |
36 | const char *key, | 36 | const char *key, |
37 | struct GNUNET_HashCode *ret); | 37 | struct GNUNET_HashCode *ret); |
38 | 38 | ||
39 | 39 | ||
40 | /** | 40 | /** |
@@ -51,14 +51,14 @@ PEERSTORE_hash_key (const char *sub_system, | |||
51 | * @return pointer to record message struct | 51 | * @return pointer to record message struct |
52 | */ | 52 | */ |
53 | struct GNUNET_MQ_Envelope * | 53 | struct GNUNET_MQ_Envelope * |
54 | PEERSTORE_create_record_mq_envelope (const char *sub_system, | 54 | PEERSTORE_create_record_mq_envelope(const char *sub_system, |
55 | const struct GNUNET_PeerIdentity *peer, | 55 | const struct GNUNET_PeerIdentity *peer, |
56 | const char *key, | 56 | const char *key, |
57 | const void *value, | 57 | const void *value, |
58 | size_t value_size, | 58 | size_t value_size, |
59 | struct GNUNET_TIME_Absolute expiry, | 59 | struct GNUNET_TIME_Absolute expiry, |
60 | enum GNUNET_PEERSTORE_StoreOption options, | 60 | enum GNUNET_PEERSTORE_StoreOption options, |
61 | uint16_t msg_type); | 61 | uint16_t msg_type); |
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
@@ -68,7 +68,7 @@ PEERSTORE_create_record_mq_envelope (const char *sub_system, | |||
68 | * @return Pointer to record or NULL on error | 68 | * @return Pointer to record or NULL on error |
69 | */ | 69 | */ |
70 | struct GNUNET_PEERSTORE_Record * | 70 | struct GNUNET_PEERSTORE_Record * |
71 | PEERSTORE_parse_record_message (const struct StoreRecordMessage *srm); | 71 | PEERSTORE_parse_record_message(const struct StoreRecordMessage *srm); |
72 | 72 | ||
73 | 73 | ||
74 | /** | 74 | /** |
@@ -77,6 +77,6 @@ PEERSTORE_parse_record_message (const struct StoreRecordMessage *srm); | |||
77 | * @param record | 77 | * @param record |
78 | */ | 78 | */ |
79 | void | 79 | void |
80 | PEERSTORE_destroy_record (struct GNUNET_PEERSTORE_Record *record); | 80 | PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record); |
81 | 81 | ||
82 | /* end of peerstore_common.h */ | 82 | /* end of peerstore_common.h */ |
diff --git a/src/peerstore/perf_peerstore_store.c b/src/peerstore/perf_peerstore_store.c index 51761cc4f..392dbbb03 100644 --- a/src/peerstore/perf_peerstore_store.c +++ b/src/peerstore/perf_peerstore_store.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file peerstore/perf_peerstore_store.c | 21 | * @file peerstore/perf_peerstore_store.c |
22 | * @brief performance test for peerstore store operation | 22 | * @brief performance test for peerstore store operation |
@@ -40,68 +40,68 @@ static char *v = "test_peerstore_stress_val"; | |||
40 | static int count = 0; | 40 | static int count = 0; |
41 | 41 | ||
42 | static void | 42 | static void |
43 | disconnect () | 43 | disconnect() |
44 | { | 44 | { |
45 | if (NULL != h) | 45 | if (NULL != h) |
46 | GNUNET_PEERSTORE_disconnect (h, GNUNET_YES); | 46 | GNUNET_PEERSTORE_disconnect(h, GNUNET_YES); |
47 | GNUNET_SCHEDULER_shutdown (); | 47 | GNUNET_SCHEDULER_shutdown(); |
48 | } | 48 | } |
49 | 49 | ||
50 | 50 | ||
51 | static void | 51 | static void |
52 | store () | 52 | store() |
53 | { | 53 | { |
54 | GNUNET_PEERSTORE_store (h, ss, &p, k, v, strlen (v) + 1, | 54 | GNUNET_PEERSTORE_store(h, ss, &p, k, v, strlen(v) + 1, |
55 | GNUNET_TIME_UNIT_FOREVER_ABS, | 55 | GNUNET_TIME_UNIT_FOREVER_ABS, |
56 | (count == | 56 | (count == |
57 | 0) ? GNUNET_PEERSTORE_STOREOPTION_REPLACE : | 57 | 0) ? GNUNET_PEERSTORE_STOREOPTION_REPLACE : |
58 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL); | 58 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL); |
59 | count++; | 59 | count++; |
60 | } | 60 | } |
61 | 61 | ||
62 | 62 | ||
63 | static void | 63 | static void |
64 | watch_cb (void *cls, const struct GNUNET_PEERSTORE_Record *record, | 64 | watch_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, |
65 | const char *emsg) | 65 | const char *emsg) |
66 | { | 66 | { |
67 | GNUNET_assert (NULL == emsg); | 67 | GNUNET_assert(NULL == emsg); |
68 | if (STORES == count) | 68 | if (STORES == count) |
69 | { | 69 | { |
70 | ok = 0; | 70 | ok = 0; |
71 | disconnect (); | 71 | disconnect(); |
72 | } | 72 | } |
73 | else | 73 | else |
74 | store (); | 74 | store(); |
75 | } | 75 | } |
76 | 76 | ||
77 | 77 | ||
78 | static void | 78 | static void |
79 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | 79 | run(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
80 | struct GNUNET_TESTING_Peer *peer) | 80 | struct GNUNET_TESTING_Peer *peer) |
81 | { | 81 | { |
82 | memset (&p, 5, sizeof (p)); | 82 | memset(&p, 5, sizeof(p)); |
83 | h = GNUNET_PEERSTORE_connect (cfg); | 83 | h = GNUNET_PEERSTORE_connect(cfg); |
84 | GNUNET_assert (NULL != h); | 84 | GNUNET_assert(NULL != h); |
85 | GNUNET_PEERSTORE_watch (h, ss, &p, k, &watch_cb, NULL); | 85 | GNUNET_PEERSTORE_watch(h, ss, &p, k, &watch_cb, NULL); |
86 | store (); | 86 | store(); |
87 | } | 87 | } |
88 | 88 | ||
89 | 89 | ||
90 | int | 90 | int |
91 | main (int argc, char *argv[]) | 91 | main(int argc, char *argv[]) |
92 | { | 92 | { |
93 | struct GNUNET_TIME_Absolute start; | 93 | struct GNUNET_TIME_Absolute start; |
94 | struct GNUNET_TIME_Relative diff; | 94 | struct GNUNET_TIME_Relative diff; |
95 | 95 | ||
96 | start = GNUNET_TIME_absolute_get (); | 96 | start = GNUNET_TIME_absolute_get(); |
97 | if (0 != | 97 | if (0 != |
98 | GNUNET_TESTING_service_run ("perf-peerstore-store", "peerstore", | 98 | GNUNET_TESTING_service_run("perf-peerstore-store", "peerstore", |
99 | "test_peerstore_api_data.conf", &run, NULL)) | 99 | "test_peerstore_api_data.conf", &run, NULL)) |
100 | return 1; | 100 | return 1; |
101 | diff = GNUNET_TIME_absolute_get_duration (start); | 101 | diff = GNUNET_TIME_absolute_get_duration(start); |
102 | fprintf (stderr, "Stored and retrieved %d records in %s (%s).\n", STORES, | 102 | fprintf(stderr, "Stored and retrieved %d records in %s (%s).\n", STORES, |
103 | GNUNET_STRINGS_relative_time_to_string (diff, GNUNET_YES), | 103 | GNUNET_STRINGS_relative_time_to_string(diff, GNUNET_YES), |
104 | GNUNET_STRINGS_relative_time_to_string (diff, GNUNET_NO)); | 104 | GNUNET_STRINGS_relative_time_to_string(diff, GNUNET_NO)); |
105 | return ok; | 105 | return ok; |
106 | } | 106 | } |
107 | 107 | ||
diff --git a/src/peerstore/plugin_peerstore_flat.c b/src/peerstore/plugin_peerstore_flat.c index 0cd2522ec..749e270e4 100644 --- a/src/peerstore/plugin_peerstore_flat.c +++ b/src/peerstore/plugin_peerstore_flat.c | |||
@@ -32,9 +32,7 @@ | |||
32 | /** | 32 | /** |
33 | * Context for all functions in this plugin. | 33 | * Context for all functions in this plugin. |
34 | */ | 34 | */ |
35 | struct Plugin | 35 | struct Plugin { |
36 | { | ||
37 | |||
38 | /** | 36 | /** |
39 | * Configuration handle | 37 | * Configuration handle |
40 | */ | 38 | */ |
@@ -94,27 +92,27 @@ struct Plugin | |||
94 | * Result found bool | 92 | * Result found bool |
95 | */ | 93 | */ |
96 | int iter_result_found; | 94 | int iter_result_found; |
97 | |||
98 | }; | 95 | }; |
99 | 96 | ||
100 | 97 | ||
101 | static int | 98 | static int |
102 | delete_entries (void *cls, | 99 | delete_entries(void *cls, |
103 | const struct GNUNET_HashCode *key, | 100 | const struct GNUNET_HashCode *key, |
104 | void *value) | 101 | void *value) |
105 | { | 102 | { |
106 | struct Plugin *plugin = cls; | 103 | struct Plugin *plugin = cls; |
107 | struct GNUNET_PEERSTORE_Record *entry = value; | 104 | struct GNUNET_PEERSTORE_Record *entry = value; |
108 | if (0 != strcmp (plugin->iter_key, entry->key)) | 105 | |
106 | if (0 != strcmp(plugin->iter_key, entry->key)) | ||
109 | return GNUNET_YES; | 107 | return GNUNET_YES; |
110 | if (0 != memcmp (plugin->iter_peer, | 108 | if (0 != memcmp(plugin->iter_peer, |
111 | &entry->peer, | 109 | &entry->peer, |
112 | sizeof (struct GNUNET_PeerIdentity))) | 110 | sizeof(struct GNUNET_PeerIdentity))) |
113 | return GNUNET_YES; | 111 | return GNUNET_YES; |
114 | if (0 != strcmp (plugin->iter_sub_system, entry->sub_system)) | 112 | if (0 != strcmp(plugin->iter_sub_system, entry->sub_system)) |
115 | return GNUNET_YES; | 113 | return GNUNET_YES; |
116 | 114 | ||
117 | GNUNET_CONTAINER_multihashmap_remove (plugin->hm, key, value); | 115 | GNUNET_CONTAINER_multihashmap_remove(plugin->hm, key, value); |
118 | plugin->deleted_entries++; | 116 | plugin->deleted_entries++; |
119 | return GNUNET_YES; | 117 | return GNUNET_YES; |
120 | } | 118 | } |
@@ -130,9 +128,9 @@ delete_entries (void *cls, | |||
130 | * @return number of deleted records | 128 | * @return number of deleted records |
131 | */ | 129 | */ |
132 | static int | 130 | static int |
133 | peerstore_flat_delete_records (void *cls, const char *sub_system, | 131 | peerstore_flat_delete_records(void *cls, const char *sub_system, |
134 | const struct GNUNET_PeerIdentity *peer, | 132 | const struct GNUNET_PeerIdentity *peer, |
135 | const char *key) | 133 | const char *key) |
136 | { | 134 | { |
137 | struct Plugin *plugin = cls; | 135 | struct Plugin *plugin = cls; |
138 | 136 | ||
@@ -141,25 +139,25 @@ peerstore_flat_delete_records (void *cls, const char *sub_system, | |||
141 | plugin->iter_key = key; | 139 | plugin->iter_key = key; |
142 | plugin->deleted_entries = 0; | 140 | plugin->deleted_entries = 0; |
143 | 141 | ||
144 | GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, | 142 | GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, |
145 | &delete_entries, | 143 | &delete_entries, |
146 | plugin); | 144 | plugin); |
147 | return plugin->deleted_entries; | 145 | return plugin->deleted_entries; |
148 | } | 146 | } |
149 | 147 | ||
150 | static int | 148 | static int |
151 | expire_entries (void *cls, | 149 | expire_entries(void *cls, |
152 | const struct GNUNET_HashCode *key, | 150 | const struct GNUNET_HashCode *key, |
153 | void *value) | 151 | void *value) |
154 | { | 152 | { |
155 | struct Plugin *plugin = cls; | 153 | struct Plugin *plugin = cls; |
156 | struct GNUNET_PEERSTORE_Record *entry = value; | 154 | struct GNUNET_PEERSTORE_Record *entry = value; |
157 | 155 | ||
158 | if (entry->expiry.abs_value_us < plugin->iter_now.abs_value_us) | 156 | if (entry->expiry.abs_value_us < plugin->iter_now.abs_value_us) |
159 | { | 157 | { |
160 | GNUNET_CONTAINER_multihashmap_remove (plugin->hm, key, value); | 158 | GNUNET_CONTAINER_multihashmap_remove(plugin->hm, key, value); |
161 | plugin->exp_changes++; | 159 | plugin->exp_changes++; |
162 | } | 160 | } |
163 | return GNUNET_YES; | 161 | return GNUNET_YES; |
164 | } | 162 | } |
165 | 163 | ||
@@ -176,49 +174,49 @@ expire_entries (void *cls, | |||
176 | * called | 174 | * called |
177 | */ | 175 | */ |
178 | static int | 176 | static int |
179 | peerstore_flat_expire_records (void *cls, struct GNUNET_TIME_Absolute now, | 177 | peerstore_flat_expire_records(void *cls, struct GNUNET_TIME_Absolute now, |
180 | GNUNET_PEERSTORE_Continuation cont, | 178 | GNUNET_PEERSTORE_Continuation cont, |
181 | void *cont_cls) | 179 | void *cont_cls) |
182 | { | 180 | { |
183 | struct Plugin *plugin = cls; | 181 | struct Plugin *plugin = cls; |
182 | |||
184 | plugin->exp_changes = 0; | 183 | plugin->exp_changes = 0; |
185 | plugin->iter_now = now; | 184 | plugin->iter_now = now; |
186 | 185 | ||
187 | GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, | 186 | GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, |
188 | &expire_entries, | 187 | &expire_entries, |
189 | plugin); | 188 | plugin); |
190 | if (NULL != cont) | 189 | if (NULL != cont) |
191 | { | 190 | { |
192 | cont (cont_cls, plugin->exp_changes); | 191 | cont(cont_cls, plugin->exp_changes); |
193 | } | 192 | } |
194 | return GNUNET_OK; | 193 | return GNUNET_OK; |
195 | |||
196 | } | 194 | } |
197 | 195 | ||
198 | 196 | ||
199 | static int | 197 | static int |
200 | iterate_entries (void *cls, | 198 | iterate_entries(void *cls, |
201 | const struct GNUNET_HashCode *key, | 199 | const struct GNUNET_HashCode *key, |
202 | void *value) | 200 | void *value) |
203 | { | 201 | { |
204 | struct Plugin *plugin = cls; | 202 | struct Plugin *plugin = cls; |
205 | struct GNUNET_PEERSTORE_Record *entry = value; | 203 | struct GNUNET_PEERSTORE_Record *entry = value; |
206 | 204 | ||
207 | if ((NULL != plugin->iter_peer) && | 205 | if ((NULL != plugin->iter_peer) && |
208 | (0 != memcmp (plugin->iter_peer, | 206 | (0 != memcmp(plugin->iter_peer, |
209 | &entry->peer, | 207 | &entry->peer, |
210 | sizeof (struct GNUNET_PeerIdentity)))) | 208 | sizeof(struct GNUNET_PeerIdentity)))) |
211 | { | 209 | { |
212 | return GNUNET_YES; | 210 | return GNUNET_YES; |
213 | } | 211 | } |
214 | if ((NULL != plugin->iter_key) && | 212 | if ((NULL != plugin->iter_key) && |
215 | (0 != strcmp (plugin->iter_key, | 213 | (0 != strcmp(plugin->iter_key, |
216 | entry->key))) | 214 | entry->key))) |
217 | { | 215 | { |
218 | return GNUNET_YES; | 216 | return GNUNET_YES; |
219 | } | 217 | } |
220 | if (NULL != plugin->iter) | 218 | if (NULL != plugin->iter) |
221 | plugin->iter (plugin->iter_cls, entry, NULL); | 219 | plugin->iter(plugin->iter_cls, entry, NULL); |
222 | plugin->iter_result_found = GNUNET_YES; | 220 | plugin->iter_result_found = GNUNET_YES; |
223 | return GNUNET_YES; | 221 | return GNUNET_YES; |
224 | } | 222 | } |
@@ -238,24 +236,25 @@ iterate_entries (void *cls, | |||
238 | * called | 236 | * called |
239 | */ | 237 | */ |
240 | static int | 238 | static int |
241 | peerstore_flat_iterate_records (void *cls, const char *sub_system, | 239 | peerstore_flat_iterate_records(void *cls, const char *sub_system, |
242 | const struct GNUNET_PeerIdentity *peer, | 240 | const struct GNUNET_PeerIdentity *peer, |
243 | const char *key, | 241 | const char *key, |
244 | GNUNET_PEERSTORE_Processor iter, | 242 | GNUNET_PEERSTORE_Processor iter, |
245 | void *iter_cls) | 243 | void *iter_cls) |
246 | { | 244 | { |
247 | struct Plugin *plugin = cls; | 245 | struct Plugin *plugin = cls; |
246 | |||
248 | plugin->iter = iter; | 247 | plugin->iter = iter; |
249 | plugin->iter_cls = iter_cls; | 248 | plugin->iter_cls = iter_cls; |
250 | plugin->iter_peer = peer; | 249 | plugin->iter_peer = peer; |
251 | plugin->iter_sub_system = sub_system; | 250 | plugin->iter_sub_system = sub_system; |
252 | plugin->iter_key = key; | 251 | plugin->iter_key = key; |
253 | 252 | ||
254 | GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, | 253 | GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, |
255 | &iterate_entries, | 254 | &iterate_entries, |
256 | plugin); | 255 | plugin); |
257 | if (NULL != iter) | 256 | if (NULL != iter) |
258 | iter (iter_cls, NULL, NULL); | 257 | iter(iter_cls, NULL, NULL); |
259 | return GNUNET_OK; | 258 | return GNUNET_OK; |
260 | } | 259 | } |
261 | 260 | ||
@@ -278,13 +277,13 @@ peerstore_flat_iterate_records (void *cls, const char *sub_system, | |||
278 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR and cont is not called | 277 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR and cont is not called |
279 | */ | 278 | */ |
280 | static int | 279 | static int |
281 | peerstore_flat_store_record (void *cls, const char *sub_system, | 280 | peerstore_flat_store_record(void *cls, const char *sub_system, |
282 | const struct GNUNET_PeerIdentity *peer, | 281 | const struct GNUNET_PeerIdentity *peer, |
283 | const char *key, const void *value, size_t size, | 282 | const char *key, const void *value, size_t size, |
284 | struct GNUNET_TIME_Absolute expiry, | 283 | struct GNUNET_TIME_Absolute expiry, |
285 | enum GNUNET_PEERSTORE_StoreOption options, | 284 | enum GNUNET_PEERSTORE_StoreOption options, |
286 | GNUNET_PEERSTORE_Continuation cont, | 285 | GNUNET_PEERSTORE_Continuation cont, |
287 | void *cont_cls) | 286 | void *cont_cls) |
288 | { | 287 | { |
289 | struct Plugin *plugin = cls; | 288 | struct Plugin *plugin = cls; |
290 | struct GNUNET_HashCode hkey; | 289 | struct GNUNET_HashCode hkey; |
@@ -292,33 +291,33 @@ peerstore_flat_store_record (void *cls, const char *sub_system, | |||
292 | const char *peer_id; | 291 | const char *peer_id; |
293 | 292 | ||
294 | 293 | ||
295 | entry = GNUNET_new (struct GNUNET_PEERSTORE_Record); | 294 | entry = GNUNET_new(struct GNUNET_PEERSTORE_Record); |
296 | entry->sub_system = GNUNET_strdup (sub_system); | 295 | entry->sub_system = GNUNET_strdup(sub_system); |
297 | entry->key = GNUNET_strdup (key); | 296 | entry->key = GNUNET_strdup(key); |
298 | entry->value = GNUNET_malloc (size); | 297 | entry->value = GNUNET_malloc(size); |
299 | GNUNET_memcpy (entry->value, value, size); | 298 | GNUNET_memcpy(entry->value, value, size); |
300 | entry->value_size = size; | 299 | entry->value_size = size; |
301 | entry->peer = *peer; | 300 | entry->peer = *peer; |
302 | entry->expiry = expiry; | 301 | entry->expiry = expiry; |
303 | 302 | ||
304 | peer_id = GNUNET_i2s (peer); | 303 | peer_id = GNUNET_i2s(peer); |
305 | GNUNET_CRYPTO_hash (peer_id, | 304 | GNUNET_CRYPTO_hash(peer_id, |
306 | strlen (peer_id), | 305 | strlen(peer_id), |
307 | &hkey); | 306 | &hkey); |
308 | 307 | ||
309 | if (GNUNET_PEERSTORE_STOREOPTION_REPLACE == options) | 308 | if (GNUNET_PEERSTORE_STOREOPTION_REPLACE == options) |
310 | { | 309 | { |
311 | peerstore_flat_delete_records (cls, sub_system, peer, key); | 310 | peerstore_flat_delete_records(cls, sub_system, peer, key); |
312 | } | 311 | } |
313 | 312 | ||
314 | GNUNET_CONTAINER_multihashmap_put (plugin->hm, | 313 | GNUNET_CONTAINER_multihashmap_put(plugin->hm, |
315 | &hkey, | 314 | &hkey, |
316 | entry, | 315 | entry, |
317 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 316 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
318 | if (NULL != cont) | 317 | if (NULL != cont) |
319 | { | 318 | { |
320 | cont (cont_cls, GNUNET_OK); | 319 | cont(cont_cls, GNUNET_OK); |
321 | } | 320 | } |
322 | return GNUNET_OK; | 321 | return GNUNET_OK; |
323 | } | 322 | } |
324 | 323 | ||
@@ -332,7 +331,7 @@ peerstore_flat_store_record (void *cls, const char *sub_system, | |||
332 | * @return GNUNET_OK on success | 331 | * @return GNUNET_OK on success |
333 | */ | 332 | */ |
334 | static int | 333 | static int |
335 | database_setup (struct Plugin *plugin) | 334 | database_setup(struct Plugin *plugin) |
336 | { | 335 | { |
337 | char *afsdir; | 336 | char *afsdir; |
338 | char *key; | 337 | char *key; |
@@ -349,138 +348,139 @@ database_setup (struct Plugin *plugin) | |||
349 | char *line; | 348 | char *line; |
350 | 349 | ||
351 | if (GNUNET_OK != | 350 | if (GNUNET_OK != |
352 | GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, "peerstore-flat", | 351 | GNUNET_CONFIGURATION_get_value_filename(plugin->cfg, "peerstore-flat", |
353 | "FILENAME", &afsdir)) | 352 | "FILENAME", &afsdir)) |
354 | { | ||
355 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "peerstore-flat", | ||
356 | "FILENAME"); | ||
357 | return GNUNET_SYSERR; | ||
358 | } | ||
359 | if (GNUNET_OK != GNUNET_DISK_file_test (afsdir)) | ||
360 | { | ||
361 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir)) | ||
362 | { | 353 | { |
363 | GNUNET_break (0); | 354 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "peerstore-flat", |
364 | GNUNET_free (afsdir); | 355 | "FILENAME"); |
365 | return GNUNET_SYSERR; | 356 | return GNUNET_SYSERR; |
366 | } | 357 | } |
367 | } | 358 | if (GNUNET_OK != GNUNET_DISK_file_test(afsdir)) |
359 | { | ||
360 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(afsdir)) | ||
361 | { | ||
362 | GNUNET_break(0); | ||
363 | GNUNET_free(afsdir); | ||
364 | return GNUNET_SYSERR; | ||
365 | } | ||
366 | } | ||
368 | /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */ | 367 | /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */ |
369 | plugin->fn = afsdir; | 368 | plugin->fn = afsdir; |
370 | 369 | ||
371 | fh = GNUNET_DISK_file_open (afsdir, | 370 | fh = GNUNET_DISK_file_open(afsdir, |
372 | GNUNET_DISK_OPEN_CREATE | | 371 | GNUNET_DISK_OPEN_CREATE | |
373 | GNUNET_DISK_OPEN_READWRITE, | 372 | GNUNET_DISK_OPEN_READWRITE, |
374 | GNUNET_DISK_PERM_USER_WRITE | | 373 | GNUNET_DISK_PERM_USER_WRITE | |
375 | GNUNET_DISK_PERM_USER_READ); | 374 | GNUNET_DISK_PERM_USER_READ); |
376 | if (NULL == fh) | 375 | if (NULL == fh) |
377 | { | 376 | { |
378 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 377 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
379 | _("Unable to initialize file: %s.\n"), | 378 | _("Unable to initialize file: %s.\n"), |
380 | afsdir); | 379 | afsdir); |
381 | return GNUNET_SYSERR; | 380 | return GNUNET_SYSERR; |
382 | } | 381 | } |
383 | 382 | ||
384 | /* Load data from file into hashmap */ | 383 | /* Load data from file into hashmap */ |
385 | plugin->hm = GNUNET_CONTAINER_multihashmap_create (10, | 384 | plugin->hm = GNUNET_CONTAINER_multihashmap_create(10, |
386 | GNUNET_NO); | 385 | GNUNET_NO); |
387 | |||
388 | if (GNUNET_SYSERR == GNUNET_DISK_file_size (afsdir, | ||
389 | &size, | ||
390 | GNUNET_YES, | ||
391 | GNUNET_YES)) | ||
392 | { | ||
393 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
394 | _("Unable to get filesize: %s.\n"), | ||
395 | afsdir); | ||
396 | return GNUNET_SYSERR; | ||
397 | } | ||
398 | |||
399 | buffer = GNUNET_malloc (size + 1); | ||
400 | |||
401 | if (GNUNET_SYSERR == GNUNET_DISK_file_read (fh, | ||
402 | buffer, | ||
403 | size)) | ||
404 | { | ||
405 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
406 | _("Unable to read file: %s.\n"), | ||
407 | afsdir); | ||
408 | GNUNET_DISK_file_close (fh); | ||
409 | GNUNET_free (buffer); | ||
410 | return GNUNET_SYSERR; | ||
411 | } | ||
412 | 386 | ||
413 | buffer[size] = '\0'; | 387 | if (GNUNET_SYSERR == GNUNET_DISK_file_size(afsdir, |
414 | GNUNET_DISK_file_close (fh); | 388 | &size, |
415 | if (0 < size) { | 389 | GNUNET_YES, |
416 | line = strtok (buffer, "\n"); | 390 | GNUNET_YES)) |
417 | while (line != NULL) { | 391 | { |
418 | sub_system = strtok (line, ","); | 392 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
419 | if (NULL == sub_system) | 393 | _("Unable to get filesize: %s.\n"), |
420 | break; | 394 | afsdir); |
421 | peer = strtok (NULL, ","); | 395 | return GNUNET_SYSERR; |
422 | if (NULL == peer) | 396 | } |
423 | break; | ||
424 | key = strtok (NULL, ","); | ||
425 | if (NULL == key) | ||
426 | break; | ||
427 | value = strtok (NULL, ","); | ||
428 | if (NULL == value) | ||
429 | break; | ||
430 | expiry = strtok (NULL, ","); | ||
431 | if (NULL == expiry) | ||
432 | break; | ||
433 | entry = GNUNET_new (struct GNUNET_PEERSTORE_Record); | ||
434 | entry->sub_system = GNUNET_strdup (sub_system); | ||
435 | entry->key = GNUNET_strdup (key); | ||
436 | { | ||
437 | size_t s; | ||
438 | char *o; | ||
439 | |||
440 | o = NULL; | ||
441 | s = GNUNET_STRINGS_base64_decode (peer, | ||
442 | strlen (peer), | ||
443 | (void**)&o); | ||
444 | if (sizeof (struct GNUNET_PeerIdentity) == s) | ||
445 | GNUNET_memcpy (&entry->peer, | ||
446 | o, | ||
447 | s); | ||
448 | else | ||
449 | GNUNET_break (0); | ||
450 | GNUNET_free_non_null (o); | ||
451 | } | ||
452 | entry->value_size = GNUNET_STRINGS_base64_decode (value, | ||
453 | strlen (value), | ||
454 | (void**)&entry->value); | ||
455 | if (GNUNET_SYSERR == | ||
456 | GNUNET_STRINGS_fancy_time_to_absolute (expiry, | ||
457 | &entry->expiry)) | ||
458 | { | ||
459 | GNUNET_free (entry->sub_system); | ||
460 | GNUNET_free (entry->key); | ||
461 | GNUNET_free (entry); | ||
462 | break; | ||
463 | } | ||
464 | peer_id = GNUNET_i2s (&entry->peer); | ||
465 | GNUNET_CRYPTO_hash (peer_id, | ||
466 | strlen (peer_id), | ||
467 | &hkey); | ||
468 | |||
469 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (plugin->hm, | ||
470 | &hkey, | ||
471 | entry, | ||
472 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
473 | 397 | ||
398 | buffer = GNUNET_malloc(size + 1); | ||
399 | |||
400 | if (GNUNET_SYSERR == GNUNET_DISK_file_read(fh, | ||
401 | buffer, | ||
402 | size)) | ||
403 | { | ||
404 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
405 | _("Unable to read file: %s.\n"), | ||
406 | afsdir); | ||
407 | GNUNET_DISK_file_close(fh); | ||
408 | GNUNET_free(buffer); | ||
409 | return GNUNET_SYSERR; | ||
410 | } | ||
411 | |||
412 | buffer[size] = '\0'; | ||
413 | GNUNET_DISK_file_close(fh); | ||
414 | if (0 < size) | ||
415 | { | ||
416 | line = strtok(buffer, "\n"); | ||
417 | while (line != NULL) | ||
418 | { | ||
419 | sub_system = strtok(line, ","); | ||
420 | if (NULL == sub_system) | ||
421 | break; | ||
422 | peer = strtok(NULL, ","); | ||
423 | if (NULL == peer) | ||
424 | break; | ||
425 | key = strtok(NULL, ","); | ||
426 | if (NULL == key) | ||
427 | break; | ||
428 | value = strtok(NULL, ","); | ||
429 | if (NULL == value) | ||
430 | break; | ||
431 | expiry = strtok(NULL, ","); | ||
432 | if (NULL == expiry) | ||
433 | break; | ||
434 | entry = GNUNET_new(struct GNUNET_PEERSTORE_Record); | ||
435 | entry->sub_system = GNUNET_strdup(sub_system); | ||
436 | entry->key = GNUNET_strdup(key); | ||
437 | { | ||
438 | size_t s; | ||
439 | char *o; | ||
440 | |||
441 | o = NULL; | ||
442 | s = GNUNET_STRINGS_base64_decode(peer, | ||
443 | strlen(peer), | ||
444 | (void**)&o); | ||
445 | if (sizeof(struct GNUNET_PeerIdentity) == s) | ||
446 | GNUNET_memcpy(&entry->peer, | ||
447 | o, | ||
448 | s); | ||
449 | else | ||
450 | GNUNET_break(0); | ||
451 | GNUNET_free_non_null(o); | ||
452 | } | ||
453 | entry->value_size = GNUNET_STRINGS_base64_decode(value, | ||
454 | strlen(value), | ||
455 | (void**)&entry->value); | ||
456 | if (GNUNET_SYSERR == | ||
457 | GNUNET_STRINGS_fancy_time_to_absolute(expiry, | ||
458 | &entry->expiry)) | ||
459 | { | ||
460 | GNUNET_free(entry->sub_system); | ||
461 | GNUNET_free(entry->key); | ||
462 | GNUNET_free(entry); | ||
463 | break; | ||
464 | } | ||
465 | peer_id = GNUNET_i2s(&entry->peer); | ||
466 | GNUNET_CRYPTO_hash(peer_id, | ||
467 | strlen(peer_id), | ||
468 | &hkey); | ||
469 | |||
470 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(plugin->hm, | ||
471 | &hkey, | ||
472 | entry, | ||
473 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
474 | } | ||
474 | } | 475 | } |
475 | } | 476 | GNUNET_free(buffer); |
476 | GNUNET_free (buffer); | ||
477 | return GNUNET_OK; | 477 | return GNUNET_OK; |
478 | } | 478 | } |
479 | 479 | ||
480 | static int | 480 | static int |
481 | store_and_free_entries (void *cls, | 481 | store_and_free_entries(void *cls, |
482 | const struct GNUNET_HashCode *key, | 482 | const struct GNUNET_HashCode *key, |
483 | void *value) | 483 | void *value) |
484 | { | 484 | { |
485 | struct GNUNET_DISK_FileHandle *fh = cls; | 485 | struct GNUNET_DISK_FileHandle *fh = cls; |
486 | struct GNUNET_PEERSTORE_Record *entry = value; | 486 | struct GNUNET_PEERSTORE_Record *entry = value; |
@@ -489,32 +489,31 @@ store_and_free_entries (void *cls, | |||
489 | const char *expiry; | 489 | const char *expiry; |
490 | char *val; | 490 | char *val; |
491 | 491 | ||
492 | GNUNET_STRINGS_base64_encode (entry->value, | 492 | GNUNET_STRINGS_base64_encode(entry->value, |
493 | entry->value_size, | 493 | entry->value_size, |
494 | &val); | 494 | &val); |
495 | expiry = GNUNET_STRINGS_absolute_time_to_string (entry->expiry); | 495 | expiry = GNUNET_STRINGS_absolute_time_to_string(entry->expiry); |
496 | GNUNET_STRINGS_base64_encode ((char*)&entry->peer, | 496 | GNUNET_STRINGS_base64_encode((char*)&entry->peer, |
497 | sizeof (struct GNUNET_PeerIdentity), | 497 | sizeof(struct GNUNET_PeerIdentity), |
498 | &peer); | 498 | &peer); |
499 | GNUNET_asprintf (&line, | 499 | GNUNET_asprintf(&line, |
500 | "%s,%s,%s,%s,%s", | 500 | "%s,%s,%s,%s,%s", |
501 | entry->sub_system, | 501 | entry->sub_system, |
502 | peer, | 502 | peer, |
503 | entry->key, | 503 | entry->key, |
504 | val, | 504 | val, |
505 | expiry); | 505 | expiry); |
506 | GNUNET_free (val); | 506 | GNUNET_free(val); |
507 | GNUNET_free (peer); | 507 | GNUNET_free(peer); |
508 | GNUNET_DISK_file_write (fh, | 508 | GNUNET_DISK_file_write(fh, |
509 | line, | 509 | line, |
510 | strlen (line)); | 510 | strlen(line)); |
511 | GNUNET_free (entry->sub_system); | 511 | GNUNET_free(entry->sub_system); |
512 | GNUNET_free (entry->key); | 512 | GNUNET_free(entry->key); |
513 | GNUNET_free (entry->value); | 513 | GNUNET_free(entry->value); |
514 | GNUNET_free (entry); | 514 | GNUNET_free(entry); |
515 | GNUNET_free (line); | 515 | GNUNET_free(line); |
516 | return GNUNET_YES; | 516 | return GNUNET_YES; |
517 | |||
518 | } | 517 | } |
519 | 518 | ||
520 | /** | 519 | /** |
@@ -523,27 +522,28 @@ store_and_free_entries (void *cls, | |||
523 | * @param plugin the plugin context (state for this module) | 522 | * @param plugin the plugin context (state for this module) |
524 | */ | 523 | */ |
525 | static void | 524 | static void |
526 | database_shutdown (struct Plugin *plugin) | 525 | database_shutdown(struct Plugin *plugin) |
527 | { | 526 | { |
528 | struct GNUNET_DISK_FileHandle *fh; | 527 | struct GNUNET_DISK_FileHandle *fh; |
529 | fh = GNUNET_DISK_file_open (plugin->fn, | 528 | |
530 | GNUNET_DISK_OPEN_CREATE | | 529 | fh = GNUNET_DISK_file_open(plugin->fn, |
531 | GNUNET_DISK_OPEN_TRUNCATE | | 530 | GNUNET_DISK_OPEN_CREATE | |
532 | GNUNET_DISK_OPEN_READWRITE, | 531 | GNUNET_DISK_OPEN_TRUNCATE | |
533 | GNUNET_DISK_PERM_USER_WRITE | | 532 | GNUNET_DISK_OPEN_READWRITE, |
534 | GNUNET_DISK_PERM_USER_READ); | 533 | GNUNET_DISK_PERM_USER_WRITE | |
534 | GNUNET_DISK_PERM_USER_READ); | ||
535 | if (NULL == fh) | 535 | if (NULL == fh) |
536 | { | 536 | { |
537 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 537 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
538 | _("Unable to initialize file: %s.\n"), | 538 | _("Unable to initialize file: %s.\n"), |
539 | plugin->fn); | 539 | plugin->fn); |
540 | return; | 540 | return; |
541 | } | 541 | } |
542 | GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, | 542 | GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, |
543 | &store_and_free_entries, | 543 | &store_and_free_entries, |
544 | fh); | 544 | fh); |
545 | GNUNET_CONTAINER_multihashmap_destroy (plugin->hm); | 545 | GNUNET_CONTAINER_multihashmap_destroy(plugin->hm); |
546 | GNUNET_DISK_file_close (fh); | 546 | GNUNET_DISK_file_close(fh); |
547 | } | 547 | } |
548 | 548 | ||
549 | 549 | ||
@@ -554,7 +554,7 @@ database_shutdown (struct Plugin *plugin) | |||
554 | * @return NULL on error, otherwise the plugin context | 554 | * @return NULL on error, otherwise the plugin context |
555 | */ | 555 | */ |
556 | void * | 556 | void * |
557 | libgnunet_plugin_peerstore_flat_init (void *cls) | 557 | libgnunet_plugin_peerstore_flat_init(void *cls) |
558 | { | 558 | { |
559 | static struct Plugin plugin; | 559 | static struct Plugin plugin; |
560 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 560 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
@@ -562,19 +562,19 @@ libgnunet_plugin_peerstore_flat_init (void *cls) | |||
562 | 562 | ||
563 | if (NULL != plugin.cfg) | 563 | if (NULL != plugin.cfg) |
564 | return NULL; /* can only initialize once! */ | 564 | return NULL; /* can only initialize once! */ |
565 | memset (&plugin, 0, sizeof (struct Plugin)); | 565 | memset(&plugin, 0, sizeof(struct Plugin)); |
566 | plugin.cfg = cfg; | 566 | plugin.cfg = cfg; |
567 | if (GNUNET_OK != database_setup (&plugin)) | 567 | if (GNUNET_OK != database_setup(&plugin)) |
568 | { | 568 | { |
569 | database_shutdown (&plugin); | 569 | database_shutdown(&plugin); |
570 | return NULL; | 570 | return NULL; |
571 | } | 571 | } |
572 | api = GNUNET_new (struct GNUNET_PEERSTORE_PluginFunctions); | 572 | api = GNUNET_new(struct GNUNET_PEERSTORE_PluginFunctions); |
573 | api->cls = &plugin; | 573 | api->cls = &plugin; |
574 | api->store_record = &peerstore_flat_store_record; | 574 | api->store_record = &peerstore_flat_store_record; |
575 | api->iterate_records = &peerstore_flat_iterate_records; | 575 | api->iterate_records = &peerstore_flat_iterate_records; |
576 | api->expire_records = &peerstore_flat_expire_records; | 576 | api->expire_records = &peerstore_flat_expire_records; |
577 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is running\n"); | 577 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is running\n"); |
578 | return api; | 578 | return api; |
579 | } | 579 | } |
580 | 580 | ||
@@ -586,15 +586,15 @@ libgnunet_plugin_peerstore_flat_init (void *cls) | |||
586 | * @return Always NULL | 586 | * @return Always NULL |
587 | */ | 587 | */ |
588 | void * | 588 | void * |
589 | libgnunet_plugin_peerstore_flat_done (void *cls) | 589 | libgnunet_plugin_peerstore_flat_done(void *cls) |
590 | { | 590 | { |
591 | struct GNUNET_PEERSTORE_PluginFunctions *api = cls; | 591 | struct GNUNET_PEERSTORE_PluginFunctions *api = cls; |
592 | struct Plugin *plugin = api->cls; | 592 | struct Plugin *plugin = api->cls; |
593 | 593 | ||
594 | database_shutdown (plugin); | 594 | database_shutdown(plugin); |
595 | plugin->cfg = NULL; | 595 | plugin->cfg = NULL; |
596 | GNUNET_free (api); | 596 | GNUNET_free(api); |
597 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is finished\n"); | 597 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is finished\n"); |
598 | return NULL; | 598 | return NULL; |
599 | } | 599 | } |
600 | 600 | ||
diff --git a/src/peerstore/plugin_peerstore_sqlite.c b/src/peerstore/plugin_peerstore_sqlite.c index 898db2231..5f6617ebc 100644 --- a/src/peerstore/plugin_peerstore_sqlite.c +++ b/src/peerstore/plugin_peerstore_sqlite.c | |||
@@ -49,16 +49,14 @@ | |||
49 | * a failure of the command 'cmd' on file 'filename' | 49 | * a failure of the command 'cmd' on file 'filename' |
50 | * with the message given by strerror(errno). | 50 | * with the message given by strerror(errno). |
51 | */ | 51 | */ |
52 | #define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, "peerstore-sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0) | 52 | #define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from(level, "peerstore-sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while (0) |
53 | 53 | ||
54 | #define LOG(kind,...) GNUNET_log_from (kind, "peerstore-sqlite", __VA_ARGS__) | 54 | #define LOG(kind, ...) GNUNET_log_from(kind, "peerstore-sqlite", __VA_ARGS__) |
55 | 55 | ||
56 | /** | 56 | /** |
57 | * Context for all functions in this plugin. | 57 | * Context for all functions in this plugin. |
58 | */ | 58 | */ |
59 | struct Plugin | 59 | struct Plugin { |
60 | { | ||
61 | |||
62 | /** | 60 | /** |
63 | * Configuration handle | 61 | * Configuration handle |
64 | */ | 62 | */ |
@@ -110,7 +108,6 @@ struct Plugin | |||
110 | * with given key | 108 | * with given key |
111 | */ | 109 | */ |
112 | sqlite3_stmt *delete_peerstoredata; | 110 | sqlite3_stmt *delete_peerstoredata; |
113 | |||
114 | }; | 111 | }; |
115 | 112 | ||
116 | 113 | ||
@@ -124,46 +121,46 @@ struct Plugin | |||
124 | * @return number of deleted records, #GNUNE_SYSERR on error | 121 | * @return number of deleted records, #GNUNE_SYSERR on error |
125 | */ | 122 | */ |
126 | static int | 123 | static int |
127 | peerstore_sqlite_delete_records (void *cls, | 124 | peerstore_sqlite_delete_records(void *cls, |
128 | const char *sub_system, | 125 | const char *sub_system, |
129 | const struct GNUNET_PeerIdentity *peer, | 126 | const struct GNUNET_PeerIdentity *peer, |
130 | const char *key) | 127 | const char *key) |
131 | { | 128 | { |
132 | struct Plugin *plugin = cls; | 129 | struct Plugin *plugin = cls; |
133 | sqlite3_stmt *stmt = plugin->delete_peerstoredata; | 130 | sqlite3_stmt *stmt = plugin->delete_peerstoredata; |
134 | struct GNUNET_SQ_QueryParam params[] = { | 131 | struct GNUNET_SQ_QueryParam params[] = { |
135 | GNUNET_SQ_query_param_string (sub_system), | 132 | GNUNET_SQ_query_param_string(sub_system), |
136 | GNUNET_SQ_query_param_auto_from_type (peer), | 133 | GNUNET_SQ_query_param_auto_from_type(peer), |
137 | GNUNET_SQ_query_param_string (key), | 134 | GNUNET_SQ_query_param_string(key), |
138 | GNUNET_SQ_query_param_end | 135 | GNUNET_SQ_query_param_end |
139 | }; | 136 | }; |
140 | int ret; | 137 | int ret; |
141 | 138 | ||
142 | if (GNUNET_OK != | 139 | if (GNUNET_OK != |
143 | GNUNET_SQ_bind (stmt, | 140 | GNUNET_SQ_bind(stmt, |
144 | params)) | 141 | params)) |
145 | { | 142 | { |
146 | LOG_SQLITE (plugin, | 143 | LOG_SQLITE(plugin, |
147 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 144 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
148 | "sqlite3_bind"); | 145 | "sqlite3_bind"); |
149 | GNUNET_SQ_reset (plugin->dbh, | 146 | GNUNET_SQ_reset(plugin->dbh, |
150 | stmt); | 147 | stmt); |
151 | return GNUNET_SYSERR; | 148 | return GNUNET_SYSERR; |
152 | } | 149 | } |
153 | if (SQLITE_DONE != | 150 | if (SQLITE_DONE != |
154 | sqlite3_step (stmt)) | 151 | sqlite3_step(stmt)) |
155 | { | 152 | { |
156 | LOG_SQLITE (plugin, | 153 | LOG_SQLITE(plugin, |
157 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 154 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
158 | "sqlite3_step"); | 155 | "sqlite3_step"); |
159 | ret = GNUNET_SYSERR; | 156 | ret = GNUNET_SYSERR; |
160 | } | 157 | } |
161 | else | 158 | else |
162 | { | 159 | { |
163 | ret = sqlite3_changes (plugin->dbh); | 160 | ret = sqlite3_changes(plugin->dbh); |
164 | } | 161 | } |
165 | GNUNET_SQ_reset (plugin->dbh, | 162 | GNUNET_SQ_reset(plugin->dbh, |
166 | stmt); | 163 | stmt); |
167 | return ret; | 164 | return ret; |
168 | } | 165 | } |
169 | 166 | ||
@@ -179,42 +176,42 @@ peerstore_sqlite_delete_records (void *cls, | |||
179 | * called | 176 | * called |
180 | */ | 177 | */ |
181 | static int | 178 | static int |
182 | peerstore_sqlite_expire_records (void *cls, struct GNUNET_TIME_Absolute now, | 179 | peerstore_sqlite_expire_records(void *cls, struct GNUNET_TIME_Absolute now, |
183 | GNUNET_PEERSTORE_Continuation cont, | 180 | GNUNET_PEERSTORE_Continuation cont, |
184 | void *cont_cls) | 181 | void *cont_cls) |
185 | { | 182 | { |
186 | struct Plugin *plugin = cls; | 183 | struct Plugin *plugin = cls; |
187 | sqlite3_stmt *stmt = plugin->expire_peerstoredata; | 184 | sqlite3_stmt *stmt = plugin->expire_peerstoredata; |
188 | struct GNUNET_SQ_QueryParam params[] = { | 185 | struct GNUNET_SQ_QueryParam params[] = { |
189 | GNUNET_SQ_query_param_absolute_time (&now), | 186 | GNUNET_SQ_query_param_absolute_time(&now), |
190 | GNUNET_SQ_query_param_end | 187 | GNUNET_SQ_query_param_end |
191 | }; | 188 | }; |
192 | 189 | ||
193 | if (GNUNET_OK != | 190 | if (GNUNET_OK != |
194 | GNUNET_SQ_bind (stmt, | 191 | GNUNET_SQ_bind(stmt, |
195 | params)) | 192 | params)) |
196 | { | 193 | { |
197 | LOG_SQLITE (plugin, | 194 | LOG_SQLITE(plugin, |
198 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 195 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
199 | "sqlite3_bind"); | 196 | "sqlite3_bind"); |
200 | GNUNET_SQ_reset (plugin->dbh, | 197 | GNUNET_SQ_reset(plugin->dbh, |
201 | stmt); | 198 | stmt); |
202 | return GNUNET_SYSERR; | 199 | return GNUNET_SYSERR; |
203 | } | 200 | } |
204 | if (SQLITE_DONE != sqlite3_step (stmt)) | 201 | if (SQLITE_DONE != sqlite3_step(stmt)) |
205 | { | 202 | { |
206 | LOG_SQLITE (plugin, | 203 | LOG_SQLITE(plugin, |
207 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 204 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
208 | "sqlite3_step"); | 205 | "sqlite3_step"); |
209 | GNUNET_SQ_reset (plugin->dbh, | 206 | GNUNET_SQ_reset(plugin->dbh, |
210 | stmt); | 207 | stmt); |
211 | return GNUNET_SYSERR; | 208 | return GNUNET_SYSERR; |
212 | } | 209 | } |
213 | if (NULL != cont) | 210 | if (NULL != cont) |
214 | cont (cont_cls, | 211 | cont(cont_cls, |
215 | sqlite3_changes (plugin->dbh)); | 212 | sqlite3_changes(plugin->dbh)); |
216 | GNUNET_SQ_reset (plugin->dbh, | 213 | GNUNET_SQ_reset(plugin->dbh, |
217 | stmt); | 214 | stmt); |
218 | return GNUNET_OK; | 215 | return GNUNET_OK; |
219 | } | 216 | } |
220 | 217 | ||
@@ -234,12 +231,12 @@ peerstore_sqlite_expire_records (void *cls, struct GNUNET_TIME_Absolute now, | |||
234 | * called | 231 | * called |
235 | */ | 232 | */ |
236 | static int | 233 | static int |
237 | peerstore_sqlite_iterate_records (void *cls, | 234 | peerstore_sqlite_iterate_records(void *cls, |
238 | const char *sub_system, | 235 | const char *sub_system, |
239 | const struct GNUNET_PeerIdentity *peer, | 236 | const struct GNUNET_PeerIdentity *peer, |
240 | const char *key, | 237 | const char *key, |
241 | GNUNET_PEERSTORE_Processor iter, | 238 | GNUNET_PEERSTORE_Processor iter, |
242 | void *iter_cls) | 239 | void *iter_cls) |
243 | { | 240 | { |
244 | struct Plugin *plugin = cls; | 241 | struct Plugin *plugin = cls; |
245 | sqlite3_stmt *stmt; | 242 | sqlite3_stmt *stmt; |
@@ -247,113 +244,113 @@ peerstore_sqlite_iterate_records (void *cls, | |||
247 | int sret; | 244 | int sret; |
248 | struct GNUNET_PEERSTORE_Record rec; | 245 | struct GNUNET_PEERSTORE_Record rec; |
249 | 246 | ||
250 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 247 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
251 | "Executing iterate request on sqlite db.\n"); | 248 | "Executing iterate request on sqlite db.\n"); |
252 | if (NULL == peer) | 249 | if (NULL == peer) |
253 | { | ||
254 | if (NULL == key) | ||
255 | { | ||
256 | struct GNUNET_SQ_QueryParam params[] = { | ||
257 | GNUNET_SQ_query_param_string (sub_system), | ||
258 | GNUNET_SQ_query_param_end | ||
259 | }; | ||
260 | |||
261 | stmt = plugin->select_peerstoredata; | ||
262 | err = GNUNET_SQ_bind (stmt, | ||
263 | params); | ||
264 | } | ||
265 | else | ||
266 | { | 250 | { |
267 | struct GNUNET_SQ_QueryParam params[] = { | 251 | if (NULL == key) |
268 | GNUNET_SQ_query_param_string (sub_system), | 252 | { |
269 | GNUNET_SQ_query_param_string (key), | 253 | struct GNUNET_SQ_QueryParam params[] = { |
270 | GNUNET_SQ_query_param_end | 254 | GNUNET_SQ_query_param_string(sub_system), |
271 | }; | 255 | GNUNET_SQ_query_param_end |
272 | 256 | }; | |
273 | stmt = plugin->select_peerstoredata_by_key; | 257 | |
274 | err = GNUNET_SQ_bind (stmt, | 258 | stmt = plugin->select_peerstoredata; |
275 | params); | 259 | err = GNUNET_SQ_bind(stmt, |
260 | params); | ||
261 | } | ||
262 | else | ||
263 | { | ||
264 | struct GNUNET_SQ_QueryParam params[] = { | ||
265 | GNUNET_SQ_query_param_string(sub_system), | ||
266 | GNUNET_SQ_query_param_string(key), | ||
267 | GNUNET_SQ_query_param_end | ||
268 | }; | ||
269 | |||
270 | stmt = plugin->select_peerstoredata_by_key; | ||
271 | err = GNUNET_SQ_bind(stmt, | ||
272 | params); | ||
273 | } | ||
276 | } | 274 | } |
277 | } | ||
278 | else | 275 | else |
279 | { | ||
280 | if (NULL == key) | ||
281 | { | 276 | { |
282 | struct GNUNET_SQ_QueryParam params[] = { | 277 | if (NULL == key) |
283 | GNUNET_SQ_query_param_string (sub_system), | 278 | { |
284 | GNUNET_SQ_query_param_auto_from_type (peer), | 279 | struct GNUNET_SQ_QueryParam params[] = { |
285 | GNUNET_SQ_query_param_end | 280 | GNUNET_SQ_query_param_string(sub_system), |
286 | }; | 281 | GNUNET_SQ_query_param_auto_from_type(peer), |
287 | 282 | GNUNET_SQ_query_param_end | |
288 | stmt = plugin->select_peerstoredata_by_pid; | 283 | }; |
289 | err = GNUNET_SQ_bind (stmt, | 284 | |
290 | params); | 285 | stmt = plugin->select_peerstoredata_by_pid; |
286 | err = GNUNET_SQ_bind(stmt, | ||
287 | params); | ||
288 | } | ||
289 | else | ||
290 | { | ||
291 | struct GNUNET_SQ_QueryParam params[] = { | ||
292 | GNUNET_SQ_query_param_string(sub_system), | ||
293 | GNUNET_SQ_query_param_auto_from_type(peer), | ||
294 | GNUNET_SQ_query_param_string(key), | ||
295 | GNUNET_SQ_query_param_end | ||
296 | }; | ||
297 | |||
298 | stmt = plugin->select_peerstoredata_by_all; | ||
299 | err = GNUNET_SQ_bind(stmt, | ||
300 | params); | ||
301 | } | ||
291 | } | 302 | } |
292 | else | ||
293 | { | ||
294 | struct GNUNET_SQ_QueryParam params[] = { | ||
295 | GNUNET_SQ_query_param_string (sub_system), | ||
296 | GNUNET_SQ_query_param_auto_from_type (peer), | ||
297 | GNUNET_SQ_query_param_string (key), | ||
298 | GNUNET_SQ_query_param_end | ||
299 | }; | ||
300 | |||
301 | stmt = plugin->select_peerstoredata_by_all; | ||
302 | err = GNUNET_SQ_bind (stmt, | ||
303 | params); | ||
304 | } | ||
305 | } | ||
306 | 303 | ||
307 | if (GNUNET_OK != err) | 304 | if (GNUNET_OK != err) |
308 | { | 305 | { |
309 | LOG_SQLITE (plugin, | 306 | LOG_SQLITE(plugin, |
310 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 307 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
311 | "sqlite3_bind_XXXX"); | 308 | "sqlite3_bind_XXXX"); |
312 | GNUNET_SQ_reset (plugin->dbh, | 309 | GNUNET_SQ_reset(plugin->dbh, |
313 | stmt); | 310 | stmt); |
314 | return GNUNET_SYSERR; | 311 | return GNUNET_SYSERR; |
315 | } | 312 | } |
316 | 313 | ||
317 | err = 0; | 314 | err = 0; |
318 | while (SQLITE_ROW == (sret = sqlite3_step (stmt))) | 315 | while (SQLITE_ROW == (sret = sqlite3_step(stmt))) |
319 | { | ||
320 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
321 | "Returning a matched record.\n"); | ||
322 | struct GNUNET_SQ_ResultSpec rs[] = { | ||
323 | GNUNET_SQ_result_spec_string (&rec.sub_system), | ||
324 | GNUNET_SQ_result_spec_auto_from_type (&rec.peer), | ||
325 | GNUNET_SQ_result_spec_string (&rec.key), | ||
326 | GNUNET_SQ_result_spec_variable_size (&rec.value, &rec.value_size), | ||
327 | GNUNET_SQ_result_spec_absolute_time (&rec.expiry), | ||
328 | GNUNET_SQ_result_spec_end | ||
329 | }; | ||
330 | |||
331 | if (GNUNET_OK != | ||
332 | GNUNET_SQ_extract_result (stmt, | ||
333 | rs)) | ||
334 | { | 316 | { |
335 | GNUNET_break (0); | 317 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
336 | break; | 318 | "Returning a matched record.\n"); |
319 | struct GNUNET_SQ_ResultSpec rs[] = { | ||
320 | GNUNET_SQ_result_spec_string(&rec.sub_system), | ||
321 | GNUNET_SQ_result_spec_auto_from_type(&rec.peer), | ||
322 | GNUNET_SQ_result_spec_string(&rec.key), | ||
323 | GNUNET_SQ_result_spec_variable_size(&rec.value, &rec.value_size), | ||
324 | GNUNET_SQ_result_spec_absolute_time(&rec.expiry), | ||
325 | GNUNET_SQ_result_spec_end | ||
326 | }; | ||
327 | |||
328 | if (GNUNET_OK != | ||
329 | GNUNET_SQ_extract_result(stmt, | ||
330 | rs)) | ||
331 | { | ||
332 | GNUNET_break(0); | ||
333 | break; | ||
334 | } | ||
335 | if (NULL != iter) | ||
336 | iter(iter_cls, | ||
337 | &rec, | ||
338 | NULL); | ||
339 | GNUNET_SQ_cleanup_result(rs); | ||
337 | } | 340 | } |
338 | if (NULL != iter) | ||
339 | iter (iter_cls, | ||
340 | &rec, | ||
341 | NULL); | ||
342 | GNUNET_SQ_cleanup_result (rs); | ||
343 | } | ||
344 | if (SQLITE_DONE != sret) | 341 | if (SQLITE_DONE != sret) |
345 | { | 342 | { |
346 | LOG_SQLITE (plugin, | 343 | LOG_SQLITE(plugin, |
347 | GNUNET_ERROR_TYPE_ERROR, | 344 | GNUNET_ERROR_TYPE_ERROR, |
348 | "sqlite_step"); | 345 | "sqlite_step"); |
349 | err = 1; | 346 | err = 1; |
350 | } | 347 | } |
351 | GNUNET_SQ_reset (plugin->dbh, | 348 | GNUNET_SQ_reset(plugin->dbh, |
352 | stmt); | 349 | stmt); |
353 | if (NULL != iter) | 350 | if (NULL != iter) |
354 | iter (iter_cls, | 351 | iter(iter_cls, |
355 | NULL, | 352 | NULL, |
356 | err ? "sqlite error" : NULL); | 353 | err ? "sqlite error" : NULL); |
357 | return GNUNET_OK; | 354 | return GNUNET_OK; |
358 | } | 355 | } |
359 | 356 | ||
@@ -376,52 +373,52 @@ peerstore_sqlite_iterate_records (void *cls, | |||
376 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR and cont is not called | 373 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR and cont is not called |
377 | */ | 374 | */ |
378 | static int | 375 | static int |
379 | peerstore_sqlite_store_record (void *cls, | 376 | peerstore_sqlite_store_record(void *cls, |
380 | const char *sub_system, | 377 | const char *sub_system, |
381 | const struct GNUNET_PeerIdentity *peer, | 378 | const struct GNUNET_PeerIdentity *peer, |
382 | const char *key, | 379 | const char *key, |
383 | const void *value, | 380 | const void *value, |
384 | size_t size, | 381 | size_t size, |
385 | struct GNUNET_TIME_Absolute expiry, | 382 | struct GNUNET_TIME_Absolute expiry, |
386 | enum GNUNET_PEERSTORE_StoreOption options, | 383 | enum GNUNET_PEERSTORE_StoreOption options, |
387 | GNUNET_PEERSTORE_Continuation cont, | 384 | GNUNET_PEERSTORE_Continuation cont, |
388 | void *cont_cls) | 385 | void *cont_cls) |
389 | { | 386 | { |
390 | struct Plugin *plugin = cls; | 387 | struct Plugin *plugin = cls; |
391 | sqlite3_stmt *stmt = plugin->insert_peerstoredata; | 388 | sqlite3_stmt *stmt = plugin->insert_peerstoredata; |
392 | struct GNUNET_SQ_QueryParam params[] = { | 389 | struct GNUNET_SQ_QueryParam params[] = { |
393 | GNUNET_SQ_query_param_string (sub_system), | 390 | GNUNET_SQ_query_param_string(sub_system), |
394 | GNUNET_SQ_query_param_auto_from_type (peer), | 391 | GNUNET_SQ_query_param_auto_from_type(peer), |
395 | GNUNET_SQ_query_param_string (key), | 392 | GNUNET_SQ_query_param_string(key), |
396 | GNUNET_SQ_query_param_fixed_size (value, size), | 393 | GNUNET_SQ_query_param_fixed_size(value, size), |
397 | GNUNET_SQ_query_param_absolute_time (&expiry), | 394 | GNUNET_SQ_query_param_absolute_time(&expiry), |
398 | GNUNET_SQ_query_param_end | 395 | GNUNET_SQ_query_param_end |
399 | }; | 396 | }; |
400 | 397 | ||
401 | if (GNUNET_PEERSTORE_STOREOPTION_REPLACE == options) | 398 | if (GNUNET_PEERSTORE_STOREOPTION_REPLACE == options) |
402 | { | 399 | { |
403 | peerstore_sqlite_delete_records (cls, | 400 | peerstore_sqlite_delete_records(cls, |
404 | sub_system, | 401 | sub_system, |
405 | peer, | 402 | peer, |
406 | key); | 403 | key); |
407 | } | 404 | } |
408 | if (GNUNET_OK != | 405 | if (GNUNET_OK != |
409 | GNUNET_SQ_bind (stmt, | 406 | GNUNET_SQ_bind(stmt, |
410 | params)) | 407 | params)) |
411 | LOG_SQLITE (plugin, | 408 | LOG_SQLITE(plugin, |
412 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 409 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
413 | "sqlite3_bind"); | 410 | "sqlite3_bind"); |
414 | else if (SQLITE_DONE != sqlite3_step (stmt)) | 411 | else if (SQLITE_DONE != sqlite3_step(stmt)) |
415 | { | 412 | { |
416 | LOG_SQLITE (plugin, | 413 | LOG_SQLITE(plugin, |
417 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 414 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
418 | "sqlite3_step"); | 415 | "sqlite3_step"); |
419 | } | 416 | } |
420 | GNUNET_SQ_reset (plugin->dbh, | 417 | GNUNET_SQ_reset(plugin->dbh, |
421 | stmt); | 418 | stmt); |
422 | if (NULL != cont) | 419 | if (NULL != cont) |
423 | cont (cont_cls, | 420 | cont(cont_cls, |
424 | GNUNET_OK); | 421 | GNUNET_OK); |
425 | return GNUNET_OK; | 422 | return GNUNET_OK; |
426 | } | 423 | } |
427 | 424 | ||
@@ -434,25 +431,25 @@ peerstore_sqlite_store_record (void *cls, | |||
434 | * @return 0 on success | 431 | * @return 0 on success |
435 | */ | 432 | */ |
436 | static int | 433 | static int |
437 | sql_exec (sqlite3 *dbh, | 434 | sql_exec(sqlite3 *dbh, |
438 | const char *sql) | 435 | const char *sql) |
439 | { | 436 | { |
440 | int result; | 437 | int result; |
441 | 438 | ||
442 | result = sqlite3_exec (dbh, | 439 | result = sqlite3_exec(dbh, |
443 | sql, | 440 | sql, |
444 | NULL, | 441 | NULL, |
445 | NULL, | 442 | NULL, |
446 | NULL); | 443 | NULL); |
447 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 444 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
448 | "Executed `%s' / %d\n", | 445 | "Executed `%s' / %d\n", |
449 | sql, | 446 | sql, |
450 | result); | 447 | result); |
451 | if (SQLITE_OK != result) | 448 | if (SQLITE_OK != result) |
452 | LOG (GNUNET_ERROR_TYPE_ERROR, | 449 | LOG(GNUNET_ERROR_TYPE_ERROR, |
453 | _("Error executing SQL query: %s\n %s\n"), | 450 | _("Error executing SQL query: %s\n %s\n"), |
454 | sqlite3_errmsg (dbh), | 451 | sqlite3_errmsg(dbh), |
455 | sql); | 452 | sql); |
456 | return result; | 453 | return result; |
457 | } | 454 | } |
458 | 455 | ||
@@ -466,28 +463,28 @@ sql_exec (sqlite3 *dbh, | |||
466 | * @return 0 on success | 463 | * @return 0 on success |
467 | */ | 464 | */ |
468 | static int | 465 | static int |
469 | sql_prepare (sqlite3 *dbh, | 466 | sql_prepare(sqlite3 *dbh, |
470 | const char *sql, | 467 | const char *sql, |
471 | sqlite3_stmt ** stmt) | 468 | sqlite3_stmt ** stmt) |
472 | { | 469 | { |
473 | char *tail; | 470 | char *tail; |
474 | int result; | 471 | int result; |
475 | 472 | ||
476 | result = sqlite3_prepare_v2 (dbh, | 473 | result = sqlite3_prepare_v2(dbh, |
477 | sql, | 474 | sql, |
478 | strlen (sql), | 475 | strlen(sql), |
479 | stmt, | 476 | stmt, |
480 | (const char **) &tail); | 477 | (const char **)&tail); |
481 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 478 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
482 | "Prepared `%s' / %p: %d\n", | 479 | "Prepared `%s' / %p: %d\n", |
483 | sql, | 480 | sql, |
484 | *stmt, | 481 | *stmt, |
485 | result); | 482 | result); |
486 | if (SQLITE_OK != result) | 483 | if (SQLITE_OK != result) |
487 | LOG (GNUNET_ERROR_TYPE_ERROR, | 484 | LOG(GNUNET_ERROR_TYPE_ERROR, |
488 | _("Error preparing SQL query: %s\n %s\n"), | 485 | _("Error preparing SQL query: %s\n %s\n"), |
489 | sqlite3_errmsg (dbh), | 486 | sqlite3_errmsg(dbh), |
490 | sql); | 487 | sql); |
491 | return result; | 488 | return result; |
492 | } | 489 | } |
493 | 490 | ||
@@ -501,110 +498,110 @@ sql_prepare (sqlite3 *dbh, | |||
501 | * @return #GNUNET_OK on success | 498 | * @return #GNUNET_OK on success |
502 | */ | 499 | */ |
503 | static int | 500 | static int |
504 | database_setup (struct Plugin *plugin) | 501 | database_setup(struct Plugin *plugin) |
505 | { | 502 | { |
506 | char *filename; | 503 | char *filename; |
507 | 504 | ||
508 | if (GNUNET_OK != | 505 | if (GNUNET_OK != |
509 | GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, | 506 | GNUNET_CONFIGURATION_get_value_filename(plugin->cfg, |
510 | "peerstore-sqlite", | 507 | "peerstore-sqlite", |
511 | "FILENAME", | 508 | "FILENAME", |
512 | &filename)) | 509 | &filename)) |
513 | { | ||
514 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
515 | "peerstore-sqlite", | ||
516 | "FILENAME"); | ||
517 | return GNUNET_SYSERR; | ||
518 | } | ||
519 | if (GNUNET_OK != GNUNET_DISK_file_test (filename)) | ||
520 | { | ||
521 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (filename)) | ||
522 | { | 510 | { |
523 | GNUNET_break (0); | 511 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
524 | GNUNET_free (filename); | 512 | "peerstore-sqlite", |
513 | "FILENAME"); | ||
525 | return GNUNET_SYSERR; | 514 | return GNUNET_SYSERR; |
526 | } | 515 | } |
527 | } | 516 | if (GNUNET_OK != GNUNET_DISK_file_test(filename)) |
517 | { | ||
518 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(filename)) | ||
519 | { | ||
520 | GNUNET_break(0); | ||
521 | GNUNET_free(filename); | ||
522 | return GNUNET_SYSERR; | ||
523 | } | ||
524 | } | ||
528 | /* filename should be UTF-8-encoded. If it isn't, it's a bug */ | 525 | /* filename should be UTF-8-encoded. If it isn't, it's a bug */ |
529 | plugin->fn = filename; | 526 | plugin->fn = filename; |
530 | /* Open database and precompile statements */ | 527 | /* Open database and precompile statements */ |
531 | if (SQLITE_OK != sqlite3_open (plugin->fn, | 528 | if (SQLITE_OK != sqlite3_open(plugin->fn, |
532 | &plugin->dbh)) | 529 | &plugin->dbh)) |
533 | { | 530 | { |
534 | LOG (GNUNET_ERROR_TYPE_ERROR, | 531 | LOG(GNUNET_ERROR_TYPE_ERROR, |
535 | _("Unable to initialize SQLite: %s.\n"), | 532 | _("Unable to initialize SQLite: %s.\n"), |
536 | sqlite3_errmsg (plugin->dbh)); | 533 | sqlite3_errmsg(plugin->dbh)); |
537 | return GNUNET_SYSERR; | 534 | return GNUNET_SYSERR; |
538 | } | 535 | } |
539 | sql_exec (plugin->dbh, | 536 | sql_exec(plugin->dbh, |
540 | "PRAGMA temp_store=MEMORY"); | 537 | "PRAGMA temp_store=MEMORY"); |
541 | sql_exec (plugin->dbh, | 538 | sql_exec(plugin->dbh, |
542 | "PRAGMA synchronous=OFF"); | 539 | "PRAGMA synchronous=OFF"); |
543 | sql_exec (plugin->dbh, | 540 | sql_exec(plugin->dbh, |
544 | "PRAGMA legacy_file_format=OFF"); | 541 | "PRAGMA legacy_file_format=OFF"); |
545 | sql_exec (plugin->dbh, | 542 | sql_exec(plugin->dbh, |
546 | "PRAGMA auto_vacuum=INCREMENTAL"); | 543 | "PRAGMA auto_vacuum=INCREMENTAL"); |
547 | sql_exec (plugin->dbh, | 544 | sql_exec(plugin->dbh, |
548 | "PRAGMA encoding=\"UTF-8\""); | 545 | "PRAGMA encoding=\"UTF-8\""); |
549 | sql_exec (plugin->dbh, | 546 | sql_exec(plugin->dbh, |
550 | "PRAGMA page_size=4096"); | 547 | "PRAGMA page_size=4096"); |
551 | sqlite3_busy_timeout (plugin->dbh, | 548 | sqlite3_busy_timeout(plugin->dbh, |
552 | BUSY_TIMEOUT_MS); | 549 | BUSY_TIMEOUT_MS); |
553 | /* Create tables */ | 550 | /* Create tables */ |
554 | sql_exec (plugin->dbh, | 551 | sql_exec(plugin->dbh, |
555 | "CREATE TABLE IF NOT EXISTS peerstoredata (\n" | 552 | "CREATE TABLE IF NOT EXISTS peerstoredata (\n" |
556 | " sub_system TEXT NOT NULL,\n" | 553 | " sub_system TEXT NOT NULL,\n" |
557 | " peer_id BLOB NOT NULL,\n" | 554 | " peer_id BLOB NOT NULL,\n" |
558 | " key TEXT NOT NULL,\n" | 555 | " key TEXT NOT NULL,\n" |
559 | " value BLOB NULL,\n" | 556 | " value BLOB NULL,\n" |
560 | " expiry INT8 NOT NULL" ");"); | 557 | " expiry INT8 NOT NULL" ");"); |
561 | /* Create Indices */ | 558 | /* Create Indices */ |
562 | if (SQLITE_OK != | 559 | if (SQLITE_OK != |
563 | sqlite3_exec (plugin->dbh, | 560 | sqlite3_exec(plugin->dbh, |
564 | "CREATE INDEX IF NOT EXISTS peerstoredata_key_index ON peerstoredata (sub_system, peer_id, key)", | 561 | "CREATE INDEX IF NOT EXISTS peerstoredata_key_index ON peerstoredata (sub_system, peer_id, key)", |
565 | NULL, | 562 | NULL, |
566 | NULL, | 563 | NULL, |
567 | NULL)) | 564 | NULL)) |
568 | { | 565 | { |
569 | LOG (GNUNET_ERROR_TYPE_ERROR, | 566 | LOG(GNUNET_ERROR_TYPE_ERROR, |
570 | _("Unable to create indices: %s.\n"), | 567 | _("Unable to create indices: %s.\n"), |
571 | sqlite3_errmsg (plugin->dbh)); | 568 | sqlite3_errmsg(plugin->dbh)); |
572 | return GNUNET_SYSERR; | 569 | return GNUNET_SYSERR; |
573 | } | 570 | } |
574 | /* Prepare statements */ | 571 | /* Prepare statements */ |
575 | 572 | ||
576 | sql_prepare (plugin->dbh, | 573 | sql_prepare(plugin->dbh, |
577 | "INSERT INTO peerstoredata (sub_system, peer_id, key, value, expiry)" | 574 | "INSERT INTO peerstoredata (sub_system, peer_id, key, value, expiry)" |
578 | " VALUES (?,?,?,?,?);", | 575 | " VALUES (?,?,?,?,?);", |
579 | &plugin->insert_peerstoredata); | 576 | &plugin->insert_peerstoredata); |
580 | sql_prepare (plugin->dbh, | 577 | sql_prepare(plugin->dbh, |
581 | "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" | 578 | "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" |
582 | " WHERE sub_system = ?", | 579 | " WHERE sub_system = ?", |
583 | &plugin->select_peerstoredata); | 580 | &plugin->select_peerstoredata); |
584 | sql_prepare (plugin->dbh, | 581 | sql_prepare(plugin->dbh, |
585 | "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" | 582 | "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" |
586 | " WHERE sub_system = ?" | 583 | " WHERE sub_system = ?" |
587 | " AND peer_id = ?", | 584 | " AND peer_id = ?", |
588 | &plugin->select_peerstoredata_by_pid); | 585 | &plugin->select_peerstoredata_by_pid); |
589 | sql_prepare (plugin->dbh, | 586 | sql_prepare(plugin->dbh, |
590 | "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" | 587 | "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" |
591 | " WHERE sub_system = ?" | 588 | " WHERE sub_system = ?" |
592 | " AND key = ?", | 589 | " AND key = ?", |
593 | &plugin->select_peerstoredata_by_key); | 590 | &plugin->select_peerstoredata_by_key); |
594 | sql_prepare (plugin->dbh, | 591 | sql_prepare(plugin->dbh, |
595 | "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" | 592 | "SELECT sub_system,peer_id,key,value,expiry FROM peerstoredata" |
596 | " WHERE sub_system = ?" | 593 | " WHERE sub_system = ?" |
597 | " AND peer_id = ?" " AND key = ?", | 594 | " AND peer_id = ?" " AND key = ?", |
598 | &plugin->select_peerstoredata_by_all); | 595 | &plugin->select_peerstoredata_by_all); |
599 | sql_prepare (plugin->dbh, | 596 | sql_prepare(plugin->dbh, |
600 | "DELETE FROM peerstoredata" | 597 | "DELETE FROM peerstoredata" |
601 | " WHERE expiry < ?", | 598 | " WHERE expiry < ?", |
602 | &plugin->expire_peerstoredata); | 599 | &plugin->expire_peerstoredata); |
603 | sql_prepare (plugin->dbh, | 600 | sql_prepare(plugin->dbh, |
604 | "DELETE FROM peerstoredata" | 601 | "DELETE FROM peerstoredata" |
605 | " WHERE sub_system = ?" | 602 | " WHERE sub_system = ?" |
606 | " AND peer_id = ?" " AND key = ?", | 603 | " AND peer_id = ?" " AND key = ?", |
607 | &plugin->delete_peerstoredata); | 604 | &plugin->delete_peerstoredata); |
608 | return GNUNET_OK; | 605 | return GNUNET_OK; |
609 | } | 606 | } |
610 | 607 | ||
@@ -615,26 +612,26 @@ database_setup (struct Plugin *plugin) | |||
615 | * @param plugin the plugin context (state for this module) | 612 | * @param plugin the plugin context (state for this module) |
616 | */ | 613 | */ |
617 | static void | 614 | static void |
618 | database_shutdown (struct Plugin *plugin) | 615 | database_shutdown(struct Plugin *plugin) |
619 | { | 616 | { |
620 | int result; | 617 | int result; |
621 | sqlite3_stmt *stmt; | 618 | sqlite3_stmt *stmt; |
622 | 619 | ||
623 | while (NULL != (stmt = sqlite3_next_stmt (plugin->dbh, | 620 | while (NULL != (stmt = sqlite3_next_stmt(plugin->dbh, |
624 | NULL))) | 621 | NULL))) |
625 | { | 622 | { |
626 | result = sqlite3_finalize (stmt); | 623 | result = sqlite3_finalize(stmt); |
627 | if (SQLITE_OK != result) | 624 | if (SQLITE_OK != result) |
628 | LOG (GNUNET_ERROR_TYPE_WARNING, | 625 | LOG(GNUNET_ERROR_TYPE_WARNING, |
629 | "Failed to close statement %p: %d\n", | 626 | "Failed to close statement %p: %d\n", |
630 | stmt, | 627 | stmt, |
631 | result); | 628 | result); |
632 | } | 629 | } |
633 | if (SQLITE_OK != sqlite3_close (plugin->dbh)) | 630 | if (SQLITE_OK != sqlite3_close(plugin->dbh)) |
634 | LOG_SQLITE (plugin, | 631 | LOG_SQLITE(plugin, |
635 | GNUNET_ERROR_TYPE_ERROR, | 632 | GNUNET_ERROR_TYPE_ERROR, |
636 | "sqlite3_close"); | 633 | "sqlite3_close"); |
637 | GNUNET_free_non_null (plugin->fn); | 634 | GNUNET_free_non_null(plugin->fn); |
638 | } | 635 | } |
639 | 636 | ||
640 | 637 | ||
@@ -645,7 +642,7 @@ database_shutdown (struct Plugin *plugin) | |||
645 | * @return NULL on error, otherwise the plugin context | 642 | * @return NULL on error, otherwise the plugin context |
646 | */ | 643 | */ |
647 | void * | 644 | void * |
648 | libgnunet_plugin_peerstore_sqlite_init (void *cls) | 645 | libgnunet_plugin_peerstore_sqlite_init(void *cls) |
649 | { | 646 | { |
650 | static struct Plugin plugin; | 647 | static struct Plugin plugin; |
651 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 648 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
@@ -653,22 +650,22 @@ libgnunet_plugin_peerstore_sqlite_init (void *cls) | |||
653 | 650 | ||
654 | if (NULL != plugin.cfg) | 651 | if (NULL != plugin.cfg) |
655 | return NULL; /* can only initialize once! */ | 652 | return NULL; /* can only initialize once! */ |
656 | memset (&plugin, | 653 | memset(&plugin, |
657 | 0, | 654 | 0, |
658 | sizeof (struct Plugin)); | 655 | sizeof(struct Plugin)); |
659 | plugin.cfg = cfg; | 656 | plugin.cfg = cfg; |
660 | if (GNUNET_OK != database_setup (&plugin)) | 657 | if (GNUNET_OK != database_setup(&plugin)) |
661 | { | 658 | { |
662 | database_shutdown (&plugin); | 659 | database_shutdown(&plugin); |
663 | return NULL; | 660 | return NULL; |
664 | } | 661 | } |
665 | api = GNUNET_new (struct GNUNET_PEERSTORE_PluginFunctions); | 662 | api = GNUNET_new(struct GNUNET_PEERSTORE_PluginFunctions); |
666 | api->cls = &plugin; | 663 | api->cls = &plugin; |
667 | api->store_record = &peerstore_sqlite_store_record; | 664 | api->store_record = &peerstore_sqlite_store_record; |
668 | api->iterate_records = &peerstore_sqlite_iterate_records; | 665 | api->iterate_records = &peerstore_sqlite_iterate_records; |
669 | api->expire_records = &peerstore_sqlite_expire_records; | 666 | api->expire_records = &peerstore_sqlite_expire_records; |
670 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 667 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
671 | "Sqlite plugin is running\n"); | 668 | "Sqlite plugin is running\n"); |
672 | return api; | 669 | return api; |
673 | } | 670 | } |
674 | 671 | ||
@@ -680,16 +677,16 @@ libgnunet_plugin_peerstore_sqlite_init (void *cls) | |||
680 | * @return Always NULL | 677 | * @return Always NULL |
681 | */ | 678 | */ |
682 | void * | 679 | void * |
683 | libgnunet_plugin_peerstore_sqlite_done (void *cls) | 680 | libgnunet_plugin_peerstore_sqlite_done(void *cls) |
684 | { | 681 | { |
685 | struct GNUNET_PEERSTORE_PluginFunctions *api = cls; | 682 | struct GNUNET_PEERSTORE_PluginFunctions *api = cls; |
686 | struct Plugin *plugin = api->cls; | 683 | struct Plugin *plugin = api->cls; |
687 | 684 | ||
688 | database_shutdown (plugin); | 685 | database_shutdown(plugin); |
689 | plugin->cfg = NULL; | 686 | plugin->cfg = NULL; |
690 | GNUNET_free (api); | 687 | GNUNET_free(api); |
691 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 688 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
692 | "Sqlite plugin is finished\n"); | 689 | "Sqlite plugin is finished\n"); |
693 | return NULL; | 690 | return NULL; |
694 | } | 691 | } |
695 | 692 | ||
diff --git a/src/peerstore/test_peerstore_api_iterate.c b/src/peerstore/test_peerstore_api_iterate.c index a19aad121..185fc8225 100644 --- a/src/peerstore/test_peerstore_api_iterate.c +++ b/src/peerstore/test_peerstore_api_iterate.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file peerstore/test_peerstore_api_iterate.c | 21 | * @file peerstore/test_peerstore_api_iterate.c |
22 | * @brief testcase for peerstore iteration operation | 22 | * @brief testcase for peerstore iteration operation |
@@ -42,132 +42,132 @@ static int count = 0; | |||
42 | 42 | ||
43 | 43 | ||
44 | static void | 44 | static void |
45 | iter3_cb (void *cls, | 45 | iter3_cb(void *cls, |
46 | const struct GNUNET_PEERSTORE_Record *record, | 46 | const struct GNUNET_PEERSTORE_Record *record, |
47 | const char *emsg) | 47 | const char *emsg) |
48 | { | 48 | { |
49 | if (NULL != emsg) | 49 | if (NULL != emsg) |
50 | { | 50 | { |
51 | GNUNET_PEERSTORE_iterate_cancel (ic); | 51 | GNUNET_PEERSTORE_iterate_cancel(ic); |
52 | return; | 52 | return; |
53 | } | 53 | } |
54 | if (NULL != record) | 54 | if (NULL != record) |
55 | { | 55 | { |
56 | count++; | 56 | count++; |
57 | return; | 57 | return; |
58 | } | 58 | } |
59 | GNUNET_assert (count == 3); | 59 | GNUNET_assert(count == 3); |
60 | ok = 0; | 60 | ok = 0; |
61 | GNUNET_PEERSTORE_disconnect (h, GNUNET_NO); | 61 | GNUNET_PEERSTORE_disconnect(h, GNUNET_NO); |
62 | GNUNET_SCHEDULER_shutdown (); | 62 | GNUNET_SCHEDULER_shutdown(); |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | static void | 66 | static void |
67 | iter2_cb (void *cls, | 67 | iter2_cb(void *cls, |
68 | const struct GNUNET_PEERSTORE_Record *record, | 68 | const struct GNUNET_PEERSTORE_Record *record, |
69 | const char *emsg) | 69 | const char *emsg) |
70 | { | 70 | { |
71 | if (NULL != emsg) | 71 | if (NULL != emsg) |
72 | { | 72 | { |
73 | GNUNET_PEERSTORE_iterate_cancel (ic); | 73 | GNUNET_PEERSTORE_iterate_cancel(ic); |
74 | return; | 74 | return; |
75 | } | 75 | } |
76 | if (NULL != record) | 76 | if (NULL != record) |
77 | { | 77 | { |
78 | count++; | 78 | count++; |
79 | return; | 79 | return; |
80 | } | 80 | } |
81 | GNUNET_assert (count == 2); | 81 | GNUNET_assert(count == 2); |
82 | count = 0; | 82 | count = 0; |
83 | ic = GNUNET_PEERSTORE_iterate (h, | 83 | ic = GNUNET_PEERSTORE_iterate(h, |
84 | ss, | 84 | ss, |
85 | NULL, | 85 | NULL, |
86 | NULL, | 86 | NULL, |
87 | &iter3_cb, | 87 | &iter3_cb, |
88 | NULL); | 88 | NULL); |
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
92 | static void | 92 | static void |
93 | iter1_cb (void *cls, | 93 | iter1_cb(void *cls, |
94 | const struct GNUNET_PEERSTORE_Record *record, | 94 | const struct GNUNET_PEERSTORE_Record *record, |
95 | const char *emsg) | 95 | const char *emsg) |
96 | { | 96 | { |
97 | if (NULL != emsg) | 97 | if (NULL != emsg) |
98 | { | 98 | { |
99 | GNUNET_PEERSTORE_iterate_cancel (ic); | 99 | GNUNET_PEERSTORE_iterate_cancel(ic); |
100 | return; | 100 | return; |
101 | } | 101 | } |
102 | if (NULL != record) | 102 | if (NULL != record) |
103 | { | 103 | { |
104 | count++; | 104 | count++; |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | GNUNET_assert (count == 1); | 107 | GNUNET_assert(count == 1); |
108 | count = 0; | 108 | count = 0; |
109 | ic = GNUNET_PEERSTORE_iterate (h, | 109 | ic = GNUNET_PEERSTORE_iterate(h, |
110 | ss, | 110 | ss, |
111 | &p1, | 111 | &p1, |
112 | NULL, | 112 | NULL, |
113 | &iter2_cb, | 113 | &iter2_cb, |
114 | NULL); | 114 | NULL); |
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
118 | static void | 118 | static void |
119 | run (void *cls, | 119 | run(void *cls, |
120 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 120 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
121 | struct GNUNET_TESTING_Peer *peer) | 121 | struct GNUNET_TESTING_Peer *peer) |
122 | { | 122 | { |
123 | h = GNUNET_PEERSTORE_connect (cfg); | 123 | h = GNUNET_PEERSTORE_connect(cfg); |
124 | GNUNET_assert (NULL != h); | 124 | GNUNET_assert(NULL != h); |
125 | memset (&p1, 1, sizeof (p1)); | 125 | memset(&p1, 1, sizeof(p1)); |
126 | memset (&p2, 2, sizeof (p2)); | 126 | memset(&p2, 2, sizeof(p2)); |
127 | GNUNET_PEERSTORE_store (h, | 127 | GNUNET_PEERSTORE_store(h, |
128 | ss, | 128 | ss, |
129 | &p1, | 129 | &p1, |
130 | k1, | 130 | k1, |
131 | val, | 131 | val, |
132 | strlen (val) + 1, | 132 | strlen(val) + 1, |
133 | GNUNET_TIME_UNIT_FOREVER_ABS, | 133 | GNUNET_TIME_UNIT_FOREVER_ABS, |
134 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | 134 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, |
135 | NULL, | 135 | NULL, |
136 | NULL); | 136 | NULL); |
137 | GNUNET_PEERSTORE_store (h, | 137 | GNUNET_PEERSTORE_store(h, |
138 | ss, | 138 | ss, |
139 | &p1, | 139 | &p1, |
140 | k2, | 140 | k2, |
141 | val, | 141 | val, |
142 | strlen (val) + 1, | 142 | strlen(val) + 1, |
143 | GNUNET_TIME_UNIT_FOREVER_ABS, | 143 | GNUNET_TIME_UNIT_FOREVER_ABS, |
144 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | 144 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, |
145 | NULL, | 145 | NULL, |
146 | NULL); | 146 | NULL); |
147 | GNUNET_PEERSTORE_store (h, | 147 | GNUNET_PEERSTORE_store(h, |
148 | ss, | 148 | ss, |
149 | &p2, | 149 | &p2, |
150 | k3, | 150 | k3, |
151 | val, | 151 | val, |
152 | strlen (val) + 1, | 152 | strlen(val) + 1, |
153 | GNUNET_TIME_UNIT_FOREVER_ABS, | 153 | GNUNET_TIME_UNIT_FOREVER_ABS, |
154 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | 154 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, |
155 | NULL, | 155 | NULL, |
156 | NULL); | 156 | NULL); |
157 | ic = GNUNET_PEERSTORE_iterate (h, | 157 | ic = GNUNET_PEERSTORE_iterate(h, |
158 | ss, | 158 | ss, |
159 | &p1, | 159 | &p1, |
160 | k1, | 160 | k1, |
161 | &iter1_cb, NULL); | 161 | &iter1_cb, NULL); |
162 | } | 162 | } |
163 | 163 | ||
164 | 164 | ||
165 | int | 165 | int |
166 | main (int argc, char *argv[]) | 166 | main(int argc, char *argv[]) |
167 | { | 167 | { |
168 | if (0 != | 168 | if (0 != |
169 | GNUNET_TESTING_service_run ("test-gnunet-peerstore", "peerstore", | 169 | GNUNET_TESTING_service_run("test-gnunet-peerstore", "peerstore", |
170 | "test_peerstore_api_data.conf", &run, NULL)) | 170 | "test_peerstore_api_data.conf", &run, NULL)) |
171 | return 1; | 171 | return 1; |
172 | return ok; | 172 | return ok; |
173 | } | 173 | } |
diff --git a/src/peerstore/test_peerstore_api_store.c b/src/peerstore/test_peerstore_api_store.c index cecf13e05..f557aafa5 100644 --- a/src/peerstore/test_peerstore_api_store.c +++ b/src/peerstore/test_peerstore_api_store.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file peerstore/test_peerstore_api_store.c | 21 | * @file peerstore/test_peerstore_api_store.c |
22 | * @brief testcase for peerstore store operation | 22 | * @brief testcase for peerstore store operation |
@@ -41,40 +41,40 @@ static int count = 0; | |||
41 | 41 | ||
42 | 42 | ||
43 | static void | 43 | static void |
44 | test3_cont2 (void *cls, | 44 | test3_cont2(void *cls, |
45 | const struct GNUNET_PEERSTORE_Record *record, | 45 | const struct GNUNET_PEERSTORE_Record *record, |
46 | const char *emsg) | 46 | const char *emsg) |
47 | { | 47 | { |
48 | if (NULL != emsg) | 48 | if (NULL != emsg) |
49 | return; | 49 | return; |
50 | if (NULL != record) | 50 | if (NULL != record) |
51 | { | 51 | { |
52 | GNUNET_assert ((strlen (val3) + 1) == record->value_size); | 52 | GNUNET_assert((strlen(val3) + 1) == record->value_size); |
53 | GNUNET_assert (0 == strcmp ((char *) val3, | 53 | GNUNET_assert(0 == strcmp((char *)val3, |
54 | (char *) record->value)); | 54 | (char *)record->value)); |
55 | count++; | 55 | count++; |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | GNUNET_assert (count == 1); | 58 | GNUNET_assert(count == 1); |
59 | ok = 0; | 59 | ok = 0; |
60 | GNUNET_PEERSTORE_disconnect (h, GNUNET_YES); | 60 | GNUNET_PEERSTORE_disconnect(h, GNUNET_YES); |
61 | GNUNET_SCHEDULER_shutdown (); | 61 | GNUNET_SCHEDULER_shutdown(); |
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
65 | static void | 65 | static void |
66 | test3_cont (void *cls, | 66 | test3_cont(void *cls, |
67 | int success) | 67 | int success) |
68 | { | 68 | { |
69 | if (GNUNET_YES != success) | 69 | if (GNUNET_YES != success) |
70 | return; | 70 | return; |
71 | count = 0; | 71 | count = 0; |
72 | GNUNET_PEERSTORE_iterate (h, | 72 | GNUNET_PEERSTORE_iterate(h, |
73 | subsystem, | 73 | subsystem, |
74 | &pid, | 74 | &pid, |
75 | key, | 75 | key, |
76 | &test3_cont2, | 76 | &test3_cont2, |
77 | NULL); | 77 | NULL); |
78 | } | 78 | } |
79 | 79 | ||
80 | 80 | ||
@@ -82,54 +82,54 @@ test3_cont (void *cls, | |||
82 | * Replace the previous 2 records | 82 | * Replace the previous 2 records |
83 | */ | 83 | */ |
84 | static void | 84 | static void |
85 | test3 () | 85 | test3() |
86 | { | 86 | { |
87 | GNUNET_PEERSTORE_store (h, | 87 | GNUNET_PEERSTORE_store(h, |
88 | subsystem, | 88 | subsystem, |
89 | &pid, | 89 | &pid, |
90 | key, | 90 | key, |
91 | val3, | 91 | val3, |
92 | strlen (val3) + 1, | 92 | strlen(val3) + 1, |
93 | GNUNET_TIME_UNIT_FOREVER_ABS, | 93 | GNUNET_TIME_UNIT_FOREVER_ABS, |
94 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | 94 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, |
95 | &test3_cont, | 95 | &test3_cont, |
96 | NULL); | 96 | NULL); |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | static void | 100 | static void |
101 | test2_cont2 (void *cls, | 101 | test2_cont2(void *cls, |
102 | const struct GNUNET_PEERSTORE_Record *record, | 102 | const struct GNUNET_PEERSTORE_Record *record, |
103 | const char *emsg) | 103 | const char *emsg) |
104 | { | 104 | { |
105 | if (NULL != emsg) | 105 | if (NULL != emsg) |
106 | return; | 106 | return; |
107 | if (NULL != record) | 107 | if (NULL != record) |
108 | { | 108 | { |
109 | GNUNET_assert (((strlen (val1) + 1) == record->value_size) || | 109 | GNUNET_assert(((strlen(val1) + 1) == record->value_size) || |
110 | ((strlen (val2) + 1) == record->value_size)); | 110 | ((strlen(val2) + 1) == record->value_size)); |
111 | GNUNET_assert ((0 == strcmp ((char *) val1, (char *) record->value)) || | 111 | GNUNET_assert((0 == strcmp((char *)val1, (char *)record->value)) || |
112 | (0 == strcmp ((char *) val2, (char *) record->value))); | 112 | (0 == strcmp((char *)val2, (char *)record->value))); |
113 | count++; | 113 | count++; |
114 | return; | 114 | return; |
115 | } | 115 | } |
116 | GNUNET_assert (count == 2); | 116 | GNUNET_assert(count == 2); |
117 | count = 0; | 117 | count = 0; |
118 | test3 (); | 118 | test3(); |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | static void | 122 | static void |
123 | test2_cont (void *cls, int success) | 123 | test2_cont(void *cls, int success) |
124 | { | 124 | { |
125 | if (GNUNET_YES != success) | 125 | if (GNUNET_YES != success) |
126 | return; | 126 | return; |
127 | count = 0; | 127 | count = 0; |
128 | GNUNET_PEERSTORE_iterate (h, | 128 | GNUNET_PEERSTORE_iterate(h, |
129 | subsystem, | 129 | subsystem, |
130 | &pid, key, | 130 | &pid, key, |
131 | &test2_cont2, | 131 | &test2_cont2, |
132 | NULL); | 132 | NULL); |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
@@ -137,53 +137,53 @@ test2_cont (void *cls, int success) | |||
137 | * Test storing a second value with the same key | 137 | * Test storing a second value with the same key |
138 | */ | 138 | */ |
139 | void | 139 | void |
140 | test2 () | 140 | test2() |
141 | { | 141 | { |
142 | GNUNET_PEERSTORE_store (h, | 142 | GNUNET_PEERSTORE_store(h, |
143 | subsystem, | 143 | subsystem, |
144 | &pid, | 144 | &pid, |
145 | key, | 145 | key, |
146 | val2, | 146 | val2, |
147 | strlen (val2) + 1, | 147 | strlen(val2) + 1, |
148 | GNUNET_TIME_UNIT_FOREVER_ABS, | 148 | GNUNET_TIME_UNIT_FOREVER_ABS, |
149 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, | 149 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, |
150 | &test2_cont, | 150 | &test2_cont, |
151 | NULL); | 151 | NULL); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | static void | 155 | static void |
156 | test1_cont2 (void *cls, | 156 | test1_cont2(void *cls, |
157 | const struct GNUNET_PEERSTORE_Record *record, | 157 | const struct GNUNET_PEERSTORE_Record *record, |
158 | const char *emsg) | 158 | const char *emsg) |
159 | { | 159 | { |
160 | if (NULL != emsg) | 160 | if (NULL != emsg) |
161 | return; | 161 | return; |
162 | if (NULL != record) | 162 | if (NULL != record) |
163 | { | 163 | { |
164 | GNUNET_assert ((strlen (val1) + 1) == record->value_size); | 164 | GNUNET_assert((strlen(val1) + 1) == record->value_size); |
165 | GNUNET_assert (0 == strcmp ((char *) val1, (char *) record->value)); | 165 | GNUNET_assert(0 == strcmp((char *)val1, (char *)record->value)); |
166 | count++; | 166 | count++; |
167 | return; | 167 | return; |
168 | } | 168 | } |
169 | GNUNET_assert (count == 1); | 169 | GNUNET_assert(count == 1); |
170 | count = 0; | 170 | count = 0; |
171 | test2 (); | 171 | test2(); |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | static void | 175 | static void |
176 | test1_cont (void *cls, int success) | 176 | test1_cont(void *cls, int success) |
177 | { | 177 | { |
178 | if (GNUNET_YES != success) | 178 | if (GNUNET_YES != success) |
179 | return; | 179 | return; |
180 | count = 0; | 180 | count = 0; |
181 | GNUNET_PEERSTORE_iterate (h, | 181 | GNUNET_PEERSTORE_iterate(h, |
182 | subsystem, | 182 | subsystem, |
183 | &pid, | 183 | &pid, |
184 | key, | 184 | key, |
185 | &test1_cont2, | 185 | &test1_cont2, |
186 | NULL); | 186 | NULL); |
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
@@ -191,40 +191,40 @@ test1_cont (void *cls, int success) | |||
191 | * Store a single record | 191 | * Store a single record |
192 | */ | 192 | */ |
193 | static void | 193 | static void |
194 | test1 () | 194 | test1() |
195 | { | 195 | { |
196 | GNUNET_PEERSTORE_store (h, | 196 | GNUNET_PEERSTORE_store(h, |
197 | subsystem, | 197 | subsystem, |
198 | &pid, | 198 | &pid, |
199 | key, | 199 | key, |
200 | val1, | 200 | val1, |
201 | strlen (val1) + 1, | 201 | strlen(val1) + 1, |
202 | GNUNET_TIME_UNIT_FOREVER_ABS, | 202 | GNUNET_TIME_UNIT_FOREVER_ABS, |
203 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | 203 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, |
204 | &test1_cont, | 204 | &test1_cont, |
205 | NULL); | 205 | NULL); |
206 | } | 206 | } |
207 | 207 | ||
208 | 208 | ||
209 | static void | 209 | static void |
210 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | 210 | run(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
211 | struct GNUNET_TESTING_Peer *peer) | 211 | struct GNUNET_TESTING_Peer *peer) |
212 | { | 212 | { |
213 | h = GNUNET_PEERSTORE_connect (cfg); | 213 | h = GNUNET_PEERSTORE_connect(cfg); |
214 | GNUNET_assert (NULL != h); | 214 | GNUNET_assert(NULL != h); |
215 | memset (&pid, 1, sizeof (pid)); | 215 | memset(&pid, 1, sizeof(pid)); |
216 | test1 (); | 216 | test1(); |
217 | } | 217 | } |
218 | 218 | ||
219 | 219 | ||
220 | int | 220 | int |
221 | main (int argc, char *argv[]) | 221 | main(int argc, char *argv[]) |
222 | { | 222 | { |
223 | if (0 != | 223 | if (0 != |
224 | GNUNET_TESTING_service_run ("test-gnunet-peerstore", | 224 | GNUNET_TESTING_service_run("test-gnunet-peerstore", |
225 | "peerstore", | 225 | "peerstore", |
226 | "test_peerstore_api_data.conf", | 226 | "test_peerstore_api_data.conf", |
227 | &run, NULL)) | 227 | &run, NULL)) |
228 | return 1; | 228 | return 1; |
229 | return ok; | 229 | return ok; |
230 | } | 230 | } |
diff --git a/src/peerstore/test_peerstore_api_sync.c b/src/peerstore/test_peerstore_api_sync.c index 6fe12335e..7df4778be 100644 --- a/src/peerstore/test_peerstore_api_sync.c +++ b/src/peerstore/test_peerstore_api_sync.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file peerstore/test_peerstore_api_sync.c | 21 | * @file peerstore/test_peerstore_api_sync.c |
22 | * @brief testcase for peerstore sync-on-disconnect feature. Stores | 22 | * @brief testcase for peerstore sync-on-disconnect feature. Stores |
@@ -80,22 +80,22 @@ static const char *val = "test_peerstore_api_store_val"; | |||
80 | * @return #GNUNET_YES (all good, continue) | 80 | * @return #GNUNET_YES (all good, continue) |
81 | */ | 81 | */ |
82 | static void | 82 | static void |
83 | iterate_cb (void *cls, | 83 | iterate_cb(void *cls, |
84 | const struct GNUNET_PEERSTORE_Record *record, | 84 | const struct GNUNET_PEERSTORE_Record *record, |
85 | const char *emsg) | 85 | const char *emsg) |
86 | { | 86 | { |
87 | const char *rec_val; | 87 | const char *rec_val; |
88 | 88 | ||
89 | GNUNET_break (NULL == emsg); | 89 | GNUNET_break(NULL == emsg); |
90 | if (NULL == record) | 90 | if (NULL == record) |
91 | { | 91 | { |
92 | GNUNET_PEERSTORE_disconnect (h, | 92 | GNUNET_PEERSTORE_disconnect(h, |
93 | GNUNET_NO); | 93 | GNUNET_NO); |
94 | GNUNET_SCHEDULER_shutdown (); | 94 | GNUNET_SCHEDULER_shutdown(); |
95 | return; | 95 | return; |
96 | } | 96 | } |
97 | rec_val = record->value; | 97 | rec_val = record->value; |
98 | GNUNET_break (0 == strcmp (rec_val, val)); | 98 | GNUNET_break(0 == strcmp(rec_val, val)); |
99 | ok = 0; | 99 | ok = 0; |
100 | } | 100 | } |
101 | 101 | ||
@@ -107,14 +107,14 @@ iterate_cb (void *cls, | |||
107 | * @param cls NULL | 107 | * @param cls NULL |
108 | */ | 108 | */ |
109 | static void | 109 | static void |
110 | test_cont (void *cls) | 110 | test_cont(void *cls) |
111 | { | 111 | { |
112 | h = GNUNET_PEERSTORE_connect (cfg); | 112 | h = GNUNET_PEERSTORE_connect(cfg); |
113 | GNUNET_PEERSTORE_iterate (h, | 113 | GNUNET_PEERSTORE_iterate(h, |
114 | subsystem, | 114 | subsystem, |
115 | &pid, key, | 115 | &pid, key, |
116 | &iterate_cb, | 116 | &iterate_cb, |
117 | NULL); | 117 | NULL); |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
@@ -122,28 +122,28 @@ test_cont (void *cls) | |||
122 | * Actually run the test. | 122 | * Actually run the test. |
123 | */ | 123 | */ |
124 | static void | 124 | static void |
125 | test1 () | 125 | test1() |
126 | { | 126 | { |
127 | h = GNUNET_PEERSTORE_connect (cfg); | 127 | h = GNUNET_PEERSTORE_connect(cfg); |
128 | GNUNET_PEERSTORE_store (h, | 128 | GNUNET_PEERSTORE_store(h, |
129 | subsystem, | 129 | subsystem, |
130 | &pid, | 130 | &pid, |
131 | key, | 131 | key, |
132 | val, strlen (val) + 1, | 132 | val, strlen(val) + 1, |
133 | GNUNET_TIME_UNIT_FOREVER_ABS, | 133 | GNUNET_TIME_UNIT_FOREVER_ABS, |
134 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | 134 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, |
135 | NULL, NULL); | 135 | NULL, NULL); |
136 | GNUNET_PEERSTORE_disconnect (h, | 136 | GNUNET_PEERSTORE_disconnect(h, |
137 | GNUNET_YES); | 137 | GNUNET_YES); |
138 | h = NULL; | 138 | h = NULL; |
139 | /* We need to wait a little bit to give the disconnect | 139 | /* We need to wait a little bit to give the disconnect |
140 | a chance to actually finish the operation; otherwise, | 140 | a chance to actually finish the operation; otherwise, |
141 | the test may fail non-deterministically if the new | 141 | the test may fail non-deterministically if the new |
142 | connection is faster than the cleanup routine of the | 142 | connection is faster than the cleanup routine of the |
143 | old one. */ | 143 | old one. */ |
144 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 144 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
145 | &test_cont, | 145 | &test_cont, |
146 | NULL); | 146 | NULL); |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
@@ -155,29 +155,29 @@ test1 () | |||
155 | * @param peer handle to our peer (unused) | 155 | * @param peer handle to our peer (unused) |
156 | */ | 156 | */ |
157 | static void | 157 | static void |
158 | run (void *cls, | 158 | run(void *cls, |
159 | const struct GNUNET_CONFIGURATION_Handle *c, | 159 | const struct GNUNET_CONFIGURATION_Handle *c, |
160 | struct GNUNET_TESTING_Peer *peer) | 160 | struct GNUNET_TESTING_Peer *peer) |
161 | { | 161 | { |
162 | cfg = c; | 162 | cfg = c; |
163 | memset (&pid, 1, sizeof (pid)); | 163 | memset(&pid, 1, sizeof(pid)); |
164 | test1 (); | 164 | test1(); |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
168 | int | 168 | int |
169 | main (int argc, char *argv[]) | 169 | main(int argc, char *argv[]) |
170 | { | 170 | { |
171 | if (0 != | 171 | if (0 != |
172 | GNUNET_TESTING_service_run ("test-gnunet-peerstore-sync", | 172 | GNUNET_TESTING_service_run("test-gnunet-peerstore-sync", |
173 | "peerstore", | 173 | "peerstore", |
174 | "test_peerstore_api_data.conf", | 174 | "test_peerstore_api_data.conf", |
175 | &run, NULL)) | 175 | &run, NULL)) |
176 | return 1; | 176 | return 1; |
177 | if (0 != ok) | 177 | if (0 != ok) |
178 | fprintf (stderr, | 178 | fprintf(stderr, |
179 | "Test failed: %d\n", | 179 | "Test failed: %d\n", |
180 | ok); | 180 | ok); |
181 | return ok; | 181 | return ok; |
182 | } | 182 | } |
183 | 183 | ||
diff --git a/src/peerstore/test_peerstore_api_watch.c b/src/peerstore/test_peerstore_api_watch.c index 9f933f584..1e097ad42 100644 --- a/src/peerstore/test_peerstore_api_watch.c +++ b/src/peerstore/test_peerstore_api_watch.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file peerstore/test_peerstore_api_watch.c | 21 | * @file peerstore/test_peerstore_api_watch.c |
22 | * @brief testcase for peerstore watch functionality | 22 | * @brief testcase for peerstore watch functionality |
@@ -39,61 +39,61 @@ static char *val = "test_peerstore_api_watch_val"; | |||
39 | 39 | ||
40 | 40 | ||
41 | static void | 41 | static void |
42 | watch_cb (void *cls, | 42 | watch_cb(void *cls, |
43 | const struct GNUNET_PEERSTORE_Record *record, | 43 | const struct GNUNET_PEERSTORE_Record *record, |
44 | const char *emsg) | 44 | const char *emsg) |
45 | { | 45 | { |
46 | GNUNET_assert (NULL == emsg); | 46 | GNUNET_assert(NULL == emsg); |
47 | GNUNET_assert (0 == strcmp (val, | 47 | GNUNET_assert(0 == strcmp(val, |
48 | (char *) record->value)); | 48 | (char *)record->value)); |
49 | ok = 0; | 49 | ok = 0; |
50 | GNUNET_PEERSTORE_disconnect (h, | 50 | GNUNET_PEERSTORE_disconnect(h, |
51 | GNUNET_NO); | 51 | GNUNET_NO); |
52 | GNUNET_SCHEDULER_shutdown (); | 52 | GNUNET_SCHEDULER_shutdown(); |
53 | } | 53 | } |
54 | 54 | ||
55 | 55 | ||
56 | static void | 56 | static void |
57 | run (void *cls, | 57 | run(void *cls, |
58 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 58 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
59 | struct GNUNET_TESTING_Peer *peer) | 59 | struct GNUNET_TESTING_Peer *peer) |
60 | { | 60 | { |
61 | struct GNUNET_PeerIdentity p; | 61 | struct GNUNET_PeerIdentity p; |
62 | 62 | ||
63 | h = GNUNET_PEERSTORE_connect (cfg); | 63 | h = GNUNET_PEERSTORE_connect(cfg); |
64 | GNUNET_assert (NULL != h); | 64 | GNUNET_assert(NULL != h); |
65 | memset (&p, | 65 | memset(&p, |
66 | 4, | 66 | 4, |
67 | sizeof (p)); | 67 | sizeof(p)); |
68 | GNUNET_PEERSTORE_watch (h, | 68 | GNUNET_PEERSTORE_watch(h, |
69 | ss, | 69 | ss, |
70 | &p, | 70 | &p, |
71 | k, | 71 | k, |
72 | &watch_cb, | 72 | &watch_cb, |
73 | NULL); | 73 | NULL); |
74 | GNUNET_PEERSTORE_store (h, | 74 | GNUNET_PEERSTORE_store(h, |
75 | ss, | 75 | ss, |
76 | &p, | 76 | &p, |
77 | k, | 77 | k, |
78 | val, | 78 | val, |
79 | strlen (val) + 1, | 79 | strlen(val) + 1, |
80 | GNUNET_TIME_UNIT_FOREVER_ABS, | 80 | GNUNET_TIME_UNIT_FOREVER_ABS, |
81 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | 81 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, |
82 | NULL, | 82 | NULL, |
83 | NULL); | 83 | NULL); |
84 | } | 84 | } |
85 | 85 | ||
86 | 86 | ||
87 | int | 87 | int |
88 | main (int argc, | 88 | main(int argc, |
89 | char *argv[]) | 89 | char *argv[]) |
90 | { | 90 | { |
91 | if (0 != | 91 | if (0 != |
92 | GNUNET_TESTING_service_run ("test-gnunet-peerstore", | 92 | GNUNET_TESTING_service_run("test-gnunet-peerstore", |
93 | "peerstore", | 93 | "peerstore", |
94 | "test_peerstore_api_data.conf", | 94 | "test_peerstore_api_data.conf", |
95 | &run, | 95 | &run, |
96 | NULL)) | 96 | NULL)) |
97 | return 1; | 97 | return 1; |
98 | return ok; | 98 | return ok; |
99 | } | 99 | } |
diff --git a/src/peerstore/test_plugin_peerstore.c b/src/peerstore/test_plugin_peerstore.c index 24b5723ff..0664659a4 100644 --- a/src/peerstore/test_plugin_peerstore.c +++ b/src/peerstore/test_plugin_peerstore.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /* | 20 | /* |
21 | * @file namestore/test_plugin_namestore.c | 21 | * @file namestore/test_plugin_namestore.c |
22 | * @brief Test for the namestore plugins | 22 | * @brief Test for the namestore plugins |
@@ -48,17 +48,17 @@ static struct GNUNET_PeerIdentity p1; | |||
48 | * @param api api to unload | 48 | * @param api api to unload |
49 | */ | 49 | */ |
50 | static void | 50 | static void |
51 | unload_plugin (struct GNUNET_PEERSTORE_PluginFunctions *api) | 51 | unload_plugin(struct GNUNET_PEERSTORE_PluginFunctions *api) |
52 | { | 52 | { |
53 | char *libname; | 53 | char *libname; |
54 | 54 | ||
55 | GNUNET_asprintf (&libname, | 55 | GNUNET_asprintf(&libname, |
56 | "libgnunet_plugin_peer_%s", | 56 | "libgnunet_plugin_peer_%s", |
57 | plugin_name); | 57 | plugin_name); |
58 | GNUNET_break (NULL == | 58 | GNUNET_break(NULL == |
59 | GNUNET_PLUGIN_unload (libname, | 59 | GNUNET_PLUGIN_unload(libname, |
60 | api)); | 60 | api)); |
61 | GNUNET_free (libname); | 61 | GNUNET_free(libname); |
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
@@ -69,124 +69,123 @@ unload_plugin (struct GNUNET_PEERSTORE_PluginFunctions *api) | |||
69 | * @return NULL on error | 69 | * @return NULL on error |
70 | */ | 70 | */ |
71 | static struct GNUNET_PEERSTORE_PluginFunctions * | 71 | static struct GNUNET_PEERSTORE_PluginFunctions * |
72 | load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | 72 | load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg) |
73 | { | 73 | { |
74 | struct GNUNET_PEERSTORE_PluginFunctions *ret; | 74 | struct GNUNET_PEERSTORE_PluginFunctions *ret; |
75 | char *libname; | 75 | char *libname; |
76 | 76 | ||
77 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 77 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
78 | _("Loading `%s' peer plugin\n"), | 78 | _("Loading `%s' peer plugin\n"), |
79 | plugin_name); | ||
80 | GNUNET_asprintf (&libname, | ||
81 | "libgnunet_plugin_peerstore_%s", | ||
82 | plugin_name); | ||
83 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, | ||
84 | (void*) cfg))) | ||
85 | { | ||
86 | fprintf (stderr, | ||
87 | "Failed to load plugin `%s'!\n", | ||
88 | plugin_name); | 79 | plugin_name); |
89 | GNUNET_free (libname); | 80 | GNUNET_asprintf(&libname, |
90 | return NULL; | 81 | "libgnunet_plugin_peerstore_%s", |
91 | } | 82 | plugin_name); |
92 | GNUNET_free (libname); | 83 | if (NULL == (ret = GNUNET_PLUGIN_load(libname, |
84 | (void*)cfg))) | ||
85 | { | ||
86 | fprintf(stderr, | ||
87 | "Failed to load plugin `%s'!\n", | ||
88 | plugin_name); | ||
89 | GNUNET_free(libname); | ||
90 | return NULL; | ||
91 | } | ||
92 | GNUNET_free(libname); | ||
93 | return ret; | 93 | return ret; |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | static void | 97 | static void |
98 | test_record (void *cls, | 98 | test_record(void *cls, |
99 | const struct GNUNET_PEERSTORE_Record *record, | 99 | const struct GNUNET_PEERSTORE_Record *record, |
100 | const char *error) | 100 | const char *error) |
101 | { | 101 | { |
102 | const struct GNUNET_PeerIdentity *id = cls; | 102 | const struct GNUNET_PeerIdentity *id = cls; |
103 | const char* testval = "test_val"; | 103 | const char* testval = "test_val"; |
104 | 104 | ||
105 | if (NULL == record) | 105 | if (NULL == record) |
106 | { | 106 | { |
107 | unload_plugin (psp); | 107 | unload_plugin(psp); |
108 | return; | 108 | return; |
109 | } | 109 | } |
110 | GNUNET_assert (0 == memcmp (&record->peer, | 110 | GNUNET_assert(0 == memcmp(&record->peer, |
111 | id, | 111 | id, |
112 | sizeof (struct GNUNET_PeerIdentity))); | 112 | sizeof(struct GNUNET_PeerIdentity))); |
113 | GNUNET_assert (0 == strcmp ("subsys", | 113 | GNUNET_assert(0 == strcmp("subsys", |
114 | record->sub_system)); | 114 | record->sub_system)); |
115 | GNUNET_assert (0 == strcmp ("key", | 115 | GNUNET_assert(0 == strcmp("key", |
116 | record->key)); | 116 | record->key)); |
117 | GNUNET_assert (0 == memcmp (testval, | 117 | GNUNET_assert(0 == memcmp(testval, |
118 | record->value, | 118 | record->value, |
119 | strlen (testval))); | 119 | strlen(testval))); |
120 | ok = 0; | 120 | ok = 0; |
121 | } | 121 | } |
122 | 122 | ||
123 | 123 | ||
124 | static void | 124 | static void |
125 | get_record (struct GNUNET_PEERSTORE_PluginFunctions *psp, | 125 | get_record(struct GNUNET_PEERSTORE_PluginFunctions *psp, |
126 | const struct GNUNET_PeerIdentity *identity) | 126 | const struct GNUNET_PeerIdentity *identity) |
127 | { | 127 | { |
128 | GNUNET_assert (GNUNET_OK == | 128 | GNUNET_assert(GNUNET_OK == |
129 | psp->iterate_records (psp->cls, | 129 | psp->iterate_records(psp->cls, |
130 | "subsys", | 130 | "subsys", |
131 | identity, | 131 | identity, |
132 | "key", | 132 | "key", |
133 | &test_record, | 133 | &test_record, |
134 | (void*)identity)); | 134 | (void*)identity)); |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
138 | static void | 138 | static void |
139 | store_cont (void *cls, | 139 | store_cont(void *cls, |
140 | int status) | 140 | int status) |
141 | { | 141 | { |
142 | GNUNET_assert (GNUNET_OK == status); | 142 | GNUNET_assert(GNUNET_OK == status); |
143 | get_record (psp, | 143 | get_record(psp, |
144 | &p1); | 144 | &p1); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | static void | 148 | static void |
149 | put_record (struct GNUNET_PEERSTORE_PluginFunctions *psp, | 149 | put_record(struct GNUNET_PEERSTORE_PluginFunctions *psp, |
150 | const struct GNUNET_PeerIdentity *identity) | 150 | const struct GNUNET_PeerIdentity *identity) |
151 | { | 151 | { |
152 | GNUNET_assert (GNUNET_OK == | 152 | GNUNET_assert(GNUNET_OK == |
153 | psp->store_record (psp->cls, | 153 | psp->store_record(psp->cls, |
154 | "subsys", | 154 | "subsys", |
155 | identity, | 155 | identity, |
156 | "key", | 156 | "key", |
157 | "test_value", | 157 | "test_value", |
158 | strlen ("test_value"), | 158 | strlen("test_value"), |
159 | GNUNET_TIME_absolute_get (), | 159 | GNUNET_TIME_absolute_get(), |
160 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | 160 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, |
161 | &store_cont, | 161 | &store_cont, |
162 | NULL)); | 162 | NULL)); |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
166 | static void | 166 | static void |
167 | run (void *cls, | 167 | run(void *cls, |
168 | char *const *args, | 168 | char *const *args, |
169 | const char *cfgfile, | 169 | const char *cfgfile, |
170 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 170 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
171 | { | 171 | { |
172 | |||
173 | ok = 1; | 172 | ok = 1; |
174 | psp = load_plugin (cfg); | 173 | psp = load_plugin(cfg); |
175 | if (NULL == psp) | 174 | if (NULL == psp) |
176 | { | 175 | { |
177 | fprintf (stderr, | 176 | fprintf(stderr, |
178 | "%s", | 177 | "%s", |
179 | "Failed to initialize peerstore. Database likely not setup, skipping test.\n"); | 178 | "Failed to initialize peerstore. Database likely not setup, skipping test.\n"); |
180 | return; | 179 | return; |
181 | } | 180 | } |
182 | memset (&p1, 1, sizeof (p1)); | 181 | memset(&p1, 1, sizeof(p1)); |
183 | put_record (psp, | 182 | put_record(psp, |
184 | &p1); | 183 | &p1); |
185 | } | 184 | } |
186 | 185 | ||
187 | 186 | ||
188 | int | 187 | int |
189 | main (int argc, char *argv[]) | 188 | main(int argc, char *argv[]) |
190 | { | 189 | { |
191 | char cfg_name[PATH_MAX]; | 190 | char cfg_name[PATH_MAX]; |
192 | char *const xargv[] = { | 191 | char *const xargv[] = { |
@@ -199,25 +198,25 @@ main (int argc, char *argv[]) | |||
199 | GNUNET_GETOPT_OPTION_END | 198 | GNUNET_GETOPT_OPTION_END |
200 | }; | 199 | }; |
201 | 200 | ||
202 | GNUNET_log_setup ("test-plugin-peerstore", | 201 | GNUNET_log_setup("test-plugin-peerstore", |
203 | "WARNING", | 202 | "WARNING", |
204 | NULL); | 203 | NULL); |
205 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 204 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); |
206 | GNUNET_snprintf (cfg_name, | 205 | GNUNET_snprintf(cfg_name, |
207 | sizeof (cfg_name), | 206 | sizeof(cfg_name), |
208 | "test_plugin_peerstore_%s.conf", | 207 | "test_plugin_peerstore_%s.conf", |
209 | plugin_name); | 208 | plugin_name); |
210 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, | 209 | GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, |
211 | xargv, | 210 | xargv, |
212 | "test-plugin-peerstore", | 211 | "test-plugin-peerstore", |
213 | "nohelp", | 212 | "nohelp", |
214 | options, | 213 | options, |
215 | &run, | 214 | &run, |
216 | NULL); | 215 | NULL); |
217 | if (ok != 0) | 216 | if (ok != 0) |
218 | fprintf (stderr, | 217 | fprintf(stderr, |
219 | "Missed some testcases: %d\n", | 218 | "Missed some testcases: %d\n", |
220 | ok); | 219 | ok); |
221 | return ok; | 220 | return ok; |
222 | } | 221 | } |
223 | 222 | ||