Compare commits
No commits in common. "b64214233236917bb1b525043fd4812793a49fd1" and "620ec2fd5b6750a44a47d78783abf7940126efbc" have entirely different histories.
b642142332
...
620ec2fd5b
|
@ -111,7 +111,7 @@ pub async fn main (_args: &[OsString]) -> anyhow::Result <()> {
|
|||
});
|
||||
|
||||
let state = Arc::new (FileServer::new (
|
||||
file_server_root.unwrap_or_else (|| PathBuf::from (".")),
|
||||
file_server_root,
|
||||
&PathBuf::new (),
|
||||
name,
|
||||
metrics_interval,
|
||||
|
|
|
@ -56,7 +56,7 @@ use errors::FileServerError;
|
|||
|
||||
#[derive (Default)]
|
||||
pub struct Config {
|
||||
pub file_server_root: PathBuf,
|
||||
pub file_server_root: Option <PathBuf>,
|
||||
}
|
||||
|
||||
pub struct FileServer {
|
||||
|
@ -69,7 +69,7 @@ pub struct FileServer {
|
|||
|
||||
impl FileServer {
|
||||
pub fn new (
|
||||
file_server_root: PathBuf,
|
||||
file_server_root: Option <PathBuf>,
|
||||
asset_root: &Path,
|
||||
name: String,
|
||||
metrics_interval: Arc <ArcSwap <Option <metrics::Interval>>>,
|
||||
|
@ -312,12 +312,12 @@ async fn stream_file (
|
|||
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 = min (bytes_left, bytes_read_64);
|
||||
|
||||
buffer.truncate (bytes_read_64 as usize);
|
||||
|
||||
if tx.send (Ok::<_, Infallible> (buffer)).await.is_err () {
|
||||
warn! ("Cancelling file stream (Sent {} out of {} bytes)", bytes_sent, content_length);
|
||||
break;
|
||||
|
@ -371,7 +371,10 @@ impl FileServer {
|
|||
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? {
|
||||
Favicon => serve_error (StatusCode::NotFound, "Not found\n"),
|
||||
|
|
|
@ -51,7 +51,6 @@ pub mod load_toml;
|
|||
pub mod prelude;
|
||||
|
||||
use std::{
|
||||
collections::*,
|
||||
future::Future,
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
|
@ -71,7 +70,6 @@ use tokio_stream::wrappers::ReceiverStream;
|
|||
use ptth_core::{
|
||||
http_serde,
|
||||
};
|
||||
// use crate::key_validity::BlakeHashWrapper;
|
||||
|
||||
use errors::ServerError;
|
||||
use prelude::*;
|
||||
|
@ -216,14 +214,10 @@ pub struct ConfigFile {
|
|||
|
||||
/// Directory that the file server module will expose to clients
|
||||
/// over the relay. If None, the current working dir is used.
|
||||
pub file_server_root: PathBuf,
|
||||
pub file_server_root: Option <PathBuf>,
|
||||
|
||||
/// For debugging.
|
||||
pub throttle_upload: bool,
|
||||
|
||||
pub client_keys: HashSet <String>,
|
||||
|
||||
pub allow_any_client: bool,
|
||||
}
|
||||
|
||||
impl ConfigFile {
|
||||
|
@ -233,10 +227,8 @@ impl ConfigFile {
|
|||
name,
|
||||
api_key,
|
||||
relay_url,
|
||||
file_server_root: PathBuf::from ("."),
|
||||
file_server_root: None,
|
||||
throttle_upload: false,
|
||||
client_keys: Default::default (),
|
||||
allow_any_client: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,10 +267,8 @@ impl Builder {
|
|||
name,
|
||||
api_key: ptth_core::gen_key (),
|
||||
relay_url,
|
||||
file_server_root: PathBuf::from ("."),
|
||||
file_server_root: None,
|
||||
throttle_upload: false,
|
||||
client_keys: Default::default (),
|
||||
allow_any_client: true,
|
||||
};
|
||||
|
||||
Self {
|
||||
|
@ -321,7 +311,7 @@ pub async fn run_server (
|
|||
|
||||
let file_server = file_server::FileServer::new (
|
||||
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 (),
|
||||
metrics_interval,
|
||||
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"))?,
|
||||
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"))?,
|
||||
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,
|
||||
allow_any_client: true,
|
||||
client_keys: Default::default (),
|
||||
};
|
||||
|
||||
if opt.print_tripcode {
|
||||
|
|
|
@ -57,10 +57,8 @@ fn main ()
|
|||
name: gui.input_name.value ().to_string (),
|
||||
api_key: gui.input_api_key.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,
|
||||
client_keys: Default::default (),
|
||||
allow_any_client: true,
|
||||
};
|
||||
|
||||
let task = rt.spawn (async {
|
||||
|
|
|
@ -4,43 +4,35 @@ TODO: "Splitting a server in half" diagram
|
|||
|
||||
# PTTH
|
||||
|
||||
PTTH is a web server.
|
||||
|
||||
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:
|
||||
PTTH lets you run file servers from behind NAT / firewalls.
|
||||
|
||||
```
|
||||
Cloud
|
||||
HTTP server ----> 1 TB of files
|
||||
^
|
||||
Not cloud |
|
||||
HTTP client
|
||||
HTTP clients ptth_server instances
|
||||
|
||||
Firefox ---> | | <--- Server 1
|
||||
Chromium --> | | <--- Server 2
|
||||
Wget ------> | ptth_relay | <--- Server 3
|
||||
Curl ------> | | <--- Server 4
|
||||
Reqwest ---> | | <--- Server 5
|
||||
```
|
||||
|
||||
But uploading 1 TB to the cloud is expensive and slow, even if
|
||||
you're sending it to S3-like blob storage.
|
||||
# Setup
|
||||
|
||||
With PTTH, the files can live outside of the cloud:
|
||||
Pick a relay computer and a server computer.
|
||||
|
||||
```
|
||||
Cloud
|
||||
+-----> ptth_relay <------+
|
||||
| |
|
||||
Not cloud | |
|
||||
HTTP client ptth_server
|
||||
1 TB of files
|
||||
```
|
||||
The relay must be able to accept incoming HTTP connections. If the relay
|
||||
will be exposed to the Internet, you should use Nginx, Caddy, or Apache as a
|
||||
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.
|
||||
|
||||
The PTTH server lives where the files live.
|
||||
The cloud host runs a relay which streams files from the end
|
||||
server as the client demands.
|
||||
The server must have read access to the files you want to serve, and it must
|
||||
be able to make outgoing HTTP(S) connections to the relay. The server
|
||||
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
|
||||
doesn't need to store any of your files.
|
||||
Begin installing PTTH. Run `cargo install ptth_relay` on the relay and
|
||||
`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
|
||||
|
|
|
@ -175,7 +175,7 @@ async fn end_to_end () {
|
|||
|
||||
//tracing_subscriber::fmt ().try_init ().ok ();
|
||||
|
||||
let relay_port = 40000;
|
||||
let relay_port = 4000;
|
||||
// No proxy
|
||||
let proxy_port = relay_port;
|
||||
let server_name = "aliens_wildland";
|
||||
|
|
Loading…
Reference in New Issue