Skip to content

Commit d170051

Browse files
committed
poll the state
this needs to be done in order to drive the cert renewal process
1 parent 9a2961f commit d170051

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

iroh-gateway/src/main.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use axum::{
1212
use bytes::Bytes;
1313
use clap::Parser;
1414
use derive_more::Deref;
15-
use futures::pin_mut;
15+
use futures::{pin_mut, StreamExt};
1616
use hyper::body::Incoming;
1717
use hyper_util::rt::{TokioExecutor, TokioIo};
1818
use iroh::bytes::{store::bao_tree::ByteNum, BlobFormat};
@@ -504,7 +504,6 @@ async fn main() -> anyhow::Result<()> {
504504
collection_cache: Mutex::new(LruCache::new(1000.try_into().unwrap())),
505505
}));
506506

507-
// Build our application by composing routes
508507
#[rustfmt::skip]
509508
let app = Router::new()
510509
.route("/blob/:blake3_hash", get(handle_local_blob_request))
@@ -525,6 +524,11 @@ async fn main() -> anyhow::Result<()> {
525524
}
526525
CertMode::Manual => {
527526
// Run with manual certificates
527+
//
528+
// Code copied from https://github.com/tokio-rs/axum/tree/main/examples/low-level-rustls/src
529+
//
530+
// TODO: use axum_server maybe, once tokio-rustls-acme is on the latest
531+
// rustls.
528532
let cert_path = args
529533
.cert_path
530534
.context("cert_path not specified")?
@@ -587,6 +591,12 @@ async fn main() -> anyhow::Result<()> {
587591
}
588592
}
589593
CertMode::LetsEncryptStaging | CertMode::LetsEncrypt => {
594+
// Run with letsencrypt certificates
595+
//
596+
// Code copied from https://github.com/tokio-rs/axum/tree/main/examples/low-level-rustls/src and adapted
597+
//
598+
// TODO: use axum_server with the axum acceptor maybe, once tokio-rustls-acme is on the latest
599+
// rustls.
590600
let is_production = args.cert_mode == CertMode::LetsEncrypt;
591601
let hostnames = args.hostname;
592602
let contact = args.contact.context("contact not specified")?;
@@ -603,6 +613,18 @@ async fn main() -> anyhow::Result<()> {
603613
// config.alpn_protocols.extend([b"h2".to_vec(), b"http/1.1".to_vec()]);
604614
let config = Arc::new(config);
605615
let acme_acceptor = state.acceptor();
616+
// drive the acme state machine
617+
//
618+
// this drives the cert renewal process.
619+
tokio::spawn(async move {
620+
let mut state = state;
621+
while let Some(event) = state.next().await {
622+
match event {
623+
Ok(ok) => tracing::debug!("acme event: {:?}", ok),
624+
Err(err) => tracing::error!("error: {:?}", err),
625+
}
626+
}
627+
});
606628
// Run our application with hyper
607629
let addr = args.addr;
608630
println!("listening on {}", addr);

0 commit comments

Comments
 (0)