[repo] Lab relay: compile fixes after the first build (clippy, fmt); 28 unit tests pass
This commit is contained in:
+4
-3
@@ -29,9 +29,10 @@ E:\build\play-remotely\lab\
|
||||
```
|
||||
|
||||
Our scripts and the relay come from this repo (`tools/lab-relay/`) and run from it, never from `downloads\`.
|
||||
The relay source is written but **has never been compiled** (the disk rule held every build back). The two
|
||||
PowerShell scripts named below (`lab-install.ps1`, `lab-api.ps1`) are **not written yet**; they come with the first
|
||||
build, for the build lead to read before anything runs.
|
||||
Built and checked on 2026-11-25 (Windows MSVC, stable 1.99, `-j 2`): `cargo test` 28 passed, `cargo clippy
|
||||
--all-targets -- -D warnings` and `cargo fmt --check` clean. The relay has **not been run** yet. The two scripts
|
||||
(`tools/lab-relay/scripts/lab-install.ps1`, `lab-api.ps1`) have been parse-checked only, never run; the build lead
|
||||
reads them before anything goes to Mark.
|
||||
|
||||
The lab root is on E: (approved for Play remotely). The relay is built in `E:uild\play-remotely\DomiStream-wt-lab`
|
||||
with `TEMP`/`TMP` set to `E:uild\play-remotely mp`, `-j 2`, and only while CPU, RAM, D: and E: are all below
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,12 +60,7 @@ fn run(args: &[String]) -> AnyResult {
|
||||
let mut threads = Vec::new();
|
||||
for spec in config.ports()? {
|
||||
let (config, rec) = (Arc::clone(&config), Arc::clone(&rec));
|
||||
println!(
|
||||
"lab-relay: {:?} {} -> {}",
|
||||
spec.protocol,
|
||||
config.listen_addr(&spec),
|
||||
config.upstream_addr(&spec)
|
||||
);
|
||||
println!("lab-relay: {:?} {} -> {}", spec.protocol, config.listen_addr(&spec), config.upstream_addr(&spec));
|
||||
threads.push(thread::spawn(move || {
|
||||
let r = match spec.transport {
|
||||
Transport::Tcp => tcp::serve(Arc::clone(&config), spec, Arc::clone(&rec)),
|
||||
|
||||
@@ -61,6 +61,7 @@ impl Rewriter {
|
||||
}
|
||||
|
||||
/// Bytes currently held back.
|
||||
#[cfg(test)]
|
||||
pub fn held(&self) -> usize {
|
||||
self.held.len()
|
||||
}
|
||||
@@ -92,7 +93,7 @@ mod tests {
|
||||
fn replaces_in_one_chunk() {
|
||||
let (out, n) = run(&mut lab(), &[ANSWER]);
|
||||
assert_eq!(n, 1);
|
||||
assert_eq!(out, ANSWER.to_vec().iter().copied().collect::<Vec<_>>().replace_all_for_test());
|
||||
assert_eq!(out, ANSWER.to_vec().replace_all_for_test());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -105,7 +105,13 @@ fn sha256_hex(bytes: &[u8]) -> String {
|
||||
fn relay(client: TcpStream, config: &Config, spec: PortSpec, rec: &Recorder, conn: u32) -> io::Result<()> {
|
||||
let upstream_addr = config.upstream_addr(&spec);
|
||||
let peer = client.peer_addr()?;
|
||||
rec.log(Kind::Open, Protocol::HttpsPlain, Direction::None, conn, format!("{peer} -> {upstream_addr} (TLS terminated)").as_bytes());
|
||||
rec.log(
|
||||
Kind::Open,
|
||||
Protocol::HttpsPlain,
|
||||
Direction::None,
|
||||
conn,
|
||||
format!("{peer} -> {upstream_addr} (TLS terminated)").as_bytes(),
|
||||
);
|
||||
let Some(files) = &config.tls else {
|
||||
return Err(io::Error::other("TLS files not configured"));
|
||||
};
|
||||
@@ -146,7 +152,11 @@ fn relay(client: TcpStream, config: &Config, spec: PortSpec, rec: &Recorder, con
|
||||
down.protocol_version(),
|
||||
down.negotiated_cipher_suite().map(|s| s.suite()),
|
||||
presented.as_deref().unwrap_or("none"),
|
||||
if presented.as_deref() == Some(expected.as_str()) { "matches the lab client certificate" } else { "differs from the lab client certificate" },
|
||||
if presented.as_deref() == Some(expected.as_str()) {
|
||||
"matches the lab client certificate"
|
||||
} else {
|
||||
"differs from the lab client certificate"
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -53,7 +53,13 @@ pub fn serve(config: Arc<Config>, spec: PortSpec, rec: Arc<Recorder>) -> io::Res
|
||||
let up = Arc::new(UdpSocket::bind(SocketAddr::new(config.listen, 0))?);
|
||||
up.connect(upstream_addr)?;
|
||||
let conn = rec.new_connection();
|
||||
rec.log(Kind::Open, spec.protocol, Direction::None, conn, format!("{from} -> {upstream_addr}").as_bytes());
|
||||
rec.log(
|
||||
Kind::Open,
|
||||
spec.protocol,
|
||||
Direction::None,
|
||||
conn,
|
||||
format!("{from} -> {upstream_addr}").as_bytes(),
|
||||
);
|
||||
spawn_return_path(Arc::clone(&up), Arc::clone(&listen), from, spec, Arc::clone(&rec), conn);
|
||||
map.insert(from, (Arc::clone(&up), conn));
|
||||
Some((up, conn))
|
||||
@@ -61,10 +67,10 @@ pub fn serve(config: Arc<Config>, spec: PortSpec, rec: Arc<Recorder>) -> io::Res
|
||||
};
|
||||
let Some((up, conn)) = flow else { continue };
|
||||
rec.log(Kind::Data, spec.protocol, Direction::ClientToHost, conn, &buf[..n]);
|
||||
if let Err(e) = up.send(&buf[..n]) {
|
||||
if !transient(&e) {
|
||||
rec.note(spec.protocol, conn, &format!("send to host failed: {e}"));
|
||||
}
|
||||
if let Err(e) = up.send(&buf[..n])
|
||||
&& !transient(&e)
|
||||
{
|
||||
rec.note(spec.protocol, conn, &format!("send to host failed: {e}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,10 +89,10 @@ fn spawn_return_path(
|
||||
match up.recv(&mut buf) {
|
||||
Ok(n) => {
|
||||
rec.log(Kind::Data, spec.protocol, Direction::HostToClient, conn, &buf[..n]);
|
||||
if let Err(e) = listen.send_to(&buf[..n], client) {
|
||||
if !transient(&e) {
|
||||
rec.note(spec.protocol, conn, &format!("send to client failed: {e}"));
|
||||
}
|
||||
if let Err(e) = listen.send_to(&buf[..n], client)
|
||||
&& !transient(&e)
|
||||
{
|
||||
rec.note(spec.protocol, conn, &format!("send to client failed: {e}"));
|
||||
}
|
||||
}
|
||||
Err(e) if transient(&e) => {}
|
||||
|
||||
Reference in New Issue
Block a user