may have fixed a bug where incorrect metadata was sent (introduced with the latest optimization)

This commit is contained in:
Arvid Norberg 2005-10-16 20:15:54 +00:00
parent d27ace98ba
commit 23fbb8d240
3 changed files with 17 additions and 4 deletions

View File

@ -383,8 +383,12 @@ namespace libtorrent
void set_max_connections(int limit);
bool move_storage(boost::filesystem::path const& save_path);
// unless this returns true, new connections must wait
// with their initialization.
bool ready_for_connections() const
{ return m_connections_initialized; }
bool valid_metadata() const
{ return m_storage.get() != 0 && m_connections_initialized; }
{ return m_storage.get() != 0; }
std::vector<char> const& metadata() const;
bool received_metadata(

View File

@ -177,7 +177,7 @@ namespace libtorrent
m_recv_buffer.resize(1);
// assume the other end has no pieces
if (m_torrent->valid_metadata())
if (m_torrent->ready_for_connections())
{
init();
send_bitfield();
@ -297,6 +297,7 @@ namespace libtorrent
{
assert(m_torrent);
assert(m_torrent->valid_metadata());
assert(m_torrent->ready_for_connections());
m_have_piece.resize(m_torrent->torrent_file().num_pieces(), false);
@ -2263,7 +2264,10 @@ namespace libtorrent
throw protocol_error("connection rejected by paused torrent");
}
if (m_torrent->valid_metadata()) init();
// if the torrent's isn't ready to accept
// connections yet, we'll have to wait with
// our initialization
if (m_torrent->ready_for_connections()) init();
// assume the other end has no pieces
// if we don't have valid metadata yet,

View File

@ -1335,7 +1335,12 @@ namespace libtorrent
std::vector<char> const& torrent::metadata() const
{
if (m_metadata.empty())
bencode(std::back_inserter(m_metadata), m_torrent_file.create_torrent());
{
bencode(std::back_inserter(m_metadata)
, m_torrent_file.create_info_metadata());
assert(hasher(&m_metadata[0], m_metadata.size()).final()
== m_torrent_file.info_hash());
}
assert(!m_metadata.empty());
return m_metadata;
}