think about extensions / auth api
This commit is contained in:
parent
ac592a9370
commit
08d2e8c4b4
2 changed files with 39 additions and 13 deletions
|
@ -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`
|
||||
|
||||
|
||||
|
|
|
@ -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<ClientAuthenticated>,
|
||||
}
|
||||
|
||||
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 {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue