From dc0da555fd351b2a96bca0a6494e83f0643fac31 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 6 Feb 2012 09:34:52 +0000 Subject: [PATCH] adding -m option to gnunet-transport to enable monitor mode (see #1972) --- doc/man/gnunet-transport.1 | 3 +++ src/transport/gnunet-transport.c | 43 +++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/doc/man/gnunet-transport.1 b/doc/man/gnunet-transport.1 index bb7dc8085..cc1a022bd 100644 --- a/doc/man/gnunet-transport.1 +++ b/doc/man/gnunet-transport.1 @@ -26,6 +26,9 @@ print help page \fB\-i\fR, \fB\-\-information\fR print information about our current connections (once) .TP +\fB\-m\fR, \fB\-\-monitor\fR +print information about our current connections (continuously) +.TP \fB\-L \fILOGLEVEL\fR, \fB\-\-loglevel=LOGLEVEL\fR Change the loglevel. Possible values for LOGLEVEL are ERROR, WARNING, INFO and DEBUG. .TP diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index c78518813..4b0c08f54 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c @@ -75,6 +75,11 @@ static int iterate_connections; */ static int test_configuration; +/** + * Option -m. + */ +static int monitor_connections; + /** * Option -n. */ @@ -482,6 +487,24 @@ process_address (void *cls, const struct GNUNET_PeerIdentity *peer, } +/** + * Task run in monitor mode when the user presses CTRL-C to abort. + * Stops monitoring activity. + * + * @param cls the 'struct GNUNET_TRANSPORT_PeerIterateContext *' + * @param tc scheduler context + */ +static void +shutdown_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_TRANSPORT_PeerIterateContext *pic = cls; + + GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pic); +} + + + /** * Main function that will be run by the scheduler. * @@ -538,6 +561,17 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_TIME_UNIT_MINUTES, &process_address, (void *) cfg); } + if (monitor_connections) + { + struct GNUNET_TRANSPORT_PeerIterateContext *pic; + + pic = GNUNET_TRANSPORT_peer_get_active_addresses (cfg, NULL, GNUNET_NO, + GNUNET_TIME_UNIT_FOREVER_REL, + &process_address, (void *) cfg); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, + &shutdown_task, + pic); + } } @@ -554,6 +588,12 @@ main (int argc, char *const *argv) {'i', "information", NULL, gettext_noop ("provide information about all current connections (once)"), 0, &GNUNET_GETOPT_set_one, &iterate_connections}, + {'m', "monitor", NULL, + gettext_noop ("provide information about all current connections (continuously)"), + 0, &GNUNET_GETOPT_set_one, &monitor_connections}, + {'n', "numeric", NULL, + gettext_noop ("do not resolve hostnames"), + 0, &GNUNET_GETOPT_set_one, &numeric}, {'s', "send", NULL, gettext_noop ("send data for benchmarking to the other peer (until CTRL-C)"), @@ -561,9 +601,6 @@ main (int argc, char *const *argv) {'t', "test", NULL, gettext_noop ("test transport configuration (involves external server)"), 0, &GNUNET_GETOPT_set_one, &test_configuration}, - {'n', "numeric", NULL, - gettext_noop ("do not resolve hostnames"), - 0, &GNUNET_GETOPT_set_one, &numeric}, GNUNET_GETOPT_OPTION_VERBOSE (&verbosity), GNUNET_GETOPT_OPTION_END }; -- 2.25.1