From cde9457fdbb1c89e63d94db89eb345f10bcd08c0 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 21 Dec 2016 01:00:49 -0500 Subject: [PATCH] fix merge issue --- simulation/fake_peer.hpp | 11 ++++++----- simulation/test_dht.cpp | 2 +- simulation/test_socks5.cpp | 2 +- src/session_impl.cpp | 8 ++++++-- test/test_file.cpp | 6 ++++++ test/test_read_piece.cpp | 2 ++ 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/simulation/fake_peer.hpp b/simulation/fake_peer.hpp index 9e4d875f8..e3c6206cb 100644 --- a/simulation/fake_peer.hpp +++ b/simulation/fake_peer.hpp @@ -88,7 +88,7 @@ struct fake_peer m_info_hash = ih; - boost::system::error_code ec; + std::printf("fake_peer::connect_to(%s)\n", lt::print_endpoint(ep).c_str()); m_socket.async_connect(ep, std::bind(&fake_peer::write_handshake , this, _1, ih)); } @@ -139,10 +139,10 @@ private: { using namespace std::placeholders; - asio::ip::tcp::endpoint const ep = m_socket.remote_endpoint(); - std::printf("fake_peer::connect (%s) -> (%d) %s\n" - , lt::print_endpoint(ep).c_str(), ec.value() - , ec.message().c_str()); + std::printf("fake_peer::connect() -> (%d) %s\n" + , ec.value(), ec.message().c_str()); + if (ec) return; + static char const handshake[] = "\x13" "BitTorrent protocol\0\0\0\0\0\0\0\x04" " " // space for info-hash @@ -151,6 +151,7 @@ private: memcpy(m_out_buffer, handshake, len); memcpy(&m_out_buffer[28], ih.data(), 20); + asio::ip::tcp::endpoint const ep = m_socket.remote_endpoint(); asio::async_write(m_socket, asio::const_buffers_1(&m_out_buffer[0] , len), [this, ep](boost::system::error_code const& ec , size_t /* bytes_transferred */) diff --git a/simulation/test_dht.cpp b/simulation/test_dht.cpp index 18c72fea2..b792f813e 100644 --- a/simulation/test_dht.cpp +++ b/simulation/test_dht.cpp @@ -100,7 +100,7 @@ TORRENT_TEST(dht_bootstrap) sim::default_config cfg; sim::simulation sim{cfg}; - dht_network dht(sim, 1000); + dht_network dht(sim, 1200); int routing_table_depth = 0; int num_nodes = 0; diff --git a/simulation/test_socks5.cpp b/simulation/test_socks5.cpp index 439308b54..7018383d2 100644 --- a/simulation/test_socks5.cpp +++ b/simulation/test_socks5.cpp @@ -324,7 +324,7 @@ TORRENT_TEST(udp_tracker) tracker_alert = true; }, [&](sim::simulation& sim, lt::session& ses - , boost::shared_ptr ti) + , std::shared_ptr ti) { // listen on port 8080 udp_server tracker(sim, "2.2.2.2", 8080, diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 9e40f86ad..6ed21d8c2 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2002,8 +2002,12 @@ namespace aux { ADD_OUTSTANDING_ASYNC("session_impl::on_socks_listen"); socks5_stream& s = *m_socks_listen_socket->get(); - m_socks_listen_port = listen_port(); - if (m_socks_listen_port == 0) m_socks_listen_port = std::uint16_t(2000 + random(60000)); + // figure out which port to ask the socks5 proxy to open or us. + m_socks_listen_port = (m_listen_sockets.empty() + || m_settings.get_bool(settings_pack::anonymous_mode)) + ? std::uint16_t(2000 + random(60000)) + : std::uint16_t(m_listen_sockets.front().tcp_external_port); + s.async_listen(tcp::endpoint(address_v4::any(), m_socks_listen_port) , std::bind(&session_impl::on_socks_listen, this , m_socks_listen_socket, _1)); diff --git a/test/test_file.cpp b/test/test_file.cpp index f5a165992..8947b2197 100644 --- a/test/test_file.cpp +++ b/test/test_file.cpp @@ -65,15 +65,21 @@ TORRENT_TEST(create_directory) { error_code ec; create_directory("__foobar__", ec); + if (ec) std::printf("ERROR: create_directory: (%d) %s\n" + , ec.value(), ec.message().c_str()); TEST_CHECK(!ec); file_status st; stat_file("__foobar__", &st, ec); + if (ec) std::printf("ERROR: stat_file: (%d) %s\n" + , ec.value(), ec.message().c_str()); TEST_CHECK(!ec); TEST_CHECK(st.mode & file_status::directory); remove("__foobar__", ec); + if (ec) std::printf("ERROR: remove: (%d) %s\n" + , ec.value(), ec.message().c_str()); TEST_CHECK(!ec); } diff --git a/test/test_read_piece.cpp b/test/test_read_piece.cpp index 826aef4eb..f7a8828e8 100644 --- a/test/test_read_piece.cpp +++ b/test/test_read_piece.cpp @@ -112,6 +112,8 @@ void test_read_piece(int flags) if (flags & seed_mode) p.flags |= add_torrent_params::flag_seed_mode; torrent_handle tor1 = ses.add_torrent(p, ec); + if (ec) std::printf("ERROR: add_torrent: (%d) %s\n" + , ec.value(), ec.message().c_str()); TEST_CHECK(!ec); TEST_CHECK(tor1.is_valid());