Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,27 @@ long-term supported release series.
Re-probes move the health state but add no sample to the window `leastLoad`
reads, which keeps holding the last 16 scheduled probes. Without failures
the observatory probes as before.
- `burstObservatory` is read and run as in Xray-core v26.11.9; it used to be
refused as an unknown root field. `pingConfig` takes `destination`,
`connectivity`, `interval`, `sampling`, `timeout` and `httpMethod` with
Xray-core's defaults and lower bounds. Every subject is pinged once at
start and then `sampling` times at random points of each
`interval * sampling`. `leastLoad`, `leastPing`, `random` and `roundRobin`
read Xray's burst statistics: the latest `sampling` pings no older than two
periods, alive while one of them succeeded, the average as the delay. A
failed ping is not counted while the `connectivity` URL fails too. With
`observatory` also present that one drives selection, as in Xray-core, and
`burstObservatory` is not run. The re-probes that failures of real traffic
bring belong to `observatory`: beside `burstObservatory` alone nothing
follows them, and its window stays the scheduled pings. Deliberately
different, for phones:
`interval`, `sampling` and `timeout` are capped at 24h, 100 and 60s with a
warning; at most four pings run at once; while the connectivity check fails
one ping leaves per backoff of 5s up to `interval` instead of every
scheduled one; and after a network change reported through `rebind_quic`
every subject is pinged again within 3 seconds and its first new sample
replaces the old network's. `CoreConfig` gains `burst_observatory` and
`NetworkChanges` gains `observe`.

## 0.10.1 - 2026-11-16

Expand Down
5 changes: 5 additions & 0 deletions crates/xray-bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8824,6 +8824,7 @@ fn dns_outbound_selector_probe_config(rule_count: usize) -> CoreConfig {
..Default::default()
},
observatory: None,
burst_observatory: None,
dns: Default::default(),
policy: Default::default(),
}
Expand Down Expand Up @@ -9323,6 +9324,7 @@ fn phase2_selector_config(member_count: usize) -> CoreConfig {
..RoutingConfig::default()
},
observatory: None,
burst_observatory: None,
dns: Default::default(),
policy: Default::default(),
}
Expand All @@ -9341,6 +9343,7 @@ fn phase2_chain_config(chain_depth: usize) -> CoreConfig {
default_outbound_tag: Some("chain-0000".to_owned()),
routing: RoutingConfig::default(),
observatory: None,
burst_observatory: None,
dns: Default::default(),
policy: Default::default(),
}
Expand Down Expand Up @@ -9457,6 +9460,7 @@ async fn measure_phase2_connection_registry(
default_outbound_tag: Some("direct".to_owned()),
routing: RoutingConfig::default(),
observatory: None,
burst_observatory: None,
dns: Default::default(),
policy: Default::default(),
})
Expand Down Expand Up @@ -10804,6 +10808,7 @@ fn route_probe_config(
..Default::default()
},
observatory: None,
burst_observatory: None,
dns: Default::default(),
policy: Default::default(),
})
Expand Down
7 changes: 7 additions & 0 deletions crates/xray-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ pub use model::{
UdpNoiseSettings, UdpSudoku, XdnsDomain, XdnsMask, XdnsProtocol, XdnsResolver, XicmpMask,
XmcMask, XmcProfile,
};
pub use model::{
BurstObservatoryConfig, BurstPingConfig, DEFAULT_BURST_OBSERVATORY_DESTINATION,
DEFAULT_BURST_OBSERVATORY_HTTP_METHOD, DEFAULT_BURST_OBSERVATORY_INTERVAL,
DEFAULT_BURST_OBSERVATORY_SAMPLING, DEFAULT_BURST_OBSERVATORY_TIMEOUT,
MAX_BURST_OBSERVATORY_INTERVAL, MAX_BURST_OBSERVATORY_SAMPLING, MAX_BURST_OBSERVATORY_TIMEOUT,
MIN_BURST_OBSERVATORY_INTERVAL,
};
pub use model::{MasqueOutboundSettings, MasqueSettings, MasqueWarpSettings, MASQUE_DEFAULT_XMUX};
pub use parser::{
parse_xray_json, parse_xray_json_with_exclusive_geodata_dirs, parse_xray_json_with_geodata_dir,
Expand Down
80 changes: 80 additions & 0 deletions crates/xray-config/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub struct CoreConfig {
pub default_outbound_tag: Option<String>,
pub routing: RoutingConfig,
pub observatory: Option<ObservatoryConfig>,
/// Xray's `burstObservatory`. When [`CoreConfig::observatory`] is also
/// present that one drives selection, as in Xray-core, and this is unused.
pub burst_observatory: Option<BurstObservatoryConfig>,
pub dns: DnsConfig,
pub policy: PolicyConfig,
}
Expand All @@ -66,6 +69,83 @@ pub struct ObservatoryConfig {
pub enable_concurrency: bool,
}

/// `pingConfig.destination` of a burst observatory that names none.
pub const DEFAULT_BURST_OBSERVATORY_DESTINATION: &str =
"https://connectivitycheck.gstatic.com/generate_204";
/// `pingConfig.interval` of a burst observatory that names none: the average
/// time between two pings of one outbound.
pub const DEFAULT_BURST_OBSERVATORY_INTERVAL: Duration = Duration::from_secs(60);
/// Xray-core raises a shorter nonzero `pingConfig.interval` to this.
pub const MIN_BURST_OBSERVATORY_INTERVAL: Duration = Duration::from_secs(10);
/// A longer `pingConfig.interval` is lowered to this, which keeps the
/// sampling period and the validity of a sample well inside a `Duration`.
pub const MAX_BURST_OBSERVATORY_INTERVAL: Duration = Duration::from_secs(24 * 60 * 60);
/// `pingConfig.sampling` of a burst observatory that names none.
pub const DEFAULT_BURST_OBSERVATORY_SAMPLING: u32 = 10;
/// A larger `pingConfig.sampling` is lowered to this. It bounds the memory of
/// one outbound's sample window and the pings scheduled for one period.
pub const MAX_BURST_OBSERVATORY_SAMPLING: u32 = 100;
/// `pingConfig.timeout` of a burst observatory that names none.
pub const DEFAULT_BURST_OBSERVATORY_TIMEOUT: Duration = Duration::from_secs(5);
/// A longer `pingConfig.timeout` is lowered to this, the bound of every
/// outbound URL probe.
pub const MAX_BURST_OBSERVATORY_TIMEOUT: Duration = Duration::from_secs(60);
/// `pingConfig.httpMethod` of a burst observatory that names none.
pub const DEFAULT_BURST_OBSERVATORY_HTTP_METHOD: &str = "HEAD";

/// Xray's `burstObservatory`: outbound health from a window of pings spread
/// at random over a sampling period.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BurstObservatoryConfig {
pub subject_selectors: Vec<String>,
pub ping: BurstPingConfig,
}

