mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-20 12:24:24 -04:00
added skeleton code for p3filelists, and interface files for directory storage and hash cache
This commit is contained in:
parent
a6d467d138
commit
b31e396c2b
3 changed files with 207 additions and 0 deletions
65
libretroshare/src/file_sharing/directory_storage.h
Normal file
65
libretroshare/src/file_sharing/directory_storage.h
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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 ;
|
||||||
|
static const uint8_t DIRECTORY_STORAGE_TAG_DIR_NAME = 0x04 ;
|
||||||
|
static const uint8_t DIRECTORY_STORAGE_TAG_MODIF_TS = 0x05 ;
|
||||||
|
static const uint8_t DIRECTORY_STORAGE_TAG_RECURS_MODIF_TS = 0x06 ;
|
||||||
|
|
||||||
|
class DirectoryStorage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DirectoryStorage(const std::string& local_file_name) ;
|
||||||
|
|
||||||
|
void save() const ;
|
||||||
|
|
||||||
|
virtual int searchTerms(const std::list<std::string>& terms, std::list<EntryIndex> &results) const;
|
||||||
|
virtual int searchHash(const RsFileHash& hash, std::list<EntryIndex> &results) const;
|
||||||
|
virtual int searchBoolExp(Expression * exp, std::list<EntryIndex> &results) const;
|
||||||
|
|
||||||
|
void getFileDetails(EntryIndex i) ;
|
||||||
|
|
||||||
|
// This class allows to abstractly browse the stored directory hierarchy in a depth-first manner.
|
||||||
|
// It gives access to sub-files and sub-directories below.
|
||||||
|
//
|
||||||
|
class DirIterator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DirIterator(const DirectoryStorage& d) ;
|
||||||
|
|
||||||
|
DirIterator& operator++() ;
|
||||||
|
EntryIndex operator*() const ; // current directory entry
|
||||||
|
|
||||||
|
bool operator()() const ; // used in for loops. Returns true when the iterator is valid.
|
||||||
|
};
|
||||||
|
class FileIterator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FileIterator(const DirectoryStorage& d) ;
|
||||||
|
|
||||||
|
FileIterator& operator++() ;
|
||||||
|
EntryIndex operator*() const ; // current file entry
|
||||||
|
|
||||||
|
bool operator()() const ; // used in for loops. Returns true when the iterator is valid.
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
void load(const std::string& local_file_name) ;
|
||||||
|
void save(const std::string& local_file_name) ;
|
||||||
|
|
||||||
|
void loadNextTag(const void *data,uint32_t& offset,uint8_t& entry_tag,uint32_t& entry_size) ;
|
||||||
|
void saveNextTag(void *data,uint32_t& offset,uint8_t entry_tag,uint32_t entry_size) ;
|
||||||
|
};
|
||||||
|
|
||||||
|
class RemoteDirectoryStorage: public DirectoryStorage
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
class LocalDirectoryStorage: public DirectoryStorage
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
29
libretroshare/src/file_sharing/hash_cache.h
Normal file
29
libretroshare/src/file_sharing/hash_cache.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
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 RsFileHash& hash) ;
|
||||||
|
bool find(const std::string& full_path,uint64_t size,time_t time_stamp,RsFileHash& hash) ;
|
||||||
|
void clean() ;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint64_t size ;
|
||||||
|
uint64_t time_stamp ;
|
||||||
|
uint64_t modf_stamp ;
|
||||||
|
RsFileHash 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(); }
|
||||||
|
bool empty() const { return _files.empty() ; }
|
||||||
|
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 ;
|
||||||
|
};
|
||||||
|
|
113
libretroshare/src/file_sharing/p3filelists.cc
Normal file
113
libretroshare/src/file_sharing/p3filelists.cc
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
#include <p3filelists.h>
|
||||||
|
#include <retroshare/rsids.h>
|
||||||
|
|
||||||
|
#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)
|
||||||
|
{
|
||||||
|
// loads existing indexes for friends. Some might be already present here.
|
||||||
|
//
|
||||||
|
|
||||||
|
// init the directory watchers
|
||||||
|
|
||||||
|
// local variables/structures
|
||||||
|
//
|
||||||
|
mUpdateFlags = P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED ;
|
||||||
|
}
|
||||||
|
void p3FileLists::~p3FileLists()
|
||||||
|
{
|
||||||
|
// delete all pointers
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3FileLists::tick()
|
||||||
|
{
|
||||||
|
// tick the watchers, possibly create new ones if additional friends do connect.
|
||||||
|
//
|
||||||
|
tickWatchers();
|
||||||
|
|
||||||
|
// tick the input/output list of update items and process them
|
||||||
|
//
|
||||||
|
tickRecv() ;
|
||||||
|
tickSend() ;
|
||||||
|
|
||||||
|
// cleanup
|
||||||
|
// - remove/delete shared file lists for people who are not friend anymore
|
||||||
|
// -
|
||||||
|
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3FileLists::tickRecv()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
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<RsItem *>& items)
|
||||||
|
{
|
||||||
|
// This loads
|
||||||
|
//
|
||||||
|
// - list of locally shared directories, and the permissions that go with them
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3FileLists::saveList(const std::list<RsItem *>& items)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3FileLists::cleanup()
|
||||||
|
{
|
||||||
|
// look through the list of friend directories. Remove those who are not our friends anymore.
|
||||||
|
//
|
||||||
|
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 ;
|
||||||
|
mPeers->getFriendList(friend_list) ;
|
||||||
|
|
||||||
|
for(std::list<RsPeerId>::const_iterator it(friend_list.begin());it!=friend_list.end();++it)
|
||||||
|
friend_set.insert(*it) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(std::map<RsPeerId,RemoteDirectoryStorage*>::const_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;
|
||||||
|
|
||||||
|
delete it->second ;
|
||||||
|
std::map<RsPeerId,RemoteDirectoryStorage*>::iterator tmp(it) ;
|
||||||
|
++tmp ;
|
||||||
|
mRemoteDirectories.erase(it) ;
|
||||||
|
it=tmp ;
|
||||||
|
|
||||||
|
mUpdateFlags |= P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
++it ;
|
||||||
|
|
||||||
|
// look through the list of friends, and add a directory storage when it's missing
|
||||||
|
//
|
||||||
|
for(std::set<RsPeerId>::const_iterator it(friend_set.begin());it!=friend_set.end();++it)
|
||||||
|
if(mRemoteDirectories.find(*it) == mRemoteDirectories.end())
|
||||||
|
{
|
||||||
|
P3FILELISTS_DEBUG() << " adding missing remote dir entry for friend " << *it << std::endl;
|
||||||
|
|
||||||
|
mRemoteDirectories[*it] = new RemoteDirectoryStorage(*it);
|
||||||
|
|
||||||
|
mUpdateFlags |= P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mUpdateFlags)
|
||||||
|
IndicateConfigChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue