From 587f929c6462698a674fe8add2f301161219d05a Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 24 May 2012 19:02:21 +0200 Subject: Rework network config settings --- src/netbase.cpp | 119 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 42 deletions(-) (limited to 'src/netbase.cpp') diff --git a/src/netbase.cpp b/src/netbase.cpp index 7de06eaef..80b0e32c3 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -16,14 +16,11 @@ using namespace std; // Settings -int nSocksVersion = 5; -int fUseProxy = false; -bool fProxyNameLookup = false; -bool fNameLookup = false; -CService addrProxy("127.0.0.1",9050); +typedef std::pair proxyType; +static proxyType proxyInfo[NET_MAX]; +static proxyType nameproxyInfo; int nConnectTimeout = 5000; -static bool vfNoProxy[NET_MAX] = {}; - +bool fNameLookup = false; static const unsigned char pchIPv4[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff }; @@ -36,11 +33,6 @@ 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& vIP, unsigned int nMaxSolutions, bool fAllowLookup) { vIP.clear(); @@ -431,29 +423,71 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe return true; } +bool SetProxy(enum Network net, CService addrProxy, int nSocksVersion) { + assert(net >= 0 && net < NET_MAX); + if (nSocksVersion != 0 && nSocksVersion != 4 && nSocksVersion != 5) + return false; + if (nSocksVersion != 0 && !addrProxy.IsValid()) + return false; + proxyInfo[net] = std::make_pair(addrProxy, nSocksVersion); + return true; +} + +bool GetProxy(enum Network net, CService &addrProxy) { + assert(net >= 0 && net < NET_MAX); + if (!proxyInfo[net].second) + return false; + addrProxy = proxyInfo[net].first; + return true; +} + +bool SetNameProxy(CService addrProxy, int nSocksVersion) { + if (nSocksVersion != 0 && nSocksVersion != 5) + return false; + if (nSocksVersion != 0 && !addrProxy.IsValid()) + return false; + nameproxyInfo = std::make_pair(addrProxy, nSocksVersion); + return true; +} + +bool GetNameProxy() { + return nameproxyInfo.second != 0; +} + +bool IsProxy(const CNetAddr &addr) { + for (int i=0; i