Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 1,078 Lines • ▼ Show 20 Lines | const std::chrono::milliseconds delta = | ||||
std::chrono::minutes{10} + GetRandMillis(std::chrono::minutes{5}); | std::chrono::minutes{10} + GetRandMillis(std::chrono::minutes{5}); | ||||
scheduler.scheduleFromNow([&] { ReattemptInitialBroadcast(scheduler); }, | scheduler.scheduleFromNow([&] { ReattemptInitialBroadcast(scheduler); }, | ||||
delta); | delta); | ||||
} | } | ||||
void PeerManager::FinalizeNode(const Config &config, NodeId nodeid, | void PeerManager::FinalizeNode(const Config &config, NodeId nodeid, | ||||
bool &fUpdateConnectionTime) { | bool &fUpdateConnectionTime) { | ||||
fUpdateConnectionTime = false; | fUpdateConnectionTime = false; | ||||
{ | |||||
LOCK(cs_main); | LOCK(cs_main); | ||||
int misbehavior{0}; | int misbehavior{0}; | ||||
{ | { | ||||
PeerRef peer = GetPeerRef(nodeid); | PeerRef peer = GetPeerRef(nodeid); | ||||
assert(peer != nullptr); | assert(peer != nullptr); | ||||
misbehavior = WITH_LOCK(peer->m_misbehavior_mutex, | misbehavior = WITH_LOCK(peer->m_misbehavior_mutex, | ||||
return peer->m_misbehavior_score); | return peer->m_misbehavior_score); | ||||
LOCK(g_peer_mutex); | LOCK(g_peer_mutex); | ||||
g_peer_map.erase(nodeid); | g_peer_map.erase(nodeid); | ||||
} | } | ||||
CNodeState *state = State(nodeid); | CNodeState *state = State(nodeid); | ||||
assert(state != nullptr); | assert(state != nullptr); | ||||
if (state->fSyncStarted) { | if (state->fSyncStarted) { | ||||
nSyncStarted--; | nSyncStarted--; | ||||
} | } | ||||
if (misbehavior == 0 && state->fCurrentlyConnected) { | if (misbehavior == 0 && state->fCurrentlyConnected) { | ||||
fUpdateConnectionTime = true; | fUpdateConnectionTime = true; | ||||
} | } | ||||
for (const QueuedBlock &entry : state->vBlocksInFlight) { | for (const QueuedBlock &entry : state->vBlocksInFlight) { | ||||
mapBlocksInFlight.erase(entry.hash); | mapBlocksInFlight.erase(entry.hash); | ||||
} | } | ||||
EraseOrphansFor(nodeid); | EraseOrphansFor(nodeid); | ||||
m_txrequest.DisconnectedPeer(nodeid); | m_txrequest.DisconnectedPeer(nodeid); | ||||
nPreferredDownload -= state->fPreferredDownload; | nPreferredDownload -= state->fPreferredDownload; | ||||
nPeersWithValidatedDownloads -= (state->nBlocksInFlightValidHeaders != 0); | nPeersWithValidatedDownloads -= | ||||
(state->nBlocksInFlightValidHeaders != 0); | |||||
assert(nPeersWithValidatedDownloads >= 0); | assert(nPeersWithValidatedDownloads >= 0); | ||||
g_outbound_peers_with_protect_from_disconnect -= | g_outbound_peers_with_protect_from_disconnect -= | ||||
state->m_chain_sync.m_protect; | state->m_chain_sync.m_protect; | ||||
assert(g_outbound_peers_with_protect_from_disconnect >= 0); | assert(g_outbound_peers_with_protect_from_disconnect >= 0); | ||||
mapNodeState.erase(nodeid); | mapNodeState.erase(nodeid); | ||||
if (mapNodeState.empty()) { | if (mapNodeState.empty()) { | ||||
// Do a consistency check after the last peer is removed. | // Do a consistency check after the last peer is removed. | ||||
assert(mapBlocksInFlight.empty()); | assert(mapBlocksInFlight.empty()); | ||||
assert(nPreferredDownload == 0); | assert(nPreferredDownload == 0); | ||||
assert(nPeersWithValidatedDownloads == 0); | assert(nPeersWithValidatedDownloads == 0); | ||||
assert(g_outbound_peers_with_protect_from_disconnect == 0); | assert(g_outbound_peers_with_protect_from_disconnect == 0); | ||||
assert(m_txrequest.Size() == 0); | assert(m_txrequest.Size() == 0); | ||||
} | } | ||||
} | |||||
WITH_LOCK(cs_proofrequest, m_proofrequest.DisconnectedPeer(nodeid)); | |||||
LogPrint(BCLog::NET, "Cleared nodestate for peer=%d\n", nodeid); | LogPrint(BCLog::NET, "Cleared nodestate for peer=%d\n", nodeid); | ||||
} | } | ||||
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) { | bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) { | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CNodeState *state = State(nodeid); | CNodeState *state = State(nodeid); | ||||
if (state == nullptr) { | if (state == nullptr) { | ||||
▲ Show 20 Lines • Show All 4,514 Lines • Show Last 20 Lines |