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

📄 indexed.cpp

📁 电驴的MAC源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
				CEntry* currEntry = currNote->entryList.front();				wxASSERT(currEntry!=NULL);				if (currEntry->m_uIP == entry->m_uIP || currEntry->m_uSourceID == entry->m_uSourceID) {					CEntry* currName = currNote->entryList.front();					currNote->entryList.pop_front();					delete currName;					currNote->entryList.push_front(entry);					load = (size * 100) / KADEMLIAMAXNOTESPERFILE;					return true;				}			} else {				//This should never happen!				currNote->entryList.push_front(entry);				wxFAIL;				load = (size * 100) / KADEMLIAMAXNOTESPERFILE;				m_totalIndexNotes++;				return true;			}		}		if (size > KADEMLIAMAXNOTESPERFILE) {			Source* currNote = currNoteHash->m_Source_map.back();			currNoteHash->m_Source_map.pop_back();			wxASSERT(currNote != NULL);			CEntry* currName = currNote->entryList.back();			currNote->entryList.pop_back();			wxASSERT(currName != NULL);			delete currName;			currNote->sourceID.SetValue(sourceID);			currNote->entryList.push_front(entry);			currNoteHash->m_Source_map.push_front(currNote);			load = 100;			return true;		} else {			Source* currNote = new Source;			currNote->sourceID.SetValue(sourceID);			currNote->entryList.push_front(entry);			currNoteHash->m_Source_map.push_front(currNote);			load = (size * 100) / KADEMLIAMAXNOTESPERFILE;			m_totalIndexNotes++;			return true;		}	}}bool CIndexed::AddLoad(const CUInt128& keyID, uint32_t timet){	Load* load = NULL;	if ((uint32_t)time(NULL) > timet) {		return false;	}	LoadMap::iterator it = m_Load_map.find(keyID);	if (it != m_Load_map.end()) {		wxFAIL;		return false;	}	load = new Load();	load->keyID.SetValue(keyID);	load->time = timet;	m_Load_map[load->keyID] = load;	m_totalIndexLoad++;	return true;}void CIndexed::SendValidKeywordResult(const CUInt128& keyID, const SSearchTerm* pSearchTerms, uint32_t ip, uint16_t port, bool oldClient, bool kad2, uint16_t startPosition, const CKadUDPKey& senderKey){	KeyHash* currKeyHash = NULL;	KeyHashMap::iterator itKeyHash = m_Keyword_map.find(keyID);	if (itKeyHash != m_Keyword_map.end()) {		currKeyHash = itKeyHash->second;		CMemFile packetdata(1024 * 50);		if (kad2) {			packetdata.WriteUInt128(Kademlia::CKademlia::GetPrefs()->GetKadID());		}		packetdata.WriteUInt128(keyID);		packetdata.WriteUInt16(50);		const uint16_t maxResults = 300;		int count = 0 - startPosition;		// we do 2 loops: In the first one we ignore all results which have a trustvalue below 1		// in the second one we then also consider those. That way we make sure our 300 max results are not full		// of spam entries. We could also sort by trustvalue, but we would risk to only send popular files this way		// on very hot keywords		bool onlyTrusted = true;		//uint32_t dbgResultsTrusted = 0;		//uint32_t dbgResultsUntrusted = 0;		do {			for (CSourceKeyMap::iterator itSource = currKeyHash->m_Source_map.begin(); itSource != currKeyHash->m_Source_map.end(); ++itSource) {				Source* currSource =  itSource->second;				for (CKadEntryPtrList::iterator itEntry = currSource->entryList.begin(); itEntry != currSource->entryList.end(); ++itEntry) {					Kademlia::CKeyEntry* currName = static_cast<Kademlia::CKeyEntry*>(*itEntry);					wxASSERT(currName->IsKeyEntry());					if ((onlyTrusted ^ (currName->GetTrustValue() < 1.0)) && (!pSearchTerms || currName->SearchTermsMatch(pSearchTerms))) {						if (count < 0) {							count++;						} else if ((uint16_t)count < maxResults) {							if (!oldClient || currName->m_uSize <= OLD_MAX_FILE_SIZE) {								count++;								//if (onlyTrusted) {								//	dbgResultsTrusted++;								//} else {								//	dbgResultsUntrusted++;								//}								packetdata.WriteUInt128(currName->m_uSourceID);								if (kad2) {									currName->WriteTagListWithPublishInfo(&packetdata);								} else {									currName->WriteTagList(&packetdata);								}								if (count % 50 == 0) {									if (kad2) {										DebugSend(Kad2SearchRes, ip, port);										CKademlia::GetUDPListener()->SendPacket(packetdata, KADEMLIA2_SEARCH_RES, ip, port, senderKey, NULL);									} else {										DebugSend(KadSearchRes, ip, port);										CKademlia::GetUDPListener()->SendPacket(packetdata, KADEMLIA_SEARCH_RES, ip, port, senderKey, NULL);									}									packetdata.Reset();									if (kad2) {										packetdata.WriteUInt128(Kademlia::CKademlia::GetPrefs()->GetKadID());									}									packetdata.WriteUInt128(keyID);									packetdata.WriteUInt16(50);								}							}						} else {							itSource = currKeyHash->m_Source_map.end();							--itSource;							break;						}					}				}			}			if (onlyTrusted && count < (int)maxResults) {				onlyTrusted = false;			} else {				break;			}		} while (!onlyTrusted);		// LOGTODO: Remove log		//AddDebugLogLineM(false, logKadIndex, wxString::Format(wxT("Kad keyword search result request: Sent %u trusted and %u untrusted results"), dbgResultsTrusted, dbgResultsUntrusted));		if (count > 0) {			uint16_t countLeft = (uint16_t)count % 50;			if (countLeft) {				if (kad2) {					packetdata.Seek(16 + 16);					packetdata.WriteUInt16(countLeft);					DebugSend(Kad2SearchRes, ip, port);					CKademlia::GetUDPListener()->SendPacket(packetdata, KADEMLIA2_SEARCH_RES, ip, port, senderKey, NULL);				} else {					packetdata.Seek(16);					packetdata.WriteUInt16(countLeft);					DebugSend(KadSearchRes, ip, port);					CKademlia::GetUDPListener()->SendPacket(packetdata, KADEMLIA_SEARCH_RES, ip, port, senderKey, NULL);				}			}		}	}	Clean();}void CIndexed::SendValidSourceResult(const CUInt128& keyID, uint32_t ip, uint16_t port, bool kad2, uint16_t startPosition, uint64_t fileSize, const CKadUDPKey& senderKey){	SrcHash* currSrcHash = NULL;	SrcHashMap::iterator itSrcHash = m_Sources_map.find(keyID);	if (itSrcHash != m_Sources_map.end()) {		currSrcHash = itSrcHash->second;		CMemFile packetdata(1024*50);		if (kad2) {			packetdata.WriteUInt128(Kademlia::CKademlia::GetPrefs()->GetKadID());		}		packetdata.WriteUInt128(keyID);		packetdata.WriteUInt16(50);		uint16_t maxResults = 300;		int count = 0 - startPosition;		for (CKadSourcePtrList::iterator itSource = currSrcHash->m_Source_map.begin(); itSource != currSrcHash->m_Source_map.end(); ++itSource) {			Source* currSource = *itSource;				if (currSource->entryList.size()) {				Kademlia::CEntry* currName = currSource->entryList.front();				if (count < 0) {					count++;				} else if (count < maxResults) {					if (!fileSize || !currName->m_uSize || currName->m_uSize == fileSize) {						packetdata.WriteUInt128(currName->m_uSourceID);						currName->WriteTagList(&packetdata);						count++;						if (count % 50 == 0) {							if (kad2) {								DebugSend(Kad2SearchRes, ip, port);								CKademlia::GetUDPListener()->SendPacket(packetdata, KADEMLIA2_SEARCH_RES, ip, port, senderKey, NULL);							} else {								DebugSend(KadSearchRes, ip, port);								CKademlia::GetUDPListener()->SendPacket(packetdata, KADEMLIA_SEARCH_RES, ip, port, senderKey, NULL);							}							packetdata.Reset();							if (kad2) {								packetdata.WriteUInt128(Kademlia::CKademlia::GetPrefs()->GetKadID());							}							packetdata.WriteUInt128(keyID);							packetdata.WriteUInt16(50);						}					}				} else {					break;				}			}		}		if (count > 0) {			uint16_t countLeft = (uint16_t)count % 50;			if (countLeft) {				if (kad2) {					packetdata.Seek(16 + 16);					packetdata.WriteUInt16(countLeft);					DebugSend(Kad2SearchRes, ip, port);					CKademlia::GetUDPListener()->SendPacket(packetdata, KADEMLIA2_SEARCH_RES, ip, port, senderKey, NULL);				} else {					packetdata.Seek(16);					packetdata.WriteUInt16(countLeft);					DebugSend(KadSearchRes, ip, port);					CKademlia::GetUDPListener()->SendPacket(packetdata, KADEMLIA_SEARCH_RES, ip, port, senderKey, NULL);				}			}		}	}	Clean();}void CIndexed::SendValidNoteResult(const CUInt128& keyID, uint32_t ip, uint16_t port, bool kad2, uint64_t fileSize, const CKadUDPKey& senderKey){	SrcHash* currNoteHash = NULL;	SrcHashMap::iterator itNote = m_Notes_map.find(keyID);	if (itNote != m_Notes_map.end()) {		currNoteHash = itNote->second;				CMemFile packetdata(1024*50);		if (kad2) {			packetdata.WriteUInt128(Kademlia::CKademlia::GetPrefs()->GetKadID());		}		packetdata.WriteUInt128(keyID);		packetdata.WriteUInt16(50);		uint16_t maxResults = 150;		uint16_t count = 0;		for (CKadSourcePtrList::iterator itSource = currNoteHash->m_Source_map.begin(); itSource != currNoteHash->m_Source_map.end(); ++itSource ) {			Source* currNote = *itSource;			if (currNote->entryList.size()) {				Kademlia::CEntry* currName = currNote->entryList.front();				if (count < maxResults) {					if (!fileSize || !currName->m_uSize || fileSize == currName->m_uSize) {						packetdata.WriteUInt128(currName->m_uSourceID);						currName->WriteTagList(&packetdata);						count++;						if (count % 50 == 0) {							if (kad2) {								DebugSend(Kad2SearchRes, ip, port);								CKademlia::GetUDPListener()->SendPacket(packetdata, KADEMLIA2_SEARCH_RES, ip, port, senderKey, NULL);							} else {								DebugSend(KadSearchNotesRes, ip, port);								CKademlia::GetUDPListener()->SendPacket(packetdata, KADEMLIA_SEARCH_NOTES_RES, ip, port, senderKey, NULL);							}							packetdata.Reset();							if (kad2) {								packetdata.WriteUInt128(Kademlia::CKademlia::GetPrefs()->GetKadID());							}							packetdata.WriteUInt128(keyID);							packetdata.WriteUInt16(50);						}					}				} else {					break;				}			}		}		uint16_t countLeft = count % 50;		if (countLeft) {			if (kad2) {				packetdata.Seek(16 + 16);				packetdata.WriteUInt16(countLeft);				DebugSend(Kad2SearchRes, ip, port);				CKademlia::GetUDPListener()->SendPacket(packetdata, KADEMLIA2_SEARCH_RES, ip, port, senderKey, NULL);			} else {				packetdata.Seek(16);				packetdata.WriteUInt16(countLeft);				DebugSend(KadSearchNotesRes, ip, port);				CKademlia::GetUDPListener()->SendPacket(packetdata, KADEMLIA_SEARCH_NOTES_RES, ip, port, senderKey, NULL);			}		}	}}bool CIndexed::SendStoreRequest(const CUInt128& keyID){	Load* load = NULL;	LoadMap::iterator it = m_Load_map.find(keyID);	if (it != m_Load_map.end()) {		load = it->second;		if (load->time < (uint32_t)time(NULL)) {			m_Load_map.erase(it);			m_totalIndexLoad--;			delete load;			return true;		}		return false;	}	return true;}SSearchTerm::SSearchTerm(){	type = AND;	tag = NULL;	left = NULL;	right = NULL;}SSearchTerm::~SSearchTerm(){	if (type == String) {		delete astr;	}	delete tag;}// File_checked_for_headers

⌨️ 快捷键说明

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