removed most of CacheStrapper stuff from ftServer, replaced fimonitor by p3FileDatabase

This commit is contained in:
mr-alice 2016-07-30 21:52:42 +02:00
parent aeb0595301
commit 5b9fd74d85
14 changed files with 463 additions and 769 deletions

View File

@ -1594,9 +1594,9 @@ std::string FileIndexMonitor::locked_findRealRoot(std::string rootdir) const
int FileIndexMonitor::RequestDirDetails(const std::string& path, DirDetails& details) const int FileIndexMonitor::RequestDirDetails(const std::string& path, DirDetails& details) const
{ {
/* lock it up */ /* lock it up */
RsStackMutex mutex(fiMutex) ; RsStackMutex mutex(fiMutex) ;
return fi.extractData(path,details) ; return fi.extractData(path,details) ;
} }
uint32_t FileIndexMonitor::getType(void *ref) const uint32_t FileIndexMonitor::getType(void *ref) const

View File

@ -137,7 +137,7 @@ class FileIndexMonitor: public CacheSource, public RsTickingThread
// Interface for browsing dir hirarchy // Interface for browsing dir hirarchy
int RequestDirDetails(void*, DirDetails&, FileSearchFlags) const ; int RequestDirDetails(void*, DirDetails&, FileSearchFlags) const ;
uint32_t getType(void*) const ; uint32_t getType(void*) const ;
int RequestDirDetails(const std::string& path, DirDetails &details) const ; int RequestDirDetails(const std::string& path, DirDetails &details) const ;
// set/update shared directories // set/update shared directories
virtual void setSharedDirectories(const std::list<SharedDirInfo>& dirs); virtual void setSharedDirectories(const std::list<SharedDirInfo>& dirs);
@ -146,7 +146,7 @@ class FileIndexMonitor: public CacheSource, public RsTickingThread
void forceDirectoryCheck(); // Force re-sweep the directories and see what's changed void forceDirectoryCheck(); // Force re-sweep the directories and see what's changed
void forceDirListsRebuildAndSend() ; // Force re-build dir lists because groups have changed. Does not re-check files. void forceDirListsRebuildAndSend() ; // Force re-build dir lists because groups have changed. Does not re-check files.
bool inDirectoryCheck(); bool inDirectoryCheck();
/* util fns */ /* util fns */

View File

@ -1,5 +1,9 @@
#include "serialiser/rsserviceids.h"
#include "file_sharing/p3filelists.h" #include "file_sharing/p3filelists.h"
#include "file_sharing/directory_storage.h" #include "file_sharing/directory_storage.h"
#include "file_sharing/directory_updater.h"
#include "retroshare/rsids.h" #include "retroshare/rsids.h"
#define P3FILELISTS_DEBUG() std::cerr << "p3FileLists: " #define P3FILELISTS_DEBUG() std::cerr << "p3FileLists: "
@ -9,19 +13,36 @@ 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_LOCAL_DIRS_CHANGED = 0x0002 ;
static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_DIRS_CHANGED = 0x0004 ; static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_DIRS_CHANGED = 0x0004 ;
p3FileLists::p3FileLists(p3LinkMgr *mpeers) #define NOT_IMPLEMENTED() { std::cerr << __PRETTY_FUNCTION__ << ": not implemented!" << std::endl; }
: mLinkMgr(mpeers), mFLSMtx("p3FileLists")
p3FileDatabase::p3FileDatabase(p3ServiceControl *mpeers)
: mServCtrl(mpeers), mFLSMtx("p3FileLists")
{ {
// loads existing indexes for friends. Some might be already present here. // loads existing indexes for friends. Some might be already present here.
// //
mRemoteDirectories.clear() ; // we should load them!
// init the directory watchers
mLocalSharedDirs = new LocalDirectoryStorage("local_file_store.bin") ;
// local variables/structures mHashCache = new HashStorage("hash_cache.bin") ;
//
mLocalDirWatcher = new LocalDirectoryUpdater(mHashCache,mLocalSharedDirs) ;
mRemoteDirWatcher = NULL; // not used yet
mLocalDirWatcher->start();
mUpdateFlags = P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED ; mUpdateFlags = P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED ;
} }
p3FileLists::~p3FileLists()
void p3FileDatabase::setSharedDirectories(const std::list<SharedDirInfo>& shared_dirs)
{
mLocalSharedDirs->setSharedDirectoryList(shared_dirs) ;
}
void p3FileDatabase::getSharedDirectories(std::list<SharedDirInfo>& shared_dirs)
{
mLocalSharedDirs->getSharedDirectoryList(shared_dirs) ;
}
p3FileDatabase::~p3FileDatabase()
{ {
RS_STACK_MUTEX(mFLSMtx) ; RS_STACK_MUTEX(mFLSMtx) ;
@ -30,10 +51,28 @@ p3FileLists::~p3FileLists()
mRemoteDirectories.clear(); // just a precaution, not to leave deleted pointers around. mRemoteDirectories.clear(); // just a precaution, not to leave deleted pointers around.
// delete all pointers delete mLocalSharedDirs ;
delete mLocalDirWatcher ;
delete mRemoteDirWatcher ;
delete mHashCache ;
} }
int p3FileLists::tick() const std::string FILE_DB_APP_NAME = "file_database";
const uint16_t FILE_DB_APP_MAJOR_VERSION = 1;
const uint16_t FILE_DB_APP_MINOR_VERSION = 0;
const uint16_t FILE_DB_MIN_MAJOR_VERSION = 1;
const uint16_t FILE_DB_MIN_MINOR_VERSION = 0;
RsServiceInfo p3FileDatabase::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_FILE_DATABASE,
FILE_DB_APP_NAME,
FILE_DB_APP_MAJOR_VERSION,
FILE_DB_APP_MINOR_VERSION,
FILE_DB_MIN_MAJOR_VERSION,
FILE_DB_MIN_MINOR_VERSION);
}
int p3FileDatabase::tick()
{ {
// tick the watchers, possibly create new ones if additional friends do connect. // tick the watchers, possibly create new ones if additional friends do connect.
// //
@ -53,29 +92,37 @@ int p3FileLists::tick()
return 0; return 0;
} }
void p3FileLists::tickRecv() void p3FileDatabase::tickWatchers()
{ {
} NOT_IMPLEMENTED();
void p3FileLists::tickSend()
{
// go through the list of out requests and send them to the corresponding friends, if they are online.
} }
bool p3FileLists::loadList(std::list<RsItem *>& items) void p3FileDatabase::tickRecv()
{
}
void p3FileDatabase::tickSend()
{
// go through the list of out requests and send them to the corresponding friends, if they are online.
NOT_IMPLEMENTED();
}
bool p3FileDatabase::loadList(std::list<RsItem *>& items)
{ {
// This loads // This loads
// //
// - list of locally shared directories, and the permissions that go with them // - list of locally shared directories, and the permissions that go with them
NOT_IMPLEMENTED();
return true ; return true ;
} }
bool p3FileLists::saveList(const std::list<RsItem *>& items) bool p3FileDatabase::saveList(bool &cleanup, std::list<RsItem *>&)
{ {
NOT_IMPLEMENTED();
return true ; return true ;
} }
void p3FileLists::cleanup() void p3FileDatabase::cleanup()
{ {
RS_STACK_MUTEX(mFLSMtx) ; RS_STACK_MUTEX(mFLSMtx) ;
@ -83,15 +130,8 @@ void p3FileLists::cleanup()
// //
P3FILELISTS_DEBUG() << "Cleanup pass." << std::endl; P3FILELISTS_DEBUG() << "Cleanup pass." << std::endl;
std::set<RsPeerId> friend_set ; std::set<RsPeerId> friend_set ;
{ mServCtrl->getPeersConnected(getServiceInfo().mServiceType, friend_set);
#warning we should use a std::set in the first place. Modify rsPeers?
std::list<RsPeerId> friend_list ;
mLinkMgr->getFriendList(friend_list) ;
for(std::list<RsPeerId>::const_iterator it(friend_list.begin());it!=friend_list.end();++it)
friend_set.insert(*it) ;
}
for(std::map<RsPeerId,RemoteDirectoryStorage*>::iterator it(mRemoteDirectories.begin());it!=mRemoteDirectories.end();) for(std::map<RsPeerId,RemoteDirectoryStorage*>::iterator it(mRemoteDirectories.begin());it!=mRemoteDirectories.end();)
if(friend_set.find(it->first) == friend_set.end()) if(friend_set.find(it->first) == friend_set.end())
@ -125,4 +165,59 @@ void p3FileLists::cleanup()
IndicateConfigChanged(); IndicateConfigChanged();
} }
int p3FileDatabase::RequestDirDetails(void *ref, DirDetails&, FileSearchFlags) const
{
NOT_IMPLEMENTED();
return 0;
}
int p3FileDatabase::RequestDirDetails(const std::string& path, DirDetails &details) const
{
NOT_IMPLEMENTED();
return 0;
}
uint32_t p3FileDatabase::getType(void *ref) const
{
NOT_IMPLEMENTED();
return 0;
}
void p3FileDatabase::forceDirectoryCheck() // Force re-sweep the directories and see what's changed
{
NOT_IMPLEMENTED();
}
bool p3FileDatabase::inDirectoryCheck()
{
NOT_IMPLEMENTED();
return 0;
}
void p3FileDatabase::setWatchPeriod(uint32_t seconds)
{
NOT_IMPLEMENTED();
}
uint32_t p3FileDatabase::watchPeriod()
{
NOT_IMPLEMENTED();
return 0;
}
void p3FileDatabase::setRememberHashCacheDuration(uint32_t days)
{
NOT_IMPLEMENTED();
}
uint32_t p3FileDatabase::rememberHashCacheDuration()
{
NOT_IMPLEMENTED();
return 0;
}
void p3FileDatabase::clearHashCache()
{
NOT_IMPLEMENTED();
}
bool p3FileDatabase::rememberHashCache()
{
NOT_IMPLEMENTED();
return false;
}
void p3FileDatabase::setRememberHashCache(bool)
{
NOT_IMPLEMENTED();
}

View File

