mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-12 02:55:18 -04:00
Major bugfixes and testing changes for ft.
It is now almost ready for integration with rs. Added ftserver3test.cc which successfully tests: * Hashing of a directory. * Transfer of Cache Files. * Local Searching. * Remote Searching. * Download from multiple sources. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@773 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
889825b77e
commit
88ef2e0e34
17 changed files with 1010 additions and 106 deletions
|
@ -26,6 +26,7 @@
|
|||
#include "ft/ftdbase.h"
|
||||
#include "util/rsdir.h"
|
||||
|
||||
#define DB_DEBUG 1
|
||||
|
||||
ftFiStore::ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,
|
||||
RsPeerId ownid, std::string cachedir)
|
||||
|
@ -36,20 +37,71 @@ ftFiStore::ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,
|
|||
|
||||
bool ftFiStore::search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info) const
|
||||
{
|
||||
/* could use hintflags to specify which bits of fileinfo to use additionally.
|
||||
eg. hintflags & FT_SEARCH_PEER_ID, then only return matching peers + hash.
|
||||
eg. hintflags & FT_SEARCH_NAME, then only return matching name + hash.
|
||||
*
|
||||
* Still to see if concept is worthwhle
|
||||
*/
|
||||
|
||||
#ifdef DB_DEBUG
|
||||
std::cerr << "ftFiStore::search(" << hash << "," << size << "," << hintflags;
|
||||
std::cerr << ")";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::list<FileDetail> results;
|
||||
std::list<FileDetail>::iterator it;
|
||||
|
||||
if (SearchHash(hash, results))
|
||||
{
|
||||
bool first = true;
|
||||
for(it = results.begin(); it != results.end(); it++)
|
||||
{
|
||||
if (it->size == size)
|
||||
{
|
||||
/*
|
||||
*/
|
||||
#ifdef DB_DEBUG
|
||||
std::cerr << "ftFiStore::search() found: ";
|
||||
std::cerr << it->name << " (" << it->size;
|
||||
std::cerr << ") @ " << it->id << " = " << hash;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
bool fullmatch = true;
|
||||
|
||||
if (it->size != size)
|
||||
fullmatch = false;
|
||||
|
||||
|
||||
#if 0
|
||||
if (hintflags & FT_SEARCH_PEER_ID)
|
||||
{
|
||||
pit = std::find(info.srcIds.begin(),
|
||||
info.srcId.end(). it->id);
|
||||
if (pit == info.srcIds.end())
|
||||
{
|
||||
fullmatch = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if (fullmatch)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
info.fname = it->name;
|
||||
info.size = it->size;
|
||||
info.hash = it->hash;
|
||||
}
|
||||
info.peerIds.push_back(it->id);
|
||||
}
|
||||
}
|
||||
|
||||
/* if the first flag is cleared, we've definitely
|
||||
* had a full match!.
|
||||
*/
|
||||
|
||||
if (!first)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -66,9 +118,21 @@ bool ftFiMonitor::search(std::string hash, uint64_t size, uint32_t hintflags, Fi
|
|||
uint64_t fsize;
|
||||
std::string path;
|
||||
|
||||
#ifdef DB_DEBUG
|
||||
std::cerr << "ftFiMonitor::search(" << hash << "," << size << "," << hintflags;
|
||||
std::cerr << ")";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (findLocalFile(hash, path, fsize))
|
||||
{
|
||||
/* fill in details */
|
||||
#ifdef DB_DEBUG
|
||||
std::cerr << "ftFiMonitor::search() found: ";
|
||||
std::cerr << path;
|
||||
std::cerr << " = " << hash << "," << fsize;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
info.size = fsize;
|
||||
info.fname = RsDirUtil::getTopDir(path);
|
||||
|
@ -89,9 +153,22 @@ ftCacheStrapper::ftCacheStrapper(p3AuthMgr *am, p3ConnectMgr *cm)
|
|||
/* overloaded search function */
|
||||
bool ftCacheStrapper::search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info) const
|
||||
{
|
||||
#ifdef DB_DEBUG
|
||||
std::cerr << "ftCacheStrapper::search(" << hash << "," << size << "," << hintflags;
|
||||
std::cerr << ")";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
CacheData data;
|
||||
if (findCache(hash, data))
|
||||
{
|
||||
#ifdef DB_DEBUG
|
||||
std::cerr << "ftCacheStrapper::search() found: ";
|
||||
std::cerr << data.path << "/" << data.name;
|
||||
std::cerr << " = " << data.hash << "," << data.size;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* ... */
|
||||
info.size = data.size;
|
||||
info.fname = data.name;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue