diff options
author | Julius Bünger <buenger@mytum.de> | 2018-10-11 14:09:36 +0200 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2018-10-11 14:40:43 +0200 |
commit | 0cdd1af62ca1f17fdca31be6e28ad24dcf3293b1 (patch) | |
tree | 76954d1d321bc8d7a6b00690652fa248f63eebd9 /src/rps/rps_api.c | |
parent | 91f7da525a15dfc2511c79cc7781d7f5a61b9b23 (diff) | |
download | gnunet-0cdd1af62ca1f17fdca31be6e28ad24dcf3293b1.tar.gz gnunet-0cdd1af62ca1f17fdca31be6e28ad24dcf3293b1.zip |
RPS api: Clean code and logging
Diffstat (limited to 'src/rps/rps_api.c')
-rw-r--r-- | src/rps/rps_api.c | 64 |
1 files changed, 21 insertions, 43 deletions
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c index 7d0674aff..47c4f019d 100644 --- a/src/rps/rps_api.c +++ b/src/rps/rps_api.c | |||
@@ -267,6 +267,9 @@ collect_peers_cb (void *cls, | |||
267 | { | 267 | { |
268 | struct GNUNET_RPS_Request_Handle *rh = cls; | 268 | struct GNUNET_RPS_Request_Handle *rh = cls; |
269 | 269 | ||
270 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
271 | "Service sent %" PRIu64 " peers from stream\n", | ||
272 | num_peers); | ||
270 | for (uint64_t i = 0; i < num_peers; i++) | 273 | for (uint64_t i = 0; i < num_peers; i++) |
271 | { | 274 | { |
272 | RPS_sampler_update (rh->sampler, &peers[i]); | 275 | RPS_sampler_update (rh->sampler, &peers[i]); |
@@ -274,44 +277,6 @@ collect_peers_cb (void *cls, | |||
274 | } | 277 | } |
275 | 278 | ||
276 | 279 | ||
277 | /** | ||
278 | * @brief Create new request handle | ||
279 | * | ||
280 | * @param rps_handle Handle to the service | ||
281 | * @param num_requests Number of requests | ||
282 | * @param ready_cb Callback | ||
283 | * @param cls Closure | ||
284 | * | ||
285 | * @return The newly created request handle | ||
286 | */ | ||
287 | static struct GNUNET_RPS_Request_Handle * | ||
288 | new_request_handle (struct GNUNET_RPS_Handle *rps_handle, | ||
289 | uint64_t num_requests, | ||
290 | GNUNET_RPS_NotifyReadyCB ready_cb, | ||
291 | void *cls) | ||
292 | { | ||
293 | struct GNUNET_RPS_Request_Handle *rh; | ||
294 | |||
295 | rh = GNUNET_new (struct GNUNET_RPS_Request_Handle); | ||
296 | rh->rps_handle = rps_handle; | ||
297 | rh->num_requests = num_requests; | ||
298 | rh->sampler = RPS_sampler_mod_init (num_requests, | ||
299 | GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff | ||
300 | rh->sampler_rh = RPS_sampler_get_n_rand_peers (rh->sampler, | ||
301 | num_requests, | ||
302 | peers_ready_cb, | ||
303 | rh); | ||
304 | rh->srh = GNUNET_RPS_stream_request (rps_handle, | ||
305 | 0, /* infinite updates */ | ||
306 | collect_peers_cb, | ||
307 | rh); /* cls */ | ||
308 | rh->ready_cb = ready_cb; | ||
309 | rh->ready_cb_cls = cls; | ||
310 | |||
311 | return rh; | ||
312 | } | ||
313 | |||
314 | |||
315 | /* Get internals for debugging/profiling purposes */ | 280 | /* Get internals for debugging/profiling purposes */ |
316 | 281 | ||
317 | /** | 282 | /** |
@@ -690,11 +655,24 @@ GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle, | |||
690 | { | 655 | { |
691 | struct GNUNET_RPS_Request_Handle *rh; | 656 | struct GNUNET_RPS_Request_Handle *rh; |
692 | 657 | ||
693 | rh = new_request_handle (rps_handle, | 658 | LOG (GNUNET_ERROR_TYPE_INFO, |
694 | num_req_peers, | 659 | "Client requested %" PRIu32 " peers\n", |
695 | ready_cb, | 660 | num_req_peers); |
696 | cls); | 661 | rh = GNUNET_new (struct GNUNET_RPS_Request_Handle); |
697 | 662 | rh->rps_handle = rps_handle; | |
663 | rh->num_requests = num_req_peers; | ||
664 | rh->sampler = RPS_sampler_mod_init (num_req_peers, | ||
665 | GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff | ||
666 | rh->sampler_rh = RPS_sampler_get_n_rand_peers (rh->sampler, | ||
667 | num_req_peers, | ||
668 | peers_ready_cb, | ||
669 | rh); | ||
670 | rh->srh = GNUNET_RPS_stream_request (rps_handle, | ||
671 | 0, /* infinite updates */ | ||
672 | collect_peers_cb, | ||
673 | rh); /* cls */ | ||
674 | rh->ready_cb = ready_cb; | ||
675 | rh->ready_cb_cls = cls; | ||
698 | 676 | ||
699 | return rh; | 677 | return rh; |
700 | } | 678 | } |