mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-06 16:15:23 -04:00
Added Cache's to retroshare configuration.
* Completed CacheConfig serialisation. * Switched to Push Cache Mode (faster and more efficient). * Added CancelCacheTransfer() if we have duplicate HASH / CACHEID. * Store remote and local caches. * cleanup all cache directories. * Broke Cache tests :( - because of dependency of mAuthMgr/mConnMgr. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@343 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
1bb4283986
commit
276a6bbd99
21 changed files with 796 additions and 352 deletions
|
@ -9,9 +9,9 @@ include $(RS_TOP_DIR)/scripts/config.mk
|
|||
|
||||
RSOBJ = ft.o ftfiler.o hashsearch.o filedexserver.o
|
||||
|
||||
TESTOBJ = ftcachetest.o
|
||||
TESTOBJ = #ftcachetest.o
|
||||
|
||||
TESTS = ftcachetest
|
||||
TESTS = #ftcachetest
|
||||
|
||||
all: librs tests
|
||||
|
||||
|
|
|
@ -217,10 +217,10 @@ void filedexserver::setFileCallback(std::string ownId, CacheStrapper *strappe
|
|||
/* setup FiStore/Monitor */
|
||||
std::string localcachedir = config_dir + "/cache/local";
|
||||
std::string remotecachedir = config_dir + "/cache/remote";
|
||||
fiStore = new FileIndexStore(ftFiler, cb, ownId, remotecachedir);
|
||||
fiStore = new FileIndexStore(strapper, ftFiler, cb, ownId, remotecachedir);
|
||||
|
||||
/* now setup the FiMon */
|
||||
fimon = new FileIndexMonitor(localcachedir, ownId);
|
||||
fimon = new FileIndexMonitor(strapper, localcachedir, ownId);
|
||||
|
||||
/* setup ftFiler
|
||||
* to find peer info / savedir
|
||||
|
@ -234,10 +234,7 @@ void filedexserver::setFileCallback(std::string ownId, CacheStrapper *strappe
|
|||
CachePair cp(fimon, fiStore, CacheId(RS_SERVICE_TYPE_FILE_INDEX, 0));
|
||||
mCacheStrapper -> addCachePair(cp);
|
||||
|
||||
/* now we can load the cache configuration */
|
||||
//std::string cacheconfig = config_dir + "/caches.cfg";
|
||||
//mCacheStrapper -> loadCaches(cacheconfig);
|
||||
|
||||
#if 0
|
||||
/************ TMP HACK LOAD until new serialiser is finished */
|
||||
/* get filename and hash from configuration */
|
||||
std::string localCacheFile; // = getSSLRoot()->getSetting(LOCAL_CACHE_FILE_KEY);
|
||||
|
@ -270,8 +267,14 @@ void filedexserver::setFileCallback(std::string ownId, CacheStrapper *strappe
|
|||
RsDirUtil::cleanupDirectory(remotecachedir, saveRemoteCaches); /* clean up all */
|
||||
|
||||
/************ TMP HACK LOAD until new serialiser is finished */
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void filedexserver::StartupMonitor()
|
||||
{
|
||||
/* startup the FileMonitor (after cache load) */
|
||||
fimon->setPeriod(600); /* 10 minutes */
|
||||
/* start it up */
|
||||
|
@ -296,9 +299,10 @@ void filedexserver::setFileCallback(std::string ownId, CacheStrapper *strappe
|
|||
delete rsft;
|
||||
}
|
||||
mResumeTransferList.clear();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int filedexserver::FileCacheSave()
|
||||
{
|
||||
/************ TMP HACK SAVE until new serialiser is finished */
|
||||
|
@ -441,29 +445,28 @@ int filedexserver::handleInputQueues()
|
|||
i_init = i;
|
||||
while((cr = pqisi -> RequestedSearch()) != NULL)
|
||||
{
|
||||
//std::cerr << "filedexserver::handleInputQueues() Recvd RequestedSearch (CacheQuery!)" << std::endl;
|
||||
/* just delete these */
|
||||
std::ostringstream out;
|
||||
if (i++ == i_init)
|
||||
{
|
||||
out << "Requested Search:" << std::endl;
|
||||
}
|
||||
out << "Requested Search:" << std::endl;
|
||||
cr -> print(out);
|
||||
pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone, out.str());
|
||||
delete cr;
|
||||
}
|
||||
|
||||
/* these go to the CacheStrapper (handled immediately) */
|
||||
std::map<CacheId, CacheData>::iterator it;
|
||||
std::map<CacheId, CacheData> answer;
|
||||
RsPeerId id;
|
||||
|
||||
mCacheStrapper->handleCacheQuery(id, answer);
|
||||
for(it = answer.begin(); it != answer.end(); it++)
|
||||
// Now handle it replacement (pushed cache results)
|
||||
{
|
||||
std::list<std::pair<RsPeerId, CacheData> > cacheUpdates;
|
||||
std::list<std::pair<RsPeerId, CacheData> >::iterator it;
|
||||
|
||||
mCacheStrapper->getCacheUpdates(cacheUpdates);
|
||||
for(it = cacheUpdates.begin(); it != cacheUpdates.end(); it++)
|
||||
{
|
||||
//std::cerr << "filedexserver::handleInputQueues() Sending (CacheAnswer!)" << std::endl;
|
||||
/* construct reply */
|
||||
RsCacheItem *ci = new RsCacheItem();
|
||||
|
||||
/* id from incoming */
|
||||
ci -> PeerId(cr->PeerId());
|
||||
ci -> PeerId(it->first);
|
||||
|
||||
ci -> file.hash = (it->second).hash;
|
||||
ci -> file.name = (it->second).name;
|
||||
|
@ -473,13 +476,13 @@ int filedexserver::handleInputQueues()
|
|||
ci -> cacheSubId = (it->second).cid.subid;
|
||||
|
||||
std::ostringstream out2;
|
||||
out2 << "Outgoing CacheStrapper reply -> RsCacheItem:" << std::endl;
|
||||
out2 << "Outgoing CacheStrapper Update -> RsCacheItem:" << std::endl;
|
||||
ci -> print(out2);
|
||||
pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone, out2.str());
|
||||
std::cerr << out2.str() << std::endl;
|
||||
|
||||
//pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone, out2.str());
|
||||
pqisi -> SendSearchResult(ci);
|
||||
}
|
||||
|
||||
delete cr;
|
||||
}
|
||||
|
||||
// now File Input.
|
||||
|
@ -545,11 +548,13 @@ int filedexserver::handleOutputQueues()
|
|||
//std::cerr << "filedexserver::handleOutputQueues()" << std::endl;
|
||||
int i = 0;
|
||||
|
||||
|
||||
#if 0 /* no more cache queries -> results are pushed */
|
||||
|
||||
std::list<RsPeerId> ids;
|
||||
std::list<RsPeerId>::iterator pit;
|
||||
|
||||
mCacheStrapper->sendCacheQuery(ids, time(NULL));
|
||||
|
||||
for(pit = ids.begin(); pit != ids.end(); pit++)
|
||||
{
|
||||
//std::cerr << "filedexserver::handleOutputQueues() Cache Query for: " << (*pit) << std::endl;
|
||||
|
@ -569,6 +574,8 @@ int filedexserver::handleOutputQueues()
|
|||
/* send it off */
|
||||
pqisi -> SearchSpecific(cr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* now see if the filer has any data */
|
||||
ftFileRequest *ftr;
|
||||
|
|
|
@ -154,10 +154,13 @@ bool loadConfigMap(std::map<std::string, std::string> &configMap);
|
|||
int FileStoreTick();
|
||||
int FileCacheSave();
|
||||
|
||||
/* Setup */
|
||||
void initialiseFileStore();
|
||||
void setFileCallback(std::string ownId, CacheStrapper *strapper,
|
||||
ftfiler *ft, NotifyBase *cb);
|
||||
void StartupMonitor();
|
||||
|
||||
/* Controls */
|
||||
int RequestDirDetails(std::string uid, std::string path, DirDetails &details);
|
||||
int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
|
||||
|
||||
|
|
|
@ -173,6 +173,46 @@ bool ftfiler::RequestCacheFile(std::string id, std::string destpath, std::str
|
|||
return 1;
|
||||
}
|
||||
|
||||
bool ftfiler::CancelCacheFile(RsPeerId id, std::string path,
|
||||
std::string hash, uint64_t size)
|
||||
{
|
||||
/* clean up old transfer - just remove it (no callback) */
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "ftfiler::CancelCacheFile() Looking for: " << hash;
|
||||
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
|
||||
}
|
||||
|
||||
/* iterate through fileItems and check for this one */
|
||||
std::list<ftFileStatus *>::iterator it;
|
||||
for(it = recvFiles.begin(); it != recvFiles.end(); it++)
|
||||
{
|
||||
if ((hash==(*it)->hash) &&
|
||||
(size==(*it)->size) &&
|
||||
((*it)->ftMode == FT_MODE_CACHE))
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "ftfiler::CancelCacheFile() ";
|
||||
out << "Match ftFileStatus: " << hash;
|
||||
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
|
||||
/* same */
|
||||
|
||||
std::cerr << "Clearing Failed Cache Transfer: " << (*it)->name;
|
||||
std::cerr << std::endl;
|
||||
delete (*it);
|
||||
it = recvFiles.erase(it);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "************* ERROR *****************";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "ftfiler::CancelCacheFile() Failed to Find: " << hash;
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ftFileStatus *ftfiler::findRecvFileItem(std::string hash)
|
||||
|
|
|
@ -159,6 +159,9 @@ virtual ~ftfiler() { return; }
|
|||
|
||||
virtual bool RequestCacheFile(std::string id, std::string path,
|
||||
std::string hash, uint64_t size);
|
||||
virtual bool CancelCacheFile(RsPeerId id, std::string path,
|
||||
std::string hash, uint64_t size);
|
||||
|
||||
virtual int getFile(std::string name, std::string hash,
|
||||
uint64_t size, std::string destpath);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue