[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r5000 - GNUnet/src/transports
From: |
gnunet |
Subject: |
[GNUnet-SVN] r5000 - GNUnet/src/transports |
Date: |
Sat, 9 Jun 2007 23:11:44 -0600 (MDT) |
Author: grothoff
Date: 2007-06-09 23:11:44 -0600 (Sat, 09 Jun 2007)
New Revision: 5000
Modified:
GNUnet/src/transports/Makefile.am
GNUnet/src/transports/ip.c
GNUnet/src/transports/ip.h
GNUnet/src/transports/nat.c
GNUnet/src/transports/tcp6.c
GNUnet/src/transports/tcp_helper.c
Log:
try resolving NAT by looking at accept info
Modified: GNUnet/src/transports/Makefile.am
===================================================================
--- GNUnet/src/transports/Makefile.am 2007-06-10 04:28:22 UTC (rev 4999)
+++ GNUnet/src/transports/Makefile.am 2007-06-10 05:11:44 UTC (rev 5000)
@@ -9,7 +9,7 @@
libgnunettransport_tcp6.la \
libgnunettransport_udp6.la
v6ip = \
- libip6.la
+ libgnunetip6.la
endif
if HAVE_XML2
build_upnp=upnp
@@ -22,17 +22,20 @@
SUBDIRS = $(build_upnp) .
noinst_LTLIBRARIES = \
- $(v6ip) \
- libip.la
+ $(v6ip)
+lib_LTLIBRARIES = \
+ libgnunetip.la
+
+
if !MINGW
# smtptransport = libgnunettransport_smtp.la
endif
-libip_la_SOURCES = \
+libgnunetip_la_SOURCES = \
ip.c ip.h
-libip6_la_SOURCES = \
+libgnunetip6_la_SOURCES = \
ip6.c ip6.h
plugin_LTLIBRARIES = \
@@ -51,7 +54,7 @@
libgnunettransport_http_la_LIBADD = \
-lmicrohttpd @LIBCURL@ \
$(top_builddir)/src/util/libgnunetutil.la \
- libip.la
+ libgnunetip.la
libgnunettransport_http_la_LDFLAGS = \
-export-dynamic -avoid-version -module
libgnunettransport_http_la_CPPFLAGS = \
@@ -60,36 +63,37 @@
libgnunettransport_tcp_la_SOURCES = tcp.c
libgnunettransport_tcp_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
- libip.la
+ libgnunetip.la
libgnunettransport_tcp_la_LDFLAGS = \
-export-dynamic -avoid-version -module
libgnunettransport_nat_la_SOURCES = nat.c
libgnunettransport_nat_la_LIBADD = \
- $(top_builddir)/src/util/libgnunetutil.la
+ $(top_builddir)/src/util/libgnunetutil.la \
+ libgnunetip.la
libgnunettransport_nat_la_LDFLAGS = \
-export-dynamic -avoid-version -module
libgnunettransport_udp_la_SOURCES = udp.c
libgnunettransport_udp_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
- libip.la
+ libgnunetip.la
libgnunettransport_udp_la_LDFLAGS = \
-export-dynamic -avoid-version -module
libgnunettransport_tcp6_la_SOURCES = tcp6.c
libgnunettransport_tcp6_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
- libip.la \
- libip6.la
+ libgnunetip.la \
+ libgnunetip6.la
libgnunettransport_tcp6_la_LDFLAGS = \
-export-dynamic -avoid-version -module
libgnunettransport_udp6_la_SOURCES = udp6.c
libgnunettransport_udp6_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
- libip.la \
- libip6.la
+ libgnunetip.la \
+ libgnunetip6.la
libgnunettransport_udp6_la_LDFLAGS = \
-export-dynamic -avoid-version -module
Modified: GNUnet/src/transports/ip.c
===================================================================
--- GNUnet/src/transports/ip.c 2007-06-10 04:28:22 UTC (rev 4999)
+++ GNUnet/src/transports/ip.c 2007-06-10 05:11:44 UTC (rev 5000)
@@ -22,7 +22,7 @@
* @file transports/ip.c
* @brief code to determine thep IP of the local machine
* and to do DNS resolution (with caching)
- *
+ *
* @author Christian Grothoff
* @author Tzvetan Horozov
* @author Heikki Lindholm
@@ -191,13 +191,117 @@
return ret;
}
+struct PICache {
+ struct PICache * next;
+ char * address;
+ PeerIdentity peer;
+ cron_t expire;
+};
+static struct PICache * pi_head;
+
+static void expirePICache() {
+ struct PICache * pos;
+ struct PICache * next;
+ struct PICache * prev;
+ cron_t now;
+
+ now = get_time();
+ pos = pi_head;
+ prev = NULL;
+ while (pos != NULL) {
+ next = pos->next;
+ if (pos->expire < now) {
+ FREE(pos->address);
+ FREE(pos);
+ if (prev == NULL)
+ pi_head = next;
+ else
+ prev->next = next;
+ }
+ prev = pos;
+ pos = next;
+ }
+}
+
+/**
+ * We only have the PeerIdentity. Do we have any
+ * clue about the address (as a string) based on
+ * the "accept" of the connection? Note that the
+ * response is just the best guess.
+ */
+char * getIPaddressFromPID(const PeerIdentity * peer) {
+ char * ret;
+ struct PICache * cache;
+
+ ret = NULL;
+ MUTEX_LOCK(lock);
+ expirePICache();
+ cache = pi_head;
+ while (cache != NULL) {
+ if (0 == memcmp(peer,
+ &cache->peer,
+ sizeof(PeerIdentity))) {
+ ret = STRDUP(cache->address);
+ break;
+ }
+ cache = cache->next;
+ }
+ MUTEX_UNLOCK(lock);
+ return ret;
+}
+
+/**
+ * We have accepted a connection from a particular
+ * address (here given as a string) and received
+ * a welcome message that claims that this connection
+ * came from a particular peer. This information is
+ * NOT validated (and it may well be impossible for
+ * us to validate the address).
+ */
+void setIPaddressFromPID(const PeerIdentity * peer,
+ const char * address) {
+ struct PICache * next;
+
+ MUTEX_LOCK(lock);
+ next = pi_head;
+ while (next != NULL) {
+ if (0 == memcmp(peer,
+ &next->peer,
+ sizeof(PeerIdentity))) {
+ next->expire = get_time() + 12 * cronHOURS;
+ if (0 == strcmp(address,
+ next->address)) {
+ MUTEX_UNLOCK(lock);
+ return;
+ }
+ FREE(next->address);
+ next->address = STRDUP(address);
+ MUTEX_UNLOCK(lock);
+ return;
+ }
+ next = next->next;
+ }
+ next = MALLOC(sizeof(struct PICache));
+ next->peer = *peer;
+ next->address = STRDUP(address);
+ next->expire = get_time() + 12 * cronHOURS;
+ expirePICache();
+ next->next = pi_head;
+ pi_head = next;
+ MUTEX_UNLOCK(lock);
+
+}
+
+
+
void __attribute__ ((constructor)) gnunet_ip_ltdl_init() {
lock = MUTEX_CREATE(YES);
}
void __attribute__ ((destructor)) gnunet_ip_ltdl_fini() {
struct IPCache * pos;
+ struct PICache * ppos;
MUTEX_DESTROY(lock);
while (head != NULL) {
pos = head->next;
@@ -206,6 +310,12 @@
FREE(head);
head = pos;
}
+ while (pi_head != NULL) {
+ ppos = pi_head->next;
+ FREE(pi_head->address);
+ FREE(pi_head);
+ pi_head = ppos;
+ }
}
Modified: GNUnet/src/transports/ip.h
===================================================================
--- GNUnet/src/transports/ip.h 2007-06-10 04:28:22 UTC (rev 4999)
+++ GNUnet/src/transports/ip.h 2007-06-10 05:11:44 UTC (rev 5000)
@@ -58,4 +58,23 @@
char * getIPaddressAsString(const void * sa,
unsigned int salen);
+/**
+ * We only have the PeerIdentity. Do we have any
+ * clue about the address (as a string) based on
+ * the "accept" of the connection? Note that the
+ * response is just the best guess.
+ */
+char * getIPaddressFromPID(const PeerIdentity * peer);
+
+/**
+ * We have accepted a connection from a particular
+ * address (here given as a string) and received
+ * a welcome message that claims that this connection
+ * came from a particular peer. This information is
+ * NOT validated (and it may well be impossible for
+ * us to validate the address).
+ */
+void setIPaddressFromPID(const PeerIdentity * peer,
+ const char * address);
+
#endif
Modified: GNUnet/src/transports/nat.c
===================================================================
--- GNUnet/src/transports/nat.c 2007-06-10 04:28:22 UTC (rev 4999)
+++ GNUnet/src/transports/nat.c 2007-06-10 05:11:44 UTC (rev 5000)
@@ -28,6 +28,7 @@
#include "gnunet_protocols.h"
#include "gnunet_transport.h"
#include "platform.h"
+#include "ip.h"
#define DEBUG_NAT NO
@@ -172,7 +173,21 @@
*/
static char * addressToString(const P2P_hello_MESSAGE * hello,
int do_resolve) {
- return STRDUP("NAT");
+ char * addr;
+ char * ret;
+ size_t n;
+
+ addr = getIPaddressFromPID(&hello->senderIdentity);
+ if (addr == NULL)
+ return STRDUP("NAT");
+ n = strlen(addr) + 10;
+ ret = MALLOC(n);
+ SNPRINTF(ret,
+ n,
+ "%s NAT",
+ addr);
+ FREE(addr);
+ return ret;
}
static int testWouldTry(TSession * tsession,
Modified: GNUnet/src/transports/tcp6.c
===================================================================
--- GNUnet/src/transports/tcp6.c 2007-06-10 04:28:22 UTC (rev 4999)
+++ GNUnet/src/transports/tcp6.c 2007-06-10 05:11:44 UTC (rev 5000)
@@ -336,7 +336,7 @@
* Start the server process to receive inbound traffic.
* @return OK on success, SYSERR if the operation failed
*/
-static int startTransportServer(void) {
+static int startTransportServer() {
struct sockaddr_in6 serverAddr;
const int on = 1;
unsigned short port;
Modified: GNUnet/src/transports/tcp_helper.c
===================================================================
--- GNUnet/src/transports/tcp_helper.c 2007-06-10 04:28:22 UTC (rev 4999)
+++ GNUnet/src/transports/tcp_helper.c 2007-06-10 05:11:44 UTC (rev 5000)
@@ -75,6 +75,10 @@
*/
int in_select;
+ void * accept_addr;
+
+ unsigned int addr_len;
+
} TCPSession;
/* *********** globals ************* */
@@ -120,6 +124,7 @@
if (tcpsession->in_select == NO) {
MUTEX_UNLOCK(tcpsession->lock);
MUTEX_DESTROY(tcpsession->lock);
+ FREENONNULL(tcpsession->accept_addr);
FREE(tcpsession);
FREE(tsession);
} else {
@@ -174,6 +179,7 @@
unsigned int len;
P2P_PACKET * mp;
const TCPWelcome * welcome;
+ char * addr;
if (SYSERR == tcpAssociate(tsession)) {
GE_BREAK(ectx, 0);
@@ -197,6 +203,15 @@
tcpSession->expectingWelcome = NO;
tcpSession->sender = welcome->clientIdentity;
tsession->peer = welcome->clientIdentity;
+ if (tcpSession->accept_addr != NULL) {
+ addr = getIPaddressAsString(tcpSession->accept_addr,
+ tcpSession->addr_len);
+ if (addr != NULL) {
+ setIPaddressFromPID(&welcome->clientIdentity,
+ addr);
+ FREE(addr);
+ }
+ }
} else {
/* send msg to core! */
if (len <= sizeof(MESSAGE_HEADER)) {
@@ -257,11 +272,22 @@
tcpSession->lock = MUTEX_CREATE(YES);
tcpSession->users = 0;
tcpSession->in_select = YES;
+
tsession = MALLOC(sizeof(TSession));
tsession->ttype = TCP_PROTOCOL_NUMBER;
tsession->internal = tcpSession;
tsession->peer = *(coreAPI->myIdentity);
-
+ if (addr_len > sizeof(IPaddr)) {
+ tcpSession->accept_addr = MALLOC(addr_len);
+ memcpy(tcpSession->accept_addr,
+ (struct sockaddr_in*) addr,
+ sizeof(struct sockaddr_in));
+ tcpSession->addr_len = addr_len;
+ } else {
+ GE_BREAK(NULL, 0);
+ tcpSession->addr_len = 0;
+ tcpSession->accept_addr = NULL;
+ }
return tsession;
}
@@ -277,6 +303,7 @@
if (tcpSession->users == 0) {
MUTEX_UNLOCK(tcpSession->lock);
MUTEX_DESTROY(tcpSession->lock);
+ FREENONNULL(tcpSession->accept_addr);
FREE(tcpSession);
FREE(tsession);
} else {
@@ -411,6 +438,8 @@
TCPSession * tcpSession;
tcpSession = MALLOC(sizeof(TCPSession));
+ tcpSession->addr_len = 0;
+ tcpSession->accept_addr = NULL;
tcpSession->sock = s;
tsession = MALLOC(sizeof(TSession));
tsession->internal = tcpSession;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r5000 - GNUnet/src/transports,
gnunet <=