This commit is contained in:
Alexey 2026-03-23 23:00:46 +03:00
parent a40d6929e5
commit 8bc432db49
No known key found for this signature in database
4 changed files with 17 additions and 12 deletions

View File

@ -13,8 +13,8 @@ use crate::config::ProxyConfig;
use crate::error::Result; use crate::error::Result;
use crate::transport::UpstreamManager; use crate::transport::UpstreamManager;
use super::http_fetch::https_get;
use super::MePool; use super::MePool;
use super::http_fetch::https_get;
use super::rotation::{MeReinitTrigger, enqueue_reinit_trigger}; use super::rotation::{MeReinitTrigger, enqueue_reinit_trigger};
use super::secret::download_proxy_secret_with_max_len_via_upstream; use super::secret::download_proxy_secret_with_max_len_via_upstream;
use super::selftest::record_timeskew_sample; use super::selftest::record_timeskew_sample;
@ -97,6 +97,7 @@ pub async fn save_proxy_config_cache(path: &str, raw_text: &str) -> Result<()> {
Ok(()) Ok(())
} }
#[allow(dead_code)]
pub async fn fetch_proxy_config_with_raw(url: &str) -> Result<(ProxyConfigData, String)> { pub async fn fetch_proxy_config_with_raw(url: &str) -> Result<(ProxyConfigData, String)> {
fetch_proxy_config_with_raw_via_upstream(url, None).await fetch_proxy_config_with_raw_via_upstream(url, None).await
} }
@ -264,6 +265,7 @@ fn parse_proxy_line(line: &str) -> Option<(i32, IpAddr, u16)> {
Some((dc, ip, port)) Some((dc, ip, port))
} }
#[allow(dead_code)]
pub async fn fetch_proxy_config(url: &str) -> Result<ProxyConfigData> { pub async fn fetch_proxy_config(url: &str) -> Result<ProxyConfigData> {
fetch_proxy_config_via_upstream(url, None).await fetch_proxy_config_via_upstream(url, None).await
} }
@ -390,7 +392,11 @@ async fn run_update_cycle(
} }
let mut ready_v6: Option<(ProxyConfigData, u64)> = None; let mut ready_v6: Option<(ProxyConfigData, u64)> = None;
let cfg_v6 = retry_fetch("https://core.telegram.org/getProxyConfigV6", upstream.clone()).await; let cfg_v6 = retry_fetch(
"https://core.telegram.org/getProxyConfigV6",
upstream.clone(),
)
.await;
if let Some(cfg_v6) = cfg_v6 if let Some(cfg_v6) = cfg_v6
&& snapshot_passes_guards(cfg, &cfg_v6, "getProxyConfigV6") && snapshot_passes_guards(cfg, &cfg_v6, "getProxyConfigV6")
{ {

View File

@ -34,8 +34,8 @@ fn build_tls_client_config() -> Arc<rustls::ClientConfig> {
} }
fn extract_host_port_path(url: &str) -> Result<(String, u16, String)> { fn extract_host_port_path(url: &str) -> Result<(String, u16, String)> {
let parsed = url::Url::parse(url) let parsed =
.map_err(|e| ProxyError::Proxy(format!("invalid URL '{url}': {e}")))?; url::Url::parse(url).map_err(|e| ProxyError::Proxy(format!("invalid URL '{url}': {e}")))?;
if parsed.scheme() != "https" { if parsed.scheme() != "https" {
return Err(ProxyError::Proxy(format!( return Err(ProxyError::Proxy(format!(
"unsupported URL scheme '{}': only https is supported", "unsupported URL scheme '{}': only https is supported",
@ -92,13 +92,9 @@ async fn connect_https_transport(
let target = resolve_target_addr(host, port).await?; let target = resolve_target_addr(host, port).await?;
return timeout(HTTP_CONNECT_TIMEOUT, manager.connect(target, None, None)) return timeout(HTTP_CONNECT_TIMEOUT, manager.connect(target, None, None))
.await .await
.map_err(|_| { .map_err(|_| ProxyError::Proxy(format!("upstream connect timeout for {host}:{port}")))?
ProxyError::Proxy(format!("upstream connect timeout for {host}:{port}"))
})?
.map_err(|e| { .map_err(|e| {
ProxyError::Proxy(format!( ProxyError::Proxy(format!("upstream connect failed for {host}:{port}: {e}"))
"upstream connect failed for {host}:{port}: {e}"
))
}); });
} }

View File

@ -4,7 +4,6 @@ mod codec;
mod config_updater; mod config_updater;
mod handshake; mod handshake;
mod health; mod health;
mod http_fetch;
#[cfg(test)] #[cfg(test)]
#[path = "tests/health_adversarial_tests.rs"] #[path = "tests/health_adversarial_tests.rs"]
mod health_adversarial_tests; mod health_adversarial_tests;
@ -14,6 +13,7 @@ mod health_integration_tests;
#[cfg(test)] #[cfg(test)]
#[path = "tests/health_regression_tests.rs"] #[path = "tests/health_regression_tests.rs"]
mod health_regression_tests; mod health_regression_tests;
mod http_fetch;
mod ping; mod ping;
mod pool; mod pool;
mod pool_config; mod pool_config;
@ -59,6 +59,7 @@ pub use pool::MePool;
pub use pool_nat::{detect_public_ip, stun_probe}; pub use pool_nat::{detect_public_ip, stun_probe};
pub use registry::ConnRegistry; pub use registry::ConnRegistry;
pub use rotation::{MeReinitTrigger, me_reinit_scheduler, me_rotation_task}; pub use rotation::{MeReinitTrigger, me_reinit_scheduler, me_rotation_task};
#[allow(unused_imports)]
pub use secret::{fetch_proxy_secret, fetch_proxy_secret_with_upstream}; pub use secret::{fetch_proxy_secret, fetch_proxy_secret_with_upstream};
pub(crate) use selftest::{bnd_snapshot, timeskew_snapshot, upstream_bnd_snapshots}; pub(crate) use selftest::{bnd_snapshot, timeskew_snapshot, upstream_bnd_snapshots};
pub use wire::proto_flags_for_tag; pub use wire::proto_flags_for_tag;

View File

@ -5,8 +5,8 @@ use tracing::{debug, info, warn};
use super::http_fetch::https_get; use super::http_fetch::https_get;
use super::selftest::record_timeskew_sample; use super::selftest::record_timeskew_sample;
use crate::transport::UpstreamManager;
use crate::error::{ProxyError, Result}; use crate::error::{ProxyError, Result};
use crate::transport::UpstreamManager;
pub const PROXY_SECRET_MIN_LEN: usize = 32; pub const PROXY_SECRET_MIN_LEN: usize = 32;
@ -36,6 +36,7 @@ pub(super) fn validate_proxy_secret_len(data_len: usize, max_len: usize) -> Resu
} }
/// Fetch Telegram proxy-secret binary. /// Fetch Telegram proxy-secret binary.
#[allow(dead_code)]
pub async fn fetch_proxy_secret(cache_path: Option<&str>, max_len: usize) -> Result<Vec<u8>> { pub async fn fetch_proxy_secret(cache_path: Option<&str>, max_len: usize) -> Result<Vec<u8>> {
fetch_proxy_secret_with_upstream(cache_path, max_len, None).await fetch_proxy_secret_with_upstream(cache_path, max_len, None).await
} }
@ -88,6 +89,7 @@ pub async fn fetch_proxy_secret_with_upstream(
} }
} }
#[allow(dead_code)]
pub async fn download_proxy_secret_with_max_len(max_len: usize) -> Result<Vec<u8>> { pub async fn download_proxy_secret_with_max_len(max_len: usize) -> Result<Vec<u8>> {
download_proxy_secret_with_max_len_via_upstream(max_len, None).await download_proxy_secret_with_max_len_via_upstream(max_len, None).await
} }