[repo] Lab relay: compile fixes after the first build (clippy, fmt); 28 unit tests pass

This commit is contained in:
2026-11-25 13:08:46 +01:00
parent ab5404b0cf
commit fd1c141ca8
6 changed files with 48 additions and 26 deletions
+14 -5
View File
@@ -118,7 +118,9 @@ pub enum ConfigError {
impl std::fmt::Display for ConfigError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NotLoopback(ip) => write!(f, "{ip} is not a loopback address; the relay binds and connects only on loopback"),
Self::NotLoopback(ip) => {
write!(f, "{ip} is not a loopback address; the relay binds and connects only on loopback")
}
Self::SelfLoop => f.write_str("listen and upstream are the same address and ports"),
Self::BadRewrite(s) => write!(f, "rewrite {s:?}: both sides must be non-empty and the same length"),
Self::PortOverflow(p) => write!(f, "port {p} plus the offset is over 65535"),
@@ -173,8 +175,10 @@ impl Config {
GAMESTREAM_PORTS
.iter()
.map(|&(port, transport, protocol)| {
let upstream_port = port.checked_add(self.upstream_port_offset).ok_or(ConfigError::PortOverflow(port))?;
let transport = if transport == Transport::Tls && self.tls.is_none() { Transport::Tcp } else { transport };
let upstream_port =
port.checked_add(self.upstream_port_offset).ok_or(ConfigError::PortOverflow(port))?;
let transport =
if transport == Transport::Tls && self.tls.is_none() { Transport::Tcp } else { transport };
let protocol = if transport == Transport::Tcp && protocol == Protocol::HttpsPlain {
Protocol::HttpsTls
} else {
@@ -260,8 +264,13 @@ mod tests {
#[test]
fn non_loopback_listen_or_upstream_is_refused() {
for a in ["--listen 0.0.0.0", "--listen 192.168.100.140", "--upstream 192.168.100.217", "--listen ::", "--upstream 26.1.2.3"]
{
for a in [
"--listen 0.0.0.0",
"--listen 192.168.100.140",
"--upstream 192.168.100.217",
"--listen ::",
"--upstream 26.1.2.3",
] {
assert!(matches!(Config::from_args(&args(a)), Err(ConfigError::NotLoopback(_))), "{a}");
}
}