@ -21,23 +21,30 @@
// //
#pragma once #pragma once
#include "ft/ftsearch.h"
#include "retroshare/rsfiles.h" #include "retroshare/rsfiles.h"
#include "services/p3service.h" #include "services/p3service.h"
#include "file_sharing/hash_cache.h"
#include "pqi/p3cfgmgr.h" #include "pqi/p3cfgmgr.h"
#include "pqi/p3linkmgr.h" #include "pqi/p3linkmgr.h"
class RemoteDirectoryStorage ; class RemoteDirectoryUpdater ;
class RemoteSharedDirectoryWatcher ; class LocalDirectoryUpdater ;
class LocalSharedDirectoryWatcher ;
class LocalSharedDirectoryMap ;
class HashCache ;
class p3FileLists: public p3Service, public p3Config //, public RsSharedFileService class RemoteDirectoryStorage ;
class LocalDirectoryStorage ;
class HashStorage ;
class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, public RsSharedFileService
{ {
public: public:
typedef uint64_t EntryIndex ; // this should probably be defined elsewhere typedef uint64_t EntryIndex ; // this should probably be defined elsewhere
virtual RsServiceInfo getServiceInfo();
struct RsFileListSyncRequest struct RsFileListSyncRequest
{ {
RsPeerId peerId ; RsPeerId peerId ;
@ -45,12 +52,17 @@ class p3FileLists: public p3Service, public p3Config //, public RsSharedFileServ
// [...] more to add here // [...] more to add here
}; };
p3FileLists(p3LinkMgr *mpeers) ; p3FileDatabase(p3ServiceControl *mpeers) ;
~p3FileLists(); ~p3FileDatabase();
/*!
* \brief forceSyncWithPeers
*
* Forces the synchronisation of the database with connected peers. This is triggered when e.g. a new gorup of friend is created, or when
* a friend was added/removed from a group.
*/
void forceSyncWithPeers();
/*
*/
// derived from p3Service // derived from p3Service
// //
virtual int tick() ; virtual int tick() ;
@ -62,32 +74,61 @@ class p3FileLists: public p3Service, public p3Config //, public RsSharedFileServ
virtual int SearchKeywords(const std::list<std::string>& keywords, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) ; virtual int SearchKeywords(const std::list<std::string>& keywords, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) ;
virtual int SearchBoolExp(Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) const ; virtual int SearchBoolExp(Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) const ;
// ftSearch
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
// Interface for browsing dir hierarchy // Interface for browsing dir hierarchy
// //
int RequestDirDetails(EntryIndex, DirDetails&, FileSearchFlags) const ;
uint32_t getType(const EntryIndex&) const ; void stopThreads() ;
void startThreads() ;
int RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details);
int RequestDirDetails(const std::string& path, DirDetails &details) const ; int RequestDirDetails(const std::string& path, DirDetails &details) const ;
// set/update shared directories // void * here is the type expected by the abstract model index from Qt. It gets turned into a DirectoryStorage::EntryIndex internally.
void setSharedDirectories(const std::list<SharedDirInfo>& dirs);
void getSharedDirectories(std::list<SharedDirInfo>& dirs); int RequestDirDetails(void *, DirDetails&, FileSearchFlags) const ;
void updateShareFlags(const SharedDirInfo& info) ; uint32_t getType(void *) const ;
// set/update shared directories
void setSharedDirectories(const std::list<SharedDirInfo>& dirs);
void getSharedDirectories(std::list<SharedDirInfo>& dirs);
void updateShareFlags(const SharedDirInfo& info) ;
bool convertSharedFilePath(const std::string& path,std::string& fullpath);
// interface for hash caching
void setWatchPeriod(uint32_t seconds);
uint32_t watchPeriod() ;
void setRememberHashCacheDuration(uint32_t days) ;
uint32_t rememberHashCacheDuration() ;
void clearHashCache() ;
bool rememberHashCache() ;
void setRememberHashCache(bool) ;
// interfact for directory parsing
void forceDirectoryCheck(); // Force re-sweep the directories and see what's changed void forceDirectoryCheck(); // Force re-sweep the directories and see what's changed
bool inDirectoryCheck(); bool inDirectoryCheck();
// Derived from p3Config // debug
// void full_print();
protected: protected:
// Derived from p3Config
//
virtual bool loadList(std::list<RsItem *>& items); virtual bool loadList(std::list<RsItem *>& items);
virtual bool saveList(const std::list<RsItem *>& items); virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
virtual RsSerialiser *setupSerialiser() ;
void cleanup(); void cleanup();
void tickRecv(); void tickRecv();
void tickSend(); void tickSend();
void tickWatchers(); void tickWatchers();
private: private:
p3LinkMgr *mLinkMgr ; p3ServiceControl *mServCtrl ;
// File sync request queues. The fast one is used for online browsing when friends are connected. // File sync request queues. The fast one is used for online browsing when friends are connected.
// The slow one is used for background update of file lists. // The slow one is used for background update of file lists.
@ -98,15 +139,14 @@ class p3FileLists: public p3Service, public p3Config //, public RsSharedFileServ
// Directory storage hierarchies // Directory storage hierarchies
// //
std::map<RsPeerId,RemoteDirectoryStorage *> mRemoteDirectories ; std::map<RsPeerId,RemoteDirectoryStorage *> mRemoteDirectories ;
LocalDirectoryStorage *mLocalSharedDirs ;
LocalSharedDirectoryMap *mLocalSharedDirs ;
RemoteSharedDirectoryWatcher *mRemoteDirWatcher ; RemoteDirectoryUpdater *mRemoteDirWatcher ;
LocalSharedDirectoryWatcher *mLocalDirWatcher ; LocalDirectoryUpdater *mLocalDirWatcher ;
// We use a shared file cache as well, to avoid re-hashing files with known modification TS and equal name. // We use a shared file cache as well, to avoid re-hashing files with known modification TS and equal name.
// //
HashCache *mHashCache ; HashStorage *mHashCache ;
// Local flags and mutexes // Local flags and mutexes

View File

@ -73,10 +73,8 @@
static const int32_t SAVE_TRANSFERS_DELAY = 301 ; // save transfer progress every 301 seconds. static const int32_t SAVE_TRANSFERS_DELAY = 301 ; // save transfer progress every 301 seconds.
static const int32_t INACTIVE_CHUNKS_CHECK_DELAY = 240 ; // time after which an inactive chunk is released static const int32_t INACTIVE_CHUNKS_CHECK_DELAY = 240 ; // time after which an inactive chunk is released
static const int32_t MAX_TIME_INACTIVE_REQUEUED = 120 ; // time after which an inactive ftFileControl is bt-queued static const int32_t MAX_TIME_INACTIVE_REQUEUED = 120 ; // time after which an inactive ftFileControl is bt-queued
static const int32_t TIMOUT_CACHE_FILE_TRANSFER = 800 ; // time after which cache transfer gets cancelled if inactive.
static const int32_t FT_FILECONTROL_QUEUE_ADD_END = 0 ; static const int32_t FT_FILECONTROL_QUEUE_ADD_END = 0 ;
static const int32_t FT_FILECONTROL_QUEUE_ADD_AFTER_CACHE = 1 ;
const uint32_t FT_CNTRL_STANDARD_RATE = 10 * 1024 * 1024; const uint32_t FT_CNTRL_STANDARD_RATE = 10 * 1024 * 1024;
const uint32_t FT_CNTRL_SLOW_RATE = 100 * 1024; const uint32_t FT_CNTRL_SLOW_RATE = 100 * 1024;
@ -99,8 +97,8 @@ ftFileControl::ftFileControl(std::string fname,
return; return;
} }
ftController::ftController(CacheStrapper *cs, ftDataMultiplex *dm, p3ServiceControl *sc, uint32_t ftServiceId) ftController::ftController(ftDataMultiplex *dm, p3ServiceControl *sc, uint32_t ftServiceId)
:CacheTransfer(cs), p3Config(), : p3Config(),
last_save_time(0), last_save_time(0),
last_clean_time(0), last_clean_time(0),
mDataplex(dm), mDataplex(dm),
@ -231,7 +229,6 @@ void ftController::data_tick()
time_t now = time(NULL) ; time_t now = time(NULL) ;
if(now > last_save_time + SAVE_TRANSFERS_DELAY) if(now > last_save_time + SAVE_TRANSFERS_DELAY)
{ {
cleanCacheDownloads() ;
searchForDirectSources() ; searchForDirectSources() ;
IndicateConfigChanged() ; IndicateConfigChanged() ;
@ -282,16 +279,15 @@ void ftController::searchForDirectSources()
for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); ++it) for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); ++it)
if(it->second->mState != ftFileControl::QUEUED && it->second->mState != ftFileControl::PAUSED) if(it->second->mState != ftFileControl::QUEUED && it->second->mState != ftFileControl::PAUSED)
if(! (it->second->mFlags & RS_FILE_REQ_CACHE)) {
{ FileInfo info ; // info needs to be re-allocated each time, to start with a clear list of peers (it's not cleared down there)
FileInfo info ; // info needs to be re-allocated each time, to start with a clear list of peers (it's not cleared down there)
if(mSearch->search(it->first, RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY, info)) if(mSearch->search(it->first, RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY, info))
for(std::list<TransferInfo>::const_iterator pit = info.peers.begin(); pit != info.peers.end(); ++pit) for(std::list<TransferInfo>::const_iterator pit = info.peers.begin(); pit != info.peers.end(); ++pit)
if(rsPeers->servicePermissionFlags(pit->peerId) & RS_NODE_PERM_DIRECT_DL) if(rsPeers->servicePermissionFlags(pit->peerId) & RS_NODE_PERM_DIRECT_DL)
if(it->second->mTransfer->addFileSource(pit->peerId)) /* if the sources don't exist already - add in */ if(it->second->mTransfer->addFileSource(pit->peerId)) /* if the sources don't exist already - add in */
setPeerState(it->second->mTransfer, pit->peerId, FT_CNTRL_STANDARD_RATE, mServiceCtrl->isPeerConnected(mFtServiceId, pit->peerId)); setPeerState(it->second->mTransfer, pit->peerId, FT_CNTRL_STANDARD_RATE, mServiceCtrl->isPeerConnected(mFtServiceId, pit->peerId));
} }
} }
void ftController::tickTransfers() void ftController::tickTransfers()
@ -335,37 +331,6 @@ void ftController::setPriority(const RsFileHash& hash,DwlSpeed p)
it->second->mTransfer->setDownloadPriority(p) ; it->second->mTransfer->setDownloadPriority(p) ;
} }
void ftController::cleanCacheDownloads()
{
std::vector<RsFileHash> toCancel ;
time_t now = time(NULL) ;
{
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
if (((it->second)->mFlags & RS_FILE_REQ_CACHE) && it->second->mState != ftFileControl::DOWNLOADING)
// check if a cache file is downloaded, if the case, timeout the transfer after TIMOUT_CACHE_FILE_TRANSFER
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::run() cache transfer found. age of this tranfer is :" << (int)(time(NULL) - (it->second)->mCreateTime);
std::cerr << std::endl;
#endif
if (now > (it->second)->mCreator->creationTimeStamp() + TIMOUT_CACHE_FILE_TRANSFER)
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::run() cache transfer to old. Cancelling transfer. Hash :" << (it->second)->mHash << ", time=" << (it->second)->mCreateTime << ", now = " << time(NULL) ;
std::cerr << std::endl;
#endif
toCancel.push_back((it->second)->mHash);
}
}
}
for(uint32_t i=0;i<toCancel.size();++i)
FileCancel(toCancel[i]);
}
/* Called every 10 seconds or so */ /* Called every 10 seconds or so */
void ftController::checkDownloadQueue() void ftController::checkDownloadQueue()
{ {
@ -446,17 +411,13 @@ void ftController::checkDownloadQueue()
for(uint32_t p=0;p<_queue.size();++p) for(uint32_t p=0;p<_queue.size();++p)
{ {
if(p < _min_prioritized_transfers) if(p < _min_prioritized_transfers)
if(_queue[p]->mFlags & RS_FILE_REQ_CACHE) // cache file. add to potential move list
to_move_before.push_back(p) ;
else
++user_transfers ; // count one more user file in the prioritized range. ++user_transfers ; // count one more user file in the prioritized range.
else else
{ {
if(to_move_after.size() + user_transfers >= _min_prioritized_transfers) // we caught enough transfers to move back to the top of the queue. if(to_move_after.size() + user_transfers >= _min_prioritized_transfers) // we caught enough transfers to move back to the top of the queue.
break ; break ;
if(!(_queue[p]->mFlags & RS_FILE_REQ_CACHE)) // non cache file. add to potential move list to_move_after.push_back(p) ;
to_move_after.push_back(p) ;
} }
} }
uint32_t to_move = (uint32_t)std::max(0,(int)_min_prioritized_transfers - (int)user_transfers) ; // we move as many transfers as needed to get _min_prioritized_transfers user transfers. uint32_t to_move = (uint32_t)std::max(0,(int)_min_prioritized_transfers - (int)user_transfers) ; // we move as many transfers as needed to get _min_prioritized_transfers user transfers.
@ -482,27 +443,6 @@ void ftController::locked_addToQueue(ftFileControl* ftfc,int add_strategy)
case FT_FILECONTROL_QUEUE_ADD_END: _queue.push_back(ftfc) ; case FT_FILECONTROL_QUEUE_ADD_END: _queue.push_back(ftfc) ;
locked_checkQueueElement(_queue.size()-1) ; locked_checkQueueElement(_queue.size()-1) ;
break ; break ;
case FT_FILECONTROL_QUEUE_ADD_AFTER_CACHE:
{
// We add the transfer just before the first non cache transfer.
// This is costly, so only use this in case we really need it.
//
uint32_t pos =0;
while(pos < _queue.size() && (pos < _min_prioritized_transfers || (_queue[pos]->mFlags & RS_FILE_REQ_CACHE)>0) )
++pos ;
_queue.push_back(NULL) ;
for(int i=int(_queue.size())-1;i>(int)pos;--i)
{
_queue[i] = _queue[i-1] ;
locked_checkQueueElement(i) ;
}
_queue[pos] = ftfc ;
locked_checkQueueElement(pos) ;
}
break ;
} }
} }
@ -787,8 +727,8 @@ bool ftController::completeFile(const RsFileHash& hash)
std::string path; std::string path;
std::string name; std::string name;
uint64_t size = 0; uint64_t size = 0;
uint32_t state = 0; uint32_t state = 0;
uint32_t period = 0; uint32_t period = 0;
TransferRequestFlags flags ; TransferRequestFlags flags ;
TransferRequestFlags extraflags ; TransferRequestFlags extraflags ;
uint32_t completeCount = 0; uint32_t completeCount = 0;
@ -889,12 +829,8 @@ bool ftController::completeFile(const RsFileHash& hash)
locked_queueRemove(it->second->mQueuePosition) ; locked_queueRemove(it->second->mQueuePosition) ;
/* switch map */ /* switch map */
if (!(fc->mFlags & RS_FILE_REQ_CACHE)) /* clean up completed cache files automatically */ mCompleted[fc->mHash] = fc;
{ completeCount = mCompleted.size();
mCompleted[fc->mHash] = fc;
completeCount = mCompleted.size();
} else
delete fc ;
mDownloads.erase(it); mDownloads.erase(it);
@ -910,51 +846,14 @@ bool ftController::completeFile(const RsFileHash& hash)
/* If it has a callback - do it now */ /* If it has a callback - do it now */
if(flags & ( RS_FILE_REQ_CACHE | RS_FILE_REQ_EXTRA))// | RS_FILE_HINTS_MEDIA)) if(flags & RS_FILE_REQ_EXTRA)// | RS_FILE_HINTS_MEDIA))
{ {
#ifdef CONTROL_DEBUG
std::cerr << "ftController::completeFile() doing Callback, callbackflags:" << (flags & ( RS_FILE_REQ_CACHE | RS_FILE_REQ_EXTRA ));//| RS_FILE_HINTS_MEDIA)) ;
std::cerr << std::endl;
#endif
if(flags & RS_FILE_REQ_CACHE)
{
/* callback */
if (state == ftFileControl::COMPLETED)
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::completeFile() doing Callback : Success";
std::cerr << std::endl;
#endif
CompletedCache(hash);
}
else
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::completeFile() Cache Callback : Failed";
std::cerr << std::endl;
#endif
FailedCache(hash);
}
}
if(flags & RS_FILE_REQ_EXTRA)
{
#ifdef CONTROL_DEBUG #ifdef CONTROL_DEBUG
std::cerr << "ftController::completeFile() adding to ExtraList"; std::cerr << "ftController::completeFile() adding to ExtraList";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mExtraList->addExtraFile(path, hash, size, period, extraflags); mExtraList->addExtraFile(path, hash, size, period, extraflags);
}
// if(flags & RS_FILE_HINTS_MEDIA)
// {
//#ifdef CONTROL_DEBUG
// std::cerr << "ftController::completeFile() NULL MEDIA callback";
// std::cerr << std::endl;
//#endif
// }
} }
else else
{ {
@ -965,14 +864,12 @@ bool ftController::completeFile(const RsFileHash& hash)
} }
/* Notify GUI */ /* Notify GUI */
if ((flags & RS_FILE_REQ_CACHE) == 0) { RsServer::notify()->AddPopupMessage(RS_POPUP_DOWNLOAD, hash.toStdString(), name, "");
RsServer::notify()->AddPopupMessage(RS_POPUP_DOWNLOAD, hash.toStdString(), name, "");
RsServer::notify()->notifyDownloadComplete(hash.toStdString()); RsServer::notify()->notifyDownloadComplete(hash.toStdString());
RsServer::notify()->notifyDownloadCompleteCount(completeCount); RsServer::notify()->notifyDownloadCompleteCount(completeCount);
rsFiles->ForceDirectoryCheck() ; rsFiles->ForceDirectoryCheck() ;
}
IndicateConfigChanged(); /* completed transfer -> save */ IndicateConfigChanged(); /* completed transfer -> save */
return true; return true;
@ -1134,17 +1031,16 @@ bool ftController::FileRequest(const std::string& fname, const RsFileHash& hash
// remove the sources from the list, if they don't have clearance for direct transfer. This happens only for non cache files. // remove the sources from the list, if they don't have clearance for direct transfer. This happens only for non cache files.
// //
if(!(flags & RS_FILE_REQ_CACHE)) for(std::list<RsPeerId>::iterator it = srcIds.begin(); it != srcIds.end(); )
for(std::list<RsPeerId>::iterator it = srcIds.begin(); it != srcIds.end(); ) if(!(rsPeers->servicePermissionFlags(*it) & RS_NODE_PERM_DIRECT_DL))
if(!(rsPeers->servicePermissionFlags(*it) & RS_NODE_PERM_DIRECT_DL)) {
{ std::list<RsPeerId>::iterator tmp(it) ;
std::list<RsPeerId>::iterator tmp(it) ; ++tmp ;
++tmp ; srcIds.erase(it) ;
srcIds.erase(it) ; it = tmp ;
it = tmp ; }
} else
else ++it ;
++it ;
std::list<RsPeerId>::const_iterator it; std::list<RsPeerId>::const_iterator it;
std::list<TransferInfo>::const_iterator pit; std::list<TransferInfo>::const_iterator pit;
@ -1280,7 +1176,7 @@ bool ftController::FileRequest(const std::string& fname, const RsFileHash& hash
if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING) if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING)
mTurtle->monitorTunnels(hash,mFtServer,true) ; mTurtle->monitorTunnels(hash,mFtServer,true) ;
bool assume_availability = flags & RS_FILE_REQ_CACHE ; // assume availability for cache files bool assume_availability = false;
ftFileCreator *fc = new ftFileCreator(savepath, size, hash,assume_availability); ftFileCreator *fc = new ftFileCreator(savepath, size, hash,assume_availability);
ftTransferModule *tm = new ftTransferModule(fc, mDataplex,this); ftTransferModule *tm = new ftTransferModule(fc, mDataplex,this);
@ -1911,58 +1807,6 @@ void ftController::statusChange(const std::list<pqiServicePeer> &plist)
} }
} }
/* Cache Interface */
bool ftController::RequestCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size)
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::RequestCacheFile(" << id << ",";
std::cerr << path << "," << hash << "," << size << ")";
std::cerr << std::endl;
#endif
/* Request File */
std::list<RsPeerId> ids;
ids.push_back(id);
FileInfo info ;
if(mSearch->search(hash, RS_FILE_HINTS_CACHE, info))
{
#ifdef CONTROL_DEBUG
std::cerr << "I already have this file:" << std::endl ;
std::cerr << " path: " << info.path << std::endl ;
std::cerr << " fname: " << info.fname << std::endl ;
std::cerr << " hash: " << info.hash << std::endl ;
std::cerr << "Copying it !!" << std::endl ;
#endif
if(info.size > 0 && copyFile(info.path,path+"/"+hash.toStdString()))
{
CompletedCache(hash);
return true ;
}
else
return false ;
}
FileRequest(hash.toStdString(), hash, size, path, RS_FILE_REQ_CACHE | RS_FILE_REQ_NO_SEARCH, ids);
return true;
}
bool ftController::CancelCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size)
{
std::cerr << "ftController::CancelCacheFile(" << id << ",";
std::cerr << path << "," << hash << "," << size << ")";
std::cerr << std::endl;
#ifdef CONTROL_DEBUG
#endif
return FileCancel(hash);
}
const std::string active_downloads_size_ss("MAX_ACTIVE_DOWNLOADS"); const std::string active_downloads_size_ss("MAX_ACTIVE_DOWNLOADS");
const std::string min_prioritized_downl_ss("MIN_PRORITIZED_DOWNLOADS"); const std::string min_prioritized_downl_ss("MIN_PRORITIZED_DOWNLOADS");
const std::string download_dir_ss("DOWN_DIR"); const std::string download_dir_ss("DOWN_DIR");
@ -2056,14 +1900,6 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
/* ignore cache files. As this is small files, better download them again from scratch at restart.*/ /* ignore cache files. As this is small files, better download them again from scratch at restart.*/
if (fit->second->mFlags & RS_FILE_REQ_CACHE)
{
#ifdef CONTROL_DEBUG
std::cerr << "ftcontroller::saveList(): Not saving (callback) file entry " << fit->second->mName << ", " << fit->second->mHash << ", " << fit->second->mSize << std::endl ;
#endif
continue;
}
// Node: We still save finished transfers. This keeps transfers that are // Node: We still save finished transfers. This keeps transfers that are
// in checking mode. Finished or checked transfers will restart and // in checking mode. Finished or checked transfers will restart and
// immediately terminate/recheck at next startup. // immediately terminate/recheck at next startup.

