diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index 0aac4d91..0891a662 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -229,8 +229,13 @@ void ConnectionCreator::set_proxy_impl(Proxy proxy, bool from_db) { return; } + if (proxy_.type() == Proxy::Type::Mtproto || proxy.type() == Proxy::Type::Mtproto) { + G()->mtproto_header().set_proxy(proxy); + G()->net_query_dispatcher().update_mtproto_header(); + } + proxy_ = std::move(proxy); - G()->mtproto_header().set_proxy(proxy_); + send_closure(G()->state_manager(), &StateManager::on_proxy, have_proxy); if (!from_db) { diff --git a/td/telegram/net/NetQueryDispatcher.cpp b/td/telegram/net/NetQueryDispatcher.cpp index b1432fa9..dafa65fe 100644 --- a/td/telegram/net/NetQueryDispatcher.cpp +++ b/td/telegram/net/NetQueryDispatcher.cpp @@ -221,6 +221,19 @@ void NetQueryDispatcher::update_use_pfs() { } } } + +void NetQueryDispatcher::update_mtproto_header() { + std::lock_guard guard(main_dc_id_mutex_); + for (size_t i = 1; i < MAX_DC_COUNT; i++) { + if (is_dc_inited(narrow_cast(i))) { + send_closure_later(dcs_[i - 1].main_session_, &SessionMultiProxy::update_mtproto_header); + send_closure_later(dcs_[i - 1].upload_session_, &SessionMultiProxy::update_mtproto_header); + send_closure_later(dcs_[i - 1].download_session_, &SessionMultiProxy::update_mtproto_header); + send_closure_later(dcs_[i - 1].download_small_session_, &SessionMultiProxy::update_mtproto_header); + } + } +} + void NetQueryDispatcher::update_valid_dc(DcId dc_id) { wait_dc_init(dc_id, true); } diff --git a/td/telegram/net/NetQueryDispatcher.h b/td/telegram/net/NetQueryDispatcher.h index b628d056..6ea3ea04 100644 --- a/td/telegram/net/NetQueryDispatcher.h +++ b/td/telegram/net/NetQueryDispatcher.h @@ -45,8 +45,11 @@ class NetQueryDispatcher { void update_session_count(); void update_use_pfs(); + void update_mtproto_header(); + void update_valid_dc(DcId dc_id); - DcId main_dc_id() { + + DcId main_dc_id() const { return DcId::internal(main_dc_id_.load()); } diff --git a/td/telegram/net/SessionMultiProxy.cpp b/td/telegram/net/SessionMultiProxy.cpp index 7fe27dd8..3ed434eb 100644 --- a/td/telegram/net/SessionMultiProxy.cpp +++ b/td/telegram/net/SessionMultiProxy.cpp @@ -87,6 +87,10 @@ void SessionMultiProxy::update_options(int32 session_count, bool use_pfs) { } } +void SessionMultiProxy::update_mtproto_header() { + init(); +} + void SessionMultiProxy::start_up() { init(); } diff --git a/td/telegram/net/SessionMultiProxy.h b/td/telegram/net/SessionMultiProxy.h index e1741e71..c318a22e 100644 --- a/td/telegram/net/SessionMultiProxy.h +++ b/td/telegram/net/SessionMultiProxy.h @@ -32,6 +32,7 @@ class SessionMultiProxy : public Actor { void update_session_count(int32 session_count); void update_use_pfs(bool use_pfs); void update_options(int32 session_count, bool use_pfs); + void update_mtproto_header(); private: size_t pos_ = 0;