2016-07-20 15:28:55 -04:00
|
|
|
#include "file_sharing/p3filelists.h"
|
2016-07-20 16:10:51 -04:00
|
|
|
#include "file_sharing/directory_storage.h"
|
2016-07-20 15:28:55 -04:00
|
|
|
#include "retroshare/rsids.h"
|
2016-07-18 21:52:44 -04:00
|
|
|
|
2016-07-20 16:10:51 -04:00
|
|
|
#define P3FILELISTS_DEBUG() std::cerr << "p3FileLists: "
|
2016-07-18 21:52:44 -04:00
|
|
|
|
|
|
|
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 ;
|
|
|
|
|
2016-07-20 16:10:51 -04:00
|
|
|
p3FileLists::p3FileLists(p3LinkMgr *mpeers)
|
|
|
|
: mLinkMgr(mpeers), mFLSMtx("p3FileLists")
|
2016-07-18 21:52:44 -04:00
|
|
|
{
|
|
|
|
// loads existing indexes for friends. Some might be already present here.
|
|
|
|
//
|
|
|
|
|
|
|
|
// init the directory watchers
|
|
|
|
|
|
|
|
// local variables/structures
|
|
|
|
//
|
|
|
|
mUpdateFlags = P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED ;
|
|
|
|
}
|
2016-07-20 16:10:51 -04:00
|
|
|
p3FileLists::~p3FileLists()
|
2016-07-18 21:52:44 -04:00
|
|
|
{
|
2016-07-20 16:10:51 -04:00
|
|
|
RS_STACK_MUTEX(mFLSMtx) ;
|
|
|
|
|
|
|
|
for(std::map<RsPeerId,RemoteDirectoryStorage*>::const_iterator it(mRemoteDirectories.begin());it!=mRemoteDirectories.end();++it)
|
|
|
|
delete it->second ;
|
|
|
|
|
|
|
|
mRemoteDirectories.clear(); // just a precaution, not to leave deleted pointers around.
|
|
|
|
|
2016-07-18 21:52:44 -04:00
|
|
|
// delete all pointers
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:10:51 -04:00
|
|
|
int p3FileLists::tick()
|
2016-07-18 21:52:44 -04:00
|
|
|
{
|
|
|
|
// 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();
|
2016-07-20 16:10:51 -04:00
|
|
|
|
|
|
|
return 0;
|
2016-07-18 21:52:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void p3FileLists::tickRecv()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void p3FileLists::tickSend()
|
|
|
|
{
|
|
|
|
// go through the list of out requests and send them to the corresponding friends, if they are online.
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:10:51 -04:00
|
|
|
bool p3FileLists::loadList(std::list<RsItem *>& items)
|
2016-07-18 21:52:44 -04:00
|
|
|
{
|
|
|
|
// This loads
|
|
|
|
//
|
|
|
|
// - list of locally shared directories, and the permissions that go with them
|
2016-07-20 16:10:51 -04:00
|
|
|
|
|
|
|
return true ;
|
2016-07-18 21:52:44 -04:00
|
|
|
}
|
|
|
|
|
2016-07-20 16:10:51 -04:00
|
|
|
bool p3FileLists::saveList(const std::list<RsItem *>& items)
|
2016-07-18 21:52:44 -04:00
|
|
|
{
|
2016-07-20 16:10:51 -04:00
|
|
|
return true ;
|
2016-07-18 21:52:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void p3FileLists::cleanup()
|
|
|
|
{
|
2016-07-20 16:10:51 -04:00
|
|
|
RS_STACK_MUTEX(mFLSMtx) ;
|
|
|
|
|
|
|
|
// look through the list of friend directories. Remove those who are not our friends anymore.
|
2016-07-18 21:52:44 -04:00
|
|
|
//
|
|
|
|
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 ;
|
2016-07-20 16:10:51 -04:00
|
|
|
mLinkMgr->getFriendList(friend_list) ;
|
2016-07-18 21:52:44 -04:00
|
|
|
|
|
|
|
for(std::list<RsPeerId>::const_iterator it(friend_list.begin());it!=friend_list.end();++it)
|
|
|
|
friend_set.insert(*it) ;
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:10:51 -04:00
|
|
|
for(std::map<RsPeerId,RemoteDirectoryStorage*>::iterator it(mRemoteDirectories.begin());it!=mRemoteDirectories.end();)
|
2016-07-18 21:52:44 -04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|