Started implementing flags to handle the sharing mode.

What works:
- the gui shows the flags in ShareManager
- the flags are loaded/saved to ft_shared.cfg and passed on to FileIndexMonitor
What does not work yet:
- the flags are not accounted for yet by FileIndexMonitor

In addition:
- simplified the directories dialog in Preferences, so that it calls the ShareManager instead of dupplicating the directories management 
code that becomes larger.
- setup the ShareManager to be a singleton, so as to coherently call it from different places.




git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1486 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-08-03 19:43:52 +00:00
parent aa1658245c
commit f9dc3b223b
19 changed files with 512 additions and 313 deletions

View file

@ -39,9 +39,9 @@
#include <openssl/sha.h>
#include <stdio.h>
/***********
* #define FIM_DEBUG 1
***********/
//***********
#define FIM_DEBUG 1
// ***********/
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in,std::string cachedir, std::string pid)
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid),
@ -59,7 +59,7 @@ FileIndexMonitor::~FileIndexMonitor()
return;
}
bool FileIndexMonitor::findLocalFile(std::string hash,
bool FileIndexMonitor::findLocalFile(std::string hash,uint32_t flags,
std::string &fullpath, uint64_t &size) const
{
std::list<FileEntry *> results;
@ -602,13 +602,45 @@ void FileIndexMonitor::updateCycle()
cb->notifyHashingInfo("") ;
}
void FileIndexMonitor::updateShareFlags(const SharedDirInfo& dir)
{
#ifdef FIM_DEBUG
std::cerr << "*** FileIndexMonitor: Updating flags for " << dir.filename << " to " << dir.shareflags << std::endl ;
#endif
{
RsStackMutex stack(fiMutex) ; /* LOCKED DIRS */
if(pendingDirs)
for(std::list<SharedDirInfo>::iterator it(pendingDirList.begin());it!=pendingDirList.end();++it)
{
std::cerr << "** testing pending dir " << (*it).filename << std::endl ;
if((*it).filename == dir.filename)
{
std::cerr << "** Updating to " << (*it).shareflags << "!!" << std::endl ;
(*it).shareflags = dir.shareflags ;
break ;
}
}
else
for(std::map<std::string,SharedDirInfo>::iterator it(directoryMap.begin());it!=directoryMap.end();++it)
{
std::cerr << "** testing " << (*it).second.filename << std::endl ;
if((*it).second.filename == dir.filename)
{
std::cerr << "** Updating from " << it->second.shareflags << "!!" << std::endl ;
(*it).second.shareflags = dir.shareflags ;
break ;
}
}
}
}
/* interface */
void FileIndexMonitor::setSharedDirectories(std::list<std::string> dirs)
void FileIndexMonitor::setSharedDirectories(std::list<SharedDirInfo> dirs)
{
std::list<std::string> checkeddirs;
std::list<SharedDirInfo> checkeddirs;
std::list<std::string>::iterator it;
std::list<SharedDirInfo>::iterator it;
#ifdef FIM_DEBUG
std::cerr << "FileIndexMonitor::setSharedDirectories() :\n";
#endif
@ -617,12 +649,12 @@ void FileIndexMonitor::setSharedDirectories(std::list<std::string> dirs)
{
#ifdef FIM_DEBUG
std::cerr << "\t" << *it;
std::cerr << "\t" << (*it).filename;
std::cerr << std::endl;
#endif
/* check if dir exists before adding in */
std::string path = (*it);
std::string path = (*it).filename;
DIR *dir = opendir(path.c_str());
if (!dir)
{
@ -633,41 +665,37 @@ void FileIndexMonitor::setSharedDirectories(std::list<std::string> dirs)
}
else
{
checkeddirs.push_back(path);
checkeddirs.push_back(*it);
}
closedir(dir);
}
fiMutex.lock(); { /* LOCKED DIRS */
{
RsStackMutex stack(fiMutex) ;/* LOCKED DIRS */
pendingDirs = true;
pendingDirList = checkeddirs;
} fiMutex.unlock(); /* UNLOCKED DIRS */
pendingDirs = true;
pendingDirList = checkeddirs;
}
}
/* interface */
void FileIndexMonitor::getSharedDirectories(std::list<std::string> &dirs)
void FileIndexMonitor::getSharedDirectories(std::list<SharedDirInfo> &dirs)
{
fiMutex.lock(); { /* LOCKED DIRS */
{
RsStackMutex stack(fiMutex) ; /* LOCKED DIRS */
/* must provide pendingDirs, as other parts depend on instanteous response */
if (pendingDirs)
{
dirs = pendingDirList;
}
else
{
/* get actual list (not pending stuff) */
std::map<std::string, std::string>::const_iterator it;
for(it = directoryMap.begin(); it != directoryMap.end(); it++)
/* must provide pendingDirs, as other parts depend on instanteous response */
if (pendingDirs)
dirs = pendingDirList;
else
{
dirs.push_back(it->second);
/* get actual list (not pending stuff) */
std::map<std::string, SharedDirInfo>::const_iterator it;
for(it = directoryMap.begin(); it != directoryMap.end(); it++)
dirs.push_back(it->second) ;
}
}
} fiMutex.unlock(); /* UNLOCKED DIRS */
}
@ -718,12 +746,12 @@ bool FileIndexMonitor::internal_setSharedDirectories()
directoryMap.clear();
/* iterate through the directories */
std::list<std::string>::iterator it;
std::map<std::string, std::string>::const_iterator cit;
std::list<SharedDirInfo>::iterator it;
std::map<std::string, SharedDirInfo>::const_iterator cit;
for(it = pendingDirList.begin(); it != pendingDirList.end(); it++)
{
/* get the head directory */
std::string root_dir = *it;
std::string root_dir = (*it).filename;
std::string top_dir = RsDirUtil::getTopDir(root_dir);
/* if unique -> add, else add modifier */
@ -741,7 +769,7 @@ bool FileIndexMonitor::internal_setSharedDirectories()
{
unique = true;
/* add it! */
directoryMap[tst_dir.c_str()] = root_dir;
directoryMap[tst_dir.c_str()] = *it;
#ifdef FIM_DEBUG
std::cerr << "Added [" << tst_dir << "] => " << root_dir << std::endl;
#endif
@ -774,7 +802,7 @@ std::string FileIndexMonitor::locked_findRealRoot(std::string rootdir) const
/**** MUST ALREADY BE LOCKED ****/
std::string realroot = "";
std::map<std::string, std::string>::const_iterator cit;
std::map<std::string, SharedDirInfo>::const_iterator cit;
if (directoryMap.end()== (cit=directoryMap.find(rootdir)))
{
std::cerr << "FileIndexMonitor::locked_findRealRoot() Invalid RootDir: ";
@ -782,7 +810,7 @@ std::string FileIndexMonitor::locked_findRealRoot(std::string rootdir) const
}
else
{
realroot = cit->second;
realroot = cit->second.filename;
}
return realroot;

View file

@ -27,6 +27,7 @@
#include "dbase/cachestrapper.h"
#include "dbase/findex.h"
#include "util/rsthreads.h"
#include "rsiface/rsfiles.h"
/******************************************************************************************
* The Local Monitoring Class: FileIndexMonitor.
@ -66,67 +67,71 @@ class NotifyBase ;
* FileIndexMonitor
*****************************************************************************************/
static const uint32_t RS_SHARED_FLAGS_PUBLIC = 0x0001 ;
static const uint32_t RS_SHARED_FLAGS_ANONYM = 0x0002 ;
class FileIndexMonitor: public CacheSource, public RsThread
{
public:
FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in, std::string cachedir, std::string pid);
virtual ~FileIndexMonitor();
FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in, std::string cachedir, std::string pid);
virtual ~FileIndexMonitor();
/* external interface for filetransfer */
bool findLocalFile(std::string hash, std::string &fullpath, uint64_t &size) const;
/* external interface for filetransfer */
bool findLocalFile(std::string hash,uint32_t f, std::string &fullpath, uint64_t &size) const;
/* external interface for local access to files */
bool convertSharedFilePath(std::string path, std::string &fullpath);
/* external interface for local access to files */
bool convertSharedFilePath(std::string path, std::string &fullpath);
/* Interacting with CacheSource */
/* overloaded from CacheSource */
virtual bool loadLocalCache(const CacheData &data); /* called with stored data */
bool updateCache(const CacheData &data); /* we call when we have a new cache for others */
/* Interacting with CacheSource */
/* overloaded from CacheSource */
virtual bool loadLocalCache(const CacheData &data); /* called with stored data */
bool updateCache(const CacheData &data); /* we call when we have a new cache for others */
/* the FileIndexMonitor inner workings */
//virtual void run(std::string& currentJob); /* overloaded from RsThread */
//void updateCycle(std::string& currentJob);
virtual void run(); /* overloaded from RsThread */
void updateCycle();
/* the FileIndexMonitor inner workings */
//virtual void run(std::string& currentJob); /* overloaded from RsThread */
//void updateCycle(std::string& currentJob);
virtual void run(); /* overloaded from RsThread */
void updateCycle();
virtual void setSharedDirectories(std::list<std::string> dirs);
void getSharedDirectories(std::list<std::string> &dirs);
virtual void setSharedDirectories(std::list<SharedDirInfo> dirs);
void getSharedDirectories(std::list<SharedDirInfo>& dirs);
void updateShareFlags(const SharedDirInfo& info) ;
void setPeriod(int insecs);
void forceDirectoryCheck();
bool inDirectoryCheck();
void setPeriod(int insecs);
void forceDirectoryCheck();
bool inDirectoryCheck();
/* util fns */
/* util fns */
private:
/* the mutex should be locked before calling... these. */
std::string locked_findRealRoot(std::string base) const;
bool hashFile(std::string path, FileEntry &fi); /* To Implement */
/* the mutex should be locked before calling... these. */
std::string locked_findRealRoot(std::string base) const;
bool hashFile(std::string path, FileEntry &fi); /* To Implement */
/* data */
/* data */
mutable RsMutex fiMutex;
mutable RsMutex fiMutex;
FileIndex fi;
FileIndex fi;
int updatePeriod;
std::map<std::string, std::string> directoryMap; /* used by findRealRoot */
int updatePeriod;
std::map<std::string, SharedDirInfo> directoryMap; /* used by findRealRoot */
/* flags to kick - if we were busy or sleeping */
bool pendingDirs;
bool pendingForceCacheWrite;
/* flags to kick - if we were busy or sleeping */
bool pendingDirs;
bool pendingForceCacheWrite;
/* flags to force Check, to tell if we're in check */
bool mForceCheck;
bool mInCheck;
/* flags to force Check, to tell if we're in check */
bool mForceCheck;
bool mInCheck;
std::list<std::string> pendingDirList;
bool internal_setSharedDirectories();
std::list<SharedDirInfo> pendingDirList;
bool internal_setSharedDirectories();
NotifyBase *cb ;
NotifyBase *cb ;
};