Changeset View
Changeset View
Standalone View
Standalone View
src/txrequest.cpp
Show First 20 Lines • Show All 574 Lines • ▼ Show 20 Lines | private: | ||||
} | } | ||||
//! Make the data structure consistent with a given point in time: | //! Make the data structure consistent with a given point in time: | ||||
//! - REQUESTED annoucements with expiry <= now are turned into COMPLETED. | //! - REQUESTED annoucements with expiry <= now are turned into COMPLETED. | ||||
//! - CANDIDATE_DELAYED announcements with reqtime <= now are turned into | //! - CANDIDATE_DELAYED announcements with reqtime <= now are turned into | ||||
//! CANDIDATE_{READY,BEST}. | //! CANDIDATE_{READY,BEST}. | ||||
//! - CANDIDATE_{READY,BEST} announcements with reqtime > now are turned | //! - CANDIDATE_{READY,BEST} announcements with reqtime > now are turned | ||||
//! into CANDIDATE_DELAYED. | //! into CANDIDATE_DELAYED. | ||||
void SetTimePoint(std::chrono::microseconds now) { | void SetTimePoint(std::chrono::microseconds now, | ||||
std::vector<std::pair<NodeId, TxId>> *expired) { | |||||
if (expired) { | |||||
expired->clear(); | |||||
} | |||||
// Iterate over all CANDIDATE_DELAYED and REQUESTED from old to new, as | // Iterate over all CANDIDATE_DELAYED and REQUESTED from old to new, as | ||||
// long as they're in the past, and convert them to CANDIDATE_READY and | // long as they're in the past, and convert them to CANDIDATE_READY and | ||||
// COMPLETED respectively. | // COMPLETED respectively. | ||||
while (!m_index.empty()) { | while (!m_index.empty()) { | ||||
auto it = m_index.get<ByTime>().begin(); | auto it = m_index.get<ByTime>().begin(); | ||||
if (it->GetState() == State::CANDIDATE_DELAYED && | if (it->GetState() == State::CANDIDATE_DELAYED && | ||||
it->m_time <= now) { | it->m_time <= now) { | ||||
PromoteCandidateReady(m_index.project<ByTxId>(it)); | PromoteCandidateReady(m_index.project<ByTxId>(it)); | ||||
} else if (it->GetState() == State::REQUESTED && | } else if (it->GetState() == State::REQUESTED && | ||||
it->m_time <= now) { | it->m_time <= now) { | ||||
if (expired) { | |||||
expired->emplace_back(it->m_peer, it->m_txid); | |||||
} | |||||
MakeCompleted(m_index.project<ByTxId>(it)); | MakeCompleted(m_index.project<ByTxId>(it)); | ||||
} else { | } else { | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
while (!m_index.empty()) { | while (!m_index.empty()) { | ||||
// If time went backwards, we may need to demote CANDIDATE_BEST and | // If time went backwards, we may need to demote CANDIDATE_BEST and | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | void ReceivedInv(NodeId peer, const TxId &txid, bool preferred, | ||||
} | } | ||||
// Update accounting metadata. | // Update accounting metadata. | ||||
++m_peerinfo[peer].m_total; | ++m_peerinfo[peer].m_total; | ||||
++m_current_sequence; | ++m_current_sequence; | ||||
} | } | ||||
//! Find the TxIds to request now from peer. | //! Find the TxIds to request now from peer. | ||||
std::vector<TxId> GetRequestable(NodeId peer, | std::vector<TxId> | ||||
std::chrono::microseconds now) { | GetRequestable(NodeId peer, std::chrono::microseconds now, | ||||
std::vector<std::pair<NodeId, TxId>> *expired) { | |||||
// Move time. | // Move time. | ||||
SetTimePoint(now); | SetTimePoint(now, expired); | ||||
// Find all CANDIDATE_BEST announcements for this peer. | // Find all CANDIDATE_BEST announcements for this peer. | ||||
std::vector<const Announcement *> selected; | std::vector<const Announcement *> selected; | ||||
auto it_peer = m_index.get<ByPeer>().lower_bound( | auto it_peer = m_index.get<ByPeer>().lower_bound( | ||||
ByPeerView{peer, true, TxId(uint256::ZERO)}); | ByPeerView{peer, true, TxId(uint256::ZERO)}); | ||||
while (it_peer != m_index.get<ByPeer>().end() && | while (it_peer != m_index.get<ByPeer>().end() && | ||||
it_peer->m_peer == peer && | it_peer->m_peer == peer && | ||||
it_peer->GetState() == State::CANDIDATE_BEST) { | it_peer->GetState() == State::CANDIDATE_BEST) { | ||||
▲ Show 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | void TxRequestTracker::RequestedTx(NodeId peer, const TxId &txid, | ||||
std::chrono::microseconds expiry) { | std::chrono::microseconds expiry) { | ||||
m_impl->RequestedTx(peer, txid, expiry); | m_impl->RequestedTx(peer, txid, expiry); | ||||
} | } | ||||
void TxRequestTracker::ReceivedResponse(NodeId peer, const TxId &txid) { | void TxRequestTracker::ReceivedResponse(NodeId peer, const TxId &txid) { | ||||
m_impl->ReceivedResponse(peer, txid); | m_impl->ReceivedResponse(peer, txid); | ||||
} | } | ||||
std::vector<TxId> | std::vector<TxId> TxRequestTracker::GetRequestable( | ||||
TxRequestTracker::GetRequestable(NodeId peer, std::chrono::microseconds now) { | NodeId peer, std::chrono::microseconds now, | ||||
return m_impl->GetRequestable(peer, now); | std::vector<std::pair<NodeId, TxId>> *expired) { | ||||
return m_impl->GetRequestable(peer, now, expired); | |||||
} | } | ||||
uint64_t TxRequestTracker::ComputePriority(const TxId &txid, NodeId peer, | uint64_t TxRequestTracker::ComputePriority(const TxId &txid, NodeId peer, | ||||
bool preferred) const { | bool preferred) const { | ||||
return m_impl->ComputePriority(txid, peer, preferred); | return m_impl->ComputePriority(txid, peer, preferred); | ||||
} | } |