View File

@ -113,12 +113,12 @@ class ftPendingRequest
}; };
class ftController: public CacheTransfer, public RsTickingThread, public pqiServiceMonitor, public p3Config class ftController: public RsTickingThread, public pqiServiceMonitor, public p3Config
{ {
public: public:
/* Setup */ /* Setup */
ftController(CacheStrapper *cs, ftDataMultiplex *dm, p3ServiceControl *sc, uint32_t ftServiceId); ftController(ftDataMultiplex *dm, p3ServiceControl *sc, uint32_t ftServiceId);
void setFtSearchNExtra(ftSearch *, ftExtraList *); void setFtSearchNExtra(ftSearch *, ftExtraList *);
void setTurtleRouter(p3turtle *) ; void setTurtleRouter(p3turtle *) ;
@ -195,10 +195,6 @@ class ftController: public CacheTransfer, public RsTickingThread, public pqiServ
protected: protected:
virtual bool RequestCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size);
virtual bool CancelCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size);
void cleanCacheDownloads() ;
void searchForDirectSources() ; void searchForDirectSources() ;
void tickTransfers() ; void tickTransfers() ;

View File

@ -1104,8 +1104,6 @@ bool ftDataMultiplex::handleSearchRequest(const RsPeerId& peerId, const RsFileHa
if(rsTurtle->isTurtlePeer(peerId)) if(rsTurtle->isTurtlePeer(peerId))
hintflags |= RS_FILE_HINTS_NETWORK_WIDE ; hintflags |= RS_FILE_HINTS_NETWORK_WIDE ;
else
hintflags |= RS_FILE_HINTS_CACHE ;
if(mSearch->search(hash, hintflags, info)) if(mSearch->search(hash, hintflags, info))
{ {

View File

@ -31,6 +31,7 @@
#include "retroshare/rspeers.h" #include "retroshare/rspeers.h"
const int ftserverzone = 29539; const int ftserverzone = 29539;
#include "file_sharing/p3filelists.h"
#include "ft/ftturtlefiletransferitem.h" #include "ft/ftturtlefiletransferitem.h"
#include "ft/ftserver.h" #include "ft/ftserver.h"
#include "ft/ftextralist.h" #include "ft/ftextralist.h"
@ -64,15 +65,11 @@ static const time_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priorit
/* Setup */ /* Setup */
ftServer::ftServer(p3PeerMgr *pm, p3ServiceControl *sc) ftServer::ftServer(p3PeerMgr *pm, p3ServiceControl *sc)
: p3Service(), : p3Service(),
mPeerMgr(pm), mPeerMgr(pm), mServiceCtrl(sc),
mServiceCtrl(sc), mFileDatabase(NULL),
mCacheStrapper(NULL),
mFiStore(NULL), mFiMon(NULL),
mFtController(NULL), mFtExtra(NULL), mFtController(NULL), mFtExtra(NULL),
mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer") mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer")
{ {
mCacheStrapper = new ftCacheStrapper(sc, getServiceInfo().mServiceType);
addSerialType(new RsFileTransferSerialiser()) ; addSerialType(new RsFileTransferSerialiser()) ;
} }
@ -145,7 +142,7 @@ void ftServer::SetupFtServer()
mFtDataplex = new ftDataMultiplex(ownId, this, mFtSearch); mFtDataplex = new ftDataMultiplex(ownId, this, mFtSearch);
/* make Controller */ /* make Controller */
mFtController = new ftController(mCacheStrapper, mFtDataplex, mServiceCtrl, getServiceInfo().mServiceType); mFtController = new ftController(mFtDataplex, mServiceCtrl, getServiceInfo().mServiceType);
mFtController -> setFtSearchNExtra(mFtSearch, mFtExtra); mFtController -> setFtSearchNExtra(mFtSearch, mFtExtra);
std::string tmppath = "."; std::string tmppath = ".";
mFtController->setPartialsDirectory(tmppath); mFtController->setPartialsDirectory(tmppath);
@ -153,21 +150,13 @@ void ftServer::SetupFtServer()
/* Make Cache Source/Store */ /* Make Cache Source/Store */
mFiStore = new ftFiStore(mCacheStrapper, mFtController, mPeerMgr, ownId, remotecachedir); mFileDatabase = new p3FileDatabase(mServiceCtrl) ;
mFiMon = new ftFiMonitor(mCacheStrapper,localcachedir, ownId,mConfigPath);
/* now add the set to the cachestrapper */
CachePair cp(mFiMon, mFiStore, CacheId(RS_SERVICE_TYPE_FILE_INDEX, 0));
mCacheStrapper -> addCachePair(cp);
/* complete search setup */ /* complete search setup */
mFtSearch->addSearchMode(mCacheStrapper, RS_FILE_HINTS_CACHE);
mFtSearch->addSearchMode(mFtExtra, RS_FILE_HINTS_EXTRA); mFtSearch->addSearchMode(mFtExtra, RS_FILE_HINTS_EXTRA);
mFtSearch->addSearchMode(mFiMon, RS_FILE_HINTS_LOCAL); mFtSearch->addSearchMode(mFileDatabase, RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_REMOTE);
mFtSearch->addSearchMode(mFiStore, RS_FILE_HINTS_REMOTE);
mServiceCtrl->registerServiceMonitor(mFtController, getServiceInfo().mServiceType); mServiceCtrl->registerServiceMonitor(mFtController, getServiceInfo().mServiceType);
mServiceCtrl->registerServiceMonitor(mCacheStrapper, getServiceInfo().mServiceType);
return; return;
} }
@ -193,7 +182,7 @@ void ftServer::StartupThreads()
/* startup Monitor Thread */ /* startup Monitor Thread */
/* startup the FileMonitor (after cache load) */ /* startup the FileMonitor (after cache load) */
/* start it up */ /* start it up */
mFiMon->start("ft monitor"); mFileDatabase->startThreads();
/* Controller thread */ /* Controller thread */
mFtController->start("ft ctrl"); mFtController->start("ft ctrl");
@ -210,9 +199,6 @@ void ftServer::StopThreads()
/* stop Controller thread */ /* stop Controller thread */
mFtController->join(); mFtController->join();
/* stop Monitor Thread */
mFiMon->join();
/* self contained threads */ /* self contained threads */
/* stop ExtraList Thread */ /* stop ExtraList Thread */
mFtExtra->join(); mFtExtra->join();
@ -223,24 +209,15 @@ void ftServer::StopThreads()
delete (mFtController); delete (mFtController);
mFtController = NULL; mFtController = NULL;
delete (mFiMon);
mFiMon = NULL;
delete (mFtExtra); delete (mFtExtra);
mFtExtra = NULL; mFtExtra = NULL;
}
CacheStrapper *ftServer::getCacheStrapper() /* stop Monitor Thread */
{ mFileDatabase->stopThreads();
return mCacheStrapper; delete mFileDatabase;
mFileDatabase = NULL ;
} }
CacheTransfer *ftServer::getCacheTransfer()
{
return mFtController;
}
/***************************************************************/ /***************************************************************/
/********************** RsFiles Interface **********************/ /********************** RsFiles Interface **********************/
/***************************************************************/ /***************************************************************/
@ -256,11 +233,6 @@ bool ftServer::ResumeTransfers()
return true; return true;
} }
bool ftServer::checkHash(const RsFileHash& /*hash*/, std::string& /*error_string*/)
{
return true ;
}
bool ftServer::getFileData(const RsFileHash& hash, uint64_t offset, uint32_t& requested_size,uint8_t *data) bool ftServer::getFileData(const RsFileHash& hash, uint64_t offset, uint32_t& requested_size,uint8_t *data)
{ {
return mFtDataplex->getFileData(hash, offset, requested_size,data); return mFtDataplex->getFileData(hash, offset, requested_size,data);
@ -273,15 +245,7 @@ bool ftServer::alreadyHaveFile(const RsFileHash& hash, FileInfo &info)
bool ftServer::FileRequest(const std::string& fname, const RsFileHash& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<RsPeerId>& srcIds) bool ftServer::FileRequest(const std::string& fname, const RsFileHash& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<RsPeerId>& srcIds)
{ {
std::string error_string ; std::cerr << "Requesting " << fname << std::endl ;
if(!checkHash(hash,error_string))
{
RsServer::notify()->notifyErrorMsg(0,0,"Error handling hash \""+hash.toStdString()+"\". This hash appears to be invalid(Error string=\""+error_string+"\"). This is probably due an bad handling of strings.") ;
return false ;
}
std::cerr << "Requesting " << fname << std::endl ;
if(!mFtController->FileRequest(fname, hash, size, dest, flags, srcIds)) if(!mFtController->FileRequest(fname, hash, size, dest, flags, srcIds))
return false ; return false ;
@ -402,16 +366,18 @@ std::string ftServer::getPartialsDirectory()
return mFtController->getPartialsDirectory(); return mFtController->getPartialsDirectory();
} }
/***************************************************************/
/************************* Other Access ************************/
/***************************************************************/
/***************************************************************/ bool ftServer::copyFile(const std::string& source, const std::string& dest)
/************************* Other Access ************************/ {
/***************************************************************/ return mFtController->copyFile(source, dest);
}
void ftServer::FileDownloads(std::list<RsFileHash> &hashs) void ftServer::FileDownloads(std::list<RsFileHash> &hashs)
{ {
mFtController->FileDownloads(hashs); mFtController->FileDownloads(hashs);
/* this only contains downloads.... not completed */
//return mFtDataplex->FileDownloads(hashs);
} }
bool ftServer::FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& cmap) bool ftServer::FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& cmap)
@ -438,7 +404,7 @@ bool ftServer::FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, Fi
// file, we skip the call to fileDetails() for efficiency reasons. // file, we skip the call to fileDetails() for efficiency reasons.
// //
FileInfo info2 ; FileInfo info2 ;
if( (!(info.transfer_info_flags & RS_FILE_REQ_CACHE)) && mFtController->FileDetails(hash, info2)) if(mFtController->FileDetails(hash, info2))
info.fname = info2.fname ; info.fname = info2.fname ;
return true ; return true ;
@ -539,12 +505,11 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i
return res ; return res ;
} }
/***************************************************************/ /***************************************************************/
/******************* ExtraFileList Access **********************/ /******************* ExtraFileList Access **********************/
/***************************************************************/ /***************************************************************/
bool ftServer::ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t size, bool ftServer::ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t size, uint32_t period, TransferRequestFlags flags)
uint32_t period, TransferRequestFlags flags)
{ {
return mFtExtra->addExtraFile(fname, hash, size, period, flags); return mFtExtra->addExtraFile(fname, hash, size, period, flags);
} }
@ -564,73 +529,27 @@ bool ftServer::ExtraFileStatus(std::string localpath, FileInfo &info)
return mFtExtra->hashExtraFileDone(localpath, info); return mFtExtra->hashExtraFileDone(localpath, info);
} }
bool ftServer::ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, bool ftServer::ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath)
std::string destpath)
{ {
return mFtExtra->moveExtraFile(fname, hash, size, destpath); return mFtExtra->moveExtraFile(fname, hash, size, destpath);
} }
/***************************************************************/
/***************************************************************/ /******************** Directory Listing ************************/
/******************** Directory Listing ************************/ /***************************************************************/
/***************************************************************/
int ftServer::RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details) int ftServer::RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details)
{ {
#ifdef SERVER_DEBUG return mFileDatabase->RequestDirDetails(uid, path, details);
std::cerr << "ftServer::RequestDirDetails(uid:" << uid;
std::cerr << ", path:" << path << ", ...) -> mFiStore";
std::cerr << std::endl;
if (!mFiStore)
{
std::cerr << "mFiStore not SET yet = FAIL";
std::cerr << std::endl;
}
#endif
if(uid == mServiceCtrl->getOwnId())
return mFiMon->RequestDirDetails(path, details);
else
return mFiStore->RequestDirDetails(uid, path, details);
} }
int ftServer::RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) int ftServer::RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags)
{ {
#ifdef SERVER_DEBUG return mFileDatabase->RequestDirDetails(ref,details,flags) ;
std::cerr << "ftServer::RequestDirDetails(ref:" << ref;
std::cerr << ", flags:" << flags << ", ...) -> mFiStore";
std::cerr << std::endl;
if (!mFiStore)
{
std::cerr << "mFiStore not SET yet = FAIL";
std::cerr << std::endl;
}
#endif
if(flags & RS_FILE_HINTS_LOCAL)
return mFiMon->RequestDirDetails(ref, details, flags);
else
return mFiStore->RequestDirDetails(ref, details, flags);
} }
uint32_t ftServer::getType(void *ref, FileSearchFlags flags) uint32_t ftServer::getType(void *ref, FileSearchFlags flags)
{ {
#ifdef SERVER_DEBUG return mFileDatabase->getType(ref) ;
std::cerr << "ftServer::RequestDirDetails(ref:" << ref;
std::cerr << ", flags:" << flags << ", ...) -> mFiStore";
std::cerr << std::endl;
if (!mFiStore)
{
std::cerr << "mFiStore not SET yet = FAIL";
std::cerr << std::endl;
}
#endif
if(flags & RS_FILE_HINTS_LOCAL)
return mFiMon->getType(ref);
else
return mFiStore->getType(ref);
} }
/***************************************************************/ /***************************************************************/
/******************** Search Interface *************************/ /******************** Search Interface *************************/
@ -639,86 +558,55 @@ uint32_t ftServer::getType(void *ref, FileSearchFlags flags)
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags) int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags)
{ {
if(flags & RS_FILE_HINTS_LOCAL) return mFileDatabase->SearchKeywords(keywords, results,flags,RsPeerId());
return mFiMon->SearchKeywords(keywords, results,flags,RsPeerId());
else
return mFiStore->SearchKeywords(keywords, results,flags);
return 0 ;
} }
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id)
{ {
#ifdef SERVER_DEBUG return mFileDatabase->SearchKeywords(keywords, results,flags,peer_id);
std::cerr << "ftServer::SearchKeywords()";
std::cerr << std::endl;
if (!mFiStore)
{
std::cerr << "mFiStore not SET yet = FAIL";
std::cerr << std::endl;
}
#endif
if(flags & RS_FILE_HINTS_LOCAL)
return mFiMon->SearchKeywords(keywords, results,flags,peer_id);
else
return mFiStore->SearchKeywords(keywords, results,flags);
} }
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags) int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags)
{ {
if(flags & RS_FILE_HINTS_LOCAL) return mFileDatabase->SearchBoolExp(exp, results,flags,RsPeerId());
return mFiMon->SearchBoolExp(exp,results,flags,RsPeerId()) ;
else
return mFiStore->searchBoolExp(exp, results);
return 0 ;
} }
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id)
{ {
if(flags & RS_FILE_HINTS_LOCAL) return mFileDatabase->SearchBoolExp(exp,results,flags,peer_id) ;
return mFiMon->SearchBoolExp(exp,results,flags,peer_id) ;
else
return mFiStore->searchBoolExp(exp, results);
} }
/***************************************************************/ /***************************************************************/
/*************** Local Shared Dir Interface ********************/ /*************** Local Shared Dir Interface ********************/
/***************************************************************/ /***************************************************************/
bool ftServer::ConvertSharedFilePath(std::string path, std::string &fullpath) bool ftServer::ConvertSharedFilePath(std::string path, std::string &fullpath)
{ {
return mFiMon->convertSharedFilePath(path, fullpath); return mFileDatabase->convertSharedFilePath(path, fullpath);
} }
void ftServer::updateSinceGroupPermissionsChanged() void ftServer::updateSinceGroupPermissionsChanged()
{ {
mFiMon->forceDirListsRebuildAndSend(); mFileDatabase->forceSyncWithPeers();
} }
void ftServer::ForceDirectoryCheck() void ftServer::ForceDirectoryCheck()
{ {
mFiMon->forceDirectoryCheck(); mFileDatabase->forceDirectoryCheck();
return; return;
} }
bool ftServer::InDirectoryCheck() bool ftServer::InDirectoryCheck()
{ {
return mFiMon->inDirectoryCheck(); return mFileDatabase->inDirectoryCheck();
}
bool ftServer::copyFile(const std::string& source, const std::string& dest)
{
return mFtController->copyFile(source, dest);
} }
bool ftServer::getSharedDirectories(std::list<SharedDirInfo> &dirs) bool ftServer::getSharedDirectories(std::list<SharedDirInfo> &dirs)
{ {
mFiMon->getSharedDirectories(dirs); mFileDatabase->getSharedDirectories(dirs);
return true; return true;
} }
bool ftServer::setSharedDirectories(std::list<SharedDirInfo> &dirs) bool ftServer::setSharedDirectories(std::list<SharedDirInfo> &dirs)
{ {
mFiMon->setSharedDirectories(dirs); mFileDatabase->setSharedDirectories(dirs);
return true; return true;
} }
@ -728,7 +616,7 @@ bool ftServer::addSharedDirectory(const SharedDirInfo& dir)
_dir.filename = RsDirUtil::convertPathToUnix(_dir.filename); _dir.filename = RsDirUtil::convertPathToUnix(_dir.filename);
std::list<SharedDirInfo> dirList; std::list<SharedDirInfo> dirList;
mFiMon->getSharedDirectories(dirList); mFileDatabase->getSharedDirectories(dirList);
// check that the directory is not already in the list. // check that the directory is not already in the list.
for(std::list<SharedDirInfo>::const_iterator it(dirList.begin());it!=dirList.end();++it) for(std::list<SharedDirInfo>::const_iterator it(dirList.begin());it!=dirList.end();++it)
@ -738,13 +626,13 @@ bool ftServer::addSharedDirectory(const SharedDirInfo& dir)
// ok then, add the shared directory. // ok then, add the shared directory.
dirList.push_back(_dir); dirList.push_back(_dir);
mFiMon->setSharedDirectories(dirList); mFileDatabase->setSharedDirectories(dirList);
return true; return true;
} }
bool ftServer::updateShareFlags(const SharedDirInfo& info) bool ftServer::updateShareFlags(const SharedDirInfo& info)
{ {
mFiMon->updateShareFlags(info); mFileDatabase->updateShareFlags(info);
return true ; return true ;
} }
@ -761,7 +649,7 @@ bool ftServer::removeSharedDirectory(std::string dir)
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mFiMon->getSharedDirectories(dirList); mFileDatabase->getSharedDirectories(dirList);
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
for(it = dirList.begin(); it != dirList.end(); ++it) for(it = dirList.begin(); it != dirList.end(); ++it)
@ -776,12 +664,7 @@ bool ftServer::removeSharedDirectory(std::string dir)
if(it == dirList.end()) if(it == dirList.end())
{ {
#ifdef SERVER_DEBUG std::cerr << "(EE) ftServer::removeSharedDirectory(): Cannot Find Directory... Fail" << std::endl;
std::cerr << "ftServer::removeSharedDirectory()";
std::cerr << " Cannot Find Directory... Fail";
std::cerr << std::endl;
#endif
return false; return false;
} }
@ -793,44 +676,44 @@ bool ftServer::removeSharedDirectory(std::string dir)
#endif #endif
dirList.erase(it); dirList.erase(it);
mFiMon->setSharedDirectories(dirList); mFileDatabase->setSharedDirectories(dirList);
return true; return true;
} }
void ftServer::setWatchPeriod(int minutes) void ftServer::setWatchPeriod(int minutes)
{ {
mFiMon->setWatchPeriod(minutes*60) ; mFileDatabase->setWatchPeriod(minutes*60) ;
} }
int ftServer::watchPeriod() const int ftServer::watchPeriod() const
{ {
return mFiMon->watchPeriod()/60 ; return mFileDatabase->watchPeriod()/60 ;
} }
void ftServer::setRememberHashFiles(bool b) void ftServer::setRememberHashFiles(bool b)
{ {
mFiMon->setRememberHashCache(b) ; mFileDatabase->setRememberHashCache(b) ;
} }
bool ftServer::rememberHashFiles() const bool ftServer::rememberHashFiles() const
{ {
return mFiMon->rememberHashCache() ; return mFileDatabase->rememberHashCache() ;
} }
void ftServer::setRememberHashFilesDuration(uint32_t days) void ftServer::setRememberHashFilesDuration(uint32_t days)
{ {
mFiMon->setRememberHashCacheDuration(days) ; mFileDatabase->setRememberHashCacheDuration(days) ;
} }
uint32_t ftServer::rememberHashFilesDuration() const uint32_t ftServer::rememberHashFilesDuration() const
{ {
return mFiMon->rememberHashCacheDuration() ; return mFileDatabase->rememberHashCacheDuration() ;
} }
void ftServer::clearHashCache() void ftServer::clearHashCache()
{ {
mFiMon->clearHashCache() ; mFileDatabase->clearHashCache() ;
} }
bool ftServer::getShareDownloadDirectory() bool ftServer::getShareDownloadDirectory()
{ {
std::list<SharedDirInfo> dirList; std::list<SharedDirInfo> dirList;
mFiMon->getSharedDirectories(dirList); mFileDatabase->getSharedDirectories(dirList);
std::string dir = mFtController->getDownloadDirectory(); std::string dir = mFtController->getDownloadDirectory();
@ -844,7 +727,8 @@ bool ftServer::getShareDownloadDirectory()
bool ftServer::shareDownloadDirectory(bool share) bool ftServer::shareDownloadDirectory(bool share)
{ {
if (share) { if (share)
{
/* Share */ /* Share */
SharedDirInfo inf ; SharedDirInfo inf ;
inf.filename = mFtController->getDownloadDirectory(); inf.filename = mFtController->getDownloadDirectory();
@ -852,48 +736,22 @@ bool ftServer::shareDownloadDirectory(bool share)
return addSharedDirectory(inf); return addSharedDirectory(inf);
} }
else
/* Unshare */ {
std::string dir = mFtController->getDownloadDirectory(); /* Unshare */
return removeSharedDirectory(dir); std::string dir = mFtController->getDownloadDirectory();
return removeSharedDirectory(dir);
}
} }
/***************************************************************/ /***************************************************************/
/****************** End of RsFiles Interface *******************/ /****************** End of RsFiles Interface *******************/
/***************************************************************/ /***************************************************************/
//bool ftServer::loadConfigMap(std::map<std::string, std::string> &/*configMap*/)
/***************************************************************/ //{
/**************** Config Interface *****************************/ // return true;
/***************************************************************/ //}
/* Key Functions to be overloaded for Full Configuration */
RsSerialiser *ftServer::setupSerialiser()
{
RsSerialiser *rss = new RsSerialiser ;
rss->addSerialType(new RsFileTransferSerialiser) ;
//rss->addSerialType(new RsGeneralConfigSerialiser());
return rss ;
}
bool ftServer::saveList(bool &/*cleanup*/, std::list<RsItem *>& /*list*/)
{
return true;
}
bool ftServer::loadList(std::list<RsItem *>& /*load*/)
{
return true;
}
bool ftServer::loadConfigMap(std::map<std::string, std::string> &/*configMap*/)
{
return true;
}
/***************************************************************/ /***************************************************************/
/********************** Data Flow **********************/ /********************** Data Flow **********************/
@ -1257,9 +1115,6 @@ int ftServer::tick()
if(handleIncoming()) if(handleIncoming())
moreToTick = true; moreToTick = true;
if(handleCacheData())
moreToTick = true;
static time_t last_law_priority_tasks_handling_time = 0 ; static time_t last_law_priority_tasks_handling_time = 0 ;
time_t now = time(NULL) ; time_t now = time(NULL) ;
@ -1275,45 +1130,6 @@ int ftServer::tick()
return moreToTick; return moreToTick;
} }
bool ftServer::handleCacheData()
{
std::list<std::pair<RsPeerId, RsCacheData> > cacheUpdates;
std::list<std::pair<RsPeerId, RsCacheData> >::iterator it;
int i=0 ;
#ifdef SERVER_DEBUG_CACHE
std::cerr << "handleCacheData() " << std::endl;
#endif
mCacheStrapper->getCacheUpdates(cacheUpdates);
for(it = cacheUpdates.begin(); it != cacheUpdates.end(); ++it)
{
/* construct reply */
RsFileTransferCacheItem *ci = new RsFileTransferCacheItem();
/* id from incoming */
ci -> PeerId(it->first);
ci -> file.hash = (it->second).hash;
ci -> file.name = (it->second).name;
ci -> file.path = ""; // (it->second).path;
ci -> file.filesize = (it->second).size;
ci -> cacheType = (it->second).cid.type;
ci -> cacheSubId = (it->second).cid.subid;
#ifdef SERVER_DEBUG_CACHE
std::string out2 = "Outgoing CacheStrapper Update -> RsCacheItem:\n";
ci -> print_string(out2);
std::cerr << out2 << std::endl;
#endif
sendItem(ci);
i++;
}
return i>0 ;
}
int ftServer::handleIncoming() int ftServer::handleIncoming()
{ {
// now File Input. // now File Input.
@ -1411,42 +1227,6 @@ int ftServer::handleIncoming()
} }
} }
break ; break ;
case RS_PKT_SUBTYPE_FT_CACHE_ITEM:
{
RsFileTransferCacheItem *ci = dynamic_cast<RsFileTransferCacheItem*>(item) ;
if (ci)
{
#ifdef SERVER_DEBUG_CACHE
std::cerr << "ftServer::handleIncoming: received cache item hash=" << ci->file.hash << ". from peer " << ci->PeerId() << std::endl;
#endif
/* these go to the CacheStrapper! */
RsCacheData data;
data.pid = ci->PeerId();
data.cid = CacheId(ci->cacheType, ci->cacheSubId);
data.path = ci->file.path;
data.name = ci->file.name;
data.hash = ci->file.hash;
data.size = ci->file.filesize;
data.recvd = time(NULL) ;
mCacheStrapper->recvCacheResponse(data, time(NULL));
}
}
break ;
// case RS_PKT_SUBTYPE_FT_CACHE_REQUEST:
// {
// // do nothing
// RsFileTransferCacheRequestItem *cr = dynamic_cast<RsFileTransferCacheRequestItem*>(item) ;
// if (cr)
// {
//#ifdef SERVER_DEBUG_CACHE
// std::cerr << "ftServer::handleIncoming: received cache request from peer " << cr->PeerId() << std::endl;
//#endif
// }
// }
// break ;
} }
delete item ; delete item ;
@ -1465,7 +1245,7 @@ int ftServer::handleIncoming()
bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr) bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr)
{ {
/* add all the subbits to config mgr */ /* add all the subbits to config mgr */
cfgmgr->addConfiguration("ft_shared.cfg", mFiMon); cfgmgr->addConfiguration("ft_database.cfg", mFileDatabase);
cfgmgr->addConfiguration("ft_extra.cfg", mFtExtra); cfgmgr->addConfiguration("ft_extra.cfg", mFtExtra);
cfgmgr->addConfiguration("ft_transfers.cfg", mFtController); cfgmgr->addConfiguration("ft_transfers.cfg", mFtController);

View File

@ -70,230 +70,203 @@ class p3turtle;
class p3PeerMgr; class p3PeerMgr;
class p3ServiceControl; class p3ServiceControl;
class p3FileDatabase;
class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTurtleClientService class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTurtleClientService
{ {
public: public:
/***************************************************************/ /***************************************************************/
/******************** Setup ************************************/ /******************** Setup ************************************/
/***************************************************************/ /***************************************************************/
ftServer(p3PeerMgr *peerMgr, p3ServiceControl *serviceCtrl); ftServer(p3PeerMgr *peerMgr, p3ServiceControl *serviceCtrl);
virtual RsServiceInfo getServiceInfo(); virtual RsServiceInfo getServiceInfo();
/* Assign important variables */ /* Assign important variables */
void setConfigDirectory(std::string path); void setConfigDirectory(std::string path);
/* add Config Items (Extra, Controller) */ /* add Config Items (Extra, Controller) */
void addConfigComponents(p3ConfigMgr *mgr); void addConfigComponents(p3ConfigMgr *mgr);
virtual CacheStrapper *getCacheStrapper(); const RsPeerId& OwnId();
virtual CacheTransfer *getCacheTransfer();
const RsPeerId& OwnId(); /* Final Setup (once everything is assigned) */
void SetupFtServer() ;
virtual void connectToTurtleRouter(p3turtle *p) ;
/* Final Setup (once everything is assigned) */ // Implements RsTurtleClientService
void SetupFtServer() ; //
virtual void connectToTurtleRouter(p3turtle *p) ; virtual bool handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_id) ;
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const RsFileHash& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
virtual RsTurtleGenericTunnelItem *deserialiseItem(void *data,uint32_t size) const ;
// Checks that the given hash is well formed. Used to chase void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ;
// string bugs. void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) ;
static bool checkHash(const RsFileHash& hash,std::string& error_string) ;
// Implements RsTurtleClientService /***************************************************************/
// /*************** Control Interface *****************************/
virtual bool handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_id) ; /************** (Implements RsFiles) ***************************/
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const RsFileHash& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ; /***************************************************************/
virtual RsTurtleGenericTunnelItem *deserialiseItem(void *data,uint32_t size) const ;
void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ; void StartupThreads();
void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) ; void StopThreads();
/***************************************************************/ // member access
/*************** Control Interface *****************************/
/************** (Implements RsFiles) ***************************/
/***************************************************************/
void StartupThreads(); ftDataMultiplex *getMultiplexer() const { return mFtDataplex ; }
void StopThreads(); ftController *getController() const { return mFtController ; }
// member access /**
ftDataMultiplex *getMultiplexer() const { return mFtDataplex ; }
ftController *getController() const { return mFtController ; }
/**
* @see RsFiles::getFileData * @see RsFiles::getFileData
*/ */
bool getFileData(const RsFileHash& hash, uint64_t offset, uint32_t& requested_size,uint8_t *data); bool getFileData(const RsFileHash& hash, uint64_t offset, uint32_t& requested_size,uint8_t *data);
/*** /***
* Control of Downloads * Control of Downloads
***/ ***/
virtual bool alreadyHaveFile(const RsFileHash& hash, FileInfo &info); virtual bool alreadyHaveFile(const RsFileHash& hash, FileInfo &info);
virtual bool FileRequest(const std::string& fname, const RsFileHash& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<RsPeerId>& srcIds); virtual bool FileRequest(const std::string& fname, const RsFileHash& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<RsPeerId>& srcIds);
virtual bool FileCancel(const RsFileHash& hash); virtual bool FileCancel(const RsFileHash& hash);
virtual bool FileControl(const RsFileHash& hash, uint32_t flags); virtual bool FileControl(const RsFileHash& hash, uint32_t flags);
virtual bool FileClearCompleted(); virtual bool FileClearCompleted();
virtual bool setDestinationDirectory(const RsFileHash& hash,const std::string& new_path) ; virtual bool setDestinationDirectory(const RsFileHash& hash,const std::string& new_path) ;
virtual bool setDestinationName(const RsFileHash& hash,const std::string& new_name) ; virtual bool setDestinationName(const RsFileHash& hash,const std::string& new_name) ;
virtual bool setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s) ; virtual bool setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s) ;
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) ; virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) ;
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ; virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ;
virtual uint32_t freeDiskSpaceLimit() const ; virtual uint32_t freeDiskSpaceLimit() const ;
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) ; virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
/*** /***
* Control of Downloads Priority. * Control of Downloads Priority.
***/ ***/
virtual uint32_t getMinPrioritizedTransfers() ; virtual uint32_t getMinPrioritizedTransfers() ;
virtual void setMinPrioritizedTransfers(uint32_t s) ; virtual void setMinPrioritizedTransfers(uint32_t s) ;
virtual uint32_t getQueueSize() ; virtual uint32_t getQueueSize() ;
virtual void setQueueSize(uint32_t s) ; virtual void setQueueSize(uint32_t s) ;
virtual bool changeQueuePosition(const RsFileHash& hash, QueueMove queue_mv); virtual bool changeQueuePosition(const RsFileHash& hash, QueueMove queue_mv);
virtual bool changeDownloadSpeed(const RsFileHash& hash, int speed); virtual bool changeDownloadSpeed(const RsFileHash& hash, int speed);
virtual bool getDownloadSpeed(const RsFileHash& hash, int & speed); virtual bool getDownloadSpeed(const RsFileHash& hash, int & speed);
virtual bool clearDownload(const RsFileHash& hash); virtual bool clearDownload(const RsFileHash& hash);
//virtual void getDwlDetails(std::list<DwlDetails> & details); //virtual void getDwlDetails(std::list<DwlDetails> & details);
/*** /***
* Download/Upload Details * Download/Upload Details
***/ ***/
virtual void FileDownloads(std::list<RsFileHash> &hashs); virtual void FileDownloads(std::list<RsFileHash> &hashs);
virtual bool FileUploads(std::list<RsFileHash> &hashs); virtual bool FileUploads(std::list<RsFileHash> &hashs);
virtual bool FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info); virtual bool FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info);
virtual bool FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info) ; virtual bool FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info) ;
virtual bool FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& map) ; virtual bool FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& map) ;
/*** /***
* Extra List Access * Extra List Access
***/ ***/
virtual bool ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t size, uint32_t period, TransferRequestFlags flags); virtual bool ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t size, uint32_t period, TransferRequestFlags flags);
virtual bool ExtraFileRemove(const RsFileHash& hash, TransferRequestFlags flags); virtual bool ExtraFileRemove(const RsFileHash& hash, TransferRequestFlags flags);
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags); virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags);
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info); virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
virtual bool ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath); virtual bool ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath);
/*** /***
* Directory Listing / Search Interface * Directory Listing / Search Interface
***/ ***/
virtual int RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details); virtual int RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details);
virtual int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags); virtual int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags);
virtual uint32_t getType(void *ref,FileSearchFlags flags) ; virtual uint32_t getType(void *ref,FileSearchFlags flags) ;
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags); virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags);
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id); virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id);
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags); virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags);
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id); virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id);
/*** /***
* Utility Functions * Utility Functions
***/ ***/
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath); virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath);
virtual void ForceDirectoryCheck(); virtual void ForceDirectoryCheck();
virtual void updateSinceGroupPermissionsChanged() ; virtual void updateSinceGroupPermissionsChanged() ;
virtual bool InDirectoryCheck(); virtual bool InDirectoryCheck();
virtual bool copyFile(const std::string& source, const std::string& dest); virtual bool copyFile(const std::string& source, const std::string& dest);
/*** /***
* Directory Handling * Directory Handling
***/ ***/
virtual void setDownloadDirectory(std::string path); virtual void setDownloadDirectory(std::string path);
virtual void setPartialsDirectory(std::string path); virtual void setPartialsDirectory(std::string path);
virtual std::string getDownloadDirectory(); virtual std::string getDownloadDirectory();
virtual std::string getPartialsDirectory(); virtual std::string getPartialsDirectory();
virtual bool getSharedDirectories(std::list<SharedDirInfo> &dirs); virtual bool getSharedDirectories(std::list<SharedDirInfo> &dirs);
virtual bool setSharedDirectories(std::list<SharedDirInfo> &dirs); virtual bool setSharedDirectories(std::list<SharedDirInfo> &dirs);
virtual bool addSharedDirectory(const SharedDirInfo& dir); virtual bool addSharedDirectory(const SharedDirInfo& dir);
virtual bool updateShareFlags(const SharedDirInfo& dir); // updates the flags. The directory should already exist ! virtual bool updateShareFlags(const SharedDirInfo& dir); // updates the flags. The directory should already exist !
virtual bool removeSharedDirectory(std::string dir); virtual bool removeSharedDirectory(std::string dir);
virtual bool getShareDownloadDirectory(); virtual bool getShareDownloadDirectory();
virtual bool shareDownloadDirectory(bool share); virtual bool shareDownloadDirectory(bool share);
virtual void setRememberHashFilesDuration(uint32_t days) ; virtual void setRememberHashFilesDuration(uint32_t days) ;
virtual uint32_t rememberHashFilesDuration() const ; virtual uint32_t rememberHashFilesDuration() const ;
virtual bool rememberHashFiles() const ; virtual bool rememberHashFiles() const ;
virtual void setRememberHashFiles(bool) ; virtual void setRememberHashFiles(bool) ;
virtual void clearHashCache() ; virtual void clearHashCache() ;
virtual void setWatchPeriod(int minutes) ; virtual void setWatchPeriod(int minutes) ;
virtual int watchPeriod() const ; virtual int watchPeriod() const ;
/***************************************************************/ /***************************************************************/
/*************** Control Interface *****************************/ /*************** Data Transfer Interface ***********************/
/***************************************************************/ /***************************************************************/
public:
virtual bool sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
virtual bool sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
virtual bool sendChunkMapRequest(const RsPeerId& peer_id,const RsFileHash& hash,bool is_client) ;
virtual bool sendChunkMap(const RsPeerId& peer_id,const RsFileHash& hash,const CompressedChunkMap& cmap,bool is_client) ;
virtual bool sendSingleChunkCRCRequest(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number) ;
virtual bool sendSingleChunkCRC(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ;
/***************************************************************/ /*************** Internal Transfer Fns *************************/
/*************** Data Transfer Interface ***********************/ virtual int tick();
/***************************************************************/
public:
virtual bool sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
virtual bool sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
virtual bool sendChunkMapRequest(const RsPeerId& peer_id,const RsFileHash& hash,bool is_client) ;
virtual bool sendChunkMap(const RsPeerId& peer_id,const RsFileHash& hash,const CompressedChunkMap& cmap,bool is_client) ;
virtual bool sendSingleChunkCRCRequest(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number) ;
virtual bool sendSingleChunkCRC(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ;
/*************** Internal Transfer Fns *************************/ /* Configuration */
virtual int tick(); bool addConfiguration(p3ConfigMgr *cfgmgr);
bool ResumeTransfers();
/* Configuration */ /*************************** p3 Config Overload ********************/
bool addConfiguration(p3ConfigMgr *cfgmgr);
bool ResumeTransfers();
/******************* p3 Config Overload ************************/ protected:
protected: int handleIncoming() ;
/* Key Functions to be overloaded for Full Configuration */ bool handleCacheData() ;
virtual RsSerialiser *setupSerialiser();
virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
virtual bool loadList(std::list<RsItem *>& load);
private: private:
bool loadConfigMap(std::map<std::string, std::string> &configMap);
/******************* p3 Config Overload ************************/
/*************************** p3 Config Overload ********************/ /**** INTERNAL FUNCTIONS ***/
//virtual int reScanDirs();
//virtual int check_dBUpdate();
protected: private:
int handleIncoming() ;
bool handleCacheData() ;
private: /* no need for Mutex protection -
* as each component is protected independently.
*/
p3PeerMgr *mPeerMgr;
p3ServiceControl *mServiceCtrl;
p3FileDatabase *mFileDatabase ;
ftController *mFtController;
ftExtraList *mFtExtra;
ftDataMultiplex *mFtDataplex;
p3turtle *mTurtleRouter ;
ftFileSearch *mFtSearch;
/**** INTERNAL FUNCTIONS ***/ RsMutex srvMutex;
//virtual int reScanDirs(); std::string mConfigPath;
//virtual int check_dBUpdate(); std::string mDownloadPath;
std::string mPartialsPath;
private:
/* no need for Mutex protection -
* as each component is protected independently.
*/
p3PeerMgr *mPeerMgr;
p3ServiceControl *mServiceCtrl;
ftCacheStrapper *mCacheStrapper;
ftFiStore *mFiStore;
ftFiMonitor *mFiMon;
ftController *mFtController;
ftExtraList *mFtExtra;
ftDataMultiplex *mFtDataplex;
p3turtle *mTurtleRouter ;
ftFileSearch *mFtSearch;
RsMutex srvMutex;
std::string mConfigPath;
std::string mDownloadPath;
std::string mPartialsPath;
}; };

