Compare commits

..

No commits in common. "b64214233236917bb1b525043fd4812793a49fd1" and "620ec2fd5b6750a44a47d78783abf7940126efbc" have entirely different histories.

6 changed files with 40 additions and 59 deletions

View File

@ -111,7 +111,7 @@ pub async fn main (_args: &[OsString]) -> anyhow::Result <()> {
}); });
let state = Arc::new (FileServer::new ( let state = Arc::new (FileServer::new (
file_server_root.unwrap_or_else (|| PathBuf::from (".")), file_server_root,
&PathBuf::new (), &PathBuf::new (),
name, name,
metrics_interval, metrics_interval,

View File

@ -56,7 +56,7 @@ use errors::FileServerError;
#[derive (Default)] #[derive (Default)]
pub struct Config { pub struct Config {
pub file_server_root: PathBuf, pub file_server_root: Option <PathBuf>,
} }
pub struct FileServer { pub struct FileServer {
@ -69,7 +69,7 @@ pub struct FileServer {
impl FileServer { impl FileServer {
pub fn new ( pub fn new (
file_server_root: PathBuf, file_server_root: Option <PathBuf>,
asset_root: &Path, asset_root: &Path,
name: String, name: String,
metrics_interval: Arc <ArcSwap <Option <metrics::Interval>>>, metrics_interval: Arc <ArcSwap <Option <metrics::Interval>>>,
@ -312,12 +312,12 @@ async fn stream_file (
break; break;
} }
buffer.truncate (bytes_read);
let bytes_read_64 = u64::try_from (bytes_read).expect ("Couldn't fit usize into u64"); let bytes_read_64 = u64::try_from (bytes_read).expect ("Couldn't fit usize into u64");
let bytes_read_64 = min (bytes_left, bytes_read_64); let bytes_read_64 = min (bytes_left, bytes_read_64);
buffer.truncate (bytes_read_64 as usize);
if tx.send (Ok::<_, Infallible> (buffer)).await.is_err () { if tx.send (Ok::<_, Infallible> (buffer)).await.is_err () {
warn! ("Cancelling file stream (Sent {} out of {} bytes)", bytes_sent, content_length); warn! ("Cancelling file stream (Sent {} out of {} bytes)", bytes_sent, content_length);
break; break;
@ -371,7 +371,10 @@ impl FileServer {
resp resp
} }
let root: &std::path::Path = &self.config.file_server_root; let default_root = PathBuf::from ("./");
let root: &std::path::Path = self.config.file_server_root
.as_ref ()
.unwrap_or (&default_root);
Ok (match internal::serve_all (root, method, uri, headers, self.hidden_path.as_deref ()).await? { Ok (match internal::serve_all (root, method, uri, headers, self.hidden_path.as_deref ()).await? {
Favicon => serve_error (StatusCode::NotFound, "Not found\n"), Favicon => serve_error (StatusCode::NotFound, "Not found\n"),

View File

@ -51,7 +51,6 @@ pub mod load_toml;
pub mod prelude; pub mod prelude;
use std::{ use std::{
collections::*,
future::Future, future::Future,
path::PathBuf, path::PathBuf,
sync::Arc, sync::Arc,
@ -71,7 +70,6 @@ use tokio_stream::wrappers::ReceiverStream;
use ptth_core::{ use ptth_core::{
http_serde, http_serde,
}; };
// use crate::key_validity::BlakeHashWrapper;
use errors::ServerError; use errors::ServerError;
use prelude::*; use prelude::*;
@ -216,14 +214,10 @@ pub struct ConfigFile {
/// Directory that the file server module will expose to clients /// Directory that the file server module will expose to clients
/// over the relay. If None, the current working dir is used. /// over the relay. If None, the current working dir is used.
pub file_server_root: PathBuf, pub file_server_root: Option <PathBuf>,
/// For debugging. /// For debugging.
pub throttle_upload: bool, pub throttle_upload: bool,
pub client_keys: HashSet <String>,
pub allow_any_client: bool,
} }
impl ConfigFile { impl ConfigFile {
@ -233,10 +227,8 @@ impl ConfigFile {
name, name,
api_key, api_key,
relay_url, relay_url,
file_server_root: PathBuf::from ("."), file_server_root: None,
throttle_upload: false, throttle_upload: false,
client_keys: Default::default (),
allow_any_client: true,
} }
} }
@ -275,10 +267,8 @@ impl Builder {
name, name,
api_key: ptth_core::gen_key (), api_key: ptth_core::gen_key (),
relay_url, relay_url,
file_server_root: PathBuf::from ("."), file_server_root: None,
throttle_upload: false, throttle_upload: false,
client_keys: Default::default (),
allow_any_client: true,
}; };
Self { Self {
@ -321,7 +311,7 @@ pub async fn run_server (
let file_server = file_server::FileServer::new ( let file_server = file_server::FileServer::new (
config_file.file_server_root.clone (), config_file.file_server_root.clone (),
&asset_root.clone ().unwrap_or_else (|| PathBuf::from (".")), &asset_root.clone ().unwrap_or_else (PathBuf::new),
config_file.name.clone (), config_file.name.clone (),
metrics_interval, metrics_interval,
hidden_path.clone (), hidden_path.clone (),
@ -530,10 +520,8 @@ pub mod executable {
name: opt.name.or (config_file.name).ok_or (anyhow::anyhow! ("`name` must be provided in command line or config file"))?, name: opt.name.or (config_file.name).ok_or (anyhow::anyhow! ("`name` must be provided in command line or config file"))?,
api_key: config_file.api_key, api_key: config_file.api_key,
relay_url: opt.relay_url.or (config_file.relay_url).ok_or (anyhow::anyhow! ("`--relay-url` must be provided in command line or `relay_url` in config file"))?, relay_url: opt.relay_url.or (config_file.relay_url).ok_or (anyhow::anyhow! ("`--relay-url` must be provided in command line or `relay_url` in config file"))?,
file_server_root: opt.file_server_root.or (config_file.file_server_root).unwrap_or_else (PathBuf::new), file_server_root: opt.file_server_root.or (config_file.file_server_root),
throttle_upload: opt.throttle_upload, throttle_upload: opt.throttle_upload,
allow_any_client: true,
client_keys: Default::default (),
}; };
if opt.print_tripcode { if opt.print_tripcode {

View File

@ -57,10 +57,8 @@ fn main ()
name: gui.input_name.value ().to_string (), name: gui.input_name.value ().to_string (),
api_key: gui.input_api_key.value ().to_string (), api_key: gui.input_api_key.value ().to_string (),
relay_url: gui.input_relay_url.value ().to_string (), relay_url: gui.input_relay_url.value ().to_string (),
file_server_root: std::path::PathBuf::from (gui.input_file_server_root.value ()), file_server_root: Some (std::path::PathBuf::from (gui.input_file_server_root.value ())),
throttle_upload: false, throttle_upload: false,
client_keys: Default::default (),
allow_any_client: true,
}; };
let task = rt.spawn (async { let task = rt.spawn (async {

View File

@ -4,43 +4,35 @@ TODO: "Splitting a server in half" diagram
# PTTH # PTTH
PTTH is a web server. PTTH lets you run file servers from behind NAT / firewalls.
A web server has:
1. A public host
2. Files to serve
**With PTTH, the files can live outside of the public host.**
If you want to host 1 TB of files, normally you'd put them on the
cloud server:
``` ```
Cloud HTTP clients ptth_server instances
HTTP server ----> 1 TB of files
^ Firefox ---> | | <--- Server 1
Not cloud | Chromium --> | | <--- Server 2
HTTP client Wget ------> | ptth_relay | <--- Server 3
Curl ------> | | <--- Server 4
Reqwest ---> | | <--- Server 5
``` ```
But uploading 1 TB to the cloud is expensive and slow, even if # Setup
you're sending it to S3-like blob storage.
With PTTH, the files can live outside of the cloud: Pick a relay computer and a server computer.
``` The relay must be able to accept incoming HTTP connections. If the relay
Cloud will be exposed to the Internet, you should use Nginx, Caddy, or Apache as a
+-----> ptth_relay <------+ reverse proxy to terminate TLS in front of ptth_relay. Relays on the Internet
| | will typically have a domain name so that clients and servers can find them.
Not cloud | |
HTTP client ptth_server
1 TB of files
```
The PTTH server lives where the files live. The server must have read access to the files you want to serve, and it must
The cloud host runs a relay which streams files from the end be able to make outgoing HTTP(S) connections to the relay. The server
server as the client demands. does not need a static IP, since it won't accept any incoming HTTP connections.
For home users, this can save you money - The relay server Begin installing PTTH. Run `cargo install ptth_relay` on the relay and
doesn't need to store any of your files. `cargo install ptth_server` on the server. ptth_server is manually tested on
Windows and Linux. ptth_relay is manually tested on Linux only.
- Run ptth_relay on cloud host
- Configure ptth_server for relay, with auto keygen
- Add tripcode to relay config

View File

@ -175,7 +175,7 @@ async fn end_to_end () {
//tracing_subscriber::fmt ().try_init ().ok (); //tracing_subscriber::fmt ().try_init ().ok ();
let relay_port = 40000; let relay_port = 4000;
// No proxy // No proxy
let proxy_port = relay_port; let proxy_port = relay_port;
let server_name = "aliens_wildland"; let server_name = "aliens_wildland";