auto-remove remote directories for friends offline for too long (depending on whether the dir is empty or not) and also remove unused dir files

This commit is contained in:
csoler 2016-11-15 21:33:39 +01:00
parent 99860c1eb0
commit 608d0d0a65
3 changed files with 30 additions and 3 deletions

View File

@ -204,6 +204,8 @@ public:
* \return
*/
time_t& lastSweepTime() { return mLastSweepTime ; }
const std::string& filename() const { return mFileName ; }
private:
time_t mLastSavedTime ;
time_t mLastSweepTime ;

View File

@ -31,6 +31,9 @@ static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORY_SYNC_REQ = 120 ; // 2 min
static const uint32_t DELAY_BETWEEN_LOCAL_DIRECTORIES_TS_UPDATE = 20 ; // 20 sec. But we only update for real if something has changed.
static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP = 60 ; // 60 sec.
static const uint32_t DELAY_BEFORE_DELETE_NON_EMPTY_REMOTE_DIR = 60*24*86400 ; // delete non empty remoe directories after 60 days of inactivity
static const uint32_t DELAY_BEFORE_DELETE_EMPTY_REMOTE_DIR = 5*24*86400 ; // delete empty remote directories after 5 days of inactivity
static const std::string HASH_CACHE_DURATION_SS = "HASH_CACHE_DURATION" ; // key string to store hash remembering time
static const std::string WATCH_FILE_DURATION_SS = "WATCH_FILES_DELAY" ; // key to store delay before re-checking for new files
static const std::string WATCH_FILE_ENABLED_SS = "WATCH_FILES_ENABLED"; // key to store ON/OFF flags for file whatch

View File

@ -440,10 +440,30 @@ void p3FileDatabase::cleanup()
for(std::list<RsPeerId>::const_iterator it(friend_lst.begin());it!=friend_lst.end();++it)
friend_set.insert(*it) ;
}
time_t now = time(NULL);
for(uint32_t i=0;i<mRemoteDirectories.size();++i)
if(mRemoteDirectories[i] != NULL && friend_set.find(mRemoteDirectories[i]->peerId()) == friend_set.end())
if(mRemoteDirectories[i] != NULL)
{
time_t recurs_mod_time ;
mRemoteDirectories[i]->getDirectoryRecursModTime(0,recurs_mod_time) ;
time_t last_contact = 0 ;
RsPeerDetails pd ;
if(rsPeers->getPeerDetails(mRemoteDirectories[i]->peerId(),pd))
last_contact = pd.lastConnect ;
// We remove directories in the following situations:
// - the peer is not a friend
// - the dir list is non empty but the peer is offline since more than 60 days
// - the dir list is empty and the peer is ffline since more than 5 days
bool should_remove = friend_set.find(mRemoteDirectories[i]->peerId()) == friend_set.end()
|| (recurs_mod_time == 0 && last_contact + DELAY_BEFORE_DELETE_EMPTY_REMOTE_DIR < now )
|| (recurs_mod_time != 0 && last_contact + DELAY_BEFORE_DELETE_NON_EMPTY_REMOTE_DIR < now );
if(!should_remove)
continue ;
#ifdef DEBUG_P3FILELISTS
P3FILELISTS_DEBUG() << " removing file list of non friend " << mRemoteDirectories[i]->peerId() << std::endl;
@ -455,6 +475,10 @@ void p3FileDatabase::cleanup()
mFriendIndexMap.erase(mRemoteDirectories[i]->peerId());
// also remove the existing file
remove(mRemoteDirectories[i]->filename().c_str()) ;
delete mRemoteDirectories[i];
mRemoteDirectories[i] = NULL ;
@ -487,8 +511,6 @@ void p3FileDatabase::cleanup()
std::set<RsPeerId> online_peers ;
mServCtrl->getPeersConnected(getServiceInfo().mServiceType, online_peers) ;
time_t now = time(NULL);
for(std::map<DirSyncRequestId,DirSyncRequestData>::iterator it = mPendingSyncRequests.begin();it!=mPendingSyncRequests.end();)
if(online_peers.find(it->second.peer_id) == online_peers.end() || it->second.request_TS + DELAY_BEFORE_DROP_REQUEST < now)
{