diff --git a/docs/manual.html b/docs/manual.html
index 9fb1fd80a..db1f018f8 100644
--- a/docs/manual.html
+++ b/docs/manual.html
@@ -2339,6 +2339,8 @@ struct peer_info
int send_quota;
int receive_quota;
+
+ int rtt;
};
The flags attribute tells you in which state the peer is. It is set to
@@ -2546,6 +2548,8 @@ is capped by session_settings::ma
send_quota and receive_quota are the number of bytes this peer has been
assigned to be allowed to send and receive until it has to request more quota
from the bandwidth manager.
+rtt is an estimated round trip time to this peer, in milliseconds. It is
+estimated by timing the the tcp connect(). It may be 0 for incoming connections.
diff --git a/docs/manual.rst b/docs/manual.rst
index fc09653bc..af2b964f4 100644
--- a/docs/manual.rst
+++ b/docs/manual.rst
@@ -2332,6 +2332,8 @@ It contains the following fields::
int send_quota;
int receive_quota;
+
+ int rtt;
};
The ``flags`` attribute tells you in which state the peer is. It is set to
@@ -2531,6 +2533,10 @@ is capped by ``session_settings::max_outstanding_disk_bytes_per_connection``.
assigned to be allowed to send and receive until it has to request more quota
from the bandwidth manager.
+``rtt`` is an estimated round trip time to this peer, in milliseconds. It is
+estimated by timing the the tcp ``connect()``. It may be 0 for incoming connections.
+
+
session_settings
================
diff --git a/examples/client_test.cpp b/examples/client_test.cpp
index 0e322039b..6ba87f44f 100644
--- a/examples/client_test.cpp
+++ b/examples/client_test.cpp
@@ -321,7 +321,7 @@ int peer_index(libtorrent::tcp::endpoint addr, std::vector
const& peers)
{
using namespace libtorrent;
- out << "IP down (total) up (total) sent-req recv flags source fail hshf sndb inactive wait disk quota block-progress "
+ out << "IP down (total) up (total) sent-req recv flags source fail hshf sndb inactive wait disk quota rtt block-progress "
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
"country "
#endif
@@ -379,12 +379,13 @@ void print_peer_info(std::ostream& out, std::vector const
<< to_string(total_seconds(i->last_active), 8) << " "
<< to_string(total_seconds(i->last_request), 4) << " "
<< add_suffix(i->pending_disk_bytes) << " "
- << to_string(i->send_quota, 5) << " ";
+ << to_string(i->send_quota, 5) << " "
+ << to_string(i->rtt, 4) << " ";
if (i->downloading_piece_index >= 0)
{
out << progress_bar(
- i->downloading_progress / float(i->downloading_total), 15);
+ i->downloading_progress / float(i->downloading_total), 14);
}
else
{
diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp
index fdec4989b..b6ef25e20 100755
--- a/include/libtorrent/peer_connection.hpp
+++ b/include/libtorrent/peer_connection.hpp
@@ -742,6 +742,14 @@ namespace libtorrent
// immediate.
bool m_fast_reconnect;
+ // the time when async_connect was called
+ ptime m_connect;
+
+ // estimated round trip time to this peer
+ // based on the time from when async_connect
+ // was called to when on_connection_complete
+ // was called. The rtt is specified in milliseconds
+ int m_rtt;
#ifndef NDEBUG
public:
bool m_in_constructor;
diff --git a/include/libtorrent/peer_info.hpp b/include/libtorrent/peer_info.hpp
index d06ed9a6a..8ea29ef25 100755
--- a/include/libtorrent/peer_info.hpp
+++ b/include/libtorrent/peer_info.hpp
@@ -171,6 +171,9 @@ namespace libtorrent
// numbers used for bandwidth limiting
int send_quota;
int receive_quota;
+
+ // estimated rtt to peer, in milliseconds
+ int rtt;
};
}
diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp
index 989b22fcb..dcaac5d1b 100755
--- a/src/peer_connection.cpp
+++ b/src/peer_connection.cpp
@@ -118,6 +118,7 @@ namespace libtorrent
, m_remote_dl_update(time_now())
, m_outstanding_writing_bytes(0)
, m_fast_reconnect(false)
+ , m_rtt(0)
#ifndef NDEBUG
, m_in_constructor(true)
#endif
@@ -200,6 +201,7 @@ namespace libtorrent
, m_remote_dl_update(time_now())
, m_outstanding_writing_bytes(0)
, m_fast_reconnect(false)
+ , m_rtt(0)
#ifndef NDEBUG
, m_in_constructor(true)
#endif
@@ -2162,6 +2164,7 @@ namespace libtorrent
{
TORRENT_ASSERT(!associated_torrent().expired());
+ p.rtt = m_rtt;
p.down_speed = statistics().download_rate();
p.up_speed = statistics().upload_rate();
p.payload_down_speed = statistics().download_payload_rate();
@@ -2912,6 +2915,7 @@ namespace libtorrent
}
m_socket->async_connect(m_remote
, bind(&peer_connection::on_connection_complete, self(), _1));
+ m_connect = time_now();
if (t->alerts().should_post(alert::debug))
{
@@ -2922,10 +2926,14 @@ namespace libtorrent
void peer_connection::on_connection_complete(asio::error_code const& e) try
{
+ ptime completed = time_now();
+
session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
INVARIANT_CHECK;
+ m_rtt = total_milliseconds(completed - m_connect);
+
if (m_disconnecting) return;
m_connecting = false;
@@ -2948,7 +2956,8 @@ namespace libtorrent
// this means the connection just succeeded
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
- (*m_ses.m_logger) << time_now_string() << " COMPLETED: " << m_remote.address().to_string() << "\n";
+ (*m_ses.m_logger) << time_now_string() << " COMPLETED: " << m_remote.address().to_string()
+ << " rtt = " << m_rtt << "\n";
#endif
on_connected();