mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-17 05:22:31 -04:00
- implemented bidirectional exchange of chunk maps for direct downloads, to allow showing proper completion of transfers from direct friends.
- moved the direction flag upward in the pipeline (ftDataSend instead of p3turtle) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3313 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
569ac25843
commit
cee8600a93
13 changed files with 483 additions and 71 deletions
|
@ -54,10 +54,14 @@ class ftDataSend
|
|||
/* Server Send */
|
||||
virtual bool sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data) = 0;
|
||||
|
||||
/// Send a request for a chunk map
|
||||
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash) = 0;
|
||||
/// Send a chunk map
|
||||
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap) = 0;
|
||||
/// Send a chunkmap[request]. Because requests/chunkmaps can go both
|
||||
//directions, but for different usages, we have this "is_client" flags,
|
||||
//that gives the ultimate goal of the data. "is_client==true" means that
|
||||
//the message is for a client (download) instead of a server.
|
||||
//
|
||||
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) = 0;
|
||||
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) = 0;
|
||||
|
||||
/// Send a request for a chunk crc map
|
||||
virtual bool sendCRC32MapRequest(const std::string& peer_id,const std::string& hash) = 0;
|
||||
/// Send a chunk crc map
|
||||
|
|
|
@ -528,7 +528,7 @@ bool ftDataMultiplex::handleRecvClientChunkMapRequest(const std::string& peerId,
|
|||
(it->second).mCreator->getAvailabilityMap(cmap);
|
||||
}
|
||||
|
||||
mDataSend->sendChunkMap(peerId,hash,cmap);
|
||||
mDataSend->sendChunkMap(peerId,hash,cmap,false);
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ bool ftDataMultiplex::handleRecvServerChunkMapRequest(const std::string& peerId,
|
|||
it->second->getAvailabilityMap(cmap);
|
||||
}
|
||||
|
||||
mDataSend->sendChunkMap(peerId,hash,cmap);
|
||||
mDataSend->sendChunkMap(peerId,hash,cmap,true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -719,14 +719,14 @@ bool ftDataMultiplex::getClientChunkMap(const std::string& upload_hash,const std
|
|||
// If the map is too old then we should ask an other map to the peer.
|
||||
//
|
||||
if(too_old)
|
||||
sendChunkMapRequest(peerId,upload_hash);
|
||||
sendChunkMapRequest(peerId,upload_hash,true);
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftDataMultiplex::sendChunkMapRequest(const std::string& peer_id,const std::string& hash)
|
||||
bool ftDataMultiplex::sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client)
|
||||
{
|
||||
return mDataSend->sendChunkMapRequest(peer_id,hash);
|
||||
return mDataSend->sendChunkMapRequest(peer_id,hash,is_client);
|
||||
}
|
||||
bool ftDataMultiplex::sendCRCMapRequest(const std::string& peer_id,const std::string& hash,const CompressedChunkMap&)
|
||||
{
|
||||
|
|
|
@ -108,7 +108,7 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
|
|||
bool sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
|
||||
/* Server/client Send */
|
||||
bool sendChunkMapRequest(const std::string& peerId, const std::string& hash) ;
|
||||
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) ;
|
||||
|
|
|
@ -738,27 +738,50 @@ bool ftServer::sendDataRequest(const std::string& peerId, const std::string& has
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string& hash)
|
||||
bool ftServer::sendChunkMapRequest(const std::string& peerId,const std::string& hash,bool is_client)
|
||||
{
|
||||
if(mTurtleRouter->isTurtlePeer(peerId))
|
||||
mTurtleRouter->sendChunkMapRequest(peerId,hash) ;
|
||||
mTurtleRouter->sendChunkMapRequest(peerId,hash,is_client) ;
|
||||
else
|
||||
std::cerr << "ftServer: Warning: not sending chunk map request to peer " << peerId << ", because it's not a turtle tunnel." << std::endl ;
|
||||
{
|
||||
/* create a packet */
|
||||
/* push to networking part */
|
||||
RsFileChunkMapRequest *rfi = new RsFileChunkMapRequest();
|
||||
|
||||
/* id */
|
||||
rfi->PeerId(peerId);
|
||||
|
||||
/* file info */
|
||||
rfi->hash = hash; /* ftr->hash; */
|
||||
rfi->is_client = is_client ;
|
||||
|
||||
mP3iface->SendFileChunkMapRequest(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::sendChunkMap(const std::string& peerId,const std::string& hash,const CompressedChunkMap& map)
|
||||
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) ;
|
||||
mTurtleRouter->sendChunkMap(peerId,hash,map,is_client) ;
|
||||
else
|
||||
std::cerr << "ftServer: Warning: not sending chunk map to peer " << peerId << ", because it's not a turtle tunnel." << std::endl ;
|
||||
{
|
||||
/* create a packet */
|
||||
/* push to networking part */
|
||||
RsFileChunkMap *rfi = new RsFileChunkMap();
|
||||
|
||||
/* id */
|
||||
rfi->PeerId(peerId);
|
||||
|
||||
/* file info */
|
||||
rfi->hash = hash; /* ftr->hash; */
|
||||
rfi->is_client = is_client; /* ftr->hash; */
|
||||
rfi->compressed_map = map; /* ftr->hash; */
|
||||
|
||||
mP3iface->SendFileChunkMap(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::sendCRC32MapRequest(const std::string& peerId,const std::string& hash)
|
||||
|
@ -1022,6 +1045,8 @@ bool ftServer::handleFileData()
|
|||
// now File Input.
|
||||
RsFileRequest *fr;
|
||||
RsFileData *fd;
|
||||
RsFileChunkMapRequest *fcmr;
|
||||
RsFileChunkMap *fcm;
|
||||
|
||||
int i_init = 0;
|
||||
int i = 0;
|
||||
|
@ -1082,7 +1107,48 @@ FileInfo(ffr);
|
|||
fd->fd.binData.TlvShallowClear();
|
||||
delete fd;
|
||||
}
|
||||
// now file chunkmap requests
|
||||
i_init = i;
|
||||
while((fcmr = mP3iface -> GetFileChunkMapRequest()) != 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;
|
||||
}
|
||||
fcmr -> print(out);
|
||||
rslog(RSL_DEBUG_BASIC, ftserverzone, out.str());
|
||||
#endif
|
||||
i++; /* count */
|
||||
|
||||
/* incoming data */
|
||||
mFtDataplex->recvChunkMapRequest(fcmr->PeerId(), fcmr->hash,fcmr->is_client) ;
|
||||
|
||||
delete fcmr;
|
||||
}
|
||||
// now file chunkmaps
|
||||
i_init = i;
|
||||
while((fcm = mP3iface -> GetFileChunkMap()) != 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;
|
||||
}
|
||||
fcm -> print(out);
|
||||
rslog(RSL_DEBUG_BASIC, ftserverzone, out.str());
|
||||
#endif
|
||||
i++; /* count */
|
||||
|
||||
/* incoming data */
|
||||
mFtDataplex->recvChunkMap(fcm->PeerId(), fcm->hash,fcm->compressed_map,fcm->is_client) ;
|
||||
|
||||
delete fcm;
|
||||
}
|
||||
if (i > 0)
|
||||
{
|
||||
return 1;
|
||||
|
|
|
@ -210,8 +210,8 @@ virtual bool unshareDownloadDirectory();
|
|||
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) ;
|
||||
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap) ;
|
||||
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&) ;
|
||||
|
||||
|
|
|
@ -348,7 +348,7 @@ bool ftTransferModule::getChunk(const std::string& peer_id,uint32_t size_hint,ui
|
|||
bool val = mFileCreator->getMissingChunk(peer_id,size_hint,offset, chunk_size,source_peer_map_needed);
|
||||
|
||||
if(source_peer_map_needed)
|
||||
mMultiplexor->sendChunkMapRequest(peer_id, mHash) ;
|
||||
mMultiplexor->sendChunkMapRequest(peer_id, mHash,false) ;
|
||||
|
||||
#ifdef FT_DEBUG
|
||||
if (val)
|
||||
|
@ -683,7 +683,6 @@ bool ftTransferModule::checkCRC()
|
|||
|
||||
// _crcmap_last_source_id = (_crcmap_last_source_id+1)%mFileSources.size() ;
|
||||
|
||||
int n=0 ;
|
||||
bool found = false ;
|
||||
std::map<std::string,peerInfo>::const_iterator mit ;
|
||||
for(mit = mFileSources.begin();mit != mFileSources.end();++mit)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue