joecalsend/src/main.rs
2025-07-05 11:53:55 -07:00

39 lines
1.1 KiB
Rust

use joecalsend::{Client, JoecalState, error, models::device::DeviceInfo};
use local_ip_address::local_ip;
use network_interface::{Addr, NetworkInterface, NetworkInterfaceConfig, V4IfAddr};
#[tokio::main]
async fn main() -> error::Result<()> {
let device = DeviceInfo::default();
dbg!(&device);
let std::net::IpAddr::V4(ip) = local_ip()? else {
unreachable!()
};
// for enumerating subnet peers when multicast fails (https://github.com/localsend/protocol?tab=readme-ov-file#32-http-legacy-mode)
let mut network_ip = ip;
let nifs = NetworkInterface::show().unwrap();
for addr in nifs.into_iter().flat_map(|i| i.addr) {
if let Addr::V4(V4IfAddr {
ip: ifip,
netmask: Some(netmask),
..
}) = addr
&& ip == ifip
{
network_ip = ip & netmask;
break;
}
}
dbg!(network_ip);
let client = Client::with_config(device, 53317, "/home/ardent/joecalsend".into())
.await
.unwrap();
let (h1, h2, h3) = client.start().await.unwrap();
let _ = tokio::join!(h1, h2, h3);
Ok(())
}