Completed most of ftserver class.

Also changes to make everything fit together.
changes to Interface to support srcId list.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@675 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-08-09 17:03:24 +00:00
parent d7e1a90c28
commit 189dcbb482
15 changed files with 512 additions and 166 deletions

View File

@ -7,13 +7,17 @@ RS_TOP_DIR = ..
include $(RS_TOP_DIR)/scripts/config.mk
###############################################################
RSOBJ = ftdata.o ftfileprovider.o ftfilecreator.o ftextralist.o ftdatamultiplex.o ftfilesearch.o fttransfermodule.o
RSOBJ = ftdata.o ftfileprovider.o ftfilecreator.o ftextralist.o ftdatamultiplex.o ftfilesearch.o fttransfermodule.o ftdbase.o ftserver.o
#ftserver.o
#ftcontroller.o pqitestor.o
TESTOBJ = ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o
TESTS = ftfileprovidertest ftfilecreatortest ftextralisttest ftdataplextest
TESTOBJ = ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o
#ftserver1test.o
TESTS = ftfileprovidertest ftfilecreatortest ftextralisttest ftdataplextest
#ftserver1test
all: librs tests
@ -29,6 +33,9 @@ ftextralisttest : ftextralisttest.o
ftdataplextest : ftdataplextest.o
$(CC) $(CFLAGS) -o ftdataplextest ftdataplextest.o $(LIBS)
ftserver1test : ftserver1test.o
$(CC) $(CFLAGS) -o ftserver1test ftserver1test.o $(LIBS)
###############################################################
include $(RS_TOP_DIR)/scripts/rules.mk
###############################################################

View File

