update and use ts shit idk anymore

This commit is contained in:
lda
2026-01-20 00:53:42 +07:00 Unverified
parent 059ce959f0
commit 56eab6dbb3
7 changed files with 283 additions and 268 deletions
+2 -2
View File
@@ -66,9 +66,9 @@ impl From<NeighborItem> for IpNeighLine {
dev,
mac,
state: state
.first()
.copied()
.into_iter()
.map(Into::into)
.max()
.unwrap_or(NUDState::None),
}
}
+1 -1
View File
@@ -183,7 +183,7 @@ impl IpNeighLine {
Self { state, ..self }
}
*/
pub fn with_dev(dev: impl Into<String>) -> impl FnMut(Self) -> Self {
pub fn _with_dev(dev: impl Into<String>) -> impl FnMut(Self) -> Self {
let dev = dev.into();
move |self_| Self {
dev: Some(dev.clone()),
+19 -36
View File
@@ -1,3 +1,4 @@
use lda_ipjs::subcommands::neighbor;
use macaddr::MacAddr;
use crate::arpparse::{self, IpNeighLine, NUDState};
@@ -76,7 +77,7 @@ pub async fn get_macs(
};
// Apply additional filters if any were provided
if !devs.is_empty() || !macs.is_empty() || !state.is_empty() {
if !devs.is_empty() || !macs.is_empty() {
let devset: HashSet<_> = devs.iter().map(AsRef::as_ref).collect();
let macset: HashSet<_> = macs.iter().collect();
@@ -95,12 +96,13 @@ pub async fn get_macs(
}
// /// the atomic get_macs. handle ONE thing only.
// // this one sucks shit
// pub async fn get_mac(
// ip: Option<IpAddr>,
// dev: Option<&str>,
// state: &[NUDState],
// ) -> Result<Vec<IpNeighLine>> {
// use lda_ipjs::subcommands::neighbor as ipjs_neigh;
// use lda_ipjs::subcommands::neighbor as ipjs_neigh;
// let ipjs_states: Vec<ipjs_neigh::NUDState> = state.iter().copied().map(Into::into).collect();
// let items = ipjs_neigh::json::get(ip, dev, &ipjs_states)
@@ -113,7 +115,8 @@ pub async fn get_macs(
// }
/// the atomic get_macs. handle ONE thing only.
pub async fn get_mac(
// 17 - 25 ms full
pub async fn _get_mac(
ip: Option<IpAddr>,
dev: Option<&str>,
state: &[NUDState],
@@ -143,45 +146,25 @@ pub async fn get_mac(
let lines = String::from_utf8_lossy(&out.stdout);
let parsed = lines.lines().flat_map(arpparse::parse_ip_neigh_line);
let rows: Vec<IpNeighLine> = if let Some(d) = dev {
parsed.map(IpNeighLine::with_dev(d)).collect()
parsed.map(IpNeighLine::_with_dev(d)).collect()
} else {
parsed.collect()
};
Ok(rows)
}
/*
/// get macs where you just run ip neigh then rust handles the filtering (faster than get mac)
pub async fn get_macs_rust(
machine_names: Option<&str>,
ips: Option<&[IpAddr]>,
devs: Option<&[&str]>,
states: Option<&[NUDState]>,
// 15 - 20 ms full
pub async fn get_mac(
ip: Option<IpAddr>,
dev: Option<&str>,
state: &[NUDState],
) -> Result<Vec<IpNeighLine>> {
let mut ip_map: HashSet<IpAddr> = HashSet::new();
let mut machine_map = HashSet::new();
if let Some(ips) = ips {
ip_map.extend(ips);
}
if let Some(m) = machine_names {
machine_map.extend(get_ips(m).await.into_iter().flatten());
}
let real = match (ip_map.is_empty(), machine_map.is_empty()) {
(true, true) => HashSet::new(),
(true, false) => machine_map,
(false, true) => ip_map,
(false, false) => ip_map.intersection(&machine_map).copied().collect(),
};
Ok(vec![])
}
pub async fn _get_machines(m: &[&str]) -> Vec<IpAddr> {
let futs = m.iter().map(|c| get_ips(c));
futures::future::join_all(futs)
let state2: Vec<neighbor::NUDState> = state.iter().copied().map(Into::into).collect();
Ok(neighbor::nl::get(ip, dev, &state2)
.await
.context("rtnetlink failed")?
.into_iter()
.flat_map(|f| f.into_iter().flatten())
.collect()
} */
.map(Into::into)
.collect())
// how did i just do that
}