diff options
Diffstat (limited to 'src/rps/gnunet-service-rps_sampler.c')
-rw-r--r-- | src/rps/gnunet-service-rps_sampler.c | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index ff4bc9e42..2cd4cb996 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c | |||
@@ -313,26 +313,9 @@ sampler_notify_on_update (struct RPS_Sampler *sampler, | |||
313 | notify_ctx = GNUNET_new (struct SamplerNotifyUpdateCTX); | 313 | notify_ctx = GNUNET_new (struct SamplerNotifyUpdateCTX); |
314 | notify_ctx->notify_cb = notify_cb; | 314 | notify_ctx->notify_cb = notify_cb; |
315 | notify_ctx->cls = cls; | 315 | notify_ctx->cls = cls; |
316 | if (NULL != sampler->notify_ctx_head) | ||
317 | { | ||
318 | for (struct SamplerNotifyUpdateCTX *notify_iter = sampler->notify_ctx_head; | ||
319 | NULL != notify_iter->next; | ||
320 | notify_iter = notify_iter->next) | ||
321 | { | ||
322 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
323 | "Pre: Context\n"); | ||
324 | } | ||
325 | } | ||
326 | GNUNET_CONTAINER_DLL_insert (sampler->notify_ctx_head, | 316 | GNUNET_CONTAINER_DLL_insert (sampler->notify_ctx_head, |
327 | sampler->notify_ctx_tail, | 317 | sampler->notify_ctx_tail, |
328 | notify_ctx); | 318 | notify_ctx); |
329 | for (struct SamplerNotifyUpdateCTX *notify_iter = sampler->notify_ctx_head; | ||
330 | NULL != notify_iter; | ||
331 | notify_iter = notify_iter->next) | ||
332 | { | ||
333 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
334 | "Post: Context\n"); | ||
335 | } | ||
336 | return notify_ctx; | 319 | return notify_ctx; |
337 | } | 320 | } |
338 | 321 | ||
@@ -559,27 +542,21 @@ RPS_sampler_mod_init (size_t init_size, | |||
559 | 542 | ||
560 | 543 | ||
561 | /** | 544 | /** |
562 | * Update every sampler element of this sampler with given peer | 545 | * @brief Notify about update of the sampler. |
563 | * | 546 | * |
564 | * @param sampler the sampler to update. | 547 | * Call the callbacks that are waiting for notification on updates to the |
565 | * @param id the PeerID that is put in the sampler | 548 | * sampler. |
549 | * | ||
550 | * @param sampler The sampler the updates are waiting for | ||
566 | */ | 551 | */ |
567 | void | 552 | static void |
568 | RPS_sampler_update (struct RPS_Sampler *sampler, | 553 | notify_update (struct RPS_Sampler *sampler) |
569 | const struct GNUNET_PeerIdentity *id) | ||
570 | { | 554 | { |
571 | struct SamplerNotifyUpdateCTX *tmp_notify_head; | 555 | struct SamplerNotifyUpdateCTX *tmp_notify_head; |
572 | struct SamplerNotifyUpdateCTX *tmp_notify_tail; | 556 | struct SamplerNotifyUpdateCTX *tmp_notify_tail; |
573 | 557 | ||
574 | to_file (sampler->file_name, | 558 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
575 | "Got %s", | 559 | "Calling callbacks waiting for update notification.\n"); |
576 | GNUNET_i2s_full (id)); | ||
577 | |||
578 | for (uint32_t i = 0; i < sampler->sampler_size; i++) | ||
579 | { | ||
580 | RPS_sampler_elem_next (sampler->sampler_elements[i], | ||
581 | id); | ||
582 | } | ||
583 | tmp_notify_head = sampler->notify_ctx_head; | 560 | tmp_notify_head = sampler->notify_ctx_head; |
584 | tmp_notify_tail = sampler->notify_ctx_tail; | 561 | tmp_notify_tail = sampler->notify_ctx_tail; |
585 | sampler->notify_ctx_head = NULL; | 562 | sampler->notify_ctx_head = NULL; |
@@ -599,6 +576,29 @@ RPS_sampler_update (struct RPS_Sampler *sampler, | |||
599 | 576 | ||
600 | 577 | ||
601 | /** | 578 | /** |
579 | * Update every sampler element of this sampler with given peer | ||
580 | * | ||
581 | * @param sampler the sampler to update. | ||
582 | * @param id the PeerID that is put in the sampler | ||
583 | */ | ||
584 | void | ||
585 | RPS_sampler_update (struct RPS_Sampler *sampler, | ||
586 | const struct GNUNET_PeerIdentity *id) | ||
587 | { | ||
588 | to_file (sampler->file_name, | ||
589 | "Got %s", | ||
590 | GNUNET_i2s_full (id)); | ||
591 | |||
592 | for (uint32_t i = 0; i < sampler->sampler_size; i++) | ||
593 | { | ||
594 | RPS_sampler_elem_next (sampler->sampler_elements[i], | ||
595 | id); | ||
596 | } | ||
597 | notify_update (sampler); | ||
598 | } | ||
599 | |||
600 | |||
601 | /** | ||
602 | * Reinitialise all previously initialised sampler elements with the given value. | 602 | * Reinitialise all previously initialised sampler elements with the given value. |
603 | * | 603 | * |
604 | * Used to get rid of a PeerID. | 604 | * Used to get rid of a PeerID. |
@@ -714,6 +714,7 @@ sampler_mod_get_rand_peer (void *cls) | |||
714 | /* Check whether we may use this sampler to give it back to the client */ | 714 | /* Check whether we may use this sampler to give it back to the client */ |
715 | if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != s_elem->last_client_request.abs_value_us) | 715 | if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != s_elem->last_client_request.abs_value_us) |
716 | { | 716 | { |
717 | // TODO remove this condition at least for the client sampler | ||
717 | last_request_diff = | 718 | last_request_diff = |
718 | GNUNET_TIME_absolute_get_difference (s_elem->last_client_request, | 719 | GNUNET_TIME_absolute_get_difference (s_elem->last_client_request, |
719 | GNUNET_TIME_absolute_get ()); | 720 | GNUNET_TIME_absolute_get ()); |