added chunk request info, and chunk download info. Corrected bug displaying speed for stalled transfers. Warning: needs full recompilation

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3935 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-12-26 10:58:02 +00:00
parent 304bbf55cf
commit 40efe19efa
7 changed files with 69 additions and 29 deletions

View File

@ -38,10 +38,10 @@ class ftChunk
friend std::ostream& operator<<(std::ostream& o,const ftChunk& f) ;
uint64_t offset;
uint64_t size;
ChunkId id ;
time_t ts;
uint64_t offset; // current offset of the slice
uint64_t size; // size remaining to download
ChunkId id ; // id of the chunk. Equal to the starting offset of the chunk
time_t ts; // time of last data received
std::string peer_id ;
};

View File

@ -373,30 +373,6 @@ bool ftFileCreator::getMissingChunk(const std::string& peer_id,uint32_t size_hin
#endif
source_chunk_map_needed = false ;
/* check for freed chunks */
time_t ts = time(NULL);
// time_t old = ts-CHUNK_MAX_AGE;
//
// std::map<uint64_t, ftChunk>::iterator it;
// for(it = mChunks.begin(); it != mChunks.end(); it++)
// {
// /* very simple algorithm */
// if (it->second.ts < old)
// {
//#ifdef FILE_DEBUG
// std::cerr << "ffc::getMissingChunk() Re-asking for an old chunk";
// std::cerr << std::endl;
//#endif
//
// /* retry this one */
// it->second.ts = ts;
// size = it->second.size;
// offset = it->second.offset;
//
// return true;
// }
// }
uint32_t& chunks_for_this_peer(mChunksPerPeer[peer_id].cnt) ;
if(chunks_for_this_peer >= MAX_FTCHUNKS_PER_PEER)
@ -433,6 +409,22 @@ void ftFileCreator::getChunkMap(FileChunksInfo& info)
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
chunkMap.getChunksInfo(info) ;
// add info pending requests, handled by ftFileCreator
//
info.pending_slices.clear();
for(std::map<uint64_t, ftChunk>::iterator it = mChunks.begin();it!=mChunks.end();++it)
{
int n = it->second.id / info.chunk_size ;
FileChunksInfo::SliceInfo si ;
si.start = it->second.offset - n*info.chunk_size ;
si.size = it->second.size ;
si.peer_id = it->second.peer_id ;
info.pending_slices[n].push_back(si) ;
}
}
bool ftFileCreator::locked_printChunkMap()

View File

@ -289,6 +289,13 @@ class FileChunksInfo
enum ChunkState { CHUNK_DONE=2, CHUNK_ACTIVE=1, CHUNK_OUTSTANDING=0 } ;
enum ChunkStrategy { CHUNK_STRATEGY_STREAMING, CHUNK_STRATEGY_RANDOM } ;
struct SliceInfo
{
uint32_t start ;
uint32_t size ;
std::string peer_id ;
};
uint64_t file_size ; // real size of the file
uint32_t chunk_size ; // size of chunks
uint32_t flags ;
@ -303,6 +310,10 @@ class FileChunksInfo
// For each chunk (by chunk number), gives the completion of the chunk.
//
std::vector<std::pair<uint32_t,uint32_t> > active_chunks ;
// The list of pending requests, chunk per chunk (by chunk id)
//
std::map<uint32_t, std::vector<SliceInfo> > pending_slices ;
};
class CompressedChunkMap

View File

@ -170,9 +170,30 @@ void FileTransferInfoWidget::draw(const FileInfo& nfo,const FileChunksInfo& info
int size_of_this_chunk = ( info.active_chunks[i].first == info.chunks.size()-1 && ((info.file_size % blockSize)>0) )?(info.file_size % blockSize):blockSize ;
uint32_t s = (uint32_t)rint(sizeX*(size_of_this_chunk - info.active_chunks[i].second)/(float)size_of_this_chunk) ;
std::cerr << "chunk " << info.active_chunks[i].first << ": Last received byte: " << size_of_this_chunk - info.active_chunks[i].second << std::endl;
// Already Downloaded.
//
painter->fillRect(ch_num_size,y,s,sizeY,QColor::fromHsv(200,200,255)) ;
// Remains to download
//
painter->fillRect(ch_num_size+s,y,sizeX-s,sizeY,QColor::fromHsv(200,50,255)) ;
// now draw the slices under pending requests
//
std::map<uint32_t,std::vector<FileChunksInfo::SliceInfo> >::const_iterator it(info.pending_slices.find(info.active_chunks[i].first)) ;
if(it != info.pending_slices.end())
for(uint k=0;k<it->second.size();++k)
{
uint32_t s1 = (uint32_t)floor(sizeX*(it->second[k].start)/(float)size_of_this_chunk) ;
uint32_t ss = (uint32_t)ceil(sizeX*(it->second[k].size )/(float)size_of_this_chunk) ;
painter->fillRect(ch_num_size+s1,y,ss,sizeY,QColor::fromHsv(50,250,250)) ;
}
painter->setPen(QColor::fromRgb(0,0,0)) ;
float percent = (size_of_this_chunk - info.active_chunks[i].second)*100.0/size_of_this_chunk ;

View File

@ -775,7 +775,7 @@ void TransfersDialog::insertTransfers()
QString fileName = QString::fromUtf8(info.fname.c_str());
QString fileHash = QString::fromStdString(info.hash);
qlonglong fileSize = info.size;
double fileDlspeed = (info.downloadStatus==FT_STATE_PAUSED)?0.0:(info.tfRate * 1024.0);
double fileDlspeed = (info.downloadStatus==FT_STATE_DOWNLOADING)?(info.tfRate * 1024.0):0.0;
/* get the sources (number of online peers) */
int online = 0;
@ -827,6 +827,9 @@ void TransfersDialog::insertTransfers()
pinfo.progress = (info.size==0)?0:(completed*100.0/info.size) ;
pinfo.nb_chunks = pinfo.cmap._map.empty()?0:fcinfo.chunks.size() ;
for(uint32_t i=0;i<fcinfo.active_chunks.size();++i)
pinfo.chunks_in_progress.push_back(fcinfo.active_chunks[i].first) ;
int addedRow = addItem("", fileName, fileHash, fileSize, pinfo, fileDlspeed, sources, status, priority, completed, remaining, downloadtime);
used_hashes.insert(info.hash) ;

View File

@ -219,6 +219,17 @@ void xProgressBar::paint()
i += j ;
}
QColor gradColor_a1, gradColor_a2 ;
gradColor_a1.setRgb(223, 134, 6);
gradColor_a2.setRgb(248, 170, 59);
linearGrad.setColorAt(0.00, gradColor_a1);
linearGrad.setColorAt(0.16, gradColor_a2);
linearGrad.setColorAt(1.00, gradColor_a1);
painter->setBrush(linearGrad);
for(uint32_t i=0;i<_pinfo.chunks_in_progress.size();++i)
painter->drawRect(rect.x() + hSpan+(int)rint(_pinfo.chunks_in_progress[i]*width/(float)ss), rect.y() + vSpan, (int)ceil(1.0f*width/(float)ss), rect.height() - 1 - vSpan * 2);
}
else
{

View File

@ -46,6 +46,8 @@ class FileProgressInfo
float progress ;
uint32_t nb_chunks ;
std::vector<uint32_t> chunks_in_progress ;
bool operator<(const FileProgressInfo &other) const;
};
//