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

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

View file

@ -33,7 +33,17 @@ pub mod domain {
}
}
/// 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)]
pub enum Type {
/// The value is used as is.

View file

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

View file

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