- Implemented CRC32 map traffic through direct downloads

- replaced the findItems() call into a hand-written search (this was causing a rare bug in displaying downloads)


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3318 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-07-29 21:07:07 +00:00
parent 7a789edcbf
commit 012808ea00
17 changed files with 529 additions and 91 deletions

View File

@ -47,20 +47,27 @@ bool ftDataSendPair::sendData(const std::string &peerId, const std::string &hash
}
/* Send a request for a chunk map */
bool ftDataSendPair::sendChunkMapRequest(const std::string& peer_id,const std::string& hash)
bool ftDataSendPair::sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client)
{
bool is_client = true; // What should this be???
return mDataRecv->recvChunkMapRequest(peer_id,hash,is_client);
}
/* Send a chunk map */
bool ftDataSendPair::sendChunkMap(const std::string& peer_id,const std::string& hash,
const CompressedChunkMap& cmap)
bool ftDataSendPair::sendChunkMap(const std::string& peer_id,const std::string& hash, const CompressedChunkMap& cmap,bool is_client)
{
bool is_client = true; // What should this be???
return mDataRecv->recvChunkMap(peer_id,hash,cmap, is_client);
}
/* Send a request for a chunk map */
bool ftDataSendPair::sendCRC32MapRequest(const std::string& peer_id,const std::string& hash)
{
return mDataRecv->recvCRC32MapRequest(peer_id,hash);
}
/* Send a chunk map */
bool ftDataSendPair::sendCRC32Map(const std::string& peer_id,const std::string& hash, const CRC32Map& crcmap)
{
return mDataRecv->recvCRC32Map(peer_id,hash,crcmap) ;
}
/* Client Send */
bool ftDataSendDummy::sendDataRequest(const std::string &peerId, const std::string &hash,
uint64_t size, uint64_t offset, uint32_t chunksize)
@ -77,18 +84,26 @@ bool ftDataSendDummy::sendData(const std::string &peerId, const std::string &has
/* Send a request for a chunk map */
bool ftDataSendDummy::sendChunkMapRequest(const std::string& peer_id,const std::string& hash)
bool ftDataSendDummy::sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client)
{
return true;
}
/* Send a chunk map */
bool ftDataSendDummy::sendChunkMap(const std::string& peer_id,const std::string& hash,
const CompressedChunkMap& cmap)
bool ftDataSendDummy::sendChunkMap(const std::string& peer_id,const std::string& hash, const CompressedChunkMap& cmap,bool is_client)
{
return true;
}
bool ftDataSendDummy::sendCRC32MapRequest(const std::string& peer_id,const std::string& hash)
{
return true;
}
/* Send a chunk map */
bool ftDataSendDummy::sendCRC32Map(const std::string& peer_id,const std::string& hash, const CRC32Map& cmap)
{
return true;
}
/* Client Recv */
bool ftDataRecvDummy::recvData(const std::string &peerId, const std::string &hash,

View File

@ -88,6 +88,11 @@ class ftDataRecv
/// Send a chunk map
virtual bool recvChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) = 0;
/// Send a request for a chunk map
virtual bool recvCRC32MapRequest(const std::string& peer_id,const std::string& hash) = 0;
/// Send a chunk map
virtual bool recvCRC32Map(const std::string& peer_id,const std::string& hash,const CRC32Map& crcmap) = 0;
};
/**************** FOR TESTING ***********************/
@ -109,12 +114,16 @@ virtual bool sendData(const std::string &peerId, const std::string &hash, uin
uint64_t offset, uint32_t chunksize, void *data);
/* Send a request for a chunk map */
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash);
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client);
/* Send a chunk map */
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,
const CompressedChunkMap& cmap);
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash, const CompressedChunkMap& cmap,bool is_client);
/* Send a request for a chunk map */
virtual bool sendCRC32MapRequest(const std::string& peer_id,const std::string& hash);
/* Send a chunk map */
virtual bool sendCRC32Map(const std::string& peer_id,const std::string& hash, const CRC32Map& cmap);
ftDataRecv *mDataRecv;
};
@ -133,12 +142,16 @@ virtual bool sendData(const std::string &peerId, const std::string &hash, uin
uint64_t offset, uint32_t chunksize, void *data);
/* Send a request for a chunk map */
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash);
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client);
/* Send a chunk map */
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,
const CompressedChunkMap& cmap);
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash, const CompressedChunkMap& cmap,bool is_client);
/* Send a request for a chunk map */
virtual bool sendCRC32MapRequest(const std::string& peer_id,const std::string& hash);
/* Send a chunk map */
virtual bool sendCRC32Map(const std::string& peer_id,const std::string& hash, const CRC32Map& cmap);
};
class ftDataRecvDummy: public ftDataRecv
@ -163,6 +176,11 @@ virtual bool recvChunkMapRequest(const std::string& peer_id,const std::string& h
virtual bool recvChunkMap(const std::string& peer_id,const std::string& hash,
const CompressedChunkMap& cmap,bool is_client);
/* Send a request for a chunk map */
virtual bool sendCRC32MapRequest(const std::string& peer_id,const std::string& hash);
/* Send a chunk map */
virtual bool sendCRC32Map(const std::string& peer_id,const std::string& hash, const CompressedChunkMap& cmap);
};
#endif

