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 
106 struct GetPeerCls {
110  struct GetPeerCls *next;
111  struct GetPeerCls *prev;
112 
117 
122 
127 
132 
137 
141  void *cont_cls;
142 
147 };
148 
149 
153 struct RPS_Sampler {
157  unsigned int sampler_size;
158  //size_t size;
159 
164 
170  struct GNUNET_TIME_Relative max_round_interval;
171 
175  uint32_t num_peers_estim;
176 
182 
190 
196 
202 
208 
211 };
212 
213 
222 void
224  uint32_t num_peers);
225 
226 
237 void
239  double desired_probability);
240 
241 
251 void
253  double deficiency_factor);
254 
255 
266 struct SamplerNotifyUpdateCTX *
267 sampler_notify_on_update(struct RPS_Sampler *sampler,
269  void *cls);
270 
271 
278 void
279 RPS_sampler_update(struct RPS_Sampler *sampler,
280  const struct GNUNET_PeerIdentity *id);
281 
282 
291 void
293  const struct GNUNET_PeerIdentity *id);
294 
295 
302 unsigned int
303 RPS_sampler_get_size(struct RPS_Sampler *sampler);
304 
305 
312 void
313 RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size);
314 
315 
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
380 
381 
385 void
387 
388 #endif /* RPS_SAMPLER_COMMON_H */
389 /* 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:131
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.