- 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 ;