diff --git a/libtorrent/include/libtorrent/proxy_base.hpp b/libtorrent/include/libtorrent/proxy_base.hpp index 7ade2a0a9..037a1c2d4 100644 --- a/libtorrent/include/libtorrent/proxy_base.hpp +++ b/libtorrent/include/libtorrent/proxy_base.hpp @@ -123,6 +123,7 @@ public: { m_remote_endpoint = endpoint_type(); m_sock.close(); + m_resolver.cancel(); } void close(asio::error_code& ec) diff --git a/libtorrent/include/libtorrent/session_settings.hpp b/libtorrent/include/libtorrent/session_settings.hpp index 7b08ec11e..f1f9d190c 100644 --- a/libtorrent/include/libtorrent/session_settings.hpp +++ b/libtorrent/include/libtorrent/session_settings.hpp @@ -115,6 +115,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_DHT , use_dht_as_fallback(true) #endif + , free_torrent_hashes(true) {} // this is the user agent that will be sent to the tracker @@ -281,6 +282,12 @@ namespace libtorrent // tracker is online bool use_dht_as_fallback; #endif + + // if this is true, the piece hashes will be freed, in order + // to save memory, once the torrent is seeding. This will + // make the get_torrent_info() function to return an incomplete + // torrent object that cannot be passed back to add_torrent() + bool free_torrent_hashes; }; #ifndef TORRENT_DISABLE_DHT diff --git a/libtorrent/src/bt_peer_connection.cpp b/libtorrent/src/bt_peer_connection.cpp index d7b3226ec..384bc2375 100755 --- a/libtorrent/src/bt_peer_connection.cpp +++ b/libtorrent/src/bt_peer_connection.cpp @@ -1272,7 +1272,13 @@ namespace libtorrent { INVARIANT_CHECK; - TORRENT_ASSERT(m_sent_handshake && m_sent_bitfield); + // Don't require the bitfield to have been sent at this point + // the case where m_sent_bitfield may not be true is if the + // torrent doesn't have any metadata, and a peer is timimg out. + // then the keep-alive message will be sent before the bitfield + // this is a violation to the original protocol, but necessary + // for the metadata extension. + TORRENT_ASSERT(m_sent_handshake); char msg[] = {0,0,0,0}; send_buffer(msg, sizeof(msg)); @@ -2477,6 +2483,11 @@ namespace libtorrent TORRENT_ASSERT(!m_rc4_encrypted || m_RC4_handler.get()); #endif + if (!in_handshake()) + { + TORRENT_ASSERT(m_sent_handshake); + } + if (!m_in_constructor) peer_connection::check_invariant(); diff --git a/libtorrent/src/kademlia/node_id.cpp b/libtorrent/src/kademlia/node_id.cpp index 52a5c766a..99f3df219 100644 --- a/libtorrent/src/kademlia/node_id.cpp +++ b/libtorrent/src/kademlia/node_id.cpp @@ -87,7 +87,7 @@ int distance_exp(node_id const& n1, node_id const& n2) // return the bit-number of the first bit // that differs int bit = byte * 8; - for (int b = 7; b > 0; --b) + for (int b = 7; b >= 0; --b) if (t >= (1 << b)) return bit + b; return bit; } diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index c41079fdc..3132b80c9 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -2317,6 +2317,8 @@ namespace detail void session_impl::stop_lsd() { mutex_t::scoped_lock l(m_mutex); + if (m_lsd.get()) + m_lsd->close(); m_lsd = 0; } diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index b71555f0f..43625e958 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -1153,7 +1153,8 @@ namespace libtorrent if (is_seed()) { m_picker.reset(); - m_torrent_file->seed_free(); + if (m_ses.settings().free_torrent_hashes) + m_torrent_file->seed_free(); } } @@ -2347,7 +2348,8 @@ namespace libtorrent if (is_seed()) { m_picker.reset(); - m_torrent_file->seed_free(); + if (m_ses.settings().free_torrent_hashes) + m_torrent_file->seed_free(); } if (!m_connections_initialized)