mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
- changed Sha1CheckSum from hand-made class to instance of t_GenericIdType<> (should be backward compatible)
- updated ft/, p3msgservice and p3chatservice accordingly - added a new class for Sha1Sum in t_GeneridIdType<>, and an additional template argument to make ids of identical size incompatible. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7082 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
10bf083ca3
commit
235280399f
19 changed files with 67 additions and 441 deletions
|
@ -38,12 +38,12 @@
|
|||
#include <string>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <util/rsid.h>
|
||||
#include <retroshare/rstypes.h>
|
||||
|
||||
/*************** SEND INTERFACE *******************/
|
||||
|
||||
class CompressedChunkMap ;
|
||||
class Sha1CheckSum ;
|
||||
|
||||
class ftDataSend
|
||||
{
|
||||
|
|
|
@ -696,61 +696,5 @@ bool ftFileCreator::verifyChunk(uint32_t chunk_number,const Sha1CheckSum& sum)
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool ftFileCreator::crossCheckChunkMap(const CRC32Map& ref,uint32_t& bad_chunks,uint32_t& incomplete_chunks)
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
CompressedChunkMap map ;
|
||||
|
||||
// Start with a full map.
|
||||
ChunkMap::buildPlainMap(mSize,map) ;
|
||||
uint32_t nb_chunks = ref.size() ;
|
||||
static const uint32_t chunk_size = ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE ;
|
||||
|
||||
std::cerr << "ftFileCreator::crossCheckChunkMap(): comparing chunks..." << std::endl;
|
||||
|
||||
if(!locked_initializeFileAttrs() )
|
||||
return false ;
|
||||
|
||||
unsigned char *buff = new unsigned char[chunk_size] ;
|
||||
incomplete_chunks = 0 ;
|
||||
bad_chunks = 0 ;
|
||||
uint32_t len = 0 ;
|
||||
|
||||
for(uint32_t i=0;i<nb_chunks;++i)
|
||||
{
|
||||
printf(" Chunk %05d/%05d:",i,nb_chunks) ;
|
||||
|
||||
if(fseeko64(fd,(uint64_t)i * (uint64_t)chunk_size,SEEK_SET)==0 && (len = fread(buff,1,chunk_size,fd)) > 0)
|
||||
{
|
||||
uint32_t crc = RsDirUtil::rs_CRC32(buff,len) ;
|
||||
|
||||
printf(" crc: %08x, ref: %08x : ",crc,ref[i]) ;
|
||||
|
||||
if(crc != ref[i])
|
||||
{
|
||||
printf(" CRC ERROR!!\n") ;
|
||||
++bad_chunks ;
|
||||
map.reset(i) ;
|
||||
}
|
||||
else
|
||||
printf(" matched\n") ;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" cannot fseek!\n") ;
|
||||
++bad_chunks ;
|
||||
map.reset(i) ;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] buff ;
|
||||
|
||||
chunkMap.setAvailabilityMap(map) ;
|
||||
}
|
||||
closeFile() ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -71,12 +71,6 @@ class ftFileCreator: public ftFileProvider
|
|||
|
||||
bool hashReceivedData(std::string& hash) ;
|
||||
|
||||
// Checks the CRC32 of all chunks against the given CRC32 map. Re-flag the bad chunks as being void.
|
||||
// bad_chunks: count of achieved chunks that don't match the CRC
|
||||
// incomplete_chunks: count of any bad or not yet downloaded chunk
|
||||
//
|
||||
bool crossCheckChunkMap(const CRC32Map& ref,uint32_t& bad_chunks,uint32_t& incomplete_chunks) ;
|
||||
|
||||
// Sets all chunks to checking state
|
||||
//
|
||||
void forceCheck() ;
|
||||
|
|
|
@ -463,8 +463,6 @@ RsTurtleGenericTunnelItem *ftServer::deserialiseItem(void *data,uint32_t size) c
|
|||
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) ;
|
||||
|
||||
|
|
|
@ -92,10 +92,6 @@ ftTransferModule::ftTransferModule(ftFileCreator *fc, ftDataMultiplex *dm, ftCon
|
|||
//mChunkSize = 10000;
|
||||
desiredRate = FT_TM_MAX_PEER_RATE; /* 1MB/s ??? */
|
||||
actualRate = 0;
|
||||
_crcmap_state = FT_TM_CRC_MAP_STATE_NOCHECK ;
|
||||
_crcmap_last_asked_time = 0 ;
|
||||
_crcmap_last_tunnel_keepup = 0 ;
|
||||
_crcreq_source = "";
|
||||
|
||||
_last_activity_time_stamp = time(NULL) ;
|
||||
}
|
||||
|
|
|
@ -136,7 +136,6 @@ public:
|
|||
bool completeFileTransfer();
|
||||
bool isCheckingHash() ;
|
||||
void forceCheck() ;
|
||||
void addCRC32Map(const CRC32Map& map) ;
|
||||
|
||||
//interface to multiplex module
|
||||
bool recvFileData(const std::string& peerId, uint64_t offset, uint32_t chunk_size, void *data);
|
||||
|
@ -188,12 +187,6 @@ private:
|
|||
double desiredRate;
|
||||
double actualRate;
|
||||
|
||||
CRC32Map _crcmap ;
|
||||
uint32_t _crcmap_state ;
|
||||
time_t _crcmap_last_asked_time ;
|
||||
time_t _crcmap_last_tunnel_keepup ;
|
||||
std::string _crcreq_source ;
|
||||
|
||||
time_t _last_activity_time_stamp ;
|
||||
|
||||
ftFileStatus mFileStatus; //used for pause/resume file transfer
|
||||
|
|
|
@ -109,21 +109,6 @@ uint32_t RsTurtleChunkCrcRequestItem::serial_size()
|
|||
|
||||
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();
|
||||
|
@ -262,47 +247,7 @@ bool RsTurtleChunkCrcRequestItem::serialize(void *data,uint32_t& pktsize)
|
|||
|
||||
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
|
||||
|
@ -328,11 +273,7 @@ bool RsTurtleChunkCrcItem::serialize(void *data,uint32_t& pktsize)
|
|||
|
||||
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]);
|
||||
ok &= setRawSha1(data, tlvsize, &offset, check_sum);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
|
@ -398,40 +339,6 @@ RsTurtleFileMapRequestItem::RsTurtleFileMapRequestItem(void *data,uint32_t pktsi
|
|||
#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)
|
||||
{
|
||||
|
@ -446,11 +353,7 @@ RsTurtleChunkCrcItem::RsTurtleChunkCrcItem(void *data,uint32_t pktsize)
|
|||
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]) ;
|
||||
ok &= getRawSha1(data, pktsize, &offset, check_sum) ;
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
|
@ -692,23 +595,7 @@ std::ostream& RsTurtleFileMapRequestItem::print(std::ostream& o, uint16_t)
|
|||
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 ;
|
||||
|
|
|
@ -132,24 +132,6 @@ class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem
|
|||
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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue