Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

router statistics - sort tunnels by traffic (libr) #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
21 changes: 13 additions & 8 deletions src/turtle/p3turtle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item)
tunnel.time_stamp = time(NULL) ;

tunnel.transfered_bytes += RsTurtleSerialiser().size(item);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use an intermediate variable here, to avoid calling size() twice. It takes some extra CPU for some items and the present function is called quite a lot.

tunnel.total_bytes += RsTurtleSerialiser().size(item);

if(item->PeerId() == tunnel.local_dst)
item->setTravelingDirection(RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 ;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2406,6 +2410,7 @@ void p3turtle::getInfo( std::vector<std::vector<std::string> >& 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();
Expand Down
1 change: 1 addition & 0 deletions src/turtle/p3turtle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here telling what total_bytes means. Indeed, just above, the transfered_bytes variable seems to do exactly the same thing if the name is correct.

float speed_Bps ; // speed of the traffic through the tunnel

/* For ending/starting tunnels only. */
Expand Down