removed most of CacheStrapper stuff from ftServer, replaced fimonitor by p3FileDatabase

This commit is contained in:
mr-alice 2016-07-30 21:52:42 +02:00
parent aeb0595301
commit 5b9fd74d85
14 changed files with 463 additions and 769 deletions

View file

@ -1,5 +1,9 @@
#include "serialiser/rsserviceids.h"
#include "file_sharing/p3filelists.h"
#include "file_sharing/directory_storage.h"
#include "file_sharing/directory_updater.h"
#include "retroshare/rsids.h"
#define P3FILELISTS_DEBUG() std::cerr << "p3FileLists: "
@ -9,19 +13,36 @@ static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED = 0x0001 ;
static const uint32_t P3FILELISTS_UPDATE_FLAG_LOCAL_DIRS_CHANGED = 0x0002 ;
static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_DIRS_CHANGED = 0x0004 ;
p3FileLists::p3FileLists(p3LinkMgr *mpeers)
: mLinkMgr(mpeers), mFLSMtx("p3FileLists")
#define NOT_IMPLEMENTED() { std::cerr << __PRETTY_FUNCTION__ << ": not implemented!" << std::endl; }
p3FileDatabase::p3FileDatabase(p3ServiceControl *mpeers)
: mServCtrl(mpeers), mFLSMtx("p3FileLists")
{
// loads existing indexes for friends. Some might be already present here.
//
// init the directory watchers
// local variables/structures
//
mRemoteDirectories.clear() ; // we should load them!
mLocalSharedDirs = new LocalDirectoryStorage("local_file_store.bin") ;
mHashCache = new HashStorage("hash_cache.bin") ;
mLocalDirWatcher = new LocalDirectoryUpdater(mHashCache,mLocalSharedDirs) ;
mRemoteDirWatcher = NULL; // not used yet
mLocalDirWatcher->start();
mUpdateFlags = P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED ;
}
p3FileLists::~p3FileLists()
void p3FileDatabase::setSharedDirectories(const std::list<SharedDirInfo>& shared_dirs)
{
mLocalSharedDirs->setSharedDirectoryList(shared_dirs) ;
}
void p3FileDatabase::getSharedDirectories(std::list<SharedDirInfo>& shared_dirs)
{
mLocalSharedDirs->getSharedDirectoryList(shared_dirs) ;
}
p3FileDatabase::~p3FileDatabase()
{
RS_STACK_MUTEX(mFLSMtx) ;
@ -30,10 +51,28 @@ p3FileLists::~p3FileLists()
mRemoteDirectories.clear(); // just a precaution, not to leave deleted pointers around.
// delete all pointers
delete mLocalSharedDirs ;
delete mLocalDirWatcher ;
delete mRemoteDirWatcher ;
delete mHashCache ;
}
int p3FileLists::tick()
const std::string FILE_DB_APP_NAME = "file_database";
const uint16_t FILE_DB_APP_MAJOR_VERSION = 1;
const uint16_t FILE_DB_APP_MINOR_VERSION = 0;
const uint16_t FILE_DB_MIN_MAJOR_VERSION = 1;
const uint16_t FILE_DB_MIN_MINOR_VERSION = 0;
RsServiceInfo p3FileDatabase::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_FILE_DATABASE,
FILE_DB_APP_NAME,
FILE_DB_APP_MAJOR_VERSION,
FILE_DB_APP_MINOR_VERSION,
FILE_DB_MIN_MAJOR_VERSION,
FILE_DB_MIN_MINOR_VERSION);
}
int p3FileDatabase::tick()
{
// tick the watchers, possibly create new ones if additional friends do connect.
//
@ -53,29 +92,37 @@ int p3FileLists::tick()
return 0;
}
void p3FileLists::tickRecv()
void p3FileDatabase::tickWatchers()
{
}
void p3FileLists::tickSend()
{
// go through the list of out requests and send them to the corresponding friends, if they are online.
NOT_IMPLEMENTED();
}
bool p3FileLists::loadList(std::list<RsItem *>& items)
void p3FileDatabase::tickRecv()
{
}
void p3FileDatabase::tickSend()
{
// go through the list of out requests and send them to the corresponding friends, if they are online.
NOT_IMPLEMENTED();
}
bool p3FileDatabase::loadList(std::list<RsItem *>& items)
{
// This loads
//
// - list of locally shared directories, and the permissions that go with them
NOT_IMPLEMENTED();
return true ;
}
bool p3FileLists::saveList(const std::list<RsItem *>& items)
bool p3FileDatabase::saveList(bool &cleanup, std::list<RsItem *>&)
{
NOT_IMPLEMENTED();
return true ;
}
void p3FileLists::cleanup()
void p3FileDatabase::cleanup()
{
RS_STACK_MUTEX(mFLSMtx) ;
@ -83,15 +130,8 @@ void p3FileLists::cleanup()
//
P3FILELISTS_DEBUG() << "Cleanup pass." << std::endl;
std::set<RsPeerId> friend_set ;
{
#warning we should use a std::set in the first place. Modify rsPeers?
std::list<RsPeerId> friend_list ;
mLinkMgr->getFriendList(friend_list) ;
for(std::list<RsPeerId>::const_iterator it(friend_list.begin());it!=friend_list.end();++it)
friend_set.insert(*it) ;
}
std::set<RsPeerId> friend_set ;
mServCtrl->getPeersConnected(getServiceInfo().mServiceType, friend_set);
for(std::map<RsPeerId,RemoteDirectoryStorage*>::iterator it(mRemoteDirectories.begin());it!=mRemoteDirectories.end();)
if(friend_set.find(it->first) == friend_set.end())
@ -125,4 +165,59 @@ void p3FileLists::cleanup()
IndicateConfigChanged();
}
int p3FileDatabase::RequestDirDetails(void *ref, DirDetails&, FileSearchFlags) const
{
NOT_IMPLEMENTED();
return 0;
}
int p3FileDatabase::RequestDirDetails(const std::string& path, DirDetails &details) const
{
NOT_IMPLEMENTED();
return 0;
}
uint32_t p3FileDatabase::getType(void *ref) const
{
NOT_IMPLEMENTED();
return 0;
}
void p3FileDatabase::forceDirectoryCheck() // Force re-sweep the directories and see what's changed
{
NOT_IMPLEMENTED();
}
bool p3FileDatabase::inDirectoryCheck()
{
NOT_IMPLEMENTED();
return 0;
}
void p3FileDatabase::setWatchPeriod(uint32_t seconds)
{
NOT_IMPLEMENTED();
}
uint32_t p3FileDatabase::watchPeriod()
{
NOT_IMPLEMENTED();
return 0;
}
void p3FileDatabase::setRememberHashCacheDuration(uint32_t days)
{
NOT_IMPLEMENTED();
}
uint32_t p3FileDatabase::rememberHashCacheDuration()
{
NOT_IMPLEMENTED();
return 0;
}
void p3FileDatabase::clearHashCache()
{
NOT_IMPLEMENTED();
}
bool p3FileDatabase::rememberHashCache()
{
NOT_IMPLEMENTED();
return false;
}
void p3FileDatabase::setRememberHashCache(bool)
{
NOT_IMPLEMENTED();
}

