Distributed SMTP queues (untested)
This commit is contained in:
@@ -39,6 +39,7 @@ arc-swap = "1.6.0"
|
||||
futures = "0.3"
|
||||
proxy-header = { version = "0.1.0", features = ["tokio"] }
|
||||
regex = "1.7.0"
|
||||
blake3 = "1.3.3"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
privdrop = "0.5.3"
|
||||
|
||||
@@ -21,9 +21,11 @@
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
use std::{borrow::Cow, path::PathBuf};
|
||||
use std::borrow::Cow;
|
||||
|
||||
use tokio::{fs, io::AsyncReadExt, sync::oneshot};
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
use crate::BlobHash;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum DeliveryEvent {
|
||||
@@ -38,7 +40,7 @@ pub enum DeliveryEvent {
|
||||
pub struct IngestMessage {
|
||||
pub sender_address: String,
|
||||
pub recipients: Vec<String>,
|
||||
pub message_path: PathBuf,
|
||||
pub message_blob: BlobHash,
|
||||
pub message_size: usize,
|
||||
}
|
||||
|
||||
@@ -53,29 +55,3 @@ pub enum DeliveryResult {
|
||||
reason: Cow<'static, str>,
|
||||
},
|
||||
}
|
||||
|
||||
impl IngestMessage {
|
||||
pub async fn read_message(&self) -> Result<Vec<u8>, ()> {
|
||||
let mut raw_message = vec![0u8; self.message_size];
|
||||
let mut file = fs::File::open(&self.message_path).await.map_err(|err| {
|
||||
tracing::error!(
|
||||
context = "read_message",
|
||||
event = "error",
|
||||
"Failed to open message file {}: {}",
|
||||
self.message_path.display(),
|
||||
err
|
||||
);
|
||||
})?;
|
||||
file.read_exact(&mut raw_message).await.map_err(|err| {
|
||||
tracing::error!(
|
||||
context = "read_message",
|
||||
event = "error",
|
||||
"Failed to read {} bytes file {} from disk: {}",
|
||||
self.message_size,
|
||||
self.message_path.display(),
|
||||
err
|
||||
);
|
||||
})?;
|
||||
Ok(raw_message)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,66 @@ use rustls_pki_types::TrustAnchor;
|
||||
use tracing_appender::non_blocking::WorkerGuard;
|
||||
use tracing_subscriber::{prelude::__tracing_subscriber_SubscriberExt, EnvFilter};
|
||||
|
||||
pub const BLOB_HASH_LEN: usize = 32;
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub struct BlobHash([u8; BLOB_HASH_LEN]);
|
||||
|
||||
impl BlobHash {
|
||||
pub fn new_max() -> Self {
|
||||
BlobHash([u8::MAX; BLOB_HASH_LEN])
|
||||
}
|
||||
|
||||
pub fn try_from_hash_slice(value: &[u8]) -> Result<BlobHash, std::array::TryFromSliceError> {
|
||||
value.try_into().map(BlobHash)
|
||||
}
|
||||
|
||||
pub fn as_slice(&self) -> &[u8] {
|
||||
self.0.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&[u8]> for BlobHash {
|
||||
fn from(value: &[u8]) -> Self {
|
||||
BlobHash(blake3::hash(value).into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<u8>> for BlobHash {
|
||||
fn from(value: Vec<u8>) -> Self {
|
||||
value.as_slice().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Vec<u8>> for BlobHash {
|
||||
fn from(value: &Vec<u8>) -> Self {
|
||||
value.as_slice().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<BlobHash> for BlobHash {
|
||||
fn as_ref(&self) -> &BlobHash {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BlobHash> for Vec<u8> {
|
||||
fn from(value: BlobHash) -> Self {
|
||||
value.0.to_vec()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[u8]> for BlobHash {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
self.0.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<[u8]> for BlobHash {
|
||||
fn as_mut(&mut self) -> &mut [u8] {
|
||||
self.0.as_mut()
|
||||
}
|
||||
}
|
||||
pub trait UnwrapFailure<T> {
|
||||
fn failed(self, action: &str) -> T;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user