GNUnet  0.11.x
Data Structures | Macros | Typedefs | Functions | Variables
gnunet-service-rps_sampler.c File Reference

sampler implementation More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_statistics_service.h"
#include "rps.h"
#include "rps-sampler_common.h"
#include "gnunet-service-rps_sampler.h"
#include "gnunet-service-rps_sampler_elem.h"
#include <math.h>
#include <inttypes.h>
#include "rps-test_util.h"
Include dependency graph for gnunet-service-rps_sampler.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...
 

Macros

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

Typedefs

typedef void(* SamplerNotifyUpdateCB) (void *cls)
 Callback called each time a new peer was put into the sampler. More...
 
typedef void(* RPS_get_peers_type) (void *cls)
 Type of function used to differentiate between modified and not modified Sampler. More...
 

Functions

static void sampler_get_rand_peer (void *cls)
 Get one random peer out of the sampled peers. More...
 
struct RPS_SamplerRPS_sampler_init (size_t init_size, struct GNUNET_TIME_Relative max_round_interval)
 Initialise a tuple of sampler elements. More...
 

Variables

static size_t min_size
 Global sampler variable. More...
 
static size_t max_size
 The maximal size the extended sampler elements should grow to. More...
 
static uint32_t client_get_index
 The size the extended sampler elements currently have. More...
 

Detailed Description

sampler implementation

Author
Julius B√ľnger

Definition in file gnunet-service-rps_sampler.c.

Macro Definition Documentation

◆ LOG

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

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

Typedef Documentation

◆ SamplerNotifyUpdateCB

typedef void(* SamplerNotifyUpdateCB) (void *cls)

Callback called each time a new peer was put into the sampler.

Parameters
clsA possibly given closure

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

◆ RPS_get_peers_type

typedef void(* RPS_get_peers_type) (void *cls)

Type of function used to differentiate between modified and not modified Sampler.

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

Function Documentation

◆ sampler_get_rand_peer()

static void sampler_get_rand_peer ( void *  cls)
static

Get one random peer out of the sampled peers.

We might want to reinitialise this sampler after giving the corrsponding peer to the client. Only used internally

; Choose the r_index of the peer we want to return at random from the interval of the gossip list

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

References SamplerNotifyUpdateCTX::cls, GetPeerCls::cont, GetPeerCls::cont_cls, EMPTY, GetPeerCls::get_peer_task, GNUNET_CONTAINER_DLL_remove, GNUNET_CRYPTO_QUALITY_STRONG, GNUNET_CRYPTO_random_u64(), GNUNET_free, RPS_SamplerRequestHandle::gpc_head, RPS_SamplerRequestHandle::gpc_tail, GetPeerCls::id, RPS_SamplerElement::is_empty, GetPeerCls::notify_ctx, RPS_SamplerElement::num_peers, RPS_SamplerElement::peer_id, GetPeerCls::req_handle, RPS_SamplerRequestHandle::sampler, RPS_Sampler::sampler_elements, sampler_notify_on_update(), and RPS_Sampler::sampler_size.

Referenced by RPS_sampler_init().

229 {
230  struct GetPeerCls *gpc = cls;
231  uint32_t r_index;
232  struct RPS_Sampler *sampler;
233 
234  gpc->get_peer_task = NULL;
235  gpc->notify_ctx = NULL;
236  sampler = gpc->req_handle->sampler;
237 
243  sampler->sampler_size);
244 
245  if (EMPTY == sampler->sampler_elements[r_index]->is_empty)
246  {
247  // LOG (GNUNET_ERROR_TYPE_DEBUG,
248  // "Not returning randomly selected, empty PeerID. - Rescheduling.\n");
249 
250  gpc->notify_ctx =
251  sampler_notify_on_update (sampler,
253  gpc);
254  return;
255  }
256 
258  gpc->req_handle->gpc_tail,
259  gpc);
260  *gpc->id = sampler->sampler_elements[r_index]->peer_id;
261  gpc->cont (gpc->cont_cls, gpc->id, 0,
262  sampler->sampler_elements[r_index]->num_peers);
263 
264  GNUNET_free (gpc);
265 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
uint32_t num_peers
How many times a PeerID was put in this sampler.
RPS_sampler_rand_peer_ready_cont cont
The callback.
static void sampler_get_rand_peer(void *cls)
Get one random peer out of the sampled peers.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
struct RPS_SamplerRequestHandle * req_handle
The RPS_SamplerRequestHandle this single request belongs to.
struct SamplerNotifyUpdateCTX * notify_ctx
Context to the given callback.
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.
struct GetPeerCls * gpc_head
Head and tail for the DLL to store the tasks for single requests.
void * cont_cls
The closure to the callback cont.
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.
Closure for sampler_mod_get_rand_peer() and sampler_get_rand_peer.
unsigned int sampler_size
Number of sampler elements we hold.
struct RPS_SamplerElement ** sampler_elements
All sampler elements in one array.
Sampler with its own array of SamplerElements.
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_free(ptr)
Wrapper around free.
struct RPS_Sampler * sampler
Sampler.
High-quality operations are desired.
Here is the call graph for this function:
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 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 196 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().

198 {
199  struct RPS_Sampler *sampler;
200 
201  /* Initialise context around extended sampler */
202  min_size = 10; // TODO make input to _samplers_init()
203  max_size = 1000; // TODO make input to _samplers_init()
204 
205  sampler = GNUNET_new (struct RPS_Sampler);
206 
208  sampler->get_peers = sampler_get_rand_peer;
209  // sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity);
210  // GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size);
211  RPS_sampler_resize (sampler, init_size);
212 
213  client_get_index = 0;
214 
215  // GNUNET_assert (init_size == sampler->sampler_size);
216  return sampler;
217 }
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:

Variable Documentation

◆ min_size

size_t min_size
static

Global sampler variable.

The minimal size for the extended sampler elements.

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

◆ max_size

size_t max_size
static

The maximal size the extended sampler elements should grow to.

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

Referenced by buffer_init().

◆ client_get_index

uint32_t client_get_index
static

The size the extended sampler elements currently have.

Inedex to the sampler element that is the next to be returned

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