aboutsummaryrefslogtreecommitdiff
path: root/src/nse/gnunet-service-nse.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2014-04-01 14:04:26 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2014-04-01 14:04:26 +0000
commitbae1739074843ab36c3f703bd124024448922bcc (patch)
tree2a8083b0144ba7d7a2a3c300665767f08be41dec /src/nse/gnunet-service-nse.c
parent21f72ad4b6113709d411852b91f8d13052570aa5 (diff)
downloadgnunet-bae1739074843ab36c3f703bd124024448922bcc.tar.gz
gnunet-bae1739074843ab36c3f703bd124024448922bcc.zip
- Log NSE histogram to file in addition to testbed-logger when HISTOGRAM_DIR
variable is present in configuration. - Make logging to testbed-logger optional and only when testbed-logger service is available. - This is change is required to get NSE histograms on planetlab nodes.
Diffstat (limited to 'src/nse/gnunet-service-nse.c')
-rw-r--r--src/nse/gnunet-service-nse.c88
1 files changed, 79 insertions, 9 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 7ad08a917..51874db14 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -92,10 +92,22 @@ static struct GNUNET_TIME_Relative gnunet_nse_interval;
92static struct GNUNET_TIME_Relative proof_find_delay; 92static struct GNUNET_TIME_Relative proof_find_delay;
93 93
94#if ENABLE_NSE_HISTOGRAM 94#if ENABLE_NSE_HISTOGRAM
95
96/**
97 * Handle to test if testbed logger service is running or not
98 */
99struct GNUNET_CLIENT_TestHandle *logger_test;
100
95/** 101/**
96 * Handle for writing when we received messages to disk. 102 * Handle for writing when we received messages to disk.
97 */ 103 */
98static struct GNUNET_TESTBED_LOGGER_Handle *lh; 104static struct GNUNET_TESTBED_LOGGER_Handle *lh;
105
106/**
107 * Handle for writing message received timestamp information to disk.
108 */
109static struct GNUNET_BIO_WriteHandle *histogram;
110
99#endif 111#endif
100 112
101 113
@@ -1049,7 +1061,10 @@ handle_p2p_size_estimate (void *cls,
1049 uint64_t t; 1061 uint64_t t;
1050 1062
1051 t = GNUNET_TIME_absolute_get().abs_value_us; 1063 t = GNUNET_TIME_absolute_get().abs_value_us;
1052 GNUNET_TESTBED_LOGGER_write (lh, &t, sizeof (uint64_t)); 1064 if (NULL != lh)
1065 GNUNET_TESTBED_LOGGER_write (lh, &t, sizeof (uint64_t));
1066 if (NULL != histogram)
1067 GNUNET_BIO_write_int64 (histogram, t);
1053 } 1068 }
1054#endif 1069#endif
1055 incoming_flood = (const struct GNUNET_NSE_FloodMessage *) message; 1070 incoming_flood = (const struct GNUNET_NSE_FloodMessage *) message;
@@ -1347,9 +1362,22 @@ shutdown_task (void *cls,
1347 my_private_key = NULL; 1362 my_private_key = NULL;
1348 } 1363 }
1349#if ENABLE_NSE_HISTOGRAM 1364#if ENABLE_NSE_HISTOGRAM
1350 struct GNUNET_TIME_Relative timeout; 1365 if (NULL != logger_test)
1351 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); 1366 {
1352 GNUNET_TESTBED_LOGGER_flush (lh, timeout, &flush_comp_cb, NULL); 1367 GNUNET_CLIENT_service_test_cancel (logger_test);
1368 logger_test = NULL;
1369 }
1370 if (NULL != lh)
1371 {
1372 struct GNUNET_TIME_Relative timeout;
1373 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
1374 GNUNET_TESTBED_LOGGER_flush (lh, timeout, &flush_comp_cb, NULL);
1375 }
1376 if (NULL != histogram)
1377 {
1378 GNUNET_BIO_write_close (histogram);
1379 histogram = NULL;
1380 }
1353#endif 1381#endif
1354} 1382}
1355 1383
@@ -1399,6 +1427,33 @@ core_init (void *cls,
1399 NULL); 1427 NULL);
1400} 1428}
1401 1429
1430#if ENABLE_NSE_HISTOGRAM
1431/**
1432 * Function called with the status of the testbed logger service
1433 *
1434 * @param cls NULL
1435 * @param status GNUNET_YES if the service is running,
1436 * GNUNET_NO if the service is not running
1437 * GNUNET_SYSERR if the configuration is invalid
1438 */
1439static void
1440status_cb (void *cls, int status)
1441{
1442 logger_test = NULL;
1443 if (GNUNET_YES != status)
1444 {
1445 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed logger not running\n");
1446 return;
1447 }
1448 if (NULL == (lh = GNUNET_TESTBED_LOGGER_connect (cfg)))
1449 {
1450 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1451 "Cannot connect to the testbed logger. Exiting.\n");
1452 GNUNET_SCHEDULER_shutdown ();
1453 }
1454}
1455#endif
1456
1402 1457
1403/** 1458/**
1404 * Handle network size estimate clients. 1459 * Handle network size estimate clients.
@@ -1465,12 +1520,27 @@ run (void *cls,
1465 } 1520 }
1466 1521
1467#if ENABLE_NSE_HISTOGRAM 1522#if ENABLE_NSE_HISTOGRAM
1468 if (NULL == (lh = GNUNET_TESTBED_LOGGER_connect (cfg)))
1469 { 1523 {
1470 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1524 char *histogram_dir;
1471 "Cannot connect to the testbed logger. Exiting.\n"); 1525 char *histogram_fn;
1472 GNUNET_SCHEDULER_shutdown (); 1526
1473 return; 1527 if (GNUNET_OK ==
1528 GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "HISTOGRAM_DIR",
1529 &histogram_dir))
1530 {
1531 GNUNET_assert (0 < GNUNET_asprintf (&histogram_fn, "%s/timestamps",
1532 histogram_dir));
1533 GNUNET_free (histogram_dir);
1534 histogram = GNUNET_BIO_write_open (histogram_fn);
1535 GNUNET_free (histogram_fn);
1536 if (NULL == histogram)
1537 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to open histogram file\n");
1538 }
1539 logger_test =
1540 GNUNET_CLIENT_service_test ("testbed-logger", cfg,
1541 GNUNET_TIME_UNIT_SECONDS,
1542 &status_cb, NULL);
1543
1474 } 1544 }
1475#endif 1545#endif
1476 1546