mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-23 22:49:37 -05:00
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:
parent
bd569ce42a
commit
a3d3778c36
@ -427,6 +427,8 @@ bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider,
|
||||
|
||||
if (provider->getFileData(offset, chunksize, data))
|
||||
{
|
||||
// setup info
|
||||
provider->setPeerId(peerId) ;
|
||||
/* send data out */
|
||||
sendData(peerId, hash, size, offset, chunksize, data);
|
||||
return true;
|
||||
|
@ -1,11 +1,13 @@
|
||||
#include <sys/times.h>
|
||||
#include "ftfileprovider.h"
|
||||
|
||||
#include "util/rsdir.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
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(){
|
||||
@ -14,6 +16,12 @@ ftFileProvider::~ftFileProvider(){
|
||||
}
|
||||
}
|
||||
|
||||
void ftFileProvider::setPeerId(const std::string& id)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
lastRequestor = id ;
|
||||
}
|
||||
|
||||
bool ftFileProvider::fileOk()
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
@ -34,12 +42,22 @@ uint64_t ftFileProvider::getFileSize()
|
||||
|
||||
bool ftFileProvider::FileDetails(FileInfo &info)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
info.hash = hash;
|
||||
info.size = mSize;
|
||||
info.path = 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 */
|
||||
|
||||
return true;
|
||||
@ -55,7 +73,7 @@ bool ftFileProvider::getFileData(uint64_t offset, uint32_t &chunk_size, void *da
|
||||
if (!initializeFileAttrs())
|
||||
return false;
|
||||
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
/*
|
||||
* Use private data, which has a pointer to file, total size etc
|
||||
@ -105,9 +123,14 @@ bool ftFileProvider::getFileData(uint64_t offset, uint32_t &chunk_size, void *da
|
||||
* (d) timestamp
|
||||
*/
|
||||
|
||||
time_t now = time(NULL);
|
||||
clock_t now = times(NULL);
|
||||
req_loc = offset;
|
||||
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;
|
||||
}
|
||||
else {
|
||||
|
@ -47,6 +47,8 @@ public:
|
||||
uint64_t getFileSize();
|
||||
bool fileOk();
|
||||
|
||||
void setPeerId(const std::string& id) ;
|
||||
|
||||
|
||||
protected:
|
||||
virtual int initializeFileAttrs(); /* does for both */
|
||||
@ -63,7 +65,8 @@ virtual int initializeFileAttrs(); /* does for both */
|
||||
std::string lastRequestor;
|
||||
uint64_t req_loc;
|
||||
uint32_t req_size;
|
||||
time_t lastTS;
|
||||
clock_t lastTS;
|
||||
float transfer_rate ;
|
||||
|
||||
/*
|
||||
* Mutex Required for stuff below
|
||||
|
Loading…
Reference in New Issue
Block a user