Marking known issues and wrapping up dev for the night

main
_ 2 years ago
parent 49cd292115
commit 116b3b4900

@ -4,6 +4,8 @@ use std::{
};
use structopt::StructOpt;
use tokio::runtime;
use tracing::debug;
#[derive (Debug, StructOpt)]
struct Opt {
@ -11,15 +13,32 @@ struct Opt {
file_server_root: Option <PathBuf>,
}
#[tokio::main]
async fn main () -> Result <(), Box <dyn Error>> {
fn main () -> Result <(), Box <dyn Error>> {
tracing_subscriber::fmt::init ();
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 (
config_file,
ptth::graceful_shutdown::init (),
Some (path)
).await
let mut rt = if false {
debug! ("Trying to use less RAM");
runtime::Builder::new ()
.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 (())
}

@ -87,7 +87,7 @@ mod tests {
fn end_to_end () {
use maplit::*;
use reqwest::Client;
use tracing::{info};
use tracing::{debug, info};
// Prefer this form for tests, since all tests share one process
// and we don't care if another test already installed a subscriber.
@ -100,7 +100,7 @@ mod tests {
let server_name = "aliens_wildland";
let api_key = "AnacondaHardcoverGrannyUnlatchLankinessMutate";
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 {
port: None,
server_tripcodes: hashmap! {

@ -116,11 +116,9 @@ impl From <&ConfigFile> for Config {
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 ());
(k, v)
(k.clone (), v)
}));
Self {

@ -292,15 +292,15 @@ async fn serve_file (
None
};
f.seek (SeekFrom::Start (range.start)).await.unwrap ();
info! ("Serving range {}-{}", range.start, range.end);
let content_length = range.end - range.start;
let seek = SeekFrom::Start (range.start);
if should_send_body {
tokio::spawn (async move {
//println! ("Opening file {:?}", path);
f.seek (seek).await.unwrap ();
let mut tx = tx;
let mut bytes_sent = 0;
@ -341,21 +341,21 @@ async fn serve_file (
response.header (String::from ("accept-ranges"), b"bytes".to_vec ());
if should_send_body {
if range_requested {
response.status_code (StatusCode::PartialContent);
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);
if range_requested {
response.status_code (StatusCode::PartialContent);
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 ());
}
if ! should_send_body {
response.status_code (StatusCode::NoContent);
}
else {
response.content_length = Some (content_length);
}
if let Some (body) = body {
response.body (body);
@ -759,6 +759,21 @@ mod tests {
).await;
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 (),
}));
}
});
}

@ -1,5 +1,5 @@
- 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
- 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
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.

Loading…
Cancel
Save