forked from premiere/premiere-libtorrent
peer interest flag is now updated when priority is changed. fixes in piece_picker
This commit is contained in:
parent
71c069ea33
commit
20e38bc42b
|
@ -190,6 +190,8 @@ namespace libtorrent
|
|||
bool is_peer_interested() const { return m_peer_interested; }
|
||||
bool has_peer_choked() const { return m_peer_choked; }
|
||||
|
||||
void update_interest();
|
||||
|
||||
// returns the torrent this connection is a part of
|
||||
// may be zero if the connection is an incoming connection
|
||||
// and it hasn't received enough information to determine
|
||||
|
|
|
@ -500,6 +500,8 @@ namespace libtorrent
|
|||
, boost::intrusive_ptr<peer_connection> p) const;
|
||||
bool request_bandwidth_from_session(int channel) const;
|
||||
|
||||
void update_peer_interest();
|
||||
|
||||
torrent_info m_torrent_file;
|
||||
|
||||
// is set to true when the torrent has
|
||||
|
|
|
@ -205,6 +205,33 @@ namespace libtorrent
|
|||
std::fill(m_peer_id.begin(), m_peer_id.end(), 0);
|
||||
}
|
||||
|
||||
void peer_connection::update_interest()
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
boost::shared_ptr<torrent> t = m_torrent.lock();
|
||||
assert(t);
|
||||
|
||||
bool interested = false;
|
||||
const std::vector<bool>& we_have = t->pieces();
|
||||
for (int j = 0; j != (int)we_have.size(); ++j)
|
||||
{
|
||||
if (!we_have[j]
|
||||
&& t->piece_priority(j) > 0
|
||||
&& m_have_piece[j])
|
||||
{
|
||||
interested = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!interested)
|
||||
send_not_interested();
|
||||
else
|
||||
t->get_policy().peer_is_interesting(*this);
|
||||
|
||||
assert(is_interesting() == interested);
|
||||
}
|
||||
|
||||
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||
void peer_connection::add_extension(boost::shared_ptr<peer_plugin> ext)
|
||||
{
|
||||
|
@ -237,7 +264,7 @@ namespace libtorrent
|
|||
t->peer_has(i);
|
||||
// if the peer has a piece and we don't, the peer is interesting
|
||||
if (!t->have_piece(i)
|
||||
&& !t->picker().piece_priority(i) == 0)
|
||||
&& t->picker().piece_priority(i) != 0)
|
||||
interesting = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -264,12 +264,11 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (!i->filtered())
|
||||
else
|
||||
{
|
||||
if (t != 0)
|
||||
assert(!t->have_piece(index));
|
||||
|
||||
assert(i->priority(m_sequenced_download_threshold) < int(m_piece_info.size()));
|
||||
int prio = i->priority(m_sequenced_download_threshold);
|
||||
if (prio > 0)
|
||||
{
|
||||
|
@ -277,6 +276,15 @@ namespace libtorrent
|
|||
assert (i->index < vec.size());
|
||||
assert(vec[i->index] == index);
|
||||
}
|
||||
|
||||
for (int k = 0; k < int(m_piece_info.size()); ++k)
|
||||
{
|
||||
for (int j = 0; j < int(m_piece_info[k].size()); ++j)
|
||||
{
|
||||
assert(int(m_piece_info[k][j]) != index
|
||||
|| (prio > 0 && prio == k && int(i->index) == j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<downloading_piece>::const_iterator down
|
||||
|
@ -386,6 +394,8 @@ namespace libtorrent
|
|||
int index = m_piece_info[priority][elem_index];
|
||||
// update the piece_map
|
||||
piece_pos& p = m_piece_map[index];
|
||||
assert(int(p.index) == index || p.have());
|
||||
|
||||
int new_priority = p.priority(m_sequenced_download_threshold);
|
||||
|
||||
if (new_priority == priority) return;
|
||||
|
@ -669,6 +679,8 @@ namespace libtorrent
|
|||
// if the priority isn't changed, don't do anything
|
||||
if (new_piece_priority == int(p.piece_priority)) return;
|
||||
|
||||
int prev_priority = p.priority(m_sequenced_download_threshold);
|
||||
|
||||
if (new_piece_priority == piece_pos::filter_priority
|
||||
&& p.piece_priority != piece_pos::filter_priority)
|
||||
{
|
||||
|
@ -697,7 +709,6 @@ namespace libtorrent
|
|||
assert(m_num_filtered >= 0);
|
||||
assert(m_num_have_filtered >= 0);
|
||||
|
||||
int prev_priority = p.priority(m_sequenced_download_threshold);
|
||||
p.piece_priority = new_piece_priority;
|
||||
int new_priority = p.priority(m_sequenced_download_threshold);
|
||||
|
||||
|
|
|
@ -1090,21 +1090,7 @@ namespace libtorrent
|
|||
if (!i->connection->is_interesting()) continue;
|
||||
if (!i->connection->has_piece(index)) continue;
|
||||
|
||||
bool interested = false;
|
||||
const std::vector<bool>& peer_has = i->connection->get_bitfield();
|
||||
const std::vector<bool>& we_have = m_torrent->pieces();
|
||||
assert(we_have.size() == peer_has.size());
|
||||
for (int j = 0; j != (int)we_have.size(); ++j)
|
||||
{
|
||||
if (!we_have[j] && peer_has[j])
|
||||
{
|
||||
interested = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!interested)
|
||||
i->connection->send_not_interested();
|
||||
assert(i->connection->is_interesting() == interested);
|
||||
i->connection->update_interest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1036,9 +1036,8 @@ namespace libtorrent
|
|||
assert(index >= 0);
|
||||
assert(index < m_torrent_file.num_pieces());
|
||||
|
||||
// TODO: update peer's interesting-bit
|
||||
|
||||
m_picker->set_piece_priority(index, priority);
|
||||
update_peer_interest();
|
||||
}
|
||||
|
||||
int torrent::piece_priority(int index) const
|
||||
|
@ -1053,8 +1052,6 @@ namespace libtorrent
|
|||
assert(index >= 0);
|
||||
assert(index < m_torrent_file.num_pieces());
|
||||
|
||||
// TODO: update peer's interesting-bit
|
||||
|
||||
return m_picker->piece_priority(index);
|
||||
}
|
||||
|
||||
|
@ -1068,8 +1065,6 @@ namespace libtorrent
|
|||
|
||||
assert(m_picker.get());
|
||||
|
||||
// TODO: update peer's interesting-bit
|
||||
|
||||
int index = 0;
|
||||
for (std::vector<int>::const_iterator i = pieces.begin()
|
||||
, end(pieces.end()); i != end; ++i, ++index)
|
||||
|
@ -1078,6 +1073,7 @@ namespace libtorrent
|
|||
assert(*i <= 7);
|
||||
m_picker->set_piece_priority(index, *i);
|
||||
}
|
||||
update_peer_interest();
|
||||
}
|
||||
|
||||
void torrent::piece_priorities(std::vector<int>& pieces) const
|
||||
|
@ -1118,8 +1114,8 @@ namespace libtorrent
|
|||
|
||||
size_type position = 0;
|
||||
|
||||
if (m_torrent_file.num_pieces())
|
||||
{
|
||||
if (m_torrent_file.num_pieces() == 0) return;
|
||||
|
||||
int piece_length = m_torrent_file.piece_length();
|
||||
// initialize the piece priorities to 0, then only allow
|
||||
// setting higher priorities
|
||||
|
@ -1140,13 +1136,15 @@ namespace libtorrent
|
|||
, bind(&set_if_greater, _1, files[i]));
|
||||
}
|
||||
prioritize_pieces(pieces);
|
||||
}
|
||||
update_peer_interest();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// updates the interested flag in peers
|
||||
void torrent::update_peer_interest()
|
||||
{
|
||||
for (peer_iterator i = begin(); i != end(); ++i)
|
||||
i->second->update_interest();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue