diff options
Diffstat (limited to 'src/rps/gnunet-service-rps_sampler.c')
-rw-r--r-- | src/rps/gnunet-service-rps_sampler.c | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index a3f778979..7573fd4eb 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/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'? |
@@ -68,7 +68,8 @@ 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 | { | ||
72 | /** | 73 | /** |
73 | * @brief The Callback to call on updates | 74 | * @brief The Callback to call on updates |
74 | */ | 75 | */ |
@@ -106,13 +107,14 @@ typedef void | |||
106 | * Only used internally | 107 | * Only used internally |
107 | */ | 108 | */ |
108 | static void | 109 | static void |
109 | sampler_get_rand_peer(void *cls); | 110 | sampler_get_rand_peer (void *cls); |
110 | 111 | ||
111 | 112 | ||
112 | /** | 113 | /** |
113 | * Closure to _get_n_rand_peers_ready_cb() | 114 | * Closure to _get_n_rand_peers_ready_cb() |
114 | */ | 115 | */ |
115 | struct RPS_SamplerRequestHandle { | 116 | struct RPS_SamplerRequestHandle |
117 | { | ||
116 | /** | 118 | /** |
117 | * DLL | 119 | * DLL |
118 | */ | 120 | */ |
@@ -159,7 +161,7 @@ struct RPS_SamplerRequestHandle { | |||
159 | ///** | 161 | ///** |
160 | // * Global sampler variable. | 162 | // * Global sampler variable. |
161 | // */ | 163 | // */ |
162 | //struct RPS_Sampler *sampler; | 164 | // struct RPS_Sampler *sampler; |
163 | 165 | ||
164 | 166 | ||
165 | /** | 167 | /** |
@@ -175,7 +177,7 @@ static size_t max_size; | |||
175 | /** | 177 | /** |
176 | * The size the extended sampler elements currently have. | 178 | * The size the extended sampler elements currently have. |
177 | */ | 179 | */ |
178 | //static size_t extra_size; | 180 | // static size_t extra_size; |
179 | 181 | ||
180 | /** | 182 | /** |
181 | * Inedex to the sampler element that is the next to be returned | 183 | * Inedex to the sampler element that is the next to be returned |
@@ -191,8 +193,8 @@ static uint32_t client_get_index; | |||
191 | * @return a handle to a sampler that consists of sampler elements. | 193 | * @return a handle to a sampler that consists of sampler elements. |
192 | */ | 194 | */ |
193 | struct RPS_Sampler * | 195 | struct RPS_Sampler * |
194 | RPS_sampler_init(size_t init_size, | 196 | RPS_sampler_init (size_t init_size, |
195 | struct GNUNET_TIME_Relative max_round_interval) | 197 | struct GNUNET_TIME_Relative max_round_interval) |
196 | { | 198 | { |
197 | struct RPS_Sampler *sampler; | 199 | struct RPS_Sampler *sampler; |
198 | 200 | ||
@@ -200,17 +202,17 @@ RPS_sampler_init(size_t init_size, | |||
200 | min_size = 10; // TODO make input to _samplers_init() | 202 | min_size = 10; // TODO make input to _samplers_init() |
201 | max_size = 1000; // TODO make input to _samplers_init() | 203 | max_size = 1000; // TODO make input to _samplers_init() |
202 | 204 | ||
203 | sampler = GNUNET_new(struct RPS_Sampler); | 205 | sampler = GNUNET_new (struct RPS_Sampler); |
204 | 206 | ||
205 | sampler->max_round_interval = max_round_interval; | 207 | sampler->max_round_interval = max_round_interval; |
206 | sampler->get_peers = sampler_get_rand_peer; | 208 | sampler->get_peers = sampler_get_rand_peer; |
207 | //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); | 209 | // sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); |
208 | //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size); | 210 | // GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size); |
209 | RPS_sampler_resize(sampler, init_size); | 211 | RPS_sampler_resize (sampler, init_size); |
210 | 212 | ||
211 | client_get_index = 0; | 213 | client_get_index = 0; |
212 | 214 | ||
213 | //GNUNET_assert (init_size == sampler->sampler_size); | 215 | // GNUNET_assert (init_size == sampler->sampler_size); |
214 | return sampler; | 216 | return sampler; |
215 | } | 217 | } |
216 | 218 | ||
@@ -222,7 +224,7 @@ RPS_sampler_init(size_t init_size, | |||
222 | * Only used internally | 224 | * Only used internally |
223 | */ | 225 | */ |
224 | static void | 226 | static void |
225 | sampler_get_rand_peer(void *cls) | 227 | sampler_get_rand_peer (void *cls) |
226 | { | 228 | { |
227 | struct GetPeerCls *gpc = cls; | 229 | struct GetPeerCls *gpc = cls; |
228 | uint32_t r_index; | 230 | uint32_t r_index; |
@@ -236,28 +238,29 @@ sampler_get_rand_peer(void *cls) | |||
236 | * Choose the r_index of the peer we want to return | 238 | * Choose the r_index of the peer we want to return |
237 | * at random from the interval of the gossip list | 239 | * at random from the interval of the gossip list |
238 | */ | 240 | */ |
239 | r_index = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, | 241 | r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, |
240 | sampler->sampler_size); | 242 | sampler->sampler_size); |
241 | 243 | ||
242 | if (EMPTY == sampler->sampler_elements[r_index]->is_empty) | 244 | if (EMPTY == sampler->sampler_elements[r_index]->is_empty) |
243 | { | 245 | { |
244 | //LOG (GNUNET_ERROR_TYPE_DEBUG, | 246 | // LOG (GNUNET_ERROR_TYPE_DEBUG, |
245 | // "Not returning randomly selected, empty PeerID. - Rescheduling.\n"); | 247 | // "Not returning randomly selected, empty PeerID. - Rescheduling.\n"); |
246 | 248 | ||
247 | gpc->notify_ctx = | 249 | gpc->notify_ctx = |
248 | sampler_notify_on_update(sampler, | 250 | sampler_notify_on_update (sampler, |
249 | &sampler_get_rand_peer, | 251 | &sampler_get_rand_peer, |
250 | gpc); | 252 | gpc); |
251 | return; | 253 | return; |
252 | } | 254 | } |
253 | 255 | ||
254 | GNUNET_CONTAINER_DLL_remove(gpc->req_handle->gpc_head, | 256 | GNUNET_CONTAINER_DLL_remove (gpc->req_handle->gpc_head, |
255 | gpc->req_handle->gpc_tail, | 257 | gpc->req_handle->gpc_tail, |
256 | gpc); | 258 | gpc); |
257 | *gpc->id = sampler->sampler_elements[r_index]->peer_id; | 259 | *gpc->id = sampler->sampler_elements[r_index]->peer_id; |
258 | gpc->cont(gpc->cont_cls, gpc->id, 0, sampler->sampler_elements[r_index]->num_peers); | 260 | gpc->cont (gpc->cont_cls, gpc->id, 0, |
261 | sampler->sampler_elements[r_index]->num_peers); | ||
259 | 262 | ||
260 | GNUNET_free(gpc); | 263 | GNUNET_free (gpc); |
261 | } | 264 | } |
262 | 265 | ||
263 | 266 | ||