View File

@ -410,12 +410,13 @@ void RsPluginManager::slowTickPlugins(time_t seconds)
void RsPluginManager::registerCacheServices() void RsPluginManager::registerCacheServices()
{ {
#warning this code should go
std::cerr << " Registering cache services." << std::endl; std::cerr << " Registering cache services." << std::endl;
for(uint32_t i=0;i<_plugins.size();++i) for(uint32_t i=0;i<_plugins.size();++i)
if(_plugins[i].plugin != NULL && _plugins[i].plugin->rs_cache_service() != NULL) if(_plugins[i].plugin != NULL && _plugins[i].plugin->rs_cache_service() != NULL)
{ {
rsFiles->getCacheStrapper()->addCachePair(CachePair(_plugins[i].plugin->rs_cache_service(),_plugins[i].plugin->rs_cache_service(),CacheId(_plugins[i].plugin->rs_service_id(), 0))) ; //rsFiles->getCacheStrapper()->addCachePair(CachePair(_plugins[i].plugin->rs_cache_service(),_plugins[i].plugin->rs_cache_service(),CacheId(_plugins[i].plugin->rs_service_id(), 0))) ;
std::cerr << " adding new cache pair for plugin " << _plugins[i].plugin->getPluginName() << ", with RS_ID " << _plugins[i].plugin->rs_service_id() << std::endl ; std::cerr << " adding new cache pair for plugin " << _plugins[i].plugin->getPluginName() << ", with RS_ID " << _plugins[i].plugin->rs_service_id() << std::endl ;
} }
} }

