Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 628 Lines • ▼ Show 20 Lines | private: | ||||
* passed to InvRequestTracker. | * passed to InvRequestTracker. | ||||
*/ | */ | ||||
void | void | ||||
AddProofAnnouncement(const CNode &node, const avalanche::ProofId &proofid, | AddProofAnnouncement(const CNode &node, const avalanche::ProofId &proofid, | ||||
std::chrono::microseconds current_time, bool preferred) | std::chrono::microseconds current_time, bool preferred) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_proofrequest); | EXCLUSIVE_LOCKS_REQUIRED(cs_proofrequest); | ||||
/** Send a version message to a peer */ | /** Send a version message to a peer */ | ||||
void PushNodeVersion(const Config &config, CNode &pnode, int64_t nTime); | void PushNodeVersion(const Config &config, CNode &pnode); | ||||
/** | /** | ||||
* Send a ping message every PING_INTERVAL or if requested via RPC. May mark | * Send a ping message every PING_INTERVAL or if requested via RPC. May mark | ||||
* the peer to be disconnected if a ping has timed out. | * the peer to be disconnected if a ping has timed out. | ||||
* We use mockable time for ping timeouts, so setmocktime may cause pings | * We use mockable time for ping timeouts, so setmocktime may cause pings | ||||
* to time out. | * to time out. | ||||
*/ | */ | ||||
void MaybeSendPing(CNode &node_to, Peer &peer, | void MaybeSendPing(CNode &node_to, Peer &peer, | ||||
▲ Show 20 Lines • Show All 883 Lines • ▼ Show 20 Lines | if (!node.HasPermission(requestParams.bypass_request_limits_permissions) && | ||||
requestTracker.CountInFlight(node.GetId()) >= | requestTracker.CountInFlight(node.GetId()) >= | ||||
requestParams.max_peer_request_in_flight) { | requestParams.max_peer_request_in_flight) { | ||||
delay += requestParams.overloaded_peer_delay; | delay += requestParams.overloaded_peer_delay; | ||||
} | } | ||||
return current_time + delay; | return current_time + delay; | ||||
} | } | ||||
void PeerManagerImpl::PushNodeVersion(const Config &config, CNode &pnode, | void PeerManagerImpl::PushNodeVersion(const Config &config, CNode &pnode) { | ||||
int64_t nTime) { | |||||
// Note that pnode.GetLocalServices() is a reflection of the local | // Note that pnode.GetLocalServices() is a reflection of the local | ||||
// services we were offering when the CNode object was created for this | // services we were offering when the CNode object was created for this | ||||
// peer. | // peer. | ||||
ServiceFlags nLocalNodeServices = pnode.GetLocalServices(); | ServiceFlags nLocalNodeServices = pnode.GetLocalServices(); | ||||
const int64_t nTime{count_seconds(GetTime<std::chrono::seconds>())}; | |||||
uint64_t nonce = pnode.GetLocalNonce(); | uint64_t nonce = pnode.GetLocalNonce(); | ||||
const int nNodeStartingHeight{m_best_height}; | const int nNodeStartingHeight{m_best_height}; | ||||
NodeId nodeid = pnode.GetId(); | NodeId nodeid = pnode.GetId(); | ||||
CAddress addr = pnode.addr; | CAddress addr = pnode.addr; | ||||
uint64_t extraEntropy = pnode.GetLocalExtraEntropy(); | uint64_t extraEntropy = pnode.GetLocalExtraEntropy(); | ||||
CAddress addrYou = | CAddress addrYou = | ||||
addr.IsRoutable() && !IsProxy(addr) && addr.IsAddrV1Compatible() | addr.IsRoutable() && !IsProxy(addr) && addr.IsAddrV1Compatible() | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | NodeId nodeid = pnode->GetId(); | ||||
assert(m_txrequest.Count(nodeid) == 0); | assert(m_txrequest.Count(nodeid) == 0); | ||||
} | } | ||||
{ | { | ||||
PeerRef peer = std::make_shared<Peer>(nodeid); | PeerRef peer = std::make_shared<Peer>(nodeid); | ||||
LOCK(m_peer_mutex); | LOCK(m_peer_mutex); | ||||
m_peer_map.emplace_hint(m_peer_map.end(), nodeid, std::move(peer)); | m_peer_map.emplace_hint(m_peer_map.end(), nodeid, std::move(peer)); | ||||
} | } | ||||
if (!pnode->IsInboundConn()) { | if (!pnode->IsInboundConn()) { | ||||
PushNodeVersion(config, *pnode, GetTime()); | PushNodeVersion(config, *pnode); | ||||
} | } | ||||
} | } | ||||
void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler &scheduler) { | void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler &scheduler) { | ||||
std::set<TxId> unbroadcast_txids = m_mempool.GetUnbroadcastTxs(); | std::set<TxId> unbroadcast_txids = m_mempool.GetUnbroadcastTxs(); | ||||
for (const TxId &txid : unbroadcast_txids) { | for (const TxId &txid : unbroadcast_txids) { | ||||
// Sanity check: all unbroadcast txns should exist in the mempool | // Sanity check: all unbroadcast txns should exist in the mempool | ||||
▲ Show 20 Lines • Show All 1,978 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::VERSION) { | ||||
if (pfrom.IsInboundConn() && addrMe.IsRoutable()) { | if (pfrom.IsInboundConn() && addrMe.IsRoutable()) { | ||||
SeenLocal(addrMe); | SeenLocal(addrMe); | ||||
} | } | ||||
// Inbound peers send us their version message when they connect. | // Inbound peers send us their version message when they connect. | ||||
// We send our version message in response. | // We send our version message in response. | ||||
if (pfrom.IsInboundConn()) { | if (pfrom.IsInboundConn()) { | ||||
PushNodeVersion(config, pfrom, GetAdjustedTime()); | PushNodeVersion(config, pfrom); | ||||
} | } | ||||
// Change version | // Change version | ||||
const int greatest_common_version = | const int greatest_common_version = | ||||
std::min(nVersion, PROTOCOL_VERSION); | std::min(nVersion, PROTOCOL_VERSION); | ||||
pfrom.SetCommonVersion(greatest_common_version); | pfrom.SetCommonVersion(greatest_common_version); | ||||
pfrom.nVersion = nVersion; | pfrom.nVersion = nVersion; | ||||
▲ Show 20 Lines • Show All 3,622 Lines • Show Last 20 Lines |