GNUnet 0.21.1
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
 ‍** 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 63 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 99 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.

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 =
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}
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)
Generate a random unsigned 64-bit value.
@ GNUNET_CRYPTO_QUALITY_STRONG
High-quality operations are desired.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.
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.
struct SamplerNotifyUpdateCTX * notify_ctx
Context to the given callback.
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.
uint32_t num_peers
How many times a PeerID was put in this sampler.
struct GNUNET_PeerIdentity peer_id
The PeerID this sampler currently samples.
enum RPS_SamplerEmpty is_empty
Flag that indicates that we are not holding a valid PeerID right now.
struct RPS_Sampler * sampler
Sampler.
struct GetPeerCls * gpc_head
Head and tail for the DLL to store the tasks for single requests.
Sampler with its own array of SamplerElements.
struct RPS_SamplerElement ** sampler_elements
All sampler elements in one array.
unsigned int sampler_size
Number of sampler elements we hold.

References 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_get_rand_peer(), sampler_notify_on_update(), and RPS_Sampler::sampler_size.

Referenced by RPS_sampler_init(), and sampler_get_rand_peer().

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.

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
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
214
215 // GNUNET_assert (init_size == sampler->sampler_size);
216 return sampler;
217}
static uint32_t client_get_index
The size the extended sampler elements currently have.
static size_t max_size
The maximal size the extended sampler elements should grow to.
static size_t min_size
‍**
void RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size)
Grow or shrink the size of the sampler.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
RPS_get_peers_type get_peers
Stores the function to return peers.
struct GNUNET_TIME_Relative max_round_interval
Maximum time a round takes.

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

Referenced by new_sub().

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

‍**

The minimal size for the extended sampler elements.

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

Referenced by RPS_sampler_init().

◆ 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_append(), buffer_init(), and RPS_sampler_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.

Referenced by RPS_sampler_init().