diff options
Diffstat (limited to 'src/rps/gnunet-service-rps_sampler.c')
-rw-r--r-- | src/rps/gnunet-service-rps_sampler.c | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index e17b154ca..a3f778979 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/gnunet-service-rps_sampler.c | 22 | * @file rps/gnunet-service-rps_sampler.c |
@@ -37,7 +37,7 @@ | |||
37 | 37 | ||
38 | #include "rps-test_util.h" | 38 | #include "rps-test_util.h" |
39 | 39 | ||
40 | #define LOG(kind, ...) GNUNET_log_from(kind,"rps-sampler",__VA_ARGS__) | 40 | #define LOG(kind, ...) GNUNET_log_from(kind, "rps-sampler", __VA_ARGS__) |
41 | 41 | ||
42 | 42 | ||
43 | // multiple 'clients'? | 43 | // multiple 'clients'? |
@@ -49,8 +49,8 @@ | |||
49 | // hist_size_init, hist_size_max | 49 | // hist_size_init, hist_size_max |
50 | 50 | ||
51 | /*********************************************************************** | 51 | /*********************************************************************** |
52 | * WARNING: This section needs to be reviewed regarding the use of | 52 | * WARNING: This section needs to be reviewed regarding the use of |
53 | * functions providing (pseudo)randomness! | 53 | * functions providing (pseudo)randomness! |
54 | ***********************************************************************/ | 54 | ***********************************************************************/ |
55 | 55 | ||
56 | // TODO care about invalid input of the caller (size 0 or less...) | 56 | // TODO care about invalid input of the caller (size 0 or less...) |
@@ -68,8 +68,7 @@ typedef void | |||
68 | * | 68 | * |
69 | * Meant to be an entry in an DLL. | 69 | * Meant to be an entry in an DLL. |
70 | */ | 70 | */ |
71 | struct SamplerNotifyUpdateCTX | 71 | struct SamplerNotifyUpdateCTX { |
72 | { | ||
73 | /** | 72 | /** |
74 | * @brief The Callback to call on updates | 73 | * @brief The Callback to call on updates |
75 | */ | 74 | */ |
@@ -107,14 +106,13 @@ typedef void | |||
107 | * Only used internally | 106 | * Only used internally |
108 | */ | 107 | */ |
109 | static void | 108 | static void |
110 | sampler_get_rand_peer (void *cls); | 109 | sampler_get_rand_peer(void *cls); |
111 | 110 | ||
112 | 111 | ||
113 | /** | 112 | /** |
114 | * Closure to _get_n_rand_peers_ready_cb() | 113 | * Closure to _get_n_rand_peers_ready_cb() |
115 | */ | 114 | */ |
116 | struct RPS_SamplerRequestHandle | 115 | struct RPS_SamplerRequestHandle { |
117 | { | ||
118 | /** | 116 | /** |
119 | * DLL | 117 | * DLL |
120 | */ | 118 | */ |
@@ -193,8 +191,8 @@ static uint32_t client_get_index; | |||
193 | * @return a handle to a sampler that consists of sampler elements. | 191 | * @return a handle to a sampler that consists of sampler elements. |
194 | */ | 192 | */ |
195 | struct RPS_Sampler * | 193 | struct RPS_Sampler * |
196 | RPS_sampler_init (size_t init_size, | 194 | RPS_sampler_init(size_t init_size, |
197 | struct GNUNET_TIME_Relative max_round_interval) | 195 | struct GNUNET_TIME_Relative max_round_interval) |
198 | { | 196 | { |
199 | struct RPS_Sampler *sampler; | 197 | struct RPS_Sampler *sampler; |
200 | 198 | ||
@@ -202,13 +200,13 @@ RPS_sampler_init (size_t init_size, | |||
202 | min_size = 10; // TODO make input to _samplers_init() | 200 | min_size = 10; // TODO make input to _samplers_init() |
203 | max_size = 1000; // TODO make input to _samplers_init() | 201 | max_size = 1000; // TODO make input to _samplers_init() |
204 | 202 | ||
205 | sampler = GNUNET_new (struct RPS_Sampler); | 203 | sampler = GNUNET_new(struct RPS_Sampler); |
206 | 204 | ||
207 | sampler->max_round_interval = max_round_interval; | 205 | sampler->max_round_interval = max_round_interval; |
208 | sampler->get_peers = sampler_get_rand_peer; | 206 | sampler->get_peers = sampler_get_rand_peer; |
209 | //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); | 207 | //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); |
210 | //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size); | 208 | //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size); |
211 | RPS_sampler_resize (sampler, init_size); | 209 | RPS_sampler_resize(sampler, init_size); |
212 | 210 | ||
213 | client_get_index = 0; | 211 | client_get_index = 0; |
214 | 212 | ||
@@ -224,7 +222,7 @@ RPS_sampler_init (size_t init_size, | |||
224 | * Only used internally | 222 | * Only used internally |
225 | */ | 223 | */ |
226 | static void | 224 | static void |
227 | sampler_get_rand_peer (void *cls) | 225 | sampler_get_rand_peer(void *cls) |
228 | { | 226 | { |
229 | struct GetPeerCls *gpc = cls; | 227 | struct GetPeerCls *gpc = cls; |
230 | uint32_t r_index; | 228 | uint32_t r_index; |
@@ -238,28 +236,28 @@ sampler_get_rand_peer (void *cls) | |||
238 | * Choose the r_index of the peer we want to return | 236 | * Choose the r_index of the peer we want to return |
239 | * at random from the interval of the gossip list | 237 | * at random from the interval of the gossip list |
240 | */ | 238 | */ |
241 | r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, | 239 | r_index = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, |
242 | sampler->sampler_size); | 240 | sampler->sampler_size); |
243 | 241 | ||
244 | if (EMPTY == sampler->sampler_elements[r_index]->is_empty) | 242 | if (EMPTY == sampler->sampler_elements[r_index]->is_empty) |
245 | { | 243 | { |
246 | //LOG (GNUNET_ERROR_TYPE_DEBUG, | 244 | //LOG (GNUNET_ERROR_TYPE_DEBUG, |
247 | // "Not returning randomly selected, empty PeerID. - Rescheduling.\n"); | 245 | // "Not returning randomly selected, empty PeerID. - Rescheduling.\n"); |
248 | 246 | ||
249 | gpc->notify_ctx = | 247 | gpc->notify_ctx = |
250 | sampler_notify_on_update (sampler, | 248 | sampler_notify_on_update(sampler, |
251 | &sampler_get_rand_peer, | 249 | &sampler_get_rand_peer, |
252 | gpc); | 250 | gpc); |
253 | return; | 251 | return; |
254 | } | 252 | } |
255 | 253 | ||
256 | GNUNET_CONTAINER_DLL_remove (gpc->req_handle->gpc_head, | 254 | GNUNET_CONTAINER_DLL_remove(gpc->req_handle->gpc_head, |
257 | gpc->req_handle->gpc_tail, | 255 | gpc->req_handle->gpc_tail, |
258 | gpc); | 256 | gpc); |
259 | *gpc->id = sampler->sampler_elements[r_index]->peer_id; | 257 | *gpc->id = sampler->sampler_elements[r_index]->peer_id; |
260 | gpc->cont (gpc->cont_cls, gpc->id, 0, sampler->sampler_elements[r_index]->num_peers); | 258 | gpc->cont(gpc->cont_cls, gpc->id, 0, sampler->sampler_elements[r_index]->num_peers); |
261 | 259 | ||
262 | GNUNET_free (gpc); | 260 | GNUNET_free(gpc); |
263 | } | 261 | } |
264 | 262 | ||
265 | 263 | ||