mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-06 16:15:23 -04:00
Created V0.3.x branch and moved the head into the trunk directory.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@246 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
commit
935745a08e
1318 changed files with 348809 additions and 0 deletions
28
libretroshare/src/server/Makefile
Normal file
28
libretroshare/src/server/Makefile
Normal file
|
@ -0,0 +1,28 @@
|
|||
|
||||
RS_TOP_DIR = ..
|
||||
include ../make.opt
|
||||
|
||||
OBJ = filedexserver.o pqifiler.o \
|
||||
ft.o ftfiler.o hashsearch.o
|
||||
|
||||
EXEC = ftcachetest
|
||||
|
||||
all : $(OBJ) librs $(EXEC)
|
||||
|
||||
librs: $(OBJ)
|
||||
$(AR) r $(LIBRS) $(OBJ)
|
||||
$(RANLIB) $(LIBRS)
|
||||
|
||||
ftcachetest : ftcachetest.o $(OBJ)
|
||||
$(CC) $(CFLAGS) -o ftcachetest ftcachetest.o $(OBJ) $(RSLIBS)
|
||||
|
||||
.cc.o:
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
clean:
|
||||
-/bin/rm $(OBJ)
|
||||
-/bin/rm ftcachetest.o
|
||||
|
||||
clobber: clean
|
||||
-/bin/rm $(EXEC)
|
||||
|
1413
libretroshare/src/server/filedexserver.cc
Normal file
1413
libretroshare/src/server/filedexserver.cc
Normal file
File diff suppressed because it is too large
Load diff
232
libretroshare/src/server/filedexserver.h
Normal file
232
libretroshare/src/server/filedexserver.h
Normal file
|
@ -0,0 +1,232 @@
|
|||
/*
|
||||
* "$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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
|
||||
#include "pqi/xpgpcert.h"
|
||||
|
||||
#else /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
#include "pqi/sslcert.h"
|
||||
|
||||
#endif /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
#include "pqi/pqi.h"
|
||||
#include "pqi/pqiindic.h"
|
||||
#include <map>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
|
||||
#include "rsiface/rsiface.h"
|
||||
class pqimonitor;
|
||||
class CacheStrapper;
|
||||
class ftfiler;
|
||||
class FileIndexStore;
|
||||
class FileIndexMonitor;
|
||||
|
||||
class ftFileRequest;
|
||||
class ftFileData;
|
||||
|
||||
|
||||
#ifdef PQI_USE_CHANNELS
|
||||
#include "pqi/pqichannel.h"
|
||||
#include "pqi/p3channel.h"
|
||||
#endif
|
||||
|
||||
#define MAX_RESULTS 100 // nice balance between results and traffic.
|
||||
|
||||
|
||||
class filedexserver
|
||||
{
|
||||
public:
|
||||
filedexserver();
|
||||
|
||||
void loadWelcomeMsg(); /* startup message */
|
||||
|
||||
int setSearchInterface(P3Interface *si, sslroot *sr);
|
||||
int additem(SearchItem *item, char *fname);
|
||||
|
||||
int sendChat(std::string msg);
|
||||
int sendPrivateChat(ChatItem *ci);
|
||||
|
||||
int sendRecommend(PQFileItem *fi, std::string msg);
|
||||
int sendMessage(MsgItem *item);
|
||||
int checkOutgoingMessages();
|
||||
|
||||
int getChat();
|
||||
/* std::deque<std::string> &getChatQueue(); */
|
||||
std::list<ChatItem *> getChatQueue();
|
||||
|
||||
std::list<MsgItem *> &getMsgList();
|
||||
std::list<MsgItem *> &getMsgOutList();
|
||||
std::list<MsgItem *> getNewMsgs();
|
||||
std::list<FileTransferItem *> getTransfers();
|
||||
|
||||
// get files (obsolete?)
|
||||
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);
|
||||
|
||||
// cleaning up....
|
||||
int removeMsgItem(int itemnum);
|
||||
// alternative versions.
|
||||
int removeMsgItem(MsgItem *mi);
|
||||
// third versions.
|
||||
int removeMsgId(unsigned long mid); /* id stored in sid */
|
||||
int markMsgIdRead(unsigned long mid);
|
||||
|
||||
// access to search info is also required.
|
||||
|
||||
std::list<std::string> &getSearchDirectories();
|
||||
int addSearchDirectory(std::string dir);
|
||||
int removeSearchDirectory(std::string dir);
|
||||
int reScanDirs();
|
||||
int check_dBUpdate();
|
||||
|
||||
int load_config();
|
||||
int save_config();
|
||||
|
||||
std::string getSaveDir();
|
||||
void setSaveDir(std::string d);
|
||||
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<ChatItem *> ichat;
|
||||
std::list<MsgItem *> imsg;
|
||||
std::list<MsgItem *> nmsg;
|
||||
std::list<MsgItem *> msgOutgoing; /* ones that haven't made it out yet! */
|
||||
|
||||
std::list<std::string> dbase_dirs;
|
||||
|
||||
P3Interface *pqisi;
|
||||
sslroot *sslr;
|
||||
|
||||
std::string config_dir;
|
||||
std::string save_dir;
|
||||
bool save_inc; // is savedir include in share list.
|
||||
|
||||
// bool state flags.
|
||||
public:
|
||||
Indicator msgChanged;
|
||||
Indicator msgMajorChanged;
|
||||
Indicator chatChanged;
|
||||
|
||||
#ifdef PQI_USE_CHANNELS
|
||||
|
||||
public:
|
||||
// Channel stuff.
|
||||
void setP3Channel(p3channel *p3c);
|
||||
int getAvailableChannels(std::list<pqichannel *> &chans);
|
||||
int getChannelMsgList(channelSign s, std::list<chanMsgSummary> &summary);
|
||||
channelMsg *getChannelMsg(channelSign s, MsgHash mh);
|
||||
|
||||
Indicator channelsChanged; // everything!
|
||||
|
||||
private:
|
||||
p3channel *p3chan;
|
||||
|
||||
#endif
|
||||
|
||||
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;
|
||||
|
||||
|
||||
/* new FileCache stuff */
|
||||
public:
|
||||
|
||||
int FileStoreTick();
|
||||
int FileCacheSave();
|
||||
|
||||
void initialiseFileStore();
|
||||
void setFileCallback(NotifyBase *cb);
|
||||
|
||||
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, cert *peer);
|
||||
void SendFileData(ftFileData *ftd, cert *peer);
|
||||
|
||||
pqimonitor *peerMonitor;
|
||||
CacheStrapper *cacheStrapper;
|
||||
ftfiler *ftFiler;
|
||||
FileIndexStore *fiStore;
|
||||
FileIndexMonitor *fimon;
|
||||
};
|
||||
|
||||
#endif // MRK_PQI_FILEDEX_SERVER_HEADER
|
97
libretroshare/src/server/ft.cc
Normal file
97
libretroshare/src/server/ft.cc
Normal file
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* "$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"
|
||||
|
||||
bool ftManager::lookupLocalHash(std::string hash, std::string &path, uint32_t &size)
|
||||
{
|
||||
std::list<FileDetail> details;
|
||||
|
||||
std::cerr << "ftManager::lookupLocalHash() hash: " << hash << std::endl;
|
||||
|
||||
if (FindCacheFile(hash, path, size))
|
||||
{
|
||||
/* got it from the CacheTransfer() */
|
||||
std::cerr << "ftManager::lookupLocalHash() Found in CacheStrapper:";
|
||||
std::cerr << path << " size: " << size << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ok = false;
|
||||
if (fhs)
|
||||
{
|
||||
ok = (0 != fhs -> searchLocalHash(hash, path, size));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Warning FileHashSearch is Invalid" << std::endl;
|
||||
}
|
||||
|
||||
if (ok)
|
||||
{
|
||||
std::cerr << "ftManager::lookupLocalHash() Found in FileHashSearch:";
|
||||
std::cerr << path << " size: " << size << std::endl;
|
||||
return true;
|
||||
}
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ftManager::lookupRemoteHash(std::string hash, std::list<std::string> &ids)
|
||||
{
|
||||
std::list<FileDetail> details;
|
||||
std::list<FileDetail>::iterator it;
|
||||
|
||||
std::cerr << "ftManager::lookupRemoteHash() hash: " << hash << std::endl;
|
||||
|
||||
if (fhs)
|
||||
{
|
||||
fhs -> searchRemoteHash(hash, details);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Warning FileHashSearch is Invalid" << std::endl;
|
||||
}
|
||||
|
||||
if (details.size() == 0)
|
||||
{
|
||||
std::cerr << "ftManager::lookupRemoteHash() Not Found!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(it = details.begin(); it != details.end(); it++)
|
||||
{
|
||||
std::cerr << "ftManager::lookupRemoteHash() Found in FileHashSearch:";
|
||||
std::cerr << " id: " << it->id << std::endl;
|
||||
ids.push_back(it->id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
144
libretroshare/src/server/ft.h
Normal file
144
libretroshare/src/server/ft.h
Normal file
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* "$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 "pqi/pqi.h"
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "dbase/cachestrapper.h"
|
||||
#include "server/hashsearch.h"
|
||||
|
||||
class ftFileManager; /* stores files */
|
||||
|
||||
|
||||
class ftFileRequest
|
||||
{
|
||||
public:
|
||||
ftFileRequest(std::string id_in, std::string hash_in,
|
||||
uint32_t size_in, uint32_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;
|
||||
uint32_t size;
|
||||
uint32_t offset;
|
||||
uint32_t chunk;
|
||||
};
|
||||
|
||||
|
||||
class ftFileData: public ftFileRequest
|
||||
{
|
||||
public:
|
||||
ftFileData(std::string id_in, std::string hash_in,
|
||||
uint32_t size_in, uint32_t offset_in,
|
||||
uint32_t chunk_in, void *data_in)
|
||||
:ftFileRequest(id_in, hash_in, size_in,
|
||||
offset_in, chunk_in), data(data_in)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
virtual ~ftFileData()
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
void *data;
|
||||
};
|
||||
|
||||
|
||||
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, uint32_t size);
|
||||
/******************* GUI Interface ************************/
|
||||
virtual int getFile(std::string name, std::string hash,
|
||||
uint32_t size, std::string destpath) = 0;
|
||||
|
||||
virtual int cancelFile(std::string hash) = 0;
|
||||
virtual int clearFailedTransfers() = 0;
|
||||
|
||||
virtual int tick() = 0;
|
||||
virtual std::list<FileTransferItem *> getStatus() = 0;
|
||||
|
||||
/************* Network Interface****************************/
|
||||
|
||||
public:
|
||||
virtual void setSaveBasePath(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, uint32_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
|
346
libretroshare/src/server/ftcachetest.cc
Normal file
346
libretroshare/src/server/ftcachetest.cc
Normal file
|
@ -0,0 +1,346 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1396
libretroshare/src/server/ftfiler.cc
Normal file
1396
libretroshare/src/server/ftfiler.cc
Normal file
File diff suppressed because it is too large
Load diff
228
libretroshare/src/server/ftfiler.h
Normal file
228
libretroshare/src/server/ftfiler.h
Normal file
|
@ -0,0 +1,228 @@
|
|||
/*
|
||||
* "$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(std::string name_in, std::string hash_in, uint32_t size_in,
|
||||
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)
|
||||
{
|
||||
/* not set ...
|
||||
* id,
|
||||
* filename,
|
||||
* sources
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
ftFileStatus(std::string id_in, std::string name_in, std::string hash_in, uint32_t size_in,
|
||||
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)
|
||||
{
|
||||
/* not set ...
|
||||
* id,
|
||||
* filename,
|
||||
* sources
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
~ftFileStatus()
|
||||
{
|
||||
if (fd)
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
|
||||
/* data */
|
||||
std::string id; /* current source */
|
||||
std::string name;
|
||||
std::string hash;
|
||||
std::string destpath;
|
||||
uint32_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;
|
||||
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 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, uint32_t size);
|
||||
virtual int getFile(std::string name, std::string hash,
|
||||
uint32_t size, std::string destpath);
|
||||
|
||||
virtual int cancelFile(std::string hash);
|
||||
virtual int clearFailedTransfers();
|
||||
|
||||
int tick();
|
||||
std::list<FileTransferItem *> getStatus();
|
||||
|
||||
virtual void setSaveBasePath(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, uint32_t offset,
|
||||
void *data, uint32_t size);
|
||||
|
||||
virtual int handleFileRequest( std::string id, std::string hash,
|
||||
uint32_t offset, uint32_t chunk);
|
||||
virtual int handleFileCacheRequest(std::string id, std::string hash,
|
||||
uint32_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, uint32_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, long idx, void *data, int size);
|
||||
int completeFileTransfer(ftFileStatus *s);
|
||||
|
||||
|
||||
// Data.
|
||||
private:
|
||||
std::list<ftFileStatus *> recvFiles;
|
||||
std::list<ftFileStatus *> fileCache;
|
||||
std::list<ftFileRequest *> out_queue;
|
||||
|
||||
std::string saveBasePath;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // MRK_PQI_FILER_HEADER
|
51
libretroshare/src/server/hashsearch.cc
Normal file
51
libretroshare/src/server/hashsearch.cc
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* "$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, uint32_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();
|
||||
}
|
||||
|
||||
|
61
libretroshare/src/server/hashsearch.h
Normal file
61
libretroshare/src/server/hashsearch.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* "$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, uint32_t &size);
|
||||
|
||||
int searchRemoteHash(std::string hash, std::list<FileDetail> &results);
|
||||
|
||||
private:
|
||||
|
||||
FileIndexStore *store;
|
||||
FileIndexMonitor *monitor;
|
||||
};
|
||||
|
||||
#endif
|
1220
libretroshare/src/server/pqifiler.cc
Normal file
1220
libretroshare/src/server/pqifiler.cc
Normal file
File diff suppressed because it is too large
Load diff
187
libretroshare/src/server/pqifiler.h
Normal file
187
libretroshare/src/server/pqifiler.h
Normal file
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
* "$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
|
Loading…
Add table
Add a link
Reference in a new issue