summaryrefslogtreecommitdiff
path: root/src/rps/gnunet-service-rps_sampler.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-09-26 00:22:41 +0200
committerJulius Bünger <buenger@mytum.de>2018-09-26 00:23:45 +0200
commita38275062455b7991c6a8536db38a55135cefff2 (patch)
treec2421f7c323f2047ca42d225a9bb5dc6644d7bb5 /src/rps/gnunet-service-rps_sampler.c
parentafbafd99c2b66bd3e35df763623883192cdad67d (diff)
Change architecture of RPS service - api
Diffstat (limited to 'src/rps/gnunet-service-rps_sampler.c')
-rw-r--r--src/rps/gnunet-service-rps_sampler.c65
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,
notify_ctx = GNUNET_new (struct SamplerNotifyUpdateCTX);
notify_ctx->notify_cb = notify_cb;
notify_ctx->cls = cls;
- if (NULL != sampler->notify_ctx_head)
- {
- for (struct SamplerNotifyUpdateCTX *notify_iter = sampler->notify_ctx_head;
- NULL != notify_iter->next;
- notify_iter = notify_iter->next)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Pre: Context\n");
- }
- }
GNUNET_CONTAINER_DLL_insert (sampler->notify_ctx_head,
sampler->notify_ctx_tail,
notify_ctx);
- for (struct SamplerNotifyUpdateCTX *notify_iter = sampler->notify_ctx_head;
- NULL != notify_iter;
- notify_iter = notify_iter->next)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Post: Context\n");
- }
return notify_ctx;
}
@@ -559,27 +542,21 @@ RPS_sampler_mod_init (size_t init_size,
/**
- * Update every sampler element of this sampler with given peer
+ * @brief Notify about update of the sampler.
*
- * @param sampler the sampler to update.
- * @param id the PeerID that is put in the sampler
+ * Call the callbacks that are waiting for notification on updates to the
+ * sampler.
+ *
+ * @param sampler The sampler the updates are waiting for
*/
- void
-RPS_sampler_update (struct RPS_Sampler *sampler,
- const struct GNUNET_PeerIdentity *id)
+static void
+notify_update (struct RPS_Sampler *sampler)
{
struct SamplerNotifyUpdateCTX *tmp_notify_head;
struct SamplerNotifyUpdateCTX *tmp_notify_tail;
- to_file (sampler->file_name,
- "Got %s",
- GNUNET_i2s_full (id));
-
- for (uint32_t i = 0; i < sampler->sampler_size; i++)
- {
- RPS_sampler_elem_next (sampler->sampler_elements[i],
- id);
- }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Calling callbacks waiting for update notification.\n");
tmp_notify_head = sampler->notify_ctx_head;
tmp_notify_tail = sampler->notify_ctx_tail;
sampler->notify_ctx_head = NULL;
@@ -599,6 +576,29 @@ RPS_sampler_update (struct RPS_Sampler *sampler,
/**
+ * Update every sampler element of this sampler with given peer
+ *
+ * @param sampler the sampler to update.
+ * @param id the PeerID that is put in the sampler
+ */
+ void
+RPS_sampler_update (struct RPS_Sampler *sampler,
+ const struct GNUNET_PeerIdentity *id)
+{
+ to_file (sampler->file_name,
+ "Got %s",
+ GNUNET_i2s_full (id));
+
+ for (uint32_t i = 0; i < sampler->sampler_size; i++)
+ {
+ RPS_sampler_elem_next (sampler->sampler_elements[i],
+ id);
+ }
+ notify_update (sampler);
+}
+
+
+/**
* Reinitialise all previously initialised sampler elements with the given value.
*
* Used to get rid of a PeerID.
@@ -714,6 +714,7 @@ sampler_mod_get_rand_peer (void *cls)
/* Check whether we may use this sampler to give it back to the client */
if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != s_elem->last_client_request.abs_value_us)
{
+ // TODO remove this condition at least for the client sampler
last_request_diff =
GNUNET_TIME_absolute_get_difference (s_elem->last_client_request,
GNUNET_TIME_absolute_get ());