GNUnet  0.21.0
rps-sampler_common.c File Reference

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"
Include dependency graph for rps-sampler_common.c:

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 SamplerNotifyUpdateCTXsampler_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_SamplerRequestHandleRPS_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_SamplerRequestHandleSingleInfoRPS_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...
 

Detailed Description

Code common to client and service sampler.

Author
Julius Bünger

Definition in file rps-sampler_common.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "rps-sampler_common", __VA_ARGS__)

Definition at line 38 of file rps-sampler_common.c.

Function Documentation

◆ RPS_sampler_update_with_nw_size()

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} ?)

Parameters
samplerThe sampler to update
num_peersThe estimated value

Definition at line 169 of file rps-sampler_common.c.

171 {
172  sampler->num_peers_estim = num_peers;
173 }
static uint32_t num_peers
How many peers do we start?
uint32_t num_peers_estim
The estimated total number of peers in the network.

References num_peers, and RPS_Sampler::num_peers_estim.

Referenced by nse_cb().

Here is the caller graph for this function:

◆ RPS_sampler_set_desired_probability()

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} ?)

Parameters
sampler
desired_probability

Definition at line 187 of file rps-sampler_common.c.

189 {
190  sampler->desired_probability = desired_probability;
191 }
double desired_probability
The desired probability with which we want to have observed all peers.

References RPS_Sampler::desired_probability.

Referenced by GNUNET_RPS_request_peer_info(), and GNUNET_RPS_request_peers().

Here is the caller graph for this function:

◆ RPS_sampler_set_deficiency_factor()

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} ?)

Parameters
sampler
desired_probability

Definition at line 195 of file rps-sampler_common.c.

197 {
198  sampler->deficiency_factor = deficiency_factor;
199 }
double deficiency_factor
A factor that catches the 'bias' of a random stream of peer ids.

References RPS_Sampler::deficiency_factor.

Referenced by GNUNET_RPS_request_peer_info(), and GNUNET_RPS_request_peers().

Here is the caller graph for this function:

◆ sampler_notify_on_update()

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.

Parameters
samplerThe sampler on which update it will be called
notify_cbThe callback
clsClosure given to the callback
Returns
The context containing callback and closure

Definition at line 213 of file rps-sampler_common.c.

216 {
217  struct SamplerNotifyUpdateCTX *notify_ctx;
218 
220  "Inserting new context for notification\n");
221  notify_ctx = GNUNET_new (struct SamplerNotifyUpdateCTX);
222  notify_ctx->notify_cb = notify_cb;
223  notify_ctx->cls = cls;
225  sampler->notify_ctx_tail,
226  notify_ctx);
227  return notify_ctx;
228 }
static void notify_cb(void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg)
Function called when the transport service has received a backchannel message for this communicator (...
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define LOG(kind,...)
struct SamplerNotifyUpdateCTX * notify_ctx_head
struct SamplerNotifyUpdateCTX * notify_ctx_tail
SamplerNotifyUpdateCB notify_cb
The Callback to call on updates.
void * cls
The according closure.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RPS_sampler_get_size()

unsigned int RPS_sampler_get_size ( struct RPS_Sampler sampler)

Get the size of the sampler.

Parameters
samplerthe sampler to return the size of.
Returns
the size of the sampler

Definition at line 238 of file rps-sampler_common.c.

239 {
240  return sampler->sampler_size;
241 }
unsigned int sampler_size
Number of sampler elements we hold.

References RPS_Sampler::sampler_size.

Referenced by adapt_sizes(), and resize_wrapper().

Here is the caller graph for this function:

◆ notify_update()

static void notify_update ( struct RPS_Sampler sampler)
static

Notify about update of the sampler.

Call the callbacks that are waiting for notification on updates to the sampler.

Parameters
samplerThe sampler the updates are waiting for

Definition at line 253 of file rps-sampler_common.c.

254 {
255  struct SamplerNotifyUpdateCTX *tmp_notify_head;
256  struct SamplerNotifyUpdateCTX *tmp_notify_tail;
257 
259  "Calling callbacks waiting for update notification.\n");
260  tmp_notify_head = sampler->notify_ctx_head;
261  tmp_notify_tail = sampler->notify_ctx_tail;
262  sampler->notify_ctx_head = NULL;
263  sampler->notify_ctx_tail = NULL;
264  for (struct SamplerNotifyUpdateCTX *notify_iter = tmp_notify_head;
265  NULL != tmp_notify_head;
266  notify_iter = tmp_notify_head)
267  {
268  GNUNET_assert (NULL != notify_iter->notify_cb);
269  GNUNET_CONTAINER_DLL_remove (tmp_notify_head,
270  tmp_notify_tail,
271  notify_iter);
272  notify_iter->notify_cb (notify_iter->cls);
273  GNUNET_free (notify_iter);
274  }
275 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_free(ptr)
Wrapper around free.

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().

Here is the caller graph for this function:

◆ 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.

Parameters
samplerthe sampler to update.
idthe PeerID that is put in the sampler

Definition at line 285 of file rps-sampler_common.c.

287 {
288  for (uint32_t i = 0; i < sampler->sampler_size; i++)
289  {
291  id);
292  }
293  notify_update (sampler);
294 }
void RPS_sampler_elem_next(struct RPS_SamplerElement *sampler_elem, const struct GNUNET_PeerIdentity *new_ID)
Update a sampler element with a PeerID.
static void notify_update(struct RPS_Sampler *sampler)
Notify about update of the sampler.
struct RPS_SamplerElement ** sampler_elements
All sampler elements in one array.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RPS_sampler_reinitialise_by_value()

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.)