View File

@ -65,26 +65,26 @@ const uint32_t RS_FILE_PEER_OFFLINE = 0x00002000;
// Flags used when requesting info about transfers, mostly to filter out the result. // Flags used when requesting info about transfers, mostly to filter out the result.
// //
const FileSearchFlags RS_FILE_HINTS_CACHE ( 0x00000001 ); const FileSearchFlags RS_FILE_HINTS_CACHE_deprecated ( 0x00000001 );
const FileSearchFlags RS_FILE_HINTS_EXTRA ( 0x00000002 ); const FileSearchFlags RS_FILE_HINTS_EXTRA ( 0x00000002 );
const FileSearchFlags RS_FILE_HINTS_LOCAL ( 0x00000004 ); const FileSearchFlags RS_FILE_HINTS_LOCAL ( 0x00000004 );
const FileSearchFlags RS_FILE_HINTS_REMOTE ( 0x00000008 ); const FileSearchFlags RS_FILE_HINTS_REMOTE ( 0x00000008 );
const FileSearchFlags RS_FILE_HINTS_DOWNLOAD ( 0x00000010 ); const FileSearchFlags RS_FILE_HINTS_DOWNLOAD ( 0x00000010 );
const FileSearchFlags RS_FILE_HINTS_UPLOAD ( 0x00000020 ); const FileSearchFlags RS_FILE_HINTS_UPLOAD ( 0x00000020 );
const FileSearchFlags RS_FILE_HINTS_SPEC_ONLY ( 0x01000000 ); const FileSearchFlags RS_FILE_HINTS_SPEC_ONLY ( 0x01000000 );
const FileSearchFlags RS_FILE_HINTS_NETWORK_WIDE ( 0x00000080 );// anonymously shared over network const FileSearchFlags RS_FILE_HINTS_NETWORK_WIDE ( 0x00000080 );// anonymously shared over network
const FileSearchFlags RS_FILE_HINTS_BROWSABLE ( 0x00000100 );// browsable by friends const FileSearchFlags RS_FILE_HINTS_BROWSABLE ( 0x00000100 );// browsable by friends
const FileSearchFlags RS_FILE_HINTS_PERMISSION_MASK ( 0x00000180 );// OR of the last two flags. Used to filter out. const FileSearchFlags RS_FILE_HINTS_PERMISSION_MASK ( 0x00000180 );// OR of the last two flags. Used to filter out.
// Flags used when requesting a transfer // Flags used when requesting a transfer
// //
const TransferRequestFlags RS_FILE_REQ_ANONYMOUS_ROUTING ( 0x00000040 ); // Use to ask turtle router to download the file. const TransferRequestFlags RS_FILE_REQ_ANONYMOUS_ROUTING ( 0x00000040 ); // Use to ask turtle router to download the file.
const TransferRequestFlags RS_FILE_REQ_ASSUME_AVAILABILITY ( 0x00000200 ); // Assume full source availability. Used for cache files. const TransferRequestFlags RS_FILE_REQ_ASSUME_AVAILABILITY ( 0x00000200 ); // Assume full source availability. Used for cache files.
const TransferRequestFlags RS_FILE_REQ_CACHE ( 0x00000400 ); // Assume full source availability. Used for cache files. const TransferRequestFlags RS_FILE_REQ_CACHE_deprecated ( 0x00000400 ); // Assume full source availability. Used for cache files.
const TransferRequestFlags RS_FILE_REQ_EXTRA ( 0x00000800 ); const TransferRequestFlags RS_FILE_REQ_EXTRA ( 0x00000800 );
const TransferRequestFlags RS_FILE_REQ_MEDIA ( 0x00001000 ); const TransferRequestFlags RS_FILE_REQ_MEDIA ( 0x00001000 );
const TransferRequestFlags RS_FILE_REQ_BACKGROUND ( 0x00002000 ); // To download slowly. const TransferRequestFlags RS_FILE_REQ_BACKGROUND ( 0x00002000 ); // To download slowly.
const TransferRequestFlags RS_FILE_REQ_NO_SEARCH ( 0x02000000 ); // disable searching for potential direct sources. const TransferRequestFlags RS_FILE_REQ_NO_SEARCH ( 0x02000000 ); // disable searching for potential direct sources.
// const uint32_t RS_FILE_HINTS_SHARE_FLAGS_MASK = RS_FILE_HINTS_NETWORK_WIDE_OTHERS | RS_FILE_HINTS_BROWSABLE_OTHERS // const uint32_t RS_FILE_HINTS_SHARE_FLAGS_MASK = RS_FILE_HINTS_NETWORK_WIDE_OTHERS | RS_FILE_HINTS_BROWSABLE_OTHERS
@ -222,9 +222,6 @@ class RsFiles
virtual void setWatchPeriod(int minutes) =0; virtual void setWatchPeriod(int minutes) =0;
virtual int watchPeriod() const =0; virtual int watchPeriod() const =0;
virtual CacheStrapper *getCacheStrapper() =0;
virtual CacheTransfer *getCacheTransfer() =0;
virtual bool getShareDownloadDirectory() = 0; virtual bool getShareDownloadDirectory() = 0;
virtual bool shareDownloadDirectory(bool share) = 0; virtual bool shareDownloadDirectory(bool share) = 0;

