From 7504964899aa924e0393464a139c961525224270 Mon Sep 17 00:00:00 2001 From: RetroPooh Date: Wed, 3 Apr 2019 17:29:13 +0300 Subject: [PATCH 1/2] display session traffic --- libretroshare/src/pqi/pqi_base.h | 18 +++++++++++++++++- libretroshare/src/pqi/pqihandler.cc | 11 ++++++++++- libretroshare/src/pqi/pqihandler.h | 4 ++++ libretroshare/src/pqi/pqiperson.cc | 7 +++++++ libretroshare/src/pqi/pqiperson.h | 1 + libretroshare/src/pqi/pqistreamer.cc | 5 +++-- libretroshare/src/rsserver/p3serverconfig.cc | 6 +++++- libretroshare/src/rsserver/p3serverconfig.h | 1 + retroshare-gui/src/gui/MainWindow.cpp | 5 ++++- .../src/gui/statusbar/ratesstatus.cpp | 9 +++++---- retroshare-gui/src/gui/statusbar/ratesstatus.h | 2 +- 11 files changed, 58 insertions(+), 11 deletions(-) diff --git a/libretroshare/src/pqi/pqi_base.h b/libretroshare/src/pqi/pqi_base.h index a7d06c644..bafd8b572 100644 --- a/libretroshare/src/pqi/pqi_base.h +++ b/libretroshare/src/pqi/pqi_base.h @@ -192,7 +192,7 @@ class NetInterface; class PQInterface: public RateInterface { public: - explicit PQInterface(const RsPeerId &id) :peerId(id) { return; } + explicit PQInterface(const RsPeerId &id) :peerId(id), traf_in(0), traf_out(0) { return; } virtual ~PQInterface() { return; } /*! @@ -234,6 +234,22 @@ class PQInterface: public RateInterface const sockaddr_storage & /*remote_peer_address*/) { return 0; } + virtual uint64_t getTraffic(bool in) + { + uint64_t ret = 0; + if (in) + { + ret = traf_in; + traf_in = 0; + return ret; + } + ret = traf_out; + traf_out = 0; + return ret; + } + uint64_t traf_in; + uint64_t traf_out; + private: RsPeerId peerId; diff --git a/libretroshare/src/pqi/pqihandler.cc b/libretroshare/src/pqi/pqihandler.cc index a589f7e26..a5e79c9ff 100644 --- a/libretroshare/src/pqi/pqihandler.cc +++ b/libretroshare/src/pqi/pqihandler.cc @@ -87,6 +87,8 @@ pqihandler::pqihandler() : coreMtx("pqihandler") rateMax_in = 0.01; rateTotal_in = 0.0 ; rateTotal_out = 0.0 ; + traffInSum = 0; + traffOutSum = 0; last_m = time(NULL) ; nb_ticks = 0 ; mLastRateCapUpdate = 0 ; @@ -375,6 +377,9 @@ int pqihandler::UpdateRates() { SearchModule *mod = (it -> second); float crate_in = mod -> pqi -> getRate(true); + + traffInSum += mod -> pqi -> getTraffic(true); + traffOutSum += mod -> pqi -> getTraffic(false); #ifdef PQI_HDL_DEBUG_UR if(crate_in > 0.0) @@ -544,4 +549,8 @@ void pqihandler::locked_StoreCurrentRates(float in, float out) rateTotal_out = out; } - +void pqihandler::GetTraffic(uint64_t &in, uint64_t &out) +{ + in = traffInSum; + out = traffOutSum; +} diff --git a/libretroshare/src/pqi/pqihandler.h b/libretroshare/src/pqi/pqihandler.h index cf1f19429..126b82615 100644 --- a/libretroshare/src/pqi/pqihandler.h +++ b/libretroshare/src/pqi/pqihandler.h @@ -91,6 +91,10 @@ class pqihandler: public P3Interface, public pqiPublisher int ExtractRates(std::map &ratemap, RsBwRates &totals); int ExtractTrafficInfo(std::list &out_lst, std::list &in_lst); + uint64_t traffInSum; + uint64_t traffOutSum; + void GetTraffic(uint64_t &in, uint64_t &out); + protected: /* check to be overloaded by those that can * generates warnings otherwise diff --git a/libretroshare/src/pqi/pqiperson.cc b/libretroshare/src/pqi/pqiperson.cc index 7f33a3e1b..aa8096d7b 100644 --- a/libretroshare/src/pqi/pqiperson.cc +++ b/libretroshare/src/pqi/pqiperson.cc @@ -647,6 +647,13 @@ float pqiperson::getRate(bool in) return activepqi -> getRate(in); } +uint64_t pqiperson::getTraffic(bool in) +{ + if ((!active) || (activepqi == NULL)) + return 0; + return activepqi -> getTraffic(in); +} + void pqiperson::setMaxRate(bool in, float val) { RS_STACK_MUTEX(mPersonMtx); diff --git a/libretroshare/src/pqi/pqiperson.h b/libretroshare/src/pqi/pqiperson.h index 69faec48c..5c74502b0 100644 --- a/libretroshare/src/pqi/pqiperson.h +++ b/libretroshare/src/pqi/pqiperson.h @@ -149,6 +149,7 @@ public: virtual int getQueueSize(bool in); virtual void getRates(RsBwRates &rates); virtual float getRate(bool in); + virtual uint64_t getTraffic(bool in); virtual void setMaxRate(bool in, float val); virtual void setRateCap(float val_in, float val_out); virtual int gatherStatistics(std::list& outqueue_lst, diff --git a/libretroshare/src/pqi/pqistreamer.cc b/libretroshare/src/pqi/pqistreamer.cc index 839a5364e..e990ee20b 100644 --- a/libretroshare/src/pqi/pqistreamer.cc +++ b/libretroshare/src/pqi/pqistreamer.cc @@ -221,6 +221,7 @@ float pqistreamer::getRate(bool b) RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/ return RateInterface::getRate(b) ; } + void pqistreamer::setMaxRate(bool b,float f) { RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/ @@ -1231,7 +1232,7 @@ void pqistreamer::outSentBytes_locked(uint32_t outb) mTotalSent += outb; mCurrSent += outb; mAvgSentCount += outb; - + PQInterface::traf_out += outb; return; } @@ -1248,7 +1249,7 @@ void pqistreamer::inReadBytes_locked(uint32_t inb) mTotalRead += inb; mCurrRead += inb; mAvgReadCount += inb; - + PQInterface::traf_in += inb; return; } diff --git a/libretroshare/src/rsserver/p3serverconfig.cc b/libretroshare/src/rsserver/p3serverconfig.cc index eab0f5722..0154427f5 100644 --- a/libretroshare/src/rsserver/p3serverconfig.cc +++ b/libretroshare/src/rsserver/p3serverconfig.cc @@ -564,4 +564,8 @@ int p3ServerConfig::GetCurrentDataRates( float &inKb, float &outKb ) return 1; } - +int p3ServerConfig::GetTrafficSum(uint64_t &inb, uint64_t &outb ) +{ + mPqiHandler->GetTraffic(inb, outb); + return 1; +} diff --git a/libretroshare/src/rsserver/p3serverconfig.h b/libretroshare/src/rsserver/p3serverconfig.h index 134558049..139b2b316 100644 --- a/libretroshare/src/rsserver/p3serverconfig.h +++ b/libretroshare/src/rsserver/p3serverconfig.h @@ -96,6 +96,7 @@ virtual bool setOperatingMode(const std::string &opModeStr); virtual int SetMaxDataRates( int downKb, int upKb ); virtual int GetMaxDataRates( int &downKb, int &upKb ); virtual int GetCurrentDataRates( float &inKb, float &outKb ); +virtual int GetTrafficSum( uint64_t &inb, uint64_t &outb ); /********************* ABOVE is RsConfig Interface *******/ diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 6219575b5..77c98b031 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -726,9 +726,12 @@ void MainWindow::updateStatus() float downKb = 0; float upKb = 0; rsConfig->GetCurrentDataRates(downKb, upKb); + uint64_t down = 0; + uint64_t up = 0; + rsConfig->GetTrafficSum(down, up); if (ratesstatus) - ratesstatus->getRatesStatus(downKb, upKb); + ratesstatus->getRatesStatus(downKb, down, upKb, up); if(torstatus) torstatus->getTorStatus(); diff --git a/retroshare-gui/src/gui/statusbar/ratesstatus.cpp b/retroshare-gui/src/gui/statusbar/ratesstatus.cpp index c2289d153..1c78bbc6b 100644 --- a/retroshare-gui/src/gui/statusbar/ratesstatus.cpp +++ b/retroshare-gui/src/gui/statusbar/ratesstatus.cpp @@ -24,6 +24,7 @@ #include "ratesstatus.h" #include +#include "util/misc.h" #include @@ -48,13 +49,13 @@ RatesStatus::RatesStatus(QWidget *parent) setLayout(hbox); } -void RatesStatus::getRatesStatus(float downKb, float upKb) +void RatesStatus::getRatesStatus(float downKb, uint64_t down, float upKb, uint64_t upl) { /* set users/friends/network */ - QString normalText = QString("%1: %2 (kB/s) | %3: %4 (kB/s) ") - .arg(tr("Down")).arg(downKb, 0, 'f', 2) - .arg(tr("Up")).arg(upKb, 0, 'f', 2); + QString normalText = QString("%1: %2 kB/s (%3) | %4: %5 kB/s (%6)") + .arg(tr("Down")).arg(downKb, 0, 'f', 2).arg(misc::friendlyUnit(down)) + .arg(tr("Up")).arg(upKb, 0, 'f', 2).arg(misc::friendlyUnit(upl)); QString compactText = QString("%1|%2").arg(downKb, 0, 'f', 2).arg(upKb, 0, 'f', 2); if (statusRates) { diff --git a/retroshare-gui/src/gui/statusbar/ratesstatus.h b/retroshare-gui/src/gui/statusbar/ratesstatus.h index b0bfeb710..78c7475d6 100644 --- a/retroshare-gui/src/gui/statusbar/ratesstatus.h +++ b/retroshare-gui/src/gui/statusbar/ratesstatus.h @@ -32,7 +32,7 @@ class RatesStatus : public QWidget public: RatesStatus(QWidget *parent = 0); - void getRatesStatus(float downKb, float upKb); + void getRatesStatus(float downKb, uint64_t down, float upKb, uint64_t upl); void setCompactMode(bool compact) {_compactMode = compact; } private: From 617b924e1f276086fc5792c566afd14a810e2eca Mon Sep 17 00:00:00 2001 From: Pooh Date: Fri, 5 Apr 2019 10:48:00 +0300 Subject: [PATCH 2/2] Update rsconfig.h --- libretroshare/src/retroshare/rsconfig.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libretroshare/src/retroshare/rsconfig.h b/libretroshare/src/retroshare/rsconfig.h index e3b74aa4b..385ab2f58 100644 --- a/libretroshare/src/retroshare/rsconfig.h +++ b/libretroshare/src/retroshare/rsconfig.h @@ -296,6 +296,7 @@ public: virtual int GetMaxDataRates( int &inKb, int &outKb ) = 0; virtual int GetCurrentDataRates( float &inKb, float &outKb ) = 0; + virtual int GetTrafficSum( uint64_t &inb, uint64_t &outb ) = 0; }; #endif