Parameters
samplerthe sampler to reinitialise a sampler element in.
idthe id of the sampler elements to update.

Definition at line 312 of file rps-sampler_common.c.

314 {
315  uint32_t i;
316 
317  for (i = 0; i < sampler->sampler_size; i++)
318  {
319  if (0 == GNUNET_memcmp (id,
320  &(sampler->sampler_elements[i]->peer_id)))
321  {
322  LOG (GNUNET_ERROR_TYPE_DEBUG, "Reinitialising sampler\n");
324  }
325  }
326 }
void RPS_sampler_elem_reinit(struct RPS_SamplerElement *sampler_elem)
Reinitialise a previously initialised sampler element.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct GNUNET_PeerIdentity peer_id
The PeerID this sampler currently samples.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RPS_sampler_count_id()

uint32_t RPS_sampler_count_id ( struct RPS_Sampler sampler,
const struct GNUNET_PeerIdentity id 
)

Counts how many Samplers currently hold a given PeerID.

Parameters
samplerthe sampler to count ids in.
idthe PeerID to count.
Returns
the number of occurrences of id.

Definition at line 338 of file rps-sampler_common.c.

340 {
341  uint32_t count;
342  uint32_t i;
343 
344  count = 0;
345  for (i = 0; i < sampler->sampler_size; i++)
346  {
347  if ((0 == GNUNET_memcmp (&sampler->sampler_elements[i]->peer_id, id))
348  && (EMPTY != sampler->sampler_elements[i]->is_empty) )
349  count++;
350  }
351  return count;
352 }
enum RPS_SamplerEmpty is_empty
Flag that indicates that we are not holding a valid PeerID right now.

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().

Here is the caller graph for this function:

◆ sampler_resize()

static void sampler_resize ( struct RPS_Sampler sampler,
unsigned int  new_size 
)
static

Grow or shrink the size of the sampler.

Parameters
samplerthe sampler to resize.
new_sizethe new size of the sampler

Definition at line 362 of file rps-sampler_common.c.