View File

@ -251,7 +251,7 @@ bool ftDataMultiplex::recvChunkMapRequest(const std::string& peerId, const std::
return true;
}
bool ftDataMultiplex::recvCRCMapRequest(const std::string& peerId, const std::string& hash/*,const CompressedChunkMap& map*/)
bool ftDataMultiplex::recvCRC32MapRequest(const std::string& peerId, const std::string& hash)
{
#ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::recvChunkMapRequest() Server Recv";
@ -344,7 +344,7 @@ bool ftDataMultiplex::doWork()
std::cerr << "ftDataMultiplex::doWork() Handling FT_CLIENT_CRC32_MAP_REQ";
std::cerr << std::endl;
#endif
handleRecvCRC32MapRequest(req.mPeerId,req.mHash,CompressedChunkMap()) ;
handleRecvCRC32MapRequest(req.mPeerId,req.mHash) ;
break ;
default:
@ -383,7 +383,7 @@ bool ftDataMultiplex::doWork()
return true;
}
bool ftDataMultiplex::recvCRCMap(const std::string& peerId, const std::string& hash,const CRC32Map& crc_map)
bool ftDataMultiplex::recvCRC32Map(const std::string& peerId, const std::string& hash,const CRC32Map& crc_map)
{
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
@ -454,7 +454,7 @@ bool ftDataMultiplex::recvChunkMap(const std::string& peerId, const std::string&
return false;
}
bool ftDataMultiplex::handleRecvCRC32MapRequest(const std::string& peerId, const std::string& hash,const CompressedChunkMap&)
bool ftDataMultiplex::handleRecvCRC32MapRequest(const std::string& peerId, const std::string& hash)
{
std::map<std::string, ftFileProvider *>::iterator it ;
bool found = true ;
@ -726,7 +726,7 @@ bool ftDataMultiplex::sendChunkMapRequest(const std::string& peer_id,const std::
{
return mDataSend->sendChunkMapRequest(peer_id,hash,is_client);
}
bool ftDataMultiplex::sendCRCMapRequest(const std::string& peer_id,const std::string& hash,const CompressedChunkMap&)
bool ftDataMultiplex::sendCRC32MapRequest(const std::string& peer_id,const std::string& hash)
{
return mDataSend->sendCRC32MapRequest(peer_id,hash);
}

View File

@ -111,7 +111,7 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
bool sendChunkMapRequest(const std::string& peerId, const std::string& hash,bool is_client) ;
/* Client Send */
bool sendCRCMapRequest(const std::string& peerId, const std::string& hash,const CompressedChunkMap& chnks) ;
bool sendCRC32MapRequest(const std::string& peerId, const std::string& hash) ;
/*************** RECV INTERFACE (provides ftDataRecv) ****************/
@ -125,9 +125,9 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
/// Receive a chunk map
virtual bool recvChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) ;
/// Receive a CRC map
virtual bool recvCRCMap(const std::string& peer_id,const std::string& hash,const CRC32Map& crc_map) ;
virtual bool recvCRC32Map(const std::string& peer_id,const std::string& hash,const CRC32Map& crc_map) ;
/// Receive a CRC map request
virtual bool recvCRCMapRequest(const std::string& peer_id,const std::string& hash) ;
virtual bool recvCRC32MapRequest(const std::string& peer_id,const std::string& hash) ;
// Returns the chunk map from the file uploading client. Also initiates a chunk map request if this
// map is too old. This supposes that the caller will ask again in a few seconds.
@ -148,7 +148,7 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
bool handleSearchRequest(const std::string& peerId, const std::string& hash);
bool handleRecvClientChunkMapRequest(const std::string& peerId, const std::string& hash) ;
bool handleRecvServerChunkMapRequest(const std::string& peerId, const std::string& hash) ;
bool handleRecvCRC32MapRequest(const std::string& peerId, const std::string& hash, const CompressedChunkMap& map) ;
bool handleRecvCRC32MapRequest(const std::string& peerId, const std::string& hash) ;
/* We end up doing the actual server job here */
bool locked_handleServerRequest(ftFileProvider *provider, std::string peerId, std::string hash, uint64_t size, uint64_t offset, uint32_t chunksize);

View File

@ -789,19 +789,44 @@ bool ftServer::sendCRC32MapRequest(const std::string& peerId,const std::string&
if(mTurtleRouter->isTurtlePeer(peerId))
mTurtleRouter->sendCRC32MapRequest(peerId,hash) ;
else
std::cerr << "ftServer: Warning: not sending CRC map request to peer " << peerId << ", because it's not a turtle tunnel." << std::endl ;
{
/* create a packet */
/* push to networking part */
RsFileCRC32MapRequest *rfi = new RsFileCRC32MapRequest();
/* id */
rfi->PeerId(peerId);
/* file info */
rfi->hash = hash; /* ftr->hash; */
mP3iface->SendFileCRC32MapRequest(rfi);
}
// We only send chunkmap requests to turtle peers. This will be a problem at display time for
// direct friends, so I'll see later whether I code it or not.
return true ;
}
bool ftServer::sendCRC32Map(const std::string& peerId,const std::string& hash,const CRC32Map& map)
bool ftServer::sendCRC32Map(const std::string& peerId,const std::string& hash,const CRC32Map& crcmap)
{
if(mTurtleRouter->isTurtlePeer(peerId))
mTurtleRouter->sendCRC32Map(peerId,hash,map) ;
mTurtleRouter->sendCRC32Map(peerId,hash,crcmap) ;
else
std::cerr << "ftServer: Warning: not sending CRC map to peer " << peerId << ", because it's not a turtle tunnel." << std::endl ;
{
/* create a packet */
/* push to networking part */
RsFileCRC32Map *rfi = new RsFileCRC32Map();
/* id */
rfi->PeerId(peerId);
/* file info */
rfi->hash = hash; /* ftr->hash; */
rfi->crc_map = crcmap; /* ftr->hash; */
mP3iface->SendFileCRC32Map(rfi);
}
// We only send chunkmap requests to turtle peers. This will be a problem at display time for
// direct friends, so I'll see later whether I code it or not.
@ -1047,6 +1072,8 @@ bool ftServer::handleFileData()
RsFileData *fd;
RsFileChunkMapRequest *fcmr;
RsFileChunkMap *fcm;
RsFileCRC32MapRequest *fccrcmr;
RsFileCRC32Map *fccrcm;
int i_init = 0;
int i = 0;
@ -1149,6 +1176,48 @@ FileInfo(ffr);
delete fcm;
}
// now file chunkmap requests
i_init = i;
while((fccrcmr = mP3iface -> GetFileCRC32MapRequest()) != NULL )
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleFileData() Recvd ChunkMap request" << std::endl;
std::ostringstream out;
if (i == i_init)
{
out << "Incoming(Net) File Data:" << std::endl;
}
fccrcmr -> print(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out.str());
#endif
i++; /* count */
/* incoming data */
mFtDataplex->recvCRC32MapRequest(fccrcmr->PeerId(), fccrcmr->hash) ;
delete fccrcmr;
}
// now file chunkmaps
i_init = i;
while((fccrcm = mP3iface -> GetFileCRC32Map()) != NULL )
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleFileData() Recvd ChunkMap request" << std::endl;
std::ostringstream out;
if (i == i_init)
{
out << "Incoming(Net) File Data:" << std::endl;
}
fccrcm -> print(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out.str());
#endif
i++; /* count */
/* incoming data */
mFtDataplex->recvCRC32Map(fccrcm->PeerId(), fccrcm->hash,fccrcm->crc_map);
delete fccrcm;
}
if (i > 0)
{
return 1;

View File

@ -27,7 +27,6 @@
* #define FT_DEBUG 1
*****/
//#define FT_DEBUG 1
#include <rsiface/rsturtle.h>
#include "fttransfermodule.h"
@ -53,7 +52,7 @@ const uint32_t FT_TM_MAX_RESETS = 5;
const uint32_t FT_TM_MINIMUM_CHUNK = 128; /* ie 1/8Kb / sec */
const uint32_t FT_TM_RESTART_DOWNLOAD = 20; /* 20 seconds */
const uint32_t FT_TM_DOWNLOAD_TIMEOUT = 10; /* 10 seconds */
const uint32_t FT_TM_CRC_MAP_MAX_WAIT_PER_GIG = 10; /* 10 seconds */
const uint32_t FT_TM_CRC_MAP_MAX_WAIT_PER_GIG = 20; /* 20 seconds per gigabyte */
const double FT_TM_MAX_INCREASE = 1.00;
const double FT_TM_MIN_INCREASE = -0.10;
@ -683,27 +682,18 @@ bool ftTransferModule::checkCRC()
// _crcmap_last_source_id = (_crcmap_last_source_id+1)%mFileSources.size() ;
bool found = false ;
int n = rand()%(mFileSources.size()) ;
int p=0 ;
std::map<std::string,peerInfo>::const_iterator mit ;
for(mit = mFileSources.begin();mit != mFileSources.end();++mit)
if(rsTurtle->isTurtlePeer(mit->first))
{
found=true ;
break ;
}
for(mit = mFileSources.begin();mit != mFileSources.end() && p<n;++mit,++p);
if(found)
{
#ifdef FT_DEBUG
std::cerr << "ftTransferModule::checkCRC(): sending CRC map request to source " << mit->first << std::endl ;
std::cerr << "ftTransferModule::checkCRC(): sending CRC map request to source " << mit->first << std::endl ;
#endif
_crcmap_last_asked_time = now ;
mMultiplexor->sendCRCMapRequest(mit->first,mHash,CompressedChunkMap());
_crcmap_last_asked_time = now ;
mMultiplexor->sendCRC32MapRequest(mit->first,mHash);
_crcmap_state = FT_TM_CRC_MAP_STATE_ASKED ;
}
else
std::cerr << "ERROR: No file source to ask a chunkmap to!" << std::endl ;
_crcmap_state = FT_TM_CRC_MAP_STATE_ASKED ;
}
break ;

