Skip to content

Commit 3a55e30

Browse files
committed
net: disable v1 connections, reconnections on clearnet
if `-v2onlyclearnet` is turned on, - v1 addresses from addrman aren't selected and manual connections aren't attempted for outbound connections if it's from IPV4/IPV6 networks. - v1 downgrade mechainm is not attempted if v2 connection wasn't successful
1 parent a9d21f6 commit 3a55e30

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/net.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ void CConnman::DisconnectNodes()
18921892
// Add to reconnection list if appropriate. We don't reconnect right here, because
18931893
// the creation of a connection is a blocking operation (up to several seconds),
18941894
// and we don't want to hold up the socket handler thread for that long.
1895-
if (pnode->m_transport->ShouldReconnectV1()) {
1895+
if (pnode->m_transport->ShouldReconnectV1() && !DisableV1OnClearnet(pnode->addr.GetNetClass())) {
18961896
reconnections_to_add.push_back({
18971897
.addr_connect = pnode->addr,
18981898
.grant = std::move(pnode->grantOutbound),
@@ -2766,6 +2766,11 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, Spa
27662766
continue;
27672767
}
27682768

2769+
bool use_v2transport(addr.nServices & GetLocalServices() & NODE_P2P_V2);
2770+
if (DisableV1OnClearnet(addr.GetNetClass()) && !use_v2transport) {
2771+
continue;
2772+
}
2773+
27692774
// only consider very recently tried nodes after 30 failed attempts
27702775
if (current_time - addr_last_try < 10min && nTries < 30) {
27712776
continue;
@@ -2948,6 +2953,19 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
29482953
} else if (FindNode(std::string(pszDest)))
29492954
return;
29502955

2956+
enum Network netclass;
2957+
if (pszDest) {
2958+
std::string host;
2959+
uint16_t port;
2960+
SplitHostPort(std::string(pszDest), port, host);
2961+
netclass = LookupHost(host, false).value().GetNetClass();
2962+
} else {
2963+
netclass = addrConnect.GetNetClass();
2964+
}
2965+
if (DisableV1OnClearnet(netclass) && !use_v2transport) {
2966+
return;
2967+
}
2968+
29512969
CNode* pnode = ConnectNode(addrConnect, pszDest, fCountFailure, conn_type, use_v2transport);
29522970

29532971
if (!pnode)

src/net_processing.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -3784,6 +3784,12 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
37843784
return;
37853785
}
37863786

3787+
const bool is_v1transport = pfrom.m_transport->GetInfo().transport_type == TransportProtocolType::V1;
3788+
if (pfrom.IsInboundConn() && is_v1transport && m_connman.DisableV1OnClearnet(pfrom.ConnectedThroughNetwork())){
3789+
pfrom.fDisconnect = true;
3790+
return;
3791+
}
3792+
37873793
if (pfrom.IsInboundConn() && addrMe.IsRoutable())
37883794
{
37893795
SeenLocal(addrMe);

0 commit comments

Comments
 (0)