363 {
364  unsigned int old_size;
365  uint32_t i;
366 
367  // TODO check min and max size
368 
369  old_size = sampler->sampler_size;
370 
371  if (old_size > new_size)
372  { /* Shrinking */
374  "Shrinking sampler %d -> %d\n",
375  old_size,
376  new_size);
377 
378  for (i = new_size; i < old_size; i++)
379  {
381  }
382 
384  sampler->sampler_size,
385  new_size);
387  "sampler->sampler_elements now points to %p\n",
388  sampler->sampler_elements);
389  }
390  else if (old_size < new_size)
391  { /* Growing */
393  "Growing sampler %d -> %d\n",
394  old_size,
395  new_size);
396 
398  sampler->sampler_size,
399  new_size);
400 
401  for (i = old_size; i < new_size; i++)
402  { /* Add new sampler elements */
403  sampler->sampler_elements[i] = RPS_sampler_elem_create ();
404  }
405  }
406  else
407  {
408  LOG (GNUNET_ERROR_TYPE_DEBUG, "Size remains the same -- nothing to do\n");
409  return;
410  }
411 
412  GNUNET_assert (sampler->sampler_size == new_size);
413 }
void RPS_sampler_elem_destroy(struct RPS_SamplerElement *sampler_elem)
Destroy a sampler element.
struct RPS_SamplerElement * RPS_sampler_elem_create(void)
Create a sampler element and initialise it.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RPS_sampler_resize()

void RPS_sampler_resize ( struct RPS_Sampler sampler,
unsigned int  new_size 
)

Grow or shrink the size of the sampler.

Parameters
samplerthe sampler to resize.
new_sizethe new size of the sampler

Definition at line 423 of file rps-sampler_common.c.

424 {
425  GNUNET_assert (0 < new_size);
426  sampler_resize (sampler, new_size);
427 }
static void sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size)
Grow or shrink the size of the sampler.

References GNUNET_assert, and sampler_resize().

Referenced by resize_wrapper(), RPS_sampler_init(), and RPS_sampler_mod_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sampler_empty()

static void sampler_empty ( struct RPS_Sampler sampler)
static

Empty the sampler.

Parameters
samplerthe sampler to empty.

Definition at line 436 of file rps-sampler_common.c.

437 {
438  sampler_resize (sampler, 0);
439 }

References sampler_resize().

Referenced by RPS_sampler_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_n_peers_ready()

static void check_n_peers_ready ( void *  cls,
const struct GNUNET_PeerIdentity id,
double  probability,
uint32_t  num_observed 
)
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.

Parameters
clsClosure
idPeer ID
probabilityThe probability with which this sampler has seen all ids
num_observedHow many ids this sampler has observed

Definition at line 455 of file rps-sampler_common.c.

459 {
461 
462  (void) id;
464  struct GNUNET_PeerIdentity *peers;
465  uint32_t num_peers;
466  void *cb_cls;
467  (void) probability;
468  (void) num_observed;
469 
470  req_handle->cur_num_peers++;
472  "Got %" PRIX32 ". of %" PRIX32 " peers\n",
473  req_handle->cur_num_peers, req_handle->num_peers);
474 
475  if (req_handle->num_peers == req_handle->cur_num_peers)
476  { /* All peers are ready -- return those to the client */
477  GNUNET_assert (NULL != req_handle->callback);
478 
480  "returning %" PRIX32 " peers to the client\n",
481  req_handle->num_peers);
482 
483  /* Copy pointers and peers temporarily as they
484  * might be deleted from within the callback */
485  tmp_cb = req_handle->callback;
486  num_peers = req_handle->num_peers;
489  req_handle->ids,
490  num_peers * sizeof(struct GNUNET_PeerIdentity));
491  cb_cls = req_handle->cls;
493  req_handle = NULL;
494  tmp_cb (peers, num_peers, cb_cls);
495  GNUNET_free (peers);
496  }
497 }
static struct GNUNET_RPS_Request_Handle * req_handle
Request handle.
Definition: gnunet-rps.c:41
static struct GNUNET_TESTBED_Peer ** peers
Handles to the running peers.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
void RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle)
Cancel a request issued through RPS_sampler_n_rand_peers_ready_cb.
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.
The identity of the host (wraps the signing key of the peer).
Closure to _get_n_rand_peers_ready_cb()
void * cls
Closure given to the callback.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_peer_info_ready()

static void check_peer_info_ready ( void *  cls,
const struct GNUNET_PeerIdentity id,
double  probability,
uint32_t  num_observed 
)
static

Callback to _get_rand_peer() used by _get_rand_peer_info().

Implements RPS_sampler_rand_peer_ready_cont

Parameters
clsClosure
idPeer ID
probabilityThe probability with which this sampler has seen all ids
num_observedHow many ids this sampler has observed

Definition at line 511 of file rps-sampler_common.c.

515 {
517 
518  (void) id;
520  struct GNUNET_PeerIdentity *peer;
521  void *cb_cls;
522  (void) probability;
523  (void) num_observed;
524 
526  "Got single peer with additional info\n");
527 
528  GNUNET_assert (NULL != req_handle->callback);
529 
531  "returning single peer with info to the client\n");
532 
533  /* Copy pointers and peers temporarily as they
534  * might be deleted from within the callback */
535  tmp_cb = req_handle->callback;
536  peer = GNUNET_new (struct GNUNET_PeerIdentity);
537  GNUNET_memcpy (peer,
538  req_handle->id,
539  sizeof(struct GNUNET_PeerIdentity));
540  cb_cls = req_handle->cls;
542  req_handle = NULL;
543  tmp_cb (peer, cb_cls, probability, num_observed);
544  GNUNET_free (peer);
545 }
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.
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.
Closure to _get_rand_peer_info()
void * cls
Closure given to the callback.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RPS_sampler_get_n_rand_peers()

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?

Parameters
samplerthe sampler to get peers from.
cbcallback that will be called once the ids are ready.
clsclosure given to cb
for_clientGNUNET_YES if result is used for client, GNUNET_NO if used internally
num_peersthe number of peers requested

Definition at line 549 of file rps-sampler_common.c.

553 {
554  uint32_t i;
556  struct GetPeerCls *gpc;
557 
558  GNUNET_assert (0 != sampler->sampler_size);
559  if (0 == num_peers)
560  return NULL;
561 
562  // TODO check if we have too much (distinct) sampled peers
564  req_handle->num_peers = num_peers;
565  req_handle->cur_num_peers = 0;
567  req_handle->sampler = sampler;
568  req_handle->callback = cb;
569  req_handle->cls = cls;
571  sampler->req_handle_tail,
572  req_handle);
573 
575  "Scheduling requests for %" PRIu32 " peers\n", num_peers);
576 
577  for (i = 0; i < num_peers; i++)
578  {
579  gpc = GNUNET_new (struct GetPeerCls);
580  gpc->req_handle = req_handle;
581  gpc->req_single_info_handle = NULL;
582  gpc->cont = check_n_peers_ready;
583  gpc->cont_cls = req_handle;
584  gpc->id = &req_handle->ids[i];
585 
587  req_handle->gpc_tail,
588  gpc);
589  // maybe add a little delay
591  gpc);
592  }
593  return req_handle;
594 }
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.
Definition: scheduler.c:1299
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_Sampler * sampler
The Sampler for the client request.
Definition: rps_api.c:174
Closure for sampler_mod_get_rand_peer() and sampler_get_rand_peer.
struct RPS_SamplerRequestHandleSingleInfo * req_single_info_handle
The RPS_SamplerRequestHandleSingleInfo this single request belongs to.
struct GNUNET_PeerIdentity * id
The address of the id to be stored at.
RPS_sampler_rand_peer_ready_cont cont
The callback.
struct RPS_SamplerRequestHandle * req_handle
The RPS_SamplerRequestHandle this single request belongs to.
struct GNUNET_SCHEDULER_Task * get_peer_task
The task for this function.
void * cont_cls
The closure to the callback cont.
struct RPS_SamplerRequestHandle * req_handle_head
Head and tail for the DLL to store the RPS_SamplerRequestHandle.
RPS_get_peers_type get_peers
Stores the function to return peers.
struct RPS_SamplerRequestHandle * req_handle_tail

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RPS_sampler_get_rand_peer_info()

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.

