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