aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/gnunet-service-datastore.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datastore/gnunet-service-datastore.c')
-rw-r--r--src/datastore/gnunet-service-datastore.c622
1 files changed, 292 insertions, 330 deletions
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;
234static void 233static void
235sync_stats () 234sync_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
359delete_expired (void *cls) 359delete_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, &quota_processor, &need);
452 &quota_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 */
577static void 567static void
578handle_reserve (void *cls, 568handle_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 */
659static void 651static void
660handle_release_reserve (void *cls, 652handle_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 */
789static int 776static int
790check_put (void *cls, 777check_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 */
808static void 794static void
809handle_put (void *cls, 795handle_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 */
866static void 851static void
867handle_get (void *cls, 852handle_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 */
896static void 880static void
897handle_get_key (void *cls, 881handle_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 */
947static void 934static void
948handle_get_replication (void *cls, 935handle_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 */
972static void 956static void
973handle_get_zero_anonymity (void *cls, 957handle_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 */
1061static int 1036static int
1062check_remove (void *cls, 1037check_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 */
1081static void 1055static void
1082handle_remove (void *cls, 1056handle_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 */
1109static void 1083static void
1110handle_drop (void *cls, 1084handle_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 */
1130static void 1102static void
1131disk_utilization_change_cb (void *cls, 1103disk_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
1242begin_service () 1212begin_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 */
1259static void 1229static void
1260add_key_to_bloomfilter (void *cls, 1230add_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 */
1287static void 1256static void
1288process_stat_done (void *cls, 1257process_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 */
1421static void * 1383static void *
1422client_connect_cb (void *cls, 1384client_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 */
1438static void 1400static void
1439client_disconnect_cb (void *cls, 1401client_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 (&quota_stat_name, 1465 GNUNET_asprintf (&quota_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", &quota))
1510 "DATASTORE",
1511 "QUOTA",
1512 &quota))
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 */
1642GNUNET_SERVICE_MAIN 1604GNUNET_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 */