mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-18 19:40:40 +01:00
net: split socket creation out of connection
Also, check for the correct error during socket creation
This commit is contained in:
18
src/net.cpp
18
src/net.cpp
@@ -417,16 +417,30 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
||||
if (addrConnect.IsValid()) {
|
||||
bool proxyConnectionFailed = false;
|
||||
|
||||
if (GetProxy(addrConnect.GetNetwork(), proxy))
|
||||
if (GetProxy(addrConnect.GetNetwork(), proxy)) {
|
||||
hSocket = CreateSocket(proxy.proxy);
|
||||
if (hSocket == INVALID_SOCKET) {
|
||||
return nullptr;
|
||||
}
|
||||
connected = ConnectThroughProxy(proxy, addrConnect.ToStringIP(), addrConnect.GetPort(), hSocket, nConnectTimeout, &proxyConnectionFailed);
|
||||
else // no proxy needed (none set for target network)
|
||||
} else {
|
||||
// no proxy needed (none set for target network)
|
||||
hSocket = CreateSocket(addrConnect);
|
||||
if (hSocket == INVALID_SOCKET) {
|
||||
return nullptr;
|
||||
}
|
||||
connected = ConnectSocketDirectly(addrConnect, hSocket, nConnectTimeout);
|
||||
}
|
||||
if (!proxyConnectionFailed) {
|
||||
// If a connection to the node was attempted, and failure (if any) is not caused by a problem connecting to
|
||||
// the proxy, mark this as an attempt.
|
||||
addrman.Attempt(addrConnect, fCountFailure);
|
||||
}
|
||||
} else if (pszDest && GetNameProxy(proxy)) {
|
||||
hSocket = CreateSocket(proxy.proxy);
|
||||
if (hSocket == INVALID_SOCKET) {
|
||||
return nullptr;
|
||||
}
|
||||
std::string host;
|
||||
int port = default_port;
|
||||
SplitHostPort(std::string(pszDest), port, host);
|
||||
|
||||
Reference in New Issue
Block a user