Files
oott/src/main.rs
T

61 lines
1.8 KiB
Rust
Raw Normal View History

use log::{debug, info};
use std::sync::{Arc, Mutex};
mod config;
mod db;
2026-01-13 07:57:47 -05:00
mod device_finders;
2026-01-19 12:45:52 -05:00
mod mac_vendor_finder;
2026-01-13 07:57:47 -05:00
2026-01-13 15:48:17 -05:00
#[tokio::main]
async fn main() -> Result<(), String> {
env_logger::init();
info!("Starting up oott");
2026-01-13 07:57:47 -05:00
// Get database connection - thread protected
let db_conn = Arc::new(Mutex::new(db::init_db().unwrap()));
2026-01-19 12:45:52 -05:00
// Find online devices via ARP
let devices = device_finders::arp::find("eno1").await.unwrap();
info!("Done with ARP probes");
info!("Found {} online devices", devices.iter().count());
// Process found devices
for device in devices.iter() {
debug!("Online device found {}", device);
// Using just one connection for now, need to update if moved DB portion to multi-thread
// need to change to a clone if we need multiple threads
let db_conn_clone = Arc::clone(&db_conn);
// Read device from database
let recorded_device_result =
db::devices::read(db_conn_clone.lock().unwrap(), device.mac_address.clone());
match recorded_device_result {
Some(recorded_device) => {
// If it exists update its last seen date
info!(
"Device found in database {}. Updating to {}.",
recorded_device, device
);
// TODO: If IPv4 or vendor changed do something
db::devices::update(db_conn_clone.lock().unwrap(), device.clone());
}
None => {
// If it doesn't exist insert it
info!(
"Device with MAC address {} not found in database. Inserting it.",
device.mac_address
);
db::devices::insert(db_conn_clone.lock().unwrap(), device.clone());
}
};
}
2026-01-19 12:45:52 -05:00
info!("Exiting");
Ok(())
2026-01-13 07:57:47 -05:00
}