refactor(fakedns): changed module name, refactored classes/types naming

This commit is contained in:
Namilsk 2026-10-01 21:50:35 +03:00
parent bb417b8a6d
commit 76c2dff67a
No known key found for this signature in database
GPG key ID: 2B2F0A4D870B4F9F
5 changed files with 42 additions and 11 deletions

View file

@ -1 +0,0 @@
pub mod dnsfaker;

View file

@ -0,0 +1,2 @@
mod resolver;
pub mod server;

View file

@ -1,8 +1,7 @@
use hickory_resolver::{
Resolver, TokioResolver,
TokioResolver,
config::{NameServerConfig, ResolverConfig},
net::runtime::TokioRuntimeProvider,
proto::rr::IntoName,
};
use rand::RngExt;
@ -29,12 +28,14 @@ enum Protocols {
DoTCP,
}
pub struct FakeIPServer {
pub struct FakeIPResolver {
entries: FakeIPStorage,
pub resolver: Option<TokioResolver>,
}
pub trait FakeIPOptions {
#[must_use]
fn new() -> Self;
fn add(&mut self, domain: String) -> Ipv4Addr;
async fn add_real_ip(
&mut self,
@ -55,10 +56,15 @@ fn generate_ip_from(network: Ipv4Addr, prefix: u32) -> Ipv4Addr {
Ipv4Addr::from(network | host)
}
// !TODO #[must_use]:FakeIpServer::new() builder AND FakeIPServer::start(), which unnecessary starts
// !TODO FakeIPServer::start(), which unnecessary starts
// DNS server itself
impl FakeIPOptions for FakeIPServer {
impl FakeIPOptions for FakeIPResolver {
fn new() -> Self {
Self {
entries: HashMap::new(),
resolver: None,
}
}
/// Just gets an FakeIP addr from FakeIPStorage.
/// ```rust
/// x = FakeIPServer::new(/* params */);
@ -69,8 +75,8 @@ impl FakeIPOptions for FakeIPServer {
/// }
/// ```
fn get(&self, domain: &str) -> Option<IpAddr> {
self.entries.get(domain).copied()
}
self.entries.get(domain).copied()
}
/// FakeIPServer function which init's integrated DNS resolver for
/// ```rust

View file

@ -0,0 +1,24 @@
use crate::sniffing::fakedns::resolver::FakeIPResolver;
use hickory_proto::{
op::Message,
op::MessageType,
serialize::{binary, txt},
};
use std::net::SocketAddr;
pub struct FakeIPServer {
bind: SocketAddr,
resolver: FakeIPResolver,
}
impl FakeIPServer {
#[must_use]
pub fn new(bind: SocketAddr, resolver: FakeIPResolver) -> Self {
Self { bind, resolver }
}
pub async fn serve() -> Result<(), std::io::Error> { todo!() }
async fn serve_tcp() -> Result<(), std::io::Error> { todo!() }
async fn serve_udp() -> Result<(), std::io::Error> { todo!() }
fn set_as_default_resolver() -> Result<(), std::io::Error> { todo!() }
}

View file

@ -1,4 +1,4 @@
mod dns;
mod fakedns;
pub mod headers;
mod metadata;
pub mod types;