aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-01-28 13:50:12 +0100
committerChristian Grothoff <christian@grothoff.org>2019-01-28 13:50:12 +0100
commit5f8301275181a3349e2df231d7e3c530d6c4d8e9 (patch)
tree0ab115475baa1af9af1765eb670a2f415ba25e5a /src/transport
parent0157a38006025eecbed40d04153817a5df0d0e6a (diff)
downloadgnunet-5f8301275181a3349e2df231d7e3c530d6c4d8e9.tar.gz
gnunet-5f8301275181a3349e2df231d7e3c530d6c4d8e9.zip
improve NAT API: allow client to store associated data with address
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-communicator-tcp.c51
-rw-r--r--src/transport/plugin_transport_http_server.c4
-rw-r--r--src/transport/plugin_transport_tcp.c4
-rw-r--r--src/transport/plugin_transport_udp.c4
4 files changed, 52 insertions, 11 deletions
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index 7d52a41db..884fbb0cb 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -25,7 +25,8 @@
25 * 25 *
26 * TODO: 26 * TODO:
27 * - NAT service API change to handle address stops! 27 * - NAT service API change to handle address stops!
28 * - address construction for HELLOs (FIXMEs, easy) 28 * - support NAT connection reversal method
29 * - support other TCP-specific NAT traversal methods
29 */ 30 */
30#include "platform.h" 31#include "platform.h"
31#include "gnunet_util_lib.h" 32#include "gnunet_util_lib.h"
@@ -1241,9 +1242,17 @@ tcp_address_to_sockaddr (const char *bindto,
1241 { 1242 {
1242 /* try IPv6 */ 1243 /* try IPv6 */
1243 struct sockaddr_in6 v6; 1244 struct sockaddr_in6 v6;
1245 const char *start;
1244 1246
1247 start = cp;
1248 if ( ('[' == *cp) &&
1249 (']' == cp[strlen (cp)-1]) )
1250 {
1251 start++; /* skip over '[' */
1252 cp[strlen (cp) -1] = '\0'; /* eat ']' */
1253 }
1245 if (1 == inet_pton (AF_INET6, 1254 if (1 == inet_pton (AF_INET6,
1246 cp, 1255 start,
1247 &v6)) 1256 &v6))
1248 { 1257 {
1249 v6.sin6_port = htons ((uint16_t) port); 1258 v6.sin6_port = htons ((uint16_t) port);
@@ -1574,17 +1583,17 @@ boot_queue (struct Queue *queue,
1574 { 1583 {
1575 case AF_INET: 1584 case AF_INET:
1576 GNUNET_asprintf (&foreign_addr, 1585 GNUNET_asprintf (&foreign_addr,
1577 "%s-%s:%d", 1586 "%s-%s",
1578 COMMUNICATOR_ADDRESS_PREFIX, 1587 COMMUNICATOR_ADDRESS_PREFIX,
1579 "inet-ntop-FIXME", 1588 GNUNET_a2s(queue->address,
1580 4242); 1589 queue->address_len));
1581 break; 1590 break;
1582 case AF_INET6: 1591 case AF_INET6:
1583 GNUNET_asprintf (&foreign_addr, 1592 GNUNET_asprintf (&foreign_addr,
1584 "%s-%s:%d", 1593 "%s-%s",
1585 COMMUNICATOR_ADDRESS_PREFIX, 1594 COMMUNICATOR_ADDRESS_PREFIX,
1586 "inet-ntop-FIXME", 1595 GNUNET_a2s(queue->address,
1587 4242); 1596 queue->address_len));
1588 break; 1597 break;
1589 default: 1598 default:
1590 GNUNET_assert (0); 1599 GNUNET_assert (0);
@@ -2154,6 +2163,8 @@ enc_notify_cb (void *cls,
2154 * a function to call whenever our set of 'valid' addresses changes. 2163 * a function to call whenever our set of 'valid' addresses changes.
2155 * 2164 *
2156 * @param cls closure 2165 * @param cls closure
2166 * @param app_ctx[in,out] location where the app can store stuff
2167 * on add and retrieve it on remove
2157 * @param add_remove #GNUNET_YES to add a new public IP address, 2168 * @param add_remove #GNUNET_YES to add a new public IP address,
2158 * #GNUNET_NO to remove a previous (now invalid) one 2169 * #GNUNET_NO to remove a previous (now invalid) one
2159 * @param ac address class the address belongs to 2170 * @param ac address class the address belongs to
@@ -2162,6 +2173,7 @@ enc_notify_cb (void *cls,
2162 */ 2173 */
2163static void 2174static void
2164nat_address_cb (void *cls, 2175nat_address_cb (void *cls,
2176 void **app_ctx,
2165 int add_remove, 2177 int add_remove,
2166 enum GNUNET_NAT_AddressClass ac, 2178 enum GNUNET_NAT_AddressClass ac,
2167 const struct sockaddr *addr, 2179 const struct sockaddr *addr,
@@ -2211,7 +2223,9 @@ run (void *cls,
2211 char *bindto; 2223 char *bindto;
2212 struct sockaddr *in; 2224 struct sockaddr *in;
2213 socklen_t in_len; 2225 socklen_t in_len;
2214 2226 struct sockaddr_storage in_sto;
2227 socklen_t sto_len;
2228
2215 (void) cls; 2229 (void) cls;
2216 cfg = c; 2230 cfg = c;
2217 if (GNUNET_OK != 2231 if (GNUNET_OK !=
@@ -2267,11 +2281,26 @@ run (void *cls,
2267 GNUNET_free (bindto); 2281 GNUNET_free (bindto);
2268 return; 2282 return;
2269 } 2283 }
2284 /* We might have bound to port 0, allowing the OS to figure it out;
2285 thus, get the real IN-address from the socket */
2286 sto_len = sizeof (in_sto);
2287 if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
2288 (struct sockaddr *) &in_sto,
2289 &sto_len))
2290 {
2291 memcpy (&in_sto,
2292 in,
2293 in_len);
2294 sto_len = in_len;
2295 }
2270 GNUNET_free (in); 2296 GNUNET_free (in);
2297 GNUNET_free (bindto);
2298 in = (struct sockaddr *) &in_sto;
2299 in_len = sto_len;
2271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2272 "Bound to `%s'\n", 2301 "Bound to `%s'\n",
2273 bindto); 2302 GNUNET_a2s ((const struct sockaddr *) &in_sto,
2274 GNUNET_free (bindto); 2303 sto_len));
2275 stats = GNUNET_STATISTICS_create ("C-TCP", 2304 stats = GNUNET_STATISTICS_create ("C-TCP",
2276 cfg); 2305 cfg);
2277 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 2306 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index c522904d3..495105fe3 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -2535,6 +2535,8 @@ server_remove_address (void *cls,
2535 * Our external IP address/port mapping has changed. 2535 * Our external IP address/port mapping has changed.
2536 * 2536 *
2537 * @param cls closure, the 'struct LocalAddrList' 2537 * @param cls closure, the 'struct LocalAddrList'
2538 * @param app_ctx[in,out] location where the app can store stuff
2539 * on add and retrieve it on remove
2538 * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean 2540 * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
2539 * the previous (now invalid) one 2541 * the previous (now invalid) one
2540 * @param ac address class the address belongs to 2542 * @param ac address class the address belongs to
@@ -2543,6 +2545,7 @@ server_remove_address (void *cls,
2543 */ 2545 */
2544static void 2546static void
2545server_nat_port_map_callback (void *cls, 2547server_nat_port_map_callback (void *cls,
2548 void **app_ctx,
2546 int add_remove, 2549 int add_remove,
2547 enum GNUNET_NAT_AddressClass ac, 2550 enum GNUNET_NAT_AddressClass ac,
2548 const struct sockaddr *addr, 2551 const struct sockaddr *addr,
@@ -2550,6 +2553,7 @@ server_nat_port_map_callback (void *cls,
2550{ 2553{
2551 struct HTTP_Server_Plugin *plugin = cls; 2554 struct HTTP_Server_Plugin *plugin = cls;
2552 2555
2556 (void) app_ctx;
2553 LOG (GNUNET_ERROR_TYPE_DEBUG, 2557 LOG (GNUNET_ERROR_TYPE_DEBUG,
2554 "NAT called to %s address `%s'\n", 2558 "NAT called to %s address `%s'\n",
2555 (add_remove == GNUNET_NO) ? "remove" : "add", 2559 (add_remove == GNUNET_NO) ? "remove" : "add",
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 5afea593f..d93c4423c 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -1430,6 +1430,8 @@ notify_session_monitor (struct Plugin *plugin,
1430 * Our external IP address/port mapping has changed. 1430 * Our external IP address/port mapping has changed.
1431 * 1431 *
1432 * @param cls closure, the `struct Plugin` 1432 * @param cls closure, the `struct Plugin`
1433 * @param app_ctx[in,out] location where the app can store stuff
1434 * on add and retrieve it on remove
1433 * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean 1435 * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
1434 * the previous (now invalid) one 1436 * the previous (now invalid) one
1435 * @param ac address class the address belongs to 1437 * @param ac address class the address belongs to
@@ -1438,6 +1440,7 @@ notify_session_monitor (struct Plugin *plugin,
1438 */ 1440 */
1439static void 1441static void
1440tcp_nat_port_map_callback (void *cls, 1442tcp_nat_port_map_callback (void *cls,
1443 void **app_ctx,
1441 int add_remove, 1444 int add_remove,
1442 enum GNUNET_NAT_AddressClass ac, 1445 enum GNUNET_NAT_AddressClass ac,
1443 const struct sockaddr *addr, 1446 const struct sockaddr *addr,
@@ -1450,6 +1453,7 @@ tcp_nat_port_map_callback (void *cls,
1450 void *arg; 1453 void *arg;
1451 size_t args; 1454 size_t args;
1452 1455
1456 (void) app_ctx;
1453 LOG (GNUNET_ERROR_TYPE_INFO, 1457 LOG (GNUNET_ERROR_TYPE_INFO,
1454 "NAT notification to %s address `%s'\n", 1458 "NAT notification to %s address `%s'\n",
1455 (GNUNET_YES == add_remove) ? "add" : "remove", 1459 (GNUNET_YES == add_remove) ? "add" : "remove",
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 30a54cb17..b05192e06 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -1309,6 +1309,8 @@ udp_plugin_check_address (void *cls,
1309 * Our external IP address/port mapping has changed. 1309 * Our external IP address/port mapping has changed.
1310 * 1310 *
1311 * @param cls closure, the `struct Plugin` 1311 * @param cls closure, the `struct Plugin`
1312 * @param app_ctx[in,out] location where the app can store stuff
1313 * on add and retrieve it on remove
1312 * @param add_remove #GNUNET_YES to mean the new public IP address, 1314 * @param add_remove #GNUNET_YES to mean the new public IP address,
1313 * #GNUNET_NO to mean the previous (now invalid) one 1315 * #GNUNET_NO to mean the previous (now invalid) one
1314 * @param ac address class the address belongs to 1316 * @param ac address class the address belongs to
@@ -1317,6 +1319,7 @@ udp_plugin_check_address (void *cls,
1317 */ 1319 */
1318static void 1320static void
1319udp_nat_port_map_callback (void *cls, 1321udp_nat_port_map_callback (void *cls,
1322 void **app_ctx,
1320 int add_remove, 1323 int add_remove,
1321 enum GNUNET_NAT_AddressClass ac, 1324 enum GNUNET_NAT_AddressClass ac,
1322 const struct sockaddr *addr, 1325 const struct sockaddr *addr,
@@ -1329,6 +1332,7 @@ udp_nat_port_map_callback (void *cls,
1329 void *arg; 1332 void *arg;
1330 size_t args; 1333 size_t args;
1331 1334
1335 (void) app_ctx;
1332 LOG (GNUNET_ERROR_TYPE_DEBUG, 1336 LOG (GNUNET_ERROR_TYPE_DEBUG,
1333 (GNUNET_YES == add_remove) 1337 (GNUNET_YES == add_remove)
1334 ? "NAT notification to add address `%s'\n" 1338 ? "NAT notification to add address `%s'\n"