removed unused server directory

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1887 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2009-12-15 16:05:24 +00:00
parent 2b52db6c47
commit 263456d54c
12 changed files with 0 additions and 5241 deletions

View File

@ -1,24 +0,0 @@
RS_TOP_DIR = ..
##### Define any flags that are needed for this section #######
###############################################################
###############################################################
include $(RS_TOP_DIR)/scripts/config.mk
###############################################################
RSOBJ = ft.o ftfiler.o hashsearch.o filedexserver.o
TESTOBJ = #ftcachetest.o
TESTS = #ftcachetest
all: librs tests
ftcachetest : ftcachetest.o $(OBJ)
$(CC) $(CFLAGS) -o ftcachetest ftcachetest.o $(OBJ) $(LIBS)
###############################################################
include $(RS_TOP_DIR)/scripts/rules.mk
###############################################################

View File

@ -1,876 +0,0 @@
/*
* "$Id: filedexserver.cc,v 1.24 2007-05-05 16:10:06 rmf24 Exp $"
*
* Other Bits for RetroShare.
*
* Copyright 2004-2006 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 "server/filedexserver.h"
#include <fstream>
#include <time.h>
#include "pqi/pqibin.h"
#include "pqi/pqiarchive.h"
#include "util/rsdebug.h"
#include "util/rsdir.h"
#include <sstream>
#include <iomanip>
/* New FileCache Stuff */
#include "server/ftfiler.h"
#include "dbase/cachestrapper.h"
#include "dbase/fimonitor.h"
#include "dbase/fistore.h"
#include "pqi/p3connmgr.h"
#include "pqi/p3authmgr.h"
#include "serialiser/rsserviceids.h"
#include "serialiser/rsconfigitems.h"
#include <sstream>
const int fldxsrvrzone = 47659;
/****
#define SERVER_DEBUG 1
#define DEBUG_TICK 1
****/
filedexserver::filedexserver()
:p3Config(CONFIG_TYPE_FSERVER),
pqisi(NULL), mAuthMgr(NULL), mConnMgr(NULL),
save_dir("."),
mCacheStrapper(NULL), ftFiler(NULL), fiStore(NULL), fimon(NULL)
{
initialiseFileStore();
}
int filedexserver::setSearchInterface(P3Interface *si, p3AuthMgr *am, p3ConnectMgr *cm)
{
pqisi = si;
mAuthMgr = am;
mConnMgr = cm;
return 1;
}
std::list<RsFileTransfer *> filedexserver::getTransfers()
{
return ftFiler->getStatus();
}
int filedexserver::tick()
{
pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone,
"filedexserver::tick()");
/* the new Cache Hack() */
FileStoreTick();
if (pqisi == NULL)
{
std::ostringstream out;
pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone,
"filedexserver::tick() Invalid Interface()");
return 1;
}
int moreToTick = 0;
if (0 < pqisi -> tick())
{
moreToTick = 1;
#ifdef DEBUG_TICK
std::cerr << "filedexserver::tick() moreToTick from pqisi" << std::endl;
#endif
}
if (0 < handleInputQueues())
{
moreToTick = 1;
#ifdef DEBUG_TICK
std::cerr << "filedexserver::tick() moreToTick from InputQueues" << std::endl;
#endif
}
if (0 < handleOutputQueues())
{
moreToTick = 1;
#ifdef DEBUG_TICK
std::cerr << "filedexserver::tick() moreToTick from OutputQueues" << std::endl;
#endif
}
return moreToTick;
}
int filedexserver::status()
{
pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone,
"filedexserver::status()");
if (pqisi == NULL)
{
pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone,
"filedexserver::status() Invalid Interface()");
return 1;
}
pqisi -> status();
return 1;
}
std::string filedexserver::getSaveDir()
{
return save_dir;
}
void filedexserver::setSaveDir(std::string d)
{
save_dir = d;
if (ftFiler)
ftFiler -> setSaveBasePath(save_dir);
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
}
void filedexserver::setEmergencySaveDir(std::string s)
{
if (ftFiler)
{
ftFiler -> setEmergencyBasePath(s);
}
}
bool filedexserver::getSaveIncSearch()
{
return save_inc;
}
void filedexserver::setSaveIncSearch(bool v)
{
save_inc = v;
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
}
int filedexserver::addSearchDirectory(std::string dir)
{
dbase_dirs.push_back(dir);
reScanDirs();
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return 1;
}
int filedexserver::removeSearchDirectory(std::string dir)
{
std::list<std::string>::iterator it;
for(it = dbase_dirs.begin(); (it != dbase_dirs.end())
&& (dir != *it); it++);
if (it != dbase_dirs.end())
{
dbase_dirs.erase(it);
}
reScanDirs();
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return 1;
}
std::list<std::string> &filedexserver::getSearchDirectories()
{
return dbase_dirs;
}
int filedexserver::reScanDirs()
{
if (fimon)
fimon->setSharedDirectories(dbase_dirs);
return 1;
}
bool filedexserver::ConvertSharedFilePath(std::string path, std::string &fullpath)
{
if (fimon)
return fimon->convertSharedFilePath(path, fullpath);
return false;
}
void filedexserver::ForceDirectoryCheck()
{
if (fimon)
fimon->forceDirectoryCheck();
return;
}
bool filedexserver::InDirectoryCheck()
{
if (fimon)
return fimon->inDirectoryCheck();
return false;
}
/*************************************** NEW File Cache Stuff ****************************/
void filedexserver::initialiseFileStore()
{
}
const std::string LOCAL_CACHE_FILE_KEY = "LCF_NAME";
const std::string LOCAL_CACHE_HASH_KEY = "LCF_HASH";
const std::string LOCAL_CACHE_SIZE_KEY = "LCF_SIZE";
void filedexserver::setFileCallback(std::string ownId, CacheStrapper *strapper, ftfiler *ft, NotifyBase *cb)
{
mCacheStrapper = strapper;
ftFiler = ft;
/* setup FiStore/Monitor */
std::string localcachedir = config_dir + "/cache/local";
std::string remotecachedir = config_dir + "/cache/remote";
fiStore = new FileIndexStore(strapper, ftFiler, cb, ownId, remotecachedir);
/* now setup the FiMon */
fimon = new FileIndexMonitor(strapper, localcachedir, ownId);
/* setup ftFiler
* to find peer info / savedir
*/
FileHashSearch *fhs = new FileHashSearch(fiStore, fimon);
ftFiler -> setFileHashSearch(fhs);
ftFiler -> setSaveBasePath(save_dir);
/* now add the set to the cachestrapper */
CachePair cp(fimon, fiStore, CacheId(RS_SERVICE_TYPE_FILE_INDEX, 0));
mCacheStrapper -> addCachePair(cp);
return;
}
void filedexserver::StartupMonitor()
{
/* startup the FileMonitor (after cache load) */
fimon->setPeriod(600); /* 10 minutes */
/* start it up */
fimon->setSharedDirectories(dbase_dirs);
fimon->start();
std::list<RsFileTransfer *>::iterator tit;
for(tit = mResumeTransferList.begin();
tit != mResumeTransferList.end(); tit++)
{
RsFileTransfer *rsft = (*tit);
/* only add in ones which have a hash (filters old versions) */
if (rsft->file.hash != "")
{
ftFiler -> getFile(
rsft->file.name,
rsft->file.hash,
rsft->file.filesize, "");
}
delete rsft;
}
mResumeTransferList.clear();
}
int filedexserver::FileCacheSave()
{
/************ TMP HACK SAVE until new serialiser is finished */
RsPeerId pid;
std::map<CacheId, CacheData> ids;
std::map<CacheId, CacheData>::iterator it;
#ifdef SERVER_DEBUG
std::cerr << "filedexserver::FileCacheSave() listCaches:" << std::endl;
fimon->listCaches(std::cerr);
fimon->cachesAvailable(pid, ids);
#endif
std::string localCacheFile;
std::string localCacheHash;
std::string localCacheSize;
if (ids.size() == 1)
{
it = ids.begin();
localCacheFile = (it->second).name;
localCacheHash = (it->second).hash;
std::ostringstream out;
out << (it->second).size;
localCacheSize = out.str();
}
/* extract the details of the local cache */
//getSSLRoot()->setSetting(LOCAL_CACHE_FILE_KEY, localCacheFile);
//getSSLRoot()->setSetting(LOCAL_CACHE_HASH_KEY, localCacheHash);
//getSSLRoot()->setSetting(LOCAL_CACHE_SIZE_KEY, localCacheSize);
/************ TMP HACK SAVE until new serialiser is finished */
return 1;
}
// Transfer control.
void filedexserver::saveFileTransferStatus()
{
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
}
// Transfer control.
int filedexserver::getFile(std::string fname, std::string hash,
uint32_t size, std::string dest)
{
int ret = ftFiler -> getFile(fname, hash, size, dest);
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return ret;
}
void filedexserver::clear_old_transfers()
{
ftFiler -> clearFailedTransfers();
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
}
void filedexserver::cancelTransfer(std::string fname, std::string hash, uint32_t size)
{
ftFiler -> cancelFile(hash);
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
}
int filedexserver::RequestDirDetails(std::string uid, std::string path,
DirDetails &details)
{
return fiStore->RequestDirDetails(uid, path, details);
}
int filedexserver::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
{
return fiStore->RequestDirDetails(ref, details, flags);
}
int filedexserver::SearchKeywords(std::list<std::string> keywords,std::list<FileDetail> &results,uint32_t flags)
{
return fiStore->SearchKeywords(keywords, results,flags);
}
int filedexserver::SearchBoolExp(Expression * exp, std::list<FileDetail> &results)
{
return fiStore->searchBoolExp(exp, results);
}
int filedexserver::FileStoreTick()
{
ftFiler -> tick();
return 1;
}
// This function needs to be divided up.
int filedexserver::handleInputQueues()
{
// get all the incoming results.. and print to the screen.
RsCacheRequest *cr;
RsCacheItem *ci;
RsFileRequest *fr;
RsFileData *fd;
// Loop through Search Results.
int i = 0;
int i_init = 0;
//std::cerr << "filedexserver::handleInputQueues()" << std::endl;
while((ci = pqisi -> GetSearchResult()) != NULL)
{
//std::cerr << "filedexserver::handleInputQueues() Recvd SearchResult (CacheResponse!)" << std::endl;
std::ostringstream out;
if (i++ == i_init)
{
out << "Recieved Search Results:" << std::endl;
}
ci -> print(out);
pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone, out.str());
/* these go to the CacheStrapper! */
CacheData data;
data.cid = CacheId(ci->cacheType, ci->cacheSubId);
data.hash = ci->file.hash;
data.size = ci->file.filesize;
data.name = ci->file.name;
data.path = ci->file.path;
data.pid = ci->PeerId();
data.pname = mAuthMgr->getName(ci->PeerId());
mCacheStrapper->recvCacheResponse(data, time(NULL));
delete ci;
}
// now requested Searches.
i_init = i;
while((cr = pqisi -> RequestedSearch()) != NULL)
{
/* just delete these */
std::ostringstream out;
out << "Requested Search:" << std::endl;
cr -> print(out);
pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone, out.str());
delete cr;
}
// Now handle it replacement (pushed cache results)
{
std::list<std::pair<RsPeerId, CacheData> > cacheUpdates;
std::list<std::pair<RsPeerId, CacheData> >::iterator it;
mCacheStrapper->getCacheUpdates(cacheUpdates);
for(it = cacheUpdates.begin(); it != cacheUpdates.end(); it++)
{
/* construct reply */
RsCacheItem *ci = new RsCacheItem();
/* 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
std::ostringstream out2;
out2 << "Outgoing CacheStrapper Update -> RsCacheItem:" << std::endl;
ci -> print(out2);
std::cerr << out2.str() << std::endl;
#endif
//pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone, out2.str());
pqisi -> SendSearchResult(ci);
}
}
// now File Input.
i_init = i;
while((fr = pqisi -> GetFileRequest()) != NULL )
{
#ifdef SERVER_DEBUG
std::cerr << "filedexserver::handleInputQueues() Recvd ftFiler Request" << std::endl;
std::ostringstream out;
if (i == i_init)
{
out << "Incoming(Net) File Item:" << std::endl;
}
fr -> print(out);
pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone, out.str());
#endif
i++; /* count */
/* This bit is for debugging only! (not really needed) */
/* request */
ftFileRequest *ffr = new ftFileRequest(fr->PeerId(),
fr->file.hash, fr->file.filesize,
fr->fileoffset, fr->chunksize);
ftFiler->recvFileInfo(ffr);
delete fr;
}
// now File Data.
i_init = i;
while((fd = pqisi -> GetFileData()) != NULL )
{
#ifdef SERVER_DEBUG
//std::cerr << "filedexserver::handleInputQueues() Recvd ftFiler Data" << std::endl;
std::ostringstream out;
if (i == i_init)
{
out << "Incoming(Net) File Data:" << std::endl;
}
fd -> print(out);
pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone, out.str());
#endif
i++; /* count */
/* incoming data */
ftFileData *ffd = new ftFileData(fd->PeerId(),
fd->fd.file.hash, fd->fd.file.filesize,
fd->fd.file_offset,
fd->fd.binData.bin_len,
fd->fd.binData.bin_data, FT_FILEDATA_FLAG_NOFREE);
ftFiler->recvFileInfo(ffd);
delete fd;
}
if (i > 0)
{
return 1;
}
return 0;
}
// This function needs to be divided up.
int filedexserver::handleOutputQueues()
{
// get all the incoming results.. and print to the screen.
//std::cerr << "filedexserver::handleOutputQueues()" << std::endl;
int i = 0;
/* now see if the filer has any data */
ftFileRequest *ftr;
while((ftr = ftFiler -> sendFileInfo()) != NULL)
{
//std::cerr << "filedexserver::handleOutputQueues() ftFiler Data for: " << ftr->id << std::endl;
/* decide if its data or request */
ftFileData *ftd = dynamic_cast<ftFileData *>(ftr);
if (ftd)
{
SendFileData(ftd, ftr->id);
}
else
{
SendFileRequest(ftr, ftr->id);
}
std::ostringstream out;
if (i++ == 0)
{
out << "Outgoing filer -> PQFileItem:" << std::endl;
}
pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone, out.str());
/* clean up */
delete ftr;
}
if (i > 0)
{
return 1;
}
return 0;
}
void filedexserver::SendFileRequest(ftFileRequest *ftr, std::string pid)
{
RsFileRequest *rfi = new RsFileRequest();
/* id */
rfi->PeerId(pid);
/* file info */
rfi->file.filesize = ftr->size;
rfi->file.hash = ftr->hash;
/* offsets */
rfi->fileoffset = ftr->offset;
rfi->chunksize = ftr->chunk;
pqisi -> SendFileRequest(rfi);
}
#define MAX_FT_CHUNK 4096
void filedexserver::SendFileData(ftFileData *ftd, std::string pid)
{
uint32_t tosend = ftd->chunk;
uint32_t baseoffset = ftd->offset;
uint32_t offset = 0;
uint32_t chunk;
while(tosend > 0)
{
/* workout size */
chunk = MAX_FT_CHUNK;
if (chunk > tosend)
{
chunk = tosend;
}
/******** New Serialiser Type *******/
RsFileData *rfd = new RsFileData();
/* set id */
rfd->PeerId(pid);
/* file info */
rfd->fd.file.filesize = ftd->size;
rfd->fd.file.hash = ftd->hash;
rfd->fd.file.name = ""; /* blank other data */
rfd->fd.file.path = "";
rfd->fd.file.pop = 0;
rfd->fd.file.age = 0;
rfd->fd.file_offset = baseoffset + offset;
/* file data */
rfd->fd.binData.setBinData(
&(((uint8_t *) ftd->data)[offset]), chunk);
pqisi -> SendFileData(rfd);
offset += chunk;
tosend -= chunk;
}
}
/***************************************************************************/
/****************************** CONFIGURATION HANDLING *********************/
/***************************************************************************/
/**** OVERLOADED FROM p3Config ****/
static const std::string fdex_dir("FDEX_DIR");
static const std::string save_dir_ss("SAVE_DIR");
static const std::string save_inc_ss("SAVE_INC");
RsSerialiser *filedexserver::setupSerialiser()
{
RsSerialiser *rss = new RsSerialiser();
/* add in the types we need! */
rss->addSerialType(new RsFileConfigSerialiser());
rss->addSerialType(new RsGeneralConfigSerialiser());
return rss;
}
std::list<RsItem *> filedexserver::saveList(bool &cleanup)
{
std::list<RsItem *> saveData;
/* it can delete them! */
cleanup = true;
/* create a key/value set for most of the parameters */
std::map<std::string, std::string> configMap;
std::map<std::string, std::string>::iterator mit;
std::list<std::string>::iterator it;
pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone,
"fildexserver::save_config()");
/* basic control parameters */
configMap[save_dir_ss] = getSaveDir();
if (getSaveIncSearch())
{
configMap[save_inc_ss] = "true";
}
else
{
configMap[save_inc_ss] = "false";
}
int i;
for(it = dbase_dirs.begin(), i = 0; (it != dbase_dirs.end())
&& (i < 1000); it++, i++)
{
std::string name = fdex_dir;
int d1, d2, d3;
d1 = i / 100;
d2 = (i - d1 * 100) / 10;
d3 = i - d1 * 100 - d2 * 10;
name += '0'+d1;
name += '0'+d2;
name += '0'+d3;
configMap[name] = (*it);
}
RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet();
/* Convert to TLV */
for(mit = configMap.begin(); mit != configMap.end(); mit++)
{
RsTlvKeyValue kv;
kv.key = mit->first;
kv.value = mit->second;
rskv->tlvkvs.pairs.push_back(kv);
}
/* Add KeyValue to saveList */
saveData.push_back(rskv);
std::list<RsFileTransfer *>::iterator fit;
std::list<RsFileTransfer *> ftlist = ftFiler -> getStatus();
for(fit = ftlist.begin(); fit != ftlist.end(); fit++)
{
/* only write out the okay/uncompleted (with hash) files */
if (((*fit)->state == FT_STATE_FAILED) ||
((*fit)->state == FT_STATE_COMPLETE) ||
((*fit)->in == false) ||
((*fit)->file.hash == ""))
{
/* ignore */
/* cleanup */
delete(*fit);
}
else
{
saveData.push_back(*fit);
}
}
/* list completed! */
return saveData;
}
bool filedexserver::loadList(std::list<RsItem *> load)
{
std::list<RsItem *>::iterator it;
std::list<RsTlvKeyValue>::iterator kit;
RsConfigKeyValueSet *rskv;
RsFileTransfer *rsft;
#ifdef SERVER_DEBUG
std::cerr << "filedexserver::loadList() Item Count: " << load.size();
std::cerr << std::endl;
#endif
for(it = load.begin(); it != load.end(); it++)
{
/* switch on type */
if (NULL != (rskv = dynamic_cast<RsConfigKeyValueSet *>(*it)))
{
/* make into map */
std::map<std::string, std::string> configMap;
for(kit = rskv->tlvkvs.pairs.begin();
kit != rskv->tlvkvs.pairs.end(); kit++)
{
configMap[kit->key] = kit->value;
}
loadConfigMap(configMap);
/* cleanup */
delete (*it);
}
else if (NULL != (rsft = dynamic_cast<RsFileTransfer *>(*it)))
{
/* save to the preLoad list */
mResumeTransferList.push_back(rsft);
}
else
{
/* cleanup */
delete (*it);
}
}
return true;
}
bool filedexserver::loadConfigMap(std::map<std::string, std::string> &configMap)
{
std::map<std::string, std::string>::iterator mit;
int i;
std::string str_true("true");
std::string empty("");
std::string dir = "notempty";
if (configMap.end() != (mit = configMap.find(save_dir_ss)))
{
setSaveDir(mit->second);
}
if (configMap.end() != (mit = configMap.find(save_inc_ss)))
{
setSaveIncSearch(mit->second == str_true);
}
dbase_dirs.clear();
for(i = 0; (i < 1000) && (dir != empty); i++)
{
std::string name = fdex_dir;
int d1, d2, d3;
d1 = i / 100;
d2 = (i - d1 * 100) / 10;
d3 = i - d1 * 100 - d2 * 10;
name += '0'+d1;
name += '0'+d2;
name += '0'+d3;
if (configMap.end() != (mit = configMap.find(name)))
{
dir = mit->second;
dbase_dirs.push_back(mit->second);
}
}
if (dbase_dirs.size() > 0)
{
std::ostringstream out;
out << "Loading " << dbase_dirs.size();
out << " Directories" << std::endl;
pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone, out.str());
reScanDirs();
}
return true;
}

