aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-nat-server.c2
-rw-r--r--src/transport/plugin_transport_udp_nat.c60
-rw-r--r--src/transport/test_transport_api_udp_nat_peer1.conf5
-rw-r--r--src/transport/test_transport_api_udp_nat_peer2.conf7
4 files changed, 42 insertions, 32 deletions
diff --git a/src/transport/gnunet-nat-server.c b/src/transport/gnunet-nat-server.c
index 6bead4c31..dcea365f8 100644
--- a/src/transport/gnunet-nat-server.c
+++ b/src/transport/gnunet-nat-server.c
@@ -62,7 +62,7 @@
62 */ 62 */
63#define DUMMY_IP "1.2.3.4" 63#define DUMMY_IP "1.2.3.4"
64 64
65#define VERBOSE 1 65#define VERBOSE 0
66 66
67/** 67/**
68 * How often do we send our ICMP messages to receive replies? 68 * How often do we send our ICMP messages to receive replies?
diff --git a/src/transport/plugin_transport_udp_nat.c b/src/transport/plugin_transport_udp_nat.c
index c2f30887b..3f74b2259 100644
--- a/src/transport/plugin_transport_udp_nat.c
+++ b/src/transport/plugin_transport_udp_nat.c
@@ -279,6 +279,11 @@ struct UDP_NAT_Probes
279 */ 279 */
280 struct sockaddr_in sock_addr; 280 struct sockaddr_in sock_addr;
281 281
282 /**
283 * The port to send this probe to, 0 to choose randomly
284 */
285 int port;
286
282}; 287};
283 288
284 289
@@ -328,10 +333,6 @@ struct Plugin
328 */ 333 */
329 uint16_t starting_port; 334 uint16_t starting_port;
330 335
331 /**
332 * Main listen port, only needed for testing...
333 */
334 uint16_t listen_port;
335 336
336 /** 337 /**
337 * Starting port for sending out crazy messages 338 * Starting port for sending out crazy messages
@@ -577,6 +578,7 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen)
577{ 578{
578 char inet4[INET_ADDRSTRLEN]; 579 char inet4[INET_ADDRSTRLEN];
579 char *address_as_string; 580 char *address_as_string;
581 char *port_as_string;
580 pid_t pid; 582 pid_t pid;
581 const struct sockaddr *sa = (const struct sockaddr *)addr; 583 const struct sockaddr *sa = (const struct sockaddr *)addr;
582 584
@@ -597,12 +599,15 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen)
597 return; 599 return;
598 } 600 }
599 601
602 GNUNET_asprintf(&port_as_string, "%d", plugin->starting_port);
600#if DEBUG_UDP_NAT 603#if DEBUG_UDP_NAT
601 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp-nat", 604 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp-nat",
602 _("Running gnunet-nat-client with address %s\n"), address_as_string); 605 _("Running gnunet-nat-client with arguments: %s %s %d\n"), plugin->external_address, address_as_string, plugin->starting_port);
603#endif 606#endif
604 /* Start the server process */ 607 /* Start the server process */
605 pid = GNUNET_OS_start_process(NULL, NULL, "gnunet-nat-client", "gnunet-nat-client", plugin->external_address, address_as_string, NULL); 608 pid = GNUNET_OS_start_process(NULL, NULL, "gnunet-nat-client", "gnunet-nat-client", plugin->external_address, address_as_string, port_as_string, NULL);
609 GNUNET_free(address_as_string);
610 GNUNET_free(port_as_string);
606 GNUNET_OS_process_wait (pid); 611 GNUNET_OS_process_wait (pid);
607} 612}
608 613
@@ -758,7 +763,7 @@ process_interfaces (void *cls,
758 v4->sin_port = htons (0); /* Indicates to receiver we are behind NAT */ 763 v4->sin_port = htons (0); /* Indicates to receiver we are behind NAT */
759 } 764 }
760 else 765 else
761 v4->sin_port = htons (plugin->listen_port); 766 v4->sin_port = htons (plugin->starting_port);
762 } 767 }
763 else 768 else
764 { 769 {
@@ -767,7 +772,7 @@ process_interfaces (void *cls,
767 if (plugin->behind_nat == GNUNET_YES) 772 if (plugin->behind_nat == GNUNET_YES)
768 v6->sin6_port = htons (0); 773 v6->sin6_port = htons (0);
769 else 774 else
770 v6->sin6_port = htons (plugin->listen_port); 775 v6->sin6_port = htons (plugin->starting_port);
771 } 776 }
772 777
773#if !IPV6 778#if !IPV6
@@ -833,7 +838,12 @@ send_udp_probe_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
833 message->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE); 838 message->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE);
834 /* Try the agreed upon port first, then go in order starting with our randomly chosen port */ 839 /* Try the agreed upon port first, then go in order starting with our randomly chosen port */
835 if (probe->index == 0) 840 if (probe->index == 0)
836 probe->sock_addr.sin_port = htons(plugin->starting_port); 841 {
842 if (probe->port != 0)
843 probe->sock_addr.sin_port = htons(probe->port);
844 else
845 probe->sock_addr.sin_port = htons(plugin->starting_port);
846 }
837 else 847 else
838 probe->sock_addr.sin_port = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a non-root port */ 848 probe->sock_addr.sin_port = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a non-root port */
839#if DEBUG_UDP_NAT 849#if DEBUG_UDP_NAT
@@ -933,7 +943,8 @@ udp_nat_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext
933 memset(&mybuf, 0, sizeof(mybuf)); 943 memset(&mybuf, 0, sizeof(mybuf));
934 int i; 944 int i;
935 struct UDP_NAT_Probes *temp_probe; 945 struct UDP_NAT_Probes *temp_probe;
936 946 int port;
947 char *port_start;
937 bytes = GNUNET_DISK_file_read(plugin->server_stdout_handle, &mybuf, sizeof(mybuf)); 948 bytes = GNUNET_DISK_file_read(plugin->server_stdout_handle, &mybuf, sizeof(mybuf));
938 949
939 if (bytes < 1) 950 if (bytes < 1)
@@ -945,15 +956,26 @@ udp_nat_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext
945 return; 956 return;
946 } 957 }
947 958
959 port = 0;
960 port_start = NULL;
948 for (i = 0; i < sizeof(mybuf); i++) 961 for (i = 0; i < sizeof(mybuf); i++)
949 { 962 {
950 if (mybuf[i] == '\n') 963 if (mybuf[i] == '\n')
951 mybuf[i] = '\0'; 964 mybuf[i] = '\0';
965
966 if ((mybuf[i] == ':') && (i + 1 < sizeof(mybuf)))
967 {
968 mybuf[i] = '\0';
969 port_start = &mybuf[i + 1];
970 }
952 } 971 }
953 972
973 if (port_start != NULL)
974 port = atoi(port_start);
975
954#if DEBUG_UDP_NAT 976#if DEBUG_UDP_NAT
955 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp-nat", 977 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp-nat",
956 _("nat-server-read read: %s\n"), &mybuf); 978 _("nat-server-read read: %s port %d\n"), &mybuf, port);
957#endif 979#endif
958 980
959 /* Schedule sending of messages to peer on random ports */ 981 /* Schedule sending of messages to peer on random ports */
@@ -966,6 +988,7 @@ udp_nat_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext
966 temp_probe->sock_addr.sin_family = AF_INET; 988 temp_probe->sock_addr.sin_family = AF_INET;
967 GNUNET_assert(inet_pton(AF_INET, &mybuf[0], &temp_probe->sock_addr.sin_addr) == 1); 989 GNUNET_assert(inet_pton(AF_INET, &mybuf[0], &temp_probe->sock_addr.sin_addr) == 1);
968 temp_probe->index = 0; 990 temp_probe->index = 0;
991 temp_probe->port = port;
969 temp_probe->next = plugin->probes; 992 temp_probe->next = plugin->probes;
970 temp_probe->plugin = plugin; 993 temp_probe->plugin = plugin;
971 temp_probe->task = GNUNET_SCHEDULER_add_delayed(plugin->env->sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500), &send_udp_probe_message, temp_probe); 994 temp_probe->task = GNUNET_SCHEDULER_add_delayed(plugin->env->sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500), &send_udp_probe_message, temp_probe);
@@ -1355,7 +1378,7 @@ udp_nat_transport_server_start (void *cls)
1355 serverAddrv4.sin_family = AF_INET; 1378 serverAddrv4.sin_family = AF_INET;
1356 serverAddrv4.sin_addr.s_addr = INADDR_ANY; 1379 serverAddrv4.sin_addr.s_addr = INADDR_ANY;
1357 if (i == 0) 1380 if (i == 0)
1358 serverAddrv4.sin_port = htons (plugin->listen_port); 1381 serverAddrv4.sin_port = htons (plugin->starting_port);
1359 else 1382 else
1360 serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a non-root port */ 1383 serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a non-root port */
1361 addrlen = sizeof (serverAddrv4); 1384 addrlen = sizeof (serverAddrv4);
@@ -1602,7 +1625,6 @@ libgnunet_plugin_transport_udp_nat_init (void *cls)
1602 char *internal_address; 1625 char *internal_address;
1603 char *external_address; 1626 char *external_address;
1604 char *starting_port; 1627 char *starting_port;
1605 char *listen_port;
1606 1628
1607 service = GNUNET_SERVICE_start ("transport-udp-nat", env->sched, env->cfg); 1629 service = GNUNET_SERVICE_start ("transport-udp-nat", env->sched, env->cfg);
1608 if (service == NULL) 1630 if (service == NULL)
@@ -1651,17 +1673,9 @@ libgnunet_plugin_transport_udp_nat_init (void *cls)
1651 GNUNET_CONFIGURATION_get_value_string (env->cfg, 1673 GNUNET_CONFIGURATION_get_value_string (env->cfg,
1652 "transport-udp-nat", 1674 "transport-udp-nat",
1653 "PORT", 1675 "PORT",
1654 &listen_port);
1655
1656 /* Yes we'll use PORT as the default configuration value, but
1657 * for testing we need two different ports for the peers so
1658 * STARTING_PORT will have to do!
1659 */
1660 GNUNET_CONFIGURATION_get_value_string (env->cfg,
1661 "transport-udp-nat",
1662 "STARTING_PORT",
1663 &starting_port); 1676 &starting_port);
1664 1677
1678
1665 mtu = 1240; 1679 mtu = 1240;
1666 if (mtu < 1200) 1680 if (mtu < 1200)
1667 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 1681 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
@@ -1672,8 +1686,6 @@ libgnunet_plugin_transport_udp_nat_init (void *cls)
1672 plugin = GNUNET_malloc (sizeof (struct Plugin)); 1686 plugin = GNUNET_malloc (sizeof (struct Plugin));
1673 plugin->external_address = external_address; 1687 plugin->external_address = external_address;
1674 plugin->internal_address = internal_address; 1688 plugin->internal_address = internal_address;
1675 if (listen_port != NULL)
1676 plugin->listen_port = atoi(listen_port);
1677 1689
1678 if (starting_port != NULL) 1690 if (starting_port != NULL)
1679 plugin->starting_port = atoi(starting_port); 1691 plugin->starting_port = atoi(starting_port);
diff --git a/src/transport/test_transport_api_udp_nat_peer1.conf b/src/transport/test_transport_api_udp_nat_peer1.conf
index 8bff71dee..c30777acc 100644
--- a/src/transport/test_transport_api_udp_nat_peer1.conf
+++ b/src/transport/test_transport_api_udp_nat_peer1.conf
@@ -1,9 +1,8 @@
1[transport-udp-nat] 1[transport-udp-nat]
2PORT = 12368 2PORT = 12368
3BEHIND_NAT = YES 3BEHIND_NAT = YES
4INTERNAL_ADDRESS = 127.0.0.1
4EXTERNAL_ADDRESS = 127.0.0.1 5EXTERNAL_ADDRESS = 127.0.0.1
5STARTING_PORT = 40000
6RANDOM_START_PORT = 50000
7 6
8[fs] 7[fs]
9ALLOW_SHUTDOWN = YES 8ALLOW_SHUTDOWN = YES
@@ -65,7 +64,7 @@ PORT = 2092
65 64
66[transport] 65[transport]
67PLUGINS = udp_nat 66PLUGINS = udp_nat
68#DEBUG = YES 67DEBUG = NO
69ALLOW_SHUTDOWN = YES 68ALLOW_SHUTDOWN = YES
70ACCEPT_FROM6 = ::1; 69ACCEPT_FROM6 = ::1;
71ACCEPT_FROM = 127.0.0.1; 70ACCEPT_FROM = 127.0.0.1;
diff --git a/src/transport/test_transport_api_udp_nat_peer2.conf b/src/transport/test_transport_api_udp_nat_peer2.conf
index d7284cc56..5ec73f6ef 100644
--- a/src/transport/test_transport_api_udp_nat_peer2.conf
+++ b/src/transport/test_transport_api_udp_nat_peer2.conf
@@ -1,9 +1,8 @@
1[transport-udp-nat] 1[transport-udp-nat]
2PORT = 22368 2PORT = 22368
3BEHIND_NAT = YES 3BEHIND_NAT = NO
4EXTERNAL_ADDRESS = 127.0.0.1 4EXTERNAL_ADDRESS = 127.0.0.1
5STARTING_PORT = 50000 5INTERNAL_ADDRESS = 127.0.0.1
6RANDOM_START_PORT = 40000
7 6
8[fs] 7[fs]
9ALLOW_SHUTDOWN = YES 8ALLOW_SHUTDOWN = YES
@@ -65,7 +64,7 @@ PORT = 2092
65 64
66[transport] 65[transport]
67PLUGINS = udp_nat 66PLUGINS = udp_nat
68#DEBUG = YES 67DEBUG = NO
69PREFIX = 68PREFIX =
70ALLOW_SHUTDOWN = YES 69ALLOW_SHUTDOWN = YES
71ACCEPT_FROM6 = ::1; 70ACCEPT_FROM6 = ::1;