|
|
|
@ -462,6 +462,7 @@ public:
|
|
|
|
|
void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message) override;
|
|
|
|
|
void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
|
|
|
|
|
const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) override;
|
|
|
|
|
void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds) override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/** Consider evicting an outbound peer based on the amount of time they've been behind our tip */
|
|
|
|
@ -580,6 +581,16 @@ private:
|
|
|
|
|
*/
|
|
|
|
|
std::map<NodeId, PeerRef> m_peer_map GUARDED_BY(m_peer_mutex);
|
|
|
|
|
|
|
|
|
|
/** Map maintaining per-node state. */
|
|
|
|
|
std::map<NodeId, CNodeState> mapNodeState GUARDED_BY(cs_main);
|
|
|
|
|
|
|
|
|
|
/** Get a pointer to a const CNodeState, used when not mutating the CNodeState object. */
|
|
|
|
|
const CNodeState* State(NodeId pnode) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
|
|
|
|
/** Get a pointer to a mutable CNodeState. */
|
|
|
|
|
CNodeState* State(NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
|
|
|
|
|
|
|
|
|
uint32_t GetFetchFlags(const CNode& pfrom) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
|
|
|
|
|
|
|
|
|
std::atomic<std::chrono::microseconds> m_next_inv_to_inbounds{0us};
|
|
|
|
|
|
|
|
|
|
/** Number of nodes with fSyncStarted. */
|
|
|
|
@ -815,16 +826,19 @@ namespace {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
/** Map maintaining per-node state. */
|
|
|
|
|
static std::map<NodeId, CNodeState> mapNodeState GUARDED_BY(cs_main);
|
|
|
|
|
|
|
|
|
|
static CNodeState *State(NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
|
|
|
|
|
std::map<NodeId, CNodeState>::iterator it = mapNodeState.find(pnode);
|
|
|
|
|
const CNodeState* PeerManagerImpl::State(NodeId pnode) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
|
|
|
|
{
|
|
|
|
|
std::map<NodeId, CNodeState>::const_iterator it = mapNodeState.find(pnode);
|
|
|
|
|
if (it == mapNodeState.end())
|
|
|
|
|
return nullptr;
|
|
|
|
|
return &it->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CNodeState* PeerManagerImpl::State(NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
|
|
|
|
{
|
|
|
|
|
return const_cast<CNodeState*>(std::as_const(*this).State(pnode));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the peer supports the address. For example, a peer that does not
|
|
|
|
|
* implement BIP155 cannot receive Tor v3 addresses because it requires
|
|
|
|
@ -1214,9 +1228,7 @@ void PeerManagerImpl::AddTxAnnouncement(const CNode& node, const GenTxid& gtxid,
|
|
|
|
|
m_txrequest.ReceivedInv(nodeid, gtxid, preferred, current_time + delay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This function is used for testing the stale tip eviction logic, see
|
|
|
|
|
// denialofservice_tests.cpp
|
|
|
|
|
void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
|
|
|
|
|
void PeerManagerImpl::UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
|
|
|
|
|
{
|
|
|
|
|
LOCK(cs_main);
|
|
|
|
|
CNodeState *state = State(node);
|
|
|
|
@ -1342,7 +1354,7 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
LOCK(cs_main);
|
|
|
|
|
CNodeState* state = State(nodeid);
|
|
|
|
|
const CNodeState* state = State(nodeid);
|
|
|
|
|
if (state == nullptr)
|
|
|
|
|
return false;
|
|
|
|
|
stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1;
|
|
|
|
@ -2122,7 +2134,8 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint32_t GetFetchFlags(const CNode& pfrom) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
|
|
|
|
|
uint32_t PeerManagerImpl::GetFetchFlags(const CNode& pfrom) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
|
|
|
|
{
|
|
|
|
|
uint32_t nFetchFlags = 0;
|
|
|
|
|
if (State(pfrom.GetId())->fHaveWitness) {
|
|
|
|
|
nFetchFlags |= MSG_WITNESS_FLAG;
|
|
|
|
|