chore: clippy warning fixes and formatting

This commit is contained in:
Namilsk 2026-10-13 20:27:57 +03:00
parent d14558ce45
commit 5502f21605
No known key found for this signature in database
GPG key ID: 2B2F0A4D870B4F9F
6 changed files with 23 additions and 41 deletions

View file

@ -45,7 +45,7 @@ pub struct GeoIpService {
impl GeoIpService {
pub fn new(config: Config) -> Result<Self, Box<dyn std::error::Error>> {
let path = config.geo_files.get(0).unwrap();
let path = config.geo_files.first().unwrap();
let reader = Reader::open_readfile(path)?;
Ok(Self { reader })
}

View file

@ -2,7 +2,7 @@ use crate::geoparsers::v2ray::parsing::decode_geosite_stream;
use crate::geoparsers::v2ray::types::{GeoSite, GeoSiteList};
use std::fs;
use std::io::{BufReader, Read};
use std::io::BufReader;
pub struct GeoSiteService {
index: GeoSiteList,

View file

@ -33,17 +33,7 @@ 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

@ -173,7 +173,6 @@ impl FakeIPOptions for FakeIPResolver {
Arc::from(server.to_owned()),
Some(Arc::from("/dns-query")),
),
_ => unreachable!(),
};
let config = ResolverConfig::from_parts(None, vec![], vec![ns]);
@ -212,7 +211,7 @@ impl FakeIPOptions for FakeIPResolver {
.unwrap()
.lookup_ip(&domain)
.await
.map_err(|e| std::io::Error::other(e))?;
.map_err(std::io::Error::other)?;
let ip = lookup
.into_iter()

View file

@ -427,7 +427,10 @@ mod tests {
client.send_to(&qbytes, addr).await.unwrap();
let mut buf = [0u8; 1024];
let (amt, _) = tokio::time::timeout(tokio::time::Duration::from_secs(2), client.recv_from(&mut buf))
let (amt, _) = tokio::time::timeout(
tokio::time::Duration::from_secs(2),
client.recv_from(&mut buf),
)
.await
.expect("UDP receive timed out")
.expect("UDP receive failed");
@ -492,8 +495,7 @@ mod tests {
drop(probe);
let resolver = Arc::new(RwLock::new(FakeIPResolver::new()));
let server = FakeIPServer::with_shared_resolver(addr, resolver.clone())
.with_ttl(30);
let server = FakeIPServer::with_shared_resolver(addr, resolver.clone()).with_ttl(30);
assert_eq!(server.bind(), addr);
assert_eq!(server.ttl(), 30);
@ -514,7 +516,10 @@ mod tests {
client_udp.send_to(&qbytes, addr).await.unwrap();
let mut buf = [0u8; 1024];
let (amt, _) = tokio::time::timeout(tokio::time::Duration::from_secs(2), client_udp.recv_from(&mut buf))
let (amt, _) = tokio::time::timeout(
tokio::time::Duration::from_secs(2),
client_udp.recv_from(&mut buf),
)
.await
.expect("UDP timeout")
.expect("UDP recv error");
@ -551,5 +556,3 @@ mod tests {
server_task.abort();
}
}

View file

@ -1,6 +1,5 @@
use crate::sniffing::types::*;
use std::fmt;
use tun::Error;
// Here we will recieve bytes and try to get their destanation & apply Rules for them.
use crate::config::Config;
@ -125,12 +124,7 @@ pub fn sniff_raw_packets(packet: &Packet) -> SniffedPacket {
// Internet Header Length (IHL).
let ihl = (packet[0] & 0x0F) as usize * 4;
let dst_port = Port::from_be_bytes([packet[ihl + 2], packet[ihl + 3]]);
let dns;
if dst_port == 53 {
dns = true;
} else {
dns = false;
};
let dns = dst_port == 53;
let v4 = PacketInfo::V4 {
src_ip: <Ipv4>::try_from(&packet[12..16])?,
src_port: Port::from_be_bytes([packet[ihl], packet[ihl + 1]]),
@ -162,12 +156,8 @@ pub fn sniff_raw_packets(packet: &Packet) -> SniffedPacket {
});
let dst_port = Port::from_be_bytes([packet[42], packet[43]]);
let dns;
if dst_port == 53 {
dns = true;
} else {
dns = false;
};
let dns = dst_port == 53;
let v6 = PacketInfo::V6 {
src_ip,
src_port: Port::from_be_bytes([packet[40], packet[41]]),
@ -193,6 +183,6 @@ pub fn sniff_raw_packets(packet: &Packet) -> SniffedPacket {
}
}
pub fn apply_rules(config: Config, pinfo: PacketInfo) {
pub fn apply_rules(_config: Config, _pinfo: PacketInfo) {
todo!()
}