diff options
-rw-r--r-- | src/rps/gnunet-service-rps_sampler.c | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index f382786a4..1783e0dce 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c | |||
@@ -209,11 +209,30 @@ struct RPS_Sampler | |||
209 | //size_t size; | 209 | //size_t size; |
210 | 210 | ||
211 | /** | 211 | /** |
212 | * All Samplers in one array. | 212 | * All sampler elements in one array. |
213 | */ | 213 | */ |
214 | struct RPS_SamplerElement **sampler_elements; | 214 | struct RPS_SamplerElement **sampler_elements; |
215 | 215 | ||
216 | /** | 216 | /** |
217 | * Number of sampler elements trash can holds. | ||
218 | */ | ||
219 | unsigned int trash_can_size; | ||
220 | |||
221 | /** | ||
222 | * Trash can for old sampler elements. | ||
223 | * We need this to evaluate the sampler. | ||
224 | * TODO remove after evaluation | ||
225 | * and undo changes in | ||
226 | * sampler_resize | ||
227 | * sampler_empty | ||
228 | * sampler_init | ||
229 | * sampler_remove? | ||
230 | * sampler_reinitialise_by_value | ||
231 | * sampler_update | ||
232 | */ | ||
233 | struct RPS_SamplerElement **trash_can; | ||
234 | |||
235 | /** | ||
217 | * Maximum time a round takes | 236 | * Maximum time a round takes |
218 | * | 237 | * |
219 | * Used in the context of RPS | 238 | * Used in the context of RPS |
@@ -394,7 +413,7 @@ RPS_sampler_elem_create (void) | |||
394 | */ | 413 | */ |
395 | static void | 414 | static void |
396 | RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, | 415 | RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, |
397 | struct RPS_Sampler *sampler, | 416 | struct RPS_Sampler *sampler, /* TODO remove? */ |
398 | const struct GNUNET_PeerIdentity *other) | 417 | const struct GNUNET_PeerIdentity *other) |
399 | { | 418 | { |
400 | struct GNUNET_HashCode other_hash; | 419 | struct GNUNET_HashCode other_hash; |
@@ -487,7 +506,6 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) | |||
487 | 506 | ||
488 | if (old_size > new_size) | 507 | if (old_size > new_size) |
489 | { /* Shrinking */ | 508 | { /* Shrinking */ |
490 | /* Temporary store those to properly call the removeCB on those later */ | ||
491 | 509 | ||
492 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 510 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
493 | "Shrinking sampler %d -> %d\n", | 511 | "Shrinking sampler %d -> %d\n", |
@@ -499,20 +517,27 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) | |||
499 | old_size, | 517 | old_size, |
500 | new_size); | 518 | new_size); |
501 | 519 | ||
520 | /* TODO Temporary store those to properly call the removeCB on those later? */ | ||
521 | GNUNET_array_grow (sampler->trash_can, | ||
522 | sampler->trash_can_size, | ||
523 | old_size - new_size); | ||
502 | for (i = new_size ; i < old_size ; i++) | 524 | for (i = new_size ; i < old_size ; i++) |
503 | { | 525 | { |
504 | to_file (sampler->file_name, | 526 | to_file (sampler->file_name, |
505 | "-%" PRIu32 ": %s", | 527 | "-%" PRIu32 ": %s", |
506 | i, | 528 | i, |
507 | sampler->sampler_elements[i]->file_name); | 529 | sampler->sampler_elements[i]->file_name); |
530 | to_file (sampler->sampler_elements[i]->file_name, | ||
531 | "--- non-active"); | ||
532 | sampler->trash_can[i - new_size] = sampler->sampler_elements[i]; | ||
508 | } | 533 | } |
509 | 534 | ||
510 | GNUNET_array_grow (sampler->sampler_elements, | 535 | GNUNET_array_grow (sampler->sampler_elements, |
511 | sampler->sampler_size, | 536 | sampler->sampler_size, |
512 | new_size); | 537 | new_size); |
513 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 538 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
514 | "sampler->sampler_elements now points to %p\n", | 539 | "sampler->sampler_elements now points to %p\n", |
515 | sampler->sampler_elements); | 540 | sampler->sampler_elements); |
516 | 541 | ||
517 | } | 542 | } |
518 | else if (old_size < new_size) | 543 | else if (old_size < new_size) |
@@ -575,6 +600,9 @@ static void | |||
575 | sampler_empty (struct RPS_Sampler *sampler) | 600 | sampler_empty (struct RPS_Sampler *sampler) |
576 | { | 601 | { |
577 | sampler_resize (sampler, 0); | 602 | sampler_resize (sampler, 0); |
603 | GNUNET_array_grow (sampler->trash_can, | ||
604 | sampler->trash_can_size, | ||
605 | 0); | ||
578 | } | 606 | } |
579 | 607 | ||
580 | 608 | ||
@@ -607,6 +635,8 @@ RPS_sampler_init (size_t init_size, | |||
607 | 635 | ||
608 | sampler->sampler_size = 0; | 636 | sampler->sampler_size = 0; |
609 | sampler->sampler_elements = NULL; | 637 | sampler->sampler_elements = NULL; |
638 | sampler->trash_can_size = 0; | ||
639 | sampler->trash_can = NULL; | ||
610 | sampler->max_round_interval = max_round_interval; | 640 | sampler->max_round_interval = max_round_interval; |
611 | sampler->get_peers = sampler_get_rand_peer; | 641 | sampler->get_peers = sampler_get_rand_peer; |
612 | sampler->gpc_head = NULL; | 642 | sampler->gpc_head = NULL; |
@@ -669,6 +699,13 @@ RPS_sampler_update (struct RPS_Sampler *sampler, | |||
669 | sampler, | 699 | sampler, |
670 | id); | 700 | id); |
671 | } | 701 | } |
702 | |||
703 | for (i = 0 ; i < sampler->trash_can_size ; i++) | ||
704 | { | ||
705 | RPS_sampler_elem_next (sampler->trash_can[i], | ||
706 | sampler, | ||
707 | id); | ||
708 | } | ||
672 | } | 709 | } |
673 | 710 | ||
674 | 711 | ||
@@ -685,12 +722,20 @@ RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, | |||
685 | const struct GNUNET_PeerIdentity *id) | 722 | const struct GNUNET_PeerIdentity *id) |
686 | { | 723 | { |
687 | uint32_t i; | 724 | uint32_t i; |
725 | struct RPS_SamplerElement *trash_entry; | ||
688 | 726 | ||
689 | for ( i = 0 ; i < sampler->sampler_size ; i++ ) | 727 | for ( i = 0 ; i < sampler->sampler_size ; i++ ) |
690 | { | 728 | { |
691 | if ( 0 == GNUNET_CRYPTO_cmp_peer_identity(id, &(sampler->sampler_elements[i]->peer_id)) ) | 729 | if ( 0 == GNUNET_CRYPTO_cmp_peer_identity(id, &(sampler->sampler_elements[i]->peer_id)) ) |
692 | { | 730 | { |
693 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Reinitialising sampler\n"); | 731 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Reinitialising sampler\n"); |
732 | trash_entry = GNUNET_new (struct RPS_SamplerElement); | ||
733 | *trash_entry = *(sampler->sampler_elements[i]); | ||
734 | GNUNET_array_append (sampler->trash_can, | ||
735 | sampler->trash_can_size, | ||
736 | trash_entry); | ||
737 | to_file (trash_entry->file_name, | ||
738 | "--- non-active"); | ||
694 | RPS_sampler_elem_reinit (sampler->sampler_elements[i]); | 739 | RPS_sampler_elem_reinit (sampler->sampler_elements[i]); |
695 | } | 740 | } |
696 | } | 741 | } |