Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 482 Lines • ▼ Show 20 Lines | |||||
static void UpdatePreferredDownload(const CNode &node, CNodeState *state) | static void UpdatePreferredDownload(const CNode &node, CNodeState *state) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | ||||
nPreferredDownload -= state->fPreferredDownload; | nPreferredDownload -= state->fPreferredDownload; | ||||
// Whether this node should be marked as a preferred download node. | // Whether this node should be marked as a preferred download node. | ||||
state->fPreferredDownload = | state->fPreferredDownload = | ||||
(!node.fInbound || node.HasPermission(PF_NOBAN)) && | (!node.fInbound || node.HasPermission(PF_NOBAN)) && | ||||
!node.m_addr_fetch && !node.fClient; | !node.IsAddrFetchConn() && !node.fClient; | ||||
nPreferredDownload += state->fPreferredDownload; | nPreferredDownload += state->fPreferredDownload; | ||||
} | } | ||||
static void PushNodeVersion(const Config &config, CNode &pnode, | static void PushNodeVersion(const Config &config, CNode &pnode, | ||||
CConnman &connman, int64_t nTime) { | CConnman &connman, 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 | ||||
▲ Show 20 Lines • Show All 431 Lines • ▼ Show 20 Lines | void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds) { | ||||
CNodeState *state = State(node); | CNodeState *state = State(node); | ||||
if (state) { | if (state) { | ||||
state->m_last_block_announcement = time_in_seconds; | state->m_last_block_announcement = time_in_seconds; | ||||
} | } | ||||
} | } | ||||
static bool IsOutboundDisconnectionCandidate(const CNode &node) { | static bool IsOutboundDisconnectionCandidate(const CNode &node) { | ||||
return !(node.fInbound || node.IsManualConn() || node.IsFeelerConn() || | return !(node.fInbound || node.IsManualConn() || node.IsFeelerConn() || | ||||
node.m_addr_fetch); | node.IsAddrFetchConn()); | ||||
} | } | ||||
void PeerLogicValidation::InitializeNode(const Config &config, CNode *pnode) { | void PeerLogicValidation::InitializeNode(const Config &config, CNode *pnode) { | ||||
CAddress addr = pnode->addr; | CAddress addr = pnode->addr; | ||||
std::string addrName = pnode->GetAddrName(); | std::string addrName = pnode->GetAddrName(); | ||||
NodeId nodeid = pnode->GetId(); | NodeId nodeid = pnode->GetId(); | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
▲ Show 20 Lines • Show All 1,845 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::ADDR) { | ||||
vAddrOk.push_back(addr); | vAddrOk.push_back(addr); | ||||
} | } | ||||
} | } | ||||
connman.AddNewAddresses(vAddrOk, pfrom.addr, 2 * 60 * 60); | connman.AddNewAddresses(vAddrOk, pfrom.addr, 2 * 60 * 60); | ||||
if (vAddr.size() < 1000) { | if (vAddr.size() < 1000) { | ||||
pfrom.fGetAddr = false; | pfrom.fGetAddr = false; | ||||
} | } | ||||
if (pfrom.m_addr_fetch) { | if (pfrom.IsAddrFetchConn()) { | ||||
pfrom.fDisconnect = true; | pfrom.fDisconnect = true; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
if (msg_type == NetMsgType::SENDHEADERS) { | if (msg_type == NetMsgType::SENDHEADERS) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
State(pfrom.GetId())->fPreferHeaders = true; | State(pfrom.GetId())->fPreferHeaders = true; | ||||
▲ Show 20 Lines • Show All 1,858 Lines • ▼ Show 20 Lines | bool PeerLogicValidation::SendMessages(const Config &config, CNode *pto, | ||||
if (pindexBestHeader == nullptr) { | if (pindexBestHeader == nullptr) { | ||||
pindexBestHeader = ::ChainActive().Tip(); | pindexBestHeader = ::ChainActive().Tip(); | ||||
} | } | ||||
// Download if this is a nice peer, or we have no nice peers and this one | // Download if this is a nice peer, or we have no nice peers and this one | ||||
// might do. | // might do. | ||||
bool fFetch = | bool fFetch = | ||||
state.fPreferredDownload || | state.fPreferredDownload || | ||||
(nPreferredDownload == 0 && !pto->fClient && !pto->m_addr_fetch); | (nPreferredDownload == 0 && !pto->fClient && !pto->IsAddrFetchConn()); | ||||
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) { | if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) { | ||||
// Only actively request headers from a single peer, unless we're close | // Only actively request headers from a single peer, unless we're close | ||||
// to today. | // to today. | ||||
if ((nSyncStarted == 0 && fFetch) || | if ((nSyncStarted == 0 && fFetch) || | ||||
pindexBestHeader->GetBlockTime() > | pindexBestHeader->GetBlockTime() > | ||||
GetAdjustedTime() - 24 * 60 * 60) { | GetAdjustedTime() - 24 * 60 * 60) { | ||||
state.fSyncStarted = true; | state.fSyncStarted = true; | ||||
▲ Show 20 Lines • Show All 600 Lines • Show Last 20 Lines |