@ -23,9 +23,6 @@
*
*/
#ifndef FT_CONTROLLER_HEADER
#define FT_CONTROLLER_HEADER
/*
* ftController
*
@ -38,20 +35,34 @@
*
*/
class ftController: public CacheTransfer, public RsThread, public pqiMonitor, public p3Config
#include "ft/ftcontroller.h"
#include "ft/ftfilecreator.h"
#include "ft/fttransfermodule.h"
#include "ft/ftsearch.h"
#include "ft/ftdatamultiplex.h"
#include "util/rsdir.h"
#include "pqi/p3connmgr.h"
#warning CONFIG_FT_CONTROL Not defined in p3cfgmgr.h
const uint32_t CONFIG_FT_CONTROL = 1;
ftController::ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string configDir)
:CacheTransfer(cs), p3Config(CONFIG_FT_CONTROL)
{
public:
/* TODO */
}
/* Setup */
ftController::ftController(std::string configDir);
void ftController::setFtSearch(ftSearch *search)
void ftController::setFtSearch(ftSearch *search)
{
mSearch = search;
}
virtual void ftController::run()
void ftController::run()
{
/* check the queues */
}
@ -68,6 +79,9 @@ void ftController::checkDownloadQueue()
bool ftController::completeFile(std::string hash)
{
#if 0
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
std::map<std::string, ftFileControl>::iterator it;
@ -88,8 +102,7 @@ bool ftController::completeFile(std::string hash)
/* done - cleanup */
fc->mTransfer->done();
mClientModule->removeTransferModule(fc->mTransfer);
mServerModule->removeFileCreator(fc->mCreator);
mDataplex->removeTransferModule(fc->mTransfer->hash());
delete fc->mTransfer;
fc->mTransfer = NULL;
@ -97,13 +110,15 @@ bool ftController::completeFile(std::string hash)
delete fc->mCreator;
fc->mCreator = NULL;
fc->state = COMPLETE;
fc->mState = COMPLETE;
/* switch map */
mCompleted[fc->hash] = *fc;
mCompleted[fc->mHash] = *fc;
mDownloads.erase(it);
return true;
#endif
}
/***************************************************************/
@ -112,11 +127,18 @@ bool ftController::completeFile(std::string hash)
bool ftController::FileRequest(std::string fname, std::string hash,
uint64_t size, std::string dest, uint32_t flags,
std::list<std::string> srcIds)
std::list<std::string> &srcIds)
{
/* check if we have the file */
if (ftSearch->findFile(LOCAL))
#if 0 /*** FIX ME !!!**************/
/* check if we have the file */
FileInfo info;
if (mSearch->search(hash, size,
RS_FILE_HINTS_LOCAL |
RS_FILE_HINTS_EXTRA |
RS_FILE_HINTS_SPEC_ONLY, info))
{
/* have it already */
/* add in as completed transfer */
@ -124,9 +146,11 @@ bool ftController::FileRequest(std::string fname, std::string hash,
}
/* do a source search - for any extra sources */
if (ftSearch->findFile(REMOTE))
if (mSearch->search(hash, size,
RS_FILE_HINTS_REMOTE |
RS_FILE_HINTS_SPEC_ONLY, info))
{
/* do something with results */
}
std::map<std::string, ftTransferModule *> mTransfers;
@ -136,27 +160,28 @@ bool ftController::FileRequest(std::string fname, std::string hash,
std::string savepath = mDownloadPath + "/" + fname;
std::string chunker = "";
ftFileCreator *fc = new ftFileCreator(savepath, size, hash, chunker);
ftTransferModule = *tm = new ftTransferModule(fc, mClientModule);
ftTransferModule *tm = new ftTransferModule(fc, mDataplex);
/* add into maps */
ftFileControl ftfc(fname, size, hash, flags, fc, tm);
/* add to ClientModule */
mClientModule->addTransferModule(tm);
mDataplex->addTransferModule(tm, fc);
/* now add source peers (and their current state) */
tm->setFileSources(srcIds);
/* get current state for transfer module */
std::list<std::string>::iterator it;
for(it = srcIds.begin(); it != srcIds.end(); it++)
{
if (mConnMgr->isOnline(*it))
{
tm->setPeer(*it, TRICKLE | ONLINE);
tm->setPeer(*it, RS_FILE_RATE_TRICKLE | RS_FILE_PEER_ONLINE);
}
else
{
tm->setPeer(*it, OFFLINE);
tm->setPeer(*it, RS_FILE_PEER_OFFLINE);
}
}
@ -165,12 +190,26 @@ bool ftController::FileRequest(std::string fname, std::string hash,
mDownloads[hash] = ftfc;
mSlowQueue.push_back(hash);
#endif
}
bool ftController::FileCancel(std::string hash);
bool ftController::FileControl(std::string hash, uint32_t flags);
bool ftController::FileClearCompleted();
bool ftController::FileCancel(std::string hash)
{
/* TODO */
return false;
}
bool ftController::FileControl(std::string hash, uint32_t flags)
{
return false;
}
bool ftController::FileClearCompleted()
{
return false;
}
/* get Details of File Transfers */
bool ftController::FileDownloads(std::list<std::string> &hashs)
@ -180,7 +219,7 @@ bool ftController::FileDownloads(std::list<std::string> &hashs)
std::map<std::string, ftFileControl>::iterator it;
for(it = mDownloads.begin(); it != mDownloads.end(); it++)
{
hashes.push_back(it->second.hash);
hashs.push_back(it->second.mHash);
}
return true;
}
@ -200,8 +239,10 @@ bool ftController::setDownloadDirectory(std::string path)
return false;
}
bool ftController::setPartialsDirectory(std::string path);
bool ftController::setPartialsDirectory(std::string path)
{
#if 0 /*** FIX ME !!!**************/
/* check it is not a subdir of download / shared directories (BAD) - TODO */
/* check if it exists */
@ -220,7 +261,9 @@ bool ftController::setPartialsDirectory(std::string path);
}
return true;
}
return false;
#endif
}
std::string ftController::getDownloadDirectory()
@ -266,6 +309,9 @@ bool ftController::FileDetails(std::string hash, FileInfo &info)
*/
void ftController::statusChange(const std::list<pqipeer> &plist)
{
#if 0 /*** FIX ME !!!**************/
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
/* add online to all downloads */
@ -278,11 +324,11 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
{
if (pit->actions | RS_PEER_CONNECTED)
{
((it->second).tm)->setPeer(ONLINE | TRICKLE);
((it->second).mTransfer)->setPeer(RS_FILE_PEER_ONLINE | RS_FILE_RATE_TRICKLE);
}
else if (pit->actions | RS_PEER_DISCONNECTED)
{
((it->second).tm)->setPeer(OFFLINE);
((it->second).mTransfer)->setPeer(RS_FILE_PEER_OFFLINE);
}
}
}
@ -294,71 +340,33 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
{
/* add in */
((it->second).tm)->setPeer(ONLINE | TRICKLE);
((it->second).mTransfer)->setPeer(RS_FILE_PEER_ONLINE | RS_FILE_RATE_TRICKLE);
}
else if (pit->actions | RS_PEER_DISCONNECTED)
{
((it->second).tm)->setPeer(OFFLINE);
((it->second).mTransfer)->setPeer(RS_FILE_PEER_OFFLINE);
}
}
#endif
}
/* p3Config Interface */
RsSerialiser *ftController::setupSerialiser()
{
return NULL;
}
std::list<RsItem *> ftController::saveList(bool &cleanup)
{
std::list<RsItem *> emptyList;
return emptyList;
}
bool ftController::loadList(std::list<RsItem *> load)
{
return false;
}
/* 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;
class ftFileControl
{
public:
ftFileControl(std::string fname, uint64_t size, std::string hash,
uint32_t flags, ftFileCreator *fc, ftTransferModule *tm);
std::string mName,
uint64_t mSize;
std::string mHash,
uint32_t mFlags;
ftFileCreator *mCreator;
ftTransferModule *mTransfer;
};
class ftPeerControl
{
std::string peerId;
std::map<std::string, uint32_t> priority;
uint32_t currentBandwidth;
uint32_t maxBandwidth;
};
std::map<std::string, ftFileControl> mDownloads;
/* A Bunch of Queues */
std::map<std::string, std::string> mStreamQueue;
std::map<std::string, std::string> mFastQueue;
std::list<std::string> mSlowQueue;
std::list<std::string> mTrickleQueue;
std::string mConfigPath;
std::string mDownloadPath;
std::string mPartialPath;
};
#endif

