Skip to content

Commit 623b987

Browse files
committed
Add -noproxy to circumvent proxy for some network
1 parent 090e5b4 commit 623b987

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/init.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ bool AppInit2(int argc, char* argv[])
180180
" -timeout=<n> \t " + _("Specify connection timeout (in milliseconds)") + "\n" +
181181
" -proxy=<ip:port> \t " + _("Connect through socks proxy") + "\n" +
182182
" -socks=<n> \t " + _("Select the version of socks proxy to use (4 or 5, 5 is default)") + "\n" +
183+
" -noproxy=<net> \t " + _("Do not use proxy for connections to network net (ipv4 or ipv6)") + "\n" +
183184
" -dns \t " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n" +
184185
" -proxydns \t " + _("Pass DNS requests to (SOCKS5) proxy") + "\n" +
185186
" -port=<port> \t\t " + _("Listen for connections on <port> (default: 8333 or testnet: 18333)") + "\n" +
@@ -532,6 +533,18 @@ bool AppInit2(int argc, char* argv[])
532533
}
533534
}
534535

536+
if (mapArgs.count("-noproxy"))
537+
{
538+
BOOST_FOREACH(std::string snet, mapMultiArgs["-noproxy"]) {
539+
enum Network net = ParseNetwork(snet);
540+
if (net == NET_UNROUTABLE) {
541+
ThreadSafeMessageBox(_("Unknown network specified in -noproxy"), _("Bitcoin"), wxOK | wxMODAL);
542+
return false;
543+
}
544+
SetNoProxy(net);
545+
}
546+
}
547+
535548
if (mapArgs.count("-connect"))
536549
SoftSetBoolArg("-dnsseed", false);
537550

src/netbase.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ bool fProxyNameLookup = false;
2121
bool fNameLookup = false;
2222
CService addrProxy("127.0.0.1",9050);
2323
int nConnectTimeout = 5000;
24+
static bool vfNoProxy[NET_MAX] = {};
2425

2526

2627
static const unsigned char pchIPv4[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff };
@@ -33,6 +34,11 @@ enum Network ParseNetwork(std::string net) {
3334
return NET_UNROUTABLE;
3435
}
3536

37+
void SetNoProxy(enum Network net, bool fNoProxy) {
38+
assert(net >= 0 && net < NET_MAX);
39+
vfNoProxy[net] = fNoProxy;
40+
}
41+
3642
bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
3743
{
3844
vIP.clear();
@@ -440,7 +446,7 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe
440446
bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
441447
{
442448
SOCKET hSocket = INVALID_SOCKET;
443-
bool fProxy = (fUseProxy && addrDest.IsRoutable());
449+
bool fProxy = (fUseProxy && addrDest.IsRoutable() && !vfNoProxy[addrDest.GetNetwork()]);
444450

445451
if (!ConnectSocketDirectly(fProxy ? addrProxy : addrDest, hSocket, nTimeout))
446452
return false;

src/netbase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum Network
2929
};
3030

3131
enum Network ParseNetwork(std::string net);
32+
void SetNoProxy(enum Network net, bool fNoProxy = true);
3233

3334
/** IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96)) */
3435
class CNetAddr

0 commit comments

Comments
 (0)