forked from premiere/premiere-libtorrent
an approximate peer download rate is now in peer_info
This commit is contained in:
parent
bbd7fefa2c
commit
a3a2217276
|
@ -269,11 +269,11 @@ 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 << " down (total) up (total) que req flags source fail hshf sndb inactive wait block-progress "
|
||||
out << " down (total) up (total) que req flags source fail hshf sndb inactive wait block-progress "
|
||||
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
|
||||
"country "
|
||||
#endif
|
||||
"client \n";
|
||||
"peer-rate client \n";
|
||||
|
||||
for (std::vector<peer_info>::const_iterator i = peers.begin();
|
||||
i != peers.end(); ++i)
|
||||
|
@ -300,6 +300,8 @@ void print_peer_info(std::ostream& out, std::vector<libtorrent::peer_info> const
|
|||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||
<< ((i->flags & peer_info::rc4_encrypted)?'E':
|
||||
(i->flags & peer_info::plaintext_encrypted)?'e':'.')
|
||||
#else
|
||||
<< " "
|
||||
#endif
|
||||
<< " "
|
||||
<< ((i->source & peer_info::tracker)?"T":"_")
|
||||
|
@ -333,6 +335,8 @@ void print_peer_info(std::ostream& out, std::vector<libtorrent::peer_info> const
|
|||
out << " " << i->country[0] << i->country[1];
|
||||
}
|
||||
#endif
|
||||
out << (i->remote_dl_rate > 0 ? add_suffix(i->remote_dl_rate) + "/s ": " ") << " ";
|
||||
|
||||
if (i->flags & peer_info::handshake)
|
||||
{
|
||||
out << esc("31") << " waiting for handshake" << esc("0") << "\n";
|
||||
|
|
|
@ -681,6 +681,15 @@ namespace libtorrent
|
|||
// so that it can be removed from the queue
|
||||
// once the connection completes
|
||||
int m_connection_ticket;
|
||||
|
||||
// bytes downloaded since last second
|
||||
// timer timeout; used for determining
|
||||
// approx download rate
|
||||
int m_remote_bytes_dled;
|
||||
|
||||
// approximate peer download rate
|
||||
int m_remote_dl_rate;
|
||||
|
||||
#ifndef NDEBUG
|
||||
public:
|
||||
bool m_in_constructor;
|
||||
|
|
|
@ -141,6 +141,9 @@ namespace libtorrent
|
|||
web_seed = 1
|
||||
};
|
||||
int connection_type;
|
||||
|
||||
// approximate peer download rate
|
||||
int remote_dl_rate;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -128,6 +128,8 @@ namespace libtorrent
|
|||
, m_peer_info(peerinfo)
|
||||
, m_speed(slow)
|
||||
, m_connection_ticket(-1)
|
||||
, m_remote_bytes_dled(0)
|
||||
, m_remote_dl_rate(0)
|
||||
#ifndef NDEBUG
|
||||
, m_in_constructor(true)
|
||||
#endif
|
||||
|
@ -198,6 +200,8 @@ namespace libtorrent
|
|||
, m_download_limit(resource_request::inf)
|
||||
, m_peer_info(peerinfo)
|
||||
, m_speed(slow)
|
||||
, m_remote_bytes_dled(0)
|
||||
, m_remote_dl_rate(0)
|
||||
#ifndef NDEBUG
|
||||
, m_in_constructor(true)
|
||||
#endif
|
||||
|
@ -743,6 +747,9 @@ namespace libtorrent
|
|||
&& t->picker().piece_priority(index) != 0)
|
||||
t->get_policy().peer_is_interesting(*this);
|
||||
}
|
||||
|
||||
// update bytes downloaded since last timer
|
||||
m_remote_bytes_dled += t->torrent_file().piece_size(index);
|
||||
|
||||
if (is_seed())
|
||||
{
|
||||
|
@ -1753,12 +1760,14 @@ namespace libtorrent
|
|||
p.failcount = peer_info_struct()->failcount;
|
||||
p.num_hashfails = peer_info_struct()->hashfails;
|
||||
p.flags |= peer_info_struct()->on_parole ? peer_info::on_parole : 0;
|
||||
p.remote_dl_rate = m_remote_dl_rate;
|
||||
}
|
||||
else
|
||||
{
|
||||
p.source = 0;
|
||||
p.failcount = 0;
|
||||
p.num_hashfails = 0;
|
||||
p.remote_dl_rate = 0;
|
||||
}
|
||||
|
||||
p.send_buffer_size = send_buffer_size();
|
||||
|
@ -1915,6 +1924,24 @@ namespace libtorrent
|
|||
, m_upload_limit));
|
||||
}
|
||||
|
||||
// note the 1/60 multiplication here - this is per second of the
|
||||
// minute; but since timers are not exact this makes this
|
||||
// calculation REALLY approximate.
|
||||
|
||||
float factor = 0.6666666666667f;
|
||||
|
||||
if(m_remote_dl_rate == 0) {
|
||||
factor = 0.0f;
|
||||
}
|
||||
|
||||
m_remote_dl_rate =
|
||||
(m_remote_dl_rate * factor) +
|
||||
((m_remote_bytes_dled * (1.0f-factor)) * (1.f/60.f));
|
||||
|
||||
m_remote_bytes_dled = 0;
|
||||
|
||||
|
||||
//
|
||||
fill_send_buffer();
|
||||
/*
|
||||
size_type diff = share_diff();
|
||||
|
|
Loading…
Reference in New Issue