View File

@ -41,13 +41,41 @@
class ftFileCreator;
class ftTransferModule;
class ftFileProvider;
class ftSearch;
class ftDataMultiplex;
#include "dbase/cachestrapper.h"
#include "util/rsthreads.h"
#include "pqi/pqimonitor.h"
#include "pqi/p3cfgmgr.h"
#include "rsiface/rsfiles.h"
#include <map>
class ftFileControl
{
public:
ftFileControl();
ftFileControl(std::string fname, uint64_t size, std::string hash,
uint32_t flags, ftFileCreator *fc, ftTransferModule *tm);
ftTransferModule * mTransfer;
ftFileCreator * mCreator;
uint32_t mState;
std::string mHash;
std::string mName;
uint64_t mSize;
};
class ftController: public CacheTransfer, public RsThread, public pqiMonitor, public p3Config
{
public:
/* Setup */
ftController(std::string configDir);
ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string configDir);
void setFtSearch(ftSearch *);
@ -59,7 +87,7 @@ virtual void run();
bool FileRequest(std::string fname, std::string hash,
uint64_t size, std::string dest, uint32_t flags,
std::list<std::string> sourceIds);
std::list<std::string> &sourceIds);
bool FileCancel(std::string hash);
bool FileControl(std::string hash, uint32_t flags);
@ -93,18 +121,24 @@ virtual bool loadList(std::list<RsItem *> load);
private:
/* RunTime Functions */
void checkDownloadQueue();
bool completeFile(std::string hash);
/* pointers to other components */
ftSearch *mSearch;
ftDataMultiplex *mDataplex;
RsMutex ctrlMutex;
std::list<FileInfo> incomingQueue;
std::map<std::string, FileInfo> mCompleted;
std::map<std::string, ftTransferModule *> mTransfers;
std::map<std::string, ftFileCreator *> mFileCreators;
std::map<std::string, ftFileControl> mDownloads;
//std::map<std::string, ftTransferModule *> mTransfers;
//std::map<std::string, ftFileCreator *> mFileCreators;
std::string mConfigPath;
std::string mDownloadPath;

View File

@ -77,11 +77,11 @@ bool ftDataMultiplex::addTransferModule(ftTransferModule *mod, ftFileCreator *f)
return true;
}
bool ftDataMultiplex::removeTransferModule(ftTransferModule *mod, ftFileCreator *f)
bool ftDataMultiplex::removeTransferModule(std::string hash)
{
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
std::map<std::string, ftClient>::iterator it;
if (mClients.end() == (it = mClients.find(mod->hash())))
if (mClients.end() == (it = mClients.find(hash)))
{
/* error */
return false;
@ -91,6 +91,51 @@ bool ftDataMultiplex::removeTransferModule(ftTransferModule *mod, ftFileCreator
}
bool ftDataMultiplex::FileUploads(std::list<std::string> &hashs)
{
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
std::map<std::string, ftFileProvider *>::iterator sit;
for(sit = mServers.begin(); sit != mServers.end(); sit++)
{
hashs.push_back(sit->first);
}
return true;
}
bool ftDataMultiplex::FileDownloads(std::list<std::string> &hashs)
{
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
std::map<std::string, ftClient>::iterator cit;
for(cit = mClients.begin(); cit != mClients.end(); cit++)
{
hashs.push_back(cit->first);
}
return true;
}
bool ftDataMultiplex::FileDetails(std::string hash, uint32_t hintsflag, FileInfo &info)
{
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
std::map<std::string, ftFileProvider *>::iterator sit;
sit = mServers.find(hash);
if (sit != mServers.end())
{
(sit->second)->FileDetails(info);
return true;
}
std::map<std::string, ftClient>::iterator cit;
if (mClients.end() != (cit = mClients.find(hash)))
{
//(cit->second).mModule->FileDetails(info);
(cit->second).mCreator->FileDetails(info);
return true;
}
return false;
}
/* data interface */
/*************** SEND INTERFACE (calls ftDataSend) *******************/

View File

@ -45,6 +45,8 @@ class ftSearch;
#include "util/rsthreads.h"
#include "ft/ftdata.h"
#include "rsiface/rsfiles.h"
class ftClient
{
@ -86,9 +88,13 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
/* ftController Interface */
bool addTransferModule(ftTransferModule *mod, ftFileCreator *f);
bool removeTransferModule(ftTransferModule *mod, ftFileCreator *f);
bool removeTransferModule(std::string hash);
/* data interface */
/* get Details of File Transfers */
bool FileUploads(std::list<std::string> &hashs);
bool FileDownloads(std::list<std::string> &hashs);
bool FileDetails(std::string hash, uint32_t hintsflag, FileInfo &info);
/*************** SEND INTERFACE (calls ftDataSend) *******************/

View File

@ -0,0 +1,104 @@
/*
* libretroshare/src/ft: ftdbase.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".
*
*/
#include "ft/ftdbase.h"
#include "util/rsdir.h"
ftFiStore::ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,
RsPeerId ownid, std::string cachedir)
:FileIndexStore(cs, cft, cb_in, ownid, cachedir)
{
return;
}
bool ftFiStore::search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info) const
{
std::list<FileDetail> results;
std::list<FileDetail>::iterator it;
if (SearchHash(hash, results))
{
for(it = results.begin(); it != results.end(); it++)
{
if (it->size == size)
{
/*
*/
}
}
}
return false;
}
ftFiMonitor::ftFiMonitor(CacheStrapper *cs, std::string cachedir, std::string pid)
:FileIndexMonitor(cs, cachedir, pid)
{
return;
}
bool ftFiMonitor::search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info) const
{
uint64_t fsize;
std::string path;
if (findLocalFile(hash, path, fsize))
{
/* fill in details */
info.size = fsize;
info.fname = RsDirUtil::getTopDir(path);
info.path = path;
return true;
}
return false;
};
ftCacheStrapper::ftCacheStrapper(p3AuthMgr *am, p3ConnectMgr *cm)
:CacheStrapper(am, cm)
{
return;
}
/* overloaded search function */
bool ftCacheStrapper::search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info) const
{
CacheData data;
if (findCache(hash, data))
{
/* ... */
info.size = data.size;
info.fname = data.name;
info.path = data.path + "/" + data.name;
return true;
}
return false;
}

View File

@ -0,0 +1,75 @@
/*
* libretroshare/src/ft: ftdbase.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_DBASE_INTERFACE_HEADER
#define FT_DBASE_INTERFACE_HEADER
/*
* ftdbase.
*
* Wrappers for the Cache/FiStore/FiMonitor classes.
* So they work in the ft world.
*/
#include "ft/ftsearch.h"
#include "dbase/fistore.h"
#include "dbase/fimonitor.h"
#include "dbase/cachestrapper.h"
class ftFiStore: public FileIndexStore, public ftSearch
{
public:
ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,
RsPeerId ownid, std::string cachedir);
/* overloaded search function */
virtual bool search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info) const;
};
class ftFiMonitor: public FileIndexMonitor, public ftSearch
{
public:
ftFiMonitor(CacheStrapper *cs, std::string cachedir, std::string pid);
/* overloaded search function */
virtual bool search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info) const;
};
class ftCacheStrapper: public CacheStrapper, public ftSearch
{
public:
ftCacheStrapper(p3AuthMgr *am, p3ConnectMgr *cm);
/* overloaded search function */
virtual bool search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info) const;
};
#endif

View File

@ -108,7 +108,7 @@ void ftExtraList::hashAFile()
/* hash it! */
std::string name, hash;
uint64_t size;
//uint64_t size;
if (RsDirUtil::hashFile(details.info.path, details.info.fname,
details.info.hash, details.info.size))
{
@ -204,7 +204,7 @@ bool ftExtraList::cleanupOldFiles()
for(it = mFiles.begin(); it != mFiles.end(); it++)
{
/* check timestamps */
if (it->second.start + it->second.period < now)
if (it->second.start + it->second.period < (unsigned) now)
{
toRemove.push_back(it->first);
}

View File

@ -1,5 +1,7 @@
#include "ftfileprovider.h"
#include "util/rsdir.h"
ftFileProvider::ftFileProvider(std::string path, uint64_t size, std::string
hash) : total_size(size), hash(hash), file_name(path), fd(NULL) {
@ -21,6 +23,19 @@ uint64_t ftFileProvider::getFileSize()
return total_size;
}
bool ftFileProvider::FileDetails(FileInfo &info)
{
info.hash = hash;
info.size = total_size;
info.path = file_name;
info.fname = RsDirUtil::getTopDir(file_name);
/* Use req_loc / req_size to estimate data rate */
return true;
}
bool ftFileProvider::getFileData(uint64_t offset, uint32_t chunk_size, void *data)
{
RsStackMutex stack(ftPMutex); /********** STACK LOCKED MTX ******/

View File

@ -33,14 +33,19 @@
#include <iostream>
#include <stdint.h>
#include "util/rsthreads.h"
#include "rsiface/rsfiles.h"
class ftFileProvider
{
public:
ftFileProvider(std::string path, uint64_t size, std::string hash);
virtual ~ftFileProvider();
virtual bool getFileData(uint64_t offset, uint32_t chunk_size, void *data);
virtual bool FileDetails(FileInfo &info);
std::string getHash();
uint64_t getFileSize();
protected:
virtual int initializeFileAttrs();
uint64_t total_size;

View File

@ -32,22 +32,24 @@ const int ftserverzone = 29539;
#include "ft/ftcontroller.h"
#include "ft/ftdatamultiplex.h"
#include "dbase/cachestrapper.h"
#include "dbase/fimonitor.h"
#include "dbase/fistore.h"
// Includes CacheStrapper / FiMonitor / FiStore for us.
#include "ft/ftdbase.h"
#include "pqi/pqi.h"
#include "pqi/p3connmgr.h"
#include "serialiser/rsserviceids.h"
#include <iostream>
#include <sstream>
/* Setup */
ftServer::ftServer(CacheStrapper *cStrapper, p3ConnectMgr *connMgr)
:mCacheStrapper(cStrapper), mConnMgr(connMgr)
ftServer::ftServer(p3AuthMgr *authMgr, p3ConnectMgr *connMgr)
:mAuthMgr(authMgr), mConnMgr(connMgr)
{
mCacheStrapper = new ftCacheStrapper(authMgr, connMgr);
}
void ftServer::setConfigDirectory(std::string path)
@ -69,19 +71,16 @@ void ftServer::addConfigComponents(p3ConfigMgr *mgr)
}
/* Final Setup (once everything is assigned) */
void ftServer::SetupFtServer()
void ftServer::SetupFtServer(NotifyBase *cb)
{
/* make Controller */
mFtController = new ftController(config_dir);
NotifyBase *cb = getNotify();
/* setup FiStore/Monitor */
std::string localcachedir = config_dir + "/cache/local";
std::string remotecachedir = config_dir + "/cache/remote";
std::string localcachedir = mConfigPath + "/cache/local";
std::string remotecachedir = mConfigPath + "/cache/remote";
std::string ownId = mConnMgr->getOwnId();
mFiStore = new FileIndexStore(mCacheStrapper, mFtController, cb, ownId, remotecachedir);
mFiMon = new FileIndexMonitor(mCacheStrapper, localcachedir, ownId);
mFiStore = new ftFiStore(mCacheStrapper, mFtController, cb, ownId, remotecachedir);
mFiMon = new ftFiMonitor(mCacheStrapper, localcachedir, ownId);
/* now add the set to the cachestrapper */
CachePair cp(mFiMon, mFiStore, CacheId(RS_SERVICE_TYPE_FILE_INDEX, 0));
@ -91,15 +90,22 @@ void ftServer::SetupFtServer()
mFtExtra = new ftExtraList();
mFtSearch = new ftFileSearch();
//mFtSearch->addSearchMode(mCacheStrapper, RS_FILE_HINTS_CACHE);
mFtSearch->addSearchMode(mCacheStrapper, RS_FILE_HINTS_CACHE);
mFtSearch->addSearchMode(mFtExtra, RS_FILE_HINTS_EXTRA);
//mFtSearch->addSearchMode(mFiMon, RS_FILE_HINTS_LOCAL);
//mFtSearch->addSearchMode(mFiStore, RS_FILE_HINTS_REMOTE);
mFtSearch->addSearchMode(mFiMon, RS_FILE_HINTS_LOCAL);
mFtSearch->addSearchMode(mFiStore, RS_FILE_HINTS_REMOTE);
/* Transport */
mFtDataplex = new ftDataMultiplex(this, mFtSearch);
/* make Controller */
mFtController = new ftController(mCacheStrapper, mFtDataplex, mConfigPath);
mFtController -> setFtSearch(mFtSearch);
mFtController -> setSaveBasePath(save_dir);
std::string tmppath = "./";
mFtController->setPartialsDirectory(tmppath);
mFtController->setDownloadDirectory(tmppath);
mFtDataplex = ftDataMultiplex(this, mFtSearch);
mConnMgr->addMonitor(mFtController);
return;
}
@ -147,10 +153,11 @@ CacheTransfer *ftServer::getCacheTransfer()
/********************** Controller Access **********************/
/***************************************************************/
bool ftServer::FileRequest(std::string fname, std::string hash,
uint32_t size, std::string dest, uint32_t flags)
bool ftServer::FileRequest(std::string fname, std::string hash, uint32_t size,
std::string dest, uint32_t flags, std::list<std::string> srcIds)
{
return mFtController->FileRequest(fname, hash, size, dest, flags);
return mFtController->FileRequest(fname, hash, size,
dest, flags, srcIds);
}
bool ftServer::FileCancel(std::string hash)
@ -168,11 +175,6 @@ 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)
@ -200,9 +202,14 @@ std::string ftServer::getPartialsDirectory()
/************************* Other Access ************************/
/***************************************************************/
bool ftServer::FileDownloads(std::list<std::string> &hashs)
{
return mFtDataplex->FileDownloads(hashs);
}
bool ftServer::FileUploads(std::list<std::string> &hashs)
{
return mFtDataplex->FileUploads(hashes);
return mFtDataplex->FileUploads(hashs);
}
bool ftServer::FileDetails(std::string hash, uint32_t hintflags, FileInfo &info)
@ -210,16 +217,16 @@ bool ftServer::FileDetails(std::string hash, uint32_t hintflags, FileInfo &info)
bool found = false;
if (hintflags | RS_FILE_HINTS_DOWNLOAD)
{
found = mFtController->FileDetails(hash, info);
found = mFtDataplex->FileDetails(hash, hintflags, info);
}
else if (hintflags | RS_FILE_HINTS_UPLOAD)
{
found = mFtDataplex->FileDetails(hash, info);
found = mFtDataplex->FileDetails(hash, hintflags, info);
}
if (!found)
{
mFtSearch->FileDetails(hash, hintflags, info);
mFtSearch->search(hash, 0, hintflags, info);
}
return found;
}
@ -301,17 +308,43 @@ bool ftServer::InDirectoryCheck()
bool ftServer::getSharedDirectories(std::list<std::string> &dirs)
{
return mFiMon->getSharedDirectories(dirs);
mFiMon->getSharedDirectories(dirs);
return true;
}
bool ftServer::setSharedDirectories(std::list<std::string> &dirs)
{
mFiMon->setSharedDirectories(dirs);
return true;
}
bool ftServer::addSharedDirectory(std::string dir)
{
return mFiMon->addSharedDirectory(dir);
std::list<std::string> dirList;
mFiMon->getSharedDirectories(dirList);
dirList.push_back(dir);
mFiMon->setSharedDirectories(dirList);
return true;
}
bool ftServer::removeSharedDirectory(std::string dir)
{
return mFiMon->removeSharedDirectory(dir);
std::list<std::string> dirList;
std::list<std::string>::iterator it;
mFiMon->getSharedDirectories(dirList);
if (dirList.end() != (it =
std::find(dirList.begin(), dirList.end(), dir)))
{
return false;
}
dirList.erase(it);
mFiMon->setSharedDirectories(dirList);
return true;
}
@ -324,7 +357,6 @@ bool ftServer::removeSharedDirectory(std::string dir)
/**************** Config Interface *****************************/
/***************************************************************/
protected:
/* Key Functions to be overloaded for Full Configuration */
RsSerialiser *ftServer::setupSerialiser()
{
@ -372,6 +404,8 @@ bool ftServer::sendDataRequest(std::string peerId, std::string hash,
rfi->chunksize = chunksize; /* ftr->chunk; */
mP3iface->SendFileRequest(rfi);
return true;
}
const uint32_t MAX_FT_CHUNK = 32 * 1024; /* 32K */
@ -425,6 +459,8 @@ bool ftServer::sendData(std::string peerId, std::string hash, uint64_t size,
/* clean up data */
free(data);
return true;
}
@ -433,9 +469,6 @@ int ftServer::tick()
rslog(RSL_DEBUG_BASIC, ftserverzone,
"filedexserver::tick()");
/* the new Cache Hack() */
FileStoreTick();
if (mP3iface == NULL)
{
std::ostringstream out;
@ -471,6 +504,8 @@ bool ftServer::handleInputQueues()
{
handleCacheData();
handleFileData();
return true;
}
bool ftServer::handleCacheData()
@ -554,6 +589,7 @@ bool ftServer::handleCacheData()
mP3iface -> SendSearchResult(ci);
}
}
return true;
}

