gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r4102 - in GNUnet: . src/transports


From: grothoff
Subject: [GNUnet-SVN] r4102 - in GNUnet: . src/transports
Date: Fri, 29 Dec 2006 07:49:30 -0800 (PST)

Author: grothoff
Date: 2006-12-29 07:49:28 -0800 (Fri, 29 Dec 2006)
New Revision: 4102

Modified:
   GNUnet/src/transports/tcp.c
   GNUnet/src/transports/udp.c
   GNUnet/todo
Log:
enabling UPnP support (not perfect, but may already work)

Modified: GNUnet/src/transports/tcp.c
===================================================================
--- GNUnet/src/transports/tcp.c 2006-12-29 15:41:06 UTC (rev 4101)
+++ GNUnet/src/transports/tcp.c 2006-12-29 15:49:28 UTC (rev 4102)
@@ -27,6 +27,7 @@
 #include "gnunet_util.h"
 #include "gnunet_protocols.h"
 #include "gnunet_transport.h"
+#include "gnunet_upnp_service.h"
 #include "gnunet_stats_service.h"
 #include "platform.h"
 #include "ip.h"
@@ -68,6 +69,8 @@
 
 static TransportAPI tcpAPI;
 
+static UPnP_ServiceAPI * upnp;
+
 static struct CIDRNetwork * filteredNetworks_;
 
 static struct CIDRNetwork * allowedNetworks_;
@@ -255,14 +258,18 @@
   msg = (P2P_hello_MESSAGE *) MALLOC(sizeof(P2P_hello_MESSAGE) + 
sizeof(HostAddress));
   haddr = (HostAddress*) &msg[1];
 
-  if (SYSERR == getPublicIPAddress(cfg,
-                                  ectx,
-                                  &haddr->ip)) {
+  if (! ( ( (upnp != NULL) &&
+           (OK == upnp->get_ip(port,
+                               "TCP",
+                               &haddr->ip)) ) ||
+         (SYSERR != getPublicIPAddress(cfg,
+                                       ectx,
+                                       &haddr->ip)) ) ) {
     FREE(msg);
     GE_LOG(ectx,
           GE_WARNING | GE_ADMIN | GE_USER | GE_BULK,
-          _("Could not determine my public IP address.\n"));
-    return NULL;
+          _("TCP: Could not determine my public IP address.\n"));
+    return NULL;  
   }
 #if DEBUG_TCP
   GE_LOG(ectx,
@@ -540,6 +547,7 @@
     return NULL;
   }
   coreAPI = core;
+  upnp = coreAPI->requestService("upnp");
   stats = coreAPI->requestService("stats");
   if (stats != NULL) {
     stat_bytesReceived
@@ -569,8 +577,14 @@
   GC_detach_change_listener(cfg,
                            &reloadConfiguration,
                            NULL);
-  coreAPI->releaseService(stats);
-  stats = NULL;
+  if (stats != NULL) {
+    coreAPI->releaseService(stats);
+    stats = NULL;
+  }
+  if (upnp != NULL) {
+    coreAPI->releaseService(upnp);
+    upnp = NULL;
+  }
   FREENONNULL(filteredNetworks_);
   FREENONNULL(allowedNetworks_);
   MUTEX_DESTROY(tcplock);

Modified: GNUnet/src/transports/udp.c
===================================================================
--- GNUnet/src/transports/udp.c 2006-12-29 15:41:06 UTC (rev 4101)
+++ GNUnet/src/transports/udp.c 2006-12-29 15:49:28 UTC (rev 4102)
@@ -28,11 +28,14 @@
 #include "gnunet_protocols.h"
 #include "gnunet_transport.h"
 #include "gnunet_stats_service.h"
+#include "gnunet_upnp_service.h"
 #include "ip.h"
 #include "platform.h"
 
 #define DEBUG_UDP NO
 
+static UPnP_ServiceAPI * upnp;
+
 #include "udp_helper.c"
 
 /**
@@ -250,21 +253,28 @@
 static P2P_hello_MESSAGE * createhello() {
   P2P_hello_MESSAGE * msg;
   HostAddress * haddr;
+  unsigned short port;
 
-  if (getGNUnetUDPPort() == 0)
+  port = getGNUnetUDPPort();
+  if (port == 0)
     return NULL; /* UDP transport configured send-only */
 
   msg = MALLOC(sizeof(P2P_hello_MESSAGE) + sizeof(HostAddress));
   haddr = (HostAddress*) &msg[1];
 
-  if (SYSERR == getPublicIPAddress(cfg,
-                                  ectx,
-                                  &haddr->senderIP)) {
+
+  if (! ( ( (upnp != NULL) &&
+           (OK == upnp->get_ip(port,
+                               "UDP",
+                               &haddr->senderIP)) ) ||
+         (SYSERR != getPublicIPAddress(cfg,
+                                       ectx,
+                                       &haddr->senderIP)) ) ) {
+    FREE(msg);
     GE_LOG(ectx,
-          GE_WARNING | GE_ADMIN | GE_BULK,
+          GE_WARNING | GE_ADMIN | GE_USER | GE_BULK,
           _("UDP: Could not determine my public IP address.\n"));
-    FREE(msg);
-    return NULL;
+    return NULL;  
   }
 #if DEBUG_UDP
   GE_LOG(ectx,
@@ -272,7 +282,7 @@
         "UDP uses IP address %u.%u.%u.%u.\n",
         PRIP(ntohl(*(int*)&haddr->senderIP)));
 #endif
-  haddr->senderPort      = htons(getGNUnetUDPPort());
+  haddr->senderPort      = htons(port);
   haddr->reserved        = htons(0);
   msg->senderAddressSize = htons(sizeof(HostAddress));
   msg->protocol          = htons(UDP_PROTOCOL_NUMBER);
@@ -524,6 +534,7 @@
           _("MTU %llu for `%s' is probably too low!\n"),
           mtu,
           "UDP");
+  upnp = coreAPI->requestService("upnp");
   stats = coreAPI->requestService("stats");
   if (stats != NULL) {
     stat_bytesReceived
@@ -552,7 +563,14 @@
 }
 
 void donetransport_udp() {
-  coreAPI->releaseService(stats);
+  if (stats != NULL) {
+    coreAPI->releaseService(stats);
+    stats = NULL;
+  }
+  if (upnp != NULL) {
+    coreAPI->releaseService(upnp);
+    upnp = NULL;
+  }
   MUTEX_DESTROY(configLock);
   configLock = NULL;
   FREENONNULL(filteredNetworks_);

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2006-12-29 15:41:06 UTC (rev 4101)
+++ GNUnet/todo 2006-12-29 15:49:28 UTC (rev 4102)
@@ -15,6 +15,9 @@
 - Windows installer [Nils]
   * uninstall: Remove account
   * libcurl, guile
+- UPnP support:
+  * remove glib dependency from upnp code!
+  * fix xmlnode memory leaks (for invalid / incomplete XML responses)
 
 0.7.2 [3'07]:
 - new features:





reply via email to

[Prev in Thread] Current Thread [Next in Thread]