From 8afc88c3606ea80f94ec052692f4c18765bb807e Mon Sep 17 00:00:00 2001 From: RetroPooh Date: Tue, 4 Jul 2023 10:39:39 +0300 Subject: [PATCH] router statistics - sort tunnels by traffic (libr) --- src/turtle/p3turtle.cc | 21 +++++++++++++-------- src/turtle/p3turtle.h | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/turtle/p3turtle.cc b/src/turtle/p3turtle.cc index 6dbfeef87..3f99aa030 100644 --- a/src/turtle/p3turtle.cc +++ b/src/turtle/p3turtle.cc @@ -1308,6 +1308,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) ; @@ -1489,6 +1490,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) { @@ -1683,14 +1685,15 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item) sendItem(res_item) ; - // Note in the tunnels list that we have an ending tunnel here. - TurtleTunnel tt ; - tt.local_src = item->PeerId() ; - tt.hash = item->file_hash ; - tt.local_dst = _own_id ; // this means us - tt.time_stamp = time(NULL) ; - tt.transfered_bytes = 0 ; - tt.speed_Bps = 0.0f ; + // Note in the tunnels list that we have an ending tunnel here. + TurtleTunnel tt ; + tt.local_src = item->PeerId() ; + tt.hash = item->file_hash ; + 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 ; @@ -1894,6 +1897,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 @@ -2406,6 +2410,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/src/turtle/p3turtle.h b/src/turtle/p3turtle.h index d6a359567..8adc593cb 100644 --- a/src/turtle/p3turtle.h +++ b/src/turtle/p3turtle.h @@ -188,6 +188,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. */