runtime fixes and multicast ignore
This commit is contained in:
@@ -22,7 +22,6 @@ impl DnsHandler {
|
|||||||
cache_path: format!("{}/hosts_cache.txt", cache_dir),
|
cache_path: format!("{}/hosts_cache.txt", cache_dir),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn init(&mut self) -> anyhow::Result<()> {
|
pub async fn init(&mut self) -> anyhow::Result<()> {
|
||||||
let path = std::path::PathBuf::from(&self.cache_path);
|
let path = std::path::PathBuf::from(&self.cache_path);
|
||||||
|
|
||||||
@@ -41,60 +40,41 @@ impl DnsHandler {
|
|||||||
|
|
||||||
if needs_update {
|
if needs_update {
|
||||||
let p_clone = self.cache_path.clone();
|
let p_clone = self.cache_path.clone();
|
||||||
|
// Просто спавним асинхронную задачу
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
tokio::time::sleep(Duration::from_secs(10)).await;
|
tokio::time::sleep(Duration::from_secs(10)).await;
|
||||||
Self::download_blocklist(p_clone);
|
// Теперь вызываем асинхронно через .await
|
||||||
|
if let Err(e) = Self::download_blocklist_async(p_clone).await {
|
||||||
|
netrunner_logger::error!("DNS: Background update failed: {}", e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn download_blocklist(cache_path: String) {
|
// Делаем функцию асинхронной и убираем block_on
|
||||||
let runtime = crate::RUNTIME.get_or_init(|| {
|
async fn download_blocklist_async(cache_path: String) -> anyhow::Result<()> {
|
||||||
tokio::runtime::Builder::new_multi_thread()
|
|
||||||
.enable_all()
|
|
||||||
.build()
|
|
||||||
.expect("Failed to create Tokio runtime")
|
|
||||||
});
|
|
||||||
|
|
||||||
runtime.block_on(async move {
|
|
||||||
info!("DNS: Starting background download to {}", cache_path);
|
info!("DNS: Starting background download to {}", cache_path);
|
||||||
|
|
||||||
let client = reqwest::Client::builder()
|
let client = reqwest::Client::builder()
|
||||||
.timeout(Duration::from_secs(30))
|
.timeout(Duration::from_secs(30))
|
||||||
.build();
|
.build()?;
|
||||||
|
|
||||||
let client = match client {
|
let resp = client
|
||||||
Ok(c) => c,
|
|
||||||
Err(e) => {
|
|
||||||
netrunner_logger::error!("DNS: Failed to create client: {}", e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
match client
|
|
||||||
.get("https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts")
|
.get("https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts")
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await?;
|
||||||
{
|
|
||||||
Ok(resp) if resp.status().is_success() => {
|
if resp.status().is_success() {
|
||||||
if let Ok(bytes) = resp.bytes().await {
|
let bytes = resp.bytes().await?;
|
||||||
if let Err(e) = tokio::fs::write(&cache_path, bytes).await {
|
tokio::fs::write(&cache_path, bytes).await?;
|
||||||
netrunner_logger::error!("DNS: File write error: {}", e);
|
|
||||||
} else {
|
|
||||||
info!("DNS: Blocklist downloaded successfully to {}", cache_path);
|
info!("DNS: Blocklist downloaded successfully to {}", cache_path);
|
||||||
|
} else {
|
||||||
|
error!("DNS: Download failed with status {}", resp.status());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
Ok(())
|
||||||
Ok(resp) => {
|
|
||||||
netrunner_logger::error!("DNS: Download failed with status {}", resp.status())
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
netrunner_logger::error!("DNS: Request error (check internet/TLS): {}", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn load_from_file(&mut self) -> anyhow::Result<()> {
|
async fn load_from_file(&mut self) -> anyhow::Result<()> {
|
||||||
|
|||||||
@@ -120,9 +120,20 @@ impl Engine {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if n >= 20 && buf[0] >> 4 == 4 {
|
let first_byte = buf[0];
|
||||||
let dest_ip = &buf[16..20];
|
let version = first_byte >> 4;
|
||||||
if dest_ip[0] >= 224 && dest_ip[0] <= 239 {
|
|
||||||
|
if version == 4 {
|
||||||
|
// IPv4 Multicast: 224.0.0.0 - 239.255.255.255
|
||||||
|
if buf[12..16] == [0, 0, 0, 0] {
|
||||||
|
continue;
|
||||||
|
} // Маршрутизация
|
||||||
|
if buf[16] >= 224 && buf[16] <= 239 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if version == 6 {
|
||||||
|
// IPv6 Multicast: ff00::/8 (первый байт 0xff)
|
||||||
|
if first_byte == 0xff {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user