MCPcopy Create free account
hub / github.com/amule-project/amule / CreatePartRecoveryData

Method CreatePartRecoveryData

src/SHAHashSet.cpp:277–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275
276
277bool CAICHHashTree::CreatePartRecoveryData(uint64 nStartPos, uint64 nSize, CFileDataIO* fileDataOut, uint32 wHashIdent, bool b32BitIdent)
278{
279 wxCHECK(nStartPos + nSize <= m_nDataSize, false);
280 wxCHECK(nSize <= m_nDataSize, false);
281
282 if (nStartPos == 0 && nSize == m_nDataSize) {
283 // this is the searched part, now write all blocks of this part
284 // hashident for this level will be adjusted by WriteLowestLevelHash
285 return WriteLowestLevelHashs(fileDataOut, wHashIdent, false, b32BitIdent);
286 } else if (m_nDataSize <= m_nBaseSize) { // sanity
287 // this is already the last level, can't go deeper
288 wxFAIL;
289 return false;
290 } else {
291 wHashIdent <<= 1;
292 wHashIdent |= (m_bIsLeftBranch) ? 1: 0;
293
294 uint64 nBlocks = m_nDataSize / m_nBaseSize + ((m_nDataSize % m_nBaseSize != 0 )? 1:0);
295 uint64 nLeft = ( ((m_bIsLeftBranch) ? nBlocks+1:nBlocks) / 2)* m_nBaseSize;
296 uint64 nRight = m_nDataSize - nLeft;
297 if (m_pLeftTree == NULL || m_pRightTree == NULL) {
298 wxFAIL;
299 return false;
300 }
301 if (nStartPos < nLeft) {
302 if (nStartPos + nSize > nLeft || !m_pRightTree->m_bHashValid) { // sanity
303 wxFAIL;
304 return false;
305 }
306 m_pRightTree->WriteHash(fileDataOut, wHashIdent, b32BitIdent);
307 return m_pLeftTree->CreatePartRecoveryData(nStartPos, nSize, fileDataOut, wHashIdent, b32BitIdent);
308 } else {
309 nStartPos -= nLeft;
310 if (nStartPos + nSize > nRight || !m_pLeftTree->m_bHashValid) { // sanity
311 wxFAIL;
312 return false;
313 }
314 m_pLeftTree->WriteHash(fileDataOut, wHashIdent, b32BitIdent);
315 return m_pRightTree->CreatePartRecoveryData(nStartPos, nSize, fileDataOut, wHashIdent, b32BitIdent);
316
317 }
318 }
319}
320
321
322void CAICHHashTree::WriteHash(CFileDataIO* fileDataOut, uint32 wHashIdent, bool b32BitIdent) const

Callers 1

ProcessAICHRequestMethod · 0.80

Calls 8

CFormatClass · 0.85
IsLargeFileMethod · 0.80
WriteUInt16Method · 0.80
WriteHashMethod · 0.45
IsPartFileMethod · 0.45
GetFileSizeMethod · 0.45
FindHashMethod · 0.45
GetPositionMethod · 0.45

Tested by

no test coverage detected