/// `burstObservatory.pingConfig` with Xray-core's defaults applied.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BurstPingConfig {
/// URL pinged through every observed outbound.
pub destination: String,
/// URL requested without any outbound after a failed ping. While it also
/// fails the network is taken to be down and the ping is not counted.
pub connectivity: Option<String>,
/// Average time between two pings of one outbound.
pub interval: Duration,
/// Pings of one outbound per period and the size of its sample window.
pub sampling: u32,
pub timeout: Duration,
/// Request method, sent as written.
pub http_method: String,
}

impl BurstPingConfig {
/// The time over which `sampling` pings of one outbound are spread.
#[must_use]
pub fn sampling_period(&self) -> Duration {
self.interval.saturating_mul(self.sampling)
}

/// How long a sample counts. Xray-core keeps it for two periods because
/// pings fall anywhere within one.
#[must_use]
pub fn sample_validity(&self) -> Duration {
self.sampling_period().saturating_mul(2)
}
}

impl Default for BurstPingConfig {
fn default() -> Self {
Self {
destination: DEFAULT_BURST_OBSERVATORY_DESTINATION.to_owned(),
connectivity: None,
interval: DEFAULT_BURST_OBSERVATORY_INTERVAL,
sampling: DEFAULT_BURST_OBSERVATORY_SAMPLING,
timeout: DEFAULT_BURST_OBSERVATORY_TIMEOUT,
http_method: DEFAULT_BURST_OBSERVATORY_HTTP_METHOD.to_owned(),
}
}
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct RoutingConfig {
pub rules: Vec<RoutingRule>,
Expand Down
38 changes: 4 additions & 34 deletions crates/xray-config/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod blackhole;
mod burst_observatory;
mod dns;
mod filter;
mod fragment;
Expand Down Expand Up @@ -391,6 +392,7 @@ impl Parser<'_> {
let outbounds = self.parse_outbounds();
let routing = self.parse_routing();
let observatory = self.parse_observatory();
let burst_observatory = self.parse_burst_observatory();
let dns = self.parse_dns();
let policy = self.parse_policy();
let default_outbound_tag = outbounds.first().and_then(|outbound| outbound.tag.clone());
Expand All @@ -401,6 +403,7 @@ impl Parser<'_> {
default_outbound_tag,
routing,
observatory,
burst_observatory,
dns,
policy,
}
Expand Down Expand Up @@ -515,40 +518,7 @@ impl Parser<'_> {
}
self.reject_unknown_fields(observatory, path, &surface::OBSERVATORY);

let subject_selectors = match observatory.get("subjectSelector") {
None | Some(Value::Null) => Vec::new(),
Some(Value::Array(values)) => {
if values.len() > MAX_OBSERVATORY_SUBJECT_SELECTORS {
self.error(
format!("{path}.subjectSelector"),
format!(
"observatory contains {} subject selectors; maximum supported per configuration is {MAX_OBSERVATORY_SUBJECT_SELECTORS}",
values.len()
),
);
return None;
}
let mut selectors = Vec::with_capacity(values.len());
for (index, value) in values.iter().enumerate() {
let Some(value) = value.as_str() else {
self.error(
format!("{path}.subjectSelector[{index}]"),
"observatory subject selector must be a string",
);
return None;
};
selectors.push(value.to_owned());
}
selectors
}
Some(_) => {
self.error(
format!("{path}.subjectSelector"),
"observatory subjectSelector must be an array",
);
return None;
}
};
let subject_selectors = self.parse_subject_selectors(observatory, path, "observatory")?;
let probe_url = match observatory.get("probeURL") {
None | Some(Value::Null) => DEFAULT_OBSERVATORY_PROBE_URL.to_owned(),
Some(Value::String(value)) if value.is_empty() => {
Expand Down
Loading