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 23, 2022
1 parent 6415556 commit bef5e10
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,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 @@ -451,7 +454,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,6 +1944,13 @@ void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes,
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 bef5e10

Please sign in to comment.