View file

@ -21,23 +21,30 @@
//
#pragma once
#include "ft/ftsearch.h"
#include "retroshare/rsfiles.h"
#include "services/p3service.h"
#include "file_sharing/hash_cache.h"
#include "pqi/p3cfgmgr.h"
#include "pqi/p3linkmgr.h"
class RemoteDirectoryStorage ;
class RemoteSharedDirectoryWatcher ;
class LocalSharedDirectoryWatcher ;
class LocalSharedDirectoryMap ;
class HashCache ;
class RemoteDirectoryUpdater ;
class LocalDirectoryUpdater ;
class p3FileLists: public p3Service, public p3Config //, public RsSharedFileService
class RemoteDirectoryStorage ;
class LocalDirectoryStorage ;
class HashStorage ;
class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, public RsSharedFileService
{
public:
typedef uint64_t EntryIndex ; // this should probably be defined elsewhere
virtual RsServiceInfo getServiceInfo();
struct RsFileListSyncRequest
{
RsPeerId peerId ;
@ -45,12 +52,17 @@ class p3FileLists: public p3Service, public p3Config //, public RsSharedFileServ
// [...] more to add here
};
p3FileLists(p3LinkMgr *mpeers) ;
~p3FileLists();
p3FileDatabase(p3ServiceControl *mpeers) ;
~p3FileDatabase();
/*!
* \brief forceSyncWithPeers
*
* Forces the synchronisation of the database with connected peers. This is triggered when e.g. a new gorup of friend is created, or when
* a friend was added/removed from a group.
*/
void forceSyncWithPeers();
/*
*/
// derived from p3Service
//
virtual int tick() ;
@ -62,32 +74,61 @@ class p3FileLists: public p3Service, public p3Config //, public RsSharedFileServ
virtual int SearchKeywords(const std::list<std::string>& keywords, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) ;
virtual int SearchBoolExp(Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) const ;
// ftSearch
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
// Interface for browsing dir hierarchy
//
int RequestDirDetails(EntryIndex, DirDetails&, FileSearchFlags) const ;
uint32_t getType(const EntryIndex&) const ;
void stopThreads() ;
void startThreads() ;
int RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details);
int RequestDirDetails(const std::string& path, DirDetails &details) const ;
// set/update shared directories
void setSharedDirectories(const std::list<SharedDirInfo>& dirs);
void getSharedDirectories(std::list<SharedDirInfo>& dirs);
void updateShareFlags(const SharedDirInfo& info) ;
// void * here is the type expected by the abstract model index from Qt. It gets turned into a DirectoryStorage::EntryIndex internally.
int RequestDirDetails(void *, DirDetails&, FileSearchFlags) const ;
uint32_t getType(void *) const ;
// set/update shared directories
void setSharedDirectories(const std::list<SharedDirInfo>& dirs);
void getSharedDirectories(std::list<SharedDirInfo>& dirs);
void updateShareFlags(const SharedDirInfo& info) ;
bool convertSharedFilePath(const std::string& path,std::string& fullpath);
// interface for hash caching
void setWatchPeriod(uint32_t seconds);
uint32_t watchPeriod() ;
void setRememberHashCacheDuration(uint32_t days) ;
uint32_t rememberHashCacheDuration() ;
void clearHashCache() ;
bool rememberHashCache() ;
void setRememberHashCache(bool) ;
// interfact for directory parsing
void forceDirectoryCheck(); // Force re-sweep the directories and see what's changed
bool inDirectoryCheck();
// Derived from p3Config
//
// debug
void full_print();
protected:
// Derived from p3Config
//
virtual bool loadList(std::list<RsItem *>& items);
virtual bool saveList(const std::list<RsItem *>& items);
virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
virtual RsSerialiser *setupSerialiser() ;
void cleanup();
void tickRecv();
void tickSend();
void tickWatchers();
private:
p3LinkMgr *mLinkMgr ;
p3ServiceControl *mServCtrl ;
// File sync request queues. The fast one is used for online browsing when friends are connected.
// The slow one is used for background update of file lists.
@ -98,15 +139,14 @@ class p3FileLists: public p3Service, public p3Config //, public RsSharedFileServ
// Directory storage hierarchies
//
std::map<RsPeerId,RemoteDirectoryStorage *> mRemoteDirectories ;
LocalSharedDirectoryMap *mLocalSharedDirs ;
LocalDirectoryStorage *mLocalSharedDirs ;
RemoteSharedDirectoryWatcher *mRemoteDirWatcher ;
LocalSharedDirectoryWatcher *mLocalDirWatcher ;
RemoteDirectoryUpdater *mRemoteDirWatcher ;
LocalDirectoryUpdater *mLocalDirWatcher ;
// We use a shared file cache as well, to avoid re-hashing files with known modification TS and equal name.
//
HashCache *mHashCache ;
HashStorage *mHashCache ;
// Local flags and mutexes