diff --git a/libtorrent/src/kademlia/dht_tracker.cpp b/libtorrent/src/kademlia/dht_tracker.cpp index eda6cd864..fd2696171 100644 --- a/libtorrent/src/kademlia/dht_tracker.cpp +++ b/libtorrent/src/kademlia/dht_tracker.cpp @@ -237,6 +237,7 @@ namespace libtorrent { namespace dht try { if (e) return; + if (!m_socket.is_open()) return; time_duration d = m_dht.connection_timeout(); m_connection_timer.expires_from_now(d); m_connection_timer.async_wait(m_strand.wrap(bind(&dht_tracker::connection_timeout, self(), _1))); @@ -254,6 +255,7 @@ namespace libtorrent { namespace dht try { if (e) return; + if (!m_socket.is_open()) return; time_duration d = m_dht.refresh_timeout(); m_refresh_timer.expires_from_now(d); m_refresh_timer.async_wait(m_strand.wrap( @@ -276,8 +278,9 @@ namespace libtorrent { namespace dht try { if (e) return; + if (!m_socket.is_open()) return; m_timer.expires_from_now(minutes(tick_period)); - m_timer.async_wait(m_strand.wrap(bind(&dht_tracker::tick, this, _1))); + m_timer.async_wait(m_strand.wrap(bind(&dht_tracker::tick, self(), _1))); ptime now = time_now(); if (now - m_last_new_key > minutes(key_refresh)) @@ -388,6 +391,7 @@ namespace libtorrent { namespace dht try { if (error == asio::error::operation_aborted) return; + if (!m_socket.is_open()) return; int current_buffer = m_buffer; m_buffer = (m_buffer + 1) & 1; @@ -716,6 +720,7 @@ namespace libtorrent { namespace dht , udp::resolver::iterator host) try { if (e || host == udp::resolver::iterator()) return; + if (!m_socket.is_open()) return; add_node(host->endpoint()); } catch (std::exception&) @@ -734,6 +739,7 @@ namespace libtorrent { namespace dht , udp::resolver::iterator host) try { if (e || host == udp::resolver::iterator()) return; + if (!m_socket.is_open()) return; m_dht.add_router_node(host->endpoint()); } catch (std::exception&) @@ -972,3 +978,4 @@ namespace libtorrent { namespace dht }} + diff --git a/libtorrent/src/torrent_info.cpp b/libtorrent/src/torrent_info.cpp index e43f3f297..8e427998c 100755 --- a/libtorrent/src/torrent_info.cpp +++ b/libtorrent/src/torrent_info.cpp @@ -400,7 +400,9 @@ namespace libtorrent { if (i->first == "pieces" || i->first == "piece length" - || i->first == "length") + || i->first == "length" + || i->first == "files" + || i->first == "name") continue; m_extra_info[i->first] = i->second; } @@ -824,8 +826,33 @@ namespace libtorrent m_nodes.push_back(node); } + bool torrent_info::remap_files(std::vector > const& map) + { + typedef std::vector > files_t; + + size_type offset = 0; + m_remapped_files.resize(map.size()); + + for (int i = 0; i < int(map.size()); ++i) + { + file_entry& fe = m_remapped_files[i]; + fe.path = map[i].first; + fe.offset = offset; + fe.size = map[i].second; + offset += fe.size; + } + if (offset != total_size()) + { + m_remapped_files.clear(); + return false; + } + + return true; + } + std::vector torrent_info::map_block(int piece, size_type offset - , int size) const + , int size, bool storage) const { assert(num_files() > 0); std::vector ret; @@ -839,9 +866,9 @@ namespace libtorrent std::vector::const_iterator file_iter; int counter = 0; - for (file_iter = begin_files();; ++counter, ++file_iter) + for (file_iter = begin_files(storage);; ++counter, ++file_iter) { - assert(file_iter != end_files()); + assert(file_iter != end_files(storage)); if (file_offset < file_iter->size) { file_slice f; @@ -862,11 +889,11 @@ namespace libtorrent } peer_request torrent_info::map_file(int file_index, size_type file_offset - , int size) const + , int size, bool storage) const { - assert(file_index < (int)m_files.size()); + assert(file_index < num_files(storage)); assert(file_index >= 0); - size_type offset = file_offset + m_files[file_index].offset; + size_type offset = file_offset + file_at(file_index, storage).offset; peer_request ret; ret.piece = offset / piece_length(); @@ -876,3 +903,4 @@ namespace libtorrent } } +