mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
First commit for the turtle download. It works without perturbating RS traffic, but still needs some (internal) smoothing
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1275 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
c298de7f15
commit
1046bdd846
@ -43,6 +43,8 @@
|
||||
#include "ft/ftdatamultiplex.h"
|
||||
#include "ft/ftextralist.h"
|
||||
|
||||
#include "turtle/p3turtle.h"
|
||||
|
||||
#include "util/rsdir.h"
|
||||
|
||||
#include "pqi/p3connmgr.h"
|
||||
@ -76,17 +78,48 @@ ftFileControl::ftFileControl(std::string fname,
|
||||
}
|
||||
|
||||
ftController::ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string configDir)
|
||||
:CacheTransfer(cs), p3Config(CONFIG_TYPE_FT_CONTROL), mDataplex(dm), mFtActive(false)
|
||||
:CacheTransfer(cs), p3Config(CONFIG_TYPE_FT_CONTROL), mDataplex(dm), mFtActive(false),mTurtle(NULL)
|
||||
{
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
void ftController::setTurtleRouter(p3turtle *pt)
|
||||
{
|
||||
mTurtle = pt ;
|
||||
}
|
||||
void ftController::setFtSearchNExtra(ftSearch *search, ftExtraList *list)
|
||||
{
|
||||
mSearch = search;
|
||||
mExtraList = list;
|
||||
}
|
||||
|
||||
void ftController::addFileSource(const std::string& hash,const std::string& peer_id)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
std::map<std::string, ftFileControl>::iterator it;
|
||||
std::map<std::string, ftFileControl> currentDownloads = *(&mDownloads);
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController: Adding source " << peer_id << " to current download hash=" << hash ;
|
||||
#endif
|
||||
for(it = currentDownloads.begin(); it != currentDownloads.end(); it++)
|
||||
if(it->first == hash)
|
||||
{
|
||||
it->second.mTransfer->addFileSource(peer_id);
|
||||
|
||||
// setPeerState(it->second.mTransfer, peer_id, rate, mConnMgr->isOnline(peer_id));
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "... added." << std::endl ;
|
||||
#endif
|
||||
return ;
|
||||
}
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "... not added: hash not found." << std::endl ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ftController::run()
|
||||
{
|
||||
|
||||
@ -134,7 +167,12 @@ void ftController::run()
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (it->second.mTransfer) {
|
||||
if (it->second.mTransfer)
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "\tTicking mTransfer: " << (void*)it->second.mTransfer;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
(it->second.mTransfer)->tick();
|
||||
|
||||
|
||||
@ -146,7 +184,7 @@ void ftController::run()
|
||||
#endif
|
||||
if ((time(NULL) - (it->second).mCreateTime) > TIMOUT_CACHE_FILE_TRANSFER) {
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController::run() cache transfer to old. Cancelling transfer. Hash :" << (it->second).mHash;
|
||||
std::cerr << "ftController::run() cache transfer to old. Cancelling transfer. Hash :" << (it->second).mHash << ", time=" << (it->second).mCreateTime << ", now = " << time(NULL) ;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
this->FileCancel((it->second).mHash);
|
||||
@ -154,6 +192,10 @@ void ftController::run()
|
||||
}
|
||||
|
||||
}
|
||||
#ifdef CONTROL_DEBUG
|
||||
else
|
||||
std::cerr << "No mTransfer for this hash." << std::endl ;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -618,6 +660,7 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
||||
/* do a source search - for any extra sources */
|
||||
if (mSearch->search(hash, size,
|
||||
RS_FILE_HINTS_REMOTE |
|
||||
RS_FILE_HINTS_TURTLE |
|
||||
RS_FILE_HINTS_SPEC_ONLY, info))
|
||||
{
|
||||
/* do something with results */
|
||||
@ -729,7 +772,7 @@ bool ftController::setPeerState(ftTransferModule *tm, std::string id,
|
||||
#endif
|
||||
tm->setPeerState(id, PQIPEER_IDLE, maxrate);
|
||||
}
|
||||
else if (online)
|
||||
else if (online || mTurtle->isOnline(id))
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController::setPeerState()";
|
||||
@ -1087,6 +1130,9 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
|
||||
std::map<std::string, ftFileControl>::iterator it;
|
||||
std::list<pqipeer>::const_iterator pit;
|
||||
|
||||
std::list<pqipeer> vlist ;
|
||||
mTurtle->getVirtualPeersList(vlist) ;
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController::statusChange()";
|
||||
std::cerr << std::endl;
|
||||
@ -1126,6 +1172,40 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
|
||||
std::cerr << " had something happen to it: ";
|
||||
std::cerr << pit-> actions;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
setPeerState(it->second.mTransfer, pit->id, rate, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Now also look at turtle virtual peers.
|
||||
//
|
||||
for(pit = vlist.begin(); pit != vlist.end(); pit++)
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "Peer: " << pit->id;
|
||||
#endif
|
||||
if (pit->actions & RS_PEER_CONNECTED)
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << " is Newly Connected!";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
setPeerState(it->second.mTransfer, pit->id, rate, true);
|
||||
}
|
||||
else if (pit->actions & RS_PEER_DISCONNECTED)
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << " is Just disconnected!";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
setPeerState(it->second.mTransfer, pit->id, rate, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << " had something happen to it: ";
|
||||
std::cerr << pit-> actions;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
setPeerState(it->second.mTransfer, pit->id, rate, false);
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ class ftFileProvider;
|
||||
class ftSearch;
|
||||
class ftExtraList;
|
||||
class ftDataMultiplex;
|
||||
class p3turtle ;
|
||||
|
||||
#include "dbase/cachestrapper.h"
|
||||
#include "util/rsthreads.h"
|
||||
@ -114,6 +115,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
||||
ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string configDir);
|
||||
|
||||
void setFtSearchNExtra(ftSearch *, ftExtraList *);
|
||||
void setTurtleRouter(p3turtle *) ;
|
||||
bool activate();
|
||||
|
||||
virtual void run();
|
||||
@ -159,6 +161,7 @@ virtual bool CancelCacheFile(RsPeerId id, std::string path, std::string hash, ui
|
||||
/* pqiMonitor callback (also provided mConnMgr pointer!) */
|
||||
public:
|
||||
virtual void statusChange(const std::list<pqipeer> &plist);
|
||||
void addFileSource(const std::string& hash,const std::string& peer_id) ;
|
||||
|
||||
|
||||
/* p3Config Interface */
|
||||
@ -184,6 +187,7 @@ bool setPeerState(ftTransferModule *tm, std::string id,
|
||||
ftSearch *mSearch;
|
||||
ftDataMultiplex *mDataplex;
|
||||
ftExtraList *mExtraList;
|
||||
p3turtle *mTurtle ;
|
||||
|
||||
RsMutex ctrlMutex;
|
||||
|
||||
|
@ -413,7 +413,7 @@ bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider,
|
||||
std::string peerId, std::string hash, uint64_t size,
|
||||
uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
void *data = malloc(size);
|
||||
void *data = malloc(chunksize);
|
||||
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::locked_handleServerRequest()";
|
||||
|
@ -32,6 +32,7 @@ const int ftserverzone = 29539;
|
||||
#include "ft/ftcontroller.h"
|
||||
#include "ft/ftfileprovider.h"
|
||||
#include "ft/ftdatamultiplex.h"
|
||||
#include "turtle/p3turtle.h"
|
||||
|
||||
|
||||
// Includes CacheStrapper / FiMonitor / FiStore for us.
|
||||
@ -144,6 +145,13 @@ void ftServer::SetupFtServer(NotifyBase *cb)
|
||||
return;
|
||||
}
|
||||
|
||||
void ftServer::connectToTurtleRouter(p3turtle *fts)
|
||||
{
|
||||
mTurtleRouter = fts ;
|
||||
|
||||
mFtSearch->addSearchMode(fts, RS_FILE_HINTS_TURTLE);
|
||||
mFtController->setTurtleRouter(fts) ;
|
||||
}
|
||||
|
||||
void ftServer::StartupThreads()
|
||||
{
|
||||
@ -532,6 +540,10 @@ bool ftServer::loadConfigMap(std::map<std::string, std::string> &configMap)
|
||||
/* Client Send */
|
||||
bool ftServer::sendDataRequest(std::string peerId, std::string hash,
|
||||
uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
mTurtleRouter->sendDataRequest(peerId,hash,size,offset,chunksize) ;
|
||||
else
|
||||
{
|
||||
/* create a packet */
|
||||
/* push to networking part */
|
||||
@ -549,6 +561,7 @@ bool ftServer::sendDataRequest(std::string peerId, std::string hash,
|
||||
rfi->chunksize = chunksize; /* ftr->chunk; */
|
||||
|
||||
mP3iface->SendFileRequest(rfi);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -558,8 +571,7 @@ bool ftServer::sendDataRequest(std::string peerId, std::string hash,
|
||||
const uint32_t MAX_FT_CHUNK = 8 * 1024; /* 16K */
|
||||
|
||||
/* Server Send */
|
||||
bool ftServer::sendData(std::string peerId, std::string hash, uint64_t size,
|
||||
uint64_t baseoffset, uint32_t chunksize, void *data)
|
||||
bool ftServer::sendData(std::string peerId, std::string hash, uint64_t size, uint64_t baseoffset, uint32_t chunksize, void *data)
|
||||
{
|
||||
/* create a packet */
|
||||
/* push to networking part */
|
||||
@ -587,6 +599,10 @@ bool ftServer::sendData(std::string peerId, std::string hash, uint64_t size,
|
||||
|
||||
/******** New Serialiser Type *******/
|
||||
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
mTurtleRouter->sendFileData(peerId,hash,size,baseoffset+offset,chunk,&(((uint8_t *) data)[offset])) ;
|
||||
else
|
||||
{
|
||||
RsFileData *rfd = new RsFileData();
|
||||
|
||||
/* set id */
|
||||
@ -603,8 +619,9 @@ bool ftServer::sendData(std::string peerId, std::string hash, uint64_t size,
|
||||
rfd->fd.file_offset = baseoffset + offset;
|
||||
|
||||
/* file data */
|
||||
rfd->fd.binData.setBinData(
|
||||
&(((uint8_t *) data)[offset]), chunk);
|
||||
rfd->fd.binData.setBinData( &(((uint8_t *) data)[offset]), chunk);
|
||||
|
||||
mP3iface->SendFileData(rfd);
|
||||
|
||||
/* print the data pointer */
|
||||
#ifdef SERVER_DEBUG
|
||||
@ -615,9 +632,7 @@ bool ftServer::sendData(std::string peerId, std::string hash, uint64_t size,
|
||||
std::cerr << " data: " << rfd->fd.binData.bin_data;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
mP3iface->SendFileData(rfd);
|
||||
}
|
||||
|
||||
offset += chunk;
|
||||
tosend -= chunk;
|
||||
|
@ -50,7 +50,6 @@
|
||||
#include "pqi/pqi.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
|
||||
|
||||
class p3ConnectMgr;
|
||||
class p3AuthMgr;
|
||||
|
||||
@ -67,6 +66,7 @@ class ftExtraList;
|
||||
class ftFileSearch;
|
||||
|
||||
class ftDataMultiplex;
|
||||
class p3turtle;
|
||||
|
||||
class ftServer: public RsFiles, public ftDataSend, public RsThread
|
||||
{
|
||||
@ -94,6 +94,7 @@ std::string OwnId();
|
||||
/* Final Setup (once everything is assigned) */
|
||||
//void SetupFtServer();
|
||||
void SetupFtServer(NotifyBase *cb);
|
||||
void connectToTurtleRouter(p3turtle *p) ;
|
||||
|
||||
void StartupThreads();
|
||||
|
||||
@ -105,6 +106,11 @@ virtual void run();
|
||||
/************** (Implements RsFiles) ***************************/
|
||||
/***************************************************************/
|
||||
|
||||
// member access
|
||||
|
||||
ftDataMultiplex *getMultiplexer() const { return mFtDataplex ; }
|
||||
ftController *getController() const { return mFtController ; }
|
||||
|
||||
/***
|
||||
* Control of Downloads
|
||||
***/
|
||||
@ -227,6 +233,7 @@ bool loadConfigMap(std::map<std::string, std::string> &configMap);
|
||||
ftExtraList *mFtExtra;
|
||||
|
||||
ftDataMultiplex *mFtDataplex;
|
||||
p3turtle *mTurtleRouter ;
|
||||
|
||||
|
||||
ftFileSearch *mFtSearch;
|
||||
|
@ -422,6 +422,7 @@ bool ftTransferModule::completeFileTransfer()
|
||||
|
||||
int ftTransferModule::tick()
|
||||
{
|
||||
queryInactive();
|
||||
#ifdef FT_DEBUG
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
@ -444,9 +445,6 @@ int ftTransferModule::tick()
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
queryInactive();
|
||||
|
||||
uint32_t flags = 0;
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
|
@ -5,24 +5,29 @@ CONFIG += release
|
||||
|
||||
################################# Linux ##########################################
|
||||
|
||||
profiling {
|
||||
QMAKE_CXXFLAGS -= -fomit-frame-pointer
|
||||
QMAKE_CXXFLAGS *= -pg -g -fno-omit-frame-pointer
|
||||
}
|
||||
|
||||
debug {
|
||||
DEFINES *= DEBUG
|
||||
# DEFINES *= OPENDHT_DEBUG DHT_DEBUG CONN_DEBUG DEBUG_UDP_SORTER P3DISC_DEBUG DEBUG_UDP_LAYER FT_DEBUG EXTADDRSEARCH_DEBUG
|
||||
# DEFINES *= P3TURTLE_DEBUG CHAT_DEBUG
|
||||
DEFINES *= CHAT_DEBUG
|
||||
# DEFINES *= CHAT_DEBUG
|
||||
DEFINES *= P3TURTLE_DEBUG CONTROL_DEBUG FT_DEBUG
|
||||
QMAKE_CXXFLAGS *= -g
|
||||
}
|
||||
|
||||
linux-g++ {
|
||||
OBJECTS_DIR = temp/linux-g++/obj
|
||||
DESTDIR = lib.linux-g++
|
||||
QMAKE_CXXFLAGS *= -fomit-frame-pointer -Wall
|
||||
QMAKE_CXXFLAGS *= -Wall
|
||||
QMAKE_CC = g++
|
||||
}
|
||||
linux-g++-64 {
|
||||
OBJECTS_DIR = temp/linux-g++-64/obj
|
||||
DESTDIR = lib.linux-g++-64
|
||||
QMAKE_CXXFLAGS *= -fomit-frame-pointer -Wall
|
||||
QMAKE_CXXFLAGS *= -Wall
|
||||
QMAKE_CC = g++
|
||||
}
|
||||
#################### Cross compilation for windows under Linux ####################
|
||||
@ -30,7 +35,7 @@ linux-g++-64 {
|
||||
win32-x-g++ {
|
||||
OBJECTS_DIR = temp/win32xgcc/obj
|
||||
DESTDIR = lib.win32xgcc
|
||||
DEFINES *= WINDOWS_SYS WIN32
|
||||
DEFINES *= WINDOWS_SYS WIN32 WIN_CROSS_UBUNTU
|
||||
QMAKE_CXXFLAGS *= -Wmissing-include-dirs
|
||||
QMAKE_CC = i586-mingw32msvc-g++
|
||||
QMAKE_LIB = i586-mingw32msvc-ar
|
||||
@ -202,7 +207,9 @@ HEADERS += dbase/cachestrapper.h \
|
||||
services/p3ranking.h \
|
||||
services/p3service.h \
|
||||
services/p3status.h \
|
||||
services/p3turtle.h \
|
||||
turtle/p3turtle.h \
|
||||
turtle/turtletypes.h \
|
||||
turtle/rsturtleitem.h \
|
||||
tcponudp/extaddrfinder.h \
|
||||
tcponudp/bio_tou.h \
|
||||
tcponudp/tcppacket.h \
|
||||
@ -266,7 +273,8 @@ SOURCES = \
|
||||
services/p3msgservice.cc \
|
||||
services/p3chatservice.cc \
|
||||
services/p3service.cc \
|
||||
services/p3turtle.cc \
|
||||
turtle/p3turtle.cc \
|
||||
turtle/rsturtleitem.cc \
|
||||
dbase/rsexpr.cc \
|
||||
dbase/cachestrapper.cc \
|
||||
dbase/fistore.cc \
|
||||
|
@ -68,6 +68,7 @@ const uint32_t RS_FILE_HINTS_LOCAL = 0x00000004;
|
||||
const uint32_t RS_FILE_HINTS_REMOTE = 0x00000008;
|
||||
const uint32_t RS_FILE_HINTS_DOWNLOAD= 0x00000010;
|
||||
const uint32_t RS_FILE_HINTS_UPLOAD = 0x00000020;
|
||||
const uint32_t RS_FILE_HINTS_TURTLE = 0x00000040;
|
||||
|
||||
|
||||
const uint32_t RS_FILE_HINTS_SPEC_ONLY = 0x01000000;
|
||||
|
@ -71,7 +71,7 @@ class RsTurtle
|
||||
// tunnels. Launches an exception if an error occurs during the
|
||||
// initialization process.
|
||||
//
|
||||
virtual void turtleDownload(const std::string& file_hash) = 0 ;
|
||||
virtual void turtleDownload(const std::string& name,const std::string& file_hash,uint64_t size) = 0 ;
|
||||
|
||||
// Sets the file sharing strategy. It concerns all local files. It would
|
||||
// be better to handle this for each file, of course.
|
||||
|
@ -61,7 +61,7 @@ RsTurtle *rsTurtle = NULL ;
|
||||
#include "services/p3channels.h"
|
||||
#include "services/p3status.h"
|
||||
#include "services/p3Qblog.h"
|
||||
#include "services/p3turtle.h"
|
||||
#include "turtle/p3turtle.h"
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
@ -171,10 +171,6 @@ RsControl *createRsControl(RsIface &iface, NotifyBase ¬ify)
|
||||
// delete config;
|
||||
//}
|
||||
|
||||
static std::string getHomePath();
|
||||
|
||||
|
||||
|
||||
void RsInit::InitRsConfig()
|
||||
{
|
||||
load_trustedpeer = false;
|
||||
@ -720,9 +716,10 @@ int RsServer::StartupRetroShare()
|
||||
msgSrv = new p3MsgService(mConnMgr);
|
||||
chatSrv = new p3ChatService(mConnMgr);
|
||||
|
||||
p3turtle *tr = new p3turtle(mConnMgr) ;
|
||||
p3turtle *tr = new p3turtle(mConnMgr,ftserver) ;
|
||||
rsTurtle = tr ;
|
||||
pqih -> addService(tr);
|
||||
ftserver->connectToTurtleRouter(tr) ;
|
||||
|
||||
pqih -> addService(ad);
|
||||
pqih -> addService(msgSrv);
|
||||
|
@ -76,8 +76,8 @@ virtual void clear() = 0;
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0;
|
||||
|
||||
/* source / destination id */
|
||||
std::string PeerId() { return peerId; }
|
||||
void PeerId(std::string id) { peerId = id; }
|
||||
const std::string& PeerId() const { return peerId; }
|
||||
void PeerId(const std::string& id) { peerId = id; }
|
||||
|
||||
/* complete id */
|
||||
uint32_t PacketId();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -153,158 +153,16 @@
|
||||
#include "pqi/pqi.h"
|
||||
#include "pqi/pqimonitor.h"
|
||||
#include "services/p3service.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "ft/ftsearch.h"
|
||||
#include "rsiface/rsturtle.h"
|
||||
#include "rsturtleitem.h"
|
||||
|
||||
class ftServer ;
|
||||
class p3AuthMgr;
|
||||
class p3ConnectMgr;
|
||||
|
||||
const uint8_t RS_TURTLE_SUBTYPE_SEARCH_REQUEST = 0x01 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_SEARCH_RESULT = 0x02 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_OPEN_TUNNEL = 0x03 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_TUNNEL_OK = 0x04 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_CLOSE_TUNNEL = 0x05 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_TUNNEL_CLOSED = 0x06 ;
|
||||
|
||||
class ftDataMultiplex;
|
||||
static const int TURTLE_MAX_SEARCH_DEPTH = 6 ;
|
||||
|
||||
typedef std::string TurtlePeerId ;
|
||||
typedef std::string TurtleFileHash ;
|
||||
typedef std::string TurtleFileName ;
|
||||
typedef TurtleRequestId TurtleSearchRequestId ;
|
||||
|
||||
typedef uint32_t TurtleTunnelRequestId ;
|
||||
typedef uint32_t TurtleTunnelId ;
|
||||
|
||||
class RsTurtleItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsTurtleItem(uint8_t turtle_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TURTLE,turtle_subtype) {}
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialize themselves ?
|
||||
virtual uint32_t serial_size() = 0 ; // deserialise is handled using a constructor
|
||||
|
||||
virtual void clear() {}
|
||||
};
|
||||
|
||||
class RsTurtleSearchResultItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleSearchResultItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_SEARCH_RESULT) {}
|
||||
RsTurtleSearchResultItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
uint16_t depth ;
|
||||
uint8_t peer_id[16]; // peer id. This will eventually be obfuscated in some way.
|
||||
|
||||
TurtleSearchRequestId request_id ; // randomly generated request id.
|
||||
|
||||
std::list<TurtleFileInfo> result ;
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleSearchRequestItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleSearchRequestItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_SEARCH_REQUEST) {}
|
||||
RsTurtleSearchRequestItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
std::string match_string ; // string to match
|
||||
uint32_t request_id ; // randomly generated request id.
|
||||
uint16_t depth ; // Used for limiting search depth.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleOpenTunnelItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleOpenTunnelItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_OPEN_TUNNEL) {}
|
||||
RsTurtleOpenTunnelItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
TurtleFileHash file_hash ; // hash to match
|
||||
uint32_t request_id ; // randomly generated request id.
|
||||
uint32_t partial_tunnel_id ; // uncomplete tunnel id. Will be completed at destination.
|
||||
uint16_t depth ; // Used for limiting search depth.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleTunnelOkItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleTunnelOkItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_TUNNEL_OK) {}
|
||||
RsTurtleTunnelOkItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
uint32_t tunnel_id ; // id of the tunnel. Should be identical for a tunnel between two same peers for the same hash.
|
||||
uint32_t request_id ; // randomly generated request id corresponding to the intial request.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleCloseTunnelItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleCloseTunnelItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_CLOSE_TUNNEL) {}
|
||||
RsTurtleCloseTunnelItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
uint32_t tunnel_id ; // id of the tunnel to close.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleTunnelClosedItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleTunnelClosedItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_TUNNEL_CLOSED) {}
|
||||
RsTurtleTunnelClosedItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
uint32_t tunnel_id ; // id of the tunnel to close.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
|
||||
// Class responsible for serializing/deserializing all turtle items.
|
||||
//
|
||||
class RsTurtleSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsTurtleSerialiser() : RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_TURTLE) {}
|
||||
|
||||
virtual uint32_t size (RsItem *item)
|
||||
{
|
||||
return static_cast<RsTurtleItem *>(item)->serial_size() ;
|
||||
}
|
||||
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
return static_cast<RsTurtleItem *>(item)->serialize(data,*size) ;
|
||||
}
|
||||
virtual RsItem *deserialise (void *data, uint32_t *size) ;
|
||||
};
|
||||
|
||||
// This class is used to keep trace of requests (searches and tunnels).
|
||||
//
|
||||
class TurtleRequestInfo
|
||||
@ -319,6 +177,8 @@ class TurtleTunnel
|
||||
public:
|
||||
TurtlePeerId local_src ; // where packets come from. Direction to the source.
|
||||
TurtlePeerId local_dst ; // where packets should go. Direction to the destination.
|
||||
TurtleFileHash hash; // for starting and ending tunnels only. Null otherwise.
|
||||
TurtleVirtualPeerId vpid; // same, but contains the virtual peer id for this tunnel.
|
||||
uint32_t time_stamp ; // last time the tunnel was actually used. Used for cleaning old tunnels.
|
||||
};
|
||||
|
||||
@ -327,14 +187,17 @@ class TurtleTunnel
|
||||
class TurtleFileHashInfo
|
||||
{
|
||||
public:
|
||||
std::list<TurtleTunnelId> tunnels ; // list of active tunnel ids for this file hash
|
||||
std::vector<TurtleTunnelId> tunnels ; // list of active tunnel ids for this file hash
|
||||
TurtleRequestId last_request ; // last request for the tunnels of this hash
|
||||
|
||||
TurtleFileName name ;
|
||||
uint64_t size ;
|
||||
};
|
||||
|
||||
class p3turtle: public p3Service, public pqiMonitor, public RsTurtle
|
||||
class p3turtle: public p3Service, public pqiMonitor, public RsTurtle, public ftSearch
|
||||
{
|
||||
public:
|
||||
p3turtle(p3ConnectMgr *cm);
|
||||
p3turtle(p3ConnectMgr *cm,ftServer *m);
|
||||
|
||||
// Lauches a search request through the pipes, and immediately returns
|
||||
// the request id, which will be further used by the gui to store results
|
||||
@ -351,7 +214,7 @@ class p3turtle: public p3Service, public pqiMonitor, public RsTurtle
|
||||
// - send the file request to the file transfer module
|
||||
// - populate the file transfer module with the adequate pqi interface and search module.
|
||||
//
|
||||
virtual void turtleDownload(const std::string& file_hash) ;
|
||||
virtual void turtleDownload(const std::string& name,const std::string& file_hash,uint64_t size) ;
|
||||
|
||||
/************* from pqiMonitor *******************/
|
||||
// Informs the turtle router that some peers are (dis)connected. This should initiate digging new tunnels,
|
||||
@ -369,6 +232,30 @@ class p3turtle: public p3Service, public pqiMonitor, public RsTurtle
|
||||
//
|
||||
virtual int tick();
|
||||
|
||||
/************* from ftSearch *******************/
|
||||
// Search function. This function looks into the file hashes currently handled , and sends back info.
|
||||
//
|
||||
virtual bool search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info) const ;
|
||||
|
||||
/************* Communication with ftserver *******************/
|
||||
// Does the turtle router manages tunnels to this peer ? (this is not a
|
||||
// real id, but a fake one, that the turtle router is capable of connecting with a tunnel id).
|
||||
bool isTurtlePeer(const std::string& peer_id) const ;
|
||||
|
||||
// Examines the peer id, finds the turtle tunnel in it, and respond yes if the tunnel is ok and operational.
|
||||
bool isOnline(const std::string& peer_id) const ;
|
||||
|
||||
// Returns a unique peer id, corresponding to the given tunnel.
|
||||
std::string getTurtlePeerId(TurtleTunnelId tid) const ;
|
||||
|
||||
// returns the list of virtual peers for all tunnels.
|
||||
void getVirtualPeersList(std::list<pqipeer>& list) ;
|
||||
|
||||
// Send a data request into the correct tunnel for the given file hash
|
||||
void sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize) ;
|
||||
|
||||
// Send file data into the correct tunnel for the given file hash
|
||||
void sendFileData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t baseoffset, uint32_t chunksize, void *data) ;
|
||||
private:
|
||||
//--------------------------- Admin/Helper functions -------------------------//
|
||||
|
||||
@ -380,6 +267,7 @@ class p3turtle: public p3Service, public pqiMonitor, public RsTurtle
|
||||
//------------------------------ Tunnel handling -----------------------------//
|
||||
|
||||
TurtleRequestId diggTunnel(const TurtleFileHash& hash) ; /// initiates tunnels from here to any peers having the given file hash
|
||||
void addDistantPeer(const TurtleFileHash&, TurtleTunnelId) ; /// adds info related to a new virtual peer.
|
||||
|
||||
//----------------------------- Routing functions ----------------------------//
|
||||
|
||||
@ -390,6 +278,8 @@ class p3turtle: public p3Service, public pqiMonitor, public RsTurtle
|
||||
void handleSearchResult(RsTurtleSearchResultItem *item);
|
||||
void handleTunnelRequest(RsTurtleOpenTunnelItem *item);
|
||||
void handleTunnelResult(RsTurtleTunnelOkItem *item);
|
||||
void handleRecvFileRequest(RsTurtleFileRequestItem *item);
|
||||
void handleRecvFileData(RsTurtleFileDataItem *item);
|
||||
|
||||
//------ Functions connecting the turtle router to other components.----------//
|
||||
|
||||
@ -400,25 +290,31 @@ class p3turtle: public p3Service, public pqiMonitor, public RsTurtle
|
||||
void returnSearchResult(RsTurtleSearchResultItem *item) ;
|
||||
|
||||
// Returns true if the file with given hash is hosted locally.
|
||||
bool performLocalHashSearch(const TurtleFileHash& hash) ;
|
||||
bool performLocalHashSearch(const TurtleFileHash& hash,FileInfo& info) ;
|
||||
|
||||
//--------------------------- Local variables --------------------------------//
|
||||
|
||||
/* data */
|
||||
p3ConnectMgr *mConnMgr;
|
||||
ftServer *_ft_server ;
|
||||
ftController *_ft_controller ;
|
||||
|
||||
RsMutex mTurtleMtx;
|
||||
mutable RsMutex mTurtleMtx;
|
||||
|
||||
std::map<TurtleSearchRequestId,TurtleRequestInfo> _search_requests_origins ; /// keeps trace of who emmitted a given search request
|
||||
std::map<TurtleTunnelRequestId,TurtleRequestInfo> _tunnel_requests_origins ; /// keeps trace of who emmitted a tunnel request
|
||||
|
||||
std::map<TurtleFileHash,TurtleFileHashInfo> _file_hashes_tunnels ; /// stores adequate tunnels for each file hash locally asked
|
||||
std::map<TurtleFileHash,TurtleFileHashInfo> _incoming_file_hashes ; /// stores adequate tunnels for each file hash locally managed
|
||||
std::map<TurtleFileHash,FileInfo> _outgoing_file_hashes ; /// stores file info for each file we provide.
|
||||
|
||||
std::map<TurtleTunnelId,TurtleTunnel > _local_tunnels ; /// local tunnels, stored by ids (Either transiting or ending).
|
||||
|
||||
std::map<TurtleVirtualPeerId,TurtleTunnelId> _virtual_peers ; /// Peers corresponding to each tunnel.
|
||||
|
||||
time_t _last_clean_time ;
|
||||
time_t _last_tunnel_management_time ;
|
||||
|
||||
std::list<pqipeer> _online_peers;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
void dumpState() ;
|
||||
#endif
|
619
libretroshare/src/turtle/rsturtleitem.cc
Normal file
619
libretroshare/src/turtle/rsturtleitem.cc
Normal file
@ -0,0 +1,619 @@
|
||||
#ifndef WINDOWS_SYS
|
||||
#include <stdexcept>
|
||||
#endif
|
||||
#include <iostream>
|
||||
#include "turtletypes.h"
|
||||
#include "rsturtleitem.h"
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
// -------------------------------- Serialization. --------------------------------- //
|
||||
// -----------------------------------------------------------------------------------//
|
||||
//
|
||||
|
||||
//
|
||||
// ---------------------------------- Packet sizes -----------------------------------//
|
||||
//
|
||||
uint32_t RsTurtleSearchRequestItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += GetTlvStringSize(match_string) ;
|
||||
s += 4 ; // request_id
|
||||
s += 2 ; // depth
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleSearchResultItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += 4 ; // search request id
|
||||
s += 2 ; // depth
|
||||
s += 4 ; // number of results
|
||||
|
||||
for(std::list<TurtleFileInfo>::const_iterator it(result.begin());it!=result.end();++it)
|
||||
{
|
||||
s += 8 ; // file size
|
||||
s += GetTlvStringSize(it->hash) ; // file hash
|
||||
s += GetTlvStringSize(it->name) ; // file name
|
||||
}
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleOpenTunnelItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += GetTlvStringSize(file_hash) ; // file hash
|
||||
s += 4 ; // tunnel request id
|
||||
s += 4 ; // partial tunnel id
|
||||
s += 2 ; // depth
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleTunnelOkItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
s += 4 ; // tunnel request id
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleFileRequestItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
s += 8 ; // file offset
|
||||
s += 4 ; // chunk size
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleFileDataItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
s += 8 ; // file offset
|
||||
s += 4 ; // chunk size
|
||||
s += chunk_size ; // actual data size.
|
||||
|
||||
return s ;
|
||||
}
|
||||
//
|
||||
// ---------------------------------- Serialization ----------------------------------//
|
||||
//
|
||||
RsItem *RsTurtleSerialiser::deserialise(void *data, uint32_t *size)
|
||||
{
|
||||
// look what we have...
|
||||
|
||||
/* get the type */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "p3turtle: deserialising packet: " << std::endl ;
|
||||
#endif
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TURTLE != getRsItemService(rstype)))
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Wrong type !!" << std::endl ;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
#ifndef WINDOWS_SYS
|
||||
try
|
||||
{
|
||||
#endif
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_TURTLE_SUBTYPE_SEARCH_REQUEST: return new RsTurtleSearchRequestItem(data,*size) ;
|
||||
case RS_TURTLE_SUBTYPE_SEARCH_RESULT: return new RsTurtleSearchResultItem(data,*size) ;
|
||||
case RS_TURTLE_SUBTYPE_OPEN_TUNNEL : return new RsTurtleOpenTunnelItem(data,*size) ;
|
||||
case RS_TURTLE_SUBTYPE_TUNNEL_OK : return new RsTurtleTunnelOkItem(data,*size) ;
|
||||
case RS_TURTLE_SUBTYPE_FILE_REQUEST : return new RsTurtleFileRequestItem(data,*size) ;
|
||||
case RS_TURTLE_SUBTYPE_FILE_DATA : return new RsTurtleFileDataItem(data,*size) ;
|
||||
|
||||
default:
|
||||
std::cerr << "Unknown packet type in RsTurtle!" << std::endl ;
|
||||
return NULL ;
|
||||
}
|
||||
#ifndef WINDOWS_SYS
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception raised: " << e.what() << std::endl ;
|
||||
return NULL ;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
bool RsTurtleSearchRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, match_string);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, request_id);
|
||||
ok &= setRawUInt16(data, tlvsize, &offset, depth);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsTurtleSearchRequestItem::RsTurtleSearchRequestItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleItem(RS_TURTLE_SUBTYPE_SEARCH_REQUEST)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = search request" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_VALUE, match_string); // file hash
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &request_id);
|
||||
ok &= getRawUInt16(data, pktsize, &offset, &depth);
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != rssize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RsTurtleSearchResultItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, request_id);
|
||||
ok &= setRawUInt16(data, tlvsize, &offset, depth);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, result.size());
|
||||
|
||||
for(std::list<TurtleFileInfo>::const_iterator it(result.begin());it!=result.end();++it)
|
||||
{
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, it->size); // file size
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_SHA1, it->hash); // file hash
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, it->name); // file name
|
||||
}
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsTurtleSearchResultItem::RsTurtleSearchResultItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleItem(RS_TURTLE_SUBTYPE_SEARCH_RESULT)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = search result" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
uint32_t s ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &request_id);
|
||||
ok &= getRawUInt16(data, pktsize, &offset, &depth);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &s) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " request_id=" << request_id << ", depth=" << depth << ", s=" << s << std::endl ;
|
||||
#endif
|
||||
|
||||
result.clear() ;
|
||||
|
||||
for(int i=0;i<(int)s;++i)
|
||||
{
|
||||
TurtleFileInfo f ;
|
||||
|
||||
ok &= getRawUInt64(data, pktsize, &offset, &(f.size)); // file size
|
||||
ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_HASH_SHA1, f.hash); // file hash
|
||||
ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_NAME, f.name); // file name
|
||||
|
||||
result.push_back(f) ;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != rssize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RsTurtleOpenTunnelItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_SHA1, file_hash); // file hash
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, request_id);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, partial_tunnel_id);
|
||||
ok &= setRawUInt16(data, tlvsize, &offset, depth);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsTurtleOpenTunnelItem::serialiseTransfer() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsTurtleOpenTunnelItem::RsTurtleOpenTunnelItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleItem(RS_TURTLE_SUBTYPE_OPEN_TUNNEL)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = open tunnel" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_HASH_SHA1, file_hash); // file hash
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &request_id);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &partial_tunnel_id) ;
|
||||
ok &= getRawUInt16(data, pktsize, &offset, &depth);
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " request_id=" << (void*)request_id << ", partial_id=" << (void*)partial_tunnel_id << ", depth=" << depth << ", hash=" << file_hash << std::endl ;
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != rssize)
|
||||
throw std::runtime_error("RsTurtleOpenTunnelItem::() error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("RsTurtleOpenTunnelItem::() unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RsTurtleTunnelOkItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, request_id);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsTurtleTunnelOkItem::serialiseTransfer() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsTurtleTunnelOkItem::RsTurtleTunnelOkItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleItem(RS_TURTLE_SUBTYPE_TUNNEL_OK)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = tunnel ok" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &request_id);
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " request_id=" << (void*)request_id << ", tunnel_id=" << (void*)tunnel_id << std::endl ;
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != rssize)
|
||||
throw std::runtime_error("RsTurtleTunnelOkItem::() error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("RsTurtleTunnelOkItem::() unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RsTurtleFileRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id) ;
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, chunk_offset);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, chunk_size);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsTurtleTunnelOkItem::serialiseTransfer() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsTurtleFileRequestItem::RsTurtleFileRequestItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleItem(RS_TURTLE_SUBTYPE_FILE_REQUEST)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file request" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id) ;
|
||||
ok &= getRawUInt64(data, pktsize, &offset, &chunk_offset);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &chunk_size);
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " tunnel_id=" << (void*)tunnel_id << ", chunk_offset=" << chunk_offset << ", chunk_size=" << chunk_size << std::endl ;
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != rssize)
|
||||
throw std::runtime_error("RsTurtleTunnelOkItem::() error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("RsTurtleTunnelOkItem::() unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
|
||||
RsTurtleFileDataItem::~RsTurtleFileDataItem()
|
||||
{
|
||||
free(chunk_data) ;
|
||||
}
|
||||
RsTurtleFileDataItem::RsTurtleFileDataItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleItem(RS_TURTLE_SUBTYPE_FILE_DATA)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file request" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id) ;
|
||||
ok &= getRawUInt64(data, pktsize, &offset, &chunk_offset);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &chunk_size);
|
||||
|
||||
chunk_data = (void*)malloc(chunk_size) ;
|
||||
memcpy(chunk_data,(void*)((unsigned char*)data+offset),chunk_size) ;
|
||||
|
||||
offset += chunk_size ;
|
||||
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " tunnel_id=" << (void*)tunnel_id << ", chunk_offset=" << chunk_offset << ", chunk_size=" << chunk_size << std::endl ;
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != rssize)
|
||||
throw std::runtime_error("RsTurtleFileDataItem::() error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("RsTurtleFileDataItem::() unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RsTurtleFileDataItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id) ;
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, chunk_offset);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, chunk_size);
|
||||
|
||||
memcpy((void*)((unsigned char*)data+offset),chunk_data,chunk_size) ;
|
||||
offset += chunk_size ;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsTurtleTunnelOkItem::serialiseTransfer() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
// -----------------------------------------------------------------------------------//
|
||||
// ------------------------------------- IO --------------------------------------- //
|
||||
// -----------------------------------------------------------------------------------//
|
||||
//
|
||||
std::ostream& RsTurtleSearchRequestItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "Search request:" << std::endl ;
|
||||
o << " direct origin: \"" << PeerId() << "\"" << std::endl ;
|
||||
o << " match string: \"" << match_string << "\"" << std::endl ;
|
||||
o << " Req. Id: " << (void *)request_id << std::endl ;
|
||||
o << " Depth : " << depth << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
|
||||
std::ostream& RsTurtleSearchResultItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "Search result:" << std::endl ;
|
||||
|
||||
o << " Peer id: " << PeerId() << std::endl ;
|
||||
o << " Depth : " << depth << std::endl ;
|
||||
o << " Req. Id: " << (void *)request_id << std::endl ;
|
||||
o << " Files:" << std::endl ;
|
||||
|
||||
for(std::list<TurtleFileInfo>::const_iterator it(result.begin());it!=result.end();++it)
|
||||
o << " " << it->hash << " " << it->size << " " << it->name << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
|
||||
std::ostream& RsTurtleOpenTunnelItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "Open Tunnel:" << std::endl ;
|
||||
|
||||
o << " Peer id : " << PeerId() << std::endl ;
|
||||
o << " Partial tId: " << (void *)partial_tunnel_id << std::endl ;
|
||||
o << " Req. Id : " << (void *)request_id << std::endl ;
|
||||
o << " Depth : " << depth << std::endl ;
|
||||
o << " Hash : " << file_hash << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
|
||||
std::ostream& RsTurtleTunnelOkItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "Tunnel Ok:" << std::endl ;
|
||||
|
||||
o << " Peer id : " << PeerId() << std::endl ;
|
||||
o << " tunnel id : " << (void*)tunnel_id << std::endl ;
|
||||
o << " Req. Id : " << (void *)request_id << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
|
||||
std::ostream& RsTurtleFileRequestItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "File request item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << (void*)tunnel_id << std::endl ;
|
||||
o << " offset : " << chunk_offset << std::endl ;
|
||||
o << " chunk size: " << chunk_size << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
|
||||
std::ostream& RsTurtleFileDataItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "File request item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << (void*)tunnel_id << std::endl ;
|
||||
o << " offset : " << chunk_offset << std::endl ;
|
||||
o << " chunk size: " << chunk_size << std::endl ;
|
||||
o << " data : " << (void*)chunk_data << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
|
180
libretroshare/src/turtle/rsturtleitem.h
Normal file
180
libretroshare/src/turtle/rsturtleitem.h
Normal file
@ -0,0 +1,180 @@
|
||||
#pragma once
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "rsiface/rsturtle.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "turtle/turtletypes.h"
|
||||
|
||||
const uint8_t RS_TURTLE_SUBTYPE_SEARCH_REQUEST = 0x01 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_SEARCH_RESULT = 0x02 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_OPEN_TUNNEL = 0x03 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_TUNNEL_OK = 0x04 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_CLOSE_TUNNEL = 0x05 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_TUNNEL_CLOSED = 0x06 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_FILE_REQUEST = 0x07 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_FILE_DATA = 0x08 ;
|
||||
|
||||
class RsTurtleItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsTurtleItem(uint8_t turtle_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TURTLE,turtle_subtype) {}
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialize themselves ?
|
||||
virtual uint32_t serial_size() = 0 ; // deserialise is handled using a constructor
|
||||
|
||||
virtual void clear() {}
|
||||
};
|
||||
|
||||
class RsTurtleSearchResultItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleSearchResultItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_SEARCH_RESULT) {}
|
||||
RsTurtleSearchResultItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
uint16_t depth ;
|
||||
uint8_t peer_id[16]; // peer id. This will eventually be obfuscated in some way.
|
||||
|
||||
TurtleSearchRequestId request_id ; // randomly generated request id.
|
||||
|
||||
std::list<TurtleFileInfo> result ;
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleSearchRequestItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleSearchRequestItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_SEARCH_REQUEST) {}
|
||||
RsTurtleSearchRequestItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
std::string match_string ; // string to match
|
||||
uint32_t request_id ; // randomly generated request id.
|
||||
uint16_t depth ; // Used for limiting search depth.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleOpenTunnelItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleOpenTunnelItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_OPEN_TUNNEL) {}
|
||||
RsTurtleOpenTunnelItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
TurtleFileHash file_hash ; // hash to match
|
||||
uint32_t request_id ; // randomly generated request id.
|
||||
uint32_t partial_tunnel_id ; // uncomplete tunnel id. Will be completed at destination.
|
||||
uint16_t depth ; // Used for limiting search depth.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleTunnelOkItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleTunnelOkItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_TUNNEL_OK) {}
|
||||
RsTurtleTunnelOkItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
uint32_t tunnel_id ; // id of the tunnel. Should be identical for a tunnel between two same peers for the same hash.
|
||||
uint32_t request_id ; // randomly generated request id corresponding to the intial request.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleCloseTunnelItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleCloseTunnelItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_CLOSE_TUNNEL) {}
|
||||
RsTurtleCloseTunnelItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
uint32_t tunnel_id ; // id of the tunnel to close.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleTunnelClosedItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleTunnelClosedItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_TUNNEL_CLOSED) {}
|
||||
RsTurtleTunnelClosedItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
uint32_t tunnel_id ; // id of the tunnel to close.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleFileRequestItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleFileRequestItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_FILE_REQUEST) {}
|
||||
RsTurtleFileRequestItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
uint32_t tunnel_id ; // id of the tunnel to travel through
|
||||
uint64_t chunk_offset ;
|
||||
uint32_t chunk_size ;
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleFileDataItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleFileDataItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_FILE_DATA) {}
|
||||
~RsTurtleFileDataItem() ;
|
||||
RsTurtleFileDataItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
uint32_t tunnel_id ; // id of the tunnel to travel through
|
||||
uint64_t chunk_offset ; // offset in the file
|
||||
uint32_t chunk_size ; // size of the file chunk
|
||||
void *chunk_data ; // actual data.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
// Class responsible for serializing/deserializing all turtle items.
|
||||
//
|
||||
class RsTurtleSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsTurtleSerialiser() : RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_TURTLE) {}
|
||||
|
||||
virtual uint32_t size (RsItem *item)
|
||||
{
|
||||
return static_cast<RsTurtleItem *>(item)->serial_size() ;
|
||||
}
|
||||
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
return static_cast<RsTurtleItem *>(item)->serialize(data,*size) ;
|
||||
}
|
||||
virtual RsItem *deserialise (void *data, uint32_t *size) ;
|
||||
};
|
||||
|
15
libretroshare/src/turtle/turtletypes.h
Normal file
15
libretroshare/src/turtle/turtletypes.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "rsiface/rsturtle.h"
|
||||
|
||||
typedef std::string TurtlePeerId ;
|
||||
typedef std::string TurtleVirtualPeerId ;
|
||||
typedef std::string TurtleFileHash ;
|
||||
typedef std::string TurtleFileName ;
|
||||
|
||||
typedef TurtleRequestId TurtleSearchRequestId ;
|
||||
|
||||
typedef uint32_t TurtleTunnelRequestId ;
|
||||
typedef uint32_t TurtleTunnelId ;
|
||||
|
||||
|
@ -264,7 +264,7 @@ void TurtleSearchDialog::download()
|
||||
<< (item->text(SR_HASH_COL)).toStdString() << "-"
|
||||
<< (item->text(SR_REALSIZE_COL)).toInt() << std::endl ;
|
||||
|
||||
rsTurtle->turtleDownload(item->text(SR_HASH_COL).toStdString()) ;
|
||||
rsTurtle->turtleDownload(item->text(SR_NAME_COL).toStdString(),item->text(SR_HASH_COL).toStdString(),item->text(SR_REALSIZE_COL).toInt()) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ class RsTurtle
|
||||
// tunnels. Launches an exception if an error occurs during the
|
||||
// initialization process.
|
||||
//
|
||||
virtual void turtleDownload(const std::string& file_hash) = 0 ;
|
||||
virtual void turtleDownload(const std::string& name,const std::string& file_hash,uint64_t size) = 0 ;
|
||||
|
||||
// Sets the file sharing strategy. It concerns all local files. It would
|
||||
// be better to handle this for each file, of course.
|
||||
|
Loading…
Reference in New Issue
Block a user