#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.
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");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received connection reversal request for wrong port\n");
#endif
return; /* wrong port */
}
struct GNUNET_NAT_Test *tst = cls;
uint16_t data;
- tst->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- tst->lsock, &do_udp_read, tst);
+ tst->ltask =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, tst->lsock,
+ &do_udp_read, tst);
if ((NULL != tc->write_ready) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- tst->lsock)) &&
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready, tst->lsock)) &&
(sizeof (data) ==
GNUNET_NETWORK_socket_recv (tst->lsock, &data, sizeof (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");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received data mismatches expected value\n");
#endif
}
#if DEBUG_NAT
else
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat", "Failed to receive data from inbound connection\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to receive data from inbound connection\n");
#endif
}
tst = na->h;
GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na);
if ((NULL != tc->write_ready) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- na->sock)) &&
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready, na->sock)) &&
(sizeof (data) ==
GNUNET_NETWORK_socket_recv (na->sock, &data, sizeof (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");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received data mismatches expected value\n");
#endif
}
#if DEBUG_NAT
else
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat", "Failed to receive data from inbound connection\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to receive data from inbound connection\n");
#endif
GNUNET_NETWORK_socket_close (na->sock);
GNUNET_free (na);
tst->ltask = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
- tst->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- tst->lsock, &do_accept, tst);
+ tst->ltask =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, tst->lsock,
+ &do_accept, tst);
s = GNUNET_NETWORK_socket_accept (tst->lsock, NULL, NULL);
if (NULL == s)
{
return; /* odd error */
}
#if DEBUG_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat", "Got an inbound connection, waiting for data\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got an inbound connection, waiting for data\n");
#endif
wl = GNUNET_malloc (sizeof (struct NatActivity));
wl->sock = s;
wl->h = tst;
- wl->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- wl->sock, &do_read, wl);
+ wl->rtask =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, wl->sock,
+ &do_read, wl);
GNUNET_CONTAINER_DLL_insert (tst->na_head, tst->na_tail, wl);
}
* @param addrlen actual lenght of the address
*/
static void
-addr_cb (void *cls,
- int add_remove, const struct sockaddr *addr, socklen_t addrlen)
+addr_cb (void *cls, int add_remove, const struct sockaddr *addr,
+ socklen_t addrlen)
{
struct GNUNET_NAT_Test *h = cls;
struct ClientActivity *ca;
if (addrlen != sizeof (struct sockaddr_in))
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));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "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));
ca->client = client;
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,
- GNUNET_YES,
- NULL, NULL));
+ GNUNET_CLIENT_transmit_and_get_response (client, &msg.header,
+ NAT_SERVER_TIMEOUT,
+ GNUNET_YES, NULL,
+ NULL));
}
*/
struct GNUNET_NAT_Test *
GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
- int is_tcp,
- uint16_t bnd_port,
- uint16_t adv_port,
+ int is_tcp, uint16_t bnd_port, uint16_t adv_port,
GNUNET_NAT_TestCallback report, void *report_cls)
{
struct GNUNET_NAT_Test *ret;
ret->report_cls = report_cls;
if (bnd_port == 0)
{
- ret->nat = GNUNET_NAT_register (cfg, is_tcp,
- 0,
- 0, NULL, NULL, &addr_cb, &reversal_cb, ret);
+ ret->nat =
+ GNUNET_NAT_register (cfg, is_tcp, 0, 0, NULL, NULL, &addr_cb,
+ &reversal_cb, ret);
}
else
{
- ret->lsock = GNUNET_NETWORK_socket_create (AF_INET,
- (is_tcp == GNUNET_YES)
- ? SOCK_STREAM : SOCK_DGRAM, 0);
+ ret->lsock =
+ GNUNET_NETWORK_socket_create (AF_INET,
+ (is_tcp ==
+ GNUNET_YES) ? SOCK_STREAM : SOCK_DGRAM,
+ 0);
if ((ret->lsock == NULL) ||
- (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret->lsock,
- (const struct sockaddr *) &sa,
- sizeof (sa))))
+ (GNUNET_OK !=
+ GNUNET_NETWORK_socket_bind (ret->lsock, (const struct sockaddr *) &sa,
+ sizeof (sa))))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
if (GNUNET_YES == is_tcp)
{
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_listen (ret->lsock, 5));
- ret->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- ret->lsock, &do_accept, ret);
+ ret->ltask =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ ret->lsock, &do_accept, ret);
}
else
{
- ret->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- ret->lsock,
- &do_udp_read, ret);
+ ret->ltask =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ ret->lsock, &do_udp_read, ret);
}
- ret->nat = GNUNET_NAT_register (cfg, is_tcp,
- adv_port,
- 1, addrs, addrlens, &addr_cb, NULL, ret);
+ ret->nat =
+ GNUNET_NAT_register (cfg, is_tcp, adv_port, 1, addrs, addrlens,
+ &addr_cb, NULL, ret);
}
return ret;
}