diff --git a/crates/ptth_relay/src/config.rs b/crates/ptth_relay/src/config.rs index e7035c4..3a6ff73 100644 --- a/crates/ptth_relay/src/config.rs +++ b/crates/ptth_relay/src/config.rs @@ -15,8 +15,7 @@ use crate::{ }, }; -// Stuff we need to load from the config file and use to -// set up the HTTP server +/// Config fields as they are loaded from the config file pub mod file { use serde::Deserialize; @@ -29,26 +28,31 @@ pub mod file { #[derive (Deserialize)] pub struct Server { - // This is duplicated in the hashmap, but it's not a problem + /// This is duplicated in the hashmap, but it's not a problem pub name: String, + pub tripcode: BlakeHashWrapper, + + /// This allows a relay-side rename of servers pub display_name: Option , } + /// Empty + #[derive (Deserialize)] pub struct DevMode { } - // Stuff that's identical between the file and the runtime structures - + /// Config fields that are identical in the file and at runtime + #[derive (Default, Deserialize)] pub struct Isomorphic { #[serde (default)] pub enable_scraper_api: bool, - // If any of these fields are used, we are in dev mode and have to - // show extra warnings, since some auth may be weakened + /// If any of the `DevMode` fields are used, we are in dev mode + /// and have to show extra warnings, since auth may be weakened pub dev_mode: Option , } @@ -65,7 +69,7 @@ pub mod file { } } -// Stuff we actually need at runtime +/// Config fields as they are used at runtime pub struct Config { pub iso: file::Isomorphic, diff --git a/crates/ptth_relay/src/relay_state.rs b/crates/ptth_relay/src/relay_state.rs index 1bb1984..b1d1124 100644 --- a/crates/ptth_relay/src/relay_state.rs +++ b/crates/ptth_relay/src/relay_state.rs @@ -72,24 +72,24 @@ impl Default for ServerStatus { } pub struct Relay { - pub config: RwLock , + pub (crate) config: RwLock , // Key: Server ID - pub request_rendezvous: Mutex >, - pub server_status: Mutex >, + pub (crate) request_rendezvous: Mutex >, + pub (crate) server_status: Mutex >, // Key: Request ID - pub response_rendezvous: RwLock >, + pub (crate) response_rendezvous: RwLock >, - pub shutdown_watch_tx: watch::Sender , - pub shutdown_watch_rx: watch::Receiver , + pub (crate) shutdown_watch_tx: watch::Sender , + pub (crate) shutdown_watch_rx: watch::Receiver , // List of recently rejected server names (Used to approve servers) - pub unregistered_servers: BoundedVec , + pub (crate) unregistered_servers: BoundedVec , // Memory backend for audit logging // TODO: Add file / database / network server logging backend - pub audit_log: BoundedVec , + pub (crate) audit_log: BoundedVec , } #[derive (Clone)] @@ -177,6 +177,8 @@ impl TryFrom for Relay { } impl Relay { + /// Returns a `Vec` of the names of currently connected servers + pub async fn list_servers (&self) -> Vec { self.request_rendezvous.lock ().await.iter () .map (|(k, _)| (*k).clone ())