View File

@ -1,193 +0,0 @@
/*
* "$Id: filedexserver.h,v 1.18 2007-05-05 16:10:06 rmf24 Exp $"
*
* Other Bits for RetroShare.
*
* Copyright 2004-2006 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 MRK_PQI_FILEDEX_SERVER_HEADER
#define MRK_PQI_FILEDEX_SERVER_HEADER
/*
* Slightly more complete server....
* has a filedex pointer, which manages the local indexing/searching.
*
*/
#include "pqi/pqi.h"
#include "pqi/pqiindic.h"
#include "serialiser/rsconfigitems.h"
#include <map>
#include <deque>
#include <list>
#include <map>
#include <iostream>
#include "rsiface/rsiface.h"
#include "pqi/p3cfgmgr.h"
class p3ConnectMgr;
class p3AuthMgr;
class CacheStrapper;
class ftfiler;
class FileIndexStore;
class FileIndexMonitor;
class ftFileRequest;
class ftFileData;
class Expression;
#define MAX_RESULTS 100 // nice balance between results and traffic.
class filedexserver: public p3Config
{
public:
filedexserver();
void loadWelcomeMsg(); /* startup message */
int setSearchInterface(P3Interface *si, p3AuthMgr *am, p3ConnectMgr *cm);
std::list<RsFileTransfer *> getTransfers();
void saveFileTransferStatus();
int getFile(std::string fname, std::string hash,
uint32_t size, std::string dest);
void clear_old_transfers();
void cancelTransfer(std::string fname, std::string hash, uint32_t size);
// access to search info is also required.
bool ConvertSharedFilePath(std::string path, std::string &fullpath);
void ForceDirectoryCheck();
bool InDirectoryCheck();
std::list<std::string> &getSearchDirectories();
int addSearchDirectory(std::string dir);
int removeSearchDirectory(std::string dir);
int reScanDirs();
int check_dBUpdate();
std::string getSaveDir();
void setSaveDir(std::string d);
void setEmergencySaveDir(std::string s);
void setConfigDir(std::string d) { config_dir = d; }
bool getSaveIncSearch();
void setSaveIncSearch(bool v);
int tick();
int status();
private:
int handleInputQueues();
int handleOutputQueues();
std::list<std::string> dbase_dirs;
P3Interface *pqisi;
p3AuthMgr *mAuthMgr;
p3ConnectMgr *mConnMgr;
std::string config_dir;
std::string save_dir;
bool save_inc; // is savedir include in share list.
public:
/* some more switches (here for uniform saving) */
int getDHTEnabled()
{
return DHTState;
}
int getUPnPEnabled()
{
return UPnPState;
}
void setDHTEnabled(int i)
{
DHTState = i;
}
void setUPnPEnabled(int i)
{
UPnPState = i;
}
private:
int DHTState;
int UPnPState;
/*************************** p3 Config Overload ********************/
protected:
/* Key Functions to be overloaded for Full Configuration */
virtual RsSerialiser *setupSerialiser();
virtual std::list<RsItem *> saveList(bool &cleanup);
virtual bool loadList(std::list<RsItem *> load);
private:
bool loadConfigMap(std::map<std::string, std::string> &configMap);
/*************************** p3 Config Overload ********************/
/* new FileCache stuff */
public:
int FileStoreTick();
int FileCacheSave();
/* Setup */
void initialiseFileStore();
void setFileCallback(std::string ownId, CacheStrapper *strapper,
ftfiler *ft, NotifyBase *cb);
void StartupMonitor();
/* Controls */
int RequestDirDetails(std::string uid, std::string path, DirDetails &details);
int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results);
int SearchBoolExp(Expression * exp, std::list<FileDetail> &results);
private:
void SendFileRequest(ftFileRequest *ftr, std::string pid);
void SendFileData(ftFileData *ftd, std::string pid);
CacheStrapper *mCacheStrapper;
ftfiler *ftFiler;
FileIndexStore *fiStore;
FileIndexMonitor *fimon;
/* Temp Transfer List (for loading config) */
std::list<RsFileTransfer *> mResumeTransferList;
};
#endif // MRK_PQI_FILEDEX_SERVER_HEADER

