📄 indexed.cpp
字号:
return pTag->GetInt() <= pSearchTerm->m_pTag->GetInt();
}
}
else if (pSearchTerm->m_pTag->IsFloat()) // meta tags with float values
{
for (TagList::const_iterator itTagList = pItem->m_listTag.begin(); itTagList != pItem->m_listTag.end(); ++itTagList)
{
const Kademlia::CKadTag* pTag = *itTagList;
if (pTag->IsFloat() && pSearchTerm->m_pTag->m_name.Compare(pTag->m_name) == 0)
return pTag->GetFloat() <= pSearchTerm->m_pTag->GetFloat();
}
}
}
else if (pSearchTerm->m_type == SSearchTerm::OpGreater)
{
if (pSearchTerm->m_pTag->IsInt()) // meta tags with integer values
{
for (TagList::const_iterator itTagList = pItem->m_listTag.begin(); itTagList != pItem->m_listTag.end(); ++itTagList)
{
const Kademlia::CKadTag* pTag = *itTagList;
if (pTag->IsInt() && pSearchTerm->m_pTag->m_name.Compare(pTag->m_name) == 0)
return pTag->GetInt() > pSearchTerm->m_pTag->GetInt();
}
}
else if (pSearchTerm->m_pTag->IsFloat()) // meta tags with float values
{
for (TagList::const_iterator itTagList = pItem->m_listTag.begin(); itTagList != pItem->m_listTag.end(); ++itTagList)
{
const Kademlia::CKadTag* pTag = *itTagList;
if (pTag->IsFloat() && pSearchTerm->m_pTag->m_name.Compare(pTag->m_name) == 0)
return pTag->GetFloat() > pSearchTerm->m_pTag->GetFloat();
}
}
}
else if (pSearchTerm->m_type == SSearchTerm::OpLess)
{
if (pSearchTerm->m_pTag->IsInt()) // meta tags with integer values
{
for (TagList::const_iterator itTagList = pItem->m_listTag.begin(); itTagList != pItem->m_listTag.end(); ++itTagList)
{
const Kademlia::CKadTag* pTag = *itTagList;
if (pTag->IsInt() && pSearchTerm->m_pTag->m_name.Compare(pTag->m_name) == 0)
return pTag->GetInt() < pSearchTerm->m_pTag->GetInt();
}
}
else if (pSearchTerm->m_pTag->IsFloat()) // meta tags with float values
{
for (TagList::const_iterator itTagList = pItem->m_listTag.begin(); itTagList != pItem->m_listTag.end(); ++itTagList)
{
const Kademlia::CKadTag* pTag = *itTagList;
if (pTag->IsFloat() && pSearchTerm->m_pTag->m_name.Compare(pTag->m_name) == 0)
return pTag->GetFloat() < pSearchTerm->m_pTag->GetFloat();
}
}
}
else if (pSearchTerm->m_type == SSearchTerm::OpEqual)
{
if (pSearchTerm->m_pTag->IsInt()) // meta tags with integer values
{
for (TagList::const_iterator itTagList = pItem->m_listTag.begin(); itTagList != pItem->m_listTag.end(); ++itTagList)
{
const Kademlia::CKadTag* pTag = *itTagList;
if (pTag->IsInt() && pSearchTerm->m_pTag->m_name.Compare(pTag->m_name) == 0)
return pTag->GetInt() == pSearchTerm->m_pTag->GetInt();
}
}
else if (pSearchTerm->m_pTag->IsFloat()) // meta tags with float values
{
for (TagList::const_iterator itTagList = pItem->m_listTag.begin(); itTagList != pItem->m_listTag.end(); ++itTagList)
{
const Kademlia::CKadTag* pTag = *itTagList;
if (pTag->IsFloat() && pSearchTerm->m_pTag->m_name.Compare(pTag->m_name) == 0)
return pTag->GetFloat() == pSearchTerm->m_pTag->GetFloat();
}
}
}
else if (pSearchTerm->m_type == SSearchTerm::OpNotEqual)
{
if (pSearchTerm->m_pTag->IsInt()) // meta tags with integer values
{
for (TagList::const_iterator itTagList = pItem->m_listTag.begin(); itTagList != pItem->m_listTag.end(); ++itTagList)
{
const Kademlia::CKadTag* pTag = *itTagList;
if (pTag->IsInt() && pSearchTerm->m_pTag->m_name.Compare(pTag->m_name) == 0)
return pTag->GetInt() != pSearchTerm->m_pTag->GetInt();
}
}
else if (pSearchTerm->m_pTag->IsFloat()) // meta tags with float values
{
for (TagList::const_iterator itTagList = pItem->m_listTag.begin(); itTagList != pItem->m_listTag.end(); ++itTagList)
{
const Kademlia::CKadTag* pTag = *itTagList;
if (pTag->IsFloat() && pSearchTerm->m_pTag->m_name.Compare(pTag->m_name) == 0)
return pTag->GetFloat() != pSearchTerm->m_pTag->GetFloat();
}
}
}
return false;
}
void CIndexed::SendValidKeywordResult(const CUInt128& uKeyID, const SSearchTerm* pSearchTerms, uint32 uIP, uint16 uPort, bool bOldClient, bool bKad2, uint16 uStartPosition)
{
KeyHash* pCurrKeyHash;
if(m_mapKeyword.Lookup(CCKey(uKeyID.GetData()), pCurrKeyHash))
{
byte byPacket[1024*50];
CByteIO byIO(byPacket,sizeof(byPacket));
byIO.WriteByte(OP_KADEMLIAHEADER);
if(bKad2)
{
byIO.WriteByte(KADEMLIA2_SEARCH_RES);
byIO.WriteUInt128(Kademlia::CKademlia::GetPrefs()->GetKadID());
}
else
byIO.WriteByte(KADEMLIA_SEARCH_RES);
byIO.WriteUInt128(uKeyID);
byIO.WriteUInt16(50);
uint16 uMaxResults = 300;
int iCount = 0-uStartPosition;
POSITION pos1 = pCurrKeyHash->mapSource.GetStartPosition();
while( pos1 != NULL )
{
CCKey key1;
Source* pCurrSource;
pCurrKeyHash->mapSource.GetNextAssoc( pos1, key1, pCurrSource );
for(POSITION pos2 = pCurrSource->ptrlEntryList.GetHeadPosition(); pos2 != NULL; )
{
CEntry* pCurrName = pCurrSource->ptrlEntryList.GetNext(pos2);
if ( !pSearchTerms || SearchTermsMatch(pSearchTerms, pCurrName) )
{
if( iCount < 0 )
iCount++;
else if( (uint16)iCount < uMaxResults )
{
if((!bOldClient || pCurrName->m_uSize <= OLD_MAX_EMULE_FILE_SIZE))
{
iCount++;
byIO.WriteUInt128(pCurrName->m_uSourceID);
byIO.WriteTagList(pCurrName->m_listTag);
if( iCount % 50 == 0 )
{
uint32 uLen = sizeof(byPacket)-byIO.GetAvailable();
CKademlia::GetUDPListener()->SendPacket(byPacket, uLen, uIP, uPort);
byIO.Reset();
byIO.WriteByte(OP_KADEMLIAHEADER);
if(bKad2)
{
if (thePrefs.GetDebugClientKadUDPLevel() > 0)
DebugSend("KADEMLIA2_SEARCH_RES", uIP, uPort);
byIO.WriteByte(KADEMLIA2_SEARCH_RES);
byIO.WriteUInt128(Kademlia::CKademlia::GetPrefs()->GetKadID());
}
else
{
if (thePrefs.GetDebugClientKadUDPLevel() > 0)
DebugSend("KADEMLIA_SEARCH_RES", uIP, uPort);
byIO.WriteByte(KADEMLIA_SEARCH_RES);
}
byIO.WriteUInt128(uKeyID);
byIO.WriteUInt16(50);
}
}
}
else
{
pos1 = NULL;
break;
}
}
}
}
if(iCount > 0)
{
uint16 uCountLeft = (uint16)iCount % 50;
if( uCountLeft )
{
uint32 uLen = sizeof(byPacket)-byIO.GetAvailable();
if(bKad2)
{
memcpy(byPacket+18+16, &uCountLeft, 2);
if (thePrefs.GetDebugClientKadUDPLevel() > 0)
DebugSend("KADEMLIA2_SEARCH_RES", uIP, uPort);
}
else
{
memcpy(byPacket+18, &uCountLeft, 2);
if (thePrefs.GetDebugClientKadUDPLevel() > 0)
DebugSend("KADEMLIA_SEARCH_RES", uIP, uPort);
}
CKademlia::GetUDPListener()->SendPacket(byPacket, uLen, uIP, uPort);
}
}
}
Clean();
}
void CIndexed::SendValidSourceResult(const CUInt128& uKeyID, uint32 uIP, uint16 uPort, bool bKad2, uint16 uStartPosition, uint64 uFileSize)
{
SrcHash* pCurrSrcHash;
if(m_mapSources.Lookup(CCKey(uKeyID.GetData()), pCurrSrcHash))
{
byte byPacket[1024*50];
CByteIO byIO(byPacket,sizeof(byPacket));
byIO.WriteByte(OP_KADEMLIAHEADER);
if(bKad2)
{
byIO.WriteByte(KADEMLIA2_SEARCH_RES);
byIO.WriteUInt128(Kademlia::CKademlia::GetPrefs()->GetKadID());
}
else
byIO.WriteByte(KADEMLIA_SEARCH_RES);
byIO.WriteUInt128(uKeyID);
byIO.WriteUInt16(50);
uint16 uMaxResults = 300;
int iCount = 0-uStartPosition;
for(POSITION pos1 = pCurrSrcHash->ptrlistSource.GetHeadPosition(); pos1 != NULL; )
{
Source* pCurrSource = pCurrSrcHash->ptrlistSource.GetNext(pos1);
if( pCurrSource->ptrlEntryList.GetSize() )
{
CEntry* pCurrName = pCurrSource->ptrlEntryList.GetHead();
if( iCount < 0 )
iCount++;
else if( (uint16)iCount < uMaxResults )
{
if( !uFileSize || !pCurrName->m_uSize || pCurrName->m_uSize == uFileSize )
{
byIO.WriteUInt128(pCurrName->m_uSourceID);
byIO.WriteTagList(pCurrName->m_listTag);
iCount++;
if( iCount % 50 == 0 )
{
uint32 uLen = sizeof(byPacket)-byIO.GetAvailable();
CKademlia::GetUDPListener()->SendPacket(byPacket, uLen, uIP, uPort);
byIO.Reset();
byIO.WriteByte(OP_KADEMLIAHEADER);
if(bKad2)
{
if (thePrefs.GetDebugClientKadUDPLevel() > 0)
DebugSend("KADEMLIA2_SEARCH_RES", uIP, uPort);
byIO.WriteByte(KADEMLIA2_SEARCH_RES);
byIO.WriteUInt128(Kademlia::CKademlia::GetPrefs()->GetKadID());
}
else
{
if (thePrefs.GetDebugClientKadUDPLevel() > 0)
DebugSend("KADEMLIA_SEARCH_RES", uIP, uPort);
byIO.WriteByte(KADEMLIA_SEARCH_RES);
}
byIO.WriteUInt128(uKeyID);
byIO.WriteUInt16(50);
}
}
}
else
{
break;
}
}
}
if( iCount > 0 )
{
uint16 uCountLeft = (uint16)iCount % 50;
if( uCountLeft )
{
uint32 uLen = sizeof(byPacket)-byIO.GetAvailable();
if(bKad2)
{
memcpy(byPacket+18+16, &uCountLeft, 2);
if (thePrefs.GetDebugClientKadUDPLevel() > 0)
DebugSend("KADEMLIA2_SEARCH_RES", uIP, uPort);
}
else
{
memcpy(byPacket+18, &uCountLeft, 2);
if (thePrefs.GetDebugClientKadUDPLevel() > 0)
DebugSend("KADEMLIA_SEARCH_RES", uIP, uPort);
}
CKademlia::GetUDPListener()->SendPacket(byPacket, uLen, uIP, uPort);
}
}
}
Clean();
}
void CIndexed::SendValidNoteResult(const CUInt128& uKeyID, uint32 uIP, uint16 uPort, bool bKad2, uint64 uFileSize)
{
try
{
SrcHash* pCurrNoteHash;
if(m_mapNotes.Lookup(CCKey(uKeyID.GetData()), pCurrNoteHash))
{
byte byPacket[1024*50];
CByteIO byIO(byPacket,sizeof(byPacket));
byIO.WriteByte(OP_KADEMLIAHEADER);
if(bKad2)
{
byIO.WriteByte(KADEMLIA2_SEARCH_RES);
byIO.WriteUInt128(Kademlia::CKademlia::GetPrefs()->GetKadID());
}
else
byIO.WriteByte(KADEMLIA_SEARCH_NOTES_RES);
byIO.WriteUInt128(uKeyID);
byIO.WriteUInt16(50);
uint16 uMaxResults = 150;
uint16 uCount = 0;
for(POSITION pos1 = pCurrNoteHash->ptrlistSource.GetHeadPosition(); pos1 != NULL; )
{
Source* pCurrNote = pCurrNoteHash->ptrlistSource.GetNext(pos1);
if( pCurrNote->ptrlEntryList.GetSize() )
{
CEntry* pCurrName = pCurrNote->ptrlEntryList.GetHead();
if( uCount < uMaxResults )
{
if( !uFileSize || !pCurrName->m_uSize || uFileSize == pCurrName->m_uSize )
{
byIO.WriteUInt128(pCurrName->m_uSourceID);
byIO.WriteTagList(pCurrName->m_listTag);
uCount++;
if( uCount % 50 == 0 )
{
uint32 uLen = sizeof(byPacket)-byIO.GetAvailable();
CKademlia::GetUDPListener()->SendPacket(byPacket, uLen, uIP, uPort);
byIO.Reset();
byIO.WriteByte(OP_KADEMLIAHEADER);
if(bKad2)
{
if (thePrefs.GetDebugClientKadUDPLevel() > 0)
DebugSend("KADEMLIA2_SEARCH_RES", uIP, uPort);
byIO.WriteByte(KADEMLIA2_SEARCH_RES);
byIO.WriteUInt128(Kademlia::CKademlia::GetPrefs()->GetKadID());
}
else
{
if (thePrefs.GetDebugClientKadUDPLevel() > 0)
DebugSend("KADEMLIA_SEARCH_NOTES_RES", uIP, uPort);
byIO.WriteByte(KADEMLIA_SEARCH_NOTES_RES);
}
byIO.WriteUInt128(uKeyID);
byIO.WriteUInt16(50);
}
}
}
else
{
break;
}
}
}
uint16 uCountLeft = uCount % 50;
if( uCountLeft )
{
uint32 uLen = sizeof(byPacket)-byIO.GetAvailable();
if(bKad2)
{
memcpy(byPacket+18+16, &uCountLeft, 2);
if (thePrefs.GetDebugClientKadUDPLevel() > 0)
DebugSend("KADEMLIA2_SEARCH_RES", uIP, uPort);
}
else
{
memcpy(byPacket+18, &uCountLeft, 2);
if (thePrefs.GetDebugClientKadUDPLevel() > 0)
DebugSend("KADEMLIA_SEARCH_NOTES_RES", uIP, uPort);
}
CKademlia::GetUDPListener()->SendPacket(byPacket, uLen, uIP, uPort);
}
}
}
catch(...)
{
AddDebugLogLine(false, _T("Exception in CIndexed::SendValidNoteResult"));
}
}
bool CIndexed::SendStoreRequest(const CUInt128& uKeyID)
{
Load* pLoad;
if(m_mapLoad.Lookup(CCKey(uKeyID.GetData()), pLoad))
{
if(pLoad->uTime < (uint32)time(NULL))
{
m_mapLoad.RemoveKey(CCKey(uKeyID.GetData()));
m_uTotalIndexLoad--;
delete pLoad;
return true;
}
return false;
}
return true;
}
uint32 CIndexed::GetFileKeyCount()
{
return m_mapKeyword.GetCount();
}
SSearchTerm::SSearchTerm()
{
m_type = AND;
m_pTag = NULL;
m_pLeft = NULL;
m_pRight = NULL;
}
SSearchTerm::~SSearchTerm()
{
if (m_type == String)
delete m_pastr;
delete m_pTag;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -