GNUnet  0.10.x
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 
172  struct GNUNET_TIME_Relative max_round_interval;
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 
334  uint32_t num_peers,
336  void *cls);
337 
338 
349  void *cls);
350 
351 
360  uint32_t
362  const struct GNUNET_PeerIdentity *id);
363 
364 
370 void
372 
373 
379 void
382 
383 
387  void
389 
390 #endif /* RPS_SAMPLER_COMMON_H */
391 /* end of rps-sampler_common.h */
struct SamplerNotifyUpdateCTX * notify_ctx_tail
void RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler, double deficiency_factor)
Set the deficiency factor.
double desired_probability
The desired probability with which we want to have observed all peers.
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...
uint32_t num_peers_estim
The estimated total number of peers in the network.
RPS_sampler_rand_peer_ready_cont cont
The callback.
void RPS_sampler_update(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Update every sampler element of this sampler with given peer.
A sampler element sampling one PeerID at a time.
struct GetPeerCls * next
DLL.
Some utils faciliating the view into the internals for the sampler needed for evaluation.
void(* SamplerNotifyUpdateCB)(void *cls)
Callback called each time a new peer was put into the sampler.
sampler element implementation
struct RPS_SamplerRequestHandleSingleInfo * req_handle_single_head
Head and tail for the DLL to store the RPS_SamplerRequestHandleSingleInfo.
Context for a callback.
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
struct RPS_SamplerRequestHandle * req_handle
The RPS_SamplerRequestHandle this single request belongs to.
Closure to _get_n_rand_peers_ready_cb()
struct SamplerNotifyUpdateCTX * notify_ctx
Context to the given callback.
void RPS_sampler_request_single_info_cancel(struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle)
Cancle a request issued through RPS_sampler_n_rand_peers_ready_cb.
struct GetPeerCls * prev
struct RPS_Sampler * sampler
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.
static struct GNUNET_CONTAINER_MultiPeerMap * ids
GNUNET_PeerIdentity -> CadetPeer.
SamplerNotifyUpdateCB notify_cb
The Callback to call on updates.
void(* RPS_get_peers_type)(void *cls)
Type of function used to differentiate between modified and not modified Sampler. ...
Closure to _get_rand_peer_info()
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_resize(struct RPS_Sampler *sampler, unsigned int new_size)
Grow or shrink the size of the 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 RPS_sampler_destroy(struct RPS_Sampler *sampler)
Cleans the sampler.
void RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle)
Cancle a request issued through RPS_sampler_n_rand_peers_ready_cb.
static unsigned int num_peers
struct RPS_SamplerRequestHandleSingleInfo * req_handle_single_tail
struct RPS_SamplerRequestHandleSingleInfo * req_single_info_handle
The RPS_SamplerRequestHandleSingleInfo this single request belongs to.
unsigned int RPS_sampler_get_size(struct RPS_Sampler *sampler)
Get the size of the sampler.
void * cont_cls
The closure to the callback cont.
The identity of the host (wraps the signing key of the peer).
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.
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.
Entry in list of pending tasks.
Definition: scheduler.c:134
unsigned int sampler_size
Number of sampler elements we hold.
double deficiency_factor
A factor that catches the &#39;bias&#39; of a random stream of peer ids.
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_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Reinitialise all previously initialised sampler elements with the given value.
struct SamplerNotifyUpdateCTX * notify_ctx_head
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.
RPS_get_peers_type get_peers
Stores the function to return peers.
struct RPS_SamplerElement ** sampler_elements
All sampler elements in one array.
struct RPS_SamplerRequestHandle * req_handle_tail
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.
Time for relative time used by GNUnet, in microseconds.
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.
struct RPS_Sampler * sampler
Sampler.
uint32_t RPS_sampler_count_id(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Counts how many Samplers currently hold a given PeerID.