Code common to client and service sampler. More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_statistics_service.h"
#include "rps-sampler_common.h"
#include "gnunet-service-rps_sampler_elem.h"
#include <math.h>
#include <inttypes.h>
#include "rps-test_util.h"
Go to the source code of this file.
Data Structures | |
struct | SamplerNotifyUpdateCTX |
Context for a callback. More... | |
struct | RPS_SamplerRequestHandle |
Closure to _get_n_rand_peers_ready_cb() More... | |
struct | RPS_SamplerRequestHandleSingleInfo |
Closure to _get_rand_peer_info() More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "rps-sampler_common", __VA_ARGS__) |
Functions | |
void | RPS_sampler_update_with_nw_size (struct RPS_Sampler *sampler, uint32_t num_peers) |
Update the current estimate of the network size stored at the sampler. More... | |
void | RPS_sampler_set_desired_probability (struct RPS_Sampler *sampler, double desired_probability) |
Set the probability that is needed at least with what a sampler element has to have observed all elements from the network. More... | |
void | RPS_sampler_set_deficiency_factor (struct RPS_Sampler *sampler, double deficiency_factor) |
Set the deficiency factor. More... | |
struct SamplerNotifyUpdateCTX * | sampler_notify_on_update (struct RPS_Sampler *sampler, SamplerNotifyUpdateCB notify_cb, void *cls) |
Add a callback that will be called when the next peer is inserted into the sampler. More... | |
unsigned int | RPS_sampler_get_size (struct RPS_Sampler *sampler) |
Get the size of the sampler. More... | |
static void | notify_update (struct RPS_Sampler *sampler) |
Notify about update of the sampler. More... | |
void | RPS_sampler_update (struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id) |
Update every sampler element of this sampler with given peer. More... | |
void | RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id) |
Reinitialise all previously initialised sampler elements with the given value. More... | |
uint32_t | RPS_sampler_count_id (struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id) |
Counts how many Samplers currently hold a given PeerID. More... | |
static void | sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) |
Grow or shrink the size of the sampler. More... | |
void | RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) |
Grow or shrink the size of the sampler. More... | |
static void | sampler_empty (struct RPS_Sampler *sampler) |
Empty the sampler. More... | |
static void | check_n_peers_ready (void *cls, const struct GNUNET_PeerIdentity *id, double probability, uint32_t num_observed) |
Callback to _get_rand_peer() used by _get_n_rand_peers(). More... | |
static void | check_peer_info_ready (void *cls, const struct GNUNET_PeerIdentity *id, double probability, uint32_t num_observed) |
Callback to _get_rand_peer() used by _get_rand_peer_info(). More... | |
struct RPS_SamplerRequestHandle * | RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, uint32_t num_peers, RPS_sampler_n_rand_peers_ready_cb cb, void *cls) |
Get n random peers out of the sampled peers. More... | |
struct RPS_SamplerRequestHandleSingleInfo * | RPS_sampler_get_rand_peer_info (struct RPS_Sampler *sampler, RPS_sampler_sinlge_info_ready_cb cb, void *cls) |
Get one random peer with additional information. More... | |
void | RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle) |
Cancel a request issued through RPS_sampler_n_rand_peers_ready_cb. More... | |
void | RPS_sampler_request_single_info_cancel (struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle) |
Cancel a request issued through RPS_sampler_sinlge_info_ready_cb. More... | |
void | RPS_sampler_destroy (struct RPS_Sampler *sampler) |
Cleans the sampler. More... | |
Code common to client and service sampler.
Definition in file rps-sampler_common.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "rps-sampler_common", __VA_ARGS__) |
Definition at line 38 of file rps-sampler_common.c.
void RPS_sampler_update_with_nw_size | ( | struct RPS_Sampler * | sampler, |
uint32_t | num_peers | ||
) |
Update the current estimate of the network size stored at the sampler.
Used for computing the condition when to return elements to the client
Only used/useful with the client sampler (Maybe move to rps-sampler_client.{h|c} ?)
sampler | The sampler to update |
num_peers | The estimated value |
Definition at line 169 of file rps-sampler_common.c.
References num_peers, and RPS_Sampler::num_peers_estim.
Referenced by nse_cb().
void RPS_sampler_set_desired_probability | ( | struct RPS_Sampler * | sampler, |
double | desired_probability | ||
) |
Set the probability that is needed at least with what a sampler element has to have observed all elements from the network.
Only used/useful with the client sampler (Maybe move to rps-sampler_client.{h|c} ?)
sampler | |
desired_probability |
Definition at line 187 of file rps-sampler_common.c.
References RPS_Sampler::desired_probability.
Referenced by GNUNET_RPS_request_peer_info(), and GNUNET_RPS_request_peers().
void RPS_sampler_set_deficiency_factor | ( | struct RPS_Sampler * | sampler, |
double | deficiency_factor | ||
) |
Set the deficiency factor.
Only used/useful with the client sampler (Maybe move to rps-sampler_client.{h|c} ?)
sampler | |
desired_probability |
Definition at line 195 of file rps-sampler_common.c.
References RPS_Sampler::deficiency_factor.
Referenced by GNUNET_RPS_request_peer_info(), and GNUNET_RPS_request_peers().
struct SamplerNotifyUpdateCTX * sampler_notify_on_update | ( | struct RPS_Sampler * | sampler, |
SamplerNotifyUpdateCB | notify_cb, | ||
void * | cls | ||
) |
Add a callback that will be called when the next peer is inserted into the sampler.
sampler | The sampler on which update it will be called |
notify_cb | The callback |
cls | Closure given to the callback |
Definition at line 213 of file rps-sampler_common.c.
References SamplerNotifyUpdateCTX::cls, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, LOG, SamplerNotifyUpdateCTX::notify_cb, notify_cb(), RPS_Sampler::notify_ctx_head, and RPS_Sampler::notify_ctx_tail.
Referenced by sampler_get_rand_peer(), and sampler_mod_get_rand_peer().
unsigned int RPS_sampler_get_size | ( | struct RPS_Sampler * | sampler | ) |
Get the size of the sampler.
sampler | the sampler to return the size of. |
Definition at line 238 of file rps-sampler_common.c.
References RPS_Sampler::sampler_size.
Referenced by adapt_sizes(), and resize_wrapper().
|
static |
Notify about update of the sampler.
Call the callbacks that are waiting for notification on updates to the sampler.
sampler | The sampler the updates are waiting for |
Definition at line 253 of file rps-sampler_common.c.
References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, LOG, RPS_Sampler::notify_ctx_head, and RPS_Sampler::notify_ctx_tail.
Referenced by RPS_sampler_update().
void RPS_sampler_update | ( | struct RPS_Sampler * | sampler, |
const struct GNUNET_PeerIdentity * | id | ||
) |
Update every sampler element of this sampler with given peer.
sampler | the sampler to update. |
id | the PeerID that is put in the sampler |
Definition at line 285 of file rps-sampler_common.c.
References notify_update(), RPS_sampler_elem_next(), RPS_Sampler::sampler_elements, and RPS_Sampler::sampler_size.
Referenced by collect_peers_cb(), collect_peers_info_cb(), and insert_in_sampler().
void RPS_sampler_reinitialise_by_value | ( | struct RPS_Sampler * | sampler, |
const struct GNUNET_PeerIdentity * | id | ||
) |
Reinitialise all previously initialised sampler elements with the given value.
Used to get rid of a PeerID.
FIXME: This should also consider currently pending requests (Pending requests already collect peerids. As long as not all requested IDs have been collected, they are kept. Ideally, the id
should be removed from all pending requests. This seems quite complicated.)
sampler | the sampler to reinitialise a sampler element in. |
id | the id of the sampler elements to update. |
Definition at line 312 of file rps-sampler_common.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_memcmp, LOG, RPS_SamplerElement::peer_id, RPS_sampler_elem_reinit(), RPS_Sampler::sampler_elements, and RPS_Sampler::sampler_size.
Referenced by remove_peer().
uint32_t RPS_sampler_count_id | ( | struct RPS_Sampler * | sampler, |
const struct GNUNET_PeerIdentity * | id | ||
) |
Counts how many Samplers currently hold a given PeerID.
sampler | the sampler to count ids in. |
id | the PeerID to count. |
Definition at line 338 of file rps-sampler_common.c.
References EMPTY, GNUNET_memcmp, RPS_SamplerElement::is_empty, RPS_SamplerElement::peer_id, RPS_Sampler::sampler_elements, and RPS_Sampler::sampler_size.
Referenced by check_sending_channel_needed(), clean_peer(), and insert_in_sampler().
|
static |
Grow or shrink the size of the sampler.
sampler | the sampler to resize. |
new_size | the new size of the sampler |
Definition at line 362 of file rps-sampler_common.c.
References GNUNET_array_grow, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, LOG, RPS_sampler_elem_create(), RPS_sampler_elem_destroy(), RPS_Sampler::sampler_elements, and RPS_Sampler::sampler_size.
Referenced by RPS_sampler_resize(), and sampler_empty().
void RPS_sampler_resize | ( | struct RPS_Sampler * | sampler, |
unsigned int | new_size | ||
) |
Grow or shrink the size of the sampler.
sampler | the sampler to resize. |
new_size | the new size of the sampler |
Definition at line 423 of file rps-sampler_common.c.
References GNUNET_assert, and sampler_resize().
Referenced by resize_wrapper(), RPS_sampler_init(), and RPS_sampler_mod_init().
|
static |
Empty the sampler.
sampler | the sampler to empty. |
Definition at line 436 of file rps-sampler_common.c.
References sampler_resize().
Referenced by RPS_sampler_destroy().
|
static |
Callback to _get_rand_peer() used by _get_n_rand_peers().
Implements RPS_sampler_rand_peer_ready_cont
Checks whether all n peers are available. If they are, give those back.
cls | Closure |
id | Peer ID |
probability | The probability with which this sampler has seen all ids |
num_observed | How many ids this sampler has observed |
Definition at line 455 of file rps-sampler_common.c.
References RPS_SamplerRequestHandle::cls, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_memcpy, GNUNET_new_array, LOG, num_peers, peers, req_handle, and RPS_sampler_request_cancel().
Referenced by RPS_sampler_get_n_rand_peers().
|
static |
Callback to _get_rand_peer() used by _get_rand_peer_info().
Implements RPS_sampler_rand_peer_ready_cont
cls | Closure |
id | Peer ID |
probability | The probability with which this sampler has seen all ids |
num_observed | How many ids this sampler has observed |
Definition at line 511 of file rps-sampler_common.c.
References RPS_SamplerRequestHandleSingleInfo::cls, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_memcpy, GNUNET_new, LOG, req_handle, and RPS_sampler_request_single_info_cancel().
Referenced by RPS_sampler_get_rand_peer_info().
struct RPS_SamplerRequestHandle * RPS_sampler_get_n_rand_peers | ( | struct RPS_Sampler * | sampler, |
uint32_t | num_peers, | ||
RPS_sampler_n_rand_peers_ready_cb | cb, | ||
void * | cls | ||
) |
Get n random peers out of the sampled peers.
We might want to reinitialise this sampler after giving the corrsponding peer to the client. Random with or without consumption?
sampler | the sampler to get peers from. |
cb | callback that will be called once the ids are ready. |
cls | closure given to cb |
for_client | GNUNET_YES if result is used for client, GNUNET_NO if used internally |
num_peers | the number of peers requested |
Definition at line 549 of file rps-sampler_common.c.
References check_n_peers_ready(), GetPeerCls::cont, GetPeerCls::cont_cls, GetPeerCls::get_peer_task, RPS_Sampler::get_peers, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_new_array, GNUNET_SCHEDULER_add_now(), GetPeerCls::id, LOG, num_peers, req_handle, GetPeerCls::req_handle, RPS_Sampler::req_handle_head, RPS_Sampler::req_handle_tail, GetPeerCls::req_single_info_handle, GNUNET_RPS_Request_Handle::sampler, and RPS_Sampler::sampler_size.
Referenced by do_round(), and GNUNET_RPS_request_peers().
struct RPS_SamplerRequestHandleSingleInfo * RPS_sampler_get_rand_peer_info | ( | struct RPS_Sampler * | sampler, |
RPS_sampler_sinlge_info_ready_cb | cb, | ||
void * | cls | ||
) |
Get one random peer with additional information.
sampler | the sampler to get peers from. |
cb | callback that will be called once the ids are ready. |
cls | closure given to cb |
Definition at line 605 of file rps-sampler_common.c.
References check_peer_info_ready(), GetPeerCls::cont, GetPeerCls::cont_cls, GetPeerCls::get_peer_task, RPS_Sampler::get_peers, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_malloc, GNUNET_new, GNUNET_SCHEDULER_add_now(), GetPeerCls::id, req_handle, GetPeerCls::req_handle, RPS_Sampler::req_handle_single_head, RPS_Sampler::req_handle_single_tail, GetPeerCls::req_single_info_handle, GNUNET_RPS_Request_Handle::sampler, and RPS_Sampler::sampler_size.
Referenced by GNUNET_RPS_request_peer_info().
void RPS_sampler_request_cancel | ( | struct RPS_SamplerRequestHandle * | req_handle | ) |
Cancel a request issued through RPS_sampler_n_rand_peers_ready_cb.
req_handle | the handle to the request |
Definition at line 647 of file rps-sampler_common.c.
References GetPeerCls::get_peer_task, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_SCHEDULER_cancel(), GetPeerCls::notify_ctx, RPS_Sampler::notify_ctx_head, RPS_Sampler::notify_ctx_tail, req_handle, RPS_Sampler::req_handle_head, RPS_Sampler::req_handle_tail, and GNUNET_RPS_Request_Handle::sampler.
Referenced by check_n_peers_ready(), GNUNET_RPS_request_cancel(), and RPS_sampler_destroy().
void RPS_sampler_request_single_info_cancel | ( | struct RPS_SamplerRequestHandleSingleInfo * | req_single_info_handle | ) |
Cancel a request issued through RPS_sampler_sinlge_info_ready_cb.
Cancel a request issued through RPS_sampler_n_rand_peers_ready_cb.
req_handle | the handle to the request |
Definition at line 685 of file rps-sampler_common.c.
References GetPeerCls::get_peer_task, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_SCHEDULER_cancel(), RPS_SamplerRequestHandleSingleInfo::gpc_head, RPS_SamplerRequestHandleSingleInfo::gpc_tail, RPS_SamplerRequestHandleSingleInfo::id, GetPeerCls::notify_ctx, RPS_Sampler::notify_ctx_head, RPS_Sampler::req_handle_single_head, GetPeerCls::req_single_info_handle, and RPS_SamplerRequestHandleSingleInfo::sampler.
Referenced by check_peer_info_ready(), and GNUNET_RPS_request_single_info_cancel().
void RPS_sampler_destroy | ( | struct RPS_Sampler * | sampler | ) |
Cleans the sampler.
Cleans the samplers.
Definition at line 726 of file rps-sampler_common.c.
References GNUNET_ERROR_TYPE_WARNING, GNUNET_free, LOG, RPS_Sampler::req_handle_head, RPS_sampler_request_cancel(), and sampler_empty().
Referenced by destroy_sub(), GNUNET_RPS_request_cancel(), and GNUNET_RPS_request_single_info_cancel().