From bf8e483d16d97bb8280d5a7a74ee2fa3c5e9c03f Mon Sep 17 00:00:00 2001 From: _ <> Date: Sat, 12 Dec 2020 15:57:22 +0000 Subject: [PATCH] :shirt: refactor: merge the servers' config file and runtime representations --- crates/ptth_relay/src/config.rs | 21 +++------------------ crates/ptth_relay/src/server_endpoint.rs | 2 +- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/crates/ptth_relay/src/config.rs b/crates/ptth_relay/src/config.rs index fac50b2..cfcde8a 100644 --- a/crates/ptth_relay/src/config.rs +++ b/crates/ptth_relay/src/config.rs @@ -78,6 +78,7 @@ pub mod file { #[derive (Deserialize)] pub struct Server { + // This is duplicated in the hashmap, but it's not a problem pub name: String, pub tripcode: BlakeHashWrapper, pub display_name: Option , @@ -106,33 +107,17 @@ pub mod file { // Stuff we actually need at runtime -pub struct Server { - pub tripcode: blake3::Hash, - pub display_name: Option , -} - pub struct Config { - pub servers: HashMap , + pub servers: HashMap , pub iso: file::Isomorphic, } -impl TryFrom for Server { - type Error = ConfigError; - - fn try_from (f: file::Server) -> Result { - Ok (Self { - tripcode: *f.tripcode, - display_name: f.display_name, - }) - } -} - impl TryFrom for Config { type Error = ConfigError; fn try_from (f: file::Config) -> Result { let servers = f.servers.into_iter () - .map (|server| Ok::<_, ConfigError> ((server.name.clone (), server.try_into ()?))); + .map (|server| Ok::<_, ConfigError> ((server.name.clone (), server))); let servers = itertools::process_results (servers, |i| HashMap::from_iter (i))?; diff --git a/crates/ptth_relay/src/server_endpoint.rs b/crates/ptth_relay/src/server_endpoint.rs index dc4083a..c6e9795 100644 --- a/crates/ptth_relay/src/server_endpoint.rs +++ b/crates/ptth_relay/src/server_endpoint.rs @@ -62,7 +62,7 @@ pub async fn handle_listen ( error! ("Denied http_listen for non-existent server name {}", watcher_code); return trip_error (); }, - Some (x) => (*x).tripcode, + Some (x) => *(*x).tripcode, } }; let actual_tripcode = blake3::hash (api_key);