update: add endless data source for debugging
parent
f53973ddad
commit
09464c548a
|
@ -1717,6 +1717,7 @@ dependencies = [
|
||||||
"hyper",
|
"hyper",
|
||||||
"itertools",
|
"itertools",
|
||||||
"ptth_core",
|
"ptth_core",
|
||||||
|
"rand 0.6.5",
|
||||||
"rmp-serde",
|
"rmp-serde",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
|
@ -18,6 +18,7 @@ handlebars = "3.5.1"
|
||||||
http = "0.2.1"
|
http = "0.2.1"
|
||||||
hyper = "0.13.8"
|
hyper = "0.13.8"
|
||||||
itertools = "0.9.0"
|
itertools = "0.9.0"
|
||||||
|
rand = "0.6.5"
|
||||||
rmp-serde = "0.14.4"
|
rmp-serde = "0.14.4"
|
||||||
serde = {version = "1.0.117", features = ["derive"]}
|
serde = {version = "1.0.117", features = ["derive"]}
|
||||||
serde_json = "1.0.60"
|
serde_json = "1.0.60"
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
|
convert::Infallible,
|
||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
|
@ -302,6 +303,24 @@ async fn handle_server_list (
|
||||||
Ok (ok_reply (s)?)
|
Ok (ok_reply (s)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn handle_endless_source (gib: usize) -> Result <Response <Body>, http::Error> {
|
||||||
|
use futures::stream::StreamExt;
|
||||||
|
|
||||||
|
let random_block = {
|
||||||
|
use rand::RngCore;
|
||||||
|
|
||||||
|
let mut rng = rand::thread_rng ();
|
||||||
|
let mut block = vec! [0u8; 64 * 1024];
|
||||||
|
rng.fill_bytes (&mut block);
|
||||||
|
block
|
||||||
|
};
|
||||||
|
|
||||||
|
Response::builder ()
|
||||||
|
.status (StatusCode::OK)
|
||||||
|
.header ("content-type", "application/octet-stream")
|
||||||
|
.body (Body::wrap_stream (futures::stream::repeat (Ok::<_, Infallible> (random_block)).take (gib * 1024 * 1024 / 64)))
|
||||||
|
}
|
||||||
|
|
||||||
#[instrument (level = "trace", skip (req, state, handlebars))]
|
#[instrument (level = "trace", skip (req, state, handlebars))]
|
||||||
async fn handle_all (
|
async fn handle_all (
|
||||||
req: Request <Body>,
|
req: Request <Body>,
|
||||||
|
@ -355,8 +374,16 @@ async fn handle_all (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if let Some (rest) = prefix_match ("/frontend/debug/", &path) {
|
else if let Some (rest) = prefix_match ("/frontend/debug/", &path) {
|
||||||
let s = handlebars.render ("debug", &())?;
|
if rest == "" {
|
||||||
Ok (ok_reply (s)?)
|
let s = handlebars.render ("debug", &())?;
|
||||||
|
Ok (ok_reply (s)?)
|
||||||
|
}
|
||||||
|
else if rest == "endless_source" {
|
||||||
|
Ok (handle_endless_source (1).await?)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Ok (error_reply (StatusCode::OK, "Can't route URL")?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if path == "/" {
|
else if path == "/" {
|
||||||
let s = handlebars.render ("root", &())?;
|
let s = handlebars.render ("root", &())?;
|
||||||
|
@ -372,7 +399,7 @@ async fn handle_all (
|
||||||
scraper_api::handle (req, state, rest).await
|
scraper_api::handle (req, state, rest).await
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Ok (error_reply (StatusCode::OK, "Hi")?)
|
Ok (error_reply (StatusCode::OK, "Can't route URL")?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,8 +412,9 @@ pub fn load_templates (asset_root: &Path)
|
||||||
let asset_root = asset_root.join ("handlebars/relay");
|
let asset_root = asset_root.join ("handlebars/relay");
|
||||||
|
|
||||||
for (k, v) in &[
|
for (k, v) in &[
|
||||||
("server_list", "server_list.hbs"),
|
("debug", "debug.hbs"),
|
||||||
("root", "root.hbs"),
|
("root", "root.hbs"),
|
||||||
|
("server_list", "server_list.hbs"),
|
||||||
] {
|
] {
|
||||||
handlebars.register_template_file (k, &asset_root.join (v))?;
|
handlebars.register_template_file (k, &asset_root.join (v))?;
|
||||||
}
|
}
|
||||||
|
@ -439,8 +467,6 @@ pub async fn run_relay (
|
||||||
}
|
}
|
||||||
|
|
||||||
let make_svc = make_service_fn (|_conn| {
|
let make_svc = make_service_fn (|_conn| {
|
||||||
use std::convert::Infallible;
|
|
||||||
|
|
||||||
let state = state.clone ();
|
let state = state.clone ();
|
||||||
let handlebars = handlebars.clone ();
|
let handlebars = handlebars.clone ();
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,19 @@ AIABAACAAQAAgAEAAIABAACAAQAAgAEAAIABAACAAQAA" rel="icon" type="image/x-icon" />
|
||||||
background-color: #ddd;
|
background-color: #ddd;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<title>ptth_relay debugging tools</title>
|
<title>Debugging tools (relay)</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>ptth_relay debugging tools</h1>
|
<h1>Debugging tools (relay)</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
|
||||||
|
Lorem ipsum dolor set amet
|
||||||
|
|
||||||
|
<p>
|
||||||
|
|
||||||
|
<a href="endless_source">1 GiB random garbage data source</a>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue