diff options
Diffstat (limited to 'src/peerstore')
-rw-r--r-- | src/peerstore/gnunet-peerstore.c | 31 | ||||
-rw-r--r-- | src/peerstore/gnunet-service-peerstore.c | 337 | ||||
-rw-r--r-- | src/peerstore/peerstore.h | 4 | ||||
-rw-r--r-- | src/peerstore/peerstore_api.c | 369 | ||||
-rw-r--r-- | src/peerstore/peerstore_common.c | 203 | ||||
-rw-r--r-- | src/peerstore/peerstore_common.h | 40 | ||||
-rw-r--r-- | src/peerstore/perf_peerstore_store.c | 76 | ||||
-rw-r--r-- | src/peerstore/plugin_peerstore_sqlite.c | 310 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_iterate.c | 120 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_store.c | 175 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_sync.c | 38 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_watch.c | 50 |
12 files changed, 834 insertions, 919 deletions
diff --git a/src/peerstore/gnunet-peerstore.c b/src/peerstore/gnunet-peerstore.c index f99c42819..bdd045d09 100644 --- a/src/peerstore/gnunet-peerstore.c +++ b/src/peerstore/gnunet-peerstore.c | |||
@@ -41,16 +41,16 @@ struct GNUNET_PEERSTORE_Handle *peerstore_handle; | |||
41 | * @param tc scheduler context | 41 | * @param tc scheduler context |
42 | */ | 42 | */ |
43 | static void | 43 | static void |
44 | shutdown_task (void *cls, | 44 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
45 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
46 | { | 45 | { |
47 | if(NULL != peerstore_handle) | 46 | if (NULL != peerstore_handle) |
48 | { | 47 | { |
49 | GNUNET_PEERSTORE_disconnect(peerstore_handle, GNUNET_YES); | 48 | GNUNET_PEERSTORE_disconnect (peerstore_handle, GNUNET_YES); |
50 | peerstore_handle = NULL; | 49 | peerstore_handle = NULL; |
51 | } | 50 | } |
52 | } | 51 | } |
53 | 52 | ||
53 | |||
54 | /** | 54 | /** |
55 | * Main function that will be run by the scheduler. | 55 | * Main function that will be run by the scheduler. |
56 | * | 56 | * |
@@ -60,22 +60,20 @@ 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, char *const *args, const char *cfgfile, |
64 | char *const *args, | ||
65 | const char *cfgfile, | ||
66 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 64 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
67 | { | 65 | { |
68 | 66 | ||
69 | peerstore_handle = NULL; | 67 | peerstore_handle = NULL; |
70 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 68 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
71 | &shutdown_task, | 69 | NULL); |
72 | NULL); | 70 | peerstore_handle = GNUNET_PEERSTORE_connect (cfg); |
73 | peerstore_handle = GNUNET_PEERSTORE_connect(cfg); | 71 | GNUNET_assert (NULL != peerstore_handle); |
74 | GNUNET_assert(NULL != peerstore_handle); | ||
75 | 72 | ||
76 | ret = 0; | 73 | ret = 0; |
77 | } | 74 | } |
78 | 75 | ||
76 | |||
79 | /** | 77 | /** |
80 | * The main function to peerstore. | 78 | * The main function to peerstore. |
81 | * | 79 | * |
@@ -90,12 +88,9 @@ main (int argc, char *const *argv) | |||
90 | GNUNET_GETOPT_OPTION_END | 88 | GNUNET_GETOPT_OPTION_END |
91 | }; | 89 | }; |
92 | return (GNUNET_OK == | 90 | return (GNUNET_OK == |
93 | GNUNET_PROGRAM_run (argc, | 91 | GNUNET_PROGRAM_run (argc, argv, "gnunet-peerstore [options [value]]", |
94 | argv, | 92 | gettext_noop ("peerstore"), options, &run, |
95 | "gnunet-peerstore [options [value]]", | 93 | NULL)) ? ret : 1; |
96 | gettext_noop | ||
97 | ("peerstore"), | ||
98 | options, &run, NULL)) ? ret : 1; | ||
99 | } | 94 | } |
100 | 95 | ||
101 | /* 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 c93d2cc95..c674d3c11 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) | 3 | (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -53,7 +53,7 @@ struct ClientEntry | |||
53 | /** | 53 | /** |
54 | * Interval for expired records cleanup (in seconds) | 54 | * Interval for expired records cleanup (in seconds) |
55 | */ | 55 | */ |
56 | #define EXPIRED_RECORDS_CLEANUP_INTERVAL 300 /* 5mins */ | 56 | #define EXPIRED_RECORDS_CLEANUP_INTERVAL 300 /* 5mins */ |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Our configuration. | 59 | * Our configuration. |
@@ -98,27 +98,29 @@ int in_shutdown; | |||
98 | /** | 98 | /** |
99 | * Perform the actual shutdown operations | 99 | * Perform the actual shutdown operations |
100 | */ | 100 | */ |
101 | void do_shutdown () | 101 | void |
102 | do_shutdown () | ||
102 | { | 103 | { |
103 | if(NULL != db_lib_name) | 104 | if (NULL != db_lib_name) |
104 | { | 105 | { |
105 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); | 106 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); |
106 | GNUNET_free (db_lib_name); | 107 | GNUNET_free (db_lib_name); |
107 | db_lib_name = NULL; | 108 | db_lib_name = NULL; |
108 | } | 109 | } |
109 | if(NULL != nc) | 110 | if (NULL != nc) |
110 | { | 111 | { |
111 | GNUNET_SERVER_notification_context_destroy(nc); | 112 | GNUNET_SERVER_notification_context_destroy (nc); |
112 | nc = NULL; | 113 | nc = NULL; |
113 | } | 114 | } |
114 | if(NULL != watchers) | 115 | if (NULL != watchers) |
115 | { | 116 | { |
116 | GNUNET_CONTAINER_multihashmap_destroy(watchers); | 117 | GNUNET_CONTAINER_multihashmap_destroy (watchers); |
117 | watchers = NULL; | 118 | watchers = NULL; |
118 | } | 119 | } |
119 | GNUNET_SCHEDULER_shutdown(); | 120 | GNUNET_SCHEDULER_shutdown (); |
120 | } | 121 | } |
121 | 122 | ||
123 | |||
122 | /** | 124 | /** |
123 | * Task run during shutdown. | 125 | * Task run during shutdown. |
124 | * | 126 | * |
@@ -126,34 +128,36 @@ void do_shutdown () | |||
126 | * @param tc unused | 128 | * @param tc unused |
127 | */ | 129 | */ |
128 | static void | 130 | static void |
129 | shutdown_task (void *cls, | 131 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
130 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
131 | { | 132 | { |
132 | in_shutdown = GNUNET_YES; | 133 | in_shutdown = GNUNET_YES; |
133 | if (NULL == client_head) /* Only when no connected clients. */ | 134 | if (NULL == client_head) /* Only when no connected clients. */ |
134 | do_shutdown (); | 135 | do_shutdown (); |
135 | } | 136 | } |
136 | 137 | ||
138 | |||
137 | /** | 139 | /** |
138 | * Deletes any expired records from storage | 140 | * Deletes any expired records from storage |
139 | */ | 141 | */ |
140 | static void | 142 | static void |
141 | cleanup_expired_records(void *cls, | 143 | cleanup_expired_records (void *cls, |
142 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 144 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
143 | { | 145 | { |
144 | int deleted; | 146 | int deleted; |
145 | 147 | ||
146 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 148 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
147 | return; | 149 | return; |
148 | GNUNET_assert(NULL != db); | 150 | GNUNET_assert (NULL != db); |
149 | deleted = db->expire_records(db->cls, GNUNET_TIME_absolute_get()); | 151 | deleted = db->expire_records (db->cls, GNUNET_TIME_absolute_get ()); |
150 | if (deleted > 0) | 152 | if (deleted > 0) |
151 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", deleted); | 153 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", deleted); |
152 | GNUNET_SCHEDULER_add_delayed( | 154 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
153 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, EXPIRED_RECORDS_CLEANUP_INTERVAL), | 155 | (GNUNET_TIME_UNIT_SECONDS, |
154 | &cleanup_expired_records, NULL); | 156 | EXPIRED_RECORDS_CLEANUP_INTERVAL), |
157 | &cleanup_expired_records, NULL); | ||
155 | } | 158 | } |
156 | 159 | ||
160 | |||
157 | /** | 161 | /** |
158 | * Search for a disconnected client and remove it | 162 | * Search for a disconnected client and remove it |
159 | * | 163 | * |
@@ -162,15 +166,15 @@ cleanup_expired_records(void *cls, | |||
162 | * @param value the watcher client, a 'struct GNUNET_SERVER_Client *' | 166 | * @param value the watcher client, a 'struct GNUNET_SERVER_Client *' |
163 | * @return #GNUNET_OK to continue iterating | 167 | * @return #GNUNET_OK to continue iterating |
164 | */ | 168 | */ |
165 | static int client_disconnect_it(void *cls, | 169 | static int |
166 | const struct GNUNET_HashCode *key, | 170 | client_disconnect_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
167 | void *value) | ||
168 | { | 171 | { |
169 | if(cls == value) | 172 | if (cls == value) |
170 | GNUNET_CONTAINER_multihashmap_remove(watchers, key, value); | 173 | GNUNET_CONTAINER_multihashmap_remove (watchers, key, value); |
171 | return GNUNET_OK; | 174 | return GNUNET_OK; |
172 | } | 175 | } |
173 | 176 | ||
177 | |||
174 | /** | 178 | /** |
175 | * A client disconnected. Remove all of its data structure entries. | 179 | * A client disconnected. Remove all of its data structure entries. |
176 | * | 180 | * |
@@ -178,16 +182,14 @@ static int client_disconnect_it(void *cls, | |||
178 | * @param client identification of the client | 182 | * @param client identification of the client |
179 | */ | 183 | */ |
180 | static void | 184 | static void |
181 | handle_client_disconnect (void *cls, | 185 | handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) |
182 | struct GNUNET_SERVER_Client | ||
183 | * client) | ||
184 | { | 186 | { |
185 | struct ClientEntry *ce; | 187 | struct ClientEntry *ce; |
186 | 188 | ||
187 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning up.\n"); | 189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning up.\n"); |
188 | if(NULL != watchers) | 190 | if (NULL != watchers) |
189 | GNUNET_CONTAINER_multihashmap_iterate(watchers, | 191 | GNUNET_CONTAINER_multihashmap_iterate (watchers, &client_disconnect_it, |
190 | &client_disconnect_it, client); | 192 | client); |
191 | ce = client_head; | 193 | ce = client_head; |
192 | while (ce != NULL) | 194 | while (ce != NULL) |
193 | { | 195 | { |
@@ -203,6 +205,7 @@ handle_client_disconnect (void *cls, | |||
203 | do_shutdown (); | 205 | do_shutdown (); |
204 | } | 206 | } |
205 | 207 | ||
208 | |||
206 | /** | 209 | /** |
207 | * Function called by for each matching record. | 210 | * Function called by for each matching record. |
208 | * | 211 | * |
@@ -212,28 +215,24 @@ handle_client_disconnect (void *cls, | |||
212 | * @return #GNUNET_YES to continue iteration | 215 | * @return #GNUNET_YES to continue iteration |
213 | */ | 216 | */ |
214 | static int | 217 | static int |
215 | record_iterator (void *cls, | 218 | record_iterator (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
216 | struct GNUNET_PEERSTORE_Record *record, | ||
217 | char *emsg) | ||
218 | { | 219 | { |
219 | struct GNUNET_SERVER_Client *client = cls; | 220 | struct GNUNET_SERVER_Client *client = cls; |
220 | struct StoreRecordMessage *srm; | 221 | struct StoreRecordMessage *srm; |
221 | 222 | ||
222 | srm = | 223 | srm = |
223 | PEERSTORE_create_record_message(record->sub_system, | 224 | PEERSTORE_create_record_message (record->sub_system, record->peer, |
224 | record->peer, | 225 | record->key, record->value, |
225 | record->key, | 226 | record->value_size, record->expiry, |
226 | record->value, | 227 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); |
227 | record->value_size, | ||
228 | record->expiry, | ||
229 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); | ||
230 | GNUNET_SERVER_notification_context_unicast (nc, client, | 228 | GNUNET_SERVER_notification_context_unicast (nc, client, |
231 | (struct GNUNET_MessageHeader *)srm, | 229 | (struct GNUNET_MessageHeader *) |
232 | GNUNET_NO); | 230 | srm, GNUNET_NO); |
233 | GNUNET_free(srm); | 231 | GNUNET_free (srm); |
234 | return GNUNET_YES; | 232 | return GNUNET_YES; |
235 | } | 233 | } |
236 | 234 | ||
235 | |||
237 | /** | 236 | /** |
238 | * Iterator over all watcher clients | 237 | * Iterator over all watcher clients |
239 | * to notify them of a new record | 238 | * to notify them of a new record |
@@ -243,44 +242,43 @@ record_iterator (void *cls, | |||
243 | * @param value the watcher client, a 'struct GNUNET_SERVER_Client *' | 242 | * @param value the watcher client, a 'struct GNUNET_SERVER_Client *' |
244 | * @return #GNUNET_YES to continue iterating | 243 | * @return #GNUNET_YES to continue iterating |
245 | */ | 244 | */ |
246 | static int watch_notifier_it(void *cls, | 245 | static int |
247 | const struct GNUNET_HashCode *key, | 246 | watch_notifier_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
248 | void *value) | ||
249 | { | 247 | { |
250 | struct GNUNET_PEERSTORE_Record *record = cls; | 248 | struct GNUNET_PEERSTORE_Record *record = cls; |
251 | struct GNUNET_SERVER_Client *client = value; | 249 | struct GNUNET_SERVER_Client *client = value; |
252 | struct StoreRecordMessage *srm; | 250 | struct StoreRecordMessage *srm; |
253 | 251 | ||
254 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); | 252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); |
255 | srm = PEERSTORE_create_record_message(record->sub_system, | 253 | srm = |
256 | record->peer, | 254 | PEERSTORE_create_record_message (record->sub_system, record->peer, |
257 | record->key, | 255 | record->key, record->value, |
258 | record->value, | 256 | record->value_size, record->expiry, |
259 | record->value_size, | 257 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); |
260 | record->expiry, | 258 | GNUNET_SERVER_notification_context_unicast (nc, client, |
261 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); | 259 | (const struct GNUNET_MessageHeader |
262 | GNUNET_SERVER_notification_context_unicast(nc, client, | 260 | *) srm, GNUNET_NO); |
263 | (const struct GNUNET_MessageHeader *)srm, GNUNET_NO); | 261 | GNUNET_free (srm); |
264 | GNUNET_free(srm); | ||
265 | return GNUNET_YES; | 262 | return GNUNET_YES; |
266 | } | 263 | } |
267 | 264 | ||
265 | |||
268 | /** | 266 | /** |
269 | * Given a new record, notifies watchers | 267 | * Given a new record, notifies watchers |
270 | * | 268 | * |
271 | * @param record changed record to update watchers with | 269 | * @param record changed record to update watchers with |
272 | */ | 270 | */ |
273 | static void watch_notifier (struct GNUNET_PEERSTORE_Record *record) | 271 | static void |
272 | watch_notifier (struct GNUNET_PEERSTORE_Record *record) | ||
274 | { | 273 | { |
275 | struct GNUNET_HashCode keyhash; | 274 | struct GNUNET_HashCode keyhash; |
276 | 275 | ||
277 | PEERSTORE_hash_key(record->sub_system, | 276 | PEERSTORE_hash_key (record->sub_system, record->peer, record->key, &keyhash); |
278 | record->peer, | 277 | GNUNET_CONTAINER_multihashmap_get_multiple (watchers, &keyhash, |
279 | record->key, | 278 | &watch_notifier_it, record); |
280 | &keyhash); | ||
281 | GNUNET_CONTAINER_multihashmap_get_multiple(watchers, &keyhash, &watch_notifier_it, record); | ||
282 | } | 279 | } |
283 | 280 | ||
281 | |||
284 | /** | 282 | /** |
285 | * Handle a watch cancel request from client | 283 | * Handle a watch cancel request from client |
286 | * | 284 | * |
@@ -288,18 +286,19 @@ static void watch_notifier (struct GNUNET_PEERSTORE_Record *record) | |||
288 | * @param client identification of the client | 286 | * @param client identification of the client |
289 | * @param message the actual message | 287 | * @param message the actual message |
290 | */ | 288 | */ |
291 | static void handle_watch_cancel (void *cls, | 289 | static void |
292 | struct GNUNET_SERVER_Client *client, | 290 | handle_watch_cancel (void *cls, struct GNUNET_SERVER_Client *client, |
293 | const struct GNUNET_MessageHeader *message) | 291 | const struct GNUNET_MessageHeader *message) |
294 | { | 292 | { |
295 | struct StoreKeyHashMessage *hm; | 293 | struct StoreKeyHashMessage *hm; |
296 | 294 | ||
297 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n"); | 295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n"); |
298 | hm = (struct StoreKeyHashMessage *) message; | 296 | hm = (struct StoreKeyHashMessage *) message; |
299 | GNUNET_CONTAINER_multihashmap_remove(watchers, &hm->keyhash, client); | 297 | GNUNET_CONTAINER_multihashmap_remove (watchers, &hm->keyhash, client); |
300 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 298 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
301 | } | 299 | } |
302 | 300 | ||
301 | |||
303 | /** | 302 | /** |
304 | * Handle a watch request from client | 303 | * Handle a watch request from client |
305 | * | 304 | * |
@@ -307,21 +306,22 @@ static void handle_watch_cancel (void *cls, | |||
307 | * @param client identification of the client | 306 | * @param client identification of the client |
308 | * @param message the actual message | 307 | * @param message the actual message |
309 | */ | 308 | */ |
310 | static void handle_watch (void *cls, | 309 | static void |
311 | struct GNUNET_SERVER_Client *client, | 310 | handle_watch (void *cls, struct GNUNET_SERVER_Client *client, |
312 | const struct GNUNET_MessageHeader *message) | 311 | const struct GNUNET_MessageHeader *message) |
313 | { | 312 | { |
314 | struct StoreKeyHashMessage *hm; | 313 | struct StoreKeyHashMessage *hm; |
315 | 314 | ||
316 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n"); | 315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n"); |
317 | hm = (struct StoreKeyHashMessage *) message; | 316 | hm = (struct StoreKeyHashMessage *) message; |
318 | GNUNET_SERVER_client_mark_monitor(client); | 317 | GNUNET_SERVER_client_mark_monitor (client); |
319 | GNUNET_SERVER_notification_context_add(nc, client); | 318 | GNUNET_SERVER_notification_context_add (nc, client); |
320 | GNUNET_CONTAINER_multihashmap_put(watchers, &hm->keyhash, | 319 | GNUNET_CONTAINER_multihashmap_put (watchers, &hm->keyhash, client, |
321 | client, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 320 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
322 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 321 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
323 | } | 322 | } |
324 | 323 | ||
324 | |||
325 | /** | 325 | /** |
326 | * Handle an iterate request from client | 326 | * Handle an iterate request from client |
327 | * | 327 | * |
@@ -329,55 +329,54 @@ static void handle_watch (void *cls, | |||
329 | * @param client identification of the client | 329 | * @param client identification of the client |
330 | * @param message the actual message | 330 | * @param message the actual message |
331 | */ | 331 | */ |
332 | static void handle_iterate (void *cls, | 332 | static void |
333 | struct GNUNET_SERVER_Client *client, | 333 | handle_iterate (void *cls, struct GNUNET_SERVER_Client *client, |
334 | const struct GNUNET_MessageHeader *message) | 334 | const struct GNUNET_MessageHeader *message) |
335 | { | 335 | { |
336 | struct GNUNET_PEERSTORE_Record *record; | 336 | struct GNUNET_PEERSTORE_Record *record; |
337 | struct GNUNET_MessageHeader *endmsg; | 337 | struct GNUNET_MessageHeader *endmsg; |
338 | 338 | ||
339 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received an iterate request.\n"); | 339 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received an iterate request.\n"); |
340 | record = PEERSTORE_parse_record_message(message); | 340 | record = PEERSTORE_parse_record_message (message); |
341 | if(NULL == record) | 341 | if (NULL == record) |
342 | { | 342 | { |
343 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Malformed iterate request.\n")); | 343 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Malformed iterate request.\n")); |
344 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 344 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
345 | return; | 345 | return; |
346 | } | 346 | } |
347 | if(NULL == record->sub_system) | 347 | if (NULL == record->sub_system) |
348 | { | 348 | { |
349 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 349 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
350 | _("Sub system not supplied in client iterate request.\n")); | 350 | _("Sub system not supplied in client iterate request.\n")); |
351 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 351 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
352 | return; | 352 | return; |
353 | } | 353 | } |
354 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 354 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
355 | "Iterate request: ss `%s', peer `%s', key `%s'\n", | 355 | "Iterate request: ss `%s', peer `%s', key `%s'\n", |
356 | record->sub_system, | 356 | record->sub_system, |
357 | (NULL == record->peer) ? "NULL" : GNUNET_i2s(record->peer), | 357 | (NULL == record->peer) ? "NULL" : GNUNET_i2s (record->peer), |
358 | (NULL == record->key) ? "NULL" : record->key); | 358 | (NULL == record->key) ? "NULL" : record->key); |
359 | GNUNET_SERVER_notification_context_add(nc, client); | 359 | GNUNET_SERVER_notification_context_add (nc, client); |
360 | if(GNUNET_OK == db->iterate_records(db->cls, | 360 | if (GNUNET_OK == |
361 | record->sub_system, | 361 | db->iterate_records (db->cls, record->sub_system, record->peer, |
362 | record->peer, | 362 | record->key, &record_iterator, client)) |
363 | record->key, | ||
364 | &record_iterator, | ||
365 | client)) | ||
366 | { | 363 | { |
367 | endmsg = GNUNET_new(struct GNUNET_MessageHeader); | 364 | endmsg = GNUNET_new (struct GNUNET_MessageHeader); |
368 | endmsg->size = htons(sizeof(struct GNUNET_MessageHeader)); | 365 | |
369 | endmsg->type = htons(GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); | 366 | endmsg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
370 | GNUNET_SERVER_notification_context_unicast(nc, client, endmsg, GNUNET_NO); | 367 | endmsg->type = htons (GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); |
371 | GNUNET_free(endmsg); | 368 | GNUNET_SERVER_notification_context_unicast (nc, client, endmsg, GNUNET_NO); |
372 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 369 | GNUNET_free (endmsg); |
370 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
373 | } | 371 | } |
374 | else | 372 | else |
375 | { | 373 | { |
376 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 374 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
377 | } | 375 | } |
378 | PEERSTORE_destroy_record(record); | 376 | PEERSTORE_destroy_record (record); |
379 | } | 377 | } |
380 | 378 | ||
379 | |||
381 | /** | 380 | /** |
382 | * Handle a store request from client | 381 | * Handle a store request from client |
383 | * | 382 | * |
@@ -385,54 +384,51 @@ static void handle_iterate (void *cls, | |||
385 | * @param client identification of the client | 384 | * @param client identification of the client |
386 | * @param message the actual message | 385 | * @param message the actual message |
387 | */ | 386 | */ |
388 | static void handle_store (void *cls, | 387 | static void |
389 | struct GNUNET_SERVER_Client *client, | 388 | handle_store (void *cls, struct GNUNET_SERVER_Client *client, |
390 | const struct GNUNET_MessageHeader *message) | 389 | const struct GNUNET_MessageHeader *message) |
391 | { | 390 | { |
392 | struct GNUNET_PEERSTORE_Record *record; | 391 | struct GNUNET_PEERSTORE_Record *record; |
393 | struct StoreRecordMessage *srm; | 392 | struct StoreRecordMessage *srm; |
394 | 393 | ||
395 | record = PEERSTORE_parse_record_message(message); | 394 | record = PEERSTORE_parse_record_message (message); |
396 | if(NULL == record) | 395 | if (NULL == record) |
397 | { | 396 | { |
398 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Malformed store request from client\n")); | 397 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
399 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 398 | _("Malformed store request from client\n")); |
399 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
400 | return; | 400 | return; |
401 | } | 401 | } |
402 | srm = (struct StoreRecordMessage *)message; | 402 | srm = (struct StoreRecordMessage *) message; |
403 | if(NULL == record->sub_system | 403 | if (NULL == record->sub_system || NULL == record->peer || NULL == record->key) |
404 | || NULL == record->peer | ||
405 | || NULL == record->key) | ||
406 | { | 404 | { |
407 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Full key not supplied in client store request\n")); | 405 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
408 | PEERSTORE_destroy_record(record); | 406 | _("Full key not supplied in client store request\n")); |
409 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 407 | PEERSTORE_destroy_record (record); |
408 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
410 | return; | 409 | return; |
411 | } | 410 | } |
412 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received a store request (size: %lu) for sub system `%s', peer `%s', key `%s'\n", | 411 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
413 | record->value_size, | 412 | "Received a store request (size: %lu) for sub system `%s', peer `%s', key `%s'\n", |
414 | record->sub_system, | 413 | record->value_size, record->sub_system, GNUNET_i2s (record->peer), |
415 | GNUNET_i2s (record->peer), | 414 | record->key); |
416 | record->key); | 415 | if (GNUNET_OK != |
417 | if(GNUNET_OK != db->store_record(db->cls, | 416 | db->store_record (db->cls, record->sub_system, record->peer, record->key, |
418 | record->sub_system, | 417 | record->value, record->value_size, *record->expiry, |
419 | record->peer, | 418 | srm->options)) |
420 | record->key, | ||
421 | record->value, | ||
422 | record->value_size, | ||
423 | *record->expiry, | ||
424 | srm->options)) | ||
425 | { | 419 | { |
426 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to store requested value, sqlite database error.")); | 420 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
427 | PEERSTORE_destroy_record(record); | 421 | _("Failed to store requested value, sqlite database error.")); |
428 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 422 | PEERSTORE_destroy_record (record); |
423 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
429 | return; | 424 | return; |
430 | } | 425 | } |
431 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 426 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
432 | watch_notifier(record); | 427 | watch_notifier (record); |
433 | PEERSTORE_destroy_record(record); | 428 | PEERSTORE_destroy_record (record); |
434 | } | 429 | } |
435 | 430 | ||
431 | |||
436 | /** | 432 | /** |
437 | * Creates an entry for a new client or returns it if it already exists. | 433 | * Creates an entry for a new client or returns it if it already exists. |
438 | * | 434 | * |
@@ -462,6 +458,7 @@ make_client_entry (struct GNUNET_SERVER_Client *client) | |||
462 | return ce; | 458 | return ce; |
463 | } | 459 | } |
464 | 460 | ||
461 | |||
465 | /** | 462 | /** |
466 | * Callback on a new client connection | 463 | * Callback on a new client connection |
467 | * | 464 | * |
@@ -475,6 +472,7 @@ handle_client_connect (void *cls, struct GNUNET_SERVER_Client *client) | |||
475 | make_client_entry (client); | 472 | make_client_entry (client); |
476 | } | 473 | } |
477 | 474 | ||
475 | |||
478 | /** | 476 | /** |
479 | * Peerstore service runner. | 477 | * Peerstore service runner. |
480 | * | 478 | * |
@@ -483,47 +481,48 @@ handle_client_connect (void *cls, struct GNUNET_SERVER_Client *client) | |||
483 | * @param c configuration to use | 481 | * @param c configuration to use |
484 | */ | 482 | */ |
485 | static void | 483 | static void |
486 | run (void *cls, | 484 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
487 | struct GNUNET_SERVER_Handle *server, | ||
488 | const struct GNUNET_CONFIGURATION_Handle *c) | 485 | const struct GNUNET_CONFIGURATION_Handle *c) |
489 | { | 486 | { |
490 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 487 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
491 | {&handle_store, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, 0}, | 488 | {&handle_store, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, 0}, |
492 | {&handle_iterate, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, 0}, | 489 | {&handle_iterate, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, 0}, |
493 | {&handle_watch, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, sizeof(struct StoreKeyHashMessage)}, | 490 | {&handle_watch, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, |
494 | {&handle_watch_cancel, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, sizeof(struct StoreKeyHashMessage)}, | 491 | sizeof (struct StoreKeyHashMessage)}, |
495 | {NULL, NULL, 0, 0} | 492 | {&handle_watch_cancel, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, |
493 | sizeof (struct StoreKeyHashMessage)}, | ||
494 | {NULL, NULL, 0, 0} | ||
496 | }; | 495 | }; |
497 | char *database; | 496 | char *database; |
498 | 497 | ||
499 | in_shutdown = GNUNET_NO; | 498 | in_shutdown = GNUNET_NO; |
500 | cfg = c; | 499 | cfg = c; |
501 | if (GNUNET_OK != | 500 | if (GNUNET_OK != |
502 | GNUNET_CONFIGURATION_get_value_string (cfg, "peerstore", "DATABASE", | 501 | GNUNET_CONFIGURATION_get_value_string (cfg, "peerstore", "DATABASE", |
503 | &database)) | 502 | &database)) |
504 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("No database backend configured\n")); | 503 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("No database backend configured\n")); |
505 | 504 | ||
506 | else | 505 | else |
507 | { | 506 | { |
508 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_peerstore_%s", database); | 507 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_peerstore_%s", database); |
509 | db = GNUNET_PLUGIN_load(db_lib_name, (void *) cfg); | 508 | db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); |
510 | GNUNET_free(database); | 509 | GNUNET_free (database); |
511 | } | 510 | } |
512 | if(NULL == db) | 511 | if (NULL == db) |
513 | { | 512 | { |
514 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Could not load database backend `%s'\n"), db_lib_name); | 513 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
515 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 514 | _("Could not load database backend `%s'\n"), db_lib_name); |
516 | return; | 515 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); |
516 | return; | ||
517 | } | 517 | } |
518 | nc = GNUNET_SERVER_notification_context_create (server, 16); | 518 | nc = GNUNET_SERVER_notification_context_create (server, 16); |
519 | watchers = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); | 519 | watchers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); |
520 | GNUNET_SCHEDULER_add_now(&cleanup_expired_records, NULL); | 520 | GNUNET_SCHEDULER_add_now (&cleanup_expired_records, NULL); |
521 | GNUNET_SERVER_add_handlers (server, handlers); | 521 | GNUNET_SERVER_add_handlers (server, handlers); |
522 | GNUNET_SERVER_connect_notify (server, &handle_client_connect, NULL); | 522 | GNUNET_SERVER_connect_notify (server, &handle_client_connect, NULL); |
523 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | 523 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
524 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 524 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
525 | &shutdown_task, | 525 | NULL); |
526 | NULL); | ||
527 | } | 526 | } |
528 | 527 | ||
529 | 528 | ||
@@ -538,11 +537,9 @@ int | |||
538 | main (int argc, char *const *argv) | 537 | main (int argc, char *const *argv) |
539 | { | 538 | { |
540 | return (GNUNET_OK == | 539 | return (GNUNET_OK == |
541 | GNUNET_SERVICE_run (argc, | 540 | GNUNET_SERVICE_run (argc, argv, "peerstore", |
542 | argv, | 541 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, &run, |
543 | "peerstore", | 542 | NULL)) ? 0 : 1; |
544 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, | ||
545 | &run, NULL)) ? 0 : 1; | ||
546 | } | 543 | } |
547 | 544 | ||
548 | /* end of gnunet-service-peerstore.c */ | 545 | /* end of gnunet-service-peerstore.c */ |
diff --git a/src/peerstore/peerstore.h b/src/peerstore/peerstore.h index 5757f784e..94970d906 100644 --- a/src/peerstore/peerstore.h +++ b/src/peerstore/peerstore.h | |||
@@ -30,11 +30,10 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | GNUNET_NETWORK_STRUCT_BEGIN | 32 | GNUNET_NETWORK_STRUCT_BEGIN |
33 | |||
34 | /** | 33 | /** |
35 | * Message carrying a PEERSTORE record message | 34 | * Message carrying a PEERSTORE record message |
36 | */ | 35 | */ |
37 | struct StoreRecordMessage | 36 | struct StoreRecordMessage |
38 | { | 37 | { |
39 | 38 | ||
40 | /** | 39 | /** |
@@ -102,5 +101,4 @@ struct StoreKeyHashMessage | |||
102 | }; | 101 | }; |
103 | 102 | ||
104 | GNUNET_NETWORK_STRUCT_END | 103 | GNUNET_NETWORK_STRUCT_END |
105 | |||
106 | #endif | 104 | #endif |
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c index 3c67846e6..bebf9678e 100644 --- a/src/peerstore/peerstore_api.c +++ b/src/peerstore/peerstore_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) | 3 | (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -256,30 +256,34 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h); | |||
256 | * | 256 | * |
257 | * @param cls a 'struct GNUNET_PEERSTORE_WatchContext *' | 257 | * @param cls a 'struct GNUNET_PEERSTORE_WatchContext *' |
258 | */ | 258 | */ |
259 | static void watch_request_sent (void *cls); | 259 | static void |
260 | watch_request_sent (void *cls); | ||
260 | 261 | ||
261 | /** | 262 | /** |
262 | * Callback after MQ envelope is sent | 263 | * Callback after MQ envelope is sent |
263 | * | 264 | * |
264 | * @param cls a 'struct GNUNET_PEERSTORE_IterateContext *' | 265 | * @param cls a 'struct GNUNET_PEERSTORE_IterateContext *' |
265 | */ | 266 | */ |
266 | static void iterate_request_sent (void *cls); | 267 | static void |
268 | iterate_request_sent (void *cls); | ||
267 | 269 | ||
268 | /** | 270 | /** |
269 | * Callback after MQ envelope is sent | 271 | * Callback after MQ envelope is sent |
270 | * | 272 | * |
271 | * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' | 273 | * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' |
272 | */ | 274 | */ |
273 | static void store_request_sent (void *cls); | 275 | static void |
276 | store_request_sent (void *cls); | ||
274 | 277 | ||
275 | /** | 278 | /** |
276 | * MQ message handlers | 279 | * MQ message handlers |
277 | */ | 280 | */ |
278 | static const struct GNUNET_MQ_MessageHandler mq_handlers[] = { | 281 | static const struct GNUNET_MQ_MessageHandler mq_handlers[] = { |
279 | {&handle_iterate_result, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, 0}, | 282 | {&handle_iterate_result, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, 0}, |
280 | {&handle_iterate_result, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, sizeof(struct GNUNET_MessageHeader)}, | 283 | {&handle_iterate_result, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, |
281 | {&handle_watch_result, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, 0}, | 284 | sizeof (struct GNUNET_MessageHeader)}, |
282 | GNUNET_MQ_HANDLERS_END | 285 | {&handle_watch_result, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, 0}, |
286 | GNUNET_MQ_HANDLERS_END | ||
283 | }; | 287 | }; |
284 | 288 | ||
285 | /******************************************************************************/ | 289 | /******************************************************************************/ |
@@ -291,32 +295,34 @@ handle_client_error (void *cls, enum GNUNET_MQ_Error error) | |||
291 | { | 295 | { |
292 | struct GNUNET_PEERSTORE_Handle *h = cls; | 296 | struct GNUNET_PEERSTORE_Handle *h = cls; |
293 | 297 | ||
294 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Received an error notification from MQ of type: %d\n"), error); | 298 | LOG (GNUNET_ERROR_TYPE_ERROR, |
295 | reconnect(h); | 299 | _("Received an error notification from MQ of type: %d\n"), error); |
300 | reconnect (h); | ||
296 | } | 301 | } |
297 | 302 | ||
303 | |||
298 | /** | 304 | /** |
299 | * Iterator over previous watches to resend them | 305 | * Iterator over previous watches to resend them |
300 | */ | 306 | */ |
301 | static int rewatch_it(void *cls, | 307 | static int |
302 | const struct GNUNET_HashCode *key, | 308 | rewatch_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
303 | void *value) | ||
304 | { | 309 | { |
305 | struct GNUNET_PEERSTORE_Handle *h = cls; | 310 | struct GNUNET_PEERSTORE_Handle *h = cls; |
306 | struct GNUNET_PEERSTORE_WatchContext *wc = value; | 311 | struct GNUNET_PEERSTORE_WatchContext *wc = value; |
307 | struct StoreKeyHashMessage *hm; | 312 | struct StoreKeyHashMessage *hm; |
308 | 313 | ||
309 | if(GNUNET_YES == wc->request_sent) | 314 | if (GNUNET_YES == wc->request_sent) |
310 | { /* Envelope gone, create new one. */ | 315 | { /* Envelope gone, create new one. */ |
311 | wc->ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); | 316 | wc->ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); |
312 | hm->keyhash = wc->keyhash; | 317 | hm->keyhash = wc->keyhash; |
313 | wc->request_sent = GNUNET_NO; | 318 | wc->request_sent = GNUNET_NO; |
314 | } | 319 | } |
315 | GNUNET_MQ_notify_sent(wc->ev, &watch_request_sent, wc); | 320 | GNUNET_MQ_notify_sent (wc->ev, &watch_request_sent, wc); |
316 | GNUNET_MQ_send(h->mq, wc->ev); | 321 | GNUNET_MQ_send (h->mq, wc->ev); |
317 | return GNUNET_YES; | 322 | return GNUNET_YES; |
318 | } | 323 | } |
319 | 324 | ||
325 | |||
320 | /** | 326 | /** |
321 | * Close the existing connection to PEERSTORE and reconnect. | 327 | * Close the existing connection to PEERSTORE and reconnect. |
322 | * | 328 | * |
@@ -330,10 +336,10 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
330 | void *icb_cls; | 336 | void *icb_cls; |
331 | struct GNUNET_PEERSTORE_StoreContext *sc; | 337 | struct GNUNET_PEERSTORE_StoreContext *sc; |
332 | 338 | ||
333 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n"); | 339 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n"); |
334 | if (NULL != h->mq) | 340 | if (NULL != h->mq) |
335 | { | 341 | { |
336 | GNUNET_MQ_destroy(h->mq); | 342 | GNUNET_MQ_destroy (h->mq); |
337 | h->mq = NULL; | 343 | h->mq = NULL; |
338 | } | 344 | } |
339 | if (NULL != h->client) | 345 | if (NULL != h->client) |
@@ -342,17 +348,15 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
342 | h->client = NULL; | 348 | h->client = NULL; |
343 | } | 349 | } |
344 | h->client = GNUNET_CLIENT_connect ("peerstore", h->cfg); | 350 | h->client = GNUNET_CLIENT_connect ("peerstore", h->cfg); |
345 | GNUNET_assert(NULL != h->client); | 351 | GNUNET_assert (NULL != h->client); |
346 | h->mq = GNUNET_MQ_queue_for_connection_client(h->client, | 352 | h->mq = |
347 | mq_handlers, | 353 | GNUNET_MQ_queue_for_connection_client (h->client, mq_handlers, |
348 | &handle_client_error, | 354 | &handle_client_error, h); |
349 | h); | 355 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
350 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 356 | "Resending pending requests after reconnect.\n"); |
351 | "Resending pending requests after reconnect.\n"); | ||
352 | if (NULL != h->watches) | 357 | if (NULL != h->watches) |
353 | { | 358 | { |
354 | GNUNET_CONTAINER_multihashmap_iterate(h->watches, | 359 | GNUNET_CONTAINER_multihashmap_iterate (h->watches, &rewatch_it, h); |
355 | &rewatch_it, h); | ||
356 | } | 360 | } |
357 | ic = h->iterate_head; | 361 | ic = h->iterate_head; |
358 | while (NULL != ic) | 362 | while (NULL != ic) |
@@ -361,26 +365,27 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
361 | { | 365 | { |
362 | icb = ic->callback; | 366 | icb = ic->callback; |
363 | icb_cls = ic->callback_cls; | 367 | icb_cls = ic->callback_cls; |
364 | GNUNET_PEERSTORE_iterate_cancel(ic); | 368 | GNUNET_PEERSTORE_iterate_cancel (ic); |
365 | if(NULL != icb) | 369 | if (NULL != icb) |
366 | icb(icb_cls, NULL,_("Iteration canceled due to reconnection.")); | 370 | icb (icb_cls, NULL, _("Iteration canceled due to reconnection.")); |
367 | } | 371 | } |
368 | else | 372 | else |
369 | { | 373 | { |
370 | GNUNET_MQ_notify_sent(ic->ev, &iterate_request_sent, ic); | 374 | GNUNET_MQ_notify_sent (ic->ev, &iterate_request_sent, ic); |
371 | GNUNET_MQ_send(h->mq, ic->ev); | 375 | GNUNET_MQ_send (h->mq, ic->ev); |
372 | } | 376 | } |
373 | ic = ic->next; | 377 | ic = ic->next; |
374 | } | 378 | } |
375 | sc = h->store_head; | 379 | sc = h->store_head; |
376 | while (NULL != sc) | 380 | while (NULL != sc) |
377 | { | 381 | { |
378 | GNUNET_MQ_notify_sent(sc->ev, &store_request_sent, sc); | 382 | GNUNET_MQ_notify_sent (sc->ev, &store_request_sent, sc); |
379 | GNUNET_MQ_send(h->mq, sc->ev); | 383 | GNUNET_MQ_send (h->mq, sc->ev); |
380 | sc = sc->next; | 384 | sc = sc->next; |
381 | } | 385 | } |
382 | } | 386 | } |
383 | 387 | ||
388 | |||
384 | /** | 389 | /** |
385 | * Iterator over watch requests to cancel them. | 390 | * Iterator over watch requests to cancel them. |
386 | * | 391 | * |
@@ -398,6 +403,7 @@ destroy_watch (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
398 | return GNUNET_YES; | 403 | return GNUNET_YES; |
399 | } | 404 | } |
400 | 405 | ||
406 | |||
401 | /** | 407 | /** |
402 | * Kill the connection to the service. This can be delayed in case of pending | 408 | * Kill the connection to the service. This can be delayed in case of pending |
403 | * STORE requests and the user explicitly asked to sync first. Otherwise it is | 409 | * STORE requests and the user explicitly asked to sync first. Otherwise it is |
@@ -405,11 +411,12 @@ destroy_watch (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
405 | * | 411 | * |
406 | * @param h Handle to the service. | 412 | * @param h Handle to the service. |
407 | */ | 413 | */ |
408 | static void do_disconnect (struct GNUNET_PEERSTORE_Handle *h) | 414 | static void |
415 | do_disconnect (struct GNUNET_PEERSTORE_Handle *h) | ||
409 | { | 416 | { |
410 | if(NULL != h->mq) | 417 | if (NULL != h->mq) |
411 | { | 418 | { |
412 | GNUNET_MQ_destroy(h->mq); | 419 | GNUNET_MQ_destroy (h->mq); |
413 | h->mq = NULL; | 420 | h->mq = NULL; |
414 | } | 421 | } |
415 | if (NULL != h->client) | 422 | if (NULL != h->client) |
@@ -417,9 +424,10 @@ static void do_disconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
417 | GNUNET_CLIENT_disconnect (h->client); | 424 | GNUNET_CLIENT_disconnect (h->client); |
418 | h->client = NULL; | 425 | h->client = NULL; |
419 | } | 426 | } |
420 | GNUNET_free(h); | 427 | GNUNET_free (h); |
421 | } | 428 | } |
422 | 429 | ||
430 | |||
423 | /** | 431 | /** |
424 | * Connect to the PEERSTORE service. | 432 | * Connect to the PEERSTORE service. |
425 | * | 433 | * |
@@ -431,27 +439,28 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
431 | struct GNUNET_PEERSTORE_Handle *h; | 439 | struct GNUNET_PEERSTORE_Handle *h; |
432 | 440 | ||
433 | h = GNUNET_new (struct GNUNET_PEERSTORE_Handle); | 441 | h = GNUNET_new (struct GNUNET_PEERSTORE_Handle); |
442 | |||
434 | h->client = GNUNET_CLIENT_connect ("peerstore", cfg); | 443 | h->client = GNUNET_CLIENT_connect ("peerstore", cfg); |
435 | if(NULL == h->client) | 444 | if (NULL == h->client) |
436 | { | 445 | { |
437 | GNUNET_free(h); | 446 | GNUNET_free (h); |
438 | return NULL; | 447 | return NULL; |
439 | } | 448 | } |
440 | h->cfg = cfg; | 449 | h->cfg = cfg; |
441 | h->disconnecting = GNUNET_NO; | 450 | h->disconnecting = GNUNET_NO; |
442 | h->mq = GNUNET_MQ_queue_for_connection_client(h->client, | 451 | h->mq = |
443 | mq_handlers, | 452 | GNUNET_MQ_queue_for_connection_client (h->client, mq_handlers, |
444 | &handle_client_error, | 453 | &handle_client_error, h); |
445 | h); | 454 | if (NULL == h->mq) |
446 | if(NULL == h->mq) | ||
447 | { | 455 | { |
448 | GNUNET_free(h); | 456 | GNUNET_free (h); |
449 | return NULL; | 457 | return NULL; |
450 | } | 458 | } |
451 | LOG(GNUNET_ERROR_TYPE_DEBUG, "New connection created\n"); | 459 | LOG (GNUNET_ERROR_TYPE_DEBUG, "New connection created\n"); |
452 | return h; | 460 | return h; |
453 | } | 461 | } |
454 | 462 | ||
463 | |||
455 | /** | 464 | /** |
456 | * Disconnect from the PEERSTORE service. Any pending ITERATE and WATCH requests | 465 | * Disconnect from the PEERSTORE service. Any pending ITERATE and WATCH requests |
457 | * will be canceled. | 466 | * will be canceled. |
@@ -468,11 +477,11 @@ GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first) | |||
468 | struct GNUNET_PEERSTORE_StoreContext *sc; | 477 | struct GNUNET_PEERSTORE_StoreContext *sc; |
469 | struct GNUNET_PEERSTORE_StoreContext *sc_iter; | 478 | struct GNUNET_PEERSTORE_StoreContext *sc_iter; |
470 | 479 | ||
471 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting.\n"); | 480 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting.\n"); |
472 | if(NULL != h->watches) | 481 | if (NULL != h->watches) |
473 | { | 482 | { |
474 | GNUNET_CONTAINER_multihashmap_iterate (h->watches, &destroy_watch, NULL); | 483 | GNUNET_CONTAINER_multihashmap_iterate (h->watches, &destroy_watch, NULL); |
475 | GNUNET_CONTAINER_multihashmap_destroy(h->watches); | 484 | GNUNET_CONTAINER_multihashmap_destroy (h->watches); |
476 | h->watches = NULL; | 485 | h->watches = NULL; |
477 | } | 486 | } |
478 | ic_iter = h->iterate_head; | 487 | ic_iter = h->iterate_head; |
@@ -487,7 +496,7 @@ GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first) | |||
487 | if (GNUNET_YES == sync_first) | 496 | if (GNUNET_YES == sync_first) |
488 | { | 497 | { |
489 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 498 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
490 | "Delaying disconnection due to pending store requests.\n"); | 499 | "Delaying disconnection due to pending store requests.\n"); |
491 | h->disconnecting = GNUNET_YES; | 500 | h->disconnecting = GNUNET_YES; |
492 | return; | 501 | return; |
493 | } | 502 | } |
@@ -512,7 +521,8 @@ GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first) | |||
512 | * | 521 | * |
513 | * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' | 522 | * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' |
514 | */ | 523 | */ |
515 | static void store_request_sent (void *cls) | 524 | static void |
525 | store_request_sent (void *cls) | ||
516 | { | 526 | { |
517 | struct GNUNET_PEERSTORE_StoreContext *sc = cls; | 527 | struct GNUNET_PEERSTORE_StoreContext *sc = cls; |
518 | GNUNET_PEERSTORE_Continuation cont; | 528 | GNUNET_PEERSTORE_Continuation cont; |
@@ -521,11 +531,12 @@ static void store_request_sent (void *cls) | |||
521 | sc->ev = NULL; | 531 | sc->ev = NULL; |
522 | cont = sc->cont; | 532 | cont = sc->cont; |
523 | cont_cls = sc->cont_cls; | 533 | cont_cls = sc->cont_cls; |
524 | GNUNET_PEERSTORE_store_cancel(sc); | 534 | GNUNET_PEERSTORE_store_cancel (sc); |
525 | if(NULL != cont) | 535 | if (NULL != cont) |
526 | cont(cont_cls, GNUNET_OK); | 536 | cont (cont_cls, GNUNET_OK); |
527 | } | 537 | } |
528 | 538 | ||
539 | |||
529 | /** | 540 | /** |
530 | * Cancel a store request | 541 | * Cancel a store request |
531 | * | 542 | * |
@@ -536,17 +547,18 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | |||
536 | { | 547 | { |
537 | struct GNUNET_PEERSTORE_Handle *h = sc->h; | 548 | struct GNUNET_PEERSTORE_Handle *h = sc->h; |
538 | 549 | ||
539 | if(NULL != sc->ev) | 550 | if (NULL != sc->ev) |
540 | { | 551 | { |
541 | GNUNET_MQ_send_cancel(sc->ev); | 552 | GNUNET_MQ_send_cancel (sc->ev); |
542 | sc->ev = NULL; | 553 | sc->ev = NULL; |
543 | } | 554 | } |
544 | GNUNET_CONTAINER_DLL_remove(sc->h->store_head, sc->h->store_tail, sc); | 555 | GNUNET_CONTAINER_DLL_remove (sc->h->store_head, sc->h->store_tail, sc); |
545 | GNUNET_free(sc); | 556 | GNUNET_free (sc); |
546 | if (GNUNET_YES == h->disconnecting && NULL == h->store_head) | 557 | if (GNUNET_YES == h->disconnecting && NULL == h->store_head) |
547 | do_disconnect (h); | 558 | do_disconnect (h); |
548 | } | 559 | } |
549 | 560 | ||
561 | |||
550 | /** | 562 | /** |
551 | * Store a new entry in the PEERSTORE. | 563 | * Store a new entry in the PEERSTORE. |
552 | * Note that stored entries can be lost in some cases | 564 | * Note that stored entries can be lost in some cases |
@@ -566,41 +578,35 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | |||
566 | struct GNUNET_PEERSTORE_StoreContext * | 578 | struct GNUNET_PEERSTORE_StoreContext * |
567 | GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | 579 | GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, |
568 | const char *sub_system, | 580 | const char *sub_system, |
569 | const struct GNUNET_PeerIdentity *peer, | 581 | const struct GNUNET_PeerIdentity *peer, const char *key, |
570 | const char *key, | 582 | const void *value, size_t size, |
571 | const void *value, | ||
572 | size_t size, | ||
573 | struct GNUNET_TIME_Absolute expiry, | 583 | struct GNUNET_TIME_Absolute expiry, |
574 | enum GNUNET_PEERSTORE_StoreOption options, | 584 | enum GNUNET_PEERSTORE_StoreOption options, |
575 | GNUNET_PEERSTORE_Continuation cont, | 585 | GNUNET_PEERSTORE_Continuation cont, void *cont_cls) |
576 | void *cont_cls) | ||
577 | { | 586 | { |
578 | struct GNUNET_MQ_Envelope *ev; | 587 | struct GNUNET_MQ_Envelope *ev; |
579 | struct GNUNET_PEERSTORE_StoreContext *sc; | 588 | struct GNUNET_PEERSTORE_StoreContext *sc; |
580 | 589 | ||
581 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 590 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
582 | "Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n", | 591 | "Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n", |
583 | size, sub_system, GNUNET_i2s (peer), key); | 592 | size, sub_system, GNUNET_i2s (peer), key); |
584 | ev = PEERSTORE_create_record_mq_envelope(sub_system, | 593 | ev = PEERSTORE_create_record_mq_envelope (sub_system, peer, key, value, size, |
585 | peer, | 594 | &expiry, options, |
586 | key, | 595 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); |
587 | value, | 596 | sc = GNUNET_new (struct GNUNET_PEERSTORE_StoreContext); |
588 | size, | 597 | |
589 | &expiry, | ||
590 | options, | ||
591 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); | ||
592 | sc = GNUNET_new(struct GNUNET_PEERSTORE_StoreContext); | ||
593 | sc->ev = ev; | 598 | sc->ev = ev; |
594 | sc->cont = cont; | 599 | sc->cont = cont; |
595 | sc->cont_cls = cont_cls; | 600 | sc->cont_cls = cont_cls; |
596 | sc->h = h; | 601 | sc->h = h; |
597 | GNUNET_CONTAINER_DLL_insert_tail(h->store_head, h->store_tail, sc); | 602 | GNUNET_CONTAINER_DLL_insert_tail (h->store_head, h->store_tail, sc); |
598 | GNUNET_MQ_notify_sent(ev, &store_request_sent, sc); | 603 | GNUNET_MQ_notify_sent (ev, &store_request_sent, sc); |
599 | GNUNET_MQ_send(h->mq, ev); | 604 | GNUNET_MQ_send (h->mq, ev); |
600 | return sc; | 605 | return sc; |
601 | 606 | ||
602 | } | 607 | } |
603 | 608 | ||
609 | |||
604 | /******************************************************************************/ | 610 | /******************************************************************************/ |
605 | /******************* ITERATE FUNCTIONS *********************/ | 611 | /******************* ITERATE FUNCTIONS *********************/ |
606 | /******************************************************************************/ | 612 | /******************************************************************************/ |
@@ -623,62 +629,67 @@ handle_iterate_result (void *cls, const struct GNUNET_MessageHeader *msg) | |||
623 | int continue_iter; | 629 | int continue_iter; |
624 | 630 | ||
625 | ic = h->iterate_head; | 631 | ic = h->iterate_head; |
626 | if(NULL == ic) | 632 | if (NULL == ic) |
627 | { | 633 | { |
628 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Unexpected iteration response, this should not happen.\n")); | 634 | LOG (GNUNET_ERROR_TYPE_ERROR, |
629 | reconnect(h); | 635 | _("Unexpected iteration response, this should not happen.\n")); |
636 | reconnect (h); | ||
630 | return; | 637 | return; |
631 | } | 638 | } |
632 | callback = ic->callback; | 639 | callback = ic->callback; |
633 | callback_cls = ic->callback_cls; | 640 | callback_cls = ic->callback_cls; |
634 | if(NULL == msg) /* Connection error */ | 641 | if (NULL == msg) /* Connection error */ |
635 | { | 642 | { |
636 | 643 | ||
637 | if(NULL != callback) | 644 | if (NULL != callback) |
638 | callback(callback_cls, NULL, | 645 | callback (callback_cls, NULL, |
639 | _("Error communicating with `PEERSTORE' service.")); | 646 | _("Error communicating with `PEERSTORE' service.")); |
640 | reconnect(h); | 647 | reconnect (h); |
641 | return; | 648 | return; |
642 | } | 649 | } |
643 | msg_type = ntohs(msg->type); | 650 | msg_type = ntohs (msg->type); |
644 | if(GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END == msg_type) | 651 | if (GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END == msg_type) |
645 | { | 652 | { |
646 | ic->request_sent = GNUNET_NO; | 653 | ic->request_sent = GNUNET_NO; |
647 | GNUNET_PEERSTORE_iterate_cancel(ic); | 654 | GNUNET_PEERSTORE_iterate_cancel (ic); |
648 | if(NULL != callback) | 655 | if (NULL != callback) |
649 | callback(callback_cls, NULL, NULL); | 656 | callback (callback_cls, NULL, NULL); |
650 | return; | 657 | return; |
651 | } | 658 | } |
652 | if(NULL != callback) | 659 | if (NULL != callback) |
653 | { | 660 | { |
654 | record = PEERSTORE_parse_record_message(msg); | 661 | record = PEERSTORE_parse_record_message (msg); |
655 | if(NULL == record) | 662 | if (NULL == record) |
656 | continue_iter = callback(callback_cls, NULL, _("Received a malformed response from service.")); | 663 | continue_iter = |
664 | callback (callback_cls, NULL, | ||
665 | _("Received a malformed response from service.")); | ||
657 | else | 666 | else |
658 | { | 667 | { |
659 | continue_iter = callback(callback_cls, record, NULL); | 668 | continue_iter = callback (callback_cls, record, NULL); |
660 | PEERSTORE_destroy_record(record); | 669 | PEERSTORE_destroy_record (record); |
661 | } | 670 | } |
662 | if(GNUNET_NO == continue_iter) | 671 | if (GNUNET_NO == continue_iter) |
663 | ic->callback = NULL; | 672 | ic->callback = NULL; |
664 | } | 673 | } |
665 | |||
666 | } | 674 | } |
667 | 675 | ||
676 | |||
668 | /** | 677 | /** |
669 | * Callback after MQ envelope is sent | 678 | * Callback after MQ envelope is sent |
670 | * | 679 | * |
671 | * @param cls a 'struct GNUNET_PEERSTORE_IterateContext *' | 680 | * @param cls a 'struct GNUNET_PEERSTORE_IterateContext *' |
672 | */ | 681 | */ |
673 | static void iterate_request_sent (void *cls) | 682 | static void |
683 | iterate_request_sent (void *cls) | ||
674 | { | 684 | { |
675 | struct GNUNET_PEERSTORE_IterateContext *ic = cls; | 685 | struct GNUNET_PEERSTORE_IterateContext *ic = cls; |
676 | 686 | ||
677 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Iterate request sent to service.\n"); | 687 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Iterate request sent to service.\n"); |
678 | ic->request_sent = GNUNET_YES; | 688 | ic->request_sent = GNUNET_YES; |
679 | ic->ev = NULL; | 689 | ic->ev = NULL; |
680 | } | 690 | } |
681 | 691 | ||
692 | |||
682 | /** | 693 | /** |
683 | * Called when the iterate request is timedout | 694 | * Called when the iterate request is timedout |
684 | * | 695 | * |
@@ -691,9 +702,10 @@ iterate_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
691 | struct GNUNET_PEERSTORE_IterateContext *ic = cls; | 702 | struct GNUNET_PEERSTORE_IterateContext *ic = cls; |
692 | 703 | ||
693 | ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 704 | ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
694 | GNUNET_PEERSTORE_iterate_cancel(ic); | 705 | GNUNET_PEERSTORE_iterate_cancel (ic); |
695 | } | 706 | } |
696 | 707 | ||
708 | |||
697 | /** | 709 | /** |
698 | * Cancel an iterate request | 710 | * Cancel an iterate request |
699 | * Please do not call after the iterate request is done | 711 | * Please do not call after the iterate request is done |
@@ -703,25 +715,26 @@ iterate_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
703 | void | 715 | void |
704 | GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) | 716 | GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) |
705 | { | 717 | { |
706 | if(GNUNET_SCHEDULER_NO_TASK != ic->timeout_task) | 718 | if (GNUNET_SCHEDULER_NO_TASK != ic->timeout_task) |
707 | { | 719 | { |
708 | GNUNET_SCHEDULER_cancel(ic->timeout_task); | 720 | GNUNET_SCHEDULER_cancel (ic->timeout_task); |
709 | ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 721 | ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
710 | } | 722 | } |
711 | if(GNUNET_NO == ic->request_sent) | 723 | if (GNUNET_NO == ic->request_sent) |
712 | { | 724 | { |
713 | if(NULL != ic->ev) | 725 | if (NULL != ic->ev) |
714 | { | 726 | { |
715 | GNUNET_MQ_send_cancel(ic->ev); | 727 | GNUNET_MQ_send_cancel (ic->ev); |
716 | ic->ev = NULL; | 728 | ic->ev = NULL; |
717 | } | 729 | } |
718 | GNUNET_CONTAINER_DLL_remove(ic->h->iterate_head, ic->h->iterate_tail, ic); | 730 | GNUNET_CONTAINER_DLL_remove (ic->h->iterate_head, ic->h->iterate_tail, ic); |
719 | GNUNET_free(ic); | 731 | GNUNET_free (ic); |
720 | } | 732 | } |
721 | else | 733 | else |
722 | ic->callback = NULL; | 734 | ic->callback = NULL; |
723 | } | 735 | } |
724 | 736 | ||
737 | |||
725 | /** | 738 | /** |
726 | * Iterate over records matching supplied key information | 739 | * Iterate over records matching supplied key information |
727 | * | 740 | * |
@@ -736,38 +749,36 @@ GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) | |||
736 | */ | 749 | */ |
737 | struct GNUNET_PEERSTORE_IterateContext * | 750 | struct GNUNET_PEERSTORE_IterateContext * |
738 | GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, | 751 | GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, |
739 | const char *sub_system, | 752 | const char *sub_system, |
740 | const struct GNUNET_PeerIdentity *peer, | 753 | const struct GNUNET_PeerIdentity *peer, |
741 | const char *key, | 754 | const char *key, struct GNUNET_TIME_Relative timeout, |
742 | struct GNUNET_TIME_Relative timeout, | 755 | GNUNET_PEERSTORE_Processor callback, |
743 | GNUNET_PEERSTORE_Processor callback, void *callback_cls) | 756 | void *callback_cls) |
744 | { | 757 | { |
745 | struct GNUNET_MQ_Envelope *ev; | 758 | struct GNUNET_MQ_Envelope *ev; |
746 | struct GNUNET_PEERSTORE_IterateContext *ic; | 759 | struct GNUNET_PEERSTORE_IterateContext *ic; |
747 | 760 | ||
748 | ev = PEERSTORE_create_record_mq_envelope(sub_system, | 761 | ev = PEERSTORE_create_record_mq_envelope (sub_system, peer, key, NULL, 0, |
749 | peer, | 762 | NULL, 0, |
750 | key, | 763 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); |
751 | NULL, | 764 | ic = GNUNET_new (struct GNUNET_PEERSTORE_IterateContext); |
752 | 0, | 765 | |
753 | NULL, | ||
754 | 0, | ||
755 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); | ||
756 | ic = GNUNET_new(struct GNUNET_PEERSTORE_IterateContext); | ||
757 | ic->callback = callback; | 766 | ic->callback = callback; |
758 | ic->callback_cls = callback_cls; | 767 | ic->callback_cls = callback_cls; |
759 | ic->ev = ev; | 768 | ic->ev = ev; |
760 | ic->h = h; | 769 | ic->h = h; |
761 | ic->request_sent = GNUNET_NO; | 770 | ic->request_sent = GNUNET_NO; |
762 | GNUNET_CONTAINER_DLL_insert_tail(h->iterate_head, h->iterate_tail, ic); | 771 | GNUNET_CONTAINER_DLL_insert_tail (h->iterate_head, h->iterate_tail, ic); |
763 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 772 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
764 | "Sending an iterate request for sub system `%s'\n", sub_system); | 773 | "Sending an iterate request for sub system `%s'\n", sub_system); |
765 | GNUNET_MQ_notify_sent(ev, &iterate_request_sent, ic); | 774 | GNUNET_MQ_notify_sent (ev, &iterate_request_sent, ic); |
766 | GNUNET_MQ_send(h->mq, ev); | 775 | GNUNET_MQ_send (h->mq, ev); |
767 | ic->timeout_task = GNUNET_SCHEDULER_add_delayed(timeout, &iterate_timeout, ic); | 776 | ic->timeout_task = |
777 | GNUNET_SCHEDULER_add_delayed (timeout, &iterate_timeout, ic); | ||
768 | return ic; | 778 | return ic; |
769 | } | 779 | } |
770 | 780 | ||
781 | |||
771 | /******************************************************************************/ | 782 | /******************************************************************************/ |
772 | /******************* WATCH FUNCTIONS *********************/ | 783 | /******************* WATCH FUNCTIONS *********************/ |
773 | /******************************************************************************/ | 784 | /******************************************************************************/ |
@@ -786,36 +797,38 @@ handle_watch_result (void *cls, const struct GNUNET_MessageHeader *msg) | |||
786 | struct GNUNET_HashCode keyhash; | 797 | struct GNUNET_HashCode keyhash; |
787 | struct GNUNET_PEERSTORE_WatchContext *wc; | 798 | struct GNUNET_PEERSTORE_WatchContext *wc; |
788 | 799 | ||
789 | if(NULL == msg) | 800 | if (NULL == msg) |
790 | { | 801 | { |
791 | LOG(GNUNET_ERROR_TYPE_ERROR, | 802 | LOG (GNUNET_ERROR_TYPE_ERROR, |
792 | _("Problem receiving a watch response, no way to determine which request.\n")); | 803 | _ |
793 | reconnect(h); | 804 | ("Problem receiving a watch response, no way to determine which request.\n")); |
805 | reconnect (h); | ||
794 | return; | 806 | return; |
795 | } | 807 | } |
796 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Received a watch record from service.\n"); | 808 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a watch record from service.\n"); |
797 | record = PEERSTORE_parse_record_message(msg); | 809 | record = PEERSTORE_parse_record_message (msg); |
798 | PEERSTORE_hash_key(record->sub_system, | 810 | PEERSTORE_hash_key (record->sub_system, record->peer, record->key, &keyhash); |
799 | record->peer, record->key, &keyhash); | 811 | wc = GNUNET_CONTAINER_multihashmap_get (h->watches, &keyhash); |
800 | wc = GNUNET_CONTAINER_multihashmap_get(h->watches, &keyhash); | 812 | if (NULL == wc) |
801 | if(NULL == wc) | ||
802 | { | 813 | { |
803 | LOG(GNUNET_ERROR_TYPE_ERROR, | 814 | LOG (GNUNET_ERROR_TYPE_ERROR, |
804 | _("Received a watch result for a non existing watch.\n")); | 815 | _("Received a watch result for a non existing watch.\n")); |
805 | reconnect(h); | 816 | reconnect (h); |
806 | return; | 817 | return; |
807 | } | 818 | } |
808 | if(NULL != wc->callback) | 819 | if (NULL != wc->callback) |
809 | wc->callback(wc->callback_cls, record, NULL); | 820 | wc->callback (wc->callback_cls, record, NULL); |
810 | PEERSTORE_destroy_record(record); | 821 | PEERSTORE_destroy_record (record); |
811 | } | 822 | } |
812 | 823 | ||
824 | |||
813 | /** | 825 | /** |
814 | * Callback after MQ envelope is sent | 826 | * Callback after MQ envelope is sent |
815 | * | 827 | * |
816 | * @param cls a 'struct GNUNET_PEERSTORE_WatchContext *' | 828 | * @param cls a 'struct GNUNET_PEERSTORE_WatchContext *' |
817 | */ | 829 | */ |
818 | static void watch_request_sent (void *cls) | 830 | static void |
831 | watch_request_sent (void *cls) | ||
819 | { | 832 | { |
820 | struct GNUNET_PEERSTORE_WatchContext *wc = cls; | 833 | struct GNUNET_PEERSTORE_WatchContext *wc = cls; |
821 | 834 | ||
@@ -823,37 +836,39 @@ static void watch_request_sent (void *cls) | |||
823 | wc->ev = NULL; | 836 | wc->ev = NULL; |
824 | } | 837 | } |
825 | 838 | ||
839 | |||
826 | /** | 840 | /** |
827 | * Cancel a watch request | 841 | * Cancel a watch request |
828 | * | 842 | * |
829 | * @param wc handle to the watch request | 843 | * @param wc handle to the watch request |
830 | */ | 844 | */ |
831 | void | 845 | void |
832 | GNUNET_PEERSTORE_watch_cancel(struct GNUNET_PEERSTORE_WatchContext *wc) | 846 | GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc) |
833 | { | 847 | { |
834 | struct GNUNET_PEERSTORE_Handle *h = wc->h; | 848 | struct GNUNET_PEERSTORE_Handle *h = wc->h; |
835 | struct GNUNET_MQ_Envelope *ev; | 849 | struct GNUNET_MQ_Envelope *ev; |
836 | struct StoreKeyHashMessage *hm; | 850 | struct StoreKeyHashMessage *hm; |
837 | 851 | ||
838 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Canceling watch.\n"); | 852 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Canceling watch.\n"); |
839 | if(GNUNET_YES == wc->request_sent) /* If request already sent to service, send a cancel request. */ | 853 | if (GNUNET_YES == wc->request_sent) /* If request already sent to service, send a cancel request. */ |
840 | { | 854 | { |
841 | ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL); | 855 | ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL); |
842 | hm->keyhash = wc->keyhash; | 856 | hm->keyhash = wc->keyhash; |
843 | GNUNET_MQ_send(h->mq, ev); | 857 | GNUNET_MQ_send (h->mq, ev); |
844 | wc->callback = NULL; | 858 | wc->callback = NULL; |
845 | wc->callback_cls = NULL; | 859 | wc->callback_cls = NULL; |
846 | } | 860 | } |
847 | if(NULL != wc->ev) | 861 | if (NULL != wc->ev) |
848 | { | 862 | { |
849 | GNUNET_MQ_send_cancel(wc->ev); | 863 | GNUNET_MQ_send_cancel (wc->ev); |
850 | wc->ev = NULL; | 864 | wc->ev = NULL; |
851 | } | 865 | } |
852 | GNUNET_CONTAINER_multihashmap_remove(h->watches, &wc->keyhash, wc); | 866 | GNUNET_CONTAINER_multihashmap_remove (h->watches, &wc->keyhash, wc); |
853 | GNUNET_free(wc); | 867 | GNUNET_free (wc); |
854 | 868 | ||
855 | } | 869 | } |
856 | 870 | ||
871 | |||
857 | /** | 872 | /** |
858 | * Request watching a given key | 873 | * Request watching a given key |
859 | * User will be notified with any new values added to key | 874 | * User will be notified with any new values added to key |
@@ -868,36 +883,36 @@ GNUNET_PEERSTORE_watch_cancel(struct GNUNET_PEERSTORE_WatchContext *wc) | |||
868 | */ | 883 | */ |
869 | struct GNUNET_PEERSTORE_WatchContext * | 884 | struct GNUNET_PEERSTORE_WatchContext * |
870 | GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h, | 885 | GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h, |
871 | const char *sub_system, | 886 | const char *sub_system, |
872 | const struct GNUNET_PeerIdentity *peer, | 887 | const struct GNUNET_PeerIdentity *peer, const char *key, |
873 | const char *key, | 888 | GNUNET_PEERSTORE_Processor callback, void *callback_cls) |
874 | GNUNET_PEERSTORE_Processor callback, void *callback_cls) | ||
875 | { | 889 | { |
876 | struct GNUNET_MQ_Envelope *ev; | 890 | struct GNUNET_MQ_Envelope *ev; |
877 | struct StoreKeyHashMessage *hm; | 891 | struct StoreKeyHashMessage *hm; |
878 | struct GNUNET_PEERSTORE_WatchContext *wc; | 892 | struct GNUNET_PEERSTORE_WatchContext *wc; |
879 | 893 | ||
880 | GNUNET_assert(NULL != sub_system); | 894 | GNUNET_assert (NULL != sub_system); |
881 | GNUNET_assert(NULL != peer); | 895 | GNUNET_assert (NULL != peer); |
882 | GNUNET_assert(NULL != key); | 896 | GNUNET_assert (NULL != key); |
883 | ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); | 897 | ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); |
884 | PEERSTORE_hash_key(sub_system, peer, key, &hm->keyhash); | 898 | PEERSTORE_hash_key (sub_system, peer, key, &hm->keyhash); |
885 | wc = GNUNET_new(struct GNUNET_PEERSTORE_WatchContext); | 899 | wc = GNUNET_new (struct GNUNET_PEERSTORE_WatchContext); |
900 | |||
886 | wc->callback = callback; | 901 | wc->callback = callback; |
887 | wc->callback_cls = callback_cls; | 902 | wc->callback_cls = callback_cls; |
888 | wc->ev = ev; | 903 | wc->ev = ev; |
889 | wc->h = h; | 904 | wc->h = h; |
890 | wc->request_sent = GNUNET_NO; | 905 | wc->request_sent = GNUNET_NO; |
891 | wc->keyhash = hm->keyhash; | 906 | wc->keyhash = hm->keyhash; |
892 | if(NULL == h->watches) | 907 | if (NULL == h->watches) |
893 | h->watches = GNUNET_CONTAINER_multihashmap_create(5, GNUNET_NO); | 908 | h->watches = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO); |
894 | GNUNET_CONTAINER_multihashmap_put(h->watches, &wc->keyhash, | 909 | GNUNET_CONTAINER_multihashmap_put (h->watches, &wc->keyhash, wc, |
895 | wc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 910 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
896 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 911 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
897 | "Sending a watch request for ss `%s', peer `%s', key `%s'.\n", | 912 | "Sending a watch request for ss `%s', peer `%s', key `%s'.\n", |
898 | sub_system, GNUNET_i2s(peer), key); | 913 | sub_system, GNUNET_i2s (peer), key); |
899 | GNUNET_MQ_notify_sent(ev, &watch_request_sent, wc); | 914 | GNUNET_MQ_notify_sent (ev, &watch_request_sent, wc); |
900 | GNUNET_MQ_send(h->mq, ev); | 915 | GNUNET_MQ_send (h->mq, ev); |
901 | return wc; | 916 | return wc; |
902 | } | 917 | } |
903 | 918 | ||
diff --git a/src/peerstore/peerstore_common.c b/src/peerstore/peerstore_common.c index 0cb801cc4..1f86fe442 100644 --- a/src/peerstore/peerstore_common.c +++ b/src/peerstore/peerstore_common.c | |||
@@ -30,10 +30,9 @@ | |||
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, const char *key, |
35 | const char *key, | 35 | struct GNUNET_HashCode *ret) |
36 | struct GNUNET_HashCode *ret) | ||
37 | { | 36 | { |
38 | size_t sssize; | 37 | size_t sssize; |
39 | size_t psize; | 38 | size_t psize; |
@@ -42,21 +41,22 @@ PEERSTORE_hash_key(const char *sub_system, | |||
42 | void *block; | 41 | void *block; |
43 | void *blockptr; | 42 | void *blockptr; |
44 | 43 | ||
45 | sssize = strlen(sub_system) + 1; | 44 | sssize = strlen (sub_system) + 1; |
46 | psize = sizeof(struct GNUNET_PeerIdentity); | 45 | psize = sizeof (struct GNUNET_PeerIdentity); |
47 | ksize = strlen(key) + 1; | 46 | ksize = strlen (key) + 1; |
48 | totalsize = sssize + psize + ksize; | 47 | totalsize = sssize + psize + ksize; |
49 | block = GNUNET_malloc(totalsize); | 48 | block = GNUNET_malloc (totalsize); |
50 | blockptr = block; | 49 | blockptr = block; |
51 | memcpy(blockptr, sub_system, sssize); | 50 | memcpy (blockptr, sub_system, sssize); |
52 | blockptr += sssize; | 51 | blockptr += sssize; |
53 | memcpy(blockptr, peer, psize); | 52 | memcpy (blockptr, peer, psize); |
54 | blockptr += psize; | 53 | blockptr += psize; |
55 | memcpy(blockptr, key, ksize); | 54 | memcpy (blockptr, key, ksize); |
56 | GNUNET_CRYPTO_hash(block, totalsize, ret); | 55 | GNUNET_CRYPTO_hash (block, totalsize, ret); |
57 | GNUNET_free(block); | 56 | GNUNET_free (block); |
58 | } | 57 | } |
59 | 58 | ||
59 | |||
60 | /** | 60 | /** |
61 | * Creates a record message ready to be sent | 61 | * Creates a record message ready to be sent |
62 | * | 62 | * |
@@ -70,13 +70,12 @@ PEERSTORE_hash_key(const char *sub_system, | |||
70 | * @return pointer to record message struct | 70 | * @return pointer to record message struct |
71 | */ | 71 | */ |
72 | struct StoreRecordMessage * | 72 | struct StoreRecordMessage * |
73 | PEERSTORE_create_record_message(const char *sub_system, | 73 | PEERSTORE_create_record_message (const char *sub_system, |
74 | const struct GNUNET_PeerIdentity *peer, | 74 | const struct GNUNET_PeerIdentity *peer, |
75 | const char *key, | 75 | const char *key, const void *value, |
76 | const void *value, | 76 | size_t value_size, |
77 | size_t value_size, | 77 | struct GNUNET_TIME_Absolute *expiry, |
78 | struct GNUNET_TIME_Absolute *expiry, | 78 | uint16_t msg_type) |
79 | uint16_t msg_type) | ||
80 | { | 79 | { |
81 | struct StoreRecordMessage *srm; | 80 | struct StoreRecordMessage *srm; |
82 | size_t ss_size; | 81 | size_t ss_size; |
@@ -84,40 +83,38 @@ PEERSTORE_create_record_message(const char *sub_system, | |||
84 | size_t request_size; | 83 | size_t request_size; |
85 | void *dummy; | 84 | void *dummy; |
86 | 85 | ||
87 | ss_size = strlen(sub_system) + 1; | 86 | ss_size = strlen (sub_system) + 1; |
88 | if(NULL == key) | 87 | if (NULL == key) |
89 | key_size = 0; | 88 | key_size = 0; |
90 | else | 89 | else |
91 | key_size = strlen(key) + 1; | 90 | key_size = strlen (key) + 1; |
92 | request_size = sizeof(struct StoreRecordMessage) + | 91 | request_size = |
93 | ss_size + | 92 | sizeof (struct StoreRecordMessage) + ss_size + key_size + value_size; |
94 | key_size + | 93 | srm = GNUNET_malloc (request_size); |
95 | value_size; | 94 | srm->header.size = htons (request_size); |
96 | srm = GNUNET_malloc(request_size); | 95 | srm->header.type = htons (msg_type); |
97 | srm->header.size = htons(request_size); | 96 | srm->key_size = htons (key_size); |
98 | srm->header.type = htons(msg_type); | 97 | if (NULL != expiry) |
99 | srm->key_size = htons(key_size); | ||
100 | if(NULL != expiry) | ||
101 | srm->expiry = *expiry; | 98 | srm->expiry = *expiry; |
102 | if(NULL == peer) | 99 | if (NULL == peer) |
103 | srm->peer_set = htons(GNUNET_NO); | 100 | srm->peer_set = htons (GNUNET_NO); |
104 | else | 101 | else |
105 | { | 102 | { |
106 | srm->peer_set = htons(GNUNET_YES); | 103 | srm->peer_set = htons (GNUNET_YES); |
107 | srm->peer = *peer; | 104 | srm->peer = *peer; |
108 | } | 105 | } |
109 | srm->sub_system_size = htons(ss_size); | 106 | srm->sub_system_size = htons (ss_size); |
110 | srm->value_size = htons(value_size); | 107 | srm->value_size = htons (value_size); |
111 | dummy = &srm[1]; | 108 | dummy = &srm[1]; |
112 | memcpy(dummy, sub_system, ss_size); | 109 | memcpy (dummy, sub_system, ss_size); |
113 | dummy += ss_size; | 110 | dummy += ss_size; |
114 | memcpy(dummy, key, key_size); | 111 | memcpy (dummy, key, key_size); |
115 | dummy += key_size; | 112 | dummy += key_size; |
116 | memcpy(dummy, value, value_size); | 113 | memcpy (dummy, value, value_size); |
117 | return srm; | 114 | return srm; |
118 | |||
119 | } | 115 | } |
120 | 116 | ||
117 | |||
121 | /** | 118 | /** |
122 | * Creates a MQ envelope for a single record | 119 | * Creates a MQ envelope for a single record |
123 | * | 120 | * |
@@ -132,14 +129,13 @@ PEERSTORE_create_record_message(const char *sub_system, | |||
132 | * @return pointer to record message struct | 129 | * @return pointer to record message struct |
133 | */ | 130 | */ |
134 | struct GNUNET_MQ_Envelope * | 131 | struct GNUNET_MQ_Envelope * |
135 | PEERSTORE_create_record_mq_envelope(const char *sub_system, | 132 | PEERSTORE_create_record_mq_envelope (const char *sub_system, |
136 | const struct GNUNET_PeerIdentity *peer, | 133 | const struct GNUNET_PeerIdentity *peer, |
137 | const char *key, | 134 | const char *key, const void *value, |
138 | const void *value, | 135 | size_t value_size, |
139 | size_t value_size, | 136 | struct GNUNET_TIME_Absolute *expiry, |
140 | struct GNUNET_TIME_Absolute *expiry, | 137 | enum GNUNET_PEERSTORE_StoreOption options, |
141 | enum GNUNET_PEERSTORE_StoreOption options, | 138 | uint16_t msg_type) |
142 | uint16_t msg_type) | ||
143 | { | 139 | { |
144 | struct StoreRecordMessage *srm; | 140 | struct StoreRecordMessage *srm; |
145 | struct GNUNET_MQ_Envelope *ev; | 141 | struct GNUNET_MQ_Envelope *ev; |
@@ -148,39 +144,37 @@ PEERSTORE_create_record_mq_envelope(const char *sub_system, | |||
148 | size_t msg_size; | 144 | size_t msg_size; |
149 | void *dummy; | 145 | void *dummy; |
150 | 146 | ||
151 | GNUNET_assert(NULL != sub_system); | 147 | GNUNET_assert (NULL != sub_system); |
152 | ss_size = strlen(sub_system) + 1; | 148 | ss_size = strlen (sub_system) + 1; |
153 | if(NULL == key) | 149 | if (NULL == key) |
154 | key_size = 0; | 150 | key_size = 0; |
155 | else | 151 | else |
156 | key_size = strlen(key) + 1; | 152 | key_size = strlen (key) + 1; |
157 | msg_size = ss_size + | 153 | msg_size = ss_size + key_size + value_size; |
158 | key_size + | 154 | ev = GNUNET_MQ_msg_extra (srm, msg_size, msg_type); |
159 | value_size; | 155 | srm->key_size = htons (key_size); |
160 | ev = GNUNET_MQ_msg_extra(srm, msg_size, msg_type); | 156 | if (NULL != expiry) |
161 | srm->key_size = htons(key_size); | ||
162 | if(NULL != expiry) | ||
163 | srm->expiry = *expiry; | 157 | srm->expiry = *expiry; |
164 | if(NULL == peer) | 158 | if (NULL == peer) |
165 | srm->peer_set = htons(GNUNET_NO); | 159 | srm->peer_set = htons (GNUNET_NO); |
166 | else | 160 | else |
167 | { | 161 | { |
168 | srm->peer_set = htons(GNUNET_YES); | 162 | srm->peer_set = htons (GNUNET_YES); |
169 | srm->peer = *peer; | 163 | srm->peer = *peer; |
170 | } | 164 | } |
171 | srm->sub_system_size = htons(ss_size); | 165 | srm->sub_system_size = htons (ss_size); |
172 | srm->value_size = htons(value_size); | 166 | srm->value_size = htons (value_size); |
173 | srm->options = options; | 167 | srm->options = options; |
174 | dummy = &srm[1]; | 168 | dummy = &srm[1]; |
175 | memcpy(dummy, sub_system, ss_size); | 169 | memcpy (dummy, sub_system, ss_size); |
176 | dummy += ss_size; | 170 | dummy += ss_size; |
177 | memcpy(dummy, key, key_size); | 171 | memcpy (dummy, key, key_size); |
178 | dummy += key_size; | 172 | dummy += key_size; |
179 | memcpy(dummy, value, value_size); | 173 | memcpy (dummy, value, value_size); |
180 | |||
181 | return ev; | 174 | return ev; |
182 | } | 175 | } |
183 | 176 | ||
177 | |||
184 | /** | 178 | /** |
185 | * Parses a message carrying a record | 179 | * Parses a message carrying a record |
186 | * | 180 | * |
@@ -188,7 +182,7 @@ PEERSTORE_create_record_mq_envelope(const char *sub_system, | |||
188 | * @return Pointer to record or NULL if error | 182 | * @return Pointer to record or NULL if error |
189 | */ | 183 | */ |
190 | struct GNUNET_PEERSTORE_Record * | 184 | struct GNUNET_PEERSTORE_Record * |
191 | PEERSTORE_parse_record_message(const struct GNUNET_MessageHeader *message) | 185 | PEERSTORE_parse_record_message (const struct GNUNET_MessageHeader *message) |
192 | { | 186 | { |
193 | struct StoreRecordMessage *srm; | 187 | struct StoreRecordMessage *srm; |
194 | struct GNUNET_PEERSTORE_Record *record; | 188 | struct GNUNET_PEERSTORE_Record *record; |
@@ -198,64 +192,67 @@ PEERSTORE_parse_record_message(const struct GNUNET_MessageHeader *message) | |||
198 | uint16_t value_size; | 192 | uint16_t value_size; |
199 | char *dummy; | 193 | char *dummy; |
200 | 194 | ||
201 | req_size = ntohs(message->size); | 195 | req_size = ntohs (message->size); |
202 | if(req_size < sizeof(struct StoreRecordMessage)) | 196 | if (req_size < sizeof (struct StoreRecordMessage)) |
203 | return NULL; | 197 | return NULL; |
204 | srm = (struct StoreRecordMessage *)message; | 198 | srm = (struct StoreRecordMessage *) message; |
205 | ss_size = ntohs(srm->sub_system_size); | 199 | ss_size = ntohs (srm->sub_system_size); |
206 | key_size = ntohs(srm->key_size); | 200 | key_size = ntohs (srm->key_size); |
207 | value_size = ntohs(srm->value_size); | 201 | value_size = ntohs (srm->value_size); |
208 | if(ss_size + key_size + value_size + sizeof(struct StoreRecordMessage) | 202 | if (ss_size + key_size + value_size + sizeof (struct StoreRecordMessage) != |
209 | != req_size) | 203 | req_size) |
210 | return NULL; | 204 | return NULL; |
211 | record = GNUNET_new(struct GNUNET_PEERSTORE_Record); | 205 | record = GNUNET_new (struct GNUNET_PEERSTORE_Record); |
212 | if(GNUNET_YES == ntohs(srm->peer_set)) | 206 | if (GNUNET_YES == ntohs (srm->peer_set)) |
213 | { | 207 | { |
214 | record->peer = GNUNET_new(struct GNUNET_PeerIdentity); | 208 | record->peer = GNUNET_new (struct GNUNET_PeerIdentity); |
215 | memcpy(record->peer, &srm->peer, sizeof(struct GNUNET_PeerIdentity)); | 209 | |
210 | memcpy (record->peer, &srm->peer, sizeof (struct GNUNET_PeerIdentity)); | ||
216 | } | 211 | } |
217 | record->expiry = GNUNET_new(struct GNUNET_TIME_Absolute); | 212 | record->expiry = GNUNET_new (struct GNUNET_TIME_Absolute); |
213 | |||
218 | *(record->expiry) = srm->expiry; | 214 | *(record->expiry) = srm->expiry; |
219 | dummy = (char *)&srm[1]; | 215 | dummy = (char *) &srm[1]; |
220 | if(ss_size > 0) | 216 | if (ss_size > 0) |
221 | { | 217 | { |
222 | record->sub_system = GNUNET_strdup(dummy); | 218 | record->sub_system = GNUNET_strdup (dummy); |
223 | dummy += ss_size; | 219 | dummy += ss_size; |
224 | } | 220 | } |
225 | if(key_size > 0) | 221 | if (key_size > 0) |
226 | { | 222 | { |
227 | record->key = GNUNET_strdup(dummy); | 223 | record->key = GNUNET_strdup (dummy); |
228 | dummy += key_size; | 224 | dummy += key_size; |
229 | } | 225 | } |
230 | if(value_size > 0) | 226 | if (value_size > 0) |
231 | { | 227 | { |
232 | record->value = GNUNET_malloc(value_size); | 228 | record->value = GNUNET_malloc (value_size); |
233 | memcpy(record->value, dummy, value_size); | 229 | memcpy (record->value, dummy, value_size); |
234 | } | 230 | } |
235 | record->value_size = value_size; | 231 | record->value_size = value_size; |
236 | |||
237 | return record; | 232 | return record; |
238 | } | 233 | } |
239 | 234 | ||
235 | |||
240 | /** | 236 | /** |
241 | * Free any memory allocated for this record | 237 | * Free any memory allocated for this record |
242 | * | 238 | * |
243 | * @param record | 239 | * @param record |
244 | */ | 240 | */ |
245 | void PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record) | 241 | void |
242 | PEERSTORE_destroy_record (struct GNUNET_PEERSTORE_Record *record) | ||
246 | { | 243 | { |
247 | if(NULL != record->sub_system) | 244 | if (NULL != record->sub_system) |
248 | GNUNET_free(record->sub_system); | 245 | GNUNET_free (record->sub_system); |
249 | if(NULL != record->peer) | 246 | if (NULL != record->peer) |
250 | GNUNET_free(record->peer); | 247 | GNUNET_free (record->peer); |
251 | if(NULL != record->key) | 248 | if (NULL != record->key) |
252 | GNUNET_free(record->key); | 249 | GNUNET_free (record->key); |
253 | if(NULL != record->value) | 250 | if (NULL != record->value) |
254 | { | 251 | { |
255 | GNUNET_free(record->value); | 252 | GNUNET_free (record->value); |
256 | record->value = 0; | 253 | record->value = 0; |
257 | } | 254 | } |
258 | if(NULL != record->expiry) | 255 | if (NULL != record->expiry) |
259 | GNUNET_free(record->expiry); | 256 | GNUNET_free (record->expiry); |
260 | GNUNET_free(record); | 257 | GNUNET_free (record); |
261 | } | 258 | } |
diff --git a/src/peerstore/peerstore_common.h b/src/peerstore/peerstore_common.h index 50ff4a2f9..fb1318146 100644 --- a/src/peerstore/peerstore_common.h +++ b/src/peerstore/peerstore_common.h | |||
@@ -31,10 +31,9 @@ | |||
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, const char *key, |
36 | const char *key, | 36 | struct GNUNET_HashCode *ret); |
37 | struct GNUNET_HashCode *ret); | ||
38 | 37 | ||
39 | /** | 38 | /** |
40 | * Creates a record message ready to be sent | 39 | * Creates a record message ready to be sent |
@@ -49,13 +48,12 @@ PEERSTORE_hash_key(const char *sub_system, | |||
49 | * @return pointer to record message struct | 48 | * @return pointer to record message struct |
50 | */ | 49 | */ |
51 | struct StoreRecordMessage * | 50 | struct StoreRecordMessage * |
52 | PEERSTORE_create_record_message(const char *sub_system, | 51 | PEERSTORE_create_record_message (const char *sub_system, |
53 | const struct GNUNET_PeerIdentity *peer, | 52 | const struct GNUNET_PeerIdentity *peer, |
54 | const char *key, | 53 | const char *key, const void *value, |
55 | const void *value, | 54 | size_t value_size, |
56 | size_t value_size, | 55 | struct GNUNET_TIME_Absolute *expiry, |
57 | struct GNUNET_TIME_Absolute *expiry, | 56 | uint16_t msg_type); |
58 | uint16_t msg_type); | ||
59 | 57 | ||
60 | /** | 58 | /** |
61 | * Creates a MQ envelope for a single record | 59 | * Creates a MQ envelope for a single record |
@@ -71,14 +69,13 @@ PEERSTORE_create_record_message(const char *sub_system, | |||
71 | * @return pointer to record message struct | 69 | * @return pointer to record message struct |
72 | */ | 70 | */ |
73 | struct GNUNET_MQ_Envelope * | 71 | struct GNUNET_MQ_Envelope * |
74 | PEERSTORE_create_record_mq_envelope(const char *sub_system, | 72 | PEERSTORE_create_record_mq_envelope (const char *sub_system, |
75 | const struct GNUNET_PeerIdentity *peer, | 73 | const struct GNUNET_PeerIdentity *peer, |
76 | const char *key, | 74 | const char *key, const void *value, |
77 | const void *value, | 75 | size_t value_size, |
78 | size_t value_size, | 76 | struct GNUNET_TIME_Absolute *expiry, |
79 | struct GNUNET_TIME_Absolute *expiry, | 77 | enum GNUNET_PEERSTORE_StoreOption options, |
80 | enum GNUNET_PEERSTORE_StoreOption options, | 78 | uint16_t msg_type); |
81 | uint16_t msg_type); | ||
82 | 79 | ||
83 | /** | 80 | /** |
84 | * Parses a message carrying a record | 81 | * Parses a message carrying a record |
@@ -87,11 +84,12 @@ PEERSTORE_create_record_mq_envelope(const char *sub_system, | |||
87 | * @return Pointer to record or NULL if error | 84 | * @return Pointer to record or NULL if error |
88 | */ | 85 | */ |
89 | struct GNUNET_PEERSTORE_Record * | 86 | struct GNUNET_PEERSTORE_Record * |
90 | PEERSTORE_parse_record_message(const struct GNUNET_MessageHeader *message); | 87 | PEERSTORE_parse_record_message (const struct GNUNET_MessageHeader *message); |
91 | 88 | ||
92 | /** | 89 | /** |
93 | * Free any memory allocated for this record | 90 | * Free any memory allocated for this record |
94 | * | 91 | * |
95 | * @param record | 92 | * @param record |
96 | */ | 93 | */ |
97 | void PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record); | 94 | void |
95 | PEERSTORE_destroy_record (struct GNUNET_PEERSTORE_Record *record); | ||
diff --git a/src/peerstore/perf_peerstore_store.c b/src/peerstore/perf_peerstore_store.c index bdf70272c..e97699fe2 100644 --- a/src/peerstore/perf_peerstore_store.c +++ b/src/peerstore/perf_peerstore_store.c | |||
@@ -40,78 +40,68 @@ static char *v = "test_peerstore_stress_val"; | |||
40 | int count = 0; | 40 | int count = 0; |
41 | 41 | ||
42 | void | 42 | 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 | void | 51 | void |
51 | store() | 52 | store () |
52 | { | 53 | { |
53 | GNUNET_PEERSTORE_store(h, | 54 | GNUNET_PEERSTORE_store (h, ss, &p, k, v, strlen (v) + 1, |
54 | ss, | 55 | GNUNET_TIME_UNIT_FOREVER_ABS, |
55 | &p, | 56 | (count == |
56 | k, | 57 | 0) ? GNUNET_PEERSTORE_STOREOPTION_REPLACE : |
57 | v, | 58 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL); |
58 | strlen(v) + 1, | ||
59 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
60 | (count == 0) ? GNUNET_PEERSTORE_STOREOPTION_REPLACE : GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, | ||
61 | NULL, | ||
62 | NULL); | ||
63 | count++; | 59 | count++; |
64 | } | 60 | } |
65 | 61 | ||
62 | |||
66 | static int | 63 | static int |
67 | watch_cb(void *cls, | 64 | watch_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
68 | struct GNUNET_PEERSTORE_Record *record, | ||
69 | char *emsg) | ||
70 | { | 65 | { |
71 | GNUNET_assert(NULL == emsg); | 66 | GNUNET_assert (NULL == emsg); |
72 | if(STORES == count) | 67 | if (STORES == count) |
73 | { | 68 | { |
74 | ok = 0; | 69 | ok = 0; |
75 | disconnect(); | 70 | disconnect (); |
76 | } | 71 | } |
77 | else | 72 | else |
78 | store(); | 73 | store (); |
79 | return GNUNET_YES; | 74 | return GNUNET_YES; |
80 | } | 75 | } |
81 | 76 | ||
77 | |||
82 | static void | 78 | static void |
83 | run (void *cls, | 79 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
84 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 80 | struct GNUNET_TESTING_Peer *peer) |
85 | struct GNUNET_TESTING_Peer *peer) | ||
86 | { | 81 | { |
87 | memset (&p, 5, sizeof (p)); | 82 | memset (&p, 5, sizeof (p)); |
88 | h = GNUNET_PEERSTORE_connect(cfg); | 83 | h = GNUNET_PEERSTORE_connect (cfg); |
89 | GNUNET_assert(NULL != h); | 84 | GNUNET_assert (NULL != h); |
90 | GNUNET_PEERSTORE_watch(h, | 85 | GNUNET_PEERSTORE_watch (h, ss, &p, k, &watch_cb, NULL); |
91 | ss, | 86 | store (); |
92 | &p, | ||
93 | k, | ||
94 | &watch_cb, | ||
95 | NULL); | ||
96 | store(); | ||
97 | } | 87 | } |
98 | 88 | ||
89 | |||
99 | int | 90 | int |
100 | main (int argc, char *argv[]) | 91 | main (int argc, char *argv[]) |
101 | { | 92 | { |
102 | struct GNUNET_TIME_Absolute start; | 93 | struct GNUNET_TIME_Absolute start; |
103 | struct GNUNET_TIME_Relative diff; | 94 | struct GNUNET_TIME_Relative diff; |
104 | 95 | ||
105 | start = GNUNET_TIME_absolute_get(); | 96 | start = GNUNET_TIME_absolute_get (); |
106 | if (0 != GNUNET_TESTING_service_run ("perf-peerstore-store", | 97 | if (0 != |
107 | "peerstore", | 98 | GNUNET_TESTING_service_run ("perf-peerstore-store", "peerstore", |
108 | "test_peerstore_api_data.conf", | 99 | "test_peerstore_api_data.conf", &run, NULL)) |
109 | &run, NULL)) | ||
110 | return 1; | 100 | return 1; |
111 | diff = GNUNET_TIME_absolute_get_duration(start); | 101 | diff = GNUNET_TIME_absolute_get_duration (start); |
112 | fprintf(stderr, "Stored and retrieved %d records in %s (%s).\n", | 102 | fprintf (stderr, "Stored and retrieved %d records in %s (%s).\n", STORES, |
113 | STORES, GNUNET_STRINGS_relative_time_to_string(diff, GNUNET_YES), | 103 | GNUNET_STRINGS_relative_time_to_string (diff, GNUNET_YES), |
114 | GNUNET_STRINGS_relative_time_to_string(diff, GNUNET_NO)); | 104 | GNUNET_STRINGS_relative_time_to_string (diff, GNUNET_NO)); |
115 | return ok; | 105 | return ok; |
116 | } | 106 | } |
117 | 107 | ||
diff --git a/src/peerstore/plugin_peerstore_sqlite.c b/src/peerstore/plugin_peerstore_sqlite.c index 2726eef3d..588fae73c 100644 --- a/src/peerstore/plugin_peerstore_sqlite.c +++ b/src/peerstore/plugin_peerstore_sqlite.c | |||
@@ -121,19 +121,24 @@ struct Plugin | |||
121 | * @return number of deleted records | 121 | * @return number of deleted records |
122 | */ | 122 | */ |
123 | static int | 123 | static int |
124 | peerstore_sqlite_delete_records(void *cls, | 124 | peerstore_sqlite_delete_records (void *cls, const char *sub_system, |
125 | const char *sub_system, | 125 | const struct GNUNET_PeerIdentity *peer, |
126 | const struct GNUNET_PeerIdentity *peer, | 126 | const char *key) |
127 | const char *key) | ||
128 | { | 127 | { |
129 | struct Plugin *plugin = cls; | 128 | struct Plugin *plugin = cls; |
130 | sqlite3_stmt *stmt = plugin->delete_peerstoredata; | 129 | sqlite3_stmt *stmt = plugin->delete_peerstoredata; |
131 | 130 | ||
132 | if((SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 1, SQLITE_STATIC)) | 131 | if ((SQLITE_OK != |
133 | || (SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct GNUNET_PeerIdentity), SQLITE_STATIC)) | 132 | sqlite3_bind_text (stmt, 1, sub_system, strlen (sub_system) + 1, |
134 | || (SQLITE_OK != sqlite3_bind_text(stmt, 3, key, strlen(key) + 1, SQLITE_STATIC))) | 133 | SQLITE_STATIC)) || |
134 | (SQLITE_OK != | ||
135 | sqlite3_bind_blob (stmt, 2, peer, sizeof (struct GNUNET_PeerIdentity), | ||
136 | SQLITE_STATIC)) || | ||
137 | (SQLITE_OK != | ||
138 | sqlite3_bind_text (stmt, 3, key, strlen (key) + 1, SQLITE_STATIC))) | ||
135 | { | 139 | { |
136 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind"); | 140 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
141 | "sqlite3_bind"); | ||
137 | } | 142 | } |
138 | else if (SQLITE_DONE != sqlite3_step (stmt)) | 143 | else if (SQLITE_DONE != sqlite3_step (stmt)) |
139 | { | 144 | { |
@@ -146,9 +151,10 @@ peerstore_sqlite_delete_records(void *cls, | |||
146 | "sqlite3_reset"); | 151 | "sqlite3_reset"); |
147 | return 0; | 152 | return 0; |
148 | } | 153 | } |
149 | return sqlite3_changes(plugin->dbh); | 154 | return sqlite3_changes (plugin->dbh); |
150 | } | 155 | } |
151 | 156 | ||
157 | |||
152 | /** | 158 | /** |
153 | * Delete expired records (expiry < now) | 159 | * Delete expired records (expiry < now) |
154 | * | 160 | * |
@@ -157,15 +163,16 @@ peerstore_sqlite_delete_records(void *cls, | |||
157 | * @return number of records deleted | 163 | * @return number of records deleted |
158 | */ | 164 | */ |
159 | static int | 165 | static int |
160 | peerstore_sqlite_expire_records(void *cls, | 166 | peerstore_sqlite_expire_records (void *cls, struct GNUNET_TIME_Absolute now) |
161 | struct GNUNET_TIME_Absolute now) | ||
162 | { | 167 | { |
163 | struct Plugin *plugin = cls; | 168 | struct Plugin *plugin = cls; |
164 | sqlite3_stmt *stmt = plugin->expire_peerstoredata; | 169 | sqlite3_stmt *stmt = plugin->expire_peerstoredata; |
165 | 170 | ||
166 | if(SQLITE_OK != sqlite3_bind_int64(stmt, 1, (sqlite3_uint64)now.abs_value_us)) | 171 | if (SQLITE_OK != |
172 | sqlite3_bind_int64 (stmt, 1, (sqlite3_uint64) now.abs_value_us)) | ||
167 | { | 173 | { |
168 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind"); | 174 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
175 | "sqlite3_bind"); | ||
169 | } | 176 | } |
170 | else if (SQLITE_DONE != sqlite3_step (stmt)) | 177 | else if (SQLITE_DONE != sqlite3_step (stmt)) |
171 | { | 178 | { |
@@ -178,10 +185,10 @@ peerstore_sqlite_expire_records(void *cls, | |||
178 | "sqlite3_reset"); | 185 | "sqlite3_reset"); |
179 | return 0; | 186 | return 0; |
180 | } | 187 | } |
181 | return sqlite3_changes(plugin->dbh); | 188 | return sqlite3_changes (plugin->dbh); |
182 | |||
183 | } | 189 | } |
184 | 190 | ||
191 | |||
185 | /** | 192 | /** |
186 | * Iterate over the records given an optional peer id | 193 | * Iterate over the records given an optional peer id |
187 | * and/or key. | 194 | * and/or key. |
@@ -195,11 +202,11 @@ peerstore_sqlite_expire_records(void *cls, | |||
195 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 202 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
196 | */ | 203 | */ |
197 | static int | 204 | static int |
198 | peerstore_sqlite_iterate_records (void *cls, | 205 | peerstore_sqlite_iterate_records (void *cls, const char *sub_system, |
199 | const char *sub_system, | 206 | const struct GNUNET_PeerIdentity *peer, |
200 | const struct GNUNET_PeerIdentity *peer, | 207 | const char *key, |
201 | const char *key, | 208 | GNUNET_PEERSTORE_Processor iter, |
202 | GNUNET_PEERSTORE_Processor iter, void *iter_cls) | 209 | void *iter_cls) |
203 | { | 210 | { |
204 | struct Plugin *plugin = cls; | 211 | struct Plugin *plugin = cls; |
205 | sqlite3_stmt *stmt; | 212 | sqlite3_stmt *stmt; |
@@ -207,59 +214,76 @@ peerstore_sqlite_iterate_records (void *cls, | |||
207 | int sret; | 214 | int sret; |
208 | struct GNUNET_PEERSTORE_Record *ret; | 215 | struct GNUNET_PEERSTORE_Record *ret; |
209 | 216 | ||
210 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Executing iterate request on sqlite db.\n"); | 217 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Executing iterate request on sqlite db.\n"); |
211 | if(NULL == peer && NULL == key) | 218 | if (NULL == peer && NULL == key) |
212 | { | 219 | { |
213 | stmt = plugin->select_peerstoredata; | 220 | stmt = plugin->select_peerstoredata; |
214 | err = (SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 1, SQLITE_STATIC)); | 221 | err = |
222 | (SQLITE_OK != | ||
223 | sqlite3_bind_text (stmt, 1, sub_system, strlen (sub_system) + 1, | ||
224 | SQLITE_STATIC)); | ||
215 | } | 225 | } |
216 | else if(NULL == key) | 226 | else if (NULL == key) |
217 | { | 227 | { |
218 | stmt = plugin->select_peerstoredata_by_pid; | 228 | stmt = plugin->select_peerstoredata_by_pid; |
219 | err = (SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 1, SQLITE_STATIC)) | 229 | err = |
220 | || (SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct GNUNET_PeerIdentity), SQLITE_STATIC)); | 230 | (SQLITE_OK != |
231 | sqlite3_bind_text (stmt, 1, sub_system, strlen (sub_system) + 1, | ||
232 | SQLITE_STATIC)) || | ||
233 | (SQLITE_OK != | ||
234 | sqlite3_bind_blob (stmt, 2, peer, sizeof (struct GNUNET_PeerIdentity), | ||
235 | SQLITE_STATIC)); | ||
221 | } | 236 | } |
222 | else if(NULL == peer) | 237 | else if (NULL == peer) |
223 | { | 238 | { |
224 | stmt = plugin->select_peerstoredata_by_key; | 239 | stmt = plugin->select_peerstoredata_by_key; |
225 | err = (SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 1, SQLITE_STATIC)) | 240 | err = |
226 | || (SQLITE_OK != sqlite3_bind_text(stmt, 2, key, strlen(key) + 1, SQLITE_STATIC)); | 241 | (SQLITE_OK != |
242 | sqlite3_bind_text (stmt, 1, sub_system, strlen (sub_system) + 1, | ||
243 | SQLITE_STATIC)) || | ||
244 | (SQLITE_OK != | ||
245 | sqlite3_bind_text (stmt, 2, key, strlen (key) + 1, SQLITE_STATIC)); | ||
227 | } | 246 | } |
228 | else | 247 | else |
229 | { | 248 | { |
230 | stmt = plugin->select_peerstoredata_by_all; | 249 | stmt = plugin->select_peerstoredata_by_all; |
231 | err = (SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 1, SQLITE_STATIC)) | 250 | err = |
232 | || (SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct GNUNET_PeerIdentity), SQLITE_STATIC)) | 251 | (SQLITE_OK != |
233 | || (SQLITE_OK != sqlite3_bind_text(stmt, 3, key, strlen(key) + 1, SQLITE_STATIC)); | 252 | sqlite3_bind_text (stmt, 1, sub_system, strlen (sub_system) + 1, |
253 | SQLITE_STATIC)) || | ||
254 | (SQLITE_OK != | ||
255 | sqlite3_bind_blob (stmt, 2, peer, sizeof (struct GNUNET_PeerIdentity), | ||
256 | SQLITE_STATIC)) || | ||
257 | (SQLITE_OK != | ||
258 | sqlite3_bind_text (stmt, 3, key, strlen (key) + 1, SQLITE_STATIC)); | ||
234 | } | 259 | } |
235 | 260 | ||
236 | if (err) | 261 | if (err) |
237 | { | 262 | { |
238 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 263 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
239 | "sqlite3_bind_XXXX"); | 264 | "sqlite3_bind_XXXX"); |
240 | if (SQLITE_OK != sqlite3_reset (stmt)) | 265 | if (SQLITE_OK != sqlite3_reset (stmt)) |
241 | LOG_SQLITE (plugin, | 266 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
242 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 267 | "sqlite3_reset"); |
243 | "sqlite3_reset"); | ||
244 | return GNUNET_SYSERR; | 268 | return GNUNET_SYSERR; |
245 | } | 269 | } |
246 | while (SQLITE_ROW == (sret = sqlite3_step (stmt))) | 270 | while (SQLITE_ROW == (sret = sqlite3_step (stmt))) |
247 | { | 271 | { |
248 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Returning a matched record.\n"); | 272 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning a matched record.\n"); |
249 | ret = GNUNET_new(struct GNUNET_PEERSTORE_Record); | 273 | ret = GNUNET_new (struct GNUNET_PEERSTORE_Record); |
250 | ret->sub_system = (char *)sqlite3_column_text(stmt, 0); | 274 | |
251 | ret->peer = (struct GNUNET_PeerIdentity *)sqlite3_column_blob(stmt, 1); | 275 | ret->sub_system = (char *) sqlite3_column_text (stmt, 0); |
252 | ret->key = (char *)sqlite3_column_text(stmt, 2); | 276 | ret->peer = (struct GNUNET_PeerIdentity *) sqlite3_column_blob (stmt, 1); |
253 | ret->value = (void *)sqlite3_column_blob(stmt, 3); | 277 | ret->key = (char *) sqlite3_column_text (stmt, 2); |
254 | ret->value_size = sqlite3_column_bytes(stmt, 3); | 278 | ret->value = (void *) sqlite3_column_blob (stmt, 3); |
255 | ret->expiry = GNUNET_new(struct GNUNET_TIME_Absolute); | 279 | ret->value_size = sqlite3_column_bytes (stmt, 3); |
256 | ret->expiry->abs_value_us = (uint64_t)sqlite3_column_int64(stmt, 4); | 280 | ret->expiry = GNUNET_new (struct GNUNET_TIME_Absolute); |
281 | |||
282 | ret->expiry->abs_value_us = (uint64_t) sqlite3_column_int64 (stmt, 4); | ||
257 | if (NULL != iter) | 283 | if (NULL != iter) |
258 | iter (iter_cls, | 284 | iter (iter_cls, ret, NULL); |
259 | ret, | 285 | GNUNET_free (ret->expiry); |
260 | NULL); | 286 | GNUNET_free (ret); |
261 | GNUNET_free(ret->expiry); | ||
262 | GNUNET_free(ret); | ||
263 | } | 287 | } |
264 | if (SQLITE_DONE != sret) | 288 | if (SQLITE_DONE != sret) |
265 | { | 289 | { |
@@ -268,16 +292,16 @@ peerstore_sqlite_iterate_records (void *cls, | |||
268 | } | 292 | } |
269 | if (SQLITE_OK != sqlite3_reset (stmt)) | 293 | if (SQLITE_OK != sqlite3_reset (stmt)) |
270 | { | 294 | { |
271 | LOG_SQLITE (plugin, | 295 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
272 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 296 | "sqlite3_reset"); |
273 | "sqlite3_reset"); | ||
274 | err = 1; | 297 | err = 1; |
275 | } | 298 | } |
276 | if(err) | 299 | if (err) |
277 | return GNUNET_SYSERR; | 300 | return GNUNET_SYSERR; |
278 | return GNUNET_OK; | 301 | return GNUNET_OK; |
279 | } | 302 | } |
280 | 303 | ||
304 | |||
281 | /** | 305 | /** |
282 | * Store a record in the peerstore. | 306 | * Store a record in the peerstore. |
283 | * Key is the combination of sub system and peer identity. | 307 | * Key is the combination of sub system and peer identity. |
@@ -294,29 +318,32 @@ peerstore_sqlite_iterate_records (void *cls, | |||
294 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | 318 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR |
295 | */ | 319 | */ |
296 | static int | 320 | static int |
297 | peerstore_sqlite_store_record (void *cls, | 321 | peerstore_sqlite_store_record (void *cls, const char *sub_system, |
298 | const char *sub_system, | ||
299 | const struct GNUNET_PeerIdentity *peer, | 322 | const struct GNUNET_PeerIdentity *peer, |
300 | const char *key, | 323 | const char *key, const void *value, size_t size, |
301 | const void *value, | ||
302 | size_t size, | ||
303 | struct GNUNET_TIME_Absolute expiry, | 324 | struct GNUNET_TIME_Absolute expiry, |
304 | enum GNUNET_PEERSTORE_StoreOption options) | 325 | enum GNUNET_PEERSTORE_StoreOption options) |
305 | { | 326 | { |
306 | struct Plugin *plugin = cls; | 327 | struct Plugin *plugin = cls; |
307 | sqlite3_stmt *stmt = plugin->insert_peerstoredata; | 328 | sqlite3_stmt *stmt = plugin->insert_peerstoredata; |
308 | 329 | ||
309 | if(GNUNET_PEERSTORE_STOREOPTION_REPLACE == options) | 330 | if (GNUNET_PEERSTORE_STOREOPTION_REPLACE == options) |
310 | { | 331 | { |
311 | peerstore_sqlite_delete_records(cls, sub_system, peer, key); | 332 | peerstore_sqlite_delete_records (cls, sub_system, peer, key); |
312 | } | 333 | } |
313 | if(SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 1, SQLITE_STATIC) | 334 | if (SQLITE_OK != |
314 | || SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct GNUNET_PeerIdentity), SQLITE_STATIC) | 335 | sqlite3_bind_text (stmt, 1, sub_system, strlen (sub_system) + 1, |
315 | || SQLITE_OK != sqlite3_bind_text(stmt, 3, key, strlen(key) + 1, SQLITE_STATIC) | 336 | SQLITE_STATIC) || |
316 | || SQLITE_OK != sqlite3_bind_blob(stmt, 4, value, size, SQLITE_STATIC) | 337 | SQLITE_OK != sqlite3_bind_blob (stmt, 2, peer, |
317 | || SQLITE_OK != sqlite3_bind_int64(stmt, 5, (sqlite3_uint64)expiry.abs_value_us)) | 338 | sizeof (struct GNUNET_PeerIdentity), |
339 | SQLITE_STATIC) || | ||
340 | SQLITE_OK != sqlite3_bind_text (stmt, 3, key, strlen (key) + 1, | ||
341 | SQLITE_STATIC) || | ||
342 | SQLITE_OK != sqlite3_bind_blob (stmt, 4, value, size, SQLITE_STATIC) || | ||
343 | SQLITE_OK != sqlite3_bind_int64 (stmt, 5, | ||
344 | (sqlite3_uint64) expiry.abs_value_us)) | ||
318 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 345 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
319 | "sqlite3_bind"); | 346 | "sqlite3_bind"); |
320 | else if (SQLITE_DONE != sqlite3_step (stmt)) | 347 | else if (SQLITE_DONE != sqlite3_step (stmt)) |
321 | { | 348 | { |
322 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 349 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
@@ -328,7 +355,6 @@ peerstore_sqlite_store_record (void *cls, | |||
328 | "sqlite3_reset"); | 355 | "sqlite3_reset"); |
329 | return GNUNET_SYSERR; | 356 | return GNUNET_SYSERR; |
330 | } | 357 | } |
331 | |||
332 | return GNUNET_OK; | 358 | return GNUNET_OK; |
333 | } | 359 | } |
334 | 360 | ||
@@ -341,20 +367,19 @@ peerstore_sqlite_store_record (void *cls, | |||
341 | * @return 0 on success | 367 | * @return 0 on success |
342 | */ | 368 | */ |
343 | static int | 369 | static int |
344 | sql_exec (sqlite3 *dbh, const char *sql) | 370 | sql_exec (sqlite3 * dbh, const char *sql) |
345 | { | 371 | { |
346 | int result; | 372 | int result; |
347 | 373 | ||
348 | result = sqlite3_exec (dbh, sql, NULL, NULL, NULL); | 374 | result = sqlite3_exec (dbh, sql, NULL, NULL, NULL); |
349 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 375 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Executed `%s' / %d\n", sql, result); |
350 | "Executed `%s' / %d\n", sql, result); | ||
351 | if (result != SQLITE_OK) | 376 | if (result != SQLITE_OK) |
352 | LOG (GNUNET_ERROR_TYPE_ERROR, | 377 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error executing SQL query: %s\n %s\n"), |
353 | _("Error executing SQL query: %s\n %s\n"), | 378 | sqlite3_errmsg (dbh), sql); |
354 | sqlite3_errmsg (dbh), sql); | ||
355 | return result; | 379 | return result; |
356 | } | 380 | } |
357 | 381 | ||
382 | |||
358 | /** | 383 | /** |
359 | * @brief Prepare a SQL statement | 384 | * @brief Prepare a SQL statement |
360 | * | 385 | * |
@@ -364,37 +389,37 @@ sql_exec (sqlite3 *dbh, const char *sql) | |||
364 | * @return 0 on success | 389 | * @return 0 on success |
365 | */ | 390 | */ |
366 | static int | 391 | static int |
367 | sql_prepare (sqlite3 *dbh, const char *sql, sqlite3_stmt **stmt) | 392 | sql_prepare (sqlite3 * dbh, const char *sql, sqlite3_stmt ** stmt) |
368 | { | 393 | { |
369 | char *tail; | 394 | char *tail; |
370 | int result; | 395 | int result; |
371 | 396 | ||
372 | result = sqlite3_prepare_v2 (dbh, sql, strlen (sql), stmt, | 397 | result = |
373 | (const char **) &tail); | 398 | sqlite3_prepare_v2 (dbh, sql, strlen (sql), stmt, (const char **) &tail); |
374 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 399 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Prepared `%s' / %p: %d\n", sql, *stmt, result); |
375 | "Prepared `%s' / %p: %d\n", sql, *stmt, result); | ||
376 | if (result != SQLITE_OK) | 400 | if (result != SQLITE_OK) |
377 | LOG (GNUNET_ERROR_TYPE_ERROR, | 401 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error preparing SQL query: %s\n %s\n"), |
378 | _("Error preparing SQL query: %s\n %s\n"), | 402 | sqlite3_errmsg (dbh), sql); |
379 | sqlite3_errmsg (dbh), sql); | ||
380 | return result; | 403 | return result; |
381 | } | 404 | } |
382 | 405 | ||
406 | |||
383 | /** | 407 | /** |
384 | * sqlite3 custom function for comparison of uint64_t values | 408 | * sqlite3 custom function for comparison of uint64_t values |
385 | * since it is not supported by default | 409 | * since it is not supported by default |
386 | */ | 410 | */ |
387 | void sqlite3_lessthan(sqlite3_context* ctx, int dummy, | 411 | void |
388 | sqlite3_value** values) | 412 | sqlite3_lessthan (sqlite3_context * ctx, int dummy, sqlite3_value ** values) |
389 | { | 413 | { |
390 | uint64_t v1; | 414 | uint64_t v1; |
391 | uint64_t v2; | 415 | uint64_t v2; |
392 | 416 | ||
393 | v1 = (uint64_t)sqlite3_value_int64(values[0]); | 417 | v1 = (uint64_t) sqlite3_value_int64 (values[0]); |
394 | v2 = (uint64_t)sqlite3_value_int64(values[1]); | 418 | v2 = (uint64_t) sqlite3_value_int64 (values[1]); |
395 | sqlite3_result_int(ctx, v1 < v2); | 419 | sqlite3_result_int (ctx, v1 < v2); |
396 | } | 420 | } |
397 | 421 | ||
422 | |||
398 | /** | 423 | /** |
399 | * Initialize the database connections and associated | 424 | * Initialize the database connections and associated |
400 | * data structures (create tables and indices | 425 | * data structures (create tables and indices |
@@ -412,8 +437,8 @@ database_setup (struct Plugin *plugin) | |||
412 | GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, "peerstore-sqlite", | 437 | GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, "peerstore-sqlite", |
413 | "FILENAME", &filename)) | 438 | "FILENAME", &filename)) |
414 | { | 439 | { |
415 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 440 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "peerstore-sqlite", |
416 | "peerstore-sqlite", "FILENAME"); | 441 | "FILENAME"); |
417 | return GNUNET_SYSERR; | 442 | return GNUNET_SYSERR; |
418 | } | 443 | } |
419 | if (GNUNET_OK != GNUNET_DISK_file_test (filename)) | 444 | if (GNUNET_OK != GNUNET_DISK_file_test (filename)) |
@@ -427,16 +452,13 @@ database_setup (struct Plugin *plugin) | |||
427 | } | 452 | } |
428 | /* filename should be UTF-8-encoded. If it isn't, it's a bug */ | 453 | /* filename should be UTF-8-encoded. If it isn't, it's a bug */ |
429 | plugin->fn = filename; | 454 | plugin->fn = filename; |
430 | |||
431 | /* Open database and precompile statements */ | 455 | /* Open database and precompile statements */ |
432 | if (SQLITE_OK != sqlite3_open (plugin->fn, &plugin->dbh)) | 456 | if (SQLITE_OK != sqlite3_open (plugin->fn, &plugin->dbh)) |
433 | { | 457 | { |
434 | LOG (GNUNET_ERROR_TYPE_ERROR, | 458 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Unable to initialize SQLite: %s.\n"), |
435 | _("Unable to initialize SQLite: %s.\n"), | 459 | sqlite3_errmsg (plugin->dbh)); |
436 | sqlite3_errmsg (plugin->dbh)); | ||
437 | return GNUNET_SYSERR; | 460 | return GNUNET_SYSERR; |
438 | } | 461 | } |
439 | |||
440 | sql_exec (plugin->dbh, "PRAGMA temp_store=MEMORY"); | 462 | sql_exec (plugin->dbh, "PRAGMA temp_store=MEMORY"); |
441 | sql_exec (plugin->dbh, "PRAGMA synchronous=OFF"); | 463 | sql_exec (plugin->dbh, "PRAGMA synchronous=OFF"); |
442 | sql_exec (plugin->dbh, "PRAGMA legacy_file_format=OFF"); | 464 | sql_exec (plugin->dbh, "PRAGMA legacy_file_format=OFF"); |
@@ -444,73 +466,54 @@ database_setup (struct Plugin *plugin) | |||
444 | sql_exec (plugin->dbh, "PRAGMA encoding=\"UTF-8\""); | 466 | sql_exec (plugin->dbh, "PRAGMA encoding=\"UTF-8\""); |
445 | sql_exec (plugin->dbh, "PRAGMA count_changes=OFF"); | 467 | sql_exec (plugin->dbh, "PRAGMA count_changes=OFF"); |
446 | sql_exec (plugin->dbh, "PRAGMA page_size=4096"); | 468 | sql_exec (plugin->dbh, "PRAGMA page_size=4096"); |
447 | |||
448 | sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS); | 469 | sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS); |
449 | |||
450 | /* Create tables */ | 470 | /* Create tables */ |
451 | |||
452 | sql_exec (plugin->dbh, | 471 | sql_exec (plugin->dbh, |
453 | "CREATE TABLE IF NOT EXISTS peerstoredata (\n" | 472 | "CREATE TABLE IF NOT EXISTS peerstoredata (\n" |
454 | " sub_system TEXT NOT NULL,\n" | 473 | " sub_system TEXT NOT NULL,\n" " peer_id BLOB NOT NULL,\n" |
455 | " peer_id BLOB NOT NULL,\n" | 474 | " key TEXT NOT NULL,\n" " value BLOB NULL,\n" |
456 | " key TEXT NOT NULL,\n" | 475 | " expiry sqlite3_uint64 NOT NULL" ");"); |
457 | " value BLOB NULL,\n" | 476 | sqlite3_create_function (plugin->dbh, "UINT64_LT", 2, SQLITE_UTF8, NULL, |
458 | " expiry sqlite3_uint64 NOT NULL" | 477 | &sqlite3_lessthan, NULL, NULL); |
459 | ");"); | ||
460 | |||
461 | sqlite3_create_function(plugin->dbh, "UINT64_LT", 2, SQLITE_UTF8, NULL, &sqlite3_lessthan, NULL, NULL); | ||
462 | |||
463 | /* Create Indices */ | 478 | /* Create Indices */ |
464 | if (SQLITE_OK != | 479 | if (SQLITE_OK != |
465 | sqlite3_exec(plugin->dbh, | 480 | sqlite3_exec (plugin->dbh, |
466 | "CREATE INDEX IF NOT EXISTS peerstoredata_key_index ON peerstoredata (sub_system, peer_id, key)", | 481 | "CREATE INDEX IF NOT EXISTS peerstoredata_key_index ON peerstoredata (sub_system, peer_id, key)", |
467 | NULL, NULL, NULL)) | 482 | NULL, NULL, NULL)) |
468 | { | 483 | { |
469 | LOG (GNUNET_ERROR_TYPE_ERROR, | 484 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Unable to create indices: %s.\n"), |
470 | _("Unable to create indices: %s.\n"), | 485 | sqlite3_errmsg (plugin->dbh)); |
471 | sqlite3_errmsg (plugin->dbh)); | 486 | return GNUNET_SYSERR; |
472 | return GNUNET_SYSERR; | ||
473 | } | 487 | } |
474 | |||
475 | /* Prepare statements */ | 488 | /* Prepare statements */ |
476 | 489 | ||
477 | sql_prepare (plugin->dbh, | 490 | sql_prepare (plugin->dbh, |
478 | "INSERT INTO peerstoredata (sub_system, peer_id, key, value, expiry) VALUES (?,?,?,?,?);", | 491 | "INSERT INTO peerstoredata (sub_system, peer_id, key, value, expiry) VALUES (?,?,?,?,?);", |
479 | &plugin->insert_peerstoredata); | 492 | &plugin->insert_peerstoredata); |
480 | sql_prepare(plugin->dbh, | 493 | sql_prepare (plugin->dbh, |
481 | "SELECT * FROM peerstoredata" | 494 | "SELECT * FROM peerstoredata" " WHERE sub_system = ?", |
482 | " WHERE sub_system = ?", | 495 | &plugin->select_peerstoredata); |
483 | &plugin->select_peerstoredata); | 496 | sql_prepare (plugin->dbh, |
484 | sql_prepare(plugin->dbh, | 497 | "SELECT * FROM peerstoredata" " WHERE sub_system = ?" |
485 | "SELECT * FROM peerstoredata" | 498 | " AND peer_id = ?", &plugin->select_peerstoredata_by_pid); |
486 | " WHERE sub_system = ?" | 499 | sql_prepare (plugin->dbh, |
487 | " AND peer_id = ?", | 500 | "SELECT * FROM peerstoredata" " WHERE sub_system = ?" |
488 | &plugin->select_peerstoredata_by_pid); | 501 | " AND key = ?", &plugin->select_peerstoredata_by_key); |
489 | sql_prepare(plugin->dbh, | 502 | sql_prepare (plugin->dbh, |
490 | "SELECT * FROM peerstoredata" | 503 | "SELECT * FROM peerstoredata" " WHERE sub_system = ?" |
491 | " WHERE sub_system = ?" | 504 | " AND peer_id = ?" " AND key = ?", |
492 | " AND key = ?", | 505 | &plugin->select_peerstoredata_by_all); |
493 | &plugin->select_peerstoredata_by_key); | 506 | sql_prepare (plugin->dbh, |
494 | sql_prepare(plugin->dbh, | 507 | "DELETE FROM peerstoredata" " WHERE UINT64_LT(expiry, ?)", |
495 | "SELECT * FROM peerstoredata" | 508 | &plugin->expire_peerstoredata); |
496 | " WHERE sub_system = ?" | 509 | sql_prepare (plugin->dbh, |
497 | " AND peer_id = ?" | 510 | "DELETE FROM peerstoredata" " WHERE sub_system = ?" |
498 | " AND key = ?", | 511 | " AND peer_id = ?" " AND key = ?", |
499 | &plugin->select_peerstoredata_by_all); | 512 | &plugin->delete_peerstoredata); |
500 | sql_prepare(plugin->dbh, | ||
501 | "DELETE FROM peerstoredata" | ||
502 | " WHERE UINT64_LT(expiry, ?)", | ||
503 | &plugin->expire_peerstoredata); | ||
504 | sql_prepare(plugin->dbh, | ||
505 | "DELETE FROM peerstoredata" | ||
506 | " WHERE sub_system = ?" | ||
507 | " AND peer_id = ?" | ||
508 | " AND key = ?", | ||
509 | &plugin->delete_peerstoredata); | ||
510 | |||
511 | return GNUNET_OK; | 513 | return GNUNET_OK; |
512 | } | 514 | } |
513 | 515 | ||
516 | |||
514 | /** | 517 | /** |
515 | * Shutdown database connection and associate data | 518 | * Shutdown database connection and associate data |
516 | * structures. | 519 | * structures. |
@@ -521,19 +524,20 @@ database_shutdown (struct Plugin *plugin) | |||
521 | { | 524 | { |
522 | int result; | 525 | int result; |
523 | sqlite3_stmt *stmt; | 526 | sqlite3_stmt *stmt; |
527 | |||
524 | while (NULL != (stmt = sqlite3_next_stmt (plugin->dbh, NULL))) | 528 | while (NULL != (stmt = sqlite3_next_stmt (plugin->dbh, NULL))) |
525 | { | 529 | { |
526 | result = sqlite3_finalize (stmt); | 530 | result = sqlite3_finalize (stmt); |
527 | if (SQLITE_OK != result) | 531 | if (SQLITE_OK != result) |
528 | LOG (GNUNET_ERROR_TYPE_WARNING, | 532 | LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to close statement %p: %d\n", |
529 | "Failed to close statement %p: %d\n", stmt, result); | 533 | stmt, result); |
530 | } | 534 | } |
531 | if (SQLITE_OK != sqlite3_close (plugin->dbh)) | 535 | if (SQLITE_OK != sqlite3_close (plugin->dbh)) |
532 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close"); | 536 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close"); |
533 | |||
534 | GNUNET_free_non_null (plugin->fn); | 537 | GNUNET_free_non_null (plugin->fn); |
535 | } | 538 | } |
536 | 539 | ||
540 | |||
537 | /** | 541 | /** |
538 | * Entry point for the plugin. | 542 | * Entry point for the plugin. |
539 | * | 543 | * |
@@ -561,10 +565,11 @@ libgnunet_plugin_peerstore_sqlite_init (void *cls) | |||
561 | api->store_record = &peerstore_sqlite_store_record; | 565 | api->store_record = &peerstore_sqlite_store_record; |
562 | api->iterate_records = &peerstore_sqlite_iterate_records; | 566 | api->iterate_records = &peerstore_sqlite_iterate_records; |
563 | api->expire_records = &peerstore_sqlite_expire_records; | 567 | api->expire_records = &peerstore_sqlite_expire_records; |
564 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Sqlite plugin is running\n"); | 568 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sqlite plugin is running\n"); |
565 | return api; | 569 | return api; |
566 | } | 570 | } |
567 | 571 | ||
572 | |||
568 | /** | 573 | /** |
569 | * Exit point from the plugin. | 574 | * Exit point from the plugin. |
570 | * | 575 | * |
@@ -582,7 +587,6 @@ libgnunet_plugin_peerstore_sqlite_done (void *cls) | |||
582 | GNUNET_free (api); | 587 | GNUNET_free (api); |
583 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sqlite plugin is finished\n"); | 588 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sqlite plugin is finished\n"); |
584 | return NULL; | 589 | return NULL; |
585 | |||
586 | } | 590 | } |
587 | 591 | ||
588 | /* end of plugin_peerstore_sqlite.c */ | 592 | /* end of plugin_peerstore_sqlite.c */ |
diff --git a/src/peerstore/test_peerstore_api_iterate.c b/src/peerstore/test_peerstore_api_iterate.c index 0b864aea5..626a020de 100644 --- a/src/peerstore/test_peerstore_api_iterate.c +++ b/src/peerstore/test_peerstore_api_iterate.c | |||
@@ -40,127 +40,87 @@ static char *val = "test_peerstore_api_iterate_val"; | |||
40 | static int count = 0; | 40 | static int count = 0; |
41 | 41 | ||
42 | static int | 42 | static int |
43 | iter3_cb(void *cls, | 43 | iter3_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
44 | struct GNUNET_PEERSTORE_Record *record, | ||
45 | char *emsg) | ||
46 | { | 44 | { |
47 | if(NULL != emsg) | 45 | if (NULL != emsg) |
48 | return GNUNET_NO; | 46 | return GNUNET_NO; |
49 | if(NULL != record) | 47 | if (NULL != record) |
50 | { | 48 | { |
51 | count++; | 49 | count++; |
52 | return GNUNET_YES; | 50 | return GNUNET_YES; |
53 | } | 51 | } |
54 | GNUNET_assert(count == 3); | 52 | GNUNET_assert (count == 3); |
55 | ok = 0; | 53 | ok = 0; |
56 | GNUNET_PEERSTORE_disconnect(h, GNUNET_NO); | 54 | GNUNET_PEERSTORE_disconnect (h, GNUNET_NO); |
57 | GNUNET_SCHEDULER_shutdown(); | 55 | GNUNET_SCHEDULER_shutdown (); |
58 | return GNUNET_YES; | 56 | return GNUNET_YES; |
59 | } | 57 | } |
60 | 58 | ||
59 | |||
61 | static int | 60 | static int |
62 | iter2_cb(void *cls, | 61 | iter2_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
63 | struct GNUNET_PEERSTORE_Record *record, | ||
64 | char *emsg) | ||
65 | { | 62 | { |
66 | if(NULL != emsg) | 63 | if (NULL != emsg) |
67 | return GNUNET_NO; | 64 | return GNUNET_NO; |
68 | if(NULL != record) | 65 | if (NULL != record) |
69 | { | 66 | { |
70 | count++; | 67 | count++; |
71 | return GNUNET_YES; | 68 | return GNUNET_YES; |
72 | } | 69 | } |
73 | GNUNET_assert(count == 2); | 70 | GNUNET_assert (count == 2); |
74 | count = 0; | 71 | count = 0; |
75 | GNUNET_PEERSTORE_iterate(h, | 72 | GNUNET_PEERSTORE_iterate (h, ss, NULL, NULL, GNUNET_TIME_UNIT_FOREVER_REL, |
76 | ss, | 73 | iter3_cb, NULL); |
77 | NULL, | ||
78 | NULL, | ||
79 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
80 | iter3_cb, | ||
81 | NULL); | ||
82 | return GNUNET_YES; | 74 | return GNUNET_YES; |
83 | } | 75 | } |
84 | 76 | ||
77 | |||
85 | static int | 78 | static int |
86 | iter1_cb(void *cls, | 79 | iter1_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
87 | struct GNUNET_PEERSTORE_Record *record, | ||
88 | char *emsg) | ||
89 | { | 80 | { |
90 | if(NULL != emsg) | 81 | if (NULL != emsg) |
91 | return GNUNET_NO; | 82 | return GNUNET_NO; |
92 | if(NULL != record) | 83 | if (NULL != record) |
93 | { | 84 | { |
94 | count++; | 85 | count++; |
95 | return GNUNET_YES; | 86 | return GNUNET_YES; |
96 | } | 87 | } |
97 | GNUNET_assert(count == 1); | 88 | GNUNET_assert (count == 1); |
98 | count = 0; | 89 | count = 0; |
99 | GNUNET_PEERSTORE_iterate(h, | 90 | GNUNET_PEERSTORE_iterate (h, ss, &p1, NULL, GNUNET_TIME_UNIT_FOREVER_REL, |
100 | ss, | 91 | iter2_cb, NULL); |
101 | &p1, | ||
102 | NULL, | ||
103 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
104 | iter2_cb, | ||
105 | NULL); | ||
106 | return GNUNET_YES; | 92 | return GNUNET_YES; |
107 | } | 93 | } |
108 | 94 | ||
95 | |||
109 | static void | 96 | static void |
110 | run (void *cls, | 97 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
111 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 98 | struct GNUNET_TESTING_Peer *peer) |
112 | struct GNUNET_TESTING_Peer *peer) | ||
113 | { | 99 | { |
114 | h = GNUNET_PEERSTORE_connect(cfg); | 100 | h = GNUNET_PEERSTORE_connect (cfg); |
115 | GNUNET_assert(NULL != h); | 101 | GNUNET_assert (NULL != h); |
116 | memset (&p1, 1, sizeof (p1)); | 102 | memset (&p1, 1, sizeof (p1)); |
117 | memset (&p2, 2, sizeof (p2)); | 103 | memset (&p2, 2, sizeof (p2)); |
118 | GNUNET_PEERSTORE_store(h, | 104 | GNUNET_PEERSTORE_store (h, ss, &p1, k1, val, strlen (val) + 1, |
119 | ss, | 105 | GNUNET_TIME_UNIT_FOREVER_ABS, |
120 | &p1, | 106 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL); |
121 | k1, | 107 | GNUNET_PEERSTORE_store (h, ss, &p1, k2, val, strlen (val) + 1, |
122 | val, | 108 | GNUNET_TIME_UNIT_FOREVER_ABS, |
123 | strlen(val) + 1, | 109 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL); |
124 | GNUNET_TIME_UNIT_FOREVER_ABS, | 110 | GNUNET_PEERSTORE_store (h, ss, &p2, k3, val, strlen (val) + 1, |
125 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | 111 | GNUNET_TIME_UNIT_FOREVER_ABS, |
126 | NULL, | 112 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL); |
127 | NULL); | 113 | GNUNET_PEERSTORE_iterate (h, ss, &p1, k1, GNUNET_TIME_UNIT_FOREVER_REL, |
128 | GNUNET_PEERSTORE_store(h, | 114 | iter1_cb, NULL); |
129 | ss, | ||
130 | &p1, | ||
131 | k2, | ||
132 | val, | ||
133 | strlen(val) + 1, | ||
134 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
135 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
136 | NULL, | ||
137 | NULL); | ||
138 | GNUNET_PEERSTORE_store(h, | ||
139 | ss, | ||
140 | &p2, | ||
141 | k3, | ||
142 | val, | ||
143 | strlen(val) + 1, | ||
144 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
145 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
146 | NULL, | ||
147 | NULL); | ||
148 | GNUNET_PEERSTORE_iterate(h, | ||
149 | ss, | ||
150 | &p1, | ||
151 | k1, | ||
152 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
153 | iter1_cb, | ||
154 | NULL); | ||
155 | } | 115 | } |
156 | 116 | ||
117 | |||
157 | int | 118 | int |
158 | main (int argc, char *argv[]) | 119 | main (int argc, char *argv[]) |
159 | { | 120 | { |
160 | if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore", | 121 | if (0 != |
161 | "peerstore", | 122 | GNUNET_TESTING_service_run ("test-gnunet-peerstore", "peerstore", |
162 | "test_peerstore_api_data.conf", | 123 | "test_peerstore_api_data.conf", &run, NULL)) |
163 | &run, NULL)) | ||
164 | return 1; | 124 | return 1; |
165 | return ok; | 125 | return ok; |
166 | } | 126 | } |
diff --git a/src/peerstore/test_peerstore_api_store.c b/src/peerstore/test_peerstore_api_store.c index 53ace3d4a..06ad34756 100644 --- a/src/peerstore/test_peerstore_api_store.c +++ b/src/peerstore/test_peerstore_api_store.c | |||
@@ -39,182 +39,155 @@ static char *val3 = "test_peerstore_api_store_val3--"; | |||
39 | 39 | ||
40 | int count = 0; | 40 | int count = 0; |
41 | 41 | ||
42 | int test3_cont2(void *cls, | 42 | int |
43 | struct GNUNET_PEERSTORE_Record *record, | 43 | test3_cont2 (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
44 | char *emsg) | ||
45 | { | 44 | { |
46 | if(NULL != emsg) | 45 | if (NULL != emsg) |
47 | return GNUNET_NO; | 46 | return GNUNET_NO; |
48 | if(NULL != record) | 47 | if (NULL != record) |
49 | { | 48 | { |
50 | GNUNET_assert((strlen(val3) + 1) == record->value_size); | 49 | GNUNET_assert ((strlen (val3) + 1) == record->value_size); |
51 | GNUNET_assert(0 == strcmp((char *)val3, (char *)record->value)); | 50 | GNUNET_assert (0 == strcmp ((char *) val3, (char *) record->value)); |
52 | count++; | 51 | count++; |
53 | return GNUNET_YES; | 52 | return GNUNET_YES; |
54 | } | 53 | } |
55 | GNUNET_assert(count == 1); | 54 | GNUNET_assert (count == 1); |
56 | ok = 0; | 55 | ok = 0; |
57 | GNUNET_PEERSTORE_disconnect(h, GNUNET_YES); | 56 | GNUNET_PEERSTORE_disconnect (h, GNUNET_YES); |
58 | GNUNET_SCHEDULER_shutdown(); | 57 | GNUNET_SCHEDULER_shutdown (); |
59 | return GNUNET_YES; | 58 | return GNUNET_YES; |
60 | } | 59 | } |
61 | 60 | ||
61 | |||
62 | static void | 62 | static void |
63 | test3_cont(void *cls, int success) | 63 | test3_cont (void *cls, int success) |
64 | { | 64 | { |
65 | if(GNUNET_YES != success) | 65 | if (GNUNET_YES != success) |
66 | return; | 66 | return; |
67 | count = 0; | 67 | count = 0; |
68 | GNUNET_PEERSTORE_iterate(h, | 68 | GNUNET_PEERSTORE_iterate (h, subsystem, &pid, key, GNUNET_TIME_UNIT_SECONDS, |
69 | subsystem, | 69 | &test3_cont2, NULL); |
70 | &pid, | ||
71 | key, | ||
72 | GNUNET_TIME_UNIT_SECONDS, | ||
73 | &test3_cont2, | ||
74 | NULL); | ||
75 | } | 70 | } |
76 | 71 | ||
72 | |||
77 | /** | 73 | /** |
78 | * Replace the previous 2 records | 74 | * Replace the previous 2 records |
79 | */ | 75 | */ |
80 | static void | 76 | static void |
81 | test3() | 77 | test3 () |
82 | { | 78 | { |
83 | GNUNET_PEERSTORE_store(h, | 79 | GNUNET_PEERSTORE_store (h, subsystem, &pid, key, val3, strlen (val3) + 1, |
84 | subsystem, | 80 | GNUNET_TIME_UNIT_FOREVER_ABS, |
85 | &pid, | 81 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, &test3_cont, |
86 | key, | 82 | NULL); |
87 | val3, | ||
88 | strlen(val3) + 1, | ||
89 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
90 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
91 | &test3_cont, | ||
92 | NULL); | ||
93 | } | 83 | } |
94 | 84 | ||
95 | int test2_cont2(void *cls, | 85 | |
96 | struct GNUNET_PEERSTORE_Record *record, | 86 | int |
97 | char *emsg) | 87 | test2_cont2 (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
98 | { | 88 | { |
99 | if(NULL != emsg) | 89 | if (NULL != emsg) |
100 | return GNUNET_NO; | 90 | return GNUNET_NO; |
101 | if(NULL != record) | 91 | if (NULL != record) |
102 | { | 92 | { |
103 | GNUNET_assert(((strlen(val1) + 1) == record->value_size) | 93 | GNUNET_assert (((strlen (val1) + 1) == record->value_size) || |
104 | || ((strlen(val2) + 1) == record->value_size)); | 94 | ((strlen (val2) + 1) == record->value_size)); |
105 | GNUNET_assert((0 == strcmp((char *)val1, (char *)record->value)) | 95 | GNUNET_assert ((0 == strcmp ((char *) val1, (char *) record->value)) || |
106 | || (0 == strcmp((char *)val2, (char *)record->value))); | 96 | (0 == strcmp ((char *) val2, (char *) record->value))); |
107 | count++; | 97 | count++; |
108 | return GNUNET_YES; | 98 | return GNUNET_YES; |
109 | } | 99 | } |
110 | GNUNET_assert(count == 2); | 100 | GNUNET_assert (count == 2); |
111 | count = 0; | 101 | count = 0; |
112 | test3(); | 102 | test3 (); |
113 | return GNUNET_YES; | 103 | return GNUNET_YES; |
114 | } | 104 | } |
115 | 105 | ||
106 | |||
116 | static void | 107 | static void |
117 | test2_cont(void *cls, int success) | 108 | test2_cont (void *cls, int success) |
118 | { | 109 | { |
119 | if(GNUNET_YES != success) | 110 | if (GNUNET_YES != success) |
120 | return; | 111 | return; |
121 | count = 0; | 112 | count = 0; |
122 | GNUNET_PEERSTORE_iterate(h, | 113 | GNUNET_PEERSTORE_iterate (h, subsystem, &pid, key, GNUNET_TIME_UNIT_SECONDS, |
123 | subsystem, | 114 | &test2_cont2, NULL); |
124 | &pid, | ||
125 | key, | ||
126 | GNUNET_TIME_UNIT_SECONDS, | ||
127 | &test2_cont2, | ||
128 | NULL); | ||
129 | } | 115 | } |
130 | 116 | ||
117 | |||
131 | /** | 118 | /** |
132 | * Test storing a second value with the same key | 119 | * Test storing a second value with the same key |
133 | */ | 120 | */ |
134 | void test2() | 121 | void |
122 | test2 () | ||
135 | { | 123 | { |
136 | GNUNET_PEERSTORE_store(h, | 124 | GNUNET_PEERSTORE_store (h, subsystem, &pid, key, val2, strlen (val2) + 1, |
137 | subsystem, | 125 | GNUNET_TIME_UNIT_FOREVER_ABS, |
138 | &pid, | 126 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, &test2_cont, |
139 | key, | 127 | NULL); |
140 | val2, | ||
141 | strlen(val2) + 1, | ||
142 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
143 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, | ||
144 | &test2_cont, | ||
145 | NULL); | ||
146 | } | 128 | } |
147 | 129 | ||
148 | int test1_cont2(void *cls, | 130 | |
149 | struct GNUNET_PEERSTORE_Record *record, | 131 | int |
150 | char *emsg) | 132 | test1_cont2 (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
151 | { | 133 | { |
152 | if(NULL != emsg) | 134 | if (NULL != emsg) |
153 | return GNUNET_NO; | 135 | return GNUNET_NO; |
154 | if(NULL != record) | 136 | if (NULL != record) |
155 | { | 137 | { |
156 | GNUNET_assert((strlen(val1) + 1) == record->value_size); | 138 | GNUNET_assert ((strlen (val1) + 1) == record->value_size); |
157 | GNUNET_assert(0 == strcmp((char *)val1, (char *)record->value)); | 139 | GNUNET_assert (0 == strcmp ((char *) val1, (char *) record->value)); |
158 | count++; | 140 | count++; |
159 | return GNUNET_YES; | 141 | return GNUNET_YES; |
160 | } | 142 | } |
161 | GNUNET_assert(count == 1); | 143 | GNUNET_assert (count == 1); |
162 | count = 0; | 144 | count = 0; |
163 | test2(); | 145 | test2 (); |
164 | return GNUNET_YES; | 146 | return GNUNET_YES; |
165 | } | 147 | } |
166 | 148 | ||
149 | |||
167 | static void | 150 | static void |
168 | test1_cont(void *cls, int success) | 151 | test1_cont (void *cls, int success) |
169 | { | 152 | { |
170 | if(GNUNET_YES != success) | 153 | if (GNUNET_YES != success) |
171 | return; | 154 | return; |
172 | count = 0; | 155 | count = 0; |
173 | GNUNET_PEERSTORE_iterate(h, | 156 | GNUNET_PEERSTORE_iterate (h, subsystem, &pid, key, GNUNET_TIME_UNIT_SECONDS, |
174 | subsystem, | 157 | &test1_cont2, NULL); |
175 | &pid, | ||
176 | key, | ||
177 | GNUNET_TIME_UNIT_SECONDS, | ||
178 | &test1_cont2, | ||
179 | NULL); | ||
180 | } | 158 | } |
181 | 159 | ||
160 | |||
182 | /** | 161 | /** |
183 | * Store a single record | 162 | * Store a single record |
184 | */ | 163 | */ |
185 | static void | 164 | static void |
186 | test1() | 165 | test1 () |
187 | { | 166 | { |
188 | GNUNET_PEERSTORE_store(h, | 167 | GNUNET_PEERSTORE_store (h, subsystem, &pid, key, val1, strlen (val1) + 1, |
189 | subsystem, | 168 | GNUNET_TIME_UNIT_FOREVER_ABS, |
190 | &pid, | 169 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, &test1_cont, |
191 | key, | 170 | NULL); |
192 | val1, | ||
193 | strlen(val1) + 1, | ||
194 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
195 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
196 | &test1_cont, | ||
197 | NULL); | ||
198 | } | 171 | } |
199 | 172 | ||
173 | |||
200 | static void | 174 | static void |
201 | run (void *cls, | 175 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
202 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 176 | struct GNUNET_TESTING_Peer *peer) |
203 | struct GNUNET_TESTING_Peer *peer) | ||
204 | { | 177 | { |
205 | h = GNUNET_PEERSTORE_connect(cfg); | 178 | h = GNUNET_PEERSTORE_connect (cfg); |
206 | GNUNET_assert(NULL != h); | 179 | GNUNET_assert (NULL != h); |
207 | memset (&pid, 1, sizeof (pid)); | 180 | memset (&pid, 1, sizeof (pid)); |
208 | test1(); | 181 | test1 (); |
209 | } | 182 | } |
210 | 183 | ||
184 | |||
211 | int | 185 | int |
212 | main (int argc, char *argv[]) | 186 | main (int argc, char *argv[]) |
213 | { | 187 | { |
214 | if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore", | 188 | if (0 != |
215 | "peerstore", | 189 | GNUNET_TESTING_service_run ("test-gnunet-peerstore", "peerstore", |
216 | "test_peerstore_api_data.conf", | 190 | "test_peerstore_api_data.conf", &run, NULL)) |
217 | &run, NULL)) | ||
218 | return 1; | 191 | return 1; |
219 | return ok; | 192 | return ok; |
220 | } | 193 | } |
diff --git a/src/peerstore/test_peerstore_api_sync.c b/src/peerstore/test_peerstore_api_sync.c index 634f62c26..3803d72c1 100644 --- a/src/peerstore/test_peerstore_api_sync.c +++ b/src/peerstore/test_peerstore_api_sync.c | |||
@@ -37,7 +37,8 @@ static struct GNUNET_PeerIdentity pid; | |||
37 | static char *key = "test_peerstore_api_store_key"; | 37 | static char *key = "test_peerstore_api_store_key"; |
38 | static char *val = "test_peerstore_api_store_val"; | 38 | static char *val = "test_peerstore_api_store_val"; |
39 | 39 | ||
40 | int iterate_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) | 40 | int |
41 | iterate_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) | ||
41 | { | 42 | { |
42 | const char *rec_val; | 43 | const char *rec_val; |
43 | 44 | ||
@@ -45,46 +46,47 @@ int iterate_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) | |||
45 | if (NULL == record) | 46 | if (NULL == record) |
46 | { | 47 | { |
47 | GNUNET_PEERSTORE_disconnect (h, GNUNET_NO); | 48 | GNUNET_PEERSTORE_disconnect (h, GNUNET_NO); |
48 | GNUNET_SCHEDULER_shutdown(); | 49 | GNUNET_SCHEDULER_shutdown (); |
49 | return GNUNET_YES; | 50 | return GNUNET_YES; |
50 | } | 51 | } |
51 | rec_val = record->value; | 52 | rec_val = record->value; |
52 | GNUNET_break (0 == strcmp(rec_val, val)); | 53 | GNUNET_break (0 == strcmp (rec_val, val)); |
53 | ok = 0; | 54 | ok = 0; |
54 | return GNUNET_YES; | 55 | return GNUNET_YES; |
55 | } | 56 | } |
56 | 57 | ||
58 | |||
57 | static void | 59 | static void |
58 | test1() | 60 | test1 () |
59 | { | 61 | { |
60 | GNUNET_PEERSTORE_store (h, subsystem, &pid, key, val, strlen(val) + 1, | 62 | GNUNET_PEERSTORE_store (h, subsystem, &pid, key, val, strlen (val) + 1, |
61 | GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_PEERSTORE_STOREOPTION_REPLACE, | 63 | GNUNET_TIME_UNIT_FOREVER_ABS, |
62 | NULL, NULL); | 64 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL); |
63 | GNUNET_PEERSTORE_disconnect (h, GNUNET_YES); | 65 | GNUNET_PEERSTORE_disconnect (h, GNUNET_YES); |
64 | h = GNUNET_PEERSTORE_connect (cfg); | 66 | h = GNUNET_PEERSTORE_connect (cfg); |
65 | GNUNET_PEERSTORE_iterate (h, subsystem, &pid, key, | 67 | GNUNET_PEERSTORE_iterate (h, subsystem, &pid, key, |
66 | GNUNET_TIME_UNIT_FOREVER_REL, &iterate_cb, NULL); | 68 | GNUNET_TIME_UNIT_FOREVER_REL, &iterate_cb, NULL); |
67 | } | 69 | } |
68 | 70 | ||
71 | |||
69 | static void | 72 | static void |
70 | run (void *cls, | 73 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, |
71 | const struct GNUNET_CONFIGURATION_Handle *c, | 74 | struct GNUNET_TESTING_Peer *peer) |
72 | struct GNUNET_TESTING_Peer *peer) | ||
73 | { | 75 | { |
74 | cfg = c; | 76 | cfg = c; |
75 | h = GNUNET_PEERSTORE_connect(cfg); | 77 | h = GNUNET_PEERSTORE_connect (cfg); |
76 | GNUNET_assert(NULL != h); | 78 | GNUNET_assert (NULL != h); |
77 | memset (&pid, 1, sizeof (pid)); | 79 | memset (&pid, 1, sizeof (pid)); |
78 | test1(); | 80 | test1 (); |
79 | } | 81 | } |
80 | 82 | ||
83 | |||
81 | int | 84 | int |
82 | main (int argc, char *argv[]) | 85 | main (int argc, char *argv[]) |
83 | { | 86 | { |
84 | if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore", | 87 | if (0 != |
85 | "peerstore", | 88 | GNUNET_TESTING_service_run ("test-gnunet-peerstore", "peerstore", |
86 | "test_peerstore_api_data.conf", | 89 | "test_peerstore_api_data.conf", &run, NULL)) |
87 | &run, NULL)) | ||
88 | return 1; | 90 | return 1; |
89 | return ok; | 91 | return ok; |
90 | } | 92 | } |
diff --git a/src/peerstore/test_peerstore_api_watch.c b/src/peerstore/test_peerstore_api_watch.c index fb6cdc540..3820f68f6 100644 --- a/src/peerstore/test_peerstore_api_watch.c +++ b/src/peerstore/test_peerstore_api_watch.c | |||
@@ -36,51 +36,37 @@ static char *k = "test_peerstore_api_watch_key"; | |||
36 | static char *val = "test_peerstore_api_watch_val"; | 36 | static char *val = "test_peerstore_api_watch_val"; |
37 | 37 | ||
38 | static int | 38 | static int |
39 | watch_cb(void *cls, | 39 | watch_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
40 | struct GNUNET_PEERSTORE_Record *record, | ||
41 | char *emsg) | ||
42 | { | 40 | { |
43 | GNUNET_assert(NULL == emsg); | 41 | GNUNET_assert (NULL == emsg); |
44 | GNUNET_assert(0 == strcmp(val, (char *)record->value)); | 42 | GNUNET_assert (0 == strcmp (val, (char *) record->value)); |
45 | ok = 0; | 43 | ok = 0; |
46 | GNUNET_PEERSTORE_disconnect(h, GNUNET_NO); | 44 | GNUNET_PEERSTORE_disconnect (h, GNUNET_NO); |
47 | GNUNET_SCHEDULER_shutdown(); | 45 | GNUNET_SCHEDULER_shutdown (); |
48 | return GNUNET_YES; | 46 | return GNUNET_YES; |
49 | } | 47 | } |
50 | 48 | ||
49 | |||
51 | static void | 50 | static void |
52 | run (void *cls, | 51 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
53 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 52 | struct GNUNET_TESTING_Peer *peer) |
54 | struct GNUNET_TESTING_Peer *peer) | ||
55 | { | 53 | { |
56 | h = GNUNET_PEERSTORE_connect(cfg); | 54 | h = GNUNET_PEERSTORE_connect (cfg); |
57 | GNUNET_assert(NULL != h); | 55 | GNUNET_assert (NULL != h); |
58 | memset (&p, 4, sizeof (p)); | 56 | memset (&p, 4, sizeof (p)); |
59 | GNUNET_PEERSTORE_watch(h, | 57 | GNUNET_PEERSTORE_watch (h, ss, &p, k, &watch_cb, NULL); |
60 | ss, | 58 | GNUNET_PEERSTORE_store (h, ss, &p, k, val, strlen (val) + 1, |
61 | &p, | 59 | GNUNET_TIME_UNIT_FOREVER_ABS, |
62 | k, | 60 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL); |
63 | &watch_cb, | ||
64 | NULL); | ||
65 | GNUNET_PEERSTORE_store(h, | ||
66 | ss, | ||
67 | &p, | ||
68 | k, | ||
69 | val, | ||
70 | strlen(val) + 1, | ||
71 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
72 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
73 | NULL, | ||
74 | NULL); | ||
75 | } | 61 | } |
76 | 62 | ||
63 | |||
77 | int | 64 | int |
78 | main (int argc, char *argv[]) | 65 | main (int argc, char *argv[]) |
79 | { | 66 | { |
80 | if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore", | 67 | if (0 != |
81 | "peerstore", | 68 | GNUNET_TESTING_service_run ("test-gnunet-peerstore", "peerstore", |
82 | "test_peerstore_api_data.conf", | 69 | "test_peerstore_api_data.conf", &run, NULL)) |
83 | &run, NULL)) | ||
84 | return 1; | 70 | return 1; |
85 | return ok; | 71 | return ok; |
86 | } | 72 | } |