aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-06-24 11:02:02 +0200
committerSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-06-24 11:02:02 +0200
commitb550d58cb1d4ad39f491dd742bfee360a1f74963 (patch)
tree6e33aa11e36c46aaca0d2eb613b3ae05745de417 /src
parent303490940d4799459e15baf14f0cea54c8f903c5 (diff)
parente3c3f5a42e9b3c763354e54bd9f6828f911c0622 (diff)
downloadgnunet-b550d58cb1d4ad39f491dd742bfee360a1f74963.tar.gz
gnunet-b550d58cb1d4ad39f491dd742bfee360a1f74963.zip
Merge branch 'master' of git+ssh://gnunet.org/gnunet
Diffstat (limited to 'src')
-rw-r--r--src/statistics/gnunet-statistics.c212
1 files changed, 114 insertions, 98 deletions
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c
index 9093336e1..a92faa3d7 100644
--- a/src/statistics/gnunet-statistics.c
+++ b/src/statistics/gnunet-statistics.c
@@ -159,6 +159,11 @@ static struct GNUNET_CONTAINER_MultiHashMap *values;
159static int num_nodes_ready; 159static int num_nodes_ready;
160 160
161/** 161/**
162 * @brief Number of nodes that have their values ready.
163 */
164static int num_nodes_ready_shutdown;
165
166/**
162 * @brief Create a new #ValueSet 167 * @brief Create a new #ValueSet
163 * 168 *
164 * @param subsystem Subsystem of the valueset. 169 * @param subsystem Subsystem of the valueset.
@@ -249,42 +254,6 @@ printer (void *cls,
249} 254}
250 255
251/** 256/**
252 * @brief Called once all statistic values are available.
253 *
254 * Implements #GNUNET_STATISTICS_Callback
255 *
256 * @param cls Closure - The index of the node.
257 * @param succes Whether statistics were obtained successfully.
258 */
259static void
260continuation_print (void *cls,
261 int success)
262{
263 const unsigned index_node = *(unsigned *) cls;
264
265 nodes[index_node].gh = NULL;
266 if (GNUNET_OK != success)
267 {
268 if (NULL == remote_host)
269 FPRINTF (stderr,
270 "%s",
271 _("Failed to obtain statistics.\n"));
272 else
273 FPRINTF (stderr,
274 _("Failed to obtain statistics from host `%s:%llu'\n"),
275 remote_host,
276 remote_port);
277 ret = 1;
278 }
279 num_nodes_ready++;
280 if (num_nodes_ready == num_nodes)
281 {
282 GNUNET_CONTAINER_multihashmap_iterate (values, printer, NULL);
283 GNUNET_SCHEDULER_shutdown();
284 }
285}
286
287/**
288 * Callback function to process statistic values. 257 * Callback function to process statistic values.
289 * 258 *
290 * @param cls closure 259 * @param cls closure
@@ -343,6 +312,112 @@ printer_watch (void *cls,
343} 312}
344 313
345/** 314/**
315 * @brief Clean all data structures related to given node.
316 *
317 * Also clears global structures if we are the last node to clean.
318 *
319 * @param cls the index of the node
320 */
321static void
322clean_node (void *cls)
323{
324 const unsigned index_node = *(unsigned *) cls;
325 struct GNUNET_STATISTICS_Handle *h;
326 struct GNUNET_STATISTICS_GetHandle *gh;
327
328 if ( (NULL != path_testbed) && /* were issued with -t <testbed-path> option */
329 (NULL != nodes[index_node].conf) )
330 {
331 GNUNET_CONFIGURATION_destroy (nodes[index_node].conf);
332 nodes[index_node].conf = NULL;
333 }
334
335 h = nodes[index_node].handle;
336 gh = nodes[index_node].gh;
337
338 if (NULL != gh)
339 {
340 GNUNET_STATISTICS_get_cancel (gh);
341 gh = NULL;
342 }
343 if (GNUNET_YES == watch)
344 {
345 GNUNET_assert (GNUNET_OK ==
346 GNUNET_STATISTICS_watch_cancel (h,
347 subsystem,
348 name,
349 &printer_watch,
350 &nodes[index_node].index_node));
351 }
352
353 if (NULL != h)
354 {
355 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
356 h = NULL;
357 }
358
359 num_nodes_ready_shutdown++;
360 if (num_nodes == num_nodes_ready_shutdown)
361 {
362 GNUNET_array_grow (nodes, num_nodes, 0);
363 GNUNET_CONTAINER_multihashmap_destroy (values);
364 }
365}
366
367/**
368 * @brief Print and shutdown
369 *
370 * @param cls unused
371 */
372static void
373print_finish (void *cls)
374{
375 GNUNET_CONTAINER_multihashmap_iterate (values, printer, NULL);
376 GNUNET_SCHEDULER_shutdown();
377}
378
379/**
380 * @brief Called once all statistic values are available.
381 *
382 * Implements #GNUNET_STATISTICS_Callback
383 *
384 * @param cls Closure - The index of the node.
385 * @param succes Whether statistics were obtained successfully.
386 */
387static void
388continuation_print (void *cls,
389 int success)
390{
391 const unsigned index_node = *(unsigned *) cls;
392
393 nodes[index_node].gh = NULL;
394 if (GNUNET_OK != success)
395 {
396 if (NULL == remote_host)
397 FPRINTF (stderr,
398 "%s",
399 _("Failed to obtain statistics.\n"));
400 else
401 FPRINTF (stderr,
402 _("Failed to obtain statistics from host `%s:%llu'\n"),
403 remote_host,
404 remote_port);
405 ret = 1;
406 }
407 if (NULL != nodes[index_node].shutdown_task)
408 {
409 GNUNET_SCHEDULER_cancel (nodes[index_node].shutdown_task);
410 nodes[index_node].shutdown_task = NULL;
411 }
412 GNUNET_SCHEDULER_add_now (clean_node, &nodes[index_node].index_node);
413 num_nodes_ready++;
414 if (num_nodes_ready == num_nodes)
415 {
416 GNUNET_SCHEDULER_add_now (print_finish, NULL);
417 }
418}
419
420/**
346 * Function called last by the statistics code. 421 * Function called last by the statistics code.
347 * 422 *
348 * @param cls closure 423 * @param cls closure
@@ -424,65 +499,6 @@ collector (void *cls,
424} 499}
425 500
426/** 501/**
427 * Function run on shutdown to clean up.
428 *
429 * @param cls the statistics handle
430 */
431static void
432shutdown_task (void *cls)
433{
434 const unsigned index_node = *(unsigned *) cls;
435 struct GNUNET_STATISTICS_Handle *h;
436 struct GNUNET_STATISTICS_GetHandle *gh;
437
438 nodes[index_node].shutdown_task = NULL;
439 if ( (NULL != path_testbed) &&
440 (NULL != nodes[index_node].conf) )
441 {
442 GNUNET_CONFIGURATION_destroy (nodes[index_node].conf);
443 nodes[index_node].conf = NULL;
444 }
445
446 h = nodes[index_node].handle;
447 gh = nodes[index_node].gh;
448 if (NULL == h)
449 {
450 num_nodes_ready--;
451 if (0 == num_nodes_ready)
452 {
453 GNUNET_array_grow (nodes, num_nodes, 0);
454 GNUNET_CONTAINER_multihashmap_destroy (values);
455 }
456 return;
457 }
458 if (NULL != gh)
459 {
460 GNUNET_STATISTICS_get_cancel (gh);
461 gh = NULL;
462 }
463 if ( (GNUNET_YES == watch) &&
464 (NULL != subsystem) &&
465 (NULL != name) )
466 GNUNET_assert (GNUNET_OK ==
467 GNUNET_STATISTICS_watch_cancel (h,
468 subsystem,
469 name,
470 &printer_watch,
471 &nodes[index_node].index_node));
472 GNUNET_STATISTICS_destroy (h,
473 GNUNET_NO);
474 h = NULL;
475
476 num_nodes_ready--;
477 if (0 == num_nodes_ready)
478 {
479 GNUNET_array_grow (nodes, num_nodes, 0);
480 GNUNET_CONTAINER_multihashmap_destroy (values);
481 }
482}
483
484
485/**
486 * Main task that does the actual work. 502 * Main task that does the actual work.
487 * 503 *
488 * @param cls closure with our configuration 504 * @param cls closure with our configuration
@@ -562,18 +578,18 @@ main_task (void *cls)
562 subsystem, 578 subsystem,
563 name, 579 name,
564 &printer_watch, 580 &printer_watch,
565 &nodes[index_node].index_node)) 581 &nodes[index_node].index_node))
566 { 582 {
567 fprintf (stderr, 583 fprintf (stderr,
568 _("Failed to initialize watch routine\n")); 584 _("Failed to initialize watch routine\n"));
569 nodes[index_node].shutdown_task = 585 nodes[index_node].shutdown_task =
570 GNUNET_SCHEDULER_add_now (&shutdown_task, 586 GNUNET_SCHEDULER_add_now (&clean_node,
571 &nodes[index_node].index_node); 587 &nodes[index_node].index_node);
572 return; 588 return;
573 } 589 }
574 } 590 }
575 nodes[index_node].shutdown_task = 591 nodes[index_node].shutdown_task =
576 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 592 GNUNET_SCHEDULER_add_shutdown (&clean_node,
577 &nodes[index_node].index_node); 593 &nodes[index_node].index_node);
578} 594}
579 595