diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-06-20 18:09:20 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-06-20 18:09:20 +0200 |
commit | ca4c2e7505f28acad688705d45cc5c5dca1799c3 (patch) | |
tree | 6820ad27dfdaa5e51e2f296832d75a4a9a6678ae /src/imap/mod.rs | |
parent | 5dd5ae8bcd6f88703bc483d7f8d5882fefad4e7e (diff) | |
download | aerogramme-ca4c2e7505f28acad688705d45cc5c5dca1799c3.tar.gz aerogramme-ca4c2e7505f28acad688705d45cc5c5dca1799c3.zip |
WIP refactor
Diffstat (limited to 'src/imap/mod.rs')
-rw-r--r-- | src/imap/mod.rs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/imap/mod.rs b/src/imap/mod.rs index 45480ce..7e042d5 100644 --- a/src/imap/mod.rs +++ b/src/imap/mod.rs @@ -2,39 +2,41 @@ mod session; mod flow; mod command; -use std::sync::Arc; use std::task::{Context, Poll}; use anyhow::Result; use boitalettres::errors::Error as BalError; use boitalettres::proto::{Request, Response}; +use boitalettres::server::accept::addr::AddrIncoming; use boitalettres::server::accept::addr::AddrStream; use boitalettres::server::Server as ImapServer; use futures::future::BoxFuture; use futures::future::FutureExt; +use tokio::sync::watch; use tower::Service; -use crate::LoginProvider; +use crate::login::ArcLoginProvider; +use crate::config::ImapConfig; /// Server is a thin wrapper to register our Services in BàL -pub struct Server(ImapServer<AddrIncoming, service::Instance>); +pub struct Server(ImapServer<AddrIncoming, Instance>); pub async fn new( config: ImapConfig, - login: Arc<dyn LoginProvider + Send + Sync>, + login: ArcLoginProvider, ) -> Result<Server> { //@FIXME add a configuration parameter let incoming = AddrIncoming::new(config.bind_addr).await?; - let imap = ImapServer::new(incoming).serve(service::Instance::new(login.clone())); + tracing::info!("IMAP activated, will listen on {:#}", imap.incoming.local_addr); - tracing::info!("IMAP activated, will listen on {:#}", self.imap.incoming.local_addr); - Server(imap) + let imap = ImapServer::new(incoming).serve(Instance::new(login.clone())); + Ok(Server(imap)) } impl Server { - pub async fn run(&self, mut must_exit: watch::Receiver<bool>) -> Result<()> { + pub async fn run(self, mut must_exit: watch::Receiver<bool>) -> Result<()> { tracing::info!("IMAP started!"); tokio::select! { - s = self => s?, + s = self.0 => s?, _ = must_exit.changed() => tracing::info!("Stopped IMAP server"), } @@ -47,10 +49,10 @@ impl Server { /// Instance is the main Tokio Tower service that we register in BàL. /// It receives new connection demands and spawn a dedicated service. struct Instance { - login_provider: Arc<dyn LoginProvider + Send + Sync>, + login_provider: ArcLoginProvider, } impl Instance { - pub fn new(login_provider: Arc<dyn LoginProvider + Send + Sync>) -> Self { + pub fn new(login_provider: ArcLoginProvider) -> Self { Self { login_provider } } } @@ -78,7 +80,7 @@ struct Connection { session: session::Manager, } impl Connection { - pub fn new(login_provider: Arc<dyn LoginProvider + Send + Sync>) -> Self { + pub fn new(login_provider: ArcLoginProvider) -> Self { Self { session: session::Manager::new(login_provider), } |