share of incoming directory by default

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1359 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
alexandrut 2009-07-12 13:22:31 +00:00
parent 49e9066afb
commit 990ed277bd
9 changed files with 440 additions and 312 deletions

View file

@ -78,7 +78,8 @@ ftFileControl::ftFileControl(std::string fname,
}
ftController::ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string configDir)
:CacheTransfer(cs), p3Config(CONFIG_TYPE_FT_CONTROL), mDataplex(dm), mFtActive(false),mTurtle(NULL)
:CacheTransfer(cs), p3Config(CONFIG_TYPE_FT_CONTROL), mDataplex(dm), mFtActive(false),
mTurtle(NULL), mShareDownloadDir(true)
{
/* TODO */
}
@ -1293,6 +1294,7 @@ bool ftController::CancelCacheFile(RsPeerId id, std::string path, std::string ha
const std::string download_dir_ss("DOWN_DIR");
const std::string partial_dir_ss("PART_DIR");
const std::string share_dwl_dir("SHARE_DWL_DIR");
/* p3Config Interface */
@ -1323,6 +1325,7 @@ std::list<RsItem *> ftController::saveList(bool &cleanup)
/* basic control parameters */
configMap[download_dir_ss] = getDownloadDirectory();
configMap[partial_dir_ss] = getPartialsDirectory();
configMap[share_dwl_dir] = mShareDownloadDir ? "YES" : "NO";
RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet();
@ -1462,6 +1465,27 @@ bool ftController::loadConfigMap(std::map<std::string, std::string> &configMap)
setPartialsDirectory(mit->second);
}
if (configMap.end() != (mit = configMap.find(share_dwl_dir)))
{
if (mit->second == "YES")
{
setShareDownloadDirectory(true);
}
else if (mit->second == "NO")
{
setShareDownloadDirectory(false);
}
}
return true;
}
void ftController::setShareDownloadDirectory(bool value)
{
mShareDownloadDir = value;
}
bool ftController::getShareDownloadDirectory()
{
return mShareDownloadDir;
}

View file

