From 07c08ddaa92f3821ef9afd0c65ceabccb0a17f72 Mon Sep 17 00:00:00 2001 From: RetroPooh Date: Mon, 1 Apr 2019 15:59:56 +0300 Subject: [PATCH 1/2] router statistics - sort tunnels by traffic --- libretroshare/src/turtle/p3turtle.cc | 5 +++++ libretroshare/src/turtle/p3turtle.h | 1 + .../src/gui/statistics/TurtleRouterDialog.cpp | 21 ++++++++++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 8217db2faa..c338e66921 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -1132,6 +1132,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item) tunnel.time_stamp = time(NULL) ; tunnel.transfered_bytes += RsTurtleSerialiser().size(item); + tunnel.total_bytes += RsTurtleSerialiser().size(item); if(item->PeerId() == tunnel.local_dst) item->setTravelingDirection(RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ; @@ -1309,6 +1310,7 @@ void p3turtle::sendTurtleData(const RsPeerId& virtual_peer_id,RsTurtleGenericTun tunnel.time_stamp = time(NULL) ; tunnel.transfered_bytes += ss ; + tunnel.total_bytes += ss ; if(tunnel.local_src == _own_id) { @@ -1523,6 +1525,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item) tt.local_dst = _own_id ; // this means us tt.time_stamp = time(NULL) ; tt.transfered_bytes = 0 ; + tt.total_bytes = 0 ; tt.speed_Bps = 0.0f ; _local_tunnels[t_id] = tt ; @@ -1696,6 +1699,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item) tunnel.hash.clear() ; tunnel.time_stamp = time(NULL) ; tunnel.transfered_bytes = 0 ; + tunnel.total_bytes = 0 ; tunnel.speed_Bps = 0.0f ; #ifdef P3TURTLE_DEBUG @@ -2127,6 +2131,7 @@ void p3turtle::getInfo( std::vector >& hashes_info, tunnel.push_back(it->second.hash.toStdString()) ; tunnel.push_back(printNumber(now-it->second.time_stamp) + " secs ago") ; tunnel.push_back(printFloatNumber(it->second.speed_Bps,false)) ; // + tunnel.push_back(printNumber(it->second.total_bytes)) ; } search_reqs_info.clear(); diff --git a/libretroshare/src/turtle/p3turtle.h b/libretroshare/src/turtle/p3turtle.h index 0c230b88bd..b2b33fdc76 100644 --- a/libretroshare/src/turtle/p3turtle.h +++ b/libretroshare/src/turtle/p3turtle.h @@ -192,6 +192,7 @@ class TurtleTunnel TurtlePeerId local_dst ; // where packets should go. Direction to the destination. uint32_t time_stamp ; // last time the tunnel was actually used. Used for cleaning old tunnels. uint32_t transfered_bytes ; // total bytes transferred in this tunnel. + uint64_t total_bytes ; float speed_Bps ; // speed of the traffic through the tunnel /* For ending/starting tunnels only. */ diff --git a/retroshare-gui/src/gui/statistics/TurtleRouterDialog.cpp b/retroshare-gui/src/gui/statistics/TurtleRouterDialog.cpp index 7572bdfaed..339dece9dd 100644 --- a/retroshare-gui/src/gui/statistics/TurtleRouterDialog.cpp +++ b/retroshare-gui/src/gui/statistics/TurtleRouterDialog.cpp @@ -72,6 +72,8 @@ void TurtleRouterDialog::processSettings(bool bLoad) } bool sr_Compare( TurtleSearchRequestDisplayInfo m1, TurtleSearchRequestDisplayInfo m2) { return m1.age < m2.age; } +bool tun_Compare( std::vector m1, std::vector m2) + { return ( strtoul(m1[6].c_str(), NULL, 0) > strtoul(m2[6].c_str(), NULL, 0) ); } void TurtleRouterDialog::updateDisplay() { @@ -83,7 +85,8 @@ void TurtleRouterDialog::updateDisplay() rsTurtle->getInfo(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ; std::sort(search_reqs_info.begin(),search_reqs_info.end(),sr_Compare) ; - + std::sort(tunnels_info.begin(),tunnels_info.end(),tun_Compare) ; + updateTunnelRequests(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ; } @@ -145,8 +148,20 @@ void TurtleRouterDialog::updateTunnelRequests( const std::vector= 800.0f && k<4) num /= 1024.0f,++k; sprintf(tmp,"%3.2f %s",num,units[k].c_str()) ; - - QString str = tr("Tunnel id") + ": " + QString::fromUtf8(tunnels_info[i][0].c_str()) + "\t" + tr("Speed") + ": " + QString::fromStdString(tmp) + "\t " + tr("last transfer") + ": " + QString::fromStdString(tunnels_info[i][4])+ "\t" + QString::fromUtf8(tunnels_info[i][2].c_str()) + " -> " + QString::fromUtf8(tunnels_info[i][1].c_str()); + + float num2 = strtol(tunnels_info[i][6].c_str(), NULL, 0); + char tmp2[100] ; + std::string units2[4] = { "B","KB","MB","GB" } ; + int k2=0 ; + while(num2 >= 800.0f && k2<4) + num2 /= 1024.0f,++k2; + sprintf(tmp2,"%3.2f %s",num2,units2[k2].c_str()) ; + + QString str = tr("Tunnel id") + ": " + QString::fromUtf8(tunnels_info[i][0].c_str()) + + "\t Traffic: " + QString("%1").arg(QString::fromStdString(tmp2),-10) + + "\t" + tr("Speed") + ": " + QString("%1").arg(QString::fromStdString(tmp),-10) + + "\t " + tr("last transfer") + ": " + QString("%1").arg(QString::fromStdString(tunnels_info[i][4]),-11) + + "\t" + QString::fromUtf8(tunnels_info[i][2].c_str()) + " -> " + QString::fromUtf8(tunnels_info[i][1].c_str()); stl.clear() ; stl.push_back(str) ; QTreeWidgetItem *item = new QTreeWidgetItem(stl); From d728f881b0bb095da8a5f3d46ca001370d6fa698 Mon Sep 17 00:00:00 2001 From: Pooh Date: Thu, 11 Apr 2019 22:15:38 +0300 Subject: [PATCH 2/2] Update TurtleRouterDialog.cpp --- retroshare-gui/src/gui/statistics/TurtleRouterDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/statistics/TurtleRouterDialog.cpp b/retroshare-gui/src/gui/statistics/TurtleRouterDialog.cpp index e124303147..7387359e7c 100644 --- a/retroshare-gui/src/gui/statistics/TurtleRouterDialog.cpp +++ b/retroshare-gui/src/gui/statistics/TurtleRouterDialog.cpp @@ -174,7 +174,7 @@ void TurtleRouterDialog::updateTunnelRequests( const std::vector