Merge branch 'main' of git.arirex.me:iris/ai-app
This commit is contained in:
commit
a18a57e73e
7 files changed
+323
-18
No files matched your search
@@ -26,8 +26,10 @@ mod usage;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use axum::middleware::Next;
|
||||
use clap::Parser;
|
||||
use tokio::signal::unix::{SignalKind, signal};
|
||||
|
||||
@@ -78,6 +80,19 @@ struct Args {
|
||||
/// its enrollment QR -- the whole lost-phone story.
|
||||
#[arg(long)]
|
||||
rotate_token: bool,
|
||||
|
||||
/// Hold every response back by this many milliseconds.
|
||||
///
|
||||
/// A development aid, and a specific one: over the tunnel a phone's
|
||||
/// requests take tens to hundreds of milliseconds, and several faults
|
||||
/// live entirely in what the app does *while* one is outstanding --
|
||||
/// a page of history landing mid-fling, a screen drawn before its
|
||||
/// first answer arrives. On a loopback server every response is back
|
||||
/// within a millisecond or two, so those windows close before
|
||||
/// anything can be observed and the bug looks like it is not there.
|
||||
/// This reopens them on demand rather than by unplugging something.
|
||||
#[arg(long, default_value_t = 0, value_name = "MS")]
|
||||
delay: u64,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
@@ -206,6 +221,22 @@ async fn main() -> Result<()> {
|
||||
auth::require_token,
|
||||
));
|
||||
|
||||
// Outside the auth layer, so an unauthenticated request is refused at
|
||||
// the speed it always was: this is here to slow the app down, not to
|
||||
// widen the window on anything guessing at tokens.
|
||||
let app = match args.delay {
|
||||
0 => app,
|
||||
ms => {
|
||||
tracing::warn!("delaying every response by {ms}ms -- development override");
|
||||
app.layer(axum::middleware::from_fn(
|
||||
move |request, next: Next| async move {
|
||||
tokio::time::sleep(Duration::from_millis(ms)).await;
|
||||
next.run(request).await
|
||||
},
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
let addr = SocketAddr::new(bind_ip, args.port);
|
||||
tracing::info!("serving https://{addr}");
|
||||
|
||||
|
||||
Reference in new issue
Block a user