From d39684ffb508e1697abb283413c9bbbee978b49d Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 25 Dec 2016 18:35:15 +0100 Subject: ensure nat clients get notifications on disconnect about 'lost' addresses --- doc/man/gnunet-nat.1 | 4 ++-- src/nat/gnunet-service-nat.c | 4 ++-- src/nat/nat_api.c | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/doc/man/gnunet-nat.1 b/doc/man/gnunet-nat.1 index 484537eb0..2ba236399 100644 --- a/doc/man/gnunet-nat.1 +++ b/doc/man/gnunet-nat.1 @@ -67,7 +67,7 @@ Watch for connection reversal requests. \fBBasic examples\fR -We are bound to "0.0.0.0:8080" on UDP and want to obtain all applicable IP addresses (BUG: sometimes upnpc fails to create mapping, cause unclear): +We are bound to "0.0.0.0:8080" on UDP and want to obtain all applicable IP addresses: # gnunet-nat -i 0.0.0.0:8080 -u @@ -75,7 +75,7 @@ We are bound to "::0" on port 8080 on TCP and want to obtain all applicable IP a # gnunet-nat -i '[::0]':8080 -t -We are bound to "127.0.0.1:8080" on UDP and want to obtain all applicable IP addresses (BUG: currently fails, also gives IPs from other interfaces in output!): +We are bound to "127.0.0.1:8080" on UDP and want to obtain all applicable IP addresses: # gnunet-nat -i 127.0.0.1:8080 -u diff --git a/src/nat/gnunet-service-nat.c b/src/nat/gnunet-service-nat.c index e7173e57a..5b5a108eb 100644 --- a/src/nat/gnunet-service-nat.c +++ b/src/nat/gnunet-service-nat.c @@ -28,8 +28,8 @@ * knowledge about the local network topology. * * TODO: - * - TEST UPnPC/PMP-based NAT traversal - * - implement STUN processing to classify NAT; + * - test ICMP based NAT traversal + * - implement & test STUN processing to classify NAT; * basically, open port & try different methods. * - implement "more" autoconfig * - implement NEW logic for external IP detection diff --git a/src/nat/nat_api.c b/src/nat/nat_api.c index 3fe97ed85..481bc6fde 100644 --- a/src/nat/nat_api.c +++ b/src/nat/nat_api.c @@ -48,6 +48,11 @@ struct AddrEntry */ struct AddrEntry *prev; + /** + * Address class of the address. + */ + enum GNUNET_NAT_AddressClass ac; + /** * Number of bytes that follow. */ @@ -130,11 +135,25 @@ do_connect (void *cls); static void reconnect (struct GNUNET_NAT_Handle *nh) { + struct AddrEntry *ae; + if (NULL != nh->mq) { GNUNET_MQ_destroy (nh->mq); nh->mq = NULL; } + while (NULL != (ae = nh->ae_head)) + { + GNUNET_CONTAINER_DLL_remove (nh->ae_head, + nh->ae_tail, + ae); + nh->address_callback (nh->callback_cls, + GNUNET_NO, + ae->ac, + (const struct sockaddr *) &ae[1], + ae->addrlen); + GNUNET_free (ae); + } nh->reconnect_delay = GNUNET_TIME_STD_BACKOFF (nh->reconnect_delay); nh->reconnect_task @@ -260,6 +279,7 @@ handle_address_change_notification (void *cls, if (GNUNET_YES == ntohl (acn->add_remove)) { ae = GNUNET_malloc (sizeof (*ae) + alen); + ae->ac = ac; ae->addrlen = alen; GNUNET_memcpy (&ae[1], sa, -- cgit v1.2.3