make torrent_handler::set_priority() to use peer_classes

This commit is contained in:
arvidn 2017-12-16 16:37:16 +01:00 committed by Arvid Norberg
parent d52763805c
commit 178281e1c5
3 changed files with 33 additions and 24 deletions

View File

@ -1,4 +1,5 @@
* make torrent_handler::set_priority() to use peer_classes
* fix support for boost-1.66 (requires C++11)
* fix i2p support
* fix loading resume data when in seed mode

View File

@ -568,15 +568,8 @@ namespace libtorrent
void connect_to_url_seed(std::list<web_seed_t>::iterator url);
bool connect_to_peer(torrent_peer* peerinfo, bool ignore_limit = false);
int priority() const { return m_priority; }
void set_priority(int prio)
{
TORRENT_ASSERT(prio <= 255 && prio >= 0);
if (prio > 255) prio = 255;
else if (prio < 0) prio = 0;
m_priority = prio;
state_updated();
}
int priority() const;
void set_priority(int const prio);
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.1
@ -1617,10 +1610,7 @@ namespace libtorrent
// the number of bytes of padding files
boost::uint32_t m_padding:24;
// this is the priority of the torrent. The higher
// the value is, the more bandwidth is assigned to
// the torrent's peers
boost::uint32_t m_priority:8;
// TODO: 8 bits available here
// ----

View File

@ -257,7 +257,6 @@ namespace libtorrent
, m_apply_ip_filter((p.flags & add_torrent_params::flag_apply_ip_filter) != 0)
, m_merge_resume_trackers((p.flags & add_torrent_params::flag_merge_resume_trackers) != 0)
, m_padding(0)
, m_priority(0)
, m_incomplete(0xffffff)
, m_announce_to_dht((p.flags & add_torrent_params::flag_paused) == 0)
, m_in_state_updates(false)
@ -12137,16 +12136,7 @@ namespace {
st->upload_mode = m_upload_mode;
st->up_bandwidth_queue = 0;
st->down_bandwidth_queue = 0;
int priority = 0;
for (int i = 0; i < num_classes(); ++i)
{
int const* prio = m_ses.peer_classes().at(class_at(i))->priority;
if (priority < prio[peer_connection::upload_channel])
priority = prio[peer_connection::upload_channel];
if (priority < prio[peer_connection::download_channel])
priority = prio[peer_connection::download_channel];
}
st->priority = priority;
st->priority = priority();
st->num_peers = int(m_connections.size()) - m_num_connecting;
@ -12330,6 +12320,34 @@ namespace {
st->last_seen_complete = m_swarm_last_seen_complete;
}
int torrent::priority() const
{
int priority = 0;
for (int i = 0; i < num_classes(); ++i)
{
int const* prio = m_ses.peer_classes().at(class_at(i))->priority;
priority = std::max(priority, prio[peer_connection::upload_channel]);
priority = std::max(priority, prio[peer_connection::download_channel]);
}
return priority;
}
void torrent::set_priority(int const prio)
{
// priority 1 is default
if (prio == 1 && m_peer_class == 0) return;
if (m_peer_class == 0)
setup_peer_class();
struct peer_class* tpc = m_ses.peer_classes().at(m_peer_class);
TORRENT_ASSERT(tpc);
tpc->priority[peer_connection::download_channel] = prio;
tpc->priority[peer_connection::upload_channel] = prio;
state_updated();
}
void torrent::add_redundant_bytes(int b, torrent::wasted_reason_t reason)
{
TORRENT_ASSERT(is_single_thread());