Compare commits

..

No commits in common. "921ea05f89b782dcb7d9ba4260d61f49de5e8184" and "05b5efc8bf21a5e8422ae29e874969afd8ad9869" have entirely different histories.

4 changed files with 22 additions and 39 deletions

View file

@ -6,12 +6,8 @@ edition = "2021"
[dependencies]
bytes = "1.1"
miette = "4.7"
thiserror = "1.0"
tracing = "0.1"
tracing-futures = "0.2"
# IMAP
imap-codec = "0.5"
@ -20,13 +16,11 @@ imap-codec = "0.5"
async-compat = "0.2"
futures = "0.3"
pin-project = "1.0"
tokio = { version = "1.18", features = ["full"] }
tokio-tower = "0.6"
tower = { version = "0.4", features = ["full"] }
[dev-dependencies]
miette = { version = "4.7", features = ["fancy"] }
eyre = "0.6"
tracing-subscriber = "0.3"
console-subscriber = "0.1"

View file

@ -10,12 +10,6 @@ This example is meant to show basic service-based IMAP server with boitalettres
$ cargo run --example simple
```
If you want to trace this `simple` example with the [`tokio-console`](https://github.com/tokio-rs/console/tree/main/tokio-console) utility, run:
```shell
$ RUSTFLAGS="tokio_unstable" cargo run --example simple --features "tokio/tracing"
```
- [Basic python testing script](../scripts/test_imap.py)
```shell

View file

@ -1,9 +1,8 @@
use miette::{IntoDiagnostic, Result};
use boitalettres::proto::{Request, Response};
use boitalettres::server::accept::addr::{AddrIncoming, AddrStream};
use boitalettres::server::Server;
async fn handle_req(req: Request) -> Result<Response> {
async fn handle_req(req: Request) -> eyre::Result<Response> {
use imap_codec::types::response::Status;
tracing::debug!("Got request: {:#?}", req);
@ -14,12 +13,10 @@ async fn handle_req(req: Request) -> Result<Response> {
}
#[tokio::main]
async fn main() -> Result<()> {
async fn main() -> eyre::Result<()> {
setup_logging();
let incoming = AddrIncoming::new("127.0.0.1:4567")
.await
.into_diagnostic()?;
let incoming = AddrIncoming::new("127.0.0.1:4567").await?;
let make_service = tower::service_fn(|addr: &AddrStream| {
tracing::debug!(remote_addr = %addr.remote_addr, local_addr = %addr.local_addr, "accept");
@ -32,28 +29,27 @@ async fn main() -> Result<()> {
});
let server = Server::new(incoming).serve(make_service);
let _ = server.await?;
server.await.map_err(Into::into)
Ok(())
}
// Don't mind this, this is just for debugging.
fn setup_logging() {
use tracing_subscriber::prelude::*;
let registry = tracing_subscriber::registry().with(
tracing_subscriber::fmt::layer().with_filter(
tracing_subscriber::filter::Targets::new()
.with_default(tracing::Level::DEBUG)
.with_target("boitalettres", tracing::Level::TRACE)
.with_target("simple", tracing::Level::TRACE)
.with_target("tower", tracing::Level::TRACE)
.with_target("tokio_tower", tracing::Level::TRACE)
.with_target("mio", tracing::Level::TRACE),
),
);
#[cfg(tokio_unstable)]
let registry = registry.with(console_subscriber::spawn());
registry.init();
tracing_subscriber::registry()
.with(console_subscriber::spawn())
.with(
tracing_subscriber::fmt::layer().with_filter(
tracing_subscriber::filter::Targets::new()
.with_default(tracing::Level::DEBUG)
.with_target("boitalettres", tracing::Level::TRACE)
.with_target("simple", tracing::Level::TRACE)
.with_target("tower", tracing::Level::TRACE)
.with_target("tokio_tower", tracing::Level::TRACE)
.with_target("mio", tracing::Level::TRACE),
),
)
.init();
}

View file

@ -15,8 +15,8 @@ mod conn;
mod pipeline;
mod service;
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
pub enum Error<A: std::error::Error + 'static> {
#[derive(Debug, thiserror::Error)]
pub enum Error<A> {
#[error("Error occured when accepting new connections")]
Accept(#[source] A),
#[error("Error occured on service creation")]
@ -50,7 +50,6 @@ impl<I, S> Future for Server<I, S>
where
I: Accept,
I::Conn: AsyncRead + AsyncWrite + Unpin + Send + 'static,
I::Error: 'static,
S: MakeServiceRef<I::Conn, Request, Response = Response>,
S::MakeError: Into<tower::BoxError> + std::fmt::Display,
S::Error: std::fmt::Display,