diff options
author | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-03-07 12:27:25 +0000 |
---|---|---|
committer | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-03-11 16:47:56 +0000 |
commit | 773b7e8850af838fe3d4734763af7d8058f4b453 (patch) | |
tree | bfd104340f8649ac336f695892e43cdf88124e53 | |
parent | e820e9369672a227534e19ab544f0f4cde0e963d (diff) |
things
-rw-r--r-- | atuin-daemon/src/server.rs | 27 | ||||
-rw-r--r-- | atuin/src/command/client/daemon.rs | 14 |
2 files changed, 24 insertions, 17 deletions
diff --git a/atuin-daemon/src/server.rs b/atuin-daemon/src/server.rs index 99b141a9..b6be13e4 100644 --- a/atuin-daemon/src/server.rs +++ b/atuin-daemon/src/server.rs @@ -1,5 +1,9 @@ +use eyre::WrapErr; + +use atuin_client::encryption; use atuin_client::history::store::HistoryStore; use atuin_client::record::sqlite_store::SqliteStore; +use atuin_client::settings::Settings; use std::path::PathBuf; use std::sync::Arc; use time::OffsetDateTime; @@ -17,6 +21,8 @@ use crate::history::history_server::{History as HistorySvc, HistoryServer}; use crate::history::{EndHistoryReply, EndHistoryRequest, StartHistoryReply, StartHistoryRequest}; +mod sync; + #[derive(Debug)] pub struct HistoryService { // A store for WIP history @@ -149,18 +155,31 @@ async fn shutdown_signal(socket: PathBuf) { /// Listen on a unix socket /// Pass the path to the socket pub async fn listen( - store: HistoryStore, + settings: Settings, + store: SqliteStore, history_db: HistoryDatabase, - socket: PathBuf, ) -> Result<()> { - let history = HistoryService::new(store, history_db); + let encryption_key: [u8; 32] = encryption::load_key(&settings) + .context("could not load encryption key")? + .into(); + + let host_id = Settings::host_id().expect("failed to get host_id"); + let history_store = HistoryStore::new(store.clone(), host_id, encryption_key); + let history = HistoryService::new(history_store, history_db); + + let socket = settings.daemon.socket_path.clone(); let uds = UnixListener::bind(socket.clone())?; let uds_stream = UnixListenerStream::new(uds); + tracing::info!("listening on unix socket {:?}", socket); + + // start services + tokio::spawn(sync::worker(settings.clone(), store)); + Server::builder() .add_service(HistoryServer::new(history)) - .serve_with_incoming_shutdown(uds_stream, shutdown_signal(socket)) + .serve_with_incoming_shutdown(uds_stream, shutdown_signal(socket.into())) .await?; Ok(()) diff --git a/atuin/src/command/client/daemon.rs b/atuin/src/command/client/daemon.rs index 8e6c4fb6..b1aa2eb2 100644 --- a/atuin/src/command/client/daemon.rs +++ b/atuin/src/command/client/daemon.rs @@ -7,19 +7,7 @@ use atuin_client::{ use atuin_daemon::server::listen; pub async fn run(settings: Settings, store: SqliteStore, history_db: Sqlite) -> Result<()> { - let encryption_key: [u8; 32] = encryption::load_key(&settings) - .context("could not load encryption key")? - .into(); - - let host_id = Settings::host_id().expect("failed to get host_id"); - let history_store = HistoryStore::new(store.clone(), host_id, encryption_key); - - listen( - history_store, - history_db, - settings.daemon.socket_path.into(), - ) - .await?; + listen(settings, store, history_db).await?; Ok(()) } |