diff --git a/.gitignore b/.gitignore index eb9b055b3..b799c1eaf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ moc_*.cpp qrc_*.cpp ui_*.h -Makefile.* +Makefile* +*.sw? *~ Thumbs.db diff --git a/libretroshare/src/file_sharing/directory_storage.cc b/libretroshare/src/file_sharing/directory_storage.cc new file mode 100644 index 000000000..e69de29bb diff --git a/libretroshare/src/file_sharing/directory_storage.h b/libretroshare/src/file_sharing/directory_storage.h index 1ba46a062..6106e4bb6 100644 --- a/libretroshare/src/file_sharing/directory_storage.h +++ b/libretroshare/src/file_sharing/directory_storage.h @@ -1,8 +1,12 @@ #include +#include +#include + +#include "retroshare/rsids.h" +#include "retroshare/rsfiles.h" static const uint8_t DIRECTORY_STORAGE_VERSION = 0x01 ; -static const uint8_t DIRECTORY_STORAGE_TAG_FILE_HASH = 0x01 ; static const uint8_t DIRECTORY_STORAGE_TAG_FILE_HASH = 0x01 ; static const uint8_t DIRECTORY_STORAGE_TAG_FILE_NAME = 0x02 ; static const uint8_t DIRECTORY_STORAGE_TAG_FILE_SIZE = 0x03 ; @@ -14,6 +18,9 @@ class DirectoryStorage { public: DirectoryStorage(const std::string& local_file_name) ; + virtual ~DirectoryStorage() {} + + typedef uint32_t EntryIndex ; void save() const ; @@ -57,9 +64,15 @@ class DirectoryStorage class RemoteDirectoryStorage: public DirectoryStorage { +public: + RemoteDirectoryStorage(const RsPeerId& pid) ; + virtual ~RemoteDirectoryStorage() {} }; class LocalDirectoryStorage: public DirectoryStorage { +public: + LocalDirectoryStorage() ; + virtual ~LocalDirectoryStorage() {} }; diff --git a/libretroshare/src/file_sharing/directory_updater.h b/libretroshare/src/file_sharing/directory_updater.h index be59eb987..3571247ab 100644 --- a/libretroshare/src/file_sharing/directory_updater.h +++ b/libretroshare/src/file_sharing/directory_updater.h @@ -11,15 +11,19 @@ class DirectoryUpdater // Does some updating job. Crawls the existing directories and checks wether it has been updated // recently enough. If not, calls the directry source. // - void tick() ; + virtual void tick() =0; // }; class LocalDirectoryUpdater: public DirectoryUpdater { + public: + virtual void tick() ; }; class RemoteDirectoryUpdater: public DirectoryUpdater { + public: + virtual void tick() ; }; diff --git a/libretroshare/src/file_sharing/hash_cache.cc b/libretroshare/src/file_sharing/hash_cache.cc new file mode 100644 index 000000000..e69de29bb diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 20fd14db6..7c35fe332 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -1,15 +1,16 @@ #include "file_sharing/p3filelists.h" +#include "file_sharing/directory_storage.h" #include "retroshare/rsids.h" -#define P3FILELISTS_DEBUG() std::cerr << "p3FileLists: " ; +#define P3FILELISTS_DEBUG() std::cerr << "p3FileLists: " static const uint32_t P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED = 0x0000 ; 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(mPeerPgr *mpeers) - : mPeers(mpeers) +p3FileLists::p3FileLists(p3LinkMgr *mpeers) + : mLinkMgr(mpeers), mFLSMtx("p3FileLists") { // loads existing indexes for friends. Some might be already present here. // @@ -20,12 +21,19 @@ p3FileLists::p3FileLists(mPeerPgr *mpeers) // mUpdateFlags = P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED ; } -void p3FileLists::~p3FileLists() +p3FileLists::~p3FileLists() { + RS_STACK_MUTEX(mFLSMtx) ; + + for(std::map::const_iterator it(mRemoteDirectories.begin());it!=mRemoteDirectories.end();++it) + delete it->second ; + + mRemoteDirectories.clear(); // just a precaution, not to leave deleted pointers around. + // delete all pointers } -void p3FileLists::tick() +int p3FileLists::tick() { // tick the watchers, possibly create new ones if additional friends do connect. // @@ -41,6 +49,8 @@ void p3FileLists::tick() // - cleanup(); + + return 0; } void p3FileLists::tickRecv() @@ -51,20 +61,25 @@ void p3FileLists::tickSend() // go through the list of out requests and send them to the corresponding friends, if they are online. } -void p3FileLists::loadList(std::list& items) +bool p3FileLists::loadList(std::list& items) { // This loads // // - list of locally shared directories, and the permissions that go with them + + return true ; } -void p3FileLists::saveList(const std::list& items) +bool p3FileLists::saveList(const std::list& items) { + return true ; } void p3FileLists::cleanup() { - // look through the list of friend directories. Remove those who are not our friends anymore. + RS_STACK_MUTEX(mFLSMtx) ; + + // look through the list of friend directories. Remove those who are not our friends anymore. // P3FILELISTS_DEBUG() << "Cleanup pass." << std::endl; @@ -72,13 +87,13 @@ void p3FileLists::cleanup() { #warning we should use a std::set in the first place. Modify rsPeers? std::list friend_list ; - mPeers->getFriendList(friend_list) ; + mLinkMgr->getFriendList(friend_list) ; for(std::list::const_iterator it(friend_list.begin());it!=friend_list.end();++it) friend_set.insert(*it) ; } - for(std::map::const_iterator it(mRemoteDirectories.begin());it!=mRemoteDirectories.end();) + for(std::map::iterator it(mRemoteDirectories.begin());it!=mRemoteDirectories.end();) if(friend_set.find(it->first) == friend_set.end()) { P3FILELISTS_DEBUG() << " removing file list of non friend " << it->first << std::endl; diff --git a/libretroshare/src/file_sharing/p3filelists.h b/libretroshare/src/file_sharing/p3filelists.h index f0a6e2a1d..e2c9d2016 100644 --- a/libretroshare/src/file_sharing/p3filelists.h +++ b/libretroshare/src/file_sharing/p3filelists.h @@ -21,15 +21,32 @@ // #pragma once -#include -#include +#include "retroshare/rsfiles.h" +#include "services/p3service.h" -class p3FileLists: public p3Service, public p3Config, public RsSharedFileService +#include "pqi/p3cfgmgr.h" +#include "pqi/p3linkmgr.h" + +class RemoteDirectoryStorage ; +class RemoteSharedDirectoryWatcher ; +class LocalSharedDirectoryWatcher ; +class LocalSharedDirectoryMap ; +class HashCache ; + +class p3FileLists: public p3Service, public p3Config //, public RsSharedFileService { public: typedef uint64_t EntryIndex ; // this should probably be defined elsewhere - p3FileLists(mPeerMgr *mpeers) ; + struct RsFileListSyncRequest + { + RsPeerId peerId ; + EntryIndex index ; + // [...] more to add here + }; + + p3FileLists(p3LinkMgr *mpeers) ; + ~p3FileLists(); /* */ @@ -61,8 +78,16 @@ class p3FileLists: public p3Service, public p3Config, public RsSharedFileService // Derived from p3Config // - private: - p3PeerMgr *mPeers ; + protected: + virtual bool loadList(std::list& items); + virtual bool saveList(const std::list& items); + void cleanup(); + void tickRecv(); + void tickSend(); + void tickWatchers(); + + private: + p3LinkMgr *mLinkMgr ; // 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. @@ -83,6 +108,9 @@ class p3FileLists: public p3Service, public p3Config, public RsSharedFileService // HashCache *mHashCache ; + // Local flags and mutexes + RsMutex mFLSMtx ; + uint32_t mUpdateFlags ; };