Code common to client and service sampler. More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_statistics_service.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 | GetPeerCls |
Closure for sampler_mod_get_rand_peer() and sampler_get_rand_peer. More... | |
struct | RPS_Sampler |
Sampler with its own array of SamplerElements. More... | |
Typedefs | |
typedef void(* | RPS_sampler_rand_peer_ready_cont) (void *cls, const struct GNUNET_PeerIdentity *id, double probability, uint32_t num_observed) |
Callback that is called from _get_rand_peer() when the PeerID is ready. More... | |
typedef void(* | RPS_get_peers_type) (void *cls) |
Type of function used to differentiate between modified and not modified Sampler. More... | |
typedef void(* | RPS_sampler_n_rand_peers_ready_cb) (const struct GNUNET_PeerIdentity *ids, uint32_t num_peers, void *cls) |
Callback that is called from _get_n_rand_peers() when the PeerIDs are ready. More... | |
typedef void(* | RPS_sampler_sinlge_info_ready_cb) (const struct GNUNET_PeerIdentity *ids, void *cls, double probability, uint32_t num_observed) |
Callback that is called from _get_n_rand_peers() when the PeerIDs are ready. More... | |
typedef void(* | SamplerNotifyUpdateCB) (void *cls) |
Callback called each time a new peer was put into the sampler. More... | |
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... | |
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... | |
unsigned int | RPS_sampler_get_size (struct RPS_Sampler *sampler) |
Get 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... | |
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... | |
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... | |
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_n_rand_peers_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.h.
typedef void(* RPS_sampler_rand_peer_ready_cont) (void *cls, const struct GNUNET_PeerIdentity *id, double probability, uint32_t num_observed) |
Callback that is called from _get_rand_peer() when the PeerID is ready.
cls | the closure given alongside this function. |
id | the PeerID that was returned |
probability | The probability with which this sampler has seen all ids |
num_observed | How many ids this sampler has observed |
Definition at line 50 of file rps-sampler_common.h.
typedef void(* RPS_get_peers_type) (void *cls) |
Type of function used to differentiate between modified and not modified Sampler.
Definition at line 61 of file rps-sampler_common.h.
typedef void(* RPS_sampler_n_rand_peers_ready_cb) (const struct GNUNET_PeerIdentity *ids, uint32_t num_peers, void *cls) |
Callback that is called from _get_n_rand_peers() when the PeerIDs are ready.
cls | the closure given alongside this function. |
ids | the PeerIDs that were returned to be freed |
Definition at line 72 of file rps-sampler_common.h.
typedef void(* RPS_sampler_sinlge_info_ready_cb) (const struct GNUNET_PeerIdentity *ids, void *cls, double probability, uint32_t num_observed) |
Callback that is called from _get_n_rand_peers() when the PeerIDs are ready.
cls | the closure given alongside this function. |
probability | Probability with which all IDs have been observed |
num_observed | Number of observed IDs |
ids | the PeerIDs that were returned to be freed |
Definition at line 87 of file rps-sampler_common.h.
typedef void(* SamplerNotifyUpdateCB) (void *cls) |
Callback called each time a new peer was put into the sampler.
cls | A possibly given closure |
Definition at line 99 of file rps-sampler_common.h.
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
sampler | The sampler to update |
num_peers | The estimated value |
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().
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.
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.
sampler | the sampler to reinitialise a sampler element in. |
id | the id of the sampler elements to update. |
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.
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.
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.
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 |
num_peers | the number of peers requested |
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.
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().
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.
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.
Referenced by check_n_peers_ready(), 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_n_rand_peers_ready_cb.
req_handle | the handle to the request |
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.