diff options
Diffstat (limited to 'src/datastore/plugin_datastore_heap.c')
-rw-r--r-- | src/datastore/plugin_datastore_heap.c | 99 |
1 files changed, 53 insertions, 46 deletions
diff --git a/src/datastore/plugin_datastore_heap.c b/src/datastore/plugin_datastore_heap.c index e15cacb5b..d04c1cf60 100644 --- a/src/datastore/plugin_datastore_heap.c +++ b/src/datastore/plugin_datastore_heap.c | |||
@@ -439,7 +439,7 @@ heap_plugin_get_key (void *cls, uint64_t next_uid, bool random, | |||
439 | } | 439 | } |
440 | if (NULL == gc.value) | 440 | if (NULL == gc.value) |
441 | { | 441 | { |
442 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 442 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
443 | return; | 443 | return; |
444 | } | 444 | } |
445 | if (GNUNET_NO == | 445 | if (GNUNET_NO == |
@@ -450,6 +450,7 @@ heap_plugin_get_key (void *cls, uint64_t next_uid, bool random, | |||
450 | gc.value->type, | 450 | gc.value->type, |
451 | gc.value->priority, | 451 | gc.value->priority, |
452 | gc.value->anonymity, | 452 | gc.value->anonymity, |
453 | gc.value->replication, | ||
453 | gc.value->expiration, | 454 | gc.value->expiration, |
454 | (uint64_t) (intptr_t) gc.value)) | 455 | (uint64_t) (intptr_t) gc.value)) |
455 | { | 456 | { |
@@ -480,8 +481,7 @@ heap_plugin_get_replication (void *cls, | |||
480 | value = GNUNET_CONTAINER_heap_remove_root (plugin->by_replication); | 481 | value = GNUNET_CONTAINER_heap_remove_root (plugin->by_replication); |
481 | if (NULL == value) | 482 | if (NULL == value) |
482 | { | 483 | { |
483 | proc (proc_cls, | 484 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
484 | NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | ||
485 | return; | 485 | return; |
486 | } | 486 | } |
487 | if (value->replication > 0) | 487 | if (value->replication > 0) |
@@ -501,14 +501,15 @@ heap_plugin_get_replication (void *cls, | |||
501 | } | 501 | } |
502 | if (GNUNET_NO == | 502 | if (GNUNET_NO == |
503 | proc (proc_cls, | 503 | proc (proc_cls, |
504 | &value->key, | 504 | &value->key, |
505 | value->size, | 505 | value->size, |
506 | &value[1], | 506 | &value[1], |
507 | value->type, | 507 | value->type, |
508 | value->priority, | 508 | value->priority, |
509 | value->anonymity, | 509 | value->anonymity, |
510 | value->expiration, | 510 | value->replication, |
511 | (uint64_t) (intptr_t) value)) | 511 | value->expiration, |
512 | (uint64_t) (intptr_t) value)) | ||
512 | delete_value (plugin, value); | 513 | delete_value (plugin, value); |
513 | } | 514 | } |
514 | 515 | ||
@@ -531,35 +532,36 @@ heap_plugin_get_expiration (void *cls, PluginDatumProcessor proc, | |||
531 | value = GNUNET_CONTAINER_heap_peek (plugin->by_expiration); | 532 | value = GNUNET_CONTAINER_heap_peek (plugin->by_expiration); |
532 | if (NULL == value) | 533 | if (NULL == value) |
533 | { | 534 | { |
534 | proc (proc_cls, | 535 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
535 | NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | ||
536 | return; | 536 | return; |
537 | } | 537 | } |
538 | if (GNUNET_NO == | 538 | if (GNUNET_NO == |
539 | proc (proc_cls, | 539 | proc (proc_cls, |
540 | &value->key, | 540 | &value->key, |
541 | value->size, | 541 | value->size, |
542 | &value[1], | 542 | &value[1], |
543 | value->type, | 543 | value->type, |
544 | value->priority, | 544 | value->priority, |
545 | value->anonymity, | 545 | value->anonymity, |
546 | value->expiration, | 546 | value->replication, |
547 | (uint64_t) (intptr_t) value)) | 547 | value->expiration, |
548 | (uint64_t) (intptr_t) value)) | ||
548 | delete_value (plugin, value); | 549 | delete_value (plugin, value); |
549 | } | 550 | } |
550 | 551 | ||
551 | 552 | ||
552 | /** | 553 | /** |
553 | * Update the priority for a particular key in the datastore. If | 554 | * Update the priority, replication and expiration for a particular |
554 | * the expiration time in value is different than the time found in | 555 | * unique ID in the datastore. If the expiration time in value is |
555 | * the datastore, the higher value should be kept. For the | 556 | * different than the time found in the datastore, the higher value |
556 | * anonymity level, the lower value is to be used. The specified | 557 | * should be kept. The specified priority and replication is added |
557 | * priority should be added to the existing priority, ignoring the | 558 | * to the existing value. |
558 | * priority in value. | ||
559 | * | 559 | * |
560 | * @param cls our `struct Plugin *` | 560 | * @param cls our `struct Plugin *` |
561 | * @param uid unique identifier of the datum | 561 | * @param uid unique identifier of the datum |
562 | * @param delta by how much should the priority | 562 | * @param priority by how much should the priority |
563 | * change? | ||
564 | * @param replication by how much should the replication | ||
563 | * change? | 565 | * change? |
564 | * @param expire new expiration time should be the | 566 | * @param expire new expiration time should be the |
565 | * MAX of any existing expiration time and | 567 | * MAX of any existing expiration time and |
@@ -569,11 +571,12 @@ heap_plugin_get_expiration (void *cls, PluginDatumProcessor proc, | |||
569 | */ | 571 | */ |
570 | static void | 572 | static void |
571 | heap_plugin_update (void *cls, | 573 | heap_plugin_update (void *cls, |
572 | uint64_t uid, | 574 | uint64_t uid, |
573 | uint32_t delta, | 575 | uint32_t priority, |
574 | struct GNUNET_TIME_Absolute expire, | 576 | uint32_t replication, |
575 | PluginUpdateCont cont, | 577 | struct GNUNET_TIME_Absolute expire, |
576 | void *cont_cls) | 578 | PluginUpdateCont cont, |
579 | void *cont_cls) | ||
577 | { | 580 | { |
578 | struct Value *value; | 581 | struct Value *value; |
579 | 582 | ||
@@ -585,11 +588,15 @@ heap_plugin_update (void *cls, | |||
585 | GNUNET_CONTAINER_heap_update_cost (value->expire_heap, | 588 | GNUNET_CONTAINER_heap_update_cost (value->expire_heap, |
586 | expire.abs_value_us); | 589 | expire.abs_value_us); |
587 | } | 590 | } |
588 | /* Saturating add, don't overflow */ | 591 | /* Saturating adds, don't overflow */ |
589 | if (value->priority > UINT32_MAX - delta) | 592 | if (value->priority > UINT32_MAX - priority) |
590 | value->priority = UINT32_MAX; | 593 | value->priority = UINT32_MAX; |
591 | else | 594 | else |
592 | value->priority += delta; | 595 | value->priority += priority; |
596 | if (value->replication > UINT32_MAX - replication) | ||
597 | value->replication = UINT32_MAX; | ||
598 | else | ||
599 | value->replication += replication; | ||
593 | cont (cont_cls, GNUNET_OK, NULL); | 600 | cont (cont_cls, GNUNET_OK, NULL); |
594 | } | 601 | } |
595 | 602 | ||
@@ -631,20 +638,20 @@ heap_plugin_get_zero_anonymity (void *cls, uint64_t next_uid, | |||
631 | } | 638 | } |
632 | if (NULL == value) | 639 | if (NULL == value) |
633 | { | 640 | { |
634 | proc (proc_cls, | 641 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
635 | NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | ||
636 | return; | 642 | return; |
637 | } | 643 | } |
638 | if (GNUNET_NO == | 644 | if (GNUNET_NO == |
639 | proc (proc_cls, | 645 | proc (proc_cls, |
640 | &value->key, | 646 | &value->key, |
641 | value->size, | 647 | value->size, |
642 | &value[1], | 648 | &value[1], |
643 | value->type, | 649 | value->type, |
644 | value->priority, | 650 | value->priority, |
645 | value->anonymity, | 651 | value->anonymity, |
646 | value->expiration, | 652 | value->replication, |
647 | (uint64_t) (intptr_t) value)) | 653 | value->expiration, |
654 | (uint64_t) (intptr_t) value)) | ||
648 | delete_value (plugin, value); | 655 | delete_value (plugin, value); |
649 | } | 656 | } |
650 | 657 | ||