Example #1
0
void CSearchManager::ProcessPublishResult(const CUInt128 &uTarget, const uint8 uLoad, const bool bLoadResponse)
{
	// We tried to publish some info and got a result.
	CSearch *pSearch = NULL;
	SearchMap::const_iterator itSearchMap = m_mapSearches.find(uTarget);
	if (itSearchMap != m_mapSearches.end())
		pSearch = itSearchMap->second;

	// Result could be very late and store deleted, abort.
	if (pSearch == NULL)
		return;

	switch(pSearch->GetSearchTypes())
	{
		case CSearch::STOREKEYWORD:
			if( bLoadResponse )
				pSearch->UpdateNodeLoad( uLoad );
			break;
		case CSearch::STOREFILE:
		case CSearch::STORENOTES:
			break;
	}

	// Inc the number of answers.
	pSearch->m_uAnswers++;
	// Update the search for the GUI
	theApp.emuledlg->kademliawnd->searchList->SearchRef(pSearch);
}
Example #2
0
void CSearchManager::ProcessPublishResult(const CUInt128 &uTarget, const uint8 uLoad, const bool bLoadResponse)
{
	// We tried to publish some info and got a result.
	CSearch *pSearch = NULL;
	SearchMap::const_iterator itSearchMap = m_mapSearches.find(uTarget);
	if (itSearchMap != m_mapSearches.end())
		pSearch = itSearchMap->second;

	// Result could be very late and store deleted, abort.
	if (pSearch == NULL)
		return;

	switch(pSearch->GetSearchTypes())
	{
		case CSearch::STOREKEYWORD:
			if( bLoadResponse )
				pSearch->UpdateNodeLoad( uLoad );
			break;
		case CSearch::STOREFILE:
		case CSearch::STORENOTES:
			break;
	}

	// Inc the number of answers.
	pSearch->m_uAnswers++;
	// Update the search for the GUI

	SendMessage( CGlobalVariable::m_hListenWnd,WM_KAD_SEARCHREF,0,(LPARAM)pSearch );
}
Example #3
0
void CSearchManager::ProcessPublishResult(const CUInt128& target, const uint8_t load, const bool loadResponse)
{
	// We tried to publish some info and got a result.
	CSearch *s = NULL;
	SearchMap::const_iterator it = m_searches.find(target);
	if (it != m_searches.end()) {
		s = it->second;
	}

	// Result could be very late and store deleted, abort.
	if (s == NULL) {
		return;
	}

	switch (s->GetSearchTypes()) {
		case CSearch::STOREKEYWORD: {
			if (loadResponse) {
				s->UpdateNodeLoad(load);
			}
			break;
		}
		case CSearch::STOREFILE:
		case CSearch::STORENOTES:
			break;
	}

	s->m_answers++;
}
Example #4
0
bool CSearchManager::FindNodeFWCheckUDP(){
	CancelNodeFWCheckUDPSearch();
	CUInt128 uID;
	uID.SetValueRandom();
	DebugLog(_T("Starting NODEFWCHECKUDP Kad Search"));
	CSearch *pSearch = new CSearch;
	pSearch->SetSearchTypes(CSearch::NODEFWCHECKUDP);
	pSearch->m_uTarget = uID;
	return StartSearch(pSearch);
}
Example #5
0
bool CSearchManager::FindNodeSpecial(const CUInt128& id, CKadClientSearcher *requester)
{
	// Do a node lookup.
	AddDebugLogLineN(logKadSearch, wxT("Starting NODESPECIAL Kad Search for ") + id.ToHexString());
	CSearch *search = new CSearch;
	search->SetSearchTypes(CSearch::NODESPECIAL);
	search->SetTargetID(id);
	search->SetNodeSpecialSearchRequester(requester);
	return StartSearch(search);
}
Example #6
0
bool CSearchManager::FindNodeFWCheckUDP()
{
	CancelNodeFWCheckUDPSearch();
	CUInt128 id(GetRandomUint128());
	AddDebugLogLineN(logKadSearch, wxT("Starting NODEFWCHECKUDP Kad Search"));
	CSearch *search = new CSearch;
	search->SetSearchTypes(CSearch::NODEFWCHECKUDP);
	search->SetTargetID(id);
	return StartSearch(search);
}
Example #7
0
int main()
{
    CSearch *pSearch;
    pSearch = new(CSearch);
    if (pSearch)
    {
        pSearch->doSearch();
        delete(pSearch);
    }
    return 0;
}
Example #8
0
bool CSearchManager::FindNodeSpecial(const CUInt128 &uID, CKadClientSearcher* pRequester){
	// Do a node lookup.
	CString strDbgID;
	uID.ToHexString(&strDbgID);
	DebugLog(_T("Starting NODESPECIAL Kad Search for %s"), strDbgID);
	CSearch *pSearch = new CSearch;
	pSearch->m_uType = CSearch::NODESPECIAL;
	pSearch->m_uTarget = uID;
	pSearch->SetNodeSpecialSearchRequester(pRequester);
	return StartSearch(pSearch);
}
Example #9
0
void CSearchManager::FindNode(const CUInt128 &uID, bool bComplete)
{
	// Do a node lookup.
	CSearch *pSearch = new CSearch;
	if(bComplete)
		pSearch->SetSearchTypes(CSearch::NODECOMPLETE);
	else
		pSearch->SetSearchTypes(CSearch::NODE);
	pSearch->m_uTarget = uID;
	StartSearch(pSearch);
}
Example #10
0
void CSearchManager::FindNode(const CUInt128& id, bool complete)
{
	// Do a node lookup.
	CSearch *s = new CSearch;
	if (complete) {
		s->SetSearchTypes(CSearch::NODECOMPLETE);
	} else {
		s->SetSearchTypes(CSearch::NODE);
	}
	s->SetTargetID(id);
	StartSearch(s);
}
Example #11
0
CSearch* CSearchManager::PrepareLookup(uint32 uType, bool bStart, const CUInt128 &uID)
{
	// Prepare a kad lookup.
	// Make sure this target is not already in progress.
	if(AlreadySearchingFor(uID))
		return NULL;

	// Create a new search.
	CSearch *pSearch = new CSearch;

	// Set type and target.
	pSearch->m_uType = uType;
	pSearch->m_uTarget = uID;

	try
	{
		switch(pSearch->m_uType)
		{
			case CSearch::STOREKEYWORD:
				if(!Kademlia::CKademlia::GetIndexed()->SendStoreRequest(uID))
				{
					// Keyword Store was determined to be a overloaded node, abort store.
					delete pSearch;
					return NULL;
				}
				break;
		}

		// Inc search ID.
		pSearch->m_uSearchID = ++m_uNextID;
		if( bStart )
		{
			// Auto start this search.
			m_mapSearches[pSearch->m_uTarget] = pSearch;
			pSearch->Go();
		}
	}
	catch ( CIOException *ioe )
	{
//-----> xt	AddDebugLogLine( false, _T("Exception in CSearchManager::PrepareLookup (IO error(%i))"), ioe->m_iCause);
		ioe->Delete();
		delete pSearch;
		return NULL;
	}
	catch (...)
	{
//-----> xt		AddDebugLogLine(false, _T("Exception in CSearchManager::PrepareLookup"));
		delete pSearch;
		return NULL;
	}
	return pSearch;
}
Example #12
0
//-----------------------------------------------------------------------------
// Name: WndProc
// Object: search dialog window proc
// Parameters :
//     in  :
//     out :
//     return :
//-----------------------------------------------------------------------------
LRESULT CALLBACK CSearch::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_INITDIALOG:
    {
        // init dialog
        CSearch* pSearch;
        pSearch=(CSearch*)lParam;
        pSearch->hWndDialog=hWnd;
        SetWindowLongPtr(hWnd,GWLP_USERDATA,(LONG_PTR)pSearch);

        pSearch->Init();
        // load dlg icons
        CDialogHelper::SetIcon(hWnd,IDI_ICON_SEARCH);

    }
    break;
    case WM_CLOSE:
        // close dialog
        ((CSearch*)GetWindowLongPtr(hWnd,GWLP_USERDATA))->Close();
        break;
    case WM_COMMAND:
    {
        CSearch* pSearch=((CSearch*)GetWindowLongPtr(hWnd,GWLP_USERDATA));
        if (!pSearch)
            break;

        switch (LOWORD(wParam))
        {
        case IDC_BUTTON_SEARCH_FIND_FIRST:
            pSearch->Find();
            break;
        case IDC_BUTTON_SEARCH_FIND_NEXT:
            pSearch->FindNext(pSearch->pListview->GetSelectedIndex()+1);
            break;
        case IDC_BUTTON_SEARCH_FIND_PREVIOUS:
            pSearch->FindPrevious(pSearch->pListview->GetSelectedIndex()-1);
            break;
        case IDCANCEL:
            pSearch->Close();
            break;
        }
    }
    default:
        return FALSE;
    }
    return FALSE;
}
Example #13
0
void CSearchManager::ProcessResult(const CUInt128& target, const CUInt128& answer, TagPtrList *info)
{
	// We have results for a request for info.
	CSearch *s = NULL;
	SearchMap::const_iterator it = m_searches.find(target);
	if (it != m_searches.end()) {
		s = it->second;
	}

	// If this search was deleted before these results, delete contacts and abort, otherwise process them.
	if (s == NULL) {
		AddDebugLogLineN(logKadSearch,
			wxT("Search either never existed or receiving late results (CSearchManager::ProcessResult)"));
	} else {
		s->ProcessResult(answer, info);
	}
}
Example #14
0
void CSearchManager::ProcessResult(const CUInt128 &uTarget, const CUInt128 &uAnswer, TagList *plistInfo)
{
	// We have results for a request for info.
	CSearch *pSearch = NULL;
	SearchMap::const_iterator itSearchMap = m_mapSearches.find(uTarget);
	if (itSearchMap != m_mapSearches.end())
		pSearch = itSearchMap->second;

	// If this search was deleted before these results, delete contacts and abort, otherwise process them.
	if (pSearch == NULL)
	{
		for (TagList::const_iterator itTagList = plistInfo->begin(); itTagList != plistInfo->end(); ++itTagList)
			delete *itTagList;
		delete plistInfo;
	}
	else
		pSearch->ProcessResult(uAnswer, plistInfo);
}
Example #15
0
void CSearchManager::ProcessResponse(const CUInt128 &uTarget, uint32 uFromIP, uint16 uFromPort, ContactList *plistResults)
{
	// We got a response to a kad lookup.
	CSearch *pSearch = NULL;
	SearchMap::const_iterator itSearchMap= m_mapSearches.find(uTarget);
	if (itSearchMap != m_mapSearches.end())
		pSearch = itSearchMap->second;

	// If this search was deleted before this response, delete contacts and abort, otherwise process them.
	if (pSearch == NULL)
	{
		for (ContactList::const_iterator itContactList = plistResults->begin(); itContactList != plistResults->end(); ++itContactList)
			delete (*itContactList);
		delete plistResults;
		return;
	}
	else
		pSearch->ProcessResponse(uFromIP, uFromPort, plistResults);
}
Example #16
0
void CSearchManager::ProcessResponse(const CUInt128& target, uint32_t fromIP, uint16_t fromPort, ContactList *results)
{
	// We got a response to a kad lookup.
	CSearch *s = NULL;
	SearchMap::const_iterator it = m_searches.find(target);
	if (it != m_searches.end()) {
		s = it->second;
	}

	// If this search was deleted before this response, delete contacts and abort, otherwise process them.
	if (s == NULL) {
		AddDebugLogLineN(logKadSearch,
			wxT("Search either never existed or receiving late results (CSearchManager::ProcessResponse)"));
		DeleteContents(*results);
	} else {
		s->ProcessResponse(fromIP, fromPort, results);
	}
	delete results;
}
Example #17
0
CSearch* CSearchManager::PrepareLookup(uint32_t type, bool start, const CUInt128& id)
{
	// Prepare a kad lookup.
	// Make sure this target is not already in progress.
	if (AlreadySearchingFor(id)) {
		return NULL;
	}

	// Create a new search.
	CSearch *s = new CSearch;

	// Set type and target.
	s->SetSearchTypes(type);
	s->SetTargetID(id);

	try {
		switch(type) {
			case CSearch::STOREKEYWORD:
				if (!Kademlia::CKademlia::GetIndexed()->SendStoreRequest(id)) {
					delete s;
					return NULL;
				}
				break;
		}

		s->SetSearchID(++m_nextID);
		if (start) {
			m_searches[id] = s;
			s->Go();
		}
	} catch (const CEOFException& DEBUG_ONLY(err)) {
		delete s;
		AddDebugLogLineN(logKadSearch, wxT("CEOFException in CSearchManager::PrepareLookup: ") + err.what());
		return NULL;
	} catch (...) {
		AddDebugLogLineN(logKadSearch, wxT("Exception in CSearchManager::PrepareLookup"));
		delete s;
		throw;
	}

	return s;
}
void AddFile_GUI::load()
{
    CSearch cs;
    //clear old data
    while (model->rowCount() > 0)
    {
        model->removeRow(0);
    }

    QFile file("sharedFiles");
    if(!file.open(QIODevice::ReadOnly)) {
        return;
        //QMessageBox::information(0, "error", file.errorString());
    }

    QTextStream in(&file);

    while(!in.atEnd()) {
        QString line = in.readLine();
        int index =0;
        cs.Search_After(line,"<file>", &index);
        if (index != 6)
            return;

        line = in.readLine();
        QString file_name = "";
        if (cs.getTextBetweenTwoStrings(line,"<file_name>", "</file_name>", file_name))
            return;

        line = in.readLine();
        QString path = "";
        if (cs.getTextBetweenTwoStrings(line,"<path>", "</path>", path))
            return;

        line = in.readLine();
        QString size="";
        if (cs.getTextBetweenTwoStrings(line,"<size>", "</size>", size))
            return;

        line = in.readLine();
        index = 0;
        cs.Search_After(line,"</file>", &index);
        if (index != 7)
            return;

        //add to tableView
        addDataInTableView(file_name, path, size);
    }

    file.close();
}
Example #19
0
CSearch* CSearchManager::PrepareFindKeywords(const wxString& keyword, uint32_t searchTermsDataSize, const uint8_t *searchTermsData, uint32_t searchid)
{
	// Create a keyword search object.
	CSearch *s = new CSearch;
	try {
		// Set search to a keyword type.
		s->SetSearchTypes(CSearch::KEYWORD);

		// Make sure we have a keyword list
		GetWords(keyword, &s->m_words, true);
		if (s->m_words.size() == 0) {
			throw wxString(_("Kademlia: search keyword too short"));
		}

		wxString wstrKeyword = s->m_words.front();

		AddLogLineNS(CFormat(_("Keyword for search: %s")) % wstrKeyword);

		// Kry - I just decided to assume everyone is unicoded
		// GonoszTopi - seconded
		KadGetKeywordHash(wstrKeyword, &s->m_target);

		// Verify that we are not already searching for this target.
		if (AlreadySearchingFor(s->m_target)) {
			throw _("Kademlia: Search keyword is already on search list: ") + wstrKeyword;
		}

		s->SetSearchTermData(searchTermsDataSize, searchTermsData);
		// Inc our searchID
		// If called from external client use predefined search id
		s->SetSearchID((searchid & 0xffffff00) == 0xffffff00 ? searchid : ++m_nextID);
		// Insert search into map
		m_searches[s->GetTarget()] = s;
		// Start search
		s->Go();
	} catch (const CEOFException& err) {
		delete s;
		wxString strError = wxT("CEOFException in ") + wxString::FromAscii(__FUNCTION__) + wxT(": ") + err.what();
		throw strError;
	} catch (const CInvalidPacket& err) {
		delete s;
		wxString strError = wxT("CInvalidPacket exception in ") + wxString::FromAscii(__FUNCTION__) + wxT(": ") + err.what();
		throw strError;
	} catch (...) {
		delete s;
		throw;
	}
	return s;
}
Example #20
0
//----------------------------------------------------------------------------
// Load Personnes list according cmp fonction
//----------------------------------------------------------------------------
void Datas::loadPersonneInListView( QListView *l, CSearch &search, dlgAmonSoft &amon )
{
    std::list< Datas::CPersonnes * >::const_iterator ite;
    QString string;

    qDebug( "loadPersonneInListView" );

    mAssert( l != 0, "l != 0" );
    l->clear();

    for( ite = g_listPersonnes.begin(); ite != g_listPersonnes.end(); ite++ )
    {
        if( search.isPrintable( *ite, amon ) && (*ite)->getID() < (ushort) -1 )
        {
            QListViewItem *item = new QListViewItem( l,
                (*ite)->getNom(),
                (*ite)->getPrenom(),
                (*ite)->getTelephone(),
                (*ite)->getEmail(),
                string.setNum( (*ite)->getID() ) );
        }
    }
    l->sort();
}
Example #21
0
CSearch* CSearchManager::PrepareFindKeywords(bool bUnicode, LPCTSTR szKeyword, UINT uSearchTermsSize, LPBYTE pucSearchTermsData)
{
	// Create a keyword search object.
	CSearch *pSearch = new CSearch;
	try
	{
		// Set search to a keyword type.
		pSearch->m_uType = CSearch::KEYWORD;

		// Make sure we have a keyword list.

/*		char wszKeyword[1000] = {_T("")};
		int nCount = 0;

		CStrConversion strConver;
		strConver.GBK_UNICODE(szKeyword, wszKeyword, nCount);

		GetWords(wszKeyword, &pSearch->m_listWords);
*/
		GetWords(szKeyword, &pSearch->m_listWords);
		if (pSearch->m_listWords.size() == 0)
		{
			delete pSearch;
//-----> xt			throw GetResString(IDS_KAD_SEARCH_KEYWORD_TOO_SHORT);
		}

		// Get the targetID based on the primary keyword.
		CStringW wstrKeyword = pSearch->m_listWords.front();
		if (bUnicode)
			KadGetKeywordHash(wstrKeyword, &pSearch->m_uTarget);
		else
		{
			// backward compatibility: use local ACP encoding
			// TODO: to be removed in some months (when majority of nodes are Unicode compatible)
			CStringA strA(wstrKeyword);
			KadGetKeywordHash(strA, &pSearch->m_uTarget);
		}

		// Verify that we are not already searching for this target.
		if (AlreadySearchingFor(pSearch->m_uTarget))
		{
			delete pSearch;			
//------> xt CString strError;
			CString strError(wstrKeyword);
//------> xt strError.Format(GetResString(IDS_KAD_SEARCH_KEYWORD_ALREADY_SEARCHING), CString(wstrKeyword));
			throw strError;
		}

		pSearch->SetSearchTermData( uSearchTermsSize, pucSearchTermsData );
		// Inc our searchID
		pSearch->m_uSearchID = ++m_uNextID;
		// Insert search into map.
		m_mapSearches[pSearch->m_uTarget] = pSearch;
		// Start search.
		pSearch->Go();
	}
	catch (CIOException* ioe)
	{
		CString strError;
		strError.Format(_T("IO-Exception in %hs: Error %u"), __FUNCTION__, ioe->m_iCause);
		ioe->Delete();
		delete pSearch;
		throw strError;
	}
	catch (CFileException* e)
	{
		TCHAR szError[MAX_CFEXP_ERRORMSG];
		e->m_strFileName = "search packet";
		e->GetErrorMessage(szError, ARRSIZE(szError));
		CString strError;
		strError.Format(_T("Exception in %hs: %s"), __FUNCTION__, szError);
		e->Delete();
		delete pSearch;
		throw strError;
	}
	catch (CString strException)
	{
		throw strException;
	}
	catch (...)
	{
		CString strError;
		strError.Format(_T("Unknown exception in %hs"), __FUNCTION__);
		delete pSearch;
		throw strError;
	}
	return pSearch;
}
Example #22
0
CSearch* CSearchManager::PrepareFindKeywords(LPCTSTR szKeyword, UINT uSearchTermsSize, LPBYTE pucSearchTermsData)
{
	// Create a keyword search object.
	CSearch *pSearch = new CSearch;
	try
	{
		// Set search to a keyword type.
		pSearch->m_uType = CSearch::KEYWORD;

		// Make sure we have a keyword list.
		GetWords(szKeyword, &pSearch->m_listWords);
		if (pSearch->m_listWords.size() == 0)
		{
			delete pSearch;
			throw GetResString(IDS_KAD_SEARCH_KEYWORD_TOO_SHORT);
		}

		// Get the targetID based on the primary keyword.
		CKadTagValueString wstrKeyword = pSearch->m_listWords.front();
			KadGetKeywordHash(wstrKeyword, &pSearch->m_uTarget);

		// Verify that we are not already searching for this target.
		if (AlreadySearchingFor(pSearch->m_uTarget))
		{
			delete pSearch;
			CString strError;
			strError.Format(GetResString(IDS_KAD_SEARCH_KEYWORD_ALREADY_SEARCHING), CString(wstrKeyword));
			throw strError;
		}

		pSearch->SetSearchTermData( uSearchTermsSize, pucSearchTermsData );
		pSearch->SetGUIName(szKeyword);
		// Inc our searchID
		pSearch->m_uSearchID = ++m_uNextID;
		// Insert search into map.
		m_mapSearches[pSearch->m_uTarget] = pSearch;
		// Start search.
		pSearch->Go();
	}
	catch (CIOException* ioe)
	{
		CString strError;
		strError.Format(_T("IO-Exception in %hs: Error %u"), __FUNCTION__, ioe->m_iCause);
		ioe->Delete();
		delete pSearch;
		throw strError;
	}
	catch (CFileException* e)
	{
		TCHAR szError[MAX_CFEXP_ERRORMSG];
		e->m_strFileName = _T("search packet");
		e->GetErrorMessage(szError, ARRSIZE(szError));
		CString strError;
		strError.Format(_T("Exception in %hs: %s"), __FUNCTION__, szError);
		e->Delete();
		delete pSearch;
		throw strError;
	}
	catch (CString strException)
	{
		throw strException;
	}
	catch (...)
	{
		CString strError;
		strError.Format(_T("Unknown exception in %hs"), __FUNCTION__);
		delete pSearch;
		throw strError;
	}
	return pSearch;
}
QList< QList<QString> > AddFile_GUI::getListWithSharedFiles()
{
    CSearch cs;
    QList< QList<QString> > l_shared_files;

    QFile file("sharedFiles");
    if(!file.open(QIODevice::ReadOnly)) {
        return l_shared_files;
    }

    QTextStream in(&file);

    while(!in.atEnd()) {
        QString line = in.readLine();
        int index =0;
        cs.Search_After(line,"<file>", &index);
        if (index != 6)
        {
            file.close();
            return l_shared_files;
        }

        line = in.readLine();
        QString file_name = "";
        if (cs.getTextBetweenTwoStrings(line,"<file_name>", "</file_name>", file_name))
        {
            file.close();
            return l_shared_files;
        }

        line = in.readLine();
        QString path = "";
        if (cs.getTextBetweenTwoStrings(line,"<path>", "</path>", path))
        {
            file.close();
            return l_shared_files;
        }

        line = in.readLine();
        QString size="";
        if (cs.getTextBetweenTwoStrings(line,"<size>", "</size>", size))
        {
            file.close();
            return l_shared_files;
        }

        line = in.readLine();
        index = 0;
        cs.Search_After(line,"</file>", &index);
        if (index != 7)
        {
            file.close();
            return l_shared_files;
        }

        //add to tableView
        QList<QString> item;
        item.push_back(file_name);
        item.push_back(path);
        item.push_back(size);
        l_shared_files.push_back(item);
    }

    file.close();
    return l_shared_files;
}
Example #24
0
void CUser::OnBnClickedButtonsearch2()
{
	// TODO: 在此添加控件通知处理程序代码
	CSearch se;
	se.DoModal();
}