fixed the buggy changes from last revision, modified the invariant checks
This commit is contained in:
parent
cbcf8df504
commit
a09159c239
|
@ -437,7 +437,13 @@ namespace libtorrent
|
|||
int m_complete;
|
||||
int m_incomplete;
|
||||
|
||||
#ifndef NDEBUG
|
||||
public:
|
||||
#endif
|
||||
std::map<address, peer_connection*> m_connections;
|
||||
#ifndef NDEBUG
|
||||
private:
|
||||
#endif
|
||||
|
||||
// this is the upload and download statistics for the whole torrent.
|
||||
// it's updated from all its peers once every second.
|
||||
|
|
|
@ -367,6 +367,17 @@ namespace libtorrent
|
|||
assert(m_torrent != 0);
|
||||
m_torrent->remove_peer(this);
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
else
|
||||
{
|
||||
if (m_torrent)
|
||||
{
|
||||
torrent::peer_iterator i = m_torrent->m_connections.find(
|
||||
get_socket()->sender());
|
||||
assert(i != m_torrent->m_connections.end());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void peer_connection::announce_piece(int index)
|
||||
|
|
|
@ -1283,13 +1283,19 @@ namespace libtorrent
|
|||
++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.
|
||||
// this invariant is a bit complicated.
|
||||
// the usual case should be that connected_peers
|
||||
// == num_torrent_peers. But when there's an incoming
|
||||
// connection, it will first be added to the policy
|
||||
// and then be added to the torrent.
|
||||
// When there's an outgoing connection, it will first
|
||||
// be added to the torrent and then to the policy.
|
||||
// that's why the two second cases are in there.
|
||||
assert(connected_peers == num_torrent_peers
|
||||
|| connected_peers == num_torrent_peers - 1);
|
||||
|| (connected_peers == num_torrent_peers + 1
|
||||
&& connected_peers > 0)
|
||||
|| (connected_peers + 1 == num_torrent_peers
|
||||
&& num_torrent_peers > 0));
|
||||
|
||||
// TODO: Make sure the number of peers in m_torrent is equal
|
||||
// to the number of connected peers in m_peers.
|
||||
|
|
|
@ -900,13 +900,20 @@ namespace libtorrent
|
|||
= m_ses.m_connections.find(p->get_socket());
|
||||
assert(i != m_ses.m_connections.end());
|
||||
|
||||
// it's important that we call new_connection before
|
||||
// the connection is added to the torrent's list.
|
||||
// because if this fails, it will throw, and if this throws
|
||||
// m_attatched_to_torrent won't be set in the peer_connections
|
||||
// and the destructor won't remove the entry from the torrent's
|
||||
// connection list.
|
||||
m_policy->new_connection(*i->second);
|
||||
|
||||
m_connections.insert(std::make_pair(p->get_socket()->sender(), p));
|
||||
|
||||
#ifndef NDEBUG
|
||||
m_policy->check_invariant();
|
||||
#endif
|
||||
|
||||
m_connections.insert(std::make_pair(p->get_socket()->sender(), p));
|
||||
|
||||
m_policy->new_connection(*i->second);
|
||||
}
|
||||
|
||||
void torrent::disconnect_all()
|
||||
|
|
Loading…
Reference in New Issue