check_PROGRAMS = \
test_transport_api_tcp \
- test_transport_api_tcp \
+ test_transport_api_tcp_nat \
test_transport_api_udp \
$(HTTP_PLUGIN_CHECK) \
test_transport_api_udp_nat \
- test_transport_api_reliability_tcp
+ test_transport_api_reliability_tcp \
+ test_transport_api_reliability_tcp_nat
# test_transport_api_http \
# TODO: add tests for http, nat, etc.
$(top_builddir)/src/transport/libgnunettransport.la \
$(top_builddir)/src/util/libgnunetutil.la
+test_transport_api_tcp_nat_SOURCES = \
+ test_transport_api.c
+test_transport_api_tcp_nat_LDADD = \
+ $(top_builddir)/src/transport/libgnunettransport.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
test_transport_api_reliability_tcp_SOURCES = \
test_transport_api_reliability.c
test_transport_api_reliability_tcp_LDADD = \
$(top_builddir)/src/transport/libgnunettransport.la \
$(top_builddir)/src/util/libgnunetutil.la
+test_transport_api_reliability_tcp_nat_SOURCES = \
+ test_transport_api_reliability.c
+test_transport_api_reliability_tcp_nat_LDADD = \
+ $(top_builddir)/src/transport/libgnunettransport.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
test_transport_api_udp_SOURCES = \
test_transport_api.c
test_transport_api_udp_LDADD = \
test_transport_api_udp_peer2.conf \
test_transport_api_udp_nat_peer1.conf \
test_transport_api_udp_nat_peer2.conf \
+ test_transport_api_tcp_nat_peer1.conf \
+ test_transport_api_tcp_nat_peer2.conf \
test_plugin_transport_data.conf \
test_plugin_transport_data_http.conf
#include "transport.h"
#define DEBUG_TCP GNUNET_NO
+#define DEBUG_TCP_NAT GNUNET_NO
/**
* How long until we give up on transmitting the welcome message?
char *port_as_string;
pid_t pid;
const struct sockaddr *sa = (const struct sockaddr *)addr;
+#if DEBUG_TCP_NAT
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
+ _("called run_gnunet_nat_client addrlen %d others are %d and %d\n"), addrlen, sizeof (struct sockaddr), sizeof (struct sockaddr_in));
+#endif
if (addrlen < sizeof (struct sockaddr))
return;
+
switch (sa->sa_family)
{
case AF_INET:
}
GNUNET_asprintf(&port_as_string, "%d", plugin->adv_port);
-#if DEBUG_UDP_NAT
+#if DEBUG_TCP_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
_("Running gnunet-nat-client with arguments: %s %s %d\n"), plugin->external_address, address_as_string, plugin->adv_port);
#endif
if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress)))
return -1; /* NAT client only works with IPv4 addresses */
+
if ( (plugin->allow_nat == GNUNET_YES) && (is_natd == GNUNET_YES) &&
(GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(plugin->nat_wait_conns, &target->hashPubKey)))
{
+#if DEBUG_TCP_NAT
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp",
+ _("Found valid IPv4 NAT address!\n"));
+#endif
session = create_session (plugin,
target,
NULL, is_natd);
pm);
GNUNET_CONTAINER_multihashmap_put(plugin->nat_wait_conns, &target->hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+#if DEBUG_TCP_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"tcp",
"Created NAT WAIT connection to `%4s' at `%s'\n",
GNUNET_i2s (target),
GNUNET_a2s (sb, sbs));
-
- run_gnunet_nat_client(plugin, addr, addrlen);
+#endif
+ run_gnunet_nat_client(plugin, sb, sbs);
return 0;
}
else if ((plugin->allow_nat == GNUNET_YES) && (is_natd == GNUNET_YES) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(plugin->nat_wait_conns, &target->hashPubKey)))
const struct sockaddr_in *s4;
const struct sockaddr_in6 *s6;
+#if DEBUG_TCP_NAT
+ GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, "tcp", "received tcp NAT probe\n");
+#endif
/* We have received a TCP NAT probe, meaning we (hopefully) initiated
* a connection to this peer by running gnunet-nat-client. This peer
* received the punch message and now wants us to use the new connection
*/
if (ntohs(message->size) != sizeof(struct TCP_NAT_ProbeMessage))
{
+#if DEBUG_TCP_NAT
+ GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, "tcp", "Bad size fo tcp NAT probe, expected %d got %d.\n", sizeof(struct TCP_NAT_ProbeMessage), ntohs(message->size));
+#endif
GNUNET_break_op(0);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
tcp_nat_probe = (struct TCP_NAT_ProbeMessage *)message;
if (GNUNET_CONTAINER_multihashmap_contains(plugin->nat_wait_conns, &tcp_nat_probe->clientIdentity.hashPubKey) == GNUNET_YES)
{
+#if DEBUG_TCP_NAT
+ GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, "tcp", "Found session for NAT probe!\n");
+#endif
session = GNUNET_CONTAINER_multihashmap_get(plugin->nat_wait_conns, &tcp_nat_probe->clientIdentity.hashPubKey);
GNUNET_assert(session != NULL);
GNUNET_SERVER_client_keep (client);
session->client = client;
+ session->last_activity = GNUNET_TIME_absolute_get ();
if (GNUNET_OK ==
GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
{
-#if DEBUG_TCP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Found address `%s' for incoming connection %p\n",
- GNUNET_a2s (vaddr, alen),
- client);
+#if DEBUG_TCP_NAT
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp",
+ "Found address `%s' for incoming connection %p\n",
+ GNUNET_a2s (vaddr, alen),
+ client);
#endif
if (alen == sizeof (struct sockaddr_in))
{
/* FIXME: free partial session? */
}
-
session->next = plugin->sessions;
plugin->sessions = session;
1,
GNUNET_NO);
/*GNUNET_SERVER_connect_socket (plugin->server,
- client);*/
+ client->);*/
+
+ process_pending_messages (session);
+ }
+ else
+ {
+#if DEBUG_TCP_NAT
+ GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, "tcp", "Did NOT find session for NAT probe!\n");
+#endif
}
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
/**
if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == ntohs(message->type)) || (ntohs(message->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE))
{
- /* We don't want to propagate WELCOME messages up! */
+ /* We don't want to propagate WELCOME and NAT Probe messages up! */
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
if (bytes < 1)
{
-#if DEBUG_UDP_NAT
+#if DEBUG_TCP_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
_("Finished reading from server stdout with code: %d\n"), bytes);
#endif
return;
}
+ in_addr.sin_family = AF_INET;
+ in_addr.sin_port = htons(port);
/**
* We have received an ICMP response, ostensibly from a non-NAT'd peer
* that wants to connect to us! Send a message to establish a connection.
*/
sock = GNUNET_CONNECTION_create_from_sockaddr (plugin->env->sched, AF_INET, (struct sockaddr *)&in_addr,
sizeof(in_addr), GNUNET_SERVER_MAX_MESSAGE_SIZE);
-
if (sock == NULL)
{
plugin->server_read_task =
tcp_probe_ctx->message.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
memcpy(&tcp_probe_ctx->message.clientIdentity, plugin->env->my_identity, sizeof(struct GNUNET_PeerIdentity));
tcp_probe_ctx->plugin = plugin;
-
+ tcp_probe_ctx->sock = sock;
tcp_probe_ctx->transmit_handle = GNUNET_CONNECTION_notify_transmit_ready (sock,
ntohs(tcp_probe_ctx->message.header.size),
GNUNET_TIME_UNIT_FOREVER_REL,
if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
"transport-tcp",
"BEHIND_NAT"))
- {
- /* We are behind nat (according to the user) */
- if (check_gnunet_nat_binary("gnunet-nat-server") == GNUNET_YES)
+ {
+ /* We are behind nat (according to the user) */
+ if (check_gnunet_nat_binary("gnunet-nat-server") == GNUNET_YES)
+ {
behind_nat = GNUNET_YES;
- else
- {
- behind_nat = GNUNET_NO;
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "tcp", "Configuration specified you are behind a NAT, but gnunet-nat-server is not installed properly (suid bit not set)!\n");
- }
- }
- else
- behind_nat = GNUNET_NO; /* We are not behind nat! */
+ }
+ else
+ {
+ behind_nat = GNUNET_NO;
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "tcp", "Configuration specified you are behind a NAT, but gnunet-nat-server is not installed properly (suid bit not set)!\n");
+ }
+ }
+ else
+ behind_nat = GNUNET_NO; /* We are not behind nat! */
if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
"transport-tcp",
return NULL;
}
- if (behind_nat)
- {
- if (GNUNET_YES != tcp_transport_start_nat_server(plugin))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "tcp",
- _
- ("Failed to start %s required for NAT in %s!\n"),
- "gnunet-nat-server"
- "transport-tcp");
- GNUNET_free_non_null(external_address);
- GNUNET_free_non_null(internal_address);
- GNUNET_SERVICE_stop (service);
- return NULL;
- }
- }
-
- if (allow_nat)
- {
- plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create(100);
- GNUNET_assert(plugin->nat_wait_conns != NULL);
- }
-
if (aport == 0)
aport = bport;
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->handlers[i].callback_cls = plugin;
GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers);
+ if (behind_nat == GNUNET_YES)
+ {
+ if (GNUNET_YES != tcp_transport_start_nat_server(plugin))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "tcp",
+ _
+ ("Failed to start %s required for NAT in %s!\n"),
+ "gnunet-nat-server"
+ "transport-tcp");
+ GNUNET_free_non_null(external_address);
+ GNUNET_free_non_null(internal_address);
+ GNUNET_SERVICE_stop (service);
+ return NULL;
+ }
+ }
+
+ if (allow_nat == GNUNET_YES)
+ {
+ plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create(100);
+ GNUNET_assert(plugin->nat_wait_conns != NULL);
+ }
+
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
"tcp", _("TCP transport listening on port %llu\n"), bport);
if (aport != bport)
static int is_tcp;
+static int is_tcp_nat;
+
static int is_udp;
static int is_udp_nat;
GNUNET_assert (GNUNET_OK ==
GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
message, &me->id));
-
- /* Can't we get away with only offering one hello? */
- /* GNUNET_TRANSPORT_offer_hello (p1.th, message); */
-
- /*sleep(1);*/ /* Make sure we are not falling prey to the "favorable timing" bug... */
-
- /* both HELLOs exchanged, get ready to test transmission! */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Finished exchanging HELLOs, now waiting for transmission!\n");
}
setup_peer (&p1, "test_transport_api_tcp_peer1.conf");
setup_peer (&p2, "test_transport_api_tcp_peer2.conf");
}
- if (is_udp_nat)
+ else if (is_tcp_nat)
+ {
+ setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf");
+ setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf");
+ }
+ else if (is_udp_nat)
{
setup_peer (&p1, "test_transport_api_udp_nat_peer1.conf");
setup_peer (&p2, "test_transport_api_udp_nat_peer2.conf");
}
- if (is_http)
+ else if (is_http)
{
setup_peer (&p1, "test_transport_api_http_peer1.conf");
setup_peer (&p2, "test_transport_api_http_peer2.conf");
#ifdef MINGW
return GNUNET_SYSERR;
#endif
- if (strstr(argv[0], "tcp") != NULL)
+ if (strstr(argv[0], "tcp_nat") != NULL)
+ {
+ is_tcp_nat = GNUNET_YES;
+ if (check_gnunet_nat_server() != GNUNET_OK)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`%s' not properly installed, cannot run NAT test!\n",
+ "gnunet-nat-server");
+ return 0;
+ }
+ }
+ else if (strstr(argv[0], "tcp") != NULL)
{
is_tcp = GNUNET_YES;
}
is_http = GNUNET_YES;
}
-
GNUNET_log_setup ("test-transport-api",
#if VERBOSE
"DEBUG",
static int is_tcp;
+static int is_tcp_nat;
+
static int is_http;
+static int connected;
+
static unsigned long long total_bytes;
static struct GNUNET_TIME_Absolute start_time;
return;
}
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got message %u of size %u\n",
- ntohl (hdr->num),
- ntohs (message->size));
+ if (ntohl(hdr->num) % 5000 == 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Got message %u of size %u\n",
+ ntohl (hdr->num),
+ ntohs (message->size));
+ }
#endif
n++;
if (0 == (n % (TOTAL_MSGS/100)))
memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
ret += s - sizeof (struct TestMessage);
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message %u of size %u\n",
- n,
- s);
+ if (n % 5000 == 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message %u of size %u\n",
+ n,
+ s);
+ }
#endif
n++;
s = get_size (n);
s, 0, TIMEOUT,
¬ify_ready,
NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Returning total message block of size %u\n",
- ret);
+ if (n % 5000 == 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Returning total message block of size %u\n",
+ ret);
+ }
total_bytes += ret;
return ret;
}
GNUNET_TIME_UNIT_FOREVER_REL,
NULL, NULL);
start_time = GNUNET_TIME_absolute_get ();
- GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
- &p2.id,
- get_size (0), 0, TIMEOUT,
- ¬ify_ready,
- NULL);
+ connected++;
}
else
{
GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024),
GNUNET_TIME_UNIT_FOREVER_REL,
NULL, NULL);
+ connected++;
+ }
+
+ if (connected == 2)
+ {
+ GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
+ &p2.id,
+ get_size (0), 0, TIMEOUT,
+ ¬ify_ready,
+ NULL);
}
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
setup_peer (&p1, "test_transport_api_http_peer1.conf");
setup_peer (&p2, "test_transport_api_http_peer2.conf");
}
+ else if (is_tcp_nat)
+ {
+ setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf");
+ setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf");
+ }
else
GNUNET_assert (0);
GNUNET_assert(p1.th != NULL);
#ifdef MINGW
return GNUNET_SYSERR;
#endif
- if (strstr(argv[0], "tcp") != NULL)
+ if (strstr(argv[0], "tcp_nat") != NULL)
+ {
+ is_tcp_nat = GNUNET_YES;
+ }
+ else if (strstr(argv[0], "tcp") != NULL)
{
is_tcp = GNUNET_YES;
}