View File

@ -72,6 +72,12 @@ virtual int SendFileChunkMapRequest(RsFileChunkMapRequest *) = 0;
virtual RsFileChunkMap *GetFileChunkMap() = 0;
virtual int SendFileChunkMap(RsFileChunkMap *) = 0;
virtual RsFileCRC32MapRequest *GetFileCRC32MapRequest() = 0;
virtual int SendFileCRC32MapRequest(RsFileCRC32MapRequest *) = 0;
virtual RsFileCRC32Map *GetFileCRC32Map() = 0;
virtual int SendFileCRC32Map(RsFileCRC32Map *) = 0;
};
class P3Interface: public SearchInterface

View File

@ -319,6 +319,14 @@ int pqihandler::SendFileChunkMap(RsFileChunkMap *ns)
{
return HandleRsItem(ns, 0);
}
int pqihandler::SendFileCRC32MapRequest(RsFileCRC32MapRequest *ns)
{
return HandleRsItem(ns, 0);
}
int pqihandler::SendFileCRC32Map(RsFileCRC32Map *ns)
{
return HandleRsItem(ns, 0);
}
int pqihandler::SendRsRawItem(RsRawItem *ns)
{
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
@ -483,6 +491,19 @@ void pqihandler::locked_SortnStoreItem(RsItem *item)
item = NULL;
break;
case RS_PKT_SUBTYPE_FI_CRC32_MAP_REQUEST:
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, "SortnStore -> File Crc32Map Request");
in_crc32map_request.push_back(item);
item = NULL;
break;
case RS_PKT_SUBTYPE_FI_CRC32_MAP:
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, "SortnStore -> File CRC32Map");
in_crc32map.push_back(item);
item = NULL;
break;
default:
break; /* no match! */
}
@ -593,7 +614,32 @@ RsFileChunkMap *pqihandler::GetFileChunkMap()
}
return NULL;
}
RsFileCRC32MapRequest *pqihandler::GetFileCRC32MapRequest()
{
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
if (in_crc32map_request.size() != 0)
{
RsFileCRC32MapRequest *fi = dynamic_cast<RsFileCRC32MapRequest *>(in_crc32map_request.front());
if (!fi) { delete in_crc32map_request.front(); }
in_crc32map_request.pop_front();
return fi;
}
return NULL;
}
RsFileCRC32Map *pqihandler::GetFileCRC32Map()
{
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
if (in_crc32map.size() != 0)
{
RsFileCRC32Map *fi = dynamic_cast<RsFileCRC32Map *>(in_crc32map.front());
if (!fi) { delete in_crc32map.front(); }
in_crc32map.pop_front();
return fi;
}
return NULL;
}
RsRawItem *pqihandler::GetRsRawItem()

