mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 23:49:35 -05:00
added an optional cache for hashes, so that hashed files are remembered for some days.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3729 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
5cc222d251
commit
630156a5e8
@ -43,6 +43,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
//***********
|
//***********
|
||||||
//#define FIM_DEBUG 1
|
//#define FIM_DEBUG 1
|
||||||
@ -51,12 +52,198 @@
|
|||||||
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in,std::string cachedir, std::string pid)
|
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in,std::string cachedir, std::string pid)
|
||||||
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid),
|
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid),
|
||||||
pendingDirs(false), pendingForceCacheWrite(false),
|
pendingDirs(false), pendingForceCacheWrite(false),
|
||||||
mForceCheck(false), mInCheck(false),cb(cb_in)
|
mForceCheck(false), mInCheck(false),cb(cb_in), hashCache(cachedir+"/" + "fc-own-cache.rsfa"),useHashCache(true)
|
||||||
|
|
||||||
{
|
{
|
||||||
updatePeriod = 60;
|
updatePeriod = 60;
|
||||||
}
|
}
|
||||||
|
bool FileIndexMonitor::rememberHashFiles()
|
||||||
|
{
|
||||||
|
RsStackMutex mtx(fiMutex) ; /* LOCKED DIRS */
|
||||||
|
return useHashCache ;
|
||||||
|
}
|
||||||
|
void FileIndexMonitor::setRememberHashFiles(bool b)
|
||||||
|
{
|
||||||
|
RsStackMutex mtx(fiMutex) ; /* LOCKED DIRS */
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << "Setting useHashCache to " << b << std::endl;
|
||||||
|
#endif
|
||||||
|
useHashCache = b ;
|
||||||
|
}
|
||||||
|
void FileIndexMonitor::setRememberHashFilesDuration(uint32_t days)
|
||||||
|
{
|
||||||
|
RsStackMutex mtx(fiMutex) ; /* LOCKED DIRS */
|
||||||
|
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << "Setting HashCache duration to " << days << std::endl;
|
||||||
|
#endif
|
||||||
|
hashCache.setRememberHashFilesDuration(days) ;
|
||||||
|
hashCache.clean() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t FileIndexMonitor::rememberHashFilesDuration() const
|
||||||
|
{
|
||||||
|
RsStackMutex mtx(fiMutex) ; /* LOCKED DIRS */
|
||||||
|
|
||||||
|
return hashCache.rememberHashFilesDuration() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove any memory of formerly hashed files that are not shared anymore
|
||||||
|
void FileIndexMonitor::clearHashFiles()
|
||||||
|
{
|
||||||
|
RsStackMutex mtx(fiMutex) ; /* LOCKED DIRS */
|
||||||
|
|
||||||
|
hashCache.clear() ;
|
||||||
|
hashCache.save() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashCache::HashCache(const std::string& path)
|
||||||
|
: _path(path)
|
||||||
|
{
|
||||||
|
_max_cache_duration_days = 10 ; // 10 days is the default value.
|
||||||
|
_files.clear() ;
|
||||||
|
_changed = false ;
|
||||||
|
std::ifstream f(_path.c_str()) ;
|
||||||
|
|
||||||
|
std::streamsize max_line_size = 2000 ; // should be enough. Anyway, if we
|
||||||
|
// miss one entry, we just lose some
|
||||||
|
// cache itemsn but this is not too
|
||||||
|
// much of a problem.
|
||||||
|
char *buff = new char[max_line_size] ;
|
||||||
|
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << "Loading HashCache from file " << path << std::endl ;
|
||||||
|
int n=0 ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
while(f.good())
|
||||||
|
{
|
||||||
|
HashCacheInfo info ;
|
||||||
|
|
||||||
|
f.getline(buff,max_line_size,'\n') ;
|
||||||
|
std::string name(buff) ;
|
||||||
|
|
||||||
|
f.getline(buff,max_line_size,'\n') ; if(sscanf(buff,"%lld",&info.size) != 1) break ;
|
||||||
|
f.getline(buff,max_line_size,'\n') ; if(sscanf(buff,"%ld",&info.time_stamp) != 1) break ;
|
||||||
|
f.getline(buff,max_line_size,'\n') ; if(sscanf(buff,"%ld",&info.modf_stamp) != 1) break ;
|
||||||
|
f.getline(buff,max_line_size,'\n') ; info.hash = std::string(buff) ;
|
||||||
|
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << " (" << name << ", " << info.size << ", " << info.time_stamp << ", " << info.modf_stamp << ", " << info.hash << std::endl ;
|
||||||
|
++n ;
|
||||||
|
#endif
|
||||||
|
_files[name] = info ;
|
||||||
|
}
|
||||||
|
f.close() ;
|
||||||
|
|
||||||
|
delete[] buff ;
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << n << " entries loaded." << std::endl ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void HashCache::save()
|
||||||
|
{
|
||||||
|
if(_changed)
|
||||||
|
{
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << "Saving Hash Cache to file " << _path << "..." << std::endl ;
|
||||||
|
#endif
|
||||||
|
std::ofstream f( (_path+".tmp").c_str() ) ;
|
||||||
|
|
||||||
|
for(std::map<std::string,HashCacheInfo>::const_iterator it(_files.begin());it!=_files.end();++it)
|
||||||
|
{
|
||||||
|
f << it->first << std::endl ;
|
||||||
|
f << it->second.size << std::endl;
|
||||||
|
f << it->second.time_stamp << std::endl;
|
||||||
|
f << it->second.modf_stamp << std::endl;
|
||||||
|
f << it->second.hash << std::endl;
|
||||||
|
}
|
||||||
|
f.close() ;
|
||||||
|
|
||||||
|
RsDirUtil::renameFile(_path+".tmp",_path) ;
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << "done." << std::endl ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
_changed = false ;
|
||||||
|
}
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
else
|
||||||
|
std::cerr << "Hash cache not changed. Not saving." << std::endl ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HashCache::find(const std::string& full_path,uint64_t size,time_t time_stamp,std::string& hash)
|
||||||
|
{
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << "HashCache: looking for " << full_path << std::endl ;
|
||||||
|
#endif
|
||||||
|
time_t now = time(NULL) ;
|
||||||
|
std::map<std::string,HashCacheInfo>::iterator it(_files.find(full_path)) ;
|
||||||
|
|
||||||
|
if(it != _files.end() && time_stamp == it->second.modf_stamp && size == it->second.size)
|
||||||
|
{
|
||||||
|
hash = it->second.hash ;
|
||||||
|
it->second.time_stamp = now ;
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << "Found in cache." << std::endl ;
|
||||||
|
#endif
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << "not found in cache." << std::endl ;
|
||||||
|
#endif
|
||||||
|
return false ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void HashCache::insert(const std::string& full_path,uint64_t size,time_t time_stamp,const std::string& hash)
|
||||||
|
{
|
||||||
|
HashCacheInfo info ;
|
||||||
|
info.size = size ;
|
||||||
|
info.modf_stamp = time_stamp ;
|
||||||
|
info.time_stamp = time(NULL) ;
|
||||||
|
info.hash = hash ;
|
||||||
|
|
||||||
|
_files[full_path] = info ;
|
||||||
|
_changed = true ;
|
||||||
|
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << "Entry inserted in cache: " << full_path << ", " << size << ", " << time_stamp << std::endl ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void HashCache::clean()
|
||||||
|
{
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << "Cleaning HashCache..." << std::endl ;
|
||||||
|
#endif
|
||||||
|
time_t now = time(NULL) ;
|
||||||
|
time_t duration = _max_cache_duration_days * 24 * 3600 ; // seconds
|
||||||
|
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << "cleaning hash cache." << std::endl ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for(std::map<std::string,HashCacheInfo>::iterator it(_files.begin());it!=_files.end();)
|
||||||
|
if(it->second.time_stamp + duration < now)
|
||||||
|
{
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << " Entry too old: " << it->first << ", ts=" << it->second.time_stamp << std::endl ;
|
||||||
|
#endif
|
||||||
|
std::map<std::string,HashCacheInfo>::iterator tmp(it) ;
|
||||||
|
++tmp ;
|
||||||
|
_files.erase(it) ;
|
||||||
|
it=tmp ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
++it ;
|
||||||
|
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << "Done." << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
FileIndexMonitor::~FileIndexMonitor()
|
FileIndexMonitor::~FileIndexMonitor()
|
||||||
{
|
{
|
||||||
@ -574,6 +761,9 @@ void FileIndexMonitor::updateCycle()
|
|||||||
fi.updateMaxModTime() ; // Update modification times for proper display.
|
fi.updateMaxModTime() ; // Update modification times for proper display.
|
||||||
|
|
||||||
mInCheck = false;
|
mInCheck = false;
|
||||||
|
|
||||||
|
if(useHashCache)
|
||||||
|
hashCache.save() ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,8 +828,13 @@ void FileIndexMonitor::hashFiles(const std::vector<DirContentToHash>& to_hash)
|
|||||||
cb->notifyHashingInfo(NOTIFY_HASHTYPE_HASH_FILE, tmpout.str()) ;
|
cb->notifyHashingInfo(NOTIFY_HASHTYPE_HASH_FILE, tmpout.str()) ;
|
||||||
|
|
||||||
FileEntry fe(to_hash[i].fentries[j]) ; // copied, because hashFile updates the hash member
|
FileEntry fe(to_hash[i].fentries[j]) ; // copied, because hashFile updates the hash member
|
||||||
|
std::string real_path(to_hash[i].realpath + "/" + to_hash[i].fentries[j].name) ;
|
||||||
|
|
||||||
if(RsDirUtil::hashFile(to_hash[i].realpath + "/" + to_hash[i].fentries[j].name, fe.hash))
|
// 1st look into the hash cache if this file already exists.
|
||||||
|
//
|
||||||
|
if(useHashCache && hashCache.find(real_path,to_hash[i].fentries[j].size,to_hash[i].fentries[j].modtime,fe.hash))
|
||||||
|
fi.updateFileEntry(to_hash[i].dirpath,fe,stamp);
|
||||||
|
else if(RsDirUtil::hashFile(real_path, fe.hash)) // not found, then hash it.
|
||||||
{
|
{
|
||||||
RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/
|
RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/
|
||||||
|
|
||||||
@ -647,6 +842,10 @@ void FileIndexMonitor::hashFiles(const std::vector<DirContentToHash>& to_hash)
|
|||||||
/* update with new time */
|
/* update with new time */
|
||||||
|
|
||||||
fi.updateFileEntry(to_hash[i].dirpath,fe,stamp);
|
fi.updateFileEntry(to_hash[i].dirpath,fe,stamp);
|
||||||
|
|
||||||
|
// Update the hash cache
|
||||||
|
if(useHashCache)
|
||||||
|
hashCache.insert(real_path,to_hash[i].fentries[j].size,to_hash[i].fentries[j].modtime,fe.hash) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cerr << "Failed to Hash File " << to_hash[i].fentries[j].name << std::endl;
|
std::cerr << "Failed to Hash File " << to_hash[i].fentries[j].name << std::endl;
|
||||||
@ -675,6 +874,9 @@ void FileIndexMonitor::hashFiles(const std::vector<DirContentToHash>& to_hash)
|
|||||||
RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/
|
RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/
|
||||||
FileIndexMonitor::locked_saveFileIndexes() ;
|
FileIndexMonitor::locked_saveFileIndexes() ;
|
||||||
last_save_size = size ;
|
last_save_size = size ;
|
||||||
|
|
||||||
|
if(useHashCache)
|
||||||
|
hashCache.save() ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,34 @@ class DirContentToHash
|
|||||||
std::string dirpath ;
|
std::string dirpath ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class HashCache
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
HashCache(const std::string& save_file_name) ;
|
||||||
|
|
||||||
|
void save() ;
|
||||||
|
void insert(const std::string& full_path,uint64_t size,time_t time_stamp,const std::string& hash) ;
|
||||||
|
bool find(const std::string& full_path,uint64_t size,time_t time_stamp,std::string& hash) ;
|
||||||
|
void clean() ;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint64_t size ;
|
||||||
|
time_t time_stamp ;
|
||||||
|
time_t modf_stamp ;
|
||||||
|
std::string hash ;
|
||||||
|
} HashCacheInfo ;
|
||||||
|
|
||||||
|
void setRememberHashFilesDuration(uint32_t days) { _max_cache_duration_days = days ; }
|
||||||
|
uint32_t rememberHashFilesDuration() const { return _max_cache_duration_days ; }
|
||||||
|
void clear() { _files.clear(); }
|
||||||
|
private:
|
||||||
|
uint32_t _max_cache_duration_days ; // maximum duration of un-requested cache entries
|
||||||
|
std::map<std::string, HashCacheInfo> _files ;
|
||||||
|
std::string _path ;
|
||||||
|
bool _changed ;
|
||||||
|
};
|
||||||
|
|
||||||
/******************************************************************************************
|
/******************************************************************************************
|
||||||
* FileIndexMonitor
|
* FileIndexMonitor
|
||||||
*****************************************************************************************/
|
*****************************************************************************************/
|
||||||
@ -119,6 +147,16 @@ class FileIndexMonitor: public CacheSource, public RsThread
|
|||||||
|
|
||||||
/* util fns */
|
/* util fns */
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Sets/gets the duration period within which already hashed files are remembered.
|
||||||
|
//
|
||||||
|
void setRememberHashFilesDuration(uint32_t days) ;
|
||||||
|
uint32_t rememberHashFilesDuration() const ;
|
||||||
|
void setRememberHashFiles(bool) ;
|
||||||
|
bool rememberHashFiles() ;
|
||||||
|
// Remove any memory of formerly hashed files that are not shared anymore
|
||||||
|
void clearHashFiles() ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* the mutex should be locked before calling these 3. */
|
/* the mutex should be locked before calling these 3. */
|
||||||
|
|
||||||
@ -154,6 +192,9 @@ class FileIndexMonitor: public CacheSource, public RsThread
|
|||||||
bool internal_setSharedDirectories();
|
bool internal_setSharedDirectories();
|
||||||
|
|
||||||
NotifyBase *cb ;
|
NotifyBase *cb ;
|
||||||
|
|
||||||
|
HashCache hashCache ;
|
||||||
|
bool useHashCache ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -161,6 +161,29 @@ bool ftFiMonitor::search(const std::string &hash, uint32_t hintflags, FileInfo &
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void ftFiMonitor::setRememberHashCacheDuration(uint32_t days)
|
||||||
|
{
|
||||||
|
setRememberHashFilesDuration(days) ; // calls FileIndexMonitor
|
||||||
|
IndicateConfigChanged() ;
|
||||||
|
}
|
||||||
|
uint32_t ftFiMonitor::rememberHashCacheDuration() const
|
||||||
|
{
|
||||||
|
return rememberHashFilesDuration() ; // calls FileIndexMonitor
|
||||||
|
}
|
||||||
|
void ftFiMonitor::setRememberHashCache(bool b)
|
||||||
|
{
|
||||||
|
setRememberHashFiles(b) ; // calls FileIndexMonitor
|
||||||
|
IndicateConfigChanged() ;
|
||||||
|
}
|
||||||
|
bool ftFiMonitor::rememberHashCache()
|
||||||
|
{
|
||||||
|
return rememberHashFiles() ; // calls FileIndexMonitor
|
||||||
|
}
|
||||||
|
void ftFiMonitor::clearHashCache()
|
||||||
|
{
|
||||||
|
clearHashFiles() ;
|
||||||
|
}
|
||||||
|
|
||||||
/******* LOAD / SAVE CONFIG List.
|
/******* LOAD / SAVE CONFIG List.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
@ -174,9 +197,14 @@ RsSerialiser *ftFiMonitor::setupSerialiser()
|
|||||||
|
|
||||||
/* add in the types we need! */
|
/* add in the types we need! */
|
||||||
rss->addSerialType(new RsFileConfigSerialiser());
|
rss->addSerialType(new RsFileConfigSerialiser());
|
||||||
|
rss->addSerialType(new RsGeneralConfigSerialiser());
|
||||||
|
|
||||||
return rss;
|
return rss;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string hash_cache_duration_ss("HASH_CACHE_DURATION");
|
||||||
|
const std::string hash_cache_ss("HASH_CACHE");
|
||||||
|
|
||||||
std::list<RsItem *> ftFiMonitor::saveList(bool &cleanup)
|
std::list<RsItem *> ftFiMonitor::saveList(bool &cleanup)
|
||||||
{
|
{
|
||||||
std::list<RsItem *> sList;
|
std::list<RsItem *> sList;
|
||||||
@ -204,6 +232,30 @@ std::list<RsItem *> ftFiMonitor::saveList(bool &cleanup)
|
|||||||
sList.push_back(fi);
|
sList.push_back(fi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::string> configMap;
|
||||||
|
|
||||||
|
/* basic control parameters */
|
||||||
|
std::ostringstream s ;
|
||||||
|
s << rememberHashFilesDuration() ;
|
||||||
|
|
||||||
|
configMap[hash_cache_duration_ss] = s.str() ;
|
||||||
|
configMap[hash_cache_ss] = rememberHashFiles()?"YES":"NO" ;
|
||||||
|
|
||||||
|
RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet();
|
||||||
|
|
||||||
|
/* Convert to TLV */
|
||||||
|
for(std::map<std::string,std::string>::const_iterator mit = configMap.begin(); mit != configMap.end(); mit++)
|
||||||
|
{
|
||||||
|
RsTlvKeyValue kv;
|
||||||
|
kv.key = mit->first;
|
||||||
|
kv.value = mit->second;
|
||||||
|
|
||||||
|
rskv->tlvkvs.pairs.push_back(kv);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add KeyValue to saveList */
|
||||||
|
sList.push_back(rskv);
|
||||||
|
|
||||||
return sList;
|
return sList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,6 +276,29 @@ bool ftFiMonitor::loadList(std::list<RsItem *> load)
|
|||||||
std::list<RsItem *>::iterator it;
|
std::list<RsItem *>::iterator it;
|
||||||
for(it = load.begin(); it != load.end(); it++)
|
for(it = load.begin(); it != load.end(); it++)
|
||||||
{
|
{
|
||||||
|
RsConfigKeyValueSet *rskv ;
|
||||||
|
/* switch on type */
|
||||||
|
if (NULL != (rskv = dynamic_cast<RsConfigKeyValueSet *>(*it)))
|
||||||
|
{
|
||||||
|
/* make into map */
|
||||||
|
std::map<std::string, std::string> configMap;
|
||||||
|
std::map<std::string, std::string>::const_iterator mit ;
|
||||||
|
|
||||||
|
for(std::list<RsTlvKeyValue>::const_iterator kit = rskv->tlvkvs.pairs.begin(); kit != rskv->tlvkvs.pairs.end(); kit++)
|
||||||
|
{
|
||||||
|
configMap[kit->key] = kit->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configMap.end() != (mit = configMap.find(hash_cache_duration_ss)))
|
||||||
|
{
|
||||||
|
uint32_t t=0 ;
|
||||||
|
if(sscanf(mit->second.c_str(),"%d",&t) == 1)
|
||||||
|
setRememberHashFilesDuration(t);
|
||||||
|
}
|
||||||
|
if(configMap.end() != (mit = configMap.find(hash_cache_ss)))
|
||||||
|
setRememberHashFiles( mit->second == "YES") ;
|
||||||
|
}
|
||||||
|
|
||||||
RsFileConfigItem *fi = dynamic_cast<RsFileConfigItem *>(*it);
|
RsFileConfigItem *fi = dynamic_cast<RsFileConfigItem *>(*it);
|
||||||
if (!fi)
|
if (!fi)
|
||||||
{
|
{
|
||||||
|
@ -66,6 +66,12 @@ class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config
|
|||||||
virtual void setSharedDirectories(const std::list<SharedDirInfo>& dirList);
|
virtual void setSharedDirectories(const std::list<SharedDirInfo>& dirList);
|
||||||
virtual void updateShareFlags(const SharedDirInfo& info) ;
|
virtual void updateShareFlags(const SharedDirInfo& info) ;
|
||||||
|
|
||||||
|
void setRememberHashCacheDuration(uint32_t days) ;
|
||||||
|
uint32_t rememberHashCacheDuration() const ;
|
||||||
|
void setRememberHashCache(bool) ;
|
||||||
|
bool rememberHashCache() ;
|
||||||
|
void clearHashCache() ;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Configuration - store shared directories
|
* Configuration - store shared directories
|
||||||
*/
|
*/
|
||||||
|
@ -83,10 +83,6 @@ void ftServer::setConfigDirectory(std::string path)
|
|||||||
RsDirUtil::checkCreateDirectory(basecachedir) ;
|
RsDirUtil::checkCreateDirectory(basecachedir) ;
|
||||||
RsDirUtil::checkCreateDirectory(localcachedir) ;
|
RsDirUtil::checkCreateDirectory(localcachedir) ;
|
||||||
RsDirUtil::checkCreateDirectory(remotecachedir) ;
|
RsDirUtil::checkCreateDirectory(remotecachedir) ;
|
||||||
|
|
||||||
//mFiStore -> setCacheDir(remotecachedir);
|
|
||||||
//mFiMon -> setCacheDir(localcachedir);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ftServer::setP3Interface(P3Interface *pqi)
|
void ftServer::setP3Interface(P3Interface *pqi)
|
||||||
@ -151,8 +147,6 @@ void ftServer::SetupFtServer(NotifyBase *cb)
|
|||||||
mConnMgr->addMonitor(mFtController);
|
mConnMgr->addMonitor(mFtController);
|
||||||
mConnMgr->addMonitor(mCacheStrapper);
|
mConnMgr->addMonitor(mCacheStrapper);
|
||||||
|
|
||||||
// mFtDwlQueue = new ftDwlQueue(mFtController);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,9 +178,6 @@ void ftServer::StartupThreads()
|
|||||||
/* Dataplex */
|
/* Dataplex */
|
||||||
mFtDataplex->start();
|
mFtDataplex->start();
|
||||||
|
|
||||||
// /* Download Queue */
|
|
||||||
// mFtDwlQueue->start();
|
|
||||||
|
|
||||||
/* start own thread */
|
/* start own thread */
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
@ -376,11 +367,6 @@ bool ftServer::clearDownload(const std::string hash)
|
|||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
//void ftServer::getDwlDetails(std::list<DwlDetails> & details)
|
|
||||||
//{
|
|
||||||
// mFtDwlQueue->getDwlDetails(details);
|
|
||||||
//}
|
|
||||||
|
|
||||||
bool ftServer::FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info)
|
bool ftServer::FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info)
|
||||||
{
|
{
|
||||||
return mFtController->getFileDownloadChunksDetails(hash,info);
|
return mFtController->getFileDownloadChunksDetails(hash,info);
|
||||||
@ -660,6 +646,26 @@ bool ftServer::removeSharedDirectory(std::string dir)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
void ftServer::setRememberHashFiles(bool b)
|
||||||
|
{
|
||||||
|
mFiMon->setRememberHashCache(b) ;
|
||||||
|
}
|
||||||
|
bool ftServer::rememberHashFiles() const
|
||||||
|
{
|
||||||
|
return mFiMon->rememberHashCache() ;
|
||||||
|
}
|
||||||
|
void ftServer::setRememberHashFilesDuration(uint32_t days)
|
||||||
|
{
|
||||||
|
mFiMon->setRememberHashCacheDuration(days) ;
|
||||||
|
}
|
||||||
|
uint32_t ftServer::rememberHashFilesDuration() const
|
||||||
|
{
|
||||||
|
return mFiMon->rememberHashCacheDuration() ;
|
||||||
|
}
|
||||||
|
void ftServer::clearHashCache()
|
||||||
|
{
|
||||||
|
mFiMon->clearHashCache() ;
|
||||||
|
}
|
||||||
|
|
||||||
void ftServer::setShareDownloadDirectory(bool value)
|
void ftServer::setShareDownloadDirectory(bool value)
|
||||||
{
|
{
|
||||||
@ -1250,7 +1256,6 @@ bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr)
|
|||||||
cfgmgr->addConfiguration("ft_shared.cfg", mFiMon);
|
cfgmgr->addConfiguration("ft_shared.cfg", mFiMon);
|
||||||
cfgmgr->addConfiguration("ft_extra.cfg", mFtExtra);
|
cfgmgr->addConfiguration("ft_extra.cfg", mFtExtra);
|
||||||
cfgmgr->addConfiguration("ft_transfers.cfg", mFtController);
|
cfgmgr->addConfiguration("ft_transfers.cfg", mFtController);
|
||||||
// cfgmgr->addConfiguration("ft_dwlqueue.cfg", mFtDwlQueue);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -202,6 +202,12 @@ virtual bool getShareDownloadDirectory();
|
|||||||
virtual bool shareDownloadDirectory();
|
virtual bool shareDownloadDirectory();
|
||||||
virtual bool unshareDownloadDirectory();
|
virtual bool unshareDownloadDirectory();
|
||||||
|
|
||||||
|
virtual void setRememberHashFilesDuration(uint32_t days) ;
|
||||||
|
virtual uint32_t rememberHashFilesDuration() const ;
|
||||||
|
virtual bool rememberHashFiles() const ;
|
||||||
|
virtual void setRememberHashFiles(bool) ;
|
||||||
|
virtual void clearHashCache() ;
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/*************** Control Interface *****************************/
|
/*************** Control Interface *****************************/
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
@ -184,6 +184,11 @@ class RsFiles
|
|||||||
virtual bool addSharedDirectory(const SharedDirInfo& dir) = 0;
|
virtual bool addSharedDirectory(const SharedDirInfo& dir) = 0;
|
||||||
virtual bool updateShareFlags(const SharedDirInfo& dir) = 0; // updates the flags. The directory should already exist !
|
virtual bool updateShareFlags(const SharedDirInfo& dir) = 0; // updates the flags. The directory should already exist !
|
||||||
virtual bool removeSharedDirectory(std::string dir) = 0;
|
virtual bool removeSharedDirectory(std::string dir) = 0;
|
||||||
|
virtual void setRememberHashFilesDuration(uint32_t days) = 0 ;
|
||||||
|
virtual uint32_t rememberHashFilesDuration() const = 0 ;
|
||||||
|
virtual void clearHashCache() = 0 ;
|
||||||
|
virtual bool rememberHashFiles() const =0;
|
||||||
|
virtual void setRememberHashFiles(bool) =0;
|
||||||
|
|
||||||
virtual void setShareDownloadDirectory(bool value) = 0;
|
virtual void setShareDownloadDirectory(bool value) = 0;
|
||||||
virtual bool getShareDownloadDirectory() = 0;
|
virtual bool getShareDownloadDirectory() = 0;
|
||||||
|
@ -115,7 +115,6 @@ private:
|
|||||||
QAction* sendchatlinkAct;
|
QAction* sendchatlinkAct;
|
||||||
QAction* copylinklocalhtmlAct;
|
QAction* copylinklocalhtmlAct;
|
||||||
|
|
||||||
QTreeView *shareddirtreeview;
|
|
||||||
|
|
||||||
/** Qt Designer generated object */
|
/** Qt Designer generated object */
|
||||||
Ui::SharedFilesDialog ui;
|
Ui::SharedFilesDialog ui;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "DirectoriesPage.h"
|
#include "DirectoriesPage.h"
|
||||||
#include "gui/ShareManager.h"
|
#include "gui/ShareManager.h"
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "rshare.h"
|
#include "rshare.h"
|
||||||
#include <retroshare/rsfiles.h>
|
#include <retroshare/rsfiles.h>
|
||||||
@ -52,10 +53,19 @@ DirectoriesPage::DirectoriesPage(QWidget * parent, Qt::WFlags flags)
|
|||||||
ui.checkBox->setChecked(false); /* signal not emitted */
|
ui.checkBox->setChecked(false); /* signal not emitted */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t t = rsFiles->rememberHashFilesDuration() ;
|
||||||
|
bool b = rsFiles->rememberHashFiles() ;
|
||||||
|
|
||||||
|
ui.rememberHashesSB->setValue(t) ;
|
||||||
|
ui.rememberHashesCB->setChecked(b) ;
|
||||||
|
|
||||||
connect(ui.incomingButton, SIGNAL(clicked( bool ) ), this , SLOT( setIncomingDirectory() ) );
|
connect(ui.incomingButton, SIGNAL(clicked( bool ) ), this , SLOT( setIncomingDirectory() ) );
|
||||||
connect(ui.partialButton, SIGNAL(clicked( bool ) ), this , SLOT( setPartialsDirectory() ) );
|
connect(ui.partialButton, SIGNAL(clicked( bool ) ), this , SLOT( setPartialsDirectory() ) );
|
||||||
connect(ui.checkBox, SIGNAL(stateChanged(int)), this, SLOT(shareDownloadDirectory(int)));
|
connect(ui.checkBox, SIGNAL(stateChanged(int)), this, SLOT(shareDownloadDirectory(int)));
|
||||||
connect(ui.editButton, SIGNAL(clicked()), this, SLOT(editDirectories()));
|
connect(ui.editButton, SIGNAL(clicked()), this, SLOT(editDirectories()));
|
||||||
|
connect(ui.cleanHashCachePB, SIGNAL(clicked()), this, SLOT(clearHashCache()));
|
||||||
|
connect(ui.rememberHashesCB, SIGNAL(toggled(bool)), this, SLOT(toggleRememberHashes(bool)));
|
||||||
|
connect(ui.rememberHashesSB, SIGNAL(valueChanged(int)), this, SLOT(setRememberHashesDuration(int)));
|
||||||
|
|
||||||
/* Hide platform specific features */
|
/* Hide platform specific features */
|
||||||
#ifdef Q_WS_WIN
|
#ifdef Q_WS_WIN
|
||||||
@ -63,6 +73,40 @@ DirectoriesPage::DirectoriesPage(QWidget * parent, Qt::WFlags flags)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DirectoriesPage::setRememberHashesDuration(int d)
|
||||||
|
{
|
||||||
|
rsFiles->setRememberHashFilesDuration(d) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectoriesPage::toggleRememberHashes(bool b)
|
||||||
|
{
|
||||||
|
if(!b)
|
||||||
|
{
|
||||||
|
if(QMessageBox::question(NULL,"Cache cleaning confirmation","The will forget any former hash of non shared files. Do you confirm ?") == QMessageBox::Ok)
|
||||||
|
{
|
||||||
|
rsFiles->clearHashCache() ;
|
||||||
|
rsFiles->setRememberHashFiles(b) ;
|
||||||
|
ui.rememberHashesSB->setEnabled(false) ;
|
||||||
|
ui.cleanHashCachePB->setEnabled(false) ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ui.rememberHashesCB->setChecked(true) ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rsFiles->setRememberHashFiles(true) ;
|
||||||
|
ui.rememberHashesSB->setEnabled(true) ;
|
||||||
|
ui.cleanHashCachePB->setEnabled(true) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DirectoriesPage::clearHashCache()
|
||||||
|
{
|
||||||
|
if(QMessageBox::question(NULL,"Cache cleaning confirmation","The will forget any former hash of non shared files. Do you confirm ?", QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok)
|
||||||
|
rsFiles->clearHashCache() ;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DirectoriesPage::closeEvent (QCloseEvent * event)
|
DirectoriesPage::closeEvent (QCloseEvent * event)
|
||||||
{
|
{
|
||||||
|
@ -42,15 +42,13 @@ class DirectoriesPage: public ConfigPage
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
#ifdef TO_REMOVE
|
|
||||||
void addShareDirectory();
|
|
||||||
void removeShareDirectory();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void editDirectories() ;
|
void editDirectories() ;
|
||||||
void setIncomingDirectory();
|
void setIncomingDirectory();
|
||||||
void setPartialsDirectory();
|
void setPartialsDirectory();
|
||||||
void shareDownloadDirectory(int state);
|
void shareDownloadDirectory(int state);
|
||||||
|
void clearHashCache() ;
|
||||||
|
void setRememberHashesDuration(int) ;
|
||||||
|
void toggleRememberHashes(bool) ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>477</width>
|
<width>483</width>
|
||||||
<height>439</height>
|
<height>439</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -604,11 +604,13 @@
|
|||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Shared Directories</string>
|
<string>Shared Directories</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item row="0" column="0" colspan="2">
|
<item>
|
||||||
<widget class="QListWidget" name="dirList"/>
|
<widget class="QListWidget" name="dirList"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
<widget class="QCheckBox" name="checkBox">
|
<widget class="QCheckBox" name="checkBox">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
@ -621,7 +623,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item>
|
||||||
<widget class="QPushButton" name="editButton">
|
<widget class="QPushButton" name="editButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Edit Share</string>
|
<string>Edit Share</string>
|
||||||
@ -629,6 +631,71 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="rememberHashesCB">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||||
|
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||||
|
p, li { white-space: pre-wrap; }
|
||||||
|
</style></head><body style=" font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;">
|
||||||
|
<p align="justify" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Remember file hashes even if not shared. </p>
|
||||||
|
<p align="justify" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This might be useful if you're sharing an </p>
|
||||||
|
<p align="justify" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">external HD, to avoid re-hashing files when </p>
|
||||||
|
<p align="justify" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">you plug it in.</p></body></html></string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Remember hashed files for </string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="rememberHashesSB">
|
||||||
|
<property name="suffix">
|
||||||
|
<string> days</string>
|
||||||
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>365</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="cleanHashCachePB">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Forget any hashed file that is not anymore shared.</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Clean Hash Cache</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
Loading…
Reference in New Issue
Block a user