feat: remove tokio

This commit is contained in:
Patrick 2025-01-01 20:19:37 +01:00
parent b9fef76c2c
commit f10c7a59c9
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F
4 changed files with 46 additions and 127 deletions

147
Cargo.lock generated
View file

@ -75,12 +75,6 @@ dependencies = [
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
[[package]]
name = "autocfg"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]] [[package]]
name = "backtrace" name = "backtrace"
version = "0.3.71" version = "0.3.71"
@ -102,12 +96,6 @@ version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]]
name = "bytes"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.5" version = "1.2.5"
@ -264,14 +252,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
[[package]] [[package]]
name = "lock_api" name = "log"
version = "0.4.12" version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]] [[package]]
name = "memchr" name = "memchr"
@ -288,23 +272,22 @@ dependencies = [
"adler", "adler",
] ]
[[package]]
name = "mio"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd"
dependencies = [
"libc",
"wasi",
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "no-std-net" name = "no-std-net"
version = "0.6.0" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43794a0ace135be66a25d3ae77d41b91615fb68ae937f904090203e81f755b65" checksum = "43794a0ace135be66a25d3ae77d41b91615fb68ae937f904090203e81f755b65"
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
"overload",
"winapi",
]
[[package]] [[package]]
name = "object" name = "object"
version = "0.32.2" version = "0.32.2"
@ -320,35 +303,18 @@ version = "1.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]] [[package]]
name = "owo-colors" name = "owo-colors"
version = "3.5.0" version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]]
name = "parking_lot"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-targets",
]
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.15" version = "0.2.15"
@ -464,15 +430,6 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "redox_syscall"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f"
dependencies = [
"bitflags",
]
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.11.1" version = "1.11.1"
@ -515,7 +472,7 @@ dependencies = [
"serde_regex", "serde_regex",
"simple-dns", "simple-dns",
"socket2", "socket2",
"tokio", "tracing-subscriber",
] ]
[[package]] [[package]]
@ -530,12 +487,6 @@ version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.217" version = "1.0.217"
@ -593,15 +544,6 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "signal-hook-registry"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "simple-dns" name = "simple-dns"
version = "0.9.1" version = "0.9.1"
@ -654,35 +596,6 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "tokio"
version = "1.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551"
dependencies = [
"backtrace",
"bytes",
"libc",
"mio",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.52.0",
]
[[package]]
name = "tokio-macros"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.41" version = "0.1.41"
@ -713,15 +626,29 @@ dependencies = [
"tracing-subscriber", "tracing-subscriber",
] ]
[[package]]
name = "tracing-log"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
dependencies = [
"log",
"once_cell",
"tracing-core",
]
[[package]] [[package]]
name = "tracing-subscriber" name = "tracing-subscriber"
version = "0.3.19" version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008"
dependencies = [ dependencies = [
"nu-ansi-term",
"sharded-slab", "sharded-slab",
"smallvec",
"thread_local", "thread_local",
"tracing-core", "tracing-core",
"tracing-log",
] ]
[[package]] [[package]]
@ -742,12 +669,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"

View file

@ -13,4 +13,4 @@ serde_json = "1.0.134"
serde_regex = "1.1.0" serde_regex = "1.1.0"
simple-dns = "0.9.1" simple-dns = "0.9.1"
socket2 = { version = "0.5.8", features = ["all"] } socket2 = { version = "0.5.8", features = ["all"] }
tokio = { version = "1.42.0", features = ["full"] } tracing-subscriber = "0.3.19"

View file

@ -11,8 +11,8 @@ and answers, with this you can decide what queries get relayed and which get blo
`mdns-relay -c <config>` where config is a json file containing these options: `mdns-relay -c <config>` where config is a json file containing these options:
```json ```json
{ {
"interfaces: "A regex used to filter interfaces on which to listen, to exclude for example the public net or VPNs completely", "interfaces": "A regex used to filter interfaces on which to listen, to exclude for example the public net or VPNs completely",
// A list of rules to be applied to incoming packages" // A list of rules to be applied to incoming packages
"rules" : [ "rules" : [
{ {
"from": "A regex to match the incoming interface", "from": "A regex to match the incoming interface",

View file

@ -10,11 +10,11 @@ use simple_dns::Packet;
use socket2::{Domain, Protocol, Socket, Type}; use socket2::{Domain, Protocol, Socket, Type};
use std::fs::File; use std::fs::File;
use std::io::BufReader; use std::io::BufReader;
use std::net::UdpSocket;
use std::{ use std::{
collections::HashSet, collections::HashSet,
net::{Ipv4Addr, SocketAddr, SocketAddrV4}, net::{Ipv4Addr, SocketAddr, SocketAddrV4},
}; };
use tokio::net::UdpSocket;
fn get_iface(from: &SocketAddr, ifaces: &Vec<Iface>) -> Result<String> { fn get_iface(from: &SocketAddr, ifaces: &Vec<Iface>) -> Result<String> {
for i in ifaces { for i in ifaces {
@ -69,8 +69,7 @@ struct Config {
rules: Vec<Rule>, rules: Vec<Rule>,
} }
#[tokio::main] fn main() -> Result<()> {
async fn main() -> Result<()> {
let cli = Cli::parse(); let cli = Cli::parse();
let file = File::open(cli.config)?; let file = File::open(cli.config)?;
let reader = BufReader::new(file); let reader = BufReader::new(file);
@ -109,20 +108,19 @@ async fn main() -> Result<()> {
}) })
}) })
.collect::<Result<Vec<_>>>()?; .collect::<Result<Vec<_>>>()?;
//println!("{:?}", interfaces); let mut buf = [0u8; 4096];
let mut buf = [0; 1024]; let socket: UdpSocket = socket.into();
let socket = UdpSocket::from_std(socket.into())?;
loop { loop {
match socket.recv_from(&mut buf).await { match socket.recv_from(&mut buf) {
Ok((_l, from)) => { Ok((l, from)) => {
let buf = &buf[0..l];
if interfaces if interfaces
.iter() .iter()
.any(|x| x.iface.ips.iter().any(|y| y.ip() == from.ip())) .any(|x| x.iface.ips.iter().any(|y| y.ip() == from.ip()))
{ {
continue; continue;
} }
let packet = Packet::parse(&buf)?; let packet = Packet::parse(buf)?;
//println!("{:?} {:?}\n", from, packet);
let iface = match get_iface(&from, &interfaces) { let iface = match get_iface(&from, &interfaces) {
Err(_) => { Err(_) => {
eprintln!("Invalid packet received from {}", from); eprintln!("Invalid packet received from {}", from);
@ -151,7 +149,7 @@ async fn main() -> Result<()> {
if out.contains(&i.iface.name) { if out.contains(&i.iface.name) {
println!("sending packet on {}", i.iface.name); println!("sending packet on {}", i.iface.name);
let sock_addr = SocketAddrV4::new(ADDR, 5353).into(); let sock_addr = SocketAddrV4::new(ADDR, 5353).into();
i.socket.send_to(&buf, &sock_addr)?; i.socket.send_to(buf, &sock_addr)?;
} }
} }
// socket.send_to(&buf, addr); // socket.send_to(&buf, addr);