diff --git a/crates/ptth_relay/src/lib.rs b/crates/ptth_relay/src/lib.rs index 74a8641..7c265ce 100644 --- a/crates/ptth_relay/src/lib.rs +++ b/crates/ptth_relay/src/lib.rs @@ -71,7 +71,7 @@ mod server_endpoint; pub use config::Config; pub use errors::*; -pub use relay_state::RelayState; +pub use relay_state::Relay; use relay_state::{ RejectedServer, @@ -99,7 +99,7 @@ fn error_reply (status: StatusCode, b: &str) async fn handle_http_request ( req: http::request::Parts, uri: String, - state: Arc , + state: Arc , server_name: &str ) -> Result , http::Error> @@ -289,7 +289,7 @@ struct AuditLogPage { -async fn handle_server_list_internal (state: &Arc ) +async fn handle_server_list_internal (state: &Arc ) -> ServerListPage <'static> { use LastSeen::*; @@ -330,7 +330,7 @@ async fn handle_server_list_internal (state: &Arc ) } } -async fn handle_unregistered_servers_internal (state: &Arc ) +async fn handle_unregistered_servers_internal (state: &Arc ) -> UnregisteredServerListPage { use LastSeen::*; @@ -359,7 +359,7 @@ async fn handle_unregistered_servers_internal (state: &Arc ) } } -async fn handle_audit_log_internal (state: &Arc ) +async fn handle_audit_log_internal (state: &Arc ) -> AuditLogPage { let audit_log = state.audit_log.to_vec ().await @@ -371,7 +371,7 @@ async fn handle_audit_log_internal (state: &Arc ) } async fn handle_server_list ( - state: Arc , + state: Arc , handlebars: Arc > ) -> Result , RequestError> { @@ -382,7 +382,7 @@ async fn handle_server_list ( } async fn handle_unregistered_servers ( - state: Arc , + state: Arc , handlebars: Arc > ) -> Result , RequestError> { @@ -393,7 +393,7 @@ async fn handle_unregistered_servers ( } async fn handle_audit_log ( - state: Arc , + state: Arc , handlebars: Arc > ) -> Result , RequestError> { @@ -473,7 +473,7 @@ async fn handle_endless_source (gib: usize, throttle: Option ) .body (Body::wrap_stream (ReceiverStream::new (rx))) } -async fn handle_gen_scraper_key (_state: Arc ) +async fn handle_gen_scraper_key (_state: Arc ) -> Result , http::Error> { let key = ptth_core::gen_key (); @@ -489,7 +489,7 @@ async fn handle_gen_scraper_key (_state: Arc ) #[instrument (level = "trace", skip (req, state, handlebars))] async fn handle_all ( req: Request , - state: Arc , + state: Arc , handlebars: Arc > ) -> Result , RequestError> @@ -580,7 +580,7 @@ fn load_templates (asset_root: &Path) } async fn reload_config ( - state: &Arc , + state: &Arc , config_reload_path: &Path ) -> Result <(), ConfigError> { let new_config = Config::from_file (config_reload_path).await?; @@ -604,7 +604,7 @@ async fn reload_config ( } pub async fn run_relay ( - state: Arc , + state: Arc , asset_root: &Path, shutdown_oneshot: oneshot::Receiver <()>, config_reload_path: Option diff --git a/crates/ptth_relay/src/main.rs b/crates/ptth_relay/src/main.rs index 8b2d617..7dc7f4a 100644 --- a/crates/ptth_relay/src/main.rs +++ b/crates/ptth_relay/src/main.rs @@ -16,7 +16,7 @@ use tracing_subscriber::{ use ptth_relay::{ Config, - RelayState, + Relay, run_relay, }; @@ -54,7 +54,7 @@ async fn main () -> Result <(), Box > { forced_shutdown.wrap_server ( run_relay ( - Arc::new (RelayState::try_from (config)?), + Arc::new (Relay::try_from (config)?), &PathBuf::new (), shutdown_rx, Some (config_path) diff --git a/crates/ptth_relay/src/relay_state.rs b/crates/ptth_relay/src/relay_state.rs index d730795..1bb1984 100644 --- a/crates/ptth_relay/src/relay_state.rs +++ b/crates/ptth_relay/src/relay_state.rs @@ -71,7 +71,7 @@ impl Default for ServerStatus { } } -pub struct RelayState { +pub struct Relay { pub config: RwLock , // Key: Server ID @@ -157,7 +157,7 @@ impl BoundedVec { } } -impl TryFrom for RelayState { +impl TryFrom for Relay { type Error = RelayError; fn try_from (config: Config) -> Result { @@ -176,7 +176,7 @@ impl TryFrom for RelayState { } } -impl RelayState { +impl Relay { pub async fn list_servers (&self) -> Vec { self.request_rendezvous.lock ().await.iter () .map (|(k, _)| (*k).clone ()) diff --git a/crates/ptth_relay/src/scraper_api.rs b/crates/ptth_relay/src/scraper_api.rs index 22693aa..ffc94b9 100644 --- a/crates/ptth_relay/src/scraper_api.rs +++ b/crates/ptth_relay/src/scraper_api.rs @@ -26,7 +26,7 @@ use crate::{ BlakeHashWrapper, KeyValidity, }, - relay_state::RelayState, + relay_state::Relay, }; // Not sure if this is the best way to do a hard-coded string table, but @@ -65,7 +65,7 @@ pub struct ServerList { pub servers: Vec , } -pub async fn v1_server_list (state: &Arc ) +pub async fn v1_server_list (state: &Arc ) -> ServerList { // name --> display_name @@ -112,7 +112,7 @@ pub async fn v1_server_list (state: &Arc ) #[instrument (level = "trace", skip (req, state))] async fn api_v1 ( req: Request , - state: Arc , + state: Arc , path_rest: &str ) -> Result , RequestError> @@ -184,7 +184,7 @@ async fn api_v1 ( #[instrument (level = "trace", skip (req, state))] pub async fn handle ( req: Request , - state: Arc , + state: Arc , path_rest: &str ) -> Result , RequestError> @@ -299,7 +299,7 @@ mod tests { let config = config::Config::try_from (config_file).expect ("Can't load config"); - let relay_state = Arc::new (RelayState::try_from (config).expect ("Can't create relay state")); + let relay_state = Arc::new (Relay::try_from (config).expect ("Can't create relay state")); let actual = super::handle (input, relay_state, self.path_rest).await; let actual = actual.expect ("Relay didn't respond"); diff --git a/crates/ptth_relay/src/server_endpoint.rs b/crates/ptth_relay/src/server_endpoint.rs index 868c2cc..995bb70 100644 --- a/crates/ptth_relay/src/server_endpoint.rs +++ b/crates/ptth_relay/src/server_endpoint.rs @@ -36,7 +36,7 @@ use super::{ }, HandleHttpResponseError, ok_reply, - RelayState, + Relay, }; // Servers will come here and either handle queued requests from parked clients, @@ -44,7 +44,7 @@ use super::{ // Step 1 pub async fn handle_listen ( - state: Arc , + state: Arc , watcher_code: String, api_key: &[u8], ) @@ -140,7 +140,7 @@ pub async fn handle_listen ( pub async fn handle_response ( req: Request , - state: Arc , + state: Arc , req_id: String, ) -> Result , HandleHttpResponseError> diff --git a/src/main.rs b/src/main.rs index b7bd88a..0067e7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,7 +46,7 @@ async fn main () -> anyhow::Result <()> { let config = ptth_relay::config::Config::try_from (config_file).expect ("Can't load config"); - let relay_state = Arc::new (ptth_relay::RelayState::try_from (config).expect ("Can't create relay state")); + let relay_state = Arc::new (ptth_relay::Relay::try_from (config).expect ("Can't create relay state")); let (stop_relay_tx, stop_relay_rx) = oneshot::channel (); let task_relay = spawn ({ @@ -54,7 +54,7 @@ async fn main () -> anyhow::Result <()> { async move { ptth_relay::run_relay ( relay_state, - Arc::new (ptth_relay::load_templates (&PathBuf::new ())?), + &PathBuf::new (), stop_relay_rx, None ).await diff --git a/src/tests.rs b/src/tests.rs index 657702a..e655891 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -20,7 +20,7 @@ use tracing::{debug, info}; // If this takes more than 5 seconds-ish, it's bad, the test should // fail -async fn wait_for_any_server (relay_state: &ptth_relay::RelayState) { +async fn wait_for_any_server (relay_state: &ptth_relay::Relay) { for _ in 0..50 { tokio::time::sleep (Duration::from_millis (100)).await; if ! relay_state.list_servers ().await.is_empty () { @@ -83,7 +83,7 @@ impl TestingConfig { } struct TestingRelay { - state: Arc , + state: Arc , task: tokio::task::JoinHandle >, stop_tx: oneshot::Sender <()>, } @@ -114,7 +114,7 @@ impl TestingRelay { let cfg = config::Config::try_from (config_file).expect ("Can't load config"); - let state = Arc::new (RelayState::try_from (cfg).expect ("Can't create relay state")); + let state = Arc::new (Relay::try_from (cfg).expect ("Can't create relay state")); let (stop_tx, stop_rx) = oneshot::channel (); let task = spawn ({ @@ -122,7 +122,7 @@ impl TestingRelay { async move { run_relay ( state, - Arc::new (load_templates (&PathBuf::new ())?), + &PathBuf::new (), stop_rx, None ).await @@ -286,13 +286,13 @@ async fn scraper_endpoints () { let config = config::Config::try_from (config_file).expect ("Can't load config"); - let relay_state = Arc::new (RelayState::try_from (config).expect ("Can't create relay state")); + let relay_state = Arc::new (Relay::try_from (config).expect ("Can't create relay state")); let relay_state_2 = relay_state.clone (); let (stop_relay_tx, stop_relay_rx) = oneshot::channel (); let task_relay = spawn (async move { run_relay ( relay_state_2, - Arc::new (load_templates (&PathBuf::new ())?), + &PathBuf::new (), stop_relay_rx, None ).await