This file is part of GNUnet.
Copyright (C) 2007-2017 GNUnet e.V.
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
+ SPDX-License-Identifier: AGPL3.0-or-later
*/
/**
*/
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;
-
+
/**
* Number of bytes that follow.
*/
* Configuration we use.
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
-
+
/**
* Message queue for communicating with the NAT service.
*/
* Our registration message.
*/
struct GNUNET_MessageHeader *reg;
-
+
/**
* Head of address DLL.
*/
* Function to call when our addresses change.
*/
GNUNET_NAT_AddressCallback address_callback;
-
+
/**
* Function to call when another peer requests connection reversal.
*/
GNUNET_NAT_ReversalCallback reversal_callback;
-
+
/**
* Closure for the various callbacks.
*/
reconnect (struct GNUNET_NAT_Handle *nh)
{
struct AddrEntry *ae;
-
+
if (NULL != nh->mq)
{
GNUNET_MQ_destroy (nh->mq);
nh->ae_tail,
ae);
nh->address_callback (nh->callback_cls,
+ &ae->app_ctx,
GNUNET_NO,
ae->ac,
(const struct sockaddr *) &ae[1],
return GNUNET_OK;
}
-
+
/**
* Handle connection reversal request.
*
return GNUNET_OK;
}
-
+
/**
* Handle connection reversal request.
*
enum GNUNET_NAT_AddressClass ac;
struct AddrEntry *ae;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received address change notification\n");
ac = (enum GNUNET_NAT_AddressClass) ntohl (acn->addr_class);
if (GNUNET_YES == ntohl (acn->add_remove))
{
GNUNET_free (ae);
}
nh->address_callback (nh->callback_cls,
+ &ae->app_ctx,
ntohl (acn->add_remove),
ac,
sa,
struct GNUNET_MQ_Envelope *env;
nh->reconnect_task = NULL;
- nh->mq = GNUNET_CLIENT_connecT (nh->cfg,
+ nh->mq = GNUNET_CLIENT_connect (nh->cfg,
"nat",
handlers,
&mq_error_handler,
size_t len;
size_t str_len;
char *off;
-
+
len = 0;
for (unsigned int i=0;i<num_addrs;i++)
len += addrlens[i];
str_len = strlen (config_section) + 1;
len += str_len;
- if ( (len > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*rm)) ||
+ if ( (len > GNUNET_MAX_MESSAGE_SIZE - sizeof (*rm)) ||
(num_addrs > UINT16_MAX) )
{
GNUNET_break (0);
if (sizeof (struct sockaddr_in) != addrlens[i])
{
GNUNET_break (0);
+ GNUNET_free (rm);
return NULL;
}
break;
if (sizeof (struct sockaddr_in6) != addrlens[i])
{
GNUNET_break (0);
+ GNUNET_free (rm);
return NULL;
}
break;
if (sizeof (struct sockaddr_un) != addrlens[i])
{
GNUNET_break (0);
+ GNUNET_free (rm);
return NULL;
}
break;
#endif
default:
GNUNET_break (0);
+ GNUNET_free (rm);
return NULL;
}
GNUNET_memcpy (off,
*
* The function does some basic sanity checks on packet size and
* content, try to extract a bit of information.
- *
+ *
* At the moment this only processes BIND requests, and returns the
* externally visible address of the request to the rest of the
* NAT logic.
* @param nh handle (used for configuration)
* @param local_sa our local address of the peer (IPv4-only)
* @param remote_sa the remote address of the peer (IPv4-only)
- * @return #GNUNET_SYSERR on error,
+ * @return #GNUNET_SYSERR on error,
* #GNUNET_NO if connection reversal is unavailable,
* #GNUNET_OK otherwise (presumably in progress)
*/
void
GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *nh)
{
- GNUNET_MQ_destroy (nh->mq);
+ if (NULL != nh->mq)
+ {
+ GNUNET_MQ_destroy (nh->mq);
+ nh->mq = NULL;
+ }
+ if (NULL != nh->reconnect_task)
+ {
+ GNUNET_SCHEDULER_cancel (nh->reconnect_task);
+ nh->reconnect_task = NULL;
+ }
GNUNET_free (nh->reg);
GNUNET_free (nh);
}