diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/datastore | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/datastore')
-rw-r--r-- | src/datastore/datastore.h | 31 | ||||
-rw-r--r-- | src/datastore/datastore_api.c | 1315 | ||||
-rw-r--r-- | src/datastore/gnunet-datastore.c | 442 | ||||
-rw-r--r-- | src/datastore/gnunet-service-datastore.c | 1518 | ||||
-rw-r--r-- | src/datastore/perf_datastore_api.c | 497 | ||||
-rw-r--r-- | src/datastore/perf_plugin_datastore.c | 563 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_heap.c | 622 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_mysql.c | 1114 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_postgres.c | 942 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_sqlite.c | 1445 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_template.c | 119 | ||||
-rw-r--r-- | src/datastore/test_datastore_api.c | 696 | ||||
-rw-r--r-- | src/datastore/test_datastore_api_management.c | 377 | ||||
-rw-r--r-- | src/datastore/test_plugin_datastore.c | 451 |
14 files changed, 5054 insertions, 5078 deletions
diff --git a/src/datastore/datastore.h b/src/datastore/datastore.h index c2a20b9d3..b4a51dc02 100644 --- a/src/datastore/datastore.h +++ b/src/datastore/datastore.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file datastore/datastore.h | 22 | * @file datastore/datastore.h |
@@ -36,8 +36,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
36 | * Message from datastore service informing client about | 36 | * Message from datastore service informing client about |
37 | * the current size of the datastore. | 37 | * the current size of the datastore. |
38 | */ | 38 | */ |
39 | struct ReserveMessage | 39 | struct ReserveMessage { |
40 | { | ||
41 | /** | 40 | /** |
42 | * Type is GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE. | 41 | * Type is GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE. |
43 | */ | 42 | */ |
@@ -61,8 +60,7 @@ struct ReserveMessage | |||
61 | * This header is optionally followed by a variable-size, | 60 | * This header is optionally followed by a variable-size, |
62 | * 0-terminated error message. | 61 | * 0-terminated error message. |
63 | */ | 62 | */ |
64 | struct StatusMessage | 63 | struct StatusMessage { |
65 | { | ||
66 | /** | 64 | /** |
67 | * Type is GNUNET_MESSAGE_TYPE_DATASTORE_STATUS. | 65 | * Type is GNUNET_MESSAGE_TYPE_DATASTORE_STATUS. |
68 | */ | 66 | */ |
@@ -78,7 +76,6 @@ struct StatusMessage | |||
78 | * by the datacache at this time, zero for unknown or no limit. | 76 | * by the datacache at this time, zero for unknown or no limit. |
79 | */ | 77 | */ |
80 | struct GNUNET_TIME_AbsoluteNBO min_expiration; | 78 | struct GNUNET_TIME_AbsoluteNBO min_expiration; |
81 | |||
82 | }; | 79 | }; |
83 | 80 | ||
84 | 81 | ||
@@ -87,8 +84,7 @@ struct StatusMessage | |||
87 | * the remainder of the reserved bytes can now be released | 84 | * the remainder of the reserved bytes can now be released |
88 | * for other requests. | 85 | * for other requests. |
89 | */ | 86 | */ |
90 | struct ReleaseReserveMessage | 87 | struct ReleaseReserveMessage { |
91 | { | ||
92 | /** | 88 | /** |
93 | * Type is GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE. | 89 | * Type is GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE. |
94 | */ | 90 | */ |
@@ -98,7 +94,6 @@ struct ReleaseReserveMessage | |||
98 | * Reservation id. | 94 | * Reservation id. |
99 | */ | 95 | */ |
100 | int32_t rid GNUNET_PACKED; | 96 | int32_t rid GNUNET_PACKED; |
101 | |||
102 | }; | 97 | }; |
103 | 98 | ||
104 | 99 | ||
@@ -106,8 +101,7 @@ struct ReleaseReserveMessage | |||
106 | * Message to the datastore service asking about specific | 101 | * Message to the datastore service asking about specific |
107 | * content. | 102 | * content. |
108 | */ | 103 | */ |
109 | struct GetKeyMessage | 104 | struct GetKeyMessage { |
110 | { | ||
111 | /** | 105 | /** |
112 | * Type is #GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY. | 106 | * Type is #GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY. |
113 | */ | 107 | */ |
@@ -132,7 +126,6 @@ struct GetKeyMessage | |||
132 | * Desired key. | 126 | * Desired key. |
133 | */ | 127 | */ |
134 | struct GNUNET_HashCode key; | 128 | struct GNUNET_HashCode key; |
135 | |||
136 | }; | 129 | }; |
137 | 130 | ||
138 | 131 | ||
@@ -140,8 +133,7 @@ struct GetKeyMessage | |||
140 | * Message to the datastore service asking about specific | 133 | * Message to the datastore service asking about specific |
141 | * content. | 134 | * content. |
142 | */ | 135 | */ |
143 | struct GetMessage | 136 | struct GetMessage { |
144 | { | ||
145 | /** | 137 | /** |
146 | * Type is #GNUNET_MESSAGE_TYPE_DATASTORE_GET. | 138 | * Type is #GNUNET_MESSAGE_TYPE_DATASTORE_GET. |
147 | */ | 139 | */ |
@@ -161,7 +153,6 @@ struct GetMessage | |||
161 | * If true return a random result | 153 | * If true return a random result |
162 | */ | 154 | */ |
163 | uint32_t random GNUNET_PACKED; | 155 | uint32_t random GNUNET_PACKED; |
164 | |||
165 | }; | 156 | }; |
166 | 157 | ||
167 | 158 | ||
@@ -169,8 +160,7 @@ struct GetMessage | |||
169 | * Message to the datastore service asking about zero | 160 | * Message to the datastore service asking about zero |
170 | * anonymity content. | 161 | * anonymity content. |
171 | */ | 162 | */ |
172 | struct GetZeroAnonymityMessage | 163 | struct GetZeroAnonymityMessage { |
173 | { | ||
174 | /** | 164 | /** |
175 | * Type is GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY. | 165 | * Type is GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY. |
176 | */ | 166 | */ |
@@ -185,7 +175,6 @@ struct GetZeroAnonymityMessage | |||
185 | * UID at which to start the search | 175 | * UID at which to start the search |
186 | */ | 176 | */ |
187 | uint64_t next_uid GNUNET_PACKED; | 177 | uint64_t next_uid GNUNET_PACKED; |
188 | |||
189 | }; | 178 | }; |
190 | 179 | ||
191 | 180 | ||
@@ -193,8 +182,7 @@ struct GetZeroAnonymityMessage | |||
193 | * Message transmitting content from or to the datastore | 182 | * Message transmitting content from or to the datastore |
194 | * service. | 183 | * service. |
195 | */ | 184 | */ |
196 | struct DataMessage | 185 | struct DataMessage { |
197 | { | ||
198 | /** | 186 | /** |
199 | * Type is either GNUNET_MESSAGE_TYPE_DATASTORE_PUT, | 187 | * Type is either GNUNET_MESSAGE_TYPE_DATASTORE_PUT, |
200 | * GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE or | 188 | * GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE or |
@@ -255,7 +243,6 @@ struct DataMessage | |||
255 | * Key under which the item can be found. | 243 | * Key under which the item can be found. |
256 | */ | 244 | */ |
257 | struct GNUNET_HashCode key; | 245 | struct GNUNET_HashCode key; |
258 | |||
259 | }; | 246 | }; |
260 | GNUNET_NETWORK_STRUCT_END | 247 | GNUNET_NETWORK_STRUCT_END |
261 | 248 | ||
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index 636dbdd1a..7069975e4 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file datastore/datastore_api.c | 22 | * @file datastore/datastore_api.c |
@@ -31,7 +31,7 @@ | |||
31 | #include "gnunet_statistics_service.h" | 31 | #include "gnunet_statistics_service.h" |
32 | #include "datastore.h" | 32 | #include "datastore.h" |
33 | 33 | ||
34 | #define LOG(kind,...) GNUNET_log_from (kind, "datastore-api",__VA_ARGS__) | 34 | #define LOG(kind, ...) GNUNET_log_from(kind, "datastore-api", __VA_ARGS__) |
35 | 35 | ||
36 | #define DELAY_WARN_TIMEOUT GNUNET_TIME_UNIT_MINUTES | 36 | #define DELAY_WARN_TIMEOUT GNUNET_TIME_UNIT_MINUTES |
37 | 37 | ||
@@ -51,8 +51,7 @@ | |||
51 | /** | 51 | /** |
52 | * Context for processing status messages. | 52 | * Context for processing status messages. |
53 | */ | 53 | */ |
54 | struct StatusContext | 54 | struct StatusContext { |
55 | { | ||
56 | /** | 55 | /** |
57 | * Continuation to call with the status. | 56 | * Continuation to call with the status. |
58 | */ | 57 | */ |
@@ -62,15 +61,13 @@ struct StatusContext | |||
62 | * Closure for @e cont. | 61 | * Closure for @e cont. |
63 | */ | 62 | */ |
64 | void *cont_cls; | 63 | void *cont_cls; |
65 | |||
66 | }; | 64 | }; |
67 | 65 | ||
68 | 66 | ||
69 | /** | 67 | /** |
70 | * Context for processing result messages. | 68 | * Context for processing result messages. |
71 | */ | 69 | */ |
72 | struct ResultContext | 70 | struct ResultContext { |
73 | { | ||
74 | /** | 71 | /** |
75 | * Function to call with the result. | 72 | * Function to call with the result. |
76 | */ | 73 | */ |
@@ -80,29 +77,23 @@ struct ResultContext | |||
80 | * Closure for @e proc. | 77 | * Closure for @e proc. |
81 | */ | 78 | */ |
82 | void *proc_cls; | 79 | void *proc_cls; |
83 | |||
84 | }; | 80 | }; |
85 | 81 | ||
86 | 82 | ||
87 | /** | 83 | /** |
88 | * Context for a queue operation. | 84 | * Context for a queue operation. |
89 | */ | 85 | */ |
90 | union QueueContext | 86 | union QueueContext { |
91 | { | ||
92 | |||
93 | struct StatusContext sc; | 87 | struct StatusContext sc; |
94 | 88 | ||
95 | struct ResultContext rc; | 89 | struct ResultContext rc; |
96 | |||
97 | }; | 90 | }; |
98 | 91 | ||
99 | 92 | ||
100 | /** | 93 | /** |
101 | * Entry in our priority queue. | 94 | * Entry in our priority queue. |
102 | */ | 95 | */ |
103 | struct GNUNET_DATASTORE_QueueEntry | 96 | struct GNUNET_DATASTORE_QueueEntry { |
104 | { | ||
105 | |||
106 | /** | 97 | /** |
107 | * This is a linked list. | 98 | * This is a linked list. |
108 | */ | 99 | */ |
@@ -160,16 +151,13 @@ struct GNUNET_DATASTORE_QueueEntry | |||
160 | * Expected response type. | 151 | * Expected response type. |
161 | */ | 152 | */ |
162 | uint16_t response_type; | 153 | uint16_t response_type; |
163 | |||
164 | }; | 154 | }; |
165 | 155 | ||
166 | 156 | ||
167 | /** | 157 | /** |
168 | * Handle to the datastore service. | 158 | * Handle to the datastore service. |
169 | */ | 159 | */ |
170 | struct GNUNET_DATASTORE_Handle | 160 | struct GNUNET_DATASTORE_Handle { |
171 | { | ||
172 | |||
173 | /** | 161 | /** |
174 | * Our configuration. | 162 | * Our configuration. |
175 | */ | 163 | */ |
@@ -222,7 +210,6 @@ struct GNUNET_DATASTORE_Handle | |||
222 | * We should ignore the next message(s) from the service. | 210 | * We should ignore the next message(s) from the service. |
223 | */ | 211 | */ |
224 | unsigned int skip_next_messages; | 212 | unsigned int skip_next_messages; |
225 | |||
226 | }; | 213 | }; |
227 | 214 | ||
228 | 215 | ||
@@ -232,7 +219,7 @@ struct GNUNET_DATASTORE_Handle | |||
232 | * @param cls the `struct GNUNET_DATASTORE_Handle` | 219 | * @param cls the `struct GNUNET_DATASTORE_Handle` |
233 | */ | 220 | */ |
234 | static void | 221 | static void |
235 | try_reconnect (void *cls); | 222 | try_reconnect(void *cls); |
236 | 223 | ||
237 | 224 | ||
238 | /** | 225 | /** |
@@ -242,20 +229,20 @@ try_reconnect (void *cls); | |||
242 | * @param h handle to datastore to disconnect and reconnect | 229 | * @param h handle to datastore to disconnect and reconnect |
243 | */ | 230 | */ |
244 | static void | 231 | static void |
245 | do_disconnect (struct GNUNET_DATASTORE_Handle *h) | 232 | do_disconnect(struct GNUNET_DATASTORE_Handle *h) |
246 | { | 233 | { |
247 | if (NULL == h->mq) | 234 | if (NULL == h->mq) |
248 | { | 235 | { |
249 | GNUNET_break (0); | 236 | GNUNET_break(0); |
250 | return; | 237 | return; |
251 | } | 238 | } |
252 | GNUNET_MQ_destroy (h->mq); | 239 | GNUNET_MQ_destroy(h->mq); |
253 | h->mq = NULL; | 240 | h->mq = NULL; |
254 | h->skip_next_messages = 0; | 241 | h->skip_next_messages = 0; |
255 | h->reconnect_task | 242 | h->reconnect_task |
256 | = GNUNET_SCHEDULER_add_delayed (h->retry_time, | 243 | = GNUNET_SCHEDULER_add_delayed(h->retry_time, |
257 | &try_reconnect, | 244 | &try_reconnect, |
258 | h); | 245 | h); |
259 | } | 246 | } |
260 | 247 | ||
261 | 248 | ||
@@ -267,19 +254,19 @@ do_disconnect (struct GNUNET_DATASTORE_Handle *h) | |||
267 | * @param qe entry to free. | 254 | * @param qe entry to free. |
268 | */ | 255 | */ |
269 | static void | 256 | static void |
270 | free_queue_entry (struct GNUNET_DATASTORE_QueueEntry *qe) | 257 | free_queue_entry(struct GNUNET_DATASTORE_QueueEntry *qe) |
271 | { | 258 | { |
272 | struct GNUNET_DATASTORE_Handle *h = qe->h; | 259 | struct GNUNET_DATASTORE_Handle *h = qe->h; |
273 | 260 | ||
274 | GNUNET_CONTAINER_DLL_remove (h->queue_head, | 261 | GNUNET_CONTAINER_DLL_remove(h->queue_head, |
275 | h->queue_tail, | 262 | h->queue_tail, |
276 | qe); | 263 | qe); |
277 | h->queue_size--; | 264 | h->queue_size--; |
278 | if (NULL != qe->env) | 265 | if (NULL != qe->env) |
279 | GNUNET_MQ_discard (qe->env); | 266 | GNUNET_MQ_discard(qe->env); |
280 | if (NULL != qe->delay_warn_task) | 267 | if (NULL != qe->delay_warn_task) |
281 | GNUNET_SCHEDULER_cancel (qe->delay_warn_task); | 268 | GNUNET_SCHEDULER_cancel(qe->delay_warn_task); |
282 | GNUNET_free (qe); | 269 | GNUNET_free(qe); |
283 | } | 270 | } |
284 | 271 | ||
285 | 272 | ||
@@ -289,20 +276,20 @@ free_queue_entry (struct GNUNET_DATASTORE_QueueEntry *qe) | |||
289 | * @param qe `struct GNUNET_DATASTORE_QueueEntry` about which the error is | 276 | * @param qe `struct GNUNET_DATASTORE_QueueEntry` about which the error is |
290 | */ | 277 | */ |
291 | static void | 278 | static void |
292 | delay_warning (void *cls) | 279 | delay_warning(void *cls) |
293 | { | 280 | { |
294 | struct GNUNET_DATASTORE_QueueEntry *qe = cls; | 281 | struct GNUNET_DATASTORE_QueueEntry *qe = cls; |
295 | 282 | ||
296 | qe->delay_warn_task = NULL; | 283 | qe->delay_warn_task = NULL; |
297 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 284 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
298 | "Request %p of type %u at head of datastore queue for more than %s\n", | 285 | "Request %p of type %u at head of datastore queue for more than %s\n", |
299 | qe, | 286 | qe, |
300 | (unsigned int) qe->response_type, | 287 | (unsigned int)qe->response_type, |
301 | GNUNET_STRINGS_relative_time_to_string (DELAY_WARN_TIMEOUT, | 288 | GNUNET_STRINGS_relative_time_to_string(DELAY_WARN_TIMEOUT, |
302 | GNUNET_YES)); | 289 | GNUNET_YES)); |
303 | qe->delay_warn_task = GNUNET_SCHEDULER_add_delayed (DELAY_WARN_TIMEOUT, | 290 | qe->delay_warn_task = GNUNET_SCHEDULER_add_delayed(DELAY_WARN_TIMEOUT, |
304 | &delay_warning, | 291 | &delay_warning, |
305 | qe); | 292 | qe); |
306 | } | 293 | } |
307 | 294 | ||
308 | 295 | ||
@@ -313,57 +300,59 @@ delay_warning (void *cls) | |||
313 | * @param error error code | 300 | * @param error error code |
314 | */ | 301 | */ |
315 | static void | 302 | static void |
316 | mq_error_handler (void *cls, | 303 | mq_error_handler(void *cls, |
317 | enum GNUNET_MQ_Error error) | 304 | enum GNUNET_MQ_Error error) |
318 | { | 305 | { |
319 | struct GNUNET_DATASTORE_Handle *h = cls; | 306 | struct GNUNET_DATASTORE_Handle *h = cls; |
320 | struct GNUNET_DATASTORE_QueueEntry *qe; | 307 | struct GNUNET_DATASTORE_QueueEntry *qe; |
321 | 308 | ||
322 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 309 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
323 | "MQ error, reconnecting to DATASTORE\n"); | 310 | "MQ error, reconnecting to DATASTORE\n"); |
324 | do_disconnect (h); | 311 | do_disconnect(h); |
325 | qe = h->queue_head; | 312 | qe = h->queue_head; |
326 | if (NULL == qe) | 313 | if (NULL == qe) |
327 | return; | 314 | return; |
328 | if (NULL != qe->delay_warn_task) | 315 | if (NULL != qe->delay_warn_task) |
329 | { | 316 | { |
330 | GNUNET_SCHEDULER_cancel (qe->delay_warn_task); | 317 | GNUNET_SCHEDULER_cancel(qe->delay_warn_task); |
331 | qe->delay_warn_task = NULL; | 318 | qe->delay_warn_task = NULL; |
332 | } | 319 | } |
333 | if (NULL == qe->env) | 320 | if (NULL == qe->env) |
334 | { | ||
335 | union QueueContext qc = qe->qc; | ||
336 | uint16_t rt = qe->response_type; | ||
337 | |||
338 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
339 | "Failed to receive response from database.\n"); | ||
340 | free_queue_entry (qe); | ||
341 | switch (rt) | ||
342 | { | 321 | { |
343 | case GNUNET_MESSAGE_TYPE_DATASTORE_STATUS: | 322 | union QueueContext qc = qe->qc; |
344 | if (NULL != qc.sc.cont) | 323 | uint16_t rt = qe->response_type; |
345 | qc.sc.cont (qc.sc.cont_cls, | 324 | |
346 | GNUNET_SYSERR, | 325 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
347 | GNUNET_TIME_UNIT_ZERO_ABS, | 326 | "Failed to receive response from database.\n"); |
348 | _("DATASTORE disconnected")); | 327 | free_queue_entry(qe); |
349 | break; | 328 | switch (rt) |
350 | case GNUNET_MESSAGE_TYPE_DATASTORE_DATA: | 329 | { |
351 | if (NULL != qc.rc.proc) | 330 | case GNUNET_MESSAGE_TYPE_DATASTORE_STATUS: |
352 | qc.rc.proc (qc.rc.proc_cls, | 331 | if (NULL != qc.sc.cont) |
353 | NULL, | 332 | qc.sc.cont(qc.sc.cont_cls, |
354 | 0, | 333 | GNUNET_SYSERR, |
355 | NULL, | 334 | GNUNET_TIME_UNIT_ZERO_ABS, |
356 | 0, | 335 | _("DATASTORE disconnected")); |
357 | 0, | 336 | break; |
358 | 0, | 337 | |
359 | 0, | 338 | case GNUNET_MESSAGE_TYPE_DATASTORE_DATA: |
360 | GNUNET_TIME_UNIT_ZERO_ABS, | 339 | if (NULL != qc.rc.proc) |
361 | 0); | 340 | qc.rc.proc(qc.rc.proc_cls, |
362 | break; | 341 | NULL, |
363 | default: | 342 | 0, |
364 | GNUNET_break (0); | 343 | NULL, |
344 | 0, | ||
345 | 0, | ||
346 | 0, | ||
347 | 0, | ||
348 | GNUNET_TIME_UNIT_ZERO_ABS, | ||
349 | 0); | ||
350 | break; | ||
351 | |||
352 | default: | ||
353 | GNUNET_break(0); | ||
354 | } | ||
365 | } | 355 | } |
366 | } | ||
367 | } | 356 | } |
368 | 357 | ||
369 | 358 | ||
@@ -374,22 +363,22 @@ mq_error_handler (void *cls, | |||
374 | * @return handle to use to access the service | 363 | * @return handle to use to access the service |
375 | */ | 364 | */ |
376 | struct GNUNET_DATASTORE_Handle * | 365 | struct GNUNET_DATASTORE_Handle * |
377 | GNUNET_DATASTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | 366 | GNUNET_DATASTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) |
378 | { | 367 | { |
379 | struct GNUNET_DATASTORE_Handle *h; | 368 | struct GNUNET_DATASTORE_Handle *h; |
380 | 369 | ||
381 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 370 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
382 | "Establishing DATASTORE connection!\n"); | 371 | "Establishing DATASTORE connection!\n"); |
383 | h = GNUNET_new (struct GNUNET_DATASTORE_Handle); | 372 | h = GNUNET_new(struct GNUNET_DATASTORE_Handle); |
384 | h->cfg = cfg; | 373 | h->cfg = cfg; |
385 | try_reconnect (h); | 374 | try_reconnect(h); |
386 | if (NULL == h->mq) | 375 | if (NULL == h->mq) |
387 | { | 376 | { |
388 | GNUNET_free (h); | 377 | GNUNET_free(h); |
389 | return NULL; | 378 | return NULL; |
390 | } | 379 | } |
391 | h->stats = GNUNET_STATISTICS_create ("datastore-api", | 380 | h->stats = GNUNET_STATISTICS_create("datastore-api", |
392 | cfg); | 381 | cfg); |
393 | return h; | 382 | return h; |
394 | } | 383 | } |
395 | 384 | ||
@@ -401,14 +390,14 @@ GNUNET_DATASTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
401 | * @param cls the datastore handle | 390 | * @param cls the datastore handle |
402 | */ | 391 | */ |
403 | static void | 392 | static void |
404 | disconnect_after_drop (void *cls) | 393 | disconnect_after_drop(void *cls) |
405 | { | 394 | { |
406 | struct GNUNET_DATASTORE_Handle *h = cls; | 395 | struct GNUNET_DATASTORE_Handle *h = cls; |
407 | 396 | ||
408 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 397 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
409 | "Drop sent, disconnecting\n"); | 398 | "Drop sent, disconnecting\n"); |
410 | GNUNET_DATASTORE_disconnect (h, | 399 | GNUNET_DATASTORE_disconnect(h, |
411 | GNUNET_NO); | 400 | GNUNET_NO); |
412 | } | 401 | } |
413 | 402 | ||
414 | 403 | ||
@@ -419,15 +408,15 @@ disconnect_after_drop (void *cls) | |||
419 | * @param error error code | 408 | * @param error error code |
420 | */ | 409 | */ |
421 | static void | 410 | static void |
422 | disconnect_on_mq_error (void *cls, | 411 | disconnect_on_mq_error(void *cls, |
423 | enum GNUNET_MQ_Error error) | 412 | enum GNUNET_MQ_Error error) |
424 | { | 413 | { |
425 | struct GNUNET_DATASTORE_Handle *h = cls; | 414 | struct GNUNET_DATASTORE_Handle *h = cls; |
426 | 415 | ||
427 | LOG (GNUNET_ERROR_TYPE_ERROR, | 416 | LOG(GNUNET_ERROR_TYPE_ERROR, |
428 | "Failed to ask datastore to drop tables\n"); | 417 | "Failed to ask datastore to drop tables\n"); |
429 | GNUNET_DATASTORE_disconnect (h, | 418 | GNUNET_DATASTORE_disconnect(h, |
430 | GNUNET_NO); | 419 | GNUNET_NO); |
431 | } | 420 | } |
432 | 421 | ||
433 | 422 | ||
@@ -439,82 +428,84 @@ disconnect_on_mq_error (void *cls, | |||
439 | * @param drop set to #GNUNET_YES to delete all data in datastore (!) | 428 | * @param drop set to #GNUNET_YES to delete all data in datastore (!) |
440 | */ | 429 | */ |
441 | void | 430 | void |
442 | GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, | 431 | GNUNET_DATASTORE_disconnect(struct GNUNET_DATASTORE_Handle *h, |
443 | int drop) | 432 | int drop) |
444 | { | 433 | { |
445 | struct GNUNET_DATASTORE_QueueEntry *qe; | 434 | struct GNUNET_DATASTORE_QueueEntry *qe; |
446 | 435 | ||
447 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 436 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
448 | "Datastore disconnect\n"); | 437 | "Datastore disconnect\n"); |
449 | if (NULL != h->mq) | 438 | if (NULL != h->mq) |
450 | { | 439 | { |
451 | GNUNET_MQ_destroy (h->mq); | 440 | GNUNET_MQ_destroy(h->mq); |
452 | h->mq = NULL; | 441 | h->mq = NULL; |
453 | } | 442 | } |
454 | if (NULL != h->reconnect_task) | 443 | if (NULL != h->reconnect_task) |
455 | { | 444 | { |
456 | GNUNET_SCHEDULER_cancel (h->reconnect_task); | 445 | GNUNET_SCHEDULER_cancel(h->reconnect_task); |
457 | h->reconnect_task = NULL; | 446 | h->reconnect_task = NULL; |
458 | } | 447 | } |
459 | while (NULL != (qe = h->queue_head)) | 448 | while (NULL != (qe = h->queue_head)) |
460 | { | ||
461 | switch (qe->response_type) | ||
462 | { | 449 | { |
463 | case GNUNET_MESSAGE_TYPE_DATASTORE_STATUS: | 450 | switch (qe->response_type) |
464 | if (NULL != qe->qc.sc.cont) | 451 | { |
465 | qe->qc.sc.cont (qe->qc.sc.cont_cls, | 452 | case GNUNET_MESSAGE_TYPE_DATASTORE_STATUS: |
466 | GNUNET_SYSERR, | 453 | if (NULL != qe->qc.sc.cont) |
467 | GNUNET_TIME_UNIT_ZERO_ABS, | 454 | qe->qc.sc.cont(qe->qc.sc.cont_cls, |
468 | _("Disconnected from DATASTORE")); | 455 | GNUNET_SYSERR, |
469 | break; | 456 | GNUNET_TIME_UNIT_ZERO_ABS, |
470 | case GNUNET_MESSAGE_TYPE_DATASTORE_DATA: | 457 | _("Disconnected from DATASTORE")); |
471 | if (NULL != qe->qc.rc.proc) | 458 | break; |
472 | qe->qc.rc.proc (qe->qc.rc.proc_cls, | 459 | |
473 | NULL, | 460 | case GNUNET_MESSAGE_TYPE_DATASTORE_DATA: |
474 | 0, | 461 | if (NULL != qe->qc.rc.proc) |
475 | NULL, | 462 | qe->qc.rc.proc(qe->qc.rc.proc_cls, |
476 | 0, | 463 | NULL, |
477 | 0, | 464 | 0, |
478 | 0, | 465 | NULL, |
479 | 0, | 466 | 0, |
480 | GNUNET_TIME_UNIT_ZERO_ABS, | 467 | 0, |
481 | 0); | 468 | 0, |
482 | break; | 469 | 0, |
483 | default: | 470 | GNUNET_TIME_UNIT_ZERO_ABS, |
484 | GNUNET_break (0); | 471 | 0); |
472 | break; | ||
473 | |||
474 | default: | ||
475 | GNUNET_break(0); | ||
476 | } | ||
477 | free_queue_entry(qe); | ||
485 | } | 478 | } |
486 | free_queue_entry (qe); | ||
487 | } | ||
488 | if (GNUNET_YES == drop) | 479 | if (GNUNET_YES == drop) |
489 | { | ||
490 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
491 | "Re-connecting to issue DROP!\n"); | ||
492 | GNUNET_assert (NULL == h->mq); | ||
493 | h->mq = GNUNET_CLIENT_connect (h->cfg, | ||
494 | "datastore", | ||
495 | NULL, | ||
496 | &disconnect_on_mq_error, | ||
497 | h); | ||
498 | if (NULL != h->mq) | ||
499 | { | 480 | { |
500 | struct GNUNET_MessageHeader *hdr; | 481 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
501 | struct GNUNET_MQ_Envelope *env; | 482 | "Re-connecting to issue DROP!\n"); |
502 | 483 | GNUNET_assert(NULL == h->mq); | |
503 | env = GNUNET_MQ_msg (hdr, | 484 | h->mq = GNUNET_CLIENT_connect(h->cfg, |
504 | GNUNET_MESSAGE_TYPE_DATASTORE_DROP); | 485 | "datastore", |
505 | GNUNET_MQ_notify_sent (env, | 486 | NULL, |
506 | &disconnect_after_drop, | 487 | &disconnect_on_mq_error, |
507 | h); | 488 | h); |
508 | GNUNET_MQ_send (h->mq, | 489 | if (NULL != h->mq) |
509 | env); | 490 | { |
510 | return; | 491 | struct GNUNET_MessageHeader *hdr; |
492 | struct GNUNET_MQ_Envelope *env; | ||
493 | |||
494 | env = GNUNET_MQ_msg(hdr, | ||
495 | GNUNET_MESSAGE_TYPE_DATASTORE_DROP); | ||
496 | GNUNET_MQ_notify_sent(env, | ||
497 | &disconnect_after_drop, | ||
498 | h); | ||
499 | GNUNET_MQ_send(h->mq, | ||
500 | env); | ||
501 | return; | ||
502 | } | ||
503 | GNUNET_break(0); | ||
511 | } | 504 | } |
512 | GNUNET_break (0); | 505 | GNUNET_STATISTICS_destroy(h->stats, |
513 | } | 506 | GNUNET_NO); |
514 | GNUNET_STATISTICS_destroy (h->stats, | ||
515 | GNUNET_NO); | ||
516 | h->stats = NULL; | 507 | h->stats = NULL; |
517 | GNUNET_free (h); | 508 | GNUNET_free(h); |
518 | } | 509 | } |
519 | 510 | ||
520 | 511 | ||
@@ -534,45 +525,45 @@ GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, | |||
534 | * @return NULL if the queue is full | 525 | * @return NULL if the queue is full |
535 | */ | 526 | */ |
536 | static struct GNUNET_DATASTORE_QueueEntry * | 527 | static struct GNUNET_DATASTORE_QueueEntry * |
537 | make_queue_entry (struct GNUNET_DATASTORE_Handle *h, | 528 | make_queue_entry(struct GNUNET_DATASTORE_Handle *h, |
538 | struct GNUNET_MQ_Envelope *env, | 529 | struct GNUNET_MQ_Envelope *env, |
539 | unsigned int queue_priority, | 530 | unsigned int queue_priority, |
540 | unsigned int max_queue_size, | 531 | unsigned int max_queue_size, |
541 | uint16_t expected_type, | 532 | uint16_t expected_type, |
542 | const union QueueContext *qc) | 533 | const union QueueContext *qc) |
543 | { | 534 | { |
544 | struct GNUNET_DATASTORE_QueueEntry *qe; | 535 | struct GNUNET_DATASTORE_QueueEntry *qe; |
545 | struct GNUNET_DATASTORE_QueueEntry *pos; | 536 | struct GNUNET_DATASTORE_QueueEntry *pos; |
546 | unsigned int c; | 537 | unsigned int c; |
547 | 538 | ||
548 | if ( (NULL != h->queue_tail) && | 539 | if ((NULL != h->queue_tail) && |
549 | (h->queue_tail->priority >= queue_priority) ) | 540 | (h->queue_tail->priority >= queue_priority)) |
550 | { | 541 | { |
551 | c = h->queue_size; | 542 | c = h->queue_size; |
552 | pos = NULL; | 543 | pos = NULL; |
553 | } | 544 | } |
554 | else | 545 | else |
555 | { | 546 | { |
556 | c = 0; | 547 | c = 0; |
557 | pos = h->queue_head; | 548 | pos = h->queue_head; |
558 | } | 549 | } |
559 | while ( (NULL != pos) && | 550 | while ((NULL != pos) && |
560 | (c < max_queue_size) && | 551 | (c < max_queue_size) && |
561 | (pos->priority >= queue_priority) ) | 552 | (pos->priority >= queue_priority)) |
562 | { | 553 | { |
563 | c++; | 554 | c++; |
564 | pos = pos->next; | 555 | pos = pos->next; |
565 | } | 556 | } |
566 | if (c >= max_queue_size) | 557 | if (c >= max_queue_size) |
567 | { | 558 | { |
568 | GNUNET_STATISTICS_update (h->stats, | 559 | GNUNET_STATISTICS_update(h->stats, |
569 | gettext_noop ("# queue overflows"), | 560 | gettext_noop("# queue overflows"), |
570 | 1, | 561 | 1, |
571 | GNUNET_NO); | 562 | GNUNET_NO); |
572 | GNUNET_MQ_discard (env); | 563 | GNUNET_MQ_discard(env); |
573 | return NULL; | 564 | return NULL; |
574 | } | 565 | } |
575 | qe = GNUNET_new (struct GNUNET_DATASTORE_QueueEntry); | 566 | qe = GNUNET_new(struct GNUNET_DATASTORE_QueueEntry); |
576 | qe->h = h; | 567 | qe->h = h; |
577 | qe->env = env; | 568 | qe->env = env; |
578 | qe->response_type = expected_type; | 569 | qe->response_type = expected_type; |
@@ -580,30 +571,30 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h, | |||
580 | qe->priority = queue_priority; | 571 | qe->priority = queue_priority; |
581 | qe->max_queue = max_queue_size; | 572 | qe->max_queue = max_queue_size; |
582 | if (NULL == pos) | 573 | if (NULL == pos) |
583 | { | 574 | { |
584 | /* append at the tail */ | 575 | /* append at the tail */ |
585 | pos = h->queue_tail; | 576 | pos = h->queue_tail; |
586 | } | 577 | } |
587 | else | 578 | else |
588 | { | 579 | { |
589 | pos = pos->prev; | 580 | pos = pos->prev; |
590 | /* do not insert at HEAD if HEAD query was already | 581 | /* do not insert at HEAD if HEAD query was already |
591 | * transmitted and we are still receiving replies! */ | 582 | * transmitted and we are still receiving replies! */ |
592 | if ( (NULL == pos) && | 583 | if ((NULL == pos) && |
593 | (NULL == h->queue_head->env) ) | 584 | (NULL == h->queue_head->env)) |
594 | pos = h->queue_head; | 585 | pos = h->queue_head; |
595 | } | 586 | } |
596 | c++; | 587 | c++; |
597 | #if INSANE_STATISTICS | 588 | #if INSANE_STATISTICS |
598 | GNUNET_STATISTICS_update (h->stats, | 589 | GNUNET_STATISTICS_update(h->stats, |
599 | gettext_noop ("# queue entries created"), | 590 | gettext_noop("# queue entries created"), |
600 | 1, | 591 | 1, |
601 | GNUNET_NO); | 592 | GNUNET_NO); |
602 | #endif | 593 | #endif |
603 | GNUNET_CONTAINER_DLL_insert_after (h->queue_head, | 594 | GNUNET_CONTAINER_DLL_insert_after(h->queue_head, |
604 | h->queue_tail, | 595 | h->queue_tail, |
605 | pos, | 596 | pos, |
606 | qe); | 597 | qe); |
607 | h->queue_size++; | 598 | h->queue_size++; |
608 | return qe; | 599 | return qe; |
609 | } | 600 | } |
@@ -616,37 +607,37 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h, | |||
616 | * @param h handle to the datastore | 607 | * @param h handle to the datastore |
617 | */ | 608 | */ |
618 | static void | 609 | static void |
619 | process_queue (struct GNUNET_DATASTORE_Handle *h) | 610 | process_queue(struct GNUNET_DATASTORE_Handle *h) |
620 | { | 611 | { |
621 | struct GNUNET_DATASTORE_QueueEntry *qe; | 612 | struct GNUNET_DATASTORE_QueueEntry *qe; |
622 | 613 | ||
623 | if (NULL == (qe = h->queue_head)) | 614 | if (NULL == (qe = h->queue_head)) |
624 | { | 615 | { |
625 | /* no entry in queue */ | 616 | /* no entry in queue */ |
626 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 617 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
627 | "Queue empty\n"); | 618 | "Queue empty\n"); |
628 | return; | 619 | return; |
629 | } | 620 | } |
630 | if (NULL == qe->env) | 621 | if (NULL == qe->env) |
631 | { | 622 | { |
632 | /* waiting for replies */ | 623 | /* waiting for replies */ |
633 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 624 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
634 | "Head request already transmitted\n"); | 625 | "Head request already transmitted\n"); |
635 | return; | 626 | return; |
636 | } | 627 | } |
637 | if (NULL == h->mq) | 628 | if (NULL == h->mq) |
638 | { | 629 | { |
639 | /* waiting for reconnect */ | 630 | /* waiting for reconnect */ |
640 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 631 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
641 | "Not connected\n"); | 632 | "Not connected\n"); |
642 | return; | 633 | return; |
643 | } | 634 | } |
644 | GNUNET_assert (NULL == qe->delay_warn_task); | 635 | GNUNET_assert(NULL == qe->delay_warn_task); |
645 | qe->delay_warn_task = GNUNET_SCHEDULER_add_delayed (DELAY_WARN_TIMEOUT, | 636 | qe->delay_warn_task = GNUNET_SCHEDULER_add_delayed(DELAY_WARN_TIMEOUT, |
646 | &delay_warning, | 637 | &delay_warning, |
647 | qe); | 638 | qe); |
648 | GNUNET_MQ_send (h->mq, | 639 | GNUNET_MQ_send(h->mq, |
649 | qe->env); | 640 | qe->env); |
650 | qe->env = NULL; | 641 | qe->env = NULL; |
651 | } | 642 | } |
652 | 643 | ||
@@ -659,36 +650,36 @@ process_queue (struct GNUNET_DATASTORE_Handle *h) | |||
659 | * @return the queue entry | 650 | * @return the queue entry |
660 | */ | 651 | */ |
661 | static struct GNUNET_DATASTORE_QueueEntry * | 652 | static struct GNUNET_DATASTORE_QueueEntry * |
662 | get_queue_head (struct GNUNET_DATASTORE_Handle *h, | 653 | get_queue_head(struct GNUNET_DATASTORE_Handle *h, |
663 | uint16_t response_type) | 654 | uint16_t response_type) |
664 | { | 655 | { |
665 | struct GNUNET_DATASTORE_QueueEntry *qe; | 656 | struct GNUNET_DATASTORE_QueueEntry *qe; |
666 | 657 | ||
667 | if (h->skip_next_messages > 0) | 658 | if (h->skip_next_messages > 0) |
668 | { | 659 | { |
669 | h->skip_next_messages--; | 660 | h->skip_next_messages--; |
670 | process_queue (h); | 661 | process_queue(h); |
671 | return NULL; | 662 | return NULL; |
672 | } | 663 | } |
673 | qe = h->queue_head; | 664 | qe = h->queue_head; |
674 | if (NULL == qe) | 665 | if (NULL == qe) |
675 | { | 666 | { |
676 | GNUNET_break (0); | 667 | GNUNET_break(0); |
677 | do_disconnect (h); | 668 | do_disconnect(h); |
678 | return NULL; | 669 | return NULL; |
679 | } | 670 | } |
680 | if (NULL != qe->env) | 671 | if (NULL != qe->env) |
681 | { | 672 | { |
682 | GNUNET_break (0); | 673 | GNUNET_break(0); |
683 | do_disconnect (h); | 674 | do_disconnect(h); |
684 | return NULL; | 675 | return NULL; |
685 | } | 676 | } |
686 | if (response_type != qe->response_type) | 677 | if (response_type != qe->response_type) |
687 | { | 678 | { |
688 | GNUNET_break (0); | 679 | GNUNET_break(0); |
689 | do_disconnect (h); | 680 | do_disconnect(h); |
690 | return NULL; | 681 | return NULL; |
691 | } | 682 | } |
692 | return qe; | 683 | return qe; |
693 | } | 684 | } |
694 | 685 | ||
@@ -701,27 +692,27 @@ get_queue_head (struct GNUNET_DATASTORE_Handle *h, | |||
701 | * @return #GNUNET_OK if the message is well-formed | 692 | * @return #GNUNET_OK if the message is well-formed |
702 | */ | 693 | */ |
703 | static int | 694 | static int |
704 | check_status (void *cls, | 695 | check_status(void *cls, |
705 | const struct StatusMessage *sm) | 696 | const struct StatusMessage *sm) |
706 | { | 697 | { |
707 | uint16_t msize = ntohs (sm->header.size) - sizeof (*sm); | 698 | uint16_t msize = ntohs(sm->header.size) - sizeof(*sm); |
708 | int32_t status = ntohl (sm->status); | 699 | int32_t status = ntohl(sm->status); |
709 | 700 | ||
710 | if (msize > 0) | 701 | if (msize > 0) |
711 | { | 702 | { |
712 | const char *emsg = (const char *) &sm[1]; | 703 | const char *emsg = (const char *)&sm[1]; |
713 | 704 | ||
714 | if ('\0' != emsg[msize - 1]) | 705 | if ('\0' != emsg[msize - 1]) |
706 | { | ||
707 | GNUNET_break(0); | ||
708 | return GNUNET_SYSERR; | ||
709 | } | ||
710 | } | ||
711 | else if (GNUNET_SYSERR == status) | ||
715 | { | 712 | { |
716 | GNUNET_break (0); | 713 | GNUNET_break(0); |
717 | return GNUNET_SYSERR; | 714 | return GNUNET_SYSERR; |
718 | } | 715 | } |
719 | } | ||
720 | else if (GNUNET_SYSERR == status) | ||
721 | { | ||
722 | GNUNET_break (0); | ||
723 | return GNUNET_SYSERR; | ||
724 | } | ||
725 | return GNUNET_OK; | 716 | return GNUNET_OK; |
726 | } | 717 | } |
727 | 718 | ||
@@ -733,40 +724,40 @@ check_status (void *cls, | |||
733 | * @param sm status message received | 724 | * @param sm status message received |
734 | */ | 725 | */ |
735 | static void | 726 | static void |
736 | handle_status (void *cls, | 727 | handle_status(void *cls, |
737 | const struct StatusMessage *sm) | 728 | const struct StatusMessage *sm) |
738 | { | 729 | { |
739 | struct GNUNET_DATASTORE_Handle *h = cls; | 730 | struct GNUNET_DATASTORE_Handle *h = cls; |
740 | struct GNUNET_DATASTORE_QueueEntry *qe; | 731 | struct GNUNET_DATASTORE_QueueEntry *qe; |
741 | struct StatusContext rc; | 732 | struct StatusContext rc; |
742 | const char *emsg; | 733 | const char *emsg; |
743 | int32_t status = ntohl (sm->status); | 734 | int32_t status = ntohl(sm->status); |
744 | 735 | ||
745 | qe = get_queue_head (h, | 736 | qe = get_queue_head(h, |
746 | GNUNET_MESSAGE_TYPE_DATASTORE_STATUS); | 737 | GNUNET_MESSAGE_TYPE_DATASTORE_STATUS); |
747 | if (NULL == qe) | 738 | if (NULL == qe) |
748 | return; | 739 | return; |
749 | rc = qe->qc.sc; | 740 | rc = qe->qc.sc; |
750 | free_queue_entry (qe); | 741 | free_queue_entry(qe); |
751 | if (ntohs (sm->header.size) > sizeof (struct StatusMessage)) | 742 | if (ntohs(sm->header.size) > sizeof(struct StatusMessage)) |
752 | emsg = (const char *) &sm[1]; | 743 | emsg = (const char *)&sm[1]; |
753 | else | 744 | else |
754 | emsg = NULL; | 745 | emsg = NULL; |
755 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 746 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
756 | "Received status %d/%s\n", | 747 | "Received status %d/%s\n", |
757 | (int) status, | 748 | (int)status, |
758 | emsg); | 749 | emsg); |
759 | GNUNET_STATISTICS_update (h->stats, | 750 | GNUNET_STATISTICS_update(h->stats, |
760 | gettext_noop ("# status messages received"), | 751 | gettext_noop("# status messages received"), |
761 | 1, | 752 | 1, |
762 | GNUNET_NO); | 753 | GNUNET_NO); |
763 | h->retry_time = GNUNET_TIME_UNIT_ZERO; | 754 | h->retry_time = GNUNET_TIME_UNIT_ZERO; |
764 | process_queue (h); | 755 | process_queue(h); |
765 | if (NULL != rc.cont) | 756 | if (NULL != rc.cont) |
766 | rc.cont (rc.cont_cls, | 757 | rc.cont(rc.cont_cls, |
767 | status, | 758 | status, |
768 | GNUNET_TIME_absolute_ntoh (sm->min_expiration), | 759 | GNUNET_TIME_absolute_ntoh(sm->min_expiration), |
769 | emsg); | 760 | emsg); |
770 | } | 761 | } |
771 | 762 | ||
772 | 763 | ||
@@ -777,16 +768,16 @@ handle_status (void *cls, | |||
777 | * @param dm message received | 768 | * @param dm message received |
778 | */ | 769 | */ |
779 | static int | 770 | static int |
780 | check_data (void *cls, | 771 | check_data(void *cls, |
781 | const struct DataMessage *dm) | 772 | const struct DataMessage *dm) |
782 | { | 773 | { |
783 | uint16_t msize = ntohs (dm->header.size) - sizeof (*dm); | 774 | uint16_t msize = ntohs(dm->header.size) - sizeof(*dm); |
784 | 775 | ||
785 | if (msize != ntohl (dm->size)) | 776 | if (msize != ntohl(dm->size)) |
786 | { | 777 | { |
787 | GNUNET_break (0); | 778 | GNUNET_break(0); |
788 | return GNUNET_SYSERR; | 779 | return GNUNET_SYSERR; |
789 | } | 780 | } |
790 | return GNUNET_OK; | 781 | return GNUNET_OK; |
791 | } | 782 | } |
792 | 783 | ||
@@ -798,44 +789,44 @@ check_data (void *cls, | |||
798 | * @param dm message received | 789 | * @param dm message received |
799 | */ | 790 | */ |
800 | static void | 791 | static void |
801 | handle_data (void *cls, | 792 | handle_data(void *cls, |
802 | const struct DataMessage *dm) | 793 | const struct DataMessage *dm) |
803 | { | 794 | { |
804 | struct GNUNET_DATASTORE_Handle *h = cls; | 795 | struct GNUNET_DATASTORE_Handle *h = cls; |
805 | struct GNUNET_DATASTORE_QueueEntry *qe; | 796 | struct GNUNET_DATASTORE_QueueEntry *qe; |
806 | struct ResultContext rc; | 797 | struct ResultContext rc; |
807 | 798 | ||
808 | qe = get_queue_head (h, | 799 | qe = get_queue_head(h, |
809 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA); | 800 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA); |
810 | if (NULL == qe) | 801 | if (NULL == qe) |
811 | return; | 802 | return; |
812 | #if INSANE_STATISTICS | 803 | #if INSANE_STATISTICS |
813 | GNUNET_STATISTICS_update (h->stats, | 804 | GNUNET_STATISTICS_update(h->stats, |
814 | gettext_noop ("# Results received"), | 805 | gettext_noop("# Results received"), |
815 | 1, | 806 | 1, |
816 | GNUNET_NO); | 807 | GNUNET_NO); |
817 | #endif | 808 | #endif |
818 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 809 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
819 | "Received result %llu with type %u and size %u with key %s\n", | 810 | "Received result %llu with type %u and size %u with key %s\n", |
820 | (unsigned long long) GNUNET_ntohll (dm->uid), | 811 | (unsigned long long)GNUNET_ntohll(dm->uid), |
821 | ntohl (dm->type), | 812 | ntohl(dm->type), |
822 | ntohl (dm->size), | 813 | ntohl(dm->size), |
823 | GNUNET_h2s (&dm->key)); | 814 | GNUNET_h2s(&dm->key)); |
824 | rc = qe->qc.rc; | 815 | rc = qe->qc.rc; |
825 | free_queue_entry (qe); | 816 | free_queue_entry(qe); |
826 | h->retry_time = GNUNET_TIME_UNIT_ZERO; | 817 | h->retry_time = GNUNET_TIME_UNIT_ZERO; |
827 | process_queue (h); | 818 | process_queue(h); |
828 | if (NULL != rc.proc) | 819 | if (NULL != rc.proc) |
829 | rc.proc (rc.proc_cls, | 820 | rc.proc(rc.proc_cls, |
830 | &dm->key, | 821 | &dm->key, |
831 | ntohl (dm->size), | 822 | ntohl(dm->size), |
832 | &dm[1], | 823 | &dm[1], |
833 | ntohl (dm->type), | 824 | ntohl(dm->type), |
834 | ntohl (dm->priority), | 825 | ntohl(dm->priority), |
835 | ntohl (dm->anonymity), | 826 | ntohl(dm->anonymity), |
836 | ntohl (dm->replication), | 827 | ntohl(dm->replication), |
837 | GNUNET_TIME_absolute_ntoh (dm->expiration), | 828 | GNUNET_TIME_absolute_ntoh(dm->expiration), |
838 | GNUNET_ntohll (dm->uid)); | 829 | GNUNET_ntohll(dm->uid)); |
839 | } | 830 | } |
840 | 831 | ||
841 | 832 | ||
@@ -847,37 +838,37 @@ handle_data (void *cls, | |||
847 | * @param msg message received | 838 | * @param msg message received |
848 | */ | 839 | */ |
849 | static void | 840 | static void |
850 | handle_data_end (void *cls, | 841 | handle_data_end(void *cls, |
851 | const struct GNUNET_MessageHeader *msg) | 842 | const struct GNUNET_MessageHeader *msg) |
852 | { | 843 | { |
853 | struct GNUNET_DATASTORE_Handle *h = cls; | 844 | struct GNUNET_DATASTORE_Handle *h = cls; |
854 | struct GNUNET_DATASTORE_QueueEntry *qe; | 845 | struct GNUNET_DATASTORE_QueueEntry *qe; |
855 | struct ResultContext rc; | 846 | struct ResultContext rc; |
856 | 847 | ||
857 | qe = get_queue_head (h, | 848 | qe = get_queue_head(h, |
858 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA); | 849 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA); |
859 | if (NULL == qe) | 850 | if (NULL == qe) |
860 | return; | 851 | return; |
861 | rc = qe->qc.rc; | 852 | rc = qe->qc.rc; |
862 | free_queue_entry (qe); | 853 | free_queue_entry(qe); |
863 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 854 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
864 | "Received end of result set, new queue size is %u\n", | 855 | "Received end of result set, new queue size is %u\n", |
865 | h->queue_size); | 856 | h->queue_size); |
866 | h->retry_time = GNUNET_TIME_UNIT_ZERO; | 857 | h->retry_time = GNUNET_TIME_UNIT_ZERO; |
867 | h->result_count = 0; | 858 | h->result_count = 0; |
868 | process_queue (h); | 859 | process_queue(h); |
869 | /* signal end of iteration */ | 860 | /* signal end of iteration */ |
870 | if (NULL != rc.proc) | 861 | if (NULL != rc.proc) |
871 | rc.proc (rc.proc_cls, | 862 | rc.proc(rc.proc_cls, |
872 | NULL, | 863 | NULL, |
873 | 0, | 864 | 0, |
874 | NULL, | 865 | NULL, |
875 | 0, | 866 | 0, |
876 | 0, | 867 | 0, |
877 | 0, | 868 | 0, |
878 | 0, | 869 | 0, |
879 | GNUNET_TIME_UNIT_ZERO_ABS, | 870 | GNUNET_TIME_UNIT_ZERO_ABS, |
880 | 0); | 871 | 0); |
881 | } | 872 | } |
882 | 873 | ||
883 | 874 | ||
@@ -887,42 +878,42 @@ handle_data_end (void *cls, | |||
887 | * @param cls the `struct GNUNET_DATASTORE_Handle` | 878 | * @param cls the `struct GNUNET_DATASTORE_Handle` |
888 | */ | 879 | */ |
889 | static void | 880 | static void |
890 | try_reconnect (void *cls) | 881 | try_reconnect(void *cls) |
891 | { | 882 | { |
892 | struct GNUNET_DATASTORE_Handle *h = cls; | 883 | struct GNUNET_DATASTORE_Handle *h = cls; |
893 | struct GNUNET_MQ_MessageHandler handlers[] = { | 884 | struct GNUNET_MQ_MessageHandler handlers[] = { |
894 | GNUNET_MQ_hd_var_size (status, | 885 | GNUNET_MQ_hd_var_size(status, |
895 | GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, | 886 | GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, |
896 | struct StatusMessage, | 887 | struct StatusMessage, |
897 | h), | 888 | h), |
898 | GNUNET_MQ_hd_var_size (data, | 889 | GNUNET_MQ_hd_var_size(data, |
899 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA, | 890 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA, |
900 | struct DataMessage, | 891 | struct DataMessage, |
901 | h), | 892 | h), |
902 | GNUNET_MQ_hd_fixed_size (data_end, | 893 | GNUNET_MQ_hd_fixed_size(data_end, |
903 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END, | 894 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END, |
904 | struct GNUNET_MessageHeader, | 895 | struct GNUNET_MessageHeader, |
905 | h), | 896 | h), |
906 | GNUNET_MQ_handler_end () | 897 | GNUNET_MQ_handler_end() |
907 | }; | 898 | }; |
908 | 899 | ||
909 | h->retry_time = GNUNET_TIME_STD_BACKOFF (h->retry_time); | 900 | h->retry_time = GNUNET_TIME_STD_BACKOFF(h->retry_time); |
910 | h->reconnect_task = NULL; | 901 | h->reconnect_task = NULL; |
911 | GNUNET_assert (NULL == h->mq); | 902 | GNUNET_assert(NULL == h->mq); |
912 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 903 | h->mq = GNUNET_CLIENT_connect(h->cfg, |
913 | "datastore", | 904 | "datastore", |
914 | handlers, | 905 | handlers, |
915 | &mq_error_handler, | 906 | &mq_error_handler, |
916 | h); | 907 | h); |
917 | if (NULL == h->mq) | 908 | if (NULL == h->mq) |
918 | return; | 909 | return; |
919 | GNUNET_STATISTICS_update (h->stats, | 910 | GNUNET_STATISTICS_update(h->stats, |
920 | gettext_noop ("# datastore connections (re)created"), | 911 | gettext_noop("# datastore connections (re)created"), |
921 | 1, | 912 | 1, |
922 | GNUNET_NO); | 913 | GNUNET_NO); |
923 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 914 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
924 | "Reconnected to DATASTORE\n"); | 915 | "Reconnected to DATASTORE\n"); |
925 | process_queue (h); | 916 | process_queue(h); |
926 | } | 917 | } |
927 | 918 | ||
928 | 919 | ||
@@ -935,10 +926,10 @@ try_reconnect (void *cls) | |||
935 | * @param emsg error message | 926 | * @param emsg error message |
936 | */ | 927 | */ |
937 | static void | 928 | static void |
938 | drop_status_cont (void *cls, | 929 | drop_status_cont(void *cls, |
939 | int32_t result, | 930 | int32_t result, |
940 | struct GNUNET_TIME_Absolute min_expiration, | 931 | struct GNUNET_TIME_Absolute min_expiration, |
941 | const char *emsg) | 932 | const char *emsg) |
942 | { | 933 | { |
943 | /* do nothing */ | 934 | /* do nothing */ |
944 | } | 935 | } |
@@ -970,71 +961,71 @@ drop_status_cont (void *cls, | |||
970 | * (or rather, will already have been invoked) | 961 | * (or rather, will already have been invoked) |
971 | */ | 962 | */ |
972 | struct GNUNET_DATASTORE_QueueEntry * | 963 | struct GNUNET_DATASTORE_QueueEntry * |
973 | GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, | 964 | GNUNET_DATASTORE_put(struct GNUNET_DATASTORE_Handle *h, |
974 | uint32_t rid, | 965 | uint32_t rid, |
975 | const struct GNUNET_HashCode *key, | 966 | const struct GNUNET_HashCode *key, |
976 | size_t size, | 967 | size_t size, |
977 | const void *data, | 968 | const void *data, |
978 | enum GNUNET_BLOCK_Type type, | 969 | enum GNUNET_BLOCK_Type type, |
979 | uint32_t priority, | 970 | uint32_t priority, |
980 | uint32_t anonymity, | 971 | uint32_t anonymity, |
981 | uint32_t replication, | 972 | uint32_t replication, |
982 | struct GNUNET_TIME_Absolute expiration, | 973 | struct GNUNET_TIME_Absolute expiration, |
983 | unsigned int queue_priority, | 974 | unsigned int queue_priority, |
984 | unsigned int max_queue_size, | 975 | unsigned int max_queue_size, |
985 | GNUNET_DATASTORE_ContinuationWithStatus cont, | 976 | GNUNET_DATASTORE_ContinuationWithStatus cont, |
986 | void *cont_cls) | 977 | void *cont_cls) |
987 | { | 978 | { |
988 | struct GNUNET_DATASTORE_QueueEntry *qe; | 979 | struct GNUNET_DATASTORE_QueueEntry *qe; |
989 | struct GNUNET_MQ_Envelope *env; | 980 | struct GNUNET_MQ_Envelope *env; |
990 | struct DataMessage *dm; | 981 | struct DataMessage *dm; |
991 | union QueueContext qc; | 982 | union QueueContext qc; |
992 | 983 | ||
993 | if (size + sizeof (*dm) >= GNUNET_MAX_MESSAGE_SIZE) | 984 | if (size + sizeof(*dm) >= GNUNET_MAX_MESSAGE_SIZE) |
994 | { | 985 | { |
995 | GNUNET_break (0); | 986 | GNUNET_break(0); |
996 | return NULL; | 987 | return NULL; |
997 | } | 988 | } |
998 | 989 | ||
999 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 990 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1000 | "Asked to put %u bytes of data under key `%s' for %s\n", | 991 | "Asked to put %u bytes of data under key `%s' for %s\n", |
1001 | size, | 992 | size, |
1002 | GNUNET_h2s (key), | 993 | GNUNET_h2s(key), |
1003 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration), | 994 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining(expiration), |
1004 | GNUNET_YES)); | 995 | GNUNET_YES)); |
1005 | env = GNUNET_MQ_msg_extra (dm, | 996 | env = GNUNET_MQ_msg_extra(dm, |
1006 | size, | 997 | size, |
1007 | GNUNET_MESSAGE_TYPE_DATASTORE_PUT); | 998 | GNUNET_MESSAGE_TYPE_DATASTORE_PUT); |
1008 | dm->rid = htonl (rid); | 999 | dm->rid = htonl(rid); |
1009 | dm->size = htonl ((uint32_t) size); | 1000 | dm->size = htonl((uint32_t)size); |
1010 | dm->type = htonl (type); | 1001 | dm->type = htonl(type); |
1011 | dm->priority = htonl (priority); | 1002 | dm->priority = htonl(priority); |
1012 | dm->anonymity = htonl (anonymity); | 1003 | dm->anonymity = htonl(anonymity); |
1013 | dm->replication = htonl (replication); | 1004 | dm->replication = htonl(replication); |
1014 | dm->expiration = GNUNET_TIME_absolute_hton (expiration); | 1005 | dm->expiration = GNUNET_TIME_absolute_hton(expiration); |
1015 | dm->key = *key; | 1006 | dm->key = *key; |
1016 | GNUNET_memcpy (&dm[1], | 1007 | GNUNET_memcpy(&dm[1], |
1017 | data, | 1008 | data, |
1018 | size); | 1009 | size); |
1019 | qc.sc.cont = cont; | 1010 | qc.sc.cont = cont; |
1020 | qc.sc.cont_cls = cont_cls; | 1011 | qc.sc.cont_cls = cont_cls; |
1021 | qe = make_queue_entry (h, | 1012 | qe = make_queue_entry(h, |
1022 | env, | 1013 | env, |
1023 | queue_priority, | 1014 | queue_priority, |
1024 | max_queue_size, | 1015 | max_queue_size, |
1025 | GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, | 1016 | GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, |
1026 | &qc); | 1017 | &qc); |
1027 | if (NULL == qe) | 1018 | if (NULL == qe) |
1028 | { | 1019 | { |
1029 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1020 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1030 | "Could not create queue entry for PUT\n"); | 1021 | "Could not create queue entry for PUT\n"); |
1031 | return NULL; | 1022 | return NULL; |
1032 | } | 1023 | } |
1033 | GNUNET_STATISTICS_update (h->stats, | 1024 | GNUNET_STATISTICS_update(h->stats, |
1034 | gettext_noop ("# PUT requests executed"), | 1025 | gettext_noop("# PUT requests executed"), |
1035 | 1, | 1026 | 1, |
1036 | GNUNET_NO); | 1027 | GNUNET_NO); |
1037 | process_queue (h); | 1028 | process_queue(h); |
1038 | return qe; | 1029 | return qe; |
1039 | } | 1030 | } |
1040 | 1031 | ||
@@ -1055,11 +1046,11 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, | |||
1055 | * (or rather, will already have been invoked) | 1046 | * (or rather, will already have been invoked) |
1056 | */ | 1047 | */ |
1057 | struct GNUNET_DATASTORE_QueueEntry * | 1048 | struct GNUNET_DATASTORE_QueueEntry * |
1058 | GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, | 1049 | GNUNET_DATASTORE_reserve(struct GNUNET_DATASTORE_Handle *h, |
1059 | uint64_t amount, | 1050 | uint64_t amount, |
1060 | uint32_t entries, | 1051 | uint32_t entries, |
1061 | GNUNET_DATASTORE_ContinuationWithStatus cont, | 1052 | GNUNET_DATASTORE_ContinuationWithStatus cont, |
1062 | void *cont_cls) | 1053 | void *cont_cls) |
1063 | { | 1054 | { |
1064 | struct GNUNET_DATASTORE_QueueEntry *qe; | 1055 | struct GNUNET_DATASTORE_QueueEntry *qe; |
1065 | struct GNUNET_MQ_Envelope *env; | 1056 | struct GNUNET_MQ_Envelope *env; |
@@ -1068,34 +1059,34 @@ GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, | |||
1068 | 1059 | ||
1069 | if (NULL == cont) | 1060 | if (NULL == cont) |
1070 | cont = &drop_status_cont; | 1061 | cont = &drop_status_cont; |
1071 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1062 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1072 | "Asked to reserve %llu bytes of data and %u entries\n", | 1063 | "Asked to reserve %llu bytes of data and %u entries\n", |
1073 | (unsigned long long) amount, | 1064 | (unsigned long long)amount, |
1074 | (unsigned int) entries); | 1065 | (unsigned int)entries); |
1075 | env = GNUNET_MQ_msg (rm, | 1066 | env = GNUNET_MQ_msg(rm, |
1076 | GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE); | 1067 | GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE); |
1077 | rm->entries = htonl (entries); | 1068 | rm->entries = htonl(entries); |
1078 | rm->amount = GNUNET_htonll (amount); | 1069 | rm->amount = GNUNET_htonll(amount); |
1079 | 1070 | ||
1080 | qc.sc.cont = cont; | 1071 | qc.sc.cont = cont; |
1081 | qc.sc.cont_cls = cont_cls; | 1072 | qc.sc.cont_cls = cont_cls; |
1082 | qe = make_queue_entry (h, | 1073 | qe = make_queue_entry(h, |
1083 | env, | 1074 | env, |
1084 | UINT_MAX, | 1075 | UINT_MAX, |
1085 | UINT_MAX, | 1076 | UINT_MAX, |
1086 | GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, | 1077 | GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, |
1087 | &qc); | 1078 | &qc); |
1088 | if (NULL == qe) | 1079 | if (NULL == qe) |
1089 | { | 1080 | { |
1090 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1081 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1091 | "Could not create queue entry to reserve\n"); | 1082 | "Could not create queue entry to reserve\n"); |
1092 | return NULL; | 1083 | return NULL; |
1093 | } | 1084 | } |
1094 | GNUNET_STATISTICS_update (h->stats, | 1085 | GNUNET_STATISTICS_update(h->stats, |
1095 | gettext_noop ("# RESERVE requests executed"), | 1086 | gettext_noop("# RESERVE requests executed"), |
1096 | 1, | 1087 | 1, |
1097 | GNUNET_NO); | 1088 | GNUNET_NO); |
1098 | process_queue (h); | 1089 | process_queue(h); |
1099 | return qe; | 1090 | return qe; |
1100 | } | 1091 | } |
1101 | 1092 | ||
@@ -1121,12 +1112,12 @@ GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, | |||
1121 | * (or rather, will already have been invoked) | 1112 | * (or rather, will already have been invoked) |
1122 | */ | 1113 | */ |
1123 | struct GNUNET_DATASTORE_QueueEntry * | 1114 | struct GNUNET_DATASTORE_QueueEntry * |
1124 | GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h, | 1115 | GNUNET_DATASTORE_release_reserve(struct GNUNET_DATASTORE_Handle *h, |
1125 | uint32_t rid, | 1116 | uint32_t rid, |
1126 | unsigned int queue_priority, | 1117 | unsigned int queue_priority, |
1127 | unsigned int max_queue_size, | 1118 | unsigned int max_queue_size, |
1128 | GNUNET_DATASTORE_ContinuationWithStatus cont, | 1119 | GNUNET_DATASTORE_ContinuationWithStatus cont, |
1129 | void *cont_cls) | 1120 | void *cont_cls) |
1130 | { | 1121 | { |
1131 | struct GNUNET_DATASTORE_QueueEntry *qe; | 1122 | struct GNUNET_DATASTORE_QueueEntry *qe; |
1132 | struct GNUNET_MQ_Envelope *env; | 1123 | struct GNUNET_MQ_Envelope *env; |
@@ -1135,31 +1126,31 @@ GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h, | |||
1135 | 1126 | ||
1136 | if (NULL == cont) | 1127 | if (NULL == cont) |
1137 | cont = &drop_status_cont; | 1128 | cont = &drop_status_cont; |
1138 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1129 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1139 | "Asked to release reserve %d\n", | 1130 | "Asked to release reserve %d\n", |
1140 | rid); | 1131 | rid); |
1141 | env = GNUNET_MQ_msg (rrm, | 1132 | env = GNUNET_MQ_msg(rrm, |
1142 | GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE); | 1133 | GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE); |
1143 | rrm->rid = htonl (rid); | 1134 | rrm->rid = htonl(rid); |
1144 | qc.sc.cont = cont; | 1135 | qc.sc.cont = cont; |
1145 | qc.sc.cont_cls = cont_cls; | 1136 | qc.sc.cont_cls = cont_cls; |
1146 | qe = make_queue_entry (h, | 1137 | qe = make_queue_entry(h, |
1147 | env, | 1138 | env, |
1148 | queue_priority, | 1139 | queue_priority, |
1149 | max_queue_size, | 1140 | max_queue_size, |
1150 | GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, | 1141 | GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, |
1151 | &qc); | 1142 | &qc); |
1152 | if (NULL == qe) | 1143 | if (NULL == qe) |
1153 | { | 1144 | { |
1154 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1145 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1155 | "Could not create queue entry to release reserve\n"); | 1146 | "Could not create queue entry to release reserve\n"); |
1156 | return NULL; | 1147 | return NULL; |
1157 | } | 1148 | } |
1158 | GNUNET_STATISTICS_update (h->stats, | 1149 | GNUNET_STATISTICS_update(h->stats, |
1159 | gettext_noop | 1150 | gettext_noop |
1160 | ("# RELEASE RESERVE requests executed"), 1, | 1151 | ("# RELEASE RESERVE requests executed"), 1, |
1161 | GNUNET_NO); | 1152 | GNUNET_NO); |
1162 | process_queue (h); | 1153 | process_queue(h); |
1163 | return qe; | 1154 | return qe; |
1164 | } | 1155 | } |
1165 | 1156 | ||
@@ -1185,60 +1176,60 @@ GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h, | |||
1185 | * (or rather, will already have been invoked) | 1176 | * (or rather, will already have been invoked) |
1186 | */ | 1177 | */ |
1187 | struct GNUNET_DATASTORE_QueueEntry * | 1178 | struct GNUNET_DATASTORE_QueueEntry * |
1188 | GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, | 1179 | GNUNET_DATASTORE_remove(struct GNUNET_DATASTORE_Handle *h, |
1189 | const struct GNUNET_HashCode *key, | 1180 | const struct GNUNET_HashCode *key, |
1190 | size_t size, | 1181 | size_t size, |
1191 | const void *data, | 1182 | const void *data, |
1192 | unsigned int queue_priority, | 1183 | unsigned int queue_priority, |
1193 | unsigned int max_queue_size, | 1184 | unsigned int max_queue_size, |
1194 | GNUNET_DATASTORE_ContinuationWithStatus cont, | 1185 | GNUNET_DATASTORE_ContinuationWithStatus cont, |
1195 | void *cont_cls) | 1186 | void *cont_cls) |
1196 | { | 1187 | { |
1197 | struct GNUNET_DATASTORE_QueueEntry *qe; | 1188 | struct GNUNET_DATASTORE_QueueEntry *qe; |
1198 | struct DataMessage *dm; | 1189 | struct DataMessage *dm; |
1199 | struct GNUNET_MQ_Envelope *env; | 1190 | struct GNUNET_MQ_Envelope *env; |
1200 | union QueueContext qc; | 1191 | union QueueContext qc; |
1201 | 1192 | ||
1202 | if (sizeof (*dm) + size >= GNUNET_MAX_MESSAGE_SIZE) | 1193 | if (sizeof(*dm) + size >= GNUNET_MAX_MESSAGE_SIZE) |
1203 | { | 1194 | { |
1204 | GNUNET_break (0); | 1195 | GNUNET_break(0); |
1205 | return NULL; | 1196 | return NULL; |
1206 | } | 1197 | } |
1207 | if (NULL == cont) | 1198 | if (NULL == cont) |
1208 | cont = &drop_status_cont; | 1199 | cont = &drop_status_cont; |
1209 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1200 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1210 | "Asked to remove %u bytes under key `%s'\n", | 1201 | "Asked to remove %u bytes under key `%s'\n", |
1211 | size, | 1202 | size, |
1212 | GNUNET_h2s (key)); | 1203 | GNUNET_h2s(key)); |
1213 | env = GNUNET_MQ_msg_extra (dm, | 1204 | env = GNUNET_MQ_msg_extra(dm, |
1214 | size, | 1205 | size, |
1215 | GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE); | 1206 | GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE); |
1216 | dm->size = htonl (size); | 1207 | dm->size = htonl(size); |
1217 | dm->key = *key; | 1208 | dm->key = *key; |
1218 | GNUNET_memcpy (&dm[1], | 1209 | GNUNET_memcpy(&dm[1], |
1219 | data, | 1210 | data, |
1220 | size); | 1211 | size); |
1221 | 1212 | ||
1222 | qc.sc.cont = cont; | 1213 | qc.sc.cont = cont; |
1223 | qc.sc.cont_cls = cont_cls; | 1214 | qc.sc.cont_cls = cont_cls; |
1224 | 1215 | ||
1225 | qe = make_queue_entry (h, | 1216 | qe = make_queue_entry(h, |
1226 | env, | 1217 | env, |
1227 | queue_priority, | 1218 | queue_priority, |
1228 | max_queue_size, | 1219 | max_queue_size, |
1229 | GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, | 1220 | GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, |
1230 | &qc); | 1221 | &qc); |
1231 | if (NULL == qe) | 1222 | if (NULL == qe) |
1232 | { | 1223 | { |
1233 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1224 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1234 | "Could not create queue entry for REMOVE\n"); | 1225 | "Could not create queue entry for REMOVE\n"); |
1235 | return NULL; | 1226 | return NULL; |
1236 | } | 1227 | } |
1237 | GNUNET_STATISTICS_update (h->stats, | 1228 | GNUNET_STATISTICS_update(h->stats, |
1238 | gettext_noop ("# REMOVE requests executed"), | 1229 | gettext_noop("# REMOVE requests executed"), |
1239 | 1, | 1230 | 1, |
1240 | GNUNET_NO); | 1231 | GNUNET_NO); |
1241 | process_queue (h); | 1232 | process_queue(h); |
1242 | return qe; | 1233 | return qe; |
1243 | } | 1234 | } |
1244 | 1235 | ||
@@ -1263,41 +1254,41 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, | |||
1263 | * cancel | 1254 | * cancel |
1264 | */ | 1255 | */ |
1265 | struct GNUNET_DATASTORE_QueueEntry * | 1256 | struct GNUNET_DATASTORE_QueueEntry * |
1266 | GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h, | 1257 | GNUNET_DATASTORE_get_for_replication(struct GNUNET_DATASTORE_Handle *h, |
1267 | unsigned int queue_priority, | 1258 | unsigned int queue_priority, |
1268 | unsigned int max_queue_size, | 1259 | unsigned int max_queue_size, |
1269 | GNUNET_DATASTORE_DatumProcessor proc, | 1260 | GNUNET_DATASTORE_DatumProcessor proc, |
1270 | void *proc_cls) | 1261 | void *proc_cls) |
1271 | { | 1262 | { |
1272 | struct GNUNET_DATASTORE_QueueEntry *qe; | 1263 | struct GNUNET_DATASTORE_QueueEntry *qe; |
1273 | struct GNUNET_MQ_Envelope *env; | 1264 | struct GNUNET_MQ_Envelope *env; |
1274 | struct GNUNET_MessageHeader *m; | 1265 | struct GNUNET_MessageHeader *m; |
1275 | union QueueContext qc; | 1266 | union QueueContext qc; |
1276 | 1267 | ||
1277 | GNUNET_assert (NULL != proc); | 1268 | GNUNET_assert(NULL != proc); |
1278 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1269 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1279 | "Asked to get replication entry\n"); | 1270 | "Asked to get replication entry\n"); |
1280 | env = GNUNET_MQ_msg (m, | 1271 | env = GNUNET_MQ_msg(m, |
1281 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION); | 1272 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION); |
1282 | qc.rc.proc = proc; | 1273 | qc.rc.proc = proc; |
1283 | qc.rc.proc_cls = proc_cls; | 1274 | qc.rc.proc_cls = proc_cls; |
1284 | qe = make_queue_entry (h, | 1275 | qe = make_queue_entry(h, |
1285 | env, | 1276 | env, |
1286 | queue_priority, | 1277 | queue_priority, |
1287 | max_queue_size, | 1278 | max_queue_size, |
1288 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA, | 1279 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA, |
1289 | &qc); | 1280 | &qc); |
1290 | if (NULL == qe) | 1281 | if (NULL == qe) |
1291 | { | 1282 | { |
1292 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1283 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1293 | "Could not create queue entry for GET REPLICATION\n"); | 1284 | "Could not create queue entry for GET REPLICATION\n"); |
1294 | return NULL; | 1285 | return NULL; |
1295 | } | 1286 | } |
1296 | GNUNET_STATISTICS_update (h->stats, | 1287 | GNUNET_STATISTICS_update(h->stats, |
1297 | gettext_noop | 1288 | gettext_noop |
1298 | ("# GET REPLICATION requests executed"), 1, | 1289 | ("# GET REPLICATION requests executed"), 1, |
1299 | GNUNET_NO); | 1290 | GNUNET_NO); |
1300 | process_queue (h); | 1291 | process_queue(h); |
1301 | return qe; | 1292 | return qe; |
1302 | } | 1293 | } |
1303 | 1294 | ||
@@ -1319,47 +1310,47 @@ GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h, | |||
1319 | * cancel | 1310 | * cancel |
1320 | */ | 1311 | */ |
1321 | struct GNUNET_DATASTORE_QueueEntry * | 1312 | struct GNUNET_DATASTORE_QueueEntry * |
1322 | GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h, | 1313 | GNUNET_DATASTORE_get_zero_anonymity(struct GNUNET_DATASTORE_Handle *h, |
1323 | uint64_t next_uid, | 1314 | uint64_t next_uid, |
1324 | unsigned int queue_priority, | 1315 | unsigned int queue_priority, |
1325 | unsigned int max_queue_size, | 1316 | unsigned int max_queue_size, |
1326 | enum GNUNET_BLOCK_Type type, | 1317 | enum GNUNET_BLOCK_Type type, |
1327 | GNUNET_DATASTORE_DatumProcessor proc, | 1318 | GNUNET_DATASTORE_DatumProcessor proc, |
1328 | void *proc_cls) | 1319 | void *proc_cls) |
1329 | { | 1320 | { |
1330 | struct GNUNET_DATASTORE_QueueEntry *qe; | 1321 | struct GNUNET_DATASTORE_QueueEntry *qe; |
1331 | struct GNUNET_MQ_Envelope *env; | 1322 | struct GNUNET_MQ_Envelope *env; |
1332 | struct GetZeroAnonymityMessage *m; | 1323 | struct GetZeroAnonymityMessage *m; |
1333 | union QueueContext qc; | 1324 | union QueueContext qc; |
1334 | 1325 | ||
1335 | GNUNET_assert (NULL != proc); | 1326 | GNUNET_assert(NULL != proc); |
1336 | GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY); | 1327 | GNUNET_assert(type != GNUNET_BLOCK_TYPE_ANY); |
1337 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1328 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1338 | "Asked to get a zero-anonymity entry of type %d\n", | 1329 | "Asked to get a zero-anonymity entry of type %d\n", |
1339 | type); | 1330 | type); |
1340 | env = GNUNET_MQ_msg (m, | 1331 | env = GNUNET_MQ_msg(m, |
1341 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY); | 1332 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY); |
1342 | m->type = htonl ((uint32_t) type); | 1333 | m->type = htonl((uint32_t)type); |
1343 | m->next_uid = GNUNET_htonll (next_uid); | 1334 | m->next_uid = GNUNET_htonll(next_uid); |
1344 | qc.rc.proc = proc; | 1335 | qc.rc.proc = proc; |
1345 | qc.rc.proc_cls = proc_cls; | 1336 | qc.rc.proc_cls = proc_cls; |
1346 | qe = make_queue_entry (h, | 1337 | qe = make_queue_entry(h, |
1347 | env, | 1338 | env, |
1348 | queue_priority, | 1339 | queue_priority, |
1349 | max_queue_size, | 1340 | max_queue_size, |
1350 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA, | 1341 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA, |
1351 | &qc); | 1342 | &qc); |
1352 | if (NULL == qe) | 1343 | if (NULL == qe) |
1353 | { | 1344 | { |
1354 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1345 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1355 | "Could not create queue entry for zero-anonymity procation\n"); | 1346 | "Could not create queue entry for zero-anonymity procation\n"); |
1356 | return NULL; | 1347 | return NULL; |
1357 | } | 1348 | } |
1358 | GNUNET_STATISTICS_update (h->stats, | 1349 | GNUNET_STATISTICS_update(h->stats, |
1359 | gettext_noop | 1350 | gettext_noop |
1360 | ("# GET ZERO ANONYMITY requests executed"), 1, | 1351 | ("# GET ZERO ANONYMITY requests executed"), 1, |
1361 | GNUNET_NO); | 1352 | GNUNET_NO); |
1362 | process_queue (h); | 1353 | process_queue(h); |
1363 | return qe; | 1354 | return qe; |
1364 | } | 1355 | } |
1365 | 1356 | ||
@@ -1383,15 +1374,15 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h, | |||
1383 | * cancel | 1374 | * cancel |
1384 | */ | 1375 | */ |
1385 | struct GNUNET_DATASTORE_QueueEntry * | 1376 | struct GNUNET_DATASTORE_QueueEntry * |
1386 | GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, | 1377 | GNUNET_DATASTORE_get_key(struct GNUNET_DATASTORE_Handle *h, |
1387 | uint64_t next_uid, | 1378 | uint64_t next_uid, |
1388 | bool random, | 1379 | bool random, |
1389 | const struct GNUNET_HashCode *key, | 1380 | const struct GNUNET_HashCode *key, |
1390 | enum GNUNET_BLOCK_Type type, | 1381 | enum GNUNET_BLOCK_Type type, |
1391 | unsigned int queue_priority, | 1382 | unsigned int queue_priority, |
1392 | unsigned int max_queue_size, | 1383 | unsigned int max_queue_size, |
1393 | GNUNET_DATASTORE_DatumProcessor proc, | 1384 | GNUNET_DATASTORE_DatumProcessor proc, |
1394 | void *proc_cls) | 1385 | void *proc_cls) |
1395 | { | 1386 | { |
1396 | struct GNUNET_DATASTORE_QueueEntry *qe; | 1387 | struct GNUNET_DATASTORE_QueueEntry *qe; |
1397 | struct GNUNET_MQ_Envelope *env; | 1388 | struct GNUNET_MQ_Envelope *env; |
@@ -1399,50 +1390,50 @@ GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, | |||
1399 | struct GetMessage *gm; | 1390 | struct GetMessage *gm; |
1400 | union QueueContext qc; | 1391 | union QueueContext qc; |
1401 | 1392 | ||
1402 | GNUNET_assert (NULL != proc); | 1393 | GNUNET_assert(NULL != proc); |
1403 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1394 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1404 | "Asked to look for data of type %u under key `%s'\n", | 1395 | "Asked to look for data of type %u under key `%s'\n", |
1405 | (unsigned int) type, | 1396 | (unsigned int)type, |
1406 | GNUNET_h2s (key)); | 1397 | GNUNET_h2s(key)); |
1407 | if (NULL == key) | 1398 | if (NULL == key) |
1408 | { | 1399 | { |
1409 | env = GNUNET_MQ_msg (gm, | 1400 | env = GNUNET_MQ_msg(gm, |
1410 | GNUNET_MESSAGE_TYPE_DATASTORE_GET); | 1401 | GNUNET_MESSAGE_TYPE_DATASTORE_GET); |
1411 | gm->type = htonl (type); | 1402 | gm->type = htonl(type); |
1412 | gm->next_uid = GNUNET_htonll (next_uid); | 1403 | gm->next_uid = GNUNET_htonll(next_uid); |
1413 | gm->random = random; | 1404 | gm->random = random; |
1414 | } | 1405 | } |
1415 | else | 1406 | else |
1416 | { | 1407 | { |
1417 | env = GNUNET_MQ_msg (gkm, | 1408 | env = GNUNET_MQ_msg(gkm, |
1418 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY); | 1409 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY); |
1419 | gkm->type = htonl (type); | 1410 | gkm->type = htonl(type); |
1420 | gkm->next_uid = GNUNET_htonll (next_uid); | 1411 | gkm->next_uid = GNUNET_htonll(next_uid); |
1421 | gkm->random = random; | 1412 | gkm->random = random; |
1422 | gkm->key = *key; | 1413 | gkm->key = *key; |
1423 | } | 1414 | } |
1424 | qc.rc.proc = proc; | 1415 | qc.rc.proc = proc; |
1425 | qc.rc.proc_cls = proc_cls; | 1416 | qc.rc.proc_cls = proc_cls; |
1426 | qe = make_queue_entry (h, | 1417 | qe = make_queue_entry(h, |
1427 | env, | 1418 | env, |
1428 | queue_priority, | 1419 | queue_priority, |
1429 | max_queue_size, | 1420 | max_queue_size, |
1430 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA, | 1421 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA, |
1431 | &qc); | 1422 | &qc); |
1432 | if (NULL == qe) | 1423 | if (NULL == qe) |
1433 | { | 1424 | { |
1434 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1425 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1435 | "Could not queue request for `%s'\n", | 1426 | "Could not queue request for `%s'\n", |
1436 | GNUNET_h2s (key)); | 1427 | GNUNET_h2s(key)); |
1437 | return NULL; | 1428 | return NULL; |
1438 | } | 1429 | } |
1439 | #if INSANE_STATISTICS | 1430 | #if INSANE_STATISTICS |
1440 | GNUNET_STATISTICS_update (h->stats, | 1431 | GNUNET_STATISTICS_update(h->stats, |
1441 | gettext_noop ("# GET requests executed"), | 1432 | gettext_noop("# GET requests executed"), |
1442 | 1, | 1433 | 1, |
1443 | GNUNET_NO); | 1434 | GNUNET_NO); |
1444 | #endif | 1435 | #endif |
1445 | process_queue (h); | 1436 | process_queue(h); |
1446 | return qe; | 1437 | return qe; |
1447 | } | 1438 | } |
1448 | 1439 | ||
@@ -1454,23 +1445,23 @@ GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, | |||
1454 | * @param qe operation to cancel | 1445 | * @param qe operation to cancel |
1455 | */ | 1446 | */ |
1456 | void | 1447 | void |
1457 | GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe) | 1448 | GNUNET_DATASTORE_cancel(struct GNUNET_DATASTORE_QueueEntry *qe) |
1458 | { | 1449 | { |
1459 | struct GNUNET_DATASTORE_Handle *h = qe->h; | 1450 | struct GNUNET_DATASTORE_Handle *h = qe->h; |
1460 | 1451 | ||
1461 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1452 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1462 | "Pending DATASTORE request %p cancelled (%d, %d)\n", | 1453 | "Pending DATASTORE request %p cancelled (%d, %d)\n", |
1463 | qe, | 1454 | qe, |
1464 | NULL == qe->env, | 1455 | NULL == qe->env, |
1465 | h->queue_head == qe); | 1456 | h->queue_head == qe); |
1466 | if (NULL == qe->env) | 1457 | if (NULL == qe->env) |
1467 | { | 1458 | { |
1468 | free_queue_entry (qe); | 1459 | free_queue_entry(qe); |
1469 | h->skip_next_messages++; | 1460 | h->skip_next_messages++; |
1470 | return; | 1461 | return; |
1471 | } | 1462 | } |
1472 | free_queue_entry (qe); | 1463 | free_queue_entry(qe); |
1473 | process_queue (h); | 1464 | process_queue(h); |
1474 | } | 1465 | } |
1475 | 1466 | ||
1476 | 1467 | ||
diff --git a/src/datastore/gnunet-datastore.c b/src/datastore/gnunet-datastore.c index 4cf318777..46a0b2358 100644 --- a/src/datastore/gnunet-datastore.c +++ b/src/datastore/gnunet-datastore.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file datastore/gnunet-datastore.c | 22 | * @file datastore/gnunet-datastore.c |
@@ -30,8 +30,7 @@ | |||
30 | 30 | ||
31 | GNUNET_NETWORK_STRUCT_BEGIN | 31 | GNUNET_NETWORK_STRUCT_BEGIN |
32 | 32 | ||
33 | struct DataRecord | 33 | struct DataRecord { |
34 | { | ||
35 | /** | 34 | /** |
36 | * Number of bytes in the item (NBO). | 35 | * Number of bytes in the item (NBO). |
37 | */ | 36 | */ |
@@ -122,14 +121,14 @@ static uint64_t record_count; | |||
122 | 121 | ||
123 | 122 | ||
124 | static void | 123 | static void |
125 | do_shutdown (void *cls) | 124 | do_shutdown(void *cls) |
126 | { | 125 | { |
127 | if (NULL != qe) | 126 | if (NULL != qe) |
128 | GNUNET_DATASTORE_cancel (qe); | 127 | GNUNET_DATASTORE_cancel(qe); |
129 | if (NULL != datastore) | 128 | if (NULL != datastore) |
130 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_NO); | 129 | GNUNET_DATASTORE_disconnect(datastore, GNUNET_NO); |
131 | if (NULL != file_handle) | 130 | if (NULL != file_handle) |
132 | GNUNET_DISK_file_close (file_handle); | 131 | GNUNET_DISK_file_close(file_handle); |
133 | } | 132 | } |
134 | 133 | ||
135 | 134 | ||
@@ -137,21 +136,21 @@ do_shutdown (void *cls) | |||
137 | * Begin dumping the database. | 136 | * Begin dumping the database. |
138 | */ | 137 | */ |
139 | static void | 138 | static void |
140 | start_dump (void); | 139 | start_dump(void); |
141 | 140 | ||
142 | 141 | ||
143 | /** | 142 | /** |
144 | * Begin inserting into the database. | 143 | * Begin inserting into the database. |
145 | */ | 144 | */ |
146 | static void | 145 | static void |
147 | start_insert (void); | 146 | start_insert(void); |
148 | 147 | ||
149 | 148 | ||
150 | /** | 149 | /** |
151 | * Perform next GET operation. | 150 | * Perform next GET operation. |
152 | */ | 151 | */ |
153 | static void | 152 | static void |
154 | do_get (const uint64_t next_uid); | 153 | do_get(const uint64_t next_uid); |
155 | 154 | ||
156 | 155 | ||
157 | /** | 156 | /** |
@@ -170,69 +169,69 @@ do_get (const uint64_t next_uid); | |||
170 | * maybe 0 if no unique identifier is available | 169 | * maybe 0 if no unique identifier is available |
171 | */ | 170 | */ |
172 | static void | 171 | static void |
173 | get_cb (void *cls, | 172 | get_cb(void *cls, |
174 | const struct GNUNET_HashCode *key, | 173 | const struct GNUNET_HashCode *key, |
175 | size_t size, | 174 | size_t size, |
176 | const void *data, | 175 | const void *data, |
177 | enum GNUNET_BLOCK_Type type, | 176 | enum GNUNET_BLOCK_Type type, |
178 | uint32_t priority, | 177 | uint32_t priority, |
179 | uint32_t anonymity, | 178 | uint32_t anonymity, |
180 | uint32_t replication, | 179 | uint32_t replication, |
181 | struct GNUNET_TIME_Absolute expiration, | 180 | struct GNUNET_TIME_Absolute expiration, |
182 | uint64_t uid) | 181 | uint64_t uid) |
183 | { | 182 | { |
184 | qe = NULL; | 183 | qe = NULL; |
185 | if (NULL == key) | 184 | if (NULL == key) |
186 | { | ||
187 | fprintf (stderr, _ ("Dumped %" PRIu64 " records\n"), record_count); | ||
188 | GNUNET_DISK_file_close (file_handle); | ||
189 | file_handle = NULL; | ||
190 | if (insert) | ||
191 | start_insert (); | ||
192 | else | ||
193 | { | 185 | { |
194 | ret = 0; | 186 | fprintf(stderr, _("Dumped %" PRIu64 " records\n"), record_count); |
195 | GNUNET_SCHEDULER_shutdown (); | 187 | GNUNET_DISK_file_close(file_handle); |
188 | file_handle = NULL; | ||
189 | if (insert) | ||
190 | start_insert(); | ||
191 | else | ||
192 | { | ||
193 | ret = 0; | ||
194 | GNUNET_SCHEDULER_shutdown(); | ||
195 | } | ||
196 | return; | ||
196 | } | 197 | } |
197 | return; | ||
198 | } | ||
199 | 198 | ||
200 | struct DataRecord dr; | 199 | struct DataRecord dr; |
201 | dr.size = htonl ((uint32_t) size); | 200 | dr.size = htonl((uint32_t)size); |
202 | dr.type = htonl (type); | 201 | dr.type = htonl(type); |
203 | dr.priority = htonl (priority); | 202 | dr.priority = htonl(priority); |
204 | dr.anonymity = htonl (anonymity); | 203 | dr.anonymity = htonl(anonymity); |
205 | dr.replication = htonl (replication); | 204 | dr.replication = htonl(replication); |
206 | dr.expiration = GNUNET_TIME_absolute_hton (expiration); | 205 | dr.expiration = GNUNET_TIME_absolute_hton(expiration); |
207 | dr.key = *key; | 206 | dr.key = *key; |
208 | 207 | ||
209 | ssize_t len; | 208 | ssize_t len; |
210 | len = GNUNET_DISK_file_write (file_handle, &dr, sizeof (dr)); | 209 | len = GNUNET_DISK_file_write(file_handle, &dr, sizeof(dr)); |
211 | if (sizeof (dr) != len) | 210 | if (sizeof(dr) != len) |
212 | { | 211 | { |
213 | fprintf (stderr, | 212 | fprintf(stderr, |
214 | _ ("Short write to file: %zd bytes expecting %zd\n"), | 213 | _("Short write to file: %zd bytes expecting %zd\n"), |
215 | len, | 214 | len, |
216 | sizeof (dr)); | 215 | sizeof(dr)); |
217 | ret = 1; | 216 | ret = 1; |
218 | GNUNET_SCHEDULER_shutdown (); | 217 | GNUNET_SCHEDULER_shutdown(); |
219 | return; | 218 | return; |
220 | } | 219 | } |
221 | 220 | ||
222 | len = GNUNET_DISK_file_write (file_handle, data, size); | 221 | len = GNUNET_DISK_file_write(file_handle, data, size); |
223 | if (size != len) | 222 | if (size != len) |
224 | { | 223 | { |
225 | fprintf (stderr, | 224 | fprintf(stderr, |
226 | _ ("Short write to file: %zd bytes expecting %zd\n"), | 225 | _("Short write to file: %zd bytes expecting %zd\n"), |
227 | len, | 226 | len, |
228 | size); | 227 | size); |
229 | ret = 1; | 228 | ret = 1; |
230 | GNUNET_SCHEDULER_shutdown (); | 229 | GNUNET_SCHEDULER_shutdown(); |
231 | return; | 230 | return; |
232 | } | 231 | } |
233 | 232 | ||
234 | record_count++; | 233 | record_count++; |
235 | do_get (uid + 1); | 234 | do_get(uid + 1); |
236 | } | 235 | } |
237 | 236 | ||
238 | 237 | ||
@@ -240,24 +239,24 @@ get_cb (void *cls, | |||
240 | * Perform next GET operation. | 239 | * Perform next GET operation. |
241 | */ | 240 | */ |
242 | static void | 241 | static void |
243 | do_get (const uint64_t next_uid) | 242 | do_get(const uint64_t next_uid) |
244 | { | 243 | { |
245 | GNUNET_assert (NULL == qe); | 244 | GNUNET_assert(NULL == qe); |
246 | qe = GNUNET_DATASTORE_get_key (datastore, | 245 | qe = GNUNET_DATASTORE_get_key(datastore, |
247 | next_uid, | 246 | next_uid, |
248 | false /* random */, | 247 | false /* random */, |
249 | NULL /* key */, | 248 | NULL /* key */, |
250 | GNUNET_BLOCK_TYPE_ANY, | 249 | GNUNET_BLOCK_TYPE_ANY, |
251 | 0 /* queue_priority */, | 250 | 0 /* queue_priority */, |
252 | 1 /* max_queue_size */, | 251 | 1 /* max_queue_size */, |
253 | &get_cb, | 252 | &get_cb, |
254 | NULL /* proc_cls */); | 253 | NULL /* proc_cls */); |
255 | if (NULL == qe) | 254 | if (NULL == qe) |
256 | { | 255 | { |
257 | fprintf (stderr, _ ("Error queueing datastore GET operation\n")); | 256 | fprintf(stderr, _("Error queueing datastore GET operation\n")); |
258 | ret = 1; | 257 | ret = 1; |
259 | GNUNET_SCHEDULER_shutdown (); | 258 | GNUNET_SCHEDULER_shutdown(); |
260 | } | 259 | } |
261 | } | 260 | } |
262 | 261 | ||
263 | 262 | ||
@@ -265,32 +264,32 @@ do_get (const uint64_t next_uid) | |||
265 | * Begin dumping the database. | 264 | * Begin dumping the database. |
266 | */ | 265 | */ |
267 | static void | 266 | static void |
268 | start_dump () | 267 | start_dump() |
269 | { | 268 | { |
270 | record_count = 0; | 269 | record_count = 0; |
271 | 270 | ||
272 | if (NULL != file_name) | 271 | if (NULL != file_name) |
273 | { | ||
274 | file_handle = GNUNET_DISK_file_open (file_name, | ||
275 | GNUNET_DISK_OPEN_WRITE | | ||
276 | GNUNET_DISK_OPEN_TRUNCATE | | ||
277 | GNUNET_DISK_OPEN_CREATE, | ||
278 | GNUNET_DISK_PERM_USER_READ | | ||
279 | GNUNET_DISK_PERM_USER_WRITE); | ||
280 | if (NULL == file_handle) | ||
281 | { | 272 | { |
282 | fprintf (stderr, _ ("Unable to open dump file: %s\n"), file_name); | 273 | file_handle = GNUNET_DISK_file_open(file_name, |
283 | ret = 1; | 274 | GNUNET_DISK_OPEN_WRITE | |
284 | GNUNET_SCHEDULER_shutdown (); | 275 | GNUNET_DISK_OPEN_TRUNCATE | |
285 | return; | 276 | GNUNET_DISK_OPEN_CREATE, |
277 | GNUNET_DISK_PERM_USER_READ | | ||
278 | GNUNET_DISK_PERM_USER_WRITE); | ||
279 | if (NULL == file_handle) | ||
280 | { | ||
281 | fprintf(stderr, _("Unable to open dump file: %s\n"), file_name); | ||
282 | ret = 1; | ||
283 | GNUNET_SCHEDULER_shutdown(); | ||
284 | return; | ||
285 | } | ||
286 | } | 286 | } |
287 | } | ||
288 | else | 287 | else |
289 | { | 288 | { |
290 | file_handle = GNUNET_DISK_get_handle_from_int_fd (STDOUT_FILENO); | 289 | file_handle = GNUNET_DISK_get_handle_from_int_fd(STDOUT_FILENO); |
291 | } | 290 | } |
292 | GNUNET_DISK_file_write (file_handle, MAGIC_BYTES, MAGIC_LEN); | 291 | GNUNET_DISK_file_write(file_handle, MAGIC_BYTES, MAGIC_LEN); |
293 | do_get (0); | 292 | do_get(0); |
294 | } | 293 | } |
295 | 294 | ||
296 | 295 | ||
@@ -308,77 +307,77 @@ start_dump () | |||
308 | * @param msg NULL on success, otherwise an error message | 307 | * @param msg NULL on success, otherwise an error message |
309 | */ | 308 | */ |
310 | static void | 309 | static void |
311 | put_cb (void *cls, | 310 | put_cb(void *cls, |
312 | int32_t success, | 311 | int32_t success, |
313 | struct GNUNET_TIME_Absolute min_expiration, | 312 | struct GNUNET_TIME_Absolute min_expiration, |
314 | const char *msg) | 313 | const char *msg) |
315 | { | 314 | { |
316 | qe = NULL; | 315 | qe = NULL; |
317 | if (GNUNET_SYSERR == success) | 316 | if (GNUNET_SYSERR == success) |
318 | { | 317 | { |
319 | fprintf (stderr, _ ("Failed to store item: %s, aborting\n"), msg); | 318 | fprintf(stderr, _("Failed to store item: %s, aborting\n"), msg); |
320 | ret = 1; | 319 | ret = 1; |
321 | GNUNET_SCHEDULER_shutdown (); | 320 | GNUNET_SCHEDULER_shutdown(); |
322 | return; | 321 | return; |
323 | } | 322 | } |
324 | 323 | ||
325 | struct DataRecord dr; | 324 | struct DataRecord dr; |
326 | ssize_t len; | 325 | ssize_t len; |
327 | 326 | ||
328 | len = GNUNET_DISK_file_read (file_handle, &dr, sizeof (dr)); | 327 | len = GNUNET_DISK_file_read(file_handle, &dr, sizeof(dr)); |
329 | if (0 == len) | 328 | if (0 == len) |
330 | { | 329 | { |
331 | fprintf (stderr, _ ("Inserted %" PRIu64 " records\n"), record_count); | 330 | fprintf(stderr, _("Inserted %" PRIu64 " records\n"), record_count); |
332 | ret = 0; | 331 | ret = 0; |
333 | GNUNET_SCHEDULER_shutdown (); | 332 | GNUNET_SCHEDULER_shutdown(); |
334 | return; | 333 | return; |
335 | } | 334 | } |
336 | else if (sizeof (dr) != len) | 335 | else if (sizeof(dr) != len) |
337 | { | 336 | { |
338 | fprintf (stderr, | 337 | fprintf(stderr, |
339 | _ ("Short read from file: %zd bytes expecting %zd\n"), | 338 | _("Short read from file: %zd bytes expecting %zd\n"), |
340 | len, | 339 | len, |
341 | sizeof (dr)); | 340 | sizeof(dr)); |
342 | ret = 1; | 341 | ret = 1; |
343 | GNUNET_SCHEDULER_shutdown (); | 342 | GNUNET_SCHEDULER_shutdown(); |
344 | return; | 343 | return; |
345 | } | 344 | } |
346 | 345 | ||
347 | const size_t size = ntohl (dr.size); | 346 | const size_t size = ntohl(dr.size); |
348 | uint8_t data[size]; | 347 | uint8_t data[size]; |
349 | len = GNUNET_DISK_file_read (file_handle, data, size); | 348 | len = GNUNET_DISK_file_read(file_handle, data, size); |
350 | if (size != len) | 349 | if (size != len) |
351 | { | 350 | { |
352 | fprintf (stderr, | 351 | fprintf(stderr, |
353 | _ ("Short read from file: %zd bytes expecting %zd\n"), | 352 | _("Short read from file: %zd bytes expecting %zd\n"), |
354 | len, | 353 | len, |
355 | size); | 354 | size); |
356 | ret = 1; | 355 | ret = 1; |
357 | GNUNET_SCHEDULER_shutdown (); | 356 | GNUNET_SCHEDULER_shutdown(); |
358 | return; | 357 | return; |
359 | } | 358 | } |
360 | 359 | ||
361 | record_count++; | 360 | record_count++; |
362 | qe = GNUNET_DATASTORE_put (datastore, | 361 | qe = GNUNET_DATASTORE_put(datastore, |
363 | 0, | 362 | 0, |
364 | &dr.key, | 363 | &dr.key, |
365 | size, | 364 | size, |
366 | data, | 365 | data, |
367 | ntohl (dr.type), | 366 | ntohl(dr.type), |
368 | ntohl (dr.priority), | 367 | ntohl(dr.priority), |
369 | ntohl (dr.anonymity), | 368 | ntohl(dr.anonymity), |
370 | ntohl (dr.replication), | 369 | ntohl(dr.replication), |
371 | GNUNET_TIME_absolute_ntoh (dr.expiration), | 370 | GNUNET_TIME_absolute_ntoh(dr.expiration), |
372 | 0, | 371 | 0, |
373 | 1, | 372 | 1, |
374 | &put_cb, | 373 | &put_cb, |
375 | NULL); | 374 | NULL); |
376 | if (NULL == qe) | 375 | if (NULL == qe) |
377 | { | 376 | { |
378 | fprintf (stderr, _ ("Error queueing datastore PUT operation\n")); | 377 | fprintf(stderr, _("Error queueing datastore PUT operation\n")); |
379 | ret = 1; | 378 | ret = 1; |
380 | GNUNET_SCHEDULER_shutdown (); | 379 | GNUNET_SCHEDULER_shutdown(); |
381 | } | 380 | } |
382 | } | 381 | } |
383 | 382 | ||
384 | 383 | ||
@@ -386,38 +385,38 @@ put_cb (void *cls, | |||
386 | * Begin inserting into the database. | 385 | * Begin inserting into the database. |
387 | */ | 386 | */ |
388 | static void | 387 | static void |
389 | start_insert () | 388 | start_insert() |
390 | { | 389 | { |
391 | record_count = 0; | 390 | record_count = 0; |
392 | 391 | ||
393 | if (NULL != file_name) | 392 | if (NULL != file_name) |
394 | { | ||
395 | file_handle = GNUNET_DISK_file_open (file_name, | ||
396 | GNUNET_DISK_OPEN_READ, | ||
397 | GNUNET_DISK_PERM_NONE); | ||
398 | if (NULL == file_handle) | ||
399 | { | 393 | { |
400 | fprintf (stderr, _ ("Unable to open dump file: %s\n"), file_name); | 394 | file_handle = GNUNET_DISK_file_open(file_name, |
401 | ret = 1; | 395 | GNUNET_DISK_OPEN_READ, |
402 | GNUNET_SCHEDULER_shutdown (); | 396 | GNUNET_DISK_PERM_NONE); |
403 | return; | 397 | if (NULL == file_handle) |
398 | { | ||
399 | fprintf(stderr, _("Unable to open dump file: %s\n"), file_name); | ||
400 | ret = 1; | ||
401 | GNUNET_SCHEDULER_shutdown(); | ||
402 | return; | ||
403 | } | ||
404 | } | 404 | } |
405 | } | ||
406 | else | 405 | else |
407 | { | 406 | { |
408 | file_handle = GNUNET_DISK_get_handle_from_int_fd (STDIN_FILENO); | 407 | file_handle = GNUNET_DISK_get_handle_from_int_fd(STDIN_FILENO); |
409 | } | 408 | } |
410 | 409 | ||
411 | uint8_t buf[MAGIC_LEN]; | 410 | uint8_t buf[MAGIC_LEN]; |
412 | ssize_t len; | 411 | ssize_t len; |
413 | 412 | ||
414 | len = GNUNET_DISK_file_read (file_handle, buf, MAGIC_LEN); | 413 | len = GNUNET_DISK_file_read(file_handle, buf, MAGIC_LEN); |
415 | if (len != MAGIC_LEN || 0 != memcmp (buf, MAGIC_BYTES, MAGIC_LEN)) | 414 | if (len != MAGIC_LEN || 0 != memcmp(buf, MAGIC_BYTES, MAGIC_LEN)) |
416 | { | 415 | { |
417 | fprintf (stderr, _ ("Input file is not of a supported format\n")); | 416 | fprintf(stderr, _("Input file is not of a supported format\n")); |
418 | return; | 417 | return; |
419 | } | 418 | } |
420 | put_cb (NULL, GNUNET_YES, GNUNET_TIME_UNIT_ZERO_ABS, NULL); | 419 | put_cb(NULL, GNUNET_YES, GNUNET_TIME_UNIT_ZERO_ABS, NULL); |
421 | } | 420 | } |
422 | 421 | ||
423 | 422 | ||
@@ -430,33 +429,33 @@ start_insert () | |||
430 | * @param cfg configuration | 429 | * @param cfg configuration |
431 | */ | 430 | */ |
432 | static void | 431 | static void |
433 | run (void *cls, | 432 | run(void *cls, |
434 | char *const *args, | 433 | char *const *args, |
435 | const char *cfgfile, | 434 | const char *cfgfile, |
436 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 435 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
437 | { | 436 | { |
438 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 437 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
439 | datastore = GNUNET_DATASTORE_connect (cfg); | 438 | datastore = GNUNET_DATASTORE_connect(cfg); |
440 | if (NULL == datastore) | 439 | if (NULL == datastore) |
441 | { | 440 | { |
442 | fprintf (stderr, _ ("Failed connecting to the datastore.\n")); | 441 | fprintf(stderr, _("Failed connecting to the datastore.\n")); |
443 | ret = 1; | 442 | ret = 1; |
444 | GNUNET_SCHEDULER_shutdown (); | 443 | GNUNET_SCHEDULER_shutdown(); |
445 | return; | 444 | return; |
446 | } | 445 | } |
447 | if (dump) | 446 | if (dump) |
448 | start_dump (); | 447 | start_dump(); |
449 | else if (insert) | 448 | else if (insert) |
450 | start_insert (); | 449 | start_insert(); |
451 | else | 450 | else |
452 | { | 451 | { |
453 | fprintf (stderr, | 452 | fprintf(stderr, |
454 | _ ("Please choose at least one operation: %s, %s\n"), | 453 | _("Please choose at least one operation: %s, %s\n"), |
455 | "dump", | 454 | "dump", |
456 | "insert"); | 455 | "insert"); |
457 | ret = 1; | 456 | ret = 1; |
458 | GNUNET_SCHEDULER_shutdown (); | 457 | GNUNET_SCHEDULER_shutdown(); |
459 | } | 458 | } |
460 | } | 459 | } |
461 | 460 | ||
462 | 461 | ||
@@ -468,38 +467,39 @@ run (void *cls, | |||
468 | * @return 0 ok, 1 on error | 467 | * @return 0 ok, 1 on error |
469 | */ | 468 | */ |
470 | int | 469 | int |
471 | main (int argc, char *const *argv) | 470 | main(int argc, char *const *argv) |
472 | { | 471 | { |
473 | struct GNUNET_GETOPT_CommandLineOption options[] = | 472 | struct GNUNET_GETOPT_CommandLineOption options[] = |
474 | {GNUNET_GETOPT_option_flag ('d', | 473 | { GNUNET_GETOPT_option_flag('d', |
475 | "dump", | 474 | "dump", |
476 | gettext_noop ( | 475 | gettext_noop( |
477 | "Dump all records from the datastore"), | 476 | "Dump all records from the datastore"), |
478 | &dump), | 477 | &dump), |
479 | GNUNET_GETOPT_option_flag ('i', | 478 | GNUNET_GETOPT_option_flag('i', |
480 | "insert", | 479 | "insert", |
481 | gettext_noop ( | 480 | gettext_noop( |
482 | "Insert records into the datastore"), | 481 | "Insert records into the datastore"), |
483 | &insert), | 482 | &insert), |
484 | GNUNET_GETOPT_option_filename ('f', | 483 | GNUNET_GETOPT_option_filename('f', |
485 | "file", | 484 | "file", |
486 | "FILENAME", | 485 | "FILENAME", |
487 | gettext_noop ("File to dump or insert"), | 486 | gettext_noop("File to dump or insert"), |
488 | &file_name), | 487 | &file_name), |
489 | GNUNET_GETOPT_OPTION_END}; | 488 | GNUNET_GETOPT_OPTION_END }; |
490 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 489 | |
490 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | ||
491 | return 2; | 491 | return 2; |
492 | 492 | ||
493 | if (GNUNET_OK != | 493 | if (GNUNET_OK != |
494 | GNUNET_PROGRAM_run (argc, | 494 | GNUNET_PROGRAM_run(argc, |
495 | argv, | 495 | argv, |
496 | "gnunet-datastore", | 496 | "gnunet-datastore", |
497 | gettext_noop ("Manipulate GNUnet datastore"), | 497 | gettext_noop("Manipulate GNUnet datastore"), |
498 | options, | 498 | options, |
499 | &run, | 499 | &run, |
500 | NULL)) | 500 | NULL)) |
501 | ret = 1; | 501 | ret = 1; |
502 | GNUNET_free ((void *) argv); | 502 | GNUNET_free((void *)argv); |
503 | return ret; | 503 | return ret; |
504 | } | 504 | } |
505 | 505 | ||
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index 4596f6131..41abf77ca 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file datastore/gnunet-service-datastore.c | 22 | * @file datastore/gnunet-service-datastore.c |
@@ -39,21 +39,21 @@ | |||
39 | /** | 39 | /** |
40 | * Limit size of bloom filter to 2 GB. | 40 | * Limit size of bloom filter to 2 GB. |
41 | */ | 41 | */ |
42 | #define MAX_BF_SIZE ((uint32_t) (1LL << 31)) | 42 | #define MAX_BF_SIZE ((uint32_t)(1LL << 31)) |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * How long are we at most keeping "expired" content | 45 | * How long are we at most keeping "expired" content |
46 | * past the expiration date in the database? | 46 | * past the expiration date in the database? |
47 | */ | 47 | */ |
48 | #define MAX_EXPIRE_DELAY \ | 48 | #define MAX_EXPIRE_DELAY \ |
49 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | 49 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * How fast are we allowed to query the database for deleting | 52 | * How fast are we allowed to query the database for deleting |
53 | * expired content? (1 item per second). | 53 | * expired content? (1 item per second). |
54 | */ | 54 | */ |
55 | #define MIN_EXPIRE_DELAY \ | 55 | #define MIN_EXPIRE_DELAY \ |
56 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 56 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Name under which we store current space consumption. | 59 | * Name under which we store current space consumption. |
@@ -75,9 +75,7 @@ static struct GNUNET_SCHEDULER_Task *stat_timeout_task; | |||
75 | /** | 75 | /** |
76 | * Our datastore plugin. | 76 | * Our datastore plugin. |
77 | */ | 77 | */ |
78 | struct DatastorePlugin | 78 | struct DatastorePlugin { |
79 | { | ||
80 | |||
81 | /** | 79 | /** |
82 | * API of the transport as returned by the plugin's | 80 | * API of the transport as returned by the plugin's |
83 | * initialization function. | 81 | * initialization function. |
@@ -105,9 +103,7 @@ struct DatastorePlugin | |||
105 | /** | 103 | /** |
106 | * Linked list of active reservations. | 104 | * Linked list of active reservations. |
107 | */ | 105 | */ |
108 | struct ReservationList | 106 | struct ReservationList { |
109 | { | ||
110 | |||
111 | /** | 107 | /** |
112 | * This is a linked list. | 108 | * This is a linked list. |
113 | */ | 109 | */ |
@@ -231,13 +227,13 @@ static int stats_worked; | |||
231 | * statistics service. | 227 | * statistics service. |
232 | */ | 228 | */ |
233 | static void | 229 | static void |
234 | sync_stats () | 230 | sync_stats() |
235 | { | 231 | { |
236 | GNUNET_STATISTICS_set (stats, quota_stat_name, payload, GNUNET_YES); | 232 | GNUNET_STATISTICS_set(stats, quota_stat_name, payload, GNUNET_YES); |
237 | GNUNET_STATISTICS_set (stats, | 233 | GNUNET_STATISTICS_set(stats, |
238 | "# utilization by current datastore", | 234 | "# utilization by current datastore", |
239 | payload, | 235 | payload, |
240 | GNUNET_NO); | 236 | GNUNET_NO); |
241 | last_sync = 0; | 237 | last_sync = 0; |
242 | } | 238 | } |
243 | 239 | ||
@@ -267,7 +263,7 @@ static struct GNUNET_SERVICE_Handle *service; | |||
267 | * @param cls not used | 263 | * @param cls not used |
268 | */ | 264 | */ |
269 | static void | 265 | static void |
270 | delete_expired (void *cls); | 266 | delete_expired(void *cls); |
271 | 267 | ||
272 | 268 | ||
273 | /** | 269 | /** |
@@ -292,57 +288,57 @@ delete_expired (void *cls); | |||
292 | * #GNUNET_NO to delete the item and continue (if supported) | 288 | * #GNUNET_NO to delete the item and continue (if supported) |
293 | */ | 289 | */ |
294 | static int | 290 | static int |
295 | expired_processor (void *cls, | 291 | expired_processor(void *cls, |
296 | const struct GNUNET_HashCode *key, | 292 | const struct GNUNET_HashCode *key, |
297 | uint32_t size, | 293 | uint32_t size, |
298 | const void *data, | 294 | const void *data, |
299 | enum GNUNET_BLOCK_Type type, | 295 | enum GNUNET_BLOCK_Type type, |
300 | uint32_t priority, | 296 | uint32_t priority, |
301 | uint32_t anonymity, | 297 | uint32_t anonymity, |
302 | uint32_t replication, | 298 | uint32_t replication, |
303 | struct GNUNET_TIME_Absolute expiration, | 299 | struct GNUNET_TIME_Absolute expiration, |
304 | uint64_t uid) | 300 | uint64_t uid) |
305 | { | 301 | { |
306 | struct GNUNET_TIME_Absolute now; | 302 | struct GNUNET_TIME_Absolute now; |
307 | 303 | ||
308 | if (NULL == key) | 304 | if (NULL == key) |
309 | { | 305 | { |
310 | expired_kill_task = | 306 | expired_kill_task = |
311 | GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY, | 307 | GNUNET_SCHEDULER_add_delayed_with_priority(MAX_EXPIRE_DELAY, |
312 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 308 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
313 | &delete_expired, | 309 | &delete_expired, |
314 | NULL); | 310 | NULL); |
315 | return GNUNET_SYSERR; | 311 | return GNUNET_SYSERR; |
316 | } | 312 | } |
317 | now = GNUNET_TIME_absolute_get (); | 313 | now = GNUNET_TIME_absolute_get(); |
318 | if (expiration.abs_value_us > now.abs_value_us) | 314 | if (expiration.abs_value_us > now.abs_value_us) |
319 | { | 315 | { |
320 | /* finished processing */ | 316 | /* finished processing */ |
321 | expired_kill_task = | 317 | expired_kill_task = |
322 | GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY, | 318 | GNUNET_SCHEDULER_add_delayed_with_priority(MAX_EXPIRE_DELAY, |
323 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 319 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
324 | &delete_expired, | 320 | &delete_expired, |
325 | NULL); | 321 | NULL); |
326 | return GNUNET_SYSERR; | 322 | return GNUNET_SYSERR; |
327 | } | 323 | } |
328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 324 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
329 | "Deleting content `%s' of type %u that expired %s ago\n", | 325 | "Deleting content `%s' of type %u that expired %s ago\n", |
330 | GNUNET_h2s (key), | 326 | GNUNET_h2s(key), |
331 | type, | 327 | type, |
332 | GNUNET_STRINGS_relative_time_to_string ( | 328 | GNUNET_STRINGS_relative_time_to_string( |
333 | GNUNET_TIME_absolute_get_difference (expiration, now), | 329 | GNUNET_TIME_absolute_get_difference(expiration, now), |
334 | GNUNET_YES)); | 330 | GNUNET_YES)); |
335 | min_expiration = now; | 331 | min_expiration = now; |
336 | GNUNET_STATISTICS_update (stats, | 332 | GNUNET_STATISTICS_update(stats, |
337 | gettext_noop ("# bytes expired"), | 333 | gettext_noop("# bytes expired"), |
338 | size, | 334 | size, |
339 | GNUNET_YES); | 335 | GNUNET_YES); |
340 | GNUNET_CONTAINER_bloomfilter_remove (filter, key); | 336 | GNUNET_CONTAINER_bloomfilter_remove(filter, key); |
341 | expired_kill_task = | 337 | expired_kill_task = |
342 | GNUNET_SCHEDULER_add_delayed_with_priority (MIN_EXPIRE_DELAY, | 338 | GNUNET_SCHEDULER_add_delayed_with_priority(MIN_EXPIRE_DELAY, |
343 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 339 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
344 | &delete_expired, | 340 | &delete_expired, |
345 | NULL); | 341 | NULL); |
346 | return GNUNET_NO; | 342 | return GNUNET_NO; |
347 | } | 343 | } |
348 | 344 | ||
@@ -356,10 +352,10 @@ expired_processor (void *cls, | |||
356 | * @param cls not used | 352 | * @param cls not used |
357 | */ | 353 | */ |
358 | static void | 354 | static void |
359 | delete_expired (void *cls) | 355 | delete_expired(void *cls) |
360 | { | 356 | { |
361 | expired_kill_task = NULL; | 357 | expired_kill_task = NULL; |
362 | plugin->api->get_expiration (plugin->api->cls, &expired_processor, NULL); | 358 | plugin->api->get_expiration(plugin->api->cls, &expired_processor, NULL); |
363 | } | 359 | } |
364 | 360 | ||
365 | 361 | ||
@@ -383,31 +379,31 @@ delete_expired (void *cls) | |||
383 | * #GNUNET_NO to delete the item and continue (if supported) | 379 | * #GNUNET_NO to delete the item and continue (if supported) |
384 | */ | 380 | */ |
385 | static int | 381 | static int |
386 | quota_processor (void *cls, | 382 | quota_processor(void *cls, |
387 | const struct GNUNET_HashCode *key, | 383 | const struct GNUNET_HashCode *key, |
388 | uint32_t size, | 384 | uint32_t size, |
389 | const void *data, | 385 | const void *data, |
390 | enum GNUNET_BLOCK_Type type, | 386 | enum GNUNET_BLOCK_Type type, |
391 | uint32_t priority, | 387 | uint32_t priority, |
392 | uint32_t anonymity, | 388 | uint32_t anonymity, |
393 | uint32_t replication, | 389 | uint32_t replication, |
394 | struct GNUNET_TIME_Absolute expiration, | 390 | struct GNUNET_TIME_Absolute expiration, |
395 | uint64_t uid) | 391 | uint64_t uid) |
396 | { | 392 | { |
397 | unsigned long long *need = cls; | 393 | unsigned long long *need = cls; |
398 | 394 | ||
399 | if (NULL == key) | 395 | if (NULL == key) |
400 | return GNUNET_SYSERR; | 396 | return GNUNET_SYSERR; |
401 | GNUNET_log ( | 397 | GNUNET_log( |
402 | GNUNET_ERROR_TYPE_DEBUG, | 398 | GNUNET_ERROR_TYPE_DEBUG, |
403 | "Deleting %llu bytes of low-priority (%u) content `%s' of type %u at %s prior to expiration (still trying to free another %llu bytes)\n", | 399 | "Deleting %llu bytes of low-priority (%u) content `%s' of type %u at %s prior to expiration (still trying to free another %llu bytes)\n", |
404 | (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD), | 400 | (unsigned long long)(size + GNUNET_DATASTORE_ENTRY_OVERHEAD), |
405 | (unsigned int) priority, | 401 | (unsigned int)priority, |
406 | GNUNET_h2s (key), | 402 | GNUNET_h2s(key), |
407 | type, | 403 | type, |
408 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining ( | 404 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining( |
409 | expiration), | 405 | expiration), |
410 | GNUNET_YES), | 406 | GNUNET_YES), |
411 | *need); | 407 | *need); |
412 | if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need) | 408 | if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need) |
413 | *need = 0; | 409 | *need = 0; |
@@ -417,11 +413,11 @@ quota_processor (void *cls, | |||
417 | min_expiration = GNUNET_TIME_UNIT_FOREVER_ABS; | 413 | min_expiration = GNUNET_TIME_UNIT_FOREVER_ABS; |
418 | else | 414 | else |
419 | min_expiration = expiration; | 415 | min_expiration = expiration; |
420 | GNUNET_STATISTICS_update (stats, | 416 | GNUNET_STATISTICS_update(stats, |
421 | gettext_noop ("# bytes purged (low-priority)"), | 417 | gettext_noop("# bytes purged (low-priority)"), |
422 | size, | 418 | size, |
423 | GNUNET_YES); | 419 | GNUNET_YES); |
424 | GNUNET_CONTAINER_bloomfilter_remove (filter, key); | 420 | GNUNET_CONTAINER_bloomfilter_remove(filter, key); |
425 | return GNUNET_NO; | 421 | return GNUNET_NO; |
426 | } | 422 | } |
427 | 423 | ||
@@ -439,19 +435,19 @@ quota_processor (void *cls, | |||
439 | * number of bytes that should be removed). | 435 | * number of bytes that should be removed). |
440 | */ | 436 | */ |
441 | static void | 437 | static void |
442 | manage_space (unsigned long long need) | 438 | manage_space(unsigned long long need) |
443 | { | 439 | { |
444 | unsigned long long last; | 440 | unsigned long long last; |
445 | 441 | ||
446 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 442 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
447 | "Asked to free up %llu bytes of cache space\n", | 443 | "Asked to free up %llu bytes of cache space\n", |
448 | need); | 444 | need); |
449 | last = 0; | 445 | last = 0; |
450 | while ((need > 0) && (last != need)) | 446 | while ((need > 0) && (last != need)) |
451 | { | 447 | { |
452 | last = need; | 448 | last = need; |
453 | plugin->api->get_expiration (plugin->api->cls, "a_processor, &need); | 449 | plugin->api->get_expiration(plugin->api->cls, "a_processor, &need); |
454 | } | 450 | } |
455 | } | 451 | } |
456 | 452 | ||
457 | 453 | ||
@@ -463,25 +459,25 @@ manage_space (unsigned long long need) | |||
463 | * @param msg optional error message (can be NULL) | 459 | * @param msg optional error message (can be NULL) |
464 | */ | 460 | */ |
465 | static void | 461 | static void |
466 | transmit_status (struct GNUNET_SERVICE_Client *client, | 462 | transmit_status(struct GNUNET_SERVICE_Client *client, |
467 | int code, | 463 | int code, |
468 | const char *msg) | 464 | const char *msg) |
469 | { | 465 | { |
470 | struct GNUNET_MQ_Envelope *env; | 466 | struct GNUNET_MQ_Envelope *env; |
471 | struct StatusMessage *sm; | 467 | struct StatusMessage *sm; |
472 | size_t slen; | 468 | size_t slen; |
473 | 469 | ||
474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 470 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
475 | "Transmitting `%s' message with value %d and message `%s'\n", | 471 | "Transmitting `%s' message with value %d and message `%s'\n", |
476 | "STATUS", | 472 | "STATUS", |
477 | code, | 473 | code, |
478 | msg != NULL ? msg : "(none)"); | 474 | msg != NULL ? msg : "(none)"); |
479 | slen = (msg == NULL) ? 0 : strlen (msg) + 1; | 475 | slen = (msg == NULL) ? 0 : strlen(msg) + 1; |
480 | env = GNUNET_MQ_msg_extra (sm, slen, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS); | 476 | env = GNUNET_MQ_msg_extra(sm, slen, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS); |
481 | sm->status = htonl (code); | 477 | sm->status = htonl(code); |
482 | sm->min_expiration = GNUNET_TIME_absolute_hton (min_expiration); | 478 | sm->min_expiration = GNUNET_TIME_absolute_hton(min_expiration); |
483 | GNUNET_memcpy (&sm[1], msg, slen); | 479 | GNUNET_memcpy(&sm[1], msg, slen); |
484 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 480 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
485 | } | 481 | } |
486 | 482 | ||
487 | 483 | ||
@@ -504,16 +500,16 @@ transmit_status (struct GNUNET_SERVICE_Client *client, | |||
504 | * #GNUNET_NO to delete the item and continue (if supported) | 500 | * #GNUNET_NO to delete the item and continue (if supported) |
505 | */ | 501 | */ |
506 | static int | 502 | static int |
507 | transmit_item (void *cls, | 503 | transmit_item(void *cls, |
508 | const struct GNUNET_HashCode *key, | 504 | const struct GNUNET_HashCode *key, |
509 | uint32_t size, | 505 | uint32_t size, |
510 | const void *data, | 506 | const void *data, |
511 | enum GNUNET_BLOCK_Type type, | 507 | enum GNUNET_BLOCK_Type type, |
512 | uint32_t priority, | 508 | uint32_t priority, |
513 | uint32_t anonymity, | 509 | uint32_t anonymity, |
514 | uint32_t replication, | 510 | uint32_t replication, |
515 | struct GNUNET_TIME_Absolute expiration, | 511 | struct GNUNET_TIME_Absolute expiration, |
516 | uint64_t uid) | 512 | uint64_t uid) |
517 | { | 513 | { |
518 | struct GNUNET_SERVICE_Client *client = cls; | 514 | struct GNUNET_SERVICE_Client *client = cls; |
519 | struct GNUNET_MQ_Envelope *env; | 515 | struct GNUNET_MQ_Envelope *env; |
@@ -521,39 +517,39 @@ transmit_item (void *cls, | |||
521 | struct DataMessage *dm; | 517 | struct DataMessage *dm; |
522 | 518 | ||
523 | if (NULL == key) | 519 | if (NULL == key) |
524 | { | 520 | { |
525 | /* transmit 'DATA_END' */ | 521 | /* transmit 'DATA_END' */ |
526 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting DATA_END message\n"); | 522 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Transmitting DATA_END message\n"); |
527 | env = GNUNET_MQ_msg (end, GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END); | 523 | env = GNUNET_MQ_msg(end, GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END); |
528 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 524 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
529 | return GNUNET_OK; | 525 | return GNUNET_OK; |
530 | } | 526 | } |
531 | GNUNET_assert (sizeof (struct DataMessage) + size < GNUNET_MAX_MESSAGE_SIZE); | 527 | GNUNET_assert(sizeof(struct DataMessage) + size < GNUNET_MAX_MESSAGE_SIZE); |
532 | env = GNUNET_MQ_msg_extra (dm, size, GNUNET_MESSAGE_TYPE_DATASTORE_DATA); | 528 | env = GNUNET_MQ_msg_extra(dm, size, GNUNET_MESSAGE_TYPE_DATASTORE_DATA); |
533 | dm->rid = htonl (0); | 529 | dm->rid = htonl(0); |
534 | dm->size = htonl (size); | 530 | dm->size = htonl(size); |
535 | dm->type = htonl (type); | 531 | dm->type = htonl(type); |
536 | dm->priority = htonl (priority); | 532 | dm->priority = htonl(priority); |
537 | dm->anonymity = htonl (anonymity); | 533 | dm->anonymity = htonl(anonymity); |
538 | dm->replication = htonl (replication); | 534 | dm->replication = htonl(replication); |
539 | dm->expiration = GNUNET_TIME_absolute_hton (expiration); | 535 | dm->expiration = GNUNET_TIME_absolute_hton(expiration); |
540 | dm->uid = GNUNET_htonll (uid); | 536 | dm->uid = GNUNET_htonll(uid); |
541 | dm->key = *key; | 537 | dm->key = *key; |
542 | GNUNET_memcpy (&dm[1], data, size); | 538 | GNUNET_memcpy(&dm[1], data, size); |
543 | GNUNET_log ( | 539 | GNUNET_log( |
544 | GNUNET_ERROR_TYPE_DEBUG, | 540 | GNUNET_ERROR_TYPE_DEBUG, |
545 | "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n", | 541 | "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n", |
546 | GNUNET_h2s (key), | 542 | GNUNET_h2s(key), |
547 | type, | 543 | type, |
548 | GNUNET_STRINGS_absolute_time_to_string (expiration), | 544 | GNUNET_STRINGS_absolute_time_to_string(expiration), |
549 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining ( | 545 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining( |
550 | expiration), | 546 | expiration), |
551 | GNUNET_YES)); | 547 | GNUNET_YES)); |
552 | GNUNET_STATISTICS_update (stats, | 548 | GNUNET_STATISTICS_update(stats, |
553 | gettext_noop ("# results found"), | 549 | gettext_noop("# results found"), |
554 | 1, | 550 | 1, |
555 | GNUNET_NO); | 551 | GNUNET_NO); |
556 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 552 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
557 | return GNUNET_OK; | 553 | return GNUNET_OK; |
558 | } | 554 | } |
559 | 555 | ||
@@ -565,7 +561,7 @@ transmit_item (void *cls, | |||
565 | * @param message the actual message | 561 | * @param message the actual message |
566 | */ | 562 | */ |
567 | static void | 563 | static void |
568 | handle_reserve (void *cls, const struct ReserveMessage *msg) | 564 | handle_reserve(void *cls, const struct ReserveMessage *msg) |
569 | { | 565 | { |
570 | /** | 566 | /** |
571 | * Static counter to produce reservation identifiers. | 567 | * Static counter to produce reservation identifiers. |
@@ -578,57 +574,57 @@ handle_reserve (void *cls, const struct ReserveMessage *msg) | |||
578 | uint64_t amount; | 574 | uint64_t amount; |
579 | uint32_t entries; | 575 | uint32_t entries; |
580 | 576 | ||
581 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing RESERVE request\n"); | 577 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing RESERVE request\n"); |
582 | amount = GNUNET_ntohll (msg->amount); | 578 | amount = GNUNET_ntohll(msg->amount); |
583 | entries = ntohl (msg->entries); | 579 | entries = ntohl(msg->entries); |
584 | used = payload + reserved; | 580 | used = payload + reserved; |
585 | req = | 581 | req = |
586 | amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries; | 582 | amount + ((unsigned long long)GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries; |
587 | if (used + req > quota) | 583 | if (used + req > quota) |
588 | { | ||
589 | if (quota < used) | ||
590 | used = | ||
591 | quota; /* cheat a bit for error message (to avoid negative numbers) */ | ||
592 | GNUNET_log ( | ||
593 | GNUNET_ERROR_TYPE_WARNING, | ||
594 | _ ( | ||
595 | "Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"), | ||
596 | quota - used, | ||
597 | req); | ||
598 | if (cache_size < req) | ||
599 | { | 584 | { |
600 | /* TODO: document this in the FAQ; essentially, if this | 585 | if (quota < used) |
601 | * message happens, the insertion request could be blocked | 586 | used = |
602 | * by less-important content from migration because it is | 587 | quota; /* cheat a bit for error message (to avoid negative numbers) */ |
603 | * larger than 1/8th of the overall available space, and | 588 | GNUNET_log( |
604 | * we only reserve 1/8th for "fresh" insertions */ | ||
605 | GNUNET_log ( | ||
606 | GNUNET_ERROR_TYPE_WARNING, | 589 | GNUNET_ERROR_TYPE_WARNING, |
607 | _ ( | 590 | _( |
608 | "The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"), | 591 | "Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"), |
609 | req, | 592 | quota - used, |
610 | cache_size); | 593 | req); |
611 | transmit_status (client, | 594 | if (cache_size < req) |
612 | 0, | 595 | { |
613 | gettext_noop ( | 596 | /* TODO: document this in the FAQ; essentially, if this |
614 | "Insufficient space to satisfy request and " | 597 | * message happens, the insertion request could be blocked |
615 | "requested amount is larger than cache size")); | 598 | * by less-important content from migration because it is |
616 | } | 599 | * larger than 1/8th of the overall available space, and |
617 | else | 600 | * we only reserve 1/8th for "fresh" insertions */ |
618 | { | 601 | GNUNET_log( |
619 | transmit_status (client, | 602 | GNUNET_ERROR_TYPE_WARNING, |
620 | 0, | 603 | _( |
621 | gettext_noop ("Insufficient space to satisfy request")); | 604 | "The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"), |
605 | req, | ||
606 | cache_size); | ||
607 | transmit_status(client, | ||
608 | 0, | ||
609 | gettext_noop( | ||
610 | "Insufficient space to satisfy request and " | ||
611 | "requested amount is larger than cache size")); | ||
612 | } | ||
613 | else | ||
614 | { | ||
615 | transmit_status(client, | ||
616 | 0, | ||
617 | gettext_noop("Insufficient space to satisfy request")); | ||
618 | } | ||
619 | GNUNET_SERVICE_client_continue(client); | ||
620 | return; | ||
622 | } | 621 | } |
623 | GNUNET_SERVICE_client_continue (client); | ||
624 | return; | ||
625 | } | ||
626 | reserved += req; | 622 | reserved += req; |
627 | GNUNET_STATISTICS_set (stats, | 623 | GNUNET_STATISTICS_set(stats, |
628 | gettext_noop ("# reserved"), | 624 | gettext_noop("# reserved"), |
629 | reserved, | 625 | reserved, |
630 | GNUNET_NO); | 626 | GNUNET_NO); |
631 | e = GNUNET_new (struct ReservationList); | 627 | e = GNUNET_new(struct ReservationList); |
632 | e->next = reservations; | 628 | e->next = reservations; |
633 | reservations = e; | 629 | reservations = e; |
634 | e->client = client; | 630 | e->client = client; |
@@ -637,8 +633,8 @@ handle_reserve (void *cls, const struct ReserveMessage *msg) | |||
637 | e->rid = ++reservation_gen; | 633 | e->rid = ++reservation_gen; |
638 | if (reservation_gen < 0) | 634 | if (reservation_gen < 0) |
639 | reservation_gen = 0; /* wrap around */ | 635 | reservation_gen = 0; /* wrap around */ |
640 | transmit_status (client, e->rid, NULL); | 636 | transmit_status(client, e->rid, NULL); |
641 | GNUNET_SERVICE_client_continue (client); | 637 | GNUNET_SERVICE_client_continue(client); |
642 | } | 638 | } |
643 | 639 | ||
644 | 640 | ||
@@ -649,51 +645,51 @@ handle_reserve (void *cls, const struct ReserveMessage *msg) | |||
649 | * @param message the actual message | 645 | * @param message the actual message |
650 | */ | 646 | */ |
651 | static void | 647 | static void |
652 | handle_release_reserve (void *cls, const struct ReleaseReserveMessage *msg) | 648 | handle_release_reserve(void *cls, const struct ReleaseReserveMessage *msg) |
653 | { | 649 | { |
654 | struct GNUNET_SERVICE_Client *client = cls; | 650 | struct GNUNET_SERVICE_Client *client = cls; |
655 | struct ReservationList *pos; | 651 | struct ReservationList *pos; |
656 | struct ReservationList *prev; | 652 | struct ReservationList *prev; |
657 | struct ReservationList *next; | 653 | struct ReservationList *next; |
658 | int rid = ntohl (msg->rid); | 654 | int rid = ntohl(msg->rid); |
659 | unsigned long long rem; | 655 | unsigned long long rem; |
660 | 656 | ||
661 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing RELEASE_RESERVE request\n"); | 657 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing RELEASE_RESERVE request\n"); |
662 | next = reservations; | 658 | next = reservations; |
663 | prev = NULL; | 659 | prev = NULL; |
664 | while (NULL != (pos = next)) | 660 | while (NULL != (pos = next)) |
665 | { | ||
666 | next = pos->next; | ||
667 | if (rid == pos->rid) | ||
668 | { | 661 | { |
669 | if (prev == NULL) | 662 | next = pos->next; |
670 | reservations = next; | 663 | if (rid == pos->rid) |
671 | else | 664 | { |
672 | prev->next = next; | 665 | if (prev == NULL) |
673 | rem = | 666 | reservations = next; |
674 | pos->amount + | 667 | else |
675 | ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries; | 668 | prev->next = next; |
676 | GNUNET_assert (reserved >= rem); | 669 | rem = |
677 | reserved -= rem; | 670 | pos->amount + |
678 | GNUNET_STATISTICS_set (stats, | 671 | ((unsigned long long)GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries; |
679 | gettext_noop ("# reserved"), | 672 | GNUNET_assert(reserved >= rem); |
680 | reserved, | 673 | reserved -= rem; |
681 | GNUNET_NO); | 674 | GNUNET_STATISTICS_set(stats, |
682 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 675 | gettext_noop("# reserved"), |
683 | "Returning %llu remaining reserved bytes to storage pool\n", | 676 | reserved, |
684 | rem); | 677 | GNUNET_NO); |
685 | GNUNET_free (pos); | 678 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
686 | transmit_status (client, GNUNET_OK, NULL); | 679 | "Returning %llu remaining reserved bytes to storage pool\n", |
687 | GNUNET_SERVICE_client_continue (client); | 680 | rem); |
688 | return; | 681 | GNUNET_free(pos); |
682 | transmit_status(client, GNUNET_OK, NULL); | ||
683 | GNUNET_SERVICE_client_continue(client); | ||
684 | return; | ||
685 | } | ||
686 | prev = pos; | ||
689 | } | 687 | } |
690 | prev = pos; | 688 | GNUNET_break(0); |
691 | } | 689 | transmit_status(client, |
692 | GNUNET_break (0); | 690 | GNUNET_SYSERR, |
693 | transmit_status (client, | 691 | gettext_noop("Could not find matching reservation")); |
694 | GNUNET_SYSERR, | 692 | GNUNET_SERVICE_client_continue(client); |
695 | gettext_noop ("Could not find matching reservation")); | ||
696 | GNUNET_SERVICE_client_continue (client); | ||
697 | } | 693 | } |
698 | 694 | ||
699 | 695 | ||
@@ -704,18 +700,18 @@ handle_release_reserve (void *cls, const struct ReleaseReserveMessage *msg) | |||
704 | * @return #GNUNET_SYSERR is not well-formed, otherwise #GNUNET_OK | 700 | * @return #GNUNET_SYSERR is not well-formed, otherwise #GNUNET_OK |
705 | */ | 701 | */ |
706 | static int | 702 | static int |
707 | check_data (const struct DataMessage *dm) | 703 | check_data(const struct DataMessage *dm) |
708 | { | 704 | { |
709 | uint16_t size; | 705 | uint16_t size; |
710 | uint32_t dsize; | 706 | uint32_t dsize; |
711 | 707 | ||
712 | size = ntohs (dm->header.size); | 708 | size = ntohs(dm->header.size); |
713 | dsize = ntohl (dm->size); | 709 | dsize = ntohl(dm->size); |
714 | if (size != dsize + sizeof (struct DataMessage)) | 710 | if (size != dsize + sizeof(struct DataMessage)) |
715 | { | 711 | { |
716 | GNUNET_break (0); | 712 | GNUNET_break(0); |
717 | return GNUNET_SYSERR; | 713 | return GNUNET_SYSERR; |
718 | } | 714 | } |
719 | return GNUNET_OK; | 715 | return GNUNET_OK; |
720 | } | 716 | } |
721 | 717 | ||
@@ -731,38 +727,38 @@ check_data (const struct DataMessage *dm) | |||
731 | * @param msg error message on error | 727 | * @param msg error message on error |
732 | */ | 728 | */ |
733 | static void | 729 | static void |
734 | put_continuation (void *cls, | 730 | put_continuation(void *cls, |
735 | const struct GNUNET_HashCode *key, | 731 | const struct GNUNET_HashCode *key, |
736 | uint32_t size, | 732 | uint32_t size, |
737 | int status, | 733 | int status, |
738 | const char *msg) | 734 | const char *msg) |
739 | { | 735 | { |
740 | struct GNUNET_SERVICE_Client *client = cls; | 736 | struct GNUNET_SERVICE_Client *client = cls; |
741 | 737 | ||
742 | if (GNUNET_OK == status) | 738 | if (GNUNET_OK == status) |
743 | { | 739 | { |
744 | GNUNET_STATISTICS_update (stats, | 740 | GNUNET_STATISTICS_update(stats, |
745 | gettext_noop ("# bytes stored"), | 741 | gettext_noop("# bytes stored"), |
746 | size, | 742 | size, |
747 | GNUNET_YES); | 743 | GNUNET_YES); |
748 | GNUNET_CONTAINER_bloomfilter_add (filter, key); | 744 | GNUNET_CONTAINER_bloomfilter_add(filter, key); |
749 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 745 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
750 | "Successfully stored %u bytes under key `%s'\n", | 746 | "Successfully stored %u bytes under key `%s'\n", |
751 | size, | 747 | size, |
752 | GNUNET_h2s (key)); | 748 | GNUNET_h2s(key)); |
753 | } | 749 | } |
754 | transmit_status (client, | 750 | transmit_status(client, |
755 | GNUNET_SYSERR == status ? GNUNET_SYSERR : GNUNET_OK, | 751 | GNUNET_SYSERR == status ? GNUNET_SYSERR : GNUNET_OK, |
756 | msg); | 752 | msg); |
757 | if (quota - reserved - cache_size < payload) | 753 | if (quota - reserved - cache_size < payload) |
758 | { | 754 | { |
759 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 755 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
760 | _ ("Need %llu bytes more space (%llu allowed, using %llu)\n"), | 756 | _("Need %llu bytes more space (%llu allowed, using %llu)\n"), |
761 | (unsigned long long) size + GNUNET_DATASTORE_ENTRY_OVERHEAD, | 757 | (unsigned long long)size + GNUNET_DATASTORE_ENTRY_OVERHEAD, |
762 | (unsigned long long) (quota - reserved - cache_size), | 758 | (unsigned long long)(quota - reserved - cache_size), |
763 | (unsigned long long) payload); | 759 | (unsigned long long)payload); |
764 | manage_space (size + GNUNET_DATASTORE_ENTRY_OVERHEAD); | 760 | manage_space(size + GNUNET_DATASTORE_ENTRY_OVERHEAD); |
765 | } | 761 | } |
766 | } | 762 | } |
767 | 763 | ||
768 | 764 | ||
@@ -774,13 +770,13 @@ put_continuation (void *cls, | |||
774 | * @return #GNUNET_OK if @a dm is well-formed | 770 | * @return #GNUNET_OK if @a dm is well-formed |
775 | */ | 771 | */ |
776 | static int | 772 | static int |
777 | check_put (void *cls, const struct DataMessage *dm) | 773 | check_put(void *cls, const struct DataMessage *dm) |
778 | { | 774 | { |
779 | if (GNUNET_OK != check_data (dm)) | 775 | if (GNUNET_OK != check_data(dm)) |
780 | { | 776 | { |
781 | GNUNET_break (0); | 777 | GNUNET_break(0); |
782 | return GNUNET_SYSERR; | 778 | return GNUNET_SYSERR; |
783 | } | 779 | } |
784 | return GNUNET_OK; | 780 | return GNUNET_OK; |
785 | } | 781 | } |
786 | 782 | ||
@@ -792,53 +788,53 @@ check_put (void *cls, const struct DataMessage *dm) | |||
792 | * @param message the actual message | 788 | * @param message the actual message |
793 | */ | 789 | */ |
794 | static void | 790 | static void |
795 | handle_put (void *cls, const struct DataMessage *dm) | 791 | handle_put(void *cls, const struct DataMessage *dm) |
796 | { | 792 | { |
797 | struct GNUNET_SERVICE_Client *client = cls; | 793 | struct GNUNET_SERVICE_Client *client = cls; |
798 | int rid; | 794 | int rid; |
799 | struct ReservationList *pos; | 795 | struct ReservationList *pos; |
800 | uint32_t size; | 796 | uint32_t size; |
801 | 797 | ||
802 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 798 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
803 | "Processing PUT request for `%s' of type %u\n", | 799 | "Processing PUT request for `%s' of type %u\n", |
804 | GNUNET_h2s (&dm->key), | 800 | GNUNET_h2s(&dm->key), |
805 | (uint32_t) ntohl (dm->type)); | 801 | (uint32_t)ntohl(dm->type)); |
806 | rid = ntohl (dm->rid); | 802 | rid = ntohl(dm->rid); |
807 | size = ntohl (dm->size); | 803 | size = ntohl(dm->size); |
808 | if (rid > 0) | 804 | if (rid > 0) |
809 | { | ||
810 | pos = reservations; | ||
811 | while ((NULL != pos) && (rid != pos->rid)) | ||
812 | pos = pos->next; | ||
813 | GNUNET_break (pos != NULL); | ||
814 | if (NULL != pos) | ||
815 | { | 805 | { |
816 | GNUNET_break (pos->entries > 0); | 806 | pos = reservations; |
817 | GNUNET_break (pos->amount >= size); | 807 | while ((NULL != pos) && (rid != pos->rid)) |
818 | pos->entries--; | 808 | pos = pos->next; |
819 | pos->amount -= size; | 809 | GNUNET_break(pos != NULL); |
820 | reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD); | 810 | if (NULL != pos) |
821 | GNUNET_STATISTICS_set (stats, | 811 | { |
822 | gettext_noop ("# reserved"), | 812 | GNUNET_break(pos->entries > 0); |
823 | reserved, | 813 | GNUNET_break(pos->amount >= size); |
824 | GNUNET_NO); | 814 | pos->entries--; |
815 | pos->amount -= size; | ||
816 | reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD); | ||
817 | GNUNET_STATISTICS_set(stats, | ||
818 | gettext_noop("# reserved"), | ||
819 | reserved, | ||
820 | GNUNET_NO); | ||
821 | } | ||
825 | } | 822 | } |
826 | } | ||
827 | bool absent = | 823 | bool absent = |
828 | GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key); | 824 | GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test(filter, &dm->key); |
829 | plugin->api->put (plugin->api->cls, | 825 | plugin->api->put(plugin->api->cls, |
830 | &dm->key, | 826 | &dm->key, |
831 | absent, | 827 | absent, |
832 | ntohl (dm->size), | 828 | ntohl(dm->size), |
833 | &dm[1], | 829 | &dm[1], |
834 | ntohl (dm->type), | 830 | ntohl(dm->type), |
835 | ntohl (dm->priority), | 831 | ntohl(dm->priority), |
836 | ntohl (dm->anonymity), | 832 | ntohl(dm->anonymity), |
837 | ntohl (dm->replication), | 833 | ntohl(dm->replication), |
838 | GNUNET_TIME_absolute_ntoh (dm->expiration), | 834 | GNUNET_TIME_absolute_ntoh(dm->expiration), |
839 | &put_continuation, | 835 | &put_continuation, |
840 | client); | 836 | client); |
841 | GNUNET_SERVICE_client_continue (client); | 837 | GNUNET_SERVICE_client_continue(client); |
842 | } | 838 | } |
843 | 839 | ||
844 | 840 | ||
@@ -849,25 +845,25 @@ handle_put (void *cls, const struct DataMessage *dm) | |||
849 | * @param msg the actual message | 845 | * @param msg the actual message |
850 | */ | 846 | */ |
851 | static void | 847 | static void |
852 | handle_get (void *cls, const struct GetMessage *msg) | 848 | handle_get(void *cls, const struct GetMessage *msg) |
853 | { | 849 | { |
854 | struct GNUNET_SERVICE_Client *client = cls; | 850 | struct GNUNET_SERVICE_Client *client = cls; |
855 | 851 | ||
856 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 852 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
857 | "Processing GET request of type %u\n", | 853 | "Processing GET request of type %u\n", |
858 | (uint32_t) ntohl (msg->type)); | 854 | (uint32_t)ntohl(msg->type)); |
859 | GNUNET_STATISTICS_update (stats, | 855 | GNUNET_STATISTICS_update(stats, |
860 | gettext_noop ("# GET requests received"), | 856 | gettext_noop("# GET requests received"), |
861 | 1, | 857 | 1, |
862 | GNUNET_NO); | 858 | GNUNET_NO); |
863 | plugin->api->get_key (plugin->api->cls, | 859 | plugin->api->get_key(plugin->api->cls, |
864 | GNUNET_ntohll (msg->next_uid), | 860 | GNUNET_ntohll(msg->next_uid), |
865 | msg->random, | 861 | msg->random, |
866 | NULL, | 862 | NULL, |
867 | ntohl (msg->type), | 863 | ntohl(msg->type), |
868 | &transmit_item, | 864 | &transmit_item, |
869 | client); | 865 | client); |
870 | GNUNET_SERVICE_client_continue (client); | 866 | GNUNET_SERVICE_client_continue(client); |
871 | } | 867 | } |
872 | 868 | ||
873 | 869 | ||
@@ -878,50 +874,50 @@ handle_get (void *cls, const struct GetMessage *msg) | |||
878 | * @param msg the actual message | 874 | * @param msg the actual message |
879 | */ | 875 | */ |
880 | static void | 876 | static void |
881 | handle_get_key (void *cls, const struct GetKeyMessage *msg) | 877 | handle_get_key(void *cls, const struct GetKeyMessage *msg) |
882 | { | 878 | { |
883 | struct GNUNET_SERVICE_Client *client = cls; | 879 | struct GNUNET_SERVICE_Client *client = cls; |
884 | 880 | ||
885 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 881 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
886 | "Processing GET request for `%s' of type %u\n", | 882 | "Processing GET request for `%s' of type %u\n", |
887 | GNUNET_h2s (&msg->key), | 883 | GNUNET_h2s(&msg->key), |
888 | (uint32_t) ntohl (msg->type)); | 884 | (uint32_t)ntohl(msg->type)); |
889 | GNUNET_STATISTICS_update (stats, | 885 | GNUNET_STATISTICS_update(stats, |
890 | gettext_noop ("# GET KEY requests received"), | 886 | gettext_noop("# GET KEY requests received"), |
891 | 1, | 887 | 1, |
892 | GNUNET_NO); | 888 | GNUNET_NO); |
893 | if (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key)) | 889 | if (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test(filter, &msg->key)) |
894 | { | 890 | { |
895 | /* don't bother database... */ | 891 | /* don't bother database... */ |
896 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 892 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
897 | "Empty result set for GET request for `%s' (bloomfilter).\n", | 893 | "Empty result set for GET request for `%s' (bloomfilter).\n", |
898 | GNUNET_h2s (&msg->key)); | 894 | GNUNET_h2s(&msg->key)); |
899 | GNUNET_STATISTICS_update (stats, | 895 | GNUNET_STATISTICS_update(stats, |
900 | gettext_noop ( | 896 | gettext_noop( |
901 | "# requests filtered by bloomfilter"), | 897 | "# requests filtered by bloomfilter"), |
902 | 1, | 898 | 1, |
903 | GNUNET_NO); | 899 | GNUNET_NO); |
904 | transmit_item (client, | 900 | transmit_item(client, |
905 | NULL, | 901 | NULL, |
906 | 0, | 902 | 0, |
907 | NULL, | 903 | NULL, |
908 | 0, | 904 | 0, |
909 | 0, | 905 | 0, |
910 | 0, | 906 | 0, |
911 | 0, | 907 | 0, |
912 | GNUNET_TIME_UNIT_ZERO_ABS, | 908 | GNUNET_TIME_UNIT_ZERO_ABS, |
913 | 0); | 909 | 0); |
914 | GNUNET_SERVICE_client_continue (client); | 910 | GNUNET_SERVICE_client_continue(client); |
915 | return; | 911 | return; |
916 | } | 912 | } |
917 | plugin->api->get_key (plugin->api->cls, | 913 | plugin->api->get_key(plugin->api->cls, |
918 | GNUNET_ntohll (msg->next_uid), | 914 | GNUNET_ntohll(msg->next_uid), |
919 | msg->random, | 915 | msg->random, |
920 | &msg->key, | 916 | &msg->key, |
921 | ntohl (msg->type), | 917 | ntohl(msg->type), |
922 | &transmit_item, | 918 | &transmit_item, |
923 | client); | 919 | client); |
924 | GNUNET_SERVICE_client_continue (client); | 920 | GNUNET_SERVICE_client_continue(client); |
925 | } | 921 | } |
926 | 922 | ||
927 | 923 | ||
@@ -932,18 +928,18 @@ handle_get_key (void *cls, const struct GetKeyMessage *msg) | |||
932 | * @param message the actual message | 928 | * @param message the actual message |
933 | */ | 929 | */ |
934 | static void | 930 | static void |
935 | handle_get_replication (void *cls, const struct GNUNET_MessageHeader *message) | 931 | handle_get_replication(void *cls, const struct GNUNET_MessageHeader *message) |
936 | { | 932 | { |
937 | struct GNUNET_SERVICE_Client *client = cls; | 933 | struct GNUNET_SERVICE_Client *client = cls; |
938 | 934 | ||
939 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing GET_REPLICATION request\n"); | 935 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing GET_REPLICATION request\n"); |
940 | GNUNET_STATISTICS_update (stats, | 936 | GNUNET_STATISTICS_update(stats, |
941 | gettext_noop ( | 937 | gettext_noop( |
942 | "# GET REPLICATION requests received"), | 938 | "# GET REPLICATION requests received"), |
943 | 1, | 939 | 1, |
944 | GNUNET_NO); | 940 | GNUNET_NO); |
945 | plugin->api->get_replication (plugin->api->cls, &transmit_item, client); | 941 | plugin->api->get_replication(plugin->api->cls, &transmit_item, client); |
946 | GNUNET_SERVICE_client_continue (client); | 942 | GNUNET_SERVICE_client_continue(client); |
947 | } | 943 | } |
948 | 944 | ||
949 | 945 | ||
@@ -954,31 +950,31 @@ handle_get_replication (void *cls, const struct GNUNET_MessageHeader *message) | |||
954 | * @param message the actual message | 950 | * @param message the actual message |
955 | */ | 951 | */ |
956 | static void | 952 | static void |
957 | handle_get_zero_anonymity (void *cls, const struct GetZeroAnonymityMessage *msg) | 953 | handle_get_zero_anonymity(void *cls, const struct GetZeroAnonymityMessage *msg) |
958 | { | 954 | { |
959 | struct GNUNET_SERVICE_Client *client = cls; | 955 | struct GNUNET_SERVICE_Client *client = cls; |
960 | enum GNUNET_BLOCK_Type type; | 956 | enum GNUNET_BLOCK_Type type; |
961 | 957 | ||
962 | type = (enum GNUNET_BLOCK_Type) ntohl (msg->type); | 958 | type = (enum GNUNET_BLOCK_Type)ntohl(msg->type); |
963 | if (type == GNUNET_BLOCK_TYPE_ANY) | 959 | if (type == GNUNET_BLOCK_TYPE_ANY) |
964 | { | 960 | { |
965 | GNUNET_break (0); | 961 | GNUNET_break(0); |
966 | GNUNET_SERVICE_client_drop (client); | 962 | GNUNET_SERVICE_client_drop(client); |
967 | return; | 963 | return; |
968 | } | 964 | } |
969 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 965 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
970 | "Processing GET_ZERO_ANONYMITY request\n"); | 966 | "Processing GET_ZERO_ANONYMITY request\n"); |
971 | GNUNET_STATISTICS_update (stats, | 967 | GNUNET_STATISTICS_update(stats, |
972 | gettext_noop ( | 968 | gettext_noop( |
973 | "# GET ZERO ANONYMITY requests received"), | 969 | "# GET ZERO ANONYMITY requests received"), |
974 | 1, | 970 | 1, |
975 | GNUNET_NO); | 971 | GNUNET_NO); |
976 | plugin->api->get_zero_anonymity (plugin->api->cls, | 972 | plugin->api->get_zero_anonymity(plugin->api->cls, |
977 | GNUNET_ntohll (msg->next_uid), | 973 | GNUNET_ntohll(msg->next_uid), |
978 | type, | 974 | type, |
979 | &transmit_item, | 975 | &transmit_item, |
980 | client); | 976 | client); |
981 | GNUNET_SERVICE_client_continue (client); | 977 | GNUNET_SERVICE_client_continue(client); |
982 | } | 978 | } |
983 | 979 | ||
984 | 980 | ||
@@ -993,36 +989,36 @@ handle_get_zero_anonymity (void *cls, const struct GetZeroAnonymityMessage *msg) | |||
993 | * @param msg error message on error | 989 | * @param msg error message on error |
994 | */ | 990 | */ |
995 | static void | 991 | static void |
996 | remove_continuation (void *cls, | 992 | remove_continuation(void *cls, |
997 | const struct GNUNET_HashCode *key, | 993 | const struct GNUNET_HashCode *key, |
998 | uint32_t size, | 994 | uint32_t size, |
999 | int status, | 995 | int status, |
1000 | const char *msg) | 996 | const char *msg) |
1001 | { | 997 | { |
1002 | struct GNUNET_SERVICE_Client *client = cls; | 998 | struct GNUNET_SERVICE_Client *client = cls; |
1003 | 999 | ||
1004 | if (GNUNET_SYSERR == status) | 1000 | if (GNUNET_SYSERR == status) |
1005 | { | 1001 | { |
1006 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "REMOVE request failed: %s.\n", msg); | 1002 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "REMOVE request failed: %s.\n", msg); |
1007 | transmit_status (client, GNUNET_NO, msg); | 1003 | transmit_status(client, GNUNET_NO, msg); |
1008 | return; | 1004 | return; |
1009 | } | 1005 | } |
1010 | if (GNUNET_NO == status) | 1006 | if (GNUNET_NO == status) |
1011 | { | 1007 | { |
1012 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1008 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1013 | "Content not found for REMOVE request.\n"); | 1009 | "Content not found for REMOVE request.\n"); |
1014 | transmit_status (client, GNUNET_NO, _ ("Content not found")); | 1010 | transmit_status(client, GNUNET_NO, _("Content not found")); |
1015 | return; | 1011 | return; |
1016 | } | 1012 | } |
1017 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1013 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1018 | "Item matches REMOVE request for key `%s'.\n", | 1014 | "Item matches REMOVE request for key `%s'.\n", |
1019 | GNUNET_h2s (key)); | 1015 | GNUNET_h2s(key)); |
1020 | GNUNET_STATISTICS_update (stats, | 1016 | GNUNET_STATISTICS_update(stats, |
1021 | gettext_noop ("# bytes removed (explicit request)"), | 1017 | gettext_noop("# bytes removed (explicit request)"), |
1022 | size, | 1018 | size, |
1023 | GNUNET_YES); | 1019 | GNUNET_YES); |
1024 | GNUNET_CONTAINER_bloomfilter_remove (filter, key); | 1020 | GNUNET_CONTAINER_bloomfilter_remove(filter, key); |
1025 | transmit_status (client, GNUNET_OK, NULL); | 1021 | transmit_status(client, GNUNET_OK, NULL); |
1026 | } | 1022 | } |
1027 | 1023 | ||
1028 | 1024 | ||
@@ -1034,13 +1030,13 @@ remove_continuation (void *cls, | |||
1034 | * @return #GNUNET_OK if @a dm is well-formed | 1030 | * @return #GNUNET_OK if @a dm is well-formed |
1035 | */ | 1031 | */ |
1036 | static int | 1032 | static int |
1037 | check_remove (void *cls, const struct DataMessage *dm) | 1033 | check_remove(void *cls, const struct DataMessage *dm) |
1038 | { | 1034 | { |
1039 | if (GNUNET_OK != check_data (dm)) | 1035 | if (GNUNET_OK != check_data(dm)) |
1040 | { | 1036 | { |
1041 | GNUNET_break (0); | 1037 | GNUNET_break(0); |
1042 | return GNUNET_SYSERR; | 1038 | return GNUNET_SYSERR; |
1043 | } | 1039 | } |
1044 | return GNUNET_OK; | 1040 | return GNUNET_OK; |
1045 | } | 1041 | } |
1046 | 1042 | ||
@@ -1053,24 +1049,24 @@ check_remove (void *cls, const struct DataMessage *dm) | |||
1053 | * @param message the actual message | 1049 | * @param message the actual message |
1054 | */ | 1050 | */ |
1055 | static void | 1051 | static void |
1056 | handle_remove (void *cls, const struct DataMessage *dm) | 1052 | handle_remove(void *cls, const struct DataMessage *dm) |
1057 | { | 1053 | { |
1058 | struct GNUNET_SERVICE_Client *client = cls; | 1054 | struct GNUNET_SERVICE_Client *client = cls; |
1059 | 1055 | ||
1060 | GNUNET_STATISTICS_update (stats, | 1056 | GNUNET_STATISTICS_update(stats, |
1061 | gettext_noop ("# REMOVE requests received"), | 1057 | gettext_noop("# REMOVE requests received"), |
1062 | 1, | 1058 | 1, |
1063 | GNUNET_NO); | 1059 | GNUNET_NO); |
1064 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1060 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1065 | "Processing REMOVE request for `%s'\n", | 1061 | "Processing REMOVE request for `%s'\n", |
1066 | GNUNET_h2s (&dm->key)); | 1062 | GNUNET_h2s(&dm->key)); |
1067 | plugin->api->remove_key (plugin->api->cls, | 1063 | plugin->api->remove_key(plugin->api->cls, |
1068 | &dm->key, | 1064 | &dm->key, |
1069 | ntohl (dm->size), | 1065 | ntohl(dm->size), |
1070 | &dm[1], | 1066 | &dm[1], |
1071 | &remove_continuation, | 1067 | &remove_continuation, |
1072 | client); | 1068 | client); |
1073 | GNUNET_SERVICE_client_continue (client); | 1069 | GNUNET_SERVICE_client_continue(client); |
1074 | } | 1070 | } |
1075 | 1071 | ||
1076 | 1072 | ||
@@ -1081,13 +1077,13 @@ handle_remove (void *cls, const struct DataMessage *dm) | |||
1081 | * @param message the actual message | 1077 | * @param message the actual message |
1082 | */ | 1078 | */ |
1083 | static void | 1079 | static void |
1084 | handle_drop (void *cls, const struct GNUNET_MessageHeader *message) | 1080 | handle_drop(void *cls, const struct GNUNET_MessageHeader *message) |
1085 | { | 1081 | { |
1086 | struct GNUNET_SERVICE_Client *client = cls; | 1082 | struct GNUNET_SERVICE_Client *client = cls; |
1087 | 1083 | ||
1088 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing DROP request\n"); | 1084 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing DROP request\n"); |
1089 | do_drop = GNUNET_YES; | 1085 | do_drop = GNUNET_YES; |
1090 | GNUNET_SERVICE_client_continue (client); | 1086 | GNUNET_SERVICE_client_continue(client); |
1091 | } | 1087 | } |
1092 | 1088 | ||
1093 | 1089 | ||
@@ -1100,27 +1096,27 @@ handle_drop (void *cls, const struct GNUNET_MessageHeader *message) | |||
1100 | * 0 for "reset to empty" | 1096 | * 0 for "reset to empty" |
1101 | */ | 1097 | */ |
1102 | static void | 1098 | static void |
1103 | disk_utilization_change_cb (void *cls, int delta) | 1099 | disk_utilization_change_cb(void *cls, int delta) |
1104 | { | 1100 | { |
1105 | if ((delta < 0) && (payload < -delta)) | 1101 | if ((delta < 0) && (payload < -delta)) |
1106 | { | 1102 | { |
1107 | GNUNET_log ( | 1103 | GNUNET_log( |
1108 | GNUNET_ERROR_TYPE_WARNING, | 1104 | GNUNET_ERROR_TYPE_WARNING, |
1109 | _ ( | 1105 | _( |
1110 | "Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"), | 1106 | "Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"), |
1111 | (long long) payload, | 1107 | (long long)payload, |
1112 | (long long) -delta); | 1108 | (long long)-delta); |
1113 | plugin->api->estimate_size (plugin->api->cls, &payload); | 1109 | plugin->api->estimate_size(plugin->api->cls, &payload); |
1114 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1110 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1115 | _ ("New payload: %lld\n"), | 1111 | _("New payload: %lld\n"), |
1116 | (long long) payload); | 1112 | (long long)payload); |
1117 | sync_stats (); | 1113 | sync_stats(); |
1118 | return; | 1114 | return; |
1119 | } | 1115 | } |
1120 | payload += delta; | 1116 | payload += delta; |
1121 | last_sync++; | 1117 | last_sync++; |
1122 | if (last_sync >= MAX_STAT_SYNC_LAG) | 1118 | if (last_sync >= MAX_STAT_SYNC_LAG) |
1123 | sync_stats (); | 1119 | sync_stats(); |
1124 | } | 1120 | } |
1125 | 1121 | ||
1126 | 1122 | ||
@@ -1135,20 +1131,20 @@ disk_utilization_change_cb (void *cls, int delta) | |||
1135 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 1131 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
1136 | */ | 1132 | */ |
1137 | static int | 1133 | static int |
1138 | process_stat_in (void *cls, | 1134 | process_stat_in(void *cls, |
1139 | const char *subsystem, | 1135 | const char *subsystem, |
1140 | const char *name, | 1136 | const char *name, |
1141 | uint64_t value, | 1137 | uint64_t value, |
1142 | int is_persistent) | 1138 | int is_persistent) |
1143 | { | 1139 | { |
1144 | GNUNET_assert (GNUNET_NO == stats_worked); | 1140 | GNUNET_assert(GNUNET_NO == stats_worked); |
1145 | stats_worked = GNUNET_YES; | 1141 | stats_worked = GNUNET_YES; |
1146 | payload += value; | 1142 | payload += value; |
1147 | GNUNET_log ( | 1143 | GNUNET_log( |
1148 | GNUNET_ERROR_TYPE_DEBUG, | 1144 | GNUNET_ERROR_TYPE_DEBUG, |
1149 | "Notification from statistics about existing payload (%llu), new payload is %llu\n", | 1145 | "Notification from statistics about existing payload (%llu), new payload is %llu\n", |
1150 | (unsigned long long) value, | 1146 | (unsigned long long)value, |
1151 | (unsigned long long) payload); | 1147 | (unsigned long long)payload); |
1152 | return GNUNET_OK; | 1148 | return GNUNET_OK; |
1153 | } | 1149 | } |
1154 | 1150 | ||
@@ -1157,32 +1153,32 @@ process_stat_in (void *cls, | |||
1157 | * Load the datastore plugin. | 1153 | * Load the datastore plugin. |
1158 | */ | 1154 | */ |
1159 | static struct DatastorePlugin * | 1155 | static struct DatastorePlugin * |
1160 | load_plugin () | 1156 | load_plugin() |
1161 | { | 1157 | { |
1162 | struct DatastorePlugin *ret; | 1158 | struct DatastorePlugin *ret; |
1163 | char *libname; | 1159 | char *libname; |
1164 | 1160 | ||
1165 | ret = GNUNET_new (struct DatastorePlugin); | 1161 | ret = GNUNET_new(struct DatastorePlugin); |
1166 | ret->env.cfg = cfg; | 1162 | ret->env.cfg = cfg; |
1167 | ret->env.duc = &disk_utilization_change_cb; | 1163 | ret->env.duc = &disk_utilization_change_cb; |
1168 | ret->env.cls = NULL; | 1164 | ret->env.cls = NULL; |
1169 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1165 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1170 | _ ("Loading `%s' datastore plugin\n"), | 1166 | _("Loading `%s' datastore plugin\n"), |
1171 | plugin_name); | 1167 | plugin_name); |
1172 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", plugin_name); | 1168 | GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", plugin_name); |
1173 | ret->short_name = GNUNET_strdup (plugin_name); | 1169 | ret->short_name = GNUNET_strdup(plugin_name); |
1174 | ret->lib_name = libname; | 1170 | ret->lib_name = libname; |
1175 | ret->api = GNUNET_PLUGIN_load (libname, &ret->env); | 1171 | ret->api = GNUNET_PLUGIN_load(libname, &ret->env); |
1176 | if (NULL == ret->api) | 1172 | if (NULL == ret->api) |
1177 | { | 1173 | { |
1178 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1174 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1179 | _ ("Failed to load datastore plugin for `%s'\n"), | 1175 | _("Failed to load datastore plugin for `%s'\n"), |
1180 | plugin_name); | 1176 | plugin_name); |
1181 | GNUNET_free (ret->short_name); | 1177 | GNUNET_free(ret->short_name); |
1182 | GNUNET_free (libname); | 1178 | GNUNET_free(libname); |
1183 | GNUNET_free (ret); | 1179 | GNUNET_free(ret); |
1184 | return NULL; | 1180 | return NULL; |
1185 | } | 1181 | } |
1186 | return ret; | 1182 | return ret; |
1187 | } | 1183 | } |
1188 | 1184 | ||
@@ -1194,14 +1190,14 @@ load_plugin () | |||
1194 | * @param plug plugin to unload | 1190 | * @param plug plugin to unload |
1195 | */ | 1191 | */ |
1196 | static void | 1192 | static void |
1197 | unload_plugin (struct DatastorePlugin *plug) | 1193 | unload_plugin(struct DatastorePlugin *plug) |
1198 | { | 1194 | { |
1199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1195 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1200 | "Datastore service is unloading plugin...\n"); | 1196 | "Datastore service is unloading plugin...\n"); |
1201 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api)); | 1197 | GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api)); |
1202 | GNUNET_free (plug->lib_name); | 1198 | GNUNET_free(plug->lib_name); |
1203 | GNUNET_free (plug->short_name); | 1199 | GNUNET_free(plug->short_name); |
1204 | GNUNET_free (plug); | 1200 | GNUNET_free(plug); |
1205 | } | 1201 | } |
1206 | 1202 | ||
1207 | 1203 | ||
@@ -1209,13 +1205,13 @@ unload_plugin (struct DatastorePlugin *plug) | |||
1209 | * Initialization complete, start operating the service. | 1205 | * Initialization complete, start operating the service. |
1210 | */ | 1206 | */ |
1211 | static void | 1207 | static void |
1212 | begin_service () | 1208 | begin_service() |
1213 | { | 1209 | { |
1214 | GNUNET_SERVICE_resume (service); | 1210 | GNUNET_SERVICE_resume(service); |
1215 | expired_kill_task = | 1211 | expired_kill_task = |
1216 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1212 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, |
1217 | &delete_expired, | 1213 | &delete_expired, |
1218 | NULL); | 1214 | NULL); |
1219 | } | 1215 | } |
1220 | 1216 | ||
1221 | 1217 | ||
@@ -1227,22 +1223,22 @@ begin_service () | |||
1227 | * @param count number of times to add key | 1223 | * @param count number of times to add key |
1228 | */ | 1224 | */ |
1229 | static void | 1225 | static void |
1230 | add_key_to_bloomfilter (void *cls, | 1226 | add_key_to_bloomfilter(void *cls, |
1231 | const struct GNUNET_HashCode *key, | 1227 | const struct GNUNET_HashCode *key, |
1232 | unsigned int count) | 1228 | unsigned int count) |
1233 | { | 1229 | { |
1234 | struct GNUNET_CONTAINER_BloomFilter *bf = cls; | 1230 | struct GNUNET_CONTAINER_BloomFilter *bf = cls; |
1235 | 1231 | ||
1236 | if (NULL == key) | 1232 | if (NULL == key) |
1237 | { | 1233 | { |
1238 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1234 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1239 | _ ("Bloomfilter construction complete.\n")); | 1235 | _("Bloomfilter construction complete.\n")); |
1240 | begin_service (); | 1236 | begin_service(); |
1241 | return; | 1237 | return; |
1242 | } | 1238 | } |
1243 | 1239 | ||
1244 | while (0 < count--) | 1240 | while (0 < count--) |
1245 | GNUNET_CONTAINER_bloomfilter_add (bf, key); | 1241 | GNUNET_CONTAINER_bloomfilter_add(bf, key); |
1246 | } | 1242 | } |
1247 | 1243 | ||
1248 | 1244 | ||
@@ -1254,54 +1250,54 @@ add_key_to_bloomfilter (void *cls, | |||
1254 | * @param success #GNUNET_NO if we failed to read the stat | 1250 | * @param success #GNUNET_NO if we failed to read the stat |
1255 | */ | 1251 | */ |
1256 | static void | 1252 | static void |
1257 | process_stat_done (void *cls, int success) | 1253 | process_stat_done(void *cls, int success) |
1258 | { | 1254 | { |
1259 | stat_get = NULL; | 1255 | stat_get = NULL; |
1260 | if (NULL != stat_timeout_task) | 1256 | if (NULL != stat_timeout_task) |
1261 | { | 1257 | { |
1262 | GNUNET_SCHEDULER_cancel (stat_timeout_task); | 1258 | GNUNET_SCHEDULER_cancel(stat_timeout_task); |
1263 | stat_timeout_task = NULL; | 1259 | stat_timeout_task = NULL; |
1264 | } | 1260 | } |
1265 | plugin = load_plugin (); | 1261 | plugin = load_plugin(); |
1266 | if (NULL == plugin) | 1262 | if (NULL == plugin) |
1267 | { | ||
1268 | GNUNET_CONTAINER_bloomfilter_free (filter); | ||
1269 | filter = NULL; | ||
1270 | if (NULL != stats) | ||
1271 | { | 1263 | { |
1272 | GNUNET_STATISTICS_destroy (stats, GNUNET_YES); | 1264 | GNUNET_CONTAINER_bloomfilter_free(filter); |
1273 | stats = NULL; | 1265 | filter = NULL; |
1266 | if (NULL != stats) | ||
1267 | { | ||
1268 | GNUNET_STATISTICS_destroy(stats, GNUNET_YES); | ||
1269 | stats = NULL; | ||
1270 | } | ||
1271 | return; | ||
1274 | } | 1272 | } |
1275 | return; | ||
1276 | } | ||
1277 | 1273 | ||
1278 | if (GNUNET_NO == stats_worked) | 1274 | if (GNUNET_NO == stats_worked) |
1279 | { | ||
1280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1281 | "Failed to obtain value from statistics service, recomputing it\n"); | ||
1282 | plugin->api->estimate_size (plugin->api->cls, &payload); | ||
1283 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1284 | _ ("New payload: %lld\n"), | ||
1285 | (long long) payload); | ||
1286 | } | ||
1287 | |||
1288 | if (GNUNET_YES == refresh_bf) | ||
1289 | { | ||
1290 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1291 | _ ("Rebuilding bloomfilter. Please be patient.\n")); | ||
1292 | if (NULL != plugin->api->get_keys) | ||
1293 | { | 1275 | { |
1294 | plugin->api->get_keys (plugin->api->cls, &add_key_to_bloomfilter, filter); | 1276 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1295 | return; | 1277 | "Failed to obtain value from statistics service, recomputing it\n"); |
1278 | plugin->api->estimate_size(plugin->api->cls, &payload); | ||
1279 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1280 | _("New payload: %lld\n"), | ||
1281 | (long long)payload); | ||
1296 | } | 1282 | } |
1297 | else | 1283 | |
1284 | if (GNUNET_YES == refresh_bf) | ||
1298 | { | 1285 | { |
1299 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1286 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1300 | _ ( | 1287 | _("Rebuilding bloomfilter. Please be patient.\n")); |
1301 | "Plugin does not support get_keys function. Please fix!\n")); | 1288 | if (NULL != plugin->api->get_keys) |
1289 | { | ||
1290 | plugin->api->get_keys(plugin->api->cls, &add_key_to_bloomfilter, filter); | ||
1291 | return; | ||
1292 | } | ||
1293 | else | ||
1294 | { | ||
1295 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1296 | _( | ||
1297 | "Plugin does not support get_keys function. Please fix!\n")); | ||
1298 | } | ||
1302 | } | 1299 | } |
1303 | } | 1300 | begin_service(); |
1304 | begin_service (); | ||
1305 | } | 1301 | } |
1306 | 1302 | ||
1307 | 1303 | ||
@@ -1311,11 +1307,11 @@ process_stat_done (void *cls, int success) | |||
1311 | * @param cls NULL | 1307 | * @param cls NULL |
1312 | */ | 1308 | */ |
1313 | static void | 1309 | static void |
1314 | stat_timeout (void *cls) | 1310 | stat_timeout(void *cls) |
1315 | { | 1311 | { |
1316 | stat_timeout_task = NULL; | 1312 | stat_timeout_task = NULL; |
1317 | GNUNET_STATISTICS_get_cancel (stat_get); | 1313 | GNUNET_STATISTICS_get_cancel(stat_get); |
1318 | process_stat_done (NULL, GNUNET_NO); | 1314 | process_stat_done(NULL, GNUNET_NO); |
1319 | } | 1315 | } |
1320 | 1316 | ||
1321 | 1317 | ||
@@ -1323,51 +1319,51 @@ stat_timeout (void *cls) | |||
1323 | * Task run during shutdown. | 1319 | * Task run during shutdown. |
1324 | */ | 1320 | */ |
1325 | static void | 1321 | static void |
1326 | cleaning_task (void *cls) | 1322 | cleaning_task(void *cls) |
1327 | { | 1323 | { |
1328 | cleaning_done = GNUNET_YES; | 1324 | cleaning_done = GNUNET_YES; |
1329 | if (NULL != expired_kill_task) | 1325 | if (NULL != expired_kill_task) |
1330 | { | 1326 | { |
1331 | GNUNET_SCHEDULER_cancel (expired_kill_task); | 1327 | GNUNET_SCHEDULER_cancel(expired_kill_task); |
1332 | expired_kill_task = NULL; | 1328 | expired_kill_task = NULL; |
1333 | } | 1329 | } |
1334 | if (GNUNET_YES == do_drop) | 1330 | if (GNUNET_YES == do_drop) |
1335 | { | 1331 | { |
1336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dropping database!\n"); | 1332 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Dropping database!\n"); |
1337 | plugin->api->drop (plugin->api->cls); | 1333 | plugin->api->drop(plugin->api->cls); |
1338 | payload = 0; | 1334 | payload = 0; |
1339 | last_sync++; | 1335 | last_sync++; |
1340 | } | 1336 | } |
1341 | if (NULL != plugin) | 1337 | if (NULL != plugin) |
1342 | { | 1338 | { |
1343 | unload_plugin (plugin); | 1339 | unload_plugin(plugin); |
1344 | plugin = NULL; | 1340 | plugin = NULL; |
1345 | } | 1341 | } |
1346 | if (NULL != filter) | 1342 | if (NULL != filter) |
1347 | { | 1343 | { |
1348 | GNUNET_CONTAINER_bloomfilter_free (filter); | 1344 | GNUNET_CONTAINER_bloomfilter_free(filter); |
1349 | filter = NULL; | 1345 | filter = NULL; |
1350 | } | 1346 | } |
1351 | if (NULL != stat_get) | 1347 | if (NULL != stat_get) |
1352 | { | 1348 | { |
1353 | GNUNET_STATISTICS_get_cancel (stat_get); | 1349 | GNUNET_STATISTICS_get_cancel(stat_get); |
1354 | stat_get = NULL; | 1350 | stat_get = NULL; |
1355 | } | 1351 | } |
1356 | if (NULL != stat_timeout_task) | 1352 | if (NULL != stat_timeout_task) |
1357 | { | 1353 | { |
1358 | GNUNET_SCHEDULER_cancel (stat_timeout_task); | 1354 | GNUNET_SCHEDULER_cancel(stat_timeout_task); |
1359 | stat_timeout_task = NULL; | 1355 | stat_timeout_task = NULL; |
1360 | } | 1356 | } |
1361 | GNUNET_free_non_null (plugin_name); | 1357 | GNUNET_free_non_null(plugin_name); |
1362 | plugin_name = NULL; | 1358 | plugin_name = NULL; |
1363 | if (last_sync > 0) | 1359 | if (last_sync > 0) |
1364 | sync_stats (); | 1360 | sync_stats(); |
1365 | if (NULL != stats) | 1361 | if (NULL != stats) |
1366 | { | 1362 | { |
1367 | GNUNET_STATISTICS_destroy (stats, GNUNET_YES); | 1363 | GNUNET_STATISTICS_destroy(stats, GNUNET_YES); |
1368 | stats = NULL; | 1364 | stats = NULL; |
1369 | } | 1365 | } |
1370 | GNUNET_free (quota_stat_name); | 1366 | GNUNET_free(quota_stat_name); |
1371 | quota_stat_name = NULL; | 1367 | quota_stat_name = NULL; |
1372 | } | 1368 | } |
1373 | 1369 | ||
@@ -1381,9 +1377,9 @@ cleaning_task (void *cls) | |||
1381 | * @return @a client | 1377 | * @return @a client |
1382 | */ | 1378 | */ |
1383 | static void * | 1379 | static void * |
1384 | client_connect_cb (void *cls, | 1380 | client_connect_cb(void *cls, |
1385 | struct GNUNET_SERVICE_Client *client, | 1381 | struct GNUNET_SERVICE_Client *client, |
1386 | struct GNUNET_MQ_Handle *mq) | 1382 | struct GNUNET_MQ_Handle *mq) |
1387 | { | 1383 | { |
1388 | return client; | 1384 | return client; |
1389 | } | 1385 | } |
@@ -1398,39 +1394,39 @@ client_connect_cb (void *cls, | |||
1398 | * @param app_ctx must match @a client | 1394 | * @param app_ctx must match @a client |
1399 | */ | 1395 | */ |
1400 | static void | 1396 | static void |
1401 | client_disconnect_cb (void *cls, | 1397 | client_disconnect_cb(void *cls, |
1402 | struct GNUNET_SERVICE_Client *client, | 1398 | struct GNUNET_SERVICE_Client *client, |
1403 | void *app_ctx) | 1399 | void *app_ctx) |
1404 | { | 1400 | { |
1405 | struct ReservationList *pos; | 1401 | struct ReservationList *pos; |
1406 | struct ReservationList *prev; | 1402 | struct ReservationList *prev; |
1407 | struct ReservationList *next; | 1403 | struct ReservationList *next; |
1408 | 1404 | ||
1409 | GNUNET_assert (app_ctx == client); | 1405 | GNUNET_assert(app_ctx == client); |
1410 | prev = NULL; | 1406 | prev = NULL; |
1411 | pos = reservations; | 1407 | pos = reservations; |
1412 | while (NULL != pos) | 1408 | while (NULL != pos) |
1413 | { | ||
1414 | next = pos->next; | ||
1415 | if (pos->client == client) | ||
1416 | { | 1409 | { |
1417 | if (NULL == prev) | 1410 | next = pos->next; |
1418 | reservations = next; | 1411 | if (pos->client == client) |
1412 | { | ||
1413 | if (NULL == prev) | ||
1414 | reservations = next; | ||
1415 | else | ||
1416 | prev->next = next; | ||
1417 | reserved -= pos->amount + pos->entries * GNUNET_DATASTORE_ENTRY_OVERHEAD; | ||
1418 | GNUNET_free(pos); | ||
1419 | } | ||
1419 | else | 1420 | else |
1420 | prev->next = next; | 1421 | { |
1421 | reserved -= pos->amount + pos->entries * GNUNET_DATASTORE_ENTRY_OVERHEAD; | 1422 | prev = pos; |
1422 | GNUNET_free (pos); | 1423 | } |
1423 | } | 1424 | pos = next; |
1424 | else | ||
1425 | { | ||
1426 | prev = pos; | ||
1427 | } | 1425 | } |
1428 | pos = next; | 1426 | GNUNET_STATISTICS_set(stats, |
1429 | } | 1427 | gettext_noop("# reserved"), |
1430 | GNUNET_STATISTICS_set (stats, | 1428 | reserved, |
1431 | gettext_noop ("# reserved"), | 1429 | GNUNET_NO); |
1432 | reserved, | ||
1433 | GNUNET_NO); | ||
1434 | } | 1430 | } |
1435 | 1431 | ||
1436 | 1432 | ||
@@ -1442,9 +1438,9 @@ client_disconnect_cb (void *cls, | |||
1442 | * @param c configuration to use | 1438 | * @param c configuration to use |
1443 | */ | 1439 | */ |
1444 | static void | 1440 | static void |
1445 | run (void *cls, | 1441 | run(void *cls, |
1446 | const struct GNUNET_CONFIGURATION_Handle *c, | 1442 | const struct GNUNET_CONFIGURATION_Handle *c, |
1447 | struct GNUNET_SERVICE_Handle *serv) | 1443 | struct GNUNET_SERVICE_Handle *serv) |
1448 | { | 1444 | { |
1449 | char *fn; | 1445 | char *fn; |
1450 | char *pfn; | 1446 | char *pfn; |
@@ -1452,199 +1448,199 @@ run (void *cls, | |||
1452 | 1448 | ||
1453 | service = serv; | 1449 | service = serv; |
1454 | cfg = c; | 1450 | cfg = c; |
1455 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | 1451 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, |
1456 | "DATASTORE", | 1452 | "DATASTORE", |
1457 | "DATABASE", | 1453 | "DATABASE", |
1458 | &plugin_name)) | 1454 | &plugin_name)) |
1459 | { | 1455 | { |
1460 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 1456 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
1461 | "DATABASE", | 1457 | "DATABASE", |
1462 | "DATASTORE"); | 1458 | "DATASTORE"); |
1463 | return; | 1459 | return; |
1464 | } | 1460 | } |
1465 | GNUNET_asprintf ("a_stat_name, | 1461 | GNUNET_asprintf("a_stat_name, |
1466 | _ ("# bytes used in file-sharing datastore `%s'"), | 1462 | _("# bytes used in file-sharing datastore `%s'"), |
1467 | plugin_name); | 1463 | plugin_name); |
1468 | if (GNUNET_OK != | 1464 | if (GNUNET_OK != |
1469 | GNUNET_CONFIGURATION_get_value_size (cfg, "DATASTORE", "QUOTA", "a)) | 1465 | GNUNET_CONFIGURATION_get_value_size(cfg, "DATASTORE", "QUOTA", "a)) |
1470 | { | 1466 | { |
1471 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "QUOTA", "DATASTORE"); | 1467 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "QUOTA", "DATASTORE"); |
1472 | return; | 1468 | return; |
1473 | } | 1469 | } |
1474 | stats = GNUNET_STATISTICS_create ("datastore", cfg); | 1470 | stats = GNUNET_STATISTICS_create("datastore", cfg); |
1475 | GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO); | 1471 | GNUNET_STATISTICS_set(stats, gettext_noop("# quota"), quota, GNUNET_NO); |
1476 | cache_size = quota / 8; /* Or should we make this an option? */ | 1472 | cache_size = quota / 8; /* Or should we make this an option? */ |
1477 | GNUNET_STATISTICS_set (stats, | 1473 | GNUNET_STATISTICS_set(stats, |
1478 | gettext_noop ("# cache size"), | 1474 | gettext_noop("# cache size"), |
1479 | cache_size, | 1475 | cache_size, |
1480 | GNUNET_NO); | 1476 | GNUNET_NO); |
1481 | if (quota / (32 * 1024LL) > MAX_BF_SIZE) | 1477 | if (quota / (32 * 1024LL) > MAX_BF_SIZE) |
1482 | bf_size = MAX_BF_SIZE; | 1478 | bf_size = MAX_BF_SIZE; |
1483 | else | 1479 | else |
1484 | bf_size = | 1480 | bf_size = |
1485 | quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */ | 1481 | quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */ |
1486 | fn = NULL; | 1482 | fn = NULL; |
1487 | if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, | 1483 | if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, |
1488 | "DATASTORE", | 1484 | "DATASTORE", |
1489 | "BLOOMFILTER", | 1485 | "BLOOMFILTER", |
1490 | &fn)) || | 1486 | &fn)) || |
1491 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn))) | 1487 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file(fn))) |
1492 | { | 1488 | { |
1493 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1489 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1494 | _ ("Could not use specified filename `%s' for bloomfilter.\n"), | 1490 | _("Could not use specified filename `%s' for bloomfilter.\n"), |
1495 | NULL != fn ? fn : ""); | 1491 | NULL != fn ? fn : ""); |
1496 | GNUNET_free_non_null (fn); | 1492 | GNUNET_free_non_null(fn); |
1497 | fn = NULL; | 1493 | fn = NULL; |
1498 | } | 1494 | } |
1499 | if (NULL != fn) | 1495 | if (NULL != fn) |
1500 | { | ||
1501 | GNUNET_asprintf (&pfn, "%s.%s", fn, plugin_name); | ||
1502 | if (GNUNET_YES == GNUNET_DISK_file_test (pfn)) | ||
1503 | { | 1496 | { |
1504 | filter = | 1497 | GNUNET_asprintf(&pfn, "%s.%s", fn, plugin_name); |
1505 | GNUNET_CONTAINER_bloomfilter_load (pfn, | 1498 | if (GNUNET_YES == GNUNET_DISK_file_test(pfn)) |
1506 | bf_size, | ||
1507 | 5); /* approx. 3% false positives at max use */ | ||
1508 | if (NULL == filter) | ||
1509 | { | ||
1510 | /* file exists but not valid, remove and try again, but refresh */ | ||
1511 | if (0 != unlink (pfn)) | ||
1512 | { | 1499 | { |
1513 | /* failed to remove, run without file */ | 1500 | filter = |
1514 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1501 | GNUNET_CONTAINER_bloomfilter_load(pfn, |
1515 | _ ("Failed to remove bogus bloomfilter file `%s'\n"), | 1502 | bf_size, |
1516 | pfn); | 1503 | 5); /* approx. 3% false positives at max use */ |
1517 | GNUNET_free (pfn); | 1504 | if (NULL == filter) |
1518 | pfn = NULL; | 1505 | { |
1519 | filter = GNUNET_CONTAINER_bloomfilter_load ( | 1506 | /* file exists but not valid, remove and try again, but refresh */ |
1520 | NULL, | 1507 | if (0 != unlink(pfn)) |
1521 | bf_size, | 1508 | { |
1522 | 5); /* approx. 3% false positives at max use */ | 1509 | /* failed to remove, run without file */ |
1523 | refresh_bf = GNUNET_YES; | 1510 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1511 | _("Failed to remove bogus bloomfilter file `%s'\n"), | ||
1512 | pfn); | ||
1513 | GNUNET_free(pfn); | ||
1514 | pfn = NULL; | ||
1515 | filter = GNUNET_CONTAINER_bloomfilter_load( | ||
1516 | NULL, | ||
1517 | bf_size, | ||
1518 | 5); /* approx. 3% false positives at max use */ | ||
1519 | refresh_bf = GNUNET_YES; | ||
1520 | } | ||
1521 | else | ||
1522 | { | ||
1523 | /* try again after remove */ | ||
1524 | filter = GNUNET_CONTAINER_bloomfilter_load( | ||
1525 | pfn, | ||
1526 | bf_size, | ||
1527 | 5); /* approx. 3% false positives at max use */ | ||
1528 | refresh_bf = GNUNET_YES; | ||
1529 | if (NULL == filter) | ||
1530 | { | ||
1531 | /* failed yet again, give up on using file */ | ||
1532 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1533 | _("Failed to remove bogus bloomfilter file `%s'\n"), | ||
1534 | pfn); | ||
1535 | GNUNET_free(pfn); | ||
1536 | pfn = NULL; | ||
1537 | filter = GNUNET_CONTAINER_bloomfilter_init( | ||
1538 | NULL, | ||
1539 | bf_size, | ||
1540 | 5); /* approx. 3% false positives at max use */ | ||
1541 | } | ||
1542 | } | ||
1543 | } | ||
1544 | else | ||
1545 | { | ||
1546 | /* normal case: have an existing valid bf file, no need to refresh */ | ||
1547 | refresh_bf = GNUNET_NO; | ||
1548 | } | ||
1524 | } | 1549 | } |
1525 | else | 1550 | else |
1526 | { | 1551 | { |
1527 | /* try again after remove */ | 1552 | filter = |
1528 | filter = GNUNET_CONTAINER_bloomfilter_load ( | 1553 | GNUNET_CONTAINER_bloomfilter_load(pfn, |
1529 | pfn, | 1554 | bf_size, |
1530 | bf_size, | 1555 | 5); /* approx. 3% false positives at max use */ |
1531 | 5); /* approx. 3% false positives at max use */ | ||
1532 | refresh_bf = GNUNET_YES; | 1556 | refresh_bf = GNUNET_YES; |
1533 | if (NULL == filter) | ||
1534 | { | ||
1535 | /* failed yet again, give up on using file */ | ||
1536 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1537 | _ ("Failed to remove bogus bloomfilter file `%s'\n"), | ||
1538 | pfn); | ||
1539 | GNUNET_free (pfn); | ||
1540 | pfn = NULL; | ||
1541 | filter = GNUNET_CONTAINER_bloomfilter_init ( | ||
1542 | NULL, | ||
1543 | bf_size, | ||
1544 | 5); /* approx. 3% false positives at max use */ | ||
1545 | } | ||
1546 | } | 1557 | } |
1547 | } | 1558 | GNUNET_free(pfn); |
1548 | else | ||
1549 | { | ||
1550 | /* normal case: have an existing valid bf file, no need to refresh */ | ||
1551 | refresh_bf = GNUNET_NO; | ||
1552 | } | ||
1553 | } | 1559 | } |
1554 | else | 1560 | else |
1555 | { | 1561 | { |
1556 | filter = | 1562 | filter = |
1557 | GNUNET_CONTAINER_bloomfilter_load (pfn, | 1563 | GNUNET_CONTAINER_bloomfilter_init(NULL, |
1558 | bf_size, | 1564 | bf_size, |
1559 | 5); /* approx. 3% false positives at max use */ | 1565 | 5); /* approx. 3% false positives at max use */ |
1560 | refresh_bf = GNUNET_YES; | 1566 | refresh_bf = GNUNET_YES; |
1561 | } | 1567 | } |
1562 | GNUNET_free (pfn); | 1568 | GNUNET_free_non_null(fn); |
1563 | } | ||
1564 | else | ||
1565 | { | ||
1566 | filter = | ||
1567 | GNUNET_CONTAINER_bloomfilter_init (NULL, | ||
1568 | bf_size, | ||
1569 | 5); /* approx. 3% false positives at max use */ | ||
1570 | refresh_bf = GNUNET_YES; | ||
1571 | } | ||
1572 | GNUNET_free_non_null (fn); | ||
1573 | if (NULL == filter) | 1569 | if (NULL == filter) |
1574 | { | ||
1575 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1576 | _ ("Failed to initialize bloomfilter.\n")); | ||
1577 | if (NULL != stats) | ||
1578 | { | 1570 | { |
1579 | GNUNET_STATISTICS_destroy (stats, GNUNET_YES); | 1571 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1580 | stats = NULL; | 1572 | _("Failed to initialize bloomfilter.\n")); |
1573 | if (NULL != stats) | ||
1574 | { | ||
1575 | GNUNET_STATISTICS_destroy(stats, GNUNET_YES); | ||
1576 | stats = NULL; | ||
1577 | } | ||
1578 | return; | ||
1581 | } | 1579 | } |
1582 | return; | 1580 | GNUNET_SERVICE_suspend(service); |
1583 | } | 1581 | stat_get = GNUNET_STATISTICS_get(stats, |
1584 | GNUNET_SERVICE_suspend (service); | 1582 | "datastore", |
1585 | stat_get = GNUNET_STATISTICS_get (stats, | 1583 | quota_stat_name, |
1586 | "datastore", | 1584 | &process_stat_done, |
1587 | quota_stat_name, | 1585 | &process_stat_in, |
1588 | &process_stat_done, | 1586 | NULL); |
1589 | &process_stat_in, | ||
1590 | NULL); | ||
1591 | if (NULL == stat_get) | 1587 | if (NULL == stat_get) |
1592 | process_stat_done (NULL, GNUNET_SYSERR); | 1588 | process_stat_done(NULL, GNUNET_SYSERR); |
1593 | else | 1589 | else |
1594 | stat_timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 1590 | stat_timeout_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
1595 | &stat_timeout, | 1591 | &stat_timeout, |
1596 | NULL); | 1592 | NULL); |
1597 | GNUNET_SCHEDULER_add_shutdown (&cleaning_task, NULL); | 1593 | GNUNET_SCHEDULER_add_shutdown(&cleaning_task, NULL); |
1598 | } | 1594 | } |
1599 | 1595 | ||
1600 | 1596 | ||
1601 | /** | 1597 | /** |
1602 | * Define "main" method using service macro. | 1598 | * Define "main" method using service macro. |
1603 | */ | 1599 | */ |
1604 | GNUNET_SERVICE_MAIN ( | 1600 | GNUNET_SERVICE_MAIN( |
1605 | "datastore", | 1601 | "datastore", |
1606 | GNUNET_SERVICE_OPTION_NONE, | 1602 | GNUNET_SERVICE_OPTION_NONE, |
1607 | &run, | 1603 | &run, |
1608 | &client_connect_cb, | 1604 | &client_connect_cb, |
1609 | &client_disconnect_cb, | 1605 | &client_disconnect_cb, |
1610 | NULL, | 1606 | NULL, |
1611 | GNUNET_MQ_hd_fixed_size (reserve, | 1607 | GNUNET_MQ_hd_fixed_size(reserve, |
1612 | GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE, | 1608 | GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE, |
1613 | struct ReserveMessage, | 1609 | struct ReserveMessage, |
1614 | NULL), | 1610 | NULL), |
1615 | GNUNET_MQ_hd_fixed_size (release_reserve, | 1611 | GNUNET_MQ_hd_fixed_size(release_reserve, |
1616 | GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE, | 1612 | GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE, |
1617 | struct ReleaseReserveMessage, | 1613 | struct ReleaseReserveMessage, |
1618 | NULL), | 1614 | NULL), |
1619 | GNUNET_MQ_hd_var_size (put, | 1615 | GNUNET_MQ_hd_var_size(put, |
1620 | GNUNET_MESSAGE_TYPE_DATASTORE_PUT, | 1616 | GNUNET_MESSAGE_TYPE_DATASTORE_PUT, |
1621 | struct DataMessage, | 1617 | struct DataMessage, |
1622 | NULL), | 1618 | NULL), |
1623 | GNUNET_MQ_hd_fixed_size (get, | 1619 | GNUNET_MQ_hd_fixed_size(get, |
1624 | GNUNET_MESSAGE_TYPE_DATASTORE_GET, | 1620 | GNUNET_MESSAGE_TYPE_DATASTORE_GET, |
1625 | struct GetMessage, | 1621 | struct GetMessage, |
1626 | NULL), | 1622 | NULL), |
1627 | GNUNET_MQ_hd_fixed_size (get_key, | 1623 | GNUNET_MQ_hd_fixed_size(get_key, |
1628 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY, | 1624 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY, |
1629 | struct GetKeyMessage, | 1625 | struct GetKeyMessage, |
1630 | NULL), | 1626 | NULL), |
1631 | GNUNET_MQ_hd_fixed_size (get_replication, | 1627 | GNUNET_MQ_hd_fixed_size(get_replication, |
1632 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION, | 1628 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION, |
1633 | struct GNUNET_MessageHeader, | 1629 | struct GNUNET_MessageHeader, |
1634 | NULL), | 1630 | NULL), |
1635 | GNUNET_MQ_hd_fixed_size (get_zero_anonymity, | 1631 | GNUNET_MQ_hd_fixed_size(get_zero_anonymity, |
1636 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY, | 1632 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY, |
1637 | struct GetZeroAnonymityMessage, | 1633 | struct GetZeroAnonymityMessage, |
1638 | NULL), | 1634 | NULL), |
1639 | GNUNET_MQ_hd_var_size (remove, | 1635 | GNUNET_MQ_hd_var_size(remove, |
1640 | GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, | 1636 | GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, |
1641 | struct DataMessage, | 1637 | struct DataMessage, |
1642 | NULL), | 1638 | NULL), |
1643 | GNUNET_MQ_hd_fixed_size (drop, | 1639 | GNUNET_MQ_hd_fixed_size(drop, |
1644 | GNUNET_MESSAGE_TYPE_DATASTORE_DROP, | 1640 | GNUNET_MESSAGE_TYPE_DATASTORE_DROP, |
1645 | struct GNUNET_MessageHeader, | 1641 | struct GNUNET_MessageHeader, |
1646 | NULL), | 1642 | NULL), |
1647 | GNUNET_MQ_handler_end ()); | 1643 | GNUNET_MQ_handler_end()); |
1648 | 1644 | ||
1649 | 1645 | ||
1650 | /* end of gnunet-service-datastore.c */ | 1646 | /* end of gnunet-service-datastore.c */ |
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index 96ec9e924..e7eff0e6a 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /* | 20 | /* |
21 | * @file datastore/perf_datastore_api.c | 21 | * @file datastore/perf_datastore_api.c |
22 | * @brief performance measurement for the datastore implementation | 22 | * @brief performance measurement for the datastore implementation |
@@ -41,7 +41,7 @@ | |||
41 | /** | 41 | /** |
42 | * How long until we give up on transmitting the message? | 42 | * How long until we give up on transmitting the message? |
43 | */ | 43 | */ |
44 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 44 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Target datastore size (in bytes). | 47 | * Target datastore size (in bytes). |
@@ -114,8 +114,7 @@ static int ok; | |||
114 | /** | 114 | /** |
115 | * Which phase of the process are we in? | 115 | * Which phase of the process are we in? |
116 | */ | 116 | */ |
117 | enum RunPhase | 117 | enum RunPhase { |
118 | { | ||
119 | /** | 118 | /** |
120 | * We are done (shutting down normally). | 119 | * We are done (shutting down normally). |
121 | */ | 120 | */ |
@@ -154,8 +153,7 @@ enum RunPhase | |||
154 | * benchmark. Could right now be global, but this allows | 153 | * benchmark. Could right now be global, but this allows |
155 | * us to theoretically run multiple clients "in parallel". | 154 | * us to theoretically run multiple clients "in parallel". |
156 | */ | 155 | */ |
157 | struct CpsRunContext | 156 | struct CpsRunContext { |
158 | { | ||
159 | /** | 157 | /** |
160 | * Execution phase we are in. | 158 | * Execution phase we are in. |
161 | */ | 159 | */ |
@@ -188,7 +186,7 @@ struct CpsRunContext | |||
188 | * @param cls the `struct CpsRunContext` | 186 | * @param cls the `struct CpsRunContext` |
189 | */ | 187 | */ |
190 | static void | 188 | static void |
191 | run_continuation (void *cls); | 189 | run_continuation(void *cls); |
192 | 190 | ||
193 | 191 | ||
194 | /** | 192 | /** |
@@ -203,55 +201,57 @@ run_continuation (void *cls); | |||
203 | * @param msg NULL on success, otherwise an error message | 201 | * @param msg NULL on success, otherwise an error message |
204 | */ | 202 | */ |
205 | static void | 203 | static void |
206 | check_success (void *cls, | 204 | check_success(void *cls, |
207 | int success, | 205 | int success, |
208 | struct GNUNET_TIME_Absolute min_expiration, | 206 | struct GNUNET_TIME_Absolute min_expiration, |
209 | const char *msg) | 207 | const char *msg) |
210 | { | 208 | { |
211 | struct CpsRunContext *crc = cls; | 209 | struct CpsRunContext *crc = cls; |
212 | 210 | ||
213 | #if REPORT_ID | 211 | #if REPORT_ID |
214 | fprintf (stderr, "%s", (GNUNET_OK == success) ? "I" : "i"); | 212 | fprintf(stderr, "%s", (GNUNET_OK == success) ? "I" : "i"); |
215 | #endif | 213 | #endif |
216 | if (GNUNET_OK != success) | 214 | if (GNUNET_OK != success) |
217 | { | 215 | { |
218 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 216 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
219 | "Check success failed: `%s'\n", | 217 | "Check success failed: `%s'\n", |
220 | msg); | 218 | msg); |
221 | crc->phase = RP_ERROR; | 219 | crc->phase = RP_ERROR; |
222 | GNUNET_SCHEDULER_add_now (&run_continuation, | 220 | GNUNET_SCHEDULER_add_now(&run_continuation, |
223 | crc); | 221 | crc); |
224 | return; | 222 | return; |
225 | } | 223 | } |
226 | stored_bytes += crc->size; | 224 | stored_bytes += crc->size; |
227 | stored_ops++; | 225 | stored_ops++; |
228 | stored_entries++; | 226 | stored_entries++; |
229 | crc->j++; | 227 | crc->j++; |
230 | switch (crc->phase) | 228 | switch (crc->phase) |
231 | { | ||
232 | case RP_PUT: | ||
233 | if (crc->j >= PUT_10) | ||
234 | { | 229 | { |
235 | crc->j = 0; | 230 | case RP_PUT: |
236 | crc->i++; | 231 | if (crc->j >= PUT_10) |
237 | if (crc->i == ITERATIONS) | 232 | { |
238 | crc->phase = RP_PUT_QUOTA; | 233 | crc->j = 0; |
239 | else | 234 | crc->i++; |
240 | crc->phase = RP_CUT; | 235 | if (crc->i == ITERATIONS) |
236 | crc->phase = RP_PUT_QUOTA; | ||
237 | else | ||
238 | crc->phase = RP_CUT; | ||
239 | } | ||
240 | break; | ||
241 | |||
242 | case RP_PUT_QUOTA: | ||
243 | if (crc->j >= QUOTA_PUTS) | ||
244 | { | ||
245 | crc->j = 0; | ||
246 | crc->phase = RP_DONE; | ||
247 | } | ||
248 | break; | ||
249 | |||
250 | default: | ||
251 | GNUNET_assert(0); | ||
241 | } | 252 | } |
242 | break; | 253 | GNUNET_SCHEDULER_add_now(&run_continuation, |
243 | case RP_PUT_QUOTA: | 254 | crc); |
244 | if (crc->j >= QUOTA_PUTS) | ||
245 | { | ||
246 | crc->j = 0; | ||
247 | crc->phase = RP_DONE; | ||
248 | } | ||
249 | break; | ||
250 | default: | ||
251 | GNUNET_assert (0); | ||
252 | } | ||
253 | GNUNET_SCHEDULER_add_now (&run_continuation, | ||
254 | crc); | ||
255 | } | 255 | } |
256 | 256 | ||
257 | 257 | ||
@@ -267,29 +267,29 @@ check_success (void *cls, | |||
267 | * @param msg NULL on success, otherwise an error message | 267 | * @param msg NULL on success, otherwise an error message |
268 | */ | 268 | */ |
269 | static void | 269 | static void |
270 | remove_next (void *cls, | 270 | remove_next(void *cls, |
271 | int success, | 271 | int success, |
272 | struct GNUNET_TIME_Absolute min_expiration, | 272 | struct GNUNET_TIME_Absolute min_expiration, |
273 | const char *msg) | 273 | const char *msg) |
274 | { | 274 | { |
275 | struct CpsRunContext *crc = cls; | 275 | struct CpsRunContext *crc = cls; |
276 | 276 | ||
277 | if (GNUNET_OK != success) | 277 | if (GNUNET_OK != success) |
278 | { | 278 | { |
279 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 279 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
280 | "remove_next failed: `%s'\n", | 280 | "remove_next failed: `%s'\n", |
281 | msg); | 281 | msg); |
282 | crc->phase = RP_ERROR; | 282 | crc->phase = RP_ERROR; |
283 | GNUNET_SCHEDULER_add_now (&run_continuation, | 283 | GNUNET_SCHEDULER_add_now(&run_continuation, |
284 | crc); | 284 | crc); |
285 | return; | 285 | return; |
286 | } | 286 | } |
287 | #if REPORT_ID | 287 | #if REPORT_ID |
288 | fprintf (stderr, "%s", "D"); | 288 | fprintf(stderr, "%s", "D"); |
289 | #endif | 289 | #endif |
290 | GNUNET_assert (GNUNET_OK == success); | 290 | GNUNET_assert(GNUNET_OK == success); |
291 | GNUNET_SCHEDULER_add_now (&run_continuation, | 291 | GNUNET_SCHEDULER_add_now(&run_continuation, |
292 | crc); | 292 | crc); |
293 | } | 293 | } |
294 | 294 | ||
295 | 295 | ||
@@ -309,32 +309,32 @@ remove_next (void *cls, | |||
309 | * maybe 0 if no unique identifier is available | 309 | * maybe 0 if no unique identifier is available |
310 | */ | 310 | */ |
311 | static void | 311 | static void |
312 | delete_value (void *cls, | 312 | delete_value(void *cls, |
313 | const struct GNUNET_HashCode *key, | 313 | const struct GNUNET_HashCode *key, |
314 | size_t size, | 314 | size_t size, |
315 | const void *data, | 315 | const void *data, |
316 | enum GNUNET_BLOCK_Type type, | 316 | enum GNUNET_BLOCK_Type type, |
317 | uint32_t priority, | 317 | uint32_t priority, |
318 | uint32_t anonymity, | 318 | uint32_t anonymity, |
319 | uint32_t replication, | 319 | uint32_t replication, |
320 | struct GNUNET_TIME_Absolute expiration, | 320 | struct GNUNET_TIME_Absolute expiration, |
321 | uint64_t uid) | 321 | uint64_t uid) |
322 | { | 322 | { |
323 | struct CpsRunContext *crc = cls; | 323 | struct CpsRunContext *crc = cls; |
324 | 324 | ||
325 | GNUNET_assert (NULL != key); | 325 | GNUNET_assert(NULL != key); |
326 | stored_ops++; | 326 | stored_ops++; |
327 | stored_bytes -= size; | 327 | stored_bytes -= size; |
328 | stored_entries--; | 328 | stored_entries--; |
329 | stored_ops++; | 329 | stored_ops++; |
330 | if (stored_bytes < MAX_SIZE) | 330 | if (stored_bytes < MAX_SIZE) |
331 | crc->phase = RP_PUT; | 331 | crc->phase = RP_PUT; |
332 | GNUNET_assert (NULL != | 332 | GNUNET_assert(NULL != |
333 | GNUNET_DATASTORE_remove (datastore, | 333 | GNUNET_DATASTORE_remove(datastore, |
334 | key, | 334 | key, |
335 | size, | 335 | size, |
336 | data, 1, 1, | 336 | data, 1, 1, |
337 | &remove_next, crc)); | 337 | &remove_next, crc)); |
338 | } | 338 | } |
339 | 339 | ||
340 | 340 | ||
@@ -345,7 +345,7 @@ delete_value (void *cls, | |||
345 | * @param cls the `struct CpsRunContext` | 345 | * @param cls the `struct CpsRunContext` |
346 | */ | 346 | */ |
347 | static void | 347 | static void |
348 | run_continuation (void *cls) | 348 | run_continuation(void *cls) |
349 | { | 349 | { |
350 | struct CpsRunContext *crc = cls; | 350 | struct CpsRunContext *crc = cls; |
351 | size_t size; | 351 | size_t size; |
@@ -353,156 +353,161 @@ run_continuation (void *cls) | |||
353 | static char data[65536]; | 353 | static char data[65536]; |
354 | char gstr[128]; | 354 | char gstr[128]; |
355 | 355 | ||
356 | ok = (int) crc->phase; | 356 | ok = (int)crc->phase; |
357 | switch (crc->phase) | 357 | switch (crc->phase) |
358 | { | 358 | { |
359 | case RP_PUT: | 359 | case RP_PUT: |
360 | memset (&key, | 360 | memset(&key, |
361 | 256 - crc->i, | 361 | 256 - crc->i, |
362 | sizeof (struct GNUNET_HashCode)); | 362 | sizeof(struct GNUNET_HashCode)); |
363 | /* most content is 32k */ | 363 | /* most content is 32k */ |
364 | size = 32 * 1024; | 364 | size = 32 * 1024; |
365 | if (0 == | 365 | if (0 == |
366 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 366 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
367 | 16)) /* but some of it is less! */ | 367 | 16)) /* but some of it is less! */ |
368 | size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 368 | size = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
369 | 32 * 1024); | 369 | 32 * 1024); |
370 | crc->size = size = size - (size & 7); /* always multiple of 8 */ | 370 | crc->size = size = size - (size & 7); /* always multiple of 8 */ |
371 | GNUNET_CRYPTO_hash (&key, | 371 | GNUNET_CRYPTO_hash(&key, |
372 | sizeof (struct GNUNET_HashCode), | 372 | sizeof(struct GNUNET_HashCode), |
373 | &key); | 373 | &key); |
374 | memset (data, | 374 | memset(data, |
375 | (int) crc->j, | 375 | (int)crc->j, |
376 | size); | 376 | size); |
377 | if (crc->j > 255) | 377 | if (crc->j > 255) |
378 | memset (data, | 378 | memset(data, |
379 | (int) (crc->j - 255), | 379 | (int)(crc->j - 255), |
380 | size / 2); | 380 | size / 2); |
381 | data[0] = crc->i; | 381 | data[0] = crc->i; |
382 | GNUNET_assert (NULL != | 382 | GNUNET_assert(NULL != |
383 | GNUNET_DATASTORE_put (datastore, | 383 | GNUNET_DATASTORE_put(datastore, |
384 | 0, | 384 | 0, |
385 | &key, | 385 | &key, |
386 | size, | 386 | size, |
387 | data, | 387 | data, |
388 | crc->j + 1, | 388 | crc->j + 1, |
389 | GNUNET_CRYPTO_random_u32 | 389 | GNUNET_CRYPTO_random_u32 |
390 | (GNUNET_CRYPTO_QUALITY_WEAK, 100), | 390 | (GNUNET_CRYPTO_QUALITY_WEAK, 100), |
391 | crc->j, | 391 | crc->j, |
392 | 0, | 392 | 0, |
393 | GNUNET_TIME_relative_to_absolute | 393 | GNUNET_TIME_relative_to_absolute |
394 | (GNUNET_TIME_relative_multiply | 394 | (GNUNET_TIME_relative_multiply |
395 | (GNUNET_TIME_UNIT_SECONDS, | 395 | (GNUNET_TIME_UNIT_SECONDS, |
396 | GNUNET_CRYPTO_random_u32 | 396 | GNUNET_CRYPTO_random_u32 |
397 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), | 397 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), |
398 | 1, | 398 | 1, |
399 | 1, | 399 | 1, |
400 | &check_success, crc)); | 400 | &check_success, crc)); |
401 | break; | 401 | break; |
402 | case RP_CUT: | 402 | |
403 | /* trim down below MAX_SIZE again */ | 403 | case RP_CUT: |
404 | GNUNET_assert (NULL != | 404 | /* trim down below MAX_SIZE again */ |
405 | GNUNET_DATASTORE_get_for_replication (datastore, | 405 | GNUNET_assert(NULL != |
406 | GNUNET_DATASTORE_get_for_replication(datastore, | ||
406 | 1, 1, | 407 | 1, 1, |
407 | &delete_value, | 408 | &delete_value, |
408 | crc)); | 409 | crc)); |
409 | break; | 410 | break; |
410 | case RP_REPORT: | 411 | |
411 | printf ( | 412 | case RP_REPORT: |
413 | printf( | ||
412 | #if REPORT_ID | 414 | #if REPORT_ID |
413 | "\n" | 415 | "\n" |
414 | #endif | 416 | #endif |
415 | "Stored %llu kB / %lluk ops / %llu ops/s\n", | 417 | "Stored %llu kB / %lluk ops / %llu ops/s\n", |
416 | stored_bytes / 1024, /* used size in k */ | 418 | stored_bytes / 1024, /* used size in k */ |
417 | stored_ops / 1024, /* total operations (in k) */ | 419 | stored_ops / 1024, /* total operations (in k) */ |
418 | 1000LL * 1000LL * stored_ops / (1 + | 420 | 1000LL * 1000LL * stored_ops / (1 + |
419 | GNUNET_TIME_absolute_get_duration | 421 | GNUNET_TIME_absolute_get_duration |
420 | (start_time).rel_value_us)); | 422 | (start_time).rel_value_us)); |
421 | crc->phase = RP_PUT; | 423 | crc->phase = RP_PUT; |
422 | crc->j = 0; | 424 | crc->j = 0; |
423 | GNUNET_SCHEDULER_add_now (&run_continuation, | 425 | GNUNET_SCHEDULER_add_now(&run_continuation, |
424 | crc); | 426 | crc); |
425 | break; | 427 | break; |
426 | case RP_PUT_QUOTA: | 428 | |
427 | memset (&key, | 429 | case RP_PUT_QUOTA: |
428 | 256 - crc->i, | 430 | memset(&key, |
429 | sizeof (struct GNUNET_HashCode)); | 431 | 256 - crc->i, |
430 | /* most content is 32k */ | 432 | sizeof(struct GNUNET_HashCode)); |
431 | size = 32 * 1024; | 433 | /* most content is 32k */ |
432 | if (0 == | 434 | size = 32 * 1024; |
433 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 435 | if (0 == |
434 | 16)) /* but some of it is less! */ | 436 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
435 | size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 437 | 16)) /* but some of it is less! */ |
436 | 32 * 1024); | 438 | size = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
437 | crc->size = size = size - (size & 7); /* always multiple of 8 */ | 439 | 32 * 1024); |
438 | GNUNET_CRYPTO_hash (&key, | 440 | crc->size = size = size - (size & 7); /* always multiple of 8 */ |
439 | sizeof (struct GNUNET_HashCode), | 441 | GNUNET_CRYPTO_hash(&key, |
440 | &key); | 442 | sizeof(struct GNUNET_HashCode), |
441 | memset (data, | 443 | &key); |
442 | (int) crc->j, | 444 | memset(data, |
443 | size); | 445 | (int)crc->j, |
444 | if (crc->j > 255) | 446 | size); |
445 | memset (data, | 447 | if (crc->j > 255) |
446 | (int) (crc->j - 255), | 448 | memset(data, |
447 | size / 2); | 449 | (int)(crc->j - 255), |
448 | data[0] = crc->i; | 450 | size / 2); |
449 | GNUNET_assert (NULL != | 451 | data[0] = crc->i; |
450 | GNUNET_DATASTORE_put (datastore, | 452 | GNUNET_assert(NULL != |
453 | GNUNET_DATASTORE_put(datastore, | ||
451 | 0, /* reservation ID */ | 454 | 0, /* reservation ID */ |
452 | &key, | 455 | &key, |
453 | size, | 456 | size, |
454 | data, | 457 | data, |
455 | crc->j + 1, /* type */ | 458 | crc->j + 1, /* type */ |
456 | GNUNET_CRYPTO_random_u32 | 459 | GNUNET_CRYPTO_random_u32 |
457 | (GNUNET_CRYPTO_QUALITY_WEAK, | 460 | (GNUNET_CRYPTO_QUALITY_WEAK, |
458 | 100), /* priority */ | 461 | 100), /* priority */ |
459 | crc->j, /* anonymity */ | 462 | crc->j, /* anonymity */ |
460 | 0, /* replication */ | 463 | 0, /* replication */ |
461 | GNUNET_TIME_relative_to_absolute | 464 | GNUNET_TIME_relative_to_absolute |
462 | (GNUNET_TIME_relative_multiply | 465 | (GNUNET_TIME_relative_multiply |
463 | (GNUNET_TIME_UNIT_SECONDS, | 466 | (GNUNET_TIME_UNIT_SECONDS, |
464 | GNUNET_CRYPTO_random_u32 | 467 | GNUNET_CRYPTO_random_u32 |
465 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), | 468 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), |
466 | 1, | 469 | 1, |
467 | 1, | 470 | 1, |
468 | &check_success, crc)); | 471 | &check_success, crc)); |
469 | break; | 472 | break; |
470 | 473 | ||
471 | case RP_DONE: | 474 | case RP_DONE: |
472 | GNUNET_snprintf (gstr, | 475 | GNUNET_snprintf(gstr, |
473 | sizeof (gstr), | 476 | sizeof(gstr), |
474 | "DATASTORE-%s", | 477 | "DATASTORE-%s", |
475 | plugin_name); | 478 | plugin_name); |
476 | if ((crc->i == ITERATIONS) && (stored_ops > 0)) | 479 | if ((crc->i == ITERATIONS) && (stored_ops > 0)) |
477 | { | 480 | { |
478 | GAUGER (gstr, | 481 | GAUGER(gstr, |
479 | "PUT operation duration", | 482 | "PUT operation duration", |
480 | GNUNET_TIME_absolute_get_duration (start_time).rel_value_us / 1000LL / | 483 | GNUNET_TIME_absolute_get_duration(start_time).rel_value_us / 1000LL / |
481 | stored_ops, | 484 | stored_ops, |
482 | "ms/operation"); | 485 | "ms/operation"); |
483 | fprintf (stdout, | 486 | fprintf(stdout, |
484 | "\nPUT performance: %s for %llu operations\n", | 487 | "\nPUT performance: %s for %llu operations\n", |
485 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start_time), | 488 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(start_time), |
486 | GNUNET_YES), | 489 | GNUNET_YES), |
487 | stored_ops); | 490 | stored_ops); |
488 | fprintf (stdout, | 491 | fprintf(stdout, |
489 | "PUT performance: %llu ms/operation\n", | 492 | "PUT performance: %llu ms/operation\n", |
490 | GNUNET_TIME_absolute_get_duration (start_time).rel_value_us / 1000LL / | 493 | GNUNET_TIME_absolute_get_duration(start_time).rel_value_us / 1000LL / |
491 | stored_ops); | 494 | stored_ops); |
495 | } | ||
496 | GNUNET_DATASTORE_disconnect(datastore, | ||
497 | GNUNET_YES); | ||
498 | GNUNET_free(crc); | ||
499 | ok = 0; | ||
500 | break; | ||
501 | |||
502 | case RP_ERROR: | ||
503 | GNUNET_DATASTORE_disconnect(datastore, GNUNET_YES); | ||
504 | GNUNET_free(crc); | ||
505 | ok = 1; | ||
506 | break; | ||
507 | |||
508 | default: | ||
509 | GNUNET_assert(0); | ||
492 | } | 510 | } |
493 | GNUNET_DATASTORE_disconnect (datastore, | ||
494 | GNUNET_YES); | ||
495 | GNUNET_free (crc); | ||
496 | ok = 0; | ||
497 | break; | ||
498 | case RP_ERROR: | ||
499 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); | ||
500 | GNUNET_free (crc); | ||
501 | ok = 1; | ||
502 | break; | ||
503 | default: | ||
504 | GNUNET_assert (0); | ||
505 | } | ||
506 | } | 511 | } |
507 | 512 | ||
508 | 513 | ||
@@ -519,25 +524,25 @@ run_continuation (void *cls) | |||
519 | * @param msg NULL on success, otherwise an error message | 524 | * @param msg NULL on success, otherwise an error message |
520 | */ | 525 | */ |
521 | static void | 526 | static void |
522 | run_tests (void *cls, | 527 | run_tests(void *cls, |
523 | int success, | 528 | int success, |
524 | struct GNUNET_TIME_Absolute min_expiration, | 529 | struct GNUNET_TIME_Absolute min_expiration, |
525 | const char *msg) | 530 | const char *msg) |
526 | { | 531 | { |
527 | struct CpsRunContext *crc = cls; | 532 | struct CpsRunContext *crc = cls; |
528 | 533 | ||
529 | if (success != GNUNET_YES) | 534 | if (success != GNUNET_YES) |
530 | { | 535 | { |
531 | fprintf (stderr, | 536 | fprintf(stderr, |
532 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", | 537 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", |
533 | msg); | 538 | msg); |
534 | GNUNET_DATASTORE_disconnect (datastore, | 539 | GNUNET_DATASTORE_disconnect(datastore, |
535 | GNUNET_YES); | 540 | GNUNET_YES); |
536 | GNUNET_free (crc); | 541 | GNUNET_free(crc); |
537 | return; | 542 | return; |
538 | } | 543 | } |
539 | GNUNET_SCHEDULER_add_now (&run_continuation, | 544 | GNUNET_SCHEDULER_add_now(&run_continuation, |
540 | crc); | 545 | crc); |
541 | } | 546 | } |
542 | 547 | ||
543 | 548 | ||
@@ -551,34 +556,34 @@ run_tests (void *cls, | |||
551 | * @param peer peer handle (unused) | 556 | * @param peer peer handle (unused) |
552 | */ | 557 | */ |
553 | static void | 558 | static void |
554 | run (void *cls, | 559 | run(void *cls, |
555 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 560 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
556 | struct GNUNET_TESTING_Peer *peer) | 561 | struct GNUNET_TESTING_Peer *peer) |
557 | { | 562 | { |
558 | struct CpsRunContext *crc; | 563 | struct CpsRunContext *crc; |
559 | static struct GNUNET_HashCode zkey; | 564 | static struct GNUNET_HashCode zkey; |
560 | 565 | ||
561 | datastore = GNUNET_DATASTORE_connect (cfg); | 566 | datastore = GNUNET_DATASTORE_connect(cfg); |
562 | start_time = GNUNET_TIME_absolute_get (); | 567 | start_time = GNUNET_TIME_absolute_get(); |
563 | crc = GNUNET_new (struct CpsRunContext); | 568 | crc = GNUNET_new(struct CpsRunContext); |
564 | crc->phase = RP_PUT; | 569 | crc->phase = RP_PUT; |
565 | if (NULL == | 570 | if (NULL == |
566 | GNUNET_DATASTORE_put (datastore, | 571 | GNUNET_DATASTORE_put(datastore, |
567 | 0, | 572 | 0, |
568 | &zkey, | 573 | &zkey, |
569 | 4, "TEST", | 574 | 4, "TEST", |
570 | GNUNET_BLOCK_TYPE_TEST, | 575 | GNUNET_BLOCK_TYPE_TEST, |
571 | 0, 0, 0, | 576 | 0, 0, 0, |
572 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS), | 577 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_SECONDS), |
573 | 0, 1, | 578 | 0, 1, |
574 | &run_tests, crc)) | 579 | &run_tests, crc)) |
575 | { | 580 | { |
576 | fprintf (stderr, | 581 | fprintf(stderr, |
577 | "%s", | 582 | "%s", |
578 | "Test 'put' operation failed.\n"); | 583 | "Test 'put' operation failed.\n"); |
579 | ok = 1; | 584 | ok = 1; |
580 | GNUNET_free (crc); | 585 | GNUNET_free(crc); |
581 | } | 586 | } |
582 | } | 587 | } |
583 | 588 | ||
584 | 589 | ||
@@ -592,23 +597,23 @@ run (void *cls, | |||
592 | * @return 0 on success | 597 | * @return 0 on success |
593 | */ | 598 | */ |
594 | int | 599 | int |
595 | main (int argc, | 600 | main(int argc, |
596 | char *argv[]) | 601 | char *argv[]) |
597 | { | 602 | { |
598 | char cfg_name[PATH_MAX]; | 603 | char cfg_name[PATH_MAX]; |
599 | 604 | ||
600 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 605 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); |
601 | GNUNET_snprintf (cfg_name, | 606 | GNUNET_snprintf(cfg_name, |
602 | sizeof (cfg_name), | 607 | sizeof(cfg_name), |
603 | "test_datastore_api_data_%s.conf", | 608 | "test_datastore_api_data_%s.conf", |
604 | plugin_name); | 609 | plugin_name); |
605 | if (0 != | 610 | if (0 != |
606 | GNUNET_TESTING_peer_run ("perf-gnunet-datastore", | 611 | GNUNET_TESTING_peer_run("perf-gnunet-datastore", |
607 | cfg_name, | 612 | cfg_name, |
608 | &run, | 613 | &run, |
609 | NULL)) | 614 | NULL)) |
610 | return 1; | 615 | return 1; |
611 | fprintf (stderr, "%s", "\n"); | 616 | fprintf(stderr, "%s", "\n"); |
612 | return ok; | 617 | return ok; |
613 | } | 618 | } |
614 | 619 | ||
diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c index 564f8f37b..a051f27ca 100644 --- a/src/datastore/perf_plugin_datastore.c +++ b/src/datastore/perf_plugin_datastore.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /* | 20 | /* |
21 | * @file perf_plugin_datastore.c | 21 | * @file perf_plugin_datastore.c |
22 | * @brief Profile database plugin directly, focusing on iterators. | 22 | * @brief Profile database plugin directly, focusing on iterators. |
@@ -59,8 +59,7 @@ static const char *plugin_name; | |||
59 | 59 | ||
60 | static int ok; | 60 | static int ok; |
61 | 61 | ||
62 | enum RunPhase | 62 | enum RunPhase { |
63 | { | ||
64 | RP_ERROR = 0, | 63 | RP_ERROR = 0, |
65 | RP_PUT, | 64 | RP_PUT, |
66 | RP_REP_GET, | 65 | RP_REP_GET, |
@@ -70,8 +69,7 @@ enum RunPhase | |||
70 | }; | 69 | }; |
71 | 70 | ||
72 | 71 | ||
73 | struct CpsRunContext | 72 | struct CpsRunContext { |
74 | { | ||
75 | unsigned int i; | 73 | unsigned int i; |
76 | struct GNUNET_TIME_Absolute start; | 74 | struct GNUNET_TIME_Absolute start; |
77 | struct GNUNET_TIME_Absolute end; | 75 | struct GNUNET_TIME_Absolute end; |
@@ -93,13 +91,13 @@ struct CpsRunContext | |||
93 | * 0 for "reset to empty" | 91 | * 0 for "reset to empty" |
94 | */ | 92 | */ |
95 | static void | 93 | static void |
96 | disk_utilization_change_cb (void *cls, int delta) | 94 | disk_utilization_change_cb(void *cls, int delta) |
97 | { | 95 | { |
98 | } | 96 | } |
99 | 97 | ||
100 | 98 | ||
101 | static void | 99 | static void |
102 | test (void *cls); | 100 | test(void *cls); |
103 | 101 | ||
104 | 102 | ||
105 | /** | 103 | /** |
@@ -112,30 +110,30 @@ test (void *cls); | |||
112 | * @param msg error message on error | 110 | * @param msg error message on error |
113 | */ | 111 | */ |
114 | static void | 112 | static void |
115 | put_continuation (void *cls, | 113 | put_continuation(void *cls, |
116 | const struct GNUNET_HashCode *key, | 114 | const struct GNUNET_HashCode *key, |
117 | uint32_t size, | 115 | uint32_t size, |
118 | int status, | 116 | int status, |
119 | const char *msg) | 117 | const char *msg) |
120 | { | 118 | { |
121 | struct CpsRunContext *crc = cls; | 119 | struct CpsRunContext *crc = cls; |
122 | 120 | ||
123 | if (GNUNET_OK != status) | 121 | if (GNUNET_OK != status) |
124 | { | 122 | { |
125 | fprintf (stderr, "ERROR: `%s'\n", msg); | 123 | fprintf(stderr, "ERROR: `%s'\n", msg); |
126 | } | 124 | } |
127 | else | 125 | else |
128 | { | 126 | { |
129 | stored_bytes += size; | 127 | stored_bytes += size; |
130 | stored_ops++; | 128 | stored_ops++; |
131 | stored_entries++; | 129 | stored_entries++; |
132 | } | 130 | } |
133 | GNUNET_SCHEDULER_add_now (&test, crc); | 131 | GNUNET_SCHEDULER_add_now(&test, crc); |
134 | } | 132 | } |
135 | 133 | ||
136 | 134 | ||
137 | static void | 135 | static void |
138 | do_put (struct CpsRunContext *crc) | 136 | do_put(struct CpsRunContext *crc) |
139 | { | 137 | { |
140 | char value[65536]; | 138 | char value[65536]; |
141 | size_t size; | 139 | size_t size; |
@@ -144,66 +142,123 @@ do_put (struct CpsRunContext *crc) | |||
144 | unsigned int prio; | 142 | unsigned int prio; |
145 | 143 | ||
146 | if (0 == i) | 144 | if (0 == i) |
147 | crc->start = GNUNET_TIME_absolute_get (); | 145 | crc->start = GNUNET_TIME_absolute_get(); |
148 | if (PUT_10 == i) | 146 | if (PUT_10 == i) |
149 | { | ||
150 | i = 0; | ||
151 | crc->end = GNUNET_TIME_absolute_get (); | ||
152 | { | 147 | { |
153 | printf ("%s took %s for %llu items\n", "Storing an item", | 148 | i = 0; |
154 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (crc->start, | 149 | crc->end = GNUNET_TIME_absolute_get(); |
155 | crc->end), | 150 | { |
156 | GNUNET_YES), | 151 | printf("%s took %s for %llu items\n", "Storing an item", |
157 | PUT_10); | 152 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_difference(crc->start, |
158 | if (PUT_10 > 0) | 153 | crc->end), |
159 | GAUGER (category, "Storing an item", | 154 | GNUNET_YES), |
160 | (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / PUT_10, | 155 | PUT_10); |
161 | "ms/item"); | 156 | if (PUT_10 > 0) |
157 | GAUGER(category, "Storing an item", | ||
158 | (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / PUT_10, | ||
159 | "ms/item"); | ||
160 | } | ||
161 | crc->i++; | ||
162 | crc->start = GNUNET_TIME_absolute_get(); | ||
163 | crc->phase++; | ||
164 | GNUNET_SCHEDULER_add_now(&test, crc); | ||
165 | return; | ||
162 | } | 166 | } |
163 | crc->i++; | ||
164 | crc->start = GNUNET_TIME_absolute_get (); | ||
165 | crc->phase++; | ||
166 | GNUNET_SCHEDULER_add_now (&test, crc); | ||
167 | return; | ||
168 | } | ||
169 | /* most content is 32k */ | 167 | /* most content is 32k */ |
170 | size = 32 * 1024; | 168 | size = 32 * 1024; |
171 | if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ | 169 | if (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ |
172 | size = 8 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); | 170 | size = 8 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); |
173 | size = size - (size & 7); /* always multiple of 8 */ | 171 | size = size - (size & 7); /* always multiple of 8 */ |
174 | 172 | ||
175 | /* generate random key */ | 173 | /* generate random key */ |
176 | key.bits[0] = (unsigned int) GNUNET_TIME_absolute_get ().abs_value_us; | 174 | key.bits[0] = (unsigned int)GNUNET_TIME_absolute_get().abs_value_us; |
177 | GNUNET_CRYPTO_hash (&key, sizeof (struct GNUNET_HashCode), &key); | 175 | GNUNET_CRYPTO_hash(&key, sizeof(struct GNUNET_HashCode), &key); |
178 | memset (value, i, size); | 176 | memset(value, i, size); |
179 | if (i > 255) | 177 | if (i > 255) |
180 | memset (value, i - 255, size / 2); | 178 | memset(value, i - 255, size / 2); |
181 | value[0] = crc->i; | 179 | value[0] = crc->i; |
182 | GNUNET_memcpy (&value[4], &i, sizeof (i)); | 180 | GNUNET_memcpy(&value[4], &i, sizeof(i)); |
183 | prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); | 181 | prio = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100); |
184 | crc->api->put (crc->api->cls, | 182 | crc->api->put(crc->api->cls, |
185 | &key, | 183 | &key, |
186 | false /* absent */, | 184 | false /* absent */, |
187 | size, | 185 | size, |
188 | value, | 186 | value, |
189 | 1 + i % 4 /* type */ , | 187 | 1 + i % 4 /* type */, |
190 | prio, | 188 | prio, |
191 | i % 4 /* anonymity */ , | 189 | i % 4 /* anonymity */, |
192 | 0 /* replication */ , | 190 | 0 /* replication */, |
193 | GNUNET_TIME_relative_to_absolute | 191 | GNUNET_TIME_relative_to_absolute |
194 | (GNUNET_TIME_relative_multiply | 192 | (GNUNET_TIME_relative_multiply |
195 | (GNUNET_TIME_UNIT_MILLISECONDS, | 193 | (GNUNET_TIME_UNIT_MILLISECONDS, |
196 | 60 * 60 * 60 * 1000 + | 194 | 60 * 60 * 60 * 1000 + |
197 | GNUNET_CRYPTO_random_u32 | 195 | GNUNET_CRYPTO_random_u32 |
198 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), | 196 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), |
199 | put_continuation, | 197 | put_continuation, |
200 | crc); | 198 | crc); |
201 | i++; | 199 | i++; |
202 | } | 200 | } |
203 | 201 | ||
204 | 202 | ||
205 | static int | 203 | static int |
206 | iterate_zeros (void *cls, | 204 | iterate_zeros(void *cls, |
205 | const struct GNUNET_HashCode *key, | ||
206 | uint32_t size, | ||
207 | const void *data, | ||
208 | enum GNUNET_BLOCK_Type type, | ||
209 | uint32_t priority, | ||
210 | uint32_t anonymity, | ||
211 | uint32_t replication, | ||
212 | struct GNUNET_TIME_Absolute expiration, | ||
213 | uint64_t uid) | ||
214 | { | ||
215 | struct CpsRunContext *crc = cls; | ||
216 | int i; | ||
217 | const char *cdata = data; | ||
218 | |||
219 | GNUNET_assert(key != NULL); | ||
220 | GNUNET_assert(size >= 8); | ||
221 | GNUNET_memcpy(&i, &cdata[4], sizeof(i)); | ||
222 | hits[i / 8] |= (1 << (i % 8)); | ||
223 | |||
224 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
225 | "Found result %d type=%u, priority=%u, size=%u, expire=%s\n", | ||
226 | i, | ||
227 | type, priority, size, | ||
228 | GNUNET_STRINGS_absolute_time_to_string(expiration)); | ||
229 | crc->cnt++; | ||
230 | if (crc->cnt == PUT_10 / 4 - 1) | ||
231 | { | ||
232 | unsigned int bc; | ||
233 | |||
234 | bc = 0; | ||
235 | for (i = 0; i < PUT_10; i++) | ||
236 | if (0 != (hits[i / 8] & (1 << (i % 8)))) | ||
237 | bc++; | ||
238 | |||
239 | crc->end = GNUNET_TIME_absolute_get(); | ||
240 | printf("%s took %s yielding %u/%u items\n", | ||
241 | "Select random zero-anonymity item", | ||
242 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_difference(crc->start, | ||
243 | crc->end), | ||
244 | GNUNET_YES), | ||
245 | bc, crc->cnt); | ||
246 | if (crc->cnt > 0) | ||
247 | GAUGER(category, "Select random zero-anonymity item", | ||
248 | (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt, | ||
249 | "ms/item"); | ||
250 | memset(hits, 0, sizeof(hits)); | ||
251 | crc->phase++; | ||
252 | crc->cnt = 0; | ||
253 | crc->start = GNUNET_TIME_absolute_get(); | ||
254 | } | ||
255 | GNUNET_SCHEDULER_add_now(&test, crc); | ||
256 | return GNUNET_OK; | ||
257 | } | ||
258 | |||
259 | |||
260 | static int | ||
261 | expiration_get(void *cls, | ||
207 | const struct GNUNET_HashCode *key, | 262 | const struct GNUNET_HashCode *key, |
208 | uint32_t size, | 263 | uint32_t size, |
209 | const void *data, | 264 | const void *data, |
@@ -218,49 +273,45 @@ iterate_zeros (void *cls, | |||
218 | int i; | 273 | int i; |
219 | const char *cdata = data; | 274 | const char *cdata = data; |
220 | 275 | ||
221 | GNUNET_assert (key != NULL); | 276 | GNUNET_assert(size >= 8); |
222 | GNUNET_assert (size >= 8); | 277 | GNUNET_memcpy(&i, &cdata[4], sizeof(i)); |
223 | GNUNET_memcpy (&i, &cdata[4], sizeof (i)); | ||
224 | hits[i / 8] |= (1 << (i % 8)); | 278 | hits[i / 8] |= (1 << (i % 8)); |
225 | |||
226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
227 | "Found result %d type=%u, priority=%u, size=%u, expire=%s\n", | ||
228 | i, | ||
229 | type, priority, size, | ||
230 | GNUNET_STRINGS_absolute_time_to_string (expiration)); | ||
231 | crc->cnt++; | 279 | crc->cnt++; |
232 | if (crc->cnt == PUT_10 / 4 - 1) | 280 | if (PUT_10 <= crc->cnt) |
233 | { | 281 | { |
234 | unsigned int bc; | 282 | unsigned int bc; |
235 | 283 | ||
236 | bc = 0; | 284 | bc = 0; |
237 | for (i = 0; i < PUT_10; i++) | 285 | for (i = 0; i < PUT_10; i++) |
238 | if (0 != (hits[i / 8] & (1 << (i % 8)))) | 286 | if (0 != (hits[i / 8] & (1 << (i % 8)))) |
239 | bc++; | 287 | bc++; |
240 | 288 | ||
241 | crc->end = GNUNET_TIME_absolute_get (); | 289 | crc->end = GNUNET_TIME_absolute_get(); |
242 | printf ("%s took %s yielding %u/%u items\n", | 290 | printf("%s took %s yielding %u/%u items\n", |
243 | "Select random zero-anonymity item", | 291 | "Selecting and deleting by expiration", |
244 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (crc->start, | 292 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_difference(crc->start, |
245 | crc->end), | 293 | crc->end), |
246 | GNUNET_YES), | 294 | GNUNET_YES), |
247 | bc, crc->cnt); | 295 | bc, (unsigned int)PUT_10); |
248 | if (crc->cnt > 0) | 296 | if (crc->cnt > 0) |
249 | GAUGER (category, "Select random zero-anonymity item", | 297 | GAUGER(category, "Selecting and deleting by expiration", |
250 | (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt, | 298 | (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt, |
251 | "ms/item"); | 299 | "ms/item"); |
252 | memset (hits, 0, sizeof (hits)); | 300 | memset(hits, 0, sizeof(hits)); |
253 | crc->phase++; | 301 | if (++crc->iter == ITERATIONS) |
254 | crc->cnt = 0; | 302 | crc->phase++; |
255 | crc->start = GNUNET_TIME_absolute_get (); | 303 | else |
256 | } | 304 | crc->phase = RP_PUT; |
257 | GNUNET_SCHEDULER_add_now (&test, crc); | 305 | crc->cnt = 0; |
258 | return GNUNET_OK; | 306 | crc->start = GNUNET_TIME_absolute_get(); |
307 | } | ||
308 | GNUNET_SCHEDULER_add_now(&test, crc); | ||
309 | return GNUNET_NO; | ||
259 | } | 310 | } |
260 | 311 | ||
261 | 312 | ||
262 | static int | 313 | static int |
263 | expiration_get (void *cls, | 314 | replication_get(void *cls, |
264 | const struct GNUNET_HashCode *key, | 315 | const struct GNUNET_HashCode *key, |
265 | uint32_t size, | 316 | uint32_t size, |
266 | const void *data, | 317 | const void *data, |
@@ -275,92 +326,39 @@ expiration_get (void *cls, | |||
275 | int i; | 326 | int i; |
276 | const char *cdata = data; | 327 | const char *cdata = data; |
277 | 328 | ||
278 | GNUNET_assert (size >= 8); | 329 | GNUNET_assert(NULL != key); |
279 | GNUNET_memcpy (&i, &cdata[4], sizeof (i)); | 330 | GNUNET_assert(size >= 8); |
331 | GNUNET_memcpy(&i, &cdata[4], sizeof(i)); | ||
280 | hits[i / 8] |= (1 << (i % 8)); | 332 | hits[i / 8] |= (1 << (i % 8)); |
281 | crc->cnt++; | 333 | crc->cnt++; |
282 | if (PUT_10 <= crc->cnt) | 334 | if (PUT_10 <= crc->cnt) |
283 | { | 335 | { |
284 | unsigned int bc; | 336 | unsigned int bc; |
285 | 337 | ||
286 | bc = 0; | 338 | bc = 0; |
287 | for (i = 0; i < PUT_10; i++) | 339 | for (i = 0; i < PUT_10; i++) |
288 | if (0 != (hits[i / 8] & (1 << (i % 8)))) | 340 | if (0 != (hits[i / 8] & (1 << (i % 8)))) |
289 | bc++; | 341 | bc++; |
290 | 342 | ||
291 | crc->end = GNUNET_TIME_absolute_get (); | 343 | crc->end = GNUNET_TIME_absolute_get(); |
292 | printf ("%s took %s yielding %u/%u items\n", | 344 | printf("%s took %s yielding %u/%u items\n", |
293 | "Selecting and deleting by expiration", | 345 | "Selecting random item for replication", |
294 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (crc->start, | 346 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_difference(crc->start, |
295 | crc->end), | 347 | crc->end), |
296 | GNUNET_YES), | 348 | GNUNET_YES), |
297 | bc, (unsigned int) PUT_10); | 349 | bc, (unsigned int)PUT_10); |
298 | if (crc->cnt > 0) | 350 | if (crc->cnt > 0) |
299 | GAUGER (category, "Selecting and deleting by expiration", | 351 | GAUGER(category, "Selecting random item for replication", |
300 | (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt, | 352 | (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt, |
301 | "ms/item"); | 353 | "ms/item"); |
302 | memset (hits, 0, sizeof (hits)); | 354 | memset(hits, 0, sizeof(hits)); |
303 | if (++crc->iter == ITERATIONS) | ||
304 | crc->phase++; | 355 | crc->phase++; |
305 | else | 356 | crc->offset = 0; |
306 | crc->phase = RP_PUT; | 357 | crc->cnt = 0; |
307 | crc->cnt = 0; | 358 | crc->start = GNUNET_TIME_absolute_get(); |
308 | crc->start = GNUNET_TIME_absolute_get (); | 359 | } |
309 | } | ||
310 | GNUNET_SCHEDULER_add_now (&test, crc); | ||
311 | return GNUNET_NO; | ||
312 | } | ||
313 | |||
314 | |||
315 | static int | ||
316 | replication_get (void *cls, | ||
317 | const struct GNUNET_HashCode *key, | ||
318 | uint32_t size, | ||
319 | const void *data, | ||
320 | enum GNUNET_BLOCK_Type type, | ||
321 | uint32_t priority, | ||
322 | uint32_t anonymity, | ||
323 | uint32_t replication, | ||
324 | struct GNUNET_TIME_Absolute expiration, | ||
325 | uint64_t uid) | ||
326 | { | ||
327 | struct CpsRunContext *crc = cls; | ||
328 | int i; | ||
329 | const char *cdata = data; | ||
330 | 360 | ||
331 | GNUNET_assert (NULL != key); | 361 | GNUNET_SCHEDULER_add_now(&test, crc); |
332 | GNUNET_assert (size >= 8); | ||
333 | GNUNET_memcpy (&i, &cdata[4], sizeof (i)); | ||
334 | hits[i / 8] |= (1 << (i % 8)); | ||
335 | crc->cnt++; | ||
336 | if (PUT_10 <= crc->cnt) | ||
337 | { | ||
338 | unsigned int bc; | ||
339 | |||
340 | bc = 0; | ||
341 | for (i = 0; i < PUT_10; i++) | ||
342 | if (0 != (hits[i / 8] & (1 << (i % 8)))) | ||
343 | bc++; | ||
344 | |||
345 | crc->end = GNUNET_TIME_absolute_get (); | ||
346 | printf ("%s took %s yielding %u/%u items\n", | ||
347 | "Selecting random item for replication", | ||
348 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (crc->start, | ||
349 | crc->end), | ||
350 | GNUNET_YES), | ||
351 | bc, (unsigned int) PUT_10); | ||
352 | if (crc->cnt > 0) | ||
353 | GAUGER (category, "Selecting random item for replication", | ||
354 | (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt, | ||
355 | "ms/item"); | ||
356 | memset (hits, 0, sizeof (hits)); | ||
357 | crc->phase++; | ||
358 | crc->offset = 0; | ||
359 | crc->cnt = 0; | ||
360 | crc->start = GNUNET_TIME_absolute_get (); | ||
361 | } | ||
362 | |||
363 | GNUNET_SCHEDULER_add_now (&test, crc); | ||
364 | return GNUNET_OK; | 362 | return GNUNET_OK; |
365 | } | 363 | } |
366 | 364 | ||
@@ -373,25 +371,25 @@ replication_get (void *cls, | |||
373 | * @param cfg configuration to use | 371 | * @param cfg configuration to use |
374 | */ | 372 | */ |
375 | static void | 373 | static void |
376 | unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api, | 374 | unload_plugin(struct GNUNET_DATASTORE_PluginFunctions *api, |
377 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 375 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
378 | { | 376 | { |
379 | char *name; | 377 | char *name; |
380 | char *libname; | 378 | char *libname; |
381 | 379 | ||
382 | if (GNUNET_OK != | 380 | if (GNUNET_OK != |
383 | GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE", | 381 | GNUNET_CONFIGURATION_get_value_string(cfg, "DATASTORE", "DATABASE", |
384 | &name)) | 382 | &name)) |
385 | { | 383 | { |
386 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 384 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
387 | _("No `%s' specified for `%s' in configuration!\n"), "DATABASE", | 385 | _("No `%s' specified for `%s' in configuration!\n"), "DATABASE", |
388 | "DATASTORE"); | 386 | "DATASTORE"); |
389 | return; | 387 | return; |
390 | } | 388 | } |
391 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); | 389 | GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", name); |
392 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); | 390 | GNUNET_break(NULL == GNUNET_PLUGIN_unload(libname, api)); |
393 | GNUNET_free (libname); | 391 | GNUNET_free(libname); |
394 | GNUNET_free (name); | 392 | GNUNET_free(name); |
395 | } | 393 | } |
396 | 394 | ||
397 | 395 | ||
@@ -401,51 +399,56 @@ unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api, | |||
401 | * the transport and core. | 399 | * the transport and core. |
402 | */ | 400 | */ |
403 | static void | 401 | static void |
404 | cleaning_task (void *cls) | 402 | cleaning_task(void *cls) |
405 | { | 403 | { |
406 | struct CpsRunContext *crc = cls; | 404 | struct CpsRunContext *crc = cls; |
407 | 405 | ||
408 | unload_plugin (crc->api, crc->cfg); | 406 | unload_plugin(crc->api, crc->cfg); |
409 | GNUNET_free (crc); | 407 | GNUNET_free(crc); |
410 | } | 408 | } |
411 | 409 | ||
412 | 410 | ||
413 | static void | 411 | static void |
414 | test (void *cls) | 412 | test(void *cls) |
415 | { | 413 | { |
416 | struct CpsRunContext *crc = cls; | 414 | struct CpsRunContext *crc = cls; |
417 | 415 | ||
418 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 416 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
419 | "In phase %d, iteration %u\n", crc->phase, crc->cnt); | 417 | "In phase %d, iteration %u\n", crc->phase, crc->cnt); |
420 | switch (crc->phase) | 418 | switch (crc->phase) |
421 | { | 419 | { |
422 | case RP_ERROR: | 420 | case RP_ERROR: |
423 | GNUNET_break (0); | 421 | GNUNET_break(0); |
424 | crc->api->drop (crc->api->cls); | 422 | crc->api->drop(crc->api->cls); |
425 | ok = 1; | 423 | ok = 1; |
426 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 424 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, |
427 | &cleaning_task, crc); | 425 | &cleaning_task, crc); |
428 | break; | 426 | break; |
429 | case RP_PUT: | 427 | |
430 | do_put (crc); | 428 | case RP_PUT: |
431 | break; | 429 | do_put(crc); |
432 | case RP_REP_GET: | 430 | break; |
433 | crc->api->get_replication (crc->api->cls, &replication_get, crc); | 431 | |
434 | break; | 432 | case RP_REP_GET: |
435 | case RP_ZA_GET: | 433 | crc->api->get_replication(crc->api->cls, &replication_get, crc); |
436 | crc->api->get_zero_anonymity (crc->api->cls, crc->offset++, 1, | 434 | break; |
437 | &iterate_zeros, crc); | 435 | |
438 | break; | 436 | case RP_ZA_GET: |
439 | case RP_EXP_GET: | 437 | crc->api->get_zero_anonymity(crc->api->cls, crc->offset++, 1, |
440 | crc->api->get_expiration (crc->api->cls, &expiration_get, crc); | 438 | &iterate_zeros, crc); |
441 | break; | 439 | break; |
442 | case RP_DONE: | 440 | |
443 | crc->api->drop (crc->api->cls); | 441 | case RP_EXP_GET: |
444 | ok = 0; | 442 | crc->api->get_expiration(crc->api->cls, &expiration_get, crc); |
445 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 443 | break; |
446 | &cleaning_task, crc); | 444 | |
447 | break; | 445 | case RP_DONE: |
448 | } | 446 | crc->api->drop(crc->api->cls); |
447 | ok = 0; | ||
448 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, | ||
449 | &cleaning_task, crc); | ||
450 | break; | ||
451 | } | ||
449 | } | 452 | } |
450 | 453 | ||
451 | 454 | ||
@@ -453,7 +456,7 @@ test (void *cls) | |||
453 | * Load the datastore plugin. | 456 | * Load the datastore plugin. |
454 | */ | 457 | */ |
455 | static struct GNUNET_DATASTORE_PluginFunctions * | 458 | static struct GNUNET_DATASTORE_PluginFunctions * |
456 | load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | 459 | load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg) |
457 | { | 460 | { |
458 | static struct GNUNET_DATASTORE_PluginEnvironment env; | 461 | static struct GNUNET_DATASTORE_PluginEnvironment env; |
459 | struct GNUNET_DATASTORE_PluginFunctions *ret; | 462 | struct GNUNET_DATASTORE_PluginFunctions *ret; |
@@ -461,63 +464,63 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
461 | char *libname; | 464 | char *libname; |
462 | 465 | ||
463 | if (GNUNET_OK != | 466 | if (GNUNET_OK != |
464 | GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE", | 467 | GNUNET_CONFIGURATION_get_value_string(cfg, "DATASTORE", "DATABASE", |
465 | &name)) | 468 | &name)) |
466 | { | 469 | { |
467 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 470 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
468 | _("No `%s' specified for `%s' in configuration!\n"), "DATABASE", | 471 | _("No `%s' specified for `%s' in configuration!\n"), "DATABASE", |
469 | "DATASTORE"); | 472 | "DATASTORE"); |
470 | return NULL; | 473 | return NULL; |
471 | } | 474 | } |
472 | env.cfg = cfg; | 475 | env.cfg = cfg; |
473 | env.duc = &disk_utilization_change_cb; | 476 | env.duc = &disk_utilization_change_cb; |
474 | env.cls = NULL; | 477 | env.cls = NULL; |
475 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"), | 478 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"), |
476 | name); | 479 | name); |
477 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); | 480 | GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", name); |
478 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) | 481 | if (NULL == (ret = GNUNET_PLUGIN_load(libname, &env))) |
479 | { | 482 | { |
480 | fprintf (stderr, "Failed to load plugin `%s'!\n", name); | 483 | fprintf(stderr, "Failed to load plugin `%s'!\n", name); |
481 | GNUNET_free (name); | 484 | GNUNET_free(name); |
482 | GNUNET_free (libname); | 485 | GNUNET_free(libname); |
483 | return NULL; | 486 | return NULL; |
484 | } | 487 | } |
485 | GNUNET_free (libname); | 488 | GNUNET_free(libname); |
486 | GNUNET_free (name); | 489 | GNUNET_free(name); |
487 | return ret; | 490 | return ret; |
488 | } | 491 | } |
489 | 492 | ||
490 | 493 | ||
491 | static void | 494 | static void |
492 | run (void *cls, char *const *args, const char *cfgfile, | 495 | run(void *cls, char *const *args, const char *cfgfile, |
493 | const struct GNUNET_CONFIGURATION_Handle *c) | 496 | const struct GNUNET_CONFIGURATION_Handle *c) |
494 | { | 497 | { |
495 | struct GNUNET_DATASTORE_PluginFunctions *api; | 498 | struct GNUNET_DATASTORE_PluginFunctions *api; |
496 | struct CpsRunContext *crc; | 499 | struct CpsRunContext *crc; |
497 | 500 | ||
498 | if (NULL == c) | 501 | if (NULL == c) |
499 | { | 502 | { |
500 | GNUNET_break (0); | 503 | GNUNET_break(0); |
501 | return; | 504 | return; |
502 | } | 505 | } |
503 | api = load_plugin (c); | 506 | api = load_plugin(c); |
504 | if (api == NULL) | 507 | if (api == NULL) |
505 | { | 508 | { |
506 | fprintf (stderr, | 509 | fprintf(stderr, |
507 | "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); | 510 | "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); |
508 | return; | 511 | return; |
509 | } | 512 | } |
510 | crc = GNUNET_new (struct CpsRunContext); | 513 | crc = GNUNET_new(struct CpsRunContext); |
511 | crc->api = api; | 514 | crc->api = api; |
512 | crc->cfg = c; | 515 | crc->cfg = c; |
513 | crc->phase = RP_PUT; | 516 | crc->phase = RP_PUT; |
514 | ok = 2; | 517 | ok = 2; |
515 | GNUNET_SCHEDULER_add_now (&test, crc); | 518 | GNUNET_SCHEDULER_add_now(&test, crc); |
516 | } | 519 | } |
517 | 520 | ||
518 | 521 | ||
519 | int | 522 | int |
520 | main (int argc, char *argv[]) | 523 | main(int argc, char *argv[]) |
521 | { | 524 | { |
522 | char dir_name[PATH_MAX]; | 525 | char dir_name[PATH_MAX]; |
523 | char cfg_name[PATH_MAX]; | 526 | char cfg_name[PATH_MAX]; |
@@ -531,21 +534,21 @@ main (int argc, char *argv[]) | |||
531 | GNUNET_GETOPT_OPTION_END | 534 | GNUNET_GETOPT_OPTION_END |
532 | }; | 535 | }; |
533 | 536 | ||
534 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 537 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); |
535 | GNUNET_snprintf (dir_name, sizeof (dir_name), "/tmp/perf-gnunet-datastore-%s", | 538 | GNUNET_snprintf(dir_name, sizeof(dir_name), "/tmp/perf-gnunet-datastore-%s", |
536 | plugin_name); | 539 | plugin_name); |
537 | GNUNET_DISK_directory_remove (dir_name); | 540 | GNUNET_DISK_directory_remove(dir_name); |
538 | GNUNET_log_setup ("perf-plugin-datastore", | 541 | GNUNET_log_setup("perf-plugin-datastore", |
539 | "WARNING", | 542 | "WARNING", |
540 | NULL); | 543 | NULL); |
541 | GNUNET_snprintf (category, sizeof (category), "DATASTORE-%s", plugin_name); | 544 | GNUNET_snprintf(category, sizeof(category), "DATASTORE-%s", plugin_name); |
542 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), | 545 | GNUNET_snprintf(cfg_name, sizeof(cfg_name), |
543 | "perf_plugin_datastore_data_%s.conf", plugin_name); | 546 | "perf_plugin_datastore_data_%s.conf", plugin_name); |
544 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, | 547 | GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, xargv, |
545 | "perf-plugin-datastore", "nohelp", options, &run, NULL); | 548 | "perf-plugin-datastore", "nohelp", options, &run, NULL); |
546 | if (ok != 0) | 549 | if (ok != 0) |
547 | fprintf (stderr, "Missed some testcases: %u\n", ok); | 550 | fprintf(stderr, "Missed some testcases: %u\n", ok); |
548 | GNUNET_DISK_directory_remove (dir_name); | 551 | GNUNET_DISK_directory_remove(dir_name); |
549 | 552 | ||
550 | return ok; | 553 | return ok; |
551 | } | 554 | } |
diff --git a/src/datastore/plugin_datastore_heap.c b/src/datastore/plugin_datastore_heap.c index 30d271202..b7d73f0c4 100644 --- a/src/datastore/plugin_datastore_heap.c +++ b/src/datastore/plugin_datastore_heap.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file datastore/plugin_datastore_heap.c | 22 | * @file datastore/plugin_datastore_heap.c |
@@ -34,9 +34,7 @@ | |||
34 | /** | 34 | /** |
35 | * A value that we are storing. | 35 | * A value that we are storing. |
36 | */ | 36 | */ |
37 | struct Value | 37 | struct Value { |
38 | { | ||
39 | |||
40 | /** | 38 | /** |
41 | * Key for the value. | 39 | * Key for the value. |
42 | */ | 40 | */ |
@@ -92,16 +90,13 @@ struct Value | |||
92 | * Type of 'data'. | 90 | * Type of 'data'. |
93 | */ | 91 | */ |
94 | enum GNUNET_BLOCK_Type type; | 92 | enum GNUNET_BLOCK_Type type; |
95 | |||
96 | }; | 93 | }; |
97 | 94 | ||
98 | 95 | ||
99 | /** | 96 | /** |
100 | * We organize 0-anonymity values in arrays "by type". | 97 | * We organize 0-anonymity values in arrays "by type". |
101 | */ | 98 | */ |
102 | struct ZeroAnonByType | 99 | struct ZeroAnonByType { |
103 | { | ||
104 | |||
105 | /** | 100 | /** |
106 | * We keep these in a DLL. | 101 | * We keep these in a DLL. |
107 | */ | 102 | */ |
@@ -137,8 +132,7 @@ struct ZeroAnonByType | |||
137 | /** | 132 | /** |
138 | * Context for all functions in this plugin. | 133 | * Context for all functions in this plugin. |
139 | */ | 134 | */ |
140 | struct Plugin | 135 | struct Plugin { |
141 | { | ||
142 | /** | 136 | /** |
143 | * Our execution environment. | 137 | * Our execution environment. |
144 | */ | 138 | */ |
@@ -173,7 +167,6 @@ struct Plugin | |||
173 | * Size of all values we're storing. | 167 | * Size of all values we're storing. |
174 | */ | 168 | */ |
175 | unsigned long long size; | 169 | unsigned long long size; |
176 | |||
177 | }; | 170 | }; |
178 | 171 | ||
179 | 172 | ||
@@ -185,7 +178,7 @@ struct Plugin | |||
185 | * @return number of bytes used on disk | 178 | * @return number of bytes used on disk |
186 | */ | 179 | */ |
187 | static void | 180 | static void |
188 | heap_plugin_estimate_size (void *cls, unsigned long long *estimate) | 181 | heap_plugin_estimate_size(void *cls, unsigned long long *estimate) |
189 | { | 182 | { |
190 | struct Plugin *plugin = cls; | 183 | struct Plugin *plugin = cls; |
191 | 184 | ||
@@ -197,8 +190,7 @@ heap_plugin_estimate_size (void *cls, unsigned long long *estimate) | |||
197 | /** | 190 | /** |
198 | * Closure for iterator for updating. | 191 | * Closure for iterator for updating. |
199 | */ | 192 | */ |
200 | struct UpdateContext | 193 | struct UpdateContext { |
201 | { | ||
202 | /** | 194 | /** |
203 | * Number of bytes in 'data'. | 195 | * Number of bytes in 'data'. |
204 | */ | 196 | */ |
@@ -240,25 +232,25 @@ struct UpdateContext | |||
240 | * @return GNUNET_YES (continue iteration), GNUNET_NO if value was found | 232 | * @return GNUNET_YES (continue iteration), GNUNET_NO if value was found |
241 | */ | 233 | */ |
242 | static int | 234 | static int |
243 | update_iterator (void *cls, | 235 | update_iterator(void *cls, |
244 | const struct GNUNET_HashCode *key, | 236 | const struct GNUNET_HashCode *key, |
245 | void *val) | 237 | void *val) |
246 | { | 238 | { |
247 | struct UpdateContext *uc = cls; | 239 | struct UpdateContext *uc = cls; |
248 | struct Value *value = val; | 240 | struct Value *value = val; |
249 | 241 | ||
250 | if (value->size != uc->size) | 242 | if (value->size != uc->size) |
251 | return GNUNET_YES; | 243 | return GNUNET_YES; |
252 | if (0 != memcmp (value->data, uc->data, uc->size)) | 244 | if (0 != memcmp(value->data, uc->data, uc->size)) |
253 | return GNUNET_YES; | 245 | return GNUNET_YES; |
254 | uc->expiration = GNUNET_TIME_absolute_max (value->expiration, | 246 | uc->expiration = GNUNET_TIME_absolute_max(value->expiration, |
255 | uc->expiration); | 247 | uc->expiration); |
256 | if (value->expiration.abs_value_us != uc->expiration.abs_value_us) | 248 | if (value->expiration.abs_value_us != uc->expiration.abs_value_us) |
257 | { | 249 | { |
258 | value->expiration = uc->expiration; | 250 | value->expiration = uc->expiration; |
259 | GNUNET_CONTAINER_heap_update_cost (value->expire_heap, | 251 | GNUNET_CONTAINER_heap_update_cost(value->expire_heap, |
260 | value->expiration.abs_value_us); | 252 | value->expiration.abs_value_us); |
261 | } | 253 | } |
262 | /* Saturating adds, don't overflow */ | 254 | /* Saturating adds, don't overflow */ |
263 | if (value->priority > UINT32_MAX - uc->priority) | 255 | if (value->priority > UINT32_MAX - uc->priority) |
264 | value->priority = UINT32_MAX; | 256 | value->priority = UINT32_MAX; |
@@ -289,87 +281,88 @@ update_iterator (void *cls, | |||
289 | * @param cont_cls continuation closure | 281 | * @param cont_cls continuation closure |
290 | */ | 282 | */ |
291 | static void | 283 | static void |
292 | heap_plugin_put (void *cls, | 284 | heap_plugin_put(void *cls, |
293 | const struct GNUNET_HashCode *key, | 285 | const struct GNUNET_HashCode *key, |
294 | bool absent, | 286 | bool absent, |
295 | uint32_t size, | 287 | uint32_t size, |
296 | const void *data, | 288 | const void *data, |
297 | enum GNUNET_BLOCK_Type type, | 289 | enum GNUNET_BLOCK_Type type, |
298 | uint32_t priority, | 290 | uint32_t priority, |
299 | uint32_t anonymity, | 291 | uint32_t anonymity, |
300 | uint32_t replication, | 292 | uint32_t replication, |
301 | struct GNUNET_TIME_Absolute expiration, | 293 | struct GNUNET_TIME_Absolute expiration, |
302 | PluginPutCont cont, | 294 | PluginPutCont cont, |
303 | void *cont_cls) | 295 | void *cont_cls) |
304 | { | 296 | { |
305 | struct Plugin *plugin = cls; | 297 | struct Plugin *plugin = cls; |
306 | struct Value *value; | 298 | struct Value *value; |
307 | 299 | ||
308 | if (!absent) { | 300 | if (!absent) |
309 | struct UpdateContext uc; | ||
310 | |||
311 | uc.size = size; | ||
312 | uc.data = data; | ||
313 | uc.priority = priority; | ||
314 | uc.replication = replication; | ||
315 | uc.expiration = expiration; | ||
316 | uc.updated = false; | ||
317 | GNUNET_CONTAINER_multihashmap_get_multiple (plugin->keyvalue, | ||
318 | key, | ||
319 | &update_iterator, | ||
320 | &uc); | ||
321 | if (uc.updated) | ||
322 | { | 301 | { |
323 | cont (cont_cls, key, size, GNUNET_NO, NULL); | 302 | struct UpdateContext uc; |
324 | return; | 303 | |
304 | uc.size = size; | ||
305 | uc.data = data; | ||
306 | uc.priority = priority; | ||
307 | uc.replication = replication; | ||
308 | uc.expiration = expiration; | ||
309 | uc.updated = false; | ||
310 | GNUNET_CONTAINER_multihashmap_get_multiple(plugin->keyvalue, | ||
311 | key, | ||
312 | &update_iterator, | ||
313 | &uc); | ||
314 | if (uc.updated) | ||
315 | { | ||
316 | cont(cont_cls, key, size, GNUNET_NO, NULL); | ||
317 | return; | ||
318 | } | ||
325 | } | 319 | } |
326 | } | 320 | value = GNUNET_malloc(sizeof(struct Value) + size); |
327 | value = GNUNET_malloc (sizeof (struct Value) + size); | ||
328 | value->key = *key; | 321 | value->key = *key; |
329 | value->data = &value[1]; | 322 | value->data = &value[1]; |
330 | value->expire_heap = GNUNET_CONTAINER_heap_insert (plugin->by_expiration, | 323 | value->expire_heap = GNUNET_CONTAINER_heap_insert(plugin->by_expiration, |
331 | value, | 324 | value, |
332 | expiration.abs_value_us); | 325 | expiration.abs_value_us); |
333 | value->replication_heap = GNUNET_CONTAINER_heap_insert (plugin->by_replication, | 326 | value->replication_heap = GNUNET_CONTAINER_heap_insert(plugin->by_replication, |
334 | value, | 327 | value, |
335 | replication); | 328 | replication); |
336 | value->expiration = expiration; | 329 | value->expiration = expiration; |
337 | if (0 == anonymity) | 330 | if (0 == anonymity) |
338 | { | ||
339 | struct ZeroAnonByType *zabt; | ||
340 | |||
341 | for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next) | ||
342 | if (zabt->type == type) | ||
343 | break; | ||
344 | if (NULL == zabt) | ||
345 | { | ||
346 | zabt = GNUNET_new (struct ZeroAnonByType); | ||
347 | zabt->type = type; | ||
348 | GNUNET_CONTAINER_DLL_insert (plugin->zero_head, | ||
349 | plugin->zero_tail, | ||
350 | zabt); | ||
351 | } | ||
352 | if (zabt->array_size == zabt->array_pos) | ||
353 | { | 331 | { |
354 | GNUNET_array_grow (zabt->array, | 332 | struct ZeroAnonByType *zabt; |
355 | zabt->array_size, | 333 | |
356 | zabt->array_size * 2 + 4); | 334 | for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next) |
335 | if (zabt->type == type) | ||
336 | break; | ||
337 | if (NULL == zabt) | ||
338 | { | ||
339 | zabt = GNUNET_new(struct ZeroAnonByType); | ||
340 | zabt->type = type; | ||
341 | GNUNET_CONTAINER_DLL_insert(plugin->zero_head, | ||
342 | plugin->zero_tail, | ||
343 | zabt); | ||
344 | } | ||
345 | if (zabt->array_size == zabt->array_pos) | ||
346 | { | ||
347 | GNUNET_array_grow(zabt->array, | ||
348 | zabt->array_size, | ||
349 | zabt->array_size * 2 + 4); | ||
350 | } | ||
351 | value->zero_anon_offset = zabt->array_pos; | ||
352 | zabt->array[zabt->array_pos++] = value; | ||
357 | } | 353 | } |
358 | value->zero_anon_offset = zabt->array_pos; | ||
359 | zabt->array[zabt->array_pos++] = value; | ||
360 | } | ||
361 | value->size = size; | 354 | value->size = size; |
362 | value->priority = priority; | 355 | value->priority = priority; |
363 | value->anonymity = anonymity; | 356 | value->anonymity = anonymity; |
364 | value->replication = replication; | 357 | value->replication = replication; |
365 | value->type = type; | 358 | value->type = type; |
366 | GNUNET_memcpy (&value[1], data, size); | 359 | GNUNET_memcpy(&value[1], data, size); |
367 | GNUNET_CONTAINER_multihashmap_put (plugin->keyvalue, | 360 | GNUNET_CONTAINER_multihashmap_put(plugin->keyvalue, |
368 | &value->key, | 361 | &value->key, |
369 | value, | 362 | value, |
370 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 363 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
371 | plugin->size += size; | 364 | plugin->size += size; |
372 | cont (cont_cls, key, size, GNUNET_OK, NULL); | 365 | cont(cont_cls, key, size, GNUNET_OK, NULL); |
373 | } | 366 | } |
374 | 367 | ||
375 | 368 | ||
@@ -381,47 +374,45 @@ heap_plugin_put (void *cls, | |||
381 | * @param value value to delete | 374 | * @param value value to delete |
382 | */ | 375 | */ |
383 | static void | 376 | static void |
384 | delete_value (struct Plugin *plugin, | 377 | delete_value(struct Plugin *plugin, |
385 | struct Value *value) | 378 | struct Value *value) |
386 | { | 379 | { |
387 | GNUNET_assert (GNUNET_YES == | 380 | GNUNET_assert(GNUNET_YES == |
388 | GNUNET_CONTAINER_multihashmap_remove (plugin->keyvalue, | 381 | GNUNET_CONTAINER_multihashmap_remove(plugin->keyvalue, |
389 | &value->key, | 382 | &value->key, |
390 | value)); | 383 | value)); |
391 | GNUNET_assert (value == GNUNET_CONTAINER_heap_remove_node (value->expire_heap)); | 384 | GNUNET_assert(value == GNUNET_CONTAINER_heap_remove_node(value->expire_heap)); |
392 | GNUNET_assert (value == GNUNET_CONTAINER_heap_remove_node (value->replication_heap)); | 385 | GNUNET_assert(value == GNUNET_CONTAINER_heap_remove_node(value->replication_heap)); |
393 | if (0 == value->anonymity) | 386 | if (0 == value->anonymity) |
394 | { | ||
395 | struct ZeroAnonByType *zabt; | ||
396 | |||
397 | for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next) | ||
398 | if (zabt->type == value->type) | ||
399 | break; | ||
400 | GNUNET_assert (NULL != zabt); | ||
401 | zabt->array[value->zero_anon_offset] = zabt->array[--zabt->array_pos]; | ||
402 | zabt->array[value->zero_anon_offset]->zero_anon_offset = value->zero_anon_offset; | ||
403 | if (0 == zabt->array_pos) | ||
404 | { | 387 | { |
405 | GNUNET_array_grow (zabt->array, | 388 | struct ZeroAnonByType *zabt; |
406 | zabt->array_size, | 389 | |
407 | 0); | 390 | for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next) |
408 | GNUNET_CONTAINER_DLL_remove (plugin->zero_head, | 391 | if (zabt->type == value->type) |
409 | plugin->zero_tail, | 392 | break; |
410 | zabt); | 393 | GNUNET_assert(NULL != zabt); |
411 | GNUNET_free (zabt); | 394 | zabt->array[value->zero_anon_offset] = zabt->array[--zabt->array_pos]; |
395 | zabt->array[value->zero_anon_offset]->zero_anon_offset = value->zero_anon_offset; | ||
396 | if (0 == zabt->array_pos) | ||
397 | { | ||
398 | GNUNET_array_grow(zabt->array, | ||
399 | zabt->array_size, | ||
400 | 0); | ||
401 | GNUNET_CONTAINER_DLL_remove(plugin->zero_head, | ||
402 | plugin->zero_tail, | ||
403 | zabt); | ||
404 | GNUNET_free(zabt); | ||
405 | } | ||
412 | } | 406 | } |
413 | } | ||
414 | plugin->size -= value->size; | 407 | plugin->size -= value->size; |
415 | GNUNET_free (value); | 408 | GNUNET_free(value); |
416 | } | 409 | } |
417 | 410 | ||
418 | 411 | ||
419 | /** | 412 | /** |
420 | * Closure for iterator called during 'get_key'. | 413 | * Closure for iterator called during 'get_key'. |
421 | */ | 414 | */ |
422 | struct GetContext | 415 | struct GetContext { |
423 | { | ||
424 | |||
425 | /** | 416 | /** |
426 | * Lowest uid to consider. | 417 | * Lowest uid to consider. |
427 | */ | 418 | */ |
@@ -441,7 +432,6 @@ struct GetContext | |||
441 | * If true, return a random value | 432 | * If true, return a random value |
442 | */ | 433 | */ |
443 | bool random; | 434 | bool random; |
444 | |||
445 | }; | 435 | }; |
446 | 436 | ||
447 | 437 | ||
@@ -454,25 +444,25 @@ struct GetContext | |||
454 | * @return GNUNET_YES (continue iteration), GNUNET_NO if result was found | 444 | * @return GNUNET_YES (continue iteration), GNUNET_NO if result was found |
455 | */ | 445 | */ |
456 | static int | 446 | static int |
457 | get_iterator (void *cls, | 447 | get_iterator(void *cls, |
458 | const struct GNUNET_HashCode *key, | 448 | const struct GNUNET_HashCode *key, |
459 | void *val) | 449 | void *val) |
460 | { | 450 | { |
461 | struct GetContext *gc = cls; | 451 | struct GetContext *gc = cls; |
462 | struct Value *value = val; | 452 | struct Value *value = val; |
463 | 453 | ||
464 | if ( (gc->type != GNUNET_BLOCK_TYPE_ANY) && | 454 | if ((gc->type != GNUNET_BLOCK_TYPE_ANY) && |
465 | (gc->type != value->type) ) | 455 | (gc->type != value->type)) |
466 | return GNUNET_OK; | 456 | return GNUNET_OK; |
467 | if (gc->random) | 457 | if (gc->random) |
468 | { | 458 | { |
469 | gc->value = value; | 459 | gc->value = value; |
470 | return GNUNET_NO; | 460 | return GNUNET_NO; |
471 | } | 461 | } |
472 | if ( (uint64_t) (intptr_t) value < gc->next_uid) | 462 | if ((uint64_t)(intptr_t)value < gc->next_uid) |
473 | return GNUNET_OK; | 463 | return GNUNET_OK; |
474 | if ( (NULL != gc->value) && | 464 | if ((NULL != gc->value) && |
475 | (value > gc->value) ) | 465 | (value > gc->value)) |
476 | return GNUNET_OK; | 466 | return GNUNET_OK; |
477 | gc->value = value; | 467 | gc->value = value; |
478 | return GNUNET_OK; | 468 | return GNUNET_OK; |
@@ -493,13 +483,13 @@ get_iterator (void *cls, | |||
493 | * @param proc_cls closure for @a proc | 483 | * @param proc_cls closure for @a proc |
494 | */ | 484 | */ |
495 | static void | 485 | static void |
496 | heap_plugin_get_key (void *cls, | 486 | heap_plugin_get_key(void *cls, |
497 | uint64_t next_uid, | 487 | uint64_t next_uid, |
498 | bool random, | 488 | bool random, |
499 | const struct GNUNET_HashCode *key, | 489 | const struct GNUNET_HashCode *key, |
500 | enum GNUNET_BLOCK_Type type, | 490 | enum GNUNET_BLOCK_Type type, |
501 | PluginDatumProcessor proc, | 491 | PluginDatumProcessor proc, |
502 | void *proc_cls) | 492 | void *proc_cls) |
503 | { | 493 | { |
504 | struct Plugin *plugin = cls; | 494 | struct Plugin *plugin = cls; |
505 | struct GetContext gc; | 495 | struct GetContext gc; |
@@ -509,34 +499,34 @@ heap_plugin_get_key (void *cls, | |||
509 | gc.random = random; | 499 | gc.random = random; |
510 | gc.type = type; | 500 | gc.type = type; |
511 | if (NULL == key) | 501 | if (NULL == key) |
512 | { | 502 | { |
513 | GNUNET_CONTAINER_multihashmap_iterate (plugin->keyvalue, | 503 | GNUNET_CONTAINER_multihashmap_iterate(plugin->keyvalue, |
514 | &get_iterator, | 504 | &get_iterator, |
515 | &gc); | 505 | &gc); |
516 | } | 506 | } |
517 | else | 507 | else |
518 | { | 508 | { |
519 | GNUNET_CONTAINER_multihashmap_get_multiple (plugin->keyvalue, | 509 | GNUNET_CONTAINER_multihashmap_get_multiple(plugin->keyvalue, |
520 | key, | 510 | key, |
521 | &get_iterator, | 511 | &get_iterator, |
522 | &gc); | 512 | &gc); |
523 | } | 513 | } |
524 | if (NULL == gc.value) | 514 | if (NULL == gc.value) |
525 | { | 515 | { |
526 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 516 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
527 | return; | 517 | return; |
528 | } | 518 | } |
529 | GNUNET_assert (GNUNET_OK == | 519 | GNUNET_assert(GNUNET_OK == |
530 | proc (proc_cls, | 520 | proc(proc_cls, |
531 | &gc.value->key, | 521 | &gc.value->key, |
532 | gc.value->size, | 522 | gc.value->size, |
533 | &gc.value[1], | 523 | &gc.value[1], |
534 | gc.value->type, | 524 | gc.value->type, |
535 | gc.value->priority, | 525 | gc.value->priority, |
536 | gc.value->anonymity, | 526 | gc.value->anonymity, |
537 | gc.value->replication, | 527 | gc.value->replication, |
538 | gc.value->expiration, | 528 | gc.value->expiration, |
539 | (uint64_t) (intptr_t) gc.value)); | 529 | (uint64_t)(intptr_t)gc.value)); |
540 | } | 530 | } |
541 | 531 | ||
542 | 532 | ||
@@ -552,45 +542,45 @@ heap_plugin_get_key (void *cls, | |||
552 | * @param proc_cls closure for proc | 542 | * @param proc_cls closure for proc |
553 | */ | 543 | */ |
554 | static void | 544 | static void |
555 | heap_plugin_get_replication (void *cls, | 545 | heap_plugin_get_replication(void *cls, |
556 | PluginDatumProcessor proc, | 546 | PluginDatumProcessor proc, |
557 | void *proc_cls) | 547 | void *proc_cls) |
558 | { | 548 | { |
559 | struct Plugin *plugin = cls; | 549 | struct Plugin *plugin = cls; |
560 | struct Value *value; | 550 | struct Value *value; |
561 | 551 | ||
562 | value = GNUNET_CONTAINER_heap_remove_root (plugin->by_replication); | 552 | value = GNUNET_CONTAINER_heap_remove_root(plugin->by_replication); |
563 | if (NULL == value) | 553 | if (NULL == value) |
564 | { | 554 | { |
565 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 555 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
566 | return; | 556 | return; |
567 | } | 557 | } |
568 | if (value->replication > 0) | 558 | if (value->replication > 0) |
569 | { | 559 | { |
570 | value->replication--; | 560 | value->replication--; |
571 | value->replication_heap = GNUNET_CONTAINER_heap_insert (plugin->by_replication, | 561 | value->replication_heap = GNUNET_CONTAINER_heap_insert(plugin->by_replication, |
572 | value, | 562 | value, |
573 | value->replication); | 563 | value->replication); |
574 | } | 564 | } |
575 | else | 565 | else |
576 | { | 566 | { |
577 | /* need a better way to pick a random item, replication level is always 0 */ | 567 | /* need a better way to pick a random item, replication level is always 0 */ |
578 | value->replication_heap = GNUNET_CONTAINER_heap_insert (plugin->by_replication, | 568 | value->replication_heap = GNUNET_CONTAINER_heap_insert(plugin->by_replication, |
579 | value, | 569 | value, |
580 | value->replication); | 570 | value->replication); |
581 | value = GNUNET_CONTAINER_heap_walk_get_next (plugin->by_replication); | 571 | value = GNUNET_CONTAINER_heap_walk_get_next(plugin->by_replication); |
582 | } | 572 | } |
583 | GNUNET_assert (GNUNET_OK == | 573 | GNUNET_assert(GNUNET_OK == |
584 | proc (proc_cls, | 574 | proc(proc_cls, |
585 | &value->key, | 575 | &value->key, |
586 | value->size, | 576 | value->size, |
587 | &value[1], | 577 | &value[1], |
588 | value->type, | 578 | value->type, |
589 | value->priority, | 579 | value->priority, |
590 | value->anonymity, | 580 | value->anonymity, |
591 | value->replication, | 581 | value->replication, |
592 | value->expiration, | 582 | value->expiration, |
593 | (uint64_t) (intptr_t) value)); | 583 | (uint64_t)(intptr_t)value)); |
594 | } | 584 | } |
595 | 585 | ||
596 | 586 | ||
@@ -603,30 +593,30 @@ heap_plugin_get_replication (void *cls, | |||
603 | * @param proc_cls closure for proc | 593 | * @param proc_cls closure for proc |
604 | */ | 594 | */ |
605 | static void | 595 | static void |
606 | heap_plugin_get_expiration (void *cls, PluginDatumProcessor proc, | 596 | heap_plugin_get_expiration(void *cls, PluginDatumProcessor proc, |
607 | void *proc_cls) | 597 | void *proc_cls) |
608 | { | 598 | { |
609 | struct Plugin *plugin = cls; | 599 | struct Plugin *plugin = cls; |
610 | struct Value *value; | 600 | struct Value *value; |
611 | 601 | ||
612 | value = GNUNET_CONTAINER_heap_peek (plugin->by_expiration); | 602 | value = GNUNET_CONTAINER_heap_peek(plugin->by_expiration); |
613 | if (NULL == value) | 603 | if (NULL == value) |
614 | { | 604 | { |
615 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 605 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
616 | return; | 606 | return; |
617 | } | 607 | } |
618 | if (GNUNET_NO == | 608 | if (GNUNET_NO == |
619 | proc (proc_cls, | 609 | proc(proc_cls, |
620 | &value->key, | 610 | &value->key, |
621 | value->size, | 611 | value->size, |
622 | &value[1], | 612 | &value[1], |
623 | value->type, | 613 | value->type, |
624 | value->priority, | 614 | value->priority, |
625 | value->anonymity, | 615 | value->anonymity, |
626 | value->replication, | 616 | value->replication, |
627 | value->expiration, | 617 | value->expiration, |
628 | (uint64_t) (intptr_t) value)) | 618 | (uint64_t)(intptr_t)value)) |
629 | delete_value (plugin, value); | 619 | delete_value(plugin, value); |
630 | } | 620 | } |
631 | 621 | ||
632 | 622 | ||
@@ -642,45 +632,45 @@ heap_plugin_get_expiration (void *cls, PluginDatumProcessor proc, | |||
642 | * @param proc_cls closure for proc | 632 | * @param proc_cls closure for proc |
643 | */ | 633 | */ |
644 | static void | 634 | static void |
645 | heap_plugin_get_zero_anonymity (void *cls, uint64_t next_uid, | 635 | heap_plugin_get_zero_anonymity(void *cls, uint64_t next_uid, |
646 | enum GNUNET_BLOCK_Type type, | 636 | enum GNUNET_BLOCK_Type type, |
647 | PluginDatumProcessor proc, void *proc_cls) | 637 | PluginDatumProcessor proc, void *proc_cls) |
648 | { | 638 | { |
649 | struct Plugin *plugin = cls; | 639 | struct Plugin *plugin = cls; |
650 | struct ZeroAnonByType *zabt; | 640 | struct ZeroAnonByType *zabt; |
651 | struct Value *value = NULL; | 641 | struct Value *value = NULL; |
652 | 642 | ||
653 | for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next) | 643 | for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next) |
654 | { | ||
655 | if ( (type != GNUNET_BLOCK_TYPE_ANY) && | ||
656 | (type != zabt->type) ) | ||
657 | continue; | ||
658 | for (int i = 0; i < zabt->array_pos; ++i) | ||
659 | { | 644 | { |
660 | if ( (uint64_t) (intptr_t) zabt->array[i] < next_uid) | 645 | if ((type != GNUNET_BLOCK_TYPE_ANY) && |
661 | continue; | 646 | (type != zabt->type)) |
662 | if ( (NULL != value) && | ||
663 | (zabt->array[i] > value) ) | ||
664 | continue; | 647 | continue; |
665 | value = zabt->array[i]; | 648 | for (int i = 0; i < zabt->array_pos; ++i) |
649 | { | ||
650 | if ((uint64_t)(intptr_t)zabt->array[i] < next_uid) | ||
651 | continue; | ||
652 | if ((NULL != value) && | ||
653 | (zabt->array[i] > value)) | ||
654 | continue; | ||
655 | value = zabt->array[i]; | ||
656 | } | ||
666 | } | 657 | } |
667 | } | ||
668 | if (NULL == value) | 658 | if (NULL == value) |
669 | { | 659 | { |
670 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 660 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
671 | return; | 661 | return; |
672 | } | 662 | } |
673 | GNUNET_assert (GNUNET_OK == | 663 | GNUNET_assert(GNUNET_OK == |
674 | proc (proc_cls, | 664 | proc(proc_cls, |
675 | &value->key, | 665 | &value->key, |
676 | value->size, | 666 | value->size, |
677 | &value[1], | 667 | &value[1], |
678 | value->type, | 668 | value->type, |
679 | value->priority, | 669 | value->priority, |
680 | value->anonymity, | 670 | value->anonymity, |
681 | value->replication, | 671 | value->replication, |
682 | value->expiration, | 672 | value->expiration, |
683 | (uint64_t) (intptr_t) value)); | 673 | (uint64_t)(intptr_t)value)); |
684 | } | 674 | } |
685 | 675 | ||
686 | 676 | ||
@@ -688,7 +678,7 @@ heap_plugin_get_zero_anonymity (void *cls, uint64_t next_uid, | |||
688 | * Drop database. | 678 | * Drop database. |
689 | */ | 679 | */ |
690 | static void | 680 | static void |
691 | heap_plugin_drop (void *cls) | 681 | heap_plugin_drop(void *cls) |
692 | { | 682 | { |
693 | /* nothing needs to be done */ | 683 | /* nothing needs to be done */ |
694 | } | 684 | } |
@@ -697,8 +687,7 @@ heap_plugin_drop (void *cls) | |||
697 | /** | 687 | /** |
698 | * Closure for the 'return_value' function. | 688 | * Closure for the 'return_value' function. |
699 | */ | 689 | */ |
700 | struct GetAllContext | 690 | struct GetAllContext { |
701 | { | ||
702 | /** | 691 | /** |
703 | * Function to call. | 692 | * Function to call. |
704 | */ | 693 | */ |
@@ -720,15 +709,15 @@ struct GetAllContext | |||
720 | * @return GNUNET_OK (continue to iterate) | 709 | * @return GNUNET_OK (continue to iterate) |
721 | */ | 710 | */ |
722 | static int | 711 | static int |
723 | return_value (void *cls, | 712 | return_value(void *cls, |
724 | const struct GNUNET_HashCode *key, | 713 | const struct GNUNET_HashCode *key, |
725 | void *val) | 714 | void *val) |
726 | { | 715 | { |
727 | struct GetAllContext *gac = cls; | 716 | struct GetAllContext *gac = cls; |
728 | 717 | ||
729 | gac->proc (gac->proc_cls, | 718 | gac->proc(gac->proc_cls, |
730 | key, | 719 | key, |
731 | 1); | 720 | 1); |
732 | return GNUNET_OK; | 721 | return GNUNET_OK; |
733 | } | 722 | } |
734 | 723 | ||
@@ -741,28 +730,26 @@ return_value (void *cls, | |||
741 | * @param proc_cls closure for proc | 730 | * @param proc_cls closure for proc |
742 | */ | 731 | */ |
743 | static void | 732 | static void |
744 | heap_get_keys (void *cls, | 733 | heap_get_keys(void *cls, |
745 | PluginKeyProcessor proc, | 734 | PluginKeyProcessor proc, |
746 | void *proc_cls) | 735 | void *proc_cls) |
747 | { | 736 | { |
748 | struct Plugin *plugin = cls; | 737 | struct Plugin *plugin = cls; |
749 | struct GetAllContext gac; | 738 | struct GetAllContext gac; |
750 | 739 | ||
751 | gac.proc = proc; | 740 | gac.proc = proc; |
752 | gac.proc_cls = proc_cls; | 741 | gac.proc_cls = proc_cls; |
753 | GNUNET_CONTAINER_multihashmap_iterate (plugin->keyvalue, | 742 | GNUNET_CONTAINER_multihashmap_iterate(plugin->keyvalue, |
754 | &return_value, | 743 | &return_value, |
755 | &gac); | 744 | &gac); |
756 | proc (proc_cls, NULL, 0); | 745 | proc(proc_cls, NULL, 0); |
757 | } | 746 | } |
758 | 747 | ||
759 | 748 | ||
760 | /** | 749 | /** |
761 | * Closure for iterator called during 'remove_key'. | 750 | * Closure for iterator called during 'remove_key'. |
762 | */ | 751 | */ |
763 | struct RemoveContext | 752 | struct RemoveContext { |
764 | { | ||
765 | |||
766 | /** | 753 | /** |
767 | * Value found. | 754 | * Value found. |
768 | */ | 755 | */ |
@@ -777,7 +764,6 @@ struct RemoveContext | |||
777 | * Data to remove. | 764 | * Data to remove. |
778 | */ | 765 | */ |
779 | const void *data; | 766 | const void *data; |
780 | |||
781 | }; | 767 | }; |
782 | 768 | ||
783 | 769 | ||
@@ -790,16 +776,16 @@ struct RemoveContext | |||
790 | * @return GNUNET_YES (continue iteration), GNUNET_NO if result was found | 776 | * @return GNUNET_YES (continue iteration), GNUNET_NO if result was found |
791 | */ | 777 | */ |
792 | static int | 778 | static int |
793 | remove_iterator (void *cls, | 779 | remove_iterator(void *cls, |
794 | const struct GNUNET_HashCode *key, | 780 | const struct GNUNET_HashCode *key, |
795 | void *val) | 781 | void *val) |
796 | { | 782 | { |
797 | struct RemoveContext *rc = cls; | 783 | struct RemoveContext *rc = cls; |
798 | struct Value *value = val; | 784 | struct Value *value = val; |
799 | 785 | ||
800 | if (value->size != rc->size) | 786 | if (value->size != rc->size) |
801 | return GNUNET_YES; | 787 | return GNUNET_YES; |
802 | if (0 != memcmp (value->data, rc->data, rc->size)) | 788 | if (0 != memcmp(value->data, rc->data, rc->size)) |
803 | return GNUNET_YES; | 789 | return GNUNET_YES; |
804 | rc->value = value; | 790 | rc->value = value; |
805 | return GNUNET_NO; | 791 | return GNUNET_NO; |
@@ -817,12 +803,12 @@ remove_iterator (void *cls, | |||
817 | * @param cont_cls continuation closure for @a cont | 803 | * @param cont_cls continuation closure for @a cont |
818 | */ | 804 | */ |
819 | static void | 805 | static void |
820 | heap_plugin_remove_key (void *cls, | 806 | heap_plugin_remove_key(void *cls, |
821 | const struct GNUNET_HashCode *key, | 807 | const struct GNUNET_HashCode *key, |
822 | uint32_t size, | 808 | uint32_t size, |
823 | const void *data, | 809 | const void *data, |
824 | PluginRemoveCont cont, | 810 | PluginRemoveCont cont, |
825 | void *cont_cls) | 811 | void *cont_cls) |
826 | { | 812 | { |
827 | struct Plugin *plugin = cls; | 813 | struct Plugin *plugin = cls; |
828 | struct RemoveContext rc; | 814 | struct RemoveContext rc; |
@@ -830,26 +816,26 @@ heap_plugin_remove_key (void *cls, | |||
830 | rc.value = NULL; | 816 | rc.value = NULL; |
831 | rc.size = size; | 817 | rc.size = size; |
832 | rc.data = data; | 818 | rc.data = data; |
833 | GNUNET_CONTAINER_multihashmap_get_multiple (plugin->keyvalue, | 819 | GNUNET_CONTAINER_multihashmap_get_multiple(plugin->keyvalue, |
834 | key, | 820 | key, |
835 | &remove_iterator, | 821 | &remove_iterator, |
836 | &rc); | 822 | &rc); |
837 | if (NULL == rc.value) | 823 | if (NULL == rc.value) |
838 | { | 824 | { |
839 | cont (cont_cls, | 825 | cont(cont_cls, |
840 | key, | 826 | key, |
841 | size, | 827 | size, |
842 | GNUNET_NO, | 828 | GNUNET_NO, |
843 | NULL); | 829 | NULL); |
844 | return; | 830 | return; |
845 | } | 831 | } |
846 | delete_value (plugin, | 832 | delete_value(plugin, |
847 | rc.value); | 833 | rc.value); |
848 | cont (cont_cls, | 834 | cont(cont_cls, |
849 | key, | 835 | key, |
850 | size, | 836 | size, |
851 | GNUNET_OK, | 837 | GNUNET_OK, |
852 | NULL); | 838 | NULL); |
853 | } | 839 | } |
854 | 840 | ||
855 | 841 | ||
@@ -860,7 +846,7 @@ heap_plugin_remove_key (void *cls, | |||
860 | * @return our "struct Plugin*" | 846 | * @return our "struct Plugin*" |
861 | */ | 847 | */ |
862 | void * | 848 | void * |
863 | libgnunet_plugin_datastore_heap_init (void *cls) | 849 | libgnunet_plugin_datastore_heap_init(void *cls) |
864 | { | 850 | { |
865 | struct GNUNET_DATASTORE_PluginEnvironment *env = cls; | 851 | struct GNUNET_DATASTORE_PluginEnvironment *env = cls; |
866 | struct GNUNET_DATASTORE_PluginFunctions *api; | 852 | struct GNUNET_DATASTORE_PluginFunctions *api; |
@@ -868,17 +854,17 @@ libgnunet_plugin_datastore_heap_init (void *cls) | |||
868 | unsigned long long esize; | 854 | unsigned long long esize; |
869 | 855 | ||
870 | if (GNUNET_OK != | 856 | if (GNUNET_OK != |
871 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 857 | GNUNET_CONFIGURATION_get_value_number(env->cfg, |
872 | "datastore-heap", | 858 | "datastore-heap", |
873 | "HASHMAPSIZE", | 859 | "HASHMAPSIZE", |
874 | &esize)) | 860 | &esize)) |
875 | esize = 128 * 1024; | 861 | esize = 128 * 1024; |
876 | plugin = GNUNET_new (struct Plugin); | 862 | plugin = GNUNET_new(struct Plugin); |
877 | plugin->env = env; | 863 | plugin->env = env; |
878 | plugin->keyvalue = GNUNET_CONTAINER_multihashmap_create (esize, GNUNET_YES); | 864 | plugin->keyvalue = GNUNET_CONTAINER_multihashmap_create(esize, GNUNET_YES); |
879 | plugin->by_expiration = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 865 | plugin->by_expiration = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); |
880 | plugin->by_replication = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX); | 866 | plugin->by_replication = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MAX); |
881 | api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions); | 867 | api = GNUNET_new(struct GNUNET_DATASTORE_PluginFunctions); |
882 | api->cls = plugin; | 868 | api->cls = plugin; |
883 | api->estimate_size = &heap_plugin_estimate_size; | 869 | api->estimate_size = &heap_plugin_estimate_size; |
884 | api->put = &heap_plugin_put; | 870 | api->put = &heap_plugin_put; |
@@ -889,8 +875,8 @@ libgnunet_plugin_datastore_heap_init (void *cls) | |||
889 | api->drop = &heap_plugin_drop; | 875 | api->drop = &heap_plugin_drop; |
890 | api->get_keys = &heap_get_keys; | 876 | api->get_keys = &heap_get_keys; |
891 | api->remove_key = &heap_plugin_remove_key; | 877 | api->remove_key = &heap_plugin_remove_key; |
892 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "heap", | 878 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "heap", |
893 | _("Heap database running\n")); | 879 | _("Heap database running\n")); |
894 | return api; | 880 | return api; |
895 | } | 881 | } |
896 | 882 | ||
@@ -904,14 +890,14 @@ libgnunet_plugin_datastore_heap_init (void *cls) | |||
904 | * @return GNUNET_OK (continue to iterate) | 890 | * @return GNUNET_OK (continue to iterate) |
905 | */ | 891 | */ |
906 | static int | 892 | static int |
907 | free_value (void *cls, | 893 | free_value(void *cls, |
908 | const struct GNUNET_HashCode *key, | 894 | const struct GNUNET_HashCode *key, |
909 | void *val) | 895 | void *val) |
910 | { | 896 | { |
911 | struct Plugin *plugin = cls; | 897 | struct Plugin *plugin = cls; |
912 | struct Value *value = val; | 898 | struct Value *value = val; |
913 | 899 | ||
914 | delete_value (plugin, value); | 900 | delete_value(plugin, value); |
915 | return GNUNET_OK; | 901 | return GNUNET_OK; |
916 | } | 902 | } |
917 | 903 | ||
@@ -922,19 +908,19 @@ free_value (void *cls, | |||
922 | * @return always NULL | 908 | * @return always NULL |
923 | */ | 909 | */ |
924 | void * | 910 | void * |
925 | libgnunet_plugin_datastore_heap_done (void *cls) | 911 | libgnunet_plugin_datastore_heap_done(void *cls) |
926 | { | 912 | { |
927 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; | 913 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; |
928 | struct Plugin *plugin = api->cls; | 914 | struct Plugin *plugin = api->cls; |
929 | 915 | ||
930 | GNUNET_CONTAINER_multihashmap_iterate (plugin->keyvalue, | 916 | GNUNET_CONTAINER_multihashmap_iterate(plugin->keyvalue, |
931 | &free_value, | 917 | &free_value, |
932 | plugin); | 918 | plugin); |
933 | GNUNET_CONTAINER_multihashmap_destroy (plugin->keyvalue); | 919 | GNUNET_CONTAINER_multihashmap_destroy(plugin->keyvalue); |
934 | GNUNET_CONTAINER_heap_destroy (plugin->by_expiration); | 920 | GNUNET_CONTAINER_heap_destroy(plugin->by_expiration); |
935 | GNUNET_CONTAINER_heap_destroy (plugin->by_replication); | 921 | GNUNET_CONTAINER_heap_destroy(plugin->by_replication); |
936 | GNUNET_free (plugin); | 922 | GNUNET_free(plugin); |
937 | GNUNET_free (api); | 923 | GNUNET_free(api); |
938 | return NULL; | 924 | return NULL; |
939 | } | 925 | } |
940 | 926 | ||
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c index 68371d389..c670a6d99 100644 --- a/src/datastore/plugin_datastore_mysql.c +++ b/src/datastore/plugin_datastore_mysql.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file datastore/plugin_datastore_mysql.c | 22 | * @file datastore/plugin_datastore_mysql.c |
@@ -129,8 +129,7 @@ | |||
129 | /** | 129 | /** |
130 | * Context for all functions in this plugin. | 130 | * Context for all functions in this plugin. |
131 | */ | 131 | */ |
132 | struct Plugin | 132 | struct Plugin { |
133 | { | ||
134 | /** | 133 | /** |
135 | * Our execution environment. | 134 | * Our execution environment. |
136 | */ | 135 | */ |
@@ -150,41 +149,41 @@ struct Plugin | |||
150 | #define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?" | 149 | #define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?" |
151 | struct GNUNET_MYSQL_StatementHandle *delete_entry_by_uid; | 150 | struct GNUNET_MYSQL_StatementHandle *delete_entry_by_uid; |
152 | 151 | ||
153 | #define DELETE_ENTRY_BY_HASH_VALUE "DELETE FROM gn090 "\ | 152 | #define DELETE_ENTRY_BY_HASH_VALUE "DELETE FROM gn090 " \ |
154 | "WHERE hash = ? AND "\ | 153 | "WHERE hash = ? AND " \ |
155 | "value = ? "\ | 154 | "value = ? " \ |
156 | "LIMIT 1" | 155 | "LIMIT 1" |
157 | struct GNUNET_MYSQL_StatementHandle *delete_entry_by_hash_value; | 156 | struct GNUNET_MYSQL_StatementHandle *delete_entry_by_hash_value; |
158 | 157 | ||
159 | #define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, uid" | 158 | #define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, uid" |
160 | 159 | ||
161 | #define SELECT_ENTRY "SELECT " RESULT_COLUMNS " FROM gn090 "\ | 160 | #define SELECT_ENTRY "SELECT " RESULT_COLUMNS " FROM gn090 " \ |
162 | "WHERE uid >= ? AND "\ | 161 | "WHERE uid >= ? AND " \ |
163 | "(rvalue >= ? OR 0 = ?) "\ | 162 | "(rvalue >= ? OR 0 = ?) " \ |
164 | "ORDER BY uid LIMIT 1" | 163 | "ORDER BY uid LIMIT 1" |
165 | struct GNUNET_MYSQL_StatementHandle *select_entry; | 164 | struct GNUNET_MYSQL_StatementHandle *select_entry; |
166 | 165 | ||
167 | #define SELECT_ENTRY_BY_HASH "SELECT " RESULT_COLUMNS " FROM gn090 "\ | 166 | #define SELECT_ENTRY_BY_HASH "SELECT " RESULT_COLUMNS " FROM gn090 " \ |
168 | "FORCE INDEX (idx_hash_type_uid) "\ | 167 | "FORCE INDEX (idx_hash_type_uid) " \ |
169 | "WHERE hash=? AND "\ | 168 | "WHERE hash=? AND " \ |
170 | "uid >= ? AND "\ | 169 | "uid >= ? AND " \ |
171 | "(rvalue >= ? OR 0 = ?) "\ | 170 | "(rvalue >= ? OR 0 = ?) " \ |
172 | "ORDER BY uid LIMIT 1" | 171 | "ORDER BY uid LIMIT 1" |
173 | struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash; | 172 | struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash; |
174 | 173 | ||
175 | #define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT " RESULT_COLUMNS " FROM gn090 "\ | 174 | #define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT " RESULT_COLUMNS " FROM gn090 " \ |
176 | "FORCE INDEX (idx_hash_type_uid) "\ | 175 | "FORCE INDEX (idx_hash_type_uid) " \ |
177 | "WHERE hash = ? AND "\ | 176 | "WHERE hash = ? AND " \ |
178 | "type = ? AND "\ | 177 | "type = ? AND " \ |
179 | "uid >= ? AND "\ | 178 | "uid >= ? AND " \ |
180 | "(rvalue >= ? OR 0 = ?) "\ | 179 | "(rvalue >= ? OR 0 = ?) " \ |
181 | "ORDER BY uid LIMIT 1" | 180 | "ORDER BY uid LIMIT 1" |
182 | struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_and_type; | 181 | struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_and_type; |
183 | 182 | ||
184 | #define UPDATE_ENTRY "UPDATE gn090 SET "\ | 183 | #define UPDATE_ENTRY "UPDATE gn090 SET " \ |
185 | "prio = prio + ?, "\ | 184 | "prio = prio + ?, " \ |
186 | "repl = repl + ?, "\ | 185 | "repl = repl + ?, " \ |
187 | "expire = GREATEST(expire, ?) "\ | 186 | "expire = GREATEST(expire, ?) " \ |
188 | "WHERE hash = ? AND vhash = ?" | 187 | "WHERE hash = ? AND vhash = ?" |
189 | struct GNUNET_MYSQL_StatementHandle *update_entry; | 188 | struct GNUNET_MYSQL_StatementHandle *update_entry; |
190 | 189 | ||
@@ -194,31 +193,31 @@ struct Plugin | |||
194 | #define SELECT_SIZE "SELECT SUM(LENGTH(value)+256) FROM gn090" | 193 | #define SELECT_SIZE "SELECT SUM(LENGTH(value)+256) FROM gn090" |
195 | struct GNUNET_MYSQL_StatementHandle *get_size; | 194 | struct GNUNET_MYSQL_StatementHandle *get_size; |
196 | 195 | ||
197 | #define SELECT_IT_NON_ANONYMOUS "SELECT " RESULT_COLUMNS " FROM gn090 "\ | 196 | #define SELECT_IT_NON_ANONYMOUS "SELECT " RESULT_COLUMNS " FROM gn090 " \ |
198 | "FORCE INDEX (idx_anonLevel_type_rvalue) "\ | 197 | "FORCE INDEX (idx_anonLevel_type_rvalue) " \ |
199 | "WHERE anonLevel=0 AND "\ | 198 | "WHERE anonLevel=0 AND " \ |
200 | "type=? AND "\ | 199 | "type=? AND " \ |
201 | "uid >= ? "\ | 200 | "uid >= ? " \ |
202 | "ORDER BY uid LIMIT 1" | 201 | "ORDER BY uid LIMIT 1" |
203 | struct GNUNET_MYSQL_StatementHandle *zero_iter; | 202 | struct GNUNET_MYSQL_StatementHandle *zero_iter; |
204 | 203 | ||
205 | #define SELECT_IT_EXPIRATION "SELECT " RESULT_COLUMNS " FROM gn090 "\ | 204 | #define SELECT_IT_EXPIRATION "SELECT " RESULT_COLUMNS " FROM gn090 " \ |
206 | "FORCE INDEX (idx_expire) "\ | 205 | "FORCE INDEX (idx_expire) " \ |
207 | "WHERE expire < ? "\ | 206 | "WHERE expire < ? " \ |
208 | "ORDER BY expire ASC LIMIT 1" | 207 | "ORDER BY expire ASC LIMIT 1" |
209 | struct GNUNET_MYSQL_StatementHandle *select_expiration; | 208 | struct GNUNET_MYSQL_StatementHandle *select_expiration; |
210 | 209 | ||
211 | #define SELECT_IT_PRIORITY "SELECT " RESULT_COLUMNS " FROM gn090 "\ | 210 | #define SELECT_IT_PRIORITY "SELECT " RESULT_COLUMNS " FROM gn090 " \ |
212 | "FORCE INDEX (idx_prio) "\ | 211 | "FORCE INDEX (idx_prio) " \ |
213 | "ORDER BY prio ASC LIMIT 1" | 212 | "ORDER BY prio ASC LIMIT 1" |
214 | struct GNUNET_MYSQL_StatementHandle *select_priority; | 213 | struct GNUNET_MYSQL_StatementHandle *select_priority; |
215 | 214 | ||
216 | #define SELECT_IT_REPLICATION "SELECT " RESULT_COLUMNS " FROM gn090 "\ | 215 | #define SELECT_IT_REPLICATION "SELECT " RESULT_COLUMNS " FROM gn090 " \ |
217 | "FORCE INDEX (idx_repl_rvalue) "\ | 216 | "FORCE INDEX (idx_repl_rvalue) " \ |
218 | "WHERE repl=? AND "\ | 217 | "WHERE repl=? AND " \ |
219 | " (rvalue>=? OR"\ | 218 | " (rvalue>=? OR" \ |
220 | " NOT EXISTS (SELECT 1 FROM gn090 FORCE INDEX (idx_repl_rvalue) WHERE repl=? AND rvalue>=?)) "\ | 219 | " NOT EXISTS (SELECT 1 FROM gn090 FORCE INDEX (idx_repl_rvalue) WHERE repl=? AND rvalue>=?)) " \ |
221 | "ORDER BY rvalue ASC "\ | 220 | "ORDER BY rvalue ASC " \ |
222 | "LIMIT 1" | 221 | "LIMIT 1" |
223 | struct GNUNET_MYSQL_StatementHandle *select_replication; | 222 | struct GNUNET_MYSQL_StatementHandle *select_replication; |
224 | 223 | ||
@@ -227,7 +226,6 @@ struct Plugin | |||
227 | 226 | ||
228 | #define GET_ALL_KEYS "SELECT hash from gn090" | 227 | #define GET_ALL_KEYS "SELECT hash from gn090" |
229 | struct GNUNET_MYSQL_StatementHandle *get_all_keys; | 228 | struct GNUNET_MYSQL_StatementHandle *get_all_keys; |
230 | |||
231 | }; | 229 | }; |
232 | 230 | ||
233 | #define MAX_PARAM 16 | 231 | #define MAX_PARAM 16 |
@@ -240,29 +238,29 @@ struct Plugin | |||
240 | * @return #GNUNET_OK on success, #GNUNET_NO if no such value exists, #GNUNET_SYSERR on error | 238 | * @return #GNUNET_OK on success, #GNUNET_NO if no such value exists, #GNUNET_SYSERR on error |
241 | */ | 239 | */ |
242 | static int | 240 | static int |
243 | do_delete_entry (struct Plugin *plugin, | 241 | do_delete_entry(struct Plugin *plugin, |
244 | unsigned long long uid) | 242 | unsigned long long uid) |
245 | { | 243 | { |
246 | int ret; | 244 | int ret; |
247 | uint64_t uid64 = (uint64_t) uid; | 245 | uint64_t uid64 = (uint64_t)uid; |
248 | struct GNUNET_MY_QueryParam params_delete[] = { | 246 | struct GNUNET_MY_QueryParam params_delete[] = { |
249 | GNUNET_MY_query_param_uint64 (&uid64), | 247 | GNUNET_MY_query_param_uint64(&uid64), |
250 | GNUNET_MY_query_param_end | 248 | GNUNET_MY_query_param_end |
251 | }; | 249 | }; |
252 | 250 | ||
253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 251 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
254 | "Deleting value %llu from gn090 table\n", | 252 | "Deleting value %llu from gn090 table\n", |
255 | uid); | 253 | uid); |
256 | ret = GNUNET_MY_exec_prepared (plugin->mc, | 254 | ret = GNUNET_MY_exec_prepared(plugin->mc, |
257 | plugin->delete_entry_by_uid, | 255 | plugin->delete_entry_by_uid, |
258 | params_delete); | 256 | params_delete); |
259 | if (ret >= 0) | 257 | if (ret >= 0) |
260 | { | 258 | { |
261 | return GNUNET_OK; | 259 | return GNUNET_OK; |
262 | } | 260 | } |
263 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 261 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
264 | "Deleting value %llu from gn090 table failed\n", | 262 | "Deleting value %llu from gn090 table failed\n", |
265 | (unsigned long long) uid); | 263 | (unsigned long long)uid); |
266 | return ret; | 264 | return ret; |
267 | } | 265 | } |
268 | 266 | ||
@@ -275,8 +273,8 @@ do_delete_entry (struct Plugin *plugin, | |||
275 | * @return number of bytes used on disk | 273 | * @return number of bytes used on disk |
276 | */ | 274 | */ |
277 | static void | 275 | static void |
278 | mysql_plugin_estimate_size (void *cls, | 276 | mysql_plugin_estimate_size(void *cls, |
279 | unsigned long long *estimate) | 277 | unsigned long long *estimate) |
280 | { | 278 | { |
281 | struct Plugin *plugin = cls; | 279 | struct Plugin *plugin = cls; |
282 | uint64_t total; | 280 | uint64_t total; |
@@ -285,29 +283,29 @@ mysql_plugin_estimate_size (void *cls, | |||
285 | GNUNET_MY_query_param_end | 283 | GNUNET_MY_query_param_end |
286 | }; | 284 | }; |
287 | struct GNUNET_MY_ResultSpec results_get[] = { | 285 | struct GNUNET_MY_ResultSpec results_get[] = { |
288 | GNUNET_MY_result_spec_uint64 (&total), | 286 | GNUNET_MY_result_spec_uint64(&total), |
289 | GNUNET_MY_result_spec_end | 287 | GNUNET_MY_result_spec_end |
290 | }; | 288 | }; |
291 | 289 | ||
292 | ret = GNUNET_MY_exec_prepared (plugin->mc, | 290 | ret = GNUNET_MY_exec_prepared(plugin->mc, |
293 | plugin->get_size, | 291 | plugin->get_size, |
294 | params_get); | 292 | params_get); |
295 | *estimate = 0; | 293 | *estimate = 0; |
296 | total = UINT64_MAX; | 294 | total = UINT64_MAX; |
297 | if ( (GNUNET_OK == ret) && | 295 | if ((GNUNET_OK == ret) && |
298 | (GNUNET_OK == | 296 | (GNUNET_OK == |
299 | GNUNET_MY_extract_result (plugin->get_size, | 297 | GNUNET_MY_extract_result(plugin->get_size, |
300 | results_get)) ) | 298 | results_get))) |
301 | { | 299 | { |
302 | *estimate = (unsigned long long) total; | 300 | *estimate = (unsigned long long)total; |
303 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 301 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
304 | "Size estimate for MySQL payload is %lld\n", | 302 | "Size estimate for MySQL payload is %lld\n", |
305 | (long long) total); | 303 | (long long)total); |
306 | GNUNET_assert (UINT64_MAX != total); | 304 | GNUNET_assert(UINT64_MAX != total); |
307 | GNUNET_break (GNUNET_NO == | 305 | GNUNET_break(GNUNET_NO == |
308 | GNUNET_MY_extract_result (plugin->get_size, | 306 | GNUNET_MY_extract_result(plugin->get_size, |
309 | NULL)); | 307 | NULL)); |
310 | } | 308 | } |
311 | } | 309 | } |
312 | 310 | ||
313 | 311 | ||
@@ -328,116 +326,116 @@ mysql_plugin_estimate_size (void *cls, | |||
328 | * @param cont_cls closure for @a cont | 326 | * @param cont_cls closure for @a cont |
329 | */ | 327 | */ |
330 | static void | 328 | static void |
331 | mysql_plugin_put (void *cls, | 329 | mysql_plugin_put(void *cls, |
332 | const struct GNUNET_HashCode *key, | 330 | const struct GNUNET_HashCode *key, |
333 | bool absent, | 331 | bool absent, |
334 | uint32_t size, | 332 | uint32_t size, |
335 | const void *data, | 333 | const void *data, |
336 | enum GNUNET_BLOCK_Type type, | 334 | enum GNUNET_BLOCK_Type type, |
337 | uint32_t priority, | 335 | uint32_t priority, |
338 | uint32_t anonymity, | 336 | uint32_t anonymity, |
339 | uint32_t replication, | 337 | uint32_t replication, |
340 | struct GNUNET_TIME_Absolute expiration, | 338 | struct GNUNET_TIME_Absolute expiration, |
341 | PluginPutCont cont, | 339 | PluginPutCont cont, |
342 | void *cont_cls) | 340 | void *cont_cls) |
343 | { | 341 | { |
344 | struct Plugin *plugin = cls; | 342 | struct Plugin *plugin = cls; |
345 | uint64_t lexpiration = expiration.abs_value_us; | 343 | uint64_t lexpiration = expiration.abs_value_us; |
346 | struct GNUNET_HashCode vhash; | 344 | struct GNUNET_HashCode vhash; |
347 | 345 | ||
348 | GNUNET_CRYPTO_hash (data, | 346 | GNUNET_CRYPTO_hash(data, |
349 | size, | 347 | size, |
350 | &vhash); | 348 | &vhash); |
351 | if (!absent) | 349 | if (!absent) |
352 | { | ||
353 | struct GNUNET_MY_QueryParam params_update[] = { | ||
354 | GNUNET_MY_query_param_uint32 (&priority), | ||
355 | GNUNET_MY_query_param_uint32 (&replication), | ||
356 | GNUNET_MY_query_param_uint64 (&lexpiration), | ||
357 | GNUNET_MY_query_param_auto_from_type (key), | ||
358 | GNUNET_MY_query_param_auto_from_type (&vhash), | ||
359 | GNUNET_MY_query_param_end | ||
360 | }; | ||
361 | |||
362 | if (GNUNET_OK != | ||
363 | GNUNET_MY_exec_prepared (plugin->mc, | ||
364 | plugin->update_entry, | ||
365 | params_update)) | ||
366 | { | 350 | { |
367 | cont (cont_cls, | 351 | struct GNUNET_MY_QueryParam params_update[] = { |
368 | key, | 352 | GNUNET_MY_query_param_uint32(&priority), |
369 | size, | 353 | GNUNET_MY_query_param_uint32(&replication), |
370 | GNUNET_SYSERR, | 354 | GNUNET_MY_query_param_uint64(&lexpiration), |
371 | _("MySQL statement run failure")); | 355 | GNUNET_MY_query_param_auto_from_type(key), |
372 | return; | 356 | GNUNET_MY_query_param_auto_from_type(&vhash), |
373 | } | 357 | GNUNET_MY_query_param_end |
374 | 358 | }; | |
375 | MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt (plugin->update_entry); | 359 | |
376 | my_ulonglong rows = mysql_stmt_affected_rows (stmt); | 360 | if (GNUNET_OK != |
377 | 361 | GNUNET_MY_exec_prepared(plugin->mc, | |
378 | GNUNET_break (GNUNET_NO == | 362 | plugin->update_entry, |
379 | GNUNET_MY_extract_result (plugin->update_entry, | 363 | params_update)) |
364 | { | ||
365 | cont(cont_cls, | ||
366 | key, | ||
367 | size, | ||
368 | GNUNET_SYSERR, | ||
369 | _("MySQL statement run failure")); | ||
370 | return; | ||
371 | } | ||
372 | |||
373 | MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt(plugin->update_entry); | ||
374 | my_ulonglong rows = mysql_stmt_affected_rows(stmt); | ||
375 | |||
376 | GNUNET_break(GNUNET_NO == | ||
377 | GNUNET_MY_extract_result(plugin->update_entry, | ||
380 | NULL)); | 378 | NULL)); |
381 | if (0 != rows) | 379 | if (0 != rows) |
382 | { | 380 | { |
383 | cont (cont_cls, | 381 | cont(cont_cls, |
384 | key, | 382 | key, |
385 | size, | 383 | size, |
386 | GNUNET_NO, | 384 | GNUNET_NO, |
387 | NULL); | 385 | NULL); |
388 | return; | 386 | return; |
387 | } | ||
389 | } | 388 | } |
390 | } | ||
391 | 389 | ||
392 | uint64_t lrvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 390 | uint64_t lrvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, |
393 | UINT64_MAX); | 391 | UINT64_MAX); |
394 | struct GNUNET_MY_QueryParam params_insert[] = { | 392 | struct GNUNET_MY_QueryParam params_insert[] = { |
395 | GNUNET_MY_query_param_uint32 (&replication), | 393 | GNUNET_MY_query_param_uint32(&replication), |
396 | GNUNET_MY_query_param_uint32 (&type), | 394 | GNUNET_MY_query_param_uint32(&type), |
397 | GNUNET_MY_query_param_uint32 (&priority), | 395 | GNUNET_MY_query_param_uint32(&priority), |
398 | GNUNET_MY_query_param_uint32 (&anonymity), | 396 | GNUNET_MY_query_param_uint32(&anonymity), |
399 | GNUNET_MY_query_param_uint64 (&lexpiration), | 397 | GNUNET_MY_query_param_uint64(&lexpiration), |
400 | GNUNET_MY_query_param_uint64 (&lrvalue), | 398 | GNUNET_MY_query_param_uint64(&lrvalue), |
401 | GNUNET_MY_query_param_auto_from_type (key), | 399 | GNUNET_MY_query_param_auto_from_type(key), |
402 | GNUNET_MY_query_param_auto_from_type (&vhash), | 400 | GNUNET_MY_query_param_auto_from_type(&vhash), |
403 | GNUNET_MY_query_param_fixed_size (data, size), | 401 | GNUNET_MY_query_param_fixed_size(data, size), |
404 | GNUNET_MY_query_param_end | 402 | GNUNET_MY_query_param_end |
405 | }; | 403 | }; |
406 | 404 | ||
407 | if (size > MAX_DATUM_SIZE) | 405 | if (size > MAX_DATUM_SIZE) |
408 | { | 406 | { |
409 | GNUNET_break (0); | 407 | GNUNET_break(0); |
410 | cont (cont_cls, key, size, GNUNET_SYSERR, _("Data too large")); | 408 | cont(cont_cls, key, size, GNUNET_SYSERR, _("Data too large")); |
411 | return; | 409 | return; |
412 | } | 410 | } |
413 | 411 | ||
414 | if (GNUNET_OK != | 412 | if (GNUNET_OK != |
415 | GNUNET_MY_exec_prepared (plugin->mc, | 413 | GNUNET_MY_exec_prepared(plugin->mc, |
416 | plugin->insert_entry, | 414 | plugin->insert_entry, |
417 | params_insert)) | 415 | params_insert)) |
418 | { | 416 | { |
419 | cont (cont_cls, | 417 | cont(cont_cls, |
420 | key, | 418 | key, |
421 | size, | 419 | size, |
422 | GNUNET_SYSERR, | 420 | GNUNET_SYSERR, |
423 | _("MySQL statement run failure")); | 421 | _("MySQL statement run failure")); |
424 | return; | 422 | return; |
425 | } | 423 | } |
426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 424 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
427 | "Inserted value `%s' with size %u into gn090 table\n", | 425 | "Inserted value `%s' with size %u into gn090 table\n", |
428 | GNUNET_h2s (key), | 426 | GNUNET_h2s(key), |
429 | (unsigned int) size); | 427 | (unsigned int)size); |
430 | if (size > 0) | 428 | if (size > 0) |
431 | plugin->env->duc (plugin->env->cls, | 429 | plugin->env->duc(plugin->env->cls, |
432 | size); | 430 | size); |
433 | GNUNET_break (GNUNET_NO == | 431 | GNUNET_break(GNUNET_NO == |
434 | GNUNET_MY_extract_result (plugin->insert_entry, | 432 | GNUNET_MY_extract_result(plugin->insert_entry, |
435 | NULL)); | 433 | NULL)); |
436 | cont (cont_cls, | 434 | cont(cont_cls, |
437 | key, | 435 | key, |
438 | size, | 436 | size, |
439 | GNUNET_OK, | 437 | GNUNET_OK, |
440 | NULL); | 438 | NULL); |
441 | } | 439 | } |
442 | 440 | ||
443 | 441 | ||
@@ -452,11 +450,11 @@ mysql_plugin_put (void *cls, | |||
452 | * @param params_select arguments to initialize stmt | 450 | * @param params_select arguments to initialize stmt |
453 | */ | 451 | */ |
454 | static void | 452 | static void |
455 | execute_select (struct Plugin *plugin, | 453 | execute_select(struct Plugin *plugin, |
456 | struct GNUNET_MYSQL_StatementHandle *stmt, | 454 | struct GNUNET_MYSQL_StatementHandle *stmt, |
457 | PluginDatumProcessor proc, | 455 | PluginDatumProcessor proc, |
458 | void *proc_cls, | 456 | void *proc_cls, |
459 | struct GNUNET_MY_QueryParam *params_select) | 457 | struct GNUNET_MY_QueryParam *params_select) |
460 | { | 458 | { |
461 | int ret; | 459 | int ret; |
462 | uint32_t replication; | 460 | uint32_t replication; |
@@ -469,65 +467,65 @@ execute_select (struct Plugin *plugin, | |||
469 | struct GNUNET_HashCode key; | 467 | struct GNUNET_HashCode key; |
470 | struct GNUNET_TIME_Absolute expiration; | 468 | struct GNUNET_TIME_Absolute expiration; |
471 | struct GNUNET_MY_ResultSpec results_select[] = { | 469 | struct GNUNET_MY_ResultSpec results_select[] = { |
472 | GNUNET_MY_result_spec_uint32 (&replication), | 470 | GNUNET_MY_result_spec_uint32(&replication), |
473 | GNUNET_MY_result_spec_uint32 (&type), | 471 | GNUNET_MY_result_spec_uint32(&type), |
474 | GNUNET_MY_result_spec_uint32 (&priority), | 472 | GNUNET_MY_result_spec_uint32(&priority), |
475 | GNUNET_MY_result_spec_uint32 (&anonymity), | 473 | GNUNET_MY_result_spec_uint32(&anonymity), |
476 | GNUNET_MY_result_spec_absolute_time (&expiration), | 474 | GNUNET_MY_result_spec_absolute_time(&expiration), |
477 | GNUNET_MY_result_spec_auto_from_type (&key), | 475 | GNUNET_MY_result_spec_auto_from_type(&key), |
478 | GNUNET_MY_result_spec_variable_size (&value, &value_size), | 476 | GNUNET_MY_result_spec_variable_size(&value, &value_size), |
479 | GNUNET_MY_result_spec_uint64 (&uid), | 477 | GNUNET_MY_result_spec_uint64(&uid), |
480 | GNUNET_MY_result_spec_end | 478 | GNUNET_MY_result_spec_end |
481 | }; | 479 | }; |
482 | 480 | ||
483 | ret = GNUNET_MY_exec_prepared (plugin->mc, | 481 | ret = GNUNET_MY_exec_prepared(plugin->mc, |
484 | stmt, | 482 | stmt, |
485 | params_select); | 483 | params_select); |
486 | if (GNUNET_OK != ret) | 484 | if (GNUNET_OK != ret) |
487 | { | 485 | { |
488 | proc (proc_cls, | 486 | proc(proc_cls, |
489 | NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 487 | NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
490 | return; | 488 | return; |
491 | } | 489 | } |
492 | 490 | ||
493 | ret = GNUNET_MY_extract_result (stmt, | 491 | ret = GNUNET_MY_extract_result(stmt, |
494 | results_select); | 492 | results_select); |
495 | if (GNUNET_OK != ret) | 493 | if (GNUNET_OK != ret) |
496 | { | 494 | { |
497 | proc (proc_cls, | 495 | proc(proc_cls, |
498 | NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 496 | NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
499 | return; | 497 | return; |
500 | } | 498 | } |
501 | 499 | ||
502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 500 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
503 | "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n", | 501 | "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n", |
504 | (unsigned int) value_size, | 502 | (unsigned int)value_size, |
505 | GNUNET_h2s (&key), | 503 | GNUNET_h2s(&key), |
506 | (unsigned int) priority, | 504 | (unsigned int)priority, |
507 | (unsigned int) anonymity, | 505 | (unsigned int)anonymity, |
508 | GNUNET_STRINGS_absolute_time_to_string (expiration)); | 506 | GNUNET_STRINGS_absolute_time_to_string(expiration)); |
509 | GNUNET_assert (value_size < MAX_DATUM_SIZE); | 507 | GNUNET_assert(value_size < MAX_DATUM_SIZE); |
510 | GNUNET_break (GNUNET_NO == | 508 | GNUNET_break(GNUNET_NO == |
511 | GNUNET_MY_extract_result (stmt, | 509 | GNUNET_MY_extract_result(stmt, |
512 | NULL)); | 510 | NULL)); |
513 | ret = proc (proc_cls, | 511 | ret = proc(proc_cls, |
514 | &key, | 512 | &key, |
515 | value_size, | 513 | value_size, |
516 | value, | 514 | value, |
517 | type, | 515 | type, |
518 | priority, | 516 | priority, |
519 | anonymity, | 517 | anonymity, |
520 | replication, | 518 | replication, |
521 | expiration, | 519 | expiration, |
522 | uid); | 520 | uid); |
523 | GNUNET_MY_cleanup_result (results_select); | 521 | GNUNET_MY_cleanup_result(results_select); |
524 | if (GNUNET_NO == ret) | 522 | if (GNUNET_NO == ret) |
525 | { | 523 | { |
526 | do_delete_entry (plugin, uid); | 524 | do_delete_entry(plugin, uid); |
527 | if (0 != value_size) | 525 | if (0 != value_size) |
528 | plugin->env->duc (plugin->env->cls, | 526 | plugin->env->duc(plugin->env->cls, |
529 | - value_size); | 527 | -value_size); |
530 | } | 528 | } |
531 | } | 529 | } |
532 | 530 | ||
533 | 531 | ||
@@ -545,74 +543,74 @@ execute_select (struct Plugin *plugin, | |||
545 | * @param proc_cls closure for @a proc | 543 | * @param proc_cls closure for @a proc |
546 | */ | 544 | */ |
547 | static void | 545 | static void |
548 | mysql_plugin_get_key (void *cls, | 546 | mysql_plugin_get_key(void *cls, |
549 | uint64_t next_uid, | 547 | uint64_t next_uid, |
550 | bool random, | 548 | bool random, |
551 | const struct GNUNET_HashCode *key, | 549 | const struct GNUNET_HashCode *key, |
552 | enum GNUNET_BLOCK_Type type, | 550 | enum GNUNET_BLOCK_Type type, |
553 | PluginDatumProcessor proc, | 551 | PluginDatumProcessor proc, |
554 | void *proc_cls) | 552 | void *proc_cls) |
555 | { | 553 | { |
556 | struct Plugin *plugin = cls; | 554 | struct Plugin *plugin = cls; |
557 | uint64_t rvalue; | 555 | uint64_t rvalue; |
558 | 556 | ||
559 | if (random) | 557 | if (random) |
560 | { | 558 | { |
561 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 559 | rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, |
562 | UINT64_MAX); | 560 | UINT64_MAX); |
563 | next_uid = 0; | 561 | next_uid = 0; |
564 | } | 562 | } |
565 | else | 563 | else |
566 | rvalue = 0; | 564 | rvalue = 0; |
567 | 565 | ||
568 | if (NULL == key) | 566 | if (NULL == key) |
569 | { | 567 | { |
570 | struct GNUNET_MY_QueryParam params_select[] = { | 568 | struct GNUNET_MY_QueryParam params_select[] = { |
571 | GNUNET_MY_query_param_uint64 (&next_uid), | 569 | GNUNET_MY_query_param_uint64(&next_uid), |
572 | GNUNET_MY_query_param_uint64 (&rvalue), | 570 | GNUNET_MY_query_param_uint64(&rvalue), |
573 | GNUNET_MY_query_param_uint64 (&rvalue), | 571 | GNUNET_MY_query_param_uint64(&rvalue), |
574 | GNUNET_MY_query_param_end | 572 | GNUNET_MY_query_param_end |
575 | }; | 573 | }; |
576 | 574 | ||
577 | execute_select (plugin, | 575 | execute_select(plugin, |
578 | plugin->select_entry, | 576 | plugin->select_entry, |
579 | proc, | 577 | proc, |
580 | proc_cls, | 578 | proc_cls, |
581 | params_select); | 579 | params_select); |
582 | } | 580 | } |
583 | else if (type != GNUNET_BLOCK_TYPE_ANY) | 581 | else if (type != GNUNET_BLOCK_TYPE_ANY) |
584 | { | 582 | { |
585 | struct GNUNET_MY_QueryParam params_select[] = { | 583 | struct GNUNET_MY_QueryParam params_select[] = { |
586 | GNUNET_MY_query_param_auto_from_type (key), | 584 | GNUNET_MY_query_param_auto_from_type(key), |
587 | GNUNET_MY_query_param_uint32 (&type), | 585 | GNUNET_MY_query_param_uint32(&type), |
588 | GNUNET_MY_query_param_uint64 (&next_uid), | 586 | GNUNET_MY_query_param_uint64(&next_uid), |
589 | GNUNET_MY_query_param_uint64 (&rvalue), | 587 | GNUNET_MY_query_param_uint64(&rvalue), |
590 | GNUNET_MY_query_param_uint64 (&rvalue), | 588 | GNUNET_MY_query_param_uint64(&rvalue), |
591 | GNUNET_MY_query_param_end | 589 | GNUNET_MY_query_param_end |
592 | }; | 590 | }; |
593 | 591 | ||
594 | execute_select (plugin, | 592 | execute_select(plugin, |
595 | plugin->select_entry_by_hash_and_type, | 593 | plugin->select_entry_by_hash_and_type, |
596 | proc, | 594 | proc, |
597 | proc_cls, | 595 | proc_cls, |
598 | params_select); | 596 | params_select); |
599 | } | 597 | } |
600 | else | 598 | else |
601 | { | 599 | { |
602 | struct GNUNET_MY_QueryParam params_select[] = { | 600 | struct GNUNET_MY_QueryParam params_select[] = { |
603 | GNUNET_MY_query_param_auto_from_type (key), | 601 | GNUNET_MY_query_param_auto_from_type(key), |
604 | GNUNET_MY_query_param_uint64 (&next_uid), | 602 | GNUNET_MY_query_param_uint64(&next_uid), |
605 | GNUNET_MY_query_param_uint64 (&rvalue), | 603 | GNUNET_MY_query_param_uint64(&rvalue), |
606 | GNUNET_MY_query_param_uint64 (&rvalue), | 604 | GNUNET_MY_query_param_uint64(&rvalue), |
607 | GNUNET_MY_query_param_end | 605 | GNUNET_MY_query_param_end |
608 | }; | 606 | }; |
609 | 607 | ||
610 | execute_select (plugin, | 608 | execute_select(plugin, |
611 | plugin->select_entry_by_hash, | 609 | plugin->select_entry_by_hash, |
612 | proc, | 610 | proc, |
613 | proc_cls, | 611 | proc_cls, |
614 | params_select); | 612 | params_select); |
615 | } | 613 | } |
616 | } | 614 | } |
617 | 615 | ||
618 | 616 | ||
@@ -628,35 +626,33 @@ mysql_plugin_get_key (void *cls, | |||
628 | * @param proc_cls closure for @a proc | 626 | * @param proc_cls closure for @a proc |
629 | */ | 627 | */ |
630 | static void | 628 | static void |
631 | mysql_plugin_get_zero_anonymity (void *cls, | 629 | mysql_plugin_get_zero_anonymity(void *cls, |
632 | uint64_t next_uid, | 630 | uint64_t next_uid, |
633 | enum GNUNET_BLOCK_Type type, | 631 | enum GNUNET_BLOCK_Type type, |
634 | PluginDatumProcessor proc, | 632 | PluginDatumProcessor proc, |
635 | void *proc_cls) | 633 | void *proc_cls) |
636 | { | 634 | { |
637 | struct Plugin *plugin = cls; | 635 | struct Plugin *plugin = cls; |
638 | uint32_t typei = (uint32_t) type; | 636 | uint32_t typei = (uint32_t)type; |
639 | 637 | ||
640 | struct GNUNET_MY_QueryParam params_zero_iter[] = { | 638 | struct GNUNET_MY_QueryParam params_zero_iter[] = { |
641 | GNUNET_MY_query_param_uint32 (&typei), | 639 | GNUNET_MY_query_param_uint32(&typei), |
642 | GNUNET_MY_query_param_uint64 (&next_uid), | 640 | GNUNET_MY_query_param_uint64(&next_uid), |
643 | GNUNET_MY_query_param_end | 641 | GNUNET_MY_query_param_end |
644 | }; | 642 | }; |
645 | 643 | ||
646 | execute_select (plugin, | 644 | execute_select(plugin, |
647 | plugin->zero_iter, | 645 | plugin->zero_iter, |
648 | proc, | 646 | proc, |
649 | proc_cls, | 647 | proc_cls, |
650 | params_zero_iter); | 648 | params_zero_iter); |
651 | } | 649 | } |
652 | 650 | ||
653 | 651 | ||
654 | /** | 652 | /** |
655 | * Context for #repl_proc() function. | 653 | * Context for #repl_proc() function. |
656 | */ | 654 | */ |
657 | struct ReplCtx | 655 | struct ReplCtx { |
658 | { | ||
659 | |||
660 | /** | 656 | /** |
661 | * Plugin handle. | 657 | * Plugin handle. |
662 | */ | 658 | */ |
@@ -695,49 +691,49 @@ struct ReplCtx | |||
695 | * #GNUNET_NO to delete the item and continue (if supported) | 691 | * #GNUNET_NO to delete the item and continue (if supported) |
696 | */ | 692 | */ |
697 | static int | 693 | static int |
698 | repl_proc (void *cls, | 694 | repl_proc(void *cls, |
699 | const struct GNUNET_HashCode *key, | 695 | const struct GNUNET_HashCode *key, |
700 | uint32_t size, | 696 | uint32_t size, |
701 | const void *data, | 697 | const void *data, |
702 | enum GNUNET_BLOCK_Type type, | 698 | enum GNUNET_BLOCK_Type type, |
703 | uint32_t priority, | 699 | uint32_t priority, |
704 | uint32_t anonymity, | 700 | uint32_t anonymity, |
705 | uint32_t replication, | 701 | uint32_t replication, |
706 | struct GNUNET_TIME_Absolute expiration, | 702 | struct GNUNET_TIME_Absolute expiration, |
707 | uint64_t uid) | 703 | uint64_t uid) |
708 | { | 704 | { |
709 | struct ReplCtx *rc = cls; | 705 | struct ReplCtx *rc = cls; |
710 | struct Plugin *plugin = rc->plugin; | 706 | struct Plugin *plugin = rc->plugin; |
711 | int ret; | 707 | int ret; |
712 | int iret; | 708 | int iret; |
713 | 709 | ||
714 | ret = rc->proc (rc->proc_cls, | 710 | ret = rc->proc(rc->proc_cls, |
715 | key, | 711 | key, |
716 | size, | 712 | size, |
717 | data, | 713 | data, |
718 | type, | 714 | type, |
719 | priority, | 715 | priority, |
720 | anonymity, | 716 | anonymity, |
721 | replication, | 717 | replication, |
722 | expiration, | 718 | expiration, |
723 | uid); | 719 | uid); |
724 | if (NULL != key) | 720 | if (NULL != key) |
725 | { | ||
726 | struct GNUNET_MY_QueryParam params_proc[] = { | ||
727 | GNUNET_MY_query_param_uint64 (&uid), | ||
728 | GNUNET_MY_query_param_end | ||
729 | }; | ||
730 | |||
731 | iret = GNUNET_MY_exec_prepared (plugin->mc, | ||
732 | plugin->dec_repl, | ||
733 | params_proc); | ||
734 | if (GNUNET_SYSERR == iret) | ||
735 | { | 721 | { |
736 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 722 | struct GNUNET_MY_QueryParam params_proc[] = { |
737 | "Failed to reduce replication counter\n"); | 723 | GNUNET_MY_query_param_uint64(&uid), |
738 | return GNUNET_SYSERR; | 724 | GNUNET_MY_query_param_end |
725 | }; | ||
726 | |||
727 | iret = GNUNET_MY_exec_prepared(plugin->mc, | ||
728 | plugin->dec_repl, | ||
729 | params_proc); | ||
730 | if (GNUNET_SYSERR == iret) | ||
731 | { | ||
732 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
733 | "Failed to reduce replication counter\n"); | ||
734 | return GNUNET_SYSERR; | ||
735 | } | ||
739 | } | 736 | } |
740 | } | ||
741 | return ret; | 737 | return ret; |
742 | } | 738 | } |
743 | 739 | ||
@@ -754,9 +750,9 @@ repl_proc (void *cls, | |||
754 | * @param proc_cls closure for @a proc | 750 | * @param proc_cls closure for @a proc |
755 | */ | 751 | */ |
756 | static void | 752 | static void |
757 | mysql_plugin_get_replication (void *cls, | 753 | mysql_plugin_get_replication(void *cls, |
758 | PluginDatumProcessor proc, | 754 | PluginDatumProcessor proc, |
759 | void *proc_cls) | 755 | void *proc_cls) |
760 | { | 756 | { |
761 | struct Plugin *plugin = cls; | 757 | struct Plugin *plugin = cls; |
762 | uint64_t rvalue; | 758 | uint64_t rvalue; |
@@ -766,14 +762,14 @@ mysql_plugin_get_replication (void *cls, | |||
766 | GNUNET_MY_query_param_end | 762 | GNUNET_MY_query_param_end |
767 | }; | 763 | }; |
768 | struct GNUNET_MY_ResultSpec results_get[] = { | 764 | struct GNUNET_MY_ResultSpec results_get[] = { |
769 | GNUNET_MY_result_spec_uint32 (&repl), | 765 | GNUNET_MY_result_spec_uint32(&repl), |
770 | GNUNET_MY_result_spec_end | 766 | GNUNET_MY_result_spec_end |
771 | }; | 767 | }; |
772 | struct GNUNET_MY_QueryParam params_select[] = { | 768 | struct GNUNET_MY_QueryParam params_select[] = { |
773 | GNUNET_MY_query_param_uint32 (&repl), | 769 | GNUNET_MY_query_param_uint32(&repl), |
774 | GNUNET_MY_query_param_uint64 (&rvalue), | 770 | GNUNET_MY_query_param_uint64(&rvalue), |
775 | GNUNET_MY_query_param_uint32 (&repl), | 771 | GNUNET_MY_query_param_uint32(&repl), |
776 | GNUNET_MY_query_param_uint64 (&rvalue), | 772 | GNUNET_MY_query_param_uint64(&rvalue), |
777 | GNUNET_MY_query_param_end | 773 | GNUNET_MY_query_param_end |
778 | }; | 774 | }; |
779 | 775 | ||
@@ -782,32 +778,32 @@ mysql_plugin_get_replication (void *cls, | |||
782 | rc.proc_cls = proc_cls; | 778 | rc.proc_cls = proc_cls; |
783 | 779 | ||
784 | if (1 != | 780 | if (1 != |
785 | GNUNET_MY_exec_prepared (plugin->mc, | 781 | GNUNET_MY_exec_prepared(plugin->mc, |
786 | plugin->max_repl, | 782 | plugin->max_repl, |
787 | params_get)) | 783 | params_get)) |
788 | { | 784 | { |
789 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 785 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
790 | return; | 786 | return; |
791 | } | 787 | } |
792 | 788 | ||
793 | if (GNUNET_OK != | 789 | if (GNUNET_OK != |
794 | GNUNET_MY_extract_result (plugin->max_repl, | 790 | GNUNET_MY_extract_result(plugin->max_repl, |
795 | results_get)) | 791 | results_get)) |
796 | { | 792 | { |
797 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 793 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
798 | return; | 794 | return; |
799 | } | 795 | } |
800 | GNUNET_break (GNUNET_NO == | 796 | GNUNET_break(GNUNET_NO == |
801 | GNUNET_MY_extract_result (plugin->max_repl, | 797 | GNUNET_MY_extract_result(plugin->max_repl, |
802 | NULL)); | 798 | NULL)); |
803 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 799 | rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, |
804 | UINT64_MAX); | 800 | UINT64_MAX); |
805 | 801 | ||
806 | execute_select (plugin, | 802 | execute_select(plugin, |
807 | plugin->select_replication, | 803 | plugin->select_replication, |
808 | &repl_proc, | 804 | &repl_proc, |
809 | &rc, | 805 | &rc, |
810 | params_select); | 806 | params_select); |
811 | } | 807 | } |
812 | 808 | ||
813 | 809 | ||
@@ -819,9 +815,9 @@ mysql_plugin_get_replication (void *cls, | |||
819 | * @param proc_cls closure for @a proc | 815 | * @param proc_cls closure for @a proc |
820 | */ | 816 | */ |
821 | static void | 817 | static void |
822 | mysql_plugin_get_keys (void *cls, | 818 | mysql_plugin_get_keys(void *cls, |
823 | PluginKeyProcessor proc, | 819 | PluginKeyProcessor proc, |
824 | void *proc_cls) | 820 | void *proc_cls) |
825 | { | 821 | { |
826 | struct Plugin *plugin = cls; | 822 | struct Plugin *plugin = cls; |
827 | int ret; | 823 | int ret; |
@@ -833,78 +829,76 @@ mysql_plugin_get_keys (void *cls, | |||
833 | GNUNET_MY_query_param_end | 829 | GNUNET_MY_query_param_end |
834 | }; | 830 | }; |
835 | struct GNUNET_MY_ResultSpec results_select[] = { | 831 | struct GNUNET_MY_ResultSpec results_select[] = { |
836 | GNUNET_MY_result_spec_auto_from_type (&key), | 832 | GNUNET_MY_result_spec_auto_from_type(&key), |
837 | GNUNET_MY_result_spec_end | 833 | GNUNET_MY_result_spec_end |
838 | }; | 834 | }; |
839 | 835 | ||
840 | GNUNET_assert (NULL != proc); | 836 | GNUNET_assert(NULL != proc); |
841 | statement = GNUNET_MYSQL_statement_get_stmt (plugin->get_all_keys); | 837 | statement = GNUNET_MYSQL_statement_get_stmt(plugin->get_all_keys); |
842 | if (GNUNET_OK != | 838 | if (GNUNET_OK != |
843 | GNUNET_MY_exec_prepared (plugin->mc, | 839 | GNUNET_MY_exec_prepared(plugin->mc, |
844 | plugin->get_all_keys, | 840 | plugin->get_all_keys, |
845 | params_select)) | 841 | params_select)) |
846 | { | 842 | { |
847 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 843 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
848 | _("`%s' for `%s' failed at %s:%d with error: %s\n"), | 844 | _("`%s' for `%s' failed at %s:%d with error: %s\n"), |
849 | "mysql_stmt_execute", | 845 | "mysql_stmt_execute", |
850 | GET_ALL_KEYS, | 846 | GET_ALL_KEYS, |
851 | __FILE__, | 847 | __FILE__, |
852 | __LINE__, | 848 | __LINE__, |
853 | mysql_stmt_error (statement)); | 849 | mysql_stmt_error(statement)); |
854 | GNUNET_MYSQL_statements_invalidate (plugin->mc); | 850 | GNUNET_MYSQL_statements_invalidate(plugin->mc); |
855 | proc (proc_cls, NULL, 0); | 851 | proc(proc_cls, NULL, 0); |
856 | return; | 852 | return; |
857 | } | 853 | } |
858 | memset (&last, 0, sizeof (last)); /* make static analysis happy */ | 854 | memset(&last, 0, sizeof(last)); /* make static analysis happy */ |
859 | ret = GNUNET_YES; | 855 | ret = GNUNET_YES; |
860 | cnt = 0; | 856 | cnt = 0; |
861 | while (ret == GNUNET_YES) | 857 | while (ret == GNUNET_YES) |
862 | { | ||
863 | ret = GNUNET_MY_extract_result (plugin->get_all_keys, | ||
864 | results_select); | ||
865 | if (0 != GNUNET_memcmp (&last, | ||
866 | &key)) | ||
867 | { | 858 | { |
868 | if (0 != cnt) | 859 | ret = GNUNET_MY_extract_result(plugin->get_all_keys, |
869 | proc (proc_cls, | 860 | results_select); |
870 | &last, | 861 | if (0 != GNUNET_memcmp(&last, |
871 | cnt); | 862 | &key)) |
872 | cnt = 1; | 863 | { |
873 | last = key; | 864 | if (0 != cnt) |
865 | proc(proc_cls, | ||
866 | &last, | ||
867 | cnt); | ||
868 | cnt = 1; | ||
869 | last = key; | ||
870 | } | ||
871 | else | ||
872 | { | ||
873 | cnt++; | ||
874 | } | ||
874 | } | 875 | } |
875 | else | ||
876 | { | ||
877 | cnt++; | ||
878 | } | ||
879 | } | ||
880 | if (0 != cnt) | 876 | if (0 != cnt) |
881 | proc (proc_cls, | 877 | proc(proc_cls, |
882 | &last, | 878 | &last, |
883 | cnt); | 879 | cnt); |
884 | /* finally, let app know we are done */ | 880 | /* finally, let app know we are done */ |
885 | proc (proc_cls, | 881 | proc(proc_cls, |
886 | NULL, | 882 | NULL, |
887 | 0); | 883 | 0); |
888 | if (GNUNET_SYSERR == ret) | 884 | if (GNUNET_SYSERR == ret) |
889 | { | 885 | { |
890 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 886 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
891 | _("`%s' failed at %s:%d with error: %s\n"), | 887 | _("`%s' failed at %s:%d with error: %s\n"), |
892 | "mysql_stmt_fetch", | 888 | "mysql_stmt_fetch", |
893 | __FILE__, | 889 | __FILE__, |
894 | __LINE__, | 890 | __LINE__, |
895 | mysql_stmt_error (statement)); | 891 | mysql_stmt_error(statement)); |
896 | GNUNET_MYSQL_statements_invalidate (plugin->mc); | 892 | GNUNET_MYSQL_statements_invalidate(plugin->mc); |
897 | return; | 893 | return; |
898 | } | 894 | } |
899 | } | 895 | } |
900 | 896 | ||
901 | 897 | ||
902 | /** | 898 | /** |
903 | * Context for #expi_proc() function. | 899 | * Context for #expi_proc() function. |
904 | */ | 900 | */ |
905 | struct ExpiCtx | 901 | struct ExpiCtx { |
906 | { | ||
907 | |||
908 | /** | 902 | /** |
909 | * Plugin handle. | 903 | * Plugin handle. |
910 | */ | 904 | */ |
@@ -944,16 +938,16 @@ struct ExpiCtx | |||
944 | * #GNUNET_NO to delete the item and continue (if supported) | 938 | * #GNUNET_NO to delete the item and continue (if supported) |
945 | */ | 939 | */ |
946 | static int | 940 | static int |
947 | expi_proc (void *cls, | 941 | expi_proc(void *cls, |
948 | const struct GNUNET_HashCode *key, | 942 | const struct GNUNET_HashCode *key, |
949 | uint32_t size, | 943 | uint32_t size, |
950 | const void *data, | 944 | const void *data, |
951 | enum GNUNET_BLOCK_Type type, | 945 | enum GNUNET_BLOCK_Type type, |
952 | uint32_t priority, | 946 | uint32_t priority, |
953 | uint32_t anonymity, | 947 | uint32_t anonymity, |
954 | uint32_t replication, | 948 | uint32_t replication, |
955 | struct GNUNET_TIME_Absolute expiration, | 949 | struct GNUNET_TIME_Absolute expiration, |
956 | uint64_t uid) | 950 | uint64_t uid) |
957 | { | 951 | { |
958 | struct ExpiCtx *rc = cls; | 952 | struct ExpiCtx *rc = cls; |
959 | struct Plugin *plugin = rc->plugin; | 953 | struct Plugin *plugin = rc->plugin; |
@@ -962,24 +956,24 @@ expi_proc (void *cls, | |||
962 | }; | 956 | }; |
963 | 957 | ||
964 | if (NULL == key) | 958 | if (NULL == key) |
965 | { | 959 | { |
966 | execute_select (plugin, | 960 | execute_select(plugin, |
967 | plugin->select_priority, | 961 | plugin->select_priority, |
968 | rc->proc, | 962 | rc->proc, |
969 | rc->proc_cls, | 963 | rc->proc_cls, |
970 | params_select); | 964 | params_select); |
971 | return GNUNET_SYSERR; | 965 | return GNUNET_SYSERR; |
972 | } | 966 | } |
973 | return rc->proc (rc->proc_cls, | 967 | return rc->proc(rc->proc_cls, |
974 | key, | 968 | key, |
975 | size, | 969 | size, |
976 | data, | 970 | data, |
977 | type, | 971 | type, |
978 | priority, | 972 | priority, |
979 | anonymity, | 973 | anonymity, |
980 | replication, | 974 | replication, |
981 | expiration, | 975 | expiration, |
982 | uid); | 976 | uid); |
983 | } | 977 | } |
984 | 978 | ||
985 | 979 | ||
@@ -992,14 +986,14 @@ expi_proc (void *cls, | |||
992 | * @param proc_cls closure for @a proc | 986 | * @param proc_cls closure for @a proc |
993 | */ | 987 | */ |
994 | static void | 988 | static void |
995 | mysql_plugin_get_expiration (void *cls, | 989 | mysql_plugin_get_expiration(void *cls, |
996 | PluginDatumProcessor proc, | 990 | PluginDatumProcessor proc, |
997 | void *proc_cls) | 991 | void *proc_cls) |
998 | { | 992 | { |
999 | struct Plugin *plugin = cls; | 993 | struct Plugin *plugin = cls; |
1000 | struct GNUNET_TIME_Absolute now; | 994 | struct GNUNET_TIME_Absolute now; |
1001 | struct GNUNET_MY_QueryParam params_select[] = { | 995 | struct GNUNET_MY_QueryParam params_select[] = { |
1002 | GNUNET_MY_query_param_absolute_time (&now), | 996 | GNUNET_MY_query_param_absolute_time(&now), |
1003 | GNUNET_MY_query_param_end | 997 | GNUNET_MY_query_param_end |
1004 | }; | 998 | }; |
1005 | struct ExpiCtx rc; | 999 | struct ExpiCtx rc; |
@@ -1007,12 +1001,12 @@ mysql_plugin_get_expiration (void *cls, | |||
1007 | rc.plugin = plugin; | 1001 | rc.plugin = plugin; |
1008 | rc.proc = proc; | 1002 | rc.proc = proc; |
1009 | rc.proc_cls = proc_cls; | 1003 | rc.proc_cls = proc_cls; |
1010 | now = GNUNET_TIME_absolute_get (); | 1004 | now = GNUNET_TIME_absolute_get(); |
1011 | execute_select (plugin, | 1005 | execute_select(plugin, |
1012 | plugin->select_expiration, | 1006 | plugin->select_expiration, |
1013 | expi_proc, | 1007 | expi_proc, |
1014 | &rc, | 1008 | &rc, |
1015 | params_select); | 1009 | params_select); |
1016 | } | 1010 | } |
1017 | 1011 | ||
1018 | 1012 | ||
@@ -1022,15 +1016,15 @@ mysql_plugin_get_expiration (void *cls, | |||
1022 | * @param cls the `struct Plugin *` | 1016 | * @param cls the `struct Plugin *` |
1023 | */ | 1017 | */ |
1024 | static void | 1018 | static void |
1025 | mysql_plugin_drop (void *cls) | 1019 | mysql_plugin_drop(void *cls) |
1026 | { | 1020 | { |
1027 | struct Plugin *plugin = cls; | 1021 | struct Plugin *plugin = cls; |
1028 | 1022 | ||
1029 | if (GNUNET_OK != | 1023 | if (GNUNET_OK != |
1030 | GNUNET_MYSQL_statement_run (plugin->mc, | 1024 | GNUNET_MYSQL_statement_run(plugin->mc, |
1031 | "DROP TABLE gn090")) | 1025 | "DROP TABLE gn090")) |
1032 | return; /* error */ | 1026 | return; /* error */ |
1033 | plugin->env->duc (plugin->env->cls, 0); | 1027 | plugin->env->duc(plugin->env->cls, 0); |
1034 | } | 1028 | } |
1035 | 1029 | ||
1036 | 1030 | ||
@@ -1045,55 +1039,55 @@ mysql_plugin_drop (void *cls) | |||
1045 | * @param cont_cls continuation closure for @a cont | 1039 | * @param cont_cls continuation closure for @a cont |
1046 | */ | 1040 | */ |
1047 | static void | 1041 | static void |
1048 | mysql_plugin_remove_key (void *cls, | 1042 | mysql_plugin_remove_key(void *cls, |
1049 | const struct GNUNET_HashCode *key, | 1043 | const struct GNUNET_HashCode *key, |
1050 | uint32_t size, | 1044 | uint32_t size, |
1051 | const void *data, | 1045 | const void *data, |
1052 | PluginRemoveCont cont, | 1046 | PluginRemoveCont cont, |
1053 | void *cont_cls) | 1047 | void *cont_cls) |
1054 | { | 1048 | { |
1055 | struct Plugin *plugin = cls; | 1049 | struct Plugin *plugin = cls; |
1056 | struct GNUNET_MY_QueryParam params_delete[] = { | 1050 | struct GNUNET_MY_QueryParam params_delete[] = { |
1057 | GNUNET_MY_query_param_auto_from_type (key), | 1051 | GNUNET_MY_query_param_auto_from_type(key), |
1058 | GNUNET_MY_query_param_fixed_size (data, size), | 1052 | GNUNET_MY_query_param_fixed_size(data, size), |
1059 | GNUNET_MY_query_param_end | 1053 | GNUNET_MY_query_param_end |
1060 | }; | 1054 | }; |
1061 | 1055 | ||
1062 | if (GNUNET_OK != | 1056 | if (GNUNET_OK != |
1063 | GNUNET_MY_exec_prepared (plugin->mc, | 1057 | GNUNET_MY_exec_prepared(plugin->mc, |
1064 | plugin->delete_entry_by_hash_value, | 1058 | plugin->delete_entry_by_hash_value, |
1065 | params_delete)) | 1059 | params_delete)) |
1066 | { | 1060 | { |
1067 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1061 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1068 | "Removing key `%s' from gn090 table failed\n", | 1062 | "Removing key `%s' from gn090 table failed\n", |
1069 | GNUNET_h2s (key)); | 1063 | GNUNET_h2s(key)); |
1070 | cont (cont_cls, | 1064 | cont(cont_cls, |
1071 | key, | 1065 | key, |
1072 | size, | 1066 | size, |
1073 | GNUNET_SYSERR, | 1067 | GNUNET_SYSERR, |
1074 | _("MySQL statement run failure")); | 1068 | _("MySQL statement run failure")); |
1075 | return; | 1069 | return; |
1076 | } | 1070 | } |
1077 | 1071 | ||
1078 | MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt (plugin->delete_entry_by_hash_value); | 1072 | MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt(plugin->delete_entry_by_hash_value); |
1079 | my_ulonglong rows = mysql_stmt_affected_rows (stmt); | 1073 | my_ulonglong rows = mysql_stmt_affected_rows(stmt); |
1080 | 1074 | ||
1081 | if (0 == rows) | 1075 | if (0 == rows) |
1082 | { | 1076 | { |
1083 | cont (cont_cls, | 1077 | cont(cont_cls, |
1084 | key, | 1078 | key, |
1085 | size, | 1079 | size, |
1086 | GNUNET_NO, | 1080 | GNUNET_NO, |
1087 | NULL); | 1081 | NULL); |
1088 | return; | 1082 | return; |
1089 | } | 1083 | } |
1090 | plugin->env->duc (plugin->env->cls, | 1084 | plugin->env->duc(plugin->env->cls, |
1091 | -size); | 1085 | -size); |
1092 | cont (cont_cls, | 1086 | cont(cont_cls, |
1093 | key, | 1087 | key, |
1094 | size, | 1088 | size, |
1095 | GNUNET_OK, | 1089 | GNUNET_OK, |
1096 | NULL); | 1090 | NULL); |
1097 | } | 1091 | } |
1098 | 1092 | ||
1099 | 1093 | ||
@@ -1104,67 +1098,67 @@ mysql_plugin_remove_key (void *cls, | |||
1104 | * @return our `struct Plugin *` | 1098 | * @return our `struct Plugin *` |
1105 | */ | 1099 | */ |
1106 | void * | 1100 | void * |
1107 | libgnunet_plugin_datastore_mysql_init (void *cls) | 1101 | libgnunet_plugin_datastore_mysql_init(void *cls) |
1108 | { | 1102 | { |
1109 | struct GNUNET_DATASTORE_PluginEnvironment *env = cls; | 1103 | struct GNUNET_DATASTORE_PluginEnvironment *env = cls; |
1110 | struct GNUNET_DATASTORE_PluginFunctions *api; | 1104 | struct GNUNET_DATASTORE_PluginFunctions *api; |
1111 | struct Plugin *plugin; | 1105 | struct Plugin *plugin; |
1112 | 1106 | ||
1113 | plugin = GNUNET_new (struct Plugin); | 1107 | plugin = GNUNET_new(struct Plugin); |
1114 | plugin->env = env; | 1108 | plugin->env = env; |
1115 | plugin->mc = GNUNET_MYSQL_context_create (env->cfg, | 1109 | plugin->mc = GNUNET_MYSQL_context_create(env->cfg, |
1116 | "datastore-mysql"); | 1110 | "datastore-mysql"); |
1117 | if (NULL == plugin->mc) | 1111 | if (NULL == plugin->mc) |
1118 | { | 1112 | { |
1119 | GNUNET_free (plugin); | 1113 | GNUNET_free(plugin); |
1120 | return NULL; | 1114 | return NULL; |
1121 | } | 1115 | } |
1122 | #define MRUNS(a) (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, a) ) | 1116 | #define MRUNS(a) (GNUNET_OK != GNUNET_MYSQL_statement_run(plugin->mc, a)) |
1123 | #define PINIT(a,b) (NULL == (a = GNUNET_MYSQL_statement_prepare (plugin->mc, b))) | 1117 | #define PINIT(a, b) (NULL == (a = GNUNET_MYSQL_statement_prepare(plugin->mc, b))) |
1124 | if (MRUNS | 1118 | if (MRUNS |
1125 | ("CREATE TABLE IF NOT EXISTS gn090 (" | 1119 | ("CREATE TABLE IF NOT EXISTS gn090 (" |
1126 | " repl INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1120 | " repl INT(11) UNSIGNED NOT NULL DEFAULT 0," |
1127 | " type INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1121 | " type INT(11) UNSIGNED NOT NULL DEFAULT 0," |
1128 | " prio INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1122 | " prio INT(11) UNSIGNED NOT NULL DEFAULT 0," |
1129 | " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1123 | " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0," |
1130 | " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," | 1124 | " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," |
1131 | " rvalue BIGINT UNSIGNED NOT NULL," | 1125 | " rvalue BIGINT UNSIGNED NOT NULL," |
1132 | " hash BINARY(64) NOT NULL DEFAULT ''," | 1126 | " hash BINARY(64) NOT NULL DEFAULT ''," |
1133 | " vhash BINARY(64) NOT NULL DEFAULT ''," | 1127 | " vhash BINARY(64) NOT NULL DEFAULT ''," |
1134 | " value BLOB NOT NULL DEFAULT ''," " uid BIGINT NOT NULL AUTO_INCREMENT," | 1128 | " value BLOB NOT NULL DEFAULT ''," " uid BIGINT NOT NULL AUTO_INCREMENT," |
1135 | " PRIMARY KEY (uid)," | 1129 | " PRIMARY KEY (uid)," |
1136 | " INDEX idx_hash_type_uid (hash(64),type,rvalue)," | 1130 | " INDEX idx_hash_type_uid (hash(64),type,rvalue)," |
1137 | " INDEX idx_prio (prio)," | 1131 | " INDEX idx_prio (prio)," |
1138 | " INDEX idx_repl_rvalue (repl,rvalue)," | 1132 | " INDEX idx_repl_rvalue (repl,rvalue)," |
1139 | " INDEX idx_expire (expire)," | 1133 | " INDEX idx_expire (expire)," |
1140 | " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)" | 1134 | " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)" |
1141 | ") ENGINE=InnoDB") || MRUNS ("SET AUTOCOMMIT = 1") || | 1135 | ") ENGINE=InnoDB") || MRUNS("SET AUTOCOMMIT = 1") || |
1142 | PINIT (plugin->insert_entry, INSERT_ENTRY) || | 1136 | PINIT(plugin->insert_entry, INSERT_ENTRY) || |
1143 | PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) || | 1137 | PINIT(plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) || |
1144 | PINIT (plugin->delete_entry_by_hash_value, DELETE_ENTRY_BY_HASH_VALUE) || | 1138 | PINIT(plugin->delete_entry_by_hash_value, DELETE_ENTRY_BY_HASH_VALUE) || |
1145 | PINIT (plugin->select_entry, SELECT_ENTRY) || | 1139 | PINIT(plugin->select_entry, SELECT_ENTRY) || |
1146 | PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) || | 1140 | PINIT(plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) || |
1147 | PINIT (plugin->select_entry_by_hash_and_type, | 1141 | PINIT(plugin->select_entry_by_hash_and_type, |
1148 | SELECT_ENTRY_BY_HASH_AND_TYPE) || | 1142 | SELECT_ENTRY_BY_HASH_AND_TYPE) || |
1149 | PINIT (plugin->get_size, SELECT_SIZE) || | 1143 | PINIT(plugin->get_size, SELECT_SIZE) || |
1150 | PINIT (plugin->update_entry, UPDATE_ENTRY) || | 1144 | PINIT(plugin->update_entry, UPDATE_ENTRY) || |
1151 | PINIT (plugin->dec_repl, DEC_REPL) || | 1145 | PINIT(plugin->dec_repl, DEC_REPL) || |
1152 | PINIT (plugin->zero_iter, SELECT_IT_NON_ANONYMOUS) || | 1146 | PINIT(plugin->zero_iter, SELECT_IT_NON_ANONYMOUS) || |
1153 | PINIT (plugin->select_expiration, SELECT_IT_EXPIRATION) || | 1147 | PINIT(plugin->select_expiration, SELECT_IT_EXPIRATION) || |
1154 | PINIT (plugin->select_priority, SELECT_IT_PRIORITY) || | 1148 | PINIT(plugin->select_priority, SELECT_IT_PRIORITY) || |
1155 | PINIT (plugin->max_repl, SELECT_MAX_REPL) || | 1149 | PINIT(plugin->max_repl, SELECT_MAX_REPL) || |
1156 | PINIT (plugin->get_all_keys, GET_ALL_KEYS) || | 1150 | PINIT(plugin->get_all_keys, GET_ALL_KEYS) || |
1157 | PINIT (plugin->select_replication, SELECT_IT_REPLICATION) || | 1151 | PINIT(plugin->select_replication, SELECT_IT_REPLICATION) || |
1158 | false) | 1152 | false) |
1159 | { | 1153 | { |
1160 | GNUNET_MYSQL_context_destroy (plugin->mc); | 1154 | GNUNET_MYSQL_context_destroy(plugin->mc); |
1161 | GNUNET_free (plugin); | 1155 | GNUNET_free(plugin); |
1162 | return NULL; | 1156 | return NULL; |
1163 | } | 1157 | } |
1164 | #undef PINIT | 1158 | #undef PINIT |
1165 | #undef MRUNS | 1159 | #undef MRUNS |
1166 | 1160 | ||
1167 | api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions); | 1161 | api = GNUNET_new(struct GNUNET_DATASTORE_PluginFunctions); |
1168 | api->cls = plugin; | 1162 | api->cls = plugin; |
1169 | api->estimate_size = &mysql_plugin_estimate_size; | 1163 | api->estimate_size = &mysql_plugin_estimate_size; |
1170 | api->put = &mysql_plugin_put; | 1164 | api->put = &mysql_plugin_put; |
@@ -1175,8 +1169,8 @@ libgnunet_plugin_datastore_mysql_init (void *cls) | |||
1175 | api->get_keys = &mysql_plugin_get_keys; | 1169 | api->get_keys = &mysql_plugin_get_keys; |
1176 | api->drop = &mysql_plugin_drop; | 1170 | api->drop = &mysql_plugin_drop; |
1177 | api->remove_key = &mysql_plugin_remove_key; | 1171 | api->remove_key = &mysql_plugin_remove_key; |
1178 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql", | 1172 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "mysql", |
1179 | _("Mysql database running\n")); | 1173 | _("Mysql database running\n")); |
1180 | return api; | 1174 | return api; |
1181 | } | 1175 | } |
1182 | 1176 | ||
@@ -1188,14 +1182,14 @@ libgnunet_plugin_datastore_mysql_init (void *cls) | |||
1188 | * @return always NULL | 1182 | * @return always NULL |
1189 | */ | 1183 | */ |
1190 | void * | 1184 | void * |
1191 | libgnunet_plugin_datastore_mysql_done (void *cls) | 1185 | libgnunet_plugin_datastore_mysql_done(void *cls) |
1192 | { | 1186 | { |
1193 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; | 1187 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; |
1194 | struct Plugin *plugin = api->cls; | 1188 | struct Plugin *plugin = api->cls; |
1195 | 1189 | ||
1196 | GNUNET_MYSQL_context_destroy (plugin->mc); | 1190 | GNUNET_MYSQL_context_destroy(plugin->mc); |
1197 | GNUNET_free (plugin); | 1191 | GNUNET_free(plugin); |
1198 | GNUNET_free (api); | 1192 | GNUNET_free(api); |
1199 | return NULL; | 1193 | return NULL; |
1200 | } | 1194 | } |
1201 | 1195 | ||
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c index 0a3018411..17b645585 100644 --- a/src/datastore/plugin_datastore_postgres.c +++ b/src/datastore/plugin_datastore_postgres.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file datastore/plugin_datastore_postgres.c | 22 | * @file datastore/plugin_datastore_postgres.c |
@@ -44,8 +44,7 @@ | |||
44 | /** | 44 | /** |
45 | * Context for all functions in this plugin. | 45 | * Context for all functions in this plugin. |
46 | */ | 46 | */ |
47 | struct Plugin | 47 | struct Plugin { |
48 | { | ||
49 | /** | 48 | /** |
50 | * Our execution environment. | 49 | * Our execution environment. |
51 | */ | 50 | */ |
@@ -55,7 +54,6 @@ struct Plugin | |||
55 | * Native Postgres database handle. | 54 | * Native Postgres database handle. |
56 | */ | 55 | */ |
57 | PGconn *dbh; | 56 | PGconn *dbh; |
58 | |||
59 | }; | 57 | }; |
60 | 58 | ||
61 | 59 | ||
@@ -66,7 +64,7 @@ struct Plugin | |||
66 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 64 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
67 | */ | 65 | */ |
68 | static int | 66 | static int |
69 | init_connection (struct Plugin *plugin) | 67 | init_connection(struct Plugin *plugin) |
70 | { | 68 | { |
71 | struct GNUNET_PQ_ExecuteStatement es[] = { | 69 | struct GNUNET_PQ_ExecuteStatement es[] = { |
72 | /* FIXME: PostgreSQL does not have unsigned integers! This is ok for the type column because | 70 | /* FIXME: PostgreSQL does not have unsigned integers! This is ok for the type column because |
@@ -75,110 +73,111 @@ init_connection (struct Plugin *plugin) | |||
75 | * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC. | 73 | * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC. |
76 | * PostgreSQL also recommends against using WITH OIDS. | 74 | * PostgreSQL also recommends against using WITH OIDS. |
77 | */ | 75 | */ |
78 | GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS gn090 (" | 76 | GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS gn090 (" |
79 | " repl INTEGER NOT NULL DEFAULT 0," | 77 | " repl INTEGER NOT NULL DEFAULT 0," |
80 | " type INTEGER NOT NULL DEFAULT 0," | 78 | " type INTEGER NOT NULL DEFAULT 0," |
81 | " prio INTEGER NOT NULL DEFAULT 0," | 79 | " prio INTEGER NOT NULL DEFAULT 0," |
82 | " anonLevel INTEGER NOT NULL DEFAULT 0," | 80 | " anonLevel INTEGER NOT NULL DEFAULT 0," |
83 | " expire BIGINT NOT NULL DEFAULT 0," | 81 | " expire BIGINT NOT NULL DEFAULT 0," |
84 | " rvalue BIGINT NOT NULL DEFAULT 0," | 82 | " rvalue BIGINT NOT NULL DEFAULT 0," |
85 | " hash BYTEA NOT NULL DEFAULT ''," | 83 | " hash BYTEA NOT NULL DEFAULT ''," |
86 | " vhash BYTEA NOT NULL DEFAULT ''," | 84 | " vhash BYTEA NOT NULL DEFAULT ''," |
87 | " value BYTEA NOT NULL DEFAULT '')" | 85 | " value BYTEA NOT NULL DEFAULT '')" |
88 | "WITH OIDS"), | 86 | "WITH OIDS"), |
89 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)"), | 87 | GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)"), |
90 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS idx_prio ON gn090 (prio)"), | 88 | GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS idx_prio ON gn090 (prio)"), |
91 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS idx_expire ON gn090 (expire)"), | 89 | GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS idx_expire ON gn090 (expire)"), |
92 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS idx_prio_anon ON gn090 (prio,anonLevel)"), | 90 | GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS idx_prio_anon ON gn090 (prio,anonLevel)"), |
93 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS idx_prio_hash_anon ON gn090 (prio,hash,anonLevel)"), | 91 | GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS idx_prio_hash_anon ON gn090 (prio,hash,anonLevel)"), |
94 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn090 (repl,rvalue)"), | 92 | GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn090 (repl,rvalue)"), |
95 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS idx_expire_hash ON gn090 (expire,hash)"), | 93 | GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS idx_expire_hash ON gn090 (expire,hash)"), |
96 | GNUNET_PQ_make_execute ("ALTER TABLE gn090 ALTER value SET STORAGE EXTERNAL"), | 94 | GNUNET_PQ_make_execute("ALTER TABLE gn090 ALTER value SET STORAGE EXTERNAL"), |
97 | GNUNET_PQ_make_execute ("ALTER TABLE gn090 ALTER hash SET STORAGE PLAIN"), | 95 | GNUNET_PQ_make_execute("ALTER TABLE gn090 ALTER hash SET STORAGE PLAIN"), |
98 | GNUNET_PQ_make_execute ("ALTER TABLE gn090 ALTER vhash SET STORAGE PLAIN"), | 96 | GNUNET_PQ_make_execute("ALTER TABLE gn090 ALTER vhash SET STORAGE PLAIN"), |
99 | GNUNET_PQ_EXECUTE_STATEMENT_END | 97 | GNUNET_PQ_EXECUTE_STATEMENT_END |
100 | }; | 98 | }; |
99 | |||
101 | #define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, oid" | 100 | #define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, oid" |
102 | struct GNUNET_PQ_PreparedStatement ps[] = { | 101 | struct GNUNET_PQ_PreparedStatement ps[] = { |
103 | GNUNET_PQ_make_prepare ("get", | 102 | GNUNET_PQ_make_prepare("get", |
104 | "SELECT " RESULT_COLUMNS " FROM gn090" | 103 | "SELECT " RESULT_COLUMNS " FROM gn090" |
105 | " WHERE oid >= $1::bigint AND" | 104 | " WHERE oid >= $1::bigint AND" |
106 | " (rvalue >= $2 OR 0 = $3::smallint) AND" | 105 | " (rvalue >= $2 OR 0 = $3::smallint) AND" |
107 | " (hash = $4 OR 0 = $5::smallint) AND" | 106 | " (hash = $4 OR 0 = $5::smallint) AND" |
108 | " (type = $6 OR 0 = $7::smallint)" | 107 | " (type = $6 OR 0 = $7::smallint)" |
109 | " ORDER BY oid ASC LIMIT 1", | 108 | " ORDER BY oid ASC LIMIT 1", |
110 | 7), | 109 | 7), |
111 | GNUNET_PQ_make_prepare ("put", | 110 | GNUNET_PQ_make_prepare("put", |
112 | "INSERT INTO gn090 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) " | 111 | "INSERT INTO gn090 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) " |
113 | "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", | 112 | "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", |
114 | 9), | 113 | 9), |
115 | GNUNET_PQ_make_prepare ("update", | 114 | GNUNET_PQ_make_prepare("update", |
116 | "UPDATE gn090" | 115 | "UPDATE gn090" |
117 | " SET prio = prio + $1," | 116 | " SET prio = prio + $1," |
118 | " repl = repl + $2," | 117 | " repl = repl + $2," |
119 | " expire = GREATEST(expire, $3)" | 118 | " expire = GREATEST(expire, $3)" |
120 | " WHERE hash = $4 AND vhash = $5", | 119 | " WHERE hash = $4 AND vhash = $5", |
121 | 5), | 120 | 5), |
122 | GNUNET_PQ_make_prepare ("decrepl", | 121 | GNUNET_PQ_make_prepare("decrepl", |
123 | "UPDATE gn090 SET repl = GREATEST (repl - 1, 0) " | 122 | "UPDATE gn090 SET repl = GREATEST (repl - 1, 0) " |
124 | "WHERE oid = $1", | 123 | "WHERE oid = $1", |
125 | 1), | 124 | 1), |
126 | GNUNET_PQ_make_prepare ("select_non_anonymous", | 125 | GNUNET_PQ_make_prepare("select_non_anonymous", |
127 | "SELECT " RESULT_COLUMNS " FROM gn090 " | 126 | "SELECT " RESULT_COLUMNS " FROM gn090 " |
128 | "WHERE anonLevel = 0 AND type = $1 AND oid >= $2::bigint " | 127 | "WHERE anonLevel = 0 AND type = $1 AND oid >= $2::bigint " |
129 | "ORDER BY oid ASC LIMIT 1", | 128 | "ORDER BY oid ASC LIMIT 1", |
130 | 2), | 129 | 2), |
131 | GNUNET_PQ_make_prepare ("select_expiration_order", | 130 | GNUNET_PQ_make_prepare("select_expiration_order", |
132 | "(SELECT " RESULT_COLUMNS " FROM gn090 " | 131 | "(SELECT " RESULT_COLUMNS " FROM gn090 " |
133 | "WHERE expire < $1 ORDER BY prio ASC LIMIT 1) " | 132 | "WHERE expire < $1 ORDER BY prio ASC LIMIT 1) " |
134 | "UNION " | 133 | "UNION " |
135 | "(SELECT " RESULT_COLUMNS " FROM gn090 " | 134 | "(SELECT " RESULT_COLUMNS " FROM gn090 " |
136 | "ORDER BY prio ASC LIMIT 1) " | 135 | "ORDER BY prio ASC LIMIT 1) " |
137 | "ORDER BY expire ASC LIMIT 1", | 136 | "ORDER BY expire ASC LIMIT 1", |
138 | 1), | 137 | 1), |
139 | GNUNET_PQ_make_prepare ("select_replication_order", | 138 | GNUNET_PQ_make_prepare("select_replication_order", |
140 | "SELECT " RESULT_COLUMNS " FROM gn090 " | 139 | "SELECT " RESULT_COLUMNS " FROM gn090 " |
141 | "ORDER BY repl DESC,RANDOM() LIMIT 1", | 140 | "ORDER BY repl DESC,RANDOM() LIMIT 1", |
142 | 0), | 141 | 0), |
143 | GNUNET_PQ_make_prepare ("delrow", | 142 | GNUNET_PQ_make_prepare("delrow", |
144 | "DELETE FROM gn090 " | 143 | "DELETE FROM gn090 " |
145 | "WHERE oid=$1", | 144 | "WHERE oid=$1", |
146 | 1), | 145 | 1), |
147 | GNUNET_PQ_make_prepare ("remove", | 146 | GNUNET_PQ_make_prepare("remove", |
148 | "DELETE FROM gn090" | 147 | "DELETE FROM gn090" |
149 | " WHERE hash = $1 AND" | 148 | " WHERE hash = $1 AND" |
150 | " value = $2", | 149 | " value = $2", |
151 | 2), | 150 | 2), |
152 | GNUNET_PQ_make_prepare ("get_keys", | 151 | GNUNET_PQ_make_prepare("get_keys", |
153 | "SELECT hash FROM gn090", | 152 | "SELECT hash FROM gn090", |
154 | 0), | 153 | 0), |
155 | GNUNET_PQ_make_prepare ("estimate_size", | 154 | GNUNET_PQ_make_prepare("estimate_size", |
156 | "SELECT CASE WHEN NOT EXISTS" | 155 | "SELECT CASE WHEN NOT EXISTS" |
157 | " (SELECT 1 FROM gn090)" | 156 | " (SELECT 1 FROM gn090)" |
158 | " THEN 0" | 157 | " THEN 0" |
159 | " ELSE (SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090)" | 158 | " ELSE (SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090)" |
160 | "END AS total", | 159 | "END AS total", |
161 | 0), | 160 | 0), |
162 | GNUNET_PQ_PREPARED_STATEMENT_END | 161 | GNUNET_PQ_PREPARED_STATEMENT_END |
163 | }; | 162 | }; |
164 | #undef RESULT_COLUMNS | 163 | #undef RESULT_COLUMNS |
165 | 164 | ||
166 | plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->env->cfg, | 165 | plugin->dbh = GNUNET_PQ_connect_with_cfg(plugin->env->cfg, |
167 | "datastore-postgres"); | 166 | "datastore-postgres"); |
168 | if (NULL == plugin->dbh) | 167 | if (NULL == plugin->dbh) |
169 | return GNUNET_SYSERR; | 168 | return GNUNET_SYSERR; |
170 | 169 | ||
171 | if ( (GNUNET_OK != | 170 | if ((GNUNET_OK != |
172 | GNUNET_PQ_exec_statements (plugin->dbh, | 171 | GNUNET_PQ_exec_statements(plugin->dbh, |
173 | es)) || | 172 | es)) || |
174 | (GNUNET_OK != | 173 | (GNUNET_OK != |
175 | GNUNET_PQ_prepare_statements (plugin->dbh, | 174 | GNUNET_PQ_prepare_statements(plugin->dbh, |
176 | ps)) ) | 175 | ps))) |
177 | { | 176 | { |
178 | PQfinish (plugin->dbh); | 177 | PQfinish(plugin->dbh); |
179 | plugin->dbh = NULL; | 178 | plugin->dbh = NULL; |
180 | return GNUNET_SYSERR; | 179 | return GNUNET_SYSERR; |
181 | } | 180 | } |
182 | return GNUNET_OK; | 181 | return GNUNET_OK; |
183 | } | 182 | } |
184 | 183 | ||
@@ -191,8 +190,8 @@ init_connection (struct Plugin *plugin) | |||
191 | * @return number of bytes used on disk | 190 | * @return number of bytes used on disk |
192 | */ | 191 | */ |
193 | static void | 192 | static void |
194 | postgres_plugin_estimate_size (void *cls, | 193 | postgres_plugin_estimate_size(void *cls, |
195 | unsigned long long *estimate) | 194 | unsigned long long *estimate) |
196 | { | 195 | { |
197 | struct Plugin *plugin = cls; | 196 | struct Plugin *plugin = cls; |
198 | uint64_t total; | 197 | uint64_t total; |
@@ -200,23 +199,23 @@ postgres_plugin_estimate_size (void *cls, | |||
200 | GNUNET_PQ_query_param_end | 199 | GNUNET_PQ_query_param_end |
201 | }; | 200 | }; |
202 | struct GNUNET_PQ_ResultSpec rs[] = { | 201 | struct GNUNET_PQ_ResultSpec rs[] = { |
203 | GNUNET_PQ_result_spec_uint64 ("total", | 202 | GNUNET_PQ_result_spec_uint64("total", |
204 | &total), | 203 | &total), |
205 | GNUNET_PQ_result_spec_end | 204 | GNUNET_PQ_result_spec_end |
206 | }; | 205 | }; |
207 | enum GNUNET_DB_QueryStatus ret; | 206 | enum GNUNET_DB_QueryStatus ret; |
208 | 207 | ||
209 | if (NULL == estimate) | 208 | if (NULL == estimate) |
210 | return; | 209 | return; |
211 | ret = GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, | 210 | ret = GNUNET_PQ_eval_prepared_singleton_select(plugin->dbh, |
212 | "estimate_size", | 211 | "estimate_size", |
213 | params, | 212 | params, |
214 | rs); | 213 | rs); |
215 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != ret) | 214 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != ret) |
216 | { | 215 | { |
217 | *estimate = 0LL; | 216 | *estimate = 0LL; |
218 | return; | 217 | return; |
219 | } | 218 | } |
220 | *estimate = total; | 219 | *estimate = total; |
221 | } | 220 | } |
222 | 221 | ||
@@ -238,110 +237,108 @@ postgres_plugin_estimate_size (void *cls, | |||
238 | * @param cont_cls continuation closure | 237 | * @param cont_cls continuation closure |
239 | */ | 238 | */ |
240 | static void | 239 | static void |
241 | postgres_plugin_put (void *cls, | 240 | postgres_plugin_put(void *cls, |
242 | const struct GNUNET_HashCode *key, | 241 | const struct GNUNET_HashCode *key, |
243 | bool absent, | 242 | bool absent, |
244 | uint32_t size, | 243 | uint32_t size, |
245 | const void *data, | 244 | const void *data, |
246 | enum GNUNET_BLOCK_Type type, | 245 | enum GNUNET_BLOCK_Type type, |
247 | uint32_t priority, | 246 | uint32_t priority, |
248 | uint32_t anonymity, | 247 | uint32_t anonymity, |
249 | uint32_t replication, | 248 | uint32_t replication, |
250 | struct GNUNET_TIME_Absolute expiration, | 249 | struct GNUNET_TIME_Absolute expiration, |
251 | PluginPutCont cont, | 250 | PluginPutCont cont, |
252 | void *cont_cls) | 251 | void *cont_cls) |
253 | { | 252 | { |
254 | struct Plugin *plugin = cls; | 253 | struct Plugin *plugin = cls; |
255 | struct GNUNET_HashCode vhash; | 254 | struct GNUNET_HashCode vhash; |
256 | enum GNUNET_DB_QueryStatus ret; | 255 | enum GNUNET_DB_QueryStatus ret; |
257 | 256 | ||
258 | GNUNET_CRYPTO_hash (data, | 257 | GNUNET_CRYPTO_hash(data, |
259 | size, | 258 | size, |
260 | &vhash); | 259 | &vhash); |
261 | if (! absent) | 260 | if (!absent) |
262 | { | ||
263 | struct GNUNET_PQ_QueryParam params[] = { | ||
264 | GNUNET_PQ_query_param_uint32 (&priority), | ||
265 | GNUNET_PQ_query_param_uint32 (&replication), | ||
266 | GNUNET_PQ_query_param_absolute_time (&expiration), | ||
267 | GNUNET_PQ_query_param_auto_from_type (key), | ||
268 | GNUNET_PQ_query_param_auto_from_type (&vhash), | ||
269 | GNUNET_PQ_query_param_end | ||
270 | }; | ||
271 | ret = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, | ||
272 | "update", | ||
273 | params); | ||
274 | if (0 > ret) | ||
275 | { | ||
276 | cont (cont_cls, | ||
277 | key, | ||
278 | size, | ||
279 | GNUNET_SYSERR, | ||
280 | _("Postgress exec failure")); | ||
281 | return; | ||
282 | } | ||
283 | bool affected = (0 != ret); | ||
284 | if (affected) | ||
285 | { | 261 | { |
286 | cont (cont_cls, | 262 | struct GNUNET_PQ_QueryParam params[] = { |
287 | key, | 263 | GNUNET_PQ_query_param_uint32(&priority), |
288 | size, | 264 | GNUNET_PQ_query_param_uint32(&replication), |
289 | GNUNET_NO, | 265 | GNUNET_PQ_query_param_absolute_time(&expiration), |
290 | NULL); | 266 | GNUNET_PQ_query_param_auto_from_type(key), |
291 | return; | 267 | GNUNET_PQ_query_param_auto_from_type(&vhash), |
268 | GNUNET_PQ_query_param_end | ||
269 | }; | ||
270 | ret = GNUNET_PQ_eval_prepared_non_select(plugin->dbh, | ||
271 | "update", | ||
272 | params); | ||
273 | if (0 > ret) | ||
274 | { | ||
275 | cont(cont_cls, | ||
276 | key, | ||
277 | size, | ||
278 | GNUNET_SYSERR, | ||
279 | _("Postgress exec failure")); | ||
280 | return; | ||
281 | } | ||
282 | bool affected = (0 != ret); | ||
283 | if (affected) | ||
284 | { | ||
285 | cont(cont_cls, | ||
286 | key, | ||
287 | size, | ||
288 | GNUNET_NO, | ||
289 | NULL); | ||
290 | return; | ||
291 | } | ||
292 | } | 292 | } |
293 | } | ||
294 | 293 | ||
295 | { | 294 | { |
296 | uint32_t utype = (uint32_t) type; | 295 | uint32_t utype = (uint32_t)type; |
297 | uint64_t rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 296 | uint64_t rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, |
298 | UINT64_MAX); | 297 | UINT64_MAX); |
299 | struct GNUNET_PQ_QueryParam params[] = { | 298 | struct GNUNET_PQ_QueryParam params[] = { |
300 | GNUNET_PQ_query_param_uint32 (&replication), | 299 | GNUNET_PQ_query_param_uint32(&replication), |
301 | GNUNET_PQ_query_param_uint32 (&utype), | 300 | GNUNET_PQ_query_param_uint32(&utype), |
302 | GNUNET_PQ_query_param_uint32 (&priority), | 301 | GNUNET_PQ_query_param_uint32(&priority), |
303 | GNUNET_PQ_query_param_uint32 (&anonymity), | 302 | GNUNET_PQ_query_param_uint32(&anonymity), |
304 | GNUNET_PQ_query_param_absolute_time (&expiration), | 303 | GNUNET_PQ_query_param_absolute_time(&expiration), |
305 | GNUNET_PQ_query_param_uint64 (&rvalue), | 304 | GNUNET_PQ_query_param_uint64(&rvalue), |
306 | GNUNET_PQ_query_param_auto_from_type (key), | 305 | GNUNET_PQ_query_param_auto_from_type(key), |
307 | GNUNET_PQ_query_param_auto_from_type (&vhash), | 306 | GNUNET_PQ_query_param_auto_from_type(&vhash), |
308 | GNUNET_PQ_query_param_fixed_size (data, size), | 307 | GNUNET_PQ_query_param_fixed_size(data, size), |
309 | GNUNET_PQ_query_param_end | 308 | GNUNET_PQ_query_param_end |
310 | }; | 309 | }; |
311 | 310 | ||
312 | ret = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, | 311 | ret = GNUNET_PQ_eval_prepared_non_select(plugin->dbh, |
313 | "put", | 312 | "put", |
314 | params); | 313 | params); |
315 | if (0 > ret) | 314 | if (0 > ret) |
316 | { | 315 | { |
317 | cont (cont_cls, | 316 | cont(cont_cls, |
318 | key, | 317 | key, |
319 | size, | 318 | size, |
320 | GNUNET_SYSERR, | 319 | GNUNET_SYSERR, |
321 | "Postgress exec failure"); | 320 | "Postgress exec failure"); |
322 | return; | 321 | return; |
323 | } | 322 | } |
324 | } | 323 | } |
325 | plugin->env->duc (plugin->env->cls, | 324 | plugin->env->duc(plugin->env->cls, |
326 | size + GNUNET_DATASTORE_ENTRY_OVERHEAD); | 325 | size + GNUNET_DATASTORE_ENTRY_OVERHEAD); |
327 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 326 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, |
328 | "datastore-postgres", | 327 | "datastore-postgres", |
329 | "Stored %u bytes in database\n", | 328 | "Stored %u bytes in database\n", |
330 | (unsigned int) size); | 329 | (unsigned int)size); |
331 | cont (cont_cls, | 330 | cont(cont_cls, |
332 | key, | 331 | key, |
333 | size, | 332 | size, |
334 | GNUNET_OK, | 333 | GNUNET_OK, |
335 | NULL); | 334 | NULL); |
336 | } | 335 | } |
337 | 336 | ||
338 | 337 | ||
339 | /** | 338 | /** |
340 | * Closure for #process_result. | 339 | * Closure for #process_result. |
341 | */ | 340 | */ |
342 | struct ProcessResultContext | 341 | struct ProcessResultContext { |
343 | { | ||
344 | |||
345 | /** | 342 | /** |
346 | * The plugin handle. | 343 | * The plugin handle. |
347 | */ | 344 | */ |
@@ -356,7 +353,6 @@ struct ProcessResultContext | |||
356 | * Closure for @e proc. | 353 | * Closure for @e proc. |
357 | */ | 354 | */ |
358 | void *proc_cls; | 355 | void *proc_cls; |
359 | |||
360 | }; | 356 | }; |
361 | 357 | ||
362 | 358 | ||
@@ -369,111 +365,111 @@ struct ProcessResultContext | |||
369 | * @param num_results number of results in @a res | 365 | * @param num_results number of results in @a res |
370 | */ | 366 | */ |
371 | static void | 367 | static void |
372 | process_result (void *cls, | 368 | process_result(void *cls, |
373 | PGresult *res, | 369 | PGresult *res, |
374 | unsigned int num_results) | 370 | unsigned int num_results) |
375 | { | 371 | { |
376 | struct ProcessResultContext *prc = cls; | 372 | struct ProcessResultContext *prc = cls; |
377 | struct Plugin *plugin = prc->plugin; | 373 | struct Plugin *plugin = prc->plugin; |
378 | 374 | ||
379 | if (0 == num_results) | 375 | if (0 == num_results) |
380 | { | 376 | { |
381 | /* no result */ | 377 | /* no result */ |
382 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 378 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, |
383 | "datastore-postgres", | 379 | "datastore-postgres", |
384 | "Ending iteration (no more results)\n"); | 380 | "Ending iteration (no more results)\n"); |
385 | prc->proc (prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0, | 381 | prc->proc(prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0, |
386 | GNUNET_TIME_UNIT_ZERO_ABS, 0); | 382 | GNUNET_TIME_UNIT_ZERO_ABS, 0); |
387 | return; | 383 | return; |
388 | } | 384 | } |
389 | if (1 != num_results) | 385 | if (1 != num_results) |
390 | { | ||
391 | GNUNET_break (0); | ||
392 | prc->proc (prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0, | ||
393 | GNUNET_TIME_UNIT_ZERO_ABS, 0); | ||
394 | return; | ||
395 | } | ||
396 | /* Technically we don't need the loop here, but nicer in case | ||
397 | we ever relax the condition above. */ | ||
398 | for (unsigned int i=0;i<num_results;i++) | ||
399 | { | ||
400 | int iret; | ||
401 | uint32_t rowid; | ||
402 | uint32_t utype; | ||
403 | uint32_t anonymity; | ||
404 | uint32_t replication; | ||
405 | uint32_t priority; | ||
406 | size_t size; | ||
407 | void *data; | ||
408 | struct GNUNET_TIME_Absolute expiration_time; | ||
409 | struct GNUNET_HashCode key; | ||
410 | struct GNUNET_PQ_ResultSpec rs[] = { | ||
411 | GNUNET_PQ_result_spec_uint32 ("repl", &replication), | ||
412 | GNUNET_PQ_result_spec_uint32 ("type", &utype), | ||
413 | GNUNET_PQ_result_spec_uint32 ("prio", &priority), | ||
414 | GNUNET_PQ_result_spec_uint32 ("anonLevel", &anonymity), | ||
415 | GNUNET_PQ_result_spec_absolute_time ("expire", &expiration_time), | ||
416 | GNUNET_PQ_result_spec_auto_from_type ("hash", &key), | ||
417 | GNUNET_PQ_result_spec_variable_size ("value", &data, &size), | ||
418 | GNUNET_PQ_result_spec_uint32 ("oid", &rowid), | ||
419 | GNUNET_PQ_result_spec_end | ||
420 | }; | ||
421 | |||
422 | if (GNUNET_OK != | ||
423 | GNUNET_PQ_extract_result (res, | ||
424 | rs, | ||
425 | i)) | ||
426 | { | 386 | { |
427 | GNUNET_break (0); | 387 | GNUNET_break(0); |
428 | prc->proc (prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0, | 388 | prc->proc(prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0, |
429 | GNUNET_TIME_UNIT_ZERO_ABS, 0); | 389 | GNUNET_TIME_UNIT_ZERO_ABS, 0); |
430 | return; | 390 | return; |
431 | } | 391 | } |
432 | 392 | /* Technically we don't need the loop here, but nicer in case | |
433 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 393 | we ever relax the condition above. */ |
434 | "datastore-postgres", | 394 | for (unsigned int i = 0; i < num_results; i++) |
435 | "Found result of size %u bytes and type %u in database\n", | ||
436 | (unsigned int) size, | ||
437 | (unsigned int) utype); | ||
438 | iret = prc->proc (prc->proc_cls, | ||
439 | &key, | ||
440 | size, | ||
441 | data, | ||
442 | (enum GNUNET_BLOCK_Type) utype, | ||
443 | priority, | ||
444 | anonymity, | ||
445 | replication, | ||
446 | expiration_time, | ||
447 | rowid); | ||
448 | if (iret == GNUNET_NO) | ||
449 | { | 395 | { |
450 | struct GNUNET_PQ_QueryParam param[] = { | 396 | int iret; |
451 | GNUNET_PQ_query_param_uint32 (&rowid), | 397 | uint32_t rowid; |
452 | GNUNET_PQ_query_param_end | 398 | uint32_t utype; |
399 | uint32_t anonymity; | ||
400 | uint32_t replication; | ||
401 | uint32_t priority; | ||
402 | size_t size; | ||
403 | void *data; | ||
404 | struct GNUNET_TIME_Absolute expiration_time; | ||
405 | struct GNUNET_HashCode key; | ||
406 | struct GNUNET_PQ_ResultSpec rs[] = { | ||
407 | GNUNET_PQ_result_spec_uint32("repl", &replication), | ||
408 | GNUNET_PQ_result_spec_uint32("type", &utype), | ||
409 | GNUNET_PQ_result_spec_uint32("prio", &priority), | ||
410 | GNUNET_PQ_result_spec_uint32("anonLevel", &anonymity), | ||
411 | GNUNET_PQ_result_spec_absolute_time("expire", &expiration_time), | ||
412 | GNUNET_PQ_result_spec_auto_from_type("hash", &key), | ||
413 | GNUNET_PQ_result_spec_variable_size("value", &data, &size), | ||
414 | GNUNET_PQ_result_spec_uint32("oid", &rowid), | ||
415 | GNUNET_PQ_result_spec_end | ||
453 | }; | 416 | }; |
454 | 417 | ||
455 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 418 | if (GNUNET_OK != |
456 | "Processor asked for item %u to be removed.\n", | 419 | GNUNET_PQ_extract_result(res, |
457 | (unsigned int) rowid); | 420 | rs, |
458 | if (0 < | 421 | i)) |
459 | GNUNET_PQ_eval_prepared_non_select (plugin->dbh, | 422 | { |
460 | "delrow", | 423 | GNUNET_break(0); |
461 | param)) | 424 | prc->proc(prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0, |
462 | { | 425 | GNUNET_TIME_UNIT_ZERO_ABS, 0); |
463 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 426 | return; |
464 | "datastore-postgres", | 427 | } |
465 | "Deleting %u bytes from database\n", | 428 | |
466 | (unsigned int) size); | 429 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, |
467 | plugin->env->duc (plugin->env->cls, | 430 | "datastore-postgres", |
468 | - (size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); | 431 | "Found result of size %u bytes and type %u in database\n", |
469 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 432 | (unsigned int)size, |
470 | "datastore-postgres", | 433 | (unsigned int)utype); |
471 | "Deleted %u bytes from database\n", | 434 | iret = prc->proc(prc->proc_cls, |
472 | (unsigned int) size); | 435 | &key, |
473 | } | 436 | size, |
474 | } | 437 | data, |
475 | GNUNET_PQ_cleanup_result (rs); | 438 | (enum GNUNET_BLOCK_Type)utype, |
476 | } /* for (i) */ | 439 | priority, |
440 | anonymity, | ||
441 | replication, | ||
442 | expiration_time, | ||
443 | rowid); | ||
444 | if (iret == GNUNET_NO) | ||
445 | { | ||
446 | struct GNUNET_PQ_QueryParam param[] = { | ||
447 | GNUNET_PQ_query_param_uint32(&rowid), | ||
448 | GNUNET_PQ_query_param_end | ||
449 | }; | ||
450 | |||
451 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
452 | "Processor asked for item %u to be removed.\n", | ||
453 | (unsigned int)rowid); | ||
454 | if (0 < | ||
455 | GNUNET_PQ_eval_prepared_non_select(plugin->dbh, | ||
456 | "delrow", | ||
457 | param)) | ||
458 | { | ||
459 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, | ||
460 | "datastore-postgres", | ||
461 | "Deleting %u bytes from database\n", | ||
462 | (unsigned int)size); | ||
463 | plugin->env->duc(plugin->env->cls, | ||
464 | -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); | ||
465 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, | ||
466 | "datastore-postgres", | ||
467 | "Deleted %u bytes from database\n", | ||
468 | (unsigned int)size); | ||
469 | } | ||
470 | } | ||
471 | GNUNET_PQ_cleanup_result(rs); | ||
472 | } /* for (i) */ | ||
477 | } | 473 | } |
478 | 474 | ||
479 | 475 | ||
@@ -491,13 +487,13 @@ process_result (void *cls, | |||
491 | * @param proc_cls closure for @a proc | 487 | * @param proc_cls closure for @a proc |
492 | */ | 488 | */ |
493 | static void | 489 | static void |
494 | postgres_plugin_get_key (void *cls, | 490 | postgres_plugin_get_key(void *cls, |
495 | uint64_t next_uid, | 491 | uint64_t next_uid, |
496 | bool random, | 492 | bool random, |
497 | const struct GNUNET_HashCode *key, | 493 | const struct GNUNET_HashCode *key, |
498 | enum GNUNET_BLOCK_Type type, | 494 | enum GNUNET_BLOCK_Type type, |
499 | PluginDatumProcessor proc, | 495 | PluginDatumProcessor proc, |
500 | void *proc_cls) | 496 | void *proc_cls) |
501 | { | 497 | { |
502 | struct Plugin *plugin = cls; | 498 | struct Plugin *plugin = cls; |
503 | uint32_t utype = type; | 499 | uint32_t utype = type; |
@@ -506,40 +502,40 @@ postgres_plugin_get_key (void *cls, | |||
506 | uint16_t use_type = GNUNET_BLOCK_TYPE_ANY != type; | 502 | uint16_t use_type = GNUNET_BLOCK_TYPE_ANY != type; |
507 | uint64_t rvalue; | 503 | uint64_t rvalue; |
508 | struct GNUNET_PQ_QueryParam params[] = { | 504 | struct GNUNET_PQ_QueryParam params[] = { |
509 | GNUNET_PQ_query_param_uint64 (&next_uid), | 505 | GNUNET_PQ_query_param_uint64(&next_uid), |
510 | GNUNET_PQ_query_param_uint64 (&rvalue), | 506 | GNUNET_PQ_query_param_uint64(&rvalue), |
511 | GNUNET_PQ_query_param_uint16 (&use_rvalue), | 507 | GNUNET_PQ_query_param_uint16(&use_rvalue), |
512 | GNUNET_PQ_query_param_auto_from_type (key), | 508 | GNUNET_PQ_query_param_auto_from_type(key), |
513 | GNUNET_PQ_query_param_uint16 (&use_key), | 509 | GNUNET_PQ_query_param_uint16(&use_key), |
514 | GNUNET_PQ_query_param_uint32 (&utype), | 510 | GNUNET_PQ_query_param_uint32(&utype), |
515 | GNUNET_PQ_query_param_uint16 (&use_type), | 511 | GNUNET_PQ_query_param_uint16(&use_type), |
516 | GNUNET_PQ_query_param_end | 512 | GNUNET_PQ_query_param_end |
517 | }; | 513 | }; |
518 | struct ProcessResultContext prc; | 514 | struct ProcessResultContext prc; |
519 | enum GNUNET_DB_QueryStatus res; | 515 | enum GNUNET_DB_QueryStatus res; |
520 | 516 | ||
521 | if (random) | 517 | if (random) |
522 | { | 518 | { |
523 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 519 | rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, |
524 | UINT64_MAX); | 520 | UINT64_MAX); |
525 | next_uid = 0; | 521 | next_uid = 0; |
526 | } | 522 | } |
527 | else | 523 | else |
528 | { | 524 | { |
529 | rvalue = 0; | 525 | rvalue = 0; |
530 | } | 526 | } |
531 | prc.plugin = plugin; | 527 | prc.plugin = plugin; |
532 | prc.proc = proc; | 528 | prc.proc = proc; |
533 | prc.proc_cls = proc_cls; | 529 | prc.proc_cls = proc_cls; |
534 | 530 | ||
535 | res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, | 531 | res = GNUNET_PQ_eval_prepared_multi_select(plugin->dbh, |
536 | "get", | 532 | "get", |
537 | params, | 533 | params, |
538 | &process_result, | 534 | &process_result, |
539 | &prc); | 535 | &prc); |
540 | if (0 > res) | 536 | if (0 > res) |
541 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, | 537 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, |
542 | GNUNET_TIME_UNIT_ZERO_ABS, 0); | 538 | GNUNET_TIME_UNIT_ZERO_ABS, 0); |
543 | } | 539 | } |
544 | 540 | ||
545 | 541 | ||
@@ -556,17 +552,17 @@ postgres_plugin_get_key (void *cls, | |||
556 | * @param proc_cls closure for @a proc | 552 | * @param proc_cls closure for @a proc |
557 | */ | 553 | */ |
558 | static void | 554 | static void |
559 | postgres_plugin_get_zero_anonymity (void *cls, | 555 | postgres_plugin_get_zero_anonymity(void *cls, |
560 | uint64_t next_uid, | 556 | uint64_t next_uid, |
561 | enum GNUNET_BLOCK_Type type, | 557 | enum GNUNET_BLOCK_Type type, |
562 | PluginDatumProcessor proc, | 558 | PluginDatumProcessor proc, |
563 | void *proc_cls) | 559 | void *proc_cls) |
564 | { | 560 | { |
565 | struct Plugin *plugin = cls; | 561 | struct Plugin *plugin = cls; |
566 | uint32_t utype = type; | 562 | uint32_t utype = type; |
567 | struct GNUNET_PQ_QueryParam params[] = { | 563 | struct GNUNET_PQ_QueryParam params[] = { |
568 | GNUNET_PQ_query_param_uint32 (&utype), | 564 | GNUNET_PQ_query_param_uint32(&utype), |
569 | GNUNET_PQ_query_param_uint64 (&next_uid), | 565 | GNUNET_PQ_query_param_uint64(&next_uid), |
570 | GNUNET_PQ_query_param_end | 566 | GNUNET_PQ_query_param_end |
571 | }; | 567 | }; |
572 | struct ProcessResultContext prc; | 568 | struct ProcessResultContext prc; |
@@ -575,23 +571,21 @@ postgres_plugin_get_zero_anonymity (void *cls, | |||
575 | prc.plugin = plugin; | 571 | prc.plugin = plugin; |
576 | prc.proc = proc; | 572 | prc.proc = proc; |
577 | prc.proc_cls = proc_cls; | 573 | prc.proc_cls = proc_cls; |
578 | res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, | 574 | res = GNUNET_PQ_eval_prepared_multi_select(plugin->dbh, |
579 | "select_non_anonymous", | 575 | "select_non_anonymous", |
580 | params, | 576 | params, |
581 | &process_result, | 577 | &process_result, |
582 | &prc); | 578 | &prc); |
583 | if (0 > res) | 579 | if (0 > res) |
584 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, | 580 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, |
585 | GNUNET_TIME_UNIT_ZERO_ABS, 0); | 581 | GNUNET_TIME_UNIT_ZERO_ABS, 0); |
586 | } | 582 | } |
587 | 583 | ||
588 | 584 | ||
589 | /** | 585 | /** |
590 | * Context for #repl_iter() function. | 586 | * Context for #repl_iter() function. |
591 | */ | 587 | */ |
592 | struct ReplCtx | 588 | struct ReplCtx { |
593 | { | ||
594 | |||
595 | /** | 589 | /** |
596 | * Plugin handle. | 590 | * Plugin handle. |
597 | */ | 591 | */ |
@@ -631,42 +625,42 @@ struct ReplCtx | |||
631 | * #GNUNET_NO to delete the item and continue (if supported) | 625 | * #GNUNET_NO to delete the item and continue (if supported) |
632 | */ | 626 | */ |
633 | static int | 627 | static int |
634 | repl_proc (void *cls, | 628 | repl_proc(void *cls, |
635 | const struct GNUNET_HashCode *key, | 629 | const struct GNUNET_HashCode *key, |
636 | uint32_t size, | 630 | uint32_t size, |
637 | const void *data, | 631 | const void *data, |
638 | enum GNUNET_BLOCK_Type type, | 632 | enum GNUNET_BLOCK_Type type, |
639 | uint32_t priority, | 633 | uint32_t priority, |
640 | uint32_t anonymity, | 634 | uint32_t anonymity, |
641 | uint32_t replication, | 635 | uint32_t replication, |
642 | struct GNUNET_TIME_Absolute expiration, | 636 | struct GNUNET_TIME_Absolute expiration, |
643 | uint64_t uid) | 637 | uint64_t uid) |
644 | { | 638 | { |
645 | struct ReplCtx *rc = cls; | 639 | struct ReplCtx *rc = cls; |
646 | struct Plugin *plugin = rc->plugin; | 640 | struct Plugin *plugin = rc->plugin; |
647 | int ret; | 641 | int ret; |
648 | uint32_t oid = (uint32_t) uid; | 642 | uint32_t oid = (uint32_t)uid; |
649 | struct GNUNET_PQ_QueryParam params[] = { | 643 | struct GNUNET_PQ_QueryParam params[] = { |
650 | GNUNET_PQ_query_param_uint32 (&oid), | 644 | GNUNET_PQ_query_param_uint32(&oid), |
651 | GNUNET_PQ_query_param_end | 645 | GNUNET_PQ_query_param_end |
652 | }; | 646 | }; |
653 | enum GNUNET_DB_QueryStatus qret; | 647 | enum GNUNET_DB_QueryStatus qret; |
654 | 648 | ||
655 | ret = rc->proc (rc->proc_cls, | 649 | ret = rc->proc(rc->proc_cls, |
656 | key, | 650 | key, |
657 | size, | 651 | size, |
658 | data, | 652 | data, |
659 | type, | 653 | type, |
660 | priority, | 654 | priority, |
661 | anonymity, | 655 | anonymity, |
662 | replication, | 656 | replication, |
663 | expiration, | 657 | expiration, |
664 | uid); | 658 | uid); |
665 | if (NULL == key) | 659 | if (NULL == key) |
666 | return ret; | 660 | return ret; |
667 | qret = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, | 661 | qret = GNUNET_PQ_eval_prepared_non_select(plugin->dbh, |
668 | "decrepl", | 662 | "decrepl", |
669 | params); | 663 | params); |
670 | if (0 > qret) | 664 | if (0 > qret) |
671 | return GNUNET_SYSERR; | 665 | return GNUNET_SYSERR; |
672 | return ret; | 666 | return ret; |
@@ -685,9 +679,9 @@ repl_proc (void *cls, | |||
685 | * @param proc_cls closure for @a proc | 679 | * @param proc_cls closure for @a proc |
686 | */ | 680 | */ |
687 | static void | 681 | static void |
688 | postgres_plugin_get_replication (void *cls, | 682 | postgres_plugin_get_replication(void *cls, |
689 | PluginDatumProcessor proc, | 683 | PluginDatumProcessor proc, |
690 | void *proc_cls) | 684 | void *proc_cls) |
691 | { | 685 | { |
692 | struct Plugin *plugin = cls; | 686 | struct Plugin *plugin = cls; |
693 | struct GNUNET_PQ_QueryParam params[] = { | 687 | struct GNUNET_PQ_QueryParam params[] = { |
@@ -703,14 +697,14 @@ postgres_plugin_get_replication (void *cls, | |||
703 | prc.plugin = plugin; | 697 | prc.plugin = plugin; |
704 | prc.proc = &repl_proc; | 698 | prc.proc = &repl_proc; |
705 | prc.proc_cls = &rc; | 699 | prc.proc_cls = &rc; |
706 | res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, | 700 | res = GNUNET_PQ_eval_prepared_multi_select(plugin->dbh, |
707 | "select_replication_order", | 701 | "select_replication_order", |
708 | params, | 702 | params, |
709 | &process_result, | 703 | &process_result, |
710 | &prc); | 704 | &prc); |
711 | if (0 > res) | 705 | if (0 > res) |
712 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, | 706 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, |
713 | GNUNET_TIME_UNIT_ZERO_ABS, 0); | 707 | GNUNET_TIME_UNIT_ZERO_ABS, 0); |
714 | } | 708 | } |
715 | 709 | ||
716 | 710 | ||
@@ -723,36 +717,34 @@ postgres_plugin_get_replication (void *cls, | |||
723 | * @param proc_cls closure for @a proc | 717 | * @param proc_cls closure for @a proc |
724 | */ | 718 | */ |
725 | static void | 719 | static void |
726 | postgres_plugin_get_expiration (void *cls, | 720 | postgres_plugin_get_expiration(void *cls, |
727 | PluginDatumProcessor proc, | 721 | PluginDatumProcessor proc, |
728 | void *proc_cls) | 722 | void *proc_cls) |
729 | { | 723 | { |
730 | struct Plugin *plugin = cls; | 724 | struct Plugin *plugin = cls; |
731 | struct GNUNET_TIME_Absolute now; | 725 | struct GNUNET_TIME_Absolute now; |
732 | struct GNUNET_PQ_QueryParam params[] = { | 726 | struct GNUNET_PQ_QueryParam params[] = { |
733 | GNUNET_PQ_query_param_absolute_time (&now), | 727 | GNUNET_PQ_query_param_absolute_time(&now), |
734 | GNUNET_PQ_query_param_end | 728 | GNUNET_PQ_query_param_end |
735 | }; | 729 | }; |
736 | struct ProcessResultContext prc; | 730 | struct ProcessResultContext prc; |
737 | 731 | ||
738 | now = GNUNET_TIME_absolute_get (); | 732 | now = GNUNET_TIME_absolute_get(); |
739 | prc.plugin = plugin; | 733 | prc.plugin = plugin; |
740 | prc.proc = proc; | 734 | prc.proc = proc; |
741 | prc.proc_cls = proc_cls; | 735 | prc.proc_cls = proc_cls; |
742 | (void) GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, | 736 | (void)GNUNET_PQ_eval_prepared_multi_select(plugin->dbh, |
743 | "select_expiration_order", | 737 | "select_expiration_order", |
744 | params, | 738 | params, |
745 | &process_result, | 739 | &process_result, |
746 | &prc); | 740 | &prc); |
747 | } | 741 | } |
748 | 742 | ||
749 | 743 | ||
750 | /** | 744 | /** |
751 | * Closure for #process_keys. | 745 | * Closure for #process_keys. |
752 | */ | 746 | */ |
753 | struct ProcessKeysContext | 747 | struct ProcessKeysContext { |
754 | { | ||
755 | |||
756 | /** | 748 | /** |
757 | * Function to call for each key. | 749 | * Function to call for each key. |
758 | */ | 750 | */ |
@@ -774,34 +766,34 @@ struct ProcessKeysContext | |||
774 | * @param num_result the number of results in @a result | 766 | * @param num_result the number of results in @a result |
775 | */ | 767 | */ |
776 | static void | 768 | static void |
777 | process_keys (void *cls, | 769 | process_keys(void *cls, |
778 | PGresult *result, | 770 | PGresult *result, |
779 | unsigned int num_results) | 771 | unsigned int num_results) |
780 | { | 772 | { |
781 | struct ProcessKeysContext *pkc = cls; | 773 | struct ProcessKeysContext *pkc = cls; |
782 | 774 | ||
783 | for (unsigned i=0;i<num_results;i++) | 775 | for (unsigned i = 0; i < num_results; i++) |
784 | { | ||
785 | struct GNUNET_HashCode key; | ||
786 | struct GNUNET_PQ_ResultSpec rs[] = { | ||
787 | GNUNET_PQ_result_spec_auto_from_type ("hash", | ||
788 | &key), | ||
789 | GNUNET_PQ_result_spec_end | ||
790 | }; | ||
791 | |||
792 | if (GNUNET_OK != | ||
793 | GNUNET_PQ_extract_result (result, | ||
794 | rs, | ||
795 | i)) | ||
796 | { | 776 | { |
797 | GNUNET_break (0); | 777 | struct GNUNET_HashCode key; |
798 | continue; | 778 | struct GNUNET_PQ_ResultSpec rs[] = { |
779 | GNUNET_PQ_result_spec_auto_from_type("hash", | ||
780 | &key), | ||
781 | GNUNET_PQ_result_spec_end | ||
782 | }; | ||
783 | |||
784 | if (GNUNET_OK != | ||
785 | GNUNET_PQ_extract_result(result, | ||
786 | rs, | ||
787 | i)) | ||
788 | { | ||
789 | GNUNET_break(0); | ||
790 | continue; | ||
791 | } | ||
792 | pkc->proc(pkc->proc_cls, | ||
793 | &key, | ||
794 | 1); | ||
795 | GNUNET_PQ_cleanup_result(rs); | ||
799 | } | 796 | } |
800 | pkc->proc (pkc->proc_cls, | ||
801 | &key, | ||
802 | 1); | ||
803 | GNUNET_PQ_cleanup_result (rs); | ||
804 | } | ||
805 | } | 797 | } |
806 | 798 | ||
807 | 799 | ||
@@ -813,9 +805,9 @@ process_keys (void *cls, | |||
813 | * @param proc_cls closure for @a proc | 805 | * @param proc_cls closure for @a proc |
814 | */ | 806 | */ |
815 | static void | 807 | static void |
816 | postgres_plugin_get_keys (void *cls, | 808 | postgres_plugin_get_keys(void *cls, |
817 | PluginKeyProcessor proc, | 809 | PluginKeyProcessor proc, |
818 | void *proc_cls) | 810 | void *proc_cls) |
819 | { | 811 | { |
820 | struct Plugin *plugin = cls; | 812 | struct Plugin *plugin = cls; |
821 | struct GNUNET_PQ_QueryParam params[] = { | 813 | struct GNUNET_PQ_QueryParam params[] = { |
@@ -825,14 +817,14 @@ postgres_plugin_get_keys (void *cls, | |||
825 | 817 | ||
826 | pkc.proc = proc; | 818 | pkc.proc = proc; |
827 | pkc.proc_cls = proc_cls; | 819 | pkc.proc_cls = proc_cls; |
828 | (void) GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, | 820 | (void)GNUNET_PQ_eval_prepared_multi_select(plugin->dbh, |
829 | "get_keys", | 821 | "get_keys", |
830 | params, | 822 | params, |
831 | &process_keys, | 823 | &process_keys, |
832 | &pkc); | 824 | &pkc); |
833 | proc (proc_cls, | 825 | proc(proc_cls, |
834 | NULL, | 826 | NULL, |
835 | 0); | 827 | 0); |
836 | } | 828 | } |
837 | 829 | ||
838 | 830 | ||
@@ -842,20 +834,20 @@ postgres_plugin_get_keys (void *cls, | |||
842 | * @param cls closure with the `struct Plugin *` | 834 | * @param cls closure with the `struct Plugin *` |
843 | */ | 835 | */ |
844 | static void | 836 | static void |
845 | postgres_plugin_drop (void *cls) | 837 | postgres_plugin_drop(void *cls) |
846 | { | 838 | { |
847 | struct Plugin *plugin = cls; | 839 | struct Plugin *plugin = cls; |
848 | struct GNUNET_PQ_ExecuteStatement es[] = { | 840 | struct GNUNET_PQ_ExecuteStatement es[] = { |
849 | GNUNET_PQ_make_execute ("DROP TABLE gn090"), | 841 | GNUNET_PQ_make_execute("DROP TABLE gn090"), |
850 | GNUNET_PQ_EXECUTE_STATEMENT_END | 842 | GNUNET_PQ_EXECUTE_STATEMENT_END |
851 | }; | 843 | }; |
852 | 844 | ||
853 | if (GNUNET_OK != | 845 | if (GNUNET_OK != |
854 | GNUNET_PQ_exec_statements (plugin->dbh, | 846 | GNUNET_PQ_exec_statements(plugin->dbh, |
855 | es)) | 847 | es)) |
856 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, | 848 | GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, |
857 | "postgres", | 849 | "postgres", |
858 | _("Failed to drop table from database.\n")); | 850 | _("Failed to drop table from database.\n")); |
859 | } | 851 | } |
860 | 852 | ||
861 | 853 | ||
@@ -870,53 +862,53 @@ postgres_plugin_drop (void *cls) | |||
870 | * @param cont_cls continuation closure for @a cont | 862 | * @param cont_cls continuation closure for @a cont |
871 | */ | 863 | */ |
872 | static void | 864 | static void |
873 | postgres_plugin_remove_key (void *cls, | 865 | postgres_plugin_remove_key(void *cls, |
874 | const struct GNUNET_HashCode *key, | 866 | const struct GNUNET_HashCode *key, |
875 | uint32_t size, | 867 | uint32_t size, |
876 | const void *data, | 868 | const void *data, |
877 | PluginRemoveCont cont, | 869 | PluginRemoveCont cont, |
878 | void *cont_cls) | 870 | void *cont_cls) |
879 | { | 871 | { |
880 | struct Plugin *plugin = cls; | 872 | struct Plugin *plugin = cls; |
881 | enum GNUNET_DB_QueryStatus ret; | 873 | enum GNUNET_DB_QueryStatus ret; |
882 | struct GNUNET_PQ_QueryParam params[] = { | 874 | struct GNUNET_PQ_QueryParam params[] = { |
883 | GNUNET_PQ_query_param_auto_from_type (key), | 875 | GNUNET_PQ_query_param_auto_from_type(key), |
884 | GNUNET_PQ_query_param_fixed_size (data, size), | 876 | GNUNET_PQ_query_param_fixed_size(data, size), |
885 | GNUNET_PQ_query_param_end | 877 | GNUNET_PQ_query_param_end |
886 | }; | 878 | }; |
887 | 879 | ||
888 | ret = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, | 880 | ret = GNUNET_PQ_eval_prepared_non_select(plugin->dbh, |
889 | "remove", | 881 | "remove", |
890 | params); | 882 | params); |
891 | if (0 > ret) | 883 | if (0 > ret) |
892 | { | 884 | { |
893 | cont (cont_cls, | 885 | cont(cont_cls, |
894 | key, | 886 | key, |
895 | size, | 887 | size, |
896 | GNUNET_SYSERR, | 888 | GNUNET_SYSERR, |
897 | _("Postgress exec failure")); | 889 | _("Postgress exec failure")); |
898 | return; | 890 | return; |
899 | } | 891 | } |
900 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == ret) | 892 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == ret) |
901 | { | 893 | { |
902 | cont (cont_cls, | 894 | cont(cont_cls, |
903 | key, | 895 | key, |
904 | size, | 896 | size, |
905 | GNUNET_NO, | 897 | GNUNET_NO, |
906 | NULL); | 898 | NULL); |
907 | return; | 899 | return; |
908 | } | 900 | } |
909 | plugin->env->duc (plugin->env->cls, | 901 | plugin->env->duc(plugin->env->cls, |
910 | - (size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); | 902 | -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); |
911 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 903 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, |
912 | "datastore-postgres", | 904 | "datastore-postgres", |
913 | "Deleted %u bytes from database\n", | 905 | "Deleted %u bytes from database\n", |
914 | (unsigned int) size); | 906 | (unsigned int)size); |
915 | cont (cont_cls, | 907 | cont(cont_cls, |
916 | key, | 908 | key, |
917 | size, | 909 | size, |
918 | GNUNET_OK, | 910 | GNUNET_OK, |
919 | NULL); | 911 | NULL); |
920 | } | 912 | } |
921 | 913 | ||
922 | 914 | ||
@@ -927,20 +919,20 @@ postgres_plugin_remove_key (void *cls, | |||
927 | * @return our `struct Plugin *` | 919 | * @return our `struct Plugin *` |
928 | */ | 920 | */ |
929 | void * | 921 | void * |
930 | libgnunet_plugin_datastore_postgres_init (void *cls) | 922 | libgnunet_plugin_datastore_postgres_init(void *cls) |
931 | { | 923 | { |
932 | struct GNUNET_DATASTORE_PluginEnvironment *env = cls; | 924 | struct GNUNET_DATASTORE_PluginEnvironment *env = cls; |
933 | struct GNUNET_DATASTORE_PluginFunctions *api; | 925 | struct GNUNET_DATASTORE_PluginFunctions *api; |
934 | struct Plugin *plugin; | 926 | struct Plugin *plugin; |
935 | 927 | ||
936 | plugin = GNUNET_new (struct Plugin); | 928 | plugin = GNUNET_new(struct Plugin); |
937 | plugin->env = env; | 929 | plugin->env = env; |
938 | if (GNUNET_OK != init_connection (plugin)) | 930 | if (GNUNET_OK != init_connection(plugin)) |
939 | { | 931 | { |
940 | GNUNET_free (plugin); | 932 | GNUNET_free(plugin); |
941 | return NULL; | 933 | return NULL; |
942 | } | 934 | } |
943 | api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions); | 935 | api = GNUNET_new(struct GNUNET_DATASTORE_PluginFunctions); |
944 | api->cls = plugin; | 936 | api->cls = plugin; |
945 | api->estimate_size = &postgres_plugin_estimate_size; | 937 | api->estimate_size = &postgres_plugin_estimate_size; |
946 | api->put = &postgres_plugin_put; | 938 | api->put = &postgres_plugin_put; |
@@ -951,9 +943,9 @@ libgnunet_plugin_datastore_postgres_init (void *cls) | |||
951 | api->get_keys = &postgres_plugin_get_keys; | 943 | api->get_keys = &postgres_plugin_get_keys; |
952 | api->drop = &postgres_plugin_drop; | 944 | api->drop = &postgres_plugin_drop; |
953 | api->remove_key = &postgres_plugin_remove_key; | 945 | api->remove_key = &postgres_plugin_remove_key; |
954 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | 946 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, |
955 | "datastore-postgres", | 947 | "datastore-postgres", |
956 | _("Postgres database running\n")); | 948 | _("Postgres database running\n")); |
957 | return api; | 949 | return api; |
958 | } | 950 | } |
959 | 951 | ||
@@ -965,14 +957,14 @@ libgnunet_plugin_datastore_postgres_init (void *cls) | |||
965 | * @return always NULL | 957 | * @return always NULL |
966 | */ | 958 | */ |
967 | void * | 959 | void * |
968 | libgnunet_plugin_datastore_postgres_done (void *cls) | 960 | libgnunet_plugin_datastore_postgres_done(void *cls) |
969 | { | 961 | { |
970 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; | 962 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; |
971 | struct Plugin *plugin = api->cls; | 963 | struct Plugin *plugin = api->cls; |
972 | 964 | ||
973 | PQfinish (plugin->dbh); | 965 | PQfinish(plugin->dbh); |
974 | GNUNET_free (plugin); | 966 | GNUNET_free(plugin); |
975 | GNUNET_free (api); | 967 | GNUNET_free(api); |
976 | return NULL; | 968 | return NULL; |
977 | } | 969 | } |
978 | 970 | ||
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index 4bd2b39cb..7d8d06529 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | * This file is part of GNUnet | 2 | * This file is part of GNUnet |
3 | * Copyright (C) 2009, 2011, 2017 GNUnet e.V. | 3 | * Copyright (C) 2009, 2011, 2017 GNUnet e.V. |
4 | * | 4 | * |
5 | * GNUnet is free software: you can redistribute it and/or modify it | 5 | * GNUnet is free software: you can redistribute it and/or modify it |
6 | * under the terms of the GNU Affero General Public License as published | 6 | * under the terms of the GNU Affero General Public License as published |
7 | * by the Free Software Foundation, either version 3 of the License, | 7 | * by the Free Software Foundation, either version 3 of the License, |
8 | * or (at your option) any later version. | 8 | * or (at your option) any later version. |
9 | * | 9 | * |
10 | * GNUnet is distributed in the hope that it will be useful, but | 10 | * GNUnet is distributed in the hope that it will be useful, but |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Affero General Public License for more details. | 13 | * Affero General Public License for more details. |
14 | * | 14 | * |
15 | * You should have received a copy of the GNU Affero General Public License | 15 | * You should have received a copy of the GNU Affero General Public License |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file datastore/plugin_datastore_sqlite.c | 22 | * @file datastore/plugin_datastore_sqlite.c |
@@ -57,15 +57,15 @@ | |||
57 | */ | 57 | */ |
58 | #define LOG_SQLITE(db, level, cmd) \ | 58 | #define LOG_SQLITE(db, level, cmd) \ |
59 | do \ | 59 | do \ |
60 | { \ | 60 | { \ |
61 | GNUNET_log_from (level, \ | 61 | GNUNET_log_from(level, \ |
62 | "sqlite", \ | 62 | "sqlite", \ |
63 | _ ("`%s' failed at %s:%d with error: %s\n"), \ | 63 | _("`%s' failed at %s:%d with error: %s\n"), \ |
64 | cmd, \ | 64 | cmd, \ |
65 | __FILE__, \ | 65 | __FILE__, \ |
66 | __LINE__, \ | 66 | __LINE__, \ |
67 | sqlite3_errmsg (db->dbh)); \ | 67 | sqlite3_errmsg(db->dbh)); \ |
68 | } while (0) | 68 | } while (0) |
69 | 69 | ||
70 | 70 | ||
71 | /** | 71 | /** |
@@ -75,28 +75,27 @@ | |||
75 | */ | 75 | */ |
76 | #define LOG_SQLITE_MSG(db, msg, level, cmd) \ | 76 | #define LOG_SQLITE_MSG(db, msg, level, cmd) \ |
77 | do \ | 77 | do \ |
78 | { \ | 78 | { \ |
79 | GNUNET_log_from (level, \ | 79 | GNUNET_log_from(level, \ |
80 | "sqlite", \ | 80 | "sqlite", \ |
81 | _ ("`%s' failed at %s:%d with error: %s\n"), \ | 81 | _("`%s' failed at %s:%d with error: %s\n"), \ |
82 | cmd, \ | 82 | cmd, \ |
83 | __FILE__, \ | 83 | __FILE__, \ |
84 | __LINE__, \ | 84 | __LINE__, \ |
85 | sqlite3_errmsg (db->dbh)); \ | 85 | sqlite3_errmsg(db->dbh)); \ |
86 | GNUNET_asprintf (msg, \ | 86 | GNUNET_asprintf(msg, \ |
87 | _ ("`%s' failed at %s:%u with error: %s"), \ | 87 | _("`%s' failed at %s:%u with error: %s"), \ |
88 | cmd, \ | 88 | cmd, \ |
89 | __FILE__, \ | 89 | __FILE__, \ |
90 | __LINE__, \ | 90 | __LINE__, \ |
91 | sqlite3_errmsg (db->dbh)); \ | 91 | sqlite3_errmsg(db->dbh)); \ |
92 | } while (0) | 92 | } while (0) |
93 | 93 | ||
94 | 94 | ||
95 | /** | 95 | /** |
96 | * Context for all functions in this plugin. | 96 | * Context for all functions in this plugin. |
97 | */ | 97 | */ |
98 | struct Plugin | 98 | struct Plugin { |
99 | { | ||
100 | /** | 99 | /** |
101 | * Our execution environment. | 100 | * Our execution environment. |
102 | */ | 101 | */ |
@@ -178,22 +177,22 @@ struct Plugin | |||
178 | * @return 0 on success | 177 | * @return 0 on success |
179 | */ | 178 | */ |
180 | static int | 179 | static int |
181 | sq_prepare (sqlite3 *dbh, const char *zSql, sqlite3_stmt **ppStmt) | 180 | sq_prepare(sqlite3 *dbh, const char *zSql, sqlite3_stmt **ppStmt) |
182 | { | 181 | { |
183 | char *dummy; | 182 | char *dummy; |
184 | int result; | 183 | int result; |
185 | 184 | ||
186 | result = sqlite3_prepare_v2 (dbh, | 185 | result = sqlite3_prepare_v2(dbh, |
187 | zSql, | 186 | zSql, |
188 | strlen (zSql), | 187 | strlen(zSql), |
189 | ppStmt, | 188 | ppStmt, |
190 | (const char **) &dummy); | 189 | (const char **)&dummy); |
191 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 190 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, |
192 | "sqlite", | 191 | "sqlite", |
193 | "Prepared `%s' / %p: %d\n", | 192 | "Prepared `%s' / %p: %d\n", |
194 | zSql, | 193 | zSql, |
195 | *ppStmt, | 194 | *ppStmt, |
196 | result); | 195 | result); |
197 | return result; | 196 | return result; |
198 | } | 197 | } |
199 | 198 | ||
@@ -204,56 +203,56 @@ sq_prepare (sqlite3 *dbh, const char *zSql, sqlite3_stmt **ppStmt) | |||
204 | * @param dbh handle to the database | 203 | * @param dbh handle to the database |
205 | */ | 204 | */ |
206 | static void | 205 | static void |
207 | create_indices (sqlite3 *dbh) | 206 | create_indices(sqlite3 *dbh) |
208 | { | 207 | { |
209 | /* create indices */ | 208 | /* create indices */ |
210 | if ( | 209 | if ( |
211 | 0 != | 210 | 0 != |
212 | (SQLITE_OK != | 211 | (SQLITE_OK != |
213 | sqlite3_exec (dbh, | 212 | sqlite3_exec(dbh, |
214 | "CREATE INDEX IF NOT EXISTS idx_hash ON gn091 (hash)", | 213 | "CREATE INDEX IF NOT EXISTS idx_hash ON gn091 (hash)", |
215 | NULL, | 214 | NULL, |
216 | NULL, | 215 | NULL, |
217 | NULL)) + | 216 | NULL)) + |
218 | (SQLITE_OK != | 217 | (SQLITE_OK != |
219 | sqlite3_exec ( | 218 | sqlite3_exec( |
220 | dbh, | 219 | dbh, |
221 | "CREATE INDEX IF NOT EXISTS idx_anon_type ON gn091 (anonLevel ASC,type)", | 220 | "CREATE INDEX IF NOT EXISTS idx_anon_type ON gn091 (anonLevel ASC,type)", |
222 | NULL, | 221 | NULL, |
223 | NULL, | 222 | NULL, |
224 | NULL)) + | 223 | NULL)) + |
225 | (SQLITE_OK != | 224 | (SQLITE_OK != |
226 | sqlite3_exec (dbh, | 225 | sqlite3_exec(dbh, |
227 | "CREATE INDEX IF NOT EXISTS idx_expire ON gn091 (expire ASC)", | 226 | "CREATE INDEX IF NOT EXISTS idx_expire ON gn091 (expire ASC)", |
228 | NULL, | 227 | NULL, |
229 | NULL, | 228 | NULL, |
230 | NULL)) + | 229 | NULL)) + |
231 | (SQLITE_OK != | 230 | (SQLITE_OK != |
232 | sqlite3_exec ( | 231 | sqlite3_exec( |
233 | dbh, | 232 | dbh, |
234 | "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn091 (repl,rvalue)", | 233 | "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn091 (repl,rvalue)", |
235 | NULL, | 234 | NULL, |
236 | NULL, | 235 | NULL, |
237 | NULL))) | 236 | NULL))) |
238 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 237 | GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, |
239 | "sqlite", | 238 | "sqlite", |
240 | "Failed to create indices: %s\n", | 239 | "Failed to create indices: %s\n", |
241 | sqlite3_errmsg (dbh)); | 240 | sqlite3_errmsg(dbh)); |
242 | } | 241 | } |
243 | 242 | ||
244 | 243 | ||
245 | #if 0 | 244 | #if 0 |
246 | #define CHECK(a) GNUNET_break (a) | 245 | #define CHECK(a) GNUNET_break(a) |
247 | #define ENULL NULL | 246 | #define ENULL NULL |
248 | #else | 247 | #else |
249 | #define ENULL &e | 248 | #define ENULL &e |
250 | #define ENULL_DEFINED 1 | 249 | #define ENULL_DEFINED 1 |
251 | #define CHECK(a) \ | 250 | #define CHECK(a) \ |
252 | if (! (a)) \ | 251 | if (!(a)) \ |
253 | { \ | 252 | { \ |
254 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", e); \ | 253 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); \ |
255 | sqlite3_free (e); \ | 254 | sqlite3_free(e); \ |
256 | } | 255 | } |
257 | #endif | 256 | #endif |
258 | 257 | ||
259 | 258 | ||
@@ -267,219 +266,220 @@ create_indices (sqlite3 *dbh) | |||
267 | * @return #GNUNET_OK on success | 266 | * @return #GNUNET_OK on success |
268 | */ | 267 | */ |
269 | static int | 268 | static int |
270 | database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | 269 | database_setup(const struct GNUNET_CONFIGURATION_Handle *cfg, |
271 | struct Plugin *plugin) | 270 | struct Plugin *plugin) |
272 | { | 271 | { |
273 | sqlite3_stmt *stmt; | 272 | sqlite3_stmt *stmt; |
274 | char *afsdir; | 273 | char *afsdir; |
274 | |||
275 | #if ENULL_DEFINED | 275 | #if ENULL_DEFINED |
276 | char *e; | 276 | char *e; |
277 | #endif | 277 | #endif |
278 | 278 | ||
279 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, | 279 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, |
280 | "datastore-sqlite", | 280 | "datastore-sqlite", |
281 | "FILENAME", | 281 | "FILENAME", |
282 | &afsdir)) | 282 | &afsdir)) |
283 | { | ||
284 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
285 | "datastore-sqlite", | ||
286 | "FILENAME"); | ||
287 | return GNUNET_SYSERR; | ||
288 | } | ||
289 | if (GNUNET_OK != GNUNET_DISK_file_test (afsdir)) | ||
290 | { | ||
291 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir)) | ||
292 | { | 283 | { |
293 | GNUNET_break (0); | 284 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
294 | GNUNET_free (afsdir); | 285 | "datastore-sqlite", |
286 | "FILENAME"); | ||
295 | return GNUNET_SYSERR; | 287 | return GNUNET_SYSERR; |
296 | } | 288 | } |
297 | /* database is new or got deleted, reset payload to zero! */ | 289 | if (GNUNET_OK != GNUNET_DISK_file_test(afsdir)) |
298 | if (NULL != plugin->env->duc) | 290 | { |
299 | plugin->env->duc (plugin->env->cls, 0); | 291 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(afsdir)) |
300 | } | 292 | { |
293 | GNUNET_break(0); | ||
294 | GNUNET_free(afsdir); | ||
295 | return GNUNET_SYSERR; | ||
296 | } | ||
297 | /* database is new or got deleted, reset payload to zero! */ | ||
298 | if (NULL != plugin->env->duc) | ||
299 | plugin->env->duc(plugin->env->cls, 0); | ||
300 | } | ||
301 | /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */ | 301 | /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */ |
302 | plugin->fn = afsdir; | 302 | plugin->fn = afsdir; |
303 | 303 | ||
304 | /* Open database and precompile statements */ | 304 | /* Open database and precompile statements */ |
305 | if (SQLITE_OK != sqlite3_open (plugin->fn, &plugin->dbh)) | 305 | if (SQLITE_OK != sqlite3_open(plugin->fn, &plugin->dbh)) |
306 | { | 306 | { |
307 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 307 | GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, |
308 | "sqlite", | 308 | "sqlite", |
309 | _ ("Unable to initialize SQLite: %s.\n"), | 309 | _("Unable to initialize SQLite: %s.\n"), |
310 | sqlite3_errmsg (plugin->dbh)); | 310 | sqlite3_errmsg(plugin->dbh)); |
311 | return GNUNET_SYSERR; | 311 | return GNUNET_SYSERR; |
312 | } | 312 | } |
313 | CHECK ( | 313 | CHECK( |
314 | SQLITE_OK == | 314 | SQLITE_OK == |
315 | sqlite3_exec (plugin->dbh, "PRAGMA temp_store=MEMORY", NULL, NULL, ENULL)); | 315 | sqlite3_exec(plugin->dbh, "PRAGMA temp_store=MEMORY", NULL, NULL, ENULL)); |
316 | CHECK ( | 316 | CHECK( |
317 | SQLITE_OK == | 317 | SQLITE_OK == |
318 | sqlite3_exec (plugin->dbh, "PRAGMA synchronous=OFF", NULL, NULL, ENULL)); | 318 | sqlite3_exec(plugin->dbh, "PRAGMA synchronous=OFF", NULL, NULL, ENULL)); |
319 | CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, | 319 | CHECK(SQLITE_OK == sqlite3_exec(plugin->dbh, |
320 | "PRAGMA legacy_file_format=OFF", | 320 | "PRAGMA legacy_file_format=OFF", |
321 | NULL, | 321 | NULL, |
322 | NULL, | 322 | NULL, |
323 | ENULL)); | 323 | ENULL)); |
324 | CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, | 324 | CHECK(SQLITE_OK == sqlite3_exec(plugin->dbh, |
325 | "PRAGMA auto_vacuum=INCREMENTAL", | 325 | "PRAGMA auto_vacuum=INCREMENTAL", |
326 | NULL, | 326 | NULL, |
327 | NULL, | 327 | NULL, |
328 | ENULL)); | 328 | ENULL)); |
329 | CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, | 329 | CHECK(SQLITE_OK == sqlite3_exec(plugin->dbh, |
330 | "PRAGMA locking_mode=EXCLUSIVE", | 330 | "PRAGMA locking_mode=EXCLUSIVE", |
331 | NULL, | 331 | NULL, |
332 | NULL, | 332 | NULL, |
333 | ENULL)); | 333 | ENULL)); |
334 | CHECK ( | 334 | CHECK( |
335 | SQLITE_OK == | 335 | SQLITE_OK == |
336 | sqlite3_exec (plugin->dbh, "PRAGMA page_size=4096", NULL, NULL, ENULL)); | 336 | sqlite3_exec(plugin->dbh, "PRAGMA page_size=4096", NULL, NULL, ENULL)); |
337 | 337 | ||
338 | CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS)); | 338 | CHECK(SQLITE_OK == sqlite3_busy_timeout(plugin->dbh, BUSY_TIMEOUT_MS)); |
339 | 339 | ||
340 | 340 | ||
341 | /* We have to do it here, because otherwise precompiling SQL might fail */ | 341 | /* We have to do it here, because otherwise precompiling SQL might fail */ |
342 | CHECK (SQLITE_OK == | 342 | CHECK(SQLITE_OK == |
343 | sq_prepare (plugin->dbh, | 343 | sq_prepare(plugin->dbh, |
344 | "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn091'", | 344 | "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn091'", |
345 | &stmt)); | 345 | &stmt)); |
346 | 346 | ||
347 | /* FIXME: SQLite does not have unsigned integers! This is ok for the type column because | 347 | /* FIXME: SQLite does not have unsigned integers! This is ok for the type column because |
348 | * we only test equality on it and can cast it to/from uint32_t. For repl, prio, and anonLevel | 348 | * we only test equality on it and can cast it to/from uint32_t. For repl, prio, and anonLevel |
349 | * we do math or inequality tests, so we can't handle the entire range of uint32_t. | 349 | * we do math or inequality tests, so we can't handle the entire range of uint32_t. |
350 | * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC. | 350 | * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC. |
351 | */ | 351 | */ |
352 | if ((SQLITE_DONE == sqlite3_step (stmt)) && | 352 | if ((SQLITE_DONE == sqlite3_step(stmt)) && |
353 | (SQLITE_OK != sqlite3_exec (plugin->dbh, | 353 | (SQLITE_OK != sqlite3_exec(plugin->dbh, |
354 | "CREATE TABLE gn091 (" | 354 | "CREATE TABLE gn091 (" |
355 | " repl INT4 NOT NULL DEFAULT 0," | 355 | " repl INT4 NOT NULL DEFAULT 0," |
356 | " type INT4 NOT NULL DEFAULT 0," | 356 | " type INT4 NOT NULL DEFAULT 0," |
357 | " prio INT4 NOT NULL DEFAULT 0," | 357 | " prio INT4 NOT NULL DEFAULT 0," |
358 | " anonLevel INT4 NOT NULL DEFAULT 0," | 358 | " anonLevel INT4 NOT NULL DEFAULT 0," |
359 | " expire INT8 NOT NULL DEFAULT 0," | 359 | " expire INT8 NOT NULL DEFAULT 0," |
360 | " rvalue INT8 NOT NULL," | 360 | " rvalue INT8 NOT NULL," |
361 | " hash TEXT NOT NULL DEFAULT ''," | 361 | " hash TEXT NOT NULL DEFAULT ''," |
362 | " vhash TEXT NOT NULL DEFAULT ''," | 362 | " vhash TEXT NOT NULL DEFAULT ''," |
363 | " value BLOB NOT NULL DEFAULT '')", | 363 | " value BLOB NOT NULL DEFAULT '')", |
364 | NULL, | 364 | NULL, |
365 | NULL, | 365 | NULL, |
366 | NULL))) | 366 | NULL))) |
367 | { | 367 | { |
368 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); | 368 | LOG_SQLITE(plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); |
369 | sqlite3_finalize (stmt); | 369 | sqlite3_finalize(stmt); |
370 | return GNUNET_SYSERR; | 370 | return GNUNET_SYSERR; |
371 | } | 371 | } |
372 | sqlite3_finalize (stmt); | 372 | sqlite3_finalize(stmt); |
373 | create_indices (plugin->dbh); | 373 | create_indices(plugin->dbh); |
374 | 374 | ||
375 | #define RESULT_COLUMNS \ | 375 | #define RESULT_COLUMNS \ |
376 | "repl, type, prio, anonLevel, expire, hash, value, _ROWID_" | 376 | "repl, type, prio, anonLevel, expire, hash, value, _ROWID_" |
377 | if ( | 377 | if ( |
378 | (SQLITE_OK != sq_prepare (plugin->dbh, | 378 | (SQLITE_OK != sq_prepare(plugin->dbh, |
379 | "UPDATE gn091 " | 379 | "UPDATE gn091 " |
380 | "SET prio = prio + ?, " | 380 | "SET prio = prio + ?, " |
381 | "repl = repl + ?, " | 381 | "repl = repl + ?, " |
382 | "expire = MAX(expire, ?) " | 382 | "expire = MAX(expire, ?) " |
383 | "WHERE hash = ? AND vhash = ?", | 383 | "WHERE hash = ? AND vhash = ?", |
384 | &plugin->update)) || | 384 | &plugin->update)) || |
385 | (SQLITE_OK != sq_prepare (plugin->dbh, | 385 | (SQLITE_OK != sq_prepare(plugin->dbh, |
386 | "UPDATE gn091 " | 386 | "UPDATE gn091 " |
387 | "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?", | 387 | "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?", |
388 | &plugin->updRepl)) || | 388 | &plugin->updRepl)) || |
389 | (SQLITE_OK != sq_prepare (plugin->dbh, | 389 | (SQLITE_OK != sq_prepare(plugin->dbh, |
390 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 390 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
391 | "WHERE repl=?2 AND " | 391 | "WHERE repl=?2 AND " |
392 | " (rvalue>=?1 OR " | 392 | " (rvalue>=?1 OR " |
393 | " NOT EXISTS (SELECT 1 FROM gn091 " | 393 | " NOT EXISTS (SELECT 1 FROM gn091 " |
394 | "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) " | 394 | "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) " |
395 | "ORDER BY rvalue ASC LIMIT 1", | 395 | "ORDER BY rvalue ASC LIMIT 1", |
396 | &plugin->selRepl)) || | 396 | &plugin->selRepl)) || |
397 | (SQLITE_OK != sq_prepare (plugin->dbh, | 397 | (SQLITE_OK != sq_prepare(plugin->dbh, |
398 | "SELECT MAX(repl) FROM gn091", | 398 | "SELECT MAX(repl) FROM gn091", |
399 | &plugin->maxRepl)) || | 399 | &plugin->maxRepl)) || |
400 | (SQLITE_OK != | 400 | (SQLITE_OK != |
401 | sq_prepare (plugin->dbh, | 401 | sq_prepare(plugin->dbh, |
402 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 402 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
403 | "WHERE NOT EXISTS (SELECT 1 FROM gn091 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) " | 403 | "WHERE NOT EXISTS (SELECT 1 FROM gn091 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) " |
404 | "ORDER BY expire ASC LIMIT 1", | 404 | "ORDER BY expire ASC LIMIT 1", |
405 | &plugin->selExpi)) || | 405 | &plugin->selExpi)) || |
406 | (SQLITE_OK != sq_prepare (plugin->dbh, | 406 | (SQLITE_OK != sq_prepare(plugin->dbh, |
407 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 407 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
408 | "WHERE _ROWID_ >= ? AND " | 408 | "WHERE _ROWID_ >= ? AND " |
409 | "anonLevel = 0 AND " | 409 | "anonLevel = 0 AND " |
410 | "type = ? " | 410 | "type = ? " |
411 | "ORDER BY _ROWID_ ASC LIMIT 1", | 411 | "ORDER BY _ROWID_ ASC LIMIT 1", |
412 | &plugin->selZeroAnon)) || | 412 | &plugin->selZeroAnon)) || |
413 | (SQLITE_OK != | 413 | (SQLITE_OK != |
414 | sq_prepare (plugin->dbh, | 414 | sq_prepare(plugin->dbh, |
415 | "INSERT INTO gn091 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) " | 415 | "INSERT INTO gn091 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) " |
416 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", | 416 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", |
417 | &plugin->insertContent)) || | 417 | &plugin->insertContent)) || |
418 | (SQLITE_OK != sq_prepare (plugin->dbh, | 418 | (SQLITE_OK != sq_prepare(plugin->dbh, |
419 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 419 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
420 | "WHERE _ROWID_ >= ?1 " | 420 | "WHERE _ROWID_ >= ?1 " |
421 | "ORDER BY _ROWID_ ASC LIMIT 1", | 421 | "ORDER BY _ROWID_ ASC LIMIT 1", |
422 | &plugin->get[0])) || | 422 | &plugin->get[0])) || |
423 | (SQLITE_OK != sq_prepare (plugin->dbh, | 423 | (SQLITE_OK != sq_prepare(plugin->dbh, |
424 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 424 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
425 | "WHERE _ROWID_ >= ?1 AND " | 425 | "WHERE _ROWID_ >= ?1 AND " |
426 | "type = ?4 " | 426 | "type = ?4 " |
427 | "ORDER BY _ROWID_ ASC LIMIT 1", | 427 | "ORDER BY _ROWID_ ASC LIMIT 1", |
428 | &plugin->get[1])) || | 428 | &plugin->get[1])) || |
429 | (SQLITE_OK != sq_prepare (plugin->dbh, | 429 | (SQLITE_OK != sq_prepare(plugin->dbh, |
430 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 430 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
431 | "WHERE _ROWID_ >= ?1 AND " | 431 | "WHERE _ROWID_ >= ?1 AND " |
432 | "hash = ?3 " | 432 | "hash = ?3 " |
433 | "ORDER BY _ROWID_ ASC LIMIT 1", | 433 | "ORDER BY _ROWID_ ASC LIMIT 1", |
434 | &plugin->get[2])) || | 434 | &plugin->get[2])) || |
435 | (SQLITE_OK != sq_prepare (plugin->dbh, | 435 | (SQLITE_OK != sq_prepare(plugin->dbh, |
436 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 436 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
437 | "WHERE _ROWID_ >= ?1 AND " | 437 | "WHERE _ROWID_ >= ?1 AND " |
438 | "hash = ?3 AND " | 438 | "hash = ?3 AND " |
439 | "type = ?4 " | 439 | "type = ?4 " |
440 | "ORDER BY _ROWID_ ASC LIMIT 1", | 440 | "ORDER BY _ROWID_ ASC LIMIT 1", |
441 | &plugin->get[3])) || | 441 | &plugin->get[3])) || |
442 | (SQLITE_OK != sq_prepare (plugin->dbh, | 442 | (SQLITE_OK != sq_prepare(plugin->dbh, |
443 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 443 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
444 | "WHERE _ROWID_ >= ?1 AND " | 444 | "WHERE _ROWID_ >= ?1 AND " |
445 | "rvalue >= ?2 " | 445 | "rvalue >= ?2 " |
446 | "ORDER BY _ROWID_ ASC LIMIT 1", | 446 | "ORDER BY _ROWID_ ASC LIMIT 1", |
447 | &plugin->get[4])) || | 447 | &plugin->get[4])) || |
448 | (SQLITE_OK != sq_prepare (plugin->dbh, | 448 | (SQLITE_OK != sq_prepare(plugin->dbh, |
449 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 449 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
450 | "WHERE _ROWID_ >= ?1 AND " | 450 | "WHERE _ROWID_ >= ?1 AND " |
451 | "rvalue >= ?2 AND " | 451 | "rvalue >= ?2 AND " |
452 | "type = ?4 " | 452 | "type = ?4 " |
453 | "ORDER BY _ROWID_ ASC LIMIT 1", | 453 | "ORDER BY _ROWID_ ASC LIMIT 1", |
454 | &plugin->get[5])) || | 454 | &plugin->get[5])) || |
455 | (SQLITE_OK != sq_prepare (plugin->dbh, | 455 | (SQLITE_OK != sq_prepare(plugin->dbh, |
456 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 456 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
457 | "WHERE _ROWID_ >= ?1 AND " | 457 | "WHERE _ROWID_ >= ?1 AND " |
458 | "rvalue >= ?2 AND " | 458 | "rvalue >= ?2 AND " |
459 | "hash = ?3 " | 459 | "hash = ?3 " |
460 | "ORDER BY _ROWID_ ASC LIMIT 1", | 460 | "ORDER BY _ROWID_ ASC LIMIT 1", |
461 | &plugin->get[6])) || | 461 | &plugin->get[6])) || |
462 | (SQLITE_OK != sq_prepare (plugin->dbh, | 462 | (SQLITE_OK != sq_prepare(plugin->dbh, |
463 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 463 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
464 | "WHERE _ROWID_ >= ?1 AND " | 464 | "WHERE _ROWID_ >= ?1 AND " |
465 | "rvalue >= ?2 AND " | 465 | "rvalue >= ?2 AND " |
466 | "hash = ?3 AND " | 466 | "hash = ?3 AND " |
467 | "type = ?4 " | 467 | "type = ?4 " |
468 | "ORDER BY _ROWID_ ASC LIMIT 1", | 468 | "ORDER BY _ROWID_ ASC LIMIT 1", |
469 | &plugin->get[7])) || | 469 | &plugin->get[7])) || |
470 | (SQLITE_OK != sq_prepare (plugin->dbh, | 470 | (SQLITE_OK != sq_prepare(plugin->dbh, |
471 | "DELETE FROM gn091 WHERE _ROWID_ = ?", | 471 | "DELETE FROM gn091 WHERE _ROWID_ = ?", |
472 | &plugin->delRow)) || | 472 | &plugin->delRow)) || |
473 | (SQLITE_OK != sq_prepare (plugin->dbh, | 473 | (SQLITE_OK != sq_prepare(plugin->dbh, |
474 | "DELETE FROM gn091 " | 474 | "DELETE FROM gn091 " |
475 | "WHERE hash = ? AND " | 475 | "WHERE hash = ? AND " |
476 | "value = ? ", | 476 | "value = ? ", |
477 | &plugin->remove)) || | 477 | &plugin->remove)) || |
478 | false) | 478 | false) |
479 | { | 479 | { |
480 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "precompiling"); | 480 | LOG_SQLITE(plugin, GNUNET_ERROR_TYPE_ERROR, "precompiling"); |
481 | return GNUNET_SYSERR; | 481 | return GNUNET_SYSERR; |
482 | } | 482 | } |
483 | return GNUNET_OK; | 483 | return GNUNET_OK; |
484 | } | 484 | } |
485 | 485 | ||
@@ -491,65 +491,66 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
491 | * @param plugin the plugin context (state for this module) | 491 | * @param plugin the plugin context (state for this module) |
492 | */ | 492 | */ |
493 | static void | 493 | static void |
494 | database_shutdown (struct Plugin *plugin) | 494 | database_shutdown(struct Plugin *plugin) |
495 | { | 495 | { |
496 | int result; | 496 | int result; |
497 | |||
497 | #if SQLITE_VERSION_NUMBER >= 3007000 | 498 | #if SQLITE_VERSION_NUMBER >= 3007000 |
498 | sqlite3_stmt *stmt; | 499 | sqlite3_stmt *stmt; |
499 | #endif | 500 | #endif |
500 | 501 | ||
501 | if (NULL != plugin->remove) | 502 | if (NULL != plugin->remove) |
502 | sqlite3_finalize (plugin->remove); | 503 | sqlite3_finalize(plugin->remove); |
503 | if (NULL != plugin->delRow) | 504 | if (NULL != plugin->delRow) |
504 | sqlite3_finalize (plugin->delRow); | 505 | sqlite3_finalize(plugin->delRow); |
505 | if (NULL != plugin->update) | 506 | if (NULL != plugin->update) |
506 | sqlite3_finalize (plugin->update); | 507 | sqlite3_finalize(plugin->update); |
507 | if (NULL != plugin->updRepl) | 508 | if (NULL != plugin->updRepl) |
508 | sqlite3_finalize (plugin->updRepl); | 509 | sqlite3_finalize(plugin->updRepl); |
509 | if (NULL != plugin->selRepl) | 510 | if (NULL != plugin->selRepl) |
510 | sqlite3_finalize (plugin->selRepl); | 511 | sqlite3_finalize(plugin->selRepl); |
511 | if (NULL != plugin->maxRepl) | 512 | if (NULL != plugin->maxRepl) |
512 | sqlite3_finalize (plugin->maxRepl); | 513 | sqlite3_finalize(plugin->maxRepl); |
513 | if (NULL != plugin->selExpi) | 514 | if (NULL != plugin->selExpi) |
514 | sqlite3_finalize (plugin->selExpi); | 515 | sqlite3_finalize(plugin->selExpi); |
515 | if (NULL != plugin->selZeroAnon) | 516 | if (NULL != plugin->selZeroAnon) |
516 | sqlite3_finalize (plugin->selZeroAnon); | 517 | sqlite3_finalize(plugin->selZeroAnon); |
517 | if (NULL != plugin->insertContent) | 518 | if (NULL != plugin->insertContent) |
518 | sqlite3_finalize (plugin->insertContent); | 519 | sqlite3_finalize(plugin->insertContent); |
519 | for (int i = 0; i < 8; ++i) | 520 | for (int i = 0; i < 8; ++i) |
520 | if (NULL != plugin->get[i]) | 521 | if (NULL != plugin->get[i]) |
521 | sqlite3_finalize (plugin->get[i]); | 522 | sqlite3_finalize(plugin->get[i]); |
522 | result = sqlite3_close (plugin->dbh); | 523 | result = sqlite3_close(plugin->dbh); |
523 | #if SQLITE_VERSION_NUMBER >= 3007000 | 524 | #if SQLITE_VERSION_NUMBER >= 3007000 |
524 | if (result == SQLITE_BUSY) | 525 | if (result == SQLITE_BUSY) |
525 | { | ||
526 | GNUNET_log_from ( | ||
527 | GNUNET_ERROR_TYPE_WARNING, | ||
528 | "sqlite", | ||
529 | _ ( | ||
530 | "Tried to close sqlite without finalizing all prepared statements.\n")); | ||
531 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); | ||
532 | while (NULL != stmt) | ||
533 | { | 526 | { |
534 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 527 | GNUNET_log_from( |
535 | "sqlite", | 528 | GNUNET_ERROR_TYPE_WARNING, |
536 | "Closing statement %p\n", | 529 | "sqlite", |
537 | stmt); | 530 | _( |
538 | result = sqlite3_finalize (stmt); | 531 | "Tried to close sqlite without finalizing all prepared statements.\n")); |
539 | if (result != SQLITE_OK) | 532 | stmt = sqlite3_next_stmt(plugin->dbh, NULL); |
540 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, | 533 | while (NULL != stmt) |
541 | "sqlite", | 534 | { |
542 | "Failed to close statement %p: %d\n", | 535 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, |
543 | stmt, | 536 | "sqlite", |
544 | result); | 537 | "Closing statement %p\n", |
545 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); | 538 | stmt); |
539 | result = sqlite3_finalize(stmt); | ||
540 | if (result != SQLITE_OK) | ||
541 | GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, | ||
542 | "sqlite", | ||
543 | "Failed to close statement %p: %d\n", | ||
544 | stmt, | ||
545 | result); | ||
546 | stmt = sqlite3_next_stmt(plugin->dbh, NULL); | ||
547 | } | ||
548 | result = sqlite3_close(plugin->dbh); | ||
546 | } | 549 | } |
547 | result = sqlite3_close (plugin->dbh); | ||
548 | } | ||
549 | #endif | 550 | #endif |
550 | if (SQLITE_OK != result) | 551 | if (SQLITE_OK != result) |
551 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close"); | 552 | LOG_SQLITE(plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close"); |
552 | GNUNET_free_non_null (plugin->fn); | 553 | GNUNET_free_non_null(plugin->fn); |
553 | } | 554 | } |
554 | 555 | ||
555 | 556 | ||
@@ -561,22 +562,22 @@ database_shutdown (struct Plugin *plugin) | |||
561 | * @param rid the ID of the row to delete | 562 | * @param rid the ID of the row to delete |
562 | */ | 563 | */ |
563 | static int | 564 | static int |
564 | delete_by_rowid (struct Plugin *plugin, uint64_t rid) | 565 | delete_by_rowid(struct Plugin *plugin, uint64_t rid) |
565 | { | 566 | { |
566 | struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_uint64 (&rid), | 567 | struct GNUNET_SQ_QueryParam params[] = { GNUNET_SQ_query_param_uint64(&rid), |
567 | GNUNET_SQ_query_param_end}; | 568 | GNUNET_SQ_query_param_end }; |
568 | 569 | ||
569 | if (GNUNET_OK != GNUNET_SQ_bind (plugin->delRow, params)) | 570 | if (GNUNET_OK != GNUNET_SQ_bind(plugin->delRow, params)) |
570 | return GNUNET_SYSERR; | ||
571 | if (SQLITE_DONE != sqlite3_step (plugin->delRow)) | ||
572 | { | ||
573 | LOG_SQLITE (plugin, | ||
574 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
575 | "sqlite3_step"); | ||
576 | GNUNET_SQ_reset (plugin->dbh, plugin->delRow); | ||
577 | return GNUNET_SYSERR; | 571 | return GNUNET_SYSERR; |
578 | } | 572 | if (SQLITE_DONE != sqlite3_step(plugin->delRow)) |
579 | GNUNET_SQ_reset (plugin->dbh, plugin->delRow); | 573 | { |
574 | LOG_SQLITE(plugin, | ||
575 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
576 | "sqlite3_step"); | ||
577 | GNUNET_SQ_reset(plugin->dbh, plugin->delRow); | ||
578 | return GNUNET_SYSERR; | ||
579 | } | ||
580 | GNUNET_SQ_reset(plugin->dbh, plugin->delRow); | ||
580 | return GNUNET_OK; | 581 | return GNUNET_OK; |
581 | } | 582 | } |
582 | 583 | ||
@@ -598,135 +599,137 @@ delete_by_rowid (struct Plugin *plugin, uint64_t rid) | |||
598 | * @param cont_cls continuation closure | 599 | * @param cont_cls continuation closure |
599 | */ | 600 | */ |
600 | static void | 601 | static void |
601 | sqlite_plugin_put (void *cls, | 602 | sqlite_plugin_put(void *cls, |
602 | const struct GNUNET_HashCode *key, | 603 | const struct GNUNET_HashCode *key, |
603 | bool absent, | 604 | bool absent, |
604 | uint32_t size, | 605 | uint32_t size, |
605 | const void *data, | 606 | const void *data, |
606 | enum GNUNET_BLOCK_Type type, | 607 | enum GNUNET_BLOCK_Type type, |
607 | uint32_t priority, | 608 | uint32_t priority, |
608 | uint32_t anonymity, | 609 | uint32_t anonymity, |
609 | uint32_t replication, | 610 | uint32_t replication, |
610 | struct GNUNET_TIME_Absolute expiration, | 611 | struct GNUNET_TIME_Absolute expiration, |
611 | PluginPutCont cont, | 612 | PluginPutCont cont, |
612 | void *cont_cls) | 613 | void *cont_cls) |
613 | { | 614 | { |
614 | struct Plugin *plugin = cls; | 615 | struct Plugin *plugin = cls; |
615 | struct GNUNET_HashCode vhash; | 616 | struct GNUNET_HashCode vhash; |
616 | char *msg = NULL; | 617 | char *msg = NULL; |
617 | 618 | ||
618 | GNUNET_CRYPTO_hash (data, size, &vhash); | 619 | GNUNET_CRYPTO_hash(data, size, &vhash); |
619 | |||
620 | if (! absent) | ||
621 | { | ||
622 | struct GNUNET_SQ_QueryParam params[] = | ||
623 | {GNUNET_SQ_query_param_uint32 (&priority), | ||
624 | GNUNET_SQ_query_param_uint32 (&replication), | ||
625 | GNUNET_SQ_query_param_absolute_time (&expiration), | ||
626 | GNUNET_SQ_query_param_auto_from_type (key), | ||
627 | GNUNET_SQ_query_param_auto_from_type (&vhash), | ||
628 | GNUNET_SQ_query_param_end}; | ||
629 | 620 | ||
630 | if (GNUNET_OK != GNUNET_SQ_bind (plugin->update, params)) | 621 | if (!absent) |
631 | { | ||
632 | cont (cont_cls, key, size, GNUNET_SYSERR, _ ("sqlite bind failure")); | ||
633 | return; | ||
634 | } | ||
635 | if (SQLITE_DONE != sqlite3_step (plugin->update)) | ||
636 | { | ||
637 | LOG_SQLITE_MSG (plugin, | ||
638 | &msg, | ||
639 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
640 | "sqlite3_step"); | ||
641 | cont (cont_cls, key, size, GNUNET_SYSERR, msg); | ||
642 | GNUNET_free_non_null (msg); | ||
643 | return; | ||
644 | } | ||
645 | int changes = sqlite3_changes (plugin->dbh); | ||
646 | GNUNET_SQ_reset (plugin->dbh, plugin->update); | ||
647 | if (0 != changes) | ||
648 | { | 622 | { |
649 | cont (cont_cls, key, size, GNUNET_NO, NULL); | 623 | struct GNUNET_SQ_QueryParam params[] = |
650 | return; | 624 | { GNUNET_SQ_query_param_uint32(&priority), |
625 | GNUNET_SQ_query_param_uint32(&replication), | ||
626 | GNUNET_SQ_query_param_absolute_time(&expiration), | ||
627 | GNUNET_SQ_query_param_auto_from_type(key), | ||
628 | GNUNET_SQ_query_param_auto_from_type(&vhash), | ||
629 | GNUNET_SQ_query_param_end }; | ||
630 | |||
631 | if (GNUNET_OK != GNUNET_SQ_bind(plugin->update, params)) | ||
632 | { | ||
633 | cont(cont_cls, key, size, GNUNET_SYSERR, _("sqlite bind failure")); | ||
634 | return; | ||
635 | } | ||
636 | if (SQLITE_DONE != sqlite3_step(plugin->update)) | ||
637 | { | ||
638 | LOG_SQLITE_MSG(plugin, | ||
639 | &msg, | ||
640 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
641 | "sqlite3_step"); | ||
642 | cont(cont_cls, key, size, GNUNET_SYSERR, msg); | ||
643 | GNUNET_free_non_null(msg); | ||
644 | return; | ||
645 | } | ||
646 | int changes = sqlite3_changes(plugin->dbh); | ||
647 | GNUNET_SQ_reset(plugin->dbh, plugin->update); | ||
648 | if (0 != changes) | ||
649 | { | ||
650 | cont(cont_cls, key, size, GNUNET_NO, NULL); | ||
651 | return; | ||
652 | } | ||
651 | } | 653 | } |
652 | } | ||
653 | 654 | ||
654 | uint64_t rvalue; | 655 | uint64_t rvalue; |
655 | uint32_t type32 = (uint32_t) type; | 656 | uint32_t type32 = (uint32_t)type; |
656 | struct GNUNET_SQ_QueryParam params[] = | 657 | struct GNUNET_SQ_QueryParam params[] = |
657 | {GNUNET_SQ_query_param_uint32 (&replication), | 658 | { GNUNET_SQ_query_param_uint32(&replication), |
658 | GNUNET_SQ_query_param_uint32 (&type32), | 659 | GNUNET_SQ_query_param_uint32(&type32), |
659 | GNUNET_SQ_query_param_uint32 (&priority), | 660 | GNUNET_SQ_query_param_uint32(&priority), |
660 | GNUNET_SQ_query_param_uint32 (&anonymity), | 661 | GNUNET_SQ_query_param_uint32(&anonymity), |
661 | GNUNET_SQ_query_param_absolute_time (&expiration), | 662 | GNUNET_SQ_query_param_absolute_time(&expiration), |
662 | GNUNET_SQ_query_param_uint64 (&rvalue), | 663 | GNUNET_SQ_query_param_uint64(&rvalue), |
663 | GNUNET_SQ_query_param_auto_from_type (key), | 664 | GNUNET_SQ_query_param_auto_from_type(key), |
664 | GNUNET_SQ_query_param_auto_from_type (&vhash), | 665 | GNUNET_SQ_query_param_auto_from_type(&vhash), |
665 | GNUNET_SQ_query_param_fixed_size (data, size), | 666 | GNUNET_SQ_query_param_fixed_size(data, size), |
666 | GNUNET_SQ_query_param_end}; | 667 | GNUNET_SQ_query_param_end }; |
667 | int n; | 668 | int n; |
668 | int ret; | 669 | int ret; |
669 | sqlite3_stmt *stmt; | 670 | sqlite3_stmt *stmt; |
670 | 671 | ||
671 | if (size > MAX_ITEM_SIZE) | 672 | if (size > MAX_ITEM_SIZE) |
672 | { | 673 | { |
673 | cont (cont_cls, key, size, GNUNET_SYSERR, _ ("Data too large")); | 674 | cont(cont_cls, key, size, GNUNET_SYSERR, _("Data too large")); |
674 | return; | 675 | return; |
675 | } | 676 | } |
676 | GNUNET_log_from ( | 677 | GNUNET_log_from( |
677 | GNUNET_ERROR_TYPE_DEBUG, | 678 | GNUNET_ERROR_TYPE_DEBUG, |
678 | "sqlite", | 679 | "sqlite", |
679 | "Storing in database block with type %u/key `%s'/priority %u/expiration in %s (%s).\n", | 680 | "Storing in database block with type %u/key `%s'/priority %u/expiration in %s (%s).\n", |
680 | type, | 681 | type, |
681 | GNUNET_h2s (key), | 682 | GNUNET_h2s(key), |
682 | priority, | 683 | priority, |
683 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining ( | 684 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining( |
684 | expiration), | 685 | expiration), |
685 | GNUNET_YES), | 686 | GNUNET_YES), |
686 | GNUNET_STRINGS_absolute_time_to_string (expiration)); | 687 | GNUNET_STRINGS_absolute_time_to_string(expiration)); |
687 | stmt = plugin->insertContent; | 688 | stmt = plugin->insertContent; |
688 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); | 689 | rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); |
689 | if (GNUNET_OK != GNUNET_SQ_bind (stmt, params)) | 690 | if (GNUNET_OK != GNUNET_SQ_bind(stmt, params)) |
690 | { | 691 | { |
691 | cont (cont_cls, key, size, GNUNET_SYSERR, NULL); | 692 | cont(cont_cls, key, size, GNUNET_SYSERR, NULL); |
692 | return; | 693 | return; |
693 | } | 694 | } |
694 | n = sqlite3_step (stmt); | 695 | n = sqlite3_step(stmt); |
695 | switch (n) | 696 | switch (n) |
696 | { | 697 | { |
697 | case SQLITE_DONE: | 698 | case SQLITE_DONE: |
698 | if (NULL != plugin->env->duc) | 699 | if (NULL != plugin->env->duc) |
699 | plugin->env->duc (plugin->env->cls, | 700 | plugin->env->duc(plugin->env->cls, |
700 | size + GNUNET_DATASTORE_ENTRY_OVERHEAD); | 701 | size + GNUNET_DATASTORE_ENTRY_OVERHEAD); |
701 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 702 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, |
702 | "sqlite", | 703 | "sqlite", |
703 | "Stored new entry (%u bytes)\n", | 704 | "Stored new entry (%u bytes)\n", |
704 | size + GNUNET_DATASTORE_ENTRY_OVERHEAD); | 705 | size + GNUNET_DATASTORE_ENTRY_OVERHEAD); |
705 | ret = GNUNET_OK; | 706 | ret = GNUNET_OK; |
706 | break; | 707 | break; |
707 | case SQLITE_BUSY: | 708 | |
708 | GNUNET_break (0); | 709 | case SQLITE_BUSY: |
709 | LOG_SQLITE_MSG (plugin, | 710 | GNUNET_break(0); |
710 | &msg, | 711 | LOG_SQLITE_MSG(plugin, |
711 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 712 | &msg, |
712 | "sqlite3_step"); | 713 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
713 | ret = GNUNET_SYSERR; | 714 | "sqlite3_step"); |
714 | break; | 715 | ret = GNUNET_SYSERR; |
715 | default: | 716 | break; |
716 | LOG_SQLITE_MSG (plugin, | 717 | |
717 | &msg, | 718 | default: |
718 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 719 | LOG_SQLITE_MSG(plugin, |
719 | "sqlite3_step"); | 720 | &msg, |
720 | GNUNET_SQ_reset (plugin->dbh, stmt); | 721 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
721 | database_shutdown (plugin); | 722 | "sqlite3_step"); |
722 | database_setup (plugin->env->cfg, plugin); | 723 | GNUNET_SQ_reset(plugin->dbh, stmt); |
723 | cont (cont_cls, key, size, GNUNET_SYSERR, msg); | 724 | database_shutdown(plugin); |
724 | GNUNET_free_non_null (msg); | 725 | database_setup(plugin->env->cfg, plugin); |
725 | return; | 726 | cont(cont_cls, key, size, GNUNET_SYSERR, msg); |
726 | } | 727 | GNUNET_free_non_null(msg); |
727 | GNUNET_SQ_reset (plugin->dbh, stmt); | 728 | return; |
728 | cont (cont_cls, key, size, ret, msg); | 729 | } |
729 | GNUNET_free_non_null (msg); | 730 | GNUNET_SQ_reset(plugin->dbh, stmt); |
731 | cont(cont_cls, key, size, ret, msg); | ||
732 | GNUNET_free_non_null(msg); | ||
730 | } | 733 | } |
731 | 734 | ||
732 | 735 | ||
@@ -740,10 +743,10 @@ sqlite_plugin_put (void *cls, | |||
740 | * @param proc_cls closure for @a proc | 743 | * @param proc_cls closure for @a proc |
741 | */ | 744 | */ |
742 | static void | 745 | static void |
743 | execute_get (struct Plugin *plugin, | 746 | execute_get(struct Plugin *plugin, |
744 | sqlite3_stmt *stmt, | 747 | sqlite3_stmt *stmt, |
745 | PluginDatumProcessor proc, | 748 | PluginDatumProcessor proc, |
746 | void *proc_cls) | 749 | void *proc_cls) |
747 | { | 750 | { |
748 | int n; | 751 | int n; |
749 | struct GNUNET_TIME_Absolute expiration; | 752 | struct GNUNET_TIME_Absolute expiration; |
@@ -757,68 +760,70 @@ execute_get (struct Plugin *plugin, | |||
757 | struct GNUNET_HashCode key; | 760 | struct GNUNET_HashCode key; |
758 | int ret; | 761 | int ret; |
759 | struct GNUNET_SQ_ResultSpec rs[] = | 762 | struct GNUNET_SQ_ResultSpec rs[] = |
760 | {GNUNET_SQ_result_spec_uint32 (&replication), | 763 | { GNUNET_SQ_result_spec_uint32(&replication), |
761 | GNUNET_SQ_result_spec_uint32 (&type), | 764 | GNUNET_SQ_result_spec_uint32(&type), |
762 | GNUNET_SQ_result_spec_uint32 (&priority), | 765 | GNUNET_SQ_result_spec_uint32(&priority), |
763 | GNUNET_SQ_result_spec_uint32 (&anonymity), | 766 | GNUNET_SQ_result_spec_uint32(&anonymity), |
764 | GNUNET_SQ_result_spec_absolute_time (&expiration), | 767 | GNUNET_SQ_result_spec_absolute_time(&expiration), |
765 | GNUNET_SQ_result_spec_auto_from_type (&key), | 768 | GNUNET_SQ_result_spec_auto_from_type(&key), |
766 | GNUNET_SQ_result_spec_variable_size (&value, &value_size), | 769 | GNUNET_SQ_result_spec_variable_size(&value, &value_size), |
767 | GNUNET_SQ_result_spec_uint64 (&rowid), | 770 | GNUNET_SQ_result_spec_uint64(&rowid), |
768 | GNUNET_SQ_result_spec_end}; | 771 | GNUNET_SQ_result_spec_end }; |
769 | 772 | ||
770 | n = sqlite3_step (stmt); | 773 | n = sqlite3_step(stmt); |
771 | switch (n) | 774 | switch (n) |
772 | { | ||
773 | case SQLITE_ROW: | ||
774 | if (GNUNET_OK != GNUNET_SQ_extract_result (stmt, rs)) | ||
775 | { | 775 | { |
776 | GNUNET_break (0); | 776 | case SQLITE_ROW: |
777 | if (GNUNET_OK != GNUNET_SQ_extract_result(stmt, rs)) | ||
778 | { | ||
779 | GNUNET_break(0); | ||
780 | break; | ||
781 | } | ||
782 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, | ||
783 | "sqlite", | ||
784 | "Found reply in database with expiration %s\n", | ||
785 | GNUNET_STRINGS_absolute_time_to_string(expiration)); | ||
786 | ret = proc(proc_cls, | ||
787 | &key, | ||
788 | value_size, | ||
789 | value, | ||
790 | type, | ||
791 | priority, | ||
792 | anonymity, | ||
793 | replication, | ||
794 | expiration, | ||
795 | rowid); | ||
796 | GNUNET_SQ_cleanup_result(rs); | ||
797 | GNUNET_SQ_reset(plugin->dbh, stmt); | ||
798 | if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid(plugin, rowid)) && | ||
799 | (NULL != plugin->env->duc)) | ||
800 | plugin->env->duc(plugin->env->cls, | ||
801 | -(value_size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); | ||
802 | return; | ||
803 | |||
804 | case SQLITE_DONE: | ||
805 | /* database must be empty */ | ||
777 | break; | 806 | break; |
807 | |||
808 | case SQLITE_BUSY: | ||
809 | case SQLITE_ERROR: | ||
810 | case SQLITE_MISUSE: | ||
811 | default: | ||
812 | LOG_SQLITE(plugin, | ||
813 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
814 | "sqlite3_step"); | ||
815 | if (SQLITE_OK != sqlite3_reset(stmt)) | ||
816 | LOG_SQLITE(plugin, | ||
817 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
818 | "sqlite3_reset"); | ||
819 | GNUNET_break(0); | ||
820 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | ||
821 | database_shutdown(plugin); | ||
822 | database_setup(plugin->env->cfg, plugin); | ||
823 | return; | ||
778 | } | 824 | } |
779 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 825 | GNUNET_SQ_reset(plugin->dbh, stmt); |
780 | "sqlite", | 826 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
781 | "Found reply in database with expiration %s\n", | ||
782 | GNUNET_STRINGS_absolute_time_to_string (expiration)); | ||
783 | ret = proc (proc_cls, | ||
784 | &key, | ||
785 | value_size, | ||
786 | value, | ||
787 | type, | ||
788 | priority, | ||
789 | anonymity, | ||
790 | replication, | ||
791 | expiration, | ||
792 | rowid); | ||
793 | GNUNET_SQ_cleanup_result (rs); | ||
794 | GNUNET_SQ_reset (plugin->dbh, stmt); | ||
795 | if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid)) && | ||
796 | (NULL != plugin->env->duc)) | ||
797 | plugin->env->duc (plugin->env->cls, | ||
798 | -(value_size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); | ||
799 | return; | ||
800 | case SQLITE_DONE: | ||
801 | /* database must be empty */ | ||
802 | break; | ||
803 | case SQLITE_BUSY: | ||
804 | case SQLITE_ERROR: | ||
805 | case SQLITE_MISUSE: | ||
806 | default: | ||
807 | LOG_SQLITE (plugin, | ||
808 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
809 | "sqlite3_step"); | ||
810 | if (SQLITE_OK != sqlite3_reset (stmt)) | ||
811 | LOG_SQLITE (plugin, | ||
812 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
813 | "sqlite3_reset"); | ||
814 | GNUNET_break (0); | ||
815 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | ||
816 | database_shutdown (plugin); | ||
817 | database_setup (plugin->env->cfg, plugin); | ||
818 | return; | ||
819 | } | ||
820 | GNUNET_SQ_reset (plugin->dbh, stmt); | ||
821 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | ||
822 | } | 827 | } |
823 | 828 | ||
824 | 829 | ||
@@ -835,27 +840,27 @@ execute_get (struct Plugin *plugin, | |||
835 | * @param proc_cls closure for @a proc | 840 | * @param proc_cls closure for @a proc |
836 | */ | 841 | */ |
837 | static void | 842 | static void |
838 | sqlite_plugin_get_zero_anonymity (void *cls, | 843 | sqlite_plugin_get_zero_anonymity(void *cls, |
839 | uint64_t next_uid, | 844 | uint64_t next_uid, |
840 | enum GNUNET_BLOCK_Type type, | 845 | enum GNUNET_BLOCK_Type type, |
841 | PluginDatumProcessor proc, | 846 | PluginDatumProcessor proc, |
842 | void *proc_cls) | 847 | void *proc_cls) |
843 | { | 848 | { |
844 | struct Plugin *plugin = cls; | 849 | struct Plugin *plugin = cls; |
845 | uint32_t type32 = type; | 850 | uint32_t type32 = type; |
846 | struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_uint64 ( | 851 | struct GNUNET_SQ_QueryParam params[] = { GNUNET_SQ_query_param_uint64( |
847 | &next_uid), | 852 | &next_uid), |
848 | GNUNET_SQ_query_param_uint32 ( | 853 | GNUNET_SQ_query_param_uint32( |
849 | &type32), | 854 | &type32), |
850 | GNUNET_SQ_query_param_end}; | 855 | GNUNET_SQ_query_param_end }; |
851 | 856 | ||
852 | GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY); | 857 | GNUNET_assert(type != GNUNET_BLOCK_TYPE_ANY); |
853 | if (GNUNET_OK != GNUNET_SQ_bind (plugin->selZeroAnon, params)) | 858 | if (GNUNET_OK != GNUNET_SQ_bind(plugin->selZeroAnon, params)) |
854 | { | 859 | { |
855 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 860 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
856 | return; | 861 | return; |
857 | } | 862 | } |
858 | execute_get (plugin, plugin->selZeroAnon, proc, proc_cls); | 863 | execute_get(plugin, plugin->selZeroAnon, proc, proc_cls); |
859 | } | 864 | } |
860 | 865 | ||
861 | 866 | ||
@@ -873,64 +878,62 @@ sqlite_plugin_get_zero_anonymity (void *cls, | |||
873 | * @param proc_cls closure for @a proc | 878 | * @param proc_cls closure for @a proc |
874 | */ | 879 | */ |
875 | static void | 880 | static void |
876 | sqlite_plugin_get_key (void *cls, | 881 | sqlite_plugin_get_key(void *cls, |
877 | uint64_t next_uid, | 882 | uint64_t next_uid, |
878 | bool random, | 883 | bool random, |
879 | const struct GNUNET_HashCode *key, | 884 | const struct GNUNET_HashCode *key, |
880 | enum GNUNET_BLOCK_Type type, | 885 | enum GNUNET_BLOCK_Type type, |
881 | PluginDatumProcessor proc, | 886 | PluginDatumProcessor proc, |
882 | void *proc_cls) | 887 | void *proc_cls) |
883 | { | 888 | { |
884 | struct Plugin *plugin = cls; | 889 | struct Plugin *plugin = cls; |
885 | uint64_t rvalue; | 890 | uint64_t rvalue; |
886 | int use_rvalue = random; | 891 | int use_rvalue = random; |
887 | uint32_t type32 = (uint32_t) type; | 892 | uint32_t type32 = (uint32_t)type; |
888 | int use_type = GNUNET_BLOCK_TYPE_ANY != type; | 893 | int use_type = GNUNET_BLOCK_TYPE_ANY != type; |
889 | int use_key = NULL != key; | 894 | int use_key = NULL != key; |
890 | sqlite3_stmt *stmt = plugin->get[use_rvalue * 4 + use_key * 2 + use_type]; | 895 | sqlite3_stmt *stmt = plugin->get[use_rvalue * 4 + use_key * 2 + use_type]; |
891 | struct GNUNET_SQ_QueryParam params[] = | 896 | struct GNUNET_SQ_QueryParam params[] = |
892 | {GNUNET_SQ_query_param_uint64 (&next_uid), | 897 | { GNUNET_SQ_query_param_uint64(&next_uid), |
893 | GNUNET_SQ_query_param_uint64 (&rvalue), | 898 | GNUNET_SQ_query_param_uint64(&rvalue), |
894 | GNUNET_SQ_query_param_auto_from_type (key), | 899 | GNUNET_SQ_query_param_auto_from_type(key), |
895 | GNUNET_SQ_query_param_uint32 (&type32), | 900 | GNUNET_SQ_query_param_uint32(&type32), |
896 | GNUNET_SQ_query_param_end}; | 901 | GNUNET_SQ_query_param_end }; |
897 | 902 | ||
898 | /* SQLite doesn't like it when you try to bind a parameter greater than the | 903 | /* SQLite doesn't like it when you try to bind a parameter greater than the |
899 | * last numbered parameter, but unused parameters in the middle are OK. | 904 | * last numbered parameter, but unused parameters in the middle are OK. |
900 | */ | 905 | */ |
901 | if (! use_type) | 906 | if (!use_type) |
902 | { | ||
903 | params[3] = (struct GNUNET_SQ_QueryParam) GNUNET_SQ_query_param_end; | ||
904 | if (! use_key) | ||
905 | { | 907 | { |
906 | params[2] = (struct GNUNET_SQ_QueryParam) GNUNET_SQ_query_param_end; | 908 | params[3] = (struct GNUNET_SQ_QueryParam)GNUNET_SQ_query_param_end; |
907 | if (! use_rvalue) | 909 | if (!use_key) |
908 | params[1] = (struct GNUNET_SQ_QueryParam) GNUNET_SQ_query_param_end; | 910 | { |
911 | params[2] = (struct GNUNET_SQ_QueryParam)GNUNET_SQ_query_param_end; | ||
912 | if (!use_rvalue) | ||
913 | params[1] = (struct GNUNET_SQ_QueryParam)GNUNET_SQ_query_param_end; | ||
914 | } | ||
909 | } | 915 | } |
910 | } | ||
911 | if (random) | 916 | if (random) |
912 | { | 917 | { |
913 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); | 918 | rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); |
914 | next_uid = 0; | 919 | next_uid = 0; |
915 | } | 920 | } |
916 | else | 921 | else |
917 | rvalue = 0; | 922 | rvalue = 0; |
918 | 923 | ||
919 | if (GNUNET_OK != GNUNET_SQ_bind (stmt, params)) | 924 | if (GNUNET_OK != GNUNET_SQ_bind(stmt, params)) |
920 | { | 925 | { |
921 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 926 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
922 | return; | 927 | return; |
923 | } | 928 | } |
924 | execute_get (plugin, stmt, proc, proc_cls); | 929 | execute_get(plugin, stmt, proc, proc_cls); |
925 | } | 930 | } |
926 | 931 | ||
927 | 932 | ||
928 | /** | 933 | /** |
929 | * Context for #repl_proc() function. | 934 | * Context for #repl_proc() function. |
930 | */ | 935 | */ |
931 | struct ReplCtx | 936 | struct ReplCtx { |
932 | { | ||
933 | |||
934 | /** | 937 | /** |
935 | * Function to call for the result (or the NULL). | 938 | * Function to call for the result (or the NULL). |
936 | */ | 939 | */ |
@@ -973,37 +976,37 @@ struct ReplCtx | |||
973 | * #GNUNET_NO to delete the item | 976 | * #GNUNET_NO to delete the item |
974 | */ | 977 | */ |
975 | static int | 978 | static int |
976 | repl_proc (void *cls, | 979 | repl_proc(void *cls, |
977 | const struct GNUNET_HashCode *key, | 980 | const struct GNUNET_HashCode *key, |
978 | uint32_t size, | 981 | uint32_t size, |
979 | const void *data, | 982 | const void *data, |
980 | enum GNUNET_BLOCK_Type type, | 983 | enum GNUNET_BLOCK_Type type, |
981 | uint32_t priority, | 984 | uint32_t priority, |
982 | uint32_t anonymity, | 985 | uint32_t anonymity, |
983 | uint32_t replication, | 986 | uint32_t replication, |
984 | struct GNUNET_TIME_Absolute expiration, | 987 | struct GNUNET_TIME_Absolute expiration, |
985 | uint64_t uid) | 988 | uint64_t uid) |
986 | { | 989 | { |
987 | struct ReplCtx *rc = cls; | 990 | struct ReplCtx *rc = cls; |
988 | int ret; | 991 | int ret; |
989 | 992 | ||
990 | if (GNUNET_SYSERR == rc->have_uid) | 993 | if (GNUNET_SYSERR == rc->have_uid) |
991 | rc->have_uid = GNUNET_NO; | 994 | rc->have_uid = GNUNET_NO; |
992 | ret = rc->proc (rc->proc_cls, | 995 | ret = rc->proc(rc->proc_cls, |
993 | key, | 996 | key, |
994 | size, | 997 | size, |
995 | data, | 998 | data, |
996 | type, | 999 | type, |
997 | priority, | 1000 | priority, |
998 | anonymity, | 1001 | anonymity, |
999 | replication, | 1002 | replication, |
1000 | expiration, | 1003 | expiration, |
1001 | uid); | 1004 | uid); |
1002 | if (NULL != key) | 1005 | if (NULL != key) |
1003 | { | 1006 | { |
1004 | rc->uid = uid; | 1007 | rc->uid = uid; |
1005 | rc->have_uid = GNUNET_YES; | 1008 | rc->have_uid = GNUNET_YES; |
1006 | } | 1009 | } |
1007 | return ret; | 1010 | return ret; |
1008 | } | 1011 | } |
1009 | 1012 | ||
@@ -1019,61 +1022,61 @@ repl_proc (void *cls, | |||
1019 | * @param proc_cls closure for @a proc | 1022 | * @param proc_cls closure for @a proc |
1020 | */ | 1023 | */ |
1021 | static void | 1024 | static void |
1022 | sqlite_plugin_get_replication (void *cls, | 1025 | sqlite_plugin_get_replication(void *cls, |
1023 | PluginDatumProcessor proc, | 1026 | PluginDatumProcessor proc, |
1024 | void *proc_cls) | 1027 | void *proc_cls) |
1025 | { | 1028 | { |
1026 | struct Plugin *plugin = cls; | 1029 | struct Plugin *plugin = cls; |
1027 | struct ReplCtx rc; | 1030 | struct ReplCtx rc; |
1028 | uint64_t rvalue; | 1031 | uint64_t rvalue; |
1029 | uint32_t repl; | 1032 | uint32_t repl; |
1030 | struct GNUNET_SQ_QueryParam params_sel_repl[] = | 1033 | struct GNUNET_SQ_QueryParam params_sel_repl[] = |
1031 | {GNUNET_SQ_query_param_uint64 (&rvalue), | 1034 | { GNUNET_SQ_query_param_uint64(&rvalue), |
1032 | GNUNET_SQ_query_param_uint32 (&repl), | 1035 | GNUNET_SQ_query_param_uint32(&repl), |
1033 | GNUNET_SQ_query_param_end}; | 1036 | GNUNET_SQ_query_param_end }; |
1034 | struct GNUNET_SQ_QueryParam params_upd_repl[] = | 1037 | struct GNUNET_SQ_QueryParam params_upd_repl[] = |
1035 | {GNUNET_SQ_query_param_uint64 (&rc.uid), GNUNET_SQ_query_param_end}; | 1038 | { GNUNET_SQ_query_param_uint64(&rc.uid), GNUNET_SQ_query_param_end }; |
1036 | 1039 | ||
1037 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1040 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, |
1038 | "datastore-sqlite", | 1041 | "datastore-sqlite", |
1039 | "Getting random block based on replication order.\n"); | 1042 | "Getting random block based on replication order.\n"); |
1040 | if (SQLITE_ROW != sqlite3_step (plugin->maxRepl)) | 1043 | if (SQLITE_ROW != sqlite3_step(plugin->maxRepl)) |
1041 | { | 1044 | { |
1042 | GNUNET_SQ_reset (plugin->dbh, plugin->maxRepl); | 1045 | GNUNET_SQ_reset(plugin->dbh, plugin->maxRepl); |
1043 | /* DB empty */ | 1046 | /* DB empty */ |
1044 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1047 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
1045 | return; | 1048 | return; |
1046 | } | 1049 | } |
1047 | repl = sqlite3_column_int (plugin->maxRepl, 0); | 1050 | repl = sqlite3_column_int(plugin->maxRepl, 0); |
1048 | GNUNET_SQ_reset (plugin->dbh, plugin->maxRepl); | 1051 | GNUNET_SQ_reset(plugin->dbh, plugin->maxRepl); |
1049 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); | 1052 | rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); |
1050 | if (GNUNET_OK != GNUNET_SQ_bind (plugin->selRepl, params_sel_repl)) | 1053 | if (GNUNET_OK != GNUNET_SQ_bind(plugin->selRepl, params_sel_repl)) |
1051 | { | 1054 | { |
1052 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1055 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
1053 | return; | 1056 | return; |
1054 | } | 1057 | } |
1055 | rc.have_uid = GNUNET_SYSERR; | 1058 | rc.have_uid = GNUNET_SYSERR; |
1056 | rc.proc = proc; | 1059 | rc.proc = proc; |
1057 | rc.proc_cls = proc_cls; | 1060 | rc.proc_cls = proc_cls; |
1058 | execute_get (plugin, plugin->selRepl, &repl_proc, &rc); | 1061 | execute_get(plugin, plugin->selRepl, &repl_proc, &rc); |
1059 | if (GNUNET_YES == rc.have_uid) | 1062 | if (GNUNET_YES == rc.have_uid) |
1060 | { | ||
1061 | if (GNUNET_OK != GNUNET_SQ_bind (plugin->updRepl, params_upd_repl)) | ||
1062 | { | 1063 | { |
1063 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1064 | if (GNUNET_OK != GNUNET_SQ_bind(plugin->updRepl, params_upd_repl)) |
1064 | return; | 1065 | { |
1066 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | ||
1067 | return; | ||
1068 | } | ||
1069 | if (SQLITE_DONE != sqlite3_step(plugin->updRepl)) | ||
1070 | LOG_SQLITE(plugin, | ||
1071 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1072 | "sqlite3_step"); | ||
1073 | GNUNET_SQ_reset(plugin->dbh, plugin->updRepl); | ||
1065 | } | 1074 | } |
1066 | if (SQLITE_DONE != sqlite3_step (plugin->updRepl)) | ||
1067 | LOG_SQLITE (plugin, | ||
1068 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1069 | "sqlite3_step"); | ||
1070 | GNUNET_SQ_reset (plugin->dbh, plugin->updRepl); | ||
1071 | } | ||
1072 | if (GNUNET_SYSERR == rc.have_uid) | 1075 | if (GNUNET_SYSERR == rc.have_uid) |
1073 | { | 1076 | { |
1074 | /* proc was not called at all so far, do it now. */ | 1077 | /* proc was not called at all so far, do it now. */ |
1075 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1078 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
1076 | } | 1079 | } |
1077 | } | 1080 | } |
1078 | 1081 | ||
1079 | 1082 | ||
@@ -1086,29 +1089,29 @@ sqlite_plugin_get_replication (void *cls, | |||
1086 | * @param proc_cls closure for @a proc | 1089 | * @param proc_cls closure for @a proc |
1087 | */ | 1090 | */ |
1088 | static void | 1091 | static void |
1089 | sqlite_plugin_get_expiration (void *cls, | 1092 | sqlite_plugin_get_expiration(void *cls, |
1090 | PluginDatumProcessor proc, | 1093 | PluginDatumProcessor proc, |
1091 | void *proc_cls) | 1094 | void *proc_cls) |
1092 | { | 1095 | { |
1093 | struct Plugin *plugin = cls; | 1096 | struct Plugin *plugin = cls; |
1094 | sqlite3_stmt *stmt; | 1097 | sqlite3_stmt *stmt; |
1095 | struct GNUNET_TIME_Absolute now; | 1098 | struct GNUNET_TIME_Absolute now; |
1096 | struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_absolute_time ( | 1099 | struct GNUNET_SQ_QueryParam params[] = { GNUNET_SQ_query_param_absolute_time( |
1097 | &now), | 1100 | &now), |
1098 | GNUNET_SQ_query_param_end}; | 1101 | GNUNET_SQ_query_param_end }; |
1099 | 1102 | ||
1100 | GNUNET_log_from ( | 1103 | GNUNET_log_from( |
1101 | GNUNET_ERROR_TYPE_DEBUG, | 1104 | GNUNET_ERROR_TYPE_DEBUG, |
1102 | "sqlite", | 1105 | "sqlite", |
1103 | "Getting random block based on expiration and priority order.\n"); | 1106 | "Getting random block based on expiration and priority order.\n"); |
1104 | now = GNUNET_TIME_absolute_get (); | 1107 | now = GNUNET_TIME_absolute_get(); |
1105 | stmt = plugin->selExpi; | 1108 | stmt = plugin->selExpi; |
1106 | if (GNUNET_OK != GNUNET_SQ_bind (stmt, params)) | 1109 | if (GNUNET_OK != GNUNET_SQ_bind(stmt, params)) |
1107 | { | 1110 | { |
1108 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1111 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
1109 | return; | 1112 | return; |
1110 | } | 1113 | } |
1111 | execute_get (plugin, stmt, proc, proc_cls); | 1114 | execute_get(plugin, stmt, proc, proc_cls); |
1112 | } | 1115 | } |
1113 | 1116 | ||
1114 | 1117 | ||
@@ -1120,35 +1123,35 @@ sqlite_plugin_get_expiration (void *cls, | |||
1120 | * @param proc_cls closure for @a proc | 1123 | * @param proc_cls closure for @a proc |
1121 | */ | 1124 | */ |
1122 | static void | 1125 | static void |
1123 | sqlite_plugin_get_keys (void *cls, PluginKeyProcessor proc, void *proc_cls) | 1126 | sqlite_plugin_get_keys(void *cls, PluginKeyProcessor proc, void *proc_cls) |
1124 | { | 1127 | { |
1125 | struct Plugin *plugin = cls; | 1128 | struct Plugin *plugin = cls; |
1126 | struct GNUNET_HashCode key; | 1129 | struct GNUNET_HashCode key; |
1127 | struct GNUNET_SQ_ResultSpec results[] = | 1130 | struct GNUNET_SQ_ResultSpec results[] = |
1128 | {GNUNET_SQ_result_spec_auto_from_type (&key), GNUNET_SQ_result_spec_end}; | 1131 | { GNUNET_SQ_result_spec_auto_from_type(&key), GNUNET_SQ_result_spec_end }; |
1129 | sqlite3_stmt *stmt; | 1132 | sqlite3_stmt *stmt; |
1130 | int ret; | 1133 | int ret; |
1131 | 1134 | ||
1132 | GNUNET_assert (NULL != proc); | 1135 | GNUNET_assert(NULL != proc); |
1133 | if (SQLITE_OK != sq_prepare (plugin->dbh, "SELECT hash FROM gn091", &stmt)) | 1136 | if (SQLITE_OK != sq_prepare(plugin->dbh, "SELECT hash FROM gn091", &stmt)) |
1134 | { | 1137 | { |
1135 | LOG_SQLITE (plugin, | 1138 | LOG_SQLITE(plugin, |
1136 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1139 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1137 | "sqlite_prepare"); | 1140 | "sqlite_prepare"); |
1138 | proc (proc_cls, NULL, 0); | 1141 | proc(proc_cls, NULL, 0); |
1139 | return; | 1142 | return; |
1140 | } | 1143 | } |
1141 | while (SQLITE_ROW == (ret = sqlite3_step (stmt))) | 1144 | while (SQLITE_ROW == (ret = sqlite3_step(stmt))) |
1142 | { | 1145 | { |
1143 | if (GNUNET_OK == GNUNET_SQ_extract_result (stmt, results)) | 1146 | if (GNUNET_OK == GNUNET_SQ_extract_result(stmt, results)) |
1144 | proc (proc_cls, &key, 1); | 1147 | proc(proc_cls, &key, 1); |
1145 | else | 1148 | else |
1146 | GNUNET_break (0); | 1149 | GNUNET_break(0); |
1147 | } | 1150 | } |
1148 | if (SQLITE_DONE != ret) | 1151 | if (SQLITE_DONE != ret) |
1149 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step"); | 1152 | LOG_SQLITE(plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step"); |
1150 | sqlite3_finalize (stmt); | 1153 | sqlite3_finalize(stmt); |
1151 | proc (proc_cls, NULL, 0); | 1154 | proc(proc_cls, NULL, 0); |
1152 | } | 1155 | } |
1153 | 1156 | ||
1154 | 1157 | ||
@@ -1158,7 +1161,7 @@ sqlite_plugin_get_keys (void *cls, PluginKeyProcessor proc, void *proc_cls) | |||
1158 | * @param cls our plugin context | 1161 | * @param cls our plugin context |
1159 | */ | 1162 | */ |
1160 | static void | 1163 | static void |
1161 | sqlite_plugin_drop (void *cls) | 1164 | sqlite_plugin_drop(void *cls) |
1162 | { | 1165 | { |
1163 | struct Plugin *plugin = cls; | 1166 | struct Plugin *plugin = cls; |
1164 | 1167 | ||
@@ -1177,44 +1180,44 @@ sqlite_plugin_drop (void *cls) | |||
1177 | * @param cont_cls continuation closure for @a cont | 1180 | * @param cont_cls continuation closure for @a cont |
1178 | */ | 1181 | */ |
1179 | static void | 1182 | static void |
1180 | sqlite_plugin_remove_key (void *cls, | 1183 | sqlite_plugin_remove_key(void *cls, |
1181 | const struct GNUNET_HashCode *key, | 1184 | const struct GNUNET_HashCode *key, |
1182 | uint32_t size, | 1185 | uint32_t size, |
1183 | const void *data, | 1186 | const void *data, |
1184 | PluginRemoveCont cont, | 1187 | PluginRemoveCont cont, |
1185 | void *cont_cls) | 1188 | void *cont_cls) |
1186 | { | 1189 | { |
1187 | struct Plugin *plugin = cls; | 1190 | struct Plugin *plugin = cls; |
1188 | struct GNUNET_SQ_QueryParam params[] = | 1191 | struct GNUNET_SQ_QueryParam params[] = |
1189 | {GNUNET_SQ_query_param_auto_from_type (key), | 1192 | { GNUNET_SQ_query_param_auto_from_type(key), |
1190 | GNUNET_SQ_query_param_fixed_size (data, size), | 1193 | GNUNET_SQ_query_param_fixed_size(data, size), |
1191 | GNUNET_SQ_query_param_end}; | 1194 | GNUNET_SQ_query_param_end }; |
1192 | 1195 | ||
1193 | if (GNUNET_OK != GNUNET_SQ_bind (plugin->remove, params)) | 1196 | if (GNUNET_OK != GNUNET_SQ_bind(plugin->remove, params)) |
1194 | { | 1197 | { |
1195 | cont (cont_cls, key, size, GNUNET_SYSERR, "bind failed"); | 1198 | cont(cont_cls, key, size, GNUNET_SYSERR, "bind failed"); |
1196 | return; | 1199 | return; |
1197 | } | 1200 | } |
1198 | if (SQLITE_DONE != sqlite3_step (plugin->remove)) | 1201 | if (SQLITE_DONE != sqlite3_step(plugin->remove)) |
1199 | { | 1202 | { |
1200 | LOG_SQLITE (plugin, | 1203 | LOG_SQLITE(plugin, |
1201 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1204 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1202 | "sqlite3_step"); | 1205 | "sqlite3_step"); |
1203 | GNUNET_SQ_reset (plugin->dbh, plugin->remove); | 1206 | GNUNET_SQ_reset(plugin->dbh, plugin->remove); |
1204 | cont (cont_cls, key, size, GNUNET_SYSERR, "sqlite3_step failed"); | 1207 | cont(cont_cls, key, size, GNUNET_SYSERR, "sqlite3_step failed"); |
1205 | return; | 1208 | return; |
1206 | } | 1209 | } |
1207 | int changes = sqlite3_changes (plugin->dbh); | 1210 | int changes = sqlite3_changes(plugin->dbh); |
1208 | GNUNET_SQ_reset (plugin->dbh, plugin->remove); | 1211 | GNUNET_SQ_reset(plugin->dbh, plugin->remove); |
1209 | if (0 == changes) | 1212 | if (0 == changes) |
1210 | { | 1213 | { |
1211 | cont (cont_cls, key, size, GNUNET_NO, NULL); | 1214 | cont(cont_cls, key, size, GNUNET_NO, NULL); |
1212 | return; | 1215 | return; |
1213 | } | 1216 | } |
1214 | if (NULL != plugin->env->duc) | 1217 | if (NULL != plugin->env->duc) |
1215 | plugin->env->duc (plugin->env->cls, | 1218 | plugin->env->duc(plugin->env->cls, |
1216 | -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); | 1219 | -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); |
1217 | cont (cont_cls, key, size, GNUNET_OK, NULL); | 1220 | cont(cont_cls, key, size, GNUNET_OK, NULL); |
1218 | } | 1221 | } |
1219 | 1222 | ||
1220 | 1223 | ||
@@ -1226,7 +1229,7 @@ sqlite_plugin_remove_key (void *cls, | |||
1226 | * @return the size of the database on disk (estimate) | 1229 | * @return the size of the database on disk (estimate) |
1227 | */ | 1230 | */ |
1228 | static void | 1231 | static void |
1229 | sqlite_plugin_estimate_size (void *cls, unsigned long long *estimate) | 1232 | sqlite_plugin_estimate_size(void *cls, unsigned long long *estimate) |
1230 | { | 1233 | { |
1231 | struct Plugin *plugin = cls; | 1234 | struct Plugin *plugin = cls; |
1232 | sqlite3_stmt *stmt; | 1235 | sqlite3_stmt *stmt; |
@@ -1240,36 +1243,36 @@ sqlite_plugin_estimate_size (void *cls, unsigned long long *estimate) | |||
1240 | if (NULL == estimate) | 1243 | if (NULL == estimate) |
1241 | return; | 1244 | return; |
1242 | if (SQLITE_VERSION_NUMBER < 3006000) | 1245 | if (SQLITE_VERSION_NUMBER < 3006000) |
1243 | { | 1246 | { |
1244 | GNUNET_log_from ( | 1247 | GNUNET_log_from( |
1245 | GNUNET_ERROR_TYPE_WARNING, | 1248 | GNUNET_ERROR_TYPE_WARNING, |
1246 | "datastore-sqlite", | 1249 | "datastore-sqlite", |
1247 | _ ("sqlite version to old to determine size, assuming zero\n")); | 1250 | _("sqlite version to old to determine size, assuming zero\n")); |
1248 | *estimate = 0; | 1251 | *estimate = 0; |
1249 | return; | 1252 | return; |
1250 | } | 1253 | } |
1251 | CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL)); | 1254 | CHECK(SQLITE_OK == sqlite3_exec(plugin->dbh, "VACUUM", NULL, NULL, ENULL)); |
1252 | CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, | 1255 | CHECK(SQLITE_OK == sqlite3_exec(plugin->dbh, |
1253 | "PRAGMA auto_vacuum=INCREMENTAL", | 1256 | "PRAGMA auto_vacuum=INCREMENTAL", |
1254 | NULL, | 1257 | NULL, |
1255 | NULL, | 1258 | NULL, |
1256 | ENULL)); | 1259 | ENULL)); |
1257 | CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_count", &stmt)); | 1260 | CHECK(SQLITE_OK == sq_prepare(plugin->dbh, "PRAGMA page_count", &stmt)); |
1258 | if (SQLITE_ROW == sqlite3_step (stmt)) | 1261 | if (SQLITE_ROW == sqlite3_step(stmt)) |
1259 | pages = sqlite3_column_int64 (stmt, 0); | 1262 | pages = sqlite3_column_int64(stmt, 0); |
1260 | else | 1263 | else |
1261 | pages = 0; | 1264 | pages = 0; |
1262 | sqlite3_finalize (stmt); | 1265 | sqlite3_finalize(stmt); |
1263 | CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_size", &stmt)); | 1266 | CHECK(SQLITE_OK == sq_prepare(plugin->dbh, "PRAGMA page_size", &stmt)); |
1264 | CHECK (SQLITE_ROW == sqlite3_step (stmt)); | 1267 | CHECK(SQLITE_ROW == sqlite3_step(stmt)); |
1265 | page_size = sqlite3_column_int64 (stmt, 0); | 1268 | page_size = sqlite3_column_int64(stmt, 0); |
1266 | sqlite3_finalize (stmt); | 1269 | sqlite3_finalize(stmt); |
1267 | GNUNET_log ( | 1270 | GNUNET_log( |
1268 | GNUNET_ERROR_TYPE_INFO, | 1271 | GNUNET_ERROR_TYPE_INFO, |
1269 | _ ( | 1272 | _( |
1270 | "Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"), | 1273 | "Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"), |
1271 | (unsigned long long) pages, | 1274 | (unsigned long long)pages, |
1272 | (unsigned long long) page_size); | 1275 | (unsigned long long)page_size); |
1273 | *estimate = pages * page_size; | 1276 | *estimate = pages * page_size; |
1274 | } | 1277 | } |
1275 | 1278 | ||
@@ -1281,7 +1284,7 @@ sqlite_plugin_estimate_size (void *cls, unsigned long long *estimate) | |||
1281 | * @return NULL on error, othrewise the plugin context | 1284 | * @return NULL on error, othrewise the plugin context |
1282 | */ | 1285 | */ |
1283 | void * | 1286 | void * |
1284 | libgnunet_plugin_datastore_sqlite_init (void *cls) | 1287 | libgnunet_plugin_datastore_sqlite_init(void *cls) |
1285 | { | 1288 | { |
1286 | static struct Plugin plugin; | 1289 | static struct Plugin plugin; |
1287 | struct GNUNET_DATASTORE_PluginEnvironment *env = cls; | 1290 | struct GNUNET_DATASTORE_PluginEnvironment *env = cls; |
@@ -1289,14 +1292,14 @@ libgnunet_plugin_datastore_sqlite_init (void *cls) | |||
1289 | 1292 | ||
1290 | if (NULL != plugin.env) | 1293 | if (NULL != plugin.env) |
1291 | return NULL; /* can only initialize once! */ | 1294 | return NULL; /* can only initialize once! */ |
1292 | memset (&plugin, 0, sizeof (struct Plugin)); | 1295 | memset(&plugin, 0, sizeof(struct Plugin)); |
1293 | plugin.env = env; | 1296 | plugin.env = env; |
1294 | if (GNUNET_OK != database_setup (env->cfg, &plugin)) | 1297 | if (GNUNET_OK != database_setup(env->cfg, &plugin)) |
1295 | { | 1298 | { |
1296 | database_shutdown (&plugin); | 1299 | database_shutdown(&plugin); |
1297 | return NULL; | 1300 | return NULL; |
1298 | } | 1301 | } |
1299 | api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions); | 1302 | api = GNUNET_new(struct GNUNET_DATASTORE_PluginFunctions); |
1300 | api->cls = &plugin; | 1303 | api->cls = &plugin; |
1301 | api->estimate_size = &sqlite_plugin_estimate_size; | 1304 | api->estimate_size = &sqlite_plugin_estimate_size; |
1302 | api->put = &sqlite_plugin_put; | 1305 | api->put = &sqlite_plugin_put; |
@@ -1307,9 +1310,9 @@ libgnunet_plugin_datastore_sqlite_init (void *cls) | |||
1307 | api->get_keys = &sqlite_plugin_get_keys; | 1310 | api->get_keys = &sqlite_plugin_get_keys; |
1308 | api->drop = &sqlite_plugin_drop; | 1311 | api->drop = &sqlite_plugin_drop; |
1309 | api->remove_key = &sqlite_plugin_remove_key; | 1312 | api->remove_key = &sqlite_plugin_remove_key; |
1310 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | 1313 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, |
1311 | "sqlite", | 1314 | "sqlite", |
1312 | _ ("Sqlite database running\n")); | 1315 | _("Sqlite database running\n")); |
1313 | return api; | 1316 | return api; |
1314 | } | 1317 | } |
1315 | 1318 | ||
@@ -1321,27 +1324,27 @@ libgnunet_plugin_datastore_sqlite_init (void *cls) | |||
1321 | * @return always NULL | 1324 | * @return always NULL |
1322 | */ | 1325 | */ |
1323 | void * | 1326 | void * |
1324 | libgnunet_plugin_datastore_sqlite_done (void *cls) | 1327 | libgnunet_plugin_datastore_sqlite_done(void *cls) |
1325 | { | 1328 | { |
1326 | char *fn; | 1329 | char *fn; |
1327 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; | 1330 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; |
1328 | struct Plugin *plugin = api->cls; | 1331 | struct Plugin *plugin = api->cls; |
1329 | 1332 | ||
1330 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1333 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, |
1331 | "sqlite", | 1334 | "sqlite", |
1332 | "sqlite plugin is done\n"); | 1335 | "sqlite plugin is done\n"); |
1333 | fn = NULL; | 1336 | fn = NULL; |
1334 | if (plugin->drop_on_shutdown) | 1337 | if (plugin->drop_on_shutdown) |
1335 | fn = GNUNET_strdup (plugin->fn); | 1338 | fn = GNUNET_strdup(plugin->fn); |
1336 | database_shutdown (plugin); | 1339 | database_shutdown(plugin); |
1337 | plugin->env = NULL; | 1340 | plugin->env = NULL; |
1338 | GNUNET_free (api); | 1341 | GNUNET_free(api); |
1339 | if (NULL != fn) | 1342 | if (NULL != fn) |
1340 | { | 1343 | { |
1341 | if (0 != unlink (fn)) | 1344 | if (0 != unlink(fn)) |
1342 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 1345 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
1343 | GNUNET_free (fn); | 1346 | GNUNET_free(fn); |
1344 | } | 1347 | } |
1345 | return NULL; | 1348 | return NULL; |
1346 | } | 1349 | } |
1347 | 1350 | ||
diff --git a/src/datastore/plugin_datastore_template.c b/src/datastore/plugin_datastore_template.c index d2e42a170..dea6151ad 100644 --- a/src/datastore/plugin_datastore_template.c +++ b/src/datastore/plugin_datastore_template.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file datastore/plugin_datastore_template.c | 22 | * @file datastore/plugin_datastore_template.c |
@@ -31,8 +31,7 @@ | |||
31 | /** | 31 | /** |
32 | * Context for all functions in this plugin. | 32 | * Context for all functions in this plugin. |
33 | */ | 33 | */ |
34 | struct Plugin | 34 | struct Plugin { |
35 | { | ||
36 | /** | 35 | /** |
37 | * Our execution environment. | 36 | * Our execution environment. |
38 | */ | 37 | */ |
@@ -48,11 +47,11 @@ struct Plugin | |||
48 | * @return number of bytes used on disk | 47 | * @return number of bytes used on disk |
49 | */ | 48 | */ |
50 | static void | 49 | static void |
51 | template_plugin_estimate_size (void *cls, unsigned long long *estimate) | 50 | template_plugin_estimate_size(void *cls, unsigned long long *estimate) |
52 | { | 51 | { |
53 | if (NULL == estimate) | 52 | if (NULL == estimate) |
54 | return; | 53 | return; |
55 | GNUNET_break (0); | 54 | GNUNET_break(0); |
56 | *estimate = 0; | 55 | *estimate = 0; |
57 | } | 56 | } |
58 | 57 | ||
@@ -74,21 +73,21 @@ template_plugin_estimate_size (void *cls, unsigned long long *estimate) | |||
74 | * @param cont_cls continuation closure | 73 | * @param cont_cls continuation closure |
75 | */ | 74 | */ |
76 | static void | 75 | static void |
77 | template_plugin_put (void *cls, | 76 | template_plugin_put(void *cls, |
78 | const struct GNUNET_HashCode *key, | 77 | const struct GNUNET_HashCode *key, |
79 | bool absent, | 78 | bool absent, |
80 | uint32_t size, | 79 | uint32_t size, |
81 | const void *data, | 80 | const void *data, |
82 | enum GNUNET_BLOCK_Type type, | 81 | enum GNUNET_BLOCK_Type type, |
83 | uint32_t priority, | 82 | uint32_t priority, |
84 | uint32_t anonymity, | 83 | uint32_t anonymity, |
85 | uint32_t replication, | 84 | uint32_t replication, |
86 | struct GNUNET_TIME_Absolute expiration, | 85 | struct GNUNET_TIME_Absolute expiration, |
87 | PluginPutCont cont, | 86 | PluginPutCont cont, |
88 | void *cont_cls) | 87 | void *cont_cls) |
89 | { | 88 | { |
90 | GNUNET_break (0); | 89 | GNUNET_break(0); |
91 | cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented"); | 90 | cont(cont_cls, key, size, GNUNET_SYSERR, "not implemented"); |
92 | } | 91 | } |
93 | 92 | ||
94 | 93 | ||
@@ -106,15 +105,15 @@ template_plugin_put (void *cls, | |||
106 | * @param proc_cls closure for proc | 105 | * @param proc_cls closure for proc |
107 | */ | 106 | */ |
108 | static void | 107 | static void |
109 | template_plugin_get_key (void *cls, | 108 | template_plugin_get_key(void *cls, |
110 | uint64_t next_uid, | 109 | uint64_t next_uid, |
111 | bool random, | 110 | bool random, |
112 | const struct GNUNET_HashCode *key, | 111 | const struct GNUNET_HashCode *key, |
113 | enum GNUNET_BLOCK_Type type, | 112 | enum GNUNET_BLOCK_Type type, |
114 | PluginDatumProcessor proc, | 113 | PluginDatumProcessor proc, |
115 | void *proc_cls) | 114 | void *proc_cls) |
116 | { | 115 | { |
117 | GNUNET_break (0); | 116 | GNUNET_break(0); |
118 | } | 117 | } |
119 | 118 | ||
120 | 119 | ||
@@ -131,10 +130,10 @@ template_plugin_get_key (void *cls, | |||
131 | * @param proc_cls closure for proc | 130 | * @param proc_cls closure for proc |
132 | */ | 131 | */ |
133 | static void | 132 | static void |
134 | template_plugin_get_replication (void *cls, PluginDatumProcessor proc, | 133 | template_plugin_get_replication(void *cls, PluginDatumProcessor proc, |
135 | void *proc_cls) | 134 | void *proc_cls) |
136 | { | 135 | { |
137 | GNUNET_break (0); | 136 | GNUNET_break(0); |
138 | } | 137 | } |
139 | 138 | ||
140 | 139 | ||
@@ -147,10 +146,10 @@ template_plugin_get_replication (void *cls, PluginDatumProcessor proc, | |||
147 | * @param proc_cls closure for proc | 146 | * @param proc_cls closure for proc |
148 | */ | 147 | */ |
149 | static void | 148 | static void |
150 | template_plugin_get_expiration (void *cls, PluginDatumProcessor proc, | 149 | template_plugin_get_expiration(void *cls, PluginDatumProcessor proc, |
151 | void *proc_cls) | 150 | void *proc_cls) |
152 | { | 151 | { |
153 | GNUNET_break (0); | 152 | GNUNET_break(0); |
154 | } | 153 | } |
155 | 154 | ||
156 | 155 | ||
@@ -166,11 +165,11 @@ template_plugin_get_expiration (void *cls, PluginDatumProcessor proc, | |||
166 | * @param proc_cls closure for proc | 165 | * @param proc_cls closure for proc |
167 | */ | 166 | */ |
168 | static void | 167 | static void |
169 | template_plugin_get_zero_anonymity (void *cls, uint64_t next_uid, | 168 | template_plugin_get_zero_anonymity(void *cls, uint64_t next_uid, |
170 | enum GNUNET_BLOCK_Type type, | 169 | enum GNUNET_BLOCK_Type type, |
171 | PluginDatumProcessor proc, void *proc_cls) | 170 | PluginDatumProcessor proc, void *proc_cls) |
172 | { | 171 | { |
173 | GNUNET_break (0); | 172 | GNUNET_break(0); |
174 | } | 173 | } |
175 | 174 | ||
176 | 175 | ||
@@ -178,9 +177,9 @@ template_plugin_get_zero_anonymity (void *cls, uint64_t next_uid, | |||
178 | * Drop database. | 177 | * Drop database. |
179 | */ | 178 | */ |
180 | static void | 179 | static void |
181 | template_plugin_drop (void *cls) | 180 | template_plugin_drop(void *cls) |
182 | { | 181 | { |
183 | GNUNET_break (0); | 182 | GNUNET_break(0); |
184 | } | 183 | } |
185 | 184 | ||
186 | 185 | ||
@@ -192,11 +191,11 @@ template_plugin_drop (void *cls) | |||
192 | * @param proc_cls closure for proc | 191 | * @param proc_cls closure for proc |
193 | */ | 192 | */ |
194 | static void | 193 | static void |
195 | template_get_keys (void *cls, | 194 | template_get_keys(void *cls, |
196 | PluginKeyProcessor proc, | 195 | PluginKeyProcessor proc, |
197 | void *proc_cls) | 196 | void *proc_cls) |
198 | { | 197 | { |
199 | proc (proc_cls, NULL, 0); | 198 | proc(proc_cls, NULL, 0); |
200 | } | 199 | } |
201 | 200 | ||
202 | 201 | ||
@@ -211,15 +210,15 @@ template_get_keys (void *cls, | |||
211 | * @param cont_cls continuation closure for @a cont | 210 | * @param cont_cls continuation closure for @a cont |
212 | */ | 211 | */ |
213 | static void | 212 | static void |
214 | template_plugin_remove_key (void *cls, | 213 | template_plugin_remove_key(void *cls, |
215 | const struct GNUNET_HashCode *key, | 214 | const struct GNUNET_HashCode *key, |
216 | uint32_t size, | 215 | uint32_t size, |
217 | const void *data, | 216 | const void *data, |
218 | PluginRemoveCont cont, | 217 | PluginRemoveCont cont, |
219 | void *cont_cls) | 218 | void *cont_cls) |
220 | { | 219 | { |
221 | GNUNET_break (0); | 220 | GNUNET_break(0); |
222 | cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented"); | 221 | cont(cont_cls, key, size, GNUNET_SYSERR, "not implemented"); |
223 | } | 222 | } |
224 | 223 | ||
225 | 224 | ||
@@ -230,15 +229,15 @@ template_plugin_remove_key (void *cls, | |||
230 | * @return our "struct Plugin*" | 229 | * @return our "struct Plugin*" |
231 | */ | 230 | */ |
232 | void * | 231 | void * |
233 | libgnunet_plugin_datastore_template_init (void *cls) | 232 | libgnunet_plugin_datastore_template_init(void *cls) |
234 | { | 233 | { |
235 | struct GNUNET_DATASTORE_PluginEnvironment *env = cls; | 234 | struct GNUNET_DATASTORE_PluginEnvironment *env = cls; |
236 | struct GNUNET_DATASTORE_PluginFunctions *api; | 235 | struct GNUNET_DATASTORE_PluginFunctions *api; |
237 | struct Plugin *plugin; | 236 | struct Plugin *plugin; |
238 | 237 | ||
239 | plugin = GNUNET_new (struct Plugin); | 238 | plugin = GNUNET_new(struct Plugin); |
240 | plugin->env = env; | 239 | plugin->env = env; |
241 | api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions); | 240 | api = GNUNET_new(struct GNUNET_DATASTORE_PluginFunctions); |
242 | api->cls = plugin; | 241 | api->cls = plugin; |
243 | api->estimate_size = &template_plugin_estimate_size; | 242 | api->estimate_size = &template_plugin_estimate_size; |
244 | api->put = &template_plugin_put; | 243 | api->put = &template_plugin_put; |
@@ -249,8 +248,8 @@ libgnunet_plugin_datastore_template_init (void *cls) | |||
249 | api->drop = &template_plugin_drop; | 248 | api->drop = &template_plugin_drop; |
250 | api->get_keys = &template_get_keys; | 249 | api->get_keys = &template_get_keys; |
251 | api->remove_key = &template_plugin_remove_key; | 250 | api->remove_key = &template_plugin_remove_key; |
252 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "template", | 251 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "template", |
253 | _("Template database running\n")); | 252 | _("Template database running\n")); |
254 | return api; | 253 | return api; |
255 | } | 254 | } |
256 | 255 | ||
@@ -261,13 +260,13 @@ libgnunet_plugin_datastore_template_init (void *cls) | |||
261 | * @return always NULL | 260 | * @return always NULL |
262 | */ | 261 | */ |
263 | void * | 262 | void * |
264 | libgnunet_plugin_datastore_template_done (void *cls) | 263 | libgnunet_plugin_datastore_template_done(void *cls) |
265 | { | 264 | { |
266 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; | 265 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; |
267 | struct Plugin *plugin = api->cls; | 266 | struct Plugin *plugin = api->cls; |
268 | 267 | ||
269 | GNUNET_free (plugin); | 268 | GNUNET_free(plugin); |
270 | GNUNET_free (api); | 269 | GNUNET_free(api); |
271 | return NULL; | 270 | return NULL; |
272 | } | 271 | } |
273 | 272 | ||
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index ee78a8cfc..56a7cdd3b 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /* | 20 | /* |
21 | * @file datastore/test_datastore_api.c | 21 | * @file datastore/test_datastore_api.c |
22 | * @brief Test for the basic datastore API. | 22 | * @brief Test for the basic datastore API. |
@@ -37,7 +37,7 @@ | |||
37 | /** | 37 | /** |
38 | * How long until we give up on transmitting the message? | 38 | * How long until we give up on transmitting the message? |
39 | */ | 39 | */ |
40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 40 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) |
41 | 41 | ||
42 | #define ITERATIONS 256 | 42 | #define ITERATIONS 256 |
43 | 43 | ||
@@ -60,45 +60,45 @@ static const char *plugin_name; | |||
60 | 60 | ||
61 | 61 | ||
62 | static size_t | 62 | static size_t |
63 | get_size (int i) | 63 | get_size(int i) |
64 | { | 64 | { |
65 | return 8 * i; | 65 | return 8 * i; |
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
69 | static const void * | 69 | static const void * |
70 | get_data (int i) | 70 | get_data(int i) |
71 | { | 71 | { |
72 | static char buf[60000]; | 72 | static char buf[60000]; |
73 | 73 | ||
74 | memset (buf, i, 8 * i); | 74 | memset(buf, i, 8 * i); |
75 | return buf; | 75 | return buf; |
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | static int | 79 | static int |
80 | get_type (int i) | 80 | get_type(int i) |
81 | { | 81 | { |
82 | return i + 1; | 82 | return i + 1; |
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
86 | static int | 86 | static int |
87 | get_priority (int i) | 87 | get_priority(int i) |
88 | { | 88 | { |
89 | return i + 1; | 89 | return i + 1; |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | static int | 93 | static int |
94 | get_anonymity (int i) | 94 | get_anonymity(int i) |
95 | { | 95 | { |
96 | return i; | 96 | return i; |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | static struct GNUNET_TIME_Absolute | 100 | static struct GNUNET_TIME_Absolute |
101 | get_expiration (int i) | 101 | get_expiration(int i) |
102 | { | 102 | { |
103 | struct GNUNET_TIME_Absolute av; | 103 | struct GNUNET_TIME_Absolute av; |
104 | 104 | ||
@@ -110,8 +110,7 @@ get_expiration (int i) | |||
110 | /** | 110 | /** |
111 | * Which phase of the process are we in? | 111 | * Which phase of the process are we in? |
112 | */ | 112 | */ |
113 | enum RunPhase | 113 | enum RunPhase { |
114 | { | ||
115 | /** | 114 | /** |
116 | * We are done (shutting down normally). | 115 | * We are done (shutting down normally). |
117 | */ | 116 | */ |
@@ -143,8 +142,7 @@ enum RunPhase | |||
143 | * benchmark. Could right now be global, but this allows | 142 | * benchmark. Could right now be global, but this allows |
144 | * us to theoretically run multiple clients "in parallel". | 143 | * us to theoretically run multiple clients "in parallel". |
145 | */ | 144 | */ |
146 | struct CpsRunContext | 145 | struct CpsRunContext { |
147 | { | ||
148 | /** | 146 | /** |
149 | * Execution phase we are in. | 147 | * Execution phase we are in. |
150 | */ | 148 | */ |
@@ -167,7 +165,7 @@ struct CpsRunContext | |||
167 | * @param cls the `struct CpsRunContext` | 165 | * @param cls the `struct CpsRunContext` |
168 | */ | 166 | */ |
169 | static void | 167 | static void |
170 | run_continuation (void *cls); | 168 | run_continuation(void *cls); |
171 | 169 | ||
172 | 170 | ||
173 | /** | 171 | /** |
@@ -182,49 +180,102 @@ run_continuation (void *cls); | |||
182 | * @param msg NULL on success, otherwise an error message | 180 | * @param msg NULL on success, otherwise an error message |
183 | */ | 181 | */ |
184 | static void | 182 | static void |
185 | check_success (void *cls, | 183 | check_success(void *cls, |
186 | int success, | 184 | int success, |
187 | struct GNUNET_TIME_Absolute min_expiration, | 185 | struct GNUNET_TIME_Absolute min_expiration, |
188 | const char *msg) | 186 | const char *msg) |
189 | { | 187 | { |
190 | struct CpsRunContext *crc = cls; | 188 | struct CpsRunContext *crc = cls; |
191 | 189 | ||
192 | if (GNUNET_OK != success) | 190 | if (GNUNET_OK != success) |
193 | { | 191 | { |
194 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 192 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
195 | "Operation %d/%d not successful: `%s'\n", | 193 | "Operation %d/%d not successful: `%s'\n", |
196 | crc->phase, | 194 | crc->phase, |
197 | crc->i, | 195 | crc->i, |
198 | msg); | 196 | msg); |
199 | crc->phase = RP_ERROR; | 197 | crc->phase = RP_ERROR; |
200 | } | 198 | } |
201 | GNUNET_free_non_null (crc->data); | 199 | GNUNET_free_non_null(crc->data); |
202 | crc->data = NULL; | 200 | crc->data = NULL; |
203 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); | 201 | GNUNET_SCHEDULER_add_now(&run_continuation, crc); |
204 | } | 202 | } |
205 | 203 | ||
206 | 204 | ||
207 | static void | 205 | static void |
208 | get_reserved (void *cls, | 206 | get_reserved(void *cls, |
209 | int success, | 207 | int success, |
210 | struct GNUNET_TIME_Absolute min_expiration, | 208 | struct GNUNET_TIME_Absolute min_expiration, |
211 | const char *msg) | 209 | const char *msg) |
212 | { | 210 | { |
213 | struct CpsRunContext *crc = cls; | 211 | struct CpsRunContext *crc = cls; |
214 | 212 | ||
215 | if (0 >= success) | 213 | if (0 >= success) |
216 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 214 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
217 | "Error obtaining reservation: `%s'\n", | 215 | "Error obtaining reservation: `%s'\n", |
218 | msg); | 216 | msg); |
219 | GNUNET_assert (0 < success); | 217 | GNUNET_assert(0 < success); |
220 | crc->rid = success; | 218 | crc->rid = success; |
221 | GNUNET_SCHEDULER_add_now (&run_continuation, | 219 | GNUNET_SCHEDULER_add_now(&run_continuation, |
222 | crc); | 220 | crc); |
223 | } | 221 | } |
224 | 222 | ||
225 | 223 | ||
226 | static void | 224 | static void |
227 | check_value (void *cls, | 225 | check_value(void *cls, |
226 | const struct GNUNET_HashCode *key, | ||
227 | size_t size, | ||
228 | const void *data, | ||
229 | enum GNUNET_BLOCK_Type type, | ||
230 | uint32_t priority, | ||
231 | uint32_t anonymity, | ||
232 | uint32_t replication, | ||
233 | struct GNUNET_TIME_Absolute expiration, | ||
234 | uint64_t uid) | ||
235 | { | ||
236 | struct CpsRunContext *crc = cls; | ||
237 | int i; | ||
238 | |||
239 | i = crc->i; | ||
240 | if (NULL == key) | ||
241 | { | ||
242 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
243 | "Value check failed (got NULL key) in %d/%d\n", | ||
244 | crc->phase, | ||
245 | crc->i); | ||
246 | crc->phase = RP_ERROR; | ||
247 | GNUNET_SCHEDULER_add_now(&run_continuation, | ||
248 | crc); | ||
249 | return; | ||
250 | } | ||
251 | #if 0 | ||
252 | fprintf(stderr, | ||
253 | "Check value got `%s' of size %u, type %d, expire %s\n", | ||
254 | GNUNET_h2s(key), (unsigned int)size, type, | ||
255 | GNUNET_STRINGS_absolute_time_to_string(expiration)); | ||
256 | fprintf(stderr, | ||
257 | "Check value iteration %d wants size %u, type %d, expire %s\n", i, | ||
258 | (unsigned int)get_size(i), get_type(i), | ||
259 | GNUNET_STRINGS_absolute_time_to_string(get_expiration(i))); | ||
260 | #endif | ||
261 | GNUNET_assert(size == get_size(i)); | ||
262 | GNUNET_assert(0 == memcmp(data, get_data(i), size)); | ||
263 | GNUNET_assert(type == get_type(i)); | ||
264 | GNUNET_assert(priority == get_priority(i)); | ||
265 | GNUNET_assert(anonymity == get_anonymity(i)); | ||
266 | GNUNET_assert(expiration.abs_value_us == get_expiration(i).abs_value_us); | ||
267 | if (crc->i == 0) | ||
268 | { | ||
269 | crc->phase = RP_DEL; | ||
270 | crc->i = ITERATIONS; | ||
271 | } | ||
272 | GNUNET_SCHEDULER_add_now(&run_continuation, | ||
273 | crc); | ||
274 | } | ||
275 | |||
276 | |||
277 | static void | ||
278 | delete_value(void *cls, | ||
228 | const struct GNUNET_HashCode *key, | 279 | const struct GNUNET_HashCode *key, |
229 | size_t size, | 280 | size_t size, |
230 | const void *data, | 281 | const void *data, |
@@ -236,48 +287,21 @@ check_value (void *cls, | |||
236 | uint64_t uid) | 287 | uint64_t uid) |
237 | { | 288 | { |
238 | struct CpsRunContext *crc = cls; | 289 | struct CpsRunContext *crc = cls; |
239 | int i; | ||
240 | 290 | ||
241 | i = crc->i; | 291 | GNUNET_assert(NULL == crc->data); |
242 | if (NULL == key) | 292 | GNUNET_assert(NULL != key); |
243 | { | 293 | crc->size = size; |
244 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 294 | crc->key = *key; |
245 | "Value check failed (got NULL key) in %d/%d\n", | 295 | crc->data = GNUNET_malloc(size); |
246 | crc->phase, | 296 | GNUNET_memcpy(crc->data, data, size); |
247 | crc->i); | 297 | crc->phase = RP_DO_DEL; |
248 | crc->phase = RP_ERROR; | 298 | GNUNET_SCHEDULER_add_now(&run_continuation, |
249 | GNUNET_SCHEDULER_add_now (&run_continuation, | 299 | crc); |
250 | crc); | ||
251 | return; | ||
252 | } | ||
253 | #if 0 | ||
254 | fprintf (stderr, | ||
255 | "Check value got `%s' of size %u, type %d, expire %s\n", | ||
256 | GNUNET_h2s (key), (unsigned int) size, type, | ||
257 | GNUNET_STRINGS_absolute_time_to_string (expiration)); | ||
258 | fprintf (stderr, | ||
259 | "Check value iteration %d wants size %u, type %d, expire %s\n", i, | ||
260 | (unsigned int) get_size (i), get_type (i), | ||
261 | GNUNET_STRINGS_absolute_time_to_string (get_expiration(i))); | ||
262 | #endif | ||
263 | GNUNET_assert (size == get_size (i)); | ||
264 | GNUNET_assert (0 == memcmp (data, get_data (i), size)); | ||
265 | GNUNET_assert (type == get_type (i)); | ||
266 | GNUNET_assert (priority == get_priority (i)); | ||
267 | GNUNET_assert (anonymity == get_anonymity (i)); | ||
268 | GNUNET_assert (expiration.abs_value_us == get_expiration (i).abs_value_us); | ||
269 | if (crc->i == 0) | ||
270 | { | ||
271 | crc->phase = RP_DEL; | ||
272 | crc->i = ITERATIONS; | ||
273 | } | ||
274 | GNUNET_SCHEDULER_add_now (&run_continuation, | ||
275 | crc); | ||
276 | } | 300 | } |
277 | 301 | ||
278 | 302 | ||
279 | static void | 303 | static void |
280 | delete_value (void *cls, | 304 | check_nothing(void *cls, |
281 | const struct GNUNET_HashCode *key, | 305 | const struct GNUNET_HashCode *key, |
282 | size_t size, | 306 | size_t size, |
283 | const void *data, | 307 | const void *data, |
@@ -290,20 +314,16 @@ delete_value (void *cls, | |||
290 | { | 314 | { |
291 | struct CpsRunContext *crc = cls; | 315 | struct CpsRunContext *crc = cls; |
292 | 316 | ||
293 | GNUNET_assert (NULL == crc->data); | 317 | GNUNET_assert(key == NULL); |
294 | GNUNET_assert (NULL != key); | 318 | if (crc->i == 0) |
295 | crc->size = size; | 319 | crc->phase = RP_RESERVE; |
296 | crc->key = *key; | 320 | GNUNET_SCHEDULER_add_now(&run_continuation, |
297 | crc->data = GNUNET_malloc (size); | 321 | crc); |
298 | GNUNET_memcpy (crc->data, data, size); | ||
299 | crc->phase = RP_DO_DEL; | ||
300 | GNUNET_SCHEDULER_add_now (&run_continuation, | ||
301 | crc); | ||
302 | } | 322 | } |
303 | 323 | ||
304 | 324 | ||
305 | static void | 325 | static void |
306 | check_nothing (void *cls, | 326 | check_multiple(void *cls, |
307 | const struct GNUNET_HashCode *key, | 327 | const struct GNUNET_HashCode *key, |
308 | size_t size, | 328 | size_t size, |
309 | const void *data, | 329 | const void *data, |
@@ -316,45 +336,25 @@ check_nothing (void *cls, | |||
316 | { | 336 | { |
317 | struct CpsRunContext *crc = cls; | 337 | struct CpsRunContext *crc = cls; |
318 | 338 | ||
319 | GNUNET_assert (key == NULL); | 339 | GNUNET_assert(key != NULL); |
320 | if (crc->i == 0) | ||
321 | crc->phase = RP_RESERVE; | ||
322 | GNUNET_SCHEDULER_add_now (&run_continuation, | ||
323 | crc); | ||
324 | } | ||
325 | |||
326 | |||
327 | static void | ||
328 | check_multiple (void *cls, | ||
329 | const struct GNUNET_HashCode *key, | ||
330 | size_t size, | ||
331 | const void *data, | ||
332 | enum GNUNET_BLOCK_Type type, | ||
333 | uint32_t priority, | ||
334 | uint32_t anonymity, | ||
335 | uint32_t replication, | ||
336 | struct GNUNET_TIME_Absolute expiration, | ||
337 | uint64_t uid) | ||
338 | { | ||
339 | struct CpsRunContext *crc = cls; | ||
340 | |||
341 | GNUNET_assert (key != NULL); | ||
342 | switch (crc->phase) | 340 | switch (crc->phase) |
343 | { | 341 | { |
344 | case RP_GET_MULTIPLE: | 342 | case RP_GET_MULTIPLE: |
345 | crc->phase = RP_GET_MULTIPLE_NEXT; | 343 | crc->phase = RP_GET_MULTIPLE_NEXT; |
346 | crc->first_uid = uid; | 344 | crc->first_uid = uid; |
347 | break; | 345 | break; |
348 | case RP_GET_MULTIPLE_NEXT: | 346 | |
349 | GNUNET_assert (uid != crc->first_uid); | 347 | case RP_GET_MULTIPLE_NEXT: |
350 | crc->phase = RP_DONE; | 348 | GNUNET_assert(uid != crc->first_uid); |
351 | break; | 349 | crc->phase = RP_DONE; |
352 | default: | 350 | break; |
353 | GNUNET_break (0); | 351 | |
354 | crc->phase = RP_ERROR; | 352 | default: |
355 | break; | 353 | GNUNET_break(0); |
356 | } | 354 | crc->phase = RP_ERROR; |
357 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); | 355 | break; |
356 | } | ||
357 | GNUNET_SCHEDULER_add_now(&run_continuation, crc); | ||
358 | } | 358 | } |
359 | 359 | ||
360 | 360 | ||
@@ -365,166 +365,177 @@ check_multiple (void *cls, | |||
365 | * @param cls the `struct CpsRunContext` | 365 | * @param cls the `struct CpsRunContext` |
366 | */ | 366 | */ |
367 | static void | 367 | static void |
368 | run_continuation (void *cls) | 368 | run_continuation(void *cls) |
369 | { | 369 | { |
370 | struct CpsRunContext *crc = cls; | 370 | struct CpsRunContext *crc = cls; |
371 | 371 | ||
372 | ok = (int) crc->phase; | 372 | ok = (int)crc->phase; |
373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 373 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
374 | "Test in phase %u\n", | 374 | "Test in phase %u\n", |
375 | crc->phase); | 375 | crc->phase); |
376 | switch (crc->phase) | 376 | switch (crc->phase) |
377 | { | 377 | { |
378 | case RP_PUT: | 378 | case RP_PUT: |
379 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 379 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
380 | "Executing PUT number %u\n", | 380 | "Executing PUT number %u\n", |
381 | crc->i); | 381 | crc->i); |
382 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | 382 | GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key); |
383 | GNUNET_DATASTORE_put (datastore, 0, &crc->key, get_size (crc->i), | 383 | GNUNET_DATASTORE_put(datastore, 0, &crc->key, get_size(crc->i), |
384 | get_data (crc->i), get_type (crc->i), | 384 | get_data(crc->i), get_type(crc->i), |
385 | get_priority (crc->i), get_anonymity (crc->i), 0, | 385 | get_priority(crc->i), get_anonymity(crc->i), 0, |
386 | get_expiration (crc->i), 1, 1, | 386 | get_expiration(crc->i), 1, 1, |
387 | &check_success, crc); | 387 | &check_success, crc); |
388 | crc->i++; | 388 | crc->i++; |
389 | if (crc->i == ITERATIONS) | 389 | if (crc->i == ITERATIONS) |
390 | crc->phase = RP_GET; | 390 | crc->phase = RP_GET; |
391 | break; | 391 | break; |
392 | case RP_GET: | 392 | |
393 | crc->i--; | 393 | case RP_GET: |
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 394 | crc->i--; |
395 | "Executing GET number %u\n", | 395 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
396 | crc->i); | 396 | "Executing GET number %u\n", |
397 | GNUNET_CRYPTO_hash (&crc->i, | 397 | crc->i); |
398 | sizeof (int), | 398 | GNUNET_CRYPTO_hash(&crc->i, |
399 | &crc->key); | 399 | sizeof(int), |
400 | GNUNET_DATASTORE_get_key (datastore, | 400 | &crc->key); |
401 | 0, | 401 | GNUNET_DATASTORE_get_key(datastore, |
402 | false, | 402 | 0, |
403 | &crc->key, | 403 | false, |
404 | get_type (crc->i), | 404 | &crc->key, |
405 | 1, | 405 | get_type(crc->i), |
406 | 1, | 406 | 1, |
407 | &check_value, | 407 | 1, |
408 | crc); | 408 | &check_value, |
409 | break; | 409 | crc); |
410 | case RP_DEL: | 410 | break; |
411 | crc->i--; | 411 | |
412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 412 | case RP_DEL: |
413 | "Executing DEL number %u\n", | 413 | crc->i--; |
414 | crc->i); | 414 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
415 | crc->data = NULL; | 415 | "Executing DEL number %u\n", |
416 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | 416 | crc->i); |
417 | GNUNET_assert (NULL != | 417 | crc->data = NULL; |
418 | GNUNET_DATASTORE_get_key (datastore, | 418 | GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key); |
419 | GNUNET_assert(NULL != | ||
420 | GNUNET_DATASTORE_get_key(datastore, | ||
419 | 0, | 421 | 0, |
420 | false, | 422 | false, |
421 | &crc->key, | 423 | &crc->key, |
422 | get_type (crc->i), | 424 | get_type(crc->i), |
423 | 1, | 425 | 1, |
424 | 1, | 426 | 1, |
425 | &delete_value, | 427 | &delete_value, |
426 | crc)); | 428 | crc)); |
427 | break; | 429 | break; |
428 | case RP_DO_DEL: | 430 | |
429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 431 | case RP_DO_DEL: |
430 | "Executing DO_DEL number %u\n", | 432 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
431 | crc->i); | 433 | "Executing DO_DEL number %u\n", |
432 | if (crc->i == 0) | 434 | crc->i); |
433 | { | 435 | if (crc->i == 0) |
434 | crc->i = ITERATIONS; | 436 | { |
435 | crc->phase = RP_DELVALIDATE; | 437 | crc->i = ITERATIONS; |
436 | } | 438 | crc->phase = RP_DELVALIDATE; |
437 | else | 439 | } |
438 | { | 440 | else |
439 | crc->phase = RP_DEL; | 441 | { |
440 | } | 442 | crc->phase = RP_DEL; |
441 | GNUNET_assert (NULL != | 443 | } |
442 | GNUNET_DATASTORE_remove (datastore, &crc->key, crc->size, | 444 | GNUNET_assert(NULL != |
445 | GNUNET_DATASTORE_remove(datastore, &crc->key, crc->size, | ||
443 | crc->data, 1, 1, | 446 | crc->data, 1, 1, |
444 | &check_success, crc)); | 447 | &check_success, crc)); |
445 | break; | 448 | break; |
446 | case RP_DELVALIDATE: | 449 | |
447 | crc->i--; | 450 | case RP_DELVALIDATE: |
448 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 451 | crc->i--; |
449 | "Executing DELVALIDATE number %u\n", | 452 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
450 | crc->i); | 453 | "Executing DELVALIDATE number %u\n", |
451 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | 454 | crc->i); |
452 | GNUNET_assert (NULL != | 455 | GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key); |
453 | GNUNET_DATASTORE_get_key (datastore, | 456 | GNUNET_assert(NULL != |
457 | GNUNET_DATASTORE_get_key(datastore, | ||
454 | 0, | 458 | 0, |
455 | false, | 459 | false, |
456 | &crc->key, | 460 | &crc->key, |
457 | get_type (crc->i), | 461 | get_type(crc->i), |
458 | 1, | 462 | 1, |
459 | 1, | 463 | 1, |
460 | &check_nothing, | 464 | &check_nothing, |
461 | crc)); | 465 | crc)); |
462 | break; | 466 | break; |
463 | case RP_RESERVE: | 467 | |
464 | crc->phase = RP_PUT_MULTIPLE; | 468 | case RP_RESERVE: |
465 | GNUNET_DATASTORE_reserve (datastore, 128 * 1024, 2, | 469 | crc->phase = RP_PUT_MULTIPLE; |
466 | &get_reserved, crc); | 470 | GNUNET_DATASTORE_reserve(datastore, 128 * 1024, 2, |
467 | break; | 471 | &get_reserved, crc); |
468 | case RP_PUT_MULTIPLE: | 472 | break; |
469 | crc->phase = RP_PUT_MULTIPLE_NEXT; | 473 | |
470 | GNUNET_DATASTORE_put (datastore, crc->rid, &crc->key, get_size (42), | 474 | case RP_PUT_MULTIPLE: |
471 | get_data (42), get_type (42), get_priority (42), | 475 | crc->phase = RP_PUT_MULTIPLE_NEXT; |
472 | get_anonymity (42), 0, get_expiration (42), 1, 1, | 476 | GNUNET_DATASTORE_put(datastore, crc->rid, &crc->key, get_size(42), |
473 | &check_success, crc); | 477 | get_data(42), get_type(42), get_priority(42), |
474 | break; | 478 | get_anonymity(42), 0, get_expiration(42), 1, 1, |
475 | case RP_PUT_MULTIPLE_NEXT: | 479 | &check_success, crc); |
476 | crc->phase = RP_GET_MULTIPLE; | 480 | break; |
477 | GNUNET_DATASTORE_put (datastore, crc->rid, | 481 | |
478 | &crc->key, | 482 | case RP_PUT_MULTIPLE_NEXT: |
479 | get_size (43), | 483 | crc->phase = RP_GET_MULTIPLE; |
480 | get_data (43), | 484 | GNUNET_DATASTORE_put(datastore, crc->rid, |
481 | get_type (42), | 485 | &crc->key, |
482 | get_priority (43), | 486 | get_size(43), |
483 | get_anonymity (43), | 487 | get_data(43), |
484 | 0, | 488 | get_type(42), |
485 | get_expiration (43), | 489 | get_priority(43), |
486 | 1, 1, | 490 | get_anonymity(43), |
487 | &check_success, crc); | 491 | 0, |
488 | break; | 492 | get_expiration(43), |
489 | case RP_GET_MULTIPLE: | 493 | 1, 1, |
490 | GNUNET_assert (NULL != | 494 | &check_success, crc); |
491 | GNUNET_DATASTORE_get_key (datastore, | 495 | break; |
496 | |||
497 | case RP_GET_MULTIPLE: | ||
498 | GNUNET_assert(NULL != | ||
499 | GNUNET_DATASTORE_get_key(datastore, | ||
492 | 0, | 500 | 0, |
493 | false, | 501 | false, |
494 | &crc->key, | 502 | &crc->key, |
495 | get_type (42), | 503 | get_type(42), |
496 | 1, | 504 | 1, |
497 | 1, | 505 | 1, |
498 | &check_multiple, | 506 | &check_multiple, |
499 | crc)); | 507 | crc)); |
500 | break; | 508 | break; |
501 | case RP_GET_MULTIPLE_NEXT: | 509 | |
502 | GNUNET_assert (NULL != | 510 | case RP_GET_MULTIPLE_NEXT: |
503 | GNUNET_DATASTORE_get_key (datastore, | 511 | GNUNET_assert(NULL != |
512 | GNUNET_DATASTORE_get_key(datastore, | ||
504 | crc->first_uid + 1, | 513 | crc->first_uid + 1, |
505 | false, | 514 | false, |
506 | &crc->key, | 515 | &crc->key, |
507 | get_type (42), | 516 | get_type(42), |
508 | 1, | 517 | 1, |
509 | 1, | 518 | 1, |
510 | &check_multiple, | 519 | &check_multiple, |
511 | crc)); | 520 | crc)); |
512 | break; | 521 | break; |
513 | case RP_DONE: | 522 | |
514 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 523 | case RP_DONE: |
515 | "Finished, disconnecting\n"); | 524 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
516 | GNUNET_DATASTORE_disconnect (datastore, | 525 | "Finished, disconnecting\n"); |
517 | GNUNET_YES); | 526 | GNUNET_DATASTORE_disconnect(datastore, |
518 | GNUNET_free (crc); | 527 | GNUNET_YES); |
519 | ok = 0; | 528 | GNUNET_free(crc); |
520 | break; | 529 | ok = 0; |
521 | case RP_ERROR: | 530 | break; |
522 | GNUNET_DATASTORE_disconnect (datastore, | 531 | |
523 | GNUNET_YES); | 532 | case RP_ERROR: |
524 | GNUNET_free (crc); | 533 | GNUNET_DATASTORE_disconnect(datastore, |
525 | ok = 43; | 534 | GNUNET_YES); |
526 | break; | 535 | GNUNET_free(crc); |
527 | } | 536 | ok = 43; |
537 | break; | ||
538 | } | ||
528 | } | 539 | } |
529 | 540 | ||
530 | 541 | ||
@@ -541,37 +552,40 @@ run_continuation (void *cls) | |||
541 | * @param msg NULL on success, otherwise an error message | 552 | * @param msg NULL on success, otherwise an error message |
542 | */ | 553 | */ |
543 | static void | 554 | static void |
544 | run_tests (void *cls, | 555 | run_tests(void *cls, |
545 | int32_t success, | 556 | int32_t success, |
546 | struct GNUNET_TIME_Absolute min_expiration, | 557 | struct GNUNET_TIME_Absolute min_expiration, |
547 | const char *msg) | 558 | const char *msg) |
548 | { | 559 | { |
549 | struct CpsRunContext *crc = cls; | 560 | struct CpsRunContext *crc = cls; |
550 | 561 | ||
551 | switch (success) | 562 | switch (success) |
552 | { | 563 | { |
553 | case GNUNET_YES: | 564 | case GNUNET_YES: |
554 | GNUNET_SCHEDULER_add_now (&run_continuation, | 565 | GNUNET_SCHEDULER_add_now(&run_continuation, |
555 | crc); | 566 | crc); |
556 | return; | 567 | return; |
557 | case GNUNET_NO: | 568 | |
558 | fprintf (stderr, | 569 | case GNUNET_NO: |
559 | "%s", "Test 'put' operation failed, key already exists (!?)\n"); | 570 | fprintf(stderr, |
560 | GNUNET_DATASTORE_disconnect (datastore, | 571 | "%s", "Test 'put' operation failed, key already exists (!?)\n"); |
561 | GNUNET_YES); | 572 | GNUNET_DATASTORE_disconnect(datastore, |
562 | GNUNET_free (crc); | 573 | GNUNET_YES); |
563 | return; | 574 | GNUNET_free(crc); |
564 | case GNUNET_SYSERR: | 575 | return; |
565 | fprintf (stderr, | 576 | |
566 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", | 577 | case GNUNET_SYSERR: |
567 | msg); | 578 | fprintf(stderr, |
568 | GNUNET_DATASTORE_disconnect (datastore, | 579 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", |
569 | GNUNET_YES); | 580 | msg); |
570 | GNUNET_free (crc); | 581 | GNUNET_DATASTORE_disconnect(datastore, |
571 | return; | 582 | GNUNET_YES); |
572 | default: | 583 | GNUNET_free(crc); |
573 | GNUNET_assert (0); | 584 | return; |
574 | } | 585 | |
586 | default: | ||
587 | GNUNET_assert(0); | ||
588 | } | ||
575 | } | 589 | } |
576 | 590 | ||
577 | 591 | ||
@@ -585,36 +599,36 @@ run_tests (void *cls, | |||
585 | * @param peer peer handle (unused) | 599 | * @param peer peer handle (unused) |
586 | */ | 600 | */ |
587 | static void | 601 | static void |
588 | run (void *cls, | 602 | run(void *cls, |
589 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 603 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
590 | struct GNUNET_TESTING_Peer *peer) | 604 | struct GNUNET_TESTING_Peer *peer) |
591 | { | 605 | { |
592 | struct CpsRunContext *crc; | 606 | struct CpsRunContext *crc; |
593 | static struct GNUNET_HashCode zkey; | 607 | static struct GNUNET_HashCode zkey; |
594 | 608 | ||
595 | crc = GNUNET_new (struct CpsRunContext); | 609 | crc = GNUNET_new(struct CpsRunContext); |
596 | crc->phase = RP_PUT; | 610 | crc->phase = RP_PUT; |
597 | now = GNUNET_TIME_absolute_get (); | 611 | now = GNUNET_TIME_absolute_get(); |
598 | datastore = GNUNET_DATASTORE_connect (cfg); | 612 | datastore = GNUNET_DATASTORE_connect(cfg); |
599 | if (NULL == | 613 | if (NULL == |
600 | GNUNET_DATASTORE_put (datastore, | 614 | GNUNET_DATASTORE_put(datastore, |
601 | 0, | 615 | 0, |
602 | &zkey, | 616 | &zkey, |
603 | 4, | 617 | 4, |
604 | "TEST", | 618 | "TEST", |
605 | GNUNET_BLOCK_TYPE_TEST, | 619 | GNUNET_BLOCK_TYPE_TEST, |
606 | 0, 0, 0, | 620 | 0, 0, 0, |
607 | GNUNET_TIME_relative_to_absolute | 621 | GNUNET_TIME_relative_to_absolute |
608 | (GNUNET_TIME_UNIT_SECONDS), | 622 | (GNUNET_TIME_UNIT_SECONDS), |
609 | 0, 1, | 623 | 0, 1, |
610 | &run_tests, crc)) | 624 | &run_tests, crc)) |
611 | { | 625 | { |
612 | fprintf (stderr, | 626 | fprintf(stderr, |
613 | "%s", | 627 | "%s", |
614 | "Test 'put' operation failed.\n"); | 628 | "Test 'put' operation failed.\n"); |
615 | ok = 1; | 629 | ok = 1; |
616 | GNUNET_free (crc); | 630 | GNUNET_free(crc); |
617 | } | 631 | } |
618 | } | 632 | } |
619 | 633 | ||
620 | 634 | ||
@@ -627,8 +641,8 @@ run (void *cls, | |||
627 | * 0 for "reset to empty" | 641 | * 0 for "reset to empty" |
628 | */ | 642 | */ |
629 | static void | 643 | static void |
630 | duc_dummy (void *cls, | 644 | duc_dummy(void *cls, |
631 | int delta) | 645 | int delta) |
632 | { | 646 | { |
633 | /* intentionally empty */ | 647 | /* intentionally empty */ |
634 | } | 648 | } |
@@ -638,42 +652,42 @@ duc_dummy (void *cls, | |||
638 | * check if plugin is actually working | 652 | * check if plugin is actually working |
639 | */ | 653 | */ |
640 | static int | 654 | static int |
641 | test_plugin (const char *cfg_name) | 655 | test_plugin(const char *cfg_name) |
642 | { | 656 | { |
643 | char libname[128]; | 657 | char libname[128]; |
644 | struct GNUNET_CONFIGURATION_Handle *cfg; | 658 | struct GNUNET_CONFIGURATION_Handle *cfg; |
645 | struct GNUNET_DATASTORE_PluginFunctions *api; | 659 | struct GNUNET_DATASTORE_PluginFunctions *api; |
646 | struct GNUNET_DATASTORE_PluginEnvironment env; | 660 | struct GNUNET_DATASTORE_PluginEnvironment env; |
647 | 661 | ||
648 | cfg = GNUNET_CONFIGURATION_create (); | 662 | cfg = GNUNET_CONFIGURATION_create(); |
649 | if (GNUNET_OK != | 663 | if (GNUNET_OK != |
650 | GNUNET_CONFIGURATION_load (cfg, | 664 | GNUNET_CONFIGURATION_load(cfg, |
651 | cfg_name)) | 665 | cfg_name)) |
652 | { | 666 | { |
653 | GNUNET_CONFIGURATION_destroy (cfg); | 667 | GNUNET_CONFIGURATION_destroy(cfg); |
654 | fprintf (stderr, | 668 | fprintf(stderr, |
655 | "Failed to load configuration %s\n", | 669 | "Failed to load configuration %s\n", |
656 | cfg_name); | 670 | cfg_name); |
657 | return 1; | 671 | return 1; |
658 | } | 672 | } |
659 | memset (&env, 0, sizeof (env)); | 673 | memset(&env, 0, sizeof(env)); |
660 | env.cfg = cfg; | 674 | env.cfg = cfg; |
661 | env.duc = &duc_dummy; | 675 | env.duc = &duc_dummy; |
662 | GNUNET_snprintf (libname, | 676 | GNUNET_snprintf(libname, |
663 | sizeof (libname), | 677 | sizeof(libname), |
664 | "libgnunet_plugin_datastore_%s", | 678 | "libgnunet_plugin_datastore_%s", |
665 | plugin_name); | 679 | plugin_name); |
666 | api = GNUNET_PLUGIN_load (libname, &env); | 680 | api = GNUNET_PLUGIN_load(libname, &env); |
667 | if (NULL == api) | 681 | if (NULL == api) |
668 | { | 682 | { |
669 | GNUNET_CONFIGURATION_destroy (cfg); | 683 | GNUNET_CONFIGURATION_destroy(cfg); |
670 | fprintf (stderr, | 684 | fprintf(stderr, |
671 | "Failed to load plugin `%s'\n", | 685 | "Failed to load plugin `%s'\n", |
672 | libname); | 686 | libname); |
673 | return 77; | 687 | return 77; |
674 | } | 688 | } |
675 | GNUNET_PLUGIN_unload (libname, api); | 689 | GNUNET_PLUGIN_unload(libname, api); |
676 | GNUNET_CONFIGURATION_destroy (cfg); | 690 | GNUNET_CONFIGURATION_destroy(cfg); |
677 | return 0; | 691 | return 0; |
678 | } | 692 | } |
679 | 693 | ||
@@ -688,26 +702,26 @@ test_plugin (const char *cfg_name) | |||
688 | * @return 0 on success | 702 | * @return 0 on success |
689 | */ | 703 | */ |
690 | int | 704 | int |
691 | main (int argc, | 705 | main(int argc, |
692 | char *argv[]) | 706 | char *argv[]) |
693 | { | 707 | { |
694 | char cfg_name[PATH_MAX]; | 708 | char cfg_name[PATH_MAX]; |
695 | int ret; | 709 | int ret; |
696 | 710 | ||
697 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 711 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); |
698 | GNUNET_snprintf (cfg_name, | 712 | GNUNET_snprintf(cfg_name, |
699 | sizeof (cfg_name), | 713 | sizeof(cfg_name), |
700 | "test_datastore_api_data_%s.conf", | 714 | "test_datastore_api_data_%s.conf", |
701 | plugin_name); | 715 | plugin_name); |
702 | ret = test_plugin (cfg_name); | 716 | ret = test_plugin(cfg_name); |
703 | if (0 != ret) | 717 | if (0 != ret) |
704 | return ret; | 718 | return ret; |
705 | /* run actual test */ | 719 | /* run actual test */ |
706 | if (0 != | 720 | if (0 != |
707 | GNUNET_TESTING_peer_run ("test-gnunet-datastore", | 721 | GNUNET_TESTING_peer_run("test-gnunet-datastore", |
708 | cfg_name, | 722 | cfg_name, |
709 | &run, | 723 | &run, |
710 | NULL)) | 724 | NULL)) |
711 | return 1; | 725 | return 1; |
712 | return ok; | 726 | return ok; |
713 | } | 727 | } |
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c index fc4c03885..e7599999f 100644 --- a/src/datastore/test_datastore_api_management.c +++ b/src/datastore/test_datastore_api_management.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /* | 20 | /* |
21 | * @file datastore/test_datastore_api_management.c | 21 | * @file datastore/test_datastore_api_management.c |
22 | * @brief Test for the space management functions of the datastore implementation. | 22 | * @brief Test for the space management functions of the datastore implementation. |
@@ -33,7 +33,7 @@ | |||
33 | /** | 33 | /** |
34 | * How long until we give up on transmitting the message? | 34 | * How long until we give up on transmitting the message? |
35 | */ | 35 | */ |
36 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 36 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Number of iterations to run; must be large enough | 39 | * Number of iterations to run; must be large enough |
@@ -41,8 +41,7 @@ | |||
41 | */ | 41 | */ |
42 | #define ITERATIONS 5000 | 42 | #define ITERATIONS 5000 |
43 | 43 | ||
44 | enum RunPhase | 44 | enum RunPhase { |
45 | { | ||
46 | RP_PUT, | 45 | RP_PUT, |
47 | RP_GET, | 46 | RP_GET, |
48 | RP_DONE, | 47 | RP_DONE, |
@@ -50,8 +49,7 @@ enum RunPhase | |||
50 | }; | 49 | }; |
51 | 50 | ||
52 | 51 | ||
53 | struct CpsRunContext | 52 | struct CpsRunContext { |
54 | { | ||
55 | struct GNUNET_HashCode key; | 53 | struct GNUNET_HashCode key; |
56 | int i; | 54 | int i; |
57 | int found; | 55 | int found; |
@@ -71,45 +69,45 @@ static const char *plugin_name; | |||
71 | 69 | ||
72 | 70 | ||
73 | static size_t | 71 | static size_t |
74 | get_size (int i) | 72 | get_size(int i) |
75 | { | 73 | { |
76 | return 8 + 8 * (i % 256); | 74 | return 8 + 8 * (i % 256); |
77 | } | 75 | } |
78 | 76 | ||
79 | 77 | ||
80 | static const void * | 78 | static const void * |
81 | get_data (int i) | 79 | get_data(int i) |
82 | { | 80 | { |
83 | static char buf[60000]; | 81 | static char buf[60000]; |
84 | 82 | ||
85 | memset (buf, i, 8 + 8 * (i % 256)); | 83 | memset(buf, i, 8 + 8 * (i % 256)); |
86 | return buf; | 84 | return buf; |
87 | } | 85 | } |
88 | 86 | ||
89 | 87 | ||
90 | static int | 88 | static int |
91 | get_type (int i) | 89 | get_type(int i) |
92 | { | 90 | { |
93 | return 1; | 91 | return 1; |
94 | } | 92 | } |
95 | 93 | ||
96 | 94 | ||
97 | static int | 95 | static int |
98 | get_priority (int i) | 96 | get_priority(int i) |
99 | { | 97 | { |
100 | return i + 1; | 98 | return i + 1; |
101 | } | 99 | } |
102 | 100 | ||
103 | 101 | ||
104 | static int | 102 | static int |
105 | get_anonymity (int i) | 103 | get_anonymity(int i) |
106 | { | 104 | { |
107 | return i; | 105 | return i; |
108 | } | 106 | } |
109 | 107 | ||
110 | 108 | ||
111 | static struct GNUNET_TIME_Absolute | 109 | static struct GNUNET_TIME_Absolute |
112 | get_expiration (int i) | 110 | get_expiration(int i) |
113 | { | 111 | { |
114 | struct GNUNET_TIME_Absolute av; | 112 | struct GNUNET_TIME_Absolute av; |
115 | 113 | ||
@@ -119,201 +117,204 @@ get_expiration (int i) | |||
119 | 117 | ||
120 | 118 | ||
121 | static void | 119 | static void |
122 | run_continuation (void *cls); | 120 | run_continuation(void *cls); |
123 | 121 | ||
124 | 122 | ||
125 | static void | 123 | static void |
126 | check_success (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg) | 124 | check_success(void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg) |
127 | { | 125 | { |
128 | struct CpsRunContext *crc = cls; | 126 | struct CpsRunContext *crc = cls; |
129 | 127 | ||
130 | if (GNUNET_OK != success) | 128 | if (GNUNET_OK != success) |
131 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", msg); | 129 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", msg); |
132 | GNUNET_assert (GNUNET_OK == success); | 130 | GNUNET_assert(GNUNET_OK == success); |
133 | GNUNET_free_non_null (crc->data); | 131 | GNUNET_free_non_null(crc->data); |
134 | crc->data = NULL; | 132 | crc->data = NULL; |
135 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); | 133 | GNUNET_SCHEDULER_add_now(&run_continuation, crc); |
136 | } | 134 | } |
137 | 135 | ||
138 | 136 | ||
139 | static void | 137 | static void |
140 | check_value (void *cls, | 138 | check_value(void *cls, |
141 | const struct GNUNET_HashCode *key, | 139 | const struct GNUNET_HashCode *key, |
142 | size_t size, | 140 | size_t size, |
143 | const void *data, | 141 | const void *data, |
144 | enum GNUNET_BLOCK_Type type, | 142 | enum GNUNET_BLOCK_Type type, |
145 | uint32_t priority, | 143 | uint32_t priority, |
146 | uint32_t anonymity, | 144 | uint32_t anonymity, |
147 | uint32_t replication, | 145 | uint32_t replication, |
148 | struct GNUNET_TIME_Absolute expiration, | 146 | struct GNUNET_TIME_Absolute expiration, |
149 | uint64_t uid) | 147 | uint64_t uid) |
150 | { | 148 | { |
151 | struct CpsRunContext *crc = cls; | 149 | struct CpsRunContext *crc = cls; |
152 | int i; | 150 | int i; |
153 | 151 | ||
154 | if (NULL == key) | 152 | if (NULL == key) |
155 | { | 153 | { |
156 | crc->phase = RP_GET_FAIL; | 154 | crc->phase = RP_GET_FAIL; |
157 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); | 155 | GNUNET_SCHEDULER_add_now(&run_continuation, crc); |
158 | return; | 156 | return; |
159 | } | 157 | } |
160 | i = crc->i; | 158 | i = crc->i; |
161 | GNUNET_assert (size == get_size (i)); | 159 | GNUNET_assert(size == get_size(i)); |
162 | GNUNET_assert (0 == memcmp (data, get_data (i), size)); | 160 | GNUNET_assert(0 == memcmp(data, get_data(i), size)); |
163 | GNUNET_assert (type == get_type (i)); | 161 | GNUNET_assert(type == get_type(i)); |
164 | GNUNET_assert (priority == get_priority (i)); | 162 | GNUNET_assert(priority == get_priority(i)); |
165 | GNUNET_assert (anonymity == get_anonymity (i)); | 163 | GNUNET_assert(anonymity == get_anonymity(i)); |
166 | GNUNET_assert (expiration.abs_value_us == get_expiration (i).abs_value_us); | 164 | GNUNET_assert(expiration.abs_value_us == get_expiration(i).abs_value_us); |
167 | crc->i--; | 165 | crc->i--; |
168 | if (crc->i == 0) | 166 | if (crc->i == 0) |
169 | crc->phase = RP_DONE; | 167 | crc->phase = RP_DONE; |
170 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); | 168 | GNUNET_SCHEDULER_add_now(&run_continuation, crc); |
171 | } | 169 | } |
172 | 170 | ||
173 | 171 | ||
174 | static void | 172 | static void |
175 | check_nothing (void *cls, | 173 | check_nothing(void *cls, |
176 | const struct GNUNET_HashCode *key, | 174 | const struct GNUNET_HashCode *key, |
177 | size_t size, | 175 | size_t size, |
178 | const void *data, | 176 | const void *data, |
179 | enum GNUNET_BLOCK_Type type, | 177 | enum GNUNET_BLOCK_Type type, |
180 | uint32_t priority, | 178 | uint32_t priority, |
181 | uint32_t anonymity, | 179 | uint32_t anonymity, |
182 | uint32_t replication, | 180 | uint32_t replication, |
183 | struct GNUNET_TIME_Absolute expiration, | 181 | struct GNUNET_TIME_Absolute expiration, |
184 | uint64_t uid) | 182 | uint64_t uid) |
185 | { | 183 | { |
186 | struct CpsRunContext *crc = cls; | 184 | struct CpsRunContext *crc = cls; |
187 | 185 | ||
188 | GNUNET_assert (key == NULL); | 186 | GNUNET_assert(key == NULL); |
189 | if (0 == --crc->i) | 187 | if (0 == --crc->i) |
190 | crc->phase = RP_DONE; | 188 | crc->phase = RP_DONE; |
191 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); | 189 | GNUNET_SCHEDULER_add_now(&run_continuation, crc); |
192 | } | 190 | } |
193 | 191 | ||
194 | 192 | ||
195 | static void | 193 | static void |
196 | run_continuation (void *cls) | 194 | run_continuation(void *cls) |
197 | { | 195 | { |
198 | struct CpsRunContext *crc = cls; | 196 | struct CpsRunContext *crc = cls; |
199 | 197 | ||
200 | ok = (int) crc->phase; | 198 | ok = (int)crc->phase; |
201 | switch (crc->phase) | 199 | switch (crc->phase) |
202 | { | ||
203 | case RP_PUT: | ||
204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT", | ||
205 | crc->i); | ||
206 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | ||
207 | GNUNET_DATASTORE_put (datastore, | ||
208 | 0, | ||
209 | &crc->key, | ||
210 | get_size (crc->i), | ||
211 | get_data (crc->i), | ||
212 | get_type (crc->i), | ||
213 | get_priority (crc->i), | ||
214 | get_anonymity (crc->i), | ||
215 | 0, | ||
216 | get_expiration (crc->i), | ||
217 | 1, | ||
218 | 1, | ||
219 | &check_success, crc); | ||
220 | crc->i++; | ||
221 | if (crc->i == ITERATIONS) | ||
222 | { | 200 | { |
223 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 201 | case RP_PUT: |
224 | "Sleeping to give datastore time to clean up\n"); | 202 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT", |
225 | sleep (1); | 203 | crc->i); |
226 | crc->phase = RP_GET; | 204 | GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key); |
227 | crc->i--; | 205 | GNUNET_DATASTORE_put(datastore, |
206 | 0, | ||
207 | &crc->key, | ||
208 | get_size(crc->i), | ||
209 | get_data(crc->i), | ||
210 | get_type(crc->i), | ||
211 | get_priority(crc->i), | ||
212 | get_anonymity(crc->i), | ||
213 | 0, | ||
214 | get_expiration(crc->i), | ||
215 | 1, | ||
216 | 1, | ||
217 | &check_success, crc); | ||
218 | crc->i++; | ||
219 | if (crc->i == ITERATIONS) | ||
220 | { | ||
221 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
222 | "Sleeping to give datastore time to clean up\n"); | ||
223 | sleep(1); | ||
224 | crc->phase = RP_GET; | ||
225 | crc->i--; | ||
226 | } | ||
227 | break; | ||
228 | |||
229 | case RP_GET: | ||
230 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET", | ||
231 | crc->i); | ||
232 | GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key); | ||
233 | GNUNET_DATASTORE_get_key(datastore, | ||
234 | 0, | ||
235 | false, | ||
236 | &crc->key, | ||
237 | get_type(crc->i), | ||
238 | 1, | ||
239 | 1, | ||
240 | &check_value, | ||
241 | crc); | ||
242 | break; | ||
243 | |||
244 | case RP_GET_FAIL: | ||
245 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET(f)", | ||
246 | crc->i); | ||
247 | GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key); | ||
248 | GNUNET_DATASTORE_get_key(datastore, | ||
249 | 0, | ||
250 | false, | ||
251 | &crc->key, | ||
252 | get_type(crc->i), | ||
253 | 1, | ||
254 | 1, | ||
255 | &check_nothing, | ||
256 | crc); | ||
257 | break; | ||
258 | |||
259 | case RP_DONE: | ||
260 | GNUNET_assert(0 == crc->i); | ||
261 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n"); | ||
262 | GNUNET_DATASTORE_disconnect(datastore, GNUNET_YES); | ||
263 | GNUNET_free(crc); | ||
264 | ok = 0; | ||
228 | } | 265 | } |
229 | break; | ||
230 | case RP_GET: | ||
231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET", | ||
232 | crc->i); | ||
233 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | ||
234 | GNUNET_DATASTORE_get_key (datastore, | ||
235 | 0, | ||
236 | false, | ||
237 | &crc->key, | ||
238 | get_type (crc->i), | ||
239 | 1, | ||
240 | 1, | ||
241 | &check_value, | ||
242 | crc); | ||
243 | break; | ||
244 | case RP_GET_FAIL: | ||
245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET(f)", | ||
246 | crc->i); | ||
247 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | ||
248 | GNUNET_DATASTORE_get_key (datastore, | ||
249 | 0, | ||
250 | false, | ||
251 | &crc->key, | ||
252 | get_type (crc->i), | ||
253 | 1, | ||
254 | 1, | ||
255 | &check_nothing, | ||
256 | crc); | ||
257 | break; | ||
258 | case RP_DONE: | ||
259 | GNUNET_assert (0 == crc->i); | ||
260 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n"); | ||
261 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); | ||
262 | GNUNET_free (crc); | ||
263 | ok = 0; | ||
264 | } | ||
265 | } | 266 | } |
266 | 267 | ||
267 | 268 | ||
268 | static void | 269 | static void |
269 | run_tests (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg) | 270 | run_tests(void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg) |
270 | { | 271 | { |
271 | struct CpsRunContext *crc = cls; | 272 | struct CpsRunContext *crc = cls; |
272 | 273 | ||
273 | if (success != GNUNET_YES) | 274 | if (success != GNUNET_YES) |
274 | { | 275 | { |
275 | fprintf (stderr, | 276 | fprintf(stderr, |
276 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", | 277 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", |
277 | msg); | 278 | msg); |
278 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); | 279 | GNUNET_DATASTORE_disconnect(datastore, GNUNET_YES); |
279 | GNUNET_free (crc); | 280 | GNUNET_free(crc); |
280 | return; | 281 | return; |
281 | } | 282 | } |
282 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); | 283 | GNUNET_SCHEDULER_add_now(&run_continuation, crc); |
283 | } | 284 | } |
284 | 285 | ||
285 | 286 | ||
286 | static void | 287 | static void |
287 | run (void *cls, | 288 | run(void *cls, |
288 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 289 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
289 | struct GNUNET_TESTING_Peer *peer) | 290 | struct GNUNET_TESTING_Peer *peer) |
290 | { | 291 | { |
291 | struct CpsRunContext *crc; | 292 | struct CpsRunContext *crc; |
292 | static struct GNUNET_HashCode zkey; | 293 | static struct GNUNET_HashCode zkey; |
293 | 294 | ||
294 | crc = GNUNET_new (struct CpsRunContext); | 295 | crc = GNUNET_new(struct CpsRunContext); |
295 | crc->cfg = cfg; | 296 | crc->cfg = cfg; |
296 | crc->phase = RP_PUT; | 297 | crc->phase = RP_PUT; |
297 | now = GNUNET_TIME_absolute_get (); | 298 | now = GNUNET_TIME_absolute_get(); |
298 | datastore = GNUNET_DATASTORE_connect (cfg); | 299 | datastore = GNUNET_DATASTORE_connect(cfg); |
299 | if (NULL == | 300 | if (NULL == |
300 | GNUNET_DATASTORE_put (datastore, | 301 | GNUNET_DATASTORE_put(datastore, |
301 | 0, | 302 | 0, |
302 | &zkey, | 303 | &zkey, |
303 | 4, | 304 | 4, |
304 | "TEST", | 305 | "TEST", |
305 | GNUNET_BLOCK_TYPE_TEST, | 306 | GNUNET_BLOCK_TYPE_TEST, |
306 | 0, 0, 0, | 307 | 0, 0, 0, |
307 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS), | 308 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_SECONDS), |
308 | 0, | 309 | 0, |
309 | 1, | 310 | 1, |
310 | &run_tests, | 311 | &run_tests, |
311 | crc)) | 312 | crc)) |
312 | { | 313 | { |
313 | fprintf (stderr, "%s", "Test 'put' operation failed.\n"); | 314 | fprintf(stderr, "%s", "Test 'put' operation failed.\n"); |
314 | GNUNET_free (crc); | 315 | GNUNET_free(crc); |
315 | ok = 1; | 316 | ok = 1; |
316 | } | 317 | } |
317 | } | 318 | } |
318 | 319 | ||
319 | 320 | ||
@@ -324,8 +325,8 @@ run (void *cls, | |||
324 | * @param delta change in utilization | 325 | * @param delta change in utilization |
325 | */ | 326 | */ |
326 | static void | 327 | static void |
327 | ignore_payload_cb (void *cls, | 328 | ignore_payload_cb(void *cls, |
328 | int delta) | 329 | int delta) |
329 | { | 330 | { |
330 | /* do nothing */ | 331 | /* do nothing */ |
331 | } | 332 | } |
@@ -335,65 +336,65 @@ ignore_payload_cb (void *cls, | |||
335 | * check if plugin is actually working | 336 | * check if plugin is actually working |
336 | */ | 337 | */ |
337 | static int | 338 | static int |
338 | test_plugin (const char *cfg_name) | 339 | test_plugin(const char *cfg_name) |
339 | { | 340 | { |
340 | char libname[PATH_MAX]; | 341 | char libname[PATH_MAX]; |
341 | struct GNUNET_CONFIGURATION_Handle *cfg; | 342 | struct GNUNET_CONFIGURATION_Handle *cfg; |
342 | struct GNUNET_DATASTORE_PluginFunctions *api; | 343 | struct GNUNET_DATASTORE_PluginFunctions *api; |
343 | struct GNUNET_DATASTORE_PluginEnvironment env; | 344 | struct GNUNET_DATASTORE_PluginEnvironment env; |
344 | 345 | ||
345 | cfg = GNUNET_CONFIGURATION_create (); | 346 | cfg = GNUNET_CONFIGURATION_create(); |
346 | if (GNUNET_OK != | 347 | if (GNUNET_OK != |
347 | GNUNET_CONFIGURATION_load (cfg, | 348 | GNUNET_CONFIGURATION_load(cfg, |
348 | cfg_name)) | 349 | cfg_name)) |
349 | { | 350 | { |
350 | GNUNET_CONFIGURATION_destroy (cfg); | 351 | GNUNET_CONFIGURATION_destroy(cfg); |
351 | fprintf (stderr, | 352 | fprintf(stderr, |
352 | "Failed to load configuration %s\n", | 353 | "Failed to load configuration %s\n", |
353 | cfg_name); | 354 | cfg_name); |
354 | return 1; | 355 | return 1; |
355 | } | 356 | } |
356 | memset (&env, 0, sizeof (env)); | 357 | memset(&env, 0, sizeof(env)); |
357 | env.cfg = cfg; | 358 | env.cfg = cfg; |
358 | env.duc = &ignore_payload_cb; | 359 | env.duc = &ignore_payload_cb; |
359 | GNUNET_snprintf (libname, | 360 | GNUNET_snprintf(libname, |
360 | sizeof (libname), | 361 | sizeof(libname), |
361 | "libgnunet_plugin_datastore_%s", | 362 | "libgnunet_plugin_datastore_%s", |
362 | plugin_name); | 363 | plugin_name); |
363 | api = GNUNET_PLUGIN_load (libname, &env); | 364 | api = GNUNET_PLUGIN_load(libname, &env); |
364 | if (NULL == api) | 365 | if (NULL == api) |
365 | { | 366 | { |
366 | GNUNET_CONFIGURATION_destroy (cfg); | 367 | GNUNET_CONFIGURATION_destroy(cfg); |
367 | fprintf (stderr, | 368 | fprintf(stderr, |
368 | "Failed to load plugin `%s'\n", | 369 | "Failed to load plugin `%s'\n", |
369 | libname); | 370 | libname); |
370 | return 77; | 371 | return 77; |
371 | } | 372 | } |
372 | GNUNET_PLUGIN_unload (libname, api); | 373 | GNUNET_PLUGIN_unload(libname, api); |
373 | GNUNET_CONFIGURATION_destroy (cfg); | 374 | GNUNET_CONFIGURATION_destroy(cfg); |
374 | return 0; | 375 | return 0; |
375 | } | 376 | } |
376 | 377 | ||
377 | 378 | ||
378 | int | 379 | int |
379 | main (int argc, char *argv[]) | 380 | main(int argc, char *argv[]) |
380 | { | 381 | { |
381 | char cfg_name[PATH_MAX]; | 382 | char cfg_name[PATH_MAX]; |
382 | int ret; | 383 | int ret; |
383 | 384 | ||
384 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 385 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); |
385 | GNUNET_snprintf (cfg_name, | 386 | GNUNET_snprintf(cfg_name, |
386 | sizeof (cfg_name), | 387 | sizeof(cfg_name), |
387 | "test_datastore_api_data_%s.conf", | 388 | "test_datastore_api_data_%s.conf", |
388 | plugin_name); | 389 | plugin_name); |
389 | ret = test_plugin (cfg_name); | 390 | ret = test_plugin(cfg_name); |
390 | if (0 != ret) | 391 | if (0 != ret) |
391 | return ret; | 392 | return ret; |
392 | if (0 != | 393 | if (0 != |
393 | GNUNET_TESTING_peer_run ("test-gnunet-datastore-management", | 394 | GNUNET_TESTING_peer_run("test-gnunet-datastore-management", |
394 | cfg_name, | 395 | cfg_name, |
395 | &run, | 396 | &run, |
396 | NULL)) | 397 | NULL)) |
397 | return 1; | 398 | return 1; |
398 | return ok; | 399 | return ok; |
399 | } | 400 | } |
diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c index 2b7bf9ae4..a260e1575 100644 --- a/src/datastore/test_plugin_datastore.c +++ b/src/datastore/test_plugin_datastore.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /* | 20 | /* |
21 | * @file test_plugin_datastore.c | 21 | * @file test_plugin_datastore.c |
22 | * @brief Test database plugin directly, calling each API function once | 22 | * @brief Test database plugin directly, calling each API function once |
@@ -44,8 +44,7 @@ static const char *plugin_name; | |||
44 | 44 | ||
45 | static int ok; | 45 | static int ok; |
46 | 46 | ||
47 | enum RunPhase | 47 | enum RunPhase { |
48 | { | ||
49 | RP_ERROR = 0, | 48 | RP_ERROR = 0, |
50 | RP_PUT, | 49 | RP_PUT, |
51 | RP_GET, | 50 | RP_GET, |
@@ -57,8 +56,7 @@ enum RunPhase | |||
57 | }; | 56 | }; |
58 | 57 | ||
59 | 58 | ||
60 | struct CpsRunContext | 59 | struct CpsRunContext { |
61 | { | ||
62 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 60 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
63 | struct GNUNET_DATASTORE_PluginFunctions *api; | 61 | struct GNUNET_DATASTORE_PluginFunctions *api; |
64 | enum RunPhase phase; | 62 | enum RunPhase phase; |
@@ -76,14 +74,14 @@ struct CpsRunContext | |||
76 | * 0 for "reset to empty" | 74 | * 0 for "reset to empty" |
77 | */ | 75 | */ |
78 | static void | 76 | static void |
79 | disk_utilization_change_cb (void *cls, int delta) | 77 | disk_utilization_change_cb(void *cls, int delta) |
80 | { | 78 | { |
81 | /* do nothing */ | 79 | /* do nothing */ |
82 | } | 80 | } |
83 | 81 | ||
84 | 82 | ||
85 | static void | 83 | static void |
86 | test (void *cls); | 84 | test(void *cls); |
87 | 85 | ||
88 | 86 | ||
89 | /** | 87 | /** |
@@ -96,47 +94,47 @@ test (void *cls); | |||
96 | * @param msg error message on error | 94 | * @param msg error message on error |
97 | */ | 95 | */ |
98 | static void | 96 | static void |
99 | put_continuation (void *cls, | 97 | put_continuation(void *cls, |
100 | const struct GNUNET_HashCode *key, | 98 | const struct GNUNET_HashCode *key, |
101 | uint32_t size, | 99 | uint32_t size, |
102 | int status, | 100 | int status, |
103 | const char *msg) | 101 | const char *msg) |
104 | { | 102 | { |
105 | struct CpsRunContext *crc = cls; | 103 | struct CpsRunContext *crc = cls; |
106 | static unsigned long long os; | 104 | static unsigned long long os; |
107 | unsigned long long cs; | 105 | unsigned long long cs; |
108 | 106 | ||
109 | if (GNUNET_OK != status) | 107 | if (GNUNET_OK != status) |
110 | { | 108 | { |
111 | fprintf (stderr, | 109 | fprintf(stderr, |
112 | "ERROR: `%s'\n", | 110 | "ERROR: `%s'\n", |
113 | msg); | 111 | msg); |
114 | } | 112 | } |
115 | else | 113 | else |
116 | { | 114 | { |
117 | crc->api->estimate_size (crc->api->cls, | 115 | crc->api->estimate_size(crc->api->cls, |
118 | &cs); | 116 | &cs); |
119 | GNUNET_assert (os <= cs); | 117 | GNUNET_assert(os <= cs); |
120 | os = cs; | 118 | os = cs; |
121 | stored_bytes += size; | 119 | stored_bytes += size; |
122 | stored_ops++; | 120 | stored_ops++; |
123 | stored_entries++; | 121 | stored_entries++; |
124 | } | 122 | } |
125 | GNUNET_SCHEDULER_add_now (&test, crc); | 123 | GNUNET_SCHEDULER_add_now(&test, crc); |
126 | } | 124 | } |
127 | 125 | ||
128 | 126 | ||
129 | static void | 127 | static void |
130 | gen_key (int i, struct GNUNET_HashCode * key) | 128 | gen_key(int i, struct GNUNET_HashCode * key) |
131 | { | 129 | { |
132 | memset (key, 0, sizeof (struct GNUNET_HashCode)); | 130 | memset(key, 0, sizeof(struct GNUNET_HashCode)); |
133 | key->bits[0] = (unsigned int) i; | 131 | key->bits[0] = (unsigned int)i; |
134 | GNUNET_CRYPTO_hash (key, sizeof (struct GNUNET_HashCode), key); | 132 | GNUNET_CRYPTO_hash(key, sizeof(struct GNUNET_HashCode), key); |
135 | } | 133 | } |
136 | 134 | ||
137 | 135 | ||
138 | static void | 136 | static void |
139 | do_put (struct CpsRunContext *crc) | 137 | do_put(struct CpsRunContext *crc) |
140 | { | 138 | { |
141 | char value[65536]; | 139 | char value[65536]; |
142 | size_t size; | 140 | size_t size; |
@@ -145,45 +143,45 @@ do_put (struct CpsRunContext *crc) | |||
145 | static int i; | 143 | static int i; |
146 | 144 | ||
147 | if (PUT_10 == i) | 145 | if (PUT_10 == i) |
148 | { | 146 | { |
149 | i = 0; | 147 | i = 0; |
150 | crc->phase++; | 148 | crc->phase++; |
151 | GNUNET_SCHEDULER_add_now (&test, crc); | 149 | GNUNET_SCHEDULER_add_now(&test, crc); |
152 | return; | 150 | return; |
153 | } | 151 | } |
154 | /* most content is 32k */ | 152 | /* most content is 32k */ |
155 | size = 32 * 1024; | 153 | size = 32 * 1024; |
156 | 154 | ||
157 | if (0 != i && GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ | 155 | if (0 != i && GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ |
158 | size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); | 156 | size = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); |
159 | size = size - (size & 7); /* always multiple of 8 */ | 157 | size = size - (size & 7); /* always multiple of 8 */ |
160 | 158 | ||
161 | /* generate random key */ | 159 | /* generate random key */ |
162 | gen_key (i, &key); | 160 | gen_key(i, &key); |
163 | memset (value, i, size); | 161 | memset(value, i, size); |
164 | if (i > 255) | 162 | if (i > 255) |
165 | memset (value, i - 255, size / 2); | 163 | memset(value, i - 255, size / 2); |
166 | value[0] = crc->i; | 164 | value[0] = crc->i; |
167 | prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); | 165 | prio = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100); |
168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 166 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
169 | "putting type %u, anon %u under key %s\n", i + 1, i, | 167 | "putting type %u, anon %u under key %s\n", i + 1, i, |
170 | GNUNET_h2s (&key)); | 168 | GNUNET_h2s(&key)); |
171 | crc->api->put (crc->api->cls, | 169 | crc->api->put(crc->api->cls, |
172 | &key, | 170 | &key, |
173 | false /* absent */, | 171 | false /* absent */, |
174 | size, | 172 | size, |
175 | value, i + 1 /* type */ , | 173 | value, i + 1 /* type */, |
176 | prio, | 174 | prio, |
177 | i /* anonymity */ , | 175 | i /* anonymity */, |
178 | 0 /* replication */ , | 176 | 0 /* replication */, |
179 | GNUNET_TIME_relative_to_absolute | 177 | GNUNET_TIME_relative_to_absolute |
180 | (GNUNET_TIME_relative_multiply | 178 | (GNUNET_TIME_relative_multiply |
181 | (GNUNET_TIME_UNIT_MILLISECONDS, | 179 | (GNUNET_TIME_UNIT_MILLISECONDS, |
182 | 60 * 60 * 60 * 1000 + | 180 | 60 * 60 * 60 * 1000 + |
183 | GNUNET_CRYPTO_random_u32 | 181 | GNUNET_CRYPTO_random_u32 |
184 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), | 182 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), |
185 | put_continuation, | 183 | put_continuation, |
186 | crc); | 184 | crc); |
187 | i++; | 185 | i++; |
188 | } | 186 | } |
189 | 187 | ||
@@ -192,51 +190,51 @@ static uint64_t guid; | |||
192 | 190 | ||
193 | 191 | ||
194 | static int | 192 | static int |
195 | iterate_one_shot (void *cls, | 193 | iterate_one_shot(void *cls, |
196 | const struct GNUNET_HashCode *key, | 194 | const struct GNUNET_HashCode *key, |
197 | uint32_t size, | 195 | uint32_t size, |
198 | const void *data, | 196 | const void *data, |
199 | enum GNUNET_BLOCK_Type type, | 197 | enum GNUNET_BLOCK_Type type, |
200 | uint32_t priority, | 198 | uint32_t priority, |
201 | uint32_t anonymity, | 199 | uint32_t anonymity, |
202 | uint32_t replication, | 200 | uint32_t replication, |
203 | struct GNUNET_TIME_Absolute expiration, | 201 | struct GNUNET_TIME_Absolute expiration, |
204 | uint64_t uid) | 202 | uint64_t uid) |
205 | { | 203 | { |
206 | struct CpsRunContext *crc = cls; | 204 | struct CpsRunContext *crc = cls; |
207 | 205 | ||
208 | GNUNET_assert (NULL != key); | 206 | GNUNET_assert(NULL != key); |
209 | guid = uid; | 207 | guid = uid; |
210 | crc->phase++; | 208 | crc->phase++; |
211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 209 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
212 | "Found result type=%u, priority=%u, size=%u, expire=%s, key %s\n", | 210 | "Found result type=%u, priority=%u, size=%u, expire=%s, key %s\n", |
213 | (unsigned int) type, | 211 | (unsigned int)type, |
214 | (unsigned int) priority, | 212 | (unsigned int)priority, |
215 | (unsigned int) size, | 213 | (unsigned int)size, |
216 | GNUNET_STRINGS_absolute_time_to_string (expiration), | 214 | GNUNET_STRINGS_absolute_time_to_string(expiration), |
217 | GNUNET_h2s (key)); | 215 | GNUNET_h2s(key)); |
218 | GNUNET_SCHEDULER_add_now (&test, | 216 | GNUNET_SCHEDULER_add_now(&test, |
219 | crc); | 217 | crc); |
220 | return GNUNET_OK; | 218 | return GNUNET_OK; |
221 | } | 219 | } |
222 | 220 | ||
223 | 221 | ||
224 | static void | 222 | static void |
225 | remove_continuation (void *cls, | 223 | remove_continuation(void *cls, |
226 | const struct GNUNET_HashCode *key, | 224 | const struct GNUNET_HashCode *key, |
227 | uint32_t size, | 225 | uint32_t size, |
228 | int status, | 226 | int status, |
229 | const char *msg) | 227 | const char *msg) |
230 | { | 228 | { |
231 | struct CpsRunContext *crc = cls; | 229 | struct CpsRunContext *crc = cls; |
232 | 230 | ||
233 | GNUNET_assert (NULL != key); | 231 | GNUNET_assert(NULL != key); |
234 | GNUNET_assert (32768 == size); | 232 | GNUNET_assert(32768 == size); |
235 | GNUNET_assert (GNUNET_OK == status); | 233 | GNUNET_assert(GNUNET_OK == status); |
236 | GNUNET_assert (NULL == msg); | 234 | GNUNET_assert(NULL == msg); |
237 | crc->phase++; | 235 | crc->phase++; |
238 | GNUNET_SCHEDULER_add_now (&test, | 236 | GNUNET_SCHEDULER_add_now(&test, |
239 | crc); | 237 | crc); |
240 | } | 238 | } |
241 | 239 | ||
242 | 240 | ||
@@ -248,28 +246,28 @@ remove_continuation (void *cls, | |||
248 | * @param cfg configuration to use | 246 | * @param cfg configuration to use |
249 | */ | 247 | */ |
250 | static void | 248 | static void |
251 | unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api, | 249 | unload_plugin(struct GNUNET_DATASTORE_PluginFunctions *api, |
252 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 250 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
253 | { | 251 | { |
254 | char *name; | 252 | char *name; |
255 | char *libname; | 253 | char *libname; |
256 | 254 | ||
257 | if (GNUNET_OK != | 255 | if (GNUNET_OK != |
258 | GNUNET_CONFIGURATION_get_value_string (cfg, | 256 | GNUNET_CONFIGURATION_get_value_string(cfg, |
259 | "DATASTORE", | 257 | "DATASTORE", |
260 | "DATABASE", | 258 | "DATABASE", |
261 | &name)) | 259 | &name)) |
262 | { | 260 | { |
263 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 261 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
264 | _("No `%s' specified for `%s' in configuration!\n"), | 262 | _("No `%s' specified for `%s' in configuration!\n"), |
265 | "DATABASE", | 263 | "DATABASE", |
266 | "DATASTORE"); | 264 | "DATASTORE"); |
267 | return; | 265 | return; |
268 | } | 266 | } |
269 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); | 267 | GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", name); |
270 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); | 268 | GNUNET_break(NULL == GNUNET_PLUGIN_unload(libname, api)); |
271 | GNUNET_free (libname); | 269 | GNUNET_free(libname); |
272 | GNUNET_free (name); | 270 | GNUNET_free(name); |
273 | } | 271 | } |
274 | 272 | ||
275 | 273 | ||
@@ -279,92 +277,99 @@ unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api, | |||
279 | * the transport and core. | 277 | * the transport and core. |
280 | */ | 278 | */ |
281 | static void | 279 | static void |
282 | cleaning_task (void *cls) | 280 | cleaning_task(void *cls) |
283 | { | 281 | { |
284 | struct CpsRunContext *crc = cls; | 282 | struct CpsRunContext *crc = cls; |
285 | 283 | ||
286 | unload_plugin (crc->api, crc->cfg); | 284 | unload_plugin(crc->api, crc->cfg); |
287 | GNUNET_free (crc); | 285 | GNUNET_free(crc); |
288 | } | 286 | } |
289 | 287 | ||
290 | 288 | ||
291 | static void | 289 | static void |
292 | test (void *cls) | 290 | test(void *cls) |
293 | { | 291 | { |
294 | struct CpsRunContext *crc = cls; | 292 | struct CpsRunContext *crc = cls; |
295 | struct GNUNET_HashCode key; | 293 | struct GNUNET_HashCode key; |
296 | 294 | ||
297 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 295 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
298 | "In phase %d, iteration %u\n", crc->phase, crc->cnt); | 296 | "In phase %d, iteration %u\n", crc->phase, crc->cnt); |
299 | switch (crc->phase) | 297 | switch (crc->phase) |
300 | { | ||
301 | case RP_ERROR: | ||
302 | ok = 1; | ||
303 | GNUNET_break (0); | ||
304 | crc->api->drop (crc->api->cls); | ||
305 | GNUNET_SCHEDULER_add_now (&cleaning_task, crc); | ||
306 | break; | ||
307 | case RP_PUT: | ||
308 | do_put (crc); | ||
309 | break; | ||
310 | case RP_GET: | ||
311 | if (crc->cnt == 1) | ||
312 | { | 298 | { |
313 | crc->cnt = 0; | 299 | case RP_ERROR: |
314 | crc->phase++; | 300 | ok = 1; |
315 | GNUNET_SCHEDULER_add_now (&test, crc); | 301 | GNUNET_break(0); |
302 | crc->api->drop(crc->api->cls); | ||
303 | GNUNET_SCHEDULER_add_now(&cleaning_task, crc); | ||
316 | break; | 304 | break; |
317 | } | 305 | |
318 | gen_key (5, &key); | 306 | case RP_PUT: |
319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 307 | do_put(crc); |
320 | "Looking for %s\n", | ||
321 | GNUNET_h2s (&key)); | ||
322 | crc->api->get_key (crc->api->cls, | ||
323 | 0, | ||
324 | false, | ||
325 | &key, | ||
326 | GNUNET_BLOCK_TYPE_ANY, | ||
327 | &iterate_one_shot, | ||
328 | crc); | ||
329 | break; | ||
330 | case RP_ITER_ZERO: | ||
331 | if (crc->cnt == 1) | ||
332 | { | ||
333 | crc->cnt = 0; | ||
334 | crc->phase++; | ||
335 | GNUNET_SCHEDULER_add_now (&test, crc); | ||
336 | break; | 308 | break; |
337 | } | 309 | |
338 | crc->api->get_zero_anonymity (crc->api->cls, 0, 1, &iterate_one_shot, crc); | 310 | case RP_GET: |
339 | break; | 311 | if (crc->cnt == 1) |
340 | case RP_REPL_GET: | 312 | { |
341 | crc->api->get_replication (crc->api->cls, &iterate_one_shot, crc); | 313 | crc->cnt = 0; |
342 | break; | 314 | crc->phase++; |
343 | case RP_EXPI_GET: | 315 | GNUNET_SCHEDULER_add_now(&test, crc); |
344 | crc->api->get_expiration (crc->api->cls, &iterate_one_shot, crc); | 316 | break; |
345 | break; | 317 | } |
346 | case RP_REMOVE: | 318 | gen_key(5, &key); |
319 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
320 | "Looking for %s\n", | ||
321 | GNUNET_h2s(&key)); | ||
322 | crc->api->get_key(crc->api->cls, | ||
323 | 0, | ||
324 | false, | ||
325 | &key, | ||
326 | GNUNET_BLOCK_TYPE_ANY, | ||
327 | &iterate_one_shot, | ||
328 | crc); | ||
329 | break; | ||
330 | |||
331 | case RP_ITER_ZERO: | ||
332 | if (crc->cnt == 1) | ||
333 | { | ||
334 | crc->cnt = 0; | ||
335 | crc->phase++; | ||
336 | GNUNET_SCHEDULER_add_now(&test, crc); | ||
337 | break; | ||
338 | } | ||
339 | crc->api->get_zero_anonymity(crc->api->cls, 0, 1, &iterate_one_shot, crc); | ||
340 | break; | ||
341 | |||
342 | case RP_REPL_GET: | ||
343 | crc->api->get_replication(crc->api->cls, &iterate_one_shot, crc); | ||
344 | break; | ||
345 | |||
346 | case RP_EXPI_GET: | ||
347 | crc->api->get_expiration(crc->api->cls, &iterate_one_shot, crc); | ||
348 | break; | ||
349 | |||
350 | case RP_REMOVE: | ||
347 | { | 351 | { |
348 | struct GNUNET_HashCode key; | 352 | struct GNUNET_HashCode key; |
349 | uint32_t size = 32768; | 353 | uint32_t size = 32768; |
350 | char value[size]; | 354 | char value[size]; |
351 | 355 | ||
352 | gen_key (0, &key); | 356 | gen_key(0, &key); |
353 | memset (value, 0, size); | 357 | memset(value, 0, size); |
354 | value[0] = crc->i; | 358 | value[0] = crc->i; |
355 | crc->api->remove_key (crc->api->cls, | 359 | crc->api->remove_key(crc->api->cls, |
356 | &key, | 360 | &key, |
357 | size, | 361 | size, |
358 | value, | 362 | value, |
359 | &remove_continuation, | 363 | &remove_continuation, |
360 | crc); | 364 | crc); |
365 | break; | ||
366 | } | ||
367 | |||
368 | case RP_DROP: | ||
369 | crc->api->drop(crc->api->cls); | ||
370 | GNUNET_SCHEDULER_add_now(&cleaning_task, crc); | ||
361 | break; | 371 | break; |
362 | } | 372 | } |
363 | case RP_DROP: | ||
364 | crc->api->drop (crc->api->cls); | ||
365 | GNUNET_SCHEDULER_add_now (&cleaning_task, crc); | ||
366 | break; | ||
367 | } | ||
368 | } | 373 | } |
369 | 374 | ||
370 | 375 | ||
@@ -372,7 +377,7 @@ test (void *cls) | |||
372 | * Load the datastore plugin. | 377 | * Load the datastore plugin. |
373 | */ | 378 | */ |
374 | static struct GNUNET_DATASTORE_PluginFunctions * | 379 | static struct GNUNET_DATASTORE_PluginFunctions * |
375 | load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | 380 | load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg) |
376 | { | 381 | { |
377 | static struct GNUNET_DATASTORE_PluginEnvironment env; | 382 | static struct GNUNET_DATASTORE_PluginEnvironment env; |
378 | struct GNUNET_DATASTORE_PluginFunctions *ret; | 383 | struct GNUNET_DATASTORE_PluginFunctions *ret; |
@@ -380,61 +385,61 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
380 | char *libname; | 385 | char *libname; |
381 | 386 | ||
382 | if (GNUNET_OK != | 387 | if (GNUNET_OK != |
383 | GNUNET_CONFIGURATION_get_value_string (cfg, | 388 | GNUNET_CONFIGURATION_get_value_string(cfg, |
384 | "DATASTORE", | 389 | "DATASTORE", |
385 | "DATABASE", | 390 | "DATABASE", |
386 | &name)) | 391 | &name)) |
387 | { | 392 | { |
388 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 393 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
389 | _("No `%s' specified for `%s' in configuration!\n"), | 394 | _("No `%s' specified for `%s' in configuration!\n"), |
390 | "DATABASE", | 395 | "DATABASE", |
391 | "DATASTORE"); | 396 | "DATASTORE"); |
392 | return NULL; | 397 | return NULL; |
393 | } | 398 | } |
394 | env.cfg = cfg; | 399 | env.cfg = cfg; |
395 | env.duc = &disk_utilization_change_cb; | 400 | env.duc = &disk_utilization_change_cb; |
396 | env.cls = NULL; | 401 | env.cls = NULL; |
397 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"), | 402 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"), |
398 | name); | 403 | name); |
399 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); | 404 | GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", name); |
400 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) | 405 | if (NULL == (ret = GNUNET_PLUGIN_load(libname, &env))) |
401 | { | 406 | { |
402 | fprintf (stderr, "Failed to load plugin `%s'!\n", name); | 407 | fprintf(stderr, "Failed to load plugin `%s'!\n", name); |
403 | GNUNET_free (libname); | 408 | GNUNET_free(libname); |
404 | GNUNET_free (name); | 409 | GNUNET_free(name); |
405 | ok = 77; /* mark test as skipped */ | 410 | ok = 77; /* mark test as skipped */ |
406 | return NULL; | 411 | return NULL; |
407 | } | 412 | } |
408 | GNUNET_free (libname); | 413 | GNUNET_free(libname); |
409 | GNUNET_free (name); | 414 | GNUNET_free(name); |
410 | return ret; | 415 | return ret; |
411 | } | 416 | } |
412 | 417 | ||
413 | 418 | ||
414 | static void | 419 | static void |
415 | run (void *cls, char *const *args, const char *cfgfile, | 420 | run(void *cls, char *const *args, const char *cfgfile, |
416 | const struct GNUNET_CONFIGURATION_Handle *c) | 421 | const struct GNUNET_CONFIGURATION_Handle *c) |
417 | { | 422 | { |
418 | struct GNUNET_DATASTORE_PluginFunctions *api; | 423 | struct GNUNET_DATASTORE_PluginFunctions *api; |
419 | struct CpsRunContext *crc; | 424 | struct CpsRunContext *crc; |
420 | 425 | ||
421 | api = load_plugin (c); | 426 | api = load_plugin(c); |
422 | if (api == NULL) | 427 | if (api == NULL) |
423 | { | 428 | { |
424 | fprintf (stderr, | 429 | fprintf(stderr, |
425 | "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); | 430 | "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); |
426 | return; | 431 | return; |
427 | } | 432 | } |
428 | crc = GNUNET_new (struct CpsRunContext); | 433 | crc = GNUNET_new(struct CpsRunContext); |
429 | crc->api = api; | 434 | crc->api = api; |
430 | crc->cfg = c; | 435 | crc->cfg = c; |
431 | crc->phase = RP_PUT; | 436 | crc->phase = RP_PUT; |
432 | GNUNET_SCHEDULER_add_now (&test, crc); | 437 | GNUNET_SCHEDULER_add_now(&test, crc); |
433 | } | 438 | } |
434 | 439 | ||
435 | 440 | ||
436 | int | 441 | int |
437 | main (int argc, char *argv[]) | 442 | main(int argc, char *argv[]) |
438 | { | 443 | { |
439 | char dir_name[PATH_MAX]; | 444 | char dir_name[PATH_MAX]; |
440 | char cfg_name[PATH_MAX]; | 445 | char cfg_name[PATH_MAX]; |
@@ -449,20 +454,20 @@ main (int argc, char *argv[]) | |||
449 | }; | 454 | }; |
450 | 455 | ||
451 | /* determine name of plugin to use */ | 456 | /* determine name of plugin to use */ |
452 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 457 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); |
453 | GNUNET_snprintf (dir_name, sizeof (dir_name), | 458 | GNUNET_snprintf(dir_name, sizeof(dir_name), |
454 | "/tmp/test-gnunet-datastore-plugin-%s", plugin_name); | 459 | "/tmp/test-gnunet-datastore-plugin-%s", plugin_name); |
455 | GNUNET_DISK_directory_remove (dir_name); | 460 | GNUNET_DISK_directory_remove(dir_name); |
456 | GNUNET_log_setup ("test-plugin-datastore", | 461 | GNUNET_log_setup("test-plugin-datastore", |
457 | "WARNING", | 462 | "WARNING", |
458 | NULL); | 463 | NULL); |
459 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), | 464 | GNUNET_snprintf(cfg_name, sizeof(cfg_name), |
460 | "test_plugin_datastore_data_%s.conf", plugin_name); | 465 | "test_plugin_datastore_data_%s.conf", plugin_name); |
461 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, | 466 | GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, xargv, |
462 | "test-plugin-datastore", "nohelp", options, &run, NULL); | 467 | "test-plugin-datastore", "nohelp", options, &run, NULL); |
463 | if ( (0 != ok) && (77 != ok) ) | 468 | if ((0 != ok) && (77 != ok)) |
464 | fprintf (stderr, "Missed some testcases: %u\n", ok); | 469 | fprintf(stderr, "Missed some testcases: %u\n", ok); |
465 | GNUNET_DISK_directory_remove (dir_name); | 470 | GNUNET_DISK_directory_remove(dir_name); |
466 | return ok; | 471 | return ok; |
467 | } | 472 | } |
468 | 473 | ||