[or-cvs] r14339: Update patch to also disable port forwarding when Vidalia ce (torbrowser/trunk/src/current-patches)
sjm217 at seul.org
sjm217 at seul.org
Wed Apr 9 20:43:21 UTC 2008
Author: sjm217
Date: 2008-04-09 16:43:21 -0400 (Wed, 09 Apr 2008)
New Revision: 14339
Modified:
torbrowser/trunk/src/current-patches/vidalia-miniupnp.patch
Log:
Update patch to also disable port forwarding when Vidalia ceases to be a server
Modified: torbrowser/trunk/src/current-patches/vidalia-miniupnp.patch
===================================================================
--- torbrowser/trunk/src/current-patches/vidalia-miniupnp.patch 2008-04-09 20:33:20 UTC (rev 14338)
+++ torbrowser/trunk/src/current-patches/vidalia-miniupnp.patch 2008-04-09 20:43:21 UTC (rev 14339)
@@ -1,299 +1,185 @@
-Index: INSTALL
-===================================================================
---- INSTALL (revision 2465)
-+++ INSTALL (working copy)
-@@ -206,3 +206,8 @@
- 'cmake --help' or 'man cmake' (on non-Windows platforms) for more information
- about supported generators and configuration options.
-
-+Including UPnP support
-+----------------------
-+
-+cmake -G "MSYS Makefiles" -DMINIUPNPC_LIBRARY_DIR="/usr/local/lib" -DMINIUPNPC_INCLUDE_DIR="/usr/local/include" .
-+
-Index: src/vidalia/CMakeLists.txt
-===================================================================
---- src/vidalia/CMakeLists.txt (revision 2473)
-+++ src/vidalia/CMakeLists.txt (working copy)
-@@ -16,6 +16,7 @@
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/config
- ${CMAKE_CURRENT_SOURCE_DIR}/help/browser
-+ ${MINIUPNPC_INCLUDE_DIR}
- )
- configure_file(
- ${CMAKE_CURRENT_SOURCE_DIR}/res/vidalia_win.rc.in
-@@ -61,6 +62,7 @@
- config/portvalidator.cpp
- config/serverpage.cpp
- config/serversettings.cpp
-+ config/upnpcontrol.cpp
- config/torsettings.cpp
- config/vidaliasettings.cpp
- config/vsettings.cpp
-@@ -80,6 +82,7 @@
- config/portvalidator.h
- config/serverpage.h
- config/serversettings.h
-+ config/upnpcontrol.h
- config/torsettings.h
- config/vidaliasettings.h
- config/vsettings.h
-@@ -234,9 +237,16 @@
- endif(APPLE)
- add_dependencies(${vidalia_BIN} translations)
-
-+## Link in miniupnpc
-+find_library(MINIUPNPC
-+ NAMES miniupnpc
-+ PATHS ${MINIUPNPC_LIBRARY_DIR}
-+)
-+
- ## Link to the Qt libraries and other libraries built as a part of Vidalia
- target_link_libraries(${vidalia_BIN}
- ${QT_LIBRARIES}
-+ ${MINIUPNPC}
- torcontrol
- util
- )
Index: src/vidalia/config/serversettings.cpp
===================================================================
---- src/vidalia/config/serversettings.cpp (revision 2473)
+--- src/vidalia/config/serversettings.cpp (revision 2498)
+++ src/vidalia/config/serversettings.cpp (working copy)
-@@ -20,6 +20,7 @@
-
- #include "serversettings.h"
- #include "torsettings.h"
-+#include "upnpcontrol.h"
-
- /** Define the set of characters that are valid in a nickname. */
- #define VALID_NICKNAME_CHARS \
-@@ -130,6 +131,9 @@
- bool rc;
-
+@@ -137,7 +137,7 @@
if (isServerEnabled()) {
-+ /* Configure UPnP device to forward DirPort and OrPort */
-+ /* TODO: does isServerEnabled() return true when a server is just set up? */
-+ configurePortForwarding();
+ /* Configure UPnP device to forward DirPort and OrPort */
+ /* TODO: does isServerEnabled() return true when a server is just set up? */
+- configurePortForwarding();
++ configurePortForwarding(true);
rc = torControl()->setConf(confValues(), errmsg);
} else {
QStringList resetKeys;
-@@ -152,6 +156,17 @@
+@@ -156,6 +156,7 @@
+ << SETTING_BANDWIDTH_BURST;
+ }
+ rc = torControl()->resetConf(resetKeys, errmsg);
++ configurePortForwarding(false);
+ }
return rc;
}
-
-+/* TODO: We should call this periodically, in case the router gets rebooted or forgets its UPnP settings */
-+/* TODO: Remove port forwarding when Tor is shutdown or the ORPort changes */
-+/* TODO: init_upnp() will block for up to 2 seconds. We should fire off a thread */
-+/** Configure UPnP device to forward DirPort and ORPort */
-+void
-+ServerSettings::configurePortForwarding()
-+{
-+ UPNPControl *pUNPControl = UPNPControl::Instance();
-+ pUNPControl->forwardPort(getORPort());
-+}
+@@ -165,11 +166,16 @@
+ /* TODO: init_upnp() will block for up to 2 seconds. We should fire off a thread */
+ /** Configure UPnP device to forward DirPort and ORPort */
+ void
+-ServerSettings::configurePortForwarding()
++ServerSettings::configurePortForwarding(boolean enable)
+ {
+ #ifdef USE_MINIUPNPC
+ UPNPControl *pUNPControl = UPNPControl::Instance();
+- pUNPControl->forwardPort(getORPort());
+
- /** Virtual method called when we retrieve a server-related setting from Tor.
- * Currently this just translates BandwidthFoo to RelayBandwidthFoo when
- * appropriate. */
++ if (enable) {
++ pUNPControl->forwardPort(getORPort());
++ } else {
++ pUNPControl->disableForwarding();
++ }
+ #endif
+ }
+
Index: src/vidalia/config/serversettings.h
===================================================================
---- src/vidalia/config/serversettings.h (revision 2473)
+--- src/vidalia/config/serversettings.h (revision 2498)
+++ src/vidalia/config/serversettings.h (working copy)
-@@ -91,6 +91,9 @@
- private:
- /** Returns Tor-recognizable configuration keys and current values. */
+@@ -93,7 +93,7 @@
QHash<QString,QString> confValues();
-+
-+ /** Configure UPnP device to forward DirPort and ORPort */
-+ void configurePortForwarding();
+
+ /** Configure UPnP device to forward DirPort and ORPort */
+- void configurePortForwarding();
++ void configurePortForwarding(boolean enable);
};
#endif
Index: src/vidalia/config/upnpcontrol.cpp
===================================================================
---- src/vidalia/config/upnpcontrol.cpp (revision 0)
-+++ src/vidalia/config/upnpcontrol.cpp (revision 0)
-@@ -0,0 +1,129 @@
-+/*
-+** This file is part of Vidalia, and is subject to the license terms in the
-+** LICENSE file, found in the top level directory of this distribution. If
-+** you did not receive the LICENSE file with this file, you may obtain it
-+** from the Vidalia source package distributed by the Vidalia Project at
-+** http://www.vidalia-project.net/. No part of Vidalia, including this file,
-+** may be copied, modified, propagated, or distributed except according to
-+** the terms described in the LICENSE file.
-+*/
+--- src/vidalia/config/upnpcontrol.cpp (revision 2498)
++++ src/vidalia/config/upnpcontrol.cpp (working copy)
+@@ -27,6 +27,7 @@
+ UPNPControl::UPNPControl()
+ {
+ init_upnp();
++ forwardedPort = 0;
+ }
+
+ int
+@@ -68,9 +69,42 @@
+
+ // Output the mapping
+ printf("(external):%s -> %s:%s\n", sPort, intClient, intPort);
++ fflush(stdout);
+
-+/*
-+** \file upnpcontrol.cpp
-+** \version $Id: torcontrol.h 2362 2008-02-29 04:30:11Z edmanm $
-+** \brief Singleton object for interacting with UPNP device
-+*/
++ // Save the mapping
++ forwardedPort = port;
+
-+#include "upnpcontrol.h"
-+
-+UPNPControl* UPNPControl::pInstance = 0;
-+UPNPControl* UPNPControl::Instance()
-+{
-+ if (0 == pInstance)
-+ pInstance = new UPNPControl;
-+ return pInstance;
-+}
-+
-+UPNPControl::UPNPControl()
-+{
-+ init_upnp();
-+}
-+
+ return 0;
+ }
+
+int
-+UPNPControl::forwardPort(quint16 port)
++UPNPControl::disableForwarding()
+{
-+ int retval;
-+
+ char sPort[6];
-+
-+ char intClient[16];
-+ char intPort[6];
+
++ if (0 == forwardedPort)
++ return 0;
++
+ // Convert the port number to a string
-+ snprintf(sPort, sizeof(sPort), "%d", port);
++ snprintf(sPort, sizeof(sPort), "%d", forwardedPort);
+
-+ // Add the port mapping of external:port -> internal:port
-+ retval = UPNP_AddPortMapping(urls.controlURL, data.servicetype,
-+ sPort, sPort, lanaddr, "Tor server", "TCP");
++ int retval = UPNP_DeletePortMapping(urls.controlURL, data.servicetype, sPort, "TCP");
+ if(UPNPCOMMAND_SUCCESS != retval) {
-+ printf("AddPortMapping(%s, %s, %s) failed with code %d\n",
-+ sPort, sPort, lanaddr, retval);
++ printf("DeletePortMapping() failed with code %d\n", retval);
+ return 1;
+ }
-+
-+ // Check if the port mapping was accepted
-+ retval = UPNP_GetSpecificPortMappingEntry(urls.controlURL,
-+ data.servicetype,
-+ sPort, "TCP",
-+ intClient, intPort);
-+ if(UPNPCOMMAND_SUCCESS != retval) {
-+ printf("GetSpecificPortMappingEntry() failed with code %d\n", retval);
-+ return 2;
-+ }
-+
-+ if(! intClient[0]) {
-+ printf("GetSpecificPortMappingEntry failed.\n");
-+ return 3;
-+ }
-+
-+ // Output the mapping
-+ printf("(external):%s -> %s:%s\n", sPort, intClient, intPort);
-+ return 0;
-+}
+
-+/** Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch */
-+void
-+UPNPControl::init_upnp()
-+{
-+ struct UPNPDev * devlist;
-+ int retval;
++ // Output the cancelled mapping
++ printf("(external):%s -> <>\n", sPort);
++ fflush(stdout);
+
-+ printf("TB : init_upnp()\n");
++ // Save the mapping
++ forwardedPort = 0;
+
-+ memset(&urls, 0, sizeof(struct UPNPUrls));
-+ memset(&data, 0, sizeof(struct IGDdatas));
-+
-+ devlist = upnpDiscover(2000, NULL, NULL);
-+ retval = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr));
-+ printf("UPNP: %d", retval);
-+
-+ freeUPNPDevlist(devlist);
++ return 0;
+}
+
-+/** Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch */
-+void
-+UPNPControl::upnp_add_redir(const char * addr, int port)
-+{
-+ char port_str[16];
-+ int r;
-+ printf("TB : upnp_add_redir (%s, %d)\n", addr, port);
-+ if(urls.controlURL[0] == '\0')
-+ {
-+ printf("TB : the init was not done !\n");
-+ fflush(stdout);
-+ return;
-+ }
-+
-+ r = UPNP_AddPortMapping(urls.controlURL, data.servicetype,
-+ port_str, port_str, addr, 0, "TCP");
-+ if(r==0)
-+ printf("AddPortMapping(%s, %s, %s) failed\n", port_str, port_str, addr);
-+ fflush(stdout);
-+}
+
-+/** Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch */
-+void
-+UPNPControl::upnp_rem_redir(int port)
-+{
-+ char port_str[16];
-+ int t;
-+ printf("TB : upnp_rem_redir (%d)\n", port);
-+ if(urls.controlURL[0] == '\0')
-+ {
-+ printf("TB : the init was not done !\n");
-+ fflush(stdout);
-+ return;
-+ }
-+ sprintf(port_str, "%d", port);
-+ UPNP_DeletePortMapping(urls.controlURL, data.servicetype, port_str, "TCP");
-+}
+ /** Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch */
+ void
+ UPNPControl::init_upnp()
+@@ -78,52 +112,13 @@
+ struct UPNPDev * devlist;
+ int retval;
+
+- printf("TB : init_upnp()\n");
+-
+ memset(&urls, 0, sizeof(struct UPNPUrls));
+ memset(&data, 0, sizeof(struct IGDdatas));
+
+ devlist = upnpDiscover(2000, NULL, NULL);
+ retval = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr));
+- printf("UPNP: %d", retval);
++ printf("GetValidIGD returned: %d\n", retval);
++ fflush(stdout);
+
+ freeUPNPDevlist(devlist);
+ }
+-
+-/** Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch */
+-void
+-UPNPControl::upnp_add_redir(const char * addr, int port)
+-{
+- char port_str[16];
+- int r;
+- printf("TB : upnp_add_redir (%s, %d)\n", addr, port);
+- if(urls.controlURL[0] == '\0')
+- {
+- printf("TB : the init was not done !\n");
+- fflush(stdout);
+- return;
+- }
+-
+- r = UPNP_AddPortMapping(urls.controlURL, data.servicetype,
+- port_str, port_str, addr, 0, "TCP");
+- if(r==0)
+- printf("AddPortMapping(%s, %s, %s) failed\n", port_str, port_str, addr);
+- fflush(stdout);
+-}
+-
+-/** Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch */
+-void
+-UPNPControl::upnp_rem_redir(int port)
+-{
+- char port_str[16];
+- int t;
+- printf("TB : upnp_rem_redir (%d)\n", port);
+- if(urls.controlURL[0] == '\0')
+- {
+- printf("TB : the init was not done !\n");
+- fflush(stdout);
+- return;
+- }
+- sprintf(port_str, "%d", port);
+- UPNP_DeletePortMapping(urls.controlURL, data.servicetype, port_str, "TCP");
+-}
Index: src/vidalia/config/upnpcontrol.h
===================================================================
---- src/vidalia/config/upnpcontrol.h (revision 0)
-+++ src/vidalia/config/upnpcontrol.h (revision 0)
-@@ -0,0 +1,48 @@
-+/*
-+** This file is part of Vidalia, and is subject to the license terms in the
-+** LICENSE file, found in the top level directory of this distribution. If
-+** you did not receive the LICENSE file with this file, you may obtain it
-+** from the Vidalia source package distributed by the Vidalia Project at
-+** http://www.vidalia-project.net/. No part of Vidalia, including this file,
-+** may be copied, modified, propagated, or distributed except according to
-+** the terms described in the LICENSE file.
-+*/
+--- src/vidalia/config/upnpcontrol.h (revision 2498)
++++ src/vidalia/config/upnpcontrol.h (working copy)
+@@ -31,6 +31,7 @@
+ public:
+ static UPNPControl* Instance();
+ int forwardPort(quint16 port);
++ int disableForwarding();
+ protected:
+ UPNPControl();
+ private:
+@@ -43,6 +44,9 @@
+ void init_upnp();
+ void upnp_add_redir (const char * addr, int port);
+ void upnp_rem_redir(int port);
+
-+/*
-+** \file upnpcontrol.h
-+** \version $Id: torcontrol.h 2362 2008-02-29 04:30:11Z edmanm $
-+** \brief Singleton object for interacting with UPNP device
-+*/
-+
-+#ifndef _UPNPCONTROL_H
-+#define _UPNPCONTROL_H
-+
-+#include <QObject>
-+
-+#define STATICLIB
-+#include <miniupnpc/miniwget.h>
-+#include <miniupnpc/miniupnpc.h>
-+#include <miniupnpc/upnpcommands.h>
-+
-+class UPNPControl : public QObject
-+{
-+ Q_OBJECT
-+
-+public:
-+ static UPNPControl* Instance();
-+ int forwardPort(quint16 port);
-+protected:
-+ UPNPControl();
-+private:
-+ static UPNPControl* pInstance;
-+
-+ /** Used by miniupnpc library */
-+ struct UPNPUrls urls;
-+ struct IGDdatas data;
-+ char lanaddr[16];
-+ void init_upnp();
-+ void upnp_add_redir (const char * addr, int port);
-+ void upnp_rem_redir(int port);
-+};
-+
-+#endif
++ /* Currently forwarded port */
++ quint16 forwardedPort;
+ };
+
+ #endif
More information about the tor-commits
mailing list