WEB: share immutable profiles + decoys across exact host lists

This commit is contained in:
Alexey
2026-10-15 07:05:36 +03:00
parent 05a367259a
commit 831cd0f1a7
51 changed files with 1661 additions and 343 deletions
+4 -4
View File
@@ -380,10 +380,10 @@ async fn handle_root(
config.web.limits.carrier_batch_bytes,
config.web.limits.pending_bytes_per_session,
config.web.limits.pending_items_per_session,
profile.max_streams_per_session,
profile.carrier_negotiation_enabled,
profile.carriers.len(),
profile.carrier_negotiation_deadlines_secs,
profile.shared.max_streams_per_session,
profile.shared.carrier_negotiation_enabled,
profile.shared.carriers.len(),
profile.shared.carrier_negotiation_deadlines_secs,
config.web.timeouts.long_poll_secs,
config.web.timeouts.bridge_request_secs,
config.web.timeouts.bridge_retry_secs,
+2 -2
View File
@@ -401,10 +401,10 @@ async fn prefixed_decoy_request_keeps_its_original_path_and_query() {
host: "proxy.example.com".to_string(),
base: "/relay/".to_string(),
decoy_fasttrack_mode: WebDecoyFastTrackMode::Off,
decoy: WebRuntimeDecoy::HttpUpstream {
decoy: Arc::new(WebRuntimeDecoy::HttpUpstream {
addr: site_addr,
authority: "decoy.internal".to_string(),
},
}),
decoy_header_secs: 1,
profiles: vec![Arc::clone(&profile)],
capabilities: vec![capability].into_boxed_slice(),
+4 -4
View File
@@ -66,10 +66,10 @@ async fn every_authentic_credential_placement_stays_out_of_the_upstream() {
host: "proxy.example.com".to_string(),
base: "/relay/".to_string(),
decoy_fasttrack_mode: WebDecoyFastTrackMode::Off,
decoy: WebRuntimeDecoy::HttpUpstream {
decoy: Arc::new(WebRuntimeDecoy::HttpUpstream {
addr: site_addr,
authority: "decoy.internal".to_string(),
},
}),
decoy_header_secs: 1,
profiles: vec![profile.clone()],
capabilities: vec![capability].into_boxed_slice(),
@@ -81,10 +81,10 @@ async fn every_authentic_credential_placement_stays_out_of_the_upstream() {
host: "other.example.com".to_string(),
base: "/other/".to_string(),
decoy_fasttrack_mode: WebDecoyFastTrackMode::Off,
decoy: WebRuntimeDecoy::HttpUpstream {
decoy: Arc::new(WebRuntimeDecoy::HttpUpstream {
addr: site_addr,
authority: "decoy.internal".to_string(),
},
}),
decoy_header_secs: 1,
profiles: Vec::new(),
capabilities: Vec::new().into_boxed_slice(),
+2 -2
View File
@@ -198,10 +198,10 @@ async fn decoy_forwarding_preserves_every_reference_request_target() {
host: previous.host.clone(),
base: previous.base.clone(),
decoy_fasttrack_mode: previous.decoy_fasttrack_mode,
decoy: WebRuntimeDecoy::HttpUpstream {
decoy: Arc::new(WebRuntimeDecoy::HttpUpstream {
addr: site_addr,
authority: "decoy.internal".to_string(),
},
}),
decoy_header_secs: 1,
profiles: previous.profiles.clone(),
capabilities: previous.capabilities.clone(),
+1 -1
View File
@@ -46,7 +46,7 @@ where
.boxed_unsync()
};
let request = Request::from_parts(parts, body);
match &vhost.decoy {
match vhost.decoy.as_ref() {
WebRuntimeDecoy::StaticDirectory(site) => {
let mut response = serve_static(request, site);
if sanitize_transport {
+2 -2
View File
@@ -16,10 +16,10 @@ async fn decoy_dns_pinned_socket_keeps_configured_hostname_in_actual_http_reques
let snapshot = Arc::get_mut(config.web.runtime.as_mut().unwrap()).unwrap();
let vhost = Arc::get_mut(snapshot.vhosts.get_mut("proxy.example.com").unwrap()).unwrap();
// A public hostname deliberately paired with a loopback socket proves no request-time lookup.
vhost.decoy = WebRuntimeDecoy::HttpUpstream {
vhost.decoy = Arc::new(WebRuntimeDecoy::HttpUpstream {
addr: origin.local_addr().unwrap(),
authority: "bsi.bund.de:8080".to_string(),
};
});
let generation = test_runtime_generation(1, config);
let runtime = WebProcessRuntime::start(Arc::new(ArcSwap::from(generation.clone())));
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
+2 -2
View File
@@ -67,10 +67,10 @@ async fn observe_http_origin(
let mut config = runtime_config_with_fasttrack(capability, WebCarrier::Https, mode);
let runtime_config = Arc::get_mut(config.web.runtime.as_mut().unwrap()).unwrap();
let vhost = Arc::get_mut(runtime_config.vhosts.get_mut("proxy.example.com").unwrap()).unwrap();
vhost.decoy = WebRuntimeDecoy::HttpUpstream {
vhost.decoy = Arc::new(WebRuntimeDecoy::HttpUpstream {
addr: origin.local_addr().unwrap(),
authority: "decoy.example".to_string(),
};
});
let generation = test_runtime_generation(1, config);
let active_runtime = Arc::new(ArcSwap::from(Arc::clone(&generation)));
let runtime = WebProcessRuntime::start(active_runtime);
+71
View File
@@ -0,0 +1,71 @@
use super::*;
use std::hint::black_box;
use std::time::Instant;
fn memory() -> (u64, u64) {
let smaps = std::fs::read_to_string("/proc/self/smaps_rollup").unwrap();
let value = |name: &str| {
smaps
.lines()
.find_map(|line| line.strip_prefix(name))
.unwrap()
.split_whitespace()
.next()
.unwrap()
.parse::<u64>()
.unwrap()
};
(value("Rss:"), value("Anonymous:"))
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[ignore = "manual matched before/after source-snapshot measurement"]
async fn matched_host_group_probe() {
let path = std::env::var("TELEMT_F1_PROBE_CONFIG").unwrap();
let before = memory();
let started = Instant::now();
let mut config = ProxyConfig::load(std::path::Path::new(&path)).unwrap();
let load_us = started.elapsed().as_micros();
black_box(&config);
let after = memory();
let snapshot = config.web.runtime.as_ref().unwrap();
let host_count = snapshot.vhosts.len();
let profile_count = snapshot.profiles.len();
let profile = &snapshot.profiles[0];
let host = profile.host.clone();
let cap = base64::engine::general_purpose::URL_SAFE_NO_PAD.encode(profile.capability);
let base = snapshot.vhosts[&host].base.clone();
config.web.limits.max_bootstraps_per_ip = 512;
let generation = test_runtime_generation(1, config);
generation.proxy_shared.apply_user_config(
&generation.config().access.users,
&std::collections::HashMap::new(),
);
let runtime = WebProcessRuntime::start(Arc::new(ArcSwap::from(generation.clone())));
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let raw = format!("GET {base}?bridge={cap} HTTP/1.1\r\nHost: {host}\r\nX-Forwarded-For: 192.0.2.10\r\nConnection: close\r\n\r\n").into_bytes();
let mut samples = Vec::new();
for index in 0..110 {
let started = Instant::now();
let response = request(&listener, &runtime, raw.clone()).await;
let elapsed = started.elapsed().as_micros();
assert!(response.starts_with(b"HTTP/1.1 200"));
if index >= 10 {
samples.push(elapsed);
}
}
samples.sort_unstable();
println!(
"F1_PROBE {}",
serde_json::json!({
"load_us": load_us, "rss_kib": after.0, "anonymous_kib": after.1,
"rss_delta_kib": after.0 as i64 - before.0 as i64,
"anonymous_delta_kib": after.1 as i64 - before.1 as i64,
"hosts": host_count, "profiles": profile_count,
"bridge_p50_us": samples[50], "bridge_p95_us": samples[95]
})
);
runtime.shutdown().await;
generation.stop_sessions().await;
generation.stop_background_tasks().await;
}
+350
View File
@@ -0,0 +1,350 @@
use super::*;
use crate::maestro::generation::RuntimeGeneration;
use crate::web::manager::{BridgeDiagnosticEvent, CarrierRequest, ManagerError, TokenHash};
use sha2::{Digest, Sha256};
use std::collections::HashMap;
// Admission and generation identity use the same parsed configuration as HTTP routing.
#[path = "host_list_tests/sessions.rs"]
mod sessions;
const HOSTS: [&str; 2] = ["a.example.com", "b.example.com"];
const SELECTOR: &str = "hosts = [\"a.example.com\", \"b.example.com\"]";
fn source(selector: &str, origin: std::net::SocketAddr) -> String {
format!(
r#"
[access.users]
alice = "000102030405060708090a0b0c0d0e0f"
[[server.listeners]]
ip = "127.0.0.1"
port = 18080
transport = "web"
web_trusted_proxy_cidrs = ["127.0.0.1/32"]
[web]
enabled = true
carrier = "https"
[[web.vhosts]]
{selector}
base_path = "relay"
public_addr = "203.0.113.10:443"
[web.vhosts.decoy]
mode = "http_upstream"
upstream = "http://{origin}"
[[web.vhosts.profiles]]
user = "alice"
secret_mode = "plain"
max_sessions = 1
max_streams = 1
max_streams_per_session = 1
"#
)
}
fn generation(id: u64, text: &str) -> Arc<RuntimeGeneration> {
let directory = tempfile::tempdir().unwrap();
let path = directory.path().join("config.toml");
std::fs::write(&path, text).unwrap();
let generation = test_runtime_generation(id, ProxyConfig::load(&path).unwrap());
generation
.proxy_shared
.apply_user_config(&generation.config().access.users, &HashMap::new());
generation
}
fn profile(runtime: &WebProcessRuntime, host: &str) -> Arc<WebRuntimeProfile> {
runtime
.active_generation()
.config()
.web
.runtime
.as_ref()
.unwrap()
.vhosts[host]
.profiles[0]
.clone()
}
fn token_hash(token: &str) -> TokenHash {
Sha256::digest(
base64::engine::general_purpose::URL_SAFE_NO_PAD
.decode(token)
.unwrap(),
)
.into()
}
fn raw_request(method: &str, path: &str, host: &str, headers: &str, body: &[u8]) -> Vec<u8> {
let mut raw = format!(
"{method} {path} HTTP/1.1\r\nHost: {host}\r\nX-Forwarded-For: 192.0.2.10\r\n{headers}Content-Length: {}\r\nConnection: close\r\n\r\n", body.len()
).into_bytes();
raw.extend_from_slice(body);
raw
}
fn bootstrap(runtime: &Arc<WebProcessRuntime>, host: &str) -> String {
runtime
.issue_bootstrap(profile(runtime, host), "192.0.2.10".parse().unwrap())
.unwrap()
.token
}
fn create(
runtime: &Arc<WebProcessRuntime>,
host: &str,
bootstrap: &str,
) -> Result<String, ManagerError> {
runtime
.create_session(
token_hash(bootstrap),
host,
"192.0.2.10".parse().unwrap(),
&frame::encode(FrameType::Hello, 0, &[1]),
CarrierRequest::legacy([0; 32]),
false,
)
.map(|created| created.token)
}
fn assert_private(response: &[u8]) {
let (headers, body) = split_response(response);
assert!(
headers.starts_with(b"HTTP/1.1 404"),
"{}",
String::from_utf8_lossy(response)
);
assert_eq!(response_header(headers, "cache-control"), "no-store");
assert_eq!(body, b"not found\n");
}
async fn stop(runtime: Arc<WebProcessRuntime>, generations: &[Arc<RuntimeGeneration>]) {
runtime.shutdown().await;
for generation in generations {
generation.stop_sessions().await;
generation.stop_background_tasks().await;
}
}
#[tokio::test]
async fn grouped_hosts_contain_credentials_in_every_fasttrack_mode() {
for mode in ["off", "shadow", "enforce"] {
let site = TcpListener::bind("127.0.0.1:0").await.unwrap();
let text = source(SELECTOR, site.local_addr().unwrap()).replace(
"enabled = true",
&format!("enabled = true\ndecoy_fasttrack_mode = \"{mode}\""),
);
let generation = generation(1, &text);
let runtime = WebProcessRuntime::start(Arc::new(ArcSwap::from(generation.clone())));
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
for (owner, other) in [(HOSTS[0], HOSTS[1]), (HOSTS[1], HOSTS[0])] {
let capability = base64::engine::general_purpose::URL_SAFE_NO_PAD
.encode(profile(&runtime, owner).capability);
let response = request(
&listener,
&runtime,
raw_request(
"GET",
&format!("/relay/?bridge={capability}"),
owner,
"",
&[],
),
)
.await;
assert!(response.starts_with(b"HTTP/1.1 200"));
let body = std::str::from_utf8(split_response(&response).1).unwrap();
let bootstrap = body
.split_once("bootstrap=\"")
.unwrap()
.1
.split_once('"')
.unwrap()
.0
.to_string();
let hello = frame::encode(FrameType::Hello, 0, &[1]);
let auth = format!(
"Authorization: Bearer {bootstrap}\r\nContent-Type: application/octet-stream\r\n"
);
assert_private(
&request(
&listener,
&runtime,
raw_request("POST", "/relay/api/v1/session", other, &auth, &hello),
)
.await,
);
let response = request(
&listener,
&runtime,
raw_request("POST", "/relay/api/v1/session", owner, &auth, &hello),
)
.await;
assert!(response.starts_with(b"HTTP/1.1 200"));
let session =
response_header(split_response(&response).0, "x-session-token").to_string();
assert!(matches!(
runtime.get_session(token_hash(&session), other),
Err(ManagerError::Authentication)
));
assert_eq!(
runtime.close_token(token_hash(&session), other, None),
Err(ManagerError::Authentication)
);
assert!(
runtime
.bootstrap_trace_identity(token_hash(&bootstrap), other)
.is_none()
);
assert_eq!(
runtime.claim_bridge_diagnostic(
token_hash(&bootstrap),
other,
BridgeDiagnosticEvent::RuntimeStarted
),
Err(ManagerError::Authentication)
);
for secret in [&capability, &bootstrap, &session] {
let encoded = secret
.bytes()
.map(|byte| format!("%{byte:02X}"))
.collect::<String>();
for path in [
format!("/relay/?bridge={secret}"),
format!("/wrong/{secret}"),
format!("/wrong/{encoded}"),
format!("/wrong?opaque={secret}"),
] {
assert_private(
&request(
&listener,
&runtime,
raw_request("GET", &path, other, "", &[]),
)
.await,
);
}
let head = request(
&listener,
&runtime,
raw_request(
"HEAD",
"/relay/",
other,
&format!("X-Opaque: {secret}\r\n"),
&[],
),
)
.await;
assert!(head.starts_with(b"HTTP/1.1 404"));
assert_eq!(
response_header(split_response(&head).0, "cache-control"),
"no-store"
);
}
for (method, path, headers, body) in [
(
"POST",
"/relay/api/v1/up",
"X-Up-Seq: 0\r\n",
hello.as_ref(),
),
(
"POST",
"/relay/api/v1/down",
"X-Down-Cursor: 0\r\n",
&[][..],
),
("DELETE", "/relay/api/v1/session", "", &[][..]),
(
"POST",
"/relay/api/v1/diagnostic",
"Content-Type: application/json\r\n",
b"{}".as_ref(),
),
] {
let auth = format!("Authorization: Bearer {session}\r\n{headers}");
assert_private(
&request(
&listener,
&runtime,
raw_request(method, path, other, &auth, body),
)
.await,
);
}
}
for host in ["unknown.example.com", "A.EXAMPLE.COM", "a.example.com:444"] {
let response =
request(&listener, &runtime, raw_request("GET", "/", host, "", &[])).await;
assert!(response.starts_with(b"HTTP/1.1 404"));
}
assert!(
tokio::time::timeout(std::time::Duration::from_millis(30), site.accept())
.await
.is_err()
);
// A positive control ensures the origin would observe an actual fallback request.
let site_task = tokio::spawn(async move {
let (mut socket, _) = site.accept().await.unwrap();
let mut head = [0; 2048];
let read = socket.read(&mut head).await.unwrap();
assert!(
std::str::from_utf8(&head[..read])
.unwrap()
.contains("/ordinary")
);
socket
.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 4\r\nConnection: close\r\n\r\nsite")
.await
.unwrap();
});
let ordinary = request(
&listener,
&runtime,
raw_request("GET", "/ordinary", HOSTS[0], "", &[]),
)
.await;
assert_eq!(split_response(&ordinary).1, b"site");
site_task.await.unwrap();
stop(runtime, &[generation]).await;
}
}
#[tokio::test]
async fn alias_recovery_cannot_retire_a_foreign_session() {
let generation = generation(1, &source(SELECTOR, "127.0.0.1:18081".parse().unwrap()));
let runtime = WebProcessRuntime::start(Arc::new(ArcSwap::from(generation.clone())));
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let a = create(&runtime, HOSTS[0], &bootstrap(&runtime, HOSTS[0])).unwrap();
let cap = base64::engine::general_purpose::URL_SAFE_NO_PAD
.encode(profile(&runtime, HOSTS[1]).capability);
let response = request(
&listener,
&runtime,
raw_request(
"GET",
&format!("/relay/?bridge={cap}"),
HOSTS[1],
&format!(
"Accept: application/vnd.telemt.web-recovery+json\r\nAuthorization: Bearer {a}\r\n"
),
&[],
),
)
.await;
assert!(
response.starts_with(b"HTTP/1.1 200"),
"{}",
String::from_utf8_lossy(&response)
);
let value: serde_json::Value = serde_json::from_slice(split_response(&response).1).unwrap();
let recovered = value["bootstrap"].as_str().unwrap();
assert_eq!(
create(&runtime, HOSTS[0], recovered),
Err(ManagerError::Authentication)
);
let b = create(&runtime, HOSTS[1], recovered).unwrap();
assert!(runtime.get_session(token_hash(&a), HOSTS[0]).is_ok());
assert!(runtime.get_session(token_hash(&b), HOSTS[1]).is_ok());
stop(runtime, &[generation]).await;
}
+211
View File
@@ -0,0 +1,211 @@
use super::*;
use tokio::sync::Barrier;
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn per_host_quotas_survive_concurrent_creation_and_generation_swaps() {
let source = source(SELECTOR, "127.0.0.1:18081".parse().unwrap());
let initial = generation(1, &source);
let runtime = WebProcessRuntime::start(Arc::new(ArcSwap::from(initial.clone())));
let mut generations = vec![initial];
for id in 2..=9 {
let selector = if id % 2 == 0 {
"hosts = [\"b.example.com\", \"a.example.com\"]"
} else {
SELECTOR
};
generations.push(generation(id, &source.replace(SELECTOR, selector)));
}
let barrier = Arc::new(Barrier::new(34));
let mut tasks = Vec::new();
for host in HOSTS {
for _ in 0..16 {
let token = bootstrap(&runtime, host);
let runtime = runtime.clone();
let barrier = barrier.clone();
tasks.push(tokio::spawn(async move {
barrier.wait().await;
(host, create(&runtime, host, &token))
}));
}
}
let reloader = {
let runtime = runtime.clone();
let barrier = barrier.clone();
let generations = generations[1..].to_vec();
tokio::spawn(async move {
barrier.wait().await;
for generation in generations {
runtime.activate_generation(generation);
tokio::task::yield_now().await;
}
})
};
barrier.wait().await;
let mut accepted = Vec::new();
for task in tasks {
let (host, result) = task.await.unwrap();
match result {
Ok(token) => accepted.push((host, token)),
Err(error) => assert_eq!(error, ManagerError::Limit),
}
}
reloader.await.unwrap();
assert_eq!(accepted.len(), 2);
for host in HOSTS {
assert_eq!(
accepted.iter().filter(|(owner, _)| *owner == host).count(),
1
);
}
let sessions: Vec<_> = accepted
.iter()
.map(|(host, token)| runtime.get_session(token_hash(token), host).unwrap())
.collect();
assert_ne!(sessions[0].profile_key(), sessions[1].profile_key());
assert_eq!(
serde_json::to_value(runtime.try_status()).unwrap()["manager"]["profiles"],
2
);
let barrier = Arc::new(Barrier::new(33));
let mut tasks = Vec::new();
let ip = "192.0.2.10".parse().unwrap();
let addr = "203.0.113.10:443".parse().unwrap();
for session in &sessions {
let key = session.profile_key();
for _ in 0..16 {
let runtime = runtime.clone();
let barrier = barrier.clone();
tasks.push(tokio::spawn(async move {
barrier.wait().await;
(key, runtime.try_acquire_stream(key, 1, ip, addr))
}));
}
}
barrier.wait().await;
let mut ports = Vec::new();
for task in tasks {
let (key, result) = task.await.unwrap();
match result {
Ok(port) => ports.push((key, port)),
Err(error) => assert_eq!(error, ManagerError::Limit),
}
}
assert_eq!(ports.len(), 2);
assert_ne!(ports[0].0, ports[1].0);
assert_eq!(
serde_json::to_value(runtime.try_status()).unwrap()["streams"]["profiles"],
2
);
for (key, port) in ports {
runtime.release_stream(key, ip, addr, port);
}
assert_eq!(
serde_json::to_value(runtime.try_status()).unwrap()["streams"]["profiles"],
0
);
stop(runtime, &generations).await;
}
#[tokio::test]
async fn regrouping_preserves_live_quota_and_bootstrap_when_limits_change() {
let grouped = source(SELECTOR, "127.0.0.1:18081".parse().unwrap());
let (prefix, group) = grouped.split_once("[[web.vhosts]]").unwrap();
let separate = format!(
"{prefix}[[web.vhosts]]{}\n[[web.vhosts]]{}",
group.replace(SELECTOR, "host = \"a.example.com\""),
group.replace(SELECTOR, "host = \"b.example.com\"")
);
let initial = generation(1, &separate);
let runtime = WebProcessRuntime::start(Arc::new(ArcSwap::from(initial.clone())));
let a = create(&runtime, HOSTS[0], &bootstrap(&runtime, HOSTS[0])).unwrap();
let key = runtime
.get_session(token_hash(&a), HOSTS[0])
.unwrap()
.profile_key();
let unused_b = bootstrap(&runtime, HOSTS[1]);
let next = generation(
2,
&grouped
.replace(SELECTOR, "hosts = [\"b.example.com\", \"a.example.com\"]")
.replace("max_sessions = 1", "max_sessions = 2"),
);
runtime.activate_generation(next.clone());
let b = create(&runtime, HOSTS[1], &unused_b).unwrap();
assert_eq!(
runtime
.get_session(token_hash(&a), HOSTS[0])
.unwrap()
.profile_key(),
key
);
let second_a = create(&runtime, HOSTS[0], &bootstrap(&runtime, HOSTS[0])).unwrap();
assert_eq!(
runtime
.get_session(token_hash(&second_a), HOSTS[0])
.unwrap()
.profile_key(),
key
);
assert_eq!(
create(&runtime, HOSTS[0], &bootstrap(&runtime, HOSTS[0])),
Err(ManagerError::Limit)
);
let stale_b = bootstrap(&runtime, HOSTS[1]);
let removed = generation(
3,
&grouped
.replace(SELECTOR, "hosts = [\"a.example.com\"]")
.replace("max_sessions = 1", "max_sessions = 2"),
);
runtime.activate_generation(removed.clone());
assert_eq!(
create(&runtime, HOSTS[1], &stale_b),
Err(ManagerError::Authentication)
);
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let response = request(
&listener,
&runtime,
raw_request("GET", "/relay/", HOSTS[1], "", &[]),
)
.await;
assert!(response.starts_with(b"HTTP/1.1 404"));
assert!(runtime.get_session(token_hash(&a), HOSTS[0]).is_ok());
assert!(runtime.get_session(token_hash(&b), HOSTS[1]).is_ok());
assert_eq!(
create(&runtime, HOSTS[0], &bootstrap(&runtime, HOSTS[0])),
Err(ManagerError::Limit)
);
stop(runtime, &[initial, next, removed]).await;
}
#[tokio::test]
async fn grouped_profiles_keep_process_and_ip_session_limits() {
for global in [1, 2] {
let text = format!(
"{}\n[web.limits]\nmax_sessions_global = {global}\nmax_sessions_per_ip = 1\n",
source(SELECTOR, "127.0.0.1:18081".parse().unwrap())
);
let generation = generation(1, &text);
let runtime = WebProcessRuntime::start(Arc::new(ArcSwap::from(generation.clone())));
create(&runtime, HOSTS[0], &bootstrap(&runtime, HOSTS[0])).unwrap();
let b = bootstrap(&runtime, HOSTS[1]);
assert_eq!(create(&runtime, HOSTS[1], &b), Err(ManagerError::Limit));
let result = runtime.create_session(
token_hash(&b),
HOSTS[1],
"192.0.2.11".parse().unwrap(),
&frame::encode(FrameType::Hello, 0, &[1]),
CarrierRequest::legacy([0; 32]),
false,
);
if global == 1 {
assert!(matches!(result, Err(ManagerError::Limit)));
} else {
assert!(result.is_ok());
}
stop(runtime, &[generation]).await;
}
}
+4 -4
View File
@@ -83,7 +83,7 @@ pub(super) fn response(
carrier_batch_bytes: limits.carrier_batch_bytes,
pending_bytes_per_session: limits.pending_bytes_per_session,
pending_items_per_session: limits.pending_items_per_session,
max_streams_per_session: profile.max_streams_per_session,
max_streams_per_session: profile.shared.max_streams_per_session,
},
timeouts: RecoveryTimeouts {
long_poll_secs: timeouts.long_poll_secs,
@@ -94,9 +94,9 @@ pub(super) fn response(
reconnect_grace_secs: timeouts.reconnect_grace_secs,
},
negotiation: RecoveryNegotiation {
enabled: profile.carrier_negotiation_enabled,
candidate_count: profile.carriers.len(),
deadlines_secs: profile.carrier_negotiation_deadlines_secs,
enabled: profile.shared.carrier_negotiation_enabled,
candidate_count: profile.shared.carriers.len(),
deadlines_secs: profile.shared.carrier_negotiation_deadlines_secs,
carrier_probe_coalesce_ms: timeouts.carrier_probe_coalesce_ms,
},
};
+25 -15
View File
@@ -127,20 +127,22 @@ fn runtime_config_with_carriers_and_deadlines(
) -> ProxyConfig {
let profile = Arc::new(WebRuntimeProfile {
host: "proxy.example.com".to_string(),
public_addr: "203.0.113.10:443".parse().unwrap(),
user: "alice".to_string(),
secret_mode: WebSecretMode::Plain,
carrier,
carrier_negotiation_enabled,
carrier_learning,
carriers: Arc::clone(&carriers),
carrier_negotiation_deadlines_secs,
capability,
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 4,
max_streams: 16,
max_streams_per_session: 4,
shared: Arc::new(crate::config::WebRuntimeProfileShared {
public_addr: "203.0.113.10:443".parse().unwrap(),
user: "alice".to_string(),
secret_mode: WebSecretMode::Plain,
carrier,
carrier_negotiation_enabled,
carrier_learning,
carriers: Arc::clone(&carriers),
carrier_negotiation_deadlines_secs,
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 4,
max_streams: 16,
max_streams_per_session: 4,
}),
});
let mut assets = BTreeMap::new();
assets.insert(
@@ -159,7 +161,7 @@ fn runtime_config_with_carriers_and_deadlines(
host: "proxy.example.com".to_string(),
base: base.to_string(),
decoy_fasttrack_mode: WebDecoyFastTrackMode::Off,
decoy: WebRuntimeDecoy::StaticDirectory(Arc::clone(&site)),
decoy: Arc::new(WebRuntimeDecoy::StaticDirectory(Arc::clone(&site))),
decoy_header_secs: 1,
profiles: vec![Arc::clone(&profile)],
capabilities: vec![capability].into_boxed_slice(),
@@ -172,7 +174,7 @@ fn runtime_config_with_carriers_and_deadlines(
host: "other.example.com".to_string(),
base: "/".to_string(),
decoy_fasttrack_mode: WebDecoyFastTrackMode::Off,
decoy: WebRuntimeDecoy::StaticDirectory(site),
decoy: Arc::new(WebRuntimeDecoy::StaticDirectory(site)),
decoy_header_secs: 1,
profiles: Vec::new(),
capabilities: Vec::new().into_boxed_slice(),
@@ -547,3 +549,11 @@ async fn https_lanes_is_advertised_and_requires_canonical_lane_headers() {
generation.stop_sessions().await;
generation.stop_background_tasks().await;
}
// Exercise loaded host groups through real HTTP and process-owned admission.
#[path = "host_list_tests.rs"]
mod host_list_tests;
// Manual matched measurements keep timing assertions out of deterministic regressions.
#[path = "host_list_benchmarks.rs"]
mod host_list_benchmarks;
+1 -1
View File
@@ -57,7 +57,7 @@ impl WebProcessRuntime {
carrier: session.carrier(),
attempt: entry.carrier_attempt,
candidate_count: u8::try_from(entry.carrier_candidates.len()).unwrap_or(4),
deadline_secs: entry.profile.carrier_negotiation_deadlines_secs[3],
deadline_secs: entry.profile.shared.carrier_negotiation_deadlines_secs[3],
state: if entry.carrier_phase == CarrierChainPhase::Provisional
&& session.is_carrier_committed()
{
+1 -1
View File
@@ -136,7 +136,7 @@ impl WebProcessRuntime {
};
let Some(mut user_publication) = generation
.proxy_shared
.claim_authenticated_user(&profile.user, profile.credential_id)
.claim_authenticated_user(&profile.shared.user, profile.shared.credential_id)
else {
self.telemetry
.record_rejection(WebRejectionReason::UserDisabled);
+1 -1
View File
@@ -23,7 +23,7 @@ pub(super) fn admit_initial(
.get(&profile_key)
.copied()
.unwrap_or(0)
>= profile.max_sessions
>= profile.shared.max_sessions
{
runtime.record_limit_hit();
runtime
+21 -17
View File
@@ -132,7 +132,7 @@ impl WebProcessRuntime {
candidate_count: automatic
.then(|| u8::try_from(entry.carrier_candidates.len()).unwrap_or(4)),
deadline_secs: automatic
.then_some(entry.profile.carrier_negotiation_deadlines_secs[3]),
.then_some(entry.profile.shared.carrier_negotiation_deadlines_secs[3]),
carrier_state: automatic.then_some(carrier_state),
};
let identity = session.trace_identity();
@@ -180,7 +180,7 @@ impl WebProcessRuntime {
if entry.carrier_started_at.is_some_and(|started| {
now.saturating_duration_since(started)
>= Duration::from_secs(
entry.profile.carrier_negotiation_deadlines_secs[deadline_index],
entry.profile.shared.carrier_negotiation_deadlines_secs[deadline_index],
)
}) {
return Err(ManagerError::Protocol);
@@ -225,14 +225,18 @@ impl WebProcessRuntime {
.runtime
.as_ref()
.and_then(|runtime| matching_profile(runtime, &issued_profile))
.filter(|profile| generation.proxy_shared.is_user_enabled(&profile.user))
.filter(|profile| {
generation
.proxy_shared
.is_user_enabled(&profile.shared.user)
})
.ok_or(ManagerError::Authentication)?;
let profile_key = profile_key(&profile);
if carrier_request.is_automatic() && !profile.carrier_negotiation_enabled {
if carrier_request.is_automatic() && !profile.shared.carrier_negotiation_enabled {
return Err(ManagerError::Protocol);
}
let capability_selection =
carrier_request.uses_capabilities() && profile.carrier_negotiation_enabled;
carrier_request.uses_capabilities() && profile.shared.carrier_negotiation_enabled;
let learning_policy = (
config.web.carrier_negotiation_enabled() && config.web.carrier_learning,
config.web.carrier_negotiation_aggressiveness,
@@ -240,7 +244,7 @@ impl WebProcessRuntime {
Duration::from_secs(config.web.timeouts.carrier_health_secs),
);
let (candidates, scores, learning_epoch, learning_disposition) =
if capability_selection && profile.carrier_learning && learning_policy.0 {
if capability_selection && profile.shared.carrier_learning && learning_policy.0 {
let learning = self.learning.lock();
match learning.epoch_for_policy(
generation.id,
@@ -252,7 +256,7 @@ impl WebProcessRuntime {
super::learning::CarrierLearningEpoch::Ready(epoch) => {
let (candidates, scores) = learning.rank(
now,
&profile.carriers,
&profile.shared.carriers,
carrier_request,
profile_key,
client_ip,
@@ -266,13 +270,13 @@ impl WebProcessRuntime {
(candidates, scores, Some(epoch), disposition)
}
super::learning::CarrierLearningEpoch::Pending => (
supported_candidates(&profile.carriers, carrier_request),
supported_candidates(&profile.shared.carriers, carrier_request),
[0; 4],
None,
WebCarrierSelectionDisposition::PolicyPending,
),
super::learning::CarrierLearningEpoch::Exhausted => (
supported_candidates(&profile.carriers, carrier_request),
supported_candidates(&profile.shared.carriers, carrier_request),
[0; 4],
None,
WebCarrierSelectionDisposition::EpochExhausted,
@@ -280,7 +284,7 @@ impl WebProcessRuntime {
}
} else if capability_selection {
(
supported_candidates(&profile.carriers, carrier_request),
supported_candidates(&profile.shared.carriers, carrier_request),
[0; 4],
None,
if learning_policy.0 {
@@ -290,12 +294,12 @@ impl WebProcessRuntime {
},
)
} else if carrier_request.uses_capabilities()
&& !carrier_request.supports(profile.carrier)
&& !carrier_request.supports(profile.shared.carrier)
{
return Err(ManagerError::Protocol);
} else {
(
vec![profile.carrier],
vec![profile.shared.carrier],
[0; 4],
None,
WebCarrierSelectionDisposition::ProfileDisabled,
@@ -307,7 +311,7 @@ impl WebProcessRuntime {
let _operator_admission = self.try_operator_admission()?;
let Some(mut user_publication) = generation
.proxy_shared
.claim_authenticated_user(&profile.user, profile.credential_id)
.claim_authenticated_user(&profile.shared.user, profile.shared.credential_id)
else {
return Err(ManagerError::Closed);
};
@@ -328,9 +332,9 @@ impl WebProcessRuntime {
.record_rejection(crate::web::telemetry::WebRejectionReason::SessionCapacity);
return Err(ManagerError::Limit);
};
let carrier_deadline_at = carrier_request
.is_automatic()
.then_some(now + Duration::from_secs(profile.carrier_negotiation_deadlines_secs[3]));
let carrier_deadline_at = carrier_request.is_automatic().then_some(
now + Duration::from_secs(profile.shared.carrier_negotiation_deadlines_secs[3]),
);
let learning_context = learning_epoch.map(|epoch| CarrierLearningContext {
profile_key,
client_ip,
@@ -412,7 +416,7 @@ impl WebProcessRuntime {
candidate_count: carrier_request.is_automatic().then_some(candidate_count),
deadline_secs: carrier_request
.is_automatic()
.then_some(profile.carrier_negotiation_deadlines_secs[3]),
.then_some(profile.shared.carrier_negotiation_deadlines_secs[3]),
carrier_state: carrier_request
.is_automatic()
.then_some(CarrierChainPhase::Provisional.as_str()),
@@ -45,10 +45,10 @@ impl WebProcessRuntime {
self.cancel_replacement(bootstrap_hash, &replacement.old_session);
return Err(ManagerError::Closed);
}
let Some(mut user_publication) = generation
.proxy_shared
.claim_authenticated_user(&replacement.profile.user, replacement.profile.credential_id)
else {
let Some(mut user_publication) = generation.proxy_shared.claim_authenticated_user(
&replacement.profile.shared.user,
replacement.profile.shared.credential_id,
) else {
drop(state);
self.cancel_replacement(bootstrap_hash, &replacement.old_session);
return Err(ManagerError::Closed);
@@ -75,7 +75,7 @@ impl WebProcessRuntime {
self.cancel_replacement(bootstrap_hash, &replacement.old_session);
return Err(ManagerError::Limit);
};
let learning_context = (replacement.profile.carrier_learning
let learning_context = (replacement.profile.shared.carrier_learning
&& replacement.learning_epoch != 0)
.then_some(CarrierLearningContext {
profile_key: replacement.profile_key,
@@ -155,7 +155,7 @@ impl WebProcessRuntime {
carrier: replacement.carrier,
attempt: Some(replacement.attempt),
candidate_count: Some(u8::try_from(entry.carrier_candidates.len()).unwrap_or(4)),
deadline_secs: Some(entry.profile.carrier_negotiation_deadlines_secs[3]),
deadline_secs: Some(entry.profile.shared.carrier_negotiation_deadlines_secs[3]),
carrier_state: Some(CarrierChainPhase::Provisional.as_str()),
};
let predecessor_session_id = entry.predecessor_session_id;
+15 -14
View File
@@ -275,9 +275,9 @@ pub(super) fn profile_key(profile: &WebRuntimeProfile) -> ProfileKey {
digest.update(WEB_PROFILE_OWNER_CONTEXT);
digest.update((profile.host.len() as u64).to_be_bytes());
digest.update(profile.host.as_bytes());
digest.update((profile.user.len() as u64).to_be_bytes());
digest.update(profile.user.as_bytes());
digest.update([match profile.secret_mode {
digest.update((profile.shared.user.len() as u64).to_be_bytes());
digest.update(profile.shared.user.as_bytes());
digest.update([match profile.shared.secret_mode {
crate::config::WebSecretMode::Plain => 0,
crate::config::WebSecretMode::Dd => 1,
}]);
@@ -294,18 +294,19 @@ pub(super) fn matching_profile(
.iter()
.find(|profile| {
profile.host == expected.host
&& profile.public_addr == expected.public_addr
&& profile.user == expected.user
&& profile.credential_id == expected.credential_id
&& profile.secret_mode == expected.secret_mode
&& profile.carrier == expected.carrier
&& profile.carrier_negotiation_enabled == expected.carrier_negotiation_enabled
&& profile.carrier_learning == expected.carrier_learning
&& profile.carriers == expected.carriers
&& profile.carrier_negotiation_deadlines_secs
== expected.carrier_negotiation_deadlines_secs
&& profile.shared.public_addr == expected.shared.public_addr
&& profile.shared.user == expected.shared.user
&& profile.shared.credential_id == expected.shared.credential_id
&& profile.shared.secret_mode == expected.shared.secret_mode
&& profile.shared.carrier == expected.shared.carrier
&& profile.shared.carrier_negotiation_enabled
== expected.shared.carrier_negotiation_enabled
&& profile.shared.carrier_learning == expected.shared.carrier_learning
&& profile.shared.carriers == expected.shared.carriers
&& profile.shared.carrier_negotiation_deadlines_secs
== expected.shared.carrier_negotiation_deadlines_secs
&& profile.capability == expected.capability
&& profile.key_fingerprint == expected.key_fingerprint
&& profile.shared.key_fingerprint == expected.shared.key_fingerprint
})
.cloned()
}
+15 -13
View File
@@ -19,20 +19,22 @@ impl Fixture {
authority,
profile: Arc::new(WebRuntimeProfile {
host: "proxy.example.com".to_string(),
public_addr: "203.0.113.10:443".parse().unwrap(),
user: "alice".to_string(),
secret_mode: WebSecretMode::Plain,
carrier: WebCarrier::Https,
carrier_negotiation_enabled: false,
carrier_learning: true,
carriers: Arc::from([WebCarrier::Https]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
capability: [7; 32],
credential_id: credential_id_from_hex(secret).unwrap(),
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 1024,
max_streams: 1024,
max_streams_per_session: 1,
shared: Arc::new(crate::config::WebRuntimeProfileShared {
public_addr: "203.0.113.10:443".parse().unwrap(),
user: "alice".to_string(),
secret_mode: WebSecretMode::Plain,
carrier: WebCarrier::Https,
carrier_negotiation_enabled: false,
carrier_learning: true,
carriers: Arc::from([WebCarrier::Https]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
credential_id: credential_id_from_hex(secret).unwrap(),
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 1024,
max_streams: 1024,
max_streams_per_session: 1,
}),
}),
}
}
+4 -4
View File
@@ -168,7 +168,7 @@ impl WebSession {
manager.release_stream(
self.profile_key,
self.client_ip,
self.profile.public_addr,
self.profile.shared.public_addr,
peer_port,
);
}
@@ -311,8 +311,8 @@ async fn run_stream(
peer,
&deps.config,
&replay_checker,
&session.profile.user,
session.profile.secret_mode,
&session.profile.shared.user,
session.profile.shared.secret_mode,
&deps.shared,
)
.await,
@@ -373,7 +373,7 @@ async fn run_stream(
writer,
success,
deps,
session.profile.public_addr,
session.profile.shared.public_addr,
peer,
ConntrackClosePolicy::Suppress,
)
+18 -16
View File
@@ -66,20 +66,22 @@ fn test_runtime_with_dc(
) -> TestRuntime {
let profile = Arc::new(WebRuntimeProfile {
host: "proxy.example.com".to_string(),
public_addr: "203.0.113.10:443".parse().unwrap(),
user: "default".to_string(),
secret_mode: WebSecretMode::Plain,
carrier,
carrier_negotiation_enabled: false,
carrier_learning: true,
carriers: Arc::from([carrier]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
capability: [7; 32],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 4,
max_streams: 16,
max_streams_per_session: 4,
shared: Arc::new(crate::config::WebRuntimeProfileShared {
public_addr: "203.0.113.10:443".parse().unwrap(),
user: "default".to_string(),
secret_mode: WebSecretMode::Plain,
carrier,
carrier_negotiation_enabled: false,
carrier_learning: true,
carriers: Arc::from([carrier]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 4,
max_streams: 16,
max_streams_per_session: 4,
}),
});
let mut config = ProxyConfig::default();
config.web.enabled = true;
@@ -415,16 +417,16 @@ async fn cancellation_while_waiting_for_data_releases_stream_ownership() {
.manager
.try_acquire_stream(
runtime.session.profile_key,
runtime.session.profile.max_streams,
runtime.session.profile.shared.max_streams,
runtime.session.client_ip,
runtime.session.profile.public_addr,
runtime.session.profile.shared.public_addr,
)
.unwrap();
assert_eq!(peer_port, 1);
runtime.manager.release_stream(
runtime.session.profile_key,
runtime.session.client_ip,
runtime.session.profile.public_addr,
runtime.session.profile.shared.public_addr,
peer_port,
);
runtime.shutdown().await;
+1
View File
@@ -202,6 +202,7 @@ impl WebSession {
if existing.is_none() {
let limit = self
.profile
.shared
.max_streams_per_session
.saturating_add(self.limits.max_tombstones_per_session)
.saturating_add(1);
+15 -13
View File
@@ -21,20 +21,22 @@ fn fixture(
WebProcessRuntime::start(Arc::new(ArcSwap::from(test_runtime_generation(1, config))));
let profile = Arc::new(WebRuntimeProfile {
host: "proxy.example.com".into(),
public_addr: "203.0.113.10:443".parse().unwrap(),
user: "default".into(),
secret_mode: WebSecretMode::Plain,
carrier,
carrier_negotiation_enabled: automatic,
carrier_learning: false,
carriers: Arc::from([carrier]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
capability: [0; 32],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".into(),
max_sessions: 2,
max_streams: 2,
max_streams_per_session: 2,
shared: Arc::new(crate::config::WebRuntimeProfileShared {
public_addr: "203.0.113.10:443".parse().unwrap(),
user: "default".into(),
secret_mode: WebSecretMode::Plain,
carrier,
carrier_negotiation_enabled: automatic,
carrier_learning: false,
carriers: Arc::from([carrier]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".into(),
max_sessions: 2,
max_streams: 2,
max_streams_per_session: 2,
}),
});
let session = WebSession::new(
Arc::downgrade(&manager),
+15 -13
View File
@@ -32,20 +32,22 @@ fn session() -> (Arc<WebSession>, Arc<WebProcessRuntime>) {
let manager = WebProcessRuntime::start(Arc::new(ArcSwap::from(generation)));
let profile = Arc::new(WebRuntimeProfile {
host: "proxy.example.com".to_string(),
public_addr: SocketAddr::from(([203, 0, 113, 10], 443)),
user: "alice".to_string(),
secret_mode: WebSecretMode::Plain,
carrier: WebCarrier::Https,
carrier_negotiation_enabled: false,
carrier_learning: false,
carriers: Arc::from([WebCarrier::Https]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
capability: [0; 32],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 1,
max_streams: 1,
max_streams_per_session: 1,
shared: Arc::new(crate::config::WebRuntimeProfileShared {
public_addr: SocketAddr::from(([203, 0, 113, 10], 443)),
user: "alice".to_string(),
secret_mode: WebSecretMode::Plain,
carrier: WebCarrier::Https,
carrier_negotiation_enabled: false,
carrier_learning: false,
carriers: Arc::from([WebCarrier::Https]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 1,
max_streams: 1,
max_streams_per_session: 1,
}),
});
let timeouts = WebTimeoutsConfig {
long_poll_secs: 1,
+1
View File
@@ -101,6 +101,7 @@ impl WebSession {
}
let lane_limit = self
.profile
.shared
.max_streams_per_session
.saturating_add(self.limits.max_tombstones_per_session)
.saturating_add(1);
+15 -13
View File
@@ -47,20 +47,22 @@ fn new_session_with_automatic(
) -> Arc<WebSession> {
let profile = Arc::new(WebRuntimeProfile {
host: "proxy.example.com".to_string(),
public_addr: SocketAddr::from(([203, 0, 113, 10], 443)),
user: "alice".to_string(),
secret_mode: WebSecretMode::Plain,
carrier: WebCarrier::HttpsLanes,
carrier_negotiation_enabled: false,
carrier_learning: true,
carriers: Arc::from([WebCarrier::HttpsLanes]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
capability: [0; 32],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 1,
max_streams: 2,
max_streams_per_session: 2,
shared: Arc::new(crate::config::WebRuntimeProfileShared {
public_addr: SocketAddr::from(([203, 0, 113, 10], 443)),
user: "alice".to_string(),
secret_mode: WebSecretMode::Plain,
carrier: WebCarrier::HttpsLanes,
carrier_negotiation_enabled: false,
carrier_learning: true,
carriers: Arc::from([WebCarrier::HttpsLanes]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 1,
max_streams: 2,
max_streams_per_session: 2,
}),
});
WebSession::new(
manager,
+15 -13
View File
@@ -11,20 +11,22 @@ use crate::web::session::{SessionCloseOutcome, SessionCloseReason};
fn session(carrier: WebCarrier, deadline: Instant) -> Arc<WebSession> {
let profile = Arc::new(WebRuntimeProfile {
host: "proxy.example.com".to_string(),
public_addr: SocketAddr::from(([203, 0, 113, 10], 443)),
user: "alice".to_string(),
secret_mode: WebSecretMode::Plain,
carrier,
carrier_negotiation_enabled: true,
carrier_learning: false,
carriers: Arc::from([carrier]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
capability: [0; 32],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 1,
max_streams: 1,
max_streams_per_session: 1,
shared: Arc::new(crate::config::WebRuntimeProfileShared {
public_addr: SocketAddr::from(([203, 0, 113, 10], 443)),
user: "alice".to_string(),
secret_mode: WebSecretMode::Plain,
carrier,
carrier_negotiation_enabled: true,
carrier_learning: false,
carriers: Arc::from([carrier]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 1,
max_streams: 1,
max_streams_per_session: 1,
}),
});
WebSession::new(
std::sync::Weak::<WebProcessRuntime>::new(),
+4 -4
View File
@@ -90,8 +90,8 @@ impl WebSession {
trace_session_id: self.trace_session_id,
client_ip: self.client_ip,
host: self.profile.host.clone(),
user: self.profile.user.clone(),
key_id: self.profile.key_fingerprint.clone(),
user: self.profile.shared.user.clone(),
key_id: self.profile.shared.key_fingerprint.clone(),
carrier: self.selected_carrier,
attempt: self.carrier_attempt,
client_class: self.carrier_class.as_str(),
@@ -144,12 +144,12 @@ impl WebSession {
/// Returns the configured non-secret user label.
pub(crate) fn profile_user(&self) -> &str {
&self.profile.user
&self.profile.shared.user
}
/// Returns the configured non-secret key fingerprint.
pub(crate) fn key_id(&self) -> &str {
&self.profile.key_fingerprint
&self.profile.shared.key_fingerprint
}
}
+15 -13
View File
@@ -134,20 +134,22 @@ fn probe_waker(probe: Arc<CallbackProbe>) -> Waker {
fn session() -> Arc<WebSession> {
let profile = Arc::new(WebRuntimeProfile {
host: "proxy.example.com".to_string(),
public_addr: SocketAddr::from(([203, 0, 113, 10], 443)),
user: "alice".to_string(),
secret_mode: WebSecretMode::Plain,
carrier: WebCarrier::Https,
carrier_negotiation_enabled: false,
carrier_learning: false,
carriers: Arc::from([WebCarrier::Https]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
capability: [0; 32],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 1,
max_streams: 1,
max_streams_per_session: 1,
shared: Arc::new(crate::config::WebRuntimeProfileShared {
public_addr: SocketAddr::from(([203, 0, 113, 10], 443)),
user: "alice".to_string(),
secret_mode: WebSecretMode::Plain,
carrier: WebCarrier::Https,
carrier_negotiation_enabled: false,
carrier_learning: false,
carriers: Arc::from([WebCarrier::Https]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 1,
max_streams: 1,
max_streams_per_session: 1,
}),
});
WebSession::new(
Weak::<WebProcessRuntime>::new(),
+4 -4
View File
@@ -342,7 +342,7 @@ impl WebSession {
effects: &mut DeferredSessionEffects,
) -> Option<u16> {
let manager = self.manager.upgrade()?;
if state.active_peer_ports.len() >= self.profile.max_streams_per_session {
if state.active_peer_ports.len() >= self.profile.shared.max_streams_per_session {
manager.record_stream_rejected_reason(
crate::web::telemetry::WebRejectionReason::StreamSessionCapacity,
);
@@ -350,9 +350,9 @@ impl WebSession {
}
let (peer_port, notify) = manager.try_acquire_stream_quiet(
self.profile_key,
self.profile.max_streams,
self.profile.shared.max_streams,
self.client_ip,
self.profile.public_addr,
self.profile.shared.public_addr,
);
if let Some(notify) = notify {
effects.notify(notify);
@@ -364,7 +364,7 @@ impl WebSession {
if let Some(notify) = manager.release_stream_quiet(
self.profile_key,
self.client_ip,
self.profile.public_addr,
self.profile.shared.public_addr,
peer_port,
) {
effects.notify(notify);
+15 -13
View File
@@ -16,20 +16,22 @@ fn session() -> Arc<WebSession> {
fn session_with_automatic(automatic: bool) -> Arc<WebSession> {
let profile = Arc::new(WebRuntimeProfile {
host: "proxy.example.com".to_string(),
public_addr: SocketAddr::from(([203, 0, 113, 10], 443)),
user: "alice".to_string(),
secret_mode: WebSecretMode::Plain,
carrier: WebCarrier::Https,
carrier_negotiation_enabled: false,
carrier_learning: true,
carriers: Arc::from([WebCarrier::Https]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
capability: [0; 32],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 1,
max_streams: 1,
max_streams_per_session: 1,
shared: Arc::new(crate::config::WebRuntimeProfileShared {
public_addr: SocketAddr::from(([203, 0, 113, 10], 443)),
user: "alice".to_string(),
secret_mode: WebSecretMode::Plain,
carrier: WebCarrier::Https,
carrier_negotiation_enabled: false,
carrier_learning: true,
carriers: Arc::from([WebCarrier::Https]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 1,
max_streams: 1,
max_streams_per_session: 1,
}),
});
WebSession::new(
std::sync::Weak::<WebProcessRuntime>::new(),
+7 -7
View File
@@ -76,7 +76,7 @@ impl WebSession {
if state.closed || self.cancel.is_cancelled() {
return Err(ManagerError::Closed);
}
if state.active_peer_ports.len() >= self.profile.max_streams_per_session
if state.active_peer_ports.len() >= self.profile.shared.max_streams_per_session
|| state.streams.contains_key(&lane_id)
|| state.closing_streams.contains_key(&lane_id)
|| state.closed_streams.contains(&lane_id)
@@ -89,9 +89,9 @@ impl WebSession {
};
let (peer_port, notify) = manager.try_acquire_stream_quiet(
self.profile_key,
self.profile.max_streams,
self.profile.shared.max_streams,
self.client_ip,
self.profile.public_addr,
self.profile.shared.public_addr,
);
if let Some(notify) = notify {
effects.notify(notify);
@@ -108,7 +108,7 @@ impl WebSession {
if let Some(notify) = manager.release_stream_quiet(
self.profile_key,
self.client_ip,
self.profile.public_addr,
self.profile.shared.public_addr,
peer_port,
) {
effects.notify(notify);
@@ -122,7 +122,7 @@ impl WebSession {
if let Some(notify) = manager.release_stream_quiet(
self.profile_key,
self.client_ip,
self.profile.public_addr,
self.profile.shared.public_addr,
peer_port,
) {
effects.notify(notify);
@@ -149,7 +149,7 @@ impl WebSession {
if let Some(notify) = manager.release_stream_quiet(
self.profile_key,
self.client_ip,
self.profile.public_addr,
self.profile.shared.public_addr,
peer_port,
) {
effects.notify(notify);
@@ -395,7 +395,7 @@ impl WebSession {
manager.release_stream(
self.profile_key,
self.client_ip,
self.profile.public_addr,
self.profile.shared.public_addr,
claim.peer_port,
);
}
+33 -31
View File
@@ -48,20 +48,22 @@ impl TestRuntime {
fn runtime(admission: bool) -> TestRuntime {
let profile = Arc::new(WebRuntimeProfile {
host: "proxy.example.com".to_string(),
public_addr: "203.0.113.10:443".parse().unwrap(),
user: "default".to_string(),
secret_mode: WebSecretMode::Plain,
carrier: WebCarrier::WebsocketLanes,
carrier_negotiation_enabled: false,
carrier_learning: true,
carriers: Arc::from([WebCarrier::WebsocketLanes]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
capability: [7; 32],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 2,
max_streams: 1,
max_streams_per_session: 1,
shared: Arc::new(crate::config::WebRuntimeProfileShared {
public_addr: "203.0.113.10:443".parse().unwrap(),
user: "default".to_string(),
secret_mode: WebSecretMode::Plain,
carrier: WebCarrier::WebsocketLanes,
carrier_negotiation_enabled: false,
carrier_learning: true,
carriers: Arc::from([WebCarrier::WebsocketLanes]),
carrier_negotiation_deadlines_secs: [3, 5, 8, 12],
credential_id: [0; 16],
key_fingerprint: "0000000000000000".to_string(),
max_sessions: 2,
max_streams: 1,
max_streams_per_session: 1,
}),
});
let mut config = ProxyConfig::default();
config.web.enabled = true;
@@ -121,7 +123,7 @@ fn detach_stale_lane(runtime: &TestRuntime, reservation: &WebSocketLaneReservati
runtime.manager.release_stream(
runtime.session.profile_key,
runtime.session.client_ip,
runtime.session.profile.public_addr,
runtime.session.profile.shared.public_addr,
claim.peer_port,
);
}
@@ -171,9 +173,9 @@ async fn rejected_open_retains_stream_quota_until_lane_socket_teardown() {
.manager
.try_acquire_stream(
runtime.session.profile_key,
runtime.session.profile.max_streams,
runtime.session.profile.shared.max_streams,
runtime.session.client_ip,
runtime.session.profile.public_addr,
runtime.session.profile.shared.public_addr,
)
.is_err()
);
@@ -183,15 +185,15 @@ async fn rejected_open_retains_stream_quota_until_lane_socket_teardown() {
.manager
.try_acquire_stream(
runtime.session.profile_key,
runtime.session.profile.max_streams,
runtime.session.profile.shared.max_streams,
runtime.session.client_ip,
runtime.session.profile.public_addr,
runtime.session.profile.shared.public_addr,
)
.unwrap();
runtime.manager.release_stream(
runtime.session.profile_key,
runtime.session.client_ip,
runtime.session.profile.public_addr,
runtime.session.profile.shared.public_addr,
peer_port,
);
runtime.shutdown().await;
@@ -213,15 +215,15 @@ async fn closed_session_releases_bound_lane_quota_on_reservation_drop() {
.manager
.try_acquire_stream(
runtime.session.profile_key,
runtime.session.profile.max_streams,
runtime.session.profile.shared.max_streams,
runtime.session.client_ip,
runtime.session.profile.public_addr,
runtime.session.profile.shared.public_addr,
)
.unwrap();
runtime.manager.release_stream(
runtime.session.profile_key,
runtime.session.client_ip,
runtime.session.profile.public_addr,
runtime.session.profile.shared.public_addr,
peer_port,
);
runtime.shutdown().await;
@@ -254,15 +256,15 @@ async fn closed_session_releases_transferred_rejected_lane_quota() {
.manager
.try_acquire_stream(
runtime.session.profile_key,
runtime.session.profile.max_streams,
runtime.session.profile.shared.max_streams,
runtime.session.client_ip,
runtime.session.profile.public_addr,
runtime.session.profile.shared.public_addr,
)
.unwrap();
runtime.manager.release_stream(
runtime.session.profile_key,
runtime.session.client_ip,
runtime.session.profile.public_addr,
runtime.session.profile.shared.public_addr,
peer_port,
);
runtime.shutdown().await;
@@ -295,9 +297,9 @@ async fn closed_session_keeps_stream_owned_quota_until_task_completion() {
.manager
.try_acquire_stream(
runtime.session.profile_key,
runtime.session.profile.max_streams,
runtime.session.profile.shared.max_streams,
runtime.session.client_ip,
runtime.session.profile.public_addr,
runtime.session.profile.shared.public_addr,
)
.is_err()
);
@@ -306,15 +308,15 @@ async fn closed_session_keeps_stream_owned_quota_until_task_completion() {
.manager
.try_acquire_stream(
runtime.session.profile_key,
runtime.session.profile.max_streams,
runtime.session.profile.shared.max_streams,
runtime.session.client_ip,
runtime.session.profile.public_addr,
runtime.session.profile.shared.public_addr,
)
.unwrap();
runtime.manager.release_stream(
runtime.session.profile_key,
runtime.session.client_ip,
runtime.session.profile.public_addr,
runtime.session.profile.shared.public_addr,
peer_port,
);
runtime.shutdown().await;
@@ -475,7 +477,7 @@ async fn exact_lane_teardown_wakes_stream_after_releasing_session_lock() {
runtime.manager.release_stream(
runtime.session.profile_key,
runtime.session.client_ip,
runtime.session.profile.public_addr,
runtime.session.profile.shared.public_addr,
claim.peer_port,
);
drop(reservation);
+4 -3
View File
@@ -150,17 +150,18 @@ impl HttpTraceExchange {
/// Binds non-secret profile and process session identity.
pub(crate) fn bind_profile(&self, profile: &WebRuntimeProfile, session_id: u64) {
let dynamic = profile
.shared
.user
.len()
.saturating_add(profile.key_fingerprint.len());
.saturating_add(profile.shared.key_fingerprint.len());
let mut state = self.state.lock();
if state.phase != ExchangePhase::Open {
return;
}
state.identity.session_id = Some(session_id);
if self.reserve_locked(&mut state, dynamic) {
state.identity.user = Some(profile.user.clone());
state.identity.key_fingerprint = Some(profile.key_fingerprint.clone());
state.identity.user = Some(profile.shared.user.clone());
state.identity.key_fingerprint = Some(profile.shared.key_fingerprint.clone());
}
}
+2 -2
View File
@@ -155,8 +155,8 @@ impl TraceIdentity {
) -> Self {
Self {
session_id,
user: Some(profile.user.clone()),
key_fingerprint: Some(profile.key_fingerprint.clone()),
user: Some(profile.shared.user.clone()),
key_fingerprint: Some(profile.shared.key_fingerprint.clone()),
}
}
}