aboutsummaryrefslogtreecommitdiff
path: root/src/rps/gnunet-service-rps_sampler.h
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-01-06 23:48:24 +0000
committerJulius Bünger <buenger@mytum.de>2015-01-06 23:48:24 +0000
commit23660470add3cd0de11e3e599f14ec59f80ef5c3 (patch)
tree7e4998968317db71913e05d6508194843b48584a /src/rps/gnunet-service-rps_sampler.h
parent933428cef51a444d9fcba0ef2a36c626cb337fa5 (diff)
downloadgnunet-23660470add3cd0de11e3e599f14ec59f80ef5c3.tar.gz
gnunet-23660470add3cd0de11e3e599f14ec59f80ef5c3.zip
moved sampler functionality in file of its own
Diffstat (limited to 'src/rps/gnunet-service-rps_sampler.h')
-rw-r--r--src/rps/gnunet-service-rps_sampler.h147
1 files changed, 147 insertions, 0 deletions
diff --git a/src/rps/gnunet-service-rps_sampler.h b/src/rps/gnunet-service-rps_sampler.h
new file mode 100644
index 000000000..3772f9f0b
--- /dev/null
+++ b/src/rps/gnunet-service-rps_sampler.h
@@ -0,0 +1,147 @@
1/*
2 This file is part of GNUnet.
3 (C)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file rps/gnunet-service-rps_sampler.h
23 * @brief sampler implementation
24 * @author Julius Bünger
25 */
26
27#ifndef RPS_SAMPLER_H
28#define RPS_SAMPLER_H
29#include <inttypes.h>
30
31/**
32 * Callback that is called when a new PeerID is inserted into a sampler.
33 *
34 * @param cls the closure given alongside this function.
35 * @param id the PeerID that is inserted
36 */
37typedef void
38(*RPS_sampler_insert_cb) (void *cls,
39 const struct GNUNET_PeerIdentity *id);
40
41/**
42 * Callback that is called when a new PeerID is removed from a sampler.
43 *
44 * @param cls the closure given alongside this function.
45 * @param id the PeerID that is removed
46 */
47typedef void
48(*RPS_sampler_remove_cb) (void *cls,
49 const struct GNUNET_PeerIdentity *id);
50
51/**
52 * A sampler sampling a stream of PeerIDs.
53 */
54//struct RPS_Sampler;
55
56
57/**
58 * Grow or shrink the size of the sampler.
59 *
60 * @param new_size the new size of the sampler
61 */
62 void
63RPS_sampler_resize (unsigned int new_size);
64
65
66/**
67 * Initialise a tuple of samplers.
68 *
69 * @param init_size the size the sampler is initialised with
70 * @param id with which all newly created sampler elements are initialised
71 * @param ins_cb the callback that will be called on every PeerID that is
72 * newly inserted into a sampler element
73 * @param ins_cls the closure given to #ins_cb
74 * @param rem_cb the callback that will be called on every PeerID that is
75 * removed from a sampler element
76 * @param rem_cls the closure given to #rem_cb
77 */
78 void
79RPS_sampler_init (size_t init_size, const struct GNUNET_PeerIdentity *id,
80 RPS_sampler_insert_cb ins_cb, void *ins_cls,
81 RPS_sampler_remove_cb rem_cb, void *rem_cls);
82
83
84/**
85 * A fuction to update every sampler in the given list
86 *
87 * @param id the PeerID that is put in the sampler
88 */
89 void
90RPS_sampler_update_list (const struct GNUNET_PeerIdentity *id);
91
92
93/**
94 * Reinitialise all previously initialised sampler elements with the given value.
95 *
96 * Used to get rid of a PeerID.
97 *
98 * @param id the id of the samplers to update.
99 */
100 void
101RPS_sampler_reinitialise_by_value (const struct GNUNET_PeerIdentity *id);
102
103
104/**
105 * Get one random peer out of the sampled peers.
106 *
107 * We might want to reinitialise this sampler after giving the
108 * corrsponding peer to the client.
109 *
110 * @return a random PeerID of the PeerIDs previously put into the sampler.
111 */
112 const struct GNUNET_PeerIdentity *
113RPS_sampler_get_rand_peer ();
114
115
116/**
117 * Get n random peers out of the sampled peers.
118 *
119 * We might want to reinitialise this sampler after giving the
120 * corrsponding peer to the client.
121 * Random with or without consumption?
122 *
123 * @return n random PeerIDs of the PeerIDs previously put into the sampler.
124 */
125 const struct GNUNET_PeerIdentity *
126RPS_sampler_get_n_rand_peers (uint64_t n);
127
128
129/**
130 * Counts how many Samplers currently hold a given PeerID.
131 *
132 * @param id the PeerID to count.
133 *
134 * @return the number of occurrences of id.
135 */
136 uint64_t
137RPS_sampler_count_id (const struct GNUNET_PeerIdentity *id);
138
139
140/**
141 * Cleans the samplers.
142 */
143 void
144RPS_sampler_destroy ();
145
146#endif
147/* end of gnunet-service-rps.c */