added rtt estimation for outgoing connections

This commit is contained in:
Arvid Norberg 2008-02-09 22:42:56 +00:00
parent 221cdf2bf8
commit cecd0dfcd2
6 changed files with 35 additions and 4 deletions

View File

@ -2339,6 +2339,8 @@ struct peer_info
int send_quota;
int receive_quota;
int rtt;
};
</pre>
<p>The <tt class="docutils literal"><span class="pre">flags</span></tt> attribute tells you in which state the peer is. It is set to
@ -2546,6 +2548,8 @@ is capped by <tt class="docutils literal"><span class="pre">session_settings::ma
<p><tt class="docutils literal"><span class="pre">send_quota</span></tt> and <tt class="docutils literal"><span class="pre">receive_quota</span></tt> 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.</p>
<p><tt class="docutils literal"><span class="pre">rtt</span></tt> is an estimated round trip time to this peer, in milliseconds. It is
estimated by timing the the tcp <tt class="docutils literal"><span class="pre">connect()</span></tt>. It may be 0 for incoming connections.</p>
</div>
<div class="section">
<h1><a id="session-settings" name="session-settings">session_settings</a></h1>

View File

@ -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
================

View File

@ -321,7 +321,7 @@ int peer_index(libtorrent::tcp::endpoint addr, std::vector<libtorrent::peer_info
void print_peer_info(std::ostream& out, std::vector<libtorrent::peer_info> 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<libtorrent::peer_info> 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
{

View File

@ -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;

View File

@ -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;
};
}

View File

@ -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();