View File

@ -65,10 +65,14 @@ virtual int SendFileRequest(RsFileRequest *ns);
virtual int SendFileData(RsFileData *ns);
virtual int SendFileChunkMapRequest(RsFileChunkMapRequest *ns);
virtual int SendFileChunkMap(RsFileChunkMap *ns);
virtual int SendFileCRC32MapRequest(RsFileCRC32MapRequest *ns);
virtual int SendFileCRC32Map(RsFileCRC32Map *ns);
virtual RsFileRequest *GetFileRequest();
virtual RsFileData *GetFileData();
virtual RsFileChunkMapRequest *GetFileChunkMapRequest();
virtual RsFileChunkMap *GetFileChunkMap();
virtual RsFileCRC32MapRequest *GetFileCRC32MapRequest();
virtual RsFileCRC32Map *GetFileCRC32Map();
// Rest of P3Interface
virtual int tick();
@ -105,7 +109,7 @@ void locked_SortnStoreItem(RsItem *item);
SecurityPolicy *globsec;
// Temporary storage...
std::list<RsItem *> in_result, in_search, in_request, in_data, in_service,in_chunkmap,in_chunkmap_request;
std::list<RsItem *> in_result, in_search, in_request, in_data, in_service,in_chunkmap,in_chunkmap_request,in_crc32map_request,in_crc32map;
private:

