Browse Source

Add -noproxy to circumvent proxy for some network

0.8
Pieter Wuille 13 years ago
parent
commit
623b987813
  1. 13
      src/init.cpp
  2. 8
      src/netbase.cpp
  3. 1
      src/netbase.h

13
src/init.cpp

@ -180,6 +180,7 @@ bool AppInit2(int argc, char* argv[]) @@ -180,6 +180,7 @@ bool AppInit2(int argc, char* argv[])
" -timeout=<n> \t " + _("Specify connection timeout (in milliseconds)") + "\n" +
" -proxy=<ip:port> \t " + _("Connect through socks proxy") + "\n" +
" -socks=<n> \t " + _("Select the version of socks proxy to use (4 or 5, 5 is default)") + "\n" +
" -noproxy=<net> \t " + _("Do not use proxy for connections to network net (ipv4 or ipv6)") + "\n" +
" -dns \t " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n" +
" -proxydns \t " + _("Pass DNS requests to (SOCKS5) proxy") + "\n" +
" -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[]) @@ -532,6 +533,18 @@ bool AppInit2(int argc, char* argv[])
}
}
if (mapArgs.count("-noproxy"))
{
BOOST_FOREACH(std::string snet, mapMultiArgs["-noproxy"]) {
enum Network net = ParseNetwork(snet);
if (net == NET_UNROUTABLE) {
ThreadSafeMessageBox(_("Unknown network specified in -noproxy"), _("Bitcoin"), wxOK | wxMODAL);
return false;
}
SetNoProxy(net);
}
}
if (mapArgs.count("-connect"))
SoftSetBoolArg("-dnsseed", false);

8
src/netbase.cpp

@ -21,6 +21,7 @@ bool fProxyNameLookup = false; @@ -21,6 +21,7 @@ bool fProxyNameLookup = false;
bool fNameLookup = false;
CService addrProxy("127.0.0.1",9050);
int nConnectTimeout = 5000;
static bool vfNoProxy[NET_MAX] = {};
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) { @@ -33,6 +34,11 @@ enum Network ParseNetwork(std::string net) {
return NET_UNROUTABLE;
}
void SetNoProxy(enum Network net, bool fNoProxy) {
assert(net >= 0 && net < NET_MAX);
vfNoProxy[net] = fNoProxy;
}
bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
{
vIP.clear();
@ -440,7 +446,7 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe @@ -440,7 +446,7 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe
bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
{
SOCKET hSocket = INVALID_SOCKET;
bool fProxy = (fUseProxy && addrDest.IsRoutable());
bool fProxy = (fUseProxy && addrDest.IsRoutable() && !vfNoProxy[addrDest.GetNetwork()]);
if (!ConnectSocketDirectly(fProxy ? addrProxy : addrDest, hSocket, nTimeout))
return false;

1
src/netbase.h

@ -29,6 +29,7 @@ enum Network @@ -29,6 +29,7 @@ enum Network
};
enum Network ParseNetwork(std::string net);
void SetNoProxy(enum Network net, bool fNoProxy = true);
/** IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96)) */
class CNetAddr

Loading…
Cancel
Save