View File

@ -45,7 +45,7 @@
#include "ft/ftdata.h"
#include "rsiface/rsfiles.h"
#include "dbase/cachestrapper.h"
//#include "dbase/cachestrapper.h"
#include "pqi/pqi.h"
#include "pqi/p3cfgmgr.h"
@ -55,8 +55,12 @@ class p3ConnectMgr;
class p3AuthMgr;
class CacheStrapper;
class FileIndexStore;
class FileIndexMonitor;
class CacheTransfer;
class NotifyBase; /* needed by FiStore */
class ftCacheStrapper;
class ftFiStore;
class ftFiMonitor;
class ftController;
class ftExtraList;
@ -73,7 +77,7 @@ class ftServer: public RsFiles, public ftDataSend
/******************** Setup ************************************/
/***************************************************************/
ftServer(CacheStrapper *cStrapper, p3ConnectMgr *connMgr);
ftServer(p3AuthMgr *authMgr, p3ConnectMgr *connMgr);
/* Assign important variables */
void setConfigDirectory(std::string path);
@ -88,7 +92,9 @@ CacheStrapper *getCacheStrapper();
CacheTransfer *getCacheTransfer();
/* Final Setup (once everything is assigned) */
void SetupFtServer();
//void SetupFtServer();
void SetupFtServer(NotifyBase *cb);
void StartupThreads();
/***************************************************************/
@ -99,8 +105,8 @@ void StartupThreads();
/***
* Control of Downloads
***/
virtual bool FileRequest(std::string fname, std::string hash,
uint32_t size, std::string dest, uint32_t flags);
virtual bool FileRequest(std::string fname, std::string hash, uint32_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();
@ -148,6 +154,7 @@ virtual std::string getDownloadDirectory();
virtual std::string getPartialsDirectory();
virtual bool getSharedDirectories(std::list<std::string> &dirs);
virtual bool setSharedDirectories(std::list<std::string> &dirs);
virtual bool addSharedDirectory(std::string dir);
virtual bool removeSharedDirectory(std::string dir);
@ -203,15 +210,15 @@ virtual int check_dBUpdate();
p3AuthMgr *mAuthMgr;
p3ConnectMgr *mConnMgr;
CacheStrapper *mCacheStrapper;
ftCacheStrapper *mCacheStrapper;
ftFiStore *mFiStore;
ftFiMonitor *mFiMon;
ftController *mFtController;
ftExtraList *mFtExtra;
ftDataMultiplex *mFtDataplex;
FileIndexStore *mFiStore;
FileIndexMonitor *mFiMon;
ftFileSearch *mFtSearch;

View File

@ -38,16 +38,19 @@ extern RsFiles *rsFiles;
class Expression;
const uint32_t RS_FILE_CTRL_PAUSE = 0x0100;
const uint32_t RS_FILE_CTRL_START = 0x0200;
/* These are used mainly by ftController at the moment */
const uint32_t RS_FILE_CTRL_PAUSE = 0x00000100;
const uint32_t RS_FILE_CTRL_START = 0x00000200;
const uint32_t RS_FILE_CTRL_TRICKLE = 0x0001;
const uint32_t RS_FILE_CTRL_SLOW = 0x0002;
const uint32_t RS_FILE_CTRL_STANDARD = 0x0003;
const uint32_t RS_FILE_CTRL_FAST = 0x0004;
const uint32_t RS_FILE_CTRL_STREAM_AUDIO = 0x0005;
const uint32_t RS_FILE_CTRL_STREAM_VIDEO = 0x0006;
const uint32_t RS_FILE_RATE_TRICKLE = 0x00000001;
const uint32_t RS_FILE_RATE_SLOW = 0x00000002;
const uint32_t RS_FILE_RATE_STANDARD = 0x00000003;
const uint32_t RS_FILE_RATE_FAST = 0x00000004;
const uint32_t RS_FILE_RATE_STREAM_AUDIO = 0x00000005;
const uint32_t RS_FILE_RATE_STREAM_VIDEO = 0x00000006;
const uint32_t RS_FILE_PEER_ONLINE = 0x00001000;
const uint32_t RS_FILE_PEER_OFFLINE = 0x00002000;
/************************************
* Used To indicate where to search.
@ -86,8 +89,8 @@ virtual ~RsFiles() { return; }
/***
* Control of Downloads.
***/
virtual bool FileRequest(std::string fname, std::string hash,
uint32_t size, std::string dest, uint32_t flags) = 0;
virtual bool FileRequest(std::string fname, std::string hash, uint32_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;

View File

@ -141,8 +141,8 @@ bool p3Files::FileControl(std::string hash, uint32_t flags)
return false;
}
bool p3Files::FileRequest(std::string fname, std::string hash,
uint32_t size, std::string dest, uint32_t flags)
bool p3Files::FileRequest(std::string fname, std::string hash, uint32_t size,
std::string dest, uint32_t flags, std::list<std::string> srcIds)
{
lockRsCore(); /* LOCKED */

View File

@ -57,8 +57,9 @@ virtual bool FileUploads(std::list<std::string> &hashs);
virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info);
/* 2) Control of Downloads. */
virtual bool FileRequest(std::string fname, std::string hash,
uint32_t size, std::string dest, uint32_t flags);
virtual bool FileRequest(std::string fname, std::string hash, uint32_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();