View File

@ -30,7 +30,7 @@
#include "pqi/pqissltunnel.h"
#include "pqi/pqinetwork.h"
#include "services/p3tunnel.h"
//#include "services/p3tunnel.h"
#include "util/rsnet.h"
#include "util/rsdebug.h"

View File

@ -346,7 +346,7 @@ class CRC32Map
// Build from a file.
//
CRC32Map(uint64_t file_size,uint32_t chunk_size)
: _crcs( file_size/chunk_size + ( (file_size%chunk_size)>0)), _map(file_size/chunk_size + ( (file_size%chunk_size)>0),0)
: _crcs( file_size/chunk_size + ( (file_size%chunk_size)>0)), _ccmap(file_size/chunk_size + ( (file_size%chunk_size)>0),0)
{
}
CRC32Map() {}
@ -355,15 +355,17 @@ class CRC32Map
//
friend CompressedChunkMap compare(const CRC32Map& crc1,const CRC32Map& crc2) ;
void set(uint32_t i,uint32_t val) { _crcs[i] = val ; _map.set(i) ; }
inline void set(uint32_t i,uint32_t val) { _crcs[i] = val ; _ccmap.set(i) ; }
uint32_t operator[](int i) const { return _crcs[i] ; }
uint32_t size() const { return _crcs.size() ; }
inline uint32_t operator[](int i) const { return _crcs[i] ; }
inline uint32_t size() const { return _crcs.size() ; }
private:
std::vector<uint32_t> _crcs;
CompressedChunkMap _map ;
CompressedChunkMap _ccmap ;
friend class RsTurtleFileCrcItem ;
friend class RsFileItemSerialiser ;
friend class RsFileCRC32Map ;
};
/* class which encapsulates download details */

View File

@ -42,6 +42,8 @@ uint32_t RsFileItemSerialiser::size(RsItem *i)
RsFileData *rfd;
RsFileChunkMapRequest *rfcmr;
RsFileChunkMap *rfcm;
RsFileCRC32MapRequest *rfcrcr;
RsFileCRC32Map *rfcrc;
if (NULL != (rfr = dynamic_cast<RsFileRequest *>(i)))
{
@ -59,6 +61,14 @@ uint32_t RsFileItemSerialiser::size(RsItem *i)
{
return sizeChunkMap(rfcm);
}
else if (NULL != (rfcrcr = dynamic_cast<RsFileCRC32MapRequest *>(i)))
{
return sizeCRC32MapReq(rfcrcr);
}
else if (NULL != (rfcrc = dynamic_cast<RsFileCRC32Map *>(i)))
{
return sizeCRC32Map(rfcrc);
}
return 0;
}
@ -70,6 +80,8 @@ bool RsFileItemSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize
RsFileData *rfd;
RsFileChunkMapRequest *rfcmr;
RsFileChunkMap *rfcm;
RsFileCRC32MapRequest *rfcrcr;
RsFileCRC32Map *rfcrc;
if (NULL != (rfr = dynamic_cast<RsFileRequest *>(i)))
{
@ -87,6 +99,14 @@ bool RsFileItemSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize
{
return serialiseChunkMap(rfcm,data,pktsize);
}
else if (NULL != (rfcrcr = dynamic_cast<RsFileCRC32MapRequest *>(i)))
{
return serialiseCRC32MapReq(rfcrcr,data,pktsize);
}
else if (NULL != (rfcrc = dynamic_cast<RsFileCRC32Map *>(i)))
{
return serialiseCRC32Map(rfcrc,data,pktsize);
}
return false;
}
@ -116,6 +136,12 @@ RsItem *RsFileItemSerialiser::deserialise(void *data, uint32_t *pktsize)
case RS_PKT_SUBTYPE_FI_CHUNK_MAP:
return deserialiseChunkMap(data, pktsize);
break;
case RS_PKT_SUBTYPE_FI_CRC32_MAP_REQUEST:
return deserialiseCRC32MapReq(data, pktsize);
break;
case RS_PKT_SUBTYPE_FI_CRC32_MAP:
return deserialiseCRC32Map(data, pktsize);
break;
default:
return NULL;
break;
@ -283,6 +309,25 @@ std::ostream &RsFileChunkMapRequest::print(std::ostream &out, uint16_t indent)
printRsItemEnd(out, "RsFileChunkMapRequest", indent);
return out;
}
std::ostream& RsFileCRC32Map::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsFileCRC32Map", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent); out << "PeerId: " << PeerId() << std::endl ;
printIndent(out, int_Indent); out << " hash: " << hash << std::endl ;
printIndent(out, int_Indent); out << "chunks: " << (void*)(crc_map._ccmap._map[0]) << "..." << std::endl ;
printRsItemEnd(out, "RsFileCRC32Map", indent);
return out;
}
std::ostream& RsFileCRC32MapRequest::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsFileCRC32MapRequest", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent); out << "PeerId: " << PeerId() << std::endl ;
printIndent(out, int_Indent); out << " hash: " << hash << std::endl ;
printRsItemEnd(out, "RsFileCRC32MapRequest", indent);
return out;
}
std::ostream &RsFileData::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsFileData", indent);
@ -406,6 +451,217 @@ uint32_t RsFileItemSerialiser::sizeChunkMap(RsFileChunkMap *item)
return s;
}
uint32_t RsFileItemSerialiser::sizeCRC32MapReq(RsFileCRC32MapRequest *item)
{
uint32_t s = 8; /* header */
s += GetTlvStringSize(item->hash) ; // hash
return s;
}
uint32_t RsFileItemSerialiser::sizeCRC32Map(RsFileCRC32Map *item)
{
uint32_t s = 8; /* header */
s += GetTlvStringSize(item->hash) ; // hash
s += 4 ; // crc32 map size
s += 4 * item->crc_map._ccmap._map.size() ; // compressed chunk map
s += 4 ; // crc32 map size
s += 4 * item->crc_map._crcs.size() ; // compressed chunk map
return s;
}
/* serialise the data to the buffer */
bool RsFileItemSerialiser::serialiseCRC32MapReq(RsFileCRC32MapRequest *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeCRC32MapReq(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsFileItemSerialiser::serialiseData() Header: " << ok << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, item->hash);
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsFileItemSerialiser::serialiseData() Size Error! " << std::endl;
#endif
}
return ok;
}
bool RsFileItemSerialiser::serialiseCRC32Map(RsFileCRC32Map *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeCRC32Map(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsFileItemSerialiser::serialiseData() Header: " << ok << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, item->hash);
ok &= setRawUInt32(data, tlvsize, &offset, item->crc_map._crcs.size());
for(uint32_t i=0;i<item->crc_map._crcs.size();++i)
ok &= setRawUInt32(data, tlvsize, &offset, item->crc_map._crcs[i]);
ok &= setRawUInt32(data, tlvsize, &offset, item->crc_map._ccmap._map.size());
for(uint32_t i=0;i<item->crc_map._ccmap._map.size();++i)
ok &= setRawUInt32(data, tlvsize, &offset, item->crc_map._ccmap._map[i]);
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsFileItemSerialiser::serialiseData() Size Error! " << std::endl;
#endif
}
return ok;
}
RsFileCRC32MapRequest *RsFileItemSerialiser::deserialiseCRC32MapReq(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_BASE != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_FILE != getRsItemType(rstype)) ||
(RS_PKT_SUBTYPE_FI_CRC32_MAP_REQUEST != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < rssize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = rssize;
bool ok = true;
/* ready to load */
RsFileCRC32MapRequest *item = new RsFileCRC32MapRequest();
item->clear();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, *pktsize, &offset, TLV_TYPE_STR_VALUE, item->hash); // file hash
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
RsFileCRC32Map *RsFileItemSerialiser::deserialiseCRC32Map(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_BASE != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_FILE != getRsItemType(rstype)) ||
(RS_PKT_SUBTYPE_FI_CRC32_MAP != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < rssize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = rssize;
bool ok = true;
/* ready to load */
RsFileCRC32Map *item = new RsFileCRC32Map();
item->clear();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, *pktsize, &offset, TLV_TYPE_STR_VALUE, item->hash); // file hash
uint32_t size =0;
ok &= getRawUInt32(data, *pktsize, &offset, &size);
if(ok)
{
item->crc_map._ccmap._map.resize(size) ;
for(uint32_t i=0;i<size && ok;++i)
ok &= getRawUInt32(data, *pktsize, &offset, &(item->crc_map._ccmap._map[i]));
}
uint32_t size2 =0;
ok &= getRawUInt32(data, *pktsize, &offset, &size2);
if(ok)
{
item->crc_map._crcs.resize(size2) ;
for(uint32_t i=0;i<size2 && ok;++i)
ok &= getRawUInt32(data, *pktsize, &offset, &(item->crc_map._crcs[i]));
}
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/* serialise the data to the buffer */
bool RsFileItemSerialiser::serialiseChunkMapReq(RsFileChunkMapRequest *item, void *data, uint32_t *pktsize)
{

View File

@ -112,6 +112,35 @@ class RsFileChunkMap: public RsItem
std::ostream &print(std::ostream &out, uint16_t indent = 0);
};
class RsFileCRC32MapRequest: public RsItem
{
public:
RsFileCRC32MapRequest()
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE, RS_PKT_TYPE_FILE, RS_PKT_SUBTYPE_FI_CRC32_MAP_REQUEST)
{}
virtual ~RsFileCRC32MapRequest() {}
virtual void clear() {}
std::string hash ; // hash of the file for which we request the chunk map
std::ostream &print(std::ostream &out, uint16_t indent = 0);
};
class RsFileCRC32Map: public RsItem
{
public:
RsFileCRC32Map()
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE, RS_PKT_TYPE_FILE, RS_PKT_SUBTYPE_FI_CRC32_MAP)
{}
virtual ~RsFileCRC32Map() {}
virtual void clear() {}
std::string hash ; // hash of the file for which we request the chunk map
CRC32Map crc_map ; // CRC32 map of the file.
std::ostream &print(std::ostream &out, uint16_t indent = 0);
};
/**************************************************************************/
class RsFileItemSerialiser: public RsSerialType
@ -134,16 +163,22 @@ class RsFileItemSerialiser: public RsSerialType
virtual uint32_t sizeData(RsFileData *);
virtual uint32_t sizeChunkMapReq(RsFileChunkMapRequest *);
virtual uint32_t sizeChunkMap(RsFileChunkMap *);
virtual uint32_t sizeCRC32MapReq(RsFileCRC32MapRequest *);
virtual uint32_t sizeCRC32Map(RsFileCRC32Map *);
virtual bool serialiseReq (RsFileRequest *item, void *data, uint32_t *size);
virtual bool serialiseData (RsFileData *item, void *data, uint32_t *size);
virtual bool serialiseChunkMapReq(RsFileChunkMapRequest *item, void *data, uint32_t *size);
virtual bool serialiseChunkMap(RsFileChunkMap *item, void *data, uint32_t *size);
virtual bool serialiseCRC32MapReq(RsFileCRC32MapRequest *item, void *data, uint32_t *size);
virtual bool serialiseCRC32Map(RsFileCRC32Map *item, void *data, uint32_t *size);
virtual RsFileRequest *deserialiseReq(void *data, uint32_t *size);
virtual RsFileData *deserialiseData(void *data, uint32_t *size);
virtual RsFileChunkMapRequest *deserialiseChunkMapReq(void *data, uint32_t *size);
virtual RsFileChunkMap *deserialiseChunkMap(void *data, uint32_t *size);
virtual RsFileData *deserialiseData(void *data, uint32_t *size);
virtual RsFileCRC32MapRequest *deserialiseCRC32MapReq(void *data, uint32_t *size);
virtual RsFileCRC32Map *deserialiseCRC32Map(void *data, uint32_t *size);
};
/**************************************************************************/

View File

@ -1085,7 +1085,7 @@ void p3turtle::handleRecvFileCRC32MapRequest(RsTurtleFileCrcRequestItem *item)
vpid = tunnel.vpid ;
}
_ft_server->getMultiplexer()->recvCRCMapRequest(vpid,hash) ;
_ft_server->getMultiplexer()->recvCRC32MapRequest(vpid,hash) ;
}
void p3turtle::handleRecvFileCRC32Map(RsTurtleFileCrcItem *item)
@ -1122,7 +1122,7 @@ void p3turtle::handleRecvFileCRC32Map(RsTurtleFileCrcItem *item)
vpid = tunnel.vpid ;
hash = tunnel.hash ;
}
_ft_server->getMultiplexer()->recvCRCMap(vpid,hash,item->crc_map) ;
_ft_server->getMultiplexer()->recvCRC32Map(vpid,hash,item->crc_map) ;
}
// Send a data request into the correct tunnel for the given file hash
void p3turtle::sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t, uint64_t offset, uint32_t chunksize)

View File

@ -161,7 +161,7 @@ uint32_t RsTurtleFileCrcItem::serial_size()
s += 4 ; // size of _crcs
s += 4 * crc_map._crcs.size() ;
s += 4 * crc_map._map._map.size() ;
s += 4 * crc_map._ccmap._map.size() ;
return s ;
}
@ -346,11 +346,11 @@ bool RsTurtleFileCrcItem::serialize(void *data,uint32_t& pktsize)
/* add mandatory parts first */
ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id);
ok &= setRawUInt32(data, tlvsize, &offset, crc_map._map._map.size());
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._map._map.size() && ok;++i)
ok &= setRawUInt32(data, tlvsize, &offset, crc_map._map._map[i]);
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]);
@ -624,11 +624,11 @@ RsTurtleFileCrcItem::RsTurtleFileCrcItem(void *data,uint32_t pktsize)
ok &= getRawUInt32(data, pktsize, &offset, &s1) ;
ok &= getRawUInt32(data, pktsize, &offset, &s2) ;
crc_map._map._map.resize(s1) ;
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._map._map[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])) ;
@ -1092,8 +1092,8 @@ std::ostream& RsTurtleFileCrcItem::print(std::ostream& o, uint16_t)
o << " tunnel id : " << (void*)tunnel_id << std::endl ;
o << " map : " ;
for(uint32_t i=0;i<crc_map._map._map.size();++i)
o << (void*)crc_map._map._map[i] << std::endl ;
for(uint32_t i=0;i<crc_map._ccmap._map.size();++i)
o << (void*)crc_map._ccmap._map[i] << std::endl ;
o << " CRC : " ;