@ -26,7 +26,7 @@
#ifndef FT_CONTROLLER_HEADER
#define FT_CONTROLLER_HEADER
/*
/*
* ftController
*
* Top level download controller.
@ -69,8 +69,8 @@ class ftFileControl
enum {DOWNLOADING,COMPLETED,ERROR_COMPLETION};
ftFileControl();
ftFileControl(std::string fname, std::string tmppath, std::string dest,
uint64_t size, std::string hash, uint32_t flags,
ftFileControl(std::string fname, std::string tmppath, std::string dest,
uint64_t size, std::string hash, uint32_t flags,
ftFileCreator *fc, ftTransferModule *tm, uint32_t cb_flags);
std::string mName;
@ -118,14 +118,17 @@ void setFtSearchNExtra(ftSearch *, ftExtraList *);
void setTurtleRouter(p3turtle *) ;
bool activate();
void setShareDownloadDirectory(bool value);
bool getShareDownloadDirectory();
virtual void run();
/***************************************************************/
/********************** Controller Access **********************/
/***************************************************************/
bool FileRequest(std::string fname, std::string hash,
uint64_t size, std::string dest, uint32_t flags,
bool FileRequest(std::string fname, std::string hash,
uint64_t size, std::string dest, uint32_t flags,
std::list<std::string> &sourceIds);
bool FileCancel(std::string hash);
@ -151,7 +154,7 @@ bool moveFile(const std::string& source,const std::string& dest) ;
protected:
virtual bool RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
virtual bool RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
virtual bool CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
/***************************************************************/
@ -172,7 +175,6 @@ virtual std::list<RsItem *> saveList(bool &cleanup);
virtual bool loadList(std::list<RsItem *> load);
bool loadConfigMap(std::map<std::string, std::string> &configMap);
private:
/* RunTime Functions */
@ -185,7 +187,7 @@ bool setPeerState(ftTransferModule *tm, std::string id,
/* pointers to other components */
ftSearch *mSearch;
ftSearch *mSearch;
ftDataMultiplex *mDataplex;
ftExtraList *mExtraList;
p3turtle *mTurtle ;
@ -218,6 +220,9 @@ bool setPeerState(ftTransferModule *tm, std::string id,
bool mFtActive;
bool mFtPendingDone;
std::list<ftPendingRequest> mPendingRequests;
/* share incoming directory */
bool mShareDownloadDir;
};
#endif

View file

@ -203,17 +203,17 @@ void ftServer::run()
{
if ((now - info.lastTS) > 10)
{
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
std::cout << "info.lastTS = " << info.lastTS << ", now=" << now << std::endl ;
#endif
toDels.push_back(sit->first);
}
}
}
}
if(!toDels.empty())
mFtDataplex->deleteServers(toDels) ;
#ifdef WIN32
Sleep(1000);
#else
@ -232,11 +232,11 @@ void ftServer::run()
/********************** Controller Access **********************/
/***************************************************************/
bool ftServer::FileRequest(std::string fname, std::string hash, uint64_t size,
bool ftServer::FileRequest(std::string fname, std::string hash, uint64_t size,
std::string dest, uint32_t flags, std::list<std::string> srcIds)
{
std::cerr << "Requesting " << fname << std::endl ;
return mFtController->FileRequest(fname, hash, size,
return mFtController->FileRequest(fname, hash, size,
dest, flags, srcIds);
}
@ -320,7 +320,7 @@ bool ftServer::FileDetails(std::string hash, uint32_t hintflags, FileInfo &info)
/******************* ExtraFileList Access **********************/
/***************************************************************/
bool ftServer::ExtraFileAdd(std::string fname, std::string hash, uint64_t size,
bool ftServer::ExtraFileAdd(std::string fname, std::string hash, uint64_t size,
uint32_t period, uint32_t flags)
{
return mFtExtra->addExtraFile(fname, hash, size, period, flags);
@ -354,7 +354,7 @@ bool ftServer::ExtraFileMove(std::string fname, std::string hash, uint64_t size,
int ftServer::RequestDirDetails(std::string uid, std::string path, DirDetails &details)
{
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
std::cerr << "ftServer::RequestDirDetails(uid:" << uid;
std::cerr << ", path:" << path << ", ...) -> mFiStore";
std::cerr << std::endl;
@ -367,10 +367,10 @@ int ftServer::RequestDirDetails(std::string uid, std::string path, DirDetails &d
#endif
return mFiStore->RequestDirDetails(uid, path, details);
}
int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
{
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
std::cerr << "ftServer::RequestDirDetails(ref:" << ref;
std::cerr << ", flags:" << flags << ", ...) -> mFiStore";
std::cerr << std::endl;
@ -384,7 +384,7 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
#endif
return mFiStore->RequestDirDetails(ref, details, flags);
}
/***************************************************************/
/******************** Search Interface *************************/
/***************************************************************/
@ -392,7 +392,7 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags)
{
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
std::cerr << "ftServer::SearchKeywords()";
std::cerr << std::endl;
@ -405,33 +405,33 @@ int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<FileDeta
#endif
return mFiStore->SearchKeywords(keywords, results,flags);
}
int ftServer::SearchBoolExp(Expression * exp, std::list<FileDetail> &results)
{
return mFiStore->searchBoolExp(exp, results);
}
/***************************************************************/
/*************** Local Shared Dir Interface ********************/
/***************************************************************/
bool ftServer::ConvertSharedFilePath(std::string path, std::string &fullpath)
{
return mFiMon->convertSharedFilePath(path, fullpath);
}
void ftServer::ForceDirectoryCheck()
{
mFiMon->forceDirectoryCheck();
return;
}
bool ftServer::InDirectoryCheck()
{
return mFiMon->inDirectoryCheck();
}
bool ftServer::getSharedDirectories(std::list<std::string> &dirs)
{
mFiMon->getSharedDirectories(dirs);
@ -459,14 +459,14 @@ bool ftServer::removeSharedDirectory(std::string dir)
std::list<std::string> dirList;
std::list<std::string>::iterator it;
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
std::cerr << "ftServer::removeSharedDirectory(" << dir << ")";
std::cerr << std::endl;
#endif
mFiMon->getSharedDirectories(dirList);
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
for(it = dirList.begin(); it != dirList.end(); it++)
{
std::cerr << "ftServer::removeSharedDirectory()";
@ -475,10 +475,10 @@ bool ftServer::removeSharedDirectory(std::string dir)
}
#endif
if (dirList.end() == (it =
if (dirList.end() == (it =
std::find(dirList.begin(), dirList.end(), dir)))
{
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
std::cerr << "ftServer::removeSharedDirectory()";
std::cerr << " Cannot Find Directory... Fail";
std::cerr << std::endl;
@ -488,7 +488,7 @@ bool ftServer::removeSharedDirectory(std::string dir)
}
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
std::cerr << "ftServer::removeSharedDirectory()";
std::cerr << " Updating Directories";
std::cerr << std::endl;
@ -500,6 +500,27 @@ bool ftServer::removeSharedDirectory(std::string dir)
return true;
}
void ftServer::setShareDownloadDirectory(bool value)
{
mFtController->setShareDownloadDirectory(value);
}
bool ftServer::getShareDownloadDirectory()
{
return mFtController->getShareDownloadDirectory();
}
bool ftServer::shareDownloadDirectory()
{
std::string dir = mFtController->getDownloadDirectory();
return addSharedDirectory(dir);
}
bool ftServer::unshareDownloadDirectory()
{
std::string dir = mFtController->getDownloadDirectory();
return removeSharedDirectory(dir);
}
/***************************************************************/
/****************** End of RsFiles Interface *******************/
@ -538,7 +559,7 @@ bool ftServer::loadConfigMap(std::map<std::string, std::string> &configMap)
/***************************************************************/
/* Client Send */
bool ftServer::sendDataRequest(std::string peerId, std::string hash,
bool ftServer::sendDataRequest(std::string peerId, std::string hash,
uint64_t size, uint64_t offset, uint32_t chunksize)
{
if(mTurtleRouter->isTurtlePeer(peerId))
@ -579,7 +600,7 @@ bool ftServer::sendData(std::string peerId, std::string hash, uint64_t size, uin
uint64_t offset = 0;
uint32_t chunk;
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
std::cerr << "ftServer::sendData() to " << peerId << std::endl;
std::cerr << "hash: " << hash;
std::cerr << " offset: " << baseoffset;
@ -624,7 +645,7 @@ bool ftServer::sendData(std::string peerId, std::string hash, uint64_t size, uin
mP3iface->SendFileData(rfd);
/* print the data pointer */
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
std::cerr << "ftServer::sendData() Packet: " << std::endl;
std::cerr << " offset: " << rfd->fd.file_offset;
std::cerr << " chunk: " << chunk;
@ -651,7 +672,7 @@ bool ftServer::sendData(std::string peerId, std::string hash, uint64_t size, uin
*/
int ftServer::tick()
{
rslog(RSL_DEBUG_BASIC, ftserverzone,
rslog(RSL_DEBUG_BASIC, ftserverzone,
"filedexserver::tick()");
if (mP3iface == NULL)
@ -661,7 +682,7 @@ int ftServer::tick()
#endif
std::ostringstream out;
rslog(RSL_DEBUG_BASIC, ftserverzone,
rslog(RSL_DEBUG_BASIC, ftserverzone,
"filedexserver::tick() Invalid Interface()");
return 1;
@ -712,13 +733,13 @@ bool ftServer::handleCacheData()
int i = 0;
int i_init = 0;
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
//std::cerr << "ftServer::handleCacheData()" << std::endl;
#endif
while((ci = mP3iface -> GetSearchResult()) != NULL)
{
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleCacheData() Recvd SearchResult (CacheResponse!)" << std::endl;
std::ostringstream out;
if (i++ == i_init)
@ -747,7 +768,7 @@ bool ftServer::handleCacheData()
i_init = i;
while((cr = mP3iface -> RequestedSearch()) != NULL)
{
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
/* just delete these */
std::ostringstream out;
out << "Requested Search:" << std::endl;
@ -758,7 +779,7 @@ bool ftServer::handleCacheData()
}
// Now handle it replacement (pushed cache results)
// Now handle it replacement (pushed cache results)
{
std::list<std::pair<RsPeerId, CacheData> > cacheUpdates;
std::list<std::pair<RsPeerId, CacheData> >::iterator it;
@ -768,7 +789,7 @@ bool ftServer::handleCacheData()
{
/* construct reply */
RsCacheItem *ci = new RsCacheItem();
/* id from incoming */
ci -> PeerId(it->first);
@ -779,7 +800,7 @@ bool ftServer::handleCacheData()
ci -> cacheType = (it->second).cid.type;
ci -> cacheSubId = (it->second).cid.subid;
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
std::ostringstream out2;
out2 << "Outgoing CacheStrapper Update -> RsCacheItem:" << std::endl;
ci -> print(out2);
@ -788,7 +809,7 @@ bool ftServer::handleCacheData()
//rslog(RSL_DEBUG_BASIC, ftserverzone, out2.str());
mP3iface -> SendSearchResult(ci);
i++;
}
}
@ -808,7 +829,7 @@ bool ftServer::handleFileData()
i_init = i;
while((fr = mP3iface -> GetFileRequest()) != NULL )
{
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleFileData() Recvd ftFiler Request" << std::endl;
std::ostringstream out;
if (i == i_init)
@ -820,8 +841,8 @@ bool ftServer::handleFileData()
#endif
i++; /* count */
mFtDataplex->recvDataRequest(fr->PeerId(),
fr->file.hash, fr->file.filesize,
mFtDataplex->recvDataRequest(fr->PeerId(),
fr->file.hash, fr->file.filesize,
fr->fileoffset, fr->chunksize);
FileInfo(ffr);
@ -832,7 +853,7 @@ FileInfo(ffr);
i_init = i;
while((fd = mP3iface -> GetFileData()) != NULL )
{
#ifdef SERVER_DEBUG
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleFileData() Recvd ftFiler Data" << std::endl;
std::cerr << "hash: " << fd->fd.file.hash;
std::cerr << " length: " << fd->fd.binData.bin_len;
@ -851,12 +872,12 @@ FileInfo(ffr);
/* incoming data */
mFtDataplex->recvData(fd->PeerId(),
fd->fd.file.hash, fd->fd.file.filesize,
fd->fd.file_offset,
fd->fd.binData.bin_len,
fd->fd.file.hash, fd->fd.file.filesize,
fd->fd.file_offset,
fd->fd.binData.bin_len,
fd->fd.binData.bin_data);
/* we've stolen the data part -> so blank before delete
/* we've stolen the data part -> so blank before delete
*/
fd->fd.binData.TlvShallowClear();
delete fd;
@ -882,7 +903,7 @@ bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr)
cfgmgr->addConfiguration("ft_shared.cfg", mFiMon);
cfgmgr->addConfiguration("ft_extra.cfg", mFtExtra);
cfgmgr->addConfiguration("ft_transfers.cfg", mFtController);
return true;
}

View file

@ -26,7 +26,7 @@
#ifndef FT_SERVER_HEADER
#define FT_SERVER_HEADER
/*
/*
* ftServer.
*
* Top level File Transfer interface.
@ -114,14 +114,14 @@ ftController *getController() const { return mFtController ; }
/***
* Control of Downloads
***/
virtual bool FileRequest(std::string fname, std::string hash, uint64_t size,
virtual bool FileRequest(std::string fname, std::string hash, uint64_t size,
std::string dest, uint32_t flags, std::list<std::string> srcIds);
virtual bool FileCancel(std::string hash);
virtual bool FileControl(std::string hash, uint32_t flags);
virtual bool FileClearCompleted();
/***
* Download/Upload Details
* Download/Upload Details
***/
virtual bool FileDownloads(std::list<std::string> &hashs);
virtual bool FileUploads(std::list<std::string> &hashs);
@ -130,10 +130,10 @@ virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info);
/***
* Extra List Access
***/
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size,
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size,
uint32_t period, uint32_t flags);
virtual bool ExtraFileRemove(std::string hash, uint32_t flags);
virtual bool ExtraFileHash(std::string localpath,
virtual bool ExtraFileHash(std::string localpath,
uint32_t period, uint32_t flags);
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
@ -150,14 +150,14 @@ virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail
virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results);
/***
* Utility Functions
* Utility Functions
***/
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath);
virtual void ForceDirectoryCheck();
virtual bool InDirectoryCheck();
/***
* Directory Handling
* Directory Handling
***/
virtual void setDownloadDirectory(std::string path);
virtual void setPartialsDirectory(std::string path);
@ -169,6 +169,10 @@ virtual bool setSharedDirectories(std::list<std::string> &dirs);
virtual bool addSharedDirectory(std::string dir);
virtual bool removeSharedDirectory(std::string dir);
virtual void setShareDownloadDirectory(bool value);
virtual bool getShareDownloadDirectory();
virtual bool shareDownloadDirectory();
virtual bool unshareDownloadDirectory();
/***************************************************************/
/*************** Control Interface *****************************/
@ -180,7 +184,7 @@ virtual bool removeSharedDirectory(std::string dir);
public:
virtual bool sendData(std::string peerId, std::string hash, uint64_t size,
uint64_t offset, uint32_t chunksize, void *data);
virtual bool sendDataRequest(std::string peerId,
virtual bool sendDataRequest(std::string peerId,
std::string hash, uint64_t size,
uint64_t offset, uint32_t chunksize);
@ -217,7 +221,7 @@ bool loadConfigMap(std::map<std::string, std::string> &configMap);
private:
/* no need for Mutex protection -
/* no need for Mutex protection -
* as each component is protected independently.
*/

View file

@ -55,7 +55,7 @@ const uint32_t RS_FILE_PEER_OFFLINE = 0x00002000;
/************************************
* Used To indicate where to search.
*
* The Order of these is very important,
* The Order of these is very important,
* it specifies the search order too.
*
*/
@ -101,13 +101,13 @@ virtual ~RsFiles() { return; }
/***
* Control of Downloads.
***/
virtual bool FileRequest(std::string fname, std::string hash, uint64_t size,
virtual bool FileRequest(std::string fname, std::string hash, uint64_t size,
std::string dest, uint32_t flags, std::list<std::string> srcIds) = 0;
virtual bool FileCancel(std::string hash) = 0;
virtual bool FileControl(std::string hash, uint32_t flags) = 0;
virtual bool FileClearCompleted() = 0;
/***
/***
* Download / Upload Details.
***/
virtual bool FileDownloads(std::list<std::string> &hashs) = 0;
@ -121,7 +121,7 @@ virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info) =
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size,
uint32_t period, uint32_t flags) = 0;
virtual bool ExtraFileRemove(std::string hash, uint32_t flags) = 0;
virtual bool ExtraFileHash(std::string localpath,
virtual bool ExtraFileHash(std::string localpath,
uint32_t period, uint32_t flags) = 0;
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0;
virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
@ -157,6 +157,10 @@ virtual bool getSharedDirectories(std::list<std::string> &dirs) = 0;
virtual bool addSharedDirectory(std::string dir) = 0;
virtual bool removeSharedDirectory(std::string dir) = 0;
virtual void setShareDownloadDirectory(bool value) = 0;
virtual bool getShareDownloadDirectory() = 0;
virtual bool shareDownloadDirectory() = 0;
virtual bool unshareDownloadDirectory() = 0;
};