GNUnet  0.20.0
rps-sampler_common.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C)
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
27 #ifndef RPS_SAMPLER_COMMON_H
28 #define RPS_SAMPLER_COMMON_H
29 
30 #include "platform.h"
31 #include "gnunet_util_lib.h"
33 
35 
36 #include <math.h>
37 #include <inttypes.h>
38 
39 #include "rps-test_util.h"
40 
41 
50 typedef void
52  const struct GNUNET_PeerIdentity *id,
53  double probability,
54  uint32_t num_observed);
55 
56 
61 typedef void
62 (*RPS_get_peers_type) (void *cls);
63 
64 
72 typedef void
74  uint32_t num_peers,
75  void *cls);
76 
77 
87 typedef void
89  void *cls,
90  double probability,
91  uint32_t num_observed);
92 
93 
99 typedef void
100 (*SamplerNotifyUpdateCB) (void *cls);
101 
102 
107 {
111  struct GetPeerCls *next;
112  struct GetPeerCls *prev;
113 
118 
123 
128 
133 
138 
142  void *cont_cls;
143 
148 };
149 
150 
155 {
159  unsigned int sampler_size;
160  // size_t size;
161 
166 
173 
177  uint32_t num_peers_estim;
178 
184 
192 
198 
204 
210 
213 };
214 
215 
224 void
226  uint32_t num_peers);
227 
228 
239 void
241  double desired_probability);
242 
243 
253 void
255  double deficiency_factor);
256 
257 
268 struct SamplerNotifyUpdateCTX *
269 sampler_notify_on_update (struct RPS_Sampler *sampler,
271  void *cls);
272 
273 
280 void
281 RPS_sampler_update (struct RPS_Sampler *sampler,
282  const struct GNUNET_PeerIdentity *id);
283 
284 
293 void
295  const struct GNUNET_PeerIdentity *id);
296 
297 
304 unsigned int
305 RPS_sampler_get_size (struct RPS_Sampler *sampler);
306 
307 
314 void
315 RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size);
316 
317 
332  uint32_t num_peers,
334  void *cls);
335 
336 
347  void *cls);
348 
349 
358 uint32_t
360  const struct GNUNET_PeerIdentity *id);
361 
362 
368 void
370 
371 
377 void
379  struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle);
380 
381 
385 void
387 
388 #endif /* RPS_SAMPLER_COMMON_H */
389 /* end of rps-sampler_common.h */
static struct GNUNET_CONTAINER_MultiPeerMap * ids
GNUNET_PeerIdentity -> CadetPeer.
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 (...
static unsigned int num_peers
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
static struct GNUNET_RPS_Request_Handle * req_handle
Request handle.
Definition: gnunet-rps.c:41
sampler element implementation
API to create, modify and access statistics.
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.
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.
void(* RPS_sampler_rand_peer_ready_cont)(void *cls, const struct GNUNET_PeerIdentity *id, double probability, uint32_t num_observed)
Callback that is called from _get_rand_peer() when the PeerID is ready.
void RPS_sampler_update(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Update every sampler element of this sampler with given peer.
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.
void(* RPS_get_peers_type)(void *cls)
Type of function used to differentiate between modified and not modified Sampler.
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(* SamplerNotifyUpdateCB)(void *cls)
Callback called each time a new peer was put into the sampler.
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.
void RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size)
Grow or shrink the size of the sampler.
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.
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_destroy(struct RPS_Sampler *sampler)
Cleans the sampler.
unsigned int RPS_sampler_get_size(struct RPS_Sampler *sampler)
Get the size of the sampler.
void RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler, double deficiency_factor)
Set the deficiency factor.
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.
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 RPS_sampler_request_single_info_cancel(struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle)
Cancel a request issued through RPS_sampler_n_rand_peers_ready_cb.
uint32_t RPS_sampler_count_id(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Counts how many Samplers currently hold a given PeerID.
Some utils facilitating the view into the internals for the sampler needed for evaluation.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition: scheduler.c:136
Time for relative time used by GNUnet, in microseconds.
Closure for sampler_mod_get_rand_peer() and sampler_get_rand_peer.
struct GetPeerCls * next
DLL.
struct RPS_SamplerRequestHandleSingleInfo * req_single_info_handle
The RPS_SamplerRequestHandleSingleInfo this single request belongs to.
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.
struct GetPeerCls * prev
A sampler element sampling one PeerID at a time.
Closure to _get_rand_peer_info()
void * cls
Closure given to the callback.
struct RPS_Sampler * sampler
Sampler.
Closure to _get_n_rand_peers_ready_cb()
struct RPS_Sampler * sampler
Sampler.
void * cls
Closure given to the callback.
Sampler with its own array of SamplerElements.
struct RPS_SamplerRequestHandle * req_handle_head
Head and tail for the DLL to store the RPS_SamplerRequestHandle.
struct RPS_SamplerRequestHandleSingleInfo * req_handle_single_tail
struct SamplerNotifyUpdateCTX * notify_ctx_head
RPS_get_peers_type get_peers
Stores the function to return peers.
struct RPS_SamplerElement ** sampler_elements
All sampler elements in one array.
struct GNUNET_TIME_Relative max_round_interval
Maximum time a round takes.
double deficiency_factor
A factor that catches the 'bias' of a random stream of peer ids.
struct RPS_SamplerRequestHandleSingleInfo * req_handle_single_head
Head and tail for the DLL to store the RPS_SamplerRequestHandleSingleInfo.
struct RPS_SamplerRequestHandle * req_handle_tail
uint32_t num_peers_estim
The estimated total number of peers in the network.
struct SamplerNotifyUpdateCTX * notify_ctx_tail
double desired_probability
The desired probability with which we want to have observed all peers.
unsigned int sampler_size
Number of sampler elements we hold.
void * cls
The according closure.