aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/gnunet-service-datastore.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/datastore/gnunet-service-datastore.c
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/datastore/gnunet-service-datastore.c')
-rw-r--r--src/datastore/gnunet-service-datastore.c1518
1 files changed, 757 insertions, 761 deletions
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c
index 4596f6131..41abf77ca 100644
--- a/src/datastore/gnunet-service-datastore.c
+++ b/src/datastore/gnunet-service-datastore.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file datastore/gnunet-service-datastore.c 22 * @file datastore/gnunet-service-datastore.c
@@ -39,21 +39,21 @@
39/** 39/**
40 * Limit size of bloom filter to 2 GB. 40 * Limit size of bloom filter to 2 GB.
41 */ 41 */
42#define MAX_BF_SIZE ((uint32_t) (1LL << 31)) 42#define MAX_BF_SIZE ((uint32_t)(1LL << 31))
43 43
44/** 44/**
45 * How long are we at most keeping "expired" content 45 * How long are we at most keeping "expired" content
46 * past the expiration date in the database? 46 * past the expiration date in the database?
47 */ 47 */
48#define MAX_EXPIRE_DELAY \ 48#define MAX_EXPIRE_DELAY \
49 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 49 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15)
50 50
51/** 51/**
52 * How fast are we allowed to query the database for deleting 52 * How fast are we allowed to query the database for deleting
53 * expired content? (1 item per second). 53 * expired content? (1 item per second).
54 */ 54 */
55#define MIN_EXPIRE_DELAY \ 55#define MIN_EXPIRE_DELAY \
56 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 56 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
57 57
58/** 58/**
59 * Name under which we store current space consumption. 59 * Name under which we store current space consumption.
@@ -75,9 +75,7 @@ static struct GNUNET_SCHEDULER_Task *stat_timeout_task;
75/** 75/**
76 * Our datastore plugin. 76 * Our datastore plugin.
77 */ 77 */
78struct DatastorePlugin 78struct DatastorePlugin {
79{
80
81 /** 79 /**
82 * API of the transport as returned by the plugin's 80 * API of the transport as returned by the plugin's
83 * initialization function. 81 * initialization function.
@@ -105,9 +103,7 @@ struct DatastorePlugin
105/** 103/**
106 * Linked list of active reservations. 104 * Linked list of active reservations.
107 */ 105 */
108struct ReservationList 106struct ReservationList {
109{
110
111 /** 107 /**
112 * This is a linked list. 108 * This is a linked list.
113 */ 109 */
@@ -231,13 +227,13 @@ static int stats_worked;
231 * statistics service. 227 * statistics service.
232 */ 228 */
233static void 229static void
234sync_stats () 230sync_stats()
235{ 231{
236 GNUNET_STATISTICS_set (stats, quota_stat_name, payload, GNUNET_YES); 232 GNUNET_STATISTICS_set(stats, quota_stat_name, payload, GNUNET_YES);
237 GNUNET_STATISTICS_set (stats, 233 GNUNET_STATISTICS_set(stats,
238 "# utilization by current datastore", 234 "# utilization by current datastore",
239 payload, 235 payload,
240 GNUNET_NO); 236 GNUNET_NO);
241 last_sync = 0; 237 last_sync = 0;
242} 238}
243 239
@@ -267,7 +263,7 @@ static struct GNUNET_SERVICE_Handle *service;
267 * @param cls not used 263 * @param cls not used
268 */ 264 */
269static void 265static void
270delete_expired (void *cls); 266delete_expired(void *cls);
271 267
272 268
273/** 269/**
@@ -292,57 +288,57 @@ delete_expired (void *cls);
292 * #GNUNET_NO to delete the item and continue (if supported) 288 * #GNUNET_NO to delete the item and continue (if supported)
293 */ 289 */
294static int 290static int
295expired_processor (void *cls, 291expired_processor(void *cls,
296 const struct GNUNET_HashCode *key, 292 const struct GNUNET_HashCode *key,
297 uint32_t size, 293 uint32_t size,
298 const void *data, 294 const void *data,
299 enum GNUNET_BLOCK_Type type, 295 enum GNUNET_BLOCK_Type type,
300 uint32_t priority, 296 uint32_t priority,
301 uint32_t anonymity, 297 uint32_t anonymity,
302 uint32_t replication, 298 uint32_t replication,
303 struct GNUNET_TIME_Absolute expiration, 299 struct GNUNET_TIME_Absolute expiration,
304 uint64_t uid) 300 uint64_t uid)
305{ 301{
306 struct GNUNET_TIME_Absolute now; 302 struct GNUNET_TIME_Absolute now;
307 303
308 if (NULL == key) 304 if (NULL == key)
309 { 305 {
310 expired_kill_task = 306 expired_kill_task =
311 GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY, 307 GNUNET_SCHEDULER_add_delayed_with_priority(MAX_EXPIRE_DELAY,
312 GNUNET_SCHEDULER_PRIORITY_IDLE, 308 GNUNET_SCHEDULER_PRIORITY_IDLE,
313 &delete_expired, 309 &delete_expired,
314 NULL); 310 NULL);
315 return GNUNET_SYSERR; 311 return GNUNET_SYSERR;
316 } 312 }
317 now = GNUNET_TIME_absolute_get (); 313 now = GNUNET_TIME_absolute_get();
318 if (expiration.abs_value_us > now.abs_value_us) 314 if (expiration.abs_value_us > now.abs_value_us)
319 { 315 {
320 /* finished processing */ 316 /* finished processing */
321 expired_kill_task = 317 expired_kill_task =
322 GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY, 318 GNUNET_SCHEDULER_add_delayed_with_priority(MAX_EXPIRE_DELAY,
323 GNUNET_SCHEDULER_PRIORITY_IDLE, 319 GNUNET_SCHEDULER_PRIORITY_IDLE,
324 &delete_expired, 320 &delete_expired,
325 NULL); 321 NULL);
326 return GNUNET_SYSERR; 322 return GNUNET_SYSERR;
327 } 323 }
328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 324 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
329 "Deleting content `%s' of type %u that expired %s ago\n", 325 "Deleting content `%s' of type %u that expired %s ago\n",
330 GNUNET_h2s (key), 326 GNUNET_h2s(key),
331 type, 327 type,
332 GNUNET_STRINGS_relative_time_to_string ( 328 GNUNET_STRINGS_relative_time_to_string(
333 GNUNET_TIME_absolute_get_difference (expiration, now), 329 GNUNET_TIME_absolute_get_difference(expiration, now),
334 GNUNET_YES)); 330 GNUNET_YES));
335 min_expiration = now; 331 min_expiration = now;
336 GNUNET_STATISTICS_update (stats, 332 GNUNET_STATISTICS_update(stats,
337 gettext_noop ("# bytes expired"), 333 gettext_noop("# bytes expired"),
338 size, 334 size,
339 GNUNET_YES); 335 GNUNET_YES);
340 GNUNET_CONTAINER_bloomfilter_remove (filter, key); 336 GNUNET_CONTAINER_bloomfilter_remove(filter, key);
341 expired_kill_task = 337 expired_kill_task =
342 GNUNET_SCHEDULER_add_delayed_with_priority (MIN_EXPIRE_DELAY, 338 GNUNET_SCHEDULER_add_delayed_with_priority(MIN_EXPIRE_DELAY,
343 GNUNET_SCHEDULER_PRIORITY_IDLE, 339 GNUNET_SCHEDULER_PRIORITY_IDLE,
344 &delete_expired, 340 &delete_expired,
345 NULL); 341 NULL);
346 return GNUNET_NO; 342 return GNUNET_NO;
347} 343}
348 344
@@ -356,10 +352,10 @@ expired_processor (void *cls,
356 * @param cls not used 352 * @param cls not used
357 */ 353 */
358static void 354static void
359delete_expired (void *cls) 355delete_expired(void *cls)
360{ 356{
361 expired_kill_task = NULL; 357 expired_kill_task = NULL;
362 plugin->api->get_expiration (plugin->api->cls, &expired_processor, NULL); 358 plugin->api->get_expiration(plugin->api->cls, &expired_processor, NULL);
363} 359}
364 360
365 361
@@ -383,31 +379,31 @@ delete_expired (void *cls)
383 * #GNUNET_NO to delete the item and continue (if supported) 379 * #GNUNET_NO to delete the item and continue (if supported)
384 */ 380 */
385static int 381static int
386quota_processor (void *cls, 382quota_processor(void *cls,
387 const struct GNUNET_HashCode *key, 383 const struct GNUNET_HashCode *key,
388 uint32_t size, 384 uint32_t size,
389 const void *data, 385 const void *data,
390 enum GNUNET_BLOCK_Type type, 386 enum GNUNET_BLOCK_Type type,
391 uint32_t priority, 387 uint32_t priority,
392 uint32_t anonymity, 388 uint32_t anonymity,
393 uint32_t replication, 389 uint32_t replication,
394 struct GNUNET_TIME_Absolute expiration, 390 struct GNUNET_TIME_Absolute expiration,
395 uint64_t uid) 391 uint64_t uid)
396{ 392{
397 unsigned long long *need = cls; 393 unsigned long long *need = cls;
398 394
399 if (NULL == key) 395 if (NULL == key)
400 return GNUNET_SYSERR; 396 return GNUNET_SYSERR;
401 GNUNET_log ( 397 GNUNET_log(
402 GNUNET_ERROR_TYPE_DEBUG, 398 GNUNET_ERROR_TYPE_DEBUG,
403 "Deleting %llu bytes of low-priority (%u) content `%s' of type %u at %s prior to expiration (still trying to free another %llu bytes)\n", 399 "Deleting %llu bytes of low-priority (%u) content `%s' of type %u at %s prior to expiration (still trying to free another %llu bytes)\n",
404 (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD), 400 (unsigned long long)(size + GNUNET_DATASTORE_ENTRY_OVERHEAD),
405 (unsigned int) priority, 401 (unsigned int)priority,
406 GNUNET_h2s (key), 402 GNUNET_h2s(key),
407 type, 403 type,
408 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining ( 404 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining(
409 expiration), 405 expiration),
410 GNUNET_YES), 406 GNUNET_YES),
411 *need); 407 *need);
412 if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need) 408 if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need)
413 *need = 0; 409 *need = 0;
@@ -417,11 +413,11 @@ quota_processor (void *cls,
417 min_expiration = GNUNET_TIME_UNIT_FOREVER_ABS; 413 min_expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
418 else 414 else
419 min_expiration = expiration; 415 min_expiration = expiration;
420 GNUNET_STATISTICS_update (stats, 416 GNUNET_STATISTICS_update(stats,
421 gettext_noop ("# bytes purged (low-priority)"), 417 gettext_noop("# bytes purged (low-priority)"),
422 size, 418 size,
423 GNUNET_YES); 419 GNUNET_YES);
424 GNUNET_CONTAINER_bloomfilter_remove (filter, key); 420 GNUNET_CONTAINER_bloomfilter_remove(filter, key);
425 return GNUNET_NO; 421 return GNUNET_NO;
426} 422}
427 423
@@ -439,19 +435,19 @@ quota_processor (void *cls,
439 * number of bytes that should be removed). 435 * number of bytes that should be removed).
440 */ 436 */
441static void 437static void
442manage_space (unsigned long long need) 438manage_space(unsigned long long need)
443{ 439{
444 unsigned long long last; 440 unsigned long long last;
445 441
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 442 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
447 "Asked to free up %llu bytes of cache space\n", 443 "Asked to free up %llu bytes of cache space\n",
448 need); 444 need);
449 last = 0; 445 last = 0;
450 while ((need > 0) && (last != need)) 446 while ((need > 0) && (last != need))
451 { 447 {
452 last = need; 448 last = need;
453 plugin->api->get_expiration (plugin->api->cls, &quota_processor, &need); 449 plugin->api->get_expiration(plugin->api->cls, &quota_processor, &need);
454 } 450 }
455} 451}
456 452
457 453
@@ -463,25 +459,25 @@ manage_space (unsigned long long need)
463 * @param msg optional error message (can be NULL) 459 * @param msg optional error message (can be NULL)
464 */ 460 */
465static void 461static void
466transmit_status (struct GNUNET_SERVICE_Client *client, 462transmit_status(struct GNUNET_SERVICE_Client *client,
467 int code, 463 int code,
468 const char *msg) 464 const char *msg)
469{ 465{
470 struct GNUNET_MQ_Envelope *env; 466 struct GNUNET_MQ_Envelope *env;
471 struct StatusMessage *sm; 467 struct StatusMessage *sm;
472 size_t slen; 468 size_t slen;
473 469
474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 470 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
475 "Transmitting `%s' message with value %d and message `%s'\n", 471 "Transmitting `%s' message with value %d and message `%s'\n",
476 "STATUS", 472 "STATUS",
477 code, 473 code,
478 msg != NULL ? msg : "(none)"); 474 msg != NULL ? msg : "(none)");
479 slen = (msg == NULL) ? 0 : strlen (msg) + 1; 475 slen = (msg == NULL) ? 0 : strlen(msg) + 1;
480 env = GNUNET_MQ_msg_extra (sm, slen, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS); 476 env = GNUNET_MQ_msg_extra(sm, slen, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS);
481 sm->status = htonl (code); 477 sm->status = htonl(code);
482 sm->min_expiration = GNUNET_TIME_absolute_hton (min_expiration); 478 sm->min_expiration = GNUNET_TIME_absolute_hton(min_expiration);
483 GNUNET_memcpy (&sm[1], msg, slen); 479 GNUNET_memcpy(&sm[1], msg, slen);
484 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 480 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env);
485} 481}
486 482
487 483
@@ -504,16 +500,16 @@ transmit_status (struct GNUNET_SERVICE_Client *client,
504 * #GNUNET_NO to delete the item and continue (if supported) 500 * #GNUNET_NO to delete the item and continue (if supported)
505 */ 501 */
506static int 502static int
507transmit_item (void *cls, 503transmit_item(void *cls,
508 const struct GNUNET_HashCode *key, 504 const struct GNUNET_HashCode *key,
509 uint32_t size, 505 uint32_t size,
510 const void *data, 506 const void *data,
511 enum GNUNET_BLOCK_Type type, 507 enum GNUNET_BLOCK_Type type,
512 uint32_t priority, 508 uint32_t priority,
513 uint32_t anonymity, 509 uint32_t anonymity,
514 uint32_t replication, 510 uint32_t replication,
515 struct GNUNET_TIME_Absolute expiration, 511 struct GNUNET_TIME_Absolute expiration,
516 uint64_t uid) 512 uint64_t uid)
517{ 513{
518 struct GNUNET_SERVICE_Client *client = cls; 514 struct GNUNET_SERVICE_Client *client = cls;
519 struct GNUNET_MQ_Envelope *env; 515 struct GNUNET_MQ_Envelope *env;
@@ -521,39 +517,39 @@ transmit_item (void *cls,
521 struct DataMessage *dm; 517 struct DataMessage *dm;
522 518
523 if (NULL == key) 519 if (NULL == key)
524 { 520 {
525 /* transmit 'DATA_END' */ 521 /* transmit 'DATA_END' */
526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting DATA_END message\n"); 522 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Transmitting DATA_END message\n");
527 env = GNUNET_MQ_msg (end, GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END); 523 env = GNUNET_MQ_msg(end, GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END);
528 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 524 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env);
529 return GNUNET_OK; 525 return GNUNET_OK;
530 } 526 }
531 GNUNET_assert (sizeof (struct DataMessage) + size < GNUNET_MAX_MESSAGE_SIZE); 527 GNUNET_assert(sizeof(struct DataMessage) + size < GNUNET_MAX_MESSAGE_SIZE);
532 env = GNUNET_MQ_msg_extra (dm, size, GNUNET_MESSAGE_TYPE_DATASTORE_DATA); 528 env = GNUNET_MQ_msg_extra(dm, size, GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
533 dm->rid = htonl (0); 529 dm->rid = htonl(0);
534 dm->size = htonl (size); 530 dm->size = htonl(size);
535 dm->type = htonl (type); 531 dm->type = htonl(type);
536 dm->priority = htonl (priority); 532 dm->priority = htonl(priority);
537 dm->anonymity = htonl (anonymity); 533 dm->anonymity = htonl(anonymity);
538 dm->replication = htonl (replication); 534 dm->replication = htonl(replication);
539 dm->expiration = GNUNET_TIME_absolute_hton (expiration); 535 dm->expiration = GNUNET_TIME_absolute_hton(expiration);
540 dm->uid = GNUNET_htonll (uid); 536 dm->uid = GNUNET_htonll(uid);
541 dm->key = *key; 537 dm->key = *key;
542 GNUNET_memcpy (&dm[1], data, size); 538 GNUNET_memcpy(&dm[1], data, size);
543 GNUNET_log ( 539 GNUNET_log(
544 GNUNET_ERROR_TYPE_DEBUG, 540 GNUNET_ERROR_TYPE_DEBUG,
545 "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n", 541 "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n",
546 GNUNET_h2s (key), 542 GNUNET_h2s(key),
547 type, 543 type,
548 GNUNET_STRINGS_absolute_time_to_string (expiration), 544 GNUNET_STRINGS_absolute_time_to_string(expiration),
549 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining ( 545 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining(
550 expiration), 546 expiration),
551 GNUNET_YES)); 547 GNUNET_YES));
552 GNUNET_STATISTICS_update (stats, 548 GNUNET_STATISTICS_update(stats,
553 gettext_noop ("# results found"), 549 gettext_noop("# results found"),
554 1, 550 1,
555 GNUNET_NO); 551 GNUNET_NO);
556 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 552 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env);
557 return GNUNET_OK; 553 return GNUNET_OK;
558} 554}
559 555
@@ -565,7 +561,7 @@ transmit_item (void *cls,
565 * @param message the actual message 561 * @param message the actual message
566 */ 562 */
567static void 563static void
568handle_reserve (void *cls, const struct ReserveMessage *msg) 564handle_reserve(void *cls, const struct ReserveMessage *msg)
569{ 565{
570 /** 566 /**
571 * Static counter to produce reservation identifiers. 567 * Static counter to produce reservation identifiers.
@@ -578,57 +574,57 @@ handle_reserve (void *cls, const struct ReserveMessage *msg)
578 uint64_t amount; 574 uint64_t amount;
579 uint32_t entries; 575 uint32_t entries;
580 576
581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing RESERVE request\n"); 577 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing RESERVE request\n");
582 amount = GNUNET_ntohll (msg->amount); 578 amount = GNUNET_ntohll(msg->amount);
583 entries = ntohl (msg->entries); 579 entries = ntohl(msg->entries);
584 used = payload + reserved; 580 used = payload + reserved;
585 req = 581 req =
586 amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries; 582 amount + ((unsigned long long)GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries;
587 if (used + req > quota) 583 if (used + req > quota)
588 {
589 if (quota < used)
590 used =
591 quota; /* cheat a bit for error message (to avoid negative numbers) */
592 GNUNET_log (
593 GNUNET_ERROR_TYPE_WARNING,
594 _ (
595 "Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"),
596 quota - used,
597 req);
598 if (cache_size < req)
599 { 584 {
600 /* TODO: document this in the FAQ; essentially, if this 585 if (quota < used)
601 * message happens, the insertion request could be blocked 586 used =
602 * by less-important content from migration because it is 587 quota; /* cheat a bit for error message (to avoid negative numbers) */
603 * larger than 1/8th of the overall available space, and 588 GNUNET_log(
604 * we only reserve 1/8th for "fresh" insertions */
605 GNUNET_log (
606 GNUNET_ERROR_TYPE_WARNING, 589 GNUNET_ERROR_TYPE_WARNING,
607 _ ( 590 _(
608 "The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"), 591 "Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"),
609 req, 592 quota - used,
610 cache_size); 593 req);
611 transmit_status (client, 594 if (cache_size < req)
612 0, 595 {
613 gettext_noop ( 596 /* TODO: document this in the FAQ; essentially, if this
614 "Insufficient space to satisfy request and " 597 * message happens, the insertion request could be blocked
615 "requested amount is larger than cache size")); 598 * by less-important content from migration because it is
616 } 599 * larger than 1/8th of the overall available space, and
617 else 600 * we only reserve 1/8th for "fresh" insertions */
618 { 601 GNUNET_log(
619 transmit_status (client, 602 GNUNET_ERROR_TYPE_WARNING,
620 0, 603 _(
621 gettext_noop ("Insufficient space to satisfy request")); 604 "The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"),
605 req,
606 cache_size);
607 transmit_status(client,
608 0,
609 gettext_noop(
610 "Insufficient space to satisfy request and "
611 "requested amount is larger than cache size"));
612 }
613 else
614 {
615 transmit_status(client,
616 0,
617 gettext_noop("Insufficient space to satisfy request"));
618 }
619 GNUNET_SERVICE_client_continue(client);
620 return;
622 } 621 }
623 GNUNET_SERVICE_client_continue (client);
624 return;
625 }
626 reserved += req; 622 reserved += req;
627 GNUNET_STATISTICS_set (stats, 623 GNUNET_STATISTICS_set(stats,
628 gettext_noop ("# reserved"), 624 gettext_noop("# reserved"),
629 reserved, 625 reserved,
630 GNUNET_NO); 626 GNUNET_NO);
631 e = GNUNET_new (struct ReservationList); 627 e = GNUNET_new(struct ReservationList);
632 e->next = reservations; 628 e->next = reservations;
633 reservations = e; 629 reservations = e;
634 e->client = client; 630 e->client = client;
@@ -637,8 +633,8 @@ handle_reserve (void *cls, const struct ReserveMessage *msg)
637 e->rid = ++reservation_gen; 633 e->rid = ++reservation_gen;
638 if (reservation_gen < 0) 634 if (reservation_gen < 0)
639 reservation_gen = 0; /* wrap around */ 635 reservation_gen = 0; /* wrap around */
640 transmit_status (client, e->rid, NULL); 636 transmit_status(client, e->rid, NULL);
641 GNUNET_SERVICE_client_continue (client); 637 GNUNET_SERVICE_client_continue(client);
642} 638}
643 639
644 640
@@ -649,51 +645,51 @@ handle_reserve (void *cls, const struct ReserveMessage *msg)
649 * @param message the actual message 645 * @param message the actual message
650 */ 646 */
651static void 647static void
652handle_release_reserve (void *cls, const struct ReleaseReserveMessage *msg) 648handle_release_reserve(void *cls, const struct ReleaseReserveMessage *msg)
653{ 649{
654 struct GNUNET_SERVICE_Client *client = cls; 650 struct GNUNET_SERVICE_Client *client = cls;
655 struct ReservationList *pos; 651 struct ReservationList *pos;
656 struct ReservationList *prev; 652 struct ReservationList *prev;
657 struct ReservationList *next; 653 struct ReservationList *next;
658 int rid = ntohl (msg->rid); 654 int rid = ntohl(msg->rid);
659 unsigned long long rem; 655 unsigned long long rem;
660 656
661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing RELEASE_RESERVE request\n"); 657 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing RELEASE_RESERVE request\n");
662 next = reservations; 658 next = reservations;
663 prev = NULL; 659 prev = NULL;
664 while (NULL != (pos = next)) 660 while (NULL != (pos = next))
665 {
666 next = pos->next;
667 if (rid == pos->rid)
668 { 661 {
669 if (prev == NULL) 662 next = pos->next;
670 reservations = next; 663 if (rid == pos->rid)
671 else 664 {
672 prev->next = next; 665 if (prev == NULL)
673 rem = 666 reservations = next;
674 pos->amount + 667 else
675 ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries; 668 prev->next = next;
676 GNUNET_assert (reserved >= rem); 669 rem =
677 reserved -= rem; 670 pos->amount +
678 GNUNET_STATISTICS_set (stats, 671 ((unsigned long long)GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries;
679 gettext_noop ("# reserved"), 672 GNUNET_assert(reserved >= rem);
680 reserved, 673 reserved -= rem;
681 GNUNET_NO); 674 GNUNET_STATISTICS_set(stats,
682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 675 gettext_noop("# reserved"),
683 "Returning %llu remaining reserved bytes to storage pool\n", 676 reserved,
684 rem); 677 GNUNET_NO);
685 GNUNET_free (pos); 678 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
686 transmit_status (client, GNUNET_OK, NULL); 679 "Returning %llu remaining reserved bytes to storage pool\n",
687 GNUNET_SERVICE_client_continue (client); 680 rem);
688 return; 681 GNUNET_free(pos);
682 transmit_status(client, GNUNET_OK, NULL);
683 GNUNET_SERVICE_client_continue(client);
684 return;
685 }
686 prev = pos;
689 } 687 }
690 prev = pos; 688 GNUNET_break(0);
691 } 689 transmit_status(client,
692 GNUNET_break (0); 690 GNUNET_SYSERR,
693 transmit_status (client, 691 gettext_noop("Could not find matching reservation"));
694 GNUNET_SYSERR, 692 GNUNET_SERVICE_client_continue(client);
695 gettext_noop ("Could not find matching reservation"));
696 GNUNET_SERVICE_client_continue (client);
697} 693}
698 694
699 695
@@ -704,18 +700,18 @@ handle_release_reserve (void *cls, const struct ReleaseReserveMessage *msg)
704 * @return #GNUNET_SYSERR is not well-formed, otherwise #GNUNET_OK 700 * @return #GNUNET_SYSERR is not well-formed, otherwise #GNUNET_OK
705 */ 701 */
706static int 702static int
707check_data (const struct DataMessage *dm) 703check_data(const struct DataMessage *dm)
708{ 704{
709 uint16_t size; 705 uint16_t size;
710 uint32_t dsize; 706 uint32_t dsize;
711 707
712 size = ntohs (dm->header.size); 708 size = ntohs(dm->header.size);
713 dsize = ntohl (dm->size); 709 dsize = ntohl(dm->size);
714 if (size != dsize + sizeof (struct DataMessage)) 710 if (size != dsize + sizeof(struct DataMessage))
715 { 711 {
716 GNUNET_break (0); 712 GNUNET_break(0);
717 return GNUNET_SYSERR; 713 return GNUNET_SYSERR;
718 } 714 }
719 return GNUNET_OK; 715 return GNUNET_OK;
720} 716}
721 717
@@ -731,38 +727,38 @@ check_data (const struct DataMessage *dm)
731 * @param msg error message on error 727 * @param msg error message on error
732 */ 728 */
733static void 729static void
734put_continuation (void *cls, 730put_continuation(void *cls,
735 const struct GNUNET_HashCode *key, 731 const struct GNUNET_HashCode *key,
736 uint32_t size, 732 uint32_t size,
737 int status, 733 int status,
738 const char *msg) 734 const char *msg)
739{ 735{
740 struct GNUNET_SERVICE_Client *client = cls; 736 struct GNUNET_SERVICE_Client *client = cls;
741 737
742 if (GNUNET_OK == status) 738 if (GNUNET_OK == status)
743 { 739 {
744 GNUNET_STATISTICS_update (stats, 740 GNUNET_STATISTICS_update(stats,
745 gettext_noop ("# bytes stored"), 741 gettext_noop("# bytes stored"),
746 size, 742 size,
747 GNUNET_YES); 743 GNUNET_YES);
748 GNUNET_CONTAINER_bloomfilter_add (filter, key); 744 GNUNET_CONTAINER_bloomfilter_add(filter, key);
749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 745 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
750 "Successfully stored %u bytes under key `%s'\n", 746 "Successfully stored %u bytes under key `%s'\n",
751 size, 747 size,
752 GNUNET_h2s (key)); 748 GNUNET_h2s(key));
753 } 749 }
754 transmit_status (client, 750 transmit_status(client,
755 GNUNET_SYSERR == status ? GNUNET_SYSERR : GNUNET_OK, 751 GNUNET_SYSERR == status ? GNUNET_SYSERR : GNUNET_OK,
756 msg); 752 msg);
757 if (quota - reserved - cache_size < payload) 753 if (quota - reserved - cache_size < payload)
758 { 754 {
759 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 755 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
760 _ ("Need %llu bytes more space (%llu allowed, using %llu)\n"), 756 _("Need %llu bytes more space (%llu allowed, using %llu)\n"),
761 (unsigned long long) size + GNUNET_DATASTORE_ENTRY_OVERHEAD, 757 (unsigned long long)size + GNUNET_DATASTORE_ENTRY_OVERHEAD,
762 (unsigned long long) (quota - reserved - cache_size), 758 (unsigned long long)(quota - reserved - cache_size),
763 (unsigned long long) payload); 759 (unsigned long long)payload);
764 manage_space (size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 760 manage_space(size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
765 } 761 }
766} 762}
767 763
768 764
@@ -774,13 +770,13 @@ put_continuation (void *cls,
774 * @return #GNUNET_OK if @a dm is well-formed 770 * @return #GNUNET_OK if @a dm is well-formed
775 */ 771 */
776static int 772static int
777check_put (void *cls, const struct DataMessage *dm) 773check_put(void *cls, const struct DataMessage *dm)
778{ 774{
779 if (GNUNET_OK != check_data (dm)) 775 if (GNUNET_OK != check_data(dm))
780 { 776 {
781 GNUNET_break (0); 777 GNUNET_break(0);
782 return GNUNET_SYSERR; 778 return GNUNET_SYSERR;
783 } 779 }
784 return GNUNET_OK; 780 return GNUNET_OK;
785} 781}
786 782
@@ -792,53 +788,53 @@ check_put (void *cls, const struct DataMessage *dm)
792 * @param message the actual message 788 * @param message the actual message
793 */ 789 */
794static void 790static void
795handle_put (void *cls, const struct DataMessage *dm) 791handle_put(void *cls, const struct DataMessage *dm)
796{ 792{
797 struct GNUNET_SERVICE_Client *client = cls; 793 struct GNUNET_SERVICE_Client *client = cls;
798 int rid; 794 int rid;
799 struct ReservationList *pos; 795 struct ReservationList *pos;
800 uint32_t size; 796 uint32_t size;
801 797
802 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 798 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
803 "Processing PUT request for `%s' of type %u\n", 799 "Processing PUT request for `%s' of type %u\n",
804 GNUNET_h2s (&dm->key), 800 GNUNET_h2s(&dm->key),
805 (uint32_t) ntohl (dm->type)); 801 (uint32_t)ntohl(dm->type));
806 rid = ntohl (dm->rid); 802 rid = ntohl(dm->rid);
807 size = ntohl (dm->size); 803 size = ntohl(dm->size);
808 if (rid > 0) 804 if (rid > 0)
809 {
810 pos = reservations;
811 while ((NULL != pos) && (rid != pos->rid))
812 pos = pos->next;
813 GNUNET_break (pos != NULL);
814 if (NULL != pos)
815 { 805 {
816 GNUNET_break (pos->entries > 0); 806 pos = reservations;
817 GNUNET_break (pos->amount >= size); 807 while ((NULL != pos) && (rid != pos->rid))
818 pos->entries--; 808 pos = pos->next;
819 pos->amount -= size; 809 GNUNET_break(pos != NULL);
820 reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 810 if (NULL != pos)
821 GNUNET_STATISTICS_set (stats, 811 {
822 gettext_noop ("# reserved"), 812 GNUNET_break(pos->entries > 0);
823 reserved, 813 GNUNET_break(pos->amount >= size);
824 GNUNET_NO); 814 pos->entries--;
815 pos->amount -= size;
816 reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
817 GNUNET_STATISTICS_set(stats,
818 gettext_noop("# reserved"),
819 reserved,
820 GNUNET_NO);
821 }
825 } 822 }
826 }
827 bool absent = 823 bool absent =
828 GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key); 824 GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test(filter, &dm->key);
829 plugin->api->put (plugin->api->cls, 825 plugin->api->put(plugin->api->cls,
830 &dm->key, 826 &dm->key,
831 absent, 827 absent,
832 ntohl (dm->size), 828 ntohl(dm->size),
833 &dm[1], 829 &dm[1],
834 ntohl (dm->type), 830 ntohl(dm->type),
835 ntohl (dm->priority), 831 ntohl(dm->priority),
836 ntohl (dm->anonymity), 832 ntohl(dm->anonymity),
837 ntohl (dm->replication), 833 ntohl(dm->replication),
838 GNUNET_TIME_absolute_ntoh (dm->expiration), 834 GNUNET_TIME_absolute_ntoh(dm->expiration),
839 &put_continuation, 835 &put_continuation,
840 client); 836 client);
841 GNUNET_SERVICE_client_continue (client); 837 GNUNET_SERVICE_client_continue(client);
842} 838}
843 839
844 840
@@ -849,25 +845,25 @@ handle_put (void *cls, const struct DataMessage *dm)
849 * @param msg the actual message 845 * @param msg the actual message
850 */ 846 */
851static void 847static void
852handle_get (void *cls, const struct GetMessage *msg) 848handle_get(void *cls, const struct GetMessage *msg)
853{ 849{
854 struct GNUNET_SERVICE_Client *client = cls; 850 struct GNUNET_SERVICE_Client *client = cls;
855 851
856 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 852 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
857 "Processing GET request of type %u\n", 853 "Processing GET request of type %u\n",
858 (uint32_t) ntohl (msg->type)); 854 (uint32_t)ntohl(msg->type));
859 GNUNET_STATISTICS_update (stats, 855 GNUNET_STATISTICS_update(stats,
860 gettext_noop ("# GET requests received"), 856 gettext_noop("# GET requests received"),
861 1, 857 1,
862 GNUNET_NO); 858 GNUNET_NO);
863 plugin->api->get_key (plugin->api->cls, 859 plugin->api->get_key(plugin->api->cls,
864 GNUNET_ntohll (msg->next_uid), 860 GNUNET_ntohll(msg->next_uid),
865 msg->random, 861 msg->random,
866 NULL, 862 NULL,
867 ntohl (msg->type), 863 ntohl(msg->type),
868 &transmit_item, 864 &transmit_item,
869 client); 865 client);
870 GNUNET_SERVICE_client_continue (client); 866 GNUNET_SERVICE_client_continue(client);
871} 867}
872 868
873 869
@@ -878,50 +874,50 @@ handle_get (void *cls, const struct GetMessage *msg)
878 * @param msg the actual message 874 * @param msg the actual message
879 */ 875 */
880static void 876static void
881handle_get_key (void *cls, const struct GetKeyMessage *msg) 877handle_get_key(void *cls, const struct GetKeyMessage *msg)
882{ 878{
883 struct GNUNET_SERVICE_Client *client = cls; 879 struct GNUNET_SERVICE_Client *client = cls;
884 880
885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 881 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
886 "Processing GET request for `%s' of type %u\n", 882 "Processing GET request for `%s' of type %u\n",
887 GNUNET_h2s (&msg->key), 883 GNUNET_h2s(&msg->key),
888 (uint32_t) ntohl (msg->type)); 884 (uint32_t)ntohl(msg->type));
889 GNUNET_STATISTICS_update (stats, 885 GNUNET_STATISTICS_update(stats,
890 gettext_noop ("# GET KEY requests received"), 886 gettext_noop("# GET KEY requests received"),
891 1, 887 1,
892 GNUNET_NO); 888 GNUNET_NO);
893 if (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key)) 889 if (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test(filter, &msg->key))
894 { 890 {
895 /* don't bother database... */ 891 /* don't bother database... */
896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 892 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
897 "Empty result set for GET request for `%s' (bloomfilter).\n", 893 "Empty result set for GET request for `%s' (bloomfilter).\n",
898 GNUNET_h2s (&msg->key)); 894 GNUNET_h2s(&msg->key));
899 GNUNET_STATISTICS_update (stats, 895 GNUNET_STATISTICS_update(stats,
900 gettext_noop ( 896 gettext_noop(
901 "# requests filtered by bloomfilter"), 897 "# requests filtered by bloomfilter"),
902 1, 898 1,
903 GNUNET_NO); 899 GNUNET_NO);
904 transmit_item (client, 900 transmit_item(client,
905 NULL, 901 NULL,
906 0, 902 0,
907 NULL, 903 NULL,
908 0, 904 0,
909 0, 905 0,
910 0, 906 0,
911 0, 907 0,
912 GNUNET_TIME_UNIT_ZERO_ABS, 908 GNUNET_TIME_UNIT_ZERO_ABS,
913 0); 909 0);
914 GNUNET_SERVICE_client_continue (client); 910 GNUNET_SERVICE_client_continue(client);
915 return; 911 return;
916 } 912 }
917 plugin->api->get_key (plugin->api->cls, 913 plugin->api->get_key(plugin->api->cls,
918 GNUNET_ntohll (msg->next_uid), 914 GNUNET_ntohll(msg->next_uid),
919 msg->random, 915 msg->random,
920 &msg->key, 916 &msg->key,
921 ntohl (msg->type), 917 ntohl(msg->type),
922 &transmit_item, 918 &transmit_item,
923 client); 919 client);
924 GNUNET_SERVICE_client_continue (client); 920 GNUNET_SERVICE_client_continue(client);
925} 921}
926 922
927 923
@@ -932,18 +928,18 @@ handle_get_key (void *cls, const struct GetKeyMessage *msg)
932 * @param message the actual message 928 * @param message the actual message
933 */ 929 */
934static void 930static void
935handle_get_replication (void *cls, const struct GNUNET_MessageHeader *message) 931handle_get_replication(void *cls, const struct GNUNET_MessageHeader *message)
936{ 932{
937 struct GNUNET_SERVICE_Client *client = cls; 933 struct GNUNET_SERVICE_Client *client = cls;
938 934
939 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing GET_REPLICATION request\n"); 935 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing GET_REPLICATION request\n");
940 GNUNET_STATISTICS_update (stats, 936 GNUNET_STATISTICS_update(stats,
941 gettext_noop ( 937 gettext_noop(
942 "# GET REPLICATION requests received"), 938 "# GET REPLICATION requests received"),
943 1, 939 1,
944 GNUNET_NO); 940 GNUNET_NO);
945 plugin->api->get_replication (plugin->api->cls, &transmit_item, client); 941 plugin->api->get_replication(plugin->api->cls, &transmit_item, client);
946 GNUNET_SERVICE_client_continue (client); 942 GNUNET_SERVICE_client_continue(client);
947} 943}
948 944
949 945
@@ -954,31 +950,31 @@ handle_get_replication (void *cls, const struct GNUNET_MessageHeader *message)
954 * @param message the actual message 950 * @param message the actual message
955 */ 951 */
956static void 952static void
957handle_get_zero_anonymity (void *cls, const struct GetZeroAnonymityMessage *msg) 953handle_get_zero_anonymity(void *cls, const struct GetZeroAnonymityMessage *msg)
958{ 954{
959 struct GNUNET_SERVICE_Client *client = cls; 955 struct GNUNET_SERVICE_Client *client = cls;
960 enum GNUNET_BLOCK_Type type; 956 enum GNUNET_BLOCK_Type type;
961 957
962 type = (enum GNUNET_BLOCK_Type) ntohl (msg->type); 958 type = (enum GNUNET_BLOCK_Type)ntohl(msg->type);
963 if (type == GNUNET_BLOCK_TYPE_ANY) 959 if (type == GNUNET_BLOCK_TYPE_ANY)
964 { 960 {
965 GNUNET_break (0); 961 GNUNET_break(0);
966 GNUNET_SERVICE_client_drop (client); 962 GNUNET_SERVICE_client_drop(client);
967 return; 963 return;
968 } 964 }
969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 965 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
970 "Processing GET_ZERO_ANONYMITY request\n"); 966 "Processing GET_ZERO_ANONYMITY request\n");
971 GNUNET_STATISTICS_update (stats, 967 GNUNET_STATISTICS_update(stats,
972 gettext_noop ( 968 gettext_noop(
973 "# GET ZERO ANONYMITY requests received"), 969 "# GET ZERO ANONYMITY requests received"),
974 1, 970 1,
975 GNUNET_NO); 971 GNUNET_NO);
976 plugin->api->get_zero_anonymity (plugin->api->cls, 972 plugin->api->get_zero_anonymity(plugin->api->cls,
977 GNUNET_ntohll (msg->next_uid), 973 GNUNET_ntohll(msg->next_uid),
978 type, 974 type,
979 &transmit_item, 975 &transmit_item,
980 client); 976 client);
981 GNUNET_SERVICE_client_continue (client); 977 GNUNET_SERVICE_client_continue(client);
982} 978}
983 979
984 980
@@ -993,36 +989,36 @@ handle_get_zero_anonymity (void *cls, const struct GetZeroAnonymityMessage *msg)
993 * @param msg error message on error 989 * @param msg error message on error
994 */ 990 */
995static void 991static void
996remove_continuation (void *cls, 992remove_continuation(void *cls,
997 const struct GNUNET_HashCode *key, 993 const struct GNUNET_HashCode *key,
998 uint32_t size, 994 uint32_t size,
999 int status, 995 int status,
1000 const char *msg) 996 const char *msg)
1001{ 997{
1002 struct GNUNET_SERVICE_Client *client = cls; 998 struct GNUNET_SERVICE_Client *client = cls;
1003 999
1004 if (GNUNET_SYSERR == status) 1000 if (GNUNET_SYSERR == status)
1005 { 1001 {
1006 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "REMOVE request failed: %s.\n", msg); 1002 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "REMOVE request failed: %s.\n", msg);
1007 transmit_status (client, GNUNET_NO, msg); 1003 transmit_status(client, GNUNET_NO, msg);
1008 return; 1004 return;
1009 } 1005 }
1010 if (GNUNET_NO == status) 1006 if (GNUNET_NO == status)
1011 { 1007 {
1012 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1008 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1013 "Content not found for REMOVE request.\n"); 1009 "Content not found for REMOVE request.\n");
1014 transmit_status (client, GNUNET_NO, _ ("Content not found")); 1010 transmit_status(client, GNUNET_NO, _("Content not found"));
1015 return; 1011 return;
1016 } 1012 }
1017 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1013 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1018 "Item matches REMOVE request for key `%s'.\n", 1014 "Item matches REMOVE request for key `%s'.\n",
1019 GNUNET_h2s (key)); 1015 GNUNET_h2s(key));
1020 GNUNET_STATISTICS_update (stats, 1016 GNUNET_STATISTICS_update(stats,
1021 gettext_noop ("# bytes removed (explicit request)"), 1017 gettext_noop("# bytes removed (explicit request)"),
1022 size, 1018 size,
1023 GNUNET_YES); 1019 GNUNET_YES);
1024 GNUNET_CONTAINER_bloomfilter_remove (filter, key); 1020 GNUNET_CONTAINER_bloomfilter_remove(filter, key);
1025 transmit_status (client, GNUNET_OK, NULL); 1021 transmit_status(client, GNUNET_OK, NULL);
1026} 1022}
1027 1023
1028 1024
@@ -1034,13 +1030,13 @@ remove_continuation (void *cls,
1034 * @return #GNUNET_OK if @a dm is well-formed 1030 * @return #GNUNET_OK if @a dm is well-formed
1035 */ 1031 */
1036static int 1032static int
1037check_remove (void *cls, const struct DataMessage *dm) 1033check_remove(void *cls, const struct DataMessage *dm)
1038{ 1034{
1039 if (GNUNET_OK != check_data (dm)) 1035 if (GNUNET_OK != check_data(dm))
1040 { 1036 {
1041 GNUNET_break (0); 1037 GNUNET_break(0);
1042 return GNUNET_SYSERR; 1038 return GNUNET_SYSERR;
1043 } 1039 }
1044 return GNUNET_OK; 1040 return GNUNET_OK;
1045} 1041}
1046 1042
@@ -1053,24 +1049,24 @@ check_remove (void *cls, const struct DataMessage *dm)
1053 * @param message the actual message 1049 * @param message the actual message
1054 */ 1050 */
1055static void 1051static void
1056handle_remove (void *cls, const struct DataMessage *dm) 1052handle_remove(void *cls, const struct DataMessage *dm)
1057{ 1053{
1058 struct GNUNET_SERVICE_Client *client = cls; 1054 struct GNUNET_SERVICE_Client *client = cls;
1059 1055
1060 GNUNET_STATISTICS_update (stats, 1056 GNUNET_STATISTICS_update(stats,
1061 gettext_noop ("# REMOVE requests received"), 1057 gettext_noop("# REMOVE requests received"),
1062 1, 1058 1,
1063 GNUNET_NO); 1059 GNUNET_NO);
1064 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1060 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1065 "Processing REMOVE request for `%s'\n", 1061 "Processing REMOVE request for `%s'\n",
1066 GNUNET_h2s (&dm->key)); 1062 GNUNET_h2s(&dm->key));
1067 plugin->api->remove_key (plugin->api->cls, 1063 plugin->api->remove_key(plugin->api->cls,
1068 &dm->key, 1064 &dm->key,
1069 ntohl (dm->size), 1065 ntohl(dm->size),
1070 &dm[1], 1066 &dm[1],
1071 &remove_continuation, 1067 &remove_continuation,
1072 client); 1068 client);
1073 GNUNET_SERVICE_client_continue (client); 1069 GNUNET_SERVICE_client_continue(client);
1074} 1070}
1075 1071
1076 1072
@@ -1081,13 +1077,13 @@ handle_remove (void *cls, const struct DataMessage *dm)
1081 * @param message the actual message 1077 * @param message the actual message
1082 */ 1078 */
1083static void 1079static void
1084handle_drop (void *cls, const struct GNUNET_MessageHeader *message) 1080handle_drop(void *cls, const struct GNUNET_MessageHeader *message)
1085{ 1081{
1086 struct GNUNET_SERVICE_Client *client = cls; 1082 struct GNUNET_SERVICE_Client *client = cls;
1087 1083
1088 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing DROP request\n"); 1084 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing DROP request\n");
1089 do_drop = GNUNET_YES; 1085 do_drop = GNUNET_YES;
1090 GNUNET_SERVICE_client_continue (client); 1086 GNUNET_SERVICE_client_continue(client);
1091} 1087}
1092 1088
1093 1089
@@ -1100,27 +1096,27 @@ handle_drop (void *cls, const struct GNUNET_MessageHeader *message)
1100 * 0 for "reset to empty" 1096 * 0 for "reset to empty"
1101 */ 1097 */
1102static void 1098static void
1103disk_utilization_change_cb (void *cls, int delta) 1099disk_utilization_change_cb(void *cls, int delta)
1104{ 1100{
1105 if ((delta < 0) && (payload < -delta)) 1101 if ((delta < 0) && (payload < -delta))
1106 { 1102 {
1107 GNUNET_log ( 1103 GNUNET_log(
1108 GNUNET_ERROR_TYPE_WARNING, 1104 GNUNET_ERROR_TYPE_WARNING,
1109 _ ( 1105 _(
1110 "Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"), 1106 "Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"),
1111 (long long) payload, 1107 (long long)payload,
1112 (long long) -delta); 1108 (long long)-delta);
1113 plugin->api->estimate_size (plugin->api->cls, &payload); 1109 plugin->api->estimate_size(plugin->api->cls, &payload);
1114 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1110 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1115 _ ("New payload: %lld\n"), 1111 _("New payload: %lld\n"),
1116 (long long) payload); 1112 (long long)payload);
1117 sync_stats (); 1113 sync_stats();
1118 return; 1114 return;
1119 } 1115 }
1120 payload += delta; 1116 payload += delta;
1121 last_sync++; 1117 last_sync++;
1122 if (last_sync >= MAX_STAT_SYNC_LAG) 1118 if (last_sync >= MAX_STAT_SYNC_LAG)
1123 sync_stats (); 1119 sync_stats();
1124} 1120}
1125 1121
1126 1122
@@ -1135,20 +1131,20 @@ disk_utilization_change_cb (void *cls, int delta)
1135 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 1131 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
1136 */ 1132 */
1137static int 1133static int
1138process_stat_in (void *cls, 1134process_stat_in(void *cls,
1139 const char *subsystem, 1135 const char *subsystem,
1140 const char *name, 1136 const char *name,
1141 uint64_t value, 1137 uint64_t value,
1142 int is_persistent) 1138 int is_persistent)
1143{ 1139{
1144 GNUNET_assert (GNUNET_NO == stats_worked); 1140 GNUNET_assert(GNUNET_NO == stats_worked);
1145 stats_worked = GNUNET_YES; 1141 stats_worked = GNUNET_YES;
1146 payload += value; 1142 payload += value;
1147 GNUNET_log ( 1143 GNUNET_log(
1148 GNUNET_ERROR_TYPE_DEBUG, 1144 GNUNET_ERROR_TYPE_DEBUG,
1149 "Notification from statistics about existing payload (%llu), new payload is %llu\n", 1145 "Notification from statistics about existing payload (%llu), new payload is %llu\n",
1150 (unsigned long long) value, 1146 (unsigned long long)value,
1151 (unsigned long long) payload); 1147 (unsigned long long)payload);
1152 return GNUNET_OK; 1148 return GNUNET_OK;
1153} 1149}
1154 1150
@@ -1157,32 +1153,32 @@ process_stat_in (void *cls,
1157 * Load the datastore plugin. 1153 * Load the datastore plugin.
1158 */ 1154 */
1159static struct DatastorePlugin * 1155static struct DatastorePlugin *
1160load_plugin () 1156load_plugin()
1161{ 1157{
1162 struct DatastorePlugin *ret; 1158 struct DatastorePlugin *ret;
1163 char *libname; 1159 char *libname;
1164 1160
1165 ret = GNUNET_new (struct DatastorePlugin); 1161 ret = GNUNET_new(struct DatastorePlugin);
1166 ret->env.cfg = cfg; 1162 ret->env.cfg = cfg;
1167 ret->env.duc = &disk_utilization_change_cb; 1163 ret->env.duc = &disk_utilization_change_cb;
1168 ret->env.cls = NULL; 1164 ret->env.cls = NULL;
1169 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1165 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1170 _ ("Loading `%s' datastore plugin\n"), 1166 _("Loading `%s' datastore plugin\n"),
1171 plugin_name); 1167 plugin_name);
1172 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", plugin_name); 1168 GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", plugin_name);
1173 ret->short_name = GNUNET_strdup (plugin_name); 1169 ret->short_name = GNUNET_strdup(plugin_name);
1174 ret->lib_name = libname; 1170 ret->lib_name = libname;
1175 ret->api = GNUNET_PLUGIN_load (libname, &ret->env); 1171 ret->api = GNUNET_PLUGIN_load(libname, &ret->env);
1176 if (NULL == ret->api) 1172 if (NULL == ret->api)
1177 { 1173 {
1178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1174 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1179 _ ("Failed to load datastore plugin for `%s'\n"), 1175 _("Failed to load datastore plugin for `%s'\n"),
1180 plugin_name); 1176 plugin_name);
1181 GNUNET_free (ret->short_name); 1177 GNUNET_free(ret->short_name);
1182 GNUNET_free (libname); 1178 GNUNET_free(libname);
1183 GNUNET_free (ret); 1179 GNUNET_free(ret);
1184 return NULL; 1180 return NULL;
1185 } 1181 }
1186 return ret; 1182 return ret;
1187} 1183}
1188 1184
@@ -1194,14 +1190,14 @@ load_plugin ()
1194 * @param plug plugin to unload 1190 * @param plug plugin to unload
1195 */ 1191 */
1196static void 1192static void
1197unload_plugin (struct DatastorePlugin *plug) 1193unload_plugin(struct DatastorePlugin *plug)
1198{ 1194{
1199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1195 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1200 "Datastore service is unloading plugin...\n"); 1196 "Datastore service is unloading plugin...\n");
1201 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api)); 1197 GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api));
1202 GNUNET_free (plug->lib_name); 1198 GNUNET_free(plug->lib_name);
1203 GNUNET_free (plug->short_name); 1199 GNUNET_free(plug->short_name);
1204 GNUNET_free (plug); 1200 GNUNET_free(plug);
1205} 1201}
1206 1202
1207 1203
@@ -1209,13 +1205,13 @@ unload_plugin (struct DatastorePlugin *plug)
1209 * Initialization complete, start operating the service. 1205 * Initialization complete, start operating the service.
1210 */ 1206 */
1211static void 1207static void
1212begin_service () 1208begin_service()
1213{ 1209{
1214 GNUNET_SERVICE_resume (service); 1210 GNUNET_SERVICE_resume(service);
1215 expired_kill_task = 1211 expired_kill_task =
1216 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1212 GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE,
1217 &delete_expired, 1213 &delete_expired,
1218 NULL); 1214 NULL);
1219} 1215}
1220 1216
1221 1217
@@ -1227,22 +1223,22 @@ begin_service ()
1227 * @param count number of times to add key 1223 * @param count number of times to add key
1228 */ 1224 */
1229static void 1225static void
1230add_key_to_bloomfilter (void *cls, 1226add_key_to_bloomfilter(void *cls,
1231 const struct GNUNET_HashCode *key, 1227 const struct GNUNET_HashCode *key,
1232 unsigned int count) 1228 unsigned int count)
1233{ 1229{
1234 struct GNUNET_CONTAINER_BloomFilter *bf = cls; 1230 struct GNUNET_CONTAINER_BloomFilter *bf = cls;
1235 1231
1236 if (NULL == key) 1232 if (NULL == key)
1237 { 1233 {
1238 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1234 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1239 _ ("Bloomfilter construction complete.\n")); 1235 _("Bloomfilter construction complete.\n"));
1240 begin_service (); 1236 begin_service();
1241 return; 1237 return;
1242 } 1238 }
1243 1239
1244 while (0 < count--) 1240 while (0 < count--)
1245 GNUNET_CONTAINER_bloomfilter_add (bf, key); 1241 GNUNET_CONTAINER_bloomfilter_add(bf, key);
1246} 1242}
1247 1243
1248 1244
@@ -1254,54 +1250,54 @@ add_key_to_bloomfilter (void *cls,
1254 * @param success #GNUNET_NO if we failed to read the stat 1250 * @param success #GNUNET_NO if we failed to read the stat
1255 */ 1251 */
1256static void 1252static void
1257process_stat_done (void *cls, int success) 1253process_stat_done(void *cls, int success)
1258{ 1254{
1259 stat_get = NULL; 1255 stat_get = NULL;
1260 if (NULL != stat_timeout_task) 1256 if (NULL != stat_timeout_task)
1261 { 1257 {
1262 GNUNET_SCHEDULER_cancel (stat_timeout_task); 1258 GNUNET_SCHEDULER_cancel(stat_timeout_task);
1263 stat_timeout_task = NULL; 1259 stat_timeout_task = NULL;
1264 } 1260 }
1265 plugin = load_plugin (); 1261 plugin = load_plugin();
1266 if (NULL == plugin) 1262 if (NULL == plugin)
1267 {
1268 GNUNET_CONTAINER_bloomfilter_free (filter);
1269 filter = NULL;
1270 if (NULL != stats)
1271 { 1263 {
1272 GNUNET_STATISTICS_destroy (stats, GNUNET_YES); 1264 GNUNET_CONTAINER_bloomfilter_free(filter);
1273 stats = NULL; 1265 filter = NULL;
1266 if (NULL != stats)
1267 {
1268 GNUNET_STATISTICS_destroy(stats, GNUNET_YES);
1269 stats = NULL;
1270 }
1271 return;
1274 } 1272 }
1275 return;
1276 }
1277 1273
1278 if (GNUNET_NO == stats_worked) 1274 if (GNUNET_NO == stats_worked)
1279 {
1280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1281 "Failed to obtain value from statistics service, recomputing it\n");
1282 plugin->api->estimate_size (plugin->api->cls, &payload);
1283 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1284 _ ("New payload: %lld\n"),
1285 (long long) payload);
1286 }
1287
1288 if (GNUNET_YES == refresh_bf)
1289 {
1290 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1291 _ ("Rebuilding bloomfilter. Please be patient.\n"));
1292 if (NULL != plugin->api->get_keys)
1293 { 1275 {
1294 plugin->api->get_keys (plugin->api->cls, &add_key_to_bloomfilter, filter); 1276 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1295 return; 1277 "Failed to obtain value from statistics service, recomputing it\n");
1278 plugin->api->estimate_size(plugin->api->cls, &payload);
1279 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1280 _("New payload: %lld\n"),
1281 (long long)payload);
1296 } 1282 }
1297 else 1283
1284 if (GNUNET_YES == refresh_bf)
1298 { 1285 {
1299 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1286 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1300 _ ( 1287 _("Rebuilding bloomfilter. Please be patient.\n"));
1301 "Plugin does not support get_keys function. Please fix!\n")); 1288 if (NULL != plugin->api->get_keys)
1289 {
1290 plugin->api->get_keys(plugin->api->cls, &add_key_to_bloomfilter, filter);
1291 return;
1292 }
1293 else
1294 {
1295 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1296 _(
1297 "Plugin does not support get_keys function. Please fix!\n"));
1298 }
1302 } 1299 }
1303 } 1300 begin_service();
1304 begin_service ();
1305} 1301}
1306 1302
1307 1303
@@ -1311,11 +1307,11 @@ process_stat_done (void *cls, int success)
1311 * @param cls NULL 1307 * @param cls NULL
1312 */ 1308 */
1313static void 1309static void
1314stat_timeout (void *cls) 1310stat_timeout(void *cls)
1315{ 1311{
1316 stat_timeout_task = NULL; 1312 stat_timeout_task = NULL;
1317 GNUNET_STATISTICS_get_cancel (stat_get); 1313 GNUNET_STATISTICS_get_cancel(stat_get);
1318 process_stat_done (NULL, GNUNET_NO); 1314 process_stat_done(NULL, GNUNET_NO);
1319} 1315}
1320 1316
1321 1317
@@ -1323,51 +1319,51 @@ stat_timeout (void *cls)
1323 * Task run during shutdown. 1319 * Task run during shutdown.
1324 */ 1320 */
1325static void 1321static void
1326cleaning_task (void *cls) 1322cleaning_task(void *cls)
1327{ 1323{
1328 cleaning_done = GNUNET_YES; 1324 cleaning_done = GNUNET_YES;
1329 if (NULL != expired_kill_task) 1325 if (NULL != expired_kill_task)
1330 { 1326 {
1331 GNUNET_SCHEDULER_cancel (expired_kill_task); 1327 GNUNET_SCHEDULER_cancel(expired_kill_task);
1332 expired_kill_task = NULL; 1328 expired_kill_task = NULL;
1333 } 1329 }
1334 if (GNUNET_YES == do_drop) 1330 if (GNUNET_YES == do_drop)
1335 { 1331 {
1336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dropping database!\n"); 1332 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Dropping database!\n");
1337 plugin->api->drop (plugin->api->cls); 1333 plugin->api->drop(plugin->api->cls);
1338 payload = 0; 1334 payload = 0;
1339 last_sync++; 1335 last_sync++;
1340 } 1336 }
1341 if (NULL != plugin) 1337 if (NULL != plugin)
1342 { 1338 {
1343 unload_plugin (plugin); 1339 unload_plugin(plugin);
1344 plugin = NULL; 1340 plugin = NULL;
1345 } 1341 }
1346 if (NULL != filter) 1342 if (NULL != filter)
1347 { 1343 {
1348 GNUNET_CONTAINER_bloomfilter_free (filter); 1344 GNUNET_CONTAINER_bloomfilter_free(filter);
1349 filter = NULL; 1345 filter = NULL;
1350 } 1346 }
1351 if (NULL != stat_get) 1347 if (NULL != stat_get)
1352 { 1348 {
1353 GNUNET_STATISTICS_get_cancel (stat_get); 1349 GNUNET_STATISTICS_get_cancel(stat_get);
1354 stat_get = NULL; 1350 stat_get = NULL;
1355 } 1351 }
1356 if (NULL != stat_timeout_task) 1352 if (NULL != stat_timeout_task)
1357 { 1353 {
1358 GNUNET_SCHEDULER_cancel (stat_timeout_task); 1354 GNUNET_SCHEDULER_cancel(stat_timeout_task);
1359 stat_timeout_task = NULL; 1355 stat_timeout_task = NULL;
1360 } 1356 }
1361 GNUNET_free_non_null (plugin_name); 1357 GNUNET_free_non_null(plugin_name);
1362 plugin_name = NULL; 1358 plugin_name = NULL;
1363 if (last_sync > 0) 1359 if (last_sync > 0)
1364 sync_stats (); 1360 sync_stats();
1365 if (NULL != stats) 1361 if (NULL != stats)
1366 { 1362 {
1367 GNUNET_STATISTICS_destroy (stats, GNUNET_YES); 1363 GNUNET_STATISTICS_destroy(stats, GNUNET_YES);
1368 stats = NULL; 1364 stats = NULL;
1369 } 1365 }
1370 GNUNET_free (quota_stat_name); 1366 GNUNET_free(quota_stat_name);
1371 quota_stat_name = NULL; 1367 quota_stat_name = NULL;
1372} 1368}
1373 1369
@@ -1381,9 +1377,9 @@ cleaning_task (void *cls)
1381 * @return @a client 1377 * @return @a client
1382 */ 1378 */
1383static void * 1379static void *
1384client_connect_cb (void *cls, 1380client_connect_cb(void *cls,
1385 struct GNUNET_SERVICE_Client *client, 1381 struct GNUNET_SERVICE_Client *client,
1386 struct GNUNET_MQ_Handle *mq) 1382 struct GNUNET_MQ_Handle *mq)
1387{ 1383{
1388 return client; 1384 return client;
1389} 1385}
@@ -1398,39 +1394,39 @@ client_connect_cb (void *cls,
1398 * @param app_ctx must match @a client 1394 * @param app_ctx must match @a client
1399 */ 1395 */
1400static void 1396static void
1401client_disconnect_cb (void *cls, 1397client_disconnect_cb(void *cls,
1402 struct GNUNET_SERVICE_Client *client, 1398 struct GNUNET_SERVICE_Client *client,
1403 void *app_ctx) 1399 void *app_ctx)
1404{ 1400{
1405 struct ReservationList *pos; 1401 struct ReservationList *pos;
1406 struct ReservationList *prev; 1402 struct ReservationList *prev;
1407 struct ReservationList *next; 1403 struct ReservationList *next;
1408 1404
1409 GNUNET_assert (app_ctx == client); 1405 GNUNET_assert(app_ctx == client);
1410 prev = NULL; 1406 prev = NULL;
1411 pos = reservations; 1407 pos = reservations;
1412 while (NULL != pos) 1408 while (NULL != pos)
1413 {
1414 next = pos->next;
1415 if (pos->client == client)
1416 { 1409 {
1417 if (NULL == prev) 1410 next = pos->next;
1418 reservations = next; 1411 if (pos->client == client)
1412 {
1413 if (NULL == prev)
1414 reservations = next;
1415 else
1416 prev->next = next;
1417 reserved -= pos->amount + pos->entries * GNUNET_DATASTORE_ENTRY_OVERHEAD;
1418 GNUNET_free(pos);
1419 }
1419 else 1420 else
1420 prev->next = next; 1421 {
1421 reserved -= pos->amount + pos->entries * GNUNET_DATASTORE_ENTRY_OVERHEAD; 1422 prev = pos;
1422 GNUNET_free (pos); 1423 }
1423 } 1424 pos = next;
1424 else
1425 {
1426 prev = pos;
1427 } 1425 }
1428 pos = next; 1426 GNUNET_STATISTICS_set(stats,
1429 } 1427 gettext_noop("# reserved"),
1430 GNUNET_STATISTICS_set (stats, 1428 reserved,
1431 gettext_noop ("# reserved"), 1429 GNUNET_NO);
1432 reserved,
1433 GNUNET_NO);
1434} 1430}
1435 1431
1436 1432
@@ -1442,9 +1438,9 @@ client_disconnect_cb (void *cls,
1442 * @param c configuration to use 1438 * @param c configuration to use
1443 */ 1439 */
1444static void 1440static void
1445run (void *cls, 1441run(void *cls,
1446 const struct GNUNET_CONFIGURATION_Handle *c, 1442 const struct GNUNET_CONFIGURATION_Handle *c,
1447 struct GNUNET_SERVICE_Handle *serv) 1443 struct GNUNET_SERVICE_Handle *serv)
1448{ 1444{
1449 char *fn; 1445 char *fn;
1450 char *pfn; 1446 char *pfn;
@@ -1452,199 +1448,199 @@ run (void *cls,
1452 1448
1453 service = serv; 1449 service = serv;
1454 cfg = c; 1450 cfg = c;
1455 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, 1451 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg,
1456 "DATASTORE", 1452 "DATASTORE",
1457 "DATABASE", 1453 "DATABASE",
1458 &plugin_name)) 1454 &plugin_name))
1459 { 1455 {
1460 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 1456 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
1461 "DATABASE", 1457 "DATABASE",
1462 "DATASTORE"); 1458 "DATASTORE");
1463 return; 1459 return;
1464 } 1460 }
1465 GNUNET_asprintf (&quota_stat_name, 1461 GNUNET_asprintf(&quota_stat_name,
1466 _ ("# bytes used in file-sharing datastore `%s'"), 1462 _("# bytes used in file-sharing datastore `%s'"),
1467 plugin_name); 1463 plugin_name);
1468 if (GNUNET_OK != 1464 if (GNUNET_OK !=
1469 GNUNET_CONFIGURATION_get_value_size (cfg, "DATASTORE", "QUOTA", &quota)) 1465 GNUNET_CONFIGURATION_get_value_size(cfg, "DATASTORE", "QUOTA", &quota))
1470 { 1466 {
1471 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "QUOTA", "DATASTORE"); 1467 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "QUOTA", "DATASTORE");
1472 return; 1468 return;
1473 } 1469 }
1474 stats = GNUNET_STATISTICS_create ("datastore", cfg); 1470 stats = GNUNET_STATISTICS_create("datastore", cfg);
1475 GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO); 1471 GNUNET_STATISTICS_set(stats, gettext_noop("# quota"), quota, GNUNET_NO);
1476 cache_size = quota / 8; /* Or should we make this an option? */ 1472 cache_size = quota / 8; /* Or should we make this an option? */
1477 GNUNET_STATISTICS_set (stats, 1473 GNUNET_STATISTICS_set(stats,
1478 gettext_noop ("# cache size"), 1474 gettext_noop("# cache size"),
1479 cache_size, 1475 cache_size,
1480 GNUNET_NO); 1476 GNUNET_NO);
1481 if (quota / (32 * 1024LL) > MAX_BF_SIZE) 1477 if (quota / (32 * 1024LL) > MAX_BF_SIZE)
1482 bf_size = MAX_BF_SIZE; 1478 bf_size = MAX_BF_SIZE;
1483 else 1479 else
1484 bf_size = 1480 bf_size =
1485 quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */ 1481 quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */
1486 fn = NULL; 1482 fn = NULL;
1487 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, 1483 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg,
1488 "DATASTORE", 1484 "DATASTORE",
1489 "BLOOMFILTER", 1485 "BLOOMFILTER",
1490 &fn)) || 1486 &fn)) ||
1491 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn))) 1487 (GNUNET_OK != GNUNET_DISK_directory_create_for_file(fn)))
1492 { 1488 {
1493 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1489 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1494 _ ("Could not use specified filename `%s' for bloomfilter.\n"), 1490 _("Could not use specified filename `%s' for bloomfilter.\n"),
1495 NULL != fn ? fn : ""); 1491 NULL != fn ? fn : "");
1496 GNUNET_free_non_null (fn); 1492 GNUNET_free_non_null(fn);
1497 fn = NULL; 1493 fn = NULL;
1498 } 1494 }
1499 if (NULL != fn) 1495 if (NULL != fn)
1500 {
1501 GNUNET_asprintf (&pfn, "%s.%s", fn, plugin_name);
1502 if (GNUNET_YES == GNUNET_DISK_file_test (pfn))
1503 { 1496 {
1504 filter = 1497 GNUNET_asprintf(&pfn, "%s.%s", fn, plugin_name);
1505 GNUNET_CONTAINER_bloomfilter_load (pfn, 1498 if (GNUNET_YES == GNUNET_DISK_file_test(pfn))
1506 bf_size,
1507 5); /* approx. 3% false positives at max use */
1508 if (NULL == filter)
1509 {
1510 /* file exists but not valid, remove and try again, but refresh */
1511 if (0 != unlink (pfn))
1512 { 1499 {
1513 /* failed to remove, run without file */ 1500 filter =
1514 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1501 GNUNET_CONTAINER_bloomfilter_load(pfn,
1515 _ ("Failed to remove bogus bloomfilter file `%s'\n"), 1502 bf_size,
1516 pfn); 1503 5); /* approx. 3% false positives at max use */
1517 GNUNET_free (pfn); 1504 if (NULL == filter)
1518 pfn = NULL; 1505 {
1519 filter = GNUNET_CONTAINER_bloomfilter_load ( 1506 /* file exists but not valid, remove and try again, but refresh */
1520 NULL, 1507 if (0 != unlink(pfn))
1521 bf_size, 1508 {
1522 5); /* approx. 3% false positives at max use */ 1509 /* failed to remove, run without file */
1523 refresh_bf = GNUNET_YES; 1510 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1511 _("Failed to remove bogus bloomfilter file `%s'\n"),
1512 pfn);
1513 GNUNET_free(pfn);
1514 pfn = NULL;
1515 filter = GNUNET_CONTAINER_bloomfilter_load(
1516 NULL,
1517 bf_size,
1518 5); /* approx. 3% false positives at max use */
1519 refresh_bf = GNUNET_YES;
1520 }
1521 else
1522 {
1523 /* try again after remove */
1524 filter = GNUNET_CONTAINER_bloomfilter_load(
1525 pfn,
1526 bf_size,
1527 5); /* approx. 3% false positives at max use */
1528 refresh_bf = GNUNET_YES;
1529 if (NULL == filter)
1530 {
1531 /* failed yet again, give up on using file */
1532 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1533 _("Failed to remove bogus bloomfilter file `%s'\n"),
1534 pfn);
1535 GNUNET_free(pfn);
1536 pfn = NULL;
1537 filter = GNUNET_CONTAINER_bloomfilter_init(
1538 NULL,
1539 bf_size,
1540 5); /* approx. 3% false positives at max use */
1541 }
1542 }
1543 }
1544 else
1545 {
1546 /* normal case: have an existing valid bf file, no need to refresh */
1547 refresh_bf = GNUNET_NO;
1548 }
1524 } 1549 }
1525 else 1550 else
1526 { 1551 {
1527 /* try again after remove */ 1552 filter =
1528 filter = GNUNET_CONTAINER_bloomfilter_load ( 1553 GNUNET_CONTAINER_bloomfilter_load(pfn,
1529 pfn, 1554 bf_size,
1530 bf_size, 1555 5); /* approx. 3% false positives at max use */
1531 5); /* approx. 3% false positives at max use */
1532 refresh_bf = GNUNET_YES; 1556 refresh_bf = GNUNET_YES;
1533 if (NULL == filter)
1534 {
1535 /* failed yet again, give up on using file */
1536 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1537 _ ("Failed to remove bogus bloomfilter file `%s'\n"),
1538 pfn);
1539 GNUNET_free (pfn);
1540 pfn = NULL;
1541 filter = GNUNET_CONTAINER_bloomfilter_init (
1542 NULL,
1543 bf_size,
1544 5); /* approx. 3% false positives at max use */
1545 }
1546 } 1557 }
1547 } 1558 GNUNET_free(pfn);
1548 else
1549 {
1550 /* normal case: have an existing valid bf file, no need to refresh */
1551 refresh_bf = GNUNET_NO;
1552 }
1553 } 1559 }
1554 else 1560 else
1555 { 1561 {
1556 filter = 1562 filter =
1557 GNUNET_CONTAINER_bloomfilter_load (pfn, 1563 GNUNET_CONTAINER_bloomfilter_init(NULL,
1558 bf_size, 1564 bf_size,
1559 5); /* approx. 3% false positives at max use */ 1565 5); /* approx. 3% false positives at max use */
1560 refresh_bf = GNUNET_YES; 1566 refresh_bf = GNUNET_YES;
1561 } 1567 }
1562 GNUNET_free (pfn); 1568 GNUNET_free_non_null(fn);
1563 }
1564 else
1565 {
1566 filter =
1567 GNUNET_CONTAINER_bloomfilter_init (NULL,
1568 bf_size,
1569 5); /* approx. 3% false positives at max use */
1570 refresh_bf = GNUNET_YES;
1571 }
1572 GNUNET_free_non_null (fn);
1573 if (NULL == filter) 1569 if (NULL == filter)
1574 {
1575 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1576 _ ("Failed to initialize bloomfilter.\n"));
1577 if (NULL != stats)
1578 { 1570 {
1579 GNUNET_STATISTICS_destroy (stats, GNUNET_YES); 1571 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1580 stats = NULL; 1572 _("Failed to initialize bloomfilter.\n"));
1573 if (NULL != stats)
1574 {
1575 GNUNET_STATISTICS_destroy(stats, GNUNET_YES);
1576 stats = NULL;
1577 }
1578 return;
1581 } 1579 }
1582 return; 1580 GNUNET_SERVICE_suspend(service);
1583 } 1581 stat_get = GNUNET_STATISTICS_get(stats,
1584 GNUNET_SERVICE_suspend (service); 1582 "datastore",
1585 stat_get = GNUNET_STATISTICS_get (stats, 1583 quota_stat_name,
1586 "datastore", 1584 &process_stat_done,
1587 quota_stat_name, 1585 &process_stat_in,
1588 &process_stat_done, 1586 NULL);
1589 &process_stat_in,
1590 NULL);
1591 if (NULL == stat_get) 1587 if (NULL == stat_get)
1592 process_stat_done (NULL, GNUNET_SYSERR); 1588 process_stat_done(NULL, GNUNET_SYSERR);
1593 else 1589 else
1594 stat_timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 1590 stat_timeout_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
1595 &stat_timeout, 1591 &stat_timeout,
1596 NULL); 1592 NULL);
1597 GNUNET_SCHEDULER_add_shutdown (&cleaning_task, NULL); 1593 GNUNET_SCHEDULER_add_shutdown(&cleaning_task, NULL);
1598} 1594}
1599 1595
1600 1596
1601/** 1597/**
1602 * Define "main" method using service macro. 1598 * Define "main" method using service macro.
1603 */ 1599 */
1604GNUNET_SERVICE_MAIN ( 1600GNUNET_SERVICE_MAIN(
1605 "datastore", 1601 "datastore",
1606 GNUNET_SERVICE_OPTION_NONE, 1602 GNUNET_SERVICE_OPTION_NONE,
1607 &run, 1603 &run,
1608 &client_connect_cb, 1604 &client_connect_cb,
1609 &client_disconnect_cb, 1605 &client_disconnect_cb,
1610 NULL, 1606 NULL,
1611 GNUNET_MQ_hd_fixed_size (reserve, 1607 GNUNET_MQ_hd_fixed_size(reserve,
1612 GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE, 1608 GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE,
1613 struct ReserveMessage, 1609 struct ReserveMessage,
1614 NULL), 1610 NULL),
1615 GNUNET_MQ_hd_fixed_size (release_reserve, 1611 GNUNET_MQ_hd_fixed_size(release_reserve,
1616 GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE, 1612 GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE,
1617 struct ReleaseReserveMessage, 1613 struct ReleaseReserveMessage,
1618 NULL), 1614 NULL),
1619 GNUNET_MQ_hd_var_size (put, 1615 GNUNET_MQ_hd_var_size(put,
1620 GNUNET_MESSAGE_TYPE_DATASTORE_PUT, 1616 GNUNET_MESSAGE_TYPE_DATASTORE_PUT,
1621 struct DataMessage, 1617 struct DataMessage,
1622 NULL), 1618 NULL),
1623 GNUNET_MQ_hd_fixed_size (get, 1619 GNUNET_MQ_hd_fixed_size(get,
1624 GNUNET_MESSAGE_TYPE_DATASTORE_GET, 1620 GNUNET_MESSAGE_TYPE_DATASTORE_GET,
1625 struct GetMessage, 1621 struct GetMessage,
1626 NULL), 1622 NULL),
1627 GNUNET_MQ_hd_fixed_size (get_key, 1623 GNUNET_MQ_hd_fixed_size(get_key,
1628 GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY, 1624 GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY,
1629 struct GetKeyMessage, 1625 struct GetKeyMessage,
1630 NULL), 1626 NULL),
1631 GNUNET_MQ_hd_fixed_size (get_replication, 1627 GNUNET_MQ_hd_fixed_size(get_replication,
1632 GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION, 1628 GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION,
1633 struct GNUNET_MessageHeader, 1629 struct GNUNET_MessageHeader,
1634 NULL), 1630 NULL),
1635 GNUNET_MQ_hd_fixed_size (get_zero_anonymity, 1631 GNUNET_MQ_hd_fixed_size(get_zero_anonymity,
1636 GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY, 1632 GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY,
1637 struct GetZeroAnonymityMessage, 1633 struct GetZeroAnonymityMessage,
1638 NULL), 1634 NULL),
1639 GNUNET_MQ_hd_var_size (remove, 1635 GNUNET_MQ_hd_var_size(remove,
1640 GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, 1636 GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE,
1641 struct DataMessage, 1637 struct DataMessage,
1642 NULL), 1638 NULL),
1643 GNUNET_MQ_hd_fixed_size (drop, 1639 GNUNET_MQ_hd_fixed_size(drop,
1644 GNUNET_MESSAGE_TYPE_DATASTORE_DROP, 1640 GNUNET_MESSAGE_TYPE_DATASTORE_DROP,
1645 struct GNUNET_MessageHeader, 1641 struct GNUNET_MessageHeader,
1646 NULL), 1642 NULL),
1647 GNUNET_MQ_handler_end ()); 1643 GNUNET_MQ_handler_end());
1648 1644
1649 1645
1650/* end of gnunet-service-datastore.c */ 1646/* end of gnunet-service-datastore.c */