use matrix_sdk::{config::SyncSettings, ruma::RoomId}; use tokio::signal; use tokio::sync::mpsc; mod bridge; mod config; mod db; mod matrix; mod meshtastic; #[tokio::main] async fn main() -> anyhow::Result<()> { env_logger::init(); let config = config::read_config().await; let pool = db::setup(config.db).await.expect("error connecting to db"); let (matrix_tx, matrix_rx) = mpsc::channel(32); let room_id = RoomId::parse(&config.matrix.room).expect("invalid room id"); log::debug!("matrix room: {:?}", room_id); let matrix_client = matrix::build(config.matrix) .await .expect("error logging into matrix"); matrix_client.sync_once(SyncSettings::default()).await?; let meshtastic_client = meshtastic::build(config.meshtastic) .await .expect("error connecting to meshtastic"); tokio::spawn(async { meshtastic_client .receive(matrix_tx) .await .expect("error receiving message from meshtastic"); }); tokio::spawn(matrix::sender(matrix_client.clone(), matrix_rx, room_id)); tokio::spawn(matrix::sync(matrix_client.clone())); match signal::ctrl_c().await { Ok(()) => {} Err(err) => { log::error!("Unable to listen for shutdown signal: {}", err); } } log::debug!("shutting down database connection"); pool.close().await; log::debug!("db connection closed"); Ok(()) }