diff options
Diffstat (limited to 'src/datastore')
-rw-r--r-- | src/datastore/gnunet-datastore.c | 120 | ||||
-rw-r--r-- | src/datastore/gnunet-service-datastore.c | 622 | ||||
-rw-r--r-- | src/datastore/perf_datastore_api.c | 10 | ||||
-rw-r--r-- | src/datastore/perf_plugin_datastore.c | 8 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_sqlite.c | 893 | ||||
-rw-r--r-- | src/datastore/test_datastore_api.c | 10 | ||||
-rw-r--r-- | src/datastore/test_datastore_api_management.c | 4 | ||||
-rw-r--r-- | src/datastore/test_plugin_datastore.c | 8 |
8 files changed, 765 insertions, 910 deletions
diff --git a/src/datastore/gnunet-datastore.c b/src/datastore/gnunet-datastore.c index cd089071c..4cf318777 100644 --- a/src/datastore/gnunet-datastore.c +++ b/src/datastore/gnunet-datastore.c | |||
@@ -66,7 +66,6 @@ struct DataRecord | |||
66 | * Key under which the item can be found. | 66 | * Key under which the item can be found. |
67 | */ | 67 | */ |
68 | struct GNUNET_HashCode key; | 68 | struct GNUNET_HashCode key; |
69 | |||
70 | }; | 69 | }; |
71 | GNUNET_NETWORK_STRUCT_END | 70 | GNUNET_NETWORK_STRUCT_END |
72 | 71 | ||
@@ -185,13 +184,11 @@ get_cb (void *cls, | |||
185 | qe = NULL; | 184 | qe = NULL; |
186 | if (NULL == key) | 185 | if (NULL == key) |
187 | { | 186 | { |
188 | FPRINTF (stderr, | 187 | fprintf (stderr, _ ("Dumped %" PRIu64 " records\n"), record_count); |
189 | _("Dumped %" PRIu64 " records\n"), | ||
190 | record_count); | ||
191 | GNUNET_DISK_file_close (file_handle); | 188 | GNUNET_DISK_file_close (file_handle); |
192 | file_handle = NULL; | 189 | file_handle = NULL; |
193 | if (insert) | 190 | if (insert) |
194 | start_insert(); | 191 | start_insert (); |
195 | else | 192 | else |
196 | { | 193 | { |
197 | ret = 0; | 194 | ret = 0; |
@@ -213,8 +210,8 @@ get_cb (void *cls, | |||
213 | len = GNUNET_DISK_file_write (file_handle, &dr, sizeof (dr)); | 210 | len = GNUNET_DISK_file_write (file_handle, &dr, sizeof (dr)); |
214 | if (sizeof (dr) != len) | 211 | if (sizeof (dr) != len) |
215 | { | 212 | { |
216 | FPRINTF (stderr, | 213 | fprintf (stderr, |
217 | _("Short write to file: %zd bytes expecting %zd\n"), | 214 | _ ("Short write to file: %zd bytes expecting %zd\n"), |
218 | len, | 215 | len, |
219 | sizeof (dr)); | 216 | sizeof (dr)); |
220 | ret = 1; | 217 | ret = 1; |
@@ -225,8 +222,8 @@ get_cb (void *cls, | |||
225 | len = GNUNET_DISK_file_write (file_handle, data, size); | 222 | len = GNUNET_DISK_file_write (file_handle, data, size); |
226 | if (size != len) | 223 | if (size != len) |
227 | { | 224 | { |
228 | FPRINTF (stderr, | 225 | fprintf (stderr, |
229 | _("Short write to file: %zd bytes expecting %zd\n"), | 226 | _ ("Short write to file: %zd bytes expecting %zd\n"), |
230 | len, | 227 | len, |
231 | size); | 228 | size); |
232 | ret = 1; | 229 | ret = 1; |
@@ -235,7 +232,7 @@ get_cb (void *cls, | |||
235 | } | 232 | } |
236 | 233 | ||
237 | record_count++; | 234 | record_count++; |
238 | do_get(uid + 1); | 235 | do_get (uid + 1); |
239 | } | 236 | } |
240 | 237 | ||
241 | 238 | ||
@@ -257,8 +254,7 @@ do_get (const uint64_t next_uid) | |||
257 | NULL /* proc_cls */); | 254 | NULL /* proc_cls */); |
258 | if (NULL == qe) | 255 | if (NULL == qe) |
259 | { | 256 | { |
260 | FPRINTF (stderr, | 257 | fprintf (stderr, _ ("Error queueing datastore GET operation\n")); |
261 | _("Error queueing datastore GET operation\n")); | ||
262 | ret = 1; | 258 | ret = 1; |
263 | GNUNET_SCHEDULER_shutdown (); | 259 | GNUNET_SCHEDULER_shutdown (); |
264 | } | 260 | } |
@@ -277,15 +273,13 @@ start_dump () | |||
277 | { | 273 | { |
278 | file_handle = GNUNET_DISK_file_open (file_name, | 274 | file_handle = GNUNET_DISK_file_open (file_name, |
279 | GNUNET_DISK_OPEN_WRITE | | 275 | GNUNET_DISK_OPEN_WRITE | |
280 | GNUNET_DISK_OPEN_TRUNCATE | | 276 | GNUNET_DISK_OPEN_TRUNCATE | |
281 | GNUNET_DISK_OPEN_CREATE, | 277 | GNUNET_DISK_OPEN_CREATE, |
282 | GNUNET_DISK_PERM_USER_READ | | 278 | GNUNET_DISK_PERM_USER_READ | |
283 | GNUNET_DISK_PERM_USER_WRITE); | 279 | GNUNET_DISK_PERM_USER_WRITE); |
284 | if (NULL == file_handle) | 280 | if (NULL == file_handle) |
285 | { | 281 | { |
286 | FPRINTF (stderr, | 282 | fprintf (stderr, _ ("Unable to open dump file: %s\n"), file_name); |
287 | _("Unable to open dump file: %s\n"), | ||
288 | file_name); | ||
289 | ret = 1; | 283 | ret = 1; |
290 | GNUNET_SCHEDULER_shutdown (); | 284 | GNUNET_SCHEDULER_shutdown (); |
291 | return; | 285 | return; |
@@ -296,7 +290,7 @@ start_dump () | |||
296 | file_handle = GNUNET_DISK_get_handle_from_int_fd (STDOUT_FILENO); | 290 | file_handle = GNUNET_DISK_get_handle_from_int_fd (STDOUT_FILENO); |
297 | } | 291 | } |
298 | GNUNET_DISK_file_write (file_handle, MAGIC_BYTES, MAGIC_LEN); | 292 | GNUNET_DISK_file_write (file_handle, MAGIC_BYTES, MAGIC_LEN); |
299 | do_get(0); | 293 | do_get (0); |
300 | } | 294 | } |
301 | 295 | ||
302 | 296 | ||
@@ -322,9 +316,7 @@ put_cb (void *cls, | |||
322 | qe = NULL; | 316 | qe = NULL; |
323 | if (GNUNET_SYSERR == success) | 317 | if (GNUNET_SYSERR == success) |
324 | { | 318 | { |
325 | FPRINTF (stderr, | 319 | fprintf (stderr, _ ("Failed to store item: %s, aborting\n"), msg); |
326 | _("Failed to store item: %s, aborting\n"), | ||
327 | msg); | ||
328 | ret = 1; | 320 | ret = 1; |
329 | GNUNET_SCHEDULER_shutdown (); | 321 | GNUNET_SCHEDULER_shutdown (); |
330 | return; | 322 | return; |
@@ -336,17 +328,15 @@ put_cb (void *cls, | |||
336 | len = GNUNET_DISK_file_read (file_handle, &dr, sizeof (dr)); | 328 | len = GNUNET_DISK_file_read (file_handle, &dr, sizeof (dr)); |
337 | if (0 == len) | 329 | if (0 == len) |
338 | { | 330 | { |
339 | FPRINTF (stderr, | 331 | fprintf (stderr, _ ("Inserted %" PRIu64 " records\n"), record_count); |
340 | _("Inserted %" PRIu64 " records\n"), | ||
341 | record_count); | ||
342 | ret = 0; | 332 | ret = 0; |
343 | GNUNET_SCHEDULER_shutdown (); | 333 | GNUNET_SCHEDULER_shutdown (); |
344 | return; | 334 | return; |
345 | } | 335 | } |
346 | else if (sizeof (dr) != len) | 336 | else if (sizeof (dr) != len) |
347 | { | 337 | { |
348 | FPRINTF (stderr, | 338 | fprintf (stderr, |
349 | _("Short read from file: %zd bytes expecting %zd\n"), | 339 | _ ("Short read from file: %zd bytes expecting %zd\n"), |
350 | len, | 340 | len, |
351 | sizeof (dr)); | 341 | sizeof (dr)); |
352 | ret = 1; | 342 | ret = 1; |
@@ -359,8 +349,8 @@ put_cb (void *cls, | |||
359 | len = GNUNET_DISK_file_read (file_handle, data, size); | 349 | len = GNUNET_DISK_file_read (file_handle, data, size); |
360 | if (size != len) | 350 | if (size != len) |
361 | { | 351 | { |
362 | FPRINTF (stderr, | 352 | fprintf (stderr, |
363 | _("Short read from file: %zd bytes expecting %zd\n"), | 353 | _ ("Short read from file: %zd bytes expecting %zd\n"), |
364 | len, | 354 | len, |
365 | size); | 355 | size); |
366 | ret = 1; | 356 | ret = 1; |
@@ -385,8 +375,7 @@ put_cb (void *cls, | |||
385 | NULL); | 375 | NULL); |
386 | if (NULL == qe) | 376 | if (NULL == qe) |
387 | { | 377 | { |
388 | FPRINTF (stderr, | 378 | fprintf (stderr, _ ("Error queueing datastore PUT operation\n")); |
389 | _("Error queueing datastore PUT operation\n")); | ||
390 | ret = 1; | 379 | ret = 1; |
391 | GNUNET_SCHEDULER_shutdown (); | 380 | GNUNET_SCHEDULER_shutdown (); |
392 | } | 381 | } |
@@ -408,9 +397,7 @@ start_insert () | |||
408 | GNUNET_DISK_PERM_NONE); | 397 | GNUNET_DISK_PERM_NONE); |
409 | if (NULL == file_handle) | 398 | if (NULL == file_handle) |
410 | { | 399 | { |
411 | FPRINTF (stderr, | 400 | fprintf (stderr, _ ("Unable to open dump file: %s\n"), file_name); |
412 | _("Unable to open dump file: %s\n"), | ||
413 | file_name); | ||
414 | ret = 1; | 401 | ret = 1; |
415 | GNUNET_SCHEDULER_shutdown (); | 402 | GNUNET_SCHEDULER_shutdown (); |
416 | return; | 403 | return; |
@@ -425,11 +412,9 @@ start_insert () | |||
425 | ssize_t len; | 412 | ssize_t len; |
426 | 413 | ||
427 | len = GNUNET_DISK_file_read (file_handle, buf, MAGIC_LEN); | 414 | len = GNUNET_DISK_file_read (file_handle, buf, MAGIC_LEN); |
428 | if (len != MAGIC_LEN || | 415 | if (len != MAGIC_LEN || 0 != memcmp (buf, MAGIC_BYTES, MAGIC_LEN)) |
429 | 0 != memcmp (buf, MAGIC_BYTES, MAGIC_LEN)) | ||
430 | { | 416 | { |
431 | FPRINTF (stderr, | 417 | fprintf (stderr, _ ("Input file is not of a supported format\n")); |
432 | _("Input file is not of a supported format\n")); | ||
433 | return; | 418 | return; |
434 | } | 419 | } |
435 | put_cb (NULL, GNUNET_YES, GNUNET_TIME_UNIT_ZERO_ABS, NULL); | 420 | put_cb (NULL, GNUNET_YES, GNUNET_TIME_UNIT_ZERO_ABS, NULL); |
@@ -454,20 +439,19 @@ run (void *cls, | |||
454 | datastore = GNUNET_DATASTORE_connect (cfg); | 439 | datastore = GNUNET_DATASTORE_connect (cfg); |
455 | if (NULL == datastore) | 440 | if (NULL == datastore) |
456 | { | 441 | { |
457 | FPRINTF (stderr, | 442 | fprintf (stderr, _ ("Failed connecting to the datastore.\n")); |
458 | _("Failed connecting to the datastore.\n")); | ||
459 | ret = 1; | 443 | ret = 1; |
460 | GNUNET_SCHEDULER_shutdown (); | 444 | GNUNET_SCHEDULER_shutdown (); |
461 | return; | 445 | return; |
462 | } | 446 | } |
463 | if (dump) | 447 | if (dump) |
464 | start_dump(); | 448 | start_dump (); |
465 | else if (insert) | 449 | else if (insert) |
466 | start_insert(); | 450 | start_insert (); |
467 | else | 451 | else |
468 | { | 452 | { |
469 | FPRINTF (stderr, | 453 | fprintf (stderr, |
470 | _("Please choose at least one operation: %s, %s\n"), | 454 | _ ("Please choose at least one operation: %s, %s\n"), |
471 | "dump", | 455 | "dump", |
472 | "insert"); | 456 | "insert"); |
473 | ret = 1; | 457 | ret = 1; |
@@ -484,34 +468,38 @@ run (void *cls, | |||
484 | * @return 0 ok, 1 on error | 468 | * @return 0 ok, 1 on error |
485 | */ | 469 | */ |
486 | int | 470 | int |
487 | main (int argc, | 471 | main (int argc, char *const *argv) |
488 | char *const *argv) | ||
489 | { | 472 | { |
490 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 473 | struct GNUNET_GETOPT_CommandLineOption options[] = |
491 | GNUNET_GETOPT_option_flag ('d', | 474 | {GNUNET_GETOPT_option_flag ('d', |
492 | "dump", | 475 | "dump", |
493 | gettext_noop ("Dump all records from the datastore"), | 476 | gettext_noop ( |
494 | &dump), | 477 | "Dump all records from the datastore"), |
495 | GNUNET_GETOPT_option_flag ('i', | 478 | &dump), |
496 | "insert", | 479 | GNUNET_GETOPT_option_flag ('i', |
497 | gettext_noop ("Insert records into the datastore"), | 480 | "insert", |
498 | &insert), | 481 | gettext_noop ( |
499 | GNUNET_GETOPT_option_filename ('f', | 482 | "Insert records into the datastore"), |
500 | "file", | 483 | &insert), |
501 | "FILENAME", | 484 | GNUNET_GETOPT_option_filename ('f', |
502 | gettext_noop ("File to dump or insert"), | 485 | "file", |
503 | &file_name), | 486 | "FILENAME", |
504 | GNUNET_GETOPT_OPTION_END | 487 | gettext_noop ("File to dump or insert"), |
505 | }; | 488 | &file_name), |
489 | GNUNET_GETOPT_OPTION_END}; | ||
506 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 490 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
507 | return 2; | 491 | return 2; |
508 | 492 | ||
509 | if (GNUNET_OK != | 493 | if (GNUNET_OK != |
510 | GNUNET_PROGRAM_run (argc, argv, "gnunet-datastore", | 494 | GNUNET_PROGRAM_run (argc, |
511 | gettext_noop ("Manipulate GNUnet datastore"), | 495 | argv, |
512 | options, &run, NULL)) | 496 | "gnunet-datastore", |
497 | gettext_noop ("Manipulate GNUnet datastore"), | ||
498 | options, | ||
499 | &run, | ||
500 | NULL)) | ||
513 | ret = 1; | 501 | ret = 1; |
514 | GNUNET_free ((void*) argv); | 502 | GNUNET_free ((void *) argv); |
515 | return ret; | 503 | return ret; |
516 | } | 504 | } |
517 | 505 | ||
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index 70a946ca5..4596f6131 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c | |||
@@ -45,13 +45,15 @@ | |||
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 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | 48 | #define MAX_EXPIRE_DELAY \ |
49 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | ||
49 | 50 | ||
50 | /** | 51 | /** |
51 | * How fast are we allowed to query the database for deleting | 52 | * How fast are we allowed to query the database for deleting |
52 | * expired content? (1 item per second). | 53 | * expired content? (1 item per second). |
53 | */ | 54 | */ |
54 | #define MIN_EXPIRE_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 55 | #define MIN_EXPIRE_DELAY \ |
56 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | ||
55 | 57 | ||
56 | /** | 58 | /** |
57 | * Name under which we store current space consumption. | 59 | * Name under which we store current space consumption. |
@@ -97,7 +99,6 @@ struct DatastorePlugin | |||
97 | * for this plugin. | 99 | * for this plugin. |
98 | */ | 100 | */ |
99 | struct GNUNET_DATASTORE_PluginEnvironment env; | 101 | struct GNUNET_DATASTORE_PluginEnvironment env; |
100 | |||
101 | }; | 102 | }; |
102 | 103 | ||
103 | 104 | ||
@@ -131,11 +132,9 @@ struct ReservationList | |||
131 | * Reservation identifier. | 132 | * Reservation identifier. |
132 | */ | 133 | */ |
133 | int32_t rid; | 134 | int32_t rid; |
134 | |||
135 | }; | 135 | }; |
136 | 136 | ||
137 | 137 | ||
138 | |||
139 | /** | 138 | /** |
140 | * Our datastore plugin (NULL if not available). | 139 | * Our datastore plugin (NULL if not available). |
141 | */ | 140 | */ |
@@ -234,10 +233,7 @@ static int stats_worked; | |||
234 | static void | 233 | static void |
235 | sync_stats () | 234 | sync_stats () |
236 | { | 235 | { |
237 | GNUNET_STATISTICS_set (stats, | 236 | GNUNET_STATISTICS_set (stats, quota_stat_name, payload, GNUNET_YES); |
238 | quota_stat_name, | ||
239 | payload, | ||
240 | GNUNET_YES); | ||
241 | GNUNET_STATISTICS_set (stats, | 237 | GNUNET_STATISTICS_set (stats, |
242 | "# utilization by current datastore", | 238 | "# utilization by current datastore", |
243 | payload, | 239 | payload, |
@@ -312,9 +308,10 @@ expired_processor (void *cls, | |||
312 | if (NULL == key) | 308 | if (NULL == key) |
313 | { | 309 | { |
314 | expired_kill_task = | 310 | expired_kill_task = |
315 | GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY, | 311 | GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY, |
316 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 312 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
317 | &delete_expired, NULL); | 313 | &delete_expired, |
314 | NULL); | ||
318 | return GNUNET_SYSERR; | 315 | return GNUNET_SYSERR; |
319 | } | 316 | } |
320 | now = GNUNET_TIME_absolute_get (); | 317 | now = GNUNET_TIME_absolute_get (); |
@@ -322,17 +319,19 @@ expired_processor (void *cls, | |||
322 | { | 319 | { |
323 | /* finished processing */ | 320 | /* finished processing */ |
324 | expired_kill_task = | 321 | expired_kill_task = |
325 | GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY, | 322 | GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY, |
326 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 323 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
327 | &delete_expired, NULL); | 324 | &delete_expired, |
325 | NULL); | ||
328 | return GNUNET_SYSERR; | 326 | return GNUNET_SYSERR; |
329 | } | 327 | } |
330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
331 | "Deleting content `%s' of type %u that expired %s ago\n", | 329 | "Deleting content `%s' of type %u that expired %s ago\n", |
332 | GNUNET_h2s (key), type, | 330 | GNUNET_h2s (key), |
333 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (expiration, | 331 | type, |
334 | now), | 332 | GNUNET_STRINGS_relative_time_to_string ( |
335 | GNUNET_YES)); | 333 | GNUNET_TIME_absolute_get_difference (expiration, now), |
334 | GNUNET_YES)); | ||
336 | min_expiration = now; | 335 | min_expiration = now; |
337 | GNUNET_STATISTICS_update (stats, | 336 | GNUNET_STATISTICS_update (stats, |
338 | gettext_noop ("# bytes expired"), | 337 | gettext_noop ("# bytes expired"), |
@@ -340,9 +339,10 @@ expired_processor (void *cls, | |||
340 | GNUNET_YES); | 339 | GNUNET_YES); |
341 | GNUNET_CONTAINER_bloomfilter_remove (filter, key); | 340 | GNUNET_CONTAINER_bloomfilter_remove (filter, key); |
342 | expired_kill_task = | 341 | expired_kill_task = |
343 | GNUNET_SCHEDULER_add_delayed_with_priority (MIN_EXPIRE_DELAY, | 342 | GNUNET_SCHEDULER_add_delayed_with_priority (MIN_EXPIRE_DELAY, |
344 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 343 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
345 | &delete_expired, NULL); | 344 | &delete_expired, |
345 | NULL); | ||
346 | return GNUNET_NO; | 346 | return GNUNET_NO; |
347 | } | 347 | } |
348 | 348 | ||
@@ -359,9 +359,7 @@ static void | |||
359 | delete_expired (void *cls) | 359 | delete_expired (void *cls) |
360 | { | 360 | { |
361 | expired_kill_task = NULL; | 361 | expired_kill_task = NULL; |
362 | plugin->api->get_expiration (plugin->api->cls, | 362 | plugin->api->get_expiration (plugin->api->cls, &expired_processor, NULL); |
363 | &expired_processor, | ||
364 | NULL); | ||
365 | } | 363 | } |
366 | 364 | ||
367 | 365 | ||
@@ -400,14 +398,17 @@ quota_processor (void *cls, | |||
400 | 398 | ||
401 | if (NULL == key) | 399 | if (NULL == key) |
402 | return GNUNET_SYSERR; | 400 | return GNUNET_SYSERR; |
403 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 401 | GNUNET_log ( |
404 | "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", | 402 | GNUNET_ERROR_TYPE_DEBUG, |
405 | (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD), | 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", |
406 | (unsigned int) priority, | 404 | (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD), |
407 | GNUNET_h2s (key), type, | 405 | (unsigned int) priority, |
408 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration), | 406 | GNUNET_h2s (key), |
409 | GNUNET_YES), | 407 | type, |
410 | *need); | 408 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining ( |
409 | expiration), | ||
410 | GNUNET_YES), | ||
411 | *need); | ||
411 | if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need) | 412 | if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need) |
412 | *need = 0; | 413 | *need = 0; |
413 | else | 414 | else |
@@ -418,7 +419,8 @@ quota_processor (void *cls, | |||
418 | min_expiration = expiration; | 419 | min_expiration = expiration; |
419 | GNUNET_STATISTICS_update (stats, | 420 | GNUNET_STATISTICS_update (stats, |
420 | gettext_noop ("# bytes purged (low-priority)"), | 421 | gettext_noop ("# bytes purged (low-priority)"), |
421 | size, GNUNET_YES); | 422 | size, |
423 | GNUNET_YES); | ||
422 | GNUNET_CONTAINER_bloomfilter_remove (filter, key); | 424 | GNUNET_CONTAINER_bloomfilter_remove (filter, key); |
423 | return GNUNET_NO; | 425 | return GNUNET_NO; |
424 | } | 426 | } |
@@ -448,9 +450,7 @@ manage_space (unsigned long long need) | |||
448 | while ((need > 0) && (last != need)) | 450 | while ((need > 0) && (last != need)) |
449 | { | 451 | { |
450 | last = need; | 452 | last = need; |
451 | plugin->api->get_expiration (plugin->api->cls, | 453 | plugin->api->get_expiration (plugin->api->cls, "a_processor, &need); |
452 | "a_processor, | ||
453 | &need); | ||
454 | } | 454 | } |
455 | } | 455 | } |
456 | 456 | ||
@@ -473,18 +473,15 @@ transmit_status (struct GNUNET_SERVICE_Client *client, | |||
473 | 473 | ||
474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
475 | "Transmitting `%s' message with value %d and message `%s'\n", | 475 | "Transmitting `%s' message with value %d and message `%s'\n", |
476 | "STATUS", code, msg != NULL ? msg : "(none)"); | 476 | "STATUS", |
477 | code, | ||
478 | msg != NULL ? msg : "(none)"); | ||
477 | slen = (msg == NULL) ? 0 : strlen (msg) + 1; | 479 | slen = (msg == NULL) ? 0 : strlen (msg) + 1; |
478 | env = GNUNET_MQ_msg_extra (sm, | 480 | env = GNUNET_MQ_msg_extra (sm, slen, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS); |
479 | slen, | ||
480 | GNUNET_MESSAGE_TYPE_DATASTORE_STATUS); | ||
481 | sm->status = htonl (code); | 481 | sm->status = htonl (code); |
482 | sm->min_expiration = GNUNET_TIME_absolute_hton (min_expiration); | 482 | sm->min_expiration = GNUNET_TIME_absolute_hton (min_expiration); |
483 | GNUNET_memcpy (&sm[1], | 483 | GNUNET_memcpy (&sm[1], msg, slen); |
484 | msg, | 484 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); |
485 | slen); | ||
486 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | ||
487 | env); | ||
488 | } | 485 | } |
489 | 486 | ||
490 | 487 | ||
@@ -526,19 +523,13 @@ transmit_item (void *cls, | |||
526 | if (NULL == key) | 523 | if (NULL == key) |
527 | { | 524 | { |
528 | /* transmit 'DATA_END' */ | 525 | /* transmit 'DATA_END' */ |
529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 526 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting DATA_END message\n"); |
530 | "Transmitting DATA_END message\n"); | 527 | env = GNUNET_MQ_msg (end, GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END); |
531 | env = GNUNET_MQ_msg (end, | 528 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); |
532 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END); | ||
533 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | ||
534 | env); | ||
535 | return GNUNET_OK; | 529 | return GNUNET_OK; |
536 | } | 530 | } |
537 | GNUNET_assert (sizeof (struct DataMessage) + size < | 531 | GNUNET_assert (sizeof (struct DataMessage) + size < GNUNET_MAX_MESSAGE_SIZE); |
538 | GNUNET_MAX_MESSAGE_SIZE); | 532 | env = GNUNET_MQ_msg_extra (dm, size, GNUNET_MESSAGE_TYPE_DATASTORE_DATA); |
539 | env = GNUNET_MQ_msg_extra (dm, | ||
540 | size, | ||
541 | GNUNET_MESSAGE_TYPE_DATASTORE_DATA); | ||
542 | dm->rid = htonl (0); | 533 | dm->rid = htonl (0); |
543 | dm->size = htonl (size); | 534 | dm->size = htonl (size); |
544 | dm->type = htonl (type); | 535 | dm->type = htonl (type); |
@@ -548,22 +539,21 @@ transmit_item (void *cls, | |||
548 | dm->expiration = GNUNET_TIME_absolute_hton (expiration); | 539 | dm->expiration = GNUNET_TIME_absolute_hton (expiration); |
549 | dm->uid = GNUNET_htonll (uid); | 540 | dm->uid = GNUNET_htonll (uid); |
550 | dm->key = *key; | 541 | dm->key = *key; |
551 | GNUNET_memcpy (&dm[1], | 542 | GNUNET_memcpy (&dm[1], data, size); |
552 | data, | 543 | GNUNET_log ( |
553 | size); | 544 | GNUNET_ERROR_TYPE_DEBUG, |
554 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 545 | "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n", |
555 | "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n", | 546 | GNUNET_h2s (key), |
556 | GNUNET_h2s (key), | 547 | type, |
557 | type, | 548 | GNUNET_STRINGS_absolute_time_to_string (expiration), |
558 | GNUNET_STRINGS_absolute_time_to_string (expiration), | 549 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining ( |
559 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration), | 550 | expiration), |
560 | GNUNET_YES)); | 551 | GNUNET_YES)); |
561 | GNUNET_STATISTICS_update (stats, | 552 | GNUNET_STATISTICS_update (stats, |
562 | gettext_noop ("# results found"), | 553 | gettext_noop ("# results found"), |
563 | 1, | 554 | 1, |
564 | GNUNET_NO); | 555 | GNUNET_NO); |
565 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 556 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); |
566 | env); | ||
567 | return GNUNET_OK; | 557 | return GNUNET_OK; |
568 | } | 558 | } |
569 | 559 | ||
@@ -575,8 +565,7 @@ transmit_item (void *cls, | |||
575 | * @param message the actual message | 565 | * @param message the actual message |
576 | */ | 566 | */ |
577 | static void | 567 | static void |
578 | handle_reserve (void *cls, | 568 | handle_reserve (void *cls, const struct ReserveMessage *msg) |
579 | const struct ReserveMessage *msg) | ||
580 | { | 569 | { |
581 | /** | 570 | /** |
582 | * Static counter to produce reservation identifiers. | 571 | * Static counter to produce reservation identifiers. |
@@ -589,20 +578,23 @@ handle_reserve (void *cls, | |||
589 | uint64_t amount; | 578 | uint64_t amount; |
590 | uint32_t entries; | 579 | uint32_t entries; |
591 | 580 | ||
592 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 581 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing RESERVE request\n"); |
593 | "Processing RESERVE request\n"); | ||
594 | amount = GNUNET_ntohll (msg->amount); | 582 | amount = GNUNET_ntohll (msg->amount); |
595 | entries = ntohl (msg->entries); | 583 | entries = ntohl (msg->entries); |
596 | used = payload + reserved; | 584 | used = payload + reserved; |
597 | req = amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries; | 585 | req = |
586 | amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries; | ||
598 | if (used + req > quota) | 587 | if (used + req > quota) |
599 | { | 588 | { |
600 | if (quota < used) | 589 | if (quota < used) |
601 | used = quota; /* cheat a bit for error message (to avoid negative numbers) */ | 590 | used = |
602 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 591 | quota; /* cheat a bit for error message (to avoid negative numbers) */ |
603 | _("Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"), | 592 | GNUNET_log ( |
604 | quota - used, | 593 | GNUNET_ERROR_TYPE_WARNING, |
605 | req); | 594 | _ ( |
595 | "Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"), | ||
596 | quota - used, | ||
597 | req); | ||
606 | if (cache_size < req) | 598 | if (cache_size < req) |
607 | { | 599 | { |
608 | /* TODO: document this in the FAQ; essentially, if this | 600 | /* TODO: document this in the FAQ; essentially, if this |
@@ -610,15 +602,17 @@ handle_reserve (void *cls, | |||
610 | * by less-important content from migration because it is | 602 | * by less-important content from migration because it is |
611 | * larger than 1/8th of the overall available space, and | 603 | * larger than 1/8th of the overall available space, and |
612 | * we only reserve 1/8th for "fresh" insertions */ | 604 | * we only reserve 1/8th for "fresh" insertions */ |
613 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 605 | GNUNET_log ( |
614 | _("The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"), | 606 | GNUNET_ERROR_TYPE_WARNING, |
615 | req, | 607 | _ ( |
616 | cache_size); | 608 | "The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"), |
609 | req, | ||
610 | cache_size); | ||
617 | transmit_status (client, | 611 | transmit_status (client, |
618 | 0, | 612 | 0, |
619 | gettext_noop | 613 | gettext_noop ( |
620 | ("Insufficient space to satisfy request and " | 614 | "Insufficient space to satisfy request and " |
621 | "requested amount is larger than cache size")); | 615 | "requested amount is larger than cache size")); |
622 | } | 616 | } |
623 | else | 617 | else |
624 | { | 618 | { |
@@ -642,10 +636,8 @@ handle_reserve (void *cls, | |||
642 | e->entries = entries; | 636 | e->entries = entries; |
643 | e->rid = ++reservation_gen; | 637 | e->rid = ++reservation_gen; |
644 | if (reservation_gen < 0) | 638 | if (reservation_gen < 0) |
645 | reservation_gen = 0; /* wrap around */ | 639 | reservation_gen = 0; /* wrap around */ |
646 | transmit_status (client, | 640 | transmit_status (client, e->rid, NULL); |
647 | e->rid, | ||
648 | NULL); | ||
649 | GNUNET_SERVICE_client_continue (client); | 641 | GNUNET_SERVICE_client_continue (client); |
650 | } | 642 | } |
651 | 643 | ||
@@ -657,8 +649,7 @@ handle_reserve (void *cls, | |||
657 | * @param message the actual message | 649 | * @param message the actual message |
658 | */ | 650 | */ |
659 | static void | 651 | static void |
660 | handle_release_reserve (void *cls, | 652 | handle_release_reserve (void *cls, const struct ReleaseReserveMessage *msg) |
661 | const struct ReleaseReserveMessage *msg) | ||
662 | { | 653 | { |
663 | struct GNUNET_SERVICE_Client *client = cls; | 654 | struct GNUNET_SERVICE_Client *client = cls; |
664 | struct ReservationList *pos; | 655 | struct ReservationList *pos; |
@@ -667,8 +658,7 @@ handle_release_reserve (void *cls, | |||
667 | int rid = ntohl (msg->rid); | 658 | int rid = ntohl (msg->rid); |
668 | unsigned long long rem; | 659 | unsigned long long rem; |
669 | 660 | ||
670 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 661 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing RELEASE_RESERVE request\n"); |
671 | "Processing RELEASE_RESERVE request\n"); | ||
672 | next = reservations; | 662 | next = reservations; |
673 | prev = NULL; | 663 | prev = NULL; |
674 | while (NULL != (pos = next)) | 664 | while (NULL != (pos = next)) |
@@ -681,8 +671,8 @@ handle_release_reserve (void *cls, | |||
681 | else | 671 | else |
682 | prev->next = next; | 672 | prev->next = next; |
683 | rem = | 673 | rem = |
684 | pos->amount + | 674 | pos->amount + |
685 | ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries; | 675 | ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries; |
686 | GNUNET_assert (reserved >= rem); | 676 | GNUNET_assert (reserved >= rem); |
687 | reserved -= rem; | 677 | reserved -= rem; |
688 | GNUNET_STATISTICS_set (stats, | 678 | GNUNET_STATISTICS_set (stats, |
@@ -693,9 +683,7 @@ handle_release_reserve (void *cls, | |||
693 | "Returning %llu remaining reserved bytes to storage pool\n", | 683 | "Returning %llu remaining reserved bytes to storage pool\n", |
694 | rem); | 684 | rem); |
695 | GNUNET_free (pos); | 685 | GNUNET_free (pos); |
696 | transmit_status (client, | 686 | transmit_status (client, GNUNET_OK, NULL); |
697 | GNUNET_OK, | ||
698 | NULL); | ||
699 | GNUNET_SERVICE_client_continue (client); | 687 | GNUNET_SERVICE_client_continue (client); |
700 | return; | 688 | return; |
701 | } | 689 | } |
@@ -757,8 +745,7 @@ put_continuation (void *cls, | |||
757 | gettext_noop ("# bytes stored"), | 745 | gettext_noop ("# bytes stored"), |
758 | size, | 746 | size, |
759 | GNUNET_YES); | 747 | GNUNET_YES); |
760 | GNUNET_CONTAINER_bloomfilter_add (filter, | 748 | GNUNET_CONTAINER_bloomfilter_add (filter, key); |
761 | key); | ||
762 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 749 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
763 | "Successfully stored %u bytes under key `%s'\n", | 750 | "Successfully stored %u bytes under key `%s'\n", |
764 | size, | 751 | size, |
@@ -770,7 +757,7 @@ put_continuation (void *cls, | |||
770 | if (quota - reserved - cache_size < payload) | 757 | if (quota - reserved - cache_size < payload) |
771 | { | 758 | { |
772 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 759 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
773 | _("Need %llu bytes more space (%llu allowed, using %llu)\n"), | 760 | _ ("Need %llu bytes more space (%llu allowed, using %llu)\n"), |
774 | (unsigned long long) size + GNUNET_DATASTORE_ENTRY_OVERHEAD, | 761 | (unsigned long long) size + GNUNET_DATASTORE_ENTRY_OVERHEAD, |
775 | (unsigned long long) (quota - reserved - cache_size), | 762 | (unsigned long long) (quota - reserved - cache_size), |
776 | (unsigned long long) payload); | 763 | (unsigned long long) payload); |
@@ -787,8 +774,7 @@ put_continuation (void *cls, | |||
787 | * @return #GNUNET_OK if @a dm is well-formed | 774 | * @return #GNUNET_OK if @a dm is well-formed |
788 | */ | 775 | */ |
789 | static int | 776 | static int |
790 | check_put (void *cls, | 777 | check_put (void *cls, const struct DataMessage *dm) |
791 | const struct DataMessage *dm) | ||
792 | { | 778 | { |
793 | if (GNUNET_OK != check_data (dm)) | 779 | if (GNUNET_OK != check_data (dm)) |
794 | { | 780 | { |
@@ -806,8 +792,7 @@ check_put (void *cls, | |||
806 | * @param message the actual message | 792 | * @param message the actual message |
807 | */ | 793 | */ |
808 | static void | 794 | static void |
809 | handle_put (void *cls, | 795 | handle_put (void *cls, const struct DataMessage *dm) |
810 | const struct DataMessage *dm) | ||
811 | { | 796 | { |
812 | struct GNUNET_SERVICE_Client *client = cls; | 797 | struct GNUNET_SERVICE_Client *client = cls; |
813 | int rid; | 798 | int rid; |
@@ -839,8 +824,8 @@ handle_put (void *cls, | |||
839 | GNUNET_NO); | 824 | GNUNET_NO); |
840 | } | 825 | } |
841 | } | 826 | } |
842 | bool absent = GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (filter, | 827 | bool absent = |
843 | &dm->key); | 828 | GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key); |
844 | plugin->api->put (plugin->api->cls, | 829 | plugin->api->put (plugin->api->cls, |
845 | &dm->key, | 830 | &dm->key, |
846 | absent, | 831 | absent, |
@@ -864,8 +849,7 @@ handle_put (void *cls, | |||
864 | * @param msg the actual message | 849 | * @param msg the actual message |
865 | */ | 850 | */ |
866 | static void | 851 | static void |
867 | handle_get (void *cls, | 852 | handle_get (void *cls, const struct GetMessage *msg) |
868 | const struct GetMessage *msg) | ||
869 | { | 853 | { |
870 | struct GNUNET_SERVICE_Client *client = cls; | 854 | struct GNUNET_SERVICE_Client *client = cls; |
871 | 855 | ||
@@ -894,8 +878,7 @@ handle_get (void *cls, | |||
894 | * @param msg the actual message | 878 | * @param msg the actual message |
895 | */ | 879 | */ |
896 | static void | 880 | static void |
897 | handle_get_key (void *cls, | 881 | handle_get_key (void *cls, const struct GetKeyMessage *msg) |
898 | const struct GetKeyMessage *msg) | ||
899 | { | 882 | { |
900 | struct GNUNET_SERVICE_Client *client = cls; | 883 | struct GNUNET_SERVICE_Client *client = cls; |
901 | 884 | ||
@@ -907,21 +890,25 @@ handle_get_key (void *cls, | |||
907 | gettext_noop ("# GET KEY requests received"), | 890 | gettext_noop ("# GET KEY requests received"), |
908 | 1, | 891 | 1, |
909 | GNUNET_NO); | 892 | GNUNET_NO); |
910 | if (GNUNET_YES != | 893 | if (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key)) |
911 | GNUNET_CONTAINER_bloomfilter_test (filter, | ||
912 | &msg->key)) | ||
913 | { | 894 | { |
914 | /* don't bother database... */ | 895 | /* don't bother database... */ |
915 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 896 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
916 | "Empty result set for GET request for `%s' (bloomfilter).\n", | 897 | "Empty result set for GET request for `%s' (bloomfilter).\n", |
917 | GNUNET_h2s (&msg->key)); | 898 | GNUNET_h2s (&msg->key)); |
918 | GNUNET_STATISTICS_update (stats, | 899 | GNUNET_STATISTICS_update (stats, |
919 | gettext_noop | 900 | gettext_noop ( |
920 | ("# requests filtered by bloomfilter"), | 901 | "# requests filtered by bloomfilter"), |
921 | 1, | 902 | 1, |
922 | GNUNET_NO); | 903 | GNUNET_NO); |
923 | transmit_item (client, | 904 | transmit_item (client, |
924 | NULL, 0, NULL, 0, 0, 0, 0, | 905 | NULL, |
906 | 0, | ||
907 | NULL, | ||
908 | 0, | ||
909 | 0, | ||
910 | 0, | ||
911 | 0, | ||
925 | GNUNET_TIME_UNIT_ZERO_ABS, | 912 | GNUNET_TIME_UNIT_ZERO_ABS, |
926 | 0); | 913 | 0); |
927 | GNUNET_SERVICE_client_continue (client); | 914 | GNUNET_SERVICE_client_continue (client); |
@@ -945,20 +932,17 @@ handle_get_key (void *cls, | |||
945 | * @param message the actual message | 932 | * @param message the actual message |
946 | */ | 933 | */ |
947 | static void | 934 | static void |
948 | handle_get_replication (void *cls, | 935 | handle_get_replication (void *cls, const struct GNUNET_MessageHeader *message) |
949 | const struct GNUNET_MessageHeader *message) | ||
950 | { | 936 | { |
951 | struct GNUNET_SERVICE_Client *client = cls; | 937 | struct GNUNET_SERVICE_Client *client = cls; |
952 | 938 | ||
953 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 939 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing GET_REPLICATION request\n"); |
954 | "Processing GET_REPLICATION request\n"); | ||
955 | GNUNET_STATISTICS_update (stats, | 940 | GNUNET_STATISTICS_update (stats, |
956 | gettext_noop ("# GET REPLICATION requests received"), | 941 | gettext_noop ( |
942 | "# GET REPLICATION requests received"), | ||
957 | 1, | 943 | 1, |
958 | GNUNET_NO); | 944 | GNUNET_NO); |
959 | plugin->api->get_replication (plugin->api->cls, | 945 | plugin->api->get_replication (plugin->api->cls, &transmit_item, client); |
960 | &transmit_item, | ||
961 | client); | ||
962 | GNUNET_SERVICE_client_continue (client); | 946 | GNUNET_SERVICE_client_continue (client); |
963 | } | 947 | } |
964 | 948 | ||
@@ -970,8 +954,7 @@ handle_get_replication (void *cls, | |||
970 | * @param message the actual message | 954 | * @param message the actual message |
971 | */ | 955 | */ |
972 | static void | 956 | static void |
973 | handle_get_zero_anonymity (void *cls, | 957 | handle_get_zero_anonymity (void *cls, const struct GetZeroAnonymityMessage *msg) |
974 | const struct GetZeroAnonymityMessage *msg) | ||
975 | { | 958 | { |
976 | struct GNUNET_SERVICE_Client *client = cls; | 959 | struct GNUNET_SERVICE_Client *client = cls; |
977 | enum GNUNET_BLOCK_Type type; | 960 | enum GNUNET_BLOCK_Type type; |
@@ -986,7 +969,8 @@ handle_get_zero_anonymity (void *cls, | |||
986 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 969 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
987 | "Processing GET_ZERO_ANONYMITY request\n"); | 970 | "Processing GET_ZERO_ANONYMITY request\n"); |
988 | GNUNET_STATISTICS_update (stats, | 971 | GNUNET_STATISTICS_update (stats, |
989 | gettext_noop ("# GET ZERO ANONYMITY requests received"), | 972 | gettext_noop ( |
973 | "# GET ZERO ANONYMITY requests received"), | ||
990 | 1, | 974 | 1, |
991 | GNUNET_NO); | 975 | GNUNET_NO); |
992 | plugin->api->get_zero_anonymity (plugin->api->cls, | 976 | plugin->api->get_zero_anonymity (plugin->api->cls, |
@@ -1019,21 +1003,15 @@ remove_continuation (void *cls, | |||
1019 | 1003 | ||
1020 | if (GNUNET_SYSERR == status) | 1004 | if (GNUNET_SYSERR == status) |
1021 | { | 1005 | { |
1022 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1006 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "REMOVE request failed: %s.\n", msg); |
1023 | "REMOVE request failed: %s.\n", | 1007 | transmit_status (client, GNUNET_NO, msg); |
1024 | msg); | ||
1025 | transmit_status (client, | ||
1026 | GNUNET_NO, | ||
1027 | msg); | ||
1028 | return; | 1008 | return; |
1029 | } | 1009 | } |
1030 | if (GNUNET_NO == status) | 1010 | if (GNUNET_NO == status) |
1031 | { | 1011 | { |
1032 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1012 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1033 | "Content not found for REMOVE request.\n"); | 1013 | "Content not found for REMOVE request.\n"); |
1034 | transmit_status (client, | 1014 | transmit_status (client, GNUNET_NO, _ ("Content not found")); |
1035 | GNUNET_NO, | ||
1036 | _("Content not found")); | ||
1037 | return; | 1015 | return; |
1038 | } | 1016 | } |
1039 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1017 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1043,11 +1021,8 @@ remove_continuation (void *cls, | |||
1043 | gettext_noop ("# bytes removed (explicit request)"), | 1021 | gettext_noop ("# bytes removed (explicit request)"), |
1044 | size, | 1022 | size, |
1045 | GNUNET_YES); | 1023 | GNUNET_YES); |
1046 | GNUNET_CONTAINER_bloomfilter_remove (filter, | 1024 | GNUNET_CONTAINER_bloomfilter_remove (filter, key); |
1047 | key); | 1025 | transmit_status (client, GNUNET_OK, NULL); |
1048 | transmit_status (client, | ||
1049 | GNUNET_OK, | ||
1050 | NULL); | ||
1051 | } | 1026 | } |
1052 | 1027 | ||
1053 | 1028 | ||
@@ -1059,8 +1034,7 @@ remove_continuation (void *cls, | |||
1059 | * @return #GNUNET_OK if @a dm is well-formed | 1034 | * @return #GNUNET_OK if @a dm is well-formed |
1060 | */ | 1035 | */ |
1061 | static int | 1036 | static int |
1062 | check_remove (void *cls, | 1037 | check_remove (void *cls, const struct DataMessage *dm) |
1063 | const struct DataMessage *dm) | ||
1064 | { | 1038 | { |
1065 | if (GNUNET_OK != check_data (dm)) | 1039 | if (GNUNET_OK != check_data (dm)) |
1066 | { | 1040 | { |
@@ -1079,14 +1053,14 @@ check_remove (void *cls, | |||
1079 | * @param message the actual message | 1053 | * @param message the actual message |
1080 | */ | 1054 | */ |
1081 | static void | 1055 | static void |
1082 | handle_remove (void *cls, | 1056 | handle_remove (void *cls, const struct DataMessage *dm) |
1083 | const struct DataMessage *dm) | ||
1084 | { | 1057 | { |
1085 | struct GNUNET_SERVICE_Client *client = cls; | 1058 | struct GNUNET_SERVICE_Client *client = cls; |
1086 | 1059 | ||
1087 | GNUNET_STATISTICS_update (stats, | 1060 | GNUNET_STATISTICS_update (stats, |
1088 | gettext_noop ("# REMOVE requests received"), | 1061 | gettext_noop ("# REMOVE requests received"), |
1089 | 1, GNUNET_NO); | 1062 | 1, |
1063 | GNUNET_NO); | ||
1090 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1064 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1091 | "Processing REMOVE request for `%s'\n", | 1065 | "Processing REMOVE request for `%s'\n", |
1092 | GNUNET_h2s (&dm->key)); | 1066 | GNUNET_h2s (&dm->key)); |
@@ -1107,13 +1081,11 @@ handle_remove (void *cls, | |||
1107 | * @param message the actual message | 1081 | * @param message the actual message |
1108 | */ | 1082 | */ |
1109 | static void | 1083 | static void |
1110 | handle_drop (void *cls, | 1084 | handle_drop (void *cls, const struct GNUNET_MessageHeader *message) |
1111 | const struct GNUNET_MessageHeader *message) | ||
1112 | { | 1085 | { |
1113 | struct GNUNET_SERVICE_Client *client = cls; | 1086 | struct GNUNET_SERVICE_Client *client = cls; |
1114 | 1087 | ||
1115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1088 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing DROP request\n"); |
1116 | "Processing DROP request\n"); | ||
1117 | do_drop = GNUNET_YES; | 1089 | do_drop = GNUNET_YES; |
1118 | GNUNET_SERVICE_client_continue (client); | 1090 | GNUNET_SERVICE_client_continue (client); |
1119 | } | 1091 | } |
@@ -1128,21 +1100,21 @@ handle_drop (void *cls, | |||
1128 | * 0 for "reset to empty" | 1100 | * 0 for "reset to empty" |
1129 | */ | 1101 | */ |
1130 | static void | 1102 | static void |
1131 | disk_utilization_change_cb (void *cls, | 1103 | disk_utilization_change_cb (void *cls, int delta) |
1132 | int delta) | ||
1133 | { | 1104 | { |
1134 | if ((delta < 0) && (payload < -delta)) | 1105 | if ((delta < 0) && (payload < -delta)) |
1135 | { | 1106 | { |
1136 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1107 | GNUNET_log ( |
1137 | _("Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"), | 1108 | GNUNET_ERROR_TYPE_WARNING, |
1138 | (long long) payload, | 1109 | _ ( |
1139 | (long long) -delta); | 1110 | "Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"), |
1140 | plugin->api->estimate_size (plugin->api->cls, | 1111 | (long long) payload, |
1141 | &payload); | 1112 | (long long) -delta); |
1113 | plugin->api->estimate_size (plugin->api->cls, &payload); | ||
1142 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1114 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1143 | _("New payload: %lld\n"), | 1115 | _ ("New payload: %lld\n"), |
1144 | (long long) payload); | 1116 | (long long) payload); |
1145 | sync_stats (); | 1117 | sync_stats (); |
1146 | return; | 1118 | return; |
1147 | } | 1119 | } |
1148 | payload += delta; | 1120 | payload += delta; |
@@ -1172,10 +1144,11 @@ process_stat_in (void *cls, | |||
1172 | GNUNET_assert (GNUNET_NO == stats_worked); | 1144 | GNUNET_assert (GNUNET_NO == stats_worked); |
1173 | stats_worked = GNUNET_YES; | 1145 | stats_worked = GNUNET_YES; |
1174 | payload += value; | 1146 | payload += value; |
1175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1147 | GNUNET_log ( |
1176 | "Notification from statistics about existing payload (%llu), new payload is %llu\n", | 1148 | GNUNET_ERROR_TYPE_DEBUG, |
1177 | (unsigned long long) value, | 1149 | "Notification from statistics about existing payload (%llu), new payload is %llu\n", |
1178 | (unsigned long long) payload); | 1150 | (unsigned long long) value, |
1151 | (unsigned long long) payload); | ||
1179 | return GNUNET_OK; | 1152 | return GNUNET_OK; |
1180 | } | 1153 | } |
1181 | 1154 | ||
@@ -1194,19 +1167,16 @@ load_plugin () | |||
1194 | ret->env.duc = &disk_utilization_change_cb; | 1167 | ret->env.duc = &disk_utilization_change_cb; |
1195 | ret->env.cls = NULL; | 1168 | ret->env.cls = NULL; |
1196 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1169 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1197 | _("Loading `%s' datastore plugin\n"), | 1170 | _ ("Loading `%s' datastore plugin\n"), |
1198 | plugin_name); | 1171 | plugin_name); |
1199 | GNUNET_asprintf (&libname, | 1172 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", plugin_name); |
1200 | "libgnunet_plugin_datastore_%s", | ||
1201 | plugin_name); | ||
1202 | ret->short_name = GNUNET_strdup (plugin_name); | 1173 | ret->short_name = GNUNET_strdup (plugin_name); |
1203 | ret->lib_name = libname; | 1174 | ret->lib_name = libname; |
1204 | ret->api = GNUNET_PLUGIN_load (libname, | 1175 | ret->api = GNUNET_PLUGIN_load (libname, &ret->env); |
1205 | &ret->env); | ||
1206 | if (NULL == ret->api) | 1176 | if (NULL == ret->api) |
1207 | { | 1177 | { |
1208 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1178 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1209 | _("Failed to load datastore plugin for `%s'\n"), | 1179 | _ ("Failed to load datastore plugin for `%s'\n"), |
1210 | plugin_name); | 1180 | plugin_name); |
1211 | GNUNET_free (ret->short_name); | 1181 | GNUNET_free (ret->short_name); |
1212 | GNUNET_free (libname); | 1182 | GNUNET_free (libname); |
@@ -1242,10 +1212,10 @@ static void | |||
1242 | begin_service () | 1212 | begin_service () |
1243 | { | 1213 | { |
1244 | GNUNET_SERVICE_resume (service); | 1214 | GNUNET_SERVICE_resume (service); |
1245 | expired_kill_task | 1215 | expired_kill_task = |
1246 | = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1216 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
1247 | &delete_expired, | 1217 | &delete_expired, |
1248 | NULL); | 1218 | NULL); |
1249 | } | 1219 | } |
1250 | 1220 | ||
1251 | 1221 | ||
@@ -1258,22 +1228,21 @@ begin_service () | |||
1258 | */ | 1228 | */ |
1259 | static void | 1229 | static void |
1260 | add_key_to_bloomfilter (void *cls, | 1230 | add_key_to_bloomfilter (void *cls, |
1261 | const struct GNUNET_HashCode *key, | 1231 | const struct GNUNET_HashCode *key, |
1262 | unsigned int count) | 1232 | unsigned int count) |
1263 | { | 1233 | { |
1264 | struct GNUNET_CONTAINER_BloomFilter *bf = cls; | 1234 | struct GNUNET_CONTAINER_BloomFilter *bf = cls; |
1265 | 1235 | ||
1266 | if (NULL == key) | 1236 | if (NULL == key) |
1267 | { | 1237 | { |
1268 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1238 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1269 | _("Bloomfilter construction complete.\n")); | 1239 | _ ("Bloomfilter construction complete.\n")); |
1270 | begin_service (); | 1240 | begin_service (); |
1271 | return; | 1241 | return; |
1272 | } | 1242 | } |
1273 | 1243 | ||
1274 | while (0 < count--) | 1244 | while (0 < count--) |
1275 | GNUNET_CONTAINER_bloomfilter_add (bf, | 1245 | GNUNET_CONTAINER_bloomfilter_add (bf, key); |
1276 | key); | ||
1277 | } | 1246 | } |
1278 | 1247 | ||
1279 | 1248 | ||
@@ -1285,8 +1254,7 @@ add_key_to_bloomfilter (void *cls, | |||
1285 | * @param success #GNUNET_NO if we failed to read the stat | 1254 | * @param success #GNUNET_NO if we failed to read the stat |
1286 | */ | 1255 | */ |
1287 | static void | 1256 | static void |
1288 | process_stat_done (void *cls, | 1257 | process_stat_done (void *cls, int success) |
1289 | int success) | ||
1290 | { | 1258 | { |
1291 | stat_get = NULL; | 1259 | stat_get = NULL; |
1292 | if (NULL != stat_timeout_task) | 1260 | if (NULL != stat_timeout_task) |
@@ -1301,8 +1269,7 @@ process_stat_done (void *cls, | |||
1301 | filter = NULL; | 1269 | filter = NULL; |
1302 | if (NULL != stats) | 1270 | if (NULL != stats) |
1303 | { | 1271 | { |
1304 | GNUNET_STATISTICS_destroy (stats, | 1272 | GNUNET_STATISTICS_destroy (stats, GNUNET_YES); |
1305 | GNUNET_YES); | ||
1306 | stats = NULL; | 1273 | stats = NULL; |
1307 | } | 1274 | } |
1308 | return; | 1275 | return; |
@@ -1312,28 +1279,26 @@ process_stat_done (void *cls, | |||
1312 | { | 1279 | { |
1313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1314 | "Failed to obtain value from statistics service, recomputing it\n"); | 1281 | "Failed to obtain value from statistics service, recomputing it\n"); |
1315 | plugin->api->estimate_size (plugin->api->cls, | 1282 | plugin->api->estimate_size (plugin->api->cls, &payload); |
1316 | &payload); | ||
1317 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1283 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1318 | _("New payload: %lld\n"), | 1284 | _ ("New payload: %lld\n"), |
1319 | (long long) payload); | 1285 | (long long) payload); |
1320 | } | 1286 | } |
1321 | 1287 | ||
1322 | if (GNUNET_YES == refresh_bf) | 1288 | if (GNUNET_YES == refresh_bf) |
1323 | { | 1289 | { |
1324 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1290 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1325 | _("Rebuilding bloomfilter. Please be patient.\n")); | 1291 | _ ("Rebuilding bloomfilter. Please be patient.\n")); |
1326 | if (NULL != plugin->api->get_keys) | 1292 | if (NULL != plugin->api->get_keys) |
1327 | { | 1293 | { |
1328 | plugin->api->get_keys (plugin->api->cls, | 1294 | plugin->api->get_keys (plugin->api->cls, &add_key_to_bloomfilter, filter); |
1329 | &add_key_to_bloomfilter, | ||
1330 | filter); | ||
1331 | return; | 1295 | return; |
1332 | } | 1296 | } |
1333 | else | 1297 | else |
1334 | { | 1298 | { |
1335 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1299 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1336 | _("Plugin does not support get_keys function. Please fix!\n")); | 1300 | _ ( |
1301 | "Plugin does not support get_keys function. Please fix!\n")); | ||
1337 | } | 1302 | } |
1338 | } | 1303 | } |
1339 | begin_service (); | 1304 | begin_service (); |
@@ -1350,8 +1315,7 @@ stat_timeout (void *cls) | |||
1350 | { | 1315 | { |
1351 | stat_timeout_task = NULL; | 1316 | stat_timeout_task = NULL; |
1352 | GNUNET_STATISTICS_get_cancel (stat_get); | 1317 | GNUNET_STATISTICS_get_cancel (stat_get); |
1353 | process_stat_done (NULL, | 1318 | process_stat_done (NULL, GNUNET_NO); |
1354 | GNUNET_NO); | ||
1355 | } | 1319 | } |
1356 | 1320 | ||
1357 | 1321 | ||
@@ -1369,8 +1333,7 @@ cleaning_task (void *cls) | |||
1369 | } | 1333 | } |
1370 | if (GNUNET_YES == do_drop) | 1334 | if (GNUNET_YES == do_drop) |
1371 | { | 1335 | { |
1372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dropping database!\n"); |
1373 | "Dropping database!\n"); | ||
1374 | plugin->api->drop (plugin->api->cls); | 1337 | plugin->api->drop (plugin->api->cls); |
1375 | payload = 0; | 1338 | payload = 0; |
1376 | last_sync++; | 1339 | last_sync++; |
@@ -1401,8 +1364,7 @@ cleaning_task (void *cls) | |||
1401 | sync_stats (); | 1364 | sync_stats (); |
1402 | if (NULL != stats) | 1365 | if (NULL != stats) |
1403 | { | 1366 | { |
1404 | GNUNET_STATISTICS_destroy (stats, | 1367 | GNUNET_STATISTICS_destroy (stats, GNUNET_YES); |
1405 | GNUNET_YES); | ||
1406 | stats = NULL; | 1368 | stats = NULL; |
1407 | } | 1369 | } |
1408 | GNUNET_free (quota_stat_name); | 1370 | GNUNET_free (quota_stat_name); |
@@ -1420,8 +1382,8 @@ cleaning_task (void *cls) | |||
1420 | */ | 1382 | */ |
1421 | static void * | 1383 | static void * |
1422 | client_connect_cb (void *cls, | 1384 | client_connect_cb (void *cls, |
1423 | struct GNUNET_SERVICE_Client *client, | 1385 | struct GNUNET_SERVICE_Client *client, |
1424 | struct GNUNET_MQ_Handle *mq) | 1386 | struct GNUNET_MQ_Handle *mq) |
1425 | { | 1387 | { |
1426 | return client; | 1388 | return client; |
1427 | } | 1389 | } |
@@ -1437,8 +1399,8 @@ client_connect_cb (void *cls, | |||
1437 | */ | 1399 | */ |
1438 | static void | 1400 | static void |
1439 | client_disconnect_cb (void *cls, | 1401 | client_disconnect_cb (void *cls, |
1440 | struct GNUNET_SERVICE_Client *client, | 1402 | struct GNUNET_SERVICE_Client *client, |
1441 | void *app_ctx) | 1403 | void *app_ctx) |
1442 | { | 1404 | { |
1443 | struct ReservationList *pos; | 1405 | struct ReservationList *pos; |
1444 | struct ReservationList *prev; | 1406 | struct ReservationList *prev; |
@@ -1469,7 +1431,6 @@ client_disconnect_cb (void *cls, | |||
1469 | gettext_noop ("# reserved"), | 1431 | gettext_noop ("# reserved"), |
1470 | reserved, | 1432 | reserved, |
1471 | GNUNET_NO); | 1433 | GNUNET_NO); |
1472 | |||
1473 | } | 1434 | } |
1474 | 1435 | ||
1475 | 1436 | ||
@@ -1491,11 +1452,10 @@ run (void *cls, | |||
1491 | 1452 | ||
1492 | service = serv; | 1453 | service = serv; |
1493 | cfg = c; | 1454 | cfg = c; |
1494 | if (GNUNET_OK != | 1455 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, |
1495 | GNUNET_CONFIGURATION_get_value_string (cfg, | 1456 | "DATASTORE", |
1496 | "DATASTORE", | 1457 | "DATABASE", |
1497 | "DATABASE", | 1458 | &plugin_name)) |
1498 | &plugin_name)) | ||
1499 | { | 1459 | { |
1500 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 1460 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
1501 | "DATABASE", | 1461 | "DATABASE", |
@@ -1503,26 +1463,17 @@ run (void *cls, | |||
1503 | return; | 1463 | return; |
1504 | } | 1464 | } |
1505 | GNUNET_asprintf ("a_stat_name, | 1465 | GNUNET_asprintf ("a_stat_name, |
1506 | _("# bytes used in file-sharing datastore `%s'"), | 1466 | _ ("# bytes used in file-sharing datastore `%s'"), |
1507 | plugin_name); | 1467 | plugin_name); |
1508 | if (GNUNET_OK != | 1468 | if (GNUNET_OK != |
1509 | GNUNET_CONFIGURATION_get_value_size (cfg, | 1469 | GNUNET_CONFIGURATION_get_value_size (cfg, "DATASTORE", "QUOTA", "a)) |
1510 | "DATASTORE", | ||
1511 | "QUOTA", | ||
1512 | "a)) | ||
1513 | { | 1470 | { |
1514 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 1471 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "QUOTA", "DATASTORE"); |
1515 | "QUOTA", | ||
1516 | "DATASTORE"); | ||
1517 | return; | 1472 | return; |
1518 | } | 1473 | } |
1519 | stats = GNUNET_STATISTICS_create ("datastore", | 1474 | stats = GNUNET_STATISTICS_create ("datastore", cfg); |
1520 | cfg); | 1475 | GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO); |
1521 | GNUNET_STATISTICS_set (stats, | 1476 | cache_size = quota / 8; /* Or should we make this an option? */ |
1522 | gettext_noop ("# quota"), | ||
1523 | quota, | ||
1524 | GNUNET_NO); | ||
1525 | cache_size = quota / 8; /* Or should we make this an option? */ | ||
1526 | GNUNET_STATISTICS_set (stats, | 1477 | GNUNET_STATISTICS_set (stats, |
1527 | gettext_noop ("# cache size"), | 1478 | gettext_noop ("# cache size"), |
1528 | cache_size, | 1479 | cache_size, |
@@ -1530,17 +1481,17 @@ run (void *cls, | |||
1530 | if (quota / (32 * 1024LL) > MAX_BF_SIZE) | 1481 | if (quota / (32 * 1024LL) > MAX_BF_SIZE) |
1531 | bf_size = MAX_BF_SIZE; | 1482 | bf_size = MAX_BF_SIZE; |
1532 | else | 1483 | else |
1533 | bf_size = quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */ | 1484 | bf_size = |
1485 | quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */ | ||
1534 | fn = NULL; | 1486 | fn = NULL; |
1535 | if ((GNUNET_OK != | 1487 | if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, |
1536 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 1488 | "DATASTORE", |
1537 | "DATASTORE", | 1489 | "BLOOMFILTER", |
1538 | "BLOOMFILTER", | 1490 | &fn)) || |
1539 | &fn)) || | ||
1540 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn))) | 1491 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn))) |
1541 | { | 1492 | { |
1542 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1493 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1543 | _("Could not use specified filename `%s' for bloomfilter.\n"), | 1494 | _ ("Could not use specified filename `%s' for bloomfilter.\n"), |
1544 | NULL != fn ? fn : ""); | 1495 | NULL != fn ? fn : ""); |
1545 | GNUNET_free_non_null (fn); | 1496 | GNUNET_free_non_null (fn); |
1546 | fn = NULL; | 1497 | fn = NULL; |
@@ -1550,139 +1501,150 @@ run (void *cls, | |||
1550 | GNUNET_asprintf (&pfn, "%s.%s", fn, plugin_name); | 1501 | GNUNET_asprintf (&pfn, "%s.%s", fn, plugin_name); |
1551 | if (GNUNET_YES == GNUNET_DISK_file_test (pfn)) | 1502 | if (GNUNET_YES == GNUNET_DISK_file_test (pfn)) |
1552 | { | 1503 | { |
1553 | filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */ | 1504 | filter = |
1505 | GNUNET_CONTAINER_bloomfilter_load (pfn, | ||
1506 | bf_size, | ||
1507 | 5); /* approx. 3% false positives at max use */ | ||
1554 | if (NULL == filter) | 1508 | if (NULL == filter) |
1555 | { | 1509 | { |
1556 | /* file exists but not valid, remove and try again, but refresh */ | 1510 | /* file exists but not valid, remove and try again, but refresh */ |
1557 | if (0 != UNLINK (pfn)) | 1511 | if (0 != unlink (pfn)) |
1558 | { | 1512 | { |
1559 | /* failed to remove, run without file */ | 1513 | /* failed to remove, run without file */ |
1560 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1514 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1561 | _("Failed to remove bogus bloomfilter file `%s'\n"), | 1515 | _ ("Failed to remove bogus bloomfilter file `%s'\n"), |
1562 | pfn); | 1516 | pfn); |
1563 | GNUNET_free (pfn); | 1517 | GNUNET_free (pfn); |
1564 | pfn = NULL; | 1518 | pfn = NULL; |
1565 | filter = GNUNET_CONTAINER_bloomfilter_load (NULL, bf_size, 5); /* approx. 3% false positives at max use */ | 1519 | filter = GNUNET_CONTAINER_bloomfilter_load ( |
1566 | refresh_bf = GNUNET_YES; | 1520 | NULL, |
1567 | } | 1521 | bf_size, |
1568 | else | 1522 | 5); /* approx. 3% false positives at max use */ |
1569 | { | 1523 | refresh_bf = GNUNET_YES; |
1570 | /* try again after remove */ | 1524 | } |
1571 | filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */ | 1525 | else |
1572 | refresh_bf = GNUNET_YES; | 1526 | { |
1573 | if (NULL == filter) | 1527 | /* try again after remove */ |
1574 | { | 1528 | filter = GNUNET_CONTAINER_bloomfilter_load ( |
1575 | /* failed yet again, give up on using file */ | 1529 | pfn, |
1576 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1530 | bf_size, |
1577 | _("Failed to remove bogus bloomfilter file `%s'\n"), | 1531 | 5); /* approx. 3% false positives at max use */ |
1578 | pfn); | 1532 | refresh_bf = GNUNET_YES; |
1579 | GNUNET_free (pfn); | 1533 | if (NULL == filter) |
1580 | pfn = NULL; | 1534 | { |
1581 | filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5); /* approx. 3% false positives at max use */ | 1535 | /* failed yet again, give up on using file */ |
1582 | } | 1536 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1583 | } | 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 | } | ||
1584 | } | 1547 | } |
1585 | else | 1548 | else |
1586 | { | 1549 | { |
1587 | /* normal case: have an existing valid bf file, no need to refresh */ | 1550 | /* normal case: have an existing valid bf file, no need to refresh */ |
1588 | refresh_bf = GNUNET_NO; | 1551 | refresh_bf = GNUNET_NO; |
1589 | } | 1552 | } |
1590 | } | 1553 | } |
1591 | else | 1554 | else |
1592 | { | 1555 | { |
1593 | filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */ | 1556 | filter = |
1557 | GNUNET_CONTAINER_bloomfilter_load (pfn, | ||
1558 | bf_size, | ||
1559 | 5); /* approx. 3% false positives at max use */ | ||
1594 | refresh_bf = GNUNET_YES; | 1560 | refresh_bf = GNUNET_YES; |
1595 | } | 1561 | } |
1596 | GNUNET_free (pfn); | 1562 | GNUNET_free (pfn); |
1597 | } | 1563 | } |
1598 | else | 1564 | else |
1599 | { | 1565 | { |
1600 | filter = GNUNET_CONTAINER_bloomfilter_init (NULL, | 1566 | filter = |
1601 | bf_size, | 1567 | GNUNET_CONTAINER_bloomfilter_init (NULL, |
1602 | 5); /* approx. 3% false positives at max use */ | 1568 | bf_size, |
1569 | 5); /* approx. 3% false positives at max use */ | ||
1603 | refresh_bf = GNUNET_YES; | 1570 | refresh_bf = GNUNET_YES; |
1604 | } | 1571 | } |
1605 | GNUNET_free_non_null (fn); | 1572 | GNUNET_free_non_null (fn); |
1606 | if (NULL == filter) | 1573 | if (NULL == filter) |
1607 | { | 1574 | { |
1608 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1575 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1609 | _("Failed to initialize bloomfilter.\n")); | 1576 | _ ("Failed to initialize bloomfilter.\n")); |
1610 | if (NULL != stats) | 1577 | if (NULL != stats) |
1611 | { | 1578 | { |
1612 | GNUNET_STATISTICS_destroy (stats, | 1579 | GNUNET_STATISTICS_destroy (stats, GNUNET_YES); |
1613 | GNUNET_YES); | ||
1614 | stats = NULL; | 1580 | stats = NULL; |
1615 | } | 1581 | } |
1616 | return; | 1582 | return; |
1617 | } | 1583 | } |
1618 | GNUNET_SERVICE_suspend (service); | 1584 | GNUNET_SERVICE_suspend (service); |
1619 | stat_get = | 1585 | stat_get = GNUNET_STATISTICS_get (stats, |
1620 | GNUNET_STATISTICS_get (stats, | 1586 | "datastore", |
1621 | "datastore", | 1587 | quota_stat_name, |
1622 | quota_stat_name, | 1588 | &process_stat_done, |
1623 | &process_stat_done, | 1589 | &process_stat_in, |
1624 | &process_stat_in, | 1590 | NULL); |
1625 | NULL); | ||
1626 | if (NULL == stat_get) | 1591 | if (NULL == stat_get) |
1627 | process_stat_done (NULL, | 1592 | process_stat_done (NULL, GNUNET_SYSERR); |
1628 | GNUNET_SYSERR); | ||
1629 | else | 1593 | else |
1630 | stat_timeout_task | 1594 | stat_timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
1631 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 1595 | &stat_timeout, |
1632 | &stat_timeout, | 1596 | NULL); |
1633 | NULL); | 1597 | GNUNET_SCHEDULER_add_shutdown (&cleaning_task, NULL); |
1634 | GNUNET_SCHEDULER_add_shutdown (&cleaning_task, | ||
1635 | NULL); | ||
1636 | } | 1598 | } |
1637 | 1599 | ||
1638 | 1600 | ||
1639 | /** | 1601 | /** |
1640 | * Define "main" method using service macro. | 1602 | * Define "main" method using service macro. |
1641 | */ | 1603 | */ |
1642 | GNUNET_SERVICE_MAIN | 1604 | GNUNET_SERVICE_MAIN ( |
1643 | ("datastore", | 1605 | "datastore", |
1644 | GNUNET_SERVICE_OPTION_NONE, | 1606 | GNUNET_SERVICE_OPTION_NONE, |
1645 | &run, | 1607 | &run, |
1646 | &client_connect_cb, | 1608 | &client_connect_cb, |
1647 | &client_disconnect_cb, | 1609 | &client_disconnect_cb, |
1648 | NULL, | 1610 | NULL, |
1649 | GNUNET_MQ_hd_fixed_size (reserve, | 1611 | GNUNET_MQ_hd_fixed_size (reserve, |
1650 | GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE, | 1612 | GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE, |
1651 | struct ReserveMessage, | 1613 | struct ReserveMessage, |
1652 | NULL), | 1614 | NULL), |
1653 | GNUNET_MQ_hd_fixed_size (release_reserve, | 1615 | GNUNET_MQ_hd_fixed_size (release_reserve, |
1654 | GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE, | 1616 | GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE, |
1655 | struct ReleaseReserveMessage, | 1617 | struct ReleaseReserveMessage, |
1656 | NULL), | 1618 | NULL), |
1657 | GNUNET_MQ_hd_var_size (put, | 1619 | GNUNET_MQ_hd_var_size (put, |
1658 | GNUNET_MESSAGE_TYPE_DATASTORE_PUT, | 1620 | GNUNET_MESSAGE_TYPE_DATASTORE_PUT, |
1659 | struct DataMessage, | 1621 | struct DataMessage, |
1660 | NULL), | 1622 | NULL), |
1661 | GNUNET_MQ_hd_fixed_size (get, | 1623 | GNUNET_MQ_hd_fixed_size (get, |
1662 | GNUNET_MESSAGE_TYPE_DATASTORE_GET, | 1624 | GNUNET_MESSAGE_TYPE_DATASTORE_GET, |
1663 | struct GetMessage, | 1625 | struct GetMessage, |
1664 | NULL), | 1626 | NULL), |
1665 | GNUNET_MQ_hd_fixed_size (get_key, | 1627 | GNUNET_MQ_hd_fixed_size (get_key, |
1666 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY, | 1628 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY, |
1667 | struct GetKeyMessage, | 1629 | struct GetKeyMessage, |
1668 | NULL), | 1630 | NULL), |
1669 | GNUNET_MQ_hd_fixed_size (get_replication, | 1631 | GNUNET_MQ_hd_fixed_size (get_replication, |
1670 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION, | 1632 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION, |
1671 | struct GNUNET_MessageHeader, | 1633 | struct GNUNET_MessageHeader, |
1672 | NULL), | 1634 | NULL), |
1673 | GNUNET_MQ_hd_fixed_size (get_zero_anonymity, | 1635 | GNUNET_MQ_hd_fixed_size (get_zero_anonymity, |
1674 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY, | 1636 | GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY, |
1675 | struct GetZeroAnonymityMessage, | 1637 | struct GetZeroAnonymityMessage, |
1676 | NULL), | 1638 | NULL), |
1677 | GNUNET_MQ_hd_var_size (remove, | 1639 | GNUNET_MQ_hd_var_size (remove, |
1678 | GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, | 1640 | GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, |
1679 | struct DataMessage, | 1641 | struct DataMessage, |
1680 | NULL), | 1642 | NULL), |
1681 | GNUNET_MQ_hd_fixed_size (drop, | 1643 | GNUNET_MQ_hd_fixed_size (drop, |
1682 | GNUNET_MESSAGE_TYPE_DATASTORE_DROP, | 1644 | GNUNET_MESSAGE_TYPE_DATASTORE_DROP, |
1683 | struct GNUNET_MessageHeader, | 1645 | struct GNUNET_MessageHeader, |
1684 | NULL), | 1646 | NULL), |
1685 | GNUNET_MQ_handler_end ()); | 1647 | GNUNET_MQ_handler_end ()); |
1686 | 1648 | ||
1687 | 1649 | ||
1688 | /* end of gnunet-service-datastore.c */ | 1650 | /* end of gnunet-service-datastore.c */ |
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index 2c261b155..96ec9e924 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c | |||
@@ -211,7 +211,7 @@ check_success (void *cls, | |||
211 | struct CpsRunContext *crc = cls; | 211 | struct CpsRunContext *crc = cls; |
212 | 212 | ||
213 | #if REPORT_ID | 213 | #if REPORT_ID |
214 | FPRINTF (stderr, "%s", (GNUNET_OK == success) ? "I" : "i"); | 214 | fprintf (stderr, "%s", (GNUNET_OK == success) ? "I" : "i"); |
215 | #endif | 215 | #endif |
216 | if (GNUNET_OK != success) | 216 | if (GNUNET_OK != success) |
217 | { | 217 | { |
@@ -285,7 +285,7 @@ remove_next (void *cls, | |||
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, |
@@ -528,7 +528,7 @@ run_tests (void *cls, | |||
528 | 528 | ||
529 | if (success != GNUNET_YES) | 529 | if (success != GNUNET_YES) |
530 | { | 530 | { |
531 | FPRINTF (stderr, | 531 | fprintf (stderr, |
532 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", | 532 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", |
533 | msg); | 533 | msg); |
534 | GNUNET_DATASTORE_disconnect (datastore, | 534 | GNUNET_DATASTORE_disconnect (datastore, |
@@ -573,7 +573,7 @@ run (void *cls, | |||
573 | 0, 1, | 573 | 0, 1, |
574 | &run_tests, crc)) | 574 | &run_tests, crc)) |
575 | { | 575 | { |
576 | FPRINTF (stderr, | 576 | fprintf (stderr, |
577 | "%s", | 577 | "%s", |
578 | "Test 'put' operation failed.\n"); | 578 | "Test 'put' operation failed.\n"); |
579 | ok = 1; | 579 | ok = 1; |
@@ -608,7 +608,7 @@ main (int argc, | |||
608 | &run, | 608 | &run, |
609 | NULL)) | 609 | NULL)) |
610 | return 1; | 610 | return 1; |
611 | FPRINTF (stderr, "%s", "\n"); | 611 | fprintf (stderr, "%s", "\n"); |
612 | return ok; | 612 | return ok; |
613 | } | 613 | } |
614 | 614 | ||
diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c index f68d1f389..564f8f37b 100644 --- a/src/datastore/perf_plugin_datastore.c +++ b/src/datastore/perf_plugin_datastore.c | |||
@@ -122,7 +122,7 @@ put_continuation (void *cls, | |||
122 | 122 | ||
123 | if (GNUNET_OK != status) | 123 | if (GNUNET_OK != status) |
124 | { | 124 | { |
125 | FPRINTF (stderr, "ERROR: `%s'\n", msg); | 125 | fprintf (stderr, "ERROR: `%s'\n", msg); |
126 | } | 126 | } |
127 | else | 127 | else |
128 | { | 128 | { |
@@ -477,7 +477,7 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
477 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); | 477 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); |
478 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) | 478 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) |
479 | { | 479 | { |
480 | FPRINTF (stderr, "Failed to load plugin `%s'!\n", name); | 480 | fprintf (stderr, "Failed to load plugin `%s'!\n", name); |
481 | GNUNET_free (name); | 481 | GNUNET_free (name); |
482 | GNUNET_free (libname); | 482 | GNUNET_free (libname); |
483 | return NULL; | 483 | return NULL; |
@@ -503,7 +503,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
503 | api = load_plugin (c); | 503 | api = load_plugin (c); |
504 | if (api == NULL) | 504 | if (api == NULL) |
505 | { | 505 | { |
506 | FPRINTF (stderr, | 506 | fprintf (stderr, |
507 | "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); | 507 | "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); |
508 | return; | 508 | return; |
509 | } | 509 | } |
@@ -544,7 +544,7 @@ main (int argc, char *argv[]) | |||
544 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, | 544 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, |
545 | "perf-plugin-datastore", "nohelp", options, &run, NULL); | 545 | "perf-plugin-datastore", "nohelp", options, &run, NULL); |
546 | if (ok != 0) | 546 | if (ok != 0) |
547 | FPRINTF (stderr, "Missed some testcases: %u\n", ok); | 547 | fprintf (stderr, "Missed some testcases: %u\n", ok); |
548 | GNUNET_DISK_directory_remove (dir_name); | 548 | GNUNET_DISK_directory_remove (dir_name); |
549 | 549 | ||
550 | return ok; | 550 | return ok; |
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index d548935ea..4bd2b39cb 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c | |||
@@ -1,4 +1,4 @@ | |||
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 | * |
@@ -55,7 +55,17 @@ | |||
55 | * a failure of the command 'cmd' on file 'filename' | 55 | * a failure of the command 'cmd' on file 'filename' |
56 | * with the message given by strerror(errno). | 56 | * with the message given by strerror(errno). |
57 | */ | 57 | */ |
58 | #define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0) | 58 | #define LOG_SQLITE(db, level, cmd) \ |
59 | do \ | ||
60 | { \ | ||
61 | GNUNET_log_from (level, \ | ||
62 | "sqlite", \ | ||
63 | _ ("`%s' failed at %s:%d with error: %s\n"), \ | ||
64 | cmd, \ | ||
65 | __FILE__, \ | ||
66 | __LINE__, \ | ||
67 | sqlite3_errmsg (db->dbh)); \ | ||
68 | } while (0) | ||
59 | 69 | ||
60 | 70 | ||
61 | /** | 71 | /** |
@@ -63,8 +73,23 @@ | |||
63 | * a failure of the command 'cmd' on file 'filename' | 73 | * a failure of the command 'cmd' on file 'filename' |
64 | * with the message given by strerror(errno). | 74 | * with the message given by strerror(errno). |
65 | */ | 75 | */ |
66 | #define LOG_SQLITE_MSG(db, msg, level, cmd) do { GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); GNUNET_asprintf(msg, _("`%s' failed at %s:%u with error: %s"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0) | 76 | #define LOG_SQLITE_MSG(db, msg, level, cmd) \ |
67 | 77 | do \ | |
78 | { \ | ||
79 | GNUNET_log_from (level, \ | ||
80 | "sqlite", \ | ||
81 | _ ("`%s' failed at %s:%d with error: %s\n"), \ | ||
82 | cmd, \ | ||
83 | __FILE__, \ | ||
84 | __LINE__, \ | ||
85 | sqlite3_errmsg (db->dbh)); \ | ||
86 | GNUNET_asprintf (msg, \ | ||
87 | _ ("`%s' failed at %s:%u with error: %s"), \ | ||
88 | cmd, \ | ||
89 | __FILE__, \ | ||
90 | __LINE__, \ | ||
91 | sqlite3_errmsg (db->dbh)); \ | ||
92 | } while (0) | ||
68 | 93 | ||
69 | 94 | ||
70 | /** | 95 | /** |
@@ -141,7 +166,6 @@ struct Plugin | |||
141 | * Should the database be dropped on shutdown? | 166 | * Should the database be dropped on shutdown? |
142 | */ | 167 | */ |
143 | int drop_on_shutdown; | 168 | int drop_on_shutdown; |
144 | |||
145 | }; | 169 | }; |
146 | 170 | ||
147 | 171 | ||
@@ -154,9 +178,7 @@ struct Plugin | |||
154 | * @return 0 on success | 178 | * @return 0 on success |
155 | */ | 179 | */ |
156 | static int | 180 | static int |
157 | sq_prepare (sqlite3 *dbh, | 181 | sq_prepare (sqlite3 *dbh, const char *zSql, sqlite3_stmt **ppStmt) |
158 | const char *zSql, | ||
159 | sqlite3_stmt **ppStmt) | ||
160 | { | 182 | { |
161 | char *dummy; | 183 | char *dummy; |
162 | int result; | 184 | int result; |
@@ -182,37 +204,56 @@ sq_prepare (sqlite3 *dbh, | |||
182 | * @param dbh handle to the database | 204 | * @param dbh handle to the database |
183 | */ | 205 | */ |
184 | static void | 206 | static void |
185 | create_indices (sqlite3 * dbh) | 207 | create_indices (sqlite3 *dbh) |
186 | { | 208 | { |
187 | /* create indices */ | 209 | /* create indices */ |
188 | if (0 != | 210 | if ( |
189 | (SQLITE_OK != | 211 | 0 != |
190 | sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_hash ON gn091 (hash)", | 212 | (SQLITE_OK != |
191 | NULL, NULL, NULL)) + | 213 | sqlite3_exec (dbh, |
214 | "CREATE INDEX IF NOT EXISTS idx_hash ON gn091 (hash)", | ||
215 | NULL, | ||
216 | NULL, | ||
217 | NULL)) + | ||
192 | (SQLITE_OK != | 218 | (SQLITE_OK != |
193 | sqlite3_exec (dbh, | 219 | sqlite3_exec ( |
194 | "CREATE INDEX IF NOT EXISTS idx_anon_type ON gn091 (anonLevel ASC,type)", | 220 | dbh, |
195 | NULL, NULL, NULL)) + | 221 | "CREATE INDEX IF NOT EXISTS idx_anon_type ON gn091 (anonLevel ASC,type)", |
222 | NULL, | ||
223 | NULL, | ||
224 | NULL)) + | ||
196 | (SQLITE_OK != | 225 | (SQLITE_OK != |
197 | sqlite3_exec (dbh, | 226 | sqlite3_exec (dbh, |
198 | "CREATE INDEX IF NOT EXISTS idx_expire ON gn091 (expire ASC)", | 227 | "CREATE INDEX IF NOT EXISTS idx_expire ON gn091 (expire ASC)", |
199 | NULL, NULL, NULL)) + | 228 | NULL, |
229 | NULL, | ||
230 | NULL)) + | ||
200 | (SQLITE_OK != | 231 | (SQLITE_OK != |
201 | sqlite3_exec (dbh, | 232 | sqlite3_exec ( |
202 | "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn091 (repl,rvalue)", | 233 | dbh, |
203 | NULL, NULL, NULL)) ) | 234 | "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn091 (repl,rvalue)", |
204 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite", | 235 | NULL, |
205 | "Failed to create indices: %s\n", sqlite3_errmsg (dbh)); | 236 | NULL, |
237 | NULL))) | ||
238 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
239 | "sqlite", | ||
240 | "Failed to create indices: %s\n", | ||
241 | sqlite3_errmsg (dbh)); | ||
206 | } | 242 | } |
207 | 243 | ||
208 | 244 | ||
209 | #if 0 | 245 | #if 0 |
210 | #define CHECK(a) GNUNET_break(a) | 246 | #define CHECK(a) GNUNET_break (a) |
211 | #define ENULL NULL | 247 | #define ENULL NULL |
212 | #else | 248 | #else |
213 | #define ENULL &e | 249 | #define ENULL &e |
214 | #define ENULL_DEFINED 1 | 250 | #define ENULL_DEFINED 1 |
215 | #define CHECK(a) if (! (a)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); sqlite3_free(e); } | 251 | #define CHECK(a) \ |
252 | if (! (a)) \ | ||
253 | { \ | ||
254 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", e); \ | ||
255 | sqlite3_free (e); \ | ||
256 | } | ||
216 | #endif | 257 | #endif |
217 | 258 | ||
218 | 259 | ||
@@ -235,21 +276,19 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
235 | char *e; | 276 | char *e; |
236 | #endif | 277 | #endif |
237 | 278 | ||
238 | if (GNUNET_OK != | 279 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, |
239 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 280 | "datastore-sqlite", |
240 | "datastore-sqlite", | 281 | "FILENAME", |
241 | "FILENAME", | 282 | &afsdir)) |
242 | &afsdir)) | ||
243 | { | 283 | { |
244 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 284 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
245 | "datastore-sqlite", | 285 | "datastore-sqlite", |
246 | "FILENAME"); | 286 | "FILENAME"); |
247 | return GNUNET_SYSERR; | 287 | return GNUNET_SYSERR; |
248 | } | 288 | } |
249 | if (GNUNET_OK != GNUNET_DISK_file_test (afsdir)) | 289 | if (GNUNET_OK != GNUNET_DISK_file_test (afsdir)) |
250 | { | 290 | { |
251 | if (GNUNET_OK != | 291 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir)) |
252 | GNUNET_DISK_directory_create_for_file (afsdir)) | ||
253 | { | 292 | { |
254 | GNUNET_break (0); | 293 | GNUNET_break (0); |
255 | GNUNET_free (afsdir); | 294 | GNUNET_free (afsdir); |
@@ -257,48 +296,46 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
257 | } | 296 | } |
258 | /* database is new or got deleted, reset payload to zero! */ | 297 | /* database is new or got deleted, reset payload to zero! */ |
259 | if (NULL != plugin->env->duc) | 298 | if (NULL != plugin->env->duc) |
260 | plugin->env->duc (plugin->env->cls, | 299 | plugin->env->duc (plugin->env->cls, 0); |
261 | 0); | ||
262 | } | 300 | } |
263 | /* 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 */ |
264 | plugin->fn = afsdir; | 302 | plugin->fn = afsdir; |
265 | 303 | ||
266 | /* Open database and precompile statements */ | 304 | /* Open database and precompile statements */ |
267 | if (SQLITE_OK != | 305 | if (SQLITE_OK != sqlite3_open (plugin->fn, &plugin->dbh)) |
268 | sqlite3_open (plugin->fn, &plugin->dbh)) | ||
269 | { | 306 | { |
270 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite", | 307 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
271 | _("Unable to initialize SQLite: %s.\n"), | 308 | "sqlite", |
309 | _ ("Unable to initialize SQLite: %s.\n"), | ||
272 | sqlite3_errmsg (plugin->dbh)); | 310 | sqlite3_errmsg (plugin->dbh)); |
273 | return GNUNET_SYSERR; | 311 | return GNUNET_SYSERR; |
274 | } | 312 | } |
275 | CHECK (SQLITE_OK == | 313 | CHECK ( |
276 | sqlite3_exec (plugin->dbh, | 314 | SQLITE_OK == |
277 | "PRAGMA temp_store=MEMORY", NULL, NULL, | 315 | sqlite3_exec (plugin->dbh, "PRAGMA temp_store=MEMORY", NULL, NULL, ENULL)); |
278 | ENULL)); | 316 | CHECK ( |
279 | CHECK (SQLITE_OK == | 317 | SQLITE_OK == |
280 | sqlite3_exec (plugin->dbh, | 318 | sqlite3_exec (plugin->dbh, "PRAGMA synchronous=OFF", NULL, NULL, ENULL)); |
281 | "PRAGMA synchronous=OFF", NULL, NULL, | 319 | CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, |
282 | ENULL)); | 320 | "PRAGMA legacy_file_format=OFF", |
283 | CHECK (SQLITE_OK == | 321 | NULL, |
284 | sqlite3_exec (plugin->dbh, | 322 | NULL, |
285 | "PRAGMA legacy_file_format=OFF", NULL, NULL, | 323 | ENULL)); |
286 | ENULL)); | 324 | CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, |
287 | CHECK (SQLITE_OK == | 325 | "PRAGMA auto_vacuum=INCREMENTAL", |
288 | sqlite3_exec (plugin->dbh, | 326 | NULL, |
289 | "PRAGMA auto_vacuum=INCREMENTAL", NULL, | 327 | NULL, |
290 | NULL, ENULL)); | 328 | ENULL)); |
291 | CHECK (SQLITE_OK == | 329 | CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, |
292 | sqlite3_exec (plugin->dbh, | 330 | "PRAGMA locking_mode=EXCLUSIVE", |
293 | "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, | 331 | NULL, |
294 | ENULL)); | 332 | NULL, |
295 | CHECK (SQLITE_OK == | 333 | ENULL)); |
296 | sqlite3_exec (plugin->dbh, | 334 | CHECK ( |
297 | "PRAGMA page_size=4096", NULL, NULL, | 335 | SQLITE_OK == |
298 | ENULL)); | 336 | sqlite3_exec (plugin->dbh, "PRAGMA page_size=4096", NULL, NULL, ENULL)); |
299 | 337 | ||
300 | CHECK (SQLITE_OK == | 338 | CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS)); |
301 | sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS)); | ||
302 | 339 | ||
303 | 340 | ||
304 | /* 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 */ |
@@ -312,152 +349,135 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
312 | * 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. |
313 | * 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. |
314 | */ | 351 | */ |
315 | if ( (SQLITE_DONE == | 352 | if ((SQLITE_DONE == sqlite3_step (stmt)) && |
316 | sqlite3_step (stmt)) && | 353 | (SQLITE_OK != sqlite3_exec (plugin->dbh, |
317 | (SQLITE_OK != | 354 | "CREATE TABLE gn091 (" |
318 | sqlite3_exec (plugin->dbh, | 355 | " repl INT4 NOT NULL DEFAULT 0," |
319 | "CREATE TABLE gn091 (" | 356 | " type INT4 NOT NULL DEFAULT 0," |
320 | " repl INT4 NOT NULL DEFAULT 0," | 357 | " prio INT4 NOT NULL DEFAULT 0," |
321 | " type INT4 NOT NULL DEFAULT 0," | 358 | " anonLevel INT4 NOT NULL DEFAULT 0," |
322 | " prio INT4 NOT NULL DEFAULT 0," | 359 | " expire INT8 NOT NULL DEFAULT 0," |
323 | " anonLevel INT4 NOT NULL DEFAULT 0," | 360 | " rvalue INT8 NOT NULL," |
324 | " expire INT8 NOT NULL DEFAULT 0," | 361 | " hash TEXT NOT NULL DEFAULT ''," |
325 | " rvalue INT8 NOT NULL," | 362 | " vhash TEXT NOT NULL DEFAULT ''," |
326 | " hash TEXT NOT NULL DEFAULT ''," | 363 | " value BLOB NOT NULL DEFAULT '')", |
327 | " vhash TEXT NOT NULL DEFAULT ''," | 364 | NULL, |
328 | " value BLOB NOT NULL DEFAULT '')", | 365 | NULL, |
329 | NULL, | 366 | NULL))) |
330 | NULL, | ||
331 | NULL)) ) | ||
332 | { | 367 | { |
333 | LOG_SQLITE (plugin, | 368 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); |
334 | GNUNET_ERROR_TYPE_ERROR, | ||
335 | "sqlite3_exec"); | ||
336 | sqlite3_finalize (stmt); | 369 | sqlite3_finalize (stmt); |
337 | return GNUNET_SYSERR; | 370 | return GNUNET_SYSERR; |
338 | } | 371 | } |
339 | sqlite3_finalize (stmt); | 372 | sqlite3_finalize (stmt); |
340 | create_indices (plugin->dbh); | 373 | create_indices (plugin->dbh); |
341 | 374 | ||
342 | #define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, _ROWID_" | 375 | #define RESULT_COLUMNS \ |
343 | if ( (SQLITE_OK != | 376 | "repl, type, prio, anonLevel, expire, hash, value, _ROWID_" |
344 | sq_prepare (plugin->dbh, | 377 | if ( |
345 | "UPDATE gn091 " | 378 | (SQLITE_OK != sq_prepare (plugin->dbh, |
346 | "SET prio = prio + ?, " | 379 | "UPDATE gn091 " |
347 | "repl = repl + ?, " | 380 | "SET prio = prio + ?, " |
348 | "expire = MAX(expire, ?) " | 381 | "repl = repl + ?, " |
349 | "WHERE hash = ? AND vhash = ?", | 382 | "expire = MAX(expire, ?) " |
350 | &plugin->update)) || | 383 | "WHERE hash = ? AND vhash = ?", |
351 | (SQLITE_OK != | 384 | &plugin->update)) || |
352 | sq_prepare (plugin->dbh, | 385 | (SQLITE_OK != sq_prepare (plugin->dbh, |
353 | "UPDATE gn091 " "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?", | 386 | "UPDATE gn091 " |
354 | &plugin->updRepl)) || | 387 | "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?", |
355 | (SQLITE_OK != | 388 | &plugin->updRepl)) || |
356 | sq_prepare (plugin->dbh, | 389 | (SQLITE_OK != sq_prepare (plugin->dbh, |
357 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 390 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
358 | "WHERE repl=?2 AND " " (rvalue>=?1 OR " | 391 | "WHERE repl=?2 AND " |
359 | " NOT EXISTS (SELECT 1 FROM gn091 " | 392 | " (rvalue>=?1 OR " |
360 | "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) " | 393 | " NOT EXISTS (SELECT 1 FROM gn091 " |
361 | "ORDER BY rvalue ASC LIMIT 1", | 394 | "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) " |
362 | &plugin->selRepl)) || | 395 | "ORDER BY rvalue ASC LIMIT 1", |
363 | (SQLITE_OK != | 396 | &plugin->selRepl)) || |
364 | sq_prepare (plugin->dbh, | 397 | (SQLITE_OK != sq_prepare (plugin->dbh, |
365 | "SELECT MAX(repl) FROM gn091", | 398 | "SELECT MAX(repl) FROM gn091", |
366 | &plugin->maxRepl)) || | 399 | &plugin->maxRepl)) || |
367 | (SQLITE_OK != | 400 | (SQLITE_OK != |
368 | sq_prepare (plugin->dbh, | 401 | sq_prepare (plugin->dbh, |
369 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 402 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
370 | "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) " |
371 | "ORDER BY expire ASC LIMIT 1", | 404 | "ORDER BY expire ASC LIMIT 1", |
372 | &plugin->selExpi)) || | 405 | &plugin->selExpi)) || |
373 | (SQLITE_OK != | 406 | (SQLITE_OK != sq_prepare (plugin->dbh, |
374 | sq_prepare (plugin->dbh, | 407 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
375 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 408 | "WHERE _ROWID_ >= ? AND " |
376 | "WHERE _ROWID_ >= ? AND " | 409 | "anonLevel = 0 AND " |
377 | "anonLevel = 0 AND " | 410 | "type = ? " |
378 | "type = ? " | 411 | "ORDER BY _ROWID_ ASC LIMIT 1", |
379 | "ORDER BY _ROWID_ ASC LIMIT 1", | 412 | &plugin->selZeroAnon)) || |
380 | &plugin->selZeroAnon)) || | 413 | (SQLITE_OK != |
381 | (SQLITE_OK != | 414 | sq_prepare (plugin->dbh, |
382 | sq_prepare (plugin->dbh, | 415 | "INSERT INTO gn091 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) " |
383 | "INSERT INTO gn091 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) " | 416 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", |
384 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", | 417 | &plugin->insertContent)) || |
385 | &plugin->insertContent)) || | 418 | (SQLITE_OK != sq_prepare (plugin->dbh, |
386 | (SQLITE_OK != | 419 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
387 | sq_prepare (plugin->dbh, | 420 | "WHERE _ROWID_ >= ?1 " |
388 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 421 | "ORDER BY _ROWID_ ASC LIMIT 1", |
389 | "WHERE _ROWID_ >= ?1 " | 422 | &plugin->get[0])) || |
390 | "ORDER BY _ROWID_ ASC LIMIT 1", | 423 | (SQLITE_OK != sq_prepare (plugin->dbh, |
391 | &plugin->get[0])) || | 424 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
392 | (SQLITE_OK != | 425 | "WHERE _ROWID_ >= ?1 AND " |
393 | sq_prepare (plugin->dbh, | 426 | "type = ?4 " |
394 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 427 | "ORDER BY _ROWID_ ASC LIMIT 1", |
395 | "WHERE _ROWID_ >= ?1 AND " | 428 | &plugin->get[1])) || |
396 | "type = ?4 " | 429 | (SQLITE_OK != sq_prepare (plugin->dbh, |
397 | "ORDER BY _ROWID_ ASC LIMIT 1", | 430 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
398 | &plugin->get[1])) || | 431 | "WHERE _ROWID_ >= ?1 AND " |
399 | (SQLITE_OK != | 432 | "hash = ?3 " |
400 | sq_prepare (plugin->dbh, | 433 | "ORDER BY _ROWID_ ASC LIMIT 1", |
401 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 434 | &plugin->get[2])) || |
402 | "WHERE _ROWID_ >= ?1 AND " | 435 | (SQLITE_OK != sq_prepare (plugin->dbh, |
403 | "hash = ?3 " | 436 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
404 | "ORDER BY _ROWID_ ASC LIMIT 1", | 437 | "WHERE _ROWID_ >= ?1 AND " |
405 | &plugin->get[2])) || | 438 | "hash = ?3 AND " |
406 | (SQLITE_OK != | 439 | "type = ?4 " |
407 | sq_prepare (plugin->dbh, | 440 | "ORDER BY _ROWID_ ASC LIMIT 1", |
408 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 441 | &plugin->get[3])) || |
409 | "WHERE _ROWID_ >= ?1 AND " | 442 | (SQLITE_OK != sq_prepare (plugin->dbh, |
410 | "hash = ?3 AND " | 443 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
411 | "type = ?4 " | 444 | "WHERE _ROWID_ >= ?1 AND " |
412 | "ORDER BY _ROWID_ ASC LIMIT 1", | 445 | "rvalue >= ?2 " |
413 | &plugin->get[3])) || | 446 | "ORDER BY _ROWID_ ASC LIMIT 1", |
414 | (SQLITE_OK != | 447 | &plugin->get[4])) || |
415 | sq_prepare (plugin->dbh, | 448 | (SQLITE_OK != sq_prepare (plugin->dbh, |
416 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 449 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
417 | "WHERE _ROWID_ >= ?1 AND " | 450 | "WHERE _ROWID_ >= ?1 AND " |
418 | "rvalue >= ?2 " | 451 | "rvalue >= ?2 AND " |
419 | "ORDER BY _ROWID_ ASC LIMIT 1", | 452 | "type = ?4 " |
420 | &plugin->get[4])) || | 453 | "ORDER BY _ROWID_ ASC LIMIT 1", |
421 | (SQLITE_OK != | 454 | &plugin->get[5])) || |
422 | sq_prepare (plugin->dbh, | 455 | (SQLITE_OK != sq_prepare (plugin->dbh, |
423 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 456 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
424 | "WHERE _ROWID_ >= ?1 AND " | 457 | "WHERE _ROWID_ >= ?1 AND " |
425 | "rvalue >= ?2 AND " | 458 | "rvalue >= ?2 AND " |
426 | "type = ?4 " | 459 | "hash = ?3 " |
427 | "ORDER BY _ROWID_ ASC LIMIT 1", | 460 | "ORDER BY _ROWID_ ASC LIMIT 1", |
428 | &plugin->get[5])) || | 461 | &plugin->get[6])) || |
429 | (SQLITE_OK != | 462 | (SQLITE_OK != sq_prepare (plugin->dbh, |
430 | sq_prepare (plugin->dbh, | 463 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
431 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 464 | "WHERE _ROWID_ >= ?1 AND " |
432 | "WHERE _ROWID_ >= ?1 AND " | 465 | "rvalue >= ?2 AND " |
433 | "rvalue >= ?2 AND " | 466 | "hash = ?3 AND " |
434 | "hash = ?3 " | 467 | "type = ?4 " |
435 | "ORDER BY _ROWID_ ASC LIMIT 1", | 468 | "ORDER BY _ROWID_ ASC LIMIT 1", |
436 | &plugin->get[6])) || | 469 | &plugin->get[7])) || |
437 | (SQLITE_OK != | 470 | (SQLITE_OK != sq_prepare (plugin->dbh, |
438 | sq_prepare (plugin->dbh, | 471 | "DELETE FROM gn091 WHERE _ROWID_ = ?", |
439 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 472 | &plugin->delRow)) || |
440 | "WHERE _ROWID_ >= ?1 AND " | 473 | (SQLITE_OK != sq_prepare (plugin->dbh, |
441 | "rvalue >= ?2 AND " | 474 | "DELETE FROM gn091 " |
442 | "hash = ?3 AND " | 475 | "WHERE hash = ? AND " |
443 | "type = ?4 " | 476 | "value = ? ", |
444 | "ORDER BY _ROWID_ ASC LIMIT 1", | 477 | &plugin->remove)) || |
445 | &plugin->get[7])) || | 478 | false) |
446 | (SQLITE_OK != | ||
447 | sq_prepare (plugin->dbh, | ||
448 | "DELETE FROM gn091 WHERE _ROWID_ = ?", | ||
449 | &plugin->delRow)) || | ||
450 | (SQLITE_OK != | ||
451 | sq_prepare (plugin->dbh, | ||
452 | "DELETE FROM gn091 " | ||
453 | "WHERE hash = ? AND " | ||
454 | "value = ? ", | ||
455 | &plugin->remove)) || | ||
456 | false) | ||
457 | { | 479 | { |
458 | LOG_SQLITE (plugin, | 480 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "precompiling"); |
459 | GNUNET_ERROR_TYPE_ERROR, | ||
460 | "precompiling"); | ||
461 | return GNUNET_SYSERR; | 481 | return GNUNET_SYSERR; |
462 | } | 482 | } |
463 | return GNUNET_OK; | 483 | return GNUNET_OK; |
@@ -503,11 +523,12 @@ database_shutdown (struct Plugin *plugin) | |||
503 | #if SQLITE_VERSION_NUMBER >= 3007000 | 523 | #if SQLITE_VERSION_NUMBER >= 3007000 |
504 | if (result == SQLITE_BUSY) | 524 | if (result == SQLITE_BUSY) |
505 | { | 525 | { |
506 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, | 526 | GNUNET_log_from ( |
507 | "sqlite", | 527 | GNUNET_ERROR_TYPE_WARNING, |
508 | _("Tried to close sqlite without finalizing all prepared statements.\n")); | 528 | "sqlite", |
509 | stmt = sqlite3_next_stmt (plugin->dbh, | 529 | _ ( |
510 | NULL); | 530 | "Tried to close sqlite without finalizing all prepared statements.\n")); |
531 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); | ||
511 | while (NULL != stmt) | 532 | while (NULL != stmt) |
512 | { | 533 | { |
513 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 534 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
@@ -521,16 +542,13 @@ database_shutdown (struct Plugin *plugin) | |||
521 | "Failed to close statement %p: %d\n", | 542 | "Failed to close statement %p: %d\n", |
522 | stmt, | 543 | stmt, |
523 | result); | 544 | result); |
524 | stmt = sqlite3_next_stmt (plugin->dbh, | 545 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); |
525 | NULL); | ||
526 | } | 546 | } |
527 | result = sqlite3_close (plugin->dbh); | 547 | result = sqlite3_close (plugin->dbh); |
528 | } | 548 | } |
529 | #endif | 549 | #endif |
530 | if (SQLITE_OK != result) | 550 | if (SQLITE_OK != result) |
531 | LOG_SQLITE (plugin, | 551 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close"); |
532 | GNUNET_ERROR_TYPE_ERROR, | ||
533 | "sqlite3_close"); | ||
534 | GNUNET_free_non_null (plugin->fn); | 552 | GNUNET_free_non_null (plugin->fn); |
535 | } | 553 | } |
536 | 554 | ||
@@ -543,28 +561,22 @@ database_shutdown (struct Plugin *plugin) | |||
543 | * @param rid the ID of the row to delete | 561 | * @param rid the ID of the row to delete |
544 | */ | 562 | */ |
545 | static int | 563 | static int |
546 | delete_by_rowid (struct Plugin *plugin, | 564 | delete_by_rowid (struct Plugin *plugin, uint64_t rid) |
547 | uint64_t rid) | ||
548 | { | 565 | { |
549 | struct GNUNET_SQ_QueryParam params[] = { | 566 | struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_uint64 (&rid), |
550 | GNUNET_SQ_query_param_uint64 (&rid), | 567 | GNUNET_SQ_query_param_end}; |
551 | GNUNET_SQ_query_param_end | 568 | |
552 | }; | 569 | if (GNUNET_OK != GNUNET_SQ_bind (plugin->delRow, params)) |
553 | |||
554 | if (GNUNET_OK != | ||
555 | GNUNET_SQ_bind (plugin->delRow, | ||
556 | params)) | ||
557 | return GNUNET_SYSERR; | 570 | return GNUNET_SYSERR; |
558 | if (SQLITE_DONE != sqlite3_step (plugin->delRow)) | 571 | if (SQLITE_DONE != sqlite3_step (plugin->delRow)) |
559 | { | 572 | { |
560 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 573 | LOG_SQLITE (plugin, |
574 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
561 | "sqlite3_step"); | 575 | "sqlite3_step"); |
562 | GNUNET_SQ_reset (plugin->dbh, | 576 | GNUNET_SQ_reset (plugin->dbh, plugin->delRow); |
563 | plugin->delRow); | ||
564 | return GNUNET_SYSERR; | 577 | return GNUNET_SYSERR; |
565 | } | 578 | } |
566 | GNUNET_SQ_reset (plugin->dbh, | 579 | GNUNET_SQ_reset (plugin->dbh, plugin->delRow); |
567 | plugin->delRow); | ||
568 | return GNUNET_OK; | 580 | return GNUNET_OK; |
569 | } | 581 | } |
570 | 582 | ||
@@ -603,94 +615,78 @@ sqlite_plugin_put (void *cls, | |||
603 | struct GNUNET_HashCode vhash; | 615 | struct GNUNET_HashCode vhash; |
604 | char *msg = NULL; | 616 | char *msg = NULL; |
605 | 617 | ||
606 | GNUNET_CRYPTO_hash (data, | 618 | GNUNET_CRYPTO_hash (data, size, &vhash); |
607 | size, | ||
608 | &vhash); | ||
609 | 619 | ||
610 | if (!absent) | 620 | if (! absent) |
611 | { | 621 | { |
612 | struct GNUNET_SQ_QueryParam params[] = { | 622 | struct GNUNET_SQ_QueryParam params[] = |
613 | GNUNET_SQ_query_param_uint32 (&priority), | 623 | {GNUNET_SQ_query_param_uint32 (&priority), |
614 | GNUNET_SQ_query_param_uint32 (&replication), | 624 | GNUNET_SQ_query_param_uint32 (&replication), |
615 | GNUNET_SQ_query_param_absolute_time (&expiration), | 625 | GNUNET_SQ_query_param_absolute_time (&expiration), |
616 | GNUNET_SQ_query_param_auto_from_type (key), | 626 | GNUNET_SQ_query_param_auto_from_type (key), |
617 | GNUNET_SQ_query_param_auto_from_type (&vhash), | 627 | GNUNET_SQ_query_param_auto_from_type (&vhash), |
618 | GNUNET_SQ_query_param_end | 628 | GNUNET_SQ_query_param_end}; |
619 | }; | 629 | |
620 | 630 | if (GNUNET_OK != GNUNET_SQ_bind (plugin->update, params)) | |
621 | if (GNUNET_OK != | ||
622 | GNUNET_SQ_bind (plugin->update, | ||
623 | params)) | ||
624 | { | 631 | { |
625 | cont (cont_cls, | 632 | cont (cont_cls, key, size, GNUNET_SYSERR, _ ("sqlite bind failure")); |
626 | key, | ||
627 | size, | ||
628 | GNUNET_SYSERR, | ||
629 | _("sqlite bind failure")); | ||
630 | return; | 633 | return; |
631 | } | 634 | } |
632 | if (SQLITE_DONE != sqlite3_step (plugin->update)) | 635 | if (SQLITE_DONE != sqlite3_step (plugin->update)) |
633 | { | 636 | { |
634 | LOG_SQLITE_MSG (plugin, &msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 637 | LOG_SQLITE_MSG (plugin, |
638 | &msg, | ||
639 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
635 | "sqlite3_step"); | 640 | "sqlite3_step"); |
636 | cont (cont_cls, | 641 | cont (cont_cls, key, size, GNUNET_SYSERR, msg); |
637 | key, | ||
638 | size, | ||
639 | GNUNET_SYSERR, | ||
640 | msg); | ||
641 | GNUNET_free_non_null (msg); | 642 | GNUNET_free_non_null (msg); |
642 | return; | 643 | return; |
643 | } | 644 | } |
644 | int changes = sqlite3_changes (plugin->dbh); | 645 | int changes = sqlite3_changes (plugin->dbh); |
645 | GNUNET_SQ_reset (plugin->dbh, | 646 | GNUNET_SQ_reset (plugin->dbh, plugin->update); |
646 | plugin->update); | ||
647 | if (0 != changes) | 647 | if (0 != changes) |
648 | { | 648 | { |
649 | cont (cont_cls, | 649 | cont (cont_cls, key, size, GNUNET_NO, NULL); |
650 | key, | ||
651 | size, | ||
652 | GNUNET_NO, | ||
653 | NULL); | ||
654 | return; | 650 | return; |
655 | } | 651 | } |
656 | } | 652 | } |
657 | 653 | ||
658 | uint64_t rvalue; | 654 | uint64_t rvalue; |
659 | uint32_t type32 = (uint32_t) type; | 655 | uint32_t type32 = (uint32_t) type; |
660 | struct GNUNET_SQ_QueryParam params[] = { | 656 | struct GNUNET_SQ_QueryParam params[] = |
661 | GNUNET_SQ_query_param_uint32 (&replication), | 657 | {GNUNET_SQ_query_param_uint32 (&replication), |
662 | GNUNET_SQ_query_param_uint32 (&type32), | 658 | GNUNET_SQ_query_param_uint32 (&type32), |
663 | GNUNET_SQ_query_param_uint32 (&priority), | 659 | GNUNET_SQ_query_param_uint32 (&priority), |
664 | GNUNET_SQ_query_param_uint32 (&anonymity), | 660 | GNUNET_SQ_query_param_uint32 (&anonymity), |
665 | GNUNET_SQ_query_param_absolute_time (&expiration), | 661 | GNUNET_SQ_query_param_absolute_time (&expiration), |
666 | GNUNET_SQ_query_param_uint64 (&rvalue), | 662 | GNUNET_SQ_query_param_uint64 (&rvalue), |
667 | GNUNET_SQ_query_param_auto_from_type (key), | 663 | GNUNET_SQ_query_param_auto_from_type (key), |
668 | GNUNET_SQ_query_param_auto_from_type (&vhash), | 664 | GNUNET_SQ_query_param_auto_from_type (&vhash), |
669 | GNUNET_SQ_query_param_fixed_size (data, size), | 665 | GNUNET_SQ_query_param_fixed_size (data, size), |
670 | GNUNET_SQ_query_param_end | 666 | GNUNET_SQ_query_param_end}; |
671 | }; | ||
672 | int n; | 667 | int n; |
673 | int ret; | 668 | int ret; |
674 | sqlite3_stmt *stmt; | 669 | sqlite3_stmt *stmt; |
675 | 670 | ||
676 | if (size > MAX_ITEM_SIZE) | 671 | if (size > MAX_ITEM_SIZE) |
677 | { | 672 | { |
678 | cont (cont_cls, key, size, GNUNET_SYSERR, _("Data too large")); | 673 | cont (cont_cls, key, size, GNUNET_SYSERR, _ ("Data too large")); |
679 | return; | 674 | return; |
680 | } | 675 | } |
681 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", | 676 | GNUNET_log_from ( |
682 | "Storing in database block with type %u/key `%s'/priority %u/expiration in %s (%s).\n", | 677 | GNUNET_ERROR_TYPE_DEBUG, |
683 | type, | 678 | "sqlite", |
684 | GNUNET_h2s (key), | 679 | "Storing in database block with type %u/key `%s'/priority %u/expiration in %s (%s).\n", |
685 | priority, | 680 | type, |
686 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration), | 681 | GNUNET_h2s (key), |
687 | GNUNET_YES), | 682 | priority, |
688 | GNUNET_STRINGS_absolute_time_to_string (expiration)); | 683 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining ( |
684 | expiration), | ||
685 | GNUNET_YES), | ||
686 | GNUNET_STRINGS_absolute_time_to_string (expiration)); | ||
689 | stmt = plugin->insertContent; | 687 | stmt = plugin->insertContent; |
690 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); | 688 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); |
691 | if (GNUNET_OK != | 689 | if (GNUNET_OK != GNUNET_SQ_bind (stmt, params)) |
692 | GNUNET_SQ_bind (stmt, | ||
693 | params)) | ||
694 | { | 690 | { |
695 | cont (cont_cls, key, size, GNUNET_SYSERR, NULL); | 691 | cont (cont_cls, key, size, GNUNET_SYSERR, NULL); |
696 | return; | 692 | return; |
@@ -702,7 +698,8 @@ sqlite_plugin_put (void *cls, | |||
702 | if (NULL != plugin->env->duc) | 698 | if (NULL != plugin->env->duc) |
703 | plugin->env->duc (plugin->env->cls, | 699 | plugin->env->duc (plugin->env->cls, |
704 | size + GNUNET_DATASTORE_ENTRY_OVERHEAD); | 700 | size + GNUNET_DATASTORE_ENTRY_OVERHEAD); |
705 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", | 701 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
702 | "sqlite", | ||
706 | "Stored new entry (%u bytes)\n", | 703 | "Stored new entry (%u bytes)\n", |
707 | size + GNUNET_DATASTORE_ENTRY_OVERHEAD); | 704 | size + GNUNET_DATASTORE_ENTRY_OVERHEAD); |
708 | ret = GNUNET_OK; | 705 | ret = GNUNET_OK; |
@@ -710,28 +707,26 @@ sqlite_plugin_put (void *cls, | |||
710 | case SQLITE_BUSY: | 707 | case SQLITE_BUSY: |
711 | GNUNET_break (0); | 708 | GNUNET_break (0); |
712 | LOG_SQLITE_MSG (plugin, | 709 | LOG_SQLITE_MSG (plugin, |
713 | &msg, | 710 | &msg, |
714 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 711 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
715 | "sqlite3_step"); | 712 | "sqlite3_step"); |
716 | ret = GNUNET_SYSERR; | 713 | ret = GNUNET_SYSERR; |
717 | break; | 714 | break; |
718 | default: | 715 | default: |
719 | LOG_SQLITE_MSG (plugin, | 716 | LOG_SQLITE_MSG (plugin, |
720 | &msg, | 717 | &msg, |
721 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 718 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
722 | "sqlite3_step"); | 719 | "sqlite3_step"); |
723 | GNUNET_SQ_reset (plugin->dbh, | 720 | GNUNET_SQ_reset (plugin->dbh, stmt); |
724 | stmt); | ||
725 | database_shutdown (plugin); | 721 | database_shutdown (plugin); |
726 | database_setup (plugin->env->cfg, plugin); | 722 | database_setup (plugin->env->cfg, plugin); |
727 | cont (cont_cls, key, size, GNUNET_SYSERR, msg); | 723 | cont (cont_cls, key, size, GNUNET_SYSERR, msg); |
728 | GNUNET_free_non_null(msg); | 724 | GNUNET_free_non_null (msg); |
729 | return; | 725 | return; |
730 | } | 726 | } |
731 | GNUNET_SQ_reset (plugin->dbh, | 727 | GNUNET_SQ_reset (plugin->dbh, stmt); |
732 | stmt); | ||
733 | cont (cont_cls, key, size, ret, msg); | 728 | cont (cont_cls, key, size, ret, msg); |
734 | GNUNET_free_non_null(msg); | 729 | GNUNET_free_non_null (msg); |
735 | } | 730 | } |
736 | 731 | ||
737 | 732 | ||
@@ -761,26 +756,22 @@ execute_get (struct Plugin *plugin, | |||
761 | size_t value_size; | 756 | size_t value_size; |
762 | struct GNUNET_HashCode key; | 757 | struct GNUNET_HashCode key; |
763 | int ret; | 758 | int ret; |
764 | struct GNUNET_SQ_ResultSpec rs[] = { | 759 | struct GNUNET_SQ_ResultSpec rs[] = |
765 | GNUNET_SQ_result_spec_uint32 (&replication), | 760 | {GNUNET_SQ_result_spec_uint32 (&replication), |
766 | GNUNET_SQ_result_spec_uint32 (&type), | 761 | GNUNET_SQ_result_spec_uint32 (&type), |
767 | GNUNET_SQ_result_spec_uint32 (&priority), | 762 | GNUNET_SQ_result_spec_uint32 (&priority), |
768 | GNUNET_SQ_result_spec_uint32 (&anonymity), | 763 | GNUNET_SQ_result_spec_uint32 (&anonymity), |
769 | GNUNET_SQ_result_spec_absolute_time (&expiration), | 764 | GNUNET_SQ_result_spec_absolute_time (&expiration), |
770 | GNUNET_SQ_result_spec_auto_from_type (&key), | 765 | GNUNET_SQ_result_spec_auto_from_type (&key), |
771 | GNUNET_SQ_result_spec_variable_size (&value, | 766 | GNUNET_SQ_result_spec_variable_size (&value, &value_size), |
772 | &value_size), | 767 | GNUNET_SQ_result_spec_uint64 (&rowid), |
773 | GNUNET_SQ_result_spec_uint64 (&rowid), | 768 | GNUNET_SQ_result_spec_end}; |
774 | GNUNET_SQ_result_spec_end | ||
775 | }; | ||
776 | 769 | ||
777 | n = sqlite3_step (stmt); | 770 | n = sqlite3_step (stmt); |
778 | switch (n) | 771 | switch (n) |
779 | { | 772 | { |
780 | case SQLITE_ROW: | 773 | case SQLITE_ROW: |
781 | if (GNUNET_OK != | 774 | if (GNUNET_OK != GNUNET_SQ_extract_result (stmt, rs)) |
782 | GNUNET_SQ_extract_result (stmt, | ||
783 | rs)) | ||
784 | { | 775 | { |
785 | GNUNET_break (0); | 776 | GNUNET_break (0); |
786 | break; | 777 | break; |
@@ -800,12 +791,9 @@ execute_get (struct Plugin *plugin, | |||
800 | expiration, | 791 | expiration, |
801 | rowid); | 792 | rowid); |
802 | GNUNET_SQ_cleanup_result (rs); | 793 | GNUNET_SQ_cleanup_result (rs); |
803 | GNUNET_SQ_reset (plugin->dbh, | 794 | GNUNET_SQ_reset (plugin->dbh, stmt); |
804 | stmt); | 795 | if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid)) && |
805 | if ( (GNUNET_NO == ret) && | 796 | (NULL != plugin->env->duc)) |
806 | (GNUNET_OK == delete_by_rowid (plugin, | ||
807 | rowid)) && | ||
808 | (NULL != plugin->env->duc) ) | ||
809 | plugin->env->duc (plugin->env->cls, | 797 | plugin->env->duc (plugin->env->cls, |
810 | -(value_size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); | 798 | -(value_size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); |
811 | return; | 799 | return; |
@@ -819,20 +807,17 @@ execute_get (struct Plugin *plugin, | |||
819 | LOG_SQLITE (plugin, | 807 | LOG_SQLITE (plugin, |
820 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 808 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
821 | "sqlite3_step"); | 809 | "sqlite3_step"); |
822 | if (SQLITE_OK != | 810 | if (SQLITE_OK != sqlite3_reset (stmt)) |
823 | sqlite3_reset (stmt)) | ||
824 | LOG_SQLITE (plugin, | 811 | LOG_SQLITE (plugin, |
825 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 812 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
826 | "sqlite3_reset"); | 813 | "sqlite3_reset"); |
827 | GNUNET_break (0); | 814 | GNUNET_break (0); |
828 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 815 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
829 | database_shutdown (plugin); | 816 | database_shutdown (plugin); |
830 | database_setup (plugin->env->cfg, | 817 | database_setup (plugin->env->cfg, plugin); |
831 | plugin); | ||
832 | return; | 818 | return; |
833 | } | 819 | } |
834 | GNUNET_SQ_reset (plugin->dbh, | 820 | GNUNET_SQ_reset (plugin->dbh, stmt); |
835 | stmt); | ||
836 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 821 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
837 | } | 822 | } |
838 | 823 | ||
@@ -858,16 +843,14 @@ sqlite_plugin_get_zero_anonymity (void *cls, | |||
858 | { | 843 | { |
859 | struct Plugin *plugin = cls; | 844 | struct Plugin *plugin = cls; |
860 | uint32_t type32 = type; | 845 | uint32_t type32 = type; |
861 | struct GNUNET_SQ_QueryParam params[] = { | 846 | struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_uint64 ( |
862 | GNUNET_SQ_query_param_uint64 (&next_uid), | 847 | &next_uid), |
863 | GNUNET_SQ_query_param_uint32 (&type32), | 848 | GNUNET_SQ_query_param_uint32 ( |
864 | GNUNET_SQ_query_param_end | 849 | &type32), |
865 | }; | 850 | GNUNET_SQ_query_param_end}; |
866 | 851 | ||
867 | GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY); | 852 | GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY); |
868 | if (GNUNET_OK != | 853 | if (GNUNET_OK != GNUNET_SQ_bind (plugin->selZeroAnon, params)) |
869 | GNUNET_SQ_bind (plugin->selZeroAnon, | ||
870 | params)) | ||
871 | { | 854 | { |
872 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 855 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
873 | return; | 856 | return; |
@@ -905,13 +888,12 @@ sqlite_plugin_get_key (void *cls, | |||
905 | int use_type = GNUNET_BLOCK_TYPE_ANY != type; | 888 | int use_type = GNUNET_BLOCK_TYPE_ANY != type; |
906 | int use_key = NULL != key; | 889 | int use_key = NULL != key; |
907 | sqlite3_stmt *stmt = plugin->get[use_rvalue * 4 + use_key * 2 + use_type]; | 890 | sqlite3_stmt *stmt = plugin->get[use_rvalue * 4 + use_key * 2 + use_type]; |
908 | struct GNUNET_SQ_QueryParam params[] = { | 891 | struct GNUNET_SQ_QueryParam params[] = |
909 | GNUNET_SQ_query_param_uint64 (&next_uid), | 892 | {GNUNET_SQ_query_param_uint64 (&next_uid), |
910 | GNUNET_SQ_query_param_uint64 (&rvalue), | 893 | GNUNET_SQ_query_param_uint64 (&rvalue), |
911 | GNUNET_SQ_query_param_auto_from_type (key), | 894 | GNUNET_SQ_query_param_auto_from_type (key), |
912 | GNUNET_SQ_query_param_uint32 (&type32), | 895 | GNUNET_SQ_query_param_uint32 (&type32), |
913 | GNUNET_SQ_query_param_end | 896 | GNUNET_SQ_query_param_end}; |
914 | }; | ||
915 | 897 | ||
916 | /* SQLite doesn't like it when you try to bind a parameter greater than the | 898 | /* SQLite doesn't like it when you try to bind a parameter greater than the |
917 | * last numbered parameter, but unused parameters in the middle are OK. | 899 | * last numbered parameter, but unused parameters in the middle are OK. |
@@ -928,24 +910,18 @@ sqlite_plugin_get_key (void *cls, | |||
928 | } | 910 | } |
929 | if (random) | 911 | if (random) |
930 | { | 912 | { |
931 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 913 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); |
932 | UINT64_MAX); | ||
933 | next_uid = 0; | 914 | next_uid = 0; |
934 | } | 915 | } |
935 | else | 916 | else |
936 | rvalue = 0; | 917 | rvalue = 0; |
937 | 918 | ||
938 | if (GNUNET_OK != | 919 | if (GNUNET_OK != GNUNET_SQ_bind (stmt, params)) |
939 | GNUNET_SQ_bind (stmt, | ||
940 | params)) | ||
941 | { | 920 | { |
942 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 921 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
943 | return; | 922 | return; |
944 | } | 923 | } |
945 | execute_get (plugin, | 924 | execute_get (plugin, stmt, proc, proc_cls); |
946 | stmt, | ||
947 | proc, | ||
948 | proc_cls); | ||
949 | } | 925 | } |
950 | 926 | ||
951 | 927 | ||
@@ -1051,37 +1027,27 @@ sqlite_plugin_get_replication (void *cls, | |||
1051 | struct ReplCtx rc; | 1027 | struct ReplCtx rc; |
1052 | uint64_t rvalue; | 1028 | uint64_t rvalue; |
1053 | uint32_t repl; | 1029 | uint32_t repl; |
1054 | struct GNUNET_SQ_QueryParam params_sel_repl[] = { | 1030 | struct GNUNET_SQ_QueryParam params_sel_repl[] = |
1055 | GNUNET_SQ_query_param_uint64 (&rvalue), | 1031 | {GNUNET_SQ_query_param_uint64 (&rvalue), |
1056 | GNUNET_SQ_query_param_uint32 (&repl), | 1032 | GNUNET_SQ_query_param_uint32 (&repl), |
1057 | GNUNET_SQ_query_param_end | 1033 | GNUNET_SQ_query_param_end}; |
1058 | }; | 1034 | struct GNUNET_SQ_QueryParam params_upd_repl[] = |
1059 | struct GNUNET_SQ_QueryParam params_upd_repl[] = { | 1035 | {GNUNET_SQ_query_param_uint64 (&rc.uid), GNUNET_SQ_query_param_end}; |
1060 | GNUNET_SQ_query_param_uint64 (&rc.uid), | ||
1061 | GNUNET_SQ_query_param_end | ||
1062 | }; | ||
1063 | 1036 | ||
1064 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1037 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1065 | "datastore-sqlite", | 1038 | "datastore-sqlite", |
1066 | "Getting random block based on replication order.\n"); | 1039 | "Getting random block based on replication order.\n"); |
1067 | if (SQLITE_ROW != | 1040 | if (SQLITE_ROW != sqlite3_step (plugin->maxRepl)) |
1068 | sqlite3_step (plugin->maxRepl)) | ||
1069 | { | 1041 | { |
1070 | GNUNET_SQ_reset (plugin->dbh, | 1042 | GNUNET_SQ_reset (plugin->dbh, plugin->maxRepl); |
1071 | plugin->maxRepl); | ||
1072 | /* DB empty */ | 1043 | /* DB empty */ |
1073 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1044 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
1074 | return; | 1045 | return; |
1075 | } | 1046 | } |
1076 | repl = sqlite3_column_int (plugin->maxRepl, | 1047 | repl = sqlite3_column_int (plugin->maxRepl, 0); |
1077 | 0); | 1048 | GNUNET_SQ_reset (plugin->dbh, plugin->maxRepl); |
1078 | GNUNET_SQ_reset (plugin->dbh, | 1049 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); |
1079 | plugin->maxRepl); | 1050 | if (GNUNET_OK != GNUNET_SQ_bind (plugin->selRepl, params_sel_repl)) |
1080 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1081 | UINT64_MAX); | ||
1082 | if (GNUNET_OK != | ||
1083 | GNUNET_SQ_bind (plugin->selRepl, | ||
1084 | params_sel_repl)) | ||
1085 | { | 1051 | { |
1086 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1052 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
1087 | return; | 1053 | return; |
@@ -1089,26 +1055,19 @@ sqlite_plugin_get_replication (void *cls, | |||
1089 | rc.have_uid = GNUNET_SYSERR; | 1055 | rc.have_uid = GNUNET_SYSERR; |
1090 | rc.proc = proc; | 1056 | rc.proc = proc; |
1091 | rc.proc_cls = proc_cls; | 1057 | rc.proc_cls = proc_cls; |
1092 | execute_get (plugin, | 1058 | execute_get (plugin, plugin->selRepl, &repl_proc, &rc); |
1093 | plugin->selRepl, | ||
1094 | &repl_proc, | ||
1095 | &rc); | ||
1096 | if (GNUNET_YES == rc.have_uid) | 1059 | if (GNUNET_YES == rc.have_uid) |
1097 | { | 1060 | { |
1098 | if (GNUNET_OK != | 1061 | if (GNUNET_OK != GNUNET_SQ_bind (plugin->updRepl, params_upd_repl)) |
1099 | GNUNET_SQ_bind (plugin->updRepl, | ||
1100 | params_upd_repl)) | ||
1101 | { | 1062 | { |
1102 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1063 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
1103 | return; | 1064 | return; |
1104 | } | 1065 | } |
1105 | if (SQLITE_DONE != | 1066 | if (SQLITE_DONE != sqlite3_step (plugin->updRepl)) |
1106 | sqlite3_step (plugin->updRepl)) | ||
1107 | LOG_SQLITE (plugin, | 1067 | LOG_SQLITE (plugin, |
1108 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1068 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1109 | "sqlite3_step"); | 1069 | "sqlite3_step"); |
1110 | GNUNET_SQ_reset (plugin->dbh, | 1070 | GNUNET_SQ_reset (plugin->dbh, plugin->updRepl); |
1111 | plugin->updRepl); | ||
1112 | } | 1071 | } |
1113 | if (GNUNET_SYSERR == rc.have_uid) | 1072 | if (GNUNET_SYSERR == rc.have_uid) |
1114 | { | 1073 | { |
@@ -1127,25 +1086,24 @@ sqlite_plugin_get_replication (void *cls, | |||
1127 | * @param proc_cls closure for @a proc | 1086 | * @param proc_cls closure for @a proc |
1128 | */ | 1087 | */ |
1129 | static void | 1088 | static void |
1130 | sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc, | 1089 | sqlite_plugin_get_expiration (void *cls, |
1090 | PluginDatumProcessor proc, | ||
1131 | void *proc_cls) | 1091 | void *proc_cls) |
1132 | { | 1092 | { |
1133 | struct Plugin *plugin = cls; | 1093 | struct Plugin *plugin = cls; |
1134 | sqlite3_stmt *stmt; | 1094 | sqlite3_stmt *stmt; |
1135 | struct GNUNET_TIME_Absolute now; | 1095 | struct GNUNET_TIME_Absolute now; |
1136 | struct GNUNET_SQ_QueryParam params[] = { | 1096 | struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_absolute_time ( |
1137 | GNUNET_SQ_query_param_absolute_time (&now), | 1097 | &now), |
1138 | GNUNET_SQ_query_param_end | 1098 | GNUNET_SQ_query_param_end}; |
1139 | }; | 1099 | |
1140 | 1100 | GNUNET_log_from ( | |
1141 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1101 | GNUNET_ERROR_TYPE_DEBUG, |
1142 | "sqlite", | 1102 | "sqlite", |
1143 | "Getting random block based on expiration and priority order.\n"); | 1103 | "Getting random block based on expiration and priority order.\n"); |
1144 | now = GNUNET_TIME_absolute_get (); | 1104 | now = GNUNET_TIME_absolute_get (); |
1145 | stmt = plugin->selExpi; | 1105 | stmt = plugin->selExpi; |
1146 | if (GNUNET_OK != | 1106 | if (GNUNET_OK != GNUNET_SQ_bind (stmt, params)) |
1147 | GNUNET_SQ_bind (stmt, | ||
1148 | params)) | ||
1149 | { | 1107 | { |
1150 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1108 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
1151 | return; | 1109 | return; |
@@ -1162,52 +1120,35 @@ sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc, | |||
1162 | * @param proc_cls closure for @a proc | 1120 | * @param proc_cls closure for @a proc |
1163 | */ | 1121 | */ |
1164 | static void | 1122 | static void |
1165 | sqlite_plugin_get_keys (void *cls, | 1123 | sqlite_plugin_get_keys (void *cls, PluginKeyProcessor proc, void *proc_cls) |
1166 | PluginKeyProcessor proc, | ||
1167 | void *proc_cls) | ||
1168 | { | 1124 | { |
1169 | struct Plugin *plugin = cls; | 1125 | struct Plugin *plugin = cls; |
1170 | struct GNUNET_HashCode key; | 1126 | struct GNUNET_HashCode key; |
1171 | struct GNUNET_SQ_ResultSpec results[] = { | 1127 | struct GNUNET_SQ_ResultSpec results[] = |
1172 | GNUNET_SQ_result_spec_auto_from_type (&key), | 1128 | {GNUNET_SQ_result_spec_auto_from_type (&key), GNUNET_SQ_result_spec_end}; |
1173 | GNUNET_SQ_result_spec_end | ||
1174 | }; | ||
1175 | sqlite3_stmt *stmt; | 1129 | sqlite3_stmt *stmt; |
1176 | int ret; | 1130 | int ret; |
1177 | 1131 | ||
1178 | GNUNET_assert (NULL != proc); | 1132 | GNUNET_assert (NULL != proc); |
1179 | if (SQLITE_OK != | 1133 | if (SQLITE_OK != sq_prepare (plugin->dbh, "SELECT hash FROM gn091", &stmt)) |
1180 | sq_prepare (plugin->dbh, | ||
1181 | "SELECT hash FROM gn091", | ||
1182 | &stmt)) | ||
1183 | { | 1134 | { |
1184 | LOG_SQLITE (plugin, | 1135 | LOG_SQLITE (plugin, |
1185 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1136 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1186 | "sqlite_prepare"); | 1137 | "sqlite_prepare"); |
1187 | proc (proc_cls, | 1138 | proc (proc_cls, NULL, 0); |
1188 | NULL, | ||
1189 | 0); | ||
1190 | return; | 1139 | return; |
1191 | } | 1140 | } |
1192 | while (SQLITE_ROW == (ret = sqlite3_step (stmt))) | 1141 | while (SQLITE_ROW == (ret = sqlite3_step (stmt))) |
1193 | { | 1142 | { |
1194 | if (GNUNET_OK == | 1143 | if (GNUNET_OK == GNUNET_SQ_extract_result (stmt, results)) |
1195 | GNUNET_SQ_extract_result (stmt, | 1144 | proc (proc_cls, &key, 1); |
1196 | results)) | ||
1197 | proc (proc_cls, | ||
1198 | &key, | ||
1199 | 1); | ||
1200 | else | 1145 | else |
1201 | GNUNET_break (0); | 1146 | GNUNET_break (0); |
1202 | } | 1147 | } |
1203 | if (SQLITE_DONE != ret) | 1148 | if (SQLITE_DONE != ret) |
1204 | LOG_SQLITE (plugin, | 1149 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step"); |
1205 | GNUNET_ERROR_TYPE_ERROR, | ||
1206 | "sqlite_step"); | ||
1207 | sqlite3_finalize (stmt); | 1150 | sqlite3_finalize (stmt); |
1208 | proc (proc_cls, | 1151 | proc (proc_cls, NULL, 0); |
1209 | NULL, | ||
1210 | 0); | ||
1211 | } | 1152 | } |
1212 | 1153 | ||
1213 | 1154 | ||
@@ -1244,21 +1185,14 @@ sqlite_plugin_remove_key (void *cls, | |||
1244 | void *cont_cls) | 1185 | void *cont_cls) |
1245 | { | 1186 | { |
1246 | struct Plugin *plugin = cls; | 1187 | struct Plugin *plugin = cls; |
1247 | struct GNUNET_SQ_QueryParam params[] = { | 1188 | struct GNUNET_SQ_QueryParam params[] = |
1248 | GNUNET_SQ_query_param_auto_from_type (key), | 1189 | {GNUNET_SQ_query_param_auto_from_type (key), |
1249 | GNUNET_SQ_query_param_fixed_size (data, size), | 1190 | GNUNET_SQ_query_param_fixed_size (data, size), |
1250 | GNUNET_SQ_query_param_end | 1191 | GNUNET_SQ_query_param_end}; |
1251 | }; | 1192 | |
1252 | 1193 | if (GNUNET_OK != GNUNET_SQ_bind (plugin->remove, params)) | |
1253 | if (GNUNET_OK != | ||
1254 | GNUNET_SQ_bind (plugin->remove, | ||
1255 | params)) | ||
1256 | { | 1194 | { |
1257 | cont (cont_cls, | 1195 | cont (cont_cls, key, size, GNUNET_SYSERR, "bind failed"); |
1258 | key, | ||
1259 | size, | ||
1260 | GNUNET_SYSERR, | ||
1261 | "bind failed"); | ||
1262 | return; | 1196 | return; |
1263 | } | 1197 | } |
1264 | if (SQLITE_DONE != sqlite3_step (plugin->remove)) | 1198 | if (SQLITE_DONE != sqlite3_step (plugin->remove)) |
@@ -1266,35 +1200,21 @@ sqlite_plugin_remove_key (void *cls, | |||
1266 | LOG_SQLITE (plugin, | 1200 | LOG_SQLITE (plugin, |
1267 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1201 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1268 | "sqlite3_step"); | 1202 | "sqlite3_step"); |
1269 | GNUNET_SQ_reset (plugin->dbh, | 1203 | GNUNET_SQ_reset (plugin->dbh, plugin->remove); |
1270 | plugin->remove); | 1204 | cont (cont_cls, key, size, GNUNET_SYSERR, "sqlite3_step failed"); |
1271 | cont (cont_cls, | ||
1272 | key, | ||
1273 | size, | ||
1274 | GNUNET_SYSERR, | ||
1275 | "sqlite3_step failed"); | ||
1276 | return; | 1205 | return; |
1277 | } | 1206 | } |
1278 | int changes = sqlite3_changes (plugin->dbh); | 1207 | int changes = sqlite3_changes (plugin->dbh); |
1279 | GNUNET_SQ_reset (plugin->dbh, | 1208 | GNUNET_SQ_reset (plugin->dbh, plugin->remove); |
1280 | plugin->remove); | ||
1281 | if (0 == changes) | 1209 | if (0 == changes) |
1282 | { | 1210 | { |
1283 | cont (cont_cls, | 1211 | cont (cont_cls, key, size, GNUNET_NO, NULL); |
1284 | key, | ||
1285 | size, | ||
1286 | GNUNET_NO, | ||
1287 | NULL); | ||
1288 | return; | 1212 | return; |
1289 | } | 1213 | } |
1290 | if (NULL != plugin->env->duc) | 1214 | if (NULL != plugin->env->duc) |
1291 | plugin->env->duc (plugin->env->cls, | 1215 | plugin->env->duc (plugin->env->cls, |
1292 | -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); | 1216 | -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); |
1293 | cont (cont_cls, | 1217 | cont (cont_cls, key, size, GNUNET_OK, NULL); |
1294 | key, | ||
1295 | size, | ||
1296 | GNUNET_OK, | ||
1297 | NULL); | ||
1298 | } | 1218 | } |
1299 | 1219 | ||
1300 | 1220 | ||
@@ -1306,8 +1226,7 @@ sqlite_plugin_remove_key (void *cls, | |||
1306 | * @return the size of the database on disk (estimate) | 1226 | * @return the size of the database on disk (estimate) |
1307 | */ | 1227 | */ |
1308 | static void | 1228 | static void |
1309 | sqlite_plugin_estimate_size (void *cls, | 1229 | sqlite_plugin_estimate_size (void *cls, unsigned long long *estimate) |
1310 | unsigned long long *estimate) | ||
1311 | { | 1230 | { |
1312 | struct Plugin *plugin = cls; | 1231 | struct Plugin *plugin = cls; |
1313 | sqlite3_stmt *stmt; | 1232 | sqlite3_stmt *stmt; |
@@ -1322,45 +1241,35 @@ sqlite_plugin_estimate_size (void *cls, | |||
1322 | return; | 1241 | return; |
1323 | if (SQLITE_VERSION_NUMBER < 3006000) | 1242 | if (SQLITE_VERSION_NUMBER < 3006000) |
1324 | { | 1243 | { |
1325 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, | 1244 | GNUNET_log_from ( |
1326 | "datastore-sqlite", | 1245 | GNUNET_ERROR_TYPE_WARNING, |
1327 | _("sqlite version to old to determine size, assuming zero\n")); | 1246 | "datastore-sqlite", |
1247 | _ ("sqlite version to old to determine size, assuming zero\n")); | ||
1328 | *estimate = 0; | 1248 | *estimate = 0; |
1329 | return; | 1249 | return; |
1330 | } | 1250 | } |
1331 | CHECK (SQLITE_OK == | 1251 | CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL)); |
1332 | sqlite3_exec (plugin->dbh, | 1252 | CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, |
1333 | "VACUUM", | 1253 | "PRAGMA auto_vacuum=INCREMENTAL", |
1334 | NULL, | 1254 | NULL, |
1335 | NULL, | 1255 | NULL, |
1336 | ENULL)); | 1256 | ENULL)); |
1337 | CHECK (SQLITE_OK == | 1257 | CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_count", &stmt)); |
1338 | sqlite3_exec (plugin->dbh, | ||
1339 | "PRAGMA auto_vacuum=INCREMENTAL", | ||
1340 | NULL, | ||
1341 | NULL, ENULL)); | ||
1342 | CHECK (SQLITE_OK == | ||
1343 | sq_prepare (plugin->dbh, | ||
1344 | "PRAGMA page_count", | ||
1345 | &stmt)); | ||
1346 | if (SQLITE_ROW == sqlite3_step (stmt)) | 1258 | if (SQLITE_ROW == sqlite3_step (stmt)) |
1347 | pages = sqlite3_column_int64 (stmt, | 1259 | pages = sqlite3_column_int64 (stmt, 0); |
1348 | 0); | ||
1349 | else | 1260 | else |
1350 | pages = 0; | 1261 | pages = 0; |
1351 | sqlite3_finalize (stmt); | 1262 | sqlite3_finalize (stmt); |
1352 | CHECK (SQLITE_OK == | 1263 | CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_size", &stmt)); |
1353 | sq_prepare (plugin->dbh, | 1264 | CHECK (SQLITE_ROW == sqlite3_step (stmt)); |
1354 | "PRAGMA page_size", | ||
1355 | &stmt)); | ||
1356 | CHECK (SQLITE_ROW == | ||
1357 | sqlite3_step (stmt)); | ||
1358 | page_size = sqlite3_column_int64 (stmt, 0); | 1265 | page_size = sqlite3_column_int64 (stmt, 0); |
1359 | sqlite3_finalize (stmt); | 1266 | sqlite3_finalize (stmt); |
1360 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1267 | GNUNET_log ( |
1361 | _("Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"), | 1268 | GNUNET_ERROR_TYPE_INFO, |
1362 | (unsigned long long) pages, | 1269 | _ ( |
1363 | (unsigned long long) page_size); | 1270 | "Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"), |
1271 | (unsigned long long) pages, | ||
1272 | (unsigned long long) page_size); | ||
1364 | *estimate = pages * page_size; | 1273 | *estimate = pages * page_size; |
1365 | } | 1274 | } |
1366 | 1275 | ||
@@ -1379,10 +1288,8 @@ libgnunet_plugin_datastore_sqlite_init (void *cls) | |||
1379 | struct GNUNET_DATASTORE_PluginFunctions *api; | 1288 | struct GNUNET_DATASTORE_PluginFunctions *api; |
1380 | 1289 | ||
1381 | if (NULL != plugin.env) | 1290 | if (NULL != plugin.env) |
1382 | return NULL; /* can only initialize once! */ | 1291 | return NULL; /* can only initialize once! */ |
1383 | memset (&plugin, | 1292 | memset (&plugin, 0, sizeof (struct Plugin)); |
1384 | 0, | ||
1385 | sizeof (struct Plugin)); | ||
1386 | plugin.env = env; | 1293 | plugin.env = env; |
1387 | if (GNUNET_OK != database_setup (env->cfg, &plugin)) | 1294 | if (GNUNET_OK != database_setup (env->cfg, &plugin)) |
1388 | { | 1295 | { |
@@ -1402,7 +1309,7 @@ libgnunet_plugin_datastore_sqlite_init (void *cls) | |||
1402 | api->remove_key = &sqlite_plugin_remove_key; | 1309 | api->remove_key = &sqlite_plugin_remove_key; |
1403 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | 1310 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, |
1404 | "sqlite", | 1311 | "sqlite", |
1405 | _("Sqlite database running\n")); | 1312 | _ ("Sqlite database running\n")); |
1406 | return api; | 1313 | return api; |
1407 | } | 1314 | } |
1408 | 1315 | ||
@@ -1431,10 +1338,8 @@ libgnunet_plugin_datastore_sqlite_done (void *cls) | |||
1431 | GNUNET_free (api); | 1338 | GNUNET_free (api); |
1432 | if (NULL != fn) | 1339 | if (NULL != fn) |
1433 | { | 1340 | { |
1434 | if (0 != UNLINK (fn)) | 1341 | if (0 != unlink (fn)) |
1435 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 1342 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
1436 | "unlink", | ||
1437 | fn); | ||
1438 | GNUNET_free (fn); | 1343 | GNUNET_free (fn); |
1439 | } | 1344 | } |
1440 | return NULL; | 1345 | return NULL; |
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index daf6cccb3..ee78a8cfc 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c | |||
@@ -251,11 +251,11 @@ check_value (void *cls, | |||
251 | return; | 251 | return; |
252 | } | 252 | } |
253 | #if 0 | 253 | #if 0 |
254 | FPRINTF (stderr, | 254 | fprintf (stderr, |
255 | "Check value got `%s' of size %u, type %d, expire %s\n", | 255 | "Check value got `%s' of size %u, type %d, expire %s\n", |
256 | GNUNET_h2s (key), (unsigned int) size, type, | 256 | GNUNET_h2s (key), (unsigned int) size, type, |
257 | GNUNET_STRINGS_absolute_time_to_string (expiration)); | 257 | GNUNET_STRINGS_absolute_time_to_string (expiration)); |
258 | FPRINTF (stderr, | 258 | fprintf (stderr, |
259 | "Check value iteration %d wants size %u, type %d, expire %s\n", i, | 259 | "Check value iteration %d wants size %u, type %d, expire %s\n", i, |
260 | (unsigned int) get_size (i), get_type (i), | 260 | (unsigned int) get_size (i), get_type (i), |
261 | GNUNET_STRINGS_absolute_time_to_string (get_expiration(i))); | 261 | GNUNET_STRINGS_absolute_time_to_string (get_expiration(i))); |
@@ -555,14 +555,14 @@ run_tests (void *cls, | |||
555 | crc); | 555 | crc); |
556 | return; | 556 | return; |
557 | case GNUNET_NO: | 557 | case GNUNET_NO: |
558 | FPRINTF (stderr, | 558 | fprintf (stderr, |
559 | "%s", "Test 'put' operation failed, key already exists (!?)\n"); | 559 | "%s", "Test 'put' operation failed, key already exists (!?)\n"); |
560 | GNUNET_DATASTORE_disconnect (datastore, | 560 | GNUNET_DATASTORE_disconnect (datastore, |
561 | GNUNET_YES); | 561 | GNUNET_YES); |
562 | GNUNET_free (crc); | 562 | GNUNET_free (crc); |
563 | return; | 563 | return; |
564 | case GNUNET_SYSERR: | 564 | case GNUNET_SYSERR: |
565 | FPRINTF (stderr, | 565 | fprintf (stderr, |
566 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", | 566 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", |
567 | msg); | 567 | msg); |
568 | GNUNET_DATASTORE_disconnect (datastore, | 568 | GNUNET_DATASTORE_disconnect (datastore, |
@@ -609,7 +609,7 @@ run (void *cls, | |||
609 | 0, 1, | 609 | 0, 1, |
610 | &run_tests, crc)) | 610 | &run_tests, crc)) |
611 | { | 611 | { |
612 | FPRINTF (stderr, | 612 | fprintf (stderr, |
613 | "%s", | 613 | "%s", |
614 | "Test 'put' operation failed.\n"); | 614 | "Test 'put' operation failed.\n"); |
615 | ok = 1; | 615 | ok = 1; |
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c index d91fe748b..fc4c03885 100644 --- a/src/datastore/test_datastore_api_management.c +++ b/src/datastore/test_datastore_api_management.c | |||
@@ -272,7 +272,7 @@ run_tests (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, c | |||
272 | 272 | ||
273 | if (success != GNUNET_YES) | 273 | if (success != GNUNET_YES) |
274 | { | 274 | { |
275 | FPRINTF (stderr, | 275 | fprintf (stderr, |
276 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", | 276 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", |
277 | msg); | 277 | msg); |
278 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); | 278 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); |
@@ -310,7 +310,7 @@ run (void *cls, | |||
310 | &run_tests, | 310 | &run_tests, |
311 | crc)) | 311 | crc)) |
312 | { | 312 | { |
313 | FPRINTF (stderr, "%s", "Test 'put' operation failed.\n"); | 313 | fprintf (stderr, "%s", "Test 'put' operation failed.\n"); |
314 | GNUNET_free (crc); | 314 | GNUNET_free (crc); |
315 | ok = 1; | 315 | ok = 1; |
316 | } | 316 | } |
diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c index c37b8ddb9..2b7bf9ae4 100644 --- a/src/datastore/test_plugin_datastore.c +++ b/src/datastore/test_plugin_datastore.c | |||
@@ -108,7 +108,7 @@ put_continuation (void *cls, | |||
108 | 108 | ||
109 | if (GNUNET_OK != status) | 109 | if (GNUNET_OK != status) |
110 | { | 110 | { |
111 | FPRINTF (stderr, | 111 | fprintf (stderr, |
112 | "ERROR: `%s'\n", | 112 | "ERROR: `%s'\n", |
113 | msg); | 113 | msg); |
114 | } | 114 | } |
@@ -399,7 +399,7 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
399 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); | 399 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); |
400 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) | 400 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) |
401 | { | 401 | { |
402 | FPRINTF (stderr, "Failed to load plugin `%s'!\n", name); | 402 | fprintf (stderr, "Failed to load plugin `%s'!\n", name); |
403 | GNUNET_free (libname); | 403 | GNUNET_free (libname); |
404 | GNUNET_free (name); | 404 | GNUNET_free (name); |
405 | ok = 77; /* mark test as skipped */ | 405 | ok = 77; /* mark test as skipped */ |
@@ -421,7 +421,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
421 | api = load_plugin (c); | 421 | api = load_plugin (c); |
422 | if (api == NULL) | 422 | if (api == NULL) |
423 | { | 423 | { |
424 | FPRINTF (stderr, | 424 | fprintf (stderr, |
425 | "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); | 425 | "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); |
426 | return; | 426 | return; |
427 | } | 427 | } |
@@ -461,7 +461,7 @@ main (int argc, char *argv[]) | |||
461 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, | 461 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, |
462 | "test-plugin-datastore", "nohelp", options, &run, NULL); | 462 | "test-plugin-datastore", "nohelp", options, &run, NULL); |
463 | if ( (0 != ok) && (77 != ok) ) | 463 | if ( (0 != ok) && (77 != ok) ) |
464 | FPRINTF (stderr, "Missed some testcases: %u\n", ok); | 464 | fprintf (stderr, "Missed some testcases: %u\n", ok); |
465 | GNUNET_DISK_directory_remove (dir_name); | 465 | GNUNET_DISK_directory_remove (dir_name); |
466 | return ok; | 466 | return ok; |
467 | } | 467 | } |