View File

@ -1228,8 +1228,6 @@ int RsServer::StartupRetroShare()
ftserver->setConfigDirectory(rsAccounts->PathAccountDirectory()); ftserver->setConfigDirectory(rsAccounts->PathAccountDirectory());
ftserver->SetupFtServer() ; ftserver->SetupFtServer() ;
CacheStrapper *mCacheStrapper = ftserver->getCacheStrapper();
//CacheTransfer *mCacheTransfer = ftserver->getCacheTransfer();
/* setup any extra bits (Default Paths) */ /* setup any extra bits (Default Paths) */
ftserver->setPartialsDirectory(emergencyPartialsDir); ftserver->setPartialsDirectory(emergencyPartialsDir);
@ -1273,7 +1271,6 @@ int RsServer::StartupRetroShare()
// These are needed to load plugins: plugin devs might want to know the place of // These are needed to load plugins: plugin devs might want to know the place of
// cache directories, get pointers to cache strapper, or access ownId() // cache directories, get pointers to cache strapper, or access ownId()
// //
mPluginsManager->setCacheDirectories(localcachedir,remotecachedir) ;
mPluginsManager->setServiceControl(serviceCtrl) ; mPluginsManager->setServiceControl(serviceCtrl) ;
// std::cerr << "rsinitconf (core 1) = " << (void*)rsInitConfig<<std::endl; // std::cerr << "rsinitconf (core 1) = " << (void*)rsInitConfig<<std::endl;
@ -1604,10 +1601,6 @@ int RsServer::StartupRetroShare()
mLinkMgr->addMonitor(serviceCtrl); mLinkMgr->addMonitor(serviceCtrl);
mLinkMgr->addMonitor(serviceInfo); mLinkMgr->addMonitor(serviceInfo);
// NOTE these were added in ftServer (was added twice).
//mLinkMgr->addMonitor(mCacheStrapper);
//mLinkMgr->addMonitor(((ftController *) mCacheTransfer));
// Services that have been changed to pqiServiceMonitor // Services that have been changed to pqiServiceMonitor
serviceCtrl->registerServiceMonitor(msgSrv, msgSrv->getServiceInfo().mServiceType); serviceCtrl->registerServiceMonitor(msgSrv, msgSrv->getServiceInfo().mServiceType);
serviceCtrl->registerServiceMonitor(mDisc, mDisc->getServiceInfo().mServiceType); serviceCtrl->registerServiceMonitor(mDisc, mDisc->getServiceInfo().mServiceType);
@ -1668,7 +1661,6 @@ int RsServer::StartupRetroShare()
* after all the other configurations have happened. * after all the other configurations have happened.
*/ */
mConfigMgr->addConfiguration("cache.cfg", mCacheStrapper);
mConfigMgr->loadConfiguration(); mConfigMgr->loadConfiguration();
/**************************************************************************/ /**************************************************************************/

View File

@ -49,6 +49,7 @@ const uint16_t RS_SERVICE_TYPE_TUNNEL = 0x0015;
const uint16_t RS_SERVICE_TYPE_HEARTBEAT = 0x0016; const uint16_t RS_SERVICE_TYPE_HEARTBEAT = 0x0016;
const uint16_t RS_SERVICE_TYPE_FILE_TRANSFER = 0x0017; const uint16_t RS_SERVICE_TYPE_FILE_TRANSFER = 0x0017;
const uint16_t RS_SERVICE_TYPE_GROUTER = 0x0018; const uint16_t RS_SERVICE_TYPE_GROUTER = 0x0018;
const uint16_t RS_SERVICE_TYPE_FILE_DATABASE = 0x0019;
const uint16_t RS_SERVICE_TYPE_SERVICEINFO = 0x0020; const uint16_t RS_SERVICE_TYPE_SERVICEINFO = 0x0020;
/* Bandwidth Control */ /* Bandwidth Control */

View File

@ -1269,13 +1269,6 @@ void TransfersDialog::insertTransfers()
continue; continue;
} }
if ((fileInfo.transfer_info_flags & RS_FILE_REQ_CACHE) && !_show_cache_transfers) {
// if file transfer is a cache file index file, don't show it
DLListModel->removeRow(row);
rowCount = DLListModel->rowCount();
continue;
}
hashs.erase(hashIt); hashs.erase(hashIt);
if (addItem(row, fileInfo) < 0) { if (addItem(row, fileInfo) < 0) {
@ -1295,11 +1288,6 @@ void TransfersDialog::insertTransfers()
continue; continue;
} }
if ((fileInfo.transfer_info_flags & RS_FILE_REQ_CACHE) && !_show_cache_transfers) {
//if file transfer is a cache file index file, don't show it
continue;
}
addItem(-1, fileInfo); addItem(-1, fileInfo);
} }
@ -1322,9 +1310,6 @@ void TransfersDialog::insertTransfers()
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_UPLOAD, info)) if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_UPLOAD, info))
continue; continue;
if((info.transfer_info_flags & RS_FILE_REQ_CACHE) && _show_cache_transfers)
continue ;
std::list<TransferInfo>::iterator pit; std::list<TransferInfo>::iterator pit;
for(pit = info.peers.begin(); pit != info.peers.end(); ++pit) for(pit = info.peers.begin(); pit != info.peers.end(); ++pit)
{ {