diff --git a/crates/voelin-core/src/query.rs b/crates/voelin-core/src/query.rs index d921d32..0d0f5fe 100644 --- a/crates/voelin-core/src/query.rs +++ b/crates/voelin-core/src/query.rs @@ -37,6 +37,13 @@ pub struct QueryLogin { pub server_port: Option, /// ...or by id (the first server when neither is given). pub server_id: Option, + /// This machine's address is on the server's query allowlist, which the + /// server's flood protection skips: the engine then sends its commands + /// without the limit it keeps for a server that has not said so (a command + /// the server refuses as a flood slows the connection down all the same). + /// The application usually cannot know, and says `false`; the development + /// servers of the tests allowlist their clients. + pub allowlisted: bool, } impl fmt::Debug for QueryLogin { @@ -49,6 +56,7 @@ impl fmt::Debug for QueryLogin { .field("secret", &self.secret.as_ref().map(|_| "[secret]")) .field("server_port", &self.server_port) .field("server_id", &self.server_id) + .field("allowlisted", &self.allowlisted) .finish() } } @@ -67,7 +75,15 @@ impl QueryLogin { secret: self.secret.clone(), server_port: self.server_port, server_id: self.server_id, - line: Default::default(), + line: voelin_query::LineOptions { + // Off the client-side limit only where the server skips it. + rate_limit: if self.allowlisted { + None + } else { + voelin_query::LineOptions::default().rate_limit + }, + ..Default::default() + }, } } } @@ -169,6 +185,7 @@ mod tests { secret: Some("hunter2".into()), server_port: Some(9987), server_id: Some(3), + allowlisted: false, }; let connect = login.connect(); assert_eq!(connect.transport, voelin_query::Transport::Ssh); @@ -185,10 +202,14 @@ mod tests { assert_eq!(connect.transport, theirs); } // The line options are the query crate's defaults, as the UI always - // gave them. + // gave them, unless the server allowlists the client. let line = voelin_query::LineOptions::default(); + assert!(line.rate_limit.is_some()); assert_eq!(connect.line.rate_limit, line.rate_limit); assert_eq!(connect.line.timeout, line.timeout); + let allowlisted = QueryLogin { allowlisted: true, ..login.clone() }.connect(); + assert_eq!(allowlisted.line.rate_limit, None); + assert_eq!(allowlisted.line.timeout, line.timeout); } #[test] @@ -200,6 +221,7 @@ mod tests { secret: Some("hunter2".into()), server_port: None, server_id: None, + allowlisted: false, }; let text = format!("{login:?}"); assert!(!text.contains("hunter2") && text.contains("[secret]"), "{text}"); diff --git a/crates/voelin-core/tests/live.rs b/crates/voelin-core/tests/live.rs index 866b28e..105aa04 100644 --- a/crates/voelin-core/tests/live.rs +++ b/crates/voelin-core/tests/live.rs @@ -109,6 +109,8 @@ fn login(connect: &voelin_query::Connect) -> QueryLogin { secret: connect.secret.clone(), server_port: connect.server_port, server_id: connect.server_id, + // The development servers allowlist their clients. + allowlisted: connect.line.rate_limit.is_none(), } } diff --git a/crates/voelin-ui/src/servers.rs b/crates/voelin-ui/src/servers.rs index 8c31ddb..c4c44f8 100644 --- a/crates/voelin-ui/src/servers.rs +++ b/crates/voelin-ui/src/servers.rs @@ -313,6 +313,7 @@ impl App { secret, server_port: q.server_port, server_id: None, + allowlisted: false, }; self.engine.send(Command::ObserveQuery { session, connect: Box::new(connect) }); } else {