View File

@ -1,118 +0,0 @@
/*
* "$Id: pqifiler.cc,v 1.13 2007-02-19 20:08:30 rmf24 Exp $"
*
* Other Bits for RetroShare.
*
* Copyright 2004-2006 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 "server/ft.h"
/****
* #define FT_DEBUG 1
***/
bool ftManager::lookupLocalHash(std::string hash, std::string &path, uint64_t &size)
{
std::list<FileDetail> details;
#ifdef FT_DEBUG
std::cerr << "ftManager::lookupLocalHash() hash: " << hash << std::endl;
#endif
if (FindCacheFile(hash, path, size))
{
/* got it from the CacheTransfer() */
#ifdef FT_DEBUG
std::cerr << "ftManager::lookupLocalHash() Found in CacheStrapper:";
std::cerr << path << " size: " << size << std::endl;
#endif
return true;
}
bool ok = false;
if (fhs)
{
ok = (0 != fhs -> searchLocalHash(hash, path, size));
}
else
{
#ifdef FT_DEBUG
std::cerr << "Warning FileHashSearch is Invalid" << std::endl;
#endif
}
if (ok)
{
#ifdef FT_DEBUG
std::cerr << "ftManager::lookupLocalHash() Found in FileHashSearch:";
std::cerr << path << " size: " << size << std::endl;
#endif
return true;
}
return ok;
}
bool ftManager::lookupRemoteHash(std::string hash, std::list<std::string> &ids)
{
std::list<FileDetail> details;
std::list<FileDetail>::iterator it;
#ifdef FT_DEBUG
std::cerr << "ftManager::lookupRemoteHash() hash: " << hash << std::endl;
#endif
if (fhs)
{
fhs -> searchRemoteHash(hash, details);
}
else
{
#ifdef FT_DEBUG
std::cerr << "Warning FileHashSearch is Invalid" << std::endl;
#endif
}
if (details.size() == 0)
{
#ifdef FT_DEBUG
std::cerr << "ftManager::lookupRemoteHash() Not Found!" << std::endl;
#endif
return false;
}
for(it = details.begin(); it != details.end(); it++)
{
#ifdef FT_DEBUG
std::cerr << "ftManager::lookupRemoteHash() Found in FileHashSearch:";
std::cerr << " id: " << it->id << std::endl;
#endif
ids.push_back(it->id);
}
return true;
}

View File

@ -1,165 +0,0 @@
/*
* "$Id: ftManager.h,v 1.13 2007-02-19 20:08:30 rmf24 Exp $"
*
* Other Bits for RetroShare.
*
* Copyright 2004-2006 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 MRK_FT_MANAGER_HEADER
#define MRK_FT_MANAGER_HEADER
/*
* ftManager - virtual base class for FileTransfer
*/
#include <list>
#include <iostream>
#include <string>
#include "pqi/pqi.h"
#include "serialiser/rsconfigitems.h"
#include "dbase/cachestrapper.h"
#include "server/hashsearch.h"
class ftFileManager; /* stores files */
class ftFileRequest
{
public:
ftFileRequest(std::string id_in, std::string hash_in,
uint64_t size_in, uint64_t offset_in,
uint32_t chunk_in)
:id(id_in), hash(hash_in), size(size_in),
offset(offset_in), chunk(chunk_in)
{
return;
}
virtual ~ftFileRequest() { return; }
std::string id;
std::string hash;
uint64_t size;
uint64_t offset;
uint32_t chunk;
};
const uint32_t FT_FILEDATA_FLAG_NOFREE = 0x01;
class ftFileData: public ftFileRequest
{
public:
ftFileData(std::string id_in, std::string hash_in,
uint64_t size_in, uint64_t offset_in,
uint32_t chunk_in, void *data_in, uint32_t flags)
:ftFileRequest(id_in, hash_in, size_in,
offset_in, chunk_in), data(data_in), ftFlags(flags)
{
return;
}
virtual ~ftFileData()
{
if (ftFlags & FT_FILEDATA_FLAG_NOFREE)
{
/* don't free */
}
else
{
if (data)
{
free(data);
}
}
data = NULL;
}
void *data;
uint32_t ftFlags;
};
class ftManager: public CacheTransfer
{
public:
ftManager(CacheStrapper *cs)
:CacheTransfer(cs), fhs(NULL) { return; }
virtual ~ftManager() { return; }
void setFileHashSearch(FileHashSearch *hs) { fhs = hs; }
/****************** PART to be IMPLEMENTE******************/
/* Functions to implement */
/*********** overloaded from CacheTransfer ***************/
/* Must callback after this fn - using utility functions */
//virtual bool RequestCacheFile(RsPeerId id, std::string path,
// std::string hash, uint64_t size);
/******************* GUI Interface ************************/
virtual int getFile(std::string name, std::string hash,
uint64_t size, std::string destpath) = 0;
virtual int cancelFile(std::string hash) = 0;
virtual int clearFailedTransfers() = 0;
virtual int tick() = 0;
virtual std::list<RsFileTransfer *> getStatus() = 0;
/************* Network Interface****************************/
public:
virtual void setSaveBasePath(std::string s) = 0;
virtual void setEmergencyBasePath(std::string s) = 0;
virtual int recvFileInfo(ftFileRequest *in) = 0;
virtual ftFileRequest * sendFileInfo() = 0;
protected:
/****************** UTILITY FUNCTIONS ********************/
/* combines two lookup functions */
bool lookupLocalHash(std::string hash, std::string &path, uint64_t &size);
bool lookupRemoteHash(std::string hash, std::list<std::string> &ids);
/*********** callback from CacheTransfer ***************/
//bool CompletedCache(std::string hash); /* internal completion -> does cb */
//bool FailedCache(std::string hash); /* internal completion -> does cb */
/*********** available from CacheTransfer ***************/
/* upload side of things .... searches through CacheStrapper(Sources) for a cache. */
//bool FindCacheFile(std::string id, std::string hash, std::string &path);
/*********** available from CacheTransfer ***************/
private:
FileHashSearch *fhs;
};
#endif

View File

@ -1,346 +0,0 @@
/*
* RetroShare FileCache Module: ficachetest.cc
*
* Copyright 2004-2007 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 "dbase/cachestrapper.h"
#include "dbase/cachetest.h"
#include "server/ftfiler.h"
#include "util/rsdir.h"
#include "pqi/pqidebug.h"
#include <iostream>
#include <fstream>
void handleQuery(CacheStrapper *csp, RsPeerId pid,
std::map<RsPeerId, CacheStrapper *> &strappers);
/* A simple test of the CacheStrapper Code.
*
* create 3 different CacheStrappers, each with a Source/Store Pair and Transfer Class.
* pass queries and responses between the CacheStrappers,
* and ensure that the hashes in the Caches are updated.
*
*/
int main(int argc, char **argv)
{
/* setup test */
std::string tmppath1 = "/tmp/ct1";
std::string tmppath2 = "/tmp/ct2";
std::string tmppath3 = "/tmp/ct3";
std::string tmppathpart1 = tmppath1 + "/partials";
std::string tmppathpart2 = tmppath2 + "/partials";
std::string tmppathpart3 = tmppath3 + "/partials";
std::string tmppathcompleted1 = tmppath1 + "/completed";
std::string tmppathcompleted2 = tmppath2 + "/completed";
std::string tmppathcompleted3 = tmppath3 + "/completed";
std::string tmppathcache2 = tmppath2 + "/cache";
std::string cachefile = "cachefile.txt";
std::string tmppathcachefile2 = tmppathcache2 + "/" + cachefile;
RsDirUtil::checkCreateDirectory(tmppath1.c_str());
RsDirUtil::checkCreateDirectory(tmppath2.c_str());
RsDirUtil::checkCreateDirectory(tmppath3.c_str());
RsDirUtil::checkCreateDirectory(tmppathpart1.c_str());
RsDirUtil::checkCreateDirectory(tmppathpart2.c_str());
RsDirUtil::checkCreateDirectory(tmppathpart3.c_str());
RsDirUtil::checkCreateDirectory(tmppathcompleted1.c_str());
RsDirUtil::checkCreateDirectory(tmppathcompleted2.c_str());
RsDirUtil::checkCreateDirectory(tmppathcompleted3.c_str());
RsDirUtil::checkCreateDirectory(tmppathcache2.c_str());
/* now create a file */
std::ofstream out(tmppathcachefile2.c_str());
out << "Hello this is a cache file!" << std::endl;
out.close();
setOutputLevel(10);
time_t period = 11;
RsPeerId pid1("0x0101");
RsPeerId pid2("0x0102");
RsPeerId pid3("0x0103");
CacheStrapper sc1(pid1, period);
CacheStrapper sc2(pid2, period);
CacheStrapper sc3(pid3, period);
//CacheTransfer ctt1(&sc1);
//CacheTransfer ctt2(&sc2);
//CacheTransfer ctt3(&sc3);
/* setup of the FileTransfer should wait until
* the CacheSource + CacheStrapper are created
*/
FileHashSearch *fhs1 = NULL;
FileHashSearch *fhs2 = NULL;
FileHashSearch *fhs3 = NULL;
ftfiler ff1(&sc1);
ftfiler ff2(&sc2);
ftfiler ff3(&sc3);
ff1.setSaveBasePath(tmppath1);
ff2.setSaveBasePath(tmppath2);
ff3.setSaveBasePath(tmppath3);
ff1.setFileHashSearch(fhs1);
ff2.setFileHashSearch(fhs2);
ff3.setFileHashSearch(fhs3);
std::map<RsPeerId, CacheStrapper *> strappers;
strappers[pid1] = &sc1;
strappers[pid2] = &sc2;
strappers[pid3] = &sc3;
std::string nulldir = "";
CacheSource *csrc1 = new CacheTestSource(nulldir);
//CacheStore *cstore1 = new CacheTestStore(&ctt1, nulldir);
CacheStore *cstore1 = new CacheTestStore(&ff1, nulldir);
CacheId cid1(TESTID, 0);
CacheSource *csrc2 = new CacheTestSource(nulldir);
//CacheStore *cstore2 = new CacheTestStore(&ctt2, nulldir);
CacheStore *cstore2 = new CacheTestStore(&ff2, nulldir);
CacheId cid2(TESTID, 0);
CacheSource *csrc3 = new CacheTestSource(nulldir);
//CacheStore *cstore3 = new CacheTestStore(&ctt3, nulldir);
CacheStore *cstore3 = new CacheTestStore(&ff3, nulldir);
CacheId cid3(TESTID, 0);
CachePair cp1(csrc1, cstore1, cid1);
CachePair cp2(csrc2, cstore2, cid2);
CachePair cp3(csrc3, cstore3, cid3);
sc1.addCachePair(cp1);
sc2.addCachePair(cp2);
sc3.addCachePair(cp3);
sc1.addPeerId(pid2);
sc2.addPeerId(pid1);
sc2.addPeerId(pid3);
sc3.addPeerId(pid2);
/* add in a cache to sc2 */
CacheData cdata;
cdata.pid = pid1;
cdata.cid = cid1;
cdata.name = cachefile; //"Perm Cache";
cdata.path = tmppathcache2; //"./";
cdata.hash = "GHJKI";
cdata.size = 28;
csrc1->refreshCache(cdata);
/* The file we created */
cdata.pid = pid2;
cdata.cid = cid2;
cdata.name = "Funny Cache";
cdata.path = "./";
cdata.size = 1023;
cdata.hash = "ABCDEF";
csrc2->refreshCache(cdata);
/* now exercise it */
for(int i = 0; 1 ; i++)
{
RsPeerId src("");
CacheStrapper *csp = NULL;
if (i % 5 == 1)
{
src = pid1;
csp = &sc1;
}
else if (i % 5 == 2)
{
src = pid2;
csp = &sc2;
}
else if (i % 5 == 3)
{
src = pid3;
csp = &sc3;
}
std::cerr << std::endl;
std::cerr << "Cache Iteraton: " << time(NULL) << std::endl;
std::cerr << std::endl;
if (src != "")
{
handleQuery(csp, src, strappers);
}
if (i % 21 == 0)
{
/* print out the resources */
sc1.listCaches(std::cerr);
sc2.listCaches(std::cerr);
sc3.listCaches(std::cerr);
}
/* every once in a while change the cache on 2 */
if (i % 31 == 25)
{
cdata.hash += "X";
csrc2->refreshCache(cdata);
}
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS
sleep(1);
#else
Sleep(1000);
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
/* tick the systems */
ff1.tick();
ff2.tick();
ff3.tick();
/* exchange packets! */
ftFileRequest *ftPkt = NULL;
while(NULL != (ftPkt = ff1.sendFileInfo()))
{
std::cerr << "Outgoing ftPkt from ff1";
std::cerr << std::endl;
if (ftPkt->id == pid2)
{
std::cerr << "ftPkt for ff2" << std::endl;
ftPkt->id = pid1; /* set source correctly */
ff2.recvFileInfo(ftPkt);
}
else if (ftPkt->id == pid3)
{
std::cerr << "ftPkt for ff3" << std::endl;
ftPkt->id = pid1; /* set source correctly */
ff3.recvFileInfo(ftPkt);
}
else
{
std::cerr << "ERROR unknown ftPkt destination!: " << ftPkt->id;
std::cerr << std::endl;
delete ftPkt;
}
}
while(NULL != (ftPkt = ff2.sendFileInfo()))
{
std::cerr << "Outgoing ftPkt from ff2";
std::cerr << std::endl;
if (ftPkt->id == pid1)
{
std::cerr << "ftPkt for ff1" << std::endl;
ftPkt->id = pid2; /* set source correctly */
ff1.recvFileInfo(ftPkt);
}
else if (ftPkt->id == pid3)
{
std::cerr << "ftPkt for ff3" << std::endl;
ftPkt->id = pid2; /* set source correctly */
ff3.recvFileInfo(ftPkt);
}
else
{
std::cerr << "ERROR unknown ftPkt destination!: " << ftPkt->id;
std::cerr << std::endl;
delete ftPkt;
}
}
while(NULL != (ftPkt = ff3.sendFileInfo()))
{
std::cerr << "Outgoing ftPkt from ff3";
std::cerr << std::endl;
if (ftPkt->id == pid1)
{
std::cerr << "ftPkt for ff1" << std::endl;
ftPkt->id = pid3; /* set source correctly */
ff1.recvFileInfo(ftPkt);
}
else if (ftPkt->id == pid2)
{
std::cerr << "ftPkt for ff2" << std::endl;
ftPkt->id = pid3; /* set source correctly */
ff2.recvFileInfo(ftPkt);
}
else
{
std::cerr << "ERROR unknown ftPkt destination!: " << ftPkt->id;
std::cerr << std::endl;
delete ftPkt;
}
}
}
/* Cleanup - TODO */
return 1;
}
void handleQuery(CacheStrapper *csp, RsPeerId pid,
std::map<RsPeerId, CacheStrapper *> &strappers)
{
/* query */
std::list<RsPeerId> ids;
std::list<RsPeerId>::iterator pit;
std::cerr << "Cache Query from: " << pid << std::endl;
csp -> sendCacheQuery(ids, time(NULL));
for(pit = ids.begin(); pit != ids.end(); pit++)
{
std::cerr << "Cache Query for: " << (*pit) << std::endl;
std::map<RsPeerId, CacheStrapper *>::iterator sit;
if (strappers.end() != (sit = strappers.find(*pit)))
{
std::map<CacheId, CacheData> hashs;
std::map<CacheId, CacheData>::iterator hit;
(sit -> second) -> handleCacheQuery(pid, hashs);
for(hit = hashs.begin(); hit != hashs.end(); hit++)
{
csp -> recvCacheResponse(hit->second, time(NULL));
}
}
else
{
std::cerr << "Unknown Query Destination!" << std::endl;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,233 +0,0 @@
/*
* "$Id: ftfiler.h,v 1.5 2007-02-19 20:08:30 rmf24 Exp $"
*
* Other Bits for RetroShare.
*
* Copyright 2004-2006 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 MRK_FT_FILER_HEADER
#define MRK_FT_FILER_HEADER
/*
* PQI Filer
*
* This managers the file transfers.
*
*/
#include "server/ft.h"
#include "pqi/pqi.h"
#include <list>
#include <iostream>
#include <string>
const int PQIFILE_INIT = 0x0000;
const int PQIFILE_NOT_ONLINE = 0x0001;
const int PQIFILE_DOWNLOADING = 0x0002;
const int PQIFILE_COMPLETE = 0x0004;
const int PQIFILE_FAIL = 0x0010;
/* reasons for DOWNLOAD FAILURE (2nd byte) */
const int PQIFILE_FAIL_CANCEL = 0x0100;
const int PQIFILE_FAIL_NOT_AVAIL = 0x0200;
const int PQIFILE_FAIL_NOT_OPEN = 0x0400;
const int PQIFILE_FAIL_NOT_SEEK = 0x0800;
const int PQIFILE_FAIL_NOT_WRITE = 0x1000;
const int PQIFILE_FAIL_NOT_READ = 0x2000;
const int PQIFILE_FAIL_BAD_PATH = 0x4000;
const int TRANSFER_MODE_TRICKLE = 1;
const int TRANSFER_MODE_NORMAL = 2;
const int TRANSFER_MODE_FAST = 3;
const uint32_t FT_MODE_STD = 1;
const uint32_t FT_MODE_CACHE = 2;
const uint32_t FT_MODE_UPLOAD = 4;
class ftFileStatus
{
public:
/****
ftFileStatus(PQFileItem *in)
:fileItem(in), status(PQIFILE_INIT), fd(NULL),
total_size(0), recv_size(0),
req_loc(0), req_size(0), lastTS(0)
{
return;
}
****/
ftFileStatus(const std::string& name_in, const std::string& hash_in, uint64_t size_in,
const std::string& destpath_in, uint32_t mode_in)
:name(name_in), hash(hash_in), destpath(destpath_in), size(size_in), ftMode(mode_in),
status(PQIFILE_INIT), mode(0), rate(0), fd(NULL), total_size(0), recv_size(0),
req_loc(0), req_size(0), lastTS(0), lastDelta(0),file_name(""),id("")
{
/* not set ...
* id,
* filename,
* sources
*/
return;
}
ftFileStatus(const std::string& id_in, const std::string& name_in, const std::string& hash_in, uint64_t size_in,
const std::string& destpath_in, uint32_t mode_in)
:id(id_in), name(name_in), hash(hash_in), destpath(destpath_in), size(size_in), ftMode(mode_in),
status(PQIFILE_INIT), mode(0), rate(0), fd(NULL), total_size(0), recv_size(0),
req_loc(0), req_size(0), lastTS(0), lastDelta(0),file_name("")
{
/* not set ...
* id,
* filename,
* sources
*/
return;
}
~ftFileStatus()
{
if (fd)
fclose(fd);
}
/* data */
std::string id; /* current source / most recent destination */
std::string name;
std::string hash;
std::string destpath;
uint64_t size;
/* new stuff */
uint32_t ftMode;
std::list<std::string> sources;
uint32_t resetCount;
/* transfer inprogress or not */
int status;
int mode;
float rate;
std::string file_name;
FILE *fd;
uint64_t total_size;
/* this is the simplistic case where only inorder data
* otherwise - need much more status info */
uint64_t recv_size;
/* current file data request / most recent request answered (upload) */
uint64_t req_loc;
uint32_t req_size;
/* timestamp */
time_t lastTS; /* last request / request answered (upload) */
uint32_t lastDelta; /* send til all recved */
};
class ftfiler: public ftManager
{
public:
ftfiler(CacheStrapper *cs)
:ftManager(cs) { return; }
virtual ~ftfiler() { return; }
virtual bool RequestCacheFile(std::string id, std::string path,
std::string hash, uint64_t size);
virtual bool CancelCacheFile(RsPeerId id, std::string path,
std::string hash, uint64_t size);
virtual int getFile(std::string name, std::string hash,
uint64_t size, std::string destpath);
virtual int cancelFile(std::string hash);
virtual int clearFailedTransfers();
int tick();
std::list<RsFileTransfer *> getStatus();
virtual void setSaveBasePath(std::string s);
virtual void setEmergencyBasePath(std::string s);
/************* Network Interface****************************/
virtual int recvFileInfo(ftFileRequest *in);
virtual ftFileRequest *sendFileInfo();
private:
virtual int handleFileError(std::string hash, uint32_t err);
virtual int handleFileNotOnline(std::string hash);
virtual int handleFileNotAvailable(std::string hash);
virtual int handleFileData(std::string hash, uint64_t offset,
void *data, uint32_t size);
virtual int handleFileRequest( std::string id, std::string hash,
uint64_t offset, uint32_t chunk);
virtual int handleFileCacheRequest(std::string id, std::string hash,
uint64_t offset, uint32_t chunk);
ftFileStatus *findRecvFileItem(std::string hash);
void queryInactive();
/**************** End of Interface *************************/
int requestData(ftFileStatus *item);
/************* PQIFILEITEM Generator ***************************
*/
ftFileStatus * createFileCache(std::string hash);
ftFileRequest * generateFileRequest(ftFileStatus *);
int generateFileData(ftFileStatus *s, std::string id, uint64_t offset, uint32_t size);
//int sendFileNotAvail(PQFileItem *req);
/************* FILE DATA HANDLING ******************************
*/
std::string determineTmpFilePath(ftFileStatus *s);
std::string determineDestFilePath(ftFileStatus *s);
int initiateFileTransfer(ftFileStatus *s);
int resetFileTransfer(ftFileStatus *s);
int addFileData(ftFileStatus *s, uint64_t idx, void *data, uint32_t size);
int completeFileTransfer(ftFileStatus *s);
// Data.
private:
std::list<ftFileStatus *> recvFiles;
std::list<ftFileStatus *> fileCache;
std::list<ftFileRequest *> out_queue;
std::string saveBasePath;
std::string mEmergencyIncomingDir;
};
#endif // MRK_PQI_FILER_HEADER

View File

@ -1,51 +0,0 @@
/*
* "$Id: hashsearch.cc,v 1.5 2007-02-19 20:08:30 rmf24 Exp $"
*
* Other Bits for RetroShare.
*
* Copyright 2004-2006 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".
*
*/
/**********
* SearchInterface for the FileTransfer
*/
#include "server/hashsearch.h"
#include "dbase/fistore.h"
#include "dbase/fimonitor.h"
/* Search Interface - For FileTransfer Lookup */
int FileHashSearch::searchLocalHash(std::string hash, std::string &path, uint64_t &size)
{
if (monitor)
{
return monitor->findLocalFile(hash, path, size);
}
return 0;
}
int FileHashSearch::searchRemoteHash(std::string hash, std::list<FileDetail> &results)
{
if (store)
store->SearchHash(hash, results);
return results.size();
}

View File

@ -1,61 +0,0 @@
/*
* "$Id: hashsearch.h,v 1.5 2007-02-19 20:08:30 rmf24 Exp $"
*
* Other Bits for RetroShare.
*
* Copyright 2004-2006 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 MRK_FILE_HASH_SEARCH_H
#define MRK_FILE_HASH_SEARCH_H
/**********
* SearchInterface for the FileTransfer
*/
#include "rsiface/rstypes.h"
class FileIndexStore;
class FileIndexMonitor;
#include "dbase/fistore.h"
#include "dbase/fimonitor.h"
class FileHashSearch
{
public:
FileHashSearch(FileIndexStore *s, FileIndexMonitor *m)
:store(s), monitor(m) { return; }
~FileHashSearch() { return; }
/* Search Interface - For FileTransfer Lookup */
int searchLocalHash(std::string hash, std::string &path, uint64_t &size);
int searchRemoteHash(std::string hash, std::list<FileDetail> &results);
private:
FileIndexStore *store;
FileIndexMonitor *monitor;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,187 +0,0 @@
/*
* "$Id: pqifiler.h,v 1.5 2007-02-19 20:08:30 rmf24 Exp $"
*
* Other Bits for RetroShare.
*
* Copyright 2004-2006 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 MRK_PQI_FILER_HEADER
#define MRK_PQI_FILER_HEADER
/*
* PQI Filer
*
* This managers the file transfers.
*
*/
#include "pqi/pqi.h"
#include "dbase/filelook.h"
#include "dbase/filedex.h"
#include <list>
#include <iostream>
#include <string>
const int PQIFILE_INIT = 0x0000;
const int PQIFILE_NOT_ONLINE = 0x0001;
const int PQIFILE_DOWNLOADING = 0x0002;
const int PQIFILE_COMPLETE = 0x0004;
const int PQIFILE_FAIL = 0x0010;
/* reasons for DOWNLOAD FAILURE (2nd byte) */
const int PQIFILE_FAIL_CANCEL = 0x0100;
const int PQIFILE_FAIL_NOT_AVAIL = 0x0200;
const int PQIFILE_FAIL_NOT_OPEN = 0x0400;
const int PQIFILE_FAIL_NOT_SEEK = 0x0800;
const int PQIFILE_FAIL_NOT_WRITE = 0x1000;
const int PQIFILE_FAIL_NOT_READ = 0x2000;
const int PQIFILE_FAIL_BAD_PATH = 0x4000;
const int TRANSFER_MODE_TRICKLE = 1;
const int TRANSFER_MODE_NORMAL = 2;
const int TRANSFER_MODE_FAST = 3;
class PQFileStatus
{
public:
PQFileStatus(PQFileItem *in)
:fileItem(in), status(PQIFILE_INIT), fd(NULL),
total_size(0), recv_size(0),
req_loc(0), req_size(0), lastTS(0)
{
return;
}
~PQFileStatus()
{
if (fileItem)
delete fileItem;
if (fd)
fclose(fd);
}
/* data */
PQFileItem *fileItem;
/* transfer inprogress or not */
int status;
int mode;
float rate;
std::string file_name;
FILE *fd;
long total_size;
/* this is the simplistic case where only inorder data
* otherwise - need much more status info */
long recv_size;
/* current file data request */
long req_loc;
int req_size;
/* timestamp */
long lastTS;
int lastDelta; /* send til all recved */
};
class pqifiler
{
public:
#ifdef USE_FILELOOK
pqifiler(fileLook*);
#else
pqifiler(filedex*);
#endif
virtual ~pqifiler() { return; }
/******************* GUI Interface *************************
*/
int getFile(PQFileItem *in);
int cancelFile(PQFileItem *i);
int clearFailedTransfers();
int tick();
std::list<FileTransferItem *> getStatus();
/************* Network Interface****************************
*/
PQItem * sendPQFileItem();
int recvPQFileItem(PQItem *in);
void setSavePath(std::string s) { savePath = s;}
private:
PQFileStatus *findRecvFileItem(PQFileItem *in);
void queryInactive();
int handleFileError(PQFileItem *in);
int handleFileNotOnline(PQFileItem *in);
int handleFileNotAvailable(PQFileItem *in);
int handleFileData(PQFileItem *in);
int handleFileRequest(PQFileItem *in);
int handleFileCacheRequest(PQFileItem *req);
int requestData(PQFileStatus *item);
/************* PQIFILEITEM Generator ***************************
*/
PQFileStatus * createFileCache(PQFileItem *in);
PQFileItem * generatePQFileRequest(PQFileStatus *);
int generateFileData(PQFileStatus *s, PQFileItem *req);
int sendFileNotAvail(PQFileItem *req);
/************* FILE DATA HANDLING ******************************
*/
std::string determineFilePath(PQFileItem *item);
int initiateFileTransfer(PQFileStatus *s);
int resetFileTransfer(PQFileStatus *s);
int addFileData(PQFileStatus *s, long idx, void *data, int size);
// Data.
private:
std::list<PQFileStatus *> recvFiles;
std::list<PQFileStatus *> fileCache;
std::list<PQItem *> out_queue;
#ifdef USE_FILELOOK
fileLook *fileIndex;
#else
filedex *fileIndex;
#endif
std::string savePath;
};
#endif // MRK_PQI_FILER_HEADER