diff --git a/libtransmission/session.cc b/libtransmission/session.cc index 69ebff852..c0070f54b 100644 --- a/libtransmission/session.cc +++ b/libtransmission/session.cc @@ -677,10 +677,7 @@ void tr_session::setSettings(tr_session_settings&& settings_in, bool force) setDefaultTrackers(val); } - if (auto const& val = new_settings.utp_enabled; force || val != old_settings.utp_enabled) - { - tr_sessionSetUTPEnabled(this, val); - } + bool const utp_changed = new_settings.utp_enabled != old_settings.utp_enabled; useBlocklist(new_settings.blocklist_enabled); @@ -727,9 +724,7 @@ void tr_session::setSettings(tr_session_settings&& settings_in, bool force) port_forwarding_->local_port_changed(); } - bool const dht_changed = new_settings.dht_enabled != old_settings.dht_enabled; - - if (!udp_core_ || force || port_changed || dht_changed) + if (!udp_core_ || force || port_changed || utp_changed) { udp_core_ = std::make_unique(*this, udpPort()); } @@ -748,11 +743,11 @@ void tr_session::setSettings(tr_session_settings&& settings_in, bool force) } } - if (!allowsDHT()) + if (!new_settings.dht_enabled) { dht_.reset(); } - else if (force || !dht_ || port_changed || addr_changed || dht_changed) + else if (force || !dht_ || port_changed || addr_changed || new_settings.dht_enabled != old_settings.dht_enabled) { dht_ = tr_dht::create(dht_mediator_, localPeerPort(), udp_core_->socket4(), udp_core_->socket6()); } @@ -1450,7 +1445,13 @@ void tr_sessionSetUTPEnabled(tr_session* session, bool enabled) return; } - session->settings_.utp_enabled = enabled; + session->runInSessionThread( + [session, enabled]() + { + auto settings = session->settings_; + settings.utp_enabled = enabled; + session->setSettings(std::move(settings), false); + }); } void tr_sessionSetLPDEnabled(tr_session* session, bool enabled)