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

📄 indexed.cpp

📁 wxWidgets写的电驴
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			CString strTok(item->fileName.Tokenize(_aszInvKadKeywordChars, iPosTok));			while (!strTok.IsEmpty())			{				astrFileNameTokens.Add(strTok);				strTok = item->fileName.Tokenize(_aszInvKadKeywordChars, iPosTok);			}		}		if (astrFileNameTokens.GetCount() == 0)			return false;		// if there are more than one search strings specified (e.g. "aaa bbb ccc") the entire string is handled		// like "aaa AND bbb AND ccc". search all strings from the string search term in the tokenized list of		// the file name. all strings of string search term have to be found (AND)		for (int iSearchTerm = 0; iSearchTerm < iStrSearchTerms; iSearchTerm++)		{			bool bFoundSearchTerm = false;			for (int i = 0; i < astrFileNameTokens.GetCount(); i++)			{				// the file name string was already stored in lowercase				// the string search term was already stored in lowercase				if (strcmp(astrFileNameTokens.GetAt(i), pSearchTerm->astr->GetAt(iSearchTerm)) == 0)				{					bFoundSearchTerm = true;					break;				}			}			if (!bFoundSearchTerm)				return false;		}#else		// if there are more than one search strings specified (e.g. "aaa bbb ccc") the entire string is handled		// like "aaa AND bbb AND ccc". search all strings from the string search term in the tokenized list of		// the file name. all strings of string search term have to be found (AND)		for (int iSearchTerm = 0; iSearchTerm < iStrSearchTerms; iSearchTerm++) {			// this will not give the same results as when tokenizing the filename string, but it is 20 times faster.			if (item->fileName.Find((*(pSearchTerm->astr))[iSearchTerm]) == -1) {				return false;			}		}#endif		return true;		// search string value in all string meta tags (this includes also the filename)		// although this would work, I am no longer sure if it's the correct way to process the search requests..		/*const Kademlia::CTag *tag;		TagList::const_iterator it;		for (it = item->taglist.begin(); it != item->taglist.end(); it++)		{			tag = *it;			if (tag->m_type == 2)			{				//TODO: Use a pre-tokenized list for better performance.				int iPos = 0;				CString strTok(static_cast<const CTagStr *>(tag)->m_value.Tokenize(_aszInvKadKeywordChars, iPos));				while (!strTok.IsEmpty()){					if (stricmp(strTok, *(pSearchTerm->str)) == 0)						return true;					strTok = static_cast<const CTagStr *>(tag)->m_value.Tokenize(_aszInvKadKeywordChars, iPos);				}			}		}		return false;*/	}	if (pSearchTerm->type == SSearchTerm::MetaTag) {		if (pSearchTerm->tag->m_type == 2) { // meta tags with string values			TagList::const_iterator it;			for (it = item->taglist.begin(); it != item->taglist.end(); ++it) {				const Kademlia::CTag* tag = *it;				if (tag->IsStr() && pSearchTerm->tag->m_name.Cmp(tag->m_name) == 0) {					return tag->GetStr().CmpNoCase(pSearchTerm->tag->GetStr()) == 0;				}			}		}	} else if (pSearchTerm->type == SSearchTerm::OpGreaterEqual) { 		if (pSearchTerm->tag->IsInt()) { // meta tags with integer values			TagList::const_iterator it;			for (it = item->taglist.begin(); it != item->taglist.end(); ++it) {				const Kademlia::CTag* tag = *it;				if (tag->IsInt() && pSearchTerm->tag->m_name.Cmp(tag->m_name) == 0) {					return tag->GetInt() >= pSearchTerm->tag->GetInt();				}			}		} else if (pSearchTerm->tag->IsFloat()) { // meta tags with float values			TagList::const_iterator it;			for (it = item->taglist.begin(); it != item->taglist.end(); ++it) {				const Kademlia::CTag* tag = *it;				if (tag->IsFloat() && pSearchTerm->tag->m_name.Cmp(tag->m_name) == 0) {					return tag->GetFloat() >= pSearchTerm->tag->GetFloat();				}			}		}	} else if (pSearchTerm->type == SSearchTerm::OpLessEqual) {		if (pSearchTerm->tag->IsInt()) { // meta tags with integer values			TagList::const_iterator it;			for (it = item->taglist.begin(); it != item->taglist.end(); ++it) {				const Kademlia::CTag* tag = *it;				if (tag->IsInt() && pSearchTerm->tag->m_name.Cmp(tag->m_name) == 0) {					return tag->GetInt() <= pSearchTerm->tag->GetInt();				}			}		} else if (pSearchTerm->tag->IsFloat()) { // meta tags with float values			TagList::const_iterator it;			for (it = item->taglist.begin(); it != item->taglist.end(); ++it) {				const Kademlia::CTag* tag = *it;				if (tag->IsFloat() && pSearchTerm->tag->m_name.Cmp(tag->m_name) == 0) {					return tag->GetFloat() <= pSearchTerm->tag->GetFloat();				}			}		}	} else if (pSearchTerm->type == SSearchTerm::OpGreater) {		if (pSearchTerm->tag->IsInt()) { // meta tags with integer values			TagList::const_iterator it;			for (it = item->taglist.begin(); it != item->taglist.end(); ++it) {				const Kademlia::CTag* tag = *it;				if (tag->IsInt() && pSearchTerm->tag->m_name.Cmp(tag->m_name) == 0) {					return tag->GetInt() > pSearchTerm->tag->GetInt();				}			}		} else if (pSearchTerm->tag->IsFloat()) { // meta tags with float values			TagList::const_iterator it;			for (it = item->taglist.begin(); it != item->taglist.end(); it++) {				const Kademlia::CTag* tag = *it;				if (tag->IsFloat() && pSearchTerm->tag->m_name.Cmp(tag->m_name) == 0) {					return tag->GetFloat() > pSearchTerm->tag->GetFloat();				}			}		}	} else if (pSearchTerm->type == SSearchTerm::OpLess) {		if (pSearchTerm->tag->IsInt()) { // meta tags with integer values			TagList::const_iterator it;			for (it = item->taglist.begin(); it != item->taglist.end(); ++it) {				const Kademlia::CTag* tag = *it;				if (tag->IsInt() && pSearchTerm->tag->m_name.Cmp(tag->m_name) == 0) {					return tag->GetInt() < pSearchTerm->tag->GetInt();				}			}		} else if (pSearchTerm->tag->IsFloat()) { // meta tags with float values			TagList::const_iterator it;			for (it = item->taglist.begin(); it != item->taglist.end(); ++it) {				const Kademlia::CTag* tag = *it;				if (tag->IsFloat() && pSearchTerm->tag->m_name.Cmp(tag->m_name) == 0) {					return tag->GetFloat() < pSearchTerm->tag->GetFloat();				}			}		}	} else if (pSearchTerm->type == SSearchTerm::OpEqual) {		if (pSearchTerm->tag->IsInt()) { // meta tags with integer values			TagList::const_iterator it;			for (it = item->taglist.begin(); it != item->taglist.end(); it++) {				const Kademlia::CTag* tag = *it;				if (tag->IsInt() && pSearchTerm->tag->m_name.Cmp(tag->m_name) == 0) {					return tag->GetInt() == pSearchTerm->tag->GetInt();				}			}		} else if (pSearchTerm->tag->IsFloat()) { // meta tags with float values			TagList::const_iterator it;			for (it = item->taglist.begin(); it != item->taglist.end(); it++) {				const Kademlia::CTag* tag = *it;				if (tag->IsFloat() && pSearchTerm->tag->m_name.Cmp(tag->m_name) == 0) {					return tag->GetFloat() == pSearchTerm->tag->GetFloat();				}			}		}	} else if (pSearchTerm->type == SSearchTerm::OpNotEqual) {		if (pSearchTerm->tag->IsInt()) { // meta tags with integer values			TagList::const_iterator it;			for (it = item->taglist.begin(); it != item->taglist.end(); it++) {				const Kademlia::CTag* tag = *it;				if (tag->IsInt() && pSearchTerm->tag->m_name.Cmp(tag->m_name) == 0) {					return tag->GetInt() != pSearchTerm->tag->GetInt();				}			}		} else if (pSearchTerm->tag->IsFloat()) { // meta tags with float values			TagList::const_iterator it;			for (it = item->taglist.begin(); it != item->taglist.end(); it++) {				const Kademlia::CTag* tag = *it;				if (tag->IsFloat() && pSearchTerm->tag->m_name.Cmp(tag->m_name) == 0) {					return tag->GetFloat() != pSearchTerm->tag->GetFloat();				}			}		}	}	return false;}//bool SearchTermsMatch(const SSearchTerm* pSearchTerm, const Kademlia::CEntry* item)//{//	// tokenize the filename (very expensive) only once per search expression and only if really needed//	CStringArray astrFileNameTokens;//	return SearchTermsMatch(pSearchTerm, item, astrFileNameTokens);//}void CIndexed::SendValidKeywordResult(const CUInt128& keyID, const SSearchTerm* pSearchTerms, uint32 ip, uint16 port){	KeyHash* currKeyHash = NULL;	KeyHashMap::iterator itKeyHash = m_Keyword_map.find(keyID);	if(itKeyHash != m_Keyword_map.end()) {		currKeyHash = itKeyHash->second;		byte packet[1024*50];		CByteIO bio(packet,sizeof(packet));		bio.writeByte(OP_KADEMLIAHEADER);		bio.writeByte(KADEMLIA_SEARCH_RES);		bio.writeUInt128(keyID);		bio.writeUInt16(50);		uint16 maxResults = 300;		uint16 count = 0;		CSourceKeyMap::iterator itSource = currKeyHash->m_Source_map.begin();		for ( ; itSource != currKeyHash->m_Source_map.end(); ++itSource) {			Source* currSource =  itSource->second;			CKadEntryPtrList::iterator itEntry = currSource->entryList.begin();			for (; itEntry != currSource->entryList.end(); ++itEntry) {				Kademlia::CEntry* currName = *itEntry;				if ( !pSearchTerms || SearchTermsMatch(pSearchTerms, currName) ) {					if( count < maxResults ) {						bio.writeUInt128(currName->sourceID);						bio.writeTagList(currName->taglist);						count++;						if( count % 50 == 0 ) {							uint32 len = sizeof(packet)-bio.getAvailable();							AddDebugLogLineM(false, logClientKadUDP, wxT("KadSearchRes ") + Uint32_16toStringIP_Port(wxUINT32_SWAP_ALWAYS(ip), port));							CKademlia::getUDPListener()->sendPacket(packet, len, ip, port);							bio.reset();							bio.writeByte(OP_KADEMLIAHEADER);							bio.writeByte(KADEMLIA_SEARCH_RES);							bio.writeUInt128(keyID);							bio.writeUInt16(50);						}					}				}			}		}		uint16 ccount = count % 50;		if( ccount ) {			uint32 len = sizeof(packet)-bio.getAvailable();			ENDIAN_SWAP_I_16(ccount);			memcpy(packet+18, &ccount, 2);			AddDebugLogLineM(false, logClientKadUDP, wxT("KadSearchRes ") + Uint32_16toStringIP_Port(wxUINT32_SWAP_ALWAYS(ip), port));			CKademlia::getUDPListener()->sendPacket(packet, len, ip, port);		}		clean();	}}void CIndexed::SendValidSourceResult(const CUInt128& keyID, uint32 ip, uint16 port){	SrcHash* currSrcHash = NULL;	SrcHashMap::iterator itSrcHash = m_Sources_map.find(keyID);	if(itSrcHash != m_Sources_map.end()) {		currSrcHash = itSrcHash->second;		byte packet[1024*50];		CByteIO bio(packet,sizeof(packet));		bio.writeByte(OP_KADEMLIAHEADER);		bio.writeByte(KADEMLIA_SEARCH_RES);		bio.writeUInt128(keyID);		bio.writeUInt16(50);		uint16 maxResults = 300;		uint16 count = 0;		CKadSourcePtrList::iterator itSource = currSrcHash->m_Source_map.begin();		for (; itSource != currSrcHash->m_Source_map.end(); ++itSource) {			Source* currSource = *itSource;				if( currSource->entryList.size() ) {				Kademlia::CEntry* currName = currSource->entryList.front();				if( count < maxResults ) {					bio.writeUInt128(currName->sourceID);					bio.writeTagList(currName->taglist);					count++;					if( count % 50 == 0 ) {						uint32 len = sizeof(packet)-bio.getAvailable();						AddDebugLogLineM(false, logClientKadUDP, wxT("KadSearchRes ") + Uint32_16toStringIP_Port(wxUINT32_SWAP_ALWAYS(ip) , port));						CKademlia::getUDPListener()->sendPacket(packet, len, ip, port);						bio.reset();						bio.writeByte(OP_KADEMLIAHEADER);						bio.writeByte(KADEMLIA_SEARCH_RES);						bio.writeUInt128(keyID);						bio.writeUInt16(50);					}				}			}		}		uint16 ccount = count % 50;		if( ccount ) {			ENDIAN_SWAP_I_16(ccount);			uint32 len = sizeof(packet)-bio.getAvailable();			memcpy(packet+18, &ccount, 2);			AddDebugLogLineM(false, logClientKadUDP, wxT("KadSearchRes ") + Uint32_16toStringIP_Port(wxUINT32_SWAP_ALWAYS(ip), port));			CKademlia::getUDPListener()->sendPacket(packet, len, ip, port);		}		clean();	}}void CIndexed::SendValidNoteResult(const CUInt128& keyID, const CUInt128& WXUNUSED(sourceID), uint32 ip, uint16 port){	SrcHash* currNoteHash = NULL;	SrcHashMap::iterator itNote = m_Notes_map.find(keyID);	if(itNote != m_Notes_map.end()) {		currNoteHash = itNote->second;				byte packet[1024*50];		CByteIO bio(packet,sizeof(packet));		bio.writeByte(OP_KADEMLIAHEADER);		bio.writeByte(KADEMLIA_SRC_NOTES_RES);		bio.writeUInt128(keyID);		bio.writeUInt16(50);		uint16 maxResults = 50;		uint16 count = 0;		CKadSourcePtrList::iterator itSource = currNoteHash->m_Source_map.begin();		for (; itSource != currNoteHash->m_Source_map.end(); ++itSource ) {			Source* currNote = *itSource;			if( currNote->entryList.size() ) {				Kademlia::CEntry* currName = currNote->entryList.front();				if( count < maxResults ) {					bio.writeUInt128(currName->sourceID);					bio.writeTagList(currName->taglist);				}				if( count % 50 == 0 ) {					uint32 len = sizeof(packet)-bio.getAvailable();					AddDebugLogLineM(false, logClientKadUDP, wxT("KadNotesRes ") + Uint32_16toStringIP_Port(wxUINT32_SWAP_ALWAYS(ip), port));					CKademlia::getUDPListener()->sendPacket(packet, len, ip, port);					bio.reset();					bio.writeByte(OP_KADEMLIAHEADER);					bio.writeByte(KADEMLIA_SRC_NOTES_RES);					bio.writeUInt128(keyID);					bio.writeUInt16(50);				}			}		}		uint16 ccount = count % 50;		if( ccount ) {			ENDIAN_SWAP_I_16(ccount);			uint32 len = sizeof(packet)-bio.getAvailable();			memcpy(packet+18, &ccount, 2);			AddDebugLogLineM(false, logClientKadUDP, wxT("KadNotesRes ") + Uint32_16toStringIP_Port(wxUINT32_SWAP_ALWAYS(ip), port));			CKademlia::getUDPListener()->sendPacket(packet, len, ip, port);		}		//clean(); //Not needed at the moment.	}}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)time(NULL)) {			m_Load_map.erase(it);			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;}

⌨️ 快捷键说明

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