♻️ Extract ptth_server crate. Docker still broken
parent
4c9595ee2e
commit
bbb88c01e8
24
Cargo.toml
24
Cargo.toml
|
@ -6,40 +6,22 @@ authors = ["Trish"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "AGPL-3.0"
|
license = "AGPL-3.0"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
aho-corasick = "0.7.14"
|
[dev-dependencies]
|
||||||
|
|
||||||
base64 = "0.12.3"
|
base64 = "0.12.3"
|
||||||
blake3 = "0.3.7"
|
blake3 = "0.3.7"
|
||||||
chrono = "0.4.19"
|
|
||||||
futures = "0.3.7"
|
|
||||||
handlebars = "3.5.1"
|
|
||||||
http = "0.2.1"
|
|
||||||
hyper = "0.13.8"
|
|
||||||
itertools = "0.9.0"
|
|
||||||
lazy_static = "1.4.0"
|
|
||||||
maplit = "1.0.2"
|
maplit = "1.0.2"
|
||||||
percent-encoding = "2.1.0"
|
|
||||||
pulldown-cmark = "0.8.0"
|
|
||||||
rand = "0.7.3"
|
|
||||||
regex = "1.4.1"
|
|
||||||
reqwest = { version = "0.10.8", features = ["stream"] }
|
reqwest = { version = "0.10.8", features = ["stream"] }
|
||||||
rmp-serde = "0.14.4"
|
|
||||||
serde = {version = "1.0.117", features = ["derive"]}
|
|
||||||
structopt = "0.3.20"
|
|
||||||
tokio = { version = "0.2.22", features = ["full"] }
|
tokio = { version = "0.2.22", features = ["full"] }
|
||||||
tracing = "0.1.21"
|
tracing = "0.1.21"
|
||||||
tracing-futures = "0.2.4"
|
|
||||||
tracing-subscriber = "0.2.15"
|
tracing-subscriber = "0.2.15"
|
||||||
toml = "0.5.7"
|
|
||||||
ulid = "0.4.1"
|
|
||||||
url = "2.2.0"
|
|
||||||
|
|
||||||
always_equal = { path = "crates/always_equal" }
|
always_equal = { path = "crates/always_equal" }
|
||||||
ptth_core = { path = "crates/ptth_core" }
|
ptth_core = { path = "crates/ptth_core" }
|
||||||
ptth_relay = { path = "crates/ptth_relay" }
|
ptth_relay = { path = "crates/ptth_relay" }
|
||||||
|
ptth_server = { path = "crates/ptth_server" }
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
[package]
|
||||||
|
|
||||||
|
name = "ptth_server"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Trish"]
|
||||||
|
edition = "2018"
|
||||||
|
license = "AGPL-3.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
aho-corasick = "0.7.14"
|
||||||
|
base64 = "0.12.3"
|
||||||
|
blake3 = "0.3.7"
|
||||||
|
futures = "0.3.7"
|
||||||
|
handlebars = "3.5.1"
|
||||||
|
hyper = "0.13.8"
|
||||||
|
lazy_static = "1.4.0"
|
||||||
|
percent-encoding = "2.1.0"
|
||||||
|
pulldown-cmark = "0.8.0"
|
||||||
|
regex = "1.4.1"
|
||||||
|
reqwest = { version = "0.10.8", features = ["stream"] }
|
||||||
|
rmp-serde = "0.14.4"
|
||||||
|
serde = {version = "1.0.117", features = ["derive"]}
|
||||||
|
structopt = "0.3.20"
|
||||||
|
tokio = { version = "0.2.22", features = ["full"] }
|
||||||
|
tracing = "0.1.21"
|
||||||
|
tracing-futures = "0.2.4"
|
||||||
|
tracing-subscriber = "0.2.15"
|
||||||
|
toml = "0.5.7"
|
||||||
|
|
||||||
|
always_equal = { path = "../always_equal" }
|
||||||
|
ptth_core = { path = "../ptth_core" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
|
||||||
|
maplit = "1.0.2"
|
||||||
|
rand = "0.6.5"
|
|
@ -22,7 +22,10 @@ use ptth_core::{
|
||||||
http_serde::RequestParts,
|
http_serde::RequestParts,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use ptth::server::file_server;
|
use ptth_server::{
|
||||||
|
file_server,
|
||||||
|
load_toml,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive (Default)]
|
#[derive (Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
@ -103,7 +106,7 @@ 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: ConfigFile = ptth::server::load_toml::load (&path);
|
let config_file: ConfigFile = load_toml::load (&path);
|
||||||
info! ("file_server_root: {:?}", config_file.file_server_root);
|
info! ("file_server_root: {:?}", config_file.file_server_root);
|
||||||
|
|
||||||
let addr = SocketAddr::from(([0, 0, 0, 0], 4000));
|
let addr = SocketAddr::from(([0, 0, 0, 0], 4000));
|
|
@ -5,7 +5,12 @@ use std::{
|
||||||
|
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use tokio::runtime;
|
use tokio::runtime;
|
||||||
use tracing::debug;
|
|
||||||
|
use ptth_server::{
|
||||||
|
ConfigFile,
|
||||||
|
load_toml,
|
||||||
|
run_server,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive (Debug, StructOpt)]
|
#[derive (Debug, StructOpt)]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
|
@ -27,29 +32,17 @@ fn main () -> Result <(), Box <dyn Error>> {
|
||||||
|
|
||||||
tracing_subscriber::fmt::init ();
|
tracing_subscriber::fmt::init ();
|
||||||
let path = opt.config_path.clone ().unwrap_or_else (|| PathBuf::from ("./config/ptth_server.toml"));
|
let path = opt.config_path.clone ().unwrap_or_else (|| PathBuf::from ("./config/ptth_server.toml"));
|
||||||
let config_file: ptth::server::ConfigFile = ptth::server::load_toml::load (&path);
|
let config_file: ConfigFile = load_toml::load (&path);
|
||||||
|
|
||||||
if opt.print_tripcode {
|
if opt.print_tripcode {
|
||||||
println! (r#""{}" = "{}""#, config_file.name, config_file.tripcode ());
|
println! (r#""{}" = "{}""#, config_file.name, config_file.tripcode ());
|
||||||
return Ok (());
|
return Ok (());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut rt = if false {
|
let mut rt = runtime::Runtime::new ()?;
|
||||||
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 move {
|
rt.block_on (async move {
|
||||||
ptth::server::run_server (
|
run_server (
|
||||||
config_file,
|
config_file,
|
||||||
ptth_core::graceful_shutdown::init (),
|
ptth_core::graceful_shutdown::init (),
|
||||||
Some (path),
|
Some (path),
|
|
@ -805,43 +805,21 @@ mod tests {
|
||||||
let mut rt = Runtime::new ().unwrap ();
|
let mut rt = Runtime::new ().unwrap ();
|
||||||
|
|
||||||
rt.block_on (async {
|
rt.block_on (async {
|
||||||
let handlebars = load_templates (&PathBuf::new ()).unwrap ();
|
|
||||||
let server_info = ServerInfo {
|
|
||||||
server_name: "PTTH File Server".to_string (),
|
|
||||||
};
|
|
||||||
|
|
||||||
let file_server_root = PathBuf::from ("./");
|
let file_server_root = PathBuf::from ("./");
|
||||||
let headers = Default::default ();
|
let headers = Default::default ();
|
||||||
|
|
||||||
for (uri_path, expected_status) in vec! [
|
|
||||||
("/", StatusCode::Ok),
|
|
||||||
("/files", StatusCode::TemporaryRedirect),
|
|
||||||
("/files/src", StatusCode::TemporaryRedirect),
|
|
||||||
("/files/src/", StatusCode::Ok),
|
|
||||||
].into_iter () {
|
|
||||||
let resp = serve_all (
|
|
||||||
&handlebars,
|
|
||||||
&server_info,
|
|
||||||
&file_server_root,
|
|
||||||
Method::Get,
|
|
||||||
uri_path,
|
|
||||||
&headers,
|
|
||||||
None
|
|
||||||
).await;
|
|
||||||
|
|
||||||
assert_eq! (resp.parts.status_code, expected_status);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
use InternalResponse::*;
|
use InternalResponse::*;
|
||||||
|
|
||||||
|
let bad_passwords_path = "/files/src/bad_passwords.txt";
|
||||||
|
|
||||||
for (uri_path, expected) in vec! [
|
for (uri_path, expected) in vec! [
|
||||||
("/", Root),
|
("/", Root),
|
||||||
("/files", Redirect ("files/".to_string ())),
|
("/files", Redirect ("files/".to_string ())),
|
||||||
("/files/?", InvalidQuery),
|
("/files/?", InvalidQuery),
|
||||||
("/files/src", Redirect ("src/".to_string ())),
|
("/files/src", Redirect ("src/".to_string ())),
|
||||||
("/files/src/?", InvalidQuery),
|
("/files/src/?", InvalidQuery),
|
||||||
("/files/src/server/bad_passwords.txt", ServeFile (ServeFileParams {
|
(bad_passwords_path, ServeFile (ServeFileParams {
|
||||||
send_body: true,
|
send_body: true,
|
||||||
range: 0..1_048_576,
|
range: 0..1_048_576,
|
||||||
range_requested: false,
|
range_requested: false,
|
||||||
|
@ -869,7 +847,7 @@ mod tests {
|
||||||
let resp = internal_serve_all (
|
let resp = internal_serve_all (
|
||||||
&file_server_root,
|
&file_server_root,
|
||||||
Method::Get,
|
Method::Get,
|
||||||
"/files/src/server/bad_passwords.txt",
|
bad_passwords_path,
|
||||||
&hashmap! {
|
&hashmap! {
|
||||||
"range".into () => b"bytes=0-2000000".to_vec (),
|
"range".into () => b"bytes=0-2000000".to_vec (),
|
||||||
},
|
},
|
||||||
|
@ -881,7 +859,7 @@ mod tests {
|
||||||
let resp = internal_serve_all (
|
let resp = internal_serve_all (
|
||||||
&file_server_root,
|
&file_server_root,
|
||||||
Method::Head,
|
Method::Head,
|
||||||
"/files/src/server/bad_passwords.txt",
|
bad_passwords_path,
|
||||||
&headers,
|
&headers,
|
||||||
None
|
None
|
||||||
).await;
|
).await;
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
|
@ -1,4 +1,2 @@
|
||||||
pub mod server;
|
|
||||||
|
|
||||||
#[cfg (test)]
|
#[cfg (test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
|
@ -13,10 +13,6 @@ use tokio::{
|
||||||
time::delay_for,
|
time::delay_for,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
|
||||||
server,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn end_to_end () {
|
fn end_to_end () {
|
||||||
use maplit::*;
|
use maplit::*;
|
||||||
|
@ -57,7 +53,7 @@ fn end_to_end () {
|
||||||
|
|
||||||
let relay_url = "http://127.0.0.1:4000";
|
let relay_url = "http://127.0.0.1:4000";
|
||||||
|
|
||||||
let config_file = server::ConfigFile {
|
let config_file = ptth_server::ConfigFile {
|
||||||
name: server_name.into (),
|
name: server_name.into (),
|
||||||
api_key: api_key.into (),
|
api_key: api_key.into (),
|
||||||
relay_url: "http://127.0.0.1:4000/7ZSFUKGV".into (),
|
relay_url: "http://127.0.0.1:4000/7ZSFUKGV".into (),
|
||||||
|
@ -67,7 +63,7 @@ fn end_to_end () {
|
||||||
let (stop_server_tx, stop_server_rx) = oneshot::channel ();
|
let (stop_server_tx, stop_server_rx) = oneshot::channel ();
|
||||||
let task_server = {
|
let task_server = {
|
||||||
spawn (async move {
|
spawn (async move {
|
||||||
server::run_server (config_file, stop_server_rx, None, None).await.unwrap ();
|
ptth_server::run_server (config_file, stop_server_rx, None, None).await.unwrap ();
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue