Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/pqi/pqipersongrp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,20 @@ bool pqipersongrp::getCryptoParams(const RsPeerId& id,RsPeerCryptoParams& params
//return locked_getCryptoParams(id,params) ;
}

bool pqipersongrp::getPeerTotalTraffic(const RsPeerId& id, uint64_t& in, uint64_t& out)
{
RsStackMutex stack(coreMtx); /******* LOCKED MUTEX **********/

std::map<RsPeerId, SearchModule *>::iterator it = mods.find(id) ;

if(it == mods.end())
return false ;

in = it->second->pqi->getTraffic(true);
out = it->second->pqi->getTraffic(false);
return true;


int pqipersongrp::addPeer(const RsPeerId& id)
{
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, "pqipersongrp::addPeer() PeerId: " + id.toStdString());
Expand Down
1 change: 1 addition & 0 deletions src/pqi/pqipersongrp.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ virtual int tick();
virtual int status();

virtual bool getCryptoParams(const RsPeerId&,RsPeerCryptoParams&) ;
virtual bool getPeerTotalTraffic(const RsPeerId& id, uint64_t& in, uint64_t& out);
protected:

virtual bool locked_getCryptoParams(const RsPeerId&, RsPeerCryptoParams&) { return false ;}
Expand Down
8 changes: 7 additions & 1 deletion src/retroshare/rsconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ struct RsConfigDataRates : RsSerializable
mAllocTs(0),
mRateOut(0), mRateMaxOut(0), mAllowedOut(0),
mAllowedTs(0),
mQueueIn(0), mQueueOut(0)
mQueueIn(0), mQueueOut(0),
mTotalIn(0), mTotalOut(0)
{}

/* all in kB/s */
Expand All @@ -168,6 +169,9 @@ struct RsConfigDataRates : RsSerializable
int mQueueIn;
int mQueueOut;

uint64_t mTotalIn;
uint64_t mTotalOut;

// RsSerializable interface
void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) {
RS_SERIAL_PROCESS(mRateIn);
Expand All @@ -184,6 +188,8 @@ struct RsConfigDataRates : RsSerializable

RS_SERIAL_PROCESS(mQueueIn);
RS_SERIAL_PROCESS(mQueueOut);
RS_SERIAL_PROCESS(mTotalIn);
RS_SERIAL_PROCESS(mTotalOut);
}
};

Expand Down
22 changes: 22 additions & 0 deletions src/services/p3bwctrl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "services/p3bwctrl.h"
#include "rsitems/rsbwctrlitems.h"
#include "retroshare/rsturtle.h"

#include <sys/time.h>

Expand Down Expand Up @@ -243,6 +244,25 @@ int p3BandwidthControl::getTotalBandwidthRates(RsConfigDataRates &rates)
rates.mQueueIn = mTotalRates.mQueueIn;
rates.mQueueOut = mTotalRates.mQueueOut;

/* Sum up traffic from all connected peers */
std::map<RsPeerId, BwCtrlData>::iterator bit;
for(bit = mBwMap.begin(); bit != mBwMap.end(); ++bit)
{
uint64_t tin = 0;
uint64_t tout = 0;
mPg->getPeerTotalTraffic(bit->first, tin, tout);
rates.mTotalIn += tin;
rates.mTotalOut += tout;
}

if (rsTurtle)
{
TurtleTrafficStatisticsInfo tinfo;
rsTurtle->getTrafficStatistics(tinfo);
rates.mRateIn += tinfo.total_dn_Bps / 1024.0f;
rates.mRateOut += tinfo.total_up_Bps / 1024.0f;
}

return 1;
}

Expand All @@ -269,6 +289,8 @@ int p3BandwidthControl::getAllBandwidthRates(std::map<RsPeerId, RsConfigDataRate
rates.mQueueIn = bit->second.mRates.mQueueIn;
rates.mQueueOut = bit->second.mRates.mQueueOut;

mPg->getPeerTotalTraffic(bit->first, rates.mTotalIn, rates.mTotalOut);

ratemap[bit->first] = rates;
}
return true ;
Expand Down