Parameters
samplerthe sampler to get peers from.
cbcallback that will be called once the ids are ready.
clsclosure given to cb

Definition at line 605 of file rps-sampler_common.c.

608 {
610  struct GetPeerCls *gpc;
611 
612  GNUNET_assert (0 != sampler->sampler_size);
613 
614  // TODO check if we have too much (distinct) sampled peers
616  req_handle->id = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity));
617  req_handle->sampler = sampler;
618  req_handle->callback = cb;
619  req_handle->cls = cls;
621  sampler->req_handle_single_tail,
622  req_handle);
623 
624  gpc = GNUNET_new (struct GetPeerCls);
625  gpc->req_handle = NULL;
628  gpc->cont_cls = req_handle;
629  gpc->id = req_handle->id;
630 
632  req_handle->gpc_tail,
633  gpc);
634  // maybe add a little delay
636  gpc);
637  return req_handle;
638 }
#define GNUNET_malloc(size)
Wrapper around malloc.
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().
struct RPS_SamplerRequestHandleSingleInfo * req_handle_single_tail
struct RPS_SamplerRequestHandleSingleInfo * req_handle_single_head
Head and tail for the DLL to store the RPS_SamplerRequestHandleSingleInfo.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RPS_sampler_request_cancel()

void RPS_sampler_request_cancel ( struct RPS_SamplerRequestHandle req_handle)

Cancel a request issued through RPS_sampler_n_rand_peers_ready_cb.

Parameters
req_handlethe handle to the request

Definition at line 647 of file rps-sampler_common.c.

648 {
649  struct GetPeerCls *i;
650 
651  while (NULL != (i = req_handle->gpc_head))
652  {
654  req_handle->gpc_tail,
655  i);
656  if (NULL != i->get_peer_task)
657  {
659  }
660  if (NULL != i->notify_ctx)
661  {
664  i->notify_ctx);
665  GNUNET_free (i->notify_ctx);
666  i->notify_ctx = NULL;
667  }
668  GNUNET_free (i);
669  }
670  GNUNET_free (req_handle->ids);
671  req_handle->ids = NULL;
674  req_handle);
676 }
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
struct SamplerNotifyUpdateCTX * notify_ctx
Context to the given callback.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RPS_sampler_request_single_info_cancel()

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.

Parameters
req_handlethe handle to the request

Definition at line 685 of file rps-sampler_common.c.

687 {
688  struct GetPeerCls *i;
689 
690  while (NULL != (i = req_single_info_handle->gpc_head))
691  {
694  i);
695  if (NULL != i->get_peer_task)
696  {
698  }
699  if (NULL != i->notify_ctx)
700  {
704  notify_ctx_tail,
705  i->notify_ctx);
706  GNUNET_free (i->notify_ctx);
707  i->notify_ctx = NULL;
708  }
709  GNUNET_free (i);
710  }
712  req_single_info_handle->id = NULL;
716  req_handle_single_tail,
719 }
struct RPS_Sampler * sampler
Sampler.
struct GetPeerCls * gpc_head
Head and tail for the DLL to store the tasks for single requests.
struct GNUNET_PeerIdentity * id
Pointer to the id.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RPS_sampler_destroy()

void RPS_sampler_destroy ( struct RPS_Sampler sampler)

Cleans the sampler.

Cleans the samplers.

Definition at line 726 of file rps-sampler_common.c.

727 {
728  if (NULL != sampler->req_handle_head)
729  {
731  "There are still pending requests. Going to remove them.\n");
732  while (NULL != sampler->req_handle_head)
733  {
735  }
736  }
737  sampler_empty (sampler);
738  GNUNET_free (sampler);
739 }
@ GNUNET_ERROR_TYPE_WARNING
static void sampler_empty(struct RPS_Sampler *sampler)
Empty the sampler.

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().

Here is the call graph for this function:
Here is the caller graph for this function: