aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_tcp.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-06-11 11:39:20 +0000
committerNathan S. Evans <evans@in.tum.de>2010-06-11 11:39:20 +0000
commit8ab1946b4136cb0b20a47661bb54dbe0820ba04f (patch)
tree396600b983a32f29054d90ba86f52f30d7cae20e /src/transport/plugin_transport_tcp.c
parent069ba0d81d3e74204b20bf6505d93d4e5200eef2 (diff)
downloadgnunet-8ab1946b4136cb0b20a47661bb54dbe0820ba04f.tar.gz
gnunet-8ab1946b4136cb0b20a47661bb54dbe0820ba04f.zip
explicitly add user provided external address to known addresses when used with NAT
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r--src/transport/plugin_transport_tcp.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 7ad3a8e4b..459057219 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -2154,6 +2154,8 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2154 int only_nat_addresses; 2154 int only_nat_addresses;
2155 char *internal_address; 2155 char *internal_address;
2156 char *external_address; 2156 char *external_address;
2157 struct sockaddr_in in_addr;
2158 struct IPv4TcpAddress t4;
2157 2159
2158 service = GNUNET_SERVICE_start ("transport-tcp", env->sched, env->cfg); 2160 service = GNUNET_SERVICE_start ("transport-tcp", env->sched, env->cfg);
2159 if (service == NULL) 2161 if (service == NULL)
@@ -2223,6 +2225,11 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2223 return NULL; 2225 return NULL;
2224 } 2226 }
2225 2227
2228 if ((external_address != NULL) && (inet_pton(AF_INET, external_address, &in_addr.sin_addr) != 1))
2229 {
2230 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, "udp", "Malformed EXTERNAL_ADDRESS %s given in configuration!\n", external_address);
2231 }
2232
2226 internal_address = NULL; 2233 internal_address = NULL;
2227 if ((GNUNET_YES == behind_nat) && (GNUNET_OK != 2234 if ((GNUNET_YES == behind_nat) && (GNUNET_OK !=
2228 GNUNET_CONFIGURATION_get_value_string (env->cfg, 2235 GNUNET_CONFIGURATION_get_value_string (env->cfg,
@@ -2240,6 +2247,10 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2240 return NULL; 2247 return NULL;
2241 } 2248 }
2242 2249
2250 if ((internal_address != NULL) && (inet_pton(AF_INET, internal_address, &in_addr.sin_addr) != 1))
2251 {
2252 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, "udp", "Malformed INTERNAL_ADDRESS %s given in configuration!\n", internal_address);
2253 }
2243 2254
2244 aport = 0; 2255 aport = 0;
2245 if ((GNUNET_OK != 2256 if ((GNUNET_OK !=
@@ -2328,15 +2339,26 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2328 GNUNET_SERVER_disconnect_notify (plugin->server, 2339 GNUNET_SERVER_disconnect_notify (plugin->server,
2329 &disconnect_notify, 2340 &disconnect_notify,
2330 plugin); 2341 plugin);
2331 /* FIXME: do the two calls below periodically again and 2342 if (plugin->behind_nat == GNUNET_NO)
2332 not just once (since the info we get might change...) */ 2343 {
2333 GNUNET_OS_network_interfaces_list (&process_interfaces, plugin); 2344 GNUNET_OS_network_interfaces_list (&process_interfaces, plugin);
2345 }
2346
2334 plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched, 2347 plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched,
2335 env->cfg, 2348 env->cfg,
2336 AF_UNSPEC, 2349 AF_UNSPEC,
2337 HOSTNAME_RESOLVE_TIMEOUT, 2350 HOSTNAME_RESOLVE_TIMEOUT,
2338 &process_hostname_ips, 2351 &process_hostname_ips,
2339 plugin); 2352 plugin);
2353
2354 if ((plugin->behind_nat == GNUNET_YES) && (inet_pton(AF_INET, plugin->external_address, &t4.ipv4_addr) == 1))
2355 {
2356 t4.t_port = htons(0);
2357 plugin->env->notify_address (plugin->env->cls,
2358 "tcp",
2359 &t4, sizeof(t4), GNUNET_TIME_UNIT_FOREVER_REL);
2360 }
2361
2340 return api; 2362 return api;
2341} 2363}
2342 2364