⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indexed.cpp

📁 电驴的MAC源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
					for (CKadEntryPtrList::iterator itEntry = SrcEntryList.begin(); itEntry != SrcEntryList.end(); ++itEntry) {						Kademlia::CKeyEntry* currName = static_cast<Kademlia::CKeyEntry*>(*itEntry);						wxASSERT(currName->IsKeyEntry());						k_file.WriteUInt32(currName->m_tLifeTime);						currName->WritePublishTrackingDataToFile(&k_file);						currName->WriteTagList(&k_file);						currName->DirtyDeletePublishData();						delete currName;						k_total++;					}					delete currSource;				}				CKeyEntry::ResetGlobalTrackingMap();				delete currKeyHash;			}			k_file.Close();		}		AddDebugLogLineM( false, logKadIndex, wxString::Format(wxT("Wrote %u source, %u keyword, and %u load entries"), s_total, k_total, l_total));		for (SrcHashMap::iterator itNoteHash = m_Notes_map.begin(); itNoteHash != m_Notes_map.end(); ++itNoteHash) {			SrcHash* currNoteHash = itNoteHash->second;			CKadSourcePtrList& KeyHashNoteMap = currNoteHash->m_Source_map;			for (CKadSourcePtrList::iterator itNote = KeyHashNoteMap.begin(); itNote != KeyHashNoteMap.end(); ++itNote) {				Source* currNote = *itNote;				CKadEntryPtrList& NoteEntryList = currNote->entryList;				for (CKadEntryPtrList::iterator itNoteEntry = NoteEntryList.begin(); itNoteEntry != NoteEntryList.end(); ++itNoteEntry) {					delete *itNoteEntry;				}				delete currNote;			}			delete currNoteHash;		} 		m_Notes_map.clear();	} catch (const CSafeIOException& err) {		AddDebugLogLineM(true, logKadIndex, wxT("CSafeIOException in CIndexed::~CIndexed: ") + err.what());	} catch (const CInvalidPacket& err) {		AddDebugLogLineM(true, logKadIndex, wxT("CInvalidPacket Exception in CIndexed::~CIndexed: ") + err.what());			} catch (const wxString& e) {		AddDebugLogLineM(true, logKadIndex, wxT("Exception in CIndexed::~CIndexed: ") + e);	}}void CIndexed::Clean(){	time_t tNow = time(NULL);	if (m_lastClean > tNow) {		return;	}	uint32_t k_Removed = 0;	uint32_t s_Removed = 0;	uint32_t s_Total = 0;	uint32_t k_Total = 0;	KeyHashMap::iterator itKeyHash = m_Keyword_map.begin();	while (itKeyHash != m_Keyword_map.end()) {		KeyHashMap::iterator curr_itKeyHash = itKeyHash++; // Don't change this to a ++it!		KeyHash* currKeyHash = curr_itKeyHash->second;		for (CSourceKeyMap::iterator itSource = currKeyHash->m_Source_map.begin(); itSource != currKeyHash->m_Source_map.end(); ) {			CSourceKeyMap::iterator curr_itSource = itSource++; // Don't change this to a ++it!			Source* currSource = curr_itSource->second;			CKadEntryPtrList::iterator itEntry = currSource->entryList.begin();			while (itEntry != currSource->entryList.end()) {				k_Total++;				Kademlia::CKeyEntry* currName = static_cast<Kademlia::CKeyEntry*>(*itEntry);				wxASSERT(currName->IsKeyEntry());				if (!currName->m_bSource && currName->m_tLifeTime < tNow) {					k_Removed++;					itEntry = currSource->entryList.erase(itEntry);					delete currName;					continue;				} else if (currName->m_bSource) {					wxFAIL;				} else {					currName->CleanUpTrackedPublishers();	// intern cleanup				}				++itEntry;			}			if (currSource->entryList.empty()) {				currKeyHash->m_Source_map.erase(curr_itSource);				delete currSource;			}		}		if (currKeyHash->m_Source_map.empty()) {			m_Keyword_map.erase(curr_itKeyHash);			delete currKeyHash;		}	}	SrcHashMap::iterator itSrcHash = m_Sources_map.begin();	while (itSrcHash != m_Sources_map.end()) {		SrcHashMap::iterator curr_itSrcHash = itSrcHash++; // Don't change this to a ++it!		SrcHash* currSrcHash = curr_itSrcHash->second;		CKadSourcePtrList::iterator itSource = currSrcHash->m_Source_map.begin();		while (itSource != currSrcHash->m_Source_map.end()) {			Source* currSource = *itSource;						CKadEntryPtrList::iterator itEntry = currSource->entryList.begin();			while (itEntry != currSource->entryList.end()) {				s_Total++;				Kademlia::CEntry* currName = *itEntry;				if (currName->m_tLifeTime < tNow) {					s_Removed++;					itEntry = currSource->entryList.erase(itEntry);					delete currName;				} else {					++itEntry;				}			}			if (currSource->entryList.empty()) {				itSource = currSrcHash->m_Source_map.erase(itSource);				delete currSource;			} else {				++itSource;			}		}		if (currSrcHash->m_Source_map.empty()) {			m_Sources_map.erase(curr_itSrcHash);			delete currSrcHash;		}	}	m_totalIndexSource = s_Total - s_Removed;	m_totalIndexKeyword = k_Total - k_Removed;	AddDebugLogLineM( false, logKadIndex, wxString::Format(wxT("Removed %u keyword out of %u and %u source out of %u"),  k_Removed, k_Total, s_Removed, s_Total));	m_lastClean = tNow + MIN2S(30);}bool CIndexed::AddKeyword(const CUInt128& keyID, const CUInt128& sourceID, Kademlia::CKeyEntry* entry, uint8_t& load){	if (!entry) {		return false;	}	wxCHECK(entry->IsKeyEntry(), false);	if (m_totalIndexKeyword > KADEMLIAMAXENTRIES) {		load = 100;		return false;	}	if (entry->m_uSize == 0 || entry->GetCommonFileName().IsEmpty() || entry->GetTagCount() == 0 || entry->m_tLifeTime < time(NULL)) {		return false;	}	KeyHashMap::iterator itKeyHash = m_Keyword_map.find(keyID); 	KeyHash* currKeyHash = NULL;	if (itKeyHash == m_Keyword_map.end()) {		Source* currSource = new Source;		currSource->sourceID.SetValue(sourceID);		entry->MergeIPsAndFilenames(NULL); // IpTracking init		currSource->entryList.push_front(entry);		currKeyHash = new KeyHash;		currKeyHash->keyID.SetValue(keyID);		currKeyHash->m_Source_map[currSource->sourceID] = currSource;		m_Keyword_map[currKeyHash->keyID] = currKeyHash;		load = 1;		m_totalIndexKeyword++;		return true;	} else {		currKeyHash = itKeyHash->second; 		size_t indexTotal = currKeyHash->m_Source_map.size();		if (indexTotal > KADEMLIAMAXINDEX) {			load = 100;			//Too many entries for this Keyword..			return false;		}		Source* currSource = NULL;		CSourceKeyMap::iterator itSource = currKeyHash->m_Source_map.find(sourceID);		if (itSource != currKeyHash->m_Source_map.end()) {			currSource = itSource->second;			if (currSource->entryList.size() > 0) {				if (indexTotal > KADEMLIAMAXINDEX - 5000) {					load = 100;					//We are in a hot node.. If we continued to update all the publishes					//while this index is full, popular files will be the only thing you index.					return false;				}				// also check for size match				CKeyEntry *oldEntry = NULL;				for (CKadEntryPtrList::iterator itEntry = currSource->entryList.begin(); itEntry != currSource->entryList.end(); ++itEntry) {					CKeyEntry *currEntry = static_cast<Kademlia::CKeyEntry*>(*itEntry);					wxASSERT(currEntry->IsKeyEntry());					if (currEntry->m_uSize == entry->m_uSize) {						oldEntry = currEntry;						currSource->entryList.erase(itEntry);						break;					}				}				entry->MergeIPsAndFilenames(oldEntry);	// oldEntry can be NULL, that's ok and we still need to do this call in this case				if (oldEntry == NULL) {					m_totalIndexKeyword++;					AddDebugLogLineM(false, logKadIndex, wxT("Multiple sizes published for file ") + entry->m_uSourceID.ToHexString());				}				delete oldEntry;				oldEntry = NULL;			} else {				m_totalIndexKeyword++;				entry->MergeIPsAndFilenames(NULL); // IpTracking init			}			load = (uint8_t)((indexTotal * 100) / KADEMLIAMAXINDEX);			currSource->entryList.push_front(entry);			return true;		} else {			currSource = new Source;			currSource->sourceID.SetValue(sourceID);			entry->MergeIPsAndFilenames(NULL); // IpTracking init			currSource->entryList.push_front(entry);			currKeyHash->m_Source_map[currSource->sourceID] = currSource;			m_totalIndexKeyword++;			load = (indexTotal * 100) / KADEMLIAMAXINDEX;			return true;		}	}}bool CIndexed::AddSources(const CUInt128& keyID, const CUInt128& sourceID, Kademlia::CEntry* entry, uint8_t& load){	if (!entry) {		return false;	}	if( entry->m_uIP == 0 || entry->m_uTCPport == 0 || entry->m_uUDPport == 0 || entry->GetTagCount() == 0 || entry->m_tLifeTime < time(NULL)) {		return false;	}			SrcHash* currSrcHash = NULL;	SrcHashMap::iterator itSrcHash = m_Sources_map.find(keyID);	if (itSrcHash == m_Sources_map.end()) {		Source* currSource = new Source;		currSource->sourceID.SetValue(sourceID);		currSource->entryList.push_front(entry);		currSrcHash = new SrcHash;		currSrcHash->keyID.SetValue(keyID);		currSrcHash->m_Source_map.push_front(currSource);		m_Sources_map[currSrcHash->keyID] =  currSrcHash;		m_totalIndexSource++;		load = 1;		return true;	} else {		currSrcHash = itSrcHash->second;		size_t size = currSrcHash->m_Source_map.size();		for (CKadSourcePtrList::iterator itSource = currSrcHash->m_Source_map.begin(); itSource != currSrcHash->m_Source_map.end(); ++itSource) {			Source* currSource = *itSource;			if (currSource->entryList.size()) {				CEntry* currEntry = currSource->entryList.front();				wxASSERT(currEntry != NULL);				if (currEntry->m_uIP == entry->m_uIP && (currEntry->m_uTCPport == entry->m_uTCPport || currEntry->m_uUDPport == entry->m_uUDPport)) {					CEntry* currName = currSource->entryList.front();					currSource->entryList.pop_front();					delete currName;					currSource->entryList.push_front(entry);					load = (size * 100) / KADEMLIAMAXSOURCEPERFILE;					return true;				}			} else {				//This should never happen!				currSource->entryList.push_front(entry);				wxFAIL;				load = (size * 100) / KADEMLIAMAXSOURCEPERFILE;				return true;			}		}		if (size > KADEMLIAMAXSOURCEPERFILE) {			Source* currSource = currSrcHash->m_Source_map.back();			currSrcHash->m_Source_map.pop_back();			wxASSERT(currSource != NULL);			Kademlia::CEntry* currName = currSource->entryList.back();			currSource->entryList.pop_back();			wxASSERT(currName != NULL);			delete currName;			currSource->sourceID.SetValue(sourceID);			currSource->entryList.push_front(entry);			currSrcHash->m_Source_map.push_front(currSource);			load = 100;			return true;		} else {			Source* currSource = new Source;			currSource->sourceID.SetValue(sourceID);			currSource->entryList.push_front(entry);			currSrcHash->m_Source_map.push_front(currSource);			m_totalIndexSource++;			load = (size * 100) / KADEMLIAMAXSOURCEPERFILE;			return true;		}	}		return false;}bool CIndexed::AddNotes(const CUInt128& keyID, const CUInt128& sourceID, Kademlia::CEntry* entry, uint8_t& load){	if (!entry) {		return false;	}	if (entry->m_uIP == 0 || entry->GetTagCount() == 0) {		return false;	}	SrcHash* currNoteHash = NULL;	SrcHashMap::iterator itNoteHash = m_Notes_map.find(keyID);	if (itNoteHash == m_Notes_map.end()) {		Source* currNote = new Source;		currNote->sourceID.SetValue(sourceID);		currNote->entryList.push_front(entry);		currNoteHash = new SrcHash;		currNoteHash->keyID.SetValue(keyID);		currNoteHash->m_Source_map.push_front(currNote);		m_Notes_map[currNoteHash->keyID] = currNoteHash;		load = 1;		m_totalIndexNotes++;		return true;	} else {		currNoteHash = itNoteHash->second;		size_t size = currNoteHash->m_Source_map.size();		for (CKadSourcePtrList::iterator itSource = currNoteHash->m_Source_map.begin(); itSource != currNoteHash->m_Source_map.end(); ++itSource) {						Source* currNote = *itSource;						if( currNote->entryList.size() ) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -