mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
Merged branch v0.5-GenericTunneling into trunk (Rev. 6284 to 6410).
- adds turtle router as a generic tunneling service - made ftServer a client of the service. Now turtle file items are handled in ftServer - added new client: p3MsgService to send/recv pgp-encrypted distant messages - added new client: p3ChatService to perform private (AES-encrypted) distant chat through tunnels. - The GUI is disabled for now, since it needs some polishing before being fully usable. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6411 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
commit
dc2521cf71
62 changed files with 5031 additions and 1989 deletions
|
@ -47,6 +47,7 @@
|
|||
#include "ft/ftsearch.h"
|
||||
#include "ft/ftdatamultiplex.h"
|
||||
#include "ft/ftextralist.h"
|
||||
#include "ft/ftserver.h"
|
||||
|
||||
#include "turtle/p3turtle.h"
|
||||
|
||||
|
@ -102,6 +103,7 @@ ftController::ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string /
|
|||
last_clean_time(0),
|
||||
mDataplex(dm),
|
||||
mTurtle(NULL),
|
||||
mFtServer(NULL),
|
||||
ctrlMutex("ftController"),
|
||||
doneMutex("ftController"),
|
||||
mFtActive(false),
|
||||
|
@ -112,10 +114,9 @@ ftController::ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string /
|
|||
/* TODO */
|
||||
}
|
||||
|
||||
void ftController::setTurtleRouter(p3turtle *pt)
|
||||
{
|
||||
mTurtle = pt ;
|
||||
}
|
||||
void ftController::setTurtleRouter(p3turtle *pt) { mTurtle = pt ; }
|
||||
void ftController::setFtServer(ftServer *ft) { mFtServer = ft ; }
|
||||
|
||||
void ftController::setFtSearchNExtra(ftSearch *search, ftExtraList *list)
|
||||
{
|
||||
mSearch = search;
|
||||
|
@ -646,7 +647,7 @@ void ftController::locked_checkQueueElement(uint32_t pos)
|
|||
_queue[pos]->mState = ftFileControl::DOWNLOADING ;
|
||||
|
||||
if(_queue[pos]->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING)
|
||||
mTurtle->monitorFileTunnels(_queue[pos]->mName,_queue[pos]->mHash,_queue[pos]->mSize) ;
|
||||
mTurtle->monitorTunnels(_queue[pos]->mHash,mFtServer) ;
|
||||
}
|
||||
|
||||
if(pos >= _max_active_downloads && _queue[pos]->mState != ftFileControl::QUEUED && _queue[pos]->mState != ftFileControl::PAUSED)
|
||||
|
@ -655,7 +656,7 @@ void ftController::locked_checkQueueElement(uint32_t pos)
|
|||
_queue[pos]->mCreator->closeFile() ;
|
||||
|
||||
if(_queue[pos]->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING)
|
||||
mTurtle->stopMonitoringFileTunnels(_queue[pos]->mHash) ;
|
||||
mTurtle->stopMonitoringTunnels(_queue[pos]->mHash) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -899,7 +900,7 @@ bool ftController::completeFile(std::string hash)
|
|||
mDownloads.erase(it);
|
||||
|
||||
if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING)
|
||||
mTurtle->stopMonitoringFileTunnels(hash_to_suppress) ;
|
||||
mTurtle->stopMonitoringTunnels(hash_to_suppress) ;
|
||||
|
||||
} /******* UNLOCKED ********/
|
||||
|
||||
|
@ -1264,7 +1265,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
|||
// We check that flags are consistent.
|
||||
|
||||
if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING)
|
||||
mTurtle->monitorFileTunnels(fname,hash,size) ;
|
||||
mTurtle->monitorTunnels(hash,mFtServer) ;
|
||||
|
||||
bool assume_availability = flags & RS_FILE_REQ_CACHE ; // assume availability for cache files
|
||||
|
||||
|
@ -1365,7 +1366,7 @@ bool ftController::setChunkStrategy(const std::string& hash,FileChunksInfo::Chun
|
|||
|
||||
bool ftController::FileCancel(const std::string& hash)
|
||||
{
|
||||
rsTurtle->stopMonitoringFileTunnels(hash) ;
|
||||
rsTurtle->stopMonitoringTunnels(hash) ;
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController::FileCancel" << std::endl;
|
||||
|
|
|
@ -42,6 +42,7 @@ class ftFileCreator;
|
|||
class ftTransferModule;
|
||||
class ftFileProvider;
|
||||
class ftSearch;
|
||||
class ftServer;
|
||||
class ftExtraList;
|
||||
class ftDataMultiplex;
|
||||
class p3turtle ;
|
||||
|
@ -119,6 +120,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
|||
|
||||
void setFtSearchNExtra(ftSearch *, ftExtraList *);
|
||||
void setTurtleRouter(p3turtle *) ;
|
||||
void setFtServer(ftServer *) ;
|
||||
bool activate();
|
||||
bool isActiveAndNoPending();
|
||||
|
||||
|
@ -234,6 +236,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
|||
ftDataMultiplex *mDataplex;
|
||||
ftExtraList *mExtraList;
|
||||
p3turtle *mTurtle ;
|
||||
ftServer *mFtServer ;
|
||||
|
||||
RsMutex ctrlMutex;
|
||||
|
||||
|
|
|
@ -1085,7 +1085,7 @@ bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider,
|
|||
std::string peerId, std::string hash, uint64_t size,
|
||||
uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
if(chunksize > std::min(size,uint64_t(10*1024*1024)))
|
||||
if(chunksize > uint32_t(10*1024*1024))
|
||||
{
|
||||
std::cerr << "Warning: peer " << peerId << " is asking a large chunk (s=" << chunksize << ") for hash " << hash << ", filesize=" << size << ". This is unexpected." << std::endl ;
|
||||
return false ;
|
||||
|
|
|
@ -153,6 +153,12 @@ bool ftFileProvider::getFileData(const std::string& peer_id,uint64_t offset, uin
|
|||
* FIXME: Warning of comparison between unsigned and signed int?
|
||||
*/
|
||||
|
||||
if(offset >= mSize)
|
||||
{
|
||||
std::cerr << "ftFileProvider::getFileData(): request (" << offset << ") exceeds file size (" << mSize << "! " << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
uint32_t data_size = chunk_size;
|
||||
uint64_t base_loc = offset;
|
||||
|
||||
|
|
|
@ -28,8 +28,10 @@
|
|||
#include "util/rsdebug.h"
|
||||
#include "util/rsdir.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
const int ftserverzone = 29539;
|
||||
|
||||
#include "ft/ftturtlefiletransferitem.h"
|
||||
#include "ft/ftserver.h"
|
||||
#include "ft/ftextralist.h"
|
||||
#include "ft/ftfilesearch.h"
|
||||
|
@ -153,6 +155,9 @@ void ftServer::connectToTurtleRouter(p3turtle *fts)
|
|||
mTurtleRouter = fts ;
|
||||
|
||||
mFtController->setTurtleRouter(fts) ;
|
||||
mFtController->setFtServer(this) ;
|
||||
|
||||
mTurtleRouter->registerTunnelService(this) ;
|
||||
}
|
||||
|
||||
void ftServer::StartupThreads()
|
||||
|
@ -450,6 +455,77 @@ bool ftServer::FileDetails(const std::string &hash, FileSearchFlags hintflags, F
|
|||
return false;
|
||||
}
|
||||
|
||||
RsTurtleGenericTunnelItem *ftServer::deserialiseItem(void *data,uint32_t size) const
|
||||
{
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "p3turtle: deserialising packet: " << std::endl ;
|
||||
#endif
|
||||
#ifdef SERVER_DEBUG
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TURTLE != getRsItemService(rstype)))
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << " Wrong type !!" << std::endl ;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
#endif
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_TURTLE_SUBTYPE_FILE_REQUEST : return new RsTurtleFileRequestItem(data,size) ;
|
||||
case RS_TURTLE_SUBTYPE_FILE_DATA : return new RsTurtleFileDataItem(data,size) ;
|
||||
case RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST : return new RsTurtleFileMapRequestItem(data,size) ;
|
||||
case RS_TURTLE_SUBTYPE_FILE_MAP : return new RsTurtleFileMapItem(data,size) ;
|
||||
case RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST : return new RsTurtleFileCrcRequestItem(data,size) ;
|
||||
case RS_TURTLE_SUBTYPE_FILE_CRC : return new RsTurtleFileCrcItem(data,size) ;
|
||||
case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST : return new RsTurtleChunkCrcRequestItem(data,size) ;
|
||||
case RS_TURTLE_SUBTYPE_CHUNK_CRC : return new RsTurtleChunkCrcItem(data,size) ;
|
||||
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void ftServer::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction dir)
|
||||
{
|
||||
if(dir == RsTurtleGenericTunnelItem::DIRECTION_SERVER)
|
||||
mFtController->addFileSource(hash,virtual_peer_id) ;
|
||||
}
|
||||
void ftServer::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id)
|
||||
{
|
||||
mFtController->removeFileSource(hash,virtual_peer_id) ;
|
||||
}
|
||||
|
||||
bool ftServer::handleTunnelRequest(const std::string& hash,const std::string& peer_id)
|
||||
{
|
||||
FileInfo info ;
|
||||
bool res = FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY | RS_FILE_HINTS_DOWNLOAD, info);
|
||||
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer: performing local hash search for hash " << hash << std::endl;
|
||||
|
||||
if(res)
|
||||
{
|
||||
std::cerr << "Found hash: " << std::endl;
|
||||
std::cerr << " hash = " << hash << std::endl;
|
||||
std::cerr << " peer = " << peer_id << std::endl;
|
||||
std::cerr << " flags = " << info.storage_permission_flags << std::endl;
|
||||
std::cerr << " local = " << rsFiles->FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY | RS_FILE_HINTS_DOWNLOAD, info) << std::endl;
|
||||
std::cerr << " groups= " ; for(std::list<std::string>::const_iterator it(info.parent_groups.begin());it!=info.parent_groups.end();++it) std::cerr << (*it) << ", " ; std::cerr << std::endl;
|
||||
std::cerr << " clear = " << rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups) << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
// The call to computeHashPeerClearance() return a combination of RS_FILE_HINTS_NETWORK_WIDE and RS_FILE_HINTS_BROWSABLE
|
||||
// This is an additional computation cost, but the way it's written here, it's only called when res is true.
|
||||
//
|
||||
res = res && (RS_FILE_HINTS_NETWORK_WIDE & rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups)) ;
|
||||
|
||||
return res ;
|
||||
}
|
||||
|
||||
/***************************************************************/
|
||||
/******************* ExtraFileList Access **********************/
|
||||
/***************************************************************/
|
||||
|
@ -809,7 +885,14 @@ bool ftServer::loadConfigMap(std::map<std::string, std::string> &/*configMap*/)
|
|||
bool ftServer::sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
|
||||
{
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
mTurtleRouter->sendDataRequest(peerId,hash,size,offset,chunksize) ;
|
||||
{
|
||||
RsTurtleFileRequestItem *item = new RsTurtleFileRequestItem ;
|
||||
|
||||
item->chunk_offset = offset ;
|
||||
item->chunk_size = chunksize ;
|
||||
|
||||
mTurtleRouter->sendTurtleData(peerId,item) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* create a packet */
|
||||
|
@ -836,7 +919,10 @@ bool ftServer::sendDataRequest(const std::string& peerId, const std::string& has
|
|||
bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string& hash,bool is_client)
|
||||
{
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
mTurtleRouter->sendChunkMapRequest(peerId,hash,is_client) ;
|
||||
{
|
||||
RsTurtleFileMapRequestItem *item = new RsTurtleFileMapRequestItem ;
|
||||
mTurtleRouter->sendTurtleData(peerId,item) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* create a packet */
|
||||
|
@ -859,7 +945,11 @@ bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string&
|
|||
bool ftServer::sendChunkMap(const std::string& peerId,const std::string& hash,const CompressedChunkMap& map,bool is_client)
|
||||
{
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
mTurtleRouter->sendChunkMap(peerId,hash,map,is_client) ;
|
||||
{
|
||||
RsTurtleFileMapItem *item = new RsTurtleFileMapItem ;
|
||||
item->compressed_map = map ;
|
||||
mTurtleRouter->sendTurtleData(peerId,item) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* create a packet */
|
||||
|
@ -882,7 +972,11 @@ bool ftServer::sendChunkMap(const std::string& peerId,const std::string& hash,co
|
|||
bool ftServer::sendCRC32MapRequest(const std::string& peerId,const std::string& hash)
|
||||
{
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
mTurtleRouter->sendCRC32MapRequest(peerId,hash) ;
|
||||
{
|
||||
RsTurtleFileCrcRequestItem *item = new RsTurtleFileCrcRequestItem;
|
||||
|
||||
mTurtleRouter->sendTurtleData(peerId,item) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* create a packet */
|
||||
|
@ -903,7 +997,12 @@ bool ftServer::sendCRC32MapRequest(const std::string& peerId,const std::string&
|
|||
bool ftServer::sendSingleChunkCRCRequest(const std::string& peerId,const std::string& hash,uint32_t chunk_number)
|
||||
{
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
mTurtleRouter->sendSingleChunkCRCRequest(peerId,hash,chunk_number) ;
|
||||
{
|
||||
RsTurtleChunkCrcRequestItem *item = new RsTurtleChunkCrcRequestItem;
|
||||
item->chunk_number = chunk_number ;
|
||||
|
||||
mTurtleRouter->sendTurtleData(peerId,item) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* create a packet */
|
||||
|
@ -926,7 +1025,12 @@ bool ftServer::sendSingleChunkCRCRequest(const std::string& peerId,const std::st
|
|||
bool ftServer::sendCRC32Map(const std::string& peerId,const std::string& hash,const CRC32Map& crcmap)
|
||||
{
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
mTurtleRouter->sendCRC32Map(peerId,hash,crcmap) ;
|
||||
{
|
||||
RsTurtleFileCrcItem *item = new RsTurtleFileCrcItem ;
|
||||
item->crc_map = crcmap ;
|
||||
|
||||
mTurtleRouter->sendTurtleData(peerId,item) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* create a packet */
|
||||
|
@ -948,7 +1052,13 @@ bool ftServer::sendCRC32Map(const std::string& peerId,const std::string& hash,co
|
|||
bool ftServer::sendSingleChunkCRC(const std::string& peerId,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc)
|
||||
{
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
mTurtleRouter->sendSingleChunkCRC(peerId,hash,chunk_number,crc) ;
|
||||
{
|
||||
RsTurtleChunkCrcItem *item = new RsTurtleChunkCrcItem;
|
||||
item->chunk_number = chunk_number ;
|
||||
item->check_sum = crc ;
|
||||
|
||||
mTurtleRouter->sendTurtleData(peerId,item) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* create a packet */
|
||||
|
@ -1003,7 +1113,23 @@ bool ftServer::sendData(const std::string& peerId, const std::string& hash, uint
|
|||
/******** New Serialiser Type *******/
|
||||
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
mTurtleRouter->sendFileData(peerId,hash,size,baseoffset+offset,chunk,&(((uint8_t *) data)[offset])) ;
|
||||
{
|
||||
RsTurtleFileDataItem *item = new RsTurtleFileDataItem ;
|
||||
|
||||
item->chunk_offset = offset+baseoffset ;
|
||||
item->chunk_size = chunk;
|
||||
item->chunk_data = malloc(chunk) ;
|
||||
|
||||
if(item->chunk_data == NULL)
|
||||
{
|
||||
std::cerr << "p3turtle: Warning: failed malloc of " << chunk << " bytes for sending data packet." << std::endl ;
|
||||
delete item;
|
||||
return false;
|
||||
}
|
||||
memcpy(item->chunk_data,&(((uint8_t *) data)[offset]),chunk) ;
|
||||
|
||||
mTurtleRouter->sendTurtleData(peerId,item) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
RsFileData *rfd = new RsFileData();
|
||||
|
@ -1047,6 +1173,76 @@ bool ftServer::sendData(const std::string& peerId, const std::string& hash, uint
|
|||
return true;
|
||||
}
|
||||
|
||||
void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
|
||||
const std::string& hash,
|
||||
const std::string& virtual_peer_id,
|
||||
RsTurtleGenericTunnelItem::Direction direction)
|
||||
{
|
||||
switch(i->PacketSubType())
|
||||
{
|
||||
case RS_TURTLE_SUBTYPE_FILE_REQUEST:
|
||||
{
|
||||
RsTurtleFileRequestItem *item = dynamic_cast<RsTurtleFileRequestItem *>(i) ;
|
||||
getMultiplexer()->recvDataRequest(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size) ;
|
||||
}
|
||||
break ;
|
||||
|
||||
case RS_TURTLE_SUBTYPE_FILE_DATA :
|
||||
{
|
||||
RsTurtleFileDataItem *item = dynamic_cast<RsTurtleFileDataItem *>(i) ;
|
||||
getMultiplexer()->recvData(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size,item->chunk_data) ;
|
||||
|
||||
item->chunk_data = NULL ; // this prevents deletion in the destructor of RsFileDataItem, because data will be deleted
|
||||
// down _ft_server->getMultiplexer()->recvData()...in ftTransferModule::recvFileData
|
||||
|
||||
}
|
||||
break ;
|
||||
|
||||
case RS_TURTLE_SUBTYPE_FILE_MAP :
|
||||
{
|
||||
RsTurtleFileMapItem *item = dynamic_cast<RsTurtleFileMapItem *>(i) ;
|
||||
getMultiplexer()->recvChunkMap(virtual_peer_id,hash,item->compressed_map,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ;
|
||||
}
|
||||
break ;
|
||||
|
||||
case RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST:
|
||||
{
|
||||
RsTurtleFileMapRequestItem *item = dynamic_cast<RsTurtleFileMapRequestItem *>(i) ;
|
||||
getMultiplexer()->recvChunkMapRequest(virtual_peer_id,hash,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ;
|
||||
}
|
||||
break ;
|
||||
|
||||
case RS_TURTLE_SUBTYPE_FILE_CRC :
|
||||
{
|
||||
RsTurtleFileCrcItem *item = dynamic_cast<RsTurtleFileCrcItem *>(i) ;
|
||||
getMultiplexer()->recvCRC32Map(virtual_peer_id,hash,item->crc_map) ;
|
||||
}
|
||||
break ;
|
||||
|
||||
case RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST:
|
||||
{
|
||||
getMultiplexer()->recvCRC32MapRequest(virtual_peer_id,hash) ;
|
||||
}
|
||||
break ;
|
||||
|
||||
case RS_TURTLE_SUBTYPE_CHUNK_CRC :
|
||||
{
|
||||
RsTurtleChunkCrcItem *item = dynamic_cast<RsTurtleChunkCrcItem *>(i) ;
|
||||
getMultiplexer()->recvSingleChunkCRC(virtual_peer_id,hash,item->chunk_number,item->check_sum) ;
|
||||
}
|
||||
break ;
|
||||
|
||||
case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST:
|
||||
{
|
||||
RsTurtleChunkCrcRequestItem *item = dynamic_cast<RsTurtleChunkCrcRequestItem *>(i) ;
|
||||
getMultiplexer()->recvSingleChunkCRCRequest(virtual_peer_id,hash,item->chunk_number) ;
|
||||
}
|
||||
break ;
|
||||
default:
|
||||
std::cerr << "WARNING: Unknown packet type received: sub_id=" << reinterpret_cast<void*>(i->PacketSubType()) << ". Is somebody trying to poison you ?" << std::endl ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* NB: The rsCore lock must be activated before calling this.
|
||||
* This Lock should be moved lower into the system...
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "ft/ftdata.h"
|
||||
#include "turtle/turtleclientservice.h"
|
||||
#include "retroshare/rsfiles.h"
|
||||
//#include "dbase/cachestrapper.h"
|
||||
|
||||
|
@ -72,142 +73,151 @@ class ftDwlQueue;
|
|||
class p3PeerMgr;
|
||||
class p3LinkMgr;
|
||||
|
||||
class ftServer: public RsFiles, public ftDataSend, public RsThread
|
||||
class ftServer: public RsFiles, public ftDataSend, public RsTurtleClientService, public RsThread
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/***************************************************************/
|
||||
/******************** Setup ************************************/
|
||||
/***************************************************************/
|
||||
/***************************************************************/
|
||||
/******************** Setup ************************************/
|
||||
/***************************************************************/
|
||||
|
||||
ftServer(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr);
|
||||
ftServer(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr);
|
||||
|
||||
/* Assign important variables */
|
||||
void setConfigDirectory(std::string path);
|
||||
/* Assign important variables */
|
||||
void setConfigDirectory(std::string path);
|
||||
|
||||
void setP3Interface(P3Interface *pqi);
|
||||
void setP3Interface(P3Interface *pqi);
|
||||
|
||||
/* add Config Items (Extra, Controller) */
|
||||
void addConfigComponents(p3ConfigMgr *mgr);
|
||||
/* add Config Items (Extra, Controller) */
|
||||
void addConfigComponents(p3ConfigMgr *mgr);
|
||||
|
||||
virtual CacheStrapper *getCacheStrapper();
|
||||
virtual CacheTransfer *getCacheTransfer();
|
||||
virtual CacheStrapper *getCacheStrapper();
|
||||
virtual CacheTransfer *getCacheTransfer();
|
||||
|
||||
std::string OwnId();
|
||||
std::string OwnId();
|
||||
|
||||
/* Final Setup (once everything is assigned) */
|
||||
//void SetupFtServer();
|
||||
void SetupFtServer(NotifyBase *cb);
|
||||
void connectToTurtleRouter(p3turtle *p) ;
|
||||
/* Final Setup (once everything is assigned) */
|
||||
//void SetupFtServer();
|
||||
void SetupFtServer(NotifyBase *cb);
|
||||
void connectToTurtleRouter(p3turtle *p) ;
|
||||
|
||||
void StartupThreads();
|
||||
void StopThreads();
|
||||
void StartupThreads();
|
||||
void StopThreads();
|
||||
|
||||
/* own thread */
|
||||
virtual void run();
|
||||
/* own thread */
|
||||
virtual void run();
|
||||
|
||||
// Checks that the given hash is well formed. Used to chase
|
||||
// string bugs.
|
||||
static bool checkHash(const std::string& hash,std::string& error_string) ;
|
||||
// Checks that the given hash is well formed. Used to chase
|
||||
// string bugs.
|
||||
static bool checkHash(const std::string& hash,std::string& error_string) ;
|
||||
|
||||
/***************************************************************/
|
||||
/*************** Control Interface *****************************/
|
||||
/************** (Implements RsFiles) ***************************/
|
||||
/***************************************************************/
|
||||
// Implements RsTurtleClientService
|
||||
//
|
||||
virtual bool handleTunnelRequest(const std::string& hash,const std::string& peer_id) ;
|
||||
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const std::string& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
|
||||
virtual RsTurtleGenericTunnelItem *deserialiseItem(void *data,uint32_t size) const ;
|
||||
|
||||
// member access
|
||||
void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ;
|
||||
void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) ;
|
||||
|
||||
ftDataMultiplex *getMultiplexer() const { return mFtDataplex ; }
|
||||
ftController *getController() const { return mFtController ; }
|
||||
/***************************************************************/
|
||||
/*************** Control Interface *****************************/
|
||||
/************** (Implements RsFiles) ***************************/
|
||||
/***************************************************************/
|
||||
|
||||
/***
|
||||
* Control of Downloads
|
||||
***/
|
||||
virtual bool alreadyHaveFile(const std::string& hash, FileInfo &info);
|
||||
virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<std::string>& srcIds);
|
||||
virtual bool FileCancel(const std::string& hash);
|
||||
virtual bool FileControl(const std::string& hash, uint32_t flags);
|
||||
virtual bool FileClearCompleted();
|
||||
virtual bool setDestinationDirectory(const std::string& hash,const std::string& new_path) ;
|
||||
virtual bool setDestinationName(const std::string& hash,const std::string& new_name) ;
|
||||
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s) ;
|
||||
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) ;
|
||||
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ;
|
||||
virtual uint32_t freeDiskSpaceLimit() const ;
|
||||
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
|
||||
// member access
|
||||
|
||||
ftDataMultiplex *getMultiplexer() const { return mFtDataplex ; }
|
||||
ftController *getController() const { return mFtController ; }
|
||||
|
||||
/***
|
||||
* Control of Downloads
|
||||
***/
|
||||
virtual bool alreadyHaveFile(const std::string& hash, FileInfo &info);
|
||||
virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<std::string>& srcIds);
|
||||
virtual bool FileCancel(const std::string& hash);
|
||||
virtual bool FileControl(const std::string& hash, uint32_t flags);
|
||||
virtual bool FileClearCompleted();
|
||||
virtual bool setDestinationDirectory(const std::string& hash,const std::string& new_path) ;
|
||||
virtual bool setDestinationName(const std::string& hash,const std::string& new_name) ;
|
||||
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s) ;
|
||||
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) ;
|
||||
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ;
|
||||
virtual uint32_t freeDiskSpaceLimit() const ;
|
||||
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
|
||||
|
||||
|
||||
/***
|
||||
* Control of Downloads Priority.
|
||||
***/
|
||||
virtual uint32_t getMinPrioritizedTransfers() ;
|
||||
virtual void setMinPrioritizedTransfers(uint32_t s) ;
|
||||
virtual uint32_t getQueueSize() ;
|
||||
virtual void setQueueSize(uint32_t s) ;
|
||||
virtual bool changeQueuePosition(const std::string hash, QueueMove queue_mv);
|
||||
virtual bool changeDownloadSpeed(const std::string hash, int speed);
|
||||
virtual bool getDownloadSpeed(const std::string hash, int & speed);
|
||||
virtual bool clearDownload(const std::string hash);
|
||||
//virtual void getDwlDetails(std::list<DwlDetails> & details);
|
||||
/***
|
||||
* Control of Downloads Priority.
|
||||
***/
|
||||
virtual uint32_t getMinPrioritizedTransfers() ;
|
||||
virtual void setMinPrioritizedTransfers(uint32_t s) ;
|
||||
virtual uint32_t getQueueSize() ;
|
||||
virtual void setQueueSize(uint32_t s) ;
|
||||
virtual bool changeQueuePosition(const std::string hash, QueueMove queue_mv);
|
||||
virtual bool changeDownloadSpeed(const std::string hash, int speed);
|
||||
virtual bool getDownloadSpeed(const std::string hash, int & speed);
|
||||
virtual bool clearDownload(const std::string hash);
|
||||
//virtual void getDwlDetails(std::list<DwlDetails> & details);
|
||||
|
||||
/***
|
||||
* Download/Upload Details
|
||||
***/
|
||||
virtual bool FileDownloads(std::list<std::string> &hashs);
|
||||
virtual bool FileUploads(std::list<std::string> &hashs);
|
||||
virtual bool FileDetails(const std::string &hash, FileSearchFlags hintflags, FileInfo &info);
|
||||
virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) ;
|
||||
virtual bool FileUploadChunksDetails(const std::string& hash,const std::string& peer_id,CompressedChunkMap& map) ;
|
||||
/***
|
||||
* Download/Upload Details
|
||||
***/
|
||||
virtual bool FileDownloads(std::list<std::string> &hashs);
|
||||
virtual bool FileUploads(std::list<std::string> &hashs);
|
||||
virtual bool FileDetails(const std::string &hash, FileSearchFlags hintflags, FileInfo &info);
|
||||
virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) ;
|
||||
virtual bool FileUploadChunksDetails(const std::string& hash,const std::string& peer_id,CompressedChunkMap& map) ;
|
||||
|
||||
|
||||
/***
|
||||
* Extra List Access
|
||||
***/
|
||||
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileRemove(std::string hash, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
|
||||
virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size, std::string destpath);
|
||||
/***
|
||||
* Extra List Access
|
||||
***/
|
||||
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileRemove(std::string hash, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags);
|
||||
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
|
||||
virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size, std::string destpath);
|
||||
|
||||
|
||||
/***
|
||||
* Directory Listing / Search Interface
|
||||
***/
|
||||
virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details);
|
||||
virtual int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags);
|
||||
virtual uint32_t getType(void *ref,FileSearchFlags flags) ;
|
||||
/***
|
||||
* Directory Listing / Search Interface
|
||||
***/
|
||||
virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details);
|
||||
virtual int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags);
|
||||
virtual uint32_t getType(void *ref,FileSearchFlags flags) ;
|
||||
|
||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags);
|
||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id);
|
||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags);
|
||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id);
|
||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags);
|
||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id);
|
||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags);
|
||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id);
|
||||
|
||||
/***
|
||||
* Utility Functions
|
||||
***/
|
||||
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath);
|
||||
virtual void ForceDirectoryCheck();
|
||||
virtual void updateSinceGroupPermissionsChanged() ;
|
||||
virtual bool InDirectoryCheck();
|
||||
virtual bool CopyFile(const std::string& source, const std::string& dest);
|
||||
/***
|
||||
* Utility Functions
|
||||
***/
|
||||
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath);
|
||||
virtual void ForceDirectoryCheck();
|
||||
virtual void updateSinceGroupPermissionsChanged() ;
|
||||
virtual bool InDirectoryCheck();
|
||||
virtual bool CopyFile(const std::string& source, const std::string& dest);
|
||||
|
||||
/***
|
||||
* Directory Handling
|
||||
***/
|
||||
virtual void setDownloadDirectory(std::string path);
|
||||
virtual void setPartialsDirectory(std::string path);
|
||||
virtual std::string getDownloadDirectory();
|
||||
virtual std::string getPartialsDirectory();
|
||||
/***
|
||||
* Directory Handling
|
||||
***/
|
||||
virtual void setDownloadDirectory(std::string path);
|
||||
virtual void setPartialsDirectory(std::string path);
|
||||
virtual std::string getDownloadDirectory();
|
||||
virtual std::string getPartialsDirectory();
|
||||
|
||||
virtual bool getSharedDirectories(std::list<SharedDirInfo> &dirs);
|
||||
virtual bool setSharedDirectories(std::list<SharedDirInfo> &dirs);
|
||||
virtual bool addSharedDirectory(const SharedDirInfo& dir);
|
||||
virtual bool updateShareFlags(const SharedDirInfo& dir); // updates the flags. The directory should already exist !
|
||||
virtual bool removeSharedDirectory(std::string dir);
|
||||
virtual bool getSharedDirectories(std::list<SharedDirInfo> &dirs);
|
||||
virtual bool setSharedDirectories(std::list<SharedDirInfo> &dirs);
|
||||
virtual bool addSharedDirectory(const SharedDirInfo& dir);
|
||||
virtual bool updateShareFlags(const SharedDirInfo& dir); // updates the flags. The directory should already exist !
|
||||
virtual bool removeSharedDirectory(std::string dir);
|
||||
|
||||
virtual bool getShareDownloadDirectory();
|
||||
virtual bool shareDownloadDirectory(bool share);
|
||||
virtual bool getShareDownloadDirectory();
|
||||
virtual bool shareDownloadDirectory(bool share);
|
||||
|
||||
virtual void setRememberHashFilesDuration(uint32_t days) ;
|
||||
virtual uint32_t rememberHashFilesDuration() const ;
|
||||
|
@ -217,84 +227,84 @@ virtual bool shareDownloadDirectory(bool share);
|
|||
virtual void setWatchPeriod(int minutes) ;
|
||||
virtual int watchPeriod() const ;
|
||||
|
||||
/***************************************************************/
|
||||
/*************** Control Interface *****************************/
|
||||
/***************************************************************/
|
||||
/***************************************************************/
|
||||
/*************** Control Interface *****************************/
|
||||
/***************************************************************/
|
||||
|
||||
/***************************************************************/
|
||||
/*************** Data Transfer Interface ***********************/
|
||||
/***************************************************************/
|
||||
public:
|
||||
virtual bool sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
virtual bool sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) ;
|
||||
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) ;
|
||||
virtual bool sendCRC32MapRequest(const std::string&, const std::string&) ;
|
||||
virtual bool sendCRC32Map(const std::string&, const std::string&, const CRC32Map&) ;
|
||||
virtual bool sendSingleChunkCRCRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_number) ;
|
||||
virtual bool sendSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ;
|
||||
/***************************************************************/
|
||||
/*************** Data Transfer Interface ***********************/
|
||||
/***************************************************************/
|
||||
public:
|
||||
virtual bool sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
virtual bool sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) ;
|
||||
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) ;
|
||||
virtual bool sendCRC32MapRequest(const std::string&, const std::string&) ;
|
||||
virtual bool sendCRC32Map(const std::string&, const std::string&, const CRC32Map&) ;
|
||||
virtual bool sendSingleChunkCRCRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_number) ;
|
||||
virtual bool sendSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ;
|
||||
|
||||
/*************** Internal Transfer Fns *************************/
|
||||
virtual int tick();
|
||||
/*************** Internal Transfer Fns *************************/
|
||||
virtual int tick();
|
||||
|
||||
/* Configuration */
|
||||
bool addConfiguration(p3ConfigMgr *cfgmgr);
|
||||
bool ResumeTransfers();
|
||||
/* Configuration */
|
||||
bool addConfiguration(p3ConfigMgr *cfgmgr);
|
||||
bool ResumeTransfers();
|
||||
|
||||
private:
|
||||
bool handleInputQueues();
|
||||
bool handleCacheData();
|
||||
bool handleFileData();
|
||||
private:
|
||||
bool handleInputQueues();
|
||||
bool handleCacheData();
|
||||
bool handleFileData();
|
||||
|
||||
/******************* p3 Config Overload ************************/
|
||||
/******************* p3 Config Overload ************************/
|
||||
protected:
|
||||
/* Key Functions to be overloaded for Full Configuration */
|
||||
virtual RsSerialiser *setupSerialiser();
|
||||
virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
|
||||
virtual bool loadList(std::list<RsItem *>& load);
|
||||
/* Key Functions to be overloaded for Full Configuration */
|
||||
virtual RsSerialiser *setupSerialiser();
|
||||
virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
|
||||
virtual bool loadList(std::list<RsItem *>& load);
|
||||
|
||||
private:
|
||||
bool loadConfigMap(std::map<std::string, std::string> &configMap);
|
||||
/******************* p3 Config Overload ************************/
|
||||
bool loadConfigMap(std::map<std::string, std::string> &configMap);
|
||||
/******************* p3 Config Overload ************************/
|
||||
|
||||
/*************************** p3 Config Overload ********************/
|
||||
/*************************** p3 Config Overload ********************/
|
||||
|
||||
private:
|
||||
|
||||
/**** INTERNAL FUNCTIONS ***/
|
||||
//virtual int reScanDirs();
|
||||
//virtual int check_dBUpdate();
|
||||
/**** INTERNAL FUNCTIONS ***/
|
||||
//virtual int reScanDirs();
|
||||
//virtual int check_dBUpdate();
|
||||
|
||||
private:
|
||||
|
||||
/* no need for Mutex protection -
|
||||
* as each component is protected independently.
|
||||
*/
|
||||
/* no need for Mutex protection -
|
||||
* as each component is protected independently.
|
||||
*/
|
||||
|
||||
P3Interface *mP3iface; /* XXX THIS NEEDS PROTECTION */
|
||||
P3Interface *mP3iface; /* XXX THIS NEEDS PROTECTION */
|
||||
|
||||
p3PeerMgr *mPeerMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
ftCacheStrapper *mCacheStrapper;
|
||||
ftFiStore *mFiStore;
|
||||
ftFiMonitor *mFiMon;
|
||||
p3PeerMgr *mPeerMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
ftController *mFtController;
|
||||
ftExtraList *mFtExtra;
|
||||
ftCacheStrapper *mCacheStrapper;
|
||||
ftFiStore *mFiStore;
|
||||
ftFiMonitor *mFiMon;
|
||||
|
||||
ftDataMultiplex *mFtDataplex;
|
||||
p3turtle *mTurtleRouter ;
|
||||
ftController *mFtController;
|
||||
ftExtraList *mFtExtra;
|
||||
|
||||
ftDataMultiplex *mFtDataplex;
|
||||
p3turtle *mTurtleRouter ;
|
||||
|
||||
|
||||
ftFileSearch *mFtSearch;
|
||||
ftFileSearch *mFtSearch;
|
||||
|
||||
ftDwlQueue *mFtDwlQueue;
|
||||
ftDwlQueue *mFtDwlQueue;
|
||||
|
||||
RsMutex srvMutex;
|
||||
std::string mConfigPath;
|
||||
std::string mDownloadPath;
|
||||
std::string mPartialsPath;
|
||||
RsMutex srvMutex;
|
||||
std::string mConfigPath;
|
||||
std::string mDownloadPath;
|
||||
std::string mPartialsPath;
|
||||
|
||||
};
|
||||
|
||||
|
|
739
libretroshare/src/ft/ftturtlefiletransferitem.cc
Normal file
739
libretroshare/src/ft/ftturtlefiletransferitem.cc
Normal file
|
@ -0,0 +1,739 @@
|
|||
/*
|
||||
* libretroshare/src/services: ftturtlefiletransferitem.cc
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2013 by Cyril Soler
|
||||
*
|
||||
* 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 "csoler@users.sourceforge.net".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <serialiser/itempriorities.h>
|
||||
#include <ft/ftturtlefiletransferitem.h>
|
||||
|
||||
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 ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleFileMapRequestItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
s += 4 ; // direction
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleFileMapItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
s += 4 ; // direction
|
||||
s += 4 ; // compressed_map.size()
|
||||
|
||||
s += 4 * compressed_map._map.size() ;
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleFileCrcRequestItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
|
||||
return s ;
|
||||
}
|
||||
uint32_t RsTurtleChunkCrcItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
s += 4 ; // chunk number
|
||||
s += 20 ; // check_sum
|
||||
|
||||
return s ;
|
||||
}
|
||||
uint32_t RsTurtleChunkCrcRequestItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
s += 4 ; // chunk number
|
||||
|
||||
return s ;
|
||||
}
|
||||
uint32_t RsTurtleFileCrcItem::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
|
||||
s += 4 ; // size of _map
|
||||
s += 4 ; // size of _crcs
|
||||
|
||||
s += 4 * crc_map._crcs.size() ;
|
||||
s += 4 * crc_map._ccmap._map.size() ;
|
||||
|
||||
return s ;
|
||||
}
|
||||
bool RsTurtleFileMapRequestItem::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, direction);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTurtleFileMapItem::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, direction);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, compressed_map._map.size());
|
||||
|
||||
for(uint32_t i=0;i<compressed_map._map.size() && ok;++i)
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, compressed_map._map[i]);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTurtleFileCrcRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "RsTurtleFileCrcRequestItem::serialize(): serializing packet:" << std::endl ;
|
||||
print(std::cerr,2) ;
|
||||
#endif
|
||||
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);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTurtleChunkCrcRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "RsTurtleChunkCrcRequestItem::serialize(): serializing packet:" << std::endl ;
|
||||
print(std::cerr,2) ;
|
||||
#endif
|
||||
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, chunk_number);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
bool RsTurtleFileCrcItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "RsTurtleFileCrcItem::serialize(): serializing packet:" << std::endl ;
|
||||
print(std::cerr,2) ;
|
||||
#endif
|
||||
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, crc_map._ccmap._map.size());
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, crc_map._crcs.size());
|
||||
|
||||
for(uint32_t i=0;i<crc_map._ccmap._map.size() && ok;++i)
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, crc_map._ccmap._map[i]);
|
||||
|
||||
for(uint32_t i=0;i<crc_map._crcs.size() && ok;++i)
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, crc_map._crcs[i]);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
bool RsTurtleChunkCrcItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "RsTurtleChunkCrcRequestItem::serialize(): serializing packet:" << std::endl ;
|
||||
print(std::cerr,2) ;
|
||||
#endif
|
||||
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, chunk_number);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[0]);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[1]);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[2]);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[3]);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[4]);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
RsTurtleFileMapItem::RsTurtleFileMapItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_MAP)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_MAP) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file map item" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
uint32_t s,d ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &d);
|
||||
direction = d ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &s) ;
|
||||
|
||||
compressed_map._map.resize(s) ;
|
||||
|
||||
for(uint32_t i=0;i<s && ok;++i)
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &(compressed_map._map[i])) ;
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != pktsize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
|
||||
RsTurtleFileMapRequestItem::RsTurtleFileMapRequestItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_MAP_REQUEST) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file map request item" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &direction);
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != pktsize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
|
||||
RsTurtleFileCrcItem::RsTurtleFileCrcItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_CRC)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_CRC) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file map item" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
uint32_t s1,s2 ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &s1) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &s2) ;
|
||||
|
||||
crc_map._ccmap._map.resize(s1) ;
|
||||
crc_map._crcs.resize(s2) ;
|
||||
|
||||
for(uint32_t i=0;i<s1 && ok;++i)
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &(crc_map._ccmap._map[i])) ;
|
||||
|
||||
for(uint32_t i=0;i<s2 && ok;++i)
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &(crc_map._crcs[i])) ;
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != pktsize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
RsTurtleChunkCrcItem::RsTurtleChunkCrcItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_CHUNK_CRC)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_CHUNK_CRC) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file map item" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &chunk_number) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &check_sum.fourbytes[0]) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &check_sum.fourbytes[1]) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &check_sum.fourbytes[2]) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &check_sum.fourbytes[3]) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &check_sum.fourbytes[4]) ;
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != pktsize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
RsTurtleFileCrcRequestItem::RsTurtleFileCrcRequestItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_CRC_REQUEST) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file map request item" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id);
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != pktsize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
RsTurtleChunkCrcRequestItem::RsTurtleChunkCrcRequestItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_CHUNK_CRC_REQUEST) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file map item" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &chunk_number) ;
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != pktsize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("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)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_REQUEST)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_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).
|
||||
UNREFERENCED_LOCAL_VARIABLE(rssize);
|
||||
#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)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_DATA)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_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).
|
||||
UNREFERENCED_LOCAL_VARIABLE(rssize);
|
||||
#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;
|
||||
}
|
||||
std::ostream& RsTurtleFileRequestItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "File request item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << std::hex << tunnel_id << std::dec << 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 : " << std::hex << tunnel_id << std::dec << std::endl ;
|
||||
o << " offset : " << chunk_offset << std::endl ;
|
||||
o << " chunk size: " << chunk_size << std::endl ;
|
||||
o << " data : " << std::hex << chunk_data << std::dec << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
|
||||
std::ostream& RsTurtleFileMapItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "File map item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ;
|
||||
o << " direction : " << direction << std::endl ;
|
||||
o << " map : " ;
|
||||
|
||||
for(uint32_t i=0;i<compressed_map._map.size();++i)
|
||||
o << std::hex << compressed_map._map[i] << std::dec << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
|
||||
std::ostream& RsTurtleFileMapRequestItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "File map request item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ;
|
||||
o << " direction : " << direction << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
|
||||
std::ostream& RsTurtleFileCrcItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "File CRC item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ;
|
||||
o << " map : " ;
|
||||
|
||||
for(uint32_t i=0;i<crc_map._ccmap._map.size();++i)
|
||||
o << std::hex << crc_map._ccmap._map[i] << std::endl ;
|
||||
|
||||
o << " CRC : " ;
|
||||
|
||||
for(uint32_t i=0;i<crc_map._crcs.size();++i)
|
||||
o << std::hex << crc_map._crcs[i] << std::dec << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
std::ostream& RsTurtleFileCrcRequestItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "File CRC request item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
std::ostream& RsTurtleChunkCrcRequestItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "Chunk CRC request item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ;
|
||||
o << " chunk num : " << chunk_number << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
std::ostream& RsTurtleChunkCrcItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "Chunk CRC request item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ;
|
||||
o << " chunk num : " << chunk_number << std::endl ;
|
||||
o << " sha1 sum : " << check_sum.toStdString() << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
|
168
libretroshare/src/ft/ftturtlefiletransferitem.h
Normal file
168
libretroshare/src/ft/ftturtlefiletransferitem.h
Normal file
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* libretroshare/src/services: ftturtlefiletransferitem.h
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2013 by Cyril Soler
|
||||
*
|
||||
* 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 "csoler@users.sourceforge.net".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <turtle/rsturtleitem.h>
|
||||
|
||||
/***********************************************************************************/
|
||||
/* Turtle File Transfer item classes */
|
||||
/***********************************************************************************/
|
||||
|
||||
class RsTurtleFileRequestItem: public RsTurtleGenericTunnelItem
|
||||
{
|
||||
public:
|
||||
RsTurtleFileRequestItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_REQUEST) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_REQUEST);}
|
||||
RsTurtleFileRequestItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
virtual bool shouldStampTunnel() const { return false ; }
|
||||
virtual Direction travelingDirection() const { return DIRECTION_SERVER ; }
|
||||
|
||||
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 RsTurtleGenericTunnelItem
|
||||
{
|
||||
public:
|
||||
RsTurtleFileDataItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_DATA) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_DATA) ;}
|
||||
~RsTurtleFileDataItem() ;
|
||||
RsTurtleFileDataItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
virtual bool shouldStampTunnel() const { return true ; }
|
||||
virtual Direction travelingDirection() const { return DIRECTION_CLIENT ; }
|
||||
|
||||
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) ;
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem
|
||||
{
|
||||
public:
|
||||
RsTurtleFileMapRequestItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_MAP_REQUEST) ;}
|
||||
RsTurtleFileMapRequestItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
virtual bool shouldStampTunnel() const { return false ; }
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem
|
||||
{
|
||||
public:
|
||||
RsTurtleFileMapItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_MAP) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_MAP) ;}
|
||||
RsTurtleFileMapItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
virtual bool shouldStampTunnel() const { return false ; }
|
||||
|
||||
CompressedChunkMap compressed_map ; // Map info for the file in compressed format. Each *bit* in the array uint's says "I have" or "I don't have"
|
||||
// by default, we suppose the peer has all the chunks. This info will thus be and-ed
|
||||
// with the default file map for this source.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleFileCrcRequestItem: public RsTurtleGenericTunnelItem
|
||||
{
|
||||
public:
|
||||
RsTurtleFileCrcRequestItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST) { setPriorityLevel(QOS_PRIORITY_RS_FILE_CRC_REQUEST);}
|
||||
RsTurtleFileCrcRequestItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
virtual bool shouldStampTunnel() const { return false ; }
|
||||
virtual Direction travelingDirection() const { return DIRECTION_SERVER ; }
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem
|
||||
{
|
||||
public:
|
||||
RsTurtleChunkCrcRequestItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST) { setPriorityLevel(QOS_PRIORITY_RS_CHUNK_CRC_REQUEST);}
|
||||
RsTurtleChunkCrcRequestItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
virtual bool shouldStampTunnel() const { return false ; }
|
||||
virtual Direction travelingDirection() const { return DIRECTION_SERVER ; }
|
||||
|
||||
uint32_t chunk_number ; // id of the chunk to CRC.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleFileCrcItem: public RsTurtleGenericTunnelItem
|
||||
{
|
||||
public:
|
||||
RsTurtleFileCrcItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_CRC) { setPriorityLevel(QOS_PRIORITY_RS_FILE_CRC);}
|
||||
RsTurtleFileCrcItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
virtual bool shouldStampTunnel() const { return true ; }
|
||||
virtual Direction travelingDirection() const { return DIRECTION_CLIENT ; }
|
||||
|
||||
CRC32Map crc_map ;// Map info for the file in compressed format. Each *bit* in the array uint's says "I have" or "I don't have"
|
||||
// by default, we suppose the peer has all the chunks. This info will thus be and-ed
|
||||
// with the default file map for this source.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem
|
||||
{
|
||||
public:
|
||||
RsTurtleChunkCrcItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_CHUNK_CRC) { setPriorityLevel(QOS_PRIORITY_RS_CHUNK_CRC);}
|
||||
RsTurtleChunkCrcItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
virtual bool shouldStampTunnel() const { return true ; }
|
||||
virtual Direction travelingDirection() const { return DIRECTION_CLIENT ; }
|
||||
|
||||
uint32_t chunk_number ;
|
||||
Sha1CheckSum check_sum ;
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue