From 6db94d3e4f4d3ded05a7b3aac424b8b1bb86ed3b Mon Sep 17 00:00:00 2001
From: _ <>
Date: Sat, 20 Feb 2021 20:25:14 +0000
Subject: [PATCH] update: add endless_sink debug tool
---
crates/ptth_relay/src/lib.rs | 34 +++++++++++++++++++++++++++++++++-
handlebars/relay/debug.hbs | 3 +++
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/crates/ptth_relay/src/lib.rs b/crates/ptth_relay/src/lib.rs
index 2c7713b..378da26 100644
--- a/crates/ptth_relay/src/lib.rs
+++ b/crates/ptth_relay/src/lib.rs
@@ -303,6 +303,31 @@ async fn handle_server_list (
Ok (ok_reply (s)?)
}
+async fn handle_endless_sink (req: Request
) -> Result , http::Error>
+{
+ use tokio::stream::StreamExt;
+
+ let (_parts, mut body) = req.into_parts ();
+
+ let mut bytes_received = 0;
+
+ loop {
+ let item = body.next ().await;
+
+ if let Some (item) = item {
+ if let Ok (bytes) = &item {
+ bytes_received += bytes.len ();
+ }
+ }
+ else {
+ debug! ("Finished sinking debug bytes");
+ break;
+ }
+ }
+
+ Ok (ok_reply (format! ("Sank {} bytes\n", bytes_received))?)
+}
+
async fn handle_endless_source (gib: usize, throttle: Option )
-> Result , http::Error>
{
@@ -373,7 +398,11 @@ async fn handle_all (
let request_code = request_code.into ();
Ok (server_endpoint::handle_response (req, state, request_code).await?)
}
+ else if path == "/frontend/debug/endless_sink" {
+ Ok (handle_endless_sink (req).await?)
+ }
else {
+ error! ("Can't POST {}", path);
Ok (error_reply (StatusCode::BAD_REQUEST, "Can't POST this")?)
};
}
@@ -415,8 +444,11 @@ async fn handle_all (
else if rest == "endless_source_throttled" {
Ok (handle_endless_source (1, Some (1024 / 64)).await?)
}
+ else if rest == "endless_sink" {
+ Ok (error_reply (StatusCode::METHOD_NOT_ALLOWED, "Don't GET this URL, POST to it.")?)
+ }
else {
- Ok (error_reply (StatusCode::OK, "Can't route URL")?)
+ Ok (error_reply (StatusCode::NOT_FOUND, "Can't route URL")?)
}
}
else if path == "/" {
diff --git a/handlebars/relay/debug.hbs b/handlebars/relay/debug.hbs
index 2a79e1e..2b97b3f 100644
--- a/handlebars/relay/debug.hbs
+++ b/handlebars/relay/debug.hbs
@@ -49,5 +49,8 @@ Lorem ipsum dolor set amet
1 GiB random garbage data source (Throttled to 1 MiB/s)
+
+Data sink (POST only)
+