🚧 wip: start making a place for PTTH_QUIC relay server config

main
(on company time) 2022-12-16 15:43:47 -06:00
parent 5eda2c4288
commit 86e5305630
4 changed files with 38 additions and 6 deletions

11
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -164,11 +164,22 @@ async fn handle_http (_req: Request <Body>, relay_state: Arc <RelayState>)
#[derive (Default)]
struct RelayState {
config: arc_swap::ArcSwap <Config>,
p4_server_proxies: Mutex <HashMap <PeerId, P4State>>,
direc_cookies: Mutex <HashMap <Vec <u8>, DirecState>>,
stats: Stats,
}
#[derive (Default)]
struct Config {
ip_nicknames: HashMap <String, [u8; 4]>,
}
#[derive (Deserialize)]
struct ConfigFile {
ip_nicknames: HashMap <String, String>,
}
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?;

View File

@ -45,6 +45,8 @@ pub use rand::{
Rng,
RngCore,
};
pub use rusty_ulid::Ulid;
pub use serde::Deserialize;
pub use tracing::{
debug,
error,