diff options
author | Eric Lombrozo <elombrozo@gmail.com> | 2013-01-07 06:39:53 -0800 |
---|---|---|
committer | Eric Lombrozo <elombrozo@gmail.com> | 2013-06-05 20:36:10 -0700 |
commit | 8926263dde10bed3f42e21e5f106365f1192e6c0 (patch) | |
tree | 2b00ca18e361e9ea76351b3dff39c8947ded8568 | |
parent | 336fe971e68f0336d42e1fa930b6a9c717f612e0 (diff) |
Moved PushGetBlocks to main.cpp to eliminate dependence of net.cpp on CBlockLocator.
-rw-r--r-- | src/main.cpp | 19 | ||||
-rw-r--r-- | src/main.h | 3 | ||||
-rw-r--r-- | src/net.cpp | 11 | ||||
-rw-r--r-- | src/net.h | 1 |
4 files changed, 18 insertions, 16 deletions
diff --git a/src/main.cpp b/src/main.cpp index b8b7771611..65ae78a136 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2208,6 +2208,17 @@ bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, uns return (nFound >= nRequired); } +void PushGetBlocks(CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd) +{ + // Filter out duplicate requests + if (pindexBegin == pnode->pindexLastGetBlocksBegin && hashEnd == pnode->hashLastGetBlocksEnd) + return; + pnode->pindexLastGetBlocksBegin = pindexBegin; + pnode->hashLastGetBlocksEnd = hashEnd; + + pnode->PushMessage("getblocks", CBlockLocator(pindexBegin), hashEnd); +} + bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp) { // Check for duplicate @@ -2253,7 +2264,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl mapOrphanBlocksByPrev.insert(make_pair(pblock2->hashPrevBlock, pblock2)); // Ask this guy to fill in what we're missing - pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(pblock2)); + PushGetBlocks(pfrom, pindexBest, GetOrphanRoot(pblock2)); } return true; } @@ -3357,12 +3368,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (!fImporting && !fReindex) pfrom->AskFor(inv); } else if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash)) { - pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(mapOrphanBlocks[inv.hash])); + PushGetBlocks(pfrom, pindexBest, GetOrphanRoot(mapOrphanBlocks[inv.hash])); } else if (nInv == nLastBlock) { // In case we are on a very long side-chain, it is possible that we already have // the last block in an inv bundle sent in response to getblocks. Try to detect // this situation and push another getblocks to continue. - pfrom->PushGetBlocks(mapBlockIndex[inv.hash], uint256(0)); + PushGetBlocks(pfrom, mapBlockIndex[inv.hash], uint256(0)); if (fDebug) printf("force request: %s\n", inv.ToString().c_str()); } @@ -3839,7 +3850,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // Start block sync if (pto->fStartSync && !fImporting && !fReindex) { pto->fStartSync = false; - pto->PushGetBlocks(pindexBest, uint256(0)); + PushGetBlocks(pto, pindexBest, uint256(0)); } // Resend wallet transactions that haven't gotten in a block yet diff --git a/src/main.h b/src/main.h index fae37ea512..feaa10318c 100644 --- a/src/main.h +++ b/src/main.h @@ -122,6 +122,9 @@ void RegisterWallet(CWallet* pwalletIn); void UnregisterWallet(CWallet* pwalletIn); /** Push an updated transaction to all registered wallets */ void SyncWithWallets(const uint256 &hash, const CTransaction& tx, const CBlock* pblock = NULL, bool fUpdate = false); + +void PushGetBlocks(CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd); + /** Process an incoming block */ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp = NULL); /** Check whether enough disk space is available for an incoming block */ diff --git a/src/net.cpp b/src/net.cpp index 54ed1d9b51..8929919f03 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -79,17 +79,6 @@ unsigned short GetListenPort() return (unsigned short)(GetArg("-port", GetDefaultPort())); } -void CNode::PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd) -{ - // Filter out duplicate requests - if (pindexBegin == pindexLastGetBlocksBegin && hashEnd == hashLastGetBlocksEnd) - return; - pindexLastGetBlocksBegin = pindexBegin; - hashLastGetBlocksEnd = hashEnd; - - PushMessage("getblocks", CBlockLocator(pindexBegin), hashEnd); -} - // find 'best' local address for a particular peer bool GetLocal(CService& addr, const CNetAddr *paddrPeer) { @@ -600,7 +600,6 @@ public: } } - void PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd); bool IsSubscribed(unsigned int nChannel); void Subscribe(unsigned int nChannel, unsigned int nHops=0); void CancelSubscribe(unsigned int nChannel); |