summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_nat_service.h3
-rw-r--r--src/nat-auto/nat_auto_api_test.c4
-rw-r--r--src/nat/gnunet-nat.c6
-rw-r--r--src/nat/nat_api.c8
-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
8 files changed, 73 insertions, 11 deletions
diff --git a/src/include/gnunet_nat_service.h b/src/include/gnunet_nat_service.h
index c1e2f0a39..b96b2386e 100644
--- a/src/include/gnunet_nat_service.h
+++ b/src/include/gnunet_nat_service.h
@@ -279,6 +279,8 @@ enum GNUNET_NAT_Type
* a function to call whenever our set of 'valid' addresses changes.
*
* @param cls closure
+ * @param app_ctx[in,out] location where the app can store stuff
+ * on add and retrieve it on remove
* @param add_remove #GNUNET_YES to add a new public IP address,
* #GNUNET_NO to remove a previous (now invalid) one
* @param ac address class the address belongs to
@@ -287,6 +289,7 @@ enum GNUNET_NAT_Type
*/
typedef void
(*GNUNET_NAT_AddressCallback) (void *cls,
+ void **app_ctx,
int add_remove,
enum GNUNET_NAT_AddressClass ac,
const struct sockaddr *addr,
diff --git a/src/nat-auto/nat_auto_api_test.c b/src/nat-auto/nat_auto_api_test.c
index 42ce08721..1511d91ba 100644
--- a/src/nat-auto/nat_auto_api_test.c
+++ b/src/nat-auto/nat_auto_api_test.c
@@ -357,6 +357,8 @@ mq_error_handler (void *cls,
* Address-callback, used to send message to gnunet-nat-server.
*
* @param cls closure
+ * @param app_ctx[in,out] location where the app can store stuff
+ * on add and retrieve it on remove
* @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
* the previous (now invalid) one
* @param ac address class the address belongs to
@@ -365,6 +367,7 @@ mq_error_handler (void *cls,
*/
static void
addr_cb (void *cls,
+ void **app_ctx,
int add_remove,
enum GNUNET_NAT_AddressClass ac,
const struct sockaddr *addr,
@@ -376,6 +379,7 @@ addr_cb (void *cls,
struct GNUNET_NAT_AUTO_TestMessage *msg;
const struct sockaddr_in *sa;
+ (void) app_ctx;
if (GNUNET_YES != add_remove)
return;
if (addrlen != sizeof (struct sockaddr_in))
diff --git a/src/nat/gnunet-nat.c b/src/nat/gnunet-nat.c
index 31b6a7268..275553203 100644
--- a/src/nat/gnunet-nat.c
+++ b/src/nat/gnunet-nat.c
@@ -110,6 +110,8 @@ test_finished ()
* a function to call whenever our set of 'valid' addresses changes.
*
* @param cls closure, NULL
+ * @param app_ctx[in,out] location where the app can store stuff
+ * on add and retrieve it on remove
* @param add_remove #GNUNET_YES to add a new public IP address,
* #GNUNET_NO to remove a previous (now invalid) one
* @param ac address class the address belongs to
@@ -118,11 +120,15 @@ test_finished ()
*/
static void
address_cb (void *cls,
+ void **app_ctx,
int add_remove,
enum GNUNET_NAT_AddressClass ac,
const struct sockaddr *addr,
socklen_t addrlen)
{
+ (void) cls;
+ (void) app_ctx;
+
fprintf (stdout,
"%s %s (%d)\n",
add_remove ? "+" : "-",
diff --git a/src/nat/nat_api.c b/src/nat/nat_api.c
index 6ae689b63..04fa366aa 100644
--- a/src/nat/nat_api.c
+++ b/src/nat/nat_api.c
@@ -49,6 +49,12 @@ struct AddrEntry
struct AddrEntry *prev;
/**
+ * Place where the application can store data (on add,
+ * and retrieve on remove).
+ */
+ void *app_ctx;
+
+ /**
* Address class of the address.
*/
enum GNUNET_NAT_AddressClass ac;
@@ -148,6 +154,7 @@ reconnect (struct GNUNET_NAT_Handle *nh)
nh->ae_tail,
ae);
nh->address_callback (nh->callback_cls,
+ &ae->app_ctx,
GNUNET_NO,
ae->ac,
(const struct sockaddr *) &ae[1],
@@ -299,6 +306,7 @@ handle_address_change_notification (void *cls,
GNUNET_free (ae);
}
nh->address_callback (nh->callback_cls,
+ &ae->app_ctx,
ntohl (acn->add_remove),
ac,
sa,
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 @@
*
* TODO:
* - NAT service API change to handle address stops!
- * - address construction for HELLOs (FIXMEs, easy)
+ * - support NAT connection reversal method
+ * - support other TCP-specific NAT traversal methods
*/
#include "platform.h"
#include "gnunet_util_lib.h"
@@ -1241,9 +1242,17 @@ tcp_address_to_sockaddr (const char *bindto,
{
/* try IPv6 */
struct sockaddr_in6 v6;
+ const char *start;
+ start = cp;
+ if ( ('[' == *cp) &&
+ (']' == cp[strlen (cp)-1]) )
+ {
+ start++; /* skip over '[' */
+ cp[strlen (cp) -1] = '\0'; /* eat ']' */
+ }
if (1 == inet_pton (AF_INET6,
- cp,
+ start,
&v6))
{
v6.sin6_port = htons ((uint16_t) port);
@@ -1574,17 +1583,17 @@ boot_queue (struct Queue *queue,
{
case AF_INET:
GNUNET_asprintf (&foreign_addr,
- "%s-%s:%d",
+ "%s-%s",
COMMUNICATOR_ADDRESS_PREFIX,
- "inet-ntop-FIXME",
- 4242);
+ GNUNET_a2s(queue->address,
+ queue->address_len));
break;
case AF_INET6:
GNUNET_asprintf (&foreign_addr,
- "%s-%s:%d",
+ "%s-%s",
COMMUNICATOR_ADDRESS_PREFIX,
- "inet-ntop-FIXME",
- 4242);
+ GNUNET_a2s(queue->address,
+ queue->address_len));
break;
default:
GNUNET_assert (0);
@@ -2154,6 +2163,8 @@ enc_notify_cb (void *cls,
* a function to call whenever our set of 'valid' addresses changes.
*
* @param cls closure
+ * @param app_ctx[in,out] location where the app can store stuff
+ * on add and retrieve it on remove
* @param add_remove #GNUNET_YES to add a new public IP address,
* #GNUNET_NO to remove a previous (now invalid) one
* @param ac address class the address belongs to
@@ -2162,6 +2173,7 @@ enc_notify_cb (void *cls,
*/
static void
nat_address_cb (void *cls,
+ void **app_ctx,
int add_remove,
enum GNUNET_NAT_AddressClass ac,
const struct sockaddr *addr,
@@ -2211,7 +2223,9 @@ run (void *cls,
char *bindto;
struct sockaddr *in;
socklen_t in_len;
-
+ struct sockaddr_storage in_sto;
+ socklen_t sto_len;
+
(void) cls;
cfg = c;
if (GNUNET_OK !=
@@ -2267,11 +2281,26 @@ run (void *cls,
GNUNET_free (bindto);
return;
}
+ /* We might have bound to port 0, allowing the OS to figure it out;
+ thus, get the real IN-address from the socket */
+ sto_len = sizeof (in_sto);
+ if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
+ (struct sockaddr *) &in_sto,
+ &sto_len))
+ {
+ memcpy (&in_sto,
+ in,
+ in_len);
+ sto_len = in_len;
+ }
GNUNET_free (in);
+ GNUNET_free (bindto);
+ in = (struct sockaddr *) &in_sto;
+ in_len = sto_len;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Bound to `%s'\n",
- bindto);
- GNUNET_free (bindto);
+ GNUNET_a2s ((const struct sockaddr *) &in_sto,
+ sto_len));
stats = GNUNET_STATISTICS_create ("C-TCP",
cfg);
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,
* Our external IP address/port mapping has changed.
*
* @param cls closure, the 'struct LocalAddrList'
+ * @param app_ctx[in,out] location where the app can store stuff
+ * on add and retrieve it on remove
* @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
* the previous (now invalid) one
* @param ac address class the address belongs to
@@ -2543,6 +2545,7 @@ server_remove_address (void *cls,
*/
static void
server_nat_port_map_callback (void *cls,
+ void **app_ctx,
int add_remove,
enum GNUNET_NAT_AddressClass ac,
const struct sockaddr *addr,
@@ -2550,6 +2553,7 @@ server_nat_port_map_callback (void *cls,
{
struct HTTP_Server_Plugin *plugin = cls;
+ (void) app_ctx;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"NAT called to %s address `%s'\n",
(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,
* Our external IP address/port mapping has changed.
*
* @param cls closure, the `struct Plugin`
+ * @param app_ctx[in,out] location where the app can store stuff
+ * on add and retrieve it on remove
* @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
* the previous (now invalid) one
* @param ac address class the address belongs to
@@ -1438,6 +1440,7 @@ notify_session_monitor (struct Plugin *plugin,
*/
static void
tcp_nat_port_map_callback (void *cls,
+ void **app_ctx,
int add_remove,
enum GNUNET_NAT_AddressClass ac,
const struct sockaddr *addr,
@@ -1450,6 +1453,7 @@ tcp_nat_port_map_callback (void *cls,
void *arg;
size_t args;
+ (void) app_ctx;
LOG (GNUNET_ERROR_TYPE_INFO,
"NAT notification to %s address `%s'\n",
(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,
* Our external IP address/port mapping has changed.
*
* @param cls closure, the `struct Plugin`
+ * @param app_ctx[in,out] location where the app can store stuff
+ * on add and retrieve it on remove
* @param add_remove #GNUNET_YES to mean the new public IP address,
* #GNUNET_NO to mean the previous (now invalid) one
* @param ac address class the address belongs to
@@ -1317,6 +1319,7 @@ udp_plugin_check_address (void *cls,
*/
static void
udp_nat_port_map_callback (void *cls,
+ void **app_ctx,
int add_remove,
enum GNUNET_NAT_AddressClass ac,
const struct sockaddr *addr,
@@ -1329,6 +1332,7 @@ udp_nat_port_map_callback (void *cls,
void *arg;
size_t args;
+ (void) app_ctx;
LOG (GNUNET_ERROR_TYPE_DEBUG,
(GNUNET_YES == add_remove)
? "NAT notification to add address `%s'\n"