diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-01-28 13:50:12 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-01-28 13:50:12 +0100 |
commit | 5f8301275181a3349e2df231d7e3c530d6c4d8e9 (patch) | |
tree | 0ab115475baa1af9af1765eb670a2f415ba25e5a /src/transport/gnunet-communicator-tcp.c | |
parent | 0157a38006025eecbed40d04153817a5df0d0e6a (diff) | |
download | gnunet-5f8301275181a3349e2df231d7e3c530d6c4d8e9.tar.gz gnunet-5f8301275181a3349e2df231d7e3c530d6c4d8e9.zip |
improve NAT API: allow client to store associated data with address
Diffstat (limited to 'src/transport/gnunet-communicator-tcp.c')
-rw-r--r-- | src/transport/gnunet-communicator-tcp.c | 51 |
1 files changed, 40 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 | */ |
2163 | static void | 2174 | static void |
2164 | nat_address_cb (void *cls, | 2175 | nat_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, |