This commit is contained in:
lda
2026-04-14 01:31:47 +07:00 Unverified
parent 826a41ae64
commit 32e976b9d0
6 changed files with 5 additions and 94 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ pub async fn resolve_devices(input: impl Into<String>) -> Result<Vec<Device>> {
/// status and wake flows should prefer deriving from inventory rather than
/// directly from raw Linux source rows.
pub async fn inventory(query: DeviceQuery) -> Result<DeviceInventory> {
let neighbors = wakey_linux::devices::query_status(&query).await?;
let neighbors = wakey_linux::devices::query_neighbors(&query).await?;
let leases = get_leases(wakey_core::LeaseQuery {
include_state: false,
})
+1 -14
View File
@@ -1,14 +1 @@
// pub const LDA_MACS: [[u8; 6]; 2] = [
// // ether
// [0x04, 0x7c, 0x16, 0x79, 0x6d, 0xee],
// // wifi
// [0xbc, 0x09, 0x1b, 0xec, 0x65, 0xd0],
// ];
// is it time to lookup host lda.lan for this...
// pub static LDA_MACS_2: LazyLock<[MacAddr; 2]> = LazyLock::new(|| LDA_MACS.map(MacAddr::from));
/// generic so you can do "123.45.67.89:22" or "lda.lan:22" as an input
// this is so bad
pub mod ping;
pub mod query;
// Intentionally left empty.
-32
View File
@@ -1,32 +0,0 @@
// this ENTIRE file is redundant... or?
use std::{net::IpAddr, time::Duration};
use tokio::{
net::{TcpStream, ToSocketAddrs},
time::timeout,
};
use wakey_core::NeighborState;
use crate::utils::query::get_mac;
pub async fn _ping_ip<T: ToSocketAddrs>(addr: T) -> bool {
timeout(Duration::from_secs(1), TcpStream::connect(addr))
.await
.is_ok()
}
pub async fn _ping_ip_2<T: ToSocketAddrs>(_addr: T) -> bool {
todo!("use icmp")
}
pub async fn _ping_ip_3<T: Into<IpAddr>>(addr: T) -> u8 {
match get_mac(Some(addr.into()), None, &[] as &[NeighborState]).await {
Err(_) => 0,
Ok(l) => l
.into_iter()
.map(|e| e.state)
.max()
.map(NeighborState::rank)
.unwrap_or_default(),
}
}
-44
View File
@@ -1,44 +0,0 @@
pub mod dev {
pub use wakey_linux::devices::devs_sorted;
}
pub mod leases {
pub use wakey_linux::dhcp::enrich_leases_with_nud_state;
}
pub mod parser {
pub use wakey_core::QueryInput as QueryType;
pub use wakey_linux::devices::classify_query as parse_query;
}
pub use leases::*;
pub use macs::*;
pub mod macs {
use anyhow::Result;
use std::net::IpAddr;
use wakey_core::{NeighborEntry, NeighborState};
pub async fn get_ips(machine_name: &str) -> Result<impl Iterator<Item = IpAddr>> {
wakey_linux::devices::get_ips(machine_name).await
}
pub async fn get_macs(
machine_names: &[impl AsRef<str>],
ips: &[IpAddr],
devs: &[impl AsRef<str>],
state: &[NeighborState],
macs: &[macaddr::MacAddr],
) -> Result<Vec<NeighborEntry>> {
wakey_linux::devices::get_neighbors(machine_names, ips, devs, state, macs).await
}
pub async fn get_mac(
ip: Option<IpAddr>,
dev: Option<&str>,
state: &[NeighborState],
) -> Result<Vec<NeighborEntry>> {
let ips: Vec<IpAddr> = ip.into_iter().collect();
let devs: Vec<&str> = dev.into_iter().collect();
get_macs(&[] as &[&str], &ips, &devs, state, &[]).await
}
}
+1 -1
View File
@@ -3,5 +3,5 @@ mod neighbors;
mod query;
pub use interfaces::{devs_sorted, has_dev, list_devs, list_interface_summaries};
pub use neighbors::{get_ips, get_neighbors, query_status};
pub use neighbors::{get_ips, get_neighbors, query_neighbors};
pub use query::classify_query;
+2 -2
View File
@@ -106,8 +106,8 @@ pub async fn get_neighbors(
}
}
/// Convenience wrapper around [`get_neighbors`] using the legacy `DeviceQuery`.
pub async fn query_status(query: &DeviceQuery) -> Result<Vec<NeighborEntry>> {
/// Convenience wrapper around [`get_neighbors`] using a `DeviceQuery` filter.
pub async fn query_neighbors(query: &DeviceQuery) -> Result<Vec<NeighborEntry>> {
get_neighbors(
query.name.as_slice(),
&query.filter.ips,