diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 3ee490dc7..d5af3857f 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -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 const& metadata() const; bool received_metadata( diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index ec07198cc..dbbba8a2c 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -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, diff --git a/src/torrent.cpp b/src/torrent.cpp index fb302f595..8ebd9a1b9 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1335,7 +1335,12 @@ namespace libtorrent std::vector 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; }