From 533500d9072b7d5a36a6491784bdeb9247e91fb0 Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Sat, 29 May 2021 23:58:37 +0200 Subject: [PATCH] p2p: Add timeout for AddrFetch peers If AddrFetch peers don't send us addresses, disconnect them after a while. --- src/net_processing.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 51d628773c..702a235993 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -4364,6 +4364,12 @@ bool PeerManagerImpl::SendMessages(CNode* pto) const auto current_time = GetTime(); + if (pto->IsAddrFetchConn() && current_time - std::chrono::seconds(pto->nTimeConnected) > 10 * AVG_ADDRESS_BROADCAST_INTERVAL) { + LogPrint(BCLog::NET, "addrfetch connection timeout; disconnecting peer=%d\n", pto->GetId()); + pto->fDisconnect = true; + return true; + } + MaybeSendPing(*pto, *peer, current_time); // MaybeSendPing may have marked peer for disconnection