From a729a5b626b155e3f04ca1f11c5e51e84e2b093e Mon Sep 17 00:00:00 2001 From: Malte Meiboom Date: Wed, 12 Nov 2025 12:10:03 +0100 Subject: [PATCH] Add anyhow and configurable TcpListener - add anyhow to Cargo.toml - make the connection parameter (for the TcpListener) configurable --- Cargo.lock | 1 + Cargo.toml | 1 + config/config.toml | 1 + src/config.rs | 1 + src/daemon/mod.rs | 6 ++++-- src/main.rs | 2 +- 6 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c3dfb5..45dbfa7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -164,6 +164,7 @@ checksum = "135b12329e5e3ce057a9f972339ea52bc954fe1e9358ef27f95e89716fbc5424" name = "husk" version = "0.1.0" dependencies = [ + "anyhow", "bytes", "indymilter", "log", diff --git a/Cargo.toml b/Cargo.toml index ac6265b..2ac0421 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ categories = ["cryptography", "email"] rust-version = "1.79" [dependencies] +anyhow = "1.0.100" bytes = "1.10.1" indymilter = "0.3.0" log = "0.4.27" diff --git a/config/config.toml b/config/config.toml index a42a11d..cea6249 100644 --- a/config/config.toml +++ b/config/config.toml @@ -1,5 +1,6 @@ # # Husk config file # +connection = "localhost:3000" logfile_config = "./config/log4rs.yml" diff --git a/src/config.rs b/src/config.rs index 428e704..be24d9c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,6 +7,7 @@ use serde_derive::Deserialize; #[derive(Deserialize, Debug)] pub struct HuskConfig { + pub connection: String, logfile_config: Option, } diff --git a/src/daemon/mod.rs b/src/daemon/mod.rs index a00909d..b0f48bd 100644 --- a/src/daemon/mod.rs +++ b/src/daemon/mod.rs @@ -4,6 +4,7 @@ // the actual daemon // +use anyhow; use bytes::Bytes; use std::ffi::CString; use tokio::signal; @@ -24,14 +25,15 @@ use indymilter::{ }; use crate::types::husk_context::HuskContext; +use crate::config::HuskConfig; pub struct Daemon { } impl Daemon { - pub async fn run() -> Result<(), ()> { + pub async fn run(config: &HuskConfig) -> anyhow::Result<()> { - let listener = TcpListener::bind("localhost:3000") + let listener = TcpListener::bind(&config.connection) .await .expect(" opening milter socket"); diff --git a/src/main.rs b/src/main.rs index 794da84..cf0bfc4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ async fn main() { log::info!("starting..."); - match Daemon::run().await { + match Daemon::run(&husk_config).await { Ok(_) => { println!("exiting..."); },