38 #define LOG(kind, ...) GNUNET_log_from (kind, "rps-sampler_common", __VA_ARGS__) 229 "Inserting new context for notification\n");
268 "Calling callbacks waiting for update notification.\n");
274 NULL != tmp_notify_head;
275 notify_iter = tmp_notify_head)
281 notify_iter->notify_cb (notify_iter->cls);
373 unsigned int old_size;
380 if (old_size > new_size)
383 "Shrinking sampler %d -> %d\n",
387 for (i = new_size; i < old_size; i++)
396 "sampler->sampler_elements now points to %p\n",
399 else if (old_size < new_size)
402 "Growing sampler %d -> %d\n",
410 for (i = old_size; i < new_size; i++)
468 uint32_t num_observed)
482 "Got %" PRIX32
". of %" PRIX32
" peers\n",
490 "returning %" PRIX32
" peers to the client\n",
501 cb_cls = req_handle->
cls;
504 tmp_cb (peers, num_peers, cb_cls);
524 uint32_t num_observed)
536 "Got single peer with additional info\n");
541 "returning single peer with info to the client\n");
550 cb_cls = req_handle->
cls;
553 tmp_cb (peer, cb_cls, probability, num_observed);
597 "Scheduling requests for %" PRIu32
" peers\n", num_peers);
606 gpc->
id = &req_handle->
ids[i];
651 gpc->
id = req_handle->
id;
673 while (NULL != (i = req_handle->
gpc_head))
693 req_handle->
ids = NULL;
712 while (NULL != (i = req_single_info_handle->
gpc_head))
725 req_single_info_handle->
sampler->
734 req_single_info_handle->
id = NULL;
737 req_single_info_handle->
sampler->
738 req_handle_single_tail,
739 req_single_info_handle);
753 "There are still pending requests. Going to remove them.\n");
struct SamplerNotifyUpdateCTX * notify_ctx_tail
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
double desired_probability
The desired probability with which we want to have observed all peers.
uint32_t num_peers_estim
The estimated total number of peers in the network.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
RPS_sampler_rand_peer_ready_cont cont
The callback.
struct SamplerNotifyUpdateCTX * prev
Previous element in DLL.
uint32_t num_peers
Number of peers we are waiting for.
void RPS_sampler_elem_destroy(struct RPS_SamplerElement *sampler_elem)
Destroy a sampler element.
Some utils faciliating the view into the internals for the sampler needed for evaluation.
void RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler, double deficiency_factor)
Set the deficiency factor.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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 elem...
void * cls
Closure given to the callback.
void RPS_sampler_request_single_info_cancel(struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle)
Cancle a request issued through RPS_sampler_sinlge_info_ready_cb.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
sampler element implementation
struct RPS_SamplerRequestHandleSingleInfo * req_handle_single_head
Head and tail for the DLL to store the RPS_SamplerRequestHandleSingleInfo.
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().
RPS_sampler_n_rand_peers_ready_cb callback
Callback to be called when all ids are available.
void RPS_sampler_update(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Update every sampler element of this sampler with given peer.
void RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle)
Cancle a request issued through RPS_sampler_n_rand_peers_ready_cb.
Code common to client and service sampler.
struct RPS_SamplerElement * RPS_sampler_elem_create(void)
Create a sampler element and initialise it.
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void RPS_sampler_elem_reinit(struct RPS_SamplerElement *sampler_elem)
Reinitialise a previously initialised sampler element.
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().
struct RPS_SamplerRequestHandle * req_handle
The RPS_SamplerRequestHandle this single request belongs to.
struct GetPeerCls * gpc_tail
void(* SamplerNotifyUpdateCB)(void *cls)
Callback called each time a new peer was put into the sampler.
Closure to _get_n_rand_peers_ready_cb()
struct SamplerNotifyUpdateCTX * notify_ctx
Context to the given callback.
struct SamplerNotifyUpdateCTX * next
Next element in DLL.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
struct RPS_Sampler * sampler
Sampler.
static void sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size)
Grow or shrink the size of the sampler.
static struct GNUNET_RPS_Request_Handle * req_handle
Request handle.
static struct GNUNET_CONTAINER_MultiPeerMap * ids
GNUNET_PeerIdentity -> CadetPeer.
enum RPS_SamplerEmpty is_empty
Flag that indicates that we are not holding a valid PeerID right now.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
struct GNUNET_PeerIdentity peer_id
The PeerID this sampler currently samples.
SamplerNotifyUpdateCB notify_cb
The Callback to call on updates.
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.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
void * cls
The according closure.
void RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size)
Grow or shrink the size of the sampler.
Closure to _get_rand_peer_info()
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.
void * cls
Closure given to the callback.
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.
struct GetPeerCls * gpc_head
Head and tail for the DLL to store the tasks for single requests.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_PeerIdentity * ids
Pointer to the array holding the ids.
static unsigned int num_peers
struct RPS_SamplerRequestHandleSingleInfo * req_handle_single_tail
static void sampler_empty(struct RPS_Sampler *sampler)
Empty the sampler.
struct GNUNET_PeerIdentity * id
Pointer to the id.
uint32_t cur_num_peers
Number of peers we currently have.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct RPS_SamplerRequestHandleSingleInfo * req_single_info_handle
The RPS_SamplerRequestHandleSingleInfo this single request belongs to.
void * cont_cls
The closure to the callback cont.
static void notify_update(struct RPS_Sampler *sampler)
Notify about update of the sampler.
The identity of the host (wraps the signing key of the peer).
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.
unsigned int RPS_sampler_get_size(struct RPS_Sampler *sampler)
Get the size of the sampler.
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.
static struct CadetPeer * peers
Operation to get peer ids.
Closure for sampler_mod_get_rand_peer() and sampler_get_rand_peer.
struct RPS_SamplerRequestHandle * req_handle_head
Head and tail for the DLL to store the RPS_SamplerRequestHandle.
unsigned int sampler_size
Number of sampler elements we hold.
double deficiency_factor
A factor that catches the 'bias' of a random stream of peer ids.
struct GetPeerCls * gpc_tail
void RPS_sampler_destroy(struct RPS_Sampler *sampler)
Cleans the sampler.
struct SamplerNotifyUpdateCTX * notify_ctx_head
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.
RPS_get_peers_type get_peers
Stores the function to return peers.
void RPS_sampler_elem_next(struct RPS_SamplerElement *sampler_elem, const struct GNUNET_PeerIdentity *new_ID)
Update a sampler element with a PeerID.
struct RPS_SamplerElement ** sampler_elements
All sampler elements in one array.
struct RPS_SamplerRequestHandle * req_handle_tail
Sampler with its own array of SamplerElements.
uint32_t RPS_sampler_count_id(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Counts how many Samplers currently hold a given PeerID.
struct GNUNET_PeerIdentity * id
The address of the id to be stored at.
struct GNUNET_SCHEDULER_Task * get_peer_task
The task for this function.
#define GNUNET_malloc(size)
Wrapper around malloc.
RPS_sampler_sinlge_info_ready_cb callback
Callback to be called when all ids are available.
struct GetPeerCls * gpc_head
Head and tail for the DLL to store the tasks for single requests.
#define GNUNET_free(ptr)
Wrapper around free.
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.
struct RPS_Sampler * sampler
Sampler.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.