Marking known issues and wrapping up dev for the night

main
_ 2020-11-09 00:53:07 +00:00
parent 49cd292115
commit 116b3b4900
5 changed files with 75 additions and 28 deletions

View File

@ -4,6 +4,8 @@ use std::{
}; };
use structopt::StructOpt; use structopt::StructOpt;
use tokio::runtime;
use tracing::debug;
#[derive (Debug, StructOpt)] #[derive (Debug, StructOpt)]
struct Opt { struct Opt {
@ -11,15 +13,32 @@ struct Opt {
file_server_root: Option <PathBuf>, file_server_root: Option <PathBuf>,
} }
#[tokio::main] fn main () -> Result <(), Box <dyn Error>> {
async fn main () -> Result <(), Box <dyn Error>> {
tracing_subscriber::fmt::init (); tracing_subscriber::fmt::init ();
let path = PathBuf::from ("./config/ptth_server.toml"); let path = PathBuf::from ("./config/ptth_server.toml");
let config_file = ptth::load_toml::load (&path); let config_file: ptth::server::ConfigFile = ptth::load_toml::load (&path);
ptth::server::run_server ( let mut rt = if false {
config_file, debug! ("Trying to use less RAM");
ptth::graceful_shutdown::init (),
Some (path) runtime::Builder::new ()
).await .threaded_scheduler ()
.enable_all ()
.core_threads (1)
.thread_stack_size (1024 * 1024)
.build ()?
}
else {
runtime::Runtime::new ()?
};
rt.block_on (async {
ptth::server::run_server (
config_file,
ptth::graceful_shutdown::init (),
Some (path)
).await
})?;
Ok (())
} }

View File

@ -87,7 +87,7 @@ mod tests {
fn end_to_end () { fn end_to_end () {
use maplit::*; use maplit::*;
use reqwest::Client; use reqwest::Client;
use tracing::{info}; use tracing::{debug, info};
// Prefer this form for tests, since all tests share one process // Prefer this form for tests, since all tests share one process
// and we don't care if another test already installed a subscriber. // and we don't care if another test already installed a subscriber.
@ -100,7 +100,7 @@ mod tests {
let server_name = "aliens_wildland"; let server_name = "aliens_wildland";
let api_key = "AnacondaHardcoverGrannyUnlatchLankinessMutate"; let api_key = "AnacondaHardcoverGrannyUnlatchLankinessMutate";
let tripcode = base64::encode (blake3::hash (api_key.as_bytes ()).as_bytes ()); let tripcode = base64::encode (blake3::hash (api_key.as_bytes ()).as_bytes ());
println! ("Relay is expecting tripcode {}", tripcode); debug! ("Relay is expecting tripcode {}", tripcode);
let config_file = relay::ConfigFile { let config_file = relay::ConfigFile {
port: None, port: None,
server_tripcodes: hashmap! { server_tripcodes: hashmap! {

View File

@ -116,11 +116,9 @@ impl From <&ConfigFile> for Config {
let v = blake3::Hash::from (bytes); let v = blake3::Hash::from (bytes);
let k = percent_encoding::percent_encode (k.as_bytes (), percent_encoding::NON_ALPHANUMERIC).to_string ();
debug! ("Tripcode {} => {}", k, v.to_hex ()); debug! ("Tripcode {} => {}", k, v.to_hex ());
(k, v) (k.clone (), v)
})); }));
Self { Self {

View File

@ -292,15 +292,15 @@ async fn serve_file (
None None
}; };
f.seek (SeekFrom::Start (range.start)).await.unwrap ();
info! ("Serving range {}-{}", range.start, range.end); info! ("Serving range {}-{}", range.start, range.end);
let content_length = range.end - range.start; let content_length = range.end - range.start;
let seek = SeekFrom::Start (range.start);
if should_send_body { if should_send_body {
tokio::spawn (async move { tokio::spawn (async move {
//println! ("Opening file {:?}", path); f.seek (seek).await.unwrap ();
let mut tx = tx; let mut tx = tx;
let mut bytes_sent = 0; let mut bytes_sent = 0;
@ -341,21 +341,21 @@ async fn serve_file (
response.header (String::from ("accept-ranges"), b"bytes".to_vec ()); response.header (String::from ("accept-ranges"), b"bytes".to_vec ());
if should_send_body { if range_requested {
if range_requested { response.status_code (StatusCode::PartialContent);
response.status_code (StatusCode::PartialContent); response.header (String::from ("content-range"), format! ("bytes {}-{}/{}", range.start, range.end - 1, range.end).into_bytes ());
response.header (String::from ("content-range"), format! ("bytes {}-{}/{}", range.start, range.end - 1, range.end).into_bytes ());
}
else {
response.status_code (StatusCode::Ok);
response.header (String::from ("content-length"), range.end.to_string ().into_bytes ());
}
response.content_length = Some (content_length);
} }
else { else {
response.status_code (StatusCode::Ok);
response.header (String::from ("content-length"), range.end.to_string ().into_bytes ());
}
if ! should_send_body {
response.status_code (StatusCode::NoContent); response.status_code (StatusCode::NoContent);
} }
else {
response.content_length = Some (content_length);
}
if let Some (body) = body { if let Some (body) = body {
response.body (body); response.body (body);
@ -759,6 +759,21 @@ mod tests {
).await; ).await;
assert_eq! (resp, RangeNotSatisfiable (1_048_576)); assert_eq! (resp, RangeNotSatisfiable (1_048_576));
let resp = internal_serve_all (
&file_server_root,
Method::Head,
"/files/src/bad_passwords.txt",
&headers,
None
).await;
assert_eq! (resp, ServeFile (ServeFileParams {
send_body: false,
range: 0..1_048_576,
range_requested: false,
file: AlwaysEqual::testing_blank (),
}));
} }
}); });
} }

17
todo.md
View File

@ -1,5 +1,5 @@
- Not working behind Nginx (Works okay behind Caddy) - Not working behind Nginx (Works okay behind Caddy)
- Reduce idle memory use? - Show file server names in HTML
- Impl multi-range / multi-part byte serving - Impl multi-range / multi-part byte serving
- Deny unused HTTP methods for endpoints - Deny unused HTTP methods for endpoints
@ -43,3 +43,18 @@ https://github.com/rust-lang/rust/issues/65818
I also considered compressing the passwords file, but I couldn't even get I also considered compressing the passwords file, but I couldn't even get
brotli to give it a decent ratio. brotli to give it a decent ratio.
## RAM use is kinda high
I tried to reduce the thread count in Tokio, but it's still around 12 or 13
MiB even when the server is doing nothing.
I'll leave in the minimize_ram setting for now, but it doesn't actually
reduce RAM use.
## Server names can't have spaces
I tried to figure out the percent encoding and it didn't work.
Maybe Base64 would be better or something? At least it's unambiguous and it
can go straight from UTF-8 to bytes to ASCII-armored.