From 8dc32abbeff6b4b348253afed6c60543665a34c2 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 11 Jul 2011 14:49:46 +0000 Subject: [PATCH] logging --- src/nat/nat.c | 20 ++++++++-------- src/nat/nat_mini.c | 18 +++++++++++---- src/nat/nat_test.c | 51 +++++++++++++++++++++++++++++------------ src/nat/test_nat.c | 8 ++++--- src/nat/test_nat_mini.c | 2 +- src/nat/test_nat_test.c | 2 +- 6 files changed, 67 insertions(+), 34 deletions(-) diff --git a/src/nat/nat.c b/src/nat/nat.c index bf9565877..d09fd79fc 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c @@ -24,15 +24,14 @@ * external IP address retrieval * @author Milan Bouchet-Valat * @author Christian Grothoff - * - * TODO: - * - implement UPnP/PMP support */ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_resolver_service.h" #include "gnunet_nat_lib.h" +#define DEBUG_NAT GNUNET_NO + /** * How often do we scan for changes in our IP address from our local * interfaces? @@ -767,7 +766,7 @@ nat_server_read (void *cls, sizeof(mybuf)); if (bytes < 1) { -#if DEBUG_TCP_NAT +#if DEBUG_NAT GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", "Finished reading from server stdout with code: %d\n", @@ -1136,10 +1135,13 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, struct in_addr in_addr; unsigned int i; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Registered with NAT service at port %u with %u IP bound local addresses\n", - (unsigned int) adv_port, - num_addrs); +#if DEBUG_NAT + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "nat", + "Registered with NAT service at port %u with %u IP bound local addresses\n", + (unsigned int) adv_port, + num_addrs); +#endif h = GNUNET_malloc (sizeof (struct GNUNET_NAT_Handle)); h->server_retry_delay = GNUNET_TIME_UNIT_SECONDS; h->cfg = cfg; @@ -1432,7 +1434,7 @@ GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h, sizeof (port_as_string), "%d", h->adv_port); -#if DEBUG_TCP_NAT +#if DEBUG_NAT GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", _("Running gnunet-helper-nat-client %s %s %u\n"), diff --git a/src/nat/nat_mini.c b/src/nat/nat_mini.c index c8ac65edb..b82866c78 100644 --- a/src/nat/nat_mini.c +++ b/src/nat/nat_mini.c @@ -28,6 +28,8 @@ #include "gnunet_nat_lib.h" #include "nat.h" +#define DEBUG_NAT GNUNET_NO + /** * How long do we give upnpc to create a mapping? */ @@ -453,8 +455,11 @@ process_unmap_output (void *cls, if (NULL == line) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "UPnP unmap done\n"); +#if DEBUG_NAT + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "nat", + "UPnP unmap done\n"); +#endif GNUNET_OS_command_stop (mini->unmap_cmd); mini->unmap_cmd = NULL; GNUNET_free (mini); @@ -506,9 +511,12 @@ GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini) GNUNET_snprintf (pstr, sizeof (pstr), "%u", (unsigned int) ntohs (mini->current_addr.sin_port)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Unmapping port %u\n", - ntohs (mini->current_addr.sin_port)); +#if DEBUG_NAT + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "nat", + "Unmapping port %u with UPnP\n", + ntohs (mini->current_addr.sin_port)); +#endif mini->unmap_cmd = GNUNET_OS_command_run (&process_unmap_output, mini, UNMAP_TIMEOUT, diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c index 8a46a96fa..8c9933cdb 100644 --- a/src/nat/nat_test.c +++ b/src/nat/nat_test.c @@ -179,8 +179,11 @@ reversal_cb (void *cls, sa = (const struct sockaddr_in *) addr; if (h->data != sa->sin_port) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received connection reversal request for wrong port\n"); +#if DEBUG_NAT + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "nat", + "Received connection reversal request for wrong port\n"); +#endif return; /* wrong port */ } /* report success */ @@ -216,13 +219,19 @@ do_udp_read (void *cls, { if (data == tst->data) tst->report (tst->report_cls, GNUNET_OK); +#if DEBUG_NAT else - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received data mismatches expected value\n"); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "nat", + "Received data mismatches expected value\n"); +#endif } +#if DEBUG_NAT else - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to receive data from inbound connection\n"); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "nat", + "Failed to receive data from inbound connection\n"); +#endif } @@ -256,13 +265,19 @@ do_read (void *cls, { if (data == tst->data) tst->report (tst->report_cls, GNUNET_OK); +#if DEBUG_NAT else - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received data mismatches expected value\n"); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "nat" + "Received data mismatches expected value\n"); +#endif } +#if DEBUG_NAT else - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to receive data from inbound connection\n"); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "nat", + "Failed to receive data from inbound connection\n"); +#endif GNUNET_NETWORK_socket_close (na->sock); GNUNET_free (na); } @@ -296,8 +311,11 @@ do_accept (void *cls, GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "accept"); return; /* odd error */ } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Got an inbound connection, waiting for data\n"); +#if DEBUG_NAT + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "nat", + "Got an inbound connection, waiting for data\n"); +#endif wl = GNUNET_malloc (sizeof (struct NatActivity)); wl->sock = s; wl->h = tst; @@ -336,9 +354,12 @@ addr_cb (void *cls, return; if (addrlen != sizeof (struct sockaddr_in)) return; /* ignore IPv6 here */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Asking gnunet-nat-server to connect to `%s'\n", - GNUNET_a2s (addr, addrlen)); +#if DEBUG_NAT + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "nat", + "Asking gnunet-nat-server to connect to `%s'\n", + GNUNET_a2s (addr, addrlen)); +#endif sa = (const struct sockaddr_in*) addr; msg.header.size = htons (sizeof(struct GNUNET_NAT_TestMessage)); msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAT_TEST); diff --git a/src/nat/test_nat.c b/src/nat/test_nat.c index 72cff0915..cb011c7af 100644 --- a/src/nat/test_nat.c +++ b/src/nat/test_nat.c @@ -41,11 +41,13 @@ #include "gnunet_nat_lib.h" -#define VERBOSE GNUNET_YES +#define VERBOSE GNUNET_NO -/* Time to wait before stopping NAT, in seconds */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) +/** + * Time to wait before stopping NAT, in seconds + */ +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) /** diff --git a/src/nat/test_nat_mini.c b/src/nat/test_nat_mini.c index 4e708c413..e7b8294c8 100644 --- a/src/nat/test_nat_mini.c +++ b/src/nat/test_nat_mini.c @@ -36,7 +36,7 @@ #include "gnunet_nat_lib.h" -#define VERBOSE GNUNET_YES +#define VERBOSE GNUNET_NO /* Time to wait before stopping NAT, in seconds */ #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) diff --git a/src/nat/test_nat_test.c b/src/nat/test_nat_test.c index a7c7ff967..32c4fb2d8 100644 --- a/src/nat/test_nat_test.c +++ b/src/nat/test_nat_test.c @@ -31,7 +31,7 @@ #include "gnunet_nat_lib.h" -#define VERBOSE GNUNET_YES +#define VERBOSE GNUNET_NO /** -- 2.25.1