Added info for upload peers and rate in Transfer tab

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1005 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-02-04 21:35:39 +00:00
parent bd569ce42a
commit a3d3778c36
3 changed files with 34 additions and 6 deletions

View File

@ -427,6 +427,8 @@ bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider,
if (provider->getFileData(offset, chunksize, data)) if (provider->getFileData(offset, chunksize, data))
{ {
// setup info
provider->setPeerId(peerId) ;
/* send data out */ /* send data out */
sendData(peerId, hash, size, offset, chunksize, data); sendData(peerId, hash, size, offset, chunksize, data);
return true; return true;

View File

@ -1,11 +1,13 @@
#include <sys/times.h>
#include "ftfileprovider.h" #include "ftfileprovider.h"
#include "util/rsdir.h" #include "util/rsdir.h"
#include <stdlib.h> #include <stdlib.h>
ftFileProvider::ftFileProvider(std::string path, uint64_t size, std::string ftFileProvider::ftFileProvider(std::string path, uint64_t size, std::string
hash) : mSize(size), hash(hash), file_name(path), fd(NULL) hash) : mSize(size), hash(hash), file_name(path), fd(NULL),transfer_rate(0)
{ {
lastTS = times(NULL) ;
} }
ftFileProvider::~ftFileProvider(){ ftFileProvider::~ftFileProvider(){
@ -14,6 +16,12 @@ ftFileProvider::~ftFileProvider(){
} }
} }
void ftFileProvider::setPeerId(const std::string& id)
{
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
lastRequestor = id ;
}
bool ftFileProvider::fileOk() bool ftFileProvider::fileOk()
{ {
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
@ -39,7 +47,17 @@ bool ftFileProvider::FileDetails(FileInfo &info)
info.size = mSize; info.size = mSize;
info.path = file_name; info.path = file_name;
info.fname = RsDirUtil::getTopDir(file_name); info.fname = RsDirUtil::getTopDir(file_name);
info.lastTS = lastTS; info.transfered = req_loc ;
info.status = FT_STATE_DOWNLOADING ;
info.peers.clear() ;
TransferInfo inf ;
inf.peerId = lastRequestor ;
inf.tfRate = transfer_rate/1024.0 ;
inf.status = FT_STATE_DOWNLOADING ;
info.peers.push_back(inf) ;
/* Use req_loc / req_size to estimate data rate */ /* Use req_loc / req_size to estimate data rate */
return true; return true;
@ -105,9 +123,14 @@ bool ftFileProvider::getFileData(uint64_t offset, uint32_t &chunk_size, void *da
* (d) timestamp * (d) timestamp
*/ */
time_t now = time(NULL); clock_t now = times(NULL);
req_loc = offset; req_loc = offset;
req_size = data_size; req_size = data_size;
transfer_rate = req_size / (float)(std::max(sysconf(_SC_CLK_TCK),(long int)now - (long int)lastTS) / (float)sysconf(_SC_CLK_TCK)) ; // in bytes/s. Average over two samples
std::cout << "req_size = " << req_size << ", now="<< now << ", lastTS=" << lastTS << ", lastTS-now=" << now-lastTS << ", speed = " << transfer_rate << ", clk=" << sysconf(_SC_CLK_TCK) << std::endl ;
lastTS = now; lastTS = now;
} }
else { else {

View File

@ -47,6 +47,8 @@ public:
uint64_t getFileSize(); uint64_t getFileSize();
bool fileOk(); bool fileOk();
void setPeerId(const std::string& id) ;
protected: protected:
virtual int initializeFileAttrs(); /* does for both */ virtual int initializeFileAttrs(); /* does for both */
@ -63,7 +65,8 @@ virtual int initializeFileAttrs(); /* does for both */
std::string lastRequestor; std::string lastRequestor;
uint64_t req_loc; uint64_t req_loc;
uint32_t req_size; uint32_t req_size;
time_t lastTS; clock_t lastTS;
float transfer_rate ;
/* /*
* Mutex Required for stuff below * Mutex Required for stuff below