2016-07-21 00:16:12 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include "util/rsthreads.h"
|
2016-07-23 22:14:43 -04:00
|
|
|
#include "retroshare/rsfiles.h"
|
|
|
|
|
|
|
|
class HashCacheClient
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void hash_callback(const std::string& full_path,const RsFileHash& hash) ;
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileHashingThread: public RsTickingThread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FileHashingThread() {}
|
|
|
|
|
|
|
|
virtual void data_tick() ;
|
|
|
|
};
|
2016-07-21 00:16:12 -04:00
|
|
|
|
2016-07-18 21:52:44 -04:00
|
|
|
class HashCache
|
|
|
|
{
|
2016-07-21 00:16:12 -04:00
|
|
|
public:
|
|
|
|
HashCache(const std::string& save_file_name) ;
|
|
|
|
|
2016-07-23 22:14:43 -04:00
|
|
|
bool requestHash(const std::string& full_path,uint64_t size,time_t mod_time,const RsFileHash& known_hash,HashCacheClient *c) ;
|
2016-07-21 00:16:12 -04:00
|
|
|
|
|
|
|
struct HashCacheInfo
|
|
|
|
{
|
|
|
|
std::string filename ;
|
|
|
|
uint64_t size ;
|
|
|
|
uint32_t time_stamp ;
|
|
|
|
uint32_t modf_stamp ;
|
|
|
|
RsFileHash hash ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
// interaction with GUI, called from p3FileLists
|
2016-07-23 22:14:43 -04:00
|
|
|
void setRememberHashFilesDuration(uint32_t days) { mMaxCacheDurationDays = days ; }
|
|
|
|
uint32_t rememberHashFilesDuration() const { return mMaxCacheDurationDays ; }
|
|
|
|
void clear() { mFiles.clear(); }
|
|
|
|
bool empty() const { return mFiles.empty() ; }
|
2016-07-21 00:16:12 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void clean() ;
|
|
|
|
|
|
|
|
void save() ;
|
|
|
|
void load() ;
|
|
|
|
|
|
|
|
// threaded stuff
|
2016-07-23 22:14:43 -04:00
|
|
|
FileHashingThread mHashingThread ;
|
2016-07-21 00:16:12 -04:00
|
|
|
RsMutex mHashMtx ;
|
|
|
|
|
|
|
|
// Local configuration and storage
|
|
|
|
|
|
|
|
uint32_t mMaxCacheDurationDays ; // maximum duration of un-requested cache entries
|
|
|
|
std::map<std::string, HashCacheInfo> mFiles ;
|
|
|
|
std::string mFilePath ;
|
|
|
|
bool mChanged ;
|
|
|
|
|
|
|
|
// current work
|
|
|
|
|
2016-07-23 22:14:43 -04:00
|
|
|
std::map<std::string,HashCacheClient *> mFilesToHash ;
|
2016-07-18 21:52:44 -04:00
|
|
|
};
|
|
|
|
|