Skip to main content

Mountain/Binary/Build/DnsCommands/
dns_resolve.rs

1#![allow(non_snake_case)]
2
3//! `dns_resolve` Tauri command - manual resolution helper used
4//! by the diagnostic panel and by `dns_test_resolution`.
5//!
6//! `editor.land` zone names resolve to 127.0.0.1; allowlisted
7//! external domains return a TEST-NET-1 placeholder; everything
8//! else fails with `error="Domain not in forward allowlist"`.
9
10use tauri::State;
11
12use crate::Binary::Build::{DnsCommands::DnsResolutionResult::DnsResolutionResult, Scheme::DnsPort};
13
14#[tauri::command]
15pub fn dns_resolve(domain:String, dns_port:State<DnsPort>) -> Result<DnsResolutionResult, String> {
16	if dns_port.0 == 0 {
17		return Err("DNS server is not running".to_string());
18	}
19
20	if domain.ends_with("editor.land") || domain.ends_with("editor.land.") {
21		return Ok(DnsResolutionResult {
22			domain:domain.clone(),
23			record_type:"A".to_string(),
24			addresses:vec!["127.0.0.1".to_string()],
25			ttl:3600,
26			succeeded:true,
27			error:None,
28		});
29	}
30
31	let allowlist = vec!["update.editor.land."];
32
33	let is_allowed = allowlist.iter().any(|d| {
34		let test_domain = if domain.ends_with('.') { domain.clone() } else { format!("{}.", domain) };
35		test_domain == *d || test_domain.ends_with(d)
36	});
37
38	if !is_allowed {
39		return Ok(DnsResolutionResult {
40			domain:domain.clone(),
41			record_type:"A".to_string(),
42			addresses:vec![],
43			ttl:0,
44			succeeded:false,
45			error:Some("Domain not in forward allowlist".to_string()),
46		});
47	}
48
49	Ok(DnsResolutionResult {
50		domain:domain.clone(),
51		record_type:"A".to_string(),
52		addresses:vec!["192.0.2.1".to_string()],
53		ttl:300,
54		succeeded:true,
55		error:None,
56	})
57}