forked from premiere/premiere-libtorrent
fixed bug where some blocks weren't restored in the piece picker when the peer they were requested from disconnected. made the invariant check on policy work
This commit is contained in:
parent
6d66566298
commit
8ef7f58d16
|
@ -203,7 +203,7 @@ namespace libtorrent
|
||||||
, m_selector(sel)
|
, m_selector(sel)
|
||||||
, m_socket(s)
|
, m_socket(s)
|
||||||
, m_torrent(0)
|
, m_torrent(0)
|
||||||
, m_attached_to_torrent(0)
|
, m_attached_to_torrent(false)
|
||||||
, m_ses(ses)
|
, m_ses(ses)
|
||||||
, m_active(false)
|
, m_active(false)
|
||||||
, m_writability_monitored(false)
|
, m_writability_monitored(false)
|
||||||
|
@ -360,7 +360,7 @@ namespace libtorrent
|
||||||
<< " *** CONNECTION CLOSED\n";
|
<< " *** CONNECTION CLOSED\n";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
m_disconnecting = true;
|
||||||
m_selector.remove(m_socket);
|
m_selector.remove(m_socket);
|
||||||
if (m_attached_to_torrent)
|
if (m_attached_to_torrent)
|
||||||
{
|
{
|
||||||
|
@ -2319,8 +2319,8 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
// check to make sure we don't have another connection with the same
|
// check to make sure we don't have another connection with the same
|
||||||
// info_hash and peer_id. If we do. close this connection.
|
// info_hash and peer_id. If we do. close this connection.
|
||||||
m_attached_to_torrent = true;
|
|
||||||
m_torrent->attach_peer(this);
|
m_torrent->attach_peer(this);
|
||||||
|
m_attached_to_torrent = true;
|
||||||
assert(m_torrent->get_policy().has_connection(this));
|
assert(m_torrent->get_policy().has_connection(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -650,6 +650,12 @@ namespace libtorrent
|
||||||
if (!prefer_whole_pieces) return;
|
if (!prefer_whole_pieces) return;
|
||||||
assert(num_blocks > 0);
|
assert(num_blocks > 0);
|
||||||
|
|
||||||
|
#ifdef TORRENT_VERBOSE_LOGGING
|
||||||
|
std::ofstream f("piece_picker.log", std::ios_base::app);
|
||||||
|
f << "backup_blocks: " << backup_blocks.size() << "\n"
|
||||||
|
<< "used: " << std::min(num_blocks, (int)backup_blocks.size()) << "\n----\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
interesting_blocks.insert(interesting_blocks.end()
|
interesting_blocks.insert(interesting_blocks.end()
|
||||||
, backup_blocks.begin(), backup_blocks.begin()
|
, backup_blocks.begin(), backup_blocks.begin()
|
||||||
+ std::min(num_blocks, (int)backup_blocks.size()));
|
+ std::min(num_blocks, (int)backup_blocks.size()));
|
||||||
|
|
|
@ -843,8 +843,21 @@ namespace libtorrent
|
||||||
void policy::new_connection(peer_connection& c)
|
void policy::new_connection(peer_connection& c)
|
||||||
{
|
{
|
||||||
assert(!c.is_local());
|
assert(!c.is_local());
|
||||||
|
/*
|
||||||
|
#ifndef NDEBUG
|
||||||
|
// avoid the invariant check to fail
|
||||||
|
peer p(address("0.0.0.0", 0), peer::not_connectable);
|
||||||
|
p.connection = &c;
|
||||||
|
m_peers.push_back(p);
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
/*
|
||||||
|
#ifndef NDEBUG
|
||||||
|
// avoid the invariant check to fail
|
||||||
|
m_peers.erase(m_peers.end() - 1);
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
// if the connection comes from the tracker,
|
// if the connection comes from the tracker,
|
||||||
// it's probably just a NAT-check. Ignore the
|
// it's probably just a NAT-check. Ignore the
|
||||||
// num connections constraint then.
|
// num connections constraint then.
|
||||||
|
@ -1177,6 +1190,7 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
|
assert(c.is_disconnecting());
|
||||||
bool unchoked = false;
|
bool unchoked = false;
|
||||||
|
|
||||||
std::vector<peer>::iterator i = std::find_if(
|
std::vector<peer>::iterator i = std::find_if(
|
||||||
|
@ -1219,7 +1233,8 @@ namespace libtorrent
|
||||||
// then unchoke another peer in order to maintain
|
// then unchoke another peer in order to maintain
|
||||||
// the total number of unchoked peers
|
// the total number of unchoked peers
|
||||||
--m_num_unchoked;
|
--m_num_unchoked;
|
||||||
unchoke_one_peer();
|
if (m_torrent->is_seed()) seed_unchoke_one_peer();
|
||||||
|
else unchoke_one_peer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1251,15 +1266,28 @@ namespace libtorrent
|
||||||
i != m_peers.end(); ++i)
|
i != m_peers.end(); ++i)
|
||||||
{
|
{
|
||||||
if (!i->connection) continue;
|
if (!i->connection) continue;
|
||||||
++connected_peers;
|
if (!i->connection->is_disconnecting())
|
||||||
|
++connected_peers;
|
||||||
if (!i->connection->is_choked()) ++actual_unchoked;
|
if (!i->connection->is_choked()) ++actual_unchoked;
|
||||||
}
|
}
|
||||||
// assert(actual_unchoked <= m_torrent->m_uploads_quota.given);
|
// assert(actual_unchoked <= m_torrent->m_uploads_quota.given);
|
||||||
assert(actual_unchoked == m_num_unchoked);
|
assert(actual_unchoked == m_num_unchoked);
|
||||||
|
|
||||||
int num_torrent_peers = (int)m_torrent->num_peers();
|
int num_torrent_peers = 0;
|
||||||
|
for (torrent::const_peer_iterator i = m_torrent->begin();
|
||||||
|
i != m_torrent->end(); ++i)
|
||||||
|
{
|
||||||
|
if (i->second->is_disconnecting()) continue;
|
||||||
|
++num_torrent_peers;
|
||||||
|
}
|
||||||
|
|
||||||
assert(connected_peers == num_torrent_peers);
|
// the second case is for when new connections
|
||||||
|
// are attached to the torrent, they are first
|
||||||
|
// added to the policy and then to the torrent.
|
||||||
|
// so in the destructor of new_connection this
|
||||||
|
// case will be used.
|
||||||
|
assert(connected_peers == num_torrent_peers
|
||||||
|
|| connected_peers - 1 == num_torrent_peers);
|
||||||
|
|
||||||
// TODO: Make sure the number of peers in m_torrent is equal
|
// TODO: Make sure the number of peers in m_torrent is equal
|
||||||
// to the number of connected peers in m_peers.
|
// to the number of connected peers in m_peers.
|
||||||
|
|
|
@ -825,6 +825,11 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
m_picker->abort_download(*i);
|
m_picker->abort_download(*i);
|
||||||
}
|
}
|
||||||
|
for (std::deque<piece_block>::const_iterator i = p->request_queue().begin();
|
||||||
|
i != p->request_queue().end(); ++i)
|
||||||
|
{
|
||||||
|
m_picker->abort_download(*i);
|
||||||
|
}
|
||||||
|
|
||||||
if (valid_metadata())
|
if (valid_metadata())
|
||||||
{
|
{
|
||||||
|
@ -883,13 +888,13 @@ namespace libtorrent
|
||||||
assert(m_connections.find(p->get_socket()->sender()) == m_connections.end());
|
assert(m_connections.find(p->get_socket()->sender()) == m_connections.end());
|
||||||
assert(!p->is_local());
|
assert(!p->is_local());
|
||||||
|
|
||||||
m_connections.insert(std::make_pair(p->get_socket()->sender(), p));
|
|
||||||
|
|
||||||
detail::session_impl::connection_map::iterator i
|
detail::session_impl::connection_map::iterator i
|
||||||
= m_ses.m_connections.find(p->get_socket());
|
= m_ses.m_connections.find(p->get_socket());
|
||||||
assert(i != m_ses.m_connections.end());
|
assert(i != m_ses.m_connections.end());
|
||||||
|
|
||||||
m_policy->new_connection(*i->second);
|
m_policy->new_connection(*i->second);
|
||||||
|
|
||||||
|
m_connections.insert(std::make_pair(p->get_socket()->sender(), p));
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent::disconnect_all()
|
void torrent::disconnect_all()
|
||||||
|
|
Loading…
Reference in New Issue