Skip to content

Commit

Permalink
p2p: BIP324 v2.0 clients retry with v1 protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruv committed Feb 22, 2022
1 parent b8cbeb9 commit 090bbb3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,10 @@ CNode* CConnman::FindNode(const CService& addr)

bool CConnman::AlreadyConnectedToAddress(const CAddress& addr)
{
return FindNode(static_cast<CNetAddr>(addr)) || FindNode(addr.ToStringIPPort());
CNode* found_by_addr = FindNode(static_cast<CNetAddr>(addr));
CNode* found_by_ip_port = FindNode(addr.ToStringIPPort());
return (found_by_addr && !found_by_addr->fDisconnect) ||
(found_by_ip_port && !found_by_ip_port->fDisconnect);
}

bool CConnman::CheckIncomingNonce(uint64_t nonce)
Expand Down Expand Up @@ -452,7 +455,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo

// Look for an existing connection
CNode* pnode = FindNode(static_cast<CService>(addrConnect));
if (pnode)
if (pnode && !pnode->fDisconnect)
{
LogPrintf("Failed to open new connection, already connected\n");
return nullptr;
Expand Down Expand Up @@ -1941,7 +1944,15 @@ void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes,
if (!pnode->fDisconnect) {
LogPrint(BCLog::NET, "socket closed for peer=%d\n", pnode->GetId());
}

pnode->CloseSocketDisconnect();

if (pnode->PreferV2Conn() && !pnode->tried_v2_handshake) {
CAddress addr = pnode->addr;
addr.nServices = ServiceFlags(addr.nServices & ~NODE_P2P_V2);
CSemaphoreGrant grant(*semOutbound);
OpenNetworkConnection(addr, true, &grant, nullptr, pnode->m_conn_type);
}
} else if (nBytes < 0) {
// error
int nErr = WSAGetLastError();
Expand Down

0 comments on commit 090bbb3

Please sign in to comment.