refactor(fakedns): FakeIPServer.get(domain) now returns Option<IpAddr>; cleaned unused deps

This commit is contained in:
Namilsk 2026-09-28 20:25:57 +03:00
parent 7954859517
commit bb417b8a6d
No known key found for this signature in database
GPG key ID: 2B2F0A4D870B4F9F
6 changed files with 52 additions and 29 deletions

View file

@ -10,27 +10,23 @@ build = "build.rs"
prost-build = "0.14.3" prost-build = "0.14.3"
[dependencies] [dependencies]
arti-client = "0.40.0"
hickory-resolver = { version = "0.26.3", features = ["dnssec-ring", "https-ring", "quic-ring", "serde", "tls-ring", "toml"] } hickory-resolver = { version = "0.26.3", features = ["dnssec-ring", "https-ring", "quic-ring", "serde", "tls-ring", "toml"] }
ipnet = "2.12.0"
iptables = "0.6.0" iptables = "0.6.0"
maxminddb = "0.27.3" maxminddb = "0.27.3"
memmap2 = "0.9.10" memmap2 = "0.9.10"
prost = "0.14.3" prost = "0.14.3"
prost-types = "0.14.3" prost-types = "0.14.3"
rand = "0.10.3" rand = "0.10.3"
regex = "1.13.1"
rtnetlink = "0.20.0" rtnetlink = "0.20.0"
serde = { version = "1.0.228", features = ["derive"] } serde = { version = "1.0.228", features = ["derive"] }
smoltcp = "0.14.0" smoltcp = "0.14.0"
tokio = { version = "1.50.0", features = ["full"] } tokio = { version = "1.50.0", features = ["full"] }
toml = { version = "1.0.6", features = ["serde"] } toml = { version = "1.0.6", features = ["serde"] }
trie = "0.3.0"
tun = { version = "0.8.6", features = ["async", "tokio"] } tun = { version = "0.8.6", features = ["async", "tokio"] }
[profile.release] [profile.release]
strip = true strip = true
lto = true lto = false
codegen-units = 1 codegen-units = 1
opt-level = 3 opt-level = 3

View file

@ -1,10 +1,25 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Default)] #[derive(Deserialize, Serialize)]
pub enum RunTypes { pub enum KillSwitchPolicy {
#[default] #[serde(alias = "allow-proxy")]
Tor, AllowProxies,
I2P, #[serde(alias = "full")]
Strict,
}
#[derive(Deserialize, Serialize)]
pub enum ClearnetPolicy {
#[serde(alias = "killswitched")]
Killwitched,
#[serde(alias = "allowed")]
Allowed,
}
#[derive(Deserialize, Serialize)]
pub struct Policy {
pub clearnet: Option<ClearnetPolicy>,
pub killswitch_mode: Option<KillSwitchPolicy>,
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
@ -13,8 +28,8 @@ pub struct Config {
pub geo_files: [String; 2], pub geo_files: [String; 2],
/// Routing settings similar to v2ray /// Routing settings similar to v2ray
pub routing: String, pub routing: String,
/// TOR/I2P Proxies /// Clearnet routing policies
pub mode: RunTypes, pub policy: Option<Policy>,
} }
// TODO: Think how to add other anonymisers // TODO: Think how to add other anonymisers
@ -26,16 +41,20 @@ pub struct Config {
// addr = "127.0.0.1:10808" // addr = "127.0.0.1:10808"
// type = "SOCKS5" # ... // type = "SOCKS5" # ...
// ``` // ```
//
impl Default for Config { impl Default for Config {
fn default() -> Self { fn default() -> Self {
Self { Self {
geo_files: [ geo_files: [
String::from("/etc/nsc/data/geolite2.mmdb"), String::from("/var/nsc/geodata/geolite2.mmdb"),
String::from("/etc/nsc/data/geosite.dat"), String::from("/var/nsc/geodata/geosite.dat"),
], ],
routing: String::from("/etc/nsc/routing.toml"), routing: String::from("/etc/nsc/routing.toml"),
mode: RunTypes::Tor, policy: Some(Policy {
clearnet: Some(ClearnetPolicy::Allowed),
killswitch_mode: Some(KillSwitchPolicy::AllowProxies),
}),
} }
} }
} }

View file

@ -4,7 +4,7 @@ use serde::Deserialize;
use std::net::IpAddr; use std::net::IpAddr;
// For now only MMDB because i cant found .proto schemes of // For now only MMDB because i cant found .proto schemes of
// V2Ray GeoSite.dat :(( // V2Ray GeoSite.dat/GeoIP.dat :((
// TODO: V2Ray protobuf parsing && Test 4 ts // TODO: V2Ray protobuf parsing && Test 4 ts
/// Interface enum for `dst_addr` info /// Interface enum for `dst_addr` info

View file

@ -33,7 +33,17 @@ pub mod domain {
} }
} }
/// Type of domain value. /// Type of domain value.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] #[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)] #[repr(i32)]
pub enum Type { pub enum Type {
/// The value is used as is. /// The value is used as is.

View file

@ -42,7 +42,7 @@ pub trait FakeIPOptions {
ip_type: IPStrategies, ip_type: IPStrategies,
) -> Result<IpAddr, std::io::Error>; ) -> Result<IpAddr, std::io::Error>;
async fn init_resolver(&mut self, link: String) -> Result<(), std::io::Error>; async fn init_resolver(&mut self, link: String) -> Result<(), std::io::Error>;
fn get(&self, domain: &str) -> Result<IpAddr, std::io::Error>; fn get(&self, domain: &str) -> Option<IpAddr>;
} }
fn generate_ip_from(network: Ipv4Addr, prefix: u32) -> Ipv4Addr { fn generate_ip_from(network: Ipv4Addr, prefix: u32) -> Ipv4Addr {
@ -62,17 +62,15 @@ impl FakeIPOptions for FakeIPServer {
/// Just gets an FakeIP addr from FakeIPStorage. /// Just gets an FakeIP addr from FakeIPStorage.
/// ```rust /// ```rust
/// x = FakeIPServer::new(/* params */); /// x = FakeIPServer::new(/* params */);
/// x.add("nosystemd.org") // returns IpAddr, but if it dropped you can call /// x.add("nosystemd.org"); // returns IpAddr, but if it dropped you can call
/// x.get("nosystemd.org").unwrap() // -> IpAddr /// let addr = x.get("nosystemd.org"); // -> Option<IpAddr>
/// if addr.is_some() {
/// println("{}", addr.unwrap()); // -> IpAddr
/// }
/// ``` /// ```
fn get(&self, domain: &str) -> Result<IpAddr, std::io::Error> { fn get(&self, domain: &str) -> Option<IpAddr> {
self.entries.get(domain).copied().ok_or_else(|| { self.entries.get(domain).copied()
std::io::Error::new( }
std::io::ErrorKind::NotFound,
format!("No FakeIP entry found for domain: {domain}"),
)
})
}
/// FakeIPServer function which init's integrated DNS resolver for /// FakeIPServer function which init's integrated DNS resolver for
/// ```rust /// ```rust

View file

@ -1,6 +1,6 @@
// Here we iniitialize systems crucial for nsc // Here we iniitialize systems crucial for nsc
use crate::sniffing::headers::Protocol;
use crate::sniffing::headers::sniff_raw_packets; use crate::sniffing::headers::sniff_raw_packets;
use crate::sniffing::types::*;
use std::io::Read; use std::io::Read;
pub fn init() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { pub fn init() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
let mut config = tun::Configuration::default(); let mut config = tun::Configuration::default();