Changeset View
Changeset View
Standalone View
Standalone View
src/netbase.cpp
Show All 20 Lines | |||||
#include <poll.h> | #include <poll.h> | ||||
#endif | #endif | ||||
#if !defined(MSG_NOSIGNAL) | #if !defined(MSG_NOSIGNAL) | ||||
#define MSG_NOSIGNAL 0 | #define MSG_NOSIGNAL 0 | ||||
#endif | #endif | ||||
// Settings | // Settings | ||||
static RecursiveMutex cs_proxyInfos; | static Mutex g_proxyinfo_mutex; | ||||
static proxyType proxyInfo[NET_MAX] GUARDED_BY(cs_proxyInfos); | static proxyType proxyInfo[NET_MAX] GUARDED_BY(g_proxyinfo_mutex); | ||||
static proxyType nameProxy GUARDED_BY(cs_proxyInfos); | static proxyType nameProxy GUARDED_BY(g_proxyinfo_mutex); | ||||
int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT; | int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT; | ||||
bool fNameLookup = DEFAULT_NAME_LOOKUP; | bool fNameLookup = DEFAULT_NAME_LOOKUP; | ||||
// Need ample time for negotiation for very slow proxies such as Tor | // Need ample time for negotiation for very slow proxies such as Tor | ||||
// (milliseconds) | // (milliseconds) | ||||
static const int SOCKS5_RECV_TIMEOUT = 20 * 1000; | static const int SOCKS5_RECV_TIMEOUT = 20 * 1000; | ||||
static std::atomic<bool> interruptSocks5Recv(false); | static std::atomic<bool> interruptSocks5Recv(false); | ||||
▲ Show 20 Lines • Show All 729 Lines • ▼ Show 20 Lines | #endif | ||||
return true; | return true; | ||||
} | } | ||||
bool SetProxy(enum Network net, const proxyType &addrProxy) { | bool SetProxy(enum Network net, const proxyType &addrProxy) { | ||||
assert(net >= 0 && net < NET_MAX); | assert(net >= 0 && net < NET_MAX); | ||||
if (!addrProxy.IsValid()) { | if (!addrProxy.IsValid()) { | ||||
return false; | return false; | ||||
} | } | ||||
LOCK(cs_proxyInfos); | LOCK(g_proxyinfo_mutex); | ||||
proxyInfo[net] = addrProxy; | proxyInfo[net] = addrProxy; | ||||
return true; | return true; | ||||
} | } | ||||
bool GetProxy(enum Network net, proxyType &proxyInfoOut) { | bool GetProxy(enum Network net, proxyType &proxyInfoOut) { | ||||
assert(net >= 0 && net < NET_MAX); | assert(net >= 0 && net < NET_MAX); | ||||
LOCK(cs_proxyInfos); | LOCK(g_proxyinfo_mutex); | ||||
if (!proxyInfo[net].IsValid()) { | if (!proxyInfo[net].IsValid()) { | ||||
return false; | return false; | ||||
} | } | ||||
proxyInfoOut = proxyInfo[net]; | proxyInfoOut = proxyInfo[net]; | ||||
return true; | return true; | ||||
} | } | ||||
/** | /** | ||||
Show All 11 Lines | |||||
* @note SOCKS5's support for UDP-over-SOCKS5 has been considered, but no SOCK5 | * @note SOCKS5's support for UDP-over-SOCKS5 has been considered, but no SOCK5 | ||||
* server in common use (most notably Tor) actually implements UDP | * server in common use (most notably Tor) actually implements UDP | ||||
* support, and a DNS resolver is beyond the scope of this project. | * support, and a DNS resolver is beyond the scope of this project. | ||||
*/ | */ | ||||
bool SetNameProxy(const proxyType &addrProxy) { | bool SetNameProxy(const proxyType &addrProxy) { | ||||
if (!addrProxy.IsValid()) { | if (!addrProxy.IsValid()) { | ||||
return false; | return false; | ||||
} | } | ||||
LOCK(cs_proxyInfos); | LOCK(g_proxyinfo_mutex); | ||||
nameProxy = addrProxy; | nameProxy = addrProxy; | ||||
return true; | return true; | ||||
} | } | ||||
bool GetNameProxy(proxyType &nameProxyOut) { | bool GetNameProxy(proxyType &nameProxyOut) { | ||||
LOCK(cs_proxyInfos); | LOCK(g_proxyinfo_mutex); | ||||
if (!nameProxy.IsValid()) { | if (!nameProxy.IsValid()) { | ||||
return false; | return false; | ||||
} | } | ||||
nameProxyOut = nameProxy; | nameProxyOut = nameProxy; | ||||
return true; | return true; | ||||
} | } | ||||
bool HaveNameProxy() { | bool HaveNameProxy() { | ||||
LOCK(cs_proxyInfos); | LOCK(g_proxyinfo_mutex); | ||||
return nameProxy.IsValid(); | return nameProxy.IsValid(); | ||||
} | } | ||||
bool IsProxy(const CNetAddr &addr) { | bool IsProxy(const CNetAddr &addr) { | ||||
LOCK(cs_proxyInfos); | LOCK(g_proxyinfo_mutex); | ||||
for (int i = 0; i < NET_MAX; i++) { | for (int i = 0; i < NET_MAX; i++) { | ||||
if (addr == static_cast<CNetAddr>(proxyInfo[i].proxy)) { | if (addr == static_cast<CNetAddr>(proxyInfo[i].proxy)) { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 174 Lines • Show Last 20 Lines |