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

Method LoadHashSet

src/SHAHashSet.cpp:776–847  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

774
775
776bool CAICHHashSet::LoadHashSet()
777{
778 if (m_eStatus != AICH_HASHSETCOMPLETE) {
779 wxFAIL;
780 return false;
781 }
782 if ( !m_pHashTree.m_bHashValid || m_pHashTree.m_nDataSize != m_pOwner->GetFileSize() || m_pHashTree.m_nDataSize == 0) {
783 wxFAIL;
784 return false;
785 }
786 wxString fullpath = thePrefs::GetConfigDir() + KNOWN2_MET_FILENAME;
787 CFile file(fullpath, CFile::read);
788 if (!file.IsOpened()) {
789 if (wxFileExists(fullpath)) {
790 wxString strError("Failed to load " KNOWN2_MET_FILENAME " file");
791 AddDebugLogLineC(logSHAHashSet, strError);
792 }
793 return false;
794 }
795
796 try {
797 uint8 header = file.ReadUInt8();
798 if (header != KNOWN2_MET_VERSION) {
799 AddDebugLogLineC(logSHAHashSet, "Loading failed: Current file is not a met-file!");
800 return false;
801 }
802
803 CAICHHash CurrentHash;
804 uint64 nExistingSize = file.GetLength();
805 uint32 nHashCount;
806 while (file.GetPosition() < nExistingSize) {
807 CurrentHash.Read(&file);
808 if (m_pHashTree.m_Hash == CurrentHash) {
809 // found Hashset
810 uint32 nExpectedCount = (PARTSIZE/EMBLOCKSIZE + ((PARTSIZE % EMBLOCKSIZE != 0)? 1 : 0)) * (m_pHashTree.m_nDataSize/PARTSIZE);
811 if (m_pHashTree.m_nDataSize % PARTSIZE != 0) {
812 nExpectedCount += (m_pHashTree.m_nDataSize % PARTSIZE)/EMBLOCKSIZE + (((m_pHashTree.m_nDataSize % PARTSIZE) % EMBLOCKSIZE != 0)? 1 : 0);
813 }
814 nHashCount = file.ReadUInt32();
815 if (nHashCount != nExpectedCount) {
816 AddDebugLogLineC(logSHAHashSet, "Failed to load HashSet: Available Hashs and expected hashcount differ!");
817 return false;
818 }
819 if (!m_pHashTree.LoadLowestLevelHashs(&file)) {
820 AddDebugLogLineC(logSHAHashSet, "Failed to load HashSet: LoadLowestLevelHashs failed!");
821 return false;
822 }
823 if (!ReCalculateHash(false)) {
824 AddDebugLogLineC(logSHAHashSet, "Failed to load HashSet: Calculating loaded hashs failed!");
825 return false;
826 }
827 if (CurrentHash != m_pHashTree.m_Hash) {
828 AddDebugLogLineC(logSHAHashSet, "Failed to load HashSet: Calculated Masterhash differs from given Masterhash - hashset corrupt!");
829 return false;
830 }
831 return true;
832 }
833 nHashCount = file.ReadUInt32();

Callers

nothing calls this directly

Calls 11

GetConfigDirFunction · 0.85
ReadUInt8Method · 0.80
ReadUInt32Method · 0.80
LoadLowestLevelHashsMethod · 0.80
SeekMethod · 0.80
whatMethod · 0.80
GetFileSizeMethod · 0.45
IsOpenedMethod · 0.45
GetLengthMethod · 0.45
GetPositionMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected