Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
237ad52bef | ||
|
|
a8ba852f16 | ||
|
|
f1a3de7730 | ||
|
|
80699dcf9d | ||
|
|
274c0f505e | ||
|
|
b393c0e5d5 | ||
|
|
d5bc8e3c64 | ||
|
|
c40f5459ba | ||
|
|
601510687e | ||
|
|
60387e9222 | ||
|
|
a48aa15308 | ||
|
|
691b58e531 |
Generated
+1
-1
@@ -436,7 +436,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dosh"
|
name = "dosh"
|
||||||
version = "0.1.7"
|
version = "0.1.17"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64",
|
"base64",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "dosh"
|
name = "dosh"
|
||||||
version = "0.1.7"
|
version = "0.1.17"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.PHONY: build test fmt clippy release-check install package-release package-release-linux package-release-windows publish-release bench-report bench-local bench-local-json bench-docker-ssh bench-docker-mosh fuzz-smoke fuzz-deep soak-local tui-harness
|
.PHONY: build test fmt clippy release-check 1.0-check reconnect-check hostile-network-check persistence-check package-check install package-release package-release-linux package-release-windows publish-release bench-report bench-local bench-local-json bench-docker-ssh bench-docker-mosh fuzz-smoke fuzz-deep soak-local tui-harness
|
||||||
|
|
||||||
build:
|
build:
|
||||||
cargo build --release
|
cargo build --release
|
||||||
@@ -19,6 +19,24 @@ release-check:
|
|||||||
cargo test
|
cargo test
|
||||||
$(MAKE) tui-harness
|
$(MAKE) tui-harness
|
||||||
|
|
||||||
|
1.0-check: release-check reconnect-check hostile-network-check persistence-check package-check
|
||||||
|
|
||||||
|
reconnect-check:
|
||||||
|
cargo test --test integration_smoke resume_updates_udp_endpoint_for_roaming -- --nocapture
|
||||||
|
DOSH_SOAK_SECONDS=$${DOSH_SOAK_SECONDS:-300} cargo test --test integration_smoke sleep_roaming_soak_30m -- --ignored --nocapture
|
||||||
|
|
||||||
|
hostile-network-check:
|
||||||
|
cargo test --test hostile_network -- --nocapture
|
||||||
|
|
||||||
|
persistence-check:
|
||||||
|
cargo test --test integration_smoke session_survives_server_restart_same_shell_and_screen -- --nocapture
|
||||||
|
cargo test --test integration_smoke multiple_persistent_named_sessions_survive_restart_independently -- --nocapture
|
||||||
|
|
||||||
|
package-check:
|
||||||
|
$(MAKE) package-release-linux
|
||||||
|
$(MAKE) package-release-windows
|
||||||
|
sh scripts/verify-release-artifacts.sh
|
||||||
|
|
||||||
install:
|
install:
|
||||||
sh install.sh --from-current
|
sh install.sh --from-current
|
||||||
|
|
||||||
|
|||||||
+19
-5
@@ -141,6 +141,20 @@ function Verify-ArchiveVersion($ExtractDir, $Url) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Install-Binary($Source, $Destination) {
|
||||||
|
$dir = Split-Path -Parent $Destination
|
||||||
|
$name = Split-Path -Leaf $Destination
|
||||||
|
$tmp = Join-Path $dir ".$name.tmp.$PID"
|
||||||
|
Copy-Item $Source $tmp -Force
|
||||||
|
try {
|
||||||
|
Move-Item $tmp $Destination -Force
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Remove-Item $tmp -Force -ErrorAction SilentlyContinue
|
||||||
|
throw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$bindir = Join-Path $Prefix "bin"
|
$bindir = Join-Path $Prefix "bin"
|
||||||
$configDir = Join-Path $HOME ".config\dosh"
|
$configDir = Join-Path $HOME ".config\dosh"
|
||||||
New-Item -ItemType Directory -Force -Path $bindir, $configDir | Out-Null
|
New-Item -ItemType Directory -Force -Path $bindir, $configDir | Out-Null
|
||||||
@@ -168,9 +182,9 @@ function Install-Prebuilt {
|
|||||||
if (-not $found) {
|
if (-not $found) {
|
||||||
throw "prebuilt archive missing $bin"
|
throw "prebuilt archive missing $bin"
|
||||||
}
|
}
|
||||||
Copy-Item $found.FullName (Join-Path $bindir $bin) -Force
|
Install-Binary $found.FullName (Join-Path $bindir $bin)
|
||||||
}
|
}
|
||||||
Copy-Item (Join-Path $bindir "dosh-client.exe") (Join-Path $bindir "dosh.exe") -Force
|
Install-Binary (Join-Path $bindir "dosh-client.exe") (Join-Path $bindir "dosh.exe")
|
||||||
return $true
|
return $true
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
@@ -202,9 +216,9 @@ function Install-FromSource {
|
|||||||
try {
|
try {
|
||||||
Push-Location $src
|
Push-Location $src
|
||||||
cargo build --release --bin dosh-client --bin dosh-bench
|
cargo build --release --bin dosh-client --bin dosh-bench
|
||||||
Copy-Item "target\release\dosh-client.exe" (Join-Path $bindir "dosh-client.exe") -Force
|
Install-Binary "target\release\dosh-client.exe" (Join-Path $bindir "dosh-client.exe")
|
||||||
Copy-Item "target\release\dosh-client.exe" (Join-Path $bindir "dosh.exe") -Force
|
Install-Binary "target\release\dosh-client.exe" (Join-Path $bindir "dosh.exe")
|
||||||
Copy-Item "target\release\dosh-bench.exe" (Join-Path $bindir "dosh-bench.exe") -Force
|
Install-Binary "target\release\dosh-bench.exe" (Join-Path $bindir "dosh-bench.exe")
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
Pop-Location
|
Pop-Location
|
||||||
|
|||||||
+21
-21
@@ -12,11 +12,7 @@ start_server=1
|
|||||||
force_config=0
|
force_config=0
|
||||||
update_cache="${DOSH_UPDATE_CACHE:-$HOME/.cache/dosh/source}"
|
update_cache="${DOSH_UPDATE_CACHE:-$HOME/.cache/dosh/source}"
|
||||||
quiet="${DOSH_UPDATE_QUIET:-0}"
|
quiet="${DOSH_UPDATE_QUIET:-0}"
|
||||||
if [ "${DOSH_UPDATE_QUIET:-0}" = "1" ] && [ "${DOSH_BINARY_REQUIRED:-0}" != "1" ]; then
|
use_prebuilt="${DOSH_USE_PREBUILT:-1}"
|
||||||
use_prebuilt=0
|
|
||||||
else
|
|
||||||
use_prebuilt="${DOSH_USE_PREBUILT:-1}"
|
|
||||||
fi
|
|
||||||
binary_url="${DOSH_BINARY_URL:-}"
|
binary_url="${DOSH_BINARY_URL:-}"
|
||||||
binary_base="${DOSH_BINARY_BASE:-}"
|
binary_base="${DOSH_BINARY_BASE:-}"
|
||||||
binary_name="${DOSH_BINARY_NAME:-}"
|
binary_name="${DOSH_BINARY_NAME:-}"
|
||||||
@@ -230,13 +226,26 @@ find_extracted_binary() {
|
|||||||
find "$1" -type f -name "$2" 2>/dev/null | sed -n '1p'
|
find "$1" -type f -name "$2" 2>/dev/null | sed -n '1p'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
install_binary() {
|
||||||
|
src="$1"
|
||||||
|
dst="$2"
|
||||||
|
dst_dir="$(dirname "$dst")"
|
||||||
|
dst_base="$(basename "$dst")"
|
||||||
|
tmp="$dst_dir/.$dst_base.tmp.$$"
|
||||||
|
install -m 0755 "$src" "$tmp"
|
||||||
|
if ! mv -f "$tmp" "$dst"; then
|
||||||
|
rm -f "$tmp"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
install_extracted_binary() {
|
install_extracted_binary() {
|
||||||
found="$(find_extracted_binary "$1" "$2")"
|
found="$(find_extracted_binary "$1" "$2")"
|
||||||
if [ -z "$found" ]; then
|
if [ -z "$found" ]; then
|
||||||
echo "prebuilt archive missing $2" >&2
|
echo "prebuilt archive missing $2" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
install -m 0755 "$found" "$3"
|
install_binary "$found" "$3"
|
||||||
}
|
}
|
||||||
|
|
||||||
sha256_file() {
|
sha256_file() {
|
||||||
@@ -333,7 +342,7 @@ try_install_prebuilt() {
|
|||||||
install_extracted_binary "$tmpdir/extract" dosh-auth "$bindir/dosh-auth" || return 1
|
install_extracted_binary "$tmpdir/extract" dosh-auth "$bindir/dosh-auth" || return 1
|
||||||
fi
|
fi
|
||||||
if found_bench="$(find_extracted_binary "$tmpdir/extract" dosh-bench)" && [ -n "$found_bench" ]; then
|
if found_bench="$(find_extracted_binary "$tmpdir/extract" dosh-bench)" && [ -n "$found_bench" ]; then
|
||||||
install -m 0755 "$found_bench" "$bindir/dosh-bench"
|
install_binary "$found_bench" "$bindir/dosh-bench"
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -392,14 +401,14 @@ install_from_source() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
install -m 0755 target/release/dosh-client "$bindir/dosh-client"
|
install_binary target/release/dosh-client "$bindir/dosh-client"
|
||||||
ln -sf dosh-client "$bindir/dosh"
|
ln -sf dosh-client "$bindir/dosh"
|
||||||
if [ "$role" = "server" ] || [ "$role" = "both" ]; then
|
if [ "$role" = "server" ] || [ "$role" = "both" ]; then
|
||||||
install -m 0755 target/release/dosh-server "$bindir/dosh-server"
|
install_binary target/release/dosh-server "$bindir/dosh-server"
|
||||||
install -m 0755 target/release/dosh-auth "$bindir/dosh-auth"
|
install_binary target/release/dosh-auth "$bindir/dosh-auth"
|
||||||
fi
|
fi
|
||||||
if [ -f target/release/dosh-bench ]; then
|
if [ -f target/release/dosh-bench ]; then
|
||||||
install -m 0755 target/release/dosh-bench "$bindir/dosh-bench"
|
install_binary target/release/dosh-bench "$bindir/dosh-bench"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,18 +426,9 @@ Wants=network-online.target
|
|||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=$bindir/dosh-server serve
|
ExecStart=$bindir/dosh-server serve
|
||||||
Restart=on-failure
|
Restart=always
|
||||||
RestartSec=1
|
RestartSec=1
|
||||||
KillMode=process
|
KillMode=process
|
||||||
NoNewPrivileges=true
|
|
||||||
PrivateTmp=true
|
|
||||||
ProtectSystem=strict
|
|
||||||
ProtectHome=read-only
|
|
||||||
ReadWritePaths=$config_dir $data_dir
|
|
||||||
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
|
|
||||||
RestrictRealtime=true
|
|
||||||
LockPersonality=true
|
|
||||||
MemoryDenyWriteExecute=true
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=default.target
|
WantedBy=default.target
|
||||||
|
|||||||
@@ -6,18 +6,9 @@ Wants=network-online.target
|
|||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=%h/.local/bin/dosh-server serve
|
ExecStart=%h/.local/bin/dosh-server serve
|
||||||
Restart=on-failure
|
Restart=always
|
||||||
RestartSec=1
|
RestartSec=1
|
||||||
KillMode=process
|
KillMode=process
|
||||||
NoNewPrivileges=true
|
|
||||||
PrivateTmp=true
|
|
||||||
ProtectSystem=strict
|
|
||||||
ProtectHome=read-only
|
|
||||||
ReadWritePaths=%h/.config/dosh %h/.local/share/dosh
|
|
||||||
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
|
|
||||||
RestrictRealtime=true
|
|
||||||
LockPersonality=true
|
|
||||||
MemoryDenyWriteExecute=true
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=default.target
|
WantedBy=default.target
|
||||||
|
|||||||
@@ -99,6 +99,21 @@ fi
|
|||||||
|
|
||||||
web_repo="${base%/}/${repo}"
|
web_repo="${base%/}/${repo}"
|
||||||
failed=0
|
failed=0
|
||||||
|
artifact_version() {
|
||||||
|
artifact="$1"
|
||||||
|
case "$artifact" in
|
||||||
|
*.tar.gz)
|
||||||
|
tar -xOf "$artifact" dosh/VERSION 2>/dev/null | tr -d '\r\n'
|
||||||
|
;;
|
||||||
|
*.zip)
|
||||||
|
unzip -p "$artifact" dosh/VERSION 2>/dev/null | tr -d '\r\n'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
for artifact in target/dosh-release/dosh-linux-*.tar.gz target/dosh-release/dosh-macos-*.tar.gz target/dosh-release/dosh-windows-*.zip; do
|
for artifact in target/dosh-release/dosh-linux-*.tar.gz target/dosh-release/dosh-macos-*.tar.gz target/dosh-release/dosh-windows-*.zip; do
|
||||||
[ -f "$artifact" ] || continue
|
[ -f "$artifact" ] || continue
|
||||||
name="$(basename "$artifact")"
|
name="$(basename "$artifact")"
|
||||||
@@ -107,6 +122,11 @@ for artifact in target/dosh-release/dosh-linux-*.tar.gz target/dosh-release/dosh
|
|||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
actual="$(artifact_version "$artifact" || true)"
|
||||||
|
if [ "$actual" != "$version" ]; then
|
||||||
|
echo "skipping stale artifact $name: version ${actual:-unknown}, expected $version" >&2
|
||||||
|
continue
|
||||||
|
fi
|
||||||
url="$web_repo/releases/download/$tag/$name"
|
url="$web_repo/releases/download/$tag/$name"
|
||||||
if curl -fsSI "$url" >/dev/null; then
|
if curl -fsSI "$url" >/dev/null; then
|
||||||
echo "verified $url"
|
echo "verified $url"
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ for test_name in \
|
|||||||
live_output_forwards_terminal_control_sequences \
|
live_output_forwards_terminal_control_sequences \
|
||||||
tui_control_sequences_survive_transport_verbatim \
|
tui_control_sequences_survive_transport_verbatim \
|
||||||
unicode_output_survives_transport \
|
unicode_output_survives_transport \
|
||||||
|
tui_graph_glyphs_survive_fast_repaints_without_snapshot_substitution \
|
||||||
|
btop_style_graph_output_stays_raw_when_retransmit_history_overflows \
|
||||||
large_tui_paint_is_delivered_in_mtu_safe_frames \
|
large_tui_paint_is_delivered_in_mtu_safe_frames \
|
||||||
resume_snapshot_preserves_alternate_screen_mode
|
resume_snapshot_preserves_alternate_screen_mode
|
||||||
do
|
do
|
||||||
|
|||||||
@@ -32,6 +32,21 @@ token="${GITEA_TOKEN:-}"
|
|||||||
title="${GITEA_TITLE:-$tag}"
|
title="${GITEA_TITLE:-$tag}"
|
||||||
expected_version="${tag#v}"
|
expected_version="${tag#v}"
|
||||||
|
|
||||||
|
artifact_version() {
|
||||||
|
artifact="$1"
|
||||||
|
case "$artifact" in
|
||||||
|
*.tar.gz)
|
||||||
|
tar -xOf "$artifact" dosh/VERSION 2>/dev/null | tr -d '\r\n'
|
||||||
|
;;
|
||||||
|
*.zip)
|
||||||
|
unzip -p "$artifact" dosh/VERSION 2>/dev/null | tr -d '\r\n'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
if [ -z "$token" ] && [ -f "$HOME/.config/dosh/gitea-token" ]; then
|
if [ -z "$token" ] && [ -f "$HOME/.config/dosh/gitea-token" ]; then
|
||||||
token="$(tr -d '\r\n' <"$HOME/.config/dosh/gitea-token")"
|
token="$(tr -d '\r\n' <"$HOME/.config/dosh/gitea-token")"
|
||||||
fi
|
fi
|
||||||
@@ -52,6 +67,11 @@ if [ "$#" -eq 0 ]; then
|
|||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
actual="$(artifact_version "$artifact" || true)"
|
||||||
|
if [ "$actual" != "$expected_version" ]; then
|
||||||
|
echo "skipping $artifact: version ${actual:-unknown}, expected $expected_version" >&2
|
||||||
|
continue
|
||||||
|
fi
|
||||||
if [ -f "$artifact.sha256" ]; then
|
if [ -f "$artifact.sha256" ]; then
|
||||||
set -- "$@" "$artifact" "$artifact.sha256"
|
set -- "$@" "$artifact" "$artifact.sha256"
|
||||||
else
|
else
|
||||||
@@ -103,21 +123,6 @@ delete_existing_asset() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
artifact_version() {
|
|
||||||
artifact="$1"
|
|
||||||
case "$artifact" in
|
|
||||||
*.tar.gz)
|
|
||||||
tar -xOf "$artifact" dosh/VERSION 2>/dev/null | tr -d '\r\n'
|
|
||||||
;;
|
|
||||||
*.zip)
|
|
||||||
unzip -p "$artifact" dosh/VERSION 2>/dev/null | tr -d '\r\n'
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
verify_release_artifact_version() {
|
verify_release_artifact_version() {
|
||||||
artifact="$1"
|
artifact="$1"
|
||||||
name="$(basename "$artifact")"
|
name="$(basename "$artifact")"
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
repo_root="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"
|
||||||
|
cd "$repo_root"
|
||||||
|
|
||||||
|
version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | sed -n '1p')"
|
||||||
|
out_dir="${DOSH_PACKAGE_DIR:-target/dosh-release}"
|
||||||
|
|
||||||
|
artifact_version() {
|
||||||
|
artifact="$1"
|
||||||
|
case "$artifact" in
|
||||||
|
*.tar.gz)
|
||||||
|
tar -xOf "$artifact" dosh/VERSION 2>/dev/null | tr -d '\r\n'
|
||||||
|
;;
|
||||||
|
*.zip)
|
||||||
|
unzip -p "$artifact" dosh/VERSION 2>/dev/null | tr -d '\r\n'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
failed=0
|
||||||
|
for artifact in \
|
||||||
|
"$out_dir/dosh-linux-x86_64.tar.gz" \
|
||||||
|
"$out_dir/dosh-macos-aarch64.tar.gz" \
|
||||||
|
"$out_dir/dosh-windows-x86_64.zip"; do
|
||||||
|
if [ ! -f "$artifact" ]; then
|
||||||
|
echo "missing release artifact: $artifact" >&2
|
||||||
|
failed=1
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ ! -f "$artifact.sha256" ]; then
|
||||||
|
echo "missing release checksum: $artifact.sha256" >&2
|
||||||
|
failed=1
|
||||||
|
fi
|
||||||
|
actual="$(artifact_version "$artifact" || true)"
|
||||||
|
if [ "$actual" != "$version" ]; then
|
||||||
|
echo "artifact version mismatch: $artifact has ${actual:-unknown}, expected $version" >&2
|
||||||
|
failed=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
exit "$failed"
|
||||||
+189
-9
@@ -4271,6 +4271,7 @@ async fn run_terminal(
|
|||||||
let mut status_tick = tokio::time::interval(Duration::from_secs(1));
|
let mut status_tick = tokio::time::interval(Duration::from_secs(1));
|
||||||
let mut resize_tick = tokio::time::interval(Duration::from_millis(250));
|
let mut resize_tick = tokio::time::interval(Duration::from_millis(250));
|
||||||
let mut stream_retransmit_tick = tokio::time::interval(Duration::from_millis(200));
|
let mut stream_retransmit_tick = tokio::time::interval(Duration::from_millis(200));
|
||||||
|
let mut frame_gap_tick = tokio::time::interval(Duration::from_millis(250));
|
||||||
let mut last_size = terminal_size();
|
let mut last_size = terminal_size();
|
||||||
// React to terminal resize the instant it happens via SIGWINCH (mosh-style),
|
// React to terminal resize the instant it happens via SIGWINCH (mosh-style),
|
||||||
// instead of waiting up to one `resize_tick`. The 250ms poll below stays as a
|
// instead of waiting up to one `resize_tick`. The 250ms poll below stays as a
|
||||||
@@ -4498,6 +4499,36 @@ async fn run_terminal(
|
|||||||
_ = resize_tick.tick() => {
|
_ = resize_tick.tick() => {
|
||||||
maybe_send_resize(&socket, addr, &cred, &mut send_seq, &mut last_size).await?;
|
maybe_send_resize(&socket, addr, &cred, &mut send_seq, &mut last_size).await?;
|
||||||
}
|
}
|
||||||
|
_ = frame_gap_tick.tick() => {
|
||||||
|
if frame_buffer.resync_due()
|
||||||
|
&& let Some(frame) = reconnect(
|
||||||
|
&socket,
|
||||||
|
&mut cred,
|
||||||
|
&mut send_seq,
|
||||||
|
last_size,
|
||||||
|
&mut frame_buffer,
|
||||||
|
&mut predictor,
|
||||||
|
)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
|
refresh_live_addr(&mut addr, &cred)?;
|
||||||
|
if !forward_only {
|
||||||
|
render_frame(&frame)?;
|
||||||
|
predictor.observe_output(&frame.bytes);
|
||||||
|
}
|
||||||
|
last_packet_at = Instant::now();
|
||||||
|
flush_pending_user_input(
|
||||||
|
&socket,
|
||||||
|
addr,
|
||||||
|
&cred,
|
||||||
|
&mut send_seq,
|
||||||
|
&mut predictor,
|
||||||
|
&mut pending_user_input,
|
||||||
|
&mut pending_user_input_bytes,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
recv = socket.recv_from(&mut recv_buf) => {
|
recv = socket.recv_from(&mut recv_buf) => {
|
||||||
let (n, _) = recv?;
|
let (n, _) = recv?;
|
||||||
let Ok(packet) = protocol::decode(&recv_buf[..n]) else {
|
let Ok(packet) = protocol::decode(&recv_buf[..n]) else {
|
||||||
@@ -4579,6 +4610,22 @@ async fn run_terminal(
|
|||||||
}
|
}
|
||||||
PacketKind::Pong => {
|
PacketKind::Pong => {
|
||||||
last_packet_at = Instant::now();
|
last_packet_at = Instant::now();
|
||||||
|
if should_flush_terminal_input_after_contact(
|
||||||
|
forward_only,
|
||||||
|
&cred.mode,
|
||||||
|
pending_user_input.is_empty(),
|
||||||
|
) {
|
||||||
|
flush_pending_user_input(
|
||||||
|
&socket,
|
||||||
|
addr,
|
||||||
|
&cred,
|
||||||
|
&mut send_seq,
|
||||||
|
&mut predictor,
|
||||||
|
&mut pending_user_input,
|
||||||
|
&mut pending_user_input_bytes,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PacketKind::Rekey => {
|
PacketKind::Rekey => {
|
||||||
// Server-initiated transport rekey (spec §11). The Rekey is
|
// Server-initiated transport rekey (spec §11). The Rekey is
|
||||||
@@ -5408,6 +5455,14 @@ fn should_hold_during_startup_gate(
|
|||||||
mode == StartupGateMode::HoldAll || already_queued || should_hold_post_submit_input(bytes)
|
mode == StartupGateMode::HoldAll || already_queued || should_hold_post_submit_input(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn should_flush_terminal_input_after_contact(
|
||||||
|
forward_only: bool,
|
||||||
|
mode: &str,
|
||||||
|
pending_empty: bool,
|
||||||
|
) -> bool {
|
||||||
|
!forward_only && !pending_empty && mode != "view-only" && mode != "forward-only"
|
||||||
|
}
|
||||||
|
|
||||||
async fn flush_pending_user_input(
|
async fn flush_pending_user_input(
|
||||||
socket: &UdpSocket,
|
socket: &UdpSocket,
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
@@ -6561,14 +6616,22 @@ fn contains_bytes(haystack: &[u8], needle: &[u8]) -> bool {
|
|||||||
.any(|window| window == needle)
|
.any(|window| window == needle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FRAME_GAP_RESYNC_AFTER_MS: u64 = 2_500;
|
||||||
|
const FRAME_GAP_RESYNC_COOLDOWN_MS: u64 = 5_000;
|
||||||
|
const FRAME_GAP_PENDING_RESYNC_THRESHOLD: usize = 128;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct FrameBuffer {
|
struct FrameBuffer {
|
||||||
pending: BTreeMap<u64, Frame>,
|
pending: BTreeMap<u64, Frame>,
|
||||||
|
gap_since: Option<Instant>,
|
||||||
|
last_resync_at: Option<Instant>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FrameBuffer {
|
impl FrameBuffer {
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
self.pending.clear();
|
self.pending.clear();
|
||||||
|
self.gap_since = None;
|
||||||
|
self.last_resync_at = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn accept(&mut self, frame: Frame, last_rendered_seq: &mut u64) -> Vec<Frame> {
|
fn accept(&mut self, frame: Frame, last_rendered_seq: &mut u64) -> Vec<Frame> {
|
||||||
@@ -6577,6 +6640,8 @@ impl FrameBuffer {
|
|||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
self.pending.clear();
|
self.pending.clear();
|
||||||
|
self.gap_since = None;
|
||||||
|
self.last_resync_at = None;
|
||||||
*last_rendered_seq = frame.output_seq;
|
*last_rendered_seq = frame.output_seq;
|
||||||
return vec![frame];
|
return vec![frame];
|
||||||
}
|
}
|
||||||
@@ -6590,8 +6655,47 @@ impl FrameBuffer {
|
|||||||
*last_rendered_seq = frame.output_seq;
|
*last_rendered_seq = frame.output_seq;
|
||||||
ready.push(frame);
|
ready.push(frame);
|
||||||
}
|
}
|
||||||
|
self.refresh_gap(*last_rendered_seq);
|
||||||
ready
|
ready
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn refresh_gap(&mut self, last_rendered_seq: u64) {
|
||||||
|
let waiting_on_missing = self
|
||||||
|
.pending
|
||||||
|
.first_key_value()
|
||||||
|
.is_some_and(|(&seq, _)| seq > last_rendered_seq.saturating_add(1));
|
||||||
|
if waiting_on_missing {
|
||||||
|
self.gap_since.get_or_insert_with(Instant::now);
|
||||||
|
} else {
|
||||||
|
self.gap_since = None;
|
||||||
|
self.last_resync_at = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resync_due(&mut self) -> bool {
|
||||||
|
let Some(gap_since) = self.gap_since else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
let now = Instant::now();
|
||||||
|
let waited = now.duration_since(gap_since);
|
||||||
|
if waited < Duration::from_millis(FRAME_GAP_RESYNC_AFTER_MS)
|
||||||
|
&& self.pending.len() < FRAME_GAP_PENDING_RESYNC_THRESHOLD
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if self.last_resync_at.is_some_and(|last| {
|
||||||
|
now.duration_since(last) < Duration::from_millis(FRAME_GAP_RESYNC_COOLDOWN_MS)
|
||||||
|
}) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
self.last_resync_at = Some(now);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
fn backdate_gap_for_test(&mut self, elapsed: Duration) {
|
||||||
|
self.gap_since = Some(Instant::now() - elapsed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read the current terminal size and, if it changed since `last_size`, send a
|
/// Read the current terminal size and, if it changed since `last_size`, send a
|
||||||
@@ -7003,10 +7107,10 @@ const TERMINAL_CLEANUP: &[u8] = concat!(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{
|
use super::{
|
||||||
CachedCredential, DisconnectStatus, DynamicForward, FrameBuffer, LocalForward,
|
CachedCredential, DisconnectStatus, DynamicForward, FRAME_GAP_RESYNC_AFTER_MS, FrameBuffer,
|
||||||
MAX_PENDING_USER_INPUT_BYTES, POST_SUBMIT_ALL_INPUT_HOLD, PendingStreamOpen, PredictMode,
|
LocalForward, MAX_PENDING_USER_INPUT_BYTES, POST_SUBMIT_ALL_INPUT_HOLD, PendingStreamOpen,
|
||||||
Predictor, RESTART_STATUS_SCRIPT, RemoteForward, STARTUP_INPUT_HOLD, SshConfig,
|
PredictMode, Predictor, RESTART_STATUS_SCRIPT, RemoteForward, STARTUP_INPUT_HOLD,
|
||||||
StartupGateMode, StatusAction, auth_allows, cache_key, cache_server_prefix,
|
SshConfig, StartupGateMode, StatusAction, auth_allows, cache_key, cache_server_prefix,
|
||||||
clear_cached_credentials, ensure_tui_safe_status_overlay, input_matches_escape,
|
clear_cached_credentials, ensure_tui_safe_status_overlay, input_matches_escape,
|
||||||
is_local_status_target, is_resume_response_for_client, latest_release_download_url,
|
is_local_status_target, is_resume_response_for_client, latest_release_download_url,
|
||||||
load_first_native_identity_with_prompt, parse_dynamic_forward, parse_escape_key,
|
load_first_native_identity_with_prompt, parse_dynamic_forward, parse_escape_key,
|
||||||
@@ -7015,11 +7119,11 @@ mod tests {
|
|||||||
release_tag_download_url, release_tag_from_effective_url, release_version_from_tag,
|
release_tag_download_url, release_tag_from_effective_url, release_version_from_tag,
|
||||||
render_status_clear, render_status_overlay, requested_env, resolved_startup_command,
|
render_status_clear, render_status_overlay, requested_env, resolved_startup_command,
|
||||||
retransmit_stream_opens, rewrite_forward_command, selected_predict_mode, selected_udp_host,
|
retransmit_stream_opens, rewrite_forward_command, selected_predict_mode, selected_udp_host,
|
||||||
server_version_mismatch, should_hold_during_startup_gate, should_hold_post_submit_input,
|
server_version_mismatch, should_flush_terminal_input_after_contact,
|
||||||
split_after_command_submit, ssh_destination_host, ssh_username, ssh_with_user,
|
should_hold_during_startup_gate, should_hold_post_submit_input, split_after_command_submit,
|
||||||
startup_command, status_ssh_target, strip_stale_mouse_reports, toml_bare_key_or_quoted,
|
ssh_destination_host, ssh_username, ssh_with_user, startup_command, status_ssh_target,
|
||||||
update_check_requested, update_version_status, upsert_managed_block, valid_forward_host,
|
strip_stale_mouse_reports, toml_bare_key_or_quoted, update_check_requested,
|
||||||
vscode_safe_alias,
|
update_version_status, upsert_managed_block, valid_forward_host, vscode_safe_alias,
|
||||||
};
|
};
|
||||||
use dosh::config::{ClientConfig, CommandExtension, HostConfig};
|
use dosh::config::{ClientConfig, CommandExtension, HostConfig};
|
||||||
use dosh::native::EnvVar;
|
use dosh::native::EnvVar;
|
||||||
@@ -7457,6 +7561,54 @@ mod tests {
|
|||||||
assert!(buffer.accept(test_frame(12, false), &mut last).is_empty());
|
assert!(buffer.accept(test_frame(12, false), &mut last).is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn frame_buffer_keeps_gap_buffered_without_snapshot_resync() {
|
||||||
|
let mut buffer = FrameBuffer::default();
|
||||||
|
let mut last = 10;
|
||||||
|
|
||||||
|
assert!(buffer.accept(test_frame(13, false), &mut last).is_empty());
|
||||||
|
assert_eq!(last, 10);
|
||||||
|
assert!(buffer.accept(test_frame(14, false), &mut last).is_empty());
|
||||||
|
assert_eq!(last, 10);
|
||||||
|
assert!(!buffer.resync_due());
|
||||||
|
|
||||||
|
let ready = buffer.accept(test_frame(11, false), &mut last);
|
||||||
|
assert_eq!(ready.len(), 1);
|
||||||
|
assert_eq!(ready[0].output_seq, 11);
|
||||||
|
assert_eq!(last, 11);
|
||||||
|
|
||||||
|
let ready = buffer.accept(test_frame(12, false), &mut last);
|
||||||
|
assert_eq!(ready.len(), 3);
|
||||||
|
assert_eq!(
|
||||||
|
ready
|
||||||
|
.iter()
|
||||||
|
.map(|frame| frame.output_seq)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![12, 13, 14]
|
||||||
|
);
|
||||||
|
assert_eq!(last, 14);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn frame_buffer_resyncs_old_gap_with_cooldown() {
|
||||||
|
let mut buffer = FrameBuffer::default();
|
||||||
|
let mut last = 10;
|
||||||
|
|
||||||
|
assert!(buffer.accept(test_frame(13, false), &mut last).is_empty());
|
||||||
|
buffer.backdate_gap_for_test(Duration::from_millis(FRAME_GAP_RESYNC_AFTER_MS + 10));
|
||||||
|
assert!(buffer.resync_due());
|
||||||
|
assert!(
|
||||||
|
!buffer.resync_due(),
|
||||||
|
"resync must be rate-limited so snapshots cannot churn the TUI"
|
||||||
|
);
|
||||||
|
|
||||||
|
let ready = buffer.accept(test_frame(20, true), &mut last);
|
||||||
|
assert_eq!(ready.len(), 1);
|
||||||
|
assert_eq!(ready[0].output_seq, 20);
|
||||||
|
assert_eq!(last, 20);
|
||||||
|
assert!(!buffer.resync_due());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn frame_buffer_ignores_stale_snapshot() {
|
fn frame_buffer_ignores_stale_snapshot() {
|
||||||
let mut buffer = FrameBuffer::default();
|
let mut buffer = FrameBuffer::default();
|
||||||
@@ -7751,6 +7903,34 @@ mod tests {
|
|||||||
assert_eq!(post_submit_hold_duration(b"x"), POST_SUBMIT_ALL_INPUT_HOLD);
|
assert_eq!(post_submit_hold_duration(b"x"), POST_SUBMIT_ALL_INPUT_HOLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn contact_flushes_pending_terminal_input_for_interactive_sessions() {
|
||||||
|
assert!(should_flush_terminal_input_after_contact(
|
||||||
|
false, "normal", false
|
||||||
|
));
|
||||||
|
assert!(should_flush_terminal_input_after_contact(
|
||||||
|
false,
|
||||||
|
"read-write",
|
||||||
|
false
|
||||||
|
));
|
||||||
|
assert!(!should_flush_terminal_input_after_contact(
|
||||||
|
false, "normal", true
|
||||||
|
));
|
||||||
|
assert!(!should_flush_terminal_input_after_contact(
|
||||||
|
true, "normal", false
|
||||||
|
));
|
||||||
|
assert!(!should_flush_terminal_input_after_contact(
|
||||||
|
false,
|
||||||
|
"view-only",
|
||||||
|
false
|
||||||
|
));
|
||||||
|
assert!(!should_flush_terminal_input_after_contact(
|
||||||
|
false,
|
||||||
|
"forward-only",
|
||||||
|
false
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reconnect_refreshes_live_send_address_from_credentials() {
|
fn reconnect_refreshes_live_send_address_from_credentials() {
|
||||||
let mut addr = "127.0.0.1:50000".parse().unwrap();
|
let mut addr = "127.0.0.1:50000".parse().unwrap();
|
||||||
|
|||||||
+38
-158
@@ -232,19 +232,6 @@ async fn serve(config_path: Option<std::path::PathBuf>) -> Result<()> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let pacing_state = Arc::clone(&state);
|
|
||||||
let pacing_socket = Arc::clone(&socket);
|
|
||||||
let pacing_interval_ms = config.output_frame_interval_ms.max(1);
|
|
||||||
tokio::spawn(async move {
|
|
||||||
let mut interval = tokio::time::interval(Duration::from_millis(pacing_interval_ms));
|
|
||||||
loop {
|
|
||||||
interval.tick().await;
|
|
||||||
if let Err(err) = flush_paced_snapshots(&pacing_state, &pacing_socket).await {
|
|
||||||
eprintln!("paced snapshot error: {err:#}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let cleanup_state = Arc::clone(&state);
|
let cleanup_state = Arc::clone(&state);
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut interval = tokio::time::interval(Duration::from_secs(5));
|
let mut interval = tokio::time::interval(Duration::from_secs(5));
|
||||||
@@ -400,8 +387,6 @@ struct ClientState {
|
|||||||
rows: u16,
|
rows: u16,
|
||||||
last_seen: Instant,
|
last_seen: Instant,
|
||||||
pending: VecDeque<PendingFrame>,
|
pending: VecDeque<PendingFrame>,
|
||||||
last_frame_sent: Instant,
|
|
||||||
paced_snapshot_due: bool,
|
|
||||||
allowed_forwardings: Vec<ForwardingRequest>,
|
allowed_forwardings: Vec<ForwardingRequest>,
|
||||||
stream_writers: HashMap<u64, mpsc::Sender<Vec<u8>>>,
|
stream_writers: HashMap<u64, mpsc::Sender<Vec<u8>>>,
|
||||||
opened_streams: HashSet<u64>,
|
opened_streams: HashSet<u64>,
|
||||||
@@ -527,12 +512,13 @@ impl ServerState {
|
|||||||
|
|
||||||
/// Whether a session named `name` should be backed by a persistent holder.
|
/// Whether a session named `name` should be backed by a persistent holder.
|
||||||
///
|
///
|
||||||
/// With persistence enabled, every PTY session gets a detached holder. That
|
/// With persistence enabled, explicitly named sessions get a detached
|
||||||
/// includes implicit `term-<millis>-<pid>` sessions: a reconnecting client has
|
/// holder. Implicit `term-<millis>-<pid>` sessions are one-off terminals
|
||||||
/// the exact session name in its ticket cache, so it can reattach after a
|
/// created by `dosh host`; users cannot intentionally reattach to them by
|
||||||
/// quick server restart without forcing users to name sessions manually.
|
/// name, so persisting them only leaves stale holders that can be
|
||||||
fn should_persist_session(&self, _name: &str) -> bool {
|
/// accidentally re-adopted after restarts.
|
||||||
self.config.persist_sessions
|
fn should_persist_session(&self, name: &str) -> bool {
|
||||||
|
self.config.persist_sessions && !protocol::is_implicit_session_name(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spawn (or, in the persistent case, spawn-and-adopt) a PTY for a session.
|
/// Spawn (or, in the persistent case, spawn-and-adopt) a PTY for a session.
|
||||||
@@ -620,6 +606,20 @@ impl ServerState {
|
|||||||
if self.sessions.contains_key(&name) {
|
if self.sessions.contains_key(&name) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if !self.should_persist_session(&name) {
|
||||||
|
eprintln!(
|
||||||
|
"discarding stale implicit persistent session {name} (shell pid {})",
|
||||||
|
meta.shell_pid
|
||||||
|
);
|
||||||
|
persist::request_shutdown(&sessions_dir, &name, None);
|
||||||
|
if meta.shell_pid > 0 {
|
||||||
|
let _ = unsafe { libc::kill(meta.shell_pid, libc::SIGHUP) };
|
||||||
|
let _ = unsafe { libc::kill(meta.shell_pid, libc::SIGTERM) };
|
||||||
|
std::thread::sleep(Duration::from_millis(50));
|
||||||
|
let _ = unsafe { libc::kill(meta.shell_pid, libc::SIGKILL) };
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let (pty, control) = match self.adopt_persistent_pty(&name) {
|
let (pty, control) = match self.adopt_persistent_pty(&name) {
|
||||||
Ok(pair) => pair,
|
Ok(pair) => pair,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -1167,8 +1167,6 @@ async fn handle_native_user_auth(
|
|||||||
rows,
|
rows,
|
||||||
last_seen: Instant::now(),
|
last_seen: Instant::now(),
|
||||||
pending: VecDeque::new(),
|
pending: VecDeque::new(),
|
||||||
last_frame_sent: Instant::now() - Duration::from_secs(3600),
|
|
||||||
paced_snapshot_due: false,
|
|
||||||
allowed_forwardings: req.auth.requested_forwardings.clone(),
|
allowed_forwardings: req.auth.requested_forwardings.clone(),
|
||||||
stream_writers: HashMap::new(),
|
stream_writers: HashMap::new(),
|
||||||
opened_streams: HashSet::new(),
|
opened_streams: HashSet::new(),
|
||||||
@@ -1311,8 +1309,6 @@ async fn handle_bootstrap_attach(
|
|||||||
rows: req.rows,
|
rows: req.rows,
|
||||||
last_seen: Instant::now(),
|
last_seen: Instant::now(),
|
||||||
pending: VecDeque::new(),
|
pending: VecDeque::new(),
|
||||||
last_frame_sent: Instant::now() - Duration::from_secs(3600),
|
|
||||||
paced_snapshot_due: false,
|
|
||||||
allowed_forwardings: Vec::new(),
|
allowed_forwardings: Vec::new(),
|
||||||
stream_writers: HashMap::new(),
|
stream_writers: HashMap::new(),
|
||||||
opened_streams: HashSet::new(),
|
opened_streams: HashSet::new(),
|
||||||
@@ -1447,8 +1443,6 @@ async fn handle_ticket_attach(
|
|||||||
rows: req.rows,
|
rows: req.rows,
|
||||||
last_seen: Instant::now(),
|
last_seen: Instant::now(),
|
||||||
pending: VecDeque::new(),
|
pending: VecDeque::new(),
|
||||||
last_frame_sent: Instant::now() - Duration::from_secs(3600),
|
|
||||||
paced_snapshot_due: false,
|
|
||||||
allowed_forwardings: Vec::new(),
|
allowed_forwardings: Vec::new(),
|
||||||
stream_writers: HashMap::new(),
|
stream_writers: HashMap::new(),
|
||||||
opened_streams: HashSet::new(),
|
opened_streams: HashSet::new(),
|
||||||
@@ -3357,9 +3351,7 @@ async fn broadcast_output(
|
|||||||
let sends = {
|
let sends = {
|
||||||
let mut locked = state.lock().expect("server state poisoned");
|
let mut locked = state.lock().expect("server state poisoned");
|
||||||
let scrollback = locked.config.scrollback;
|
let scrollback = locked.config.scrollback;
|
||||||
let retransmit_window = locked.config.retransmit_window;
|
let retransmit_window = locked.config.retransmit_window.max(1);
|
||||||
let frame_interval = Duration::from_millis(locked.config.output_frame_interval_ms);
|
|
||||||
let now = Instant::now();
|
|
||||||
let session = locked
|
let session = locked
|
||||||
.sessions
|
.sessions
|
||||||
.get_mut(&output.session)
|
.get_mut(&output.session)
|
||||||
@@ -3394,32 +3386,21 @@ async fn broadcast_output(
|
|||||||
}
|
}
|
||||||
let mut sends = Vec::new();
|
let mut sends = Vec::new();
|
||||||
for (client_id, client) in session.clients.iter_mut() {
|
for (client_id, client) in session.clients.iter_mut() {
|
||||||
let terminal_control =
|
|
||||||
output.bytes.contains(&0x1b) || session.parser.screen().alternate_screen();
|
|
||||||
if !terminal_control
|
|
||||||
&& !frame_interval.is_zero()
|
|
||||||
&& now.duration_since(client.last_frame_sent) < frame_interval
|
|
||||||
{
|
|
||||||
client.paced_snapshot_due = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
client.send_seq += 1;
|
client.send_seq += 1;
|
||||||
// Count traffic toward the packet-count rekey trigger (spec §11).
|
// Count traffic toward the packet-count rekey trigger (spec §11).
|
||||||
client.epoch_packets = client.epoch_packets.saturating_add(1);
|
client.epoch_packets = client.epoch_packets.saturating_add(1);
|
||||||
// Only materialize a screen snapshot when this client has fallen too
|
// Live terminal bytes are never rewritten into vt100 snapshots. A
|
||||||
// far behind; the common case sends the raw output bytes and must not
|
// snapshot is useful for attach/resume, but substituting it during a
|
||||||
// clone the whole vt100 grid per client per packet.
|
// running TUI can lose graph/background-cell details that apps like
|
||||||
let (bytes, snapshot) = if client.pending.len() >= retransmit_window {
|
// btop rely on. If retransmit history is full, prune only history.
|
||||||
client.pending.clear();
|
while client.pending.len() >= retransmit_window {
|
||||||
(screen_snapshot(session.parser.screen()), true)
|
client.pending.pop_front();
|
||||||
} else {
|
}
|
||||||
(output.bytes.clone(), false)
|
|
||||||
};
|
|
||||||
let frame = Frame {
|
let frame = Frame {
|
||||||
session: output.session.clone(),
|
session: output.session.clone(),
|
||||||
output_seq,
|
output_seq,
|
||||||
bytes,
|
bytes: output.bytes.clone(),
|
||||||
snapshot,
|
snapshot: false,
|
||||||
closed: false,
|
closed: false,
|
||||||
};
|
};
|
||||||
let body = protocol::to_body(&frame)?;
|
let body = protocol::to_body(&frame)?;
|
||||||
@@ -3432,17 +3413,12 @@ async fn broadcast_output(
|
|||||||
SERVER_TO_CLIENT,
|
SERVER_TO_CLIENT,
|
||||||
&body,
|
&body,
|
||||||
)?;
|
)?;
|
||||||
while client.pending.len() >= retransmit_window {
|
|
||||||
client.pending.pop_front();
|
|
||||||
}
|
|
||||||
client.pending.push_back(PendingFrame {
|
client.pending.push_back(PendingFrame {
|
||||||
output_seq,
|
output_seq,
|
||||||
packet: packet.clone(),
|
packet: packet.clone(),
|
||||||
last_sent: Instant::now(),
|
last_sent: Instant::now(),
|
||||||
attempts: 0,
|
attempts: 0,
|
||||||
});
|
});
|
||||||
client.last_frame_sent = now;
|
|
||||||
client.paced_snapshot_due = false;
|
|
||||||
sends.push((client.endpoint, packet));
|
sends.push((client.endpoint, packet));
|
||||||
}
|
}
|
||||||
sends
|
sends
|
||||||
@@ -3543,11 +3519,9 @@ async fn retransmit_pending(
|
|||||||
if pending.output_seq <= client.last_acked {
|
if pending.output_seq <= client.last_acked {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if now.duration_since(pending.last_sent) >= Duration::from_millis(200)
|
if now.duration_since(pending.last_sent) >= Duration::from_millis(200) {
|
||||||
&& pending.attempts < 8
|
|
||||||
{
|
|
||||||
pending.last_sent = now;
|
pending.last_sent = now;
|
||||||
pending.attempts += 1;
|
pending.attempts = pending.attempts.saturating_add(1);
|
||||||
sends.push((client.endpoint, pending.packet.clone()));
|
sends.push((client.endpoint, pending.packet.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3626,76 +3600,6 @@ async fn retransmit_pending(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn flush_paced_snapshots(
|
|
||||||
state: &Arc<Mutex<ServerState>>,
|
|
||||||
socket: &Arc<UdpSocket>,
|
|
||||||
) -> Result<()> {
|
|
||||||
let sends = {
|
|
||||||
let mut locked = state.lock().expect("server state poisoned");
|
|
||||||
let frame_interval = Duration::from_millis(locked.config.output_frame_interval_ms);
|
|
||||||
if frame_interval.is_zero() {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
let retransmit_window = locked.config.retransmit_window;
|
|
||||||
let now = Instant::now();
|
|
||||||
let mut sends = Vec::new();
|
|
||||||
for (session_name, session) in locked.sessions.iter_mut() {
|
|
||||||
let due = session.clients.values().any(|client| {
|
|
||||||
client.paced_snapshot_due
|
|
||||||
&& now.duration_since(client.last_frame_sent) >= frame_interval
|
|
||||||
});
|
|
||||||
if !due {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let snapshot = screen_snapshot(session.parser.screen());
|
|
||||||
let output_seq = session.output_seq;
|
|
||||||
for (client_id, client) in session.clients.iter_mut() {
|
|
||||||
if !client.paced_snapshot_due
|
|
||||||
|| now.duration_since(client.last_frame_sent) < frame_interval
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
client.send_seq += 1;
|
|
||||||
client.epoch_packets = client.epoch_packets.saturating_add(1);
|
|
||||||
let frame = Frame {
|
|
||||||
session: session_name.clone(),
|
|
||||||
output_seq,
|
|
||||||
bytes: snapshot.clone(),
|
|
||||||
snapshot: true,
|
|
||||||
closed: false,
|
|
||||||
};
|
|
||||||
let body = protocol::to_body(&frame)?;
|
|
||||||
let packet = protocol::encode_encrypted(
|
|
||||||
PacketKind::Frame,
|
|
||||||
*client_id,
|
|
||||||
client.send_seq,
|
|
||||||
client.last_acked,
|
|
||||||
&client.session_key,
|
|
||||||
SERVER_TO_CLIENT,
|
|
||||||
&body,
|
|
||||||
)?;
|
|
||||||
while client.pending.len() >= retransmit_window {
|
|
||||||
client.pending.pop_front();
|
|
||||||
}
|
|
||||||
client.pending.push_back(PendingFrame {
|
|
||||||
output_seq,
|
|
||||||
packet: packet.clone(),
|
|
||||||
last_sent: now,
|
|
||||||
attempts: 0,
|
|
||||||
});
|
|
||||||
client.last_frame_sent = now;
|
|
||||||
client.paced_snapshot_due = false;
|
|
||||||
sends.push((client.endpoint, packet));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sends
|
|
||||||
};
|
|
||||||
for (endpoint, packet) in sends {
|
|
||||||
socket.send_to(&packet, endpoint).await?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// How long the previous epoch's key is retained after a rekey so in-flight
|
/// How long the previous epoch's key is retained after a rekey so in-flight
|
||||||
/// pre-rekey packets still decrypt instead of being dropped as fatal.
|
/// pre-rekey packets still decrypt instead of being dropped as fatal.
|
||||||
const REKEY_PREVIOUS_KEY_GRACE_SECS: u64 = 5;
|
const REKEY_PREVIOUS_KEY_GRACE_SECS: u64 = 5;
|
||||||
@@ -3950,7 +3854,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn persists_all_sessions_when_enabled() {
|
fn persists_named_sessions_when_enabled() {
|
||||||
let (pty_tx, _rx) = mpsc::unbounded_channel();
|
let (pty_tx, _rx) = mpsc::unbounded_channel();
|
||||||
let config = ServerConfig {
|
let config = ServerConfig {
|
||||||
persist_sessions: true,
|
persist_sessions: true,
|
||||||
@@ -3960,7 +3864,7 @@ mod tests {
|
|||||||
let state = ServerState::new(config, [0u8; 32], pty_tx);
|
let state = ServerState::new(config, [0u8; 32], pty_tx);
|
||||||
assert!(state.should_persist_session("default")); // prewarmed
|
assert!(state.should_persist_session("default")); // prewarmed
|
||||||
assert!(state.should_persist_session("work")); // explicitly named
|
assert!(state.should_persist_session("work")); // explicitly named
|
||||||
assert!(state.should_persist_session("term-1781470634216-76685")); // implicit reconnect
|
assert!(!state.should_persist_session("term-1781470634216-76685")); // one-off terminal
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -4077,8 +3981,6 @@ mod tests {
|
|||||||
rows: 24,
|
rows: 24,
|
||||||
last_seen: Instant::now(),
|
last_seen: Instant::now(),
|
||||||
pending: VecDeque::new(),
|
pending: VecDeque::new(),
|
||||||
last_frame_sent: Instant::now() - Duration::from_secs(3600),
|
|
||||||
paced_snapshot_due: false,
|
|
||||||
allowed_forwardings: Vec::new(),
|
allowed_forwardings: Vec::new(),
|
||||||
stream_writers: HashMap::new(),
|
stream_writers: HashMap::new(),
|
||||||
opened_streams: HashSet::new(),
|
opened_streams: HashSet::new(),
|
||||||
@@ -4395,8 +4297,6 @@ mod tests {
|
|||||||
rows: 24,
|
rows: 24,
|
||||||
last_seen: Instant::now(),
|
last_seen: Instant::now(),
|
||||||
pending: VecDeque::new(),
|
pending: VecDeque::new(),
|
||||||
last_frame_sent: Instant::now() - Duration::from_secs(3600),
|
|
||||||
paced_snapshot_due: false,
|
|
||||||
allowed_forwardings: Vec::new(),
|
allowed_forwardings: Vec::new(),
|
||||||
stream_writers: HashMap::new(),
|
stream_writers: HashMap::new(),
|
||||||
opened_streams: HashSet::new(),
|
opened_streams: HashSet::new(),
|
||||||
@@ -4491,8 +4391,6 @@ mod tests {
|
|||||||
rows: 24,
|
rows: 24,
|
||||||
last_seen: Instant::now(),
|
last_seen: Instant::now(),
|
||||||
pending: VecDeque::new(),
|
pending: VecDeque::new(),
|
||||||
last_frame_sent: Instant::now() - Duration::from_secs(3600),
|
|
||||||
paced_snapshot_due: false,
|
|
||||||
allowed_forwardings: Vec::new(),
|
allowed_forwardings: Vec::new(),
|
||||||
stream_writers: HashMap::new(),
|
stream_writers: HashMap::new(),
|
||||||
opened_streams: HashSet::from([42]),
|
opened_streams: HashSet::from([42]),
|
||||||
@@ -4562,7 +4460,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn output_pacing_coalesces_fast_frames_into_snapshot() {
|
async fn live_terminal_output_is_never_replaced_by_paced_snapshots() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
||||||
let config = ServerConfig {
|
let config = ServerConfig {
|
||||||
output_frame_interval_ms: 1000,
|
output_frame_interval_ms: 1000,
|
||||||
@@ -4614,25 +4512,6 @@ mod tests {
|
|||||||
let frame: Frame = protocol::from_body(&plain).unwrap();
|
let frame: Frame = protocol::from_body(&plain).unwrap();
|
||||||
assert!(!frame.snapshot);
|
assert!(!frame.snapshot);
|
||||||
assert_eq!(frame.bytes, b"first");
|
assert_eq!(frame.bytes, b"first");
|
||||||
assert!(
|
|
||||||
tokio::time::timeout(Duration::from_millis(30), receiver.recv_from(&mut buf))
|
|
||||||
.await
|
|
||||||
.is_err(),
|
|
||||||
"second frame should be coalesced"
|
|
||||||
);
|
|
||||||
|
|
||||||
{
|
|
||||||
let mut locked = state.lock().unwrap();
|
|
||||||
let client = locked
|
|
||||||
.sessions
|
|
||||||
.get_mut("test")
|
|
||||||
.unwrap()
|
|
||||||
.clients
|
|
||||||
.get_mut(&client_id)
|
|
||||||
.unwrap();
|
|
||||||
client.last_frame_sent = Instant::now() - Duration::from_secs(2);
|
|
||||||
}
|
|
||||||
flush_paced_snapshots(&state, &sender).await.unwrap();
|
|
||||||
let (n, _) = tokio::time::timeout(Duration::from_secs(1), receiver.recv_from(&mut buf))
|
let (n, _) = tokio::time::timeout(Duration::from_secs(1), receiver.recv_from(&mut buf))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -4640,8 +4519,9 @@ mod tests {
|
|||||||
let packet = protocol::decode(&buf[..n]).unwrap();
|
let packet = protocol::decode(&buf[..n]).unwrap();
|
||||||
let plain = protocol::decrypt_body(&packet, &session_key, SERVER_TO_CLIENT).unwrap();
|
let plain = protocol::decrypt_body(&packet, &session_key, SERVER_TO_CLIENT).unwrap();
|
||||||
let frame: Frame = protocol::from_body(&plain).unwrap();
|
let frame: Frame = protocol::from_body(&plain).unwrap();
|
||||||
assert!(frame.snapshot);
|
assert!(!frame.snapshot);
|
||||||
assert_eq!(frame.output_seq, 2);
|
assert_eq!(frame.output_seq, 2);
|
||||||
|
assert_eq!(frame.bytes, b"second");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -435,6 +435,10 @@ pub fn run_holder(
|
|||||||
let mut cmd = [0u8; 1];
|
let mut cmd = [0u8; 1];
|
||||||
match stream.read(&mut cmd) {
|
match stream.read(&mut cmd) {
|
||||||
Ok(1) if cmd[0] == HOLDER_CMD_SHUTDOWN => {
|
Ok(1) if cmd[0] == HOLDER_CMD_SHUTDOWN => {
|
||||||
|
if shell_pid > 0 {
|
||||||
|
let _ = unsafe { libc::kill(shell_pid, libc::SIGHUP) };
|
||||||
|
let _ = unsafe { libc::kill(shell_pid, libc::SIGTERM) };
|
||||||
|
}
|
||||||
let _ = std::fs::remove_dir_all(runtime_dir);
|
let _ = std::fs::remove_dir_all(runtime_dir);
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
+225
-26
@@ -98,6 +98,35 @@ persist_sessions = false
|
|||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_server_config_with_output_interval(
|
||||||
|
dir: &tempfile::TempDir,
|
||||||
|
port: u16,
|
||||||
|
output_frame_interval_ms: u64,
|
||||||
|
) -> std::path::PathBuf {
|
||||||
|
let config = write_server_config(dir, port);
|
||||||
|
let mut raw = fs::read_to_string(&config).unwrap();
|
||||||
|
raw.push_str(&format!(
|
||||||
|
"output_frame_interval_ms = {output_frame_interval_ms}\n"
|
||||||
|
));
|
||||||
|
fs::write(&config, raw).unwrap();
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_server_config_with_retransmit_window(
|
||||||
|
dir: &tempfile::TempDir,
|
||||||
|
port: u16,
|
||||||
|
retransmit_window: u64,
|
||||||
|
) -> std::path::PathBuf {
|
||||||
|
let config = write_server_config(dir, port);
|
||||||
|
let mut raw = fs::read_to_string(&config).unwrap();
|
||||||
|
raw = raw.replace(
|
||||||
|
"retransmit_window = 256\n",
|
||||||
|
&format!("retransmit_window = {retransmit_window}\n"),
|
||||||
|
);
|
||||||
|
fs::write(&config, raw).unwrap();
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
fn start_server(dir: &tempfile::TempDir, config: &std::path::Path) -> Child {
|
fn start_server(dir: &tempfile::TempDir, config: &std::path::Path) -> Child {
|
||||||
let server = env!("CARGO_BIN_EXE_dosh-server");
|
let server = env!("CARGO_BIN_EXE_dosh-server");
|
||||||
let child = Command::new(server)
|
let child = Command::new(server)
|
||||||
@@ -1363,18 +1392,10 @@ fn server_retransmits_unacked_output_frames() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let mut seen = Vec::new();
|
let mut seen = Vec::new();
|
||||||
let mut duplicate = None;
|
let deadline = std::time::Instant::now() + Duration::from_secs(4);
|
||||||
let deadline = std::time::Instant::now() + Duration::from_secs(3);
|
|
||||||
while std::time::Instant::now() < deadline {
|
while std::time::Instant::now() < deadline {
|
||||||
if let Some((header, frame)) = recv_frame(&socket, &bootstrap.session_key) {
|
if let Some((header, frame)) = recv_frame(&socket, &bootstrap.session_key) {
|
||||||
if String::from_utf8_lossy(&frame.bytes).contains("DOSH_RETRANSMIT") {
|
if String::from_utf8_lossy(&frame.bytes).contains("DOSH_RETRANSMIT") {
|
||||||
if seen
|
|
||||||
.iter()
|
|
||||||
.any(|(_, output_seq)| *output_seq == frame.output_seq)
|
|
||||||
{
|
|
||||||
duplicate = Some((header.seq, frame.output_seq));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
seen.push((header.seq, frame.output_seq));
|
seen.push((header.seq, frame.output_seq));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1383,9 +1404,18 @@ fn server_retransmits_unacked_output_frames() {
|
|||||||
let _ = server.kill();
|
let _ = server.kill();
|
||||||
let _ = server.wait();
|
let _ = server.wait();
|
||||||
|
|
||||||
|
let max_same_output_seq = seen
|
||||||
|
.iter()
|
||||||
|
.map(|(_, output_seq)| {
|
||||||
|
seen.iter()
|
||||||
|
.filter(|(_, candidate)| candidate == output_seq)
|
||||||
|
.count()
|
||||||
|
})
|
||||||
|
.max()
|
||||||
|
.unwrap_or(0);
|
||||||
assert!(
|
assert!(
|
||||||
duplicate.is_some(),
|
max_same_output_seq >= 10,
|
||||||
"expected retransmitted same output seq, seen={seen:?}"
|
"expected retransmission to continue past the old 8-attempt ceiling, seen={seen:?}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1639,6 +1669,110 @@ fn unicode_output_survives_transport() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tui_graph_glyphs_survive_fast_repaints_without_snapshot_substitution() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let port = free_udp_port();
|
||||||
|
let config = write_server_config_with_output_interval(&dir, port, 1000);
|
||||||
|
let mut server = start_server(&dir, &config);
|
||||||
|
let (socket, bootstrap, ok) = direct_attach(&config, port, "read-write");
|
||||||
|
|
||||||
|
let graph = "DOSH_GRAPH ⣀⣤⣶⣿ █▇▆▅▄▃▂▁ ╭╮╯╰";
|
||||||
|
let input = Input {
|
||||||
|
bytes: format!(
|
||||||
|
"printf '\\033[?1049h\\033[?25l'; for i in 1 2 3 4 5; do printf '\\033[H{} %s\\n' \"$i\"; done; printf '\\033[?25h\\033[?1049l'\n",
|
||||||
|
graph
|
||||||
|
)
|
||||||
|
.into_bytes(),
|
||||||
|
};
|
||||||
|
send_encrypted(
|
||||||
|
&socket,
|
||||||
|
port,
|
||||||
|
PacketKind::Input,
|
||||||
|
ok.client_id,
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
&bootstrap.session_key,
|
||||||
|
&protocol::to_body(&input).unwrap(),
|
||||||
|
);
|
||||||
|
let text = collect_frame_text(&socket, &bootstrap.session_key, 3000);
|
||||||
|
|
||||||
|
let _ = server.kill();
|
||||||
|
let _ = server.wait();
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
text.contains(graph) && text.matches("DOSH_GRAPH").count() >= 5,
|
||||||
|
"expected repeated raw graph glyph frames, got {text:?}"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
text.contains("\x1b[?25l") && text.contains("\x1b[?25h"),
|
||||||
|
"expected cursor visibility controls to survive around graph repaint, got {text:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn btop_style_graph_output_stays_raw_when_retransmit_history_overflows() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let port = free_udp_port();
|
||||||
|
let config = write_server_config_with_retransmit_window(&dir, port, 3);
|
||||||
|
let mut server = start_server(&dir, &config);
|
||||||
|
let (socket, bootstrap, ok) = direct_attach(&config, port, "read-write");
|
||||||
|
|
||||||
|
let graph = "DOSH_BTOP_NET ⠀⠁⠃⠇⡇⣇⣧⣷⣿";
|
||||||
|
let input = Input {
|
||||||
|
bytes: format!(
|
||||||
|
"stty -echo; \
|
||||||
|
printf '\\033[?1049h\\033[?2026h\\033[?25l'; \
|
||||||
|
for i in 1 2 3 4 5 6 7 8 9 10; do \
|
||||||
|
printf '\\033[6;4H\\033[38;2;80;220;140m{} %s\\033[0m' \"$i\"; \
|
||||||
|
done; \
|
||||||
|
printf '\\033[?25h\\033[?2026l\\033[?1049l'\n",
|
||||||
|
graph
|
||||||
|
)
|
||||||
|
.into_bytes(),
|
||||||
|
};
|
||||||
|
send_encrypted(
|
||||||
|
&socket,
|
||||||
|
port,
|
||||||
|
PacketKind::Input,
|
||||||
|
ok.client_id,
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
&bootstrap.session_key,
|
||||||
|
&protocol::to_body(&input).unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut text = String::new();
|
||||||
|
let mut snapshots = 0usize;
|
||||||
|
let deadline = std::time::Instant::now() + Duration::from_secs(3);
|
||||||
|
while std::time::Instant::now() < deadline
|
||||||
|
&& !(text.matches("DOSH_BTOP_NET").count() >= 10 && text.contains("\x1b[?2026l"))
|
||||||
|
{
|
||||||
|
if let Some((_header, frame)) = recv_frame(&socket, &bootstrap.session_key) {
|
||||||
|
if frame.snapshot {
|
||||||
|
snapshots += 1;
|
||||||
|
}
|
||||||
|
text.push_str(&String::from_utf8_lossy(&frame.bytes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = server.kill();
|
||||||
|
let _ = server.wait();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
snapshots, 0,
|
||||||
|
"live btop-style graph output must not be replaced by snapshots; got {snapshots}"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
text.matches("DOSH_BTOP_NET").count() >= 10
|
||||||
|
&& text.contains("⣿")
|
||||||
|
&& text.contains("\x1b[38;2;80;220;140m")
|
||||||
|
&& text.contains("\x1b[?2026h")
|
||||||
|
&& text.contains("\x1b[?2026l"),
|
||||||
|
"expected raw btop-style graph output to survive under retransmit pressure, got {text:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn large_tui_paint_is_delivered_in_mtu_safe_frames() {
|
fn large_tui_paint_is_delivered_in_mtu_safe_frames() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = tempfile::tempdir().unwrap();
|
||||||
@@ -2385,6 +2519,9 @@ fn write_persistent_server_config(dir: &tempfile::TempDir, port: u16) -> std::pa
|
|||||||
let mut raw = fs::read_to_string(&config).unwrap();
|
let mut raw = fs::read_to_string(&config).unwrap();
|
||||||
// The base writer hardcodes `persist_sessions = false`; flip it on.
|
// The base writer hardcodes `persist_sessions = false`; flip it on.
|
||||||
raw = raw.replace("persist_sessions = false", "persist_sessions = true");
|
raw = raw.replace("persist_sessions = false", "persist_sessions = true");
|
||||||
|
// Persistence tests attach the sessions they need explicitly. Leaving the
|
||||||
|
// base prewarm on here creates a detached default holder in every test.
|
||||||
|
raw = raw.replace("prewarm_sessions = [\"default\"]", "prewarm_sessions = []");
|
||||||
fs::write(&config, raw).unwrap();
|
fs::write(&config, raw).unwrap();
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
@@ -2420,6 +2557,45 @@ fn kill_holder(sessions_dir: &Path, session: &str) {
|
|||||||
.status();
|
.status();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a holder the way older Dosh builds did for implicit sessions, so
|
||||||
|
/// startup migration can be tested without depending on the new spawn policy.
|
||||||
|
fn spawn_legacy_holder(sessions_dir: &Path, session: &str) {
|
||||||
|
let server = env!("CARGO_BIN_EXE_dosh-server");
|
||||||
|
let runtime_dir = dosh::persist::ensure_runtime_dir(sessions_dir, session).unwrap();
|
||||||
|
let mut launcher = Command::new(server)
|
||||||
|
.arg("hold")
|
||||||
|
.arg("--runtime-dir")
|
||||||
|
.arg(&runtime_dir)
|
||||||
|
.arg("--session")
|
||||||
|
.arg(session)
|
||||||
|
.arg("--shell")
|
||||||
|
.arg("/bin/sh")
|
||||||
|
.arg("--cols")
|
||||||
|
.arg("80")
|
||||||
|
.arg("--rows")
|
||||||
|
.arg("24")
|
||||||
|
.stdout(Stdio::null())
|
||||||
|
.stderr(Stdio::null())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
let deadline = std::time::Instant::now() + Duration::from_secs(5);
|
||||||
|
while std::time::Instant::now() < deadline {
|
||||||
|
if holder_shell_pid(sessions_dir, session).is_some()
|
||||||
|
&& runtime_dir.join("holder.sock").exists()
|
||||||
|
{
|
||||||
|
let _ = launcher.wait();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if let Some(status) = launcher.try_wait().unwrap() {
|
||||||
|
panic!("legacy holder launcher exited before ready: {status}");
|
||||||
|
}
|
||||||
|
thread::sleep(Duration::from_millis(20));
|
||||||
|
}
|
||||||
|
let _ = launcher.kill();
|
||||||
|
let _ = launcher.wait();
|
||||||
|
panic!("legacy holder did not become ready");
|
||||||
|
}
|
||||||
|
|
||||||
/// Send one encrypted Input line and give the shell a moment to act.
|
/// Send one encrypted Input line and give the shell a moment to act.
|
||||||
fn type_line(socket: &UdpSocket, port: u16, ok: &AttachOk, key: &[u8; 32], seq: u64, line: &str) {
|
fn type_line(socket: &UdpSocket, port: u16, ok: &AttachOk, key: &[u8; 32], seq: u64, line: &str) {
|
||||||
let input = Input {
|
let input = Input {
|
||||||
@@ -2557,7 +2733,7 @@ fn session_survives_server_restart_same_shell_and_screen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn implicit_session_survives_server_restart_for_same_ticket_holder() {
|
fn implicit_session_does_not_create_restart_holder() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = tempfile::tempdir().unwrap();
|
||||||
let sessions_dir = dir.path().join("sessions");
|
let sessions_dir = dir.path().join("sessions");
|
||||||
let port = free_udp_port();
|
let port = free_udp_port();
|
||||||
@@ -2580,20 +2756,14 @@ fn implicit_session_survives_server_restart_for_same_ticket_holder() {
|
|||||||
|
|
||||||
let shell_pid_before = holder_shell_pid(&sessions_dir, &session);
|
let shell_pid_before = holder_shell_pid(&sessions_dir, &session);
|
||||||
assert!(
|
assert!(
|
||||||
shell_pid_before.is_some(),
|
shell_pid_before.is_none(),
|
||||||
"implicit sessions should get a persistent holder when persistence is enabled"
|
"implicit sessions must not get persistent holders when persistence is enabled"
|
||||||
);
|
);
|
||||||
|
|
||||||
let _ = server.kill();
|
let _ = server.kill();
|
||||||
let _ = server.wait();
|
let _ = server.wait();
|
||||||
thread::sleep(Duration::from_millis(300));
|
thread::sleep(Duration::from_millis(300));
|
||||||
|
|
||||||
let pid = shell_pid_before.unwrap();
|
|
||||||
assert!(
|
|
||||||
unsafe { libc::kill(pid, 0) } == 0,
|
|
||||||
"implicit session shell pid {pid} must survive server restart"
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut server = start_server(&dir, &config);
|
let mut server = start_server(&dir, &config);
|
||||||
let (socket2, bootstrap2, ok2) = direct_attach_session(&config, port, "read-write", &session);
|
let (socket2, bootstrap2, ok2) = direct_attach_session(&config, port, "read-write", &session);
|
||||||
let key2 = bootstrap2.session_key;
|
let key2 = bootstrap2.session_key;
|
||||||
@@ -2610,15 +2780,44 @@ fn implicit_session_survives_server_restart_for_same_ticket_holder() {
|
|||||||
|
|
||||||
let _ = server.kill();
|
let _ = server.kill();
|
||||||
let _ = server.wait();
|
let _ = server.wait();
|
||||||
kill_holder(&sessions_dir, &session);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert!(
|
||||||
shell_pid_after, shell_pid_before,
|
shell_pid_after.is_none(),
|
||||||
"implicit session should re-adopt the same shell pid"
|
"implicit restart attach must stay ephemeral"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
post.contains("IMPLICIT_MARK=implicit_restart_42"),
|
post.contains("IMPLICIT_MARK=") && !post.contains("implicit_restart_42"),
|
||||||
"implicit session state must survive restart, got {post:?}"
|
"implicit session must start fresh after server restart, got {post:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn startup_discards_legacy_implicit_holders() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let sessions_dir = dir.path().join("sessions");
|
||||||
|
let port = free_udp_port();
|
||||||
|
let config = write_persistent_server_config(&dir, port);
|
||||||
|
let session = protocol::generate_implicit_session_name();
|
||||||
|
|
||||||
|
spawn_legacy_holder(&sessions_dir, &session);
|
||||||
|
let shell_pid = holder_shell_pid(&sessions_dir, &session).expect("legacy holder shell pid");
|
||||||
|
assert!(
|
||||||
|
unsafe { libc::kill(shell_pid, 0) } == 0,
|
||||||
|
"legacy holder shell must be live before startup"
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut server = start_server(&dir, &config);
|
||||||
|
thread::sleep(Duration::from_millis(300));
|
||||||
|
|
||||||
|
let _ = server.kill();
|
||||||
|
let _ = server.wait();
|
||||||
|
assert!(
|
||||||
|
holder_shell_pid(&sessions_dir, &session).is_none(),
|
||||||
|
"startup must remove old implicit holder metadata"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
unsafe { libc::kill(shell_pid, 0) } != 0,
|
||||||
|
"startup must shut down old implicit holder shell"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
#[test]
|
||||||
|
fn quiet_update_keeps_prebuilt_enabled_by_default() {
|
||||||
|
let install = include_str!("../install.sh");
|
||||||
|
assert!(install.contains("use_prebuilt=\"${DOSH_USE_PREBUILT:-1}\""));
|
||||||
|
assert!(
|
||||||
|
!install.contains("use_prebuilt=0"),
|
||||||
|
"quiet updates must not force source builds"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn release_scripts_skip_stale_artifacts_when_auto_discovering() {
|
||||||
|
let upload = include_str!("../scripts/upload-gitea-release.sh");
|
||||||
|
assert!(upload.contains("skipping $artifact: version"));
|
||||||
|
assert!(upload.contains("expected_version"));
|
||||||
|
|
||||||
|
let publish = include_str!("../scripts/publish-gitea-release.sh");
|
||||||
|
assert!(publish.contains("skipping stale artifact"));
|
||||||
|
assert!(publish.contains("actual=\"$(artifact_version \"$artifact\" || true)\""));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn systemd_service_does_not_sandbox_remote_shells() {
|
||||||
|
let service = include_str!("../packaging/systemd/dosh-server.service");
|
||||||
|
let install = include_str!("../install.sh");
|
||||||
|
for raw in [service, install] {
|
||||||
|
assert!(raw.contains("KillMode=process"));
|
||||||
|
assert!(
|
||||||
|
raw.contains("Restart=always"),
|
||||||
|
"dosh-server should come back after accidental SIGTERM while preserving child shells"
|
||||||
|
);
|
||||||
|
for directive in [
|
||||||
|
"NoNewPrivileges=",
|
||||||
|
"PrivateTmp=",
|
||||||
|
"ProtectSystem=",
|
||||||
|
"ProtectHome=",
|
||||||
|
"RestrictAddressFamilies=",
|
||||||
|
"RestrictRealtime=",
|
||||||
|
"LockPersonality=",
|
||||||
|
"MemoryDenyWriteExecute=",
|
||||||
|
] {
|
||||||
|
assert!(
|
||||||
|
!raw.contains(directive),
|
||||||
|
"dosh sessions are user shells; systemd sandbox directive {directive} changes terminal/app behavior"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
assert!(
|
||||||
|
!raw.contains("ReadWritePaths="),
|
||||||
|
"remote shells must not be restricted to dosh config/data paths"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user