Add -proxytoo option, which allows proxy use non-exclusively, unlike the -proxy option.

Conflicts:

	src/init.cpp
	src/netbase.cpp

Conflicts:

	.gitignore
	src/init.cpp

Conflicts:

	src/init.cpp
	src/netbase.cpp
This commit is contained in:
R E Broadley 2014-05-24 23:25:36 +07:00 committed by Evan Duffield
parent 6afc2e7b23
commit 4fcaa57368
3 changed files with 23 additions and 2 deletions

View File

@ -304,7 +304,8 @@ std::string HelpMessage()
" -datadir=<dir> " + _("Specify data directory") + "\n" + " -datadir=<dir> " + _("Specify data directory") + "\n" +
" -dbcache=<n> " + _("Set database cache size in megabytes (default: 25)") + "\n" + " -dbcache=<n> " + _("Set database cache size in megabytes (default: 25)") + "\n" +
" -timeout=<n> " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n" + " -timeout=<n> " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n" +
" -proxy=<ip:port> " + _("Connect through socks proxy") + "\n" + " -proxy=<ip:port> " + _("Exclusively connect through socks proxy") + "\n" +
" -proxytoo=<ip:port> " + _("Also connect through socks proxy") + "\n" +
" -socks=<n> " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n" + " -socks=<n> " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n" +
" -tor=<ip:port> " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\n" " -tor=<ip:port> " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\n"
" -dns " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n" + " -dns " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n" +
@ -788,6 +789,23 @@ bool AppInit2(boost::thread_group& threadGroup)
SetReachable(NET_TOR); 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 // see Step 2: parameter interactions for more information about these
fNoListen = !GetBoolArg("-listen", true); fNoListen = !GetBoolArg("-listen", true);
fDiscover = GetBoolArg("-discover", true); fDiscover = GetBoolArg("-discover", true);

View File

@ -21,6 +21,7 @@ using namespace std;
static proxyType proxyInfo[NET_MAX]; static proxyType proxyInfo[NET_MAX];
static proxyType nameproxyInfo; static proxyType nameproxyInfo;
static CCriticalSection cs_proxyInfos; static CCriticalSection cs_proxyInfos;
int fProxyToo = false;
int nConnectTimeout = 5000; int nConnectTimeout = 5000;
bool fNameLookup = false; bool fNameLookup = false;
@ -475,7 +476,7 @@ bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
proxyType proxy; proxyType proxy;
// no proxy needed // no proxy needed
if (!GetProxy(addrDest.GetNetwork(), proxy)) if (!GetProxy(addrDest.GetNetwork(), proxy) || (fProxyToo && rand() %2 == 0))
return ConnectSocketDirectly(addrDest, hSocketRet, nTimeout); return ConnectSocketDirectly(addrDest, hSocketRet, nTimeout);
SOCKET hSocket = INVALID_SOCKET; SOCKET hSocket = INVALID_SOCKET;

View File

@ -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 ConnectSocket(const CService &addr, SOCKET& hSocketRet, int nTimeout = nConnectTimeout);
bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest, int portDefault = 0, int nTimeout = nConnectTimeout); bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest, int portDefault = 0, int nTimeout = nConnectTimeout);
// Settings
extern int fProxyToo;
#endif #endif