[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r12798 - in gnunet: . src/include src/nat
From: |
gnunet |
Subject: |
[GNUnet-SVN] r12798 - in gnunet: . src/include src/nat |
Date: |
Wed, 1 Sep 2010 15:36:01 +0200 |
Author: grothoff
Date: 2010-09-01 15:36:01 +0200 (Wed, 01 Sep 2010)
New Revision: 12798
Removed:
gnunet/src/nat/libnatpmp/
gnunet/src/nat/miniupnp/
Modified:
gnunet/configure.ac
gnunet/src/include/gnunet_nat_lib.h
gnunet/src/nat/Makefile.am
gnunet/src/nat/nat.c
gnunet/src/nat/natpmp.h
gnunet/src/nat/upnp.c
gnunet/src/nat/upnp.h
Log:
starting NAT code cleanup
Modified: gnunet/configure.ac
===================================================================
--- gnunet/configure.ac 2010-09-01 13:21:45 UTC (rev 12797)
+++ gnunet/configure.ac 2010-09-01 13:36:01 UTC (rev 12798)
@@ -753,8 +753,6 @@
src/hostlist/Makefile
src/monkey/Makefile
src/nat/Makefile
-src/nat/libnatpmp/Makefile
-src/nat/miniupnp/Makefile
src/peerinfo/Makefile
src/peerinfo-tool/Makefile
src/statistics/Makefile
Modified: gnunet/src/include/gnunet_nat_lib.h
===================================================================
--- gnunet/src/include/gnunet_nat_lib.h 2010-09-01 13:21:45 UTC (rev 12797)
+++ gnunet/src/include/gnunet_nat_lib.h 2010-09-01 13:36:01 UTC (rev 12798)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
+ (C) 2007, 2008, 2009, 2010 Christian Grothoff (and other contributing
authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -27,30 +27,11 @@
*/
#ifndef GNUNET_NAT_LIB_H
-#define GNUNET_NAT_LIB_H 1
+#define GNUNET_NAT_LIB_H
-#include "platform.h"
#include "gnunet_util_lib.h"
-#include "upnp.h"
-#include "natpmp.h"
-#include <inttypes.h>
-
/**
- * Used to communicate with the UPnP and NAT-PMP plugins
- * FIXME: move to src/nat/common.h
- */
-enum GNUNET_NAT_port_forwarding
- {
- GNUNET_NAT_PORT_ERROR,
- GNUNET_NAT_PORT_UNMAPPED,
- GNUNET_NAT_PORT_UNMAPPING,
- GNUNET_NAT_PORT_MAPPING,
- GNUNET_NAT_PORT_MAPPED
- };
-
-
-/**
* Signature of the callback passed to GNUNET_NAT_register.
*
* @param cls closure
@@ -59,10 +40,12 @@
* @param addr either the previous or the new public IP address
* @param addrlen actual lenght of the address
*/
-typedef void (*GNUNET_NAT_AddressCallback) (void *cls, int add_remove,
+typedef void (*GNUNET_NAT_AddressCallback) (void *cls,
+ int add_remove,
const struct sockaddr * addr,
socklen_t addrlen);
+
/**
* Handle for active NAT registrations.
*/
@@ -81,13 +64,14 @@
* @param callback_cls closure for callback
* @return NULL on error, otherwise handle that can be used to unregister
*/
-struct GNUNET_NAT_Handle *GNUNET_NAT_register (struct GNUNET_SCHEDULER_Handle
- *sched,
- const struct sockaddr *addr,
- socklen_t addrlen,
- GNUNET_NAT_AddressCallback
- callback, void *callback_cls);
+struct GNUNET_NAT_Handle *
+GNUNET_NAT_register (struct GNUNET_SCHEDULER_Handle *sched,
+ const struct sockaddr *addr,
+ socklen_t addrlen,
+ GNUNET_NAT_AddressCallback callback,
+ void *callback_cls);
+
/**
* Stop port redirection and public IP address detection for the given handle.
* This frees the handle, after having sent the needed commands to close open
ports.
@@ -96,18 +80,6 @@
*/
void GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h);
-/**
- * Compare the sin(6)_addr fields of AF_INET or AF_INET(6) sockaddr.
- * FIXME: move to src/nat/common.h or so.
- *
- * @param a first sockaddr
- * @param b second sockaddr
- * @return 0 if addresses are equal, non-null value otherwise
- */
-int GNUNET_NAT_cmp_addr (const struct sockaddr *a,
- const struct sockaddr *b);
-
-
#endif
/* end of gnunet_nat_lib.h */
Modified: gnunet/src/nat/Makefile.am
===================================================================
--- gnunet/src/nat/Makefile.am 2010-09-01 13:21:45 UTC (rev 12797)
+++ gnunet/src/nat/Makefile.am 2010-09-01 13:36:01 UTC (rev 12798)
@@ -1,4 +1,4 @@
-SUBDIRS = miniupnp libnatpmp
+SUBDIRS = .
INCLUDES = -I$(top_srcdir)/src/include
@@ -12,7 +12,9 @@
if !MINGW
+if HAVE_EXPERIMENTAL
lib_LTLIBRARIES = libgnunetnat.la
+endif
libgnunetnat_la_SOURCES = \
upnp.c upnp.h \
@@ -24,16 +26,16 @@
libgnunetnat_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/nat/miniupnp/libminiupnp.la \
- $(top_builddir)/src/nat/libnatpmp/libnatpmp.la \
- $(GN_LIBINTL) @EXT_LIBS@
+ $(GN_LIBINTL) @EXT_LIBS@
libgnunetnat_la_LDFLAGS = \
$(GN_LIB_LDFLAGS) $(WINFLAGS) \
-version-info 0:0:0
+if HAVE_EXPERIMENTAL
check_PROGRAMS = \
test-nat
+endif
if !DISABLE_TEST_RUN
TESTS = $(check_PROGRAMS)
@@ -46,4 +48,4 @@
$(top_builddir)/src/nat/libgnunetnat.la \
$(top_builddir)/src/util/libgnunetutil.la
-endif
\ No newline at end of file
+endif
Modified: gnunet/src/nat/nat.c
===================================================================
--- gnunet/src/nat/nat.c 2010-09-01 13:21:45 UTC (rev 12797)
+++ gnunet/src/nat/nat.c 2010-09-01 13:36:01 UTC (rev 12798)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2009 Christian Grothoff (and other contributing authors)
+ (C) 2009, 2010 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -31,152 +31,161 @@
*
* @author Milan Bouchet-Valat
*/
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-
-#include <sys/types.h>
-
#include "platform.h"
-#include "gnunet_common.h"
#include "gnunet_util_lib.h"
#include "gnunet_nat_lib.h"
+#include "nat.h"
#include "natpmp.h"
#include "upnp.h"
-/* Component name for logging */
-#define COMP_NAT _("NAT")
-#define DEBUG
-
+/**
+ * Handle for active NAT registrations.
+ */
struct GNUNET_NAT_Handle
{
- int is_enabled;
+ /**
+ * Handle for UPnP operations.
+ */
+ GNUNET_NAT_UPNP_Handle *upnp;
- enum GNUNET_NAT_port_forwarding natpmp_status;
- enum GNUNET_NAT_port_forwarding upnp_status;
-
- int should_change;
- u_short public_port;
-
- GNUNET_NAT_UPNP_Handle *upnp;
+ /**
+ * Handle for NAT PMP operations.
+ */
GNUNET_NAT_NATPMP_Handle *natpmp;
+ /**
+ * Scheduler.
+ */
struct GNUNET_SCHEDULER_Handle *sched;
- GNUNET_SCHEDULER_TaskIdentifier pulse_timer;
- struct sockaddr *local_addr; /* LAN address as passed by the caller */
- struct sockaddr *ext_addr; /* External address as reported by NAT box */
- struct sockaddr *contact_addr; /* External address and port where paquets
are redirected*/
+ /**
+ * LAN address as passed by the caller
+ */
+ struct sockaddr *local_addr;
+
+ /**
+ * External address as reported by NAT box
+ */
+ struct sockaddr *ext_addr;
+
+ /**
+ * External address and port where packets are redirected
+ */
+ struct sockaddr *contact_addr;
+
GNUNET_NAT_AddressCallback callback;
+
+ /**
+ * Closure for 'callback'.
+ */
void *callback_cls;
+
+ GNUNET_SCHEDULER_TaskIdentifier pulse_timer;
+
+ enum GNUNET_NAT_PortState natpmp_status;
+
+ enum GNUNET_NAT_PortState upnp_status;
+
+ int is_enabled;
+
+ int should_change;
+
+ int port_mapped;
+
+ int did_warn;
+
+ uint16_t public_port;
+
};
#ifdef DEBUG
static const char *
-get_nat_state_str (int state)
+get_nat_state_str (enum GNUNET_NAT_PortState state)
{
switch (state)
{
- /* we're in the process of trying to set up port forwarding */
case GNUNET_NAT_PORT_MAPPING:
return "Starting";
-
- /* we've successfully forwarded the port */
case GNUNET_NAT_PORT_MAPPED:
return "Forwarded";
-
- /* we're cancelling the port forwarding */
case GNUNET_NAT_PORT_UNMAPPING:
return "Stopping";
-
- /* the port isn't forwarded */
case GNUNET_NAT_PORT_UNMAPPED:
return "Not forwarded";
-
case GNUNET_NAT_PORT_ERROR:
return "Redirection failed";
+ default:
+ return "not found";
}
-
- return "notfound";
}
#endif
+
static int
get_traversal_status (const struct GNUNET_NAT_Handle * s)
{
return MAX (s->natpmp_status, s->upnp_status);
}
+
/**
* Compare the sin(6)_addr fields of AF_INET or AF_INET(6) sockaddr.
* @param a first sockaddr
* @param b second sockaddr
* @return 0 if addresses are equal, non-null value otherwise */
int
-GNUNET_NAT_cmp_addr (const struct sockaddr *a, const struct sockaddr *b)
+GNUNET_NAT_cmp_addr (const struct sockaddr *a,
+ const struct sockaddr *b)
{
if (!(a && b))
return -1;
-
- if (a->sa_family == AF_INET && b->sa_family == AF_INET)
+ if ( (a->sa_family == AF_INET) && (b->sa_family == AF_INET) )
return memcmp (&(((struct sockaddr_in *) a)->sin_addr),
&(((struct sockaddr_in *) b)->sin_addr),
sizeof (struct in_addr));
- else if (a->sa_family == AF_INET6 && b->sa_family == AF_INET6)
+ if ( (a->sa_family == AF_INET6) && (b->sa_family == AF_INET6) )
return memcmp (&(((struct sockaddr_in6 *) a)->sin6_addr),
&(((struct sockaddr_in6 *) b)->sin6_addr),
sizeof (struct in6_addr));
- else
- return -1;
+ return -1;
}
-/* Deal with a new IP address or port redirection:
+
+/**
+ * Deal with a new IP address or port redirection:
* Send signals with the appropriate sockaddr (IP and port), free and changes
* or nullify the previous sockaddr. Change the port if needed.
*/
static void
-notify_change (struct GNUNET_NAT_Handle *nat, struct sockaddr *addr, int
new_port_mapped)
+notify_change (struct GNUNET_NAT_Handle *nat,
+ struct sockaddr *addr,
+ size_t addrlen,
+ int new_port_mapped)
{
- static int port_mapped = GNUNET_NO;
-
- /* Nothing to do. We already check in nat_pulse() that addr has changed */
- if (new_port_mapped == port_mapped)
+ if (new_port_mapped == nat->port_mapped)
return;
+ nat->port_mapped = new_port_mapped;
- port_mapped = new_port_mapped;
+ if ( (NULL != nat->contact_addr) &&
+ (NULL != nat->callback) )
+ nat->callback (nat->callback_cls,
+ GNUNET_NO,
+ nat->contact_addr,
+ sizeof (nat->contact_addr));
+ GNUNET_free_non_null (nat->contact_addr);
+ nat->contact_addr = NULL;
+ GNUNET_free_non_null (nat->ext_addr);
+ nat->ext_addr = NULL;
+ if (NULL == addr)
+ return;
+ nat->ext_addr = GNUNET_malloc (addrlen);
+ memcpy (nat->ext_addr, addr, addrlen);
- if (nat->contact_addr && nat->callback)
- (*nat->callback) (nat->callback_cls, GNUNET_NO, (struct sockaddr *)
&nat->contact_addr,
- sizeof (nat->contact_addr));
-
- /* At this point, we're sure contact_addr has changed */
- if (nat->contact_addr)
- {
- GNUNET_free (nat->contact_addr);
- nat->contact_addr = NULL;
- }
-
- /* No address, don't signal a new one */
- if (!addr)
- {
- if (nat->ext_addr)
- GNUNET_free (nat->ext_addr);
- nat->ext_addr = NULL;
- return;
- }
- /* Copy the new address and use it */
- else if (addr != nat->ext_addr)
- {
- if (nat->ext_addr)
- GNUNET_free (nat->ext_addr);
- nat->ext_addr = GNUNET_malloc (sizeof (*addr));
- memcpy (nat->ext_addr, addr, sizeof (*addr));
- }
-
/* Recreate the ext_addr:public_port bogus address to pass to the callback */
if (nat->ext_addr->sa_family == AF_INET)
{
- struct sockaddr_in *tmp_addr;
+ struct sockaddr_in tmp_addr;
+
tmp_addr = GNUNET_malloc (sizeof (struct sockaddr_in));
tmp_addr->sin_family = AF_INET;
#ifdef HAVE_SOCKADDR_IN_SIN_LEN
@@ -185,13 +194,16 @@
tmp_addr->sin_port = port_mapped ? htons (nat->public_port) : 0;
tmp_addr->sin_addr = ((struct sockaddr_in *) nat->ext_addr)->sin_addr;
nat->contact_addr = (struct sockaddr *) tmp_addr;
- if (nat->callback)
- (*nat->callback) (nat->callback_cls, GNUNET_YES, nat->contact_addr,
- sizeof (struct sockaddr_in));
+ if (NULL != nat->callback)
+ nat->callback (nat->callback_cls,
+ GNUNET_YES,
+ nat->contact_addr,
+ sizeof (struct sockaddr_in));
}
else if (nat->ext_addr->sa_family == AF_INET6)
{
struct sockaddr_in6 *tmp_addr;
+
tmp_addr = GNUNET_malloc (sizeof (struct sockaddr_in6));
tmp_addr->sin6_family = AF_INET6;
#ifdef HAVE_SOCKADDR_IN_SIN_LEN
@@ -200,23 +212,31 @@
tmp_addr->sin6_port = port_mapped ? htons (nat->public_port) : 0;
tmp_addr->sin6_addr = ((struct sockaddr_in6 *) nat->ext_addr)->sin6_addr;
nat->contact_addr = (struct sockaddr *) tmp_addr;
- if (nat->callback)
- (*nat->callback) (nat->callback_cls, GNUNET_YES, nat->contact_addr,
- sizeof (struct sockaddr_in6));
+ if (NULL != nat->callback)
+ nat->callback (nat->callback_cls,
+ GNUNET_YES,
+ nat->contact_addr,
+ sizeof (struct sockaddr_in6));
}
+ else
+ {
+ GNUNET_break (0);
+ }
}
+
static void
-nat_pulse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+nat_pulse (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_NAT_Handle *nat = cls;
- static int first_warning = GNUNET_YES;
int old_status;
int new_status;
int port_mapped;
struct sockaddr *ext_addr_upnp = NULL;
struct sockaddr *ext_addr_natpmp = NULL;
+ nat->pulse_timer = GNUNET_SCHEDULER_NO_TASK;
old_status = get_traversal_status (nat);
/* Only update the protocol that has been successful until now */
@@ -230,6 +250,7 @@
&ext_addr_natpmp);
else
{
+ /* try both */
nat->upnp_status =
GNUNET_NAT_UPNP_pulse (nat->upnp, nat->is_enabled, GNUNET_YES,
&ext_addr_upnp);
@@ -237,18 +258,17 @@
GNUNET_NAT_NATPMP_pulse (nat->natpmp, nat->is_enabled,
&ext_addr_natpmp);
}
-
new_status = get_traversal_status (nat);
-
- if (old_status != new_status &&
- (new_status == GNUNET_NAT_PORT_UNMAPPED || new_status ==
GNUNET_NAT_PORT_ERROR))
- GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, COMP_NAT,
+ if ( (old_status != new_status) &&
+ ( (new_status == GNUNET_NAT_PORT_UNMAPPED) ||
+ (new_status == GNUNET_NAT_PORT_ERROR) ) )
+ GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
+ "NAT",
_("Port redirection failed: no UPnP or NAT-PMP routers
supporting this feature found\n"));
-
#ifdef DEBUG
if (new_status != old_status)
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, COMP_NAT,
- _("State changed from \"%s\" to \"%s\"\n"),
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "NAT",
+ _("State changed from `%s' to `%s'\n"),
get_nat_state_str (old_status),
get_nat_state_str (new_status));
#endif
@@ -257,53 +277,64 @@
if (!(ext_addr_upnp || ext_addr_natpmp))
{
/* Address has just changed and we could not get it, or it's the first
try */
- if (nat->ext_addr || first_warning)
+ if ( (NULL != nat->ext_addr) ||
+ (GNUNET_NO == nat->did_warn) )
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, COMP_NAT,
- _("Could not determine external IP address\n"));
- first_warning = GNUNET_NO;
+ GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
+ "NAT",
+ _("Could not determine external IP address\n"));
+ nat->did_warn = GNUNET_YES;
}
-
notify_change (nat, NULL, port_mapped);
}
else if (ext_addr_upnp && GNUNET_NAT_cmp_addr (nat->ext_addr, ext_addr_upnp)
!= 0)
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, COMP_NAT,
- _("External IP address changed from %s to %s\n"),
- GNUNET_a2s (nat->ext_addr, sizeof (nat->ext_addr)),
- GNUNET_a2s (ext_addr_upnp, sizeof (ext_addr_upnp)));
-
+ GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
+ "NAT",
+ _("External IP address changed to %s\n"),
+ GNUNET_a2s (ext_addr_upnp, sizeof (ext_addr_upnp)));
notify_change (nat, ext_addr_upnp, port_mapped);
}
else if (ext_addr_natpmp && GNUNET_NAT_cmp_addr (nat->ext_addr,
ext_addr_natpmp) != 0)
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, COMP_NAT,
- _("External IP address changed from %s to %s\n"),
- GNUNET_a2s (nat->ext_addr, sizeof (nat->ext_addr)),
- GNUNET_a2s (ext_addr_natpmp, sizeof (ext_addr_natpmp)));
-
+ GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "NAT",
+ _("External IP address changed to `%s'\n"),
+ GNUNET_a2s (ext_addr_natpmp, sizeof (ext_addr_natpmp)));
notify_change (nat, ext_addr_natpmp, port_mapped);
}
-
nat->pulse_timer = GNUNET_SCHEDULER_add_delayed (nat->sched,
GNUNET_TIME_UNIT_SECONDS,
&nat_pulse, nat);
}
+
+/**
+ * Attempt to enable port redirection and detect public IP address contacting
+ * UPnP or NAT-PMP routers on the local network. Use addr to specify to which
+ * of the local host's addresses should the external port be mapped. The port
+ * is taken from the corresponding sockaddr_in[6] field.
+ *
+ * @param sched the sheduler used in the program
+ * @param addr the local address packets should be redirected to
+ * @param addrlen actual lenght of the address
+ * @param callback function to call everytime the public IP address changes
+ * @param callback_cls closure for callback
+ * @return NULL on error, otherwise handle that can be used to unregister
+ */
struct GNUNET_NAT_Handle *
GNUNET_NAT_register (struct GNUNET_SCHEDULER_Handle *sched,
const struct sockaddr *addr, socklen_t addrlen,
GNUNET_NAT_AddressCallback callback, void *callback_cls)
{
- struct GNUNET_NAT_Handle *nat = GNUNET_malloc (sizeof (struct
GNUNET_NAT_Handle));
+ struct GNUNET_NAT_Handle *nat;
+ nat = GNUNET_malloc (sizeof (struct GNUNET_NAT_Handle));
if (addr)
{
- GNUNET_assert (addr->sa_family == AF_INET
- || addr->sa_family == AF_INET6);
+ GNUNET_assert ( (addr->sa_family == AF_INET) ||
+ (addr->sa_family == AF_INET6) );
nat->local_addr = GNUNET_malloc (addrlen);
memcpy (nat->local_addr, addr, addrlen);
-
if (addr->sa_family == AF_INET)
{
nat->public_port = ntohs (((struct sockaddr_in *) addr)->sin_port);
@@ -315,12 +346,6 @@
((struct sockaddr_in6 *) nat->local_addr)->sin6_port = 0;
}
}
- else
- {
- nat->local_addr = NULL;
- nat->public_port = 0;
- }
-
nat->should_change = GNUNET_YES;
nat->sched = sched;
nat->is_enabled = GNUNET_YES;
@@ -328,37 +353,41 @@
nat->natpmp_status = GNUNET_NAT_PORT_UNMAPPED;
nat->callback = callback;
nat->callback_cls = callback_cls;
- nat->ext_addr = NULL;
- nat->contact_addr = NULL;
nat->natpmp = GNUNET_NAT_NATPMP_init (nat->local_addr, addrlen,
nat->public_port);
nat->upnp = GNUNET_NAT_UPNP_init (nat->local_addr, addrlen,
nat->public_port);
-
nat->pulse_timer = GNUNET_SCHEDULER_add_delayed (sched,
GNUNET_TIME_UNIT_SECONDS,
&nat_pulse, nat);
-
return nat;
}
+
+/**
+ * Stop port redirection and public IP address detection for the given handle.
+ * This frees the handle, after having sent the needed commands to close open
ports.
+ *
+ * @param h the handle to stop
+ */
void
GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *nat)
{
struct sockaddr *addr;
- GNUNET_SCHEDULER_cancel (nat->sched, nat->pulse_timer);
+ GNUNET_SCHEDULER_cancel (nat->sched,
+ nat->pulse_timer);
nat->upnp_status =
- GNUNET_NAT_UPNP_pulse (nat->upnp, GNUNET_NO, GNUNET_NO,
+ GNUNET_NAT_UPNP_pulse (nat->upnp,
+ GNUNET_NO, GNUNET_NO,
&addr);
nat->natpmp_status =
GNUNET_NAT_NATPMP_pulse (nat->natpmp, GNUNET_NO,
&addr);
-
GNUNET_NAT_NATPMP_close (nat->natpmp);
GNUNET_NAT_UPNP_close (nat->upnp);
-
- if (nat->local_addr)
- GNUNET_free (nat->local_addr);
- if (nat->ext_addr)
- GNUNET_free (nat->ext_addr);
+ GNUNET_free_non_null (nat->local_addr);
+ GNUNET_free_non_null (nat->ext_addr);
GNUNET_free (nat);
}
+
+/* end of nat.c */
+
Modified: gnunet/src/nat/natpmp.h
===================================================================
--- gnunet/src/nat/natpmp.h 2010-09-01 13:21:45 UTC (rev 12797)
+++ gnunet/src/nat/natpmp.h 2010-09-01 13:36:01 UTC (rev 12798)
@@ -30,15 +30,18 @@
#include "platform.h"
-typedef struct GNUNET_NAT_NATPMP_Handle GNUNET_NAT_NATPMP_Handle;
+struct GNUNET_NAT_NATPMP_Handle;
-GNUNET_NAT_NATPMP_Handle *GNUNET_NAT_NATPMP_init (const struct sockaddr *addr,
- socklen_t addrlen,
- unsigned short port);
+struct GNUNET_NAT_NATPMP_Handle *
+GNUNET_NAT_NATPMP_init (const struct sockaddr *addr,
+ socklen_t addrlen,
+ unsigned short port);
-void GNUNET_NAT_NATPMP_close (GNUNET_NAT_NATPMP_Handle * nat);
+void GNUNET_NAT_NATPMP_close (struct GNUNET_NAT_NATPMP_Handle * nat);
-int GNUNET_NAT_NATPMP_pulse (GNUNET_NAT_NATPMP_Handle * nat, int is_enabled,
+int GNUNET_NAT_NATPMP_pulse (struct GNUNET_NAT_NATPMP_Handle * nat,
+ int is_enabled,
struct sockaddr **ext_addr);
-#endif /* NATPMP_H */
+#endif
+/* NATPMP_H */
Modified: gnunet/src/nat/upnp.c
===================================================================
--- gnunet/src/nat/upnp.c 2010-09-01 13:21:45 UTC (rev 12797)
+++ gnunet/src/nat/upnp.c 2010-09-01 13:36:01 UTC (rev 12798)
@@ -46,15 +46,14 @@
/* Component name for logging */
#define COMP_NAT_UPNP _("NAT (UPnP)")
-typedef enum
+enum UPNP_State
{
UPNP_IDLE,
UPNP_ERR,
UPNP_DISCOVER,
UPNP_MAP,
UPNP_UNMAP
-}
-UPNP_state;
+};
struct GNUNET_NAT_UPNP_Handle
{
@@ -65,7 +64,7 @@
const struct sockaddr *addr;
socklen_t addrlen;
unsigned int is_mapped;
- UPNP_state state;
+ enum UPNP_State state;
struct sockaddr *ext_addr;
const char *iface;
};
@@ -81,35 +80,37 @@
if (addr && GNUNET_NAT_cmp_addr (upnp->addr, addr) == 0)
{
- upnp->iface = name;
+ upnp->iface = name; // BADNESS!
return GNUNET_SYSERR;
}
return GNUNET_OK;
}
+
GNUNET_NAT_UPNP_Handle *
-GNUNET_NAT_UPNP_init (const struct sockaddr *addr, socklen_t addrlen,
+GNUNET_NAT_UPNP_init (const struct sockaddr *addr,
+ socklen_t addrlen,
u_short port)
{
- GNUNET_NAT_UPNP_Handle *upnp =
- GNUNET_malloc (sizeof (GNUNET_NAT_UPNP_Handle));
+ GNUNET_NAT_UPNP_Handle *upnp;
+ upnp = GNUNET_malloc (sizeof (GNUNET_NAT_UPNP_Handle));
upnp->state = UPNP_DISCOVER;
upnp->addr = addr;
upnp->addrlen = addrlen;
upnp->port = port;
-
/* Find the interface corresponding to the address,
* on which we should broadcast call for routers */
- upnp->iface = NULL;
- GNUNET_OS_network_interfaces_list (process_if, upnp);
+ GNUNET_OS_network_interfaces_list (&process_if, upnp);
if (!upnp->iface)
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, COMP_NAT_UPNP, "Could not
find an interface matching the wanted address.\n");
-
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ COMP_NAT_UPNP,
+ "Could not find an interface matching the wanted
address.\n");
return upnp;
}
+
void
GNUNET_NAT_UPNP_close (GNUNET_NAT_UPNP_Handle * handle)
{
Modified: gnunet/src/nat/upnp.h
===================================================================
--- gnunet/src/nat/upnp.h 2010-09-01 13:21:45 UTC (rev 12797)
+++ gnunet/src/nat/upnp.h 2010-09-01 13:36:01 UTC (rev 12798)
@@ -30,14 +30,19 @@
#include "platform.h"
-typedef struct GNUNET_NAT_UPNP_Handle GNUNET_NAT_UPNP_Handle;
+struct GNUNET_NAT_UPNP_Handle;
-GNUNET_NAT_UPNP_Handle *GNUNET_NAT_UPNP_init (const struct sockaddr *addr,
- socklen_t addrlen,
- unsigned short port);
+struct GNUNET_NAT_UPNP_Handle *
+GNUNET_NAT_UPNP_init (const struct sockaddr *addr,
+ socklen_t addrlen,
+ unsigned short port);
-void GNUNET_NAT_UPNP_close (GNUNET_NAT_UPNP_Handle *);
+void GNUNET_NAT_UPNP_close (struct GNUNET_NAT_UPNP_Handle * h);
-int GNUNET_NAT_UPNP_pulse (GNUNET_NAT_UPNP_Handle *, int is_enabled,
- int do_port_check, struct sockaddr **ext_addr);
-#endif /* UPNP_H */
+int GNUNET_NAT_UPNP_pulse (struct GNUNET_NAT_UPNP_Handle *h,
+ int is_enabled,
+ int do_port_check,
+ struct sockaddr **ext_addr);
+
+#endif
+/* UPNP_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r12798 - in gnunet: . src/include src/nat,
gnunet <=