GNUnet  0.10.x
Functions
gnunet-service-rps_sampler.h File Reference

sampler implementation More...

#include <inttypes.h>
#include "rps-sampler_common.h"
Include dependency graph for gnunet-service-rps_sampler.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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_SamplerRPS_sampler_init (size_t init_size, struct GNUNET_TIME_Relative max_round_interval)
 Initialise a tuple of samplers. 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...
 
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...
 
void RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle)
 Cancle a request issued through RPS_sampler_n_rand_peers_ready_cb. 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_destroy (struct RPS_Sampler *sampler)
 Cleans the samplers. More...
 

Detailed Description

sampler implementation

Author
Julius B√ľnger

Definition in file gnunet-service-rps_sampler.h.

Function Documentation

◆ 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 244 of file rps-sampler_common.c.

Referenced by adapt_sizes(), and resize_wrapper().

245 {
246  return sampler->sampler_size;
247 }
unsigned int sampler_size
Number of sampler elements we hold.
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 (not 0)
samplerthe sampler to resize.
new_sizethe new size of the sampler

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

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

430 {
431  GNUNET_assert(0 < new_size);
432  sampler_resize(sampler, new_size);
433 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size)
Grow or shrink the size of the sampler.
Here is the caller graph for this function:

◆ RPS_sampler_init()

struct RPS_Sampler* RPS_sampler_init ( size_t  init_size,
struct GNUNET_TIME_Relative  max_round_interval 
)

Initialise a tuple of samplers.

Parameters
init_sizethe size the sampler is initialised with
max_round_intervalmaximum time a round takes
Returns
a handle to a sampler that consists of sampler elements.

Initialise a tuple of samplers.

Parameters
init_sizethe size the sampler is initialised with
max_round_intervalmaximum time a round takes
Returns
a handle to a sampler that consists of sampler elements.

Definition at line 194 of file gnunet-service-rps_sampler.c.

References RPS_Sampler::get_peers, GNUNET_new, RPS_Sampler::max_round_interval, RPS_sampler_resize(), and sampler_get_rand_peer().

Referenced by new_sub().

196 {
197  struct RPS_Sampler *sampler;
198 
199  /* Initialise context around extended sampler */
200  min_size = 10; // TODO make input to _samplers_init()
201  max_size = 1000; // TODO make input to _samplers_init()
202 
203  sampler = GNUNET_new(struct RPS_Sampler);
204 
206  sampler->get_peers = sampler_get_rand_peer;
207  //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity);
208  //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size);
209  RPS_sampler_resize(sampler, init_size);
210 
211  client_get_index = 0;
212 
213  //GNUNET_assert (init_size == sampler->sampler_size);
214  return sampler;
215 }
static void sampler_get_rand_peer(void *cls)
Get one random peer out of the sampled peers.
static size_t min_size
Global sampler variable.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TIME_Relative max_round_interval
Maximum time a round takes.
static uint32_t client_get_index
The size the extended sampler elements currently have.
void RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size)
Grow or shrink the size of the sampler.
static size_t max_size
The maximal size the extended sampler elements should grow to.
RPS_get_peers_type get_peers
Stores the function to return peers.
Sampler with its own array of SamplerElements.
Here is the call graph for this function:
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 291 of file rps-sampler_common.c.

Referenced by collect_peers_cb(), collect_peers_info_cb(), and insert_in_sampler().

293 {
294  for (uint32_t i = 0; i < sampler->sampler_size; i++)
295  {
297  id);
298  }
299  notify_update(sampler);
300 }
static void notify_update(struct RPS_Sampler *sampler)
Notify about update of the sampler.
unsigned int sampler_size
Number of sampler elements we hold.
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.
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 in.
idthe id of the samplers 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.)

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

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

Referenced by remove_peer().

320 {
321  uint32_t i;
322 
323  for (i = 0; i < sampler->sampler_size; i++)
324  {
325  if (0 == GNUNET_memcmp(id,
326  &(sampler->sampler_elements[i]->peer_id)))
327  {
328  LOG(GNUNET_ERROR_TYPE_DEBUG, "Reinitialising sampler\n");
330  }
331  }
332 }
void RPS_sampler_elem_reinit(struct RPS_SamplerElement *sampler_elem)
Reinitialise a previously initialised sampler element.
struct GNUNET_PeerIdentity peer_id
The PeerID this sampler currently samples.
#define LOG(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
unsigned int sampler_size
Number of sampler elements we hold.
struct RPS_SamplerElement ** sampler_elements
All sampler elements in one array.
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

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
num_peersthe number of peers requested

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

Referenced by do_round(), and GNUNET_RPS_request_peers().

