From 52f4cb48590a706caf7a492e8d94b85620d5cd33 Mon Sep 17 00:00:00 2001 From: s_nakamoto Date: Tue, 24 Nov 2009 21:04:50 +0000 Subject: minor fix to batched initial download in case requester has more than 500 block non-main branch git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@41 1a98c847-1fd6-4fd8-948a-caf3550aa51b --- main.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'main.h') diff --git a/main.h b/main.h index 79f14c6861..822045a573 100644 --- a/main.h +++ b/main.h @@ -1298,6 +1298,27 @@ public: vHave.push_back(hashGenesisBlock); } + int GetDistanceBack() + { + // Retrace how far back it was in the sender's branch + int nDistance = 0; + int nStep = 1; + foreach(const uint256& hash, vHave) + { + map::iterator mi = mapBlockIndex.find(hash); + if (mi != mapBlockIndex.end()) + { + CBlockIndex* pindex = (*mi).second; + if (pindex->IsInMainChain()) + return nDistance; + } + nDistance += nStep; + if (nDistance > 10) + nStep *= 2; + } + return nDistance; + } + CBlockIndex* GetBlockIndex() { // Find the first block the caller has in the main chain -- cgit v1.2.3