From 2168e3467756e8a6e73c8a59ee78ba44789c1f9d Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Fri, 4 Jul 2014 00:03:06 -0300 Subject: [PATCH] miniupnp dependency removed, yes! :-) fix #130 libtorrent implements a upnp client: use it to map the other twisterd port. --- Makefile.am | 6 +---- configure.ac | 27 ------------------- doc/build-unix.md | 26 +----------------- .../include/libtorrent/aux_/session_impl.hpp | 1 + libtorrent/src/session_impl.cpp | 11 ++++++++ src/init.cpp | 6 ----- src/main.h | 5 ---- src/makefile.android | 13 --------- src/makefile.freebsd | 12 --------- src/makefile.mingw | 8 ------ src/makefile.osx | 12 --------- src/makefile.unix | 13 --------- src/twister.cpp | 12 +++++---- twister-qt.pro | 17 ------------ 14 files changed, 21 insertions(+), 148 deletions(-) diff --git a/Makefile.am b/Makefile.am index 1feac2b2..21d779a4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -162,17 +162,13 @@ BITCOIN_TWISTER_SOURCES = \ src/twister_utils.cpp \ $(SSE2_SOURCES) -if USE_UPNP -UPNP_LIB = -lminiupnpc -endif - twisterd_SOURCES = $(LIBTORRENT_SOURCES) $(BITCOIN_TWISTER_SOURCES) twisterd_LDFLAGS = @OPENSSL_LDFLAGS@ @DB_CXX_LDFLAGS@ twisterd_DEPENDENCIES = $(LEVELDB_LIB) -twisterd_LDADD = $(LEVELDB_LIB) $(UPNP_LIB) \ +twisterd_LDADD = $(LEVELDB_LIB) \ @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_PROGRAM_OPTIONS_LIB@ @BOOST_THREAD_LIB@ @BOOST_CHRONO_LIB@ @BOOST_LOCALE_LIB@ \ @BOOST_REGEX_LIB@ @DB_CXX_LIBS@ @OPENSSL_LIBS@ diff --git a/configure.ac b/configure.ac index bc8f41d0..1d4b94f1 100644 --- a/configure.ac +++ b/configure.ac @@ -205,16 +205,6 @@ AC_ARG_ENABLE( [[ARG_ENABLE_SSE2=yes]] ) -AC_ARG_ENABLE( - [upnp], - [AS_HELP_STRING( - [--enable-upnp], - [enable miniupnp support [default=yes]])], - [[ARG_ENABLE_UPNP=$enableval]], - [[ARG_ENABLE_UPNP=yes]] -) - - AC_ARG_ENABLE( [pool-allocators], [AS_HELP_STRING( @@ -474,21 +464,6 @@ AS_CASE(["$ARG_ENABLE_SSE2"], AC_MSG_ERROR([Unknown option "$ARG_ENABLE_SSE2". Use either "yes" or "no".])] ) -AC_MSG_CHECKING([whether miniupnp should be enabled]) -AS_CASE(["$ARG_ENABLE_UPNP"], - ["yes"|"on"], [ - AC_MSG_RESULT([yes]) - AC_DEFINE([USE_UPNP],[1],[Enable miniupnp]) - COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DUSE_UPNP=1 " - ], - ["no"|"off"], [ - AC_MSG_RESULT([no]) - ], - [AC_MSG_RESULT([$ARG_ENABLE_UPNP]) - AC_MSG_ERROR([Unknown option "$ARG_ENABLE_UPNP". Use either "yes" or "no".])] -) - - AC_MSG_CHECKING([whether geoip support should be enabled]) AS_CASE(["$ARG_ENABLE_GEOIP"], ["yes"], [ @@ -652,7 +627,6 @@ AM_CONDITIONAL([ENABLE_PYTHON_BINDING], [test "x$ARG_ENABLE_PYTHON_BINDING" = "x AM_CONDITIONAL([WITH_SHIPPED_GEOIP], [test "x$ARG_WITH_LIBGEOIP" = "xno" ]) AM_CONDITIONAL([WITH_OPENSSL], [test "x$ARG_ENABLE_ENCRYPTION" = "xyes" -o "x$ARG_ENABLE_ENCRYPTION" = "xon" ]) AM_CONDITIONAL([USE_SSE2], [test "x$ARG_ENABLE_SSE2" = "xyes" -o "x$ARG_ENABLE_SSE2" = "xon" ]) -AM_CONDITIONAL([USE_UPNP], [test "x$ARG_ENABLE_UPNP" = "xyes" -o "x$ARG_ENABLE_UPNP" = "xon" ]) ############################################################################### # Other useful stuff @@ -751,7 +725,6 @@ Build options: Features: encryption support: ${ARG_ENABLE_ENCRYPTION:-yes} SSE2 Scrypt: ${ARG_ENABLE_SSE2:-yes} - miniupnp support: ${ARG_ENABLE_UPNP:-yes} geoip support: ${ARG_ENABLE_GEOIP:-yes} dht support: ${ARG_ENABLE_DHT:-yes} pool allocators: ${ARG_ENABLE_POOL_ALLOC:-yes} diff --git a/doc/build-unix.md b/doc/build-unix.md index 0b9e4cf1..29db039d 100644 --- a/doc/build-unix.md +++ b/doc/build-unix.md @@ -18,15 +18,6 @@ Dependencies libssl SSL Support Secure communications libdb4.8 Berkeley DB Blockchain & wallet storage libboost Boost C++ Library - miniupnpc UPnP Support Optional firewall-jumping support - -[miniupnpc](http://miniupnp.free.fr/) may be used for UPnP port mapping. It can be downloaded from [here]( -http://miniupnp.tuxfamily.org/files/). UPnP support is compiled in and -turned off by default. Set USE_UPNP to a different value to control this: - - USE_UPNP= No UPnP support miniupnp not required - USE_UPNP=0 (the default) UPnP support turned off by default at runtime - USE_UPNP=1 UPnP support turned on by default at runtime IPv6 support may be disabled by setting: @@ -36,14 +27,12 @@ Licenses of statically linked libraries: Berkeley DB New BSD license with additional requirement that linked software must be free open source Boost MIT-like license - miniupnpc New (3-clause) BSD license - Versions used in this release: - GCC 4.3.3 - OpenSSL 1.0.1c - Berkeley DB 4.8.30.NC - Boost 1.37 -- miniupnpc 1.6 Dependency Build Instructions: Ubuntu & Debian ---------------------------------------------- @@ -69,10 +58,6 @@ for other Ubuntu & Debian: (If using Boost 1.37, append -mt to the boost libraries in the makefile) -Optional: - - sudo apt-get install libminiupnpc-dev (see USE_UPNP compile flag) - Dependency Build Instructions: Gentoo ------------------------------------- @@ -85,7 +70,7 @@ Note: If you just want to install bitcoind on Gentoo, you can add the Bitcoin ov Take the following steps to build (no UPnP support): cd ${BITCOIN_DIR}/src - make -f makefile.unix USE_UPNP= USE_IPV6=1 BDB_INCLUDE_PATH='/usr/include/db4.8' + make -f makefile.unix USE_IPV6=1 BDB_INCLUDE_PATH='/usr/include/db4.8' strip bitcoind @@ -95,15 +80,6 @@ The release is built with GCC and then "strip bitcoind" to strip the debug symbols, which reduces the executable size by about 90%. -miniupnpc ---------- - tar -xzvf miniupnpc-1.6.tar.gz - cd miniupnpc-1.6 - make - sudo su - make install - - Berkeley DB ----------- You need Berkeley DB 4.8. If you have to build Berkeley DB yourself: diff --git a/libtorrent/include/libtorrent/aux_/session_impl.hpp b/libtorrent/include/libtorrent/aux_/session_impl.hpp index 0d269a41..1724749b 100644 --- a/libtorrent/include/libtorrent/aux_/session_impl.hpp +++ b/libtorrent/include/libtorrent/aux_/session_impl.hpp @@ -957,6 +957,7 @@ namespace libtorrent // 0 is natpmp 1 is upnp int m_tcp_mapping[2]; + int m_twister_tcp_mapping[2]; int m_udp_mapping[2]; #ifdef TORRENT_USE_OPENSSL int m_ssl_mapping[2]; diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index 9ca2cfd7..7a7cc281 100644 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -85,6 +85,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/random.hpp" #include "libtorrent/magnet_uri.hpp" +#include "twister.h" // for LIBTORRENT_PORT_OFFSET + #if defined TORRENT_STATS && defined __MACH__ #include #endif @@ -766,6 +768,8 @@ namespace aux { m_tcp_mapping[0] = -1; m_tcp_mapping[1] = -1; + m_twister_tcp_mapping[0] = -1; + m_twister_tcp_mapping[1] = -1; m_udp_mapping[0] = -1; m_udp_mapping[1] = -1; #ifdef TORRENT_USE_OPENSSL @@ -2463,6 +2467,9 @@ retry: { if (m_tcp_mapping[0] != -1) m_natpmp->delete_mapping(m_tcp_mapping[0]); m_tcp_mapping[0] = m_natpmp->add_mapping(natpmp::tcp, tcp_port, tcp_port); + if (m_twister_tcp_mapping[0] != -1) m_natpmp->delete_mapping(m_twister_tcp_mapping[0]); + m_twister_tcp_mapping[0] = m_natpmp->add_mapping(natpmp::tcp, + tcp_port-LIBTORRENT_PORT_OFFSET, tcp_port-LIBTORRENT_PORT_OFFSET); #ifdef TORRENT_USE_OPENSSL if (m_ssl_mapping[0] != -1) m_natpmp->delete_mapping(m_ssl_mapping[0]); m_ssl_mapping[0] = m_natpmp->add_mapping(natpmp::tcp, ssl_port, ssl_port); @@ -2472,6 +2479,9 @@ retry: { if (m_tcp_mapping[1] != -1) m_upnp->delete_mapping(m_tcp_mapping[1]); m_tcp_mapping[1] = m_upnp->add_mapping(upnp::tcp, tcp_port, tcp_port); + if (m_twister_tcp_mapping[1] != -1) m_upnp->delete_mapping(m_twister_tcp_mapping[1]); + m_twister_tcp_mapping[1] = m_upnp->add_mapping(upnp::tcp, + tcp_port-LIBTORRENT_PORT_OFFSET, tcp_port-LIBTORRENT_PORT_OFFSET); #ifdef TORRENT_USE_OPENSSL if (m_ssl_mapping[1] != -1) m_upnp->delete_mapping(m_ssl_mapping[1]); m_ssl_mapping[1] = m_upnp->add_mapping(upnp::tcp, ssl_port, ssl_port); @@ -6249,6 +6259,7 @@ retry: m_upnp->close(); m_udp_mapping[1] = -1; m_tcp_mapping[1] = -1; + m_twister_tcp_mapping[1] = -1; #ifdef TORRENT_USE_OPENSSL m_ssl_mapping[1] = -1; #endif diff --git a/src/init.cpp b/src/init.cpp index 41bb2950..88dce88b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -211,13 +211,7 @@ std::string HelpMessage() strUsage += " -bantime= " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n"; strUsage += " -maxreceivebuffer= " + _("Maximum per-connection receive buffer, *1000 bytes (default: 5000)") + "\n"; strUsage += " -maxsendbuffer= " + _("Maximum per-connection send buffer, *1000 bytes (default: 1000)") + "\n"; -#ifdef USE_UPNP -#if USE_UPNP strUsage += " -upnp " + _("Use UPnP to map the listening port (default: 1 when listening)") + "\n"; -#else - strUsage += " -upnp " + _("Use UPnP to map the listening port (default: 0)") + "\n"; -#endif -#endif strUsage += " -paytxfee= " + _("Fee per KB to add to transactions you send") + "\n"; if (fHaveGUI) strUsage += " -server " + _("Accept command line and JSON-RPC commands") + "\n"; diff --git a/src/main.h b/src/main.h index 6a0d56e1..153c97a1 100644 --- a/src/main.h +++ b/src/main.h @@ -54,11 +54,6 @@ static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 static const int MAX_SCRIPTCHECK_THREADS = 16; /** Default amount of block size reserved for high-priority transactions (in bytes) */ static const int DEFAULT_BLOCK_PRIORITY_SIZE = 27000; -#ifdef USE_UPNP -static const int fHaveUPnP = true; -#else -static const int fHaveUPnP = false; -#endif /** The maximum size for spam messages */ static const int MAX_SPAM_MSG_SIZE = 140; /** The maximum size for username */ diff --git a/src/makefile.android b/src/makefile.android index a2eb23a2..978f9711 100644 --- a/src/makefile.android +++ b/src/makefile.android @@ -2,11 +2,6 @@ # Distributed under the MIT/X11 software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -# :=0 --> UPnP support turned off by default at runtime -# :=1 --> UPnP support turned on by default at runtime -# :=- --> No UPnP support - miniupnp not required -USE_UPNP:=- - # :=1 --> Enable IPv6 support # :=0 --> Disable IPv6 support USE_IPV6:=0 @@ -36,14 +31,6 @@ TESTLIBS += \ -Wl,-B$(LMODE) \ -l boost_unit_test_framework$(BOOST_LIB_SUFFIX) -ifndef USE_UPNP - override USE_UPNP = - -endif -ifneq (${USE_UPNP}, -) - LIBS += -l miniupnpc - DEFS += -DUSE_UPNP=$(USE_UPNP) -endif - ifneq (${USE_IPV6}, -) DEFS += -DUSE_IPV6=$(USE_IPV6) endif diff --git a/src/makefile.freebsd b/src/makefile.freebsd index 9a48e80c..5022d0c1 100644 --- a/src/makefile.freebsd +++ b/src/makefile.freebsd @@ -2,11 +2,6 @@ # Distributed under the MIT/X11 software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -# :=0 --> UPnP support turned off by default at runtime -# :=1 --> UPnP support turned on by default at runtime -# :=- --> No UPnP support - miniupnp not required -USE_UPNP:=1 - # :=1 --> Enable IPv6 support # :=0 --> Disable IPv6 support USE_IPV6:=1 @@ -48,13 +43,6 @@ TESTLIBS += \ -Wl,-B$(LMODE) \ -l boost_unit_test_framework$(BOOST_LIB_SUFFIX) -ifndef USE_UPNP - override USE_UPNP = - -endif -ifneq (${USE_UPNP}, -) - LIBS += -l miniupnpc - DEFS += -DUSE_UPNP=$(USE_UPNP) -endif ifneq (${USE_IPV6}, -) DEFS += -DUSE_IPV6=$(USE_IPV6) diff --git a/src/makefile.mingw b/src/makefile.mingw index 431bf0d7..008966dc 100644 --- a/src/makefile.mingw +++ b/src/makefile.mingw @@ -17,7 +17,6 @@ CXX ?= g++ -USE_UPNP:=- USE_IPV6:=1 DEPSDIR?=/usr/local @@ -52,13 +51,6 @@ LDFLAGS=-Wl,--dynamicbase -Wl,--nxcompat -Wl,--large-address-aware TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data) -ifndef USE_UPNP - override USE_UPNP = - -endif -ifneq (${USE_UPNP}, -) - LIBS += -l miniupnpc -l iphlpapi - DEFS += -DSTATICLIB -DUSE_UPNP=$(USE_UPNP) -endif ifneq (${USE_IPV6}, -) DEFS += -DUSE_IPV6=$(USE_IPV6) diff --git a/src/makefile.osx b/src/makefile.osx index adf842d2..7d18597c 100644 --- a/src/makefile.osx +++ b/src/makefile.osx @@ -2,11 +2,6 @@ # Distributed under the MIT/X11 software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -# :=0 --> UPnP support turned off by default at runtime -# :=1 --> UPnP support turned on by default at runtime -# :=- --> No UPnP support - miniupnp not required -USE_UPNP:=1 - # :=1 --> Enable IPv6 support # :=0 --> Disable IPv6 support USE_IPV6:=1 @@ -48,13 +43,6 @@ TESTLIBS += \ -l boost_unit_test_framework$(BOOST_LIB_SUFFIX) # -Wl,-B$(LMODE) // does not work on OSX -ifndef USE_UPNP - override USE_UPNP = - -endif -ifneq (${USE_UPNP}, -) - LIBS += -l miniupnpc - DEFS += -DUSE_UPNP=$(USE_UPNP) -endif ifneq (${USE_IPV6}, -) DEFS += -DUSE_IPV6=$(USE_IPV6) diff --git a/src/makefile.unix b/src/makefile.unix index 1fae0e65..a07be7b2 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -2,11 +2,6 @@ # Distributed under the MIT/X11 software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -# :=0 --> UPnP support turned off by default at runtime -# :=1 --> UPnP support turned on by default at runtime -# :=- --> No UPnP support - miniupnp not required -USE_UPNP:=1 - # :=1 --> Enable IPv6 support # :=0 --> Disable IPv6 support USE_IPV6:=1 @@ -48,14 +43,6 @@ TESTLIBS += \ -Wl,-B$(LMODE) \ -l boost_unit_test_framework$(BOOST_LIB_SUFFIX) -ifndef USE_UPNP - override USE_UPNP = - -endif -ifneq (${USE_UPNP}, -) - LIBS += -l miniupnpc - DEFS += -DUSE_UPNP=$(USE_UPNP) -endif - ifneq (${USE_IPV6}, -) DEFS += -DUSE_IPV6=$(USE_IPV6) endif diff --git a/src/twister.cpp b/src/twister.cpp index 2aaff17a..07cc28b9 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -254,8 +254,8 @@ void ThreadWaitExtIP() std::string ipStr; - // wait up to 5 seconds for bitcoin to get the external IP - for( int i = 0; i < 10; i++ ) { + // wait up to 10 seconds for bitcoin to get the external IP + for( int i = 0; i < 20; i++ ) { const CNetAddr paddrPeer("8.8.8.8"); CAddress addr( GetLocalAddress(&paddrPeer) ); if( addr.IsValid() ) { @@ -309,8 +309,10 @@ void ThreadWaitExtIP() } if( !m_usingProxy ) { - ses->start_upnp(); - ses->start_natpmp(); + if( GetBoolArg("-upnp", true) ) { + ses->start_upnp(); + ses->start_natpmp(); + } ses->listen_on(std::make_pair(listen_port, listen_port) , ec, bind_to_interface.c_str()); @@ -334,7 +336,7 @@ void ThreadWaitExtIP() } } - session_settings settings; + session_settings settings("twisterd/"+FormatFullVersion()); // settings to test local connections settings.allow_multiple_connections_per_ip = true; //settings.enable_outgoing_utp = false; // (false to see connections in netstat) diff --git a/twister-qt.pro b/twister-qt.pro index 6f496341..3cbc0603 100644 --- a/twister-qt.pro +++ b/twister-qt.pro @@ -58,23 +58,6 @@ contains(USE_QRCODE, 1) { LIBS += -lqrencode } -# use: qmake "USE_UPNP=1" ( enabled by default; default) -# or: qmake "USE_UPNP=0" (disabled by default) -# or: qmake "USE_UPNP=-" (not supported) -# miniupnpc (http://miniupnp.free.fr/files/) must be installed for support -contains(USE_UPNP, -) { - message(Building without UPNP support) -} else { - message(Building with UPNP support) - count(USE_UPNP, 0) { - USE_UPNP=1 - } - DEFINES += USE_UPNP=$$USE_UPNP STATICLIB - INCLUDEPATH += $$MINIUPNPC_INCLUDE_PATH - LIBS += $$join(MINIUPNPC_LIB_PATH,,-L,) -lminiupnpc - win32:LIBS += -liphlpapi -} - # use: qmake "USE_DBUS=1" contains(USE_DBUS, 1) { message(Building with DBUS (Freedesktop notifications) support)