#include "gnunet_nat_lib.h"
#include "nat.h"
+#define LOG(kind,...) GNUNET_log_from (kind, "nat", __VA_ARGS__)
+
+#define NAT_SERVER_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
/**
* Entry we keep for each incoming connection.
sa = (const struct sockaddr_in *) addr;
if (h->data != sa->sin_port)
{
-#if DEBUG_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
- "Received connection reversal request for wrong port\n");
-#endif
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received connection reversal request for wrong port\n");
return; /* wrong port */
}
/* report success */
{
if (data == tst->data)
tst->report (tst->report_cls, GNUNET_OK);
-#if DEBUG_NAT
else
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
- "Received data mismatches expected value\n");
-#endif
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received data mismatches expected value\n");
}
-#if DEBUG_NAT
else
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
- "Failed to receive data from inbound connection\n");
-#endif
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to receive data from inbound connection\n");
}
{
if (data == tst->data)
tst->report (tst->report_cls, GNUNET_OK);
-#if DEBUG_NAT
else
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat",
- "Received data mismatches expected value\n");
-#endif
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received data mismatches expected value\n");
}
-#if DEBUG_NAT
else
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
- "Failed to receive data from inbound connection\n");
-#endif
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to receive data from inbound connection\n");
GNUNET_NETWORK_socket_close (na->sock);
GNUNET_free (na);
}
GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "accept");
return; /* odd error */
}
-#if DEBUG_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
- "Got an inbound connection, waiting for data\n");
-#endif
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got an inbound connection, waiting for data\n");
wl = GNUNET_malloc (sizeof (struct NatActivity));
wl->sock = s;
wl->h = tst;
if (GNUNET_YES != add_remove)
return;
if (addrlen != sizeof (struct sockaddr_in))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "NAT test ignores IPv6 address `%s' returned from NAT library\n",
+ GNUNET_a2s (addr, addrlen));
return; /* ignore IPv6 here */
-#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
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Asking gnunet-nat-server to connect to `%s'\n",
+ GNUNET_a2s (addr, addrlen));
sa = (const struct sockaddr_in *) addr;
msg.header.size = htons (sizeof (struct GNUNET_NAT_TestMessage));
msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAT_TEST);
GNUNET_CONTAINER_DLL_insert (h->ca_head, h->ca_tail, ca);
GNUNET_break (GNUNET_OK ==
GNUNET_CLIENT_transmit_and_get_response (client, &msg.header,
- GNUNET_TIME_UNIT_SECONDS,
+ NAT_SERVER_TIMEOUT,
GNUNET_YES, NULL,
NULL));
}
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
ret->lsock, &do_udp_read, ret);
}
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "NAT test listens on port %u (%s)\n",
+ bnd_port,
+ (GNUNET_YES == is_tcp) ? "tcp" : "udp");
ret->nat =
GNUNET_NAT_register (cfg, is_tcp, adv_port, 1, addrs, addrlens,
&addr_cb, NULL, ret);
struct NatActivity *pos;
struct ClientActivity *cpos;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping NAT test\n");
while (NULL != (cpos = tst->ca_head))
{
GNUNET_CONTAINER_DLL_remove (tst->ca_head, tst->ca_tail, cpos);
- GNUNET_CLIENT_disconnect (cpos->client, GNUNET_NO);
+ GNUNET_CLIENT_disconnect (cpos->client);
GNUNET_free (cpos);
}
while (NULL != (pos = tst->na_head))