diff options
author | Julius Bünger <buenger@mytum.de> | 2018-03-05 18:25:39 +0100 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2018-03-05 18:34:35 +0100 |
commit | 132597e5050e591617cd4e303015608ff503d879 (patch) | |
tree | f8cebacaf2915bdcf812a89608ec90d540cca170 /src/rps/rps_api.c | |
parent | d036b626b8eea15f99d91faf309843936289fde7 (diff) | |
download | gnunet-132597e5050e591617cd4e303015608ff503d879.tar.gz gnunet-132597e5050e591617cd4e303015608ff503d879.zip |
rps: add debug function to api to get view of service
Diffstat (limited to 'src/rps/rps_api.c')
-rw-r--r-- | src/rps/rps_api.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c index ccd480086..62ba9e226 100644 --- a/src/rps/rps_api.c +++ b/src/rps/rps_api.c | |||
@@ -56,6 +56,16 @@ struct GNUNET_RPS_Handle | |||
56 | * The id of the last request. | 56 | * The id of the last request. |
57 | */ | 57 | */ |
58 | uint32_t current_request_id; | 58 | uint32_t current_request_id; |
59 | |||
60 | /** | ||
61 | * @brief Callback called on each update of the view | ||
62 | */ | ||
63 | GNUNET_RPS_ViewUpdateCB view_update_cb; | ||
64 | |||
65 | /** | ||
66 | * @brief Callback called on each update of the view | ||
67 | */ | ||
68 | void *view_update_cls; | ||
59 | }; | 69 | }; |
60 | 70 | ||
61 | 71 | ||
@@ -236,6 +246,86 @@ handle_reply (void *cls, | |||
236 | } | 246 | } |
237 | 247 | ||
238 | 248 | ||
249 | /* Get internals for debugging/profiling purposes */ | ||
250 | |||
251 | /** | ||
252 | * Request updates of view | ||
253 | * | ||
254 | * @param rps_handle handle to the rps service | ||
255 | * @param num_req_peers number of peers we want to receive | ||
256 | * (0 for infinite updates) | ||
257 | * @param cls a closure that will be given to the callback | ||
258 | * @param ready_cb the callback called when the peers are available | ||
259 | */ | ||
260 | void | ||
261 | GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle, | ||
262 | uint32_t num_updates, | ||
263 | GNUNET_RPS_ViewUpdateCB view_update_cb, | ||
264 | void *cls) | ||
265 | { | ||
266 | struct GNUNET_MQ_Envelope *ev; | ||
267 | struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg; | ||
268 | |||
269 | rps_handle->view_update_cb = view_update_cb; | ||
270 | rps_handle->view_update_cls = cls; | ||
271 | |||
272 | ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST); | ||
273 | msg->num_updates = htonl (num_updates); | ||
274 | GNUNET_MQ_send (rps_handle->mq, ev); | ||
275 | } | ||
276 | |||
277 | /** | ||
278 | * This function is called, when the service updates the view. | ||
279 | * It verifies that @a msg is well-formed. | ||
280 | * | ||
281 | * @param cls the closure | ||
282 | * @param msg the message | ||
283 | * @return #GNUNET_OK if @a msg is well-formed | ||
284 | */ | ||
285 | static int | ||
286 | check_view_update (void *cls, | ||
287 | const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg) | ||
288 | { | ||
289 | uint16_t msize = ntohs (msg->header.size); | ||
290 | uint32_t num_peers = ntohl (msg->num_peers); | ||
291 | |||
292 | msize -= sizeof (struct GNUNET_RPS_CS_DEBUG_ViewReply); | ||
293 | if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) || | ||
294 | (msize % sizeof (struct GNUNET_PeerIdentity) != 0) ) | ||
295 | { | ||
296 | GNUNET_break (0); | ||
297 | return GNUNET_SYSERR; | ||
298 | } | ||
299 | return GNUNET_OK; | ||
300 | } | ||
301 | |||
302 | /** | ||
303 | * This function is called, when the service updated its view. | ||
304 | * It calls the callback the caller provided | ||
305 | * and disconnects afterwards. | ||
306 | * | ||
307 | * @param msg the message | ||
308 | */ | ||
309 | static void | ||
310 | handle_view_update (void *cls, | ||
311 | const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg) | ||
312 | { | ||
313 | struct GNUNET_RPS_Handle *h = cls; | ||
314 | struct GNUNET_PeerIdentity *peers; | ||
315 | |||
316 | /* Give the peers back */ | ||
317 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
318 | "New view of %" PRIu32 " peers:\n", | ||
319 | ntohl (msg->num_peers)); | ||
320 | |||
321 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; | ||
322 | GNUNET_assert (NULL != h); | ||
323 | GNUNET_assert (NULL != h->view_update_cb); | ||
324 | h->view_update_cb (h->view_update_cls, ntohl (msg->num_peers), peers); | ||
325 | } | ||
326 | |||
327 | |||
328 | |||
239 | /** | 329 | /** |
240 | * Reconnect to the service | 330 | * Reconnect to the service |
241 | */ | 331 | */ |
@@ -281,6 +371,10 @@ reconnect (struct GNUNET_RPS_Handle *h) | |||
281 | GNUNET_MESSAGE_TYPE_RPS_CS_REPLY, | 371 | GNUNET_MESSAGE_TYPE_RPS_CS_REPLY, |
282 | struct GNUNET_RPS_CS_ReplyMessage, | 372 | struct GNUNET_RPS_CS_ReplyMessage, |
283 | h), | 373 | h), |
374 | GNUNET_MQ_hd_var_size (view_update, | ||
375 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY, | ||
376 | struct GNUNET_RPS_CS_DEBUG_ViewReply, | ||
377 | h), | ||
284 | GNUNET_MQ_handler_end () | 378 | GNUNET_MQ_handler_end () |
285 | }; | 379 | }; |
286 | 380 | ||
@@ -306,6 +400,7 @@ GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
306 | struct GNUNET_RPS_Handle *h; | 400 | struct GNUNET_RPS_Handle *h; |
307 | 401 | ||
308 | h = GNUNET_new (struct GNUNET_RPS_Handle); | 402 | h = GNUNET_new (struct GNUNET_RPS_Handle); |
403 | h->current_request_id = 0; | ||
309 | h->cfg = cfg; | 404 | h->cfg = cfg; |
310 | reconnect (h); | 405 | reconnect (h); |
311 | if (NULL == h->mq) | 406 | if (NULL == h->mq) |