diff --git a/src/init.cpp b/src/init.cpp
index e03ff438d4..53b0fbb580 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -304,7 +304,8 @@ std::string HelpMessage()
" -datadir=
" + _("Specify data directory") + "\n" +
" -dbcache= " + _("Set database cache size in megabytes (default: 25)") + "\n" +
" -timeout= " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n" +
- " -proxy= " + _("Connect through socks proxy") + "\n" +
+ " -proxy= " + _("Exclusively connect through socks proxy") + "\n" +
+ " -proxytoo= " + _("Also connect through socks proxy") + "\n" +
" -socks= " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n" +
" -tor= " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\n"
" -dns " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n" +
@@ -788,6 +789,23 @@ bool AppInit2(boost::thread_group& threadGroup)
SetReachable(NET_TOR);
}
+ if (mapArgs.count("-proxytoo")) {
+ fProxyToo = true;
+ CService addrProxy = CService(mapArgs["-proxytoo"], 9050);
+ if (!addrProxy.IsValid())
+ return InitError(strprintf(_("Invalid -proxytoo address: '%s'"), mapArgs["-proxytoo"].c_str()));
+
+ if (!IsLimited(NET_IPV4))
+ SetProxy(NET_IPV4, addrProxy, nSocksVersion);
+ if (nSocksVersion > 4) {
+#ifdef USE_IPV6
+ if (!IsLimited(NET_IPV6))
+ SetProxy(NET_IPV6, addrProxy, nSocksVersion);
+#endif
+ SetNameProxy(addrProxy, nSocksVersion);
+ }
+ }
+
// see Step 2: parameter interactions for more information about these
fNoListen = !GetBoolArg("-listen", true);
fDiscover = GetBoolArg("-discover", true);
diff --git a/src/netbase.cpp b/src/netbase.cpp
index d969516750..e69d8cd21a 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -21,6 +21,7 @@ using namespace std;
static proxyType proxyInfo[NET_MAX];
static proxyType nameproxyInfo;
static CCriticalSection cs_proxyInfos;
+int fProxyToo = false;
int nConnectTimeout = 5000;
bool fNameLookup = false;
@@ -475,7 +476,7 @@ bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
proxyType proxy;
// no proxy needed
- if (!GetProxy(addrDest.GetNetwork(), proxy))
+ if (!GetProxy(addrDest.GetNetwork(), proxy) || (fProxyToo && rand() %2 == 0))
return ConnectSocketDirectly(addrDest, hSocketRet, nTimeout);
SOCKET hSocket = INVALID_SOCKET;
diff --git a/src/netbase.h b/src/netbase.h
index e4ec4ef597..1bc7ef1b42 100644
--- a/src/netbase.h
+++ b/src/netbase.h
@@ -148,4 +148,6 @@ bool LookupNumeric(const char *pszName, CService& addr, int portDefault = 0);
bool ConnectSocket(const CService &addr, SOCKET& hSocketRet, int nTimeout = nConnectTimeout);
bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest, int portDefault = 0, int nTimeout = nConnectTimeout);
+// Settings
+extern int fProxyToo;
#endif