added more asserts related to recent downloading_piece optimization and fixed a translation problem to the public interface

This commit is contained in:
Arvid Norberg 2007-07-04 15:46:10 +00:00
parent 3bdf01778a
commit b20270d243
4 changed files with 36 additions and 10 deletions

View File

@ -272,6 +272,16 @@ namespace libtorrent
return i->second; return i->second;
} }
peer_connection* connection_for(address const& a)
{
for (peer_iterator i = m_connections.begin()
, end(m_connections.end()); i != end; ++i)
{
if (i->first.address() == a) return i->second;
}
return 0;
}
// the number of peers that belong to this torrent // the number of peers that belong to this torrent
int num_peers() const { return (int)m_connections.size(); } int num_peers() const { return (int)m_connections.size(); }
int num_seeds() const; int num_seeds() const;

View File

@ -56,6 +56,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/session_impl.hpp" #include "libtorrent/aux_/session_impl.hpp"
#include "libtorrent/piece_picker.hpp" #include "libtorrent/piece_picker.hpp"
#ifndef NDEBUG
#include "libtorrent/bt_peer_connection.hpp"
#endif
namespace libtorrent namespace libtorrent
{ {
class peer_connection; class peer_connection;
@ -190,6 +194,7 @@ namespace libtorrent
{ {
assert(!t.is_seed()); assert(!t.is_seed());
assert(!c.has_peer_choked()); assert(!c.has_peer_choked());
assert(c.peer_info_struct() != 0 || !dynamic_cast<bt_peer_connection*>(&c));
int num_requests = c.desired_queue_size() int num_requests = c.desired_queue_size()
- (int)c.download_queue().size() - (int)c.download_queue().size()
- (int)c.request_queue().size(); - (int)c.request_queue().size();
@ -1399,17 +1404,20 @@ namespace libtorrent
for (const_iterator i = m_peers.begin(); for (const_iterator i = m_peers.begin();
i != m_peers.end(); ++i) i != m_peers.end(); ++i)
{ {
peer const& p = *i;
if (!m_torrent->settings().allow_multiple_connections_per_ip) if (!m_torrent->settings().allow_multiple_connections_per_ip)
assert(unique_test.find(i->ip.address()) == unique_test.end()); assert(unique_test.find(p.ip.address()) == unique_test.end());
unique_test.insert(i->ip.address()); unique_test.insert(p.ip.address());
++total_connections; ++total_connections;
if (!i->connection) continue; if (!p.connection) continue;
assert(i->connection->peer_info_struct() == 0 if (!m_torrent->settings().allow_multiple_connections_per_ip)
|| i->connection->peer_info_struct() == &*i); assert(p.connection == m_torrent->connection_for(p.ip.address()));
assert(p.connection->peer_info_struct() == 0
|| p.connection->peer_info_struct() == &p);
++nonempty_connections; ++nonempty_connections;
if (!i->connection->is_disconnecting()) if (!p.connection->is_disconnecting())
++connected_peers; ++connected_peers;
if (!i->connection->is_choked()) ++actual_unchoked; if (!p.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);

View File

@ -937,8 +937,8 @@ namespace libtorrent
policy::peer* p = static_cast<policy::peer*>(*i); policy::peer* p = static_cast<policy::peer*>(*i);
if (p == 0) continue; if (p == 0) continue;
#ifndef NDEBUG #ifndef NDEBUG
peer_iterator pi = m_connections.find(p->ip); if (!settings().allow_multiple_connections_per_ip)
assert((pi != m_connections.end()) == bool(p->connection)); assert(p->connection == 0 || p->connection == connection_for(p->ip.address()));
#endif #endif
if (p->connection) p->connection->received_invalid_data(index); if (p->connection) p->connection->received_invalid_data(index);
@ -1897,6 +1897,8 @@ namespace libtorrent
if (pp) p->add_extension(pp); if (pp) p->add_extension(pp);
} }
#endif #endif
assert(connection_for(p->remote()) == p);
assert(ci->second == p);
m_policy->new_connection(*ci->second); m_policy->new_connection(*ci->second);
} }
catch (std::exception& e) catch (std::exception& e)

View File

@ -776,7 +776,13 @@ namespace libtorrent
if (i->info[j].peer == 0) if (i->info[j].peer == 0)
pi.blocks[j].peer = tcp::endpoint(); pi.blocks[j].peer = tcp::endpoint();
else else
pi.blocks[j].peer = static_cast<policy::peer*>(i->info[j].peer)->ip; {
policy::peer* p = static_cast<policy::peer*>(i->info[j].peer);
if (p->connection)
pi.blocks[j].peer = p->connection->remote();
else
pi.blocks[j].peer = p->ip;
}
pi.blocks[j].num_downloads = i->info[j].num_downloads; pi.blocks[j].num_downloads = i->info[j].num_downloads;
pi.blocks[j].state = i->info[j].state; pi.blocks[j].state = i->info[j].state;