diff --git a/Cargo.lock b/Cargo.lock index 727b9e5..30c5250 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1354,6 +1354,7 @@ name = "ptth_quic" version = "0.1.0" dependencies = [ "anyhow", + "arc-swap", "base64 0.20.0", "ctrlc", "futures-util", @@ -1364,6 +1365,8 @@ dependencies = [ "reqwest", "rmp-serde 1.1.1", "rustls", + "rusty_ulid 1.0.0", + "serde", "structopt", "tokio", "tracing", @@ -1910,18 +1913,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.150" +version = "1.0.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e326c9ec8042f1b5da33252c8a37e9ffbd2c9bef0155215b6e6c80c790e05f91" +checksum = "97fed41fc1a24994d044e6db6935e69511a1153b52c15eb42493b26fa87feba0" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.150" +version = "1.0.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42a3df25b0713732468deadad63ab9da1f1fd75a48a15024b50363f128db627e" +checksum = "255abe9a125a985c05190d687b320c12f9b1f0b99445e608c21ba0782c719ad8" dependencies = [ "proc-macro2", "quote", diff --git a/crates/ptth_quic/Cargo.toml b/crates/ptth_quic/Cargo.toml index 30f9d16..2175cc3 100644 --- a/crates/ptth_quic/Cargo.toml +++ b/crates/ptth_quic/Cargo.toml @@ -9,6 +9,7 @@ license = "AGPL-3.0" [dependencies] anyhow = "1.0.66" +arc-swap = "1.5.1" base64 = "0.20.0" ctrlc = "3.2.4" futures-util = "0.3.25" @@ -18,6 +19,8 @@ rand = "0.8.5" rcgen = "0.10.0" rmp-serde = "1.1.1" rustls = "0.20.7" +rusty_ulid = "1.0.0" +serde = "1.0.151" structopt = "0.3.26" tokio = { version = "1.23.0", features = ["full"] } tracing-subscriber = "0.3.16" diff --git a/crates/ptth_quic/src/executable_relay_server.rs b/crates/ptth_quic/src/executable_relay_server.rs index fffa727..0e2478f 100644 --- a/crates/ptth_quic/src/executable_relay_server.rs +++ b/crates/ptth_quic/src/executable_relay_server.rs @@ -164,11 +164,22 @@ async fn handle_http (_req: Request , relay_state: Arc ) #[derive (Default)] struct RelayState { + config: arc_swap::ArcSwap , p4_server_proxies: Mutex >, direc_cookies: Mutex , DirecState>>, stats: Stats, } +#[derive (Default)] +struct Config { + ip_nicknames: HashMap , +} + +#[derive (Deserialize)] +struct ConfigFile { + ip_nicknames: HashMap , +} + struct DirecState { start_time: Instant, p2_id: PeerId, @@ -287,6 +298,19 @@ async fn handle_quic_connection ( conn: quinn::Connecting, ) -> anyhow::Result <()> { + let id = Ulid::generate (); + + let remote_addr = conn.remote_address (); + let ip_nickname = match remote_addr { + SocketAddr::V4 (x) => { + let ip = x.ip ().octets (); + "Unknown" + }, + _ => "Unknown, not IPv4", + }; + + debug! ("EHG7NVUD Incoming QUIC connection {} from {:?} ({})", id, remote_addr, ip_nickname); + let conn = conn.await?; // Everyone who connects must identify themselves with the first @@ -299,14 +323,14 @@ async fn handle_quic_connection ( match peer { protocol::P3Peer::P2ClientProxy (peer) => { - trace! ("H36JTVE5 Accepting connection from P2 client"); + trace! ("H36JTVE5 Handling connection {} as P2 client", id); // TODO: Check authorization for P2 peers protocol::p3_authorize_p2_peer (&mut send).await?; handle_p2_connection (relay_state, conn, peer).await?; }, protocol::P3Peer::P4ServerProxy (peer) => { - trace! ("LRHUKB7K Accepting connection from P4 end server"); + trace! ("LRHUKB7K Handling connection {} as P4 end server", id); // TODO: Check authorization for P4 peers protocol::p3_authorize_p4_peer (&mut send).await?; diff --git a/crates/ptth_quic/src/prelude.rs b/crates/ptth_quic/src/prelude.rs index 589b65a..4be9557 100644 --- a/crates/ptth_quic/src/prelude.rs +++ b/crates/ptth_quic/src/prelude.rs @@ -45,6 +45,8 @@ pub use rand::{ Rng, RngCore, }; +pub use rusty_ulid::Ulid; +pub use serde::Deserialize; pub use tracing::{ debug, error,