From df85b31490ceeebdd4a5ad3c3d3d1f105a6c25bf Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 15 Jan 2020 11:35:32 +0100 Subject: [PATCH] deprecate and remvoe broadcast_lsd setting --- ChangeLog | 1 + include/libtorrent/aux_/session_impl.hpp | 4 ++-- include/libtorrent/aux_/session_interface.hpp | 2 +- include/libtorrent/lsd.hpp | 11 +++++------ include/libtorrent/settings_pack.hpp | 6 +++++- include/libtorrent/torrent.hpp | 4 +--- src/broadcast_socket.cpp | 2 -- src/lsd.cpp | 14 ++++++-------- src/session_impl.cpp | 4 ++-- src/settings_pack.cpp | 2 +- src/torrent.cpp | 5 +---- test/test_lsd.cpp | 1 + 12 files changed, 26 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index a93b92542..f5313bf54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * deprecate broadcast_lsd setting. Just use multicast * deprecate upnp_ignore_nonrouters setting * don't attempt sending event=stopped if event=start never succeeded * make sure &key= stays consistent between different source IPs (as mandated by BEP7) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 7c9f637e3..f86d8978b 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -108,7 +108,7 @@ namespace libtorrent { struct plugin; struct upnp; struct natpmp; - class lsd; + struct lsd; class torrent; class alert; struct torrent_handle; @@ -642,7 +642,7 @@ namespace aux { torrent_handle find_torrent_handle(sha1_hash const& info_hash); - void announce_lsd(sha1_hash const& ih, int port, bool broadcast = false) override; + void announce_lsd(sha1_hash const& ih, int port) override; void save_state(entry* e, save_state_flags_t flags) const; void load_state(bdecode_node const* e, save_state_flags_t flags); diff --git a/include/libtorrent/aux_/session_interface.hpp b/include/libtorrent/aux_/session_interface.hpp index 2ad95eb38..294e44834 100644 --- a/include/libtorrent/aux_/session_interface.hpp +++ b/include/libtorrent/aux_/session_interface.hpp @@ -288,7 +288,7 @@ namespace aux { virtual aux::vector& torrent_list(torrent_list_index_t i) = 0; virtual bool has_lsd() const = 0; - virtual void announce_lsd(sha1_hash const& ih, int port, bool broadcast = false) = 0; + virtual void announce_lsd(sha1_hash const& ih, int port) = 0; virtual libtorrent::utp_socket_manager* utp_socket_manager() = 0; virtual void inc_boost_connections() = 0; virtual std::vector& block_info_storage() = 0; diff --git a/include/libtorrent/lsd.hpp b/include/libtorrent/lsd.hpp index a1156016e..66effd542 100644 --- a/include/libtorrent/lsd.hpp +++ b/include/libtorrent/lsd.hpp @@ -41,15 +41,14 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { -class lsd : public std::enable_shared_from_this +struct lsd : std::enable_shared_from_this { -public: lsd(io_service& ios, aux::lsd_callback& cb); ~lsd(); void start(error_code& ec); - void announce(sha1_hash const& ih, int listen_port, bool broadcast = false); + void announce(sha1_hash const& ih, int listen_port); void close(); private: @@ -57,7 +56,7 @@ private: std::shared_ptr self() { return shared_from_this(); } void announce_impl(sha1_hash const& ih, int listen_port - , bool broadcast, int retry_count); + , int retry_count); void resend_announce(error_code const& e, sha1_hash const& ih , int listen_port, int retry_count); void on_announce(udp::endpoint const& from, span buffer); @@ -84,8 +83,8 @@ private: // as a peer int m_cookie; - bool m_disabled; - bool m_disabled6; + bool m_disabled = false; + bool m_disabled6 = false; }; } diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 73c7689a4..20e09da26 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -490,13 +490,17 @@ namespace aux { // requested from another peer already. strict_end_game_mode, +#if TORRENT_ABI_VERSION == 1 // if ``broadcast_lsd`` is set to true, the local peer discovery (or // Local Service Discovery) will not only use IP multicast, but also // broadcast its messages. This can be useful when running on networks // that don't support multicast. Since broadcast messages might be // expensive and disruptive on networks, only every 8th announce uses // broadcast. - broadcast_lsd, + broadcast_lsd TORRENT_DEPRECATED_ENUM, +#else + deprecated_broadcast_lsd, +#endif // when set to true, libtorrent will try to make outgoing utp // connections controls whether libtorrent will accept incoming diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index d62f8b568..70f56dbf9 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1590,9 +1590,7 @@ namespace libtorrent { // the number of unchoked peers in this torrent unsigned int m_num_uploads:24; - // rotating sequence number for LSD announces sent out. - // used to only use IP broadcast for every 8th lsd announce - std::uint8_t m_lsd_seq:3; + // 3 unused bits // when this is true, this torrent supports peer exchange bool m_enable_pex:1; diff --git a/src/broadcast_socket.cpp b/src/broadcast_socket.cpp index dd65d6bd2..6077e5042 100644 --- a/src/broadcast_socket.cpp +++ b/src/broadcast_socket.cpp @@ -210,8 +210,6 @@ namespace libtorrent { std::shared_ptr s = std::make_shared(ios); s->open(addr.is_v4() ? udp::v4() : udp::v6(), ec); if (ec) return; - s->bind(udp::endpoint(addr, 0), ec); - if (ec) return; m_unicast_sockets.emplace_back(s, mask); socket_entry& se = m_unicast_sockets.back(); diff --git a/src/lsd.cpp b/src/lsd.cpp index 562f374c6..14a0aa767 100644 --- a/src/lsd.cpp +++ b/src/lsd.cpp @@ -72,8 +72,6 @@ lsd::lsd(io_service& ios, aux::lsd_callback& cb) , m_socket6(udp::endpoint(make_address_v6("ff15::efc0:988f", dummy), 6771)) , m_broadcast_timer(ios) , m_cookie((random(0x7fffffff) ^ std::uintptr_t(this)) & 0x7fffffff) - , m_disabled(false) - , m_disabled6(false) { } @@ -109,13 +107,13 @@ void lsd::start(error_code& ec) lsd::~lsd() = default; -void lsd::announce(sha1_hash const& ih, int listen_port, bool broadcast) +void lsd::announce(sha1_hash const& ih, int listen_port) { - announce_impl(ih, listen_port, broadcast, 0); + announce_impl(ih, listen_port, 0); } void lsd::announce_impl(sha1_hash const& ih, int const listen_port - , bool const broadcast, int retry_count) + , int retry_count) { if (m_disabled && m_disabled6) return; @@ -130,7 +128,7 @@ void lsd::announce_impl(sha1_hash const& ih, int const listen_port { int const msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, aux::to_hex(ih).c_str() , m_cookie, "239.192.152.143"); - m_socket.send(msg, msg_len, ec, broadcast ? broadcast_socket::flag_broadcast : 0); + m_socket.send(msg, msg_len, ec); if (ec) { m_disabled = true; @@ -148,7 +146,7 @@ void lsd::announce_impl(sha1_hash const& ih, int const listen_port { int const msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, aux::to_hex(ih).c_str() , m_cookie, "[ff15::efc0:988f]"); - m_socket6.send(msg, msg_len, ec, broadcast ? broadcast_socket::flag_broadcast : 0); + m_socket6.send(msg, msg_len, ec); if (ec) { m_disabled6 = true; @@ -179,7 +177,7 @@ void lsd::resend_announce(error_code const& e, sha1_hash const& info_hash COMPLETE_ASYNC("lsd::resend_announce"); if (e) return; - announce_impl(info_hash, listen_port, false, retry_count); + announce_impl(info_hash, listen_port, retry_count); } void lsd::on_announce(udp::endpoint const& from, span buf) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index e96bb0198..8fc07e50a 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -5475,11 +5475,11 @@ namespace aux { return 0; } - void session_impl::announce_lsd(sha1_hash const& ih, int port, bool broadcast) + void session_impl::announce_lsd(sha1_hash const& ih, int port) { // use internal listen port for local peers if (m_lsd) - m_lsd->announce(ih, port, broadcast); + m_lsd->announce(ih, port); } void session_impl::on_lsd_peer(tcp::endpoint const& peer, sha1_hash const& ih) diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 52bbf3aa7..85cd5d2ae 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -170,7 +170,7 @@ constexpr int CLOSE_FILE_INTERVAL = 0; SET(incoming_starts_queued_torrents, false, nullptr), SET(report_true_downloaded, false, nullptr), SET(strict_end_game_mode, true, nullptr), - SET(broadcast_lsd, true, nullptr), + DEPRECATED_SET(broadcast_lsd, true, nullptr), SET(enable_outgoing_utp, true, nullptr), SET(enable_incoming_utp, true, nullptr), SET(enable_outgoing_tcp, true, nullptr), diff --git a/src/torrent.cpp b/src/torrent.cpp index c686101f1..af687498a 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -208,7 +208,6 @@ bool is_downloading_state(int const st) , m_max_uploads((1 << 24) - 1) , m_save_resume_flags() , m_num_uploads(0) - , m_lsd_seq(0) , m_enable_pex(!bool(p.flags & torrent_flags::disable_pex)) , m_magnet_link(false) , m_apply_ip_filter(p.flags & torrent_flags::apply_ip_filter) @@ -2603,9 +2602,7 @@ bool is_downloading_state(int const st) #endif // announce with the local discovery service - m_ses.announce_lsd(m_torrent_file->info_hash(), port - , settings().get_bool(settings_pack::broadcast_lsd) && m_lsd_seq == 0); - ++m_lsd_seq; + m_ses.announce_lsd(m_torrent_file->info_hash(), port); } #ifndef TORRENT_DISABLE_DHT diff --git a/test/test_lsd.cpp b/test/test_lsd.cpp index c61d9866a..f7d535655 100644 --- a/test/test_lsd.cpp +++ b/test/test_lsd.cpp @@ -54,6 +54,7 @@ void test_lsd() settings_pack pack; pack.set_bool(settings_pack::allow_multiple_connections_per_ip, true); + pack.set_int(settings_pack::alert_mask, alert::error_notification | alert::session_log_notification | alert::status_notification); pack.set_bool(settings_pack::enable_dht, false); pack.set_bool(settings_pack::enable_lsd, true); pack.set_bool(settings_pack::enable_upnp, false);