diff --git a/grammers-mtsender/src/configuration.rs b/grammers-mtsender/src/configuration.rs index 60d11878..0163ba94 100644 --- a/grammers-mtsender/src/configuration.rs +++ b/grammers-mtsender/src/configuration.rs @@ -38,6 +38,8 @@ pub struct ConnectionParams { /// the host manually and selecting an IP address of your choice. #[cfg(feature = "proxy")] pub proxy_url: Option, + /// Whether to connect via IPv6 instead of defaulting to IPv4. + pub use_ipv6: bool, #[doc(hidden)] pub __non_exhaustive: (), } @@ -67,6 +69,7 @@ impl Default for ConnectionParams { app_version: env!("CARGO_PKG_VERSION").to_string(), system_lang_code, lang_code, + use_ipv6: false, #[cfg(feature = "proxy")] proxy_url: None, __non_exhaustive: (), diff --git a/grammers-mtsender/src/sender_pool.rs b/grammers-mtsender/src/sender_pool.rs index 8be1bfaf..2afd5b47 100644 --- a/grammers-mtsender/src/sender_pool.rs +++ b/grammers-mtsender/src/sender_pool.rs @@ -291,23 +291,22 @@ impl SenderPoolRunner { ) -> Result, InvocationError> { let transport = transport::Full::new; + let address = if self.connection_params.use_ipv6 { + dc_option.ipv6.into() + } else { + dc_option.ipv4.into() + }; + #[cfg(feature = "proxy")] let addr = || { if let Some(proxy) = self.connection_params.proxy_url.clone() { - ServerAddr::Proxied { - address: dc_option.ipv4.into(), - proxy, - } + ServerAddr::Proxied { address, proxy } } else { - ServerAddr::Tcp { - address: dc_option.ipv4.into(), - } + ServerAddr::Tcp { address } } }; #[cfg(not(feature = "proxy"))] - let addr = || ServerAddr::Tcp { - address: dc_option.ipv4.into(), - }; + let addr = || ServerAddr::Tcp { address }; let init_connection = tl::functions::InvokeWithLayer { layer: tl::LAYER, diff --git a/grammers-session/src/dc_options.rs b/grammers-session/src/dc_options.rs index e5fc8d5b..7af0aad5 100644 --- a/grammers-session/src/dc_options.rs +++ b/grammers-session/src/dc_options.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::net::{Ipv4Addr, SocketAddrV4, SocketAddrV6}; +use std::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6}; use crate::types::DcOption; @@ -16,8 +16,8 @@ const fn ipv4(a: u8, b: u8, c: u8, d: u8) -> SocketAddrV4 { SocketAddrV4::new(Ipv4Addr::new(a, b, c, d), 443) } -const fn ipv6(a: u8, b: u8, c: u8, d: u8) -> SocketAddrV6 { - SocketAddrV6::new(ipv4(a, b, c, d).ip().to_ipv6_compatible(), 443, 0, 0) +const fn ipv6(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> SocketAddrV6 { + SocketAddrV6::new(Ipv6Addr::new(a, b, c, d, e, f, g, h), 443, 0, 0) } /// Hardcoded known `static` options from `functions::help::GetConfig`. @@ -25,31 +25,31 @@ pub(crate) const KNOWN_DC_OPTIONS: [DcOption; 5] = [ DcOption { id: 1, ipv4: ipv4(149, 154, 175, 53), - ipv6: ipv6(149, 154, 175, 53), + ipv6: ipv6(0x2001, 0xb28, 0xf23d, 0xf001, 0, 0, 0, 0xa), auth_key: None, }, DcOption { id: 2, ipv4: ipv4(149, 154, 167, 41), - ipv6: ipv6(149, 154, 167, 41), + ipv6: ipv6(0x2001, 0x67c, 0x4e8, 0xf002, 0, 0, 0, 0xa), auth_key: None, }, DcOption { id: 3, ipv4: ipv4(149, 154, 175, 100), - ipv6: ipv6(149, 154, 175, 100), + ipv6: ipv6(0x2001, 0xb28, 0xf23d, 0xf003, 0, 0, 0, 0xa), auth_key: None, }, DcOption { id: 4, ipv4: ipv4(149, 154, 167, 92), - ipv6: ipv6(149, 154, 167, 92), + ipv6: ipv6(0x2001, 0x67c, 0x4e8, 0xf004, 0, 0, 0, 0xa), auth_key: None, }, DcOption { id: 5, ipv4: ipv4(91, 108, 56, 104), - ipv6: ipv6(91, 108, 56, 104), + ipv6: ipv6(0x2001, 0xb28, 0xf23f, 0xf005, 0, 0, 0, 0xa), auth_key: None, }, ];