diff --git a/td/telegram/net/DcOptions.h b/td/telegram/net/DcOptions.h index 07cf67c80..c4242cc64 100644 --- a/td/telegram/net/DcOptions.h +++ b/td/telegram/net/DcOptions.h @@ -33,10 +33,6 @@ class DcOption { int32 flags; }; - bool is_ipv6() const { - return (flags_ & Flags::IPv6) != 0; - } - public: DcOption() = default; @@ -113,6 +109,10 @@ class DcOption { return ip_address_; } + bool is_ipv6() const { + return (flags_ & Flags::IPv6) != 0; + } + bool is_media_only() const { return (flags_ & Flags::MediaOnly) != 0; } diff --git a/td/telegram/net/DcOptionsSet.cpp b/td/telegram/net/DcOptionsSet.cpp index 1df19c514..9d97dd374 100644 --- a/td/telegram/net/DcOptionsSet.cpp +++ b/td/telegram/net/DcOptionsSet.cpp @@ -43,7 +43,8 @@ DcOptions DcOptionsSet::get_dc_options() const { return result; } -vector DcOptionsSet::find_all_connections(DcId dc_id, bool allow_media_only, bool use_static) { +vector DcOptionsSet::find_all_connections(DcId dc_id, bool allow_media_only, + bool use_static) { std::vector options; std::vector static_options; @@ -85,6 +86,12 @@ vector DcOptionsSet::find_all_connections(DcId dc_ if (use_static) { if (!static_options.empty()) { options = std::move(static_options); + } else { + bool have_ipv4 = std::any_of(options.begin(), options.end(), [](auto &v) { return !v.option->is_ipv6(); }); + if (have_ipv4) { + options.erase(std::remove_if(options.begin(), options.end(), [](auto &v) { return v.option->is_ipv6(); }), + options.end()); + } } } else { if (options.empty()) {