From 97ce1b07bfdb32759ba80a56b300418fc82b0f59 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 21 Aug 2016 20:21:50 -0400 Subject: [PATCH 1/9] fix building tarball --- build_dist.sh | 10 +++++----- src/puff.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build_dist.sh b/build_dist.sh index 10e2ecaf4..1f9339282 100755 --- a/build_dist.sh +++ b/build_dist.sh @@ -1,9 +1,9 @@ #!/bin/sh -make distclean +make clean cd docs -make +make RST2HTML=rst2html.py cd .. #clear out any extended attributes that Finder may add @@ -22,9 +22,9 @@ rm -f bindings/python/Makefile bindings/python/Makefile.in chmod a-x docs/*.rst docs/*.htm* src/*.cpp include/libtorrent/*.hpp ./autotool.sh -./configure --enable-python-binding --enable-examples=yes --enable-encryption --enable-tests=yes --with-boost-system=mt --with-boost-chrono=mt --with-boost-random=mt --with-boost-python=mt -make V=1 -j8 distcheck +./configure --enable-python-binding --enable-examples=yes --enable-encryption --enable-tests=yes --with-boost-system=mt --with-boost-chrono=mt --with-boost-random=mt --with-boost-python=mt --with-openssl=/opt/local +make V=1 -j8 check -./configure --enable-python-binding --enable-examples=yes --enable-encryption --with-boost-system=mt --with-boost-chrono=mt --with-boost-random=mt --with-boost-python=mt +./configure --enable-python-binding --enable-examples=yes --enable-encryption --with-boost-system=mt --with-boost-chrono=mt --with-boost-random=mt --with-boost-python=mt --with-openssl=/opt/local make V=1 -j8 dist diff --git a/src/puff.cpp b/src/puff.cpp index 83e1b0e26..b6d86be58 100644 --- a/src/puff.cpp +++ b/src/puff.cpp @@ -84,7 +84,7 @@ #include /* for setjmp(), longjmp(), and jmp_buf */ #include /* for NULL */ -#include "puff.hpp" /* prototype for puff() */ +#include "libtorrent/puff.hpp" /* prototype for puff() */ #define local static /* for local function definitions */ From 2a36f9015d6d7387a0fd89b2c551967d9d4db9fb Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 22 Aug 2016 07:59:46 -0400 Subject: [PATCH 2/9] build mpi.c as c++ to allow including boost headers (#1026) build mpi.c as c++ to allow including boost headers --- Jamfile | 2 +- src/Makefile.am | 2 +- src/{mpi.c => mpi.cpp} | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) rename src/{mpi.c => mpi.cpp} (99%) diff --git a/Jamfile b/Jamfile index ddae14729..490d80dcb 100644 --- a/Jamfile +++ b/Jamfile @@ -328,7 +328,7 @@ rule building ( properties * ) if on in $(properties) { - result += src/mpi.c ; + result += src/mpi.cpp ; result += src/pe_crypto.cpp ; } diff --git a/src/Makefile.am b/src/Makefile.am index d2ff91f79..4c3496ad1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -86,7 +86,7 @@ libtorrent_rasterbar_la_SOURCES = \ magnet_uri.cpp \ merkle.cpp \ metadata_transfer.cpp \ - mpi.c \ + mpi.cpp \ natpmp.cpp \ parse_url.cpp \ part_file.cpp \ diff --git a/src/mpi.c b/src/mpi.cpp similarity index 99% rename from src/mpi.c rename to src/mpi.cpp index 1153e5d47..b8104f88e 100644 --- a/src/mpi.c +++ b/src/mpi.cpp @@ -1,3 +1,5 @@ +#include "libtorrent/aux_/disable_warnings_push.hpp" + /* Start: bn_error.c */ #include "libtorrent/tommath_private.h" #ifdef BN_ERROR_C From 558ec097a2e21db19a1f2edcc43f54d09c8e8ddd Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 22 Aug 2016 21:38:57 -0400 Subject: [PATCH 3/9] fix applying settings to only take actual updates into account (#1027) --- src/settings_pack.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index d45a6aaa7..c67ea6d68 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -598,6 +598,9 @@ namespace libtorrent if (index < 0 || index >= settings_pack::num_string_settings) continue; + // if the vaue did not change, don't call the update callback + if (sett.get_str(i->first) == i->second) continue; + sett.set_str(i->first, i->second); str_setting_entry_t const& sa = str_settings[i->first & settings_pack::index_mask]; if (sa.fun && ses @@ -617,6 +620,9 @@ namespace libtorrent if (index < 0 || index >= settings_pack::num_int_settings) continue; + // if the vaue did not change, don't call the update callback + if (sett.get_int(i->first) == i->second) continue; + sett.set_int(i->first, i->second); int_setting_entry_t const& sa = int_settings[i->first & settings_pack::index_mask]; if (sa.fun && ses @@ -636,6 +642,9 @@ namespace libtorrent if (index < 0 || index >= settings_pack::num_bool_settings) continue; + // if the vaue did not change, don't call the update callback + if (sett.get_bool(i->first) == i->second) continue; + sett.set_bool(i->first, i->second); bool_setting_entry_t const& sa = bool_settings[i->first & settings_pack::index_mask]; if (sa.fun && ses From 6aacc0bf03f193d59369f7bf66d94bacfb5ef9b5 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 23 Aug 2016 00:27:11 -0400 Subject: [PATCH 4/9] fix bug in bt-get2.cpp example --- examples/bt-get2.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/bt-get2.cpp b/examples/bt-get2.cpp index c608752c1..93389788b 100644 --- a/examples/bt-get2.cpp +++ b/examples/bt-get2.cpp @@ -137,6 +137,7 @@ int main(int argc, char const* argv[]) // save resume data once every 30 seconds if (clk::now() - last_save_resume > std::chrono::seconds(30)) { h.save_resume_data(); + last_save_resume = clk::now(); } } From 599967c4b55f0ab7b56ebda82b671cf4f5dac4cc Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 23 Aug 2016 02:04:24 -0400 Subject: [PATCH 5/9] add missing files to makefile --- build_dist.sh | 2 +- examples/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build_dist.sh b/build_dist.sh index 1f9339282..cc684e0af 100755 --- a/build_dist.sh +++ b/build_dist.sh @@ -3,7 +3,7 @@ make clean cd docs -make RST2HTML=rst2html.py +make RST2HTML=rst2html-3.4.py cd .. #clear out any extended attributes that Finder may add diff --git a/examples/Makefile.am b/examples/Makefile.am index 4ced3561c..f786fc8e6 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -14,7 +14,7 @@ bin_PROGRAMS = $(example_programs) endif EXTRA_PROGRAMS = $(example_programs) -EXTRA_DIST = Jamfile CMakeLists.txt run_cmake.sh.in cmake/FindLibtorrentRasterbar.cmake +EXTRA_DIST = Jamfile CMakeLists.txt run_cmake.sh.in session_view.hpp torrent_view.hpp print.hpp cmake/FindLibtorrentRasterbar.cmake client_test_SOURCES = client_test.cpp print.cpp session_view.cpp torrent_view.cpp stats_counters_SOURCES = stats_counters.cpp From 3a665a1040d7c955a21e3235af5cfec03b12ab8f Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Thu, 25 Aug 2016 16:26:48 -0700 Subject: [PATCH 6/9] fix inconsistant prefix calulcation (#1030) The special case for calculating the prefix in the last bucket was being applied to the condidate node but not the existing nodes in the bucket. --- include/libtorrent/kademlia/node_id.hpp | 2 +- src/kademlia/node_id.cpp | 4 ++-- src/kademlia/routing_table.cpp | 17 +++++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/libtorrent/kademlia/node_id.hpp b/include/libtorrent/kademlia/node_id.hpp index affdba502..c01e24378 100644 --- a/include/libtorrent/kademlia/node_id.hpp +++ b/include/libtorrent/kademlia/node_id.hpp @@ -72,7 +72,7 @@ bool TORRENT_EXTRA_EXPORT verify_secret_id(node_id const& nid); node_id TORRENT_EXTRA_EXPORT generate_id_impl(address const& ip_, boost::uint32_t r); bool TORRENT_EXTRA_EXPORT verify_id(node_id const& nid, address const& source_ip); -bool TORRENT_EXTRA_EXPORT matching_prefix(node_entry const& n, int mask, int prefix, int bucket_index); +bool TORRENT_EXTRA_EXPORT matching_prefix(node_entry const& n, int mask, int prefix, int offset); node_id TORRENT_EXTRA_EXPORT generate_prefix_mask(int bits); } } // namespace libtorrent::dht diff --git a/src/kademlia/node_id.cpp b/src/kademlia/node_id.cpp index e74d60c19..8976bfde1 100644 --- a/src/kademlia/node_id.cpp +++ b/src/kademlia/node_id.cpp @@ -216,10 +216,10 @@ node_id generate_id(address const& ip) return generate_id_impl(ip, random()); } -bool matching_prefix(node_entry const& n, int mask, int prefix, int bucket_index) +bool matching_prefix(node_entry const& n, int mask, int prefix, int offset) { node_id id = n.id; - id <<= bucket_index + 1; + id <<= offset; return (id[0] & mask) == prefix; } diff --git a/src/kademlia/routing_table.cpp b/src/kademlia/routing_table.cpp index faeb0c9c8..0bafd4f3e 100644 --- a/src/kademlia/routing_table.cpp +++ b/src/kademlia/routing_table.cpp @@ -809,18 +809,19 @@ ip_ok: std::vector nodes; bool force_replace = false; + // the last bucket is special, since it hasn't been split yet, it + // includes that top bit as well + int const prefix_offset = + bucket_index + 1 == m_buckets.size() ? bucket_index : bucket_index + 1; + { node_id id = e.id; - // the last bucket is special, since it hasn't been split yet, it - // includes that top bit as well - if (bucket_index + 1 == m_buckets.size()) - id <<= bucket_index; - else - id <<= bucket_index + 1; + id <<= prefix_offset; + int const candidate_prefix = id[0] & mask; for (j = b.begin(); j != b.end(); ++j) { - if (!matching_prefix(*j, mask, id[0] & mask, bucket_index)) continue; + if (!matching_prefix(*j, mask, candidate_prefix, prefix_offset)) continue; nodes.push_back(j); } } @@ -850,7 +851,7 @@ ip_ok: for (j = b.begin(); j != b.end(); ++j) { node_id id = j->id; - id <<= bucket_index + 1; + id <<= prefix_offset; int this_prefix = (id[0] & mask) >> mask_shift; TORRENT_ASSERT(this_prefix >= 0); TORRENT_ASSERT(this_prefix < int(prefix.size())); From 88fe6ae8c3a13251ae060c78af5749d99136fa26 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 30 Aug 2016 08:25:07 -0400 Subject: [PATCH 7/9] don't link against sha1.cpp when using libcrypto's implementation (#1040) --- src/Makefile.am | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 4c3496ad1..f273f90fe 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -32,6 +32,11 @@ KADEMLIA_SOURCES = \ ../ed25519/src/verify.cpp endif +if ! WITH_OPENSSL +BUILTIN_CRYPTO_SOURCES = \ + sha1.cpp +endif + libtorrent_rasterbar_la_SOURCES = \ web_connection_base.cpp \ alert.cpp \ @@ -115,7 +120,6 @@ libtorrent_rasterbar_la_SOURCES = \ session_settings.cpp \ proxy_settings.cpp \ settings_pack.cpp \ - sha1.cpp \ smart_ban.cpp \ socket_io.cpp \ socket_type.cpp \ @@ -148,7 +152,9 @@ libtorrent_rasterbar_la_SOURCES = \ version.cpp \ file_progress.cpp \ \ - $(KADEMLIA_SOURCES) + $(KADEMLIA_SOURCES) \ + \ + $(BUILTIN_CRYPTO_SOURCES) libtorrent_rasterbar_la_LDFLAGS = -version-info $(INTERFACE_VERSION_INFO) libtorrent_rasterbar_la_LIBADD = @BOOST_SYSTEM_LIB@ @OPENSSL_LIBS@ From b554909486b17cca8f41d1d58e98b77bc518f783 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 30 Aug 2016 21:15:35 -0400 Subject: [PATCH 8/9] hint DHT bootstrap nodes of actual bootstrap request --- ChangeLog | 2 ++ simulation/fake_peer.hpp | 11 +++++++++-- simulation/test_dht_bootstrap.cpp | 10 ++++++++++ src/kademlia/refresh.cpp | 8 ++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4c6f2fca..da4c2fa53 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ + * hint DHT bootstrap nodes of actual bootstrap request + 1.1.1 release * update puff.c for gzip inflation diff --git a/simulation/fake_peer.hpp b/simulation/fake_peer.hpp index 1ed6925d0..c113680b0 100644 --- a/simulation/fake_peer.hpp +++ b/simulation/fake_peer.hpp @@ -208,10 +208,12 @@ struct fake_node lt::bdecode_node n; boost::system::error_code err; - int const ret = bdecode(m_in_buffer, m_in_buffer + bytes_transferred + int const ret = bdecode(m_in_buffer.data(), m_in_buffer.data() + bytes_transferred , n, err, nullptr, 10, 200); TEST_EQUAL(ret, 0); + m_incoming_packets.emplace_back(m_in_buffer.data(), m_in_buffer.data() + bytes_transferred); + // TODO: ideally we would validate the DHT message m_tripped = true; }); @@ -224,9 +226,14 @@ struct fake_node bool tripped() const { return m_tripped; } + std::vector> const& incoming_packets() const + { return m_incoming_packets; } + private: - char m_in_buffer[300]; + std::array m_in_buffer; + + std::vector> m_incoming_packets; asio::io_service m_ios; asio::ip::udp::socket m_socket; diff --git a/simulation/test_dht_bootstrap.cpp b/simulation/test_dht_bootstrap.cpp index fe3af95cf..d01703f8b 100644 --- a/simulation/test_dht_bootstrap.cpp +++ b/simulation/test_dht_bootstrap.cpp @@ -92,5 +92,15 @@ TORRENT_TEST(dht_bootstrap) sim.run(); TEST_EQUAL(node.tripped(), true); + + std::vector const& p = node.incoming_packets().front(); + lt::bdecode_node n; + boost::system::error_code err; + int const ret = bdecode(p.data(), p.data() + p.size() + , n, err, nullptr, 10, 200); + TEST_EQUAL(ret, 0); + + lt::bdecode_node a = n.dict_find_dict("a"); + TEST_CHECK(a.dict_find_int_value("bs", -1) == 1); } diff --git a/src/kademlia/refresh.cpp b/src/kademlia/refresh.cpp index 998e6efd1..e6aa5c70f 100644 --- a/src/kademlia/refresh.cpp +++ b/src/kademlia/refresh.cpp @@ -65,6 +65,14 @@ bool bootstrap::invoke(observer_ptr o) make_id_secret(target); a["info_hash"] = target.to_string(); + if (o->flags & observer::flag_initial) + { + // if this packet is being sent to a bootstrap/router node, let it know + // that we're actualy bootstrapping (as opposed to being collateral + // traffic). + a["bs"] = 1; + } + // e["q"] = "find_node"; // a["target"] = target.to_string(); m_node.stats_counters().inc_stats_counter(counters::dht_get_peers_out); From e4a27c0b4bf7ee3272b90fece91db9522b8be7c5 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Tue, 6 Sep 2016 18:30:30 -0400 Subject: [PATCH 9/9] backport of fix in resolve_links::match (#1068) backport of fix in resolve_links::match --- ChangeLog | 1 + src/resolve_links.cpp | 76 ++++++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index da4c2fa53..669e78277 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * fix internal resolve links lookup for mutable torrents * hint DHT bootstrap nodes of actual bootstrap request 1.1.1 release diff --git a/src/resolve_links.cpp b/src/resolve_links.cpp index 510998e3e..b0fc40bfb 100644 --- a/src/resolve_links.cpp +++ b/src/resolve_links.cpp @@ -90,48 +90,50 @@ void resolve_links::match(boost::shared_ptr const& ti boost::int64_t file_size = fs.file_size(i); typedef boost::unordered_multimap::iterator iterator; - iterator iter = m_file_sizes.find(file_size); + typedef std::pair range_iterator; - // we don't have a file whose size matches, look at the next one - if (iter == m_file_sizes.end()) continue; - - TORRENT_ASSERT(iter->second < m_torrent_file->files().num_files()); - TORRENT_ASSERT(iter->second >= 0); - - // if we already have found a duplicate for this file, no need - // to keep looking - if (m_links[iter->second].ti) continue; - - // files are aligned and have the same size, now start comparing - // piece hashes, to see if the files are identical - - // the pieces of the incoming file - int their_piece = fs.map_file(i, 0, 0).piece; - // the pieces of "this" file (from m_torrent_file) - int our_piece = m_torrent_file->files().map_file( - iter->second, 0, 0).piece; - - int num_pieces = (file_size + piece_size - 1) / piece_size; - - bool match = true; - for (int p = 0; p < num_pieces; ++p, ++their_piece, ++our_piece) + range_iterator range = m_file_sizes.equal_range(file_size); + for (iterator iter = range.first; iter != range.second; ++iter) { - if (m_torrent_file->hash_for_piece(our_piece) - != ti->hash_for_piece(their_piece)) + TORRENT_ASSERT(iter->second < m_torrent_file->files().num_files()); + TORRENT_ASSERT(iter->second >= 0); + + // if we already have found a duplicate for this file, no need + // to keep looking + if (m_links[iter->second].ti) continue; + + // files are aligned and have the same size, now start comparing + // piece hashes, to see if the files are identical + + // the pieces of the incoming file + int their_piece = fs.map_file(i, 0, 0).piece; + // the pieces of "this" file (from m_torrent_file) + int our_piece = m_torrent_file->files().map_file( + iter->second, 0, 0).piece; + + int num_pieces = (file_size + piece_size - 1) / piece_size; + + bool match = true; + for (int p = 0; p < num_pieces; ++p, ++their_piece, ++our_piece) { - match = false; - break; + if (m_torrent_file->hash_for_piece(our_piece) + != ti->hash_for_piece(their_piece)) + { + match = false; + break; + } } + if (!match) continue; + + m_links[iter->second].ti = ti; + m_links[iter->second].save_path = save_path; + m_links[iter->second].file_idx = i; + + // since we have a duplicate for this file, we may as well remove + // it from the file-size map, so we won't find it again. + m_file_sizes.erase(iter); + break; } - if (!match) continue; - - m_links[iter->second].ti = ti; - m_links[iter->second].save_path = save_path; - m_links[iter->second].file_idx = i; - - // since we have a duplicate for this file, we may as well remove - // it from the file-size map, so we won't find it again. - m_file_sizes.erase(iter); } }