aboutsummaryrefslogtreecommitdiff
path: root/src/rps/gnunet-service-rps_sampler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps/gnunet-service-rps_sampler.c')
-rw-r--r--src/rps/gnunet-service-rps_sampler.c58
1 files changed, 13 insertions, 45 deletions
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c
index b51867d28..2ff718d5e 100644
--- a/src/rps/gnunet-service-rps_sampler.c
+++ b/src/rps/gnunet-service-rps_sampler.c
@@ -804,11 +804,8 @@ sampler_mod_get_rand_peer (void *cls,
804 const struct GNUNET_SCHEDULER_TaskContext *tc) 804 const struct GNUNET_SCHEDULER_TaskContext *tc)
805{ 805{
806 struct GetPeerCls *gpc = cls; 806 struct GetPeerCls *gpc = cls;
807 struct GNUNET_PeerIdentity tmp_id;
808 unsigned int empty_flag;
809 struct RPS_SamplerElement *s_elem; 807 struct RPS_SamplerElement *s_elem;
810 struct GNUNET_TIME_Relative last_request_diff; 808 struct GNUNET_TIME_Relative last_request_diff;
811 uint32_t tmp_client_get_index;
812 809
813 gpc->get_peer_task = NULL; 810 gpc->get_peer_task = NULL;
814 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 811 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -816,52 +813,23 @@ sampler_mod_get_rand_peer (void *cls,
816 813
817 LOG (GNUNET_ERROR_TYPE_DEBUG, "Single peer was requested\n"); 814 LOG (GNUNET_ERROR_TYPE_DEBUG, "Single peer was requested\n");
818 815
819 816 /* Cycle the #client_get_index one step further */
820 /* Store the next #client_get_index to check whether we cycled over the whole list */ 817 client_get_index = (client_get_index + 1) % gpc->sampler->sampler_size;
821 if (0 < client_get_index)
822 tmp_client_get_index = client_get_index - 1;
823 else
824 tmp_client_get_index = gpc->sampler->sampler_size - 1;
825
826 LOG (GNUNET_ERROR_TYPE_DEBUG,
827 "sched for later if index reaches %" PRIX32 " (sampler size: %" PRIX32 ").\n",
828 tmp_client_get_index, gpc->sampler->sampler_size);
829
830 do
831 { /* Get first non empty sampler */
832 if (tmp_client_get_index == client_get_index)
833 { /* We once cycled over the whole list */
834 LOG (GNUNET_ERROR_TYPE_DEBUG, "reached tmp_index %" PRIX32 ".\n",
835 client_get_index);
836 GNUNET_assert (NULL == gpc->get_peer_task);
837 gpc->get_peer_task =
838 GNUNET_SCHEDULER_add_delayed (gpc->sampler->max_round_interval,
839 &sampler_mod_get_rand_peer,
840 cls);
841 return;
842 }
843
844 tmp_id = gpc->sampler->sampler_elements[client_get_index]->peer_id;
845 empty_flag = gpc->sampler->sampler_elements[client_get_index]->is_empty;
846 RPS_sampler_elem_reinit (gpc->sampler->sampler_elements[client_get_index]);
847 if (EMPTY != empty_flag)
848 RPS_sampler_elem_next (gpc->sampler->sampler_elements[client_get_index],
849 gpc->sampler,
850 &tmp_id);
851
852 /* Cycle the #client_get_index one step further */
853 if ( client_get_index == gpc->sampler->sampler_size - 1 )
854 client_get_index = 0;
855 else
856 client_get_index++;
857
858 /* LOG (GNUNET_ERROR_TYPE_DEBUG, "incremented index to %" PRIX32 ".\n",
859 client_get_index); */
860 } while (EMPTY == gpc->sampler->sampler_elements[client_get_index]->is_empty);
861 818
862 s_elem = gpc->sampler->sampler_elements[client_get_index]; 819 s_elem = gpc->sampler->sampler_elements[client_get_index];
863 *gpc->id = s_elem->peer_id; 820 *gpc->id = s_elem->peer_id;
864 821
822 if (NULL == s_elem)
823 {
824 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sampler_mod element empty, rescheduling.\n");
825 GNUNET_assert (NULL == gpc->get_peer_task);
826 gpc->get_peer_task =
827 GNUNET_SCHEDULER_add_delayed (gpc->sampler->max_round_interval,
828 &sampler_mod_get_rand_peer,
829 cls);
830 return;
831 }
832
865 /* Check whether we may use this sampler to give it back to the client */ 833 /* Check whether we may use this sampler to give it back to the client */
866 if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != s_elem->last_client_request.abs_value_us) 834 if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != s_elem->last_client_request.abs_value_us)
867 { 835 {