diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index 34686bb0..242e29dd 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -753,8 +753,9 @@ Result ConnectionCreator::get_transport_type(const Proxy Result ConnectionCreator::find_connection(const ProxyInfo &proxy, DcId dc_id, bool allow_media_only, FindConnectionExtra &extra) { extra.debug_str = PSTRING() << "Failed to find valid IP for " << dc_id; - TRY_RESULT(info, - dc_options_set_.find_connection(dc_id, allow_media_only, proxy.use_proxy() && !proxy.use_mtproto_proxy())); + TRY_RESULT(info, dc_options_set_.find_connection( + dc_id, allow_media_only, + proxy.use_proxy() && proxy.use_socks5_proxy() && proxy.ip_address().is_ipv4())); extra.stat = info.stat; TRY_RESULT(transport_type, get_transport_type(proxy, info)); extra.transport_type = std::move(transport_type); diff --git a/tdutils/td/utils/port/IPAddress.cpp b/tdutils/td/utils/port/IPAddress.cpp index 4923583f..ecc32c54 100644 --- a/tdutils/td/utils/port/IPAddress.cpp +++ b/tdutils/td/utils/port/IPAddress.cpp @@ -178,6 +178,7 @@ bool IPAddress::is_valid() const { } const sockaddr *IPAddress::get_sockaddr() const { + CHECK(is_valid()); return &sockaddr_; } @@ -199,7 +200,11 @@ int IPAddress::get_address_family() const { } bool IPAddress::is_ipv4() const { - return get_address_family() == AF_INET; + return is_valid() && get_address_family() == AF_INET; +} + +bool IPAddress::is_ipv6() const { + return is_valid() && get_address_family() == AF_INET6; } uint32 IPAddress::get_ipv4() const { @@ -461,7 +466,7 @@ void IPAddress::set_port(int port) { bool operator==(const IPAddress &a, const IPAddress &b) { if (!a.is_valid() || !b.is_valid()) { - return false; + return !a.is_valid() && !b.is_valid(); } if (a.get_address_family() != b.get_address_family()) { return false; @@ -480,8 +485,8 @@ bool operator==(const IPAddress &a, const IPAddress &b) { } bool operator<(const IPAddress &a, const IPAddress &b) { - if (a.is_valid() != b.is_valid()) { - return a.is_valid() < b.is_valid(); + if (!a.is_valid() || !b.is_valid()) { + return !a.is_valid() && b.is_valid(); } if (a.get_address_family() != b.get_address_family()) { return a.get_address_family() < b.get_address_family(); diff --git a/tdutils/td/utils/port/IPAddress.h b/tdutils/td/utils/port/IPAddress.h index f2bab9fc..c9993dbb 100644 --- a/tdutils/td/utils/port/IPAddress.h +++ b/tdutils/td/utils/port/IPAddress.h @@ -29,17 +29,18 @@ class IPAddress { IPAddress(); bool is_valid() const; - - const sockaddr *get_sockaddr() const; - size_t get_sockaddr_len() const; - int get_address_family() const; - Slice get_ip_str() const; bool is_ipv4() const; - uint32 get_ipv4() const; - Slice get_ipv6() const; + bool is_ipv6() const; + int get_port() const; void set_port(int port); + uint32 get_ipv4() const; + Slice get_ipv6() const; + Slice get_ip_str() const; + + static CSlice ipv4_to_str(int32 ipv4); + IPAddress get_any_addr() const; Status init_ipv6_port(CSlice ipv6, int port) TD_WARN_UNUSED_RESULT; @@ -54,7 +55,10 @@ class IPAddress { friend bool operator==(const IPAddress &a, const IPAddress &b); friend bool operator<(const IPAddress &a, const IPAddress &b); - static CSlice ipv4_to_str(int32 ipv4); + // for internal usage only + const sockaddr *get_sockaddr() const; + size_t get_sockaddr_len() const; + int get_address_family() const; private: union {