572 {
573  uint32_t i;
575  struct GetPeerCls *gpc;
576 
577  GNUNET_assert(0 != sampler->sampler_size);
578  if (0 == num_peers)
579  return NULL;
580 
581  // TODO check if we have too much (distinct) sampled peers
582  req_handle = GNUNET_new(struct RPS_SamplerRequestHandle);
583  req_handle->num_peers = num_peers;
584  req_handle->cur_num_peers = 0;
585  req_handle->ids = GNUNET_new_array(num_peers, struct GNUNET_PeerIdentity);
586  req_handle->sampler = sampler;
587  req_handle->callback = cb;
588  req_handle->cls = cls;
590  sampler->req_handle_tail,
591  req_handle);
592 
594  "Scheduling requests for %" PRIu32 " peers\n", num_peers);
595 
596  for (i = 0; i < num_peers; i++)
597  {
598  gpc = GNUNET_new(struct GetPeerCls);
599  gpc->req_handle = req_handle;
600  gpc->req_single_info_handle = NULL;
601  gpc->cont = check_n_peers_ready;
602  gpc->cont_cls = req_handle;
603  gpc->id = &req_handle->ids[i];
604 
606  req_handle->gpc_tail,
607  gpc);
608  // maybe add a little delay
610  gpc);
611  }
612  return req_handle;
613 }
#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.
uint32_t num_peers
Number of peers we are waiting for.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void * cls
Closure given to the callback.
RPS_sampler_n_rand_peers_ready_cb callback
Callback to be called when all ids are available.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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.
Closure to _get_n_rand_peers_ready_cb()
static struct GNUNET_RPS_Request_Handle * req_handle
Request handle.
Definition: gnunet-rps.c:41
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:1264
#define LOG(kind,...)
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
struct GetPeerCls * gpc_head
Head and tail for the DLL to store the tasks for single requests.
struct GNUNET_PeerIdentity * ids
Pointer to the array holding the ids.
static unsigned int num_peers
uint32_t cur_num_peers
Number of peers we currently have.
struct RPS_SamplerRequestHandleSingleInfo * req_single_info_handle
The RPS_SamplerRequestHandleSingleInfo this single request belongs to.
void * cont_cls
The closure to the callback cont.
The identity of the host (wraps the signing key of the peer).
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.
RPS_get_peers_type get_peers
Stores the function to return peers.
struct RPS_SamplerRequestHandle * req_handle_tail
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.
struct RPS_Sampler * sampler
Sampler.
Here is the caller graph for this function:

◆ RPS_sampler_request_cancel()

void RPS_sampler_request_cancel ( struct RPS_SamplerRequestHandle req_handle)

Cancle a request issued through RPS_sampler_n_rand_peers_ready_cb.

Parameters
req_handlethe handle to the request

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

Referenced by GNUNET_RPS_request_cancel().

667 {
668  struct GetPeerCls *i;
669 
670  while (NULL != (i = req_handle->gpc_head))
671  {
673  req_handle->gpc_tail,
674  i);
675  if (NULL != i->get_peer_task)
676  {
678  }
679  if (NULL != i->notify_ctx)
680  {
682  req_handle->sampler->notify_ctx_tail,
683  i->notify_ctx);
685  i->notify_ctx = NULL;
686  }
687  GNUNET_free(i);
688  }
689  GNUNET_free(req_handle->ids);
690  req_handle->ids = NULL;
692  req_handle->sampler->req_handle_tail,
693  req_handle);
694  GNUNET_free(req_handle);
695 }
struct SamplerNotifyUpdateCTX * notify_ctx_tail
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct SamplerNotifyUpdateCTX * notify_ctx
Context to the given callback.
struct GetPeerCls * gpc_head
Head and tail for the DLL to store the tasks for single requests.
struct GNUNET_PeerIdentity * ids
Pointer to the array holding the 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.
struct SamplerNotifyUpdateCTX * notify_ctx_head
struct RPS_SamplerRequestHandle * req_handle_tail
struct GNUNET_SCHEDULER_Task * get_peer_task
The task for this function.
#define GNUNET_free(ptr)
Wrapper around free.
struct RPS_Sampler * sampler
Sampler.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 cound ids in.
idthe PeerID to count.
Returns
the number of occurrences of id.
Parameters
samplerthe sampler to count ids in.
idthe PeerID to count.
Returns
the number of occurrences of id.

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

Referenced by check_sending_channel_needed(), clean_peer(), and insert_in_sampler().

346 {
347  uint32_t count;
348  uint32_t i;
349 
350  count = 0;
351  for (i = 0; i < sampler->sampler_size; i++)
352  {
353  if (0 == GNUNET_memcmp(&sampler->sampler_elements[i]->peer_id, id)
354  && EMPTY != sampler->sampler_elements[i]->is_empty)
355  count++;
356  }
357  return count;
358 }
enum RPS_SamplerEmpty is_empty
Flag that indicates that we are not holding a valid PeerID right now.
struct GNUNET_PeerIdentity peer_id
The PeerID this sampler currently samples.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
unsigned int sampler_size
Number of sampler elements we hold.
struct RPS_SamplerElement ** sampler_elements
All sampler elements in one array.
Here is the caller graph for this function:

◆ RPS_sampler_destroy()

void RPS_sampler_destroy ( struct RPS_Sampler sampler)

Cleans the samplers.

Parameters
samplerthe sampler to destroy.

Cleans the samplers.

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

Referenced by destroy_sub(), GNUNET_RPS_request_cancel(), and GNUNET_RPS_request_single_info_cancel().

742 {
743  if (NULL != sampler->req_handle_head)
744  {
746  "There are still pending requests. Going to remove them.\n");
747  while (NULL != sampler->req_handle_head)
748  {
750  }
751  }
752  sampler_empty(sampler);
753  GNUNET_free(sampler);
754 }
void RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle)
Cancle a request issued through RPS_sampler_n_rand_peers_ready_cb.
#define LOG(kind,...)
static void sampler_empty(struct RPS_Sampler *sampler)
Empty the sampler.
struct RPS_SamplerRequestHandle * req_handle_head
Head and tail for the DLL to store the RPS_SamplerRequestHandle.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function: