From e88d2c1928abbb5d7145f6362bf90a1ee371e642 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 18 Nov 2009 23:02:37 +0000 Subject: [PATCH] Added consistent display of chunk map git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1837 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/ft/ftcontroller.cc | 14 +++++++++++ libretroshare/src/ft/ftcontroller.h | 1 + libretroshare/src/ft/ftfilecreator.cc | 15 +++++++++++- libretroshare/src/ft/ftfilecreator.h | 3 +++ libretroshare/src/ft/ftserver.cc | 24 ++++++++++--------- libretroshare/src/libretroshare.pro | 8 +++++-- .../src/gui/FileTransferInfoWidget.cpp | 2 +- 7 files changed, 52 insertions(+), 15 deletions(-) diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index 5f3eb414f..32ad7d06f 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -94,6 +94,20 @@ void ftController::setFtSearchNExtra(ftSearch *search, ftExtraList *list) mExtraList = list; } +bool ftController::getFileChunksDetails(const std::string& hash,FileChunksInfo& info) +{ + RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ + + std::map::iterator it = mDownloads.find(hash) ; + + if(it == mDownloads.end()) + return false ; + + it->second.mCreator->getChunkMap(info) ; + + return true ; +} + void ftController::addFileSource(const std::string& hash,const std::string& peer_id) { RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ diff --git a/libretroshare/src/ft/ftcontroller.h b/libretroshare/src/ft/ftcontroller.h index 82c54c331..553413a1e 100644 --- a/libretroshare/src/ft/ftcontroller.h +++ b/libretroshare/src/ft/ftcontroller.h @@ -136,6 +136,7 @@ bool FileCancel(std::string hash); bool FileControl(std::string hash, uint32_t flags); bool FileClearCompleted(); bool FlagFileComplete(std::string hash); +bool getFileChunksDetails(const std::string& hash,FileChunksInfo& info); /* get Details of File Transfers */ bool FileDownloads(std::list &hashs); diff --git a/libretroshare/src/ft/ftfilecreator.cc b/libretroshare/src/ft/ftfilecreator.cc index 255f0f7e5..a03a0b8e9 100644 --- a/libretroshare/src/ft/ftfilecreator.cc +++ b/libretroshare/src/ft/ftfilecreator.cc @@ -16,7 +16,7 @@ ***********************************************************/ ftFileCreator::ftFileCreator(std::string path, uint64_t size, std::string -hash, uint64_t recvd): ftFileProvider(path,size,hash) +hash, uint64_t recvd): ftFileProvider(path,size,hash), chunkMap(size) { /* * FIXME any inits to do? @@ -38,6 +38,8 @@ hash, uint64_t recvd): ftFileProvider(path,size,hash) /* initialise the Transfer Lists */ mStart = recvd; mEnd = recvd; + + chunkMap.received(recvd) ; } bool ftFileCreator::getFileData(uint64_t offset, @@ -264,6 +266,9 @@ int ftFileCreator::locked_notifyReceived(uint64_t offset, uint32_t chunk_size) mStart = offset + chunk_size; } + // update chunk map + chunkMap.received(mStart) ; + if (mChunks.size() == 0) { mStart = mEnd; @@ -271,6 +276,7 @@ int ftFileCreator::locked_notifyReceived(uint64_t offset, uint32_t chunk_size) /* otherwise there is another earlier block to go */ + return 1; } @@ -349,11 +355,18 @@ bool ftFileCreator::getMissingChunk(uint64_t &offset, uint32_t &chunk) #endif mChunks[offset] = ftChunk(offset, chunk, ts); + + chunkMap.requested(offset,chunk) ; } return true; /* cos more data to get */ } +void ftFileCreator::getChunkMap(FileChunksInfo& info) +{ + RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ + info = chunkMap ; +} bool ftFileCreator::locked_printChunkMap() { diff --git a/libretroshare/src/ft/ftfilecreator.h b/libretroshare/src/ft/ftfilecreator.h index 2968b0ca9..2b990172a 100644 --- a/libretroshare/src/ft/ftfilecreator.h +++ b/libretroshare/src/ft/ftfilecreator.h @@ -33,6 +33,7 @@ * */ #include "ftfileprovider.h" +#include "ftchunkmap.h" #include class ftChunk; @@ -49,6 +50,7 @@ virtual bool getFileData(uint64_t offset, uint32_t &chunk_size, void *data); bool finished() { return getRecvd() == getFileSize(); } uint64_t getRecvd(); + void getChunkMap(FileChunksInfo& info) ; /* * creation functions for FileCreator @@ -74,6 +76,7 @@ private: std::map mChunks; + ChunkMap chunkMap ; }; class ftChunk { diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index ed6ff3f91..c46a0f709 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -307,17 +307,19 @@ void ftServer::getDwlDetails(std::list & details) bool ftServer::FileChunksDetails(const std::string& hash,FileChunksInfo& info) { - // for know put some dummy info. It's for display sake only. - info.chunk_size = 1024*1024 ; - info.file_size = 250*info.chunk_size - 123 ; // last chunk is not complete. - info.chunks.resize(250,FileChunksInfo::CHUNK_DONE) ; - int n = rand()%150 + 50 ; - for(int i=0;i<10;++i) - info.chunks[n+i] = FileChunksInfo::CHUNK_ACTIVE ; - for(int i=n+10;i<250;++i) - info.chunks[i] = FileChunksInfo::CHUNK_OUTSTANDING ; - - return true ; + return mFtController->getFileChunksDetails(hash,info); +// +// // for know put some dummy info. It's for display sake only. +// info.chunk_size = 1024*1024 ; +// info.file_size = 250*info.chunk_size - 123 ; // last chunk is not complete. +// info.chunks.resize(250,FileChunksInfo::CHUNK_DONE) ; +// int n = rand()%150 + 50 ; +// for(int i=0;i<10;++i) +// info.chunks[n+i] = FileChunksInfo::CHUNK_ACTIVE ; +// for(int i=n+10;i<250;++i) +// info.chunks[i] = FileChunksInfo::CHUNK_OUTSTANDING ; +// +// return true ; } /* Directory Handling */ diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 60d5b4f99..7a9834f42 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -14,8 +14,10 @@ debug { # DEFINES *= DEBUG # DEFINES *= OPENDHT_DEBUG DHT_DEBUG CONN_DEBUG DEBUG_UDP_SORTER P3DISC_DEBUG DEBUG_UDP_LAYER FT_DEBUG EXTADDRSEARCH_DEBUG # DEFINES *= CHAT_DEBUG CONTROL_DEBUG FT_DEBUG -# DEFINES *= P3TURTLE_DEBUG -# DEFINES *= UPNP_DEBUG CONN_DEBUG +# DEFINES *= P3TURTLE_DEBUG UPNP_DEBUG +# DEFINES *= CONN_DEBUG +# DEFINES *= NET_DEBUG +# DEFINES *= DISTRIB_DEBUG QMAKE_CXXFLAGS *= -g } @@ -147,6 +149,7 @@ HEADERS += dbase/cachestrapper.h \ ft/ftfileprovider.h \ ft/ftfilesearch.h \ ft/ftsearch.h \ + ft/ftchunkmap.h \ ft/ftserver.h \ ft/fttransfermodule.h \ ft/ftdwlqueue.h \ @@ -288,6 +291,7 @@ SOURCES += \ ft/ftextralist.cc \ ft/ftfilecreator.cc \ ft/ftdata.cc \ + ft/ftchunkmap.cc \ ft/ftfileprovider.cc \ ft/ftdwlqueue.cc \ dht/opendhtmgr.cc \ diff --git a/retroshare-gui/src/gui/FileTransferInfoWidget.cpp b/retroshare-gui/src/gui/FileTransferInfoWidget.cpp index c33e41f38..23e5ab9c2 100644 --- a/retroshare-gui/src/gui/FileTransferInfoWidget.cpp +++ b/retroshare-gui/src/gui/FileTransferInfoWidget.cpp @@ -101,7 +101,7 @@ void FileTransferInfoWidget::draw(const FileChunksInfo& info,QPainter *painter) if (fileSize%blockSize == 0) blocks--; QRectF source(0.0, 0.0, 12.0, 12.0); - for (int i=0;i<=blocks;i++) + for (int i=0;i maxWidth - 13) {