[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\`.
|
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
|
Built and checked on 2026-11-25 (Windows MSVC, stable 1.99, `-j 2`): `cargo test` 28 passed, `cargo clippy
|
||||||
PowerShell scripts named below (`lab-install.ps1`, `lab-api.ps1`) are **not written yet**; they come with the first
|
--all-targets -- -D warnings` and `cargo fmt --check` clean. The relay has **not been run** yet. The two scripts
|
||||||
build, for the build lead to read before anything runs.
|
(`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`
|
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
|
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 {
|
impl std::fmt::Display for ConfigError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
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::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::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"),
|
Self::PortOverflow(p) => write!(f, "port {p} plus the offset is over 65535"),
|
||||||
@@ -173,8 +175,10 @@ impl Config {
|
|||||||
GAMESTREAM_PORTS
|
GAMESTREAM_PORTS
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(port, transport, protocol)| {
|
.map(|&(port, transport, protocol)| {
|
||||||
let upstream_port = port.checked_add(self.upstream_port_offset).ok_or(ConfigError::PortOverflow(port))?;
|
let upstream_port =
|
||||||
let transport = if transport == Transport::Tls && self.tls.is_none() { Transport::Tcp } else { transport };
|
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 {
|
let protocol = if transport == Transport::Tcp && protocol == Protocol::HttpsPlain {
|
||||||
Protocol::HttpsTls
|
Protocol::HttpsTls
|
||||||
} else {
|
} else {
|
||||||
@@ -260,8 +264,13 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn non_loopback_listen_or_upstream_is_refused() {
|
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}");
|
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();
|
let mut threads = Vec::new();
|
||||||
for spec in config.ports()? {
|
for spec in config.ports()? {
|
||||||
let (config, rec) = (Arc::clone(&config), Arc::clone(&rec));
|
let (config, rec) = (Arc::clone(&config), Arc::clone(&rec));
|
||||||
println!(
|
println!("lab-relay: {:?} {} -> {}", spec.protocol, config.listen_addr(&spec), config.upstream_addr(&spec));
|
||||||
"lab-relay: {:?} {} -> {}",
|
|
||||||
spec.protocol,
|
|
||||||
config.listen_addr(&spec),
|
|
||||||
config.upstream_addr(&spec)
|
|
||||||
);
|
|
||||||
threads.push(thread::spawn(move || {
|
threads.push(thread::spawn(move || {
|
||||||
let r = match spec.transport {
|
let r = match spec.transport {
|
||||||
Transport::Tcp => tcp::serve(Arc::clone(&config), spec, Arc::clone(&rec)),
|
Transport::Tcp => tcp::serve(Arc::clone(&config), spec, Arc::clone(&rec)),
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ impl Rewriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Bytes currently held back.
|
/// Bytes currently held back.
|
||||||
|
#[cfg(test)]
|
||||||
pub fn held(&self) -> usize {
|
pub fn held(&self) -> usize {
|
||||||
self.held.len()
|
self.held.len()
|
||||||
}
|
}
|
||||||
@@ -92,7 +93,7 @@ mod tests {
|
|||||||
fn replaces_in_one_chunk() {
|
fn replaces_in_one_chunk() {
|
||||||
let (out, n) = run(&mut lab(), &[ANSWER]);
|
let (out, n) = run(&mut lab(), &[ANSWER]);
|
||||||
assert_eq!(n, 1);
|
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]
|
#[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<()> {
|
fn relay(client: TcpStream, config: &Config, spec: PortSpec, rec: &Recorder, conn: u32) -> io::Result<()> {
|
||||||
let upstream_addr = config.upstream_addr(&spec);
|
let upstream_addr = config.upstream_addr(&spec);
|
||||||
let peer = client.peer_addr()?;
|
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 {
|
let Some(files) = &config.tls else {
|
||||||
return Err(io::Error::other("TLS files not configured"));
|
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.protocol_version(),
|
||||||
down.negotiated_cipher_suite().map(|s| s.suite()),
|
down.negotiated_cipher_suite().map(|s| s.suite()),
|
||||||
presented.as_deref().unwrap_or("none"),
|
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))?);
|
let up = Arc::new(UdpSocket::bind(SocketAddr::new(config.listen, 0))?);
|
||||||
up.connect(upstream_addr)?;
|
up.connect(upstream_addr)?;
|
||||||
let conn = rec.new_connection();
|
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);
|
spawn_return_path(Arc::clone(&up), Arc::clone(&listen), from, spec, Arc::clone(&rec), conn);
|
||||||
map.insert(from, (Arc::clone(&up), conn));
|
map.insert(from, (Arc::clone(&up), conn));
|
||||||
Some((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 };
|
let Some((up, conn)) = flow else { continue };
|
||||||
rec.log(Kind::Data, spec.protocol, Direction::ClientToHost, conn, &buf[..n]);
|
rec.log(Kind::Data, spec.protocol, Direction::ClientToHost, conn, &buf[..n]);
|
||||||
if let Err(e) = up.send(&buf[..n]) {
|
if let Err(e) = up.send(&buf[..n])
|
||||||
if !transient(&e) {
|
&& !transient(&e)
|
||||||
rec.note(spec.protocol, conn, &format!("send to host failed: {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) {
|
match up.recv(&mut buf) {
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
rec.log(Kind::Data, spec.protocol, Direction::HostToClient, conn, &buf[..n]);
|
rec.log(Kind::Data, spec.protocol, Direction::HostToClient, conn, &buf[..n]);
|
||||||
if let Err(e) = listen.send_to(&buf[..n], client) {
|
if let Err(e) = listen.send_to(&buf[..n], client)
|
||||||
if !transient(&e) {
|
&& !transient(&e)
|
||||||
rec.note(spec.protocol, conn, &format!("send to client failed: {e}"));
|
{
|
||||||
}
|
rec.note(spec.protocol, conn, &format!("send to client failed: {e}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) if transient(&e) => {}
|
Err(e) if transient(&e) => {}
|
||||||
|
|||||||
Reference in New Issue
Block a user