Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 477 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* When a peer sends us a valid block, instruct it to announce blocks to us | * When a peer sends us a valid block, instruct it to announce blocks to us | ||||
* using CMPCTBLOCK if possible by adding its nodeid to the end of | * using CMPCTBLOCK if possible by adding its nodeid to the end of | ||||
* lNodesAnnouncingHeaderAndIDs, and keeping that list under a certain size by | * lNodesAnnouncingHeaderAndIDs, and keeping that list under a certain size by | ||||
* removing the first element if necessary. | * removing the first element if necessary. | ||||
*/ | */ | ||||
static void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, | static void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, | ||||
CConnman *connman) { | CConnman *connman) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | |||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
CNodeState *nodestate = State(nodeid); | CNodeState *nodestate = State(nodeid); | ||||
if (!nodestate) { | if (!nodestate) { | ||||
LogPrint(BCLog::NET, "node state unavailable: peer=%d\n", nodeid); | LogPrint(BCLog::NET, "node state unavailable: peer=%d\n", nodeid); | ||||
return; | return; | ||||
} | } | ||||
if (!nodestate->fProvidesHeaderAndIDs) { | if (!nodestate->fProvidesHeaderAndIDs) { | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 444 Lines • ▼ Show 20 Lines | |||||
// blockchain -> download logic notification | // blockchain -> download logic notification | ||||
// | // | ||||
// To prevent fingerprinting attacks, only send blocks/headers outside of the | // To prevent fingerprinting attacks, only send blocks/headers outside of the | ||||
// active chain if they are no more than a month older (both in time, and in | // active chain if they are no more than a month older (both in time, and in | ||||
// best equivalent proof of work) than the best header chain we know about and | // best equivalent proof of work) than the best header chain we know about and | ||||
// we fully-validated them at some point. | // we fully-validated them at some point. | ||||
static bool BlockRequestAllowed(const CBlockIndex *pindex, | static bool BlockRequestAllowed(const CBlockIndex *pindex, | ||||
const Consensus::Params &consensusParams) { | const Consensus::Params &consensusParams) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | |||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
if (chainActive.Contains(pindex)) { | if (chainActive.Contains(pindex)) { | ||||
return true; | return true; | ||||
} | } | ||||
return pindex->IsValid(BlockValidity::SCRIPTS) && | return pindex->IsValid(BlockValidity::SCRIPTS) && | ||||
(pindexBestHeader != nullptr) && | (pindexBestHeader != nullptr) && | ||||
(pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() < | (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() < | ||||
STALE_RELAY_AGE_LIMIT) && | STALE_RELAY_AGE_LIMIT) && | ||||
▲ Show 20 Lines • Show All 458 Lines • ▼ Show 20 Lines | if (send && pindex->nStatus.hasData()) { | ||||
connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::INV, vInv)); | connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::INV, vInv)); | ||||
pfrom->hashContinue.SetNull(); | pfrom->hashContinue.SetNull(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
static void ProcessGetData(const Config &config, CNode *pfrom, | static void ProcessGetData(const Config &config, CNode *pfrom, | ||||
CConnman *connman, | CConnman *connman, | ||||
const std::atomic<bool> &interruptMsgProc) { | const std::atomic<bool> &interruptMsgProc) | ||||
LOCKS_EXCLUDED(cs_main) { | |||||
AssertLockNotHeld(cs_main); | AssertLockNotHeld(cs_main); | ||||
std::deque<CInv>::iterator it = pfrom->vRecvGetData.begin(); | std::deque<CInv>::iterator it = pfrom->vRecvGetData.begin(); | ||||
std::vector<CInv> vNotFound; | std::vector<CInv> vNotFound; | ||||
const CNetMsgMaker msgMaker(pfrom->GetSendVersion()); | const CNetMsgMaker msgMaker(pfrom->GetSendVersion()); | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
▲ Show 20 Lines • Show All 1,882 Lines • ▼ Show 20 Lines | else { | ||||
// Ignore unknown commands for extensibility | // Ignore unknown commands for extensibility | ||||
LogPrint(BCLog::NET, "Unknown command \"%s\" from peer=%d\n", | LogPrint(BCLog::NET, "Unknown command \"%s\" from peer=%d\n", | ||||
SanitizeString(strCommand), pfrom->GetId()); | SanitizeString(strCommand), pfrom->GetId()); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
static bool SendRejectsAndCheckIfBanned(CNode *pnode, CConnman *connman) { | static bool SendRejectsAndCheckIfBanned(CNode *pnode, CConnman *connman) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | |||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
CNodeState &state = *State(pnode->GetId()); | CNodeState &state = *State(pnode->GetId()); | ||||
if (g_enable_bip61) { | if (g_enable_bip61) { | ||||
for (const CBlockReject &reject : state.rejects) { | for (const CBlockReject &reject : state.rejects) { | ||||
connman->PushMessage( | connman->PushMessage( | ||||
pnode, | pnode, | ||||
CNetMsgMaker(INIT_PROTO_VERSION) | CNetMsgMaker(INIT_PROTO_VERSION) | ||||
▲ Show 20 Lines • Show All 1,043 Lines • Show Last 20 Lines |