From 08d2e8c4b45c2c9787aa5d46ae5c5a6208f4b74e Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Thu, 4 Nov 2021 12:29:07 -0500 Subject: [PATCH] think about extensions / auth api --- docs/daemon/api.md | 25 +++++++++++++++++++++++-- imap/src/pool/mod.rs | 27 ++++++++++++++++----------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/docs/daemon/api.md b/docs/daemon/api.md index 270184e..99b973a 100644 --- a/docs/daemon/api.md +++ b/docs/daemon/api.md @@ -1,8 +1,19 @@ # Daemon API To communicate with the daemon start by connecting to the socket it exposes. -This opens a long-lasting connection that can be used to send RPC messages. The -following messages are planned: +This opens a long-lasting connection that can be used to send RPC messages. + +## Authentication + +If connecting over a network rather than a socket, the client should +authenticate in order to talk to panorama at all. The framework for this is _TLS +client authentication_. + +### Namespace `panorama::auth` + +TODO: + +## Standard API ### Namespace `panorama::mail` @@ -33,3 +44,13 @@ TODO: send with retry? ``` Search for messages, returns a summary of messages + first sentence. + +## Extensions + +Since extensions may be separate processes, they must also communicate with the +daemon, but since the daemon is responsible for launching them, they don't have +to connect to the socket explicitly. + +### Namespace `panorama::extensions` + + diff --git a/imap/src/pool/mod.rs b/imap/src/pool/mod.rs index 4e457b0..f288cbb 100644 --- a/imap/src/pool/mod.rs +++ b/imap/src/pool/mod.rs @@ -4,13 +4,14 @@ use anyhow::Result; use crossbeam::queue::ArrayQueue; use tokio::sync::Semaphore; -use crate::{interface::ImapClient, proto::response::Envelope}; +use crate::{client::auth::{AuthMethod, Login}, interface::ImapClient, proto::response::Envelope}; use super::client::{ClientAuthenticated, Config, ConfigBuilder}; #[derive(Debug)] pub struct PoolConfig { pub max_connections: usize, + pub client_config: Config, } /// A pool of IMAP connections. @@ -33,25 +34,25 @@ impl ImapClient for ImapPool { } impl ImapPool { - pub fn new(config: Config, pool_config: PoolConfig) -> Self { + pub fn new(pool_config: PoolConfig) -> Self { debug!("Created new IMAP pool with config {:?}", pool_config); - let inner = InnerPool::init(config, pool_config); + let inner = InnerPool::init(pool_config); ImapPool(Arc::new(inner)) } } pub struct InnerPool { - config: Config, + config: PoolConfig, semaphore: Semaphore, connections: ArrayQueue, } impl InnerPool { - pub fn init(config: Config, pool_config: PoolConfig) -> Self { + pub fn init(config: PoolConfig) -> Self { InnerPool { config, - semaphore: Semaphore::new(pool_config.max_connections), - connections: ArrayQueue::new(pool_config.max_connections), + semaphore: Semaphore::new(config.max_connections), + connections: ArrayQueue::new(config.max_connections), } } @@ -66,12 +67,16 @@ impl InnerPool { // no existing connection, time to make a new one None => { let client = ConfigBuilder::default() - .hostname(self.config.hostname.clone()) - .port(self.config.port) - .tls(self.config.tls) + .hostname(self.config.client_config.hostname.clone()) + .port(self.config.client_config.port) + .tls(self.config.client_config.tls) .open() .await?; - debug!("Client connected to {}", self.config.hostname); + debug!("Client connected to {}", self.config.client_config.hostname); + + // authenticate + let client_auth = client.auth(Login { + }); } };