Implemented load/save of chunk maps for current downloads.

The side effect is that even when stopped, downloads show the correct downloaded size (up to the size of one chunk).



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1865 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-12-10 22:55:27 +00:00
parent 4d190963cf
commit b6c048a5fd
8 changed files with 200 additions and 48 deletions

View file

@ -31,8 +31,6 @@
#define RSSERIAL_DEBUG 1
***/
#define RSSERIAL_DEBUG 1
#include <iostream>
/*************************************************************************/
@ -198,6 +196,11 @@ uint32_t RsFileConfigSerialiser::sizeTransfer(RsFileTransfer *item)
s += 4; /* trate */
s += 4; /* lrate */
s += 4; /* ltransfer */
s += 4; // chunk_size
s += 4; // chunk_number
s += 4; // chunk_strategy
s += 4; // chunk map size
s += 4*item->chunk_map.size(); // chunk_map
return s;
}
@ -240,6 +243,14 @@ bool RsFileConfigSerialiser::serialiseTransfer(RsFileTransfer *item, void *d
ok &= setRawUInt32(data, tlvsize, &offset, item->lrate);
ok &= setRawUInt32(data, tlvsize, &offset, item->ltransfer);
ok &= setRawUInt32(data, tlvsize, &offset, item->chunk_size);
ok &= setRawUInt32(data, tlvsize, &offset, item->chunk_number);
ok &= setRawUInt32(data, tlvsize, &offset, item->chunk_strategy);
ok &= setRawUInt32(data, tlvsize, &offset, item->chunk_map.size());
for(uint32_t i=0;i<item->chunk_map.size();++i)
ok &= setRawUInt32(data, tlvsize, &offset, item->chunk_map[i]);
if (offset != tlvsize)
{
ok = false;
@ -299,6 +310,16 @@ RsFileTransfer *RsFileConfigSerialiser::deserialiseTransfer(void *data, uint32_t
ok &= getRawUInt32(data, rssize, &offset, &(item->lrate));
ok &= getRawUInt32(data, rssize, &offset, &(item->ltransfer));
ok &= getRawUInt32(data, rssize, &offset, &(item->chunk_size));
ok &= getRawUInt32(data, rssize, &offset, &(item->chunk_number));
ok &= getRawUInt32(data, rssize, &offset, &(item->chunk_strategy));
uint32_t map_size = 0 ;
ok &= getRawUInt32(data, rssize, &offset, &map_size);
item->chunk_map.resize(map_size) ;
for(uint32_t i=0;i<map_size;++i)
ok &= getRawUInt32(data, rssize, &offset, &(item->chunk_map[i]));
if (offset != rssize)
{
/* error */

View file

@ -27,6 +27,7 @@
*/
#include <map>
#include <vector>
#include "serialiser/rsserial.h"
#include "serialiser/rstlvbase.h"
@ -179,31 +180,34 @@ virtual RsItem * deserialise(void *data, uint32_t *size);
class RsFileTransfer: public RsItem
{
public:
RsFileTransfer()
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
RS_PKT_TYPE_FILE_CONFIG,
RS_PKT_SUBTYPE_FILE_TRANSFER)
{ return; }
virtual ~RsFileTransfer();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsFileTransfer() :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG, RS_PKT_SUBTYPE_FILE_TRANSFER)
{
return;
}
virtual ~RsFileTransfer();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsTlvFileItem file;
RsTlvPeerIdSet allPeerIds;
RsTlvFileItem file;
RsTlvPeerIdSet allPeerIds;
std::string cPeerId;
std::string cPeerId;
uint16_t state;
uint16_t in;
uint16_t state;
uint16_t in;
uint64_t transferred;
uint32_t crate;
uint32_t trate;
uint64_t transferred;
uint32_t crate;
uint32_t trate;
uint32_t lrate;
uint32_t ltransfer;
uint32_t lrate;
uint32_t ltransfer;
// chunk information
uint32_t chunk_size ; // common size of chunks
uint32_t chunk_number ; // total number of chunks (this is not redondant, cause chunks are compressed)
uint32_t chunk_strategy ; // strategy flags for chunks
std::vector<uint32_t> chunk_map ; // chunk availability (bitwise)
};
/**************************************************************************/