* Addition of new File Transfer structure. (server / search / extralist / controller)

* Fixed up variable names in p3Qblog.cc
 * Cleaned up unused BaseInfo/PersonInfo/DirInfo in rstypes/rsiface
 * added new rsfiles interface (rough outline at the moment)



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@628 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-07-02 13:19:59 +00:00
parent eeb13e7b18
commit 473f3f75f3
16 changed files with 1337 additions and 419 deletions

View file

@ -0,0 +1,109 @@
/*
* libretroshare/src/ft: ftcontroller.h
*
* File Transfer for RetroShare.
*
* Copyright 2008 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef FT_CONTROLLER_HEADER
#define FT_CONTROLLER_HEADER
/*
* ftController
*
* Top level download controller.
*
* inherits configuration (save downloading files)
* inherits pqiMonitor (knows which peers are online).
* inherits CacheTransfer (transfers cache files too)
* inherits RsThread (to control transfers)
*
*/
class ftController: public CacheTransfer, public RsThread, public pqiMonitor, public p3Config
{
public:
/* Setup */
ftController(std::string configDir);
void setFtSearch(ftSearch *);
virtual void run();
/***************************************************************/
/********************** Controller Access **********************/
/***************************************************************/
bool FileRequest(std::string fname, std::string hash,
uint32_t size, std::string dest, uint32_t flags);
bool FileCancel(std::string hash);
bool FileControl(std::string hash, uint32_t flags);
bool FileClearCompleted();
/* get Details of File Transfers */
bool FileDownloads(std::list<std::string> &hashs);
/* Directory Handling */
void setDownloadDirectory(std::string path);
void setPartialsDirectory(std::string path);
std::string getDownloadDirectory();
std::string getPartialsDirectory();
bool FileDetails(std::string hash, FileInfo &info);
/***************************************************************/
/********************** Controller Access **********************/
/***************************************************************/
/* pqiMonitor callback (also provided mConnMgr pointer!) */
public:
virtual void statusChange(const std::list<pqipeer> &plist);
/* p3Config Interface */
protected:
virtual RsSerialiser *setupSerialiser();
virtual std::list<RsItem *> saveList(bool &cleanup);
virtual bool loadList(std::list<RsItem *> load);
private:
/* RunTime Functions */
/* pointers to other components */
ftSearch *mSearch;
RsMutex ctrlMutex;
std::list<FileDetails> incomingQueue;
std::map<std::string, FileDetails> mCompleted;
std::map<std::string, ftTransferModule *> mTransfers;
std::map<std::string, ftFileCreator *> mFileCreators;
std::string mConfigPath;
std::string mDownloadPath;
std::string mPartialPath;
};
#endif

View file

@ -0,0 +1,268 @@
/*
* libretroshare/src/ft: ftextralist.cc
*
* File Transfer for RetroShare.
*
* Copyright 2008 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef FT_FILE_EXTRA_LIST_HEADER
#define FT_FILE_EXTRA_LIST_HEADER
/*
* ftFileExtraList
*
* This maintains a list of 'Extra Files' to share with peers.
*
* Files are added via:
* 1) For Files which have been hashed already:
* addExtraFile(std::string path, std::string hash, uint64_t size, uint32_t period, uint32_t flags);
*
* 2) For Files to be hashed:
* hashExtraFile(std::string path, uint32_t period, uint32_t flags);
*
* Results of Hashing can be retrieved via:
* hashExtraFileDone(std::string path, std::string &hash, uint64_t &size);
*
* Files can be searched for via:
* searchExtraFiles(std::string hash, ftFileDetail file);
*
* This Class is Mutexed protected, and has a thread in it which checks the files periodically.
* If a file is found to have changed... It is discarded from the list - and not updated.
*
* this thread is also used to hash added files.
*
* The list of extra files is stored using the configuration system.
*
*/
class FileDetails
{
public:
std::list<std::string> sources;
std::string path;
std::string fname;
std::string hash;
uint64_t size;
uint32_t start;
uint32_t period;
uint32_t flags;
};
const uint32_t FT_DETAILS_CLEANUP = 0x0100; /* remove when it expires */
const uint32_t FT_DETAILS_LOCAL = 0x0001;
const uint32_t FT_DETAILS_REMOTE = 0x0002;
class ftExtraList: public p3Config
{
public:
ftExtraList::ftExtraList()
:p3Config(CONFIG_FT_EXTRA_LIST)
{
return;
}
void ftExtraList::run()
{
bool todo = false;
time_t cleanup = 0;
time_t now = 0;
while (1)
{
now = time(NULL);
{
RsStackMutex stack(extMutex);
todo = (mToHash.size() > 0);
}
if (todo)
{
/* Hash a file */
hashAFile();
/* microsleep */
usleep(10);
}
else
{
/* cleanup */
if (cleanup < now)
{
cleanupOldFiles();
cleanup = now + CLEANUP_PERIOD;
}
/* sleep */
sleep(1);
}
}
}
void ftExtraList::hashAFile()
{
/* extract entry from the queue */
std::string path;
{
RsStackMutex stack(extMutex);
path = mToHash.front();
mToHash.pop_front();
}
/* hash it! */
if (hashFile(path, details))
{
/* stick it in the available queue */
addExtraFile(path, hash, size, period, flags);
/* add to the path->hash map */
addNewlyHashed(path, details);
}
}
/***
* If the File is alreay Hashed, then just add it in.
**/
bool ftExtraList::addExtraFile(std::string path, std::string hash,
uint64_t size, uint32_t period, uint32_t flags)
{
RsStackMutex stack(extMutex);
}
bool ftExtraList::cleanupOldFiles()
{
RsStackMutex stack(extMutex);
std::list<std::string> toRemove;
std::list<std::string>::iterator rit;
std::map<std::string, FileDetails>::iterator it;
for(it = mFiles.begin(); it != mFiles.end(); it++)
{
/* check timestamps */
if (it->
{
toRemove.push_back(it->first);
}
}
if (toRemove.size() > 0)
{
/* remove items */
for(rit = toRemove.begin(); rit != toRemove.end(); rit++)
{
if (mFiles.end() != (it = mFiles.find(*rit)))
{
mFiles.erase(it);
}
}
}
}
/***
* Hash file, and add to the files,
* file is removed after period.
**/
bool ftExtraList::hashExtraFile(std::string path, uint32_t period, uint32_t flags)
{
/* add into queue */
RsStackMutex stack(extMutex);
FileDetails details(path, period, flags);
mToHash.push_back(details);
return true;
}
bool ftExtraList::hashExtraFileDone(std::string path, FileDetails &details)
{
std::string hash;
{
/* Find in the path->hash map */
RsStackMutex stack(extMutex);
std::map<std::string, std::string>::iterator it;
if (mHashedList.end() == (it = mHashedList.find(path)))
{
return false;
}
hash = it->second;
}
return searchExtraFiles(hash, details);
}
/***
* Search Function - used by File Transfer
*
**/
bool ftExtraList::searchExtraFiles(std::string hash, FileDetails &details)
{
RsStackMutex stack(extMutex);
/* find hash */
std::map<std::string, FileDetails>::iterator fit;
if (mFiles.end() == (fit = mFiles.find(hash)))
{
return false;
}
details = fit->second;
return true;
}
/***
* Configuration - store extra files.
*
**/
RsSerialiser *ftExtraList::setupSerialiser()
{
return NULL;
}
std::list<RsItem *> ftExtraList::saveList(bool &cleanup)
{
std::list<RsItem *> sList;
return sList;
}
bool ftExtraList::loadList(std::list<RsItem *> load)
{
return true;
}

View file

@ -0,0 +1,122 @@
/*
* libretroshare/src/ft: ftextralist.h
*
* File Transfer for RetroShare.
*
* Copyright 2008 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef FT_FILE_EXTRA_LIST_HEADER
#define FT_FILE_EXTRA_LIST_HEADER
/*
* ftFileExtraList
*
* This maintains a list of 'Extra Files' to share with peers.
*
* Files are added via:
* 1) For Files which have been hashed already:
* addExtraFile(std::string path, std::string hash, uint64_t size, uint32_t period, uint32_t flags);
*
* 2) For Files to be hashed:
* hashExtraFile(std::string path, uint32_t period, uint32_t flags);
*
* Results of Hashing can be retrieved via:
* hashExtraFileDone(std::string path, std::string &hash, uint64_t &size);
*
* Files can be searched for via:
* searchExtraFiles(std::string hash, ftFileDetail file);
*
* This Class is Mutexed protected, and has a thread in it which checks the files periodically.
* If a file is found to have changed... It is discarded from the list - and not updated.
*
* this thread is also used to hash added files.
*
* The list of extra files is stored using the configuration system.
*
*/
class FileDetails
{
public:
std::list<std::string> sources;
std::string path;
std::string fname;
std::string hash;
uint64_t size;
uint32_t start;
uint32_t period;
uint32_t flags;
};
const uint32_t FT_DETAILS_CLEANUP = 0x0100; /* remove when it expires */
const uint32_t FT_DETAILS_LOCAL = 0x0001;
const uint32_t FT_DETAILS_REMOTE = 0x0002;
class ftExtraList: public p3Config
{
public:
ftExtraList();
/***
* If the File is alreay Hashed, then just add it in.
**/
bool addExtraFile(std::string path, std::string hash,
uint64_t size, uint32_t period, uint32_t flags);
/***
* Hash file, and add to the files,
* file is removed after period.
**/
bool hashExtraFile(std::string path, uint32_t period, uint32_t flags);
bool hashExtraFileDone(std::string path, FileDetails &details);
/***
* Search Function - used by File Transfer
*
**/
bool searchExtraFiles(std::string hash, FileDetails &details);
/***
* Configuration - store extra files.
*
**/
protected:
virtual RsSerialiser *setupSerialiser();
virtual std::list<RsItem *> saveList(bool &cleanup);
virtual bool loadList(std::list<RsItem *> load);
private:
RsMutex extMutex;
std::map<std::string, std::string> hashedList; /* path -> hash ( not saved ) */
std::map<std::string, FileDetails> files;
};

View file

@ -0,0 +1,79 @@
/*
* libretroshare/src/ft: ftfilesearch.cc
*
* File Transfer for RetroShare.
*
* Copyright 2008 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef FT_FILE_SEARCH_HEADERd
#define FT_FILE_SEARCH_HEADER
/*
* ftFileSearch
*
* This is actually implements the ftSearch Interface.
*
*/
#include "ft/ftfilesearch.h"
#include "dbase/cachestrapper.h"
#include "dbase/fimonitor.h"
#include "dbase/fistore.h"
bool ftFileSearch::search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info)
{
#if 0
/* actual search depends on the hints */
if (hintflags | CACHE)
{
mCacheStrapper->..
}
if (hintflags | LOCAL)
{
}
if (hintflags | EXTRA)
{
}
if (hintflags | REMOTE)
{
}
private:
CacheStrapper *mCacheStrapper;
ftExtraList *mExtraList;
FileIndexMonitor *mFileMonitor;
FileIndexStore *mFileStore;
#endif
}

View file

@ -0,0 +1,64 @@
/*
* libretroshare/src/ft: ftfilesearch.h
*
* File Transfer for RetroShare.
*
* Copyright 2008 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef FT_FILE_SEARCH_HEADER
#define FT_FILE_SEARCH_HEADER
/*
* ftFileSearch
*
* This is actually implements the ftSearch Interface.
*
*/
#include "ft/ftsearch.h"
class CacheStrapper;
class ftExtraList;
class FileIndexMonitor;
class FileIndexStore;
class ftFileSearch: public ftSearch
{
public:
ftFileSearch(CacheStrapper *c, ftExtraList *x, FileIndexMonitor *m, FileIndexStore *s)
:mCacheStrapper(c), mExtraList(x), mFileMonitor(m), mFileStore(s) { return; }
virtual bool search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info);
private:
CacheStrapper *mCacheStrapper;
ftExtraList *mExtraList;
FileIndexMonitor *mFileMonitor;
FileIndexStore *mFileStore;
};

View file

@ -0,0 +1,51 @@
/*
* libretroshare/src/ft: ftsearch.h
*
* File Transfer for RetroShare.
*
* Copyright 2008 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef FT_SEARCH_HEADER
#define FT_SEARCH_HEADER
/*
* ftSearch
*
* This is a generic search interface - used by ft* to find files.
* The derived class will search for Caches/Local/ExtraList/Remote entries.
*
*/
#include "rsiface/rstypes.h"
class ftSearch
{
public:
ftSearch() { return; }
virtual bool search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info);
};

View file

@ -0,0 +1,301 @@
/*
* libretroshare/src/ft: ftserver.cc
*
* File Transfer for RetroShare.
*
* Copyright 2008 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
/* Setup */
ftServer::ftServer(CacheStrapper *cStrapper, p3ConnectMgr *connMgr)
:mCacheStrapper(cStrapper), mConnMgr(connMgr)
{
/* Final Setup (once everything is assigned) */
ftServer::SetupFtServer()
{
/* make Controller */
mFtController = new ftController();
NotifyBase *cb = getNotify();
/* setup FiStore/Monitor */
std::string localcachedir = config_dir + "/cache/local";
std::string remotecachedir = config_dir + "/cache/remote";
std::string ownId = mConnMgr->getOwnId();
mFiStore = new FileIndexStore(mCacheStrapper, mFtController, cb, ownId, remotecachedir);
mFiMon = new FileIndexMonitor(mCacheStrapper, localcachedir, ownId);
/* now add the set to the cachestrapper */
CachePair cp(mFiMon, mFiStore, CacheId(RS_SERVICE_TYPE_FILE_INDEX, 0));
mCacheStrapper -> addCachePair(cp);
/* extras List */
mFtExtra = new ftExtraList();
mFtSearch = new ftFileSearch(mCacheStrapper, mFtExtra, mFiMon, mFiStore);
mFtController -> setFtSearch(mFtSearch);
ftFiler -> setSaveBasePath(save_dir);
return;
}
/* Assign important variables */
void setConfigDirectory(std::string path);
void setPQInterface(PQInterface *pqi);
/* Final Setup (once everything is assigned) */
void SetupFtServer();
/* add Config Items (Extra, Controller) */
void addConfigComponents(p3ConfigMgr *mgr);
void ftServer::setConfigDirectory(std::string path)
{
mConfigPath = path;
}
void ftServer::setPQInterface(PQInterface *pqi)
/* Control Interface */
};
void ftServer::StartupThreads()
{
/* start up Controller thread */
/* start own thread */
}
CacheStrapper *ftServer::getCacheStrapper()
{
return mCacheStrapper;
}
CacheTransfer *ftServer::getCacheTransfer()
{
return mFtController;
}
/***************************************************************/
/********************** RsFiles Interface **********************/
/***************************************************************/
/***************************************************************/
/********************** Controller Access **********************/
/***************************************************************/
bool ftServer::FileRequest(std::string fname, std::string hash,
uint32_t size, std::string dest, uint32_t flags)
{
return mFtController->FileRequest(fname, hash, size, dest, flags);
}
bool ftServer::FileCancel(std::string hash);
{
return mFtController->FileCancel(hash);
}
bool ftServer::FileControl(std::string hash, uint32_t flags);
{
return mFtController->FileControl(hash, flags);
}
bool ftServer::FileClearCompleted();
{
return mFtController->FileClearCompleted();
}
/* get Details of File Transfers */
bool ftServer::FileDownloads(std::list<std::string> &hashs);
{
return mFtController->FileDownloads(hashs);
}
/* Directory Handling */
void ftServer::setDownloadDirectory(std::string path)
{
return mFtController->setDownloadDirectory(path);
}
std::string ftServer::getDownloadDirectory()
{
return mFtController->getDownloadDirectory();
}
void ftServer::setPartialsDirectory(std::string path);
{
return mFtController->setPartialsDirectory(path);
}
void ftServer::getPartialsDirectory()
{
return mFtController->getPartialsDirectory();
}
/***************************************************************/
/************************* Other Access ************************/
/***************************************************************/
bool ftServer::FileUploads(std::list<std::string> &hashs);
{
return mFtUploader->FileUploads(hashes);
}
bool ftServer::FileDetails(std::string hash, uint32_t hintflags, FileInfo &info);
{
bool found = false;
if (hintflags | DOWNLOADING)
{
found = mFtController->FileDetails(hash, info);
}
else if (hintflags | UPLOADING)
{
found = mFtUploader->FileDetails(hash, info);
}
if (!found)
{
mFtSearch->FileDetails(hash, hintflags, info);
}
return found;
}
/***************************************************************/
/******************* ExtraFileList Access **********************/
/***************************************************************/
bool ftServer::ExtraFileAdd(std::string fname, std::string hash, uint32_t size,
uint32_t period, uint32_t flags)
{
return mFtExtra->addExtraFile(fname, hash, size, period, flags);
}
bool ftServer::ExtraFileRemove(std::string hash, uin32_t flags);
{
return mFtExtra->removeExtraFile(hash, flags);
}
bool ftServer::ExtraFileHash(std::string localpath, uint32_t period, uint32_t flags);
{
return mFtExtra->hashExtraFile(localpath, period, flags);
}
bool ftServer::ExtraFileStatus(std::string localpath, FileInfo &info);
{
return mFtExtra->hashExtraFileDone(localpath, info);
}
/***************************************************************/
/******************** Directory Listing ************************/
/***************************************************************/
int ftServer::RequestDirDetails(std::string uid, std::string path, DirDetails &details);
{
return mFiStore->RequestDirDetails(uid, path, details);
}
int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
{
return mFiStore->RequestDirDetails(ref, details, flags);
}
/***************************************************************/
/******************** Search Interface *************************/
/***************************************************************/
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results);
{
return mFiStore->SearchKeywords(keywords, results);
}
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 mFtMon->inDirectoryCheck();
}
bool ftServer::getSharedDirectories(std::list<std::string> &dirs)
{
return mFtMon->getSharedDirectories(dirs);
}
bool ftServer::addSharedDirectory(std::string dir)
{
return mFtMon->addSharedDirectory(dir);
}
bool ftServer::removeSharedDirectory(std::string dir)
{
return mFtMon->removeSharedDirectory(dir);
}
/***************************************************************/
/****************** End of RsFiles Interface *******************/
/***************************************************************/
/***************************************************************/
/**************** Config Interface *****************************/
/***************************************************************/
protected:
/* Key Functions to be overloaded for Full Configuration */
virtual RsSerialiser *setupSerialiser();
virtual std::list<RsItem *> saveList(bool &cleanup);
virtual bool loadList(std::list<RsItem *> load);
private:
bool loadConfigMap(std::map<std::string, std::string> &configMap);
/******************* p3 Config Overload ************************/
};
#endif

View file

@ -0,0 +1,181 @@
/*
* libretroshare/src/ft: ftserver.h
*
* File Transfer for RetroShare.
*
* Copyright 2008 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef FT_SERVER_HEADER
#define FT_SERVER_HEADER
/*
* ftServer.
*
* Top level File Transfer interface.
* (replaces old filedexserver)
*
* sets up the whole File Transfer class structure.
* sets up the File Indexing side of cache system too.
*
* provides rsFiles interface for external control.
*
*/
#include "pqi/pqi.h"
#include "pqi/pqiindic.h"
#include "serialiser/rsconfigitems.h"
#include <map>
#include <deque>
#include <list>
#include <map>
#include <iostream>
#include "rsiface/rsiface.h"
#include "pqi/p3cfgmgr.h"
class p3ConnectMgr;
class p3AuthMgr;
class CacheStrapper;
class ftfiler;
class FileIndexStore;
class FileIndexMonitor;
class ftServer: public RsFiles
{
public:
/***************************************************************/
/******************** Setup ************************************/
/***************************************************************/
ftServer(CacheStrapper *cStrapper) { return; }
/* Assign important variables */
void setConfigDirectory(std::string path);
void setPQInterface(PQInterface *pqi);
/* Final Setup (once everything is assigned) */
void SetupFtServer();
/* add Config Items (Extra, Controller) */
void addConfigComponents(p3ConfigMgr *mgr);
CacheTransfer *getCacheTransfer();
/***************************************************************/
/*************** Control Interface *****************************/
/************** (Implements RsFiles) ***************************/
/***************************************************************/
virtual int FileRequest(std::string fname, std::string hash,
uint32_t size, std::string dest, uint32_t flags);
virtual int FileCancel(std::string hash);
virtual int FileControl(std::string hash, uint32_t flags);
virtual int FileClearCompleted();
/* get Details of File Transfers */
virtual bool FileDownloads(std::list<std::string> &hashs);
virtual bool FileUploads(std::list<std::string> &hashs);
virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info);
/* Access ftExtraList - Details */
virtual int ExtraFileAdd(std::string fname, std::string hash, uint32_t size,
uint32_t period, uint32_t flags);
virtual int ExtraFileRemove(std::string hash, uin32_t flags);
virtual bool ExtraFileHash(std::string localpath, uint32_t period, uint32_t flags);
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
/* Directory Listing */
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details);
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
/* Search Interface */
virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results);
virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results);
/* Utility Functions */
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath);
virtual void ForceDirectoryCheck();
virtual bool InDirectoryCheck();
/* Directory Handling */
virtual void setDownloadDirectory(std::string path);
virtual void setPartialsDirectory(std::string path);
virtual bool getSharedDirectories(std::list<std::string> &dirs);
virtual int addSharedDirectory(std::string dir);
virtual int removeSharedDirectory(std::string dir);
virtual int reScanDirs();
virtual int check_dBUpdate();
std::string getSaveDir();
void setSaveDir(std::string d);
void setEmergencySaveDir(std::string s);
void setConfigDir(std::string d) { config_dir = d; }
bool getSaveIncSearch();
void setSaveIncSearch(bool v);
/***************************************************************/
/*************** Control Interface *****************************/
/***************************************************************/
/******************* p3 Config Overload ************************/
protected:
/* Key Functions to be overloaded for Full Configuration */
virtual RsSerialiser *setupSerialiser();
virtual std::list<RsItem *> saveList(bool &cleanup);
virtual bool loadList(std::list<RsItem *> load);
private:
bool loadConfigMap(std::map<std::string, std::string> &configMap);
/******************* p3 Config Overload ************************/
/*************************** p3 Config Overload ********************/
private:
/* no need for Mutex protection -
* as each component is protected independently.
*/
CacheStrapper *mCacheStrapper;
ftController *mFtController;
ftExtraList *mFtExtra;
FileIndexStore *fiStore;
FileIndexMonitor *fimon;
RsMutex srvMutex;
std::string mConfigPath;
std::string mDownloadPath;
std::string mPartialsPath;
};
#endif