View File

@ -21,7 +21,7 @@ const uint8_t RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST = 0x09 ;
const uint8_t RS_TURTLE_SUBTYPE_FILE_MAP = 0x10 ;
const uint8_t RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST = 0x11 ;
const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC = 0x12 ;
const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST = 0xfe ; // test value
const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST = 0x13 ;
/***********************************************************************************/
/* Basic Turtle Item Class */

View File

@ -421,31 +421,33 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
int TransfersDialog::addItem(const QString&, const QString& name, const QString& coreID, qlonglong fileSize, const FileProgressInfo& pinfo, double dlspeed,
const QString& sources, const QString& status, const QString& priority, qlonglong completed, qlonglong remaining, qlonglong downloadtime)
{
int row;
QList<QStandardItem *> list = DLListModel->findItems(coreID, Qt::MatchExactly, ID);
if (list.size() > 0) {
row = list.front()->row();
} else {
row = DLListModel->rowCount();
DLListModel->insertRow(row);
}
int row ;
for(row=0;row<ULListModel->rowCount();++row)
if(DLListModel->item(row,ID)->data(Qt::EditRole).toString() == coreID)
break ;
DLListModel->setData(DLListModel->index(row, NAME), QVariant(name));
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)fileSize));
DLListModel->setData(DLListModel->index(row, COMPLETED), QVariant((qlonglong)completed));
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)dlspeed));
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant::fromValue(pinfo));
DLListModel->setData(DLListModel->index(row, SOURCES), QVariant((QString)sources));
DLListModel->setData(DLListModel->index(row, STATUS), QVariant((QString)status));
DLListModel->setData(DLListModel->index(row, PRIORITY), QVariant((QString)priority));
DLListModel->setData(DLListModel->index(row, REMAINING), QVariant((qlonglong)remaining));
DLListModel->setData(DLListModel->index(row, DOWNLOADTIME), QVariant((qlonglong)downloadtime));
DLListModel->setData(DLListModel->index(row, ID), QVariant((QString)coreID));
if(row >= DLListModel->rowCount() )
{
row = DLListModel->rowCount();
DLListModel->insertRow(row);
}
QString ext = QFileInfo(name).suffix();
DLListModel->setData(DLListModel->index(row,NAME), getIconFromExtension(ext), Qt::DecorationRole);
DLListModel->setData(DLListModel->index(row, NAME), QVariant(name));
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)fileSize));
DLListModel->setData(DLListModel->index(row, COMPLETED), QVariant((qlonglong)completed));
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)dlspeed));
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant::fromValue(pinfo));
DLListModel->setData(DLListModel->index(row, SOURCES), QVariant((QString)sources));
DLListModel->setData(DLListModel->index(row, STATUS), QVariant((QString)status));
DLListModel->setData(DLListModel->index(row, PRIORITY), QVariant((QString)priority));
DLListModel->setData(DLListModel->index(row, REMAINING), QVariant((qlonglong)remaining));
DLListModel->setData(DLListModel->index(row, DOWNLOADTIME), QVariant((qlonglong)downloadtime));
DLListModel->setData(DLListModel->index(row, ID), QVariant((QString)coreID));
return row ;
QString ext = QFileInfo(name).suffix();
DLListModel->setData(DLListModel->index(row,NAME), getIconFromExtension(ext), Qt::DecorationRole);
return row ;
}
QIcon TransfersDialog::getIconFromExtension(const QString& ext)
@ -868,13 +870,8 @@ void TransfersDialog::insertTransfers()
std::string hash = ULListModel->item(removeIndex, UHASH)->data(Qt::EditRole).toString().toStdString();
std::string peer = ULListModel->item(removeIndex, UUSERID)->data(Qt::EditRole).toString().toStdString();
std::cerr<< "searching " << hash+peer << std::endl ;
if(used_hashes.find(hash + peer) == used_hashes.end())
{
std::cerr << "found"<< std::endl ;
QListDelete (ULListModel->takeRow(removeIndex));
}
else
removeIndex++;
}