Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f60c11fc20 | ||
|
|
87fa83e482 |
No files matched your search
Generated
+10
-10
@@ -6300,7 +6300,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||
|
||||
[[package]]
|
||||
name = "tsunagi"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@@ -6324,7 +6324,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tsunagi-android"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"egui",
|
||||
@@ -6348,7 +6348,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tsunagi-awg"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"iroh",
|
||||
@@ -6363,7 +6363,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tsunagi-core"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
dependencies = [
|
||||
"arc-swap",
|
||||
"bytes",
|
||||
@@ -6408,7 +6408,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tsunagi-runtime"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
dependencies = [
|
||||
"data-encoding",
|
||||
"hex",
|
||||
@@ -6463,7 +6463,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tsunagi-tcp-tls"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"caps",
|
||||
@@ -6485,7 +6485,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tsunagi-tray"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
dependencies = [
|
||||
"eframe",
|
||||
"egui-phosphor",
|
||||
@@ -6501,7 +6501,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tsunagi-ui"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
dependencies = [
|
||||
"egui",
|
||||
"egui-phosphor",
|
||||
@@ -6534,7 +6534,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tsunagi-wg-quic"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
dependencies = [
|
||||
"boringtun",
|
||||
"bytes",
|
||||
@@ -6564,7 +6564,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tsunagi-wireguard"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
dependencies = [
|
||||
"boringtun",
|
||||
"bytes",
|
||||
|
||||
@@ -136,8 +136,11 @@ The **Shoes** family adds two embedded TCP carriers. `vless-xhttp` uses VLESS
|
||||
over XHTTP stream-one with HTTP/2 and pinned TLS 1.3 (preferred port 9443).
|
||||
`ss2022` uses Shadowsocks 2022 with AES-128-GCM or AES-256-GCM (9444).
|
||||
Peers agree fresh credentials over their authenticated control connection on
|
||||
every attempt. The agent runs both listeners itself. Override their ports with
|
||||
`tsng up -o vless-xhttp:port=10443 -o ss2022:port=10444`.
|
||||
every attempt. The native `tcp-tls` listener prefers TCP 9442. To use all three
|
||||
on a public server, allow inbound TCP 9442–9444. For a second agent on the
|
||||
same host, set its listeners explicitly, for example
|
||||
`tsng up -o tcp-tls:port=10442 -o vless-xhttp:port=10443 -o ss2022:port=10444`,
|
||||
and allow TCP 10442–10444 for that instance.
|
||||
|
||||
With two updated peers, `tcp-tls` and both Shoes carriers try the opposite dial
|
||||
direction if the first fails. One reachable TCP listener suffices. If neither
|
||||
@@ -163,7 +166,10 @@ buttons change it. Hover or tap the information icon for protocol details. **Sho
|
||||
Tsunagi versions. On Android, tap a device to see its version and traffic.
|
||||
|
||||
Select a peer’s speedometer in **Devices** to measure download and upload
|
||||
through its current encrypted mesh path. The cell shows live rates in Mbit/s.
|
||||
through its current encrypted mesh path. A test becomes available after a
|
||||
round trip to the peer succeeds over that path, directly or through relay
|
||||
members. The control connection coordinates the test and returns its results.
|
||||
Only packets received over the data path count towards the rate in Mbit/s.
|
||||
Select the result to test again, or use **Test exits** to check the network’s
|
||||
online, compatible exit nodes one at a time. The test ends at the peer, so its
|
||||
Internet uplink beyond that peer is outside the measurement. Hover or long-press
|
||||
@@ -182,9 +188,12 @@ initiator. These ceilings count probe IP packets before tunnel overhead.
|
||||
Adjacent peers need a common external transport at the same wire version.
|
||||
Peers that both support link comparison probe another mutually enabled transport
|
||||
while traffic continues on the current one. They can switch to a faster healthy link.
|
||||
`tsng status` and the tray show the direct data link's measured RTT separately
|
||||
from the control connection's RTT. A mesh relay's first-hop RTT cannot measure
|
||||
the round trip to the destination.
|
||||
`tsng status` and Devices show the round trip of an encrypted probe to the
|
||||
destination, including any mesh relay hops. The previous measurement stays
|
||||
visible while the next probe is in flight. Losing the route or missing two
|
||||
consecutive probes clears the measurement. Devices shows **Ready** or **Idle**
|
||||
only while the data path is confirmed and the tunnel has a usable session key.
|
||||
Control RTT is shown separately.
|
||||
Selection applies to this device's incoming and outgoing data links; control and
|
||||
discovery are independent. A relay's next hop may use a different transport.
|
||||
Every pair uses one internal WireGuard cipher, hidden from these controls.
|
||||
|
||||
@@ -24,7 +24,7 @@ android {
|
||||
targetSdk 35
|
||||
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
|
||||
versionCode providers.gradleProperty('tsunagiVersionCode').getOrElse('1').toInteger()
|
||||
versionName providers.gradleProperty('tsunagiVersionName').getOrElse('1.0.11')
|
||||
versionName providers.gradleProperty('tsunagiVersionName').getOrElse('1.0.12')
|
||||
ndk { abiFilters abi }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tsunagi-android"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
description = "Android VPN client and egui views for tsunagi."
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
@@ -16,7 +16,7 @@ name = "vpn_source_probe"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
tsunagi-runtime = { path = "../tsunagi-runtime", version = "1.0.11" }
|
||||
tsunagi-runtime = { path = "../tsunagi-runtime", version = "1.0.12" }
|
||||
tsunagi-ui = { path = "../tsunagi-ui" }
|
||||
tsunagi-core = { path = "../tsunagi-core" }
|
||||
tsunagi-wg-quic = { path = "../tsunagi-wg-quic" }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tsunagi-awg"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
description = "Ephemeral pairwise Amnezia transport for Tsunagi."
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tsunagi-core"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
description = "Small private mesh networks: persistent agent identity, deterministic network spaces, an iroh control plane, signed state and a local DNS view."
|
||||
readme = "../../README.md"
|
||||
keywords = ["mesh", "p2p", "iroh", "networking"]
|
||||
|
||||
@@ -355,6 +355,14 @@ fn data_link_backoff(failures: u32) -> Duration {
|
||||
Duration::from_secs(secs)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct PendingSpeedStart {
|
||||
peer: EndpointId,
|
||||
session: u64,
|
||||
request: tsunagi_speedtest::Start,
|
||||
received: Instant,
|
||||
}
|
||||
|
||||
struct Runtime {
|
||||
discovery_worker: Option<DiscoveryWorker>,
|
||||
discovery_candidates: mpsc::Receiver<Candidate>,
|
||||
@@ -380,6 +388,8 @@ struct Runtime {
|
||||
/// peer, which outlives any particular path.
|
||||
links: HashMap<(EndpointId, String), Arc<HealthLink>>,
|
||||
pending_health: HashMap<(EndpointId, String), HealthSettings>,
|
||||
// The initiator can finish its first data echo just before our own.
|
||||
pending_speed: Option<PendingSpeedStart>,
|
||||
comparisons: HashMap<EndpointId, selection::Schedule>,
|
||||
last_failed_protocol: HashMap<EndpointId, String>,
|
||||
/// Every data link of this network, and what is reached through what.
|
||||
@@ -509,6 +519,7 @@ impl Runtime {
|
||||
dial_results_rx,
|
||||
links: HashMap::new(),
|
||||
pending_health: HashMap::new(),
|
||||
pending_speed: None,
|
||||
comparisons: HashMap::new(),
|
||||
last_failed_protocol: HashMap::new(),
|
||||
hub,
|
||||
@@ -559,10 +570,13 @@ impl Runtime {
|
||||
// Long discovery intervals must not let live transit edges expire.
|
||||
let mut reach_refresh = tokio::time::interval(REACH_EXPIRY / 3);
|
||||
reach_refresh.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
|
||||
let mut speed_refresh = tokio::time::interval(Duration::from_millis(50));
|
||||
speed_refresh.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
|
||||
loop {
|
||||
tokio::select! {
|
||||
biased;
|
||||
_ = self.shutdown.wait() => break,
|
||||
_ = speed_refresh.tick(), if self.pending_speed.is_some() => self.retry_speed_start(),
|
||||
_ = roster.changed() => self.sync_exit_use(),
|
||||
_ = reach_refresh.tick(), if self.params.discovery_interval > REACH_EXPIRY / 3 => self.announce_reach(false),
|
||||
_ = self.hub.changed() => {
|
||||
@@ -3057,16 +3071,29 @@ impl Runtime {
|
||||
&& super::speed::supported(&session.capabilities)
|
||||
&& let Some(message) =
|
||||
tsunagi_speedtest::Control::decode(payload.as_bytes())
|
||||
&& let Some(inner) = self.params.agent.upgrade()
|
||||
&& let Some(reply) = super::speed::receive_control(
|
||||
&inner,
|
||||
self.network_id,
|
||||
peer,
|
||||
message,
|
||||
|| snapshot_connection(&session.conn).rtt,
|
||||
)
|
||||
{
|
||||
let _ = self.send_to(peer, reply);
|
||||
match message {
|
||||
tsunagi_speedtest::Control::Start(start)
|
||||
if self.pending_speed.is_none()
|
||||
&& self.overlay_rtt(peer).is_none()
|
||||
&& self.data_error(session).is_none() =>
|
||||
{
|
||||
self.pending_speed = Some(PendingSpeedStart {
|
||||
peer,
|
||||
session: session.id,
|
||||
request: start,
|
||||
received: Instant::now(),
|
||||
});
|
||||
}
|
||||
tsunagi_speedtest::Control::Cancel { id }
|
||||
if self
|
||||
.pending_speed
|
||||
.is_some_and(|p| p.peer == peer && p.request.id == id) =>
|
||||
{
|
||||
self.pending_speed = None;
|
||||
}
|
||||
_ => self.deliver_speed_control(peer, message),
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -3339,6 +3366,50 @@ impl Runtime {
|
||||
})
|
||||
}
|
||||
|
||||
fn retry_speed_start(&mut self) {
|
||||
let Some(pending) = self.pending_speed else {
|
||||
return;
|
||||
};
|
||||
let Some(session) = self.sessions.get(&pending.peer).filter(|s| {
|
||||
s.id == pending.session
|
||||
&& super::speed::supported(&s.capabilities)
|
||||
&& super::speed::supported(&self.local_capabilities)
|
||||
}) else {
|
||||
self.pending_speed = None;
|
||||
return;
|
||||
};
|
||||
// Allow one ordinary three-second echo timeout and the next probe tick.
|
||||
if pending.received.elapsed() < Duration::from_millis(3500)
|
||||
&& self.data_error(session).is_none()
|
||||
&& self.overlay_rtt(pending.peer).is_none()
|
||||
{
|
||||
return;
|
||||
}
|
||||
self.pending_speed = None;
|
||||
self.deliver_speed_control(
|
||||
pending.peer,
|
||||
tsunagi_speedtest::Control::Start(pending.request),
|
||||
);
|
||||
}
|
||||
|
||||
fn deliver_speed_control(&mut self, peer: EndpointId, message: tsunagi_speedtest::Control) {
|
||||
if let Some(inner) = self.params.agent.upgrade()
|
||||
&& let Some(reply) =
|
||||
super::speed::receive_control(&inner, self.network_id, peer, message, || {
|
||||
self.overlay_rtt(peer)
|
||||
})
|
||||
{
|
||||
let _ = self.send_to(peer, reply);
|
||||
}
|
||||
}
|
||||
|
||||
fn overlay_rtt(&self, peer: EndpointId) -> Option<Duration> {
|
||||
if self.tunnel_errors.contains_key(&peer) || !self.hub.reachable(peer) {
|
||||
return None;
|
||||
}
|
||||
self.params.routes.vips.peer_rtt(self.network_id, peer)
|
||||
}
|
||||
|
||||
fn data_error(&self, session: &Session) -> Option<String> {
|
||||
if self.params.carriers.is_empty() {
|
||||
return Some(super::DATA_DISABLED.into());
|
||||
@@ -3413,9 +3484,11 @@ impl Runtime {
|
||||
.next()
|
||||
.and_then(|kind| self.links.get(&(session.peer, kind)));
|
||||
PeerStatus {
|
||||
data_rtt: selected
|
||||
.and_then(|link| link.quality())
|
||||
.map(|quality| quality.rtt),
|
||||
data_rtt: if self.params.interface.is_some() && self.params.tunnel.is_some() {
|
||||
self.overlay_rtt(session.peer)
|
||||
} else {
|
||||
selected.and_then(|link| link.quality()).map(|q| q.rtt)
|
||||
},
|
||||
data_transport_detail: selected.map(|link| link.path_description()),
|
||||
broadcast: session.broadcast,
|
||||
exit_node: session.exit_node,
|
||||
|
||||
@@ -126,7 +126,7 @@ impl SpeedTests {
|
||||
.collect(),
|
||||
capable: peers
|
||||
.iter()
|
||||
.filter(|p| enabled && supported(&p.capabilities))
|
||||
.filter(|p| enabled && p.has_confirmed_data_path() && supported(&p.capabilities))
|
||||
.map(|p| p.endpoint_id.to_string())
|
||||
.collect(),
|
||||
}
|
||||
@@ -221,7 +221,7 @@ fn config(
|
||||
key: Key,
|
||||
id: u64,
|
||||
bytes: u32,
|
||||
rtt: Option<Duration>,
|
||||
rtt: Duration,
|
||||
) -> Option<(wire::Config, DiagnosticPeer)> {
|
||||
let addresses = inner.routes.diagnostic_peer(key.0, key.1)?;
|
||||
let ceiling = if inner.speed.metered.load(Ordering::Relaxed) {
|
||||
@@ -235,7 +235,7 @@ fn config(
|
||||
remote: addresses.remote,
|
||||
mtu: u16::try_from(inner.config.interface_mtu).unwrap_or(u16::MAX),
|
||||
byte_limit: bytes.min(ceiling),
|
||||
rtt: rtt.unwrap_or(Duration::from_millis(100)),
|
||||
rtt,
|
||||
};
|
||||
Some((cfg, addresses))
|
||||
}
|
||||
@@ -257,7 +257,11 @@ pub(super) fn receive_control(
|
||||
{
|
||||
return envelope(&wire::Control::Busy { id });
|
||||
}
|
||||
let (cfg, addresses) = config(inner, key, id, request.byte_limit, rtt())?;
|
||||
let Some((cfg, addresses)) =
|
||||
rtt().and_then(|rtt| config(inner, key, id, request.byte_limit, rtt))
|
||||
else {
|
||||
return envelope(&wire::Control::Cancel { id });
|
||||
};
|
||||
let limit = cfg.byte_limit;
|
||||
let (handle, session) = wire::respond(cfg, request);
|
||||
inner.speed.active.store(Some(Arc::new(Channel {
|
||||
@@ -430,10 +434,18 @@ impl Agent {
|
||||
.collect();
|
||||
if targets.is_empty() {
|
||||
return Err(Error::SpeedTest(
|
||||
if peer.is_some() {
|
||||
"Peer is offline or does not support this speed-test version"
|
||||
if let Some(target) = peer {
|
||||
if status
|
||||
.peers
|
||||
.iter()
|
||||
.any(|p| p.endpoint_id == target && supported(&p.capabilities))
|
||||
{
|
||||
"No confirmed data path to this peer"
|
||||
} else {
|
||||
"Peer is offline or does not support this speed-test version"
|
||||
}
|
||||
} else {
|
||||
"No online exit nodes support speed tests in this network"
|
||||
"No compatible exit nodes with a confirmed data path in this network"
|
||||
}
|
||||
.into(),
|
||||
));
|
||||
@@ -522,7 +534,7 @@ impl Agent {
|
||||
Some((_, update, started)) => update_report(report, update, started),
|
||||
None => {
|
||||
report.phase = SpeedPhase::Failed(
|
||||
"Peer is no longer eligible or its overlay address is unavailable"
|
||||
"Peer no longer has a confirmed data path or is no longer eligible"
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
@@ -577,10 +589,12 @@ async fn run_outgoing(
|
||||
};
|
||||
let status = agent.network_status(key.0).await.ok()?;
|
||||
let peer = status.peers.iter().find(|p| {
|
||||
p.endpoint_id == key.1 && (!exits_only || p.exit_node) && supported(&p.capabilities)
|
||||
p.endpoint_id == key.1
|
||||
&& (!exits_only || p.exit_node)
|
||||
&& status.speed.capable.contains(&p.endpoint_id.to_string())
|
||||
})?;
|
||||
let id = rand::random();
|
||||
let (cfg, addresses) = config(inner, key, id, limit, peer.data_rtt.or(peer.rtt))?;
|
||||
let (cfg, addresses) = config(inner, key, id, limit, peer.data_rtt?)?;
|
||||
let limit = cfg.byte_limit;
|
||||
let (handle, session) = wire::initiate(cfg);
|
||||
let io = TestIo::new(inner, key, Some(generation));
|
||||
|
||||
@@ -179,7 +179,8 @@ pub struct PeerStatus {
|
||||
pub transport: TransportKind,
|
||||
/// RTT of the selected path, when iroh reported one.
|
||||
pub rtt: Option<Duration>,
|
||||
/// Recent RTT of the selected direct data link, measured by authenticated probes.
|
||||
/// Round trip to this peer over encrypted overlay data, including relay hops.
|
||||
/// Carrier-only agents report their selected physical link's round trip.
|
||||
pub data_rtt: Option<Duration>,
|
||||
/// The selected direct data carrier's own description of its underlying path.
|
||||
pub data_transport_detail: Option<String>,
|
||||
@@ -197,6 +198,15 @@ pub struct PeerStatus {
|
||||
pub data_path: DataPath,
|
||||
}
|
||||
|
||||
impl PeerStatus {
|
||||
/// A usable route with a successful data round trip to this peer.
|
||||
pub fn has_confirmed_data_path(&self) -> bool {
|
||||
!matches!(self.data_path, DataPath::None)
|
||||
&& self.data_rtt.is_some()
|
||||
&& self.data_error.is_none()
|
||||
}
|
||||
}
|
||||
|
||||
/// Counters scoped to one logical network.
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub struct NetworkMetrics {
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
//! the encrypted inner bytes without entering an IP plugin or the TUN.
|
||||
//! Data-plane failure never stops control sessions or discovery.
|
||||
|
||||
pub use crate::vip::router::is_path_probe;
|
||||
|
||||
pub mod relay;
|
||||
pub mod routing;
|
||||
pub mod transport;
|
||||
|
||||
@@ -890,7 +890,7 @@ pub struct PeerReport {
|
||||
pub transport: String,
|
||||
/// Round-trip time of the control connection in milliseconds.
|
||||
pub rtt_ms: Option<u64>,
|
||||
/// Fresh median RTT of the selected direct data link, in milliseconds.
|
||||
/// Measured round trip to the peer over its data path, in milliseconds.
|
||||
pub data_rtt_ms: Option<u64>,
|
||||
/// Underlying path reported by the selected direct data carrier.
|
||||
pub data_transport_detail: Option<String>,
|
||||
@@ -989,8 +989,7 @@ pub struct OverlayPeerReport {
|
||||
pub address: Option<String>,
|
||||
/// Seconds since the last WireGuard handshake while its session key is usable.
|
||||
pub handshake_secs_ago: Option<u64>,
|
||||
/// An established tunnel has no recent or pending IP traffic. An expired
|
||||
/// key on a tunnel required to stay warm is reported as waiting instead.
|
||||
/// An established tunnel has no recent or pending application traffic.
|
||||
#[serde(default)]
|
||||
pub idle: bool,
|
||||
/// Packets encrypted and sent to this peer.
|
||||
|
||||
@@ -10,7 +10,7 @@ pub struct SpeedReport {
|
||||
pub batch: Option<SpeedBatchReport>,
|
||||
/// Per-peer progress or the last local result, keyed by endpoint ID.
|
||||
pub peers: BTreeMap<String, SpeedPeerReport>,
|
||||
/// Currently connected peers advertising the same diagnostic wire version.
|
||||
/// Compatible peers with a confirmed encrypted data path for a test.
|
||||
pub capable: Vec<String>,
|
||||
}
|
||||
|
||||
|
||||
@@ -295,8 +295,7 @@ impl Interface {
|
||||
_=interval.tick()=>{
|
||||
let (probes,jobs)=routes.vips.tick(routes.vips.check_capacity().saturating_sub(checks.len()));
|
||||
for (route,packet) in probes {
|
||||
let obs = routes.traffic.packet(route.network,route.peer,Direction::Tx,&packet,||Role::Vip);
|
||||
if carrier.carry(route,packet) {obs.record();}
|
||||
carrier.carry(route,packet);
|
||||
}
|
||||
for job in jobs {
|
||||
let factory = Arc::clone(&factory);
|
||||
@@ -1025,22 +1024,8 @@ impl Interface {
|
||||
// Source ownership was checked before any VIP reverse translation.
|
||||
let packet = match self.routes.vips.incoming(network, peer, packet.clone()) {
|
||||
crate::vip::router::Decision::Send(route, reply) => {
|
||||
self.routes
|
||||
.traffic
|
||||
.packet(network, peer, Direction::Rx, &packet, || Role::Vip)
|
||||
.record();
|
||||
let packet = reply;
|
||||
// Probe replies use the ordinary peer carrier, never the TUN.
|
||||
let tx = self.routes.traffic.packet(
|
||||
route.network,
|
||||
route.peer,
|
||||
Direction::Tx,
|
||||
&packet,
|
||||
|| Role::Vip,
|
||||
);
|
||||
if self.carrier.carry(route, packet) {
|
||||
tx.record();
|
||||
}
|
||||
// Only an authenticated RTT request generates an immediate peer reply here.
|
||||
self.carrier.carry(route, reply);
|
||||
return Ok(());
|
||||
}
|
||||
crate::vip::router::Decision::Local(translated) => {
|
||||
@@ -1064,14 +1049,9 @@ impl Interface {
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
crate::vip::router::Decision::ProbeReceived => {
|
||||
self.routes
|
||||
.traffic
|
||||
.packet(network, peer, Direction::Rx, &packet, || Role::Vip)
|
||||
.record();
|
||||
crate::vip::router::Decision::ProbeReceived | crate::vip::router::Decision::Drop => {
|
||||
return Ok(());
|
||||
}
|
||||
crate::vip::router::Decision::Drop => return Ok(()),
|
||||
crate::vip::router::Decision::Pass => packet,
|
||||
};
|
||||
self.deliver_admitted(network, peer, packet, broadcast, exit.as_ref(), forwarded)
|
||||
|
||||
@@ -144,30 +144,30 @@ impl VipRouter {
|
||||
) {
|
||||
let mut s = self.lock();
|
||||
s.limits = limits.clone();
|
||||
let source_changed = s
|
||||
.networks
|
||||
.get(&network)
|
||||
.is_none_or(|n| n.address != address);
|
||||
let mut present = HashSet::new();
|
||||
for (peer, address, available) in peers {
|
||||
present.insert(peer);
|
||||
let p = s.paths.entry((network, peer)).or_default();
|
||||
if p.address != Some(address) {
|
||||
p.rtt = None;
|
||||
p.heard = None;
|
||||
p.pending = None;
|
||||
if source_changed || p.address != Some(address) || p.available != available {
|
||||
*p = Path::default();
|
||||
}
|
||||
p.address = Some(address);
|
||||
p.available = available;
|
||||
}
|
||||
for ((n, peer), p) in &mut s.paths {
|
||||
if *n == network && !present.contains(peer) {
|
||||
p.available = false;
|
||||
}
|
||||
}
|
||||
if let Some(address) = address {
|
||||
present.insert(local);
|
||||
let p = s.paths.entry((network, local)).or_default();
|
||||
p.address = Some(address);
|
||||
p.available = true;
|
||||
p.rtt = Some(0);
|
||||
p.heard = Some(Instant::now());
|
||||
}
|
||||
s.paths
|
||||
.retain(|(n, peer), _| *n != network || present.contains(peer));
|
||||
s.networks.insert(
|
||||
network,
|
||||
Network {
|
||||
@@ -177,6 +177,16 @@ impl VipRouter {
|
||||
},
|
||||
);
|
||||
}
|
||||
/// Last confirmed round trip through both endpoints' encrypted packet channels.
|
||||
pub fn peer_rtt(&self, network: NetworkId, peer: EndpointId) -> Option<Duration> {
|
||||
let s = self.lock();
|
||||
s.paths
|
||||
.get(&(network, peer))
|
||||
.filter(|p| p.available)?
|
||||
.rtt
|
||||
.map(Duration::from_micros)
|
||||
}
|
||||
|
||||
pub fn remove_network(&self, network: NetworkId) {
|
||||
let mut s = self.lock();
|
||||
s.networks.remove(&network);
|
||||
@@ -342,6 +352,47 @@ impl VipRouter {
|
||||
let live: HashSet<_> = s.flows.keys().copied().collect();
|
||||
s.reverse.retain(|_, t| live.contains(t));
|
||||
let mut probes = Vec::new();
|
||||
let State {
|
||||
paths,
|
||||
networks,
|
||||
sequence,
|
||||
..
|
||||
} = &mut *s;
|
||||
for (&(network, peer), path) in paths {
|
||||
let Some(net) = networks.get(&network) else {
|
||||
continue;
|
||||
};
|
||||
let (Some(source), Some(address)) = (net.address, path.address) else {
|
||||
continue;
|
||||
};
|
||||
if !path.available || peer == net.local {
|
||||
continue;
|
||||
}
|
||||
if path
|
||||
.pending
|
||||
.is_some_and(|(_, at)| now.duration_since(at) >= Duration::from_secs(3))
|
||||
{
|
||||
path.pending = None;
|
||||
path.misses = path.misses.saturating_add(1);
|
||||
if path.misses >= 2 {
|
||||
path.rtt = None;
|
||||
path.heard = None;
|
||||
}
|
||||
}
|
||||
if path.pending.is_none()
|
||||
&& path
|
||||
.last_probe
|
||||
.is_none_or(|at| now.duration_since(at) >= Duration::from_secs(1))
|
||||
{
|
||||
*sequence = sequence.wrapping_add(1);
|
||||
path.pending = Some((*sequence, now));
|
||||
path.last_probe = Some(now);
|
||||
probes.push((
|
||||
Route { network, peer },
|
||||
probe(source, address, 1, *sequence),
|
||||
));
|
||||
}
|
||||
}
|
||||
let mut jobs = Vec::new();
|
||||
let mut targets = BTreeMap::new();
|
||||
for (n, net) in &s.networks {
|
||||
@@ -366,37 +417,10 @@ impl VipRouter {
|
||||
let Some(net) = s.networks.get(&network) else {
|
||||
continue;
|
||||
};
|
||||
let (local, source) = (net.local, net.address);
|
||||
let sequence = s.sequence.wrapping_add(1);
|
||||
s.sequence = sequence;
|
||||
let Some(path) = s.paths.get_mut(&(network, peer)) else {
|
||||
let source = net.address;
|
||||
let Some(address) = s.paths.get(&(network, peer)).and_then(|p| p.address) else {
|
||||
continue;
|
||||
};
|
||||
let Some(address) = path.address else {
|
||||
continue;
|
||||
};
|
||||
if peer == local {
|
||||
path.rtt = Some(0);
|
||||
path.heard = Some(now);
|
||||
} else if path.available {
|
||||
if path
|
||||
.pending
|
||||
.is_some_and(|(_, at)| now.duration_since(at) >= Duration::from_secs(3))
|
||||
{
|
||||
path.pending = None;
|
||||
path.misses = path.misses.saturating_add(1);
|
||||
}
|
||||
if path.pending.is_none()
|
||||
&& path
|
||||
.last_probe
|
||||
.is_none_or(|at| now.duration_since(at) >= Duration::from_secs(1))
|
||||
&& let Some(source) = source
|
||||
{
|
||||
path.pending = Some((sequence, now));
|
||||
path.last_probe = Some(now);
|
||||
probes.push((Route { network, peer }, probe(source, address, 1, sequence)));
|
||||
}
|
||||
}
|
||||
for (l, b) in listeners {
|
||||
let key = (network, peer, address, l.protocol, b.port);
|
||||
wanted_checks.insert(key);
|
||||
@@ -759,28 +783,32 @@ impl VipRouter {
|
||||
let Some(source) = net.address else {
|
||||
return Decision::Drop;
|
||||
};
|
||||
let Some(path) = s.paths.get_mut(&(network, peer)) else {
|
||||
return Decision::Drop;
|
||||
};
|
||||
let Some(remote) = path.address else {
|
||||
return Decision::Drop;
|
||||
};
|
||||
if packet::addresses(&packet) != Some((remote, source)) {
|
||||
return Decision::Drop;
|
||||
}
|
||||
if kind == 1 {
|
||||
let Some((_, destination)) = packet::addresses(&packet).map(|(a, b)| (b, a)) else {
|
||||
return Decision::Drop;
|
||||
};
|
||||
return Decision::Send(
|
||||
Route { network, peer },
|
||||
probe(source, destination, 2, sequence),
|
||||
);
|
||||
return Decision::Send(Route { network, peer }, probe(source, remote, 2, sequence));
|
||||
}
|
||||
if kind == 2
|
||||
&& let Some(p) = s.paths.get_mut(&(network, peer))
|
||||
&& let Some((expected, at)) = p.pending
|
||||
&& path.available
|
||||
&& let Some((expected, at)) = path.pending
|
||||
&& expected == sequence
|
||||
&& at.elapsed() < Duration::from_secs(3)
|
||||
{
|
||||
let rtt = at.elapsed().as_micros().min(u128::from(u64::MAX)) as u64;
|
||||
p.rtt = Some(
|
||||
p.rtt
|
||||
path.rtt = Some(
|
||||
path.rtt
|
||||
.map_or(rtt, |old| old.saturating_mul(7).saturating_add(rtt) / 8),
|
||||
);
|
||||
p.heard = Some(Instant::now());
|
||||
p.pending = None;
|
||||
p.misses = 0;
|
||||
path.heard = Some(Instant::now());
|
||||
path.pending = None;
|
||||
path.misses = 0;
|
||||
return Decision::ProbeReceived;
|
||||
}
|
||||
return Decision::Drop;
|
||||
@@ -981,15 +1009,18 @@ fn probe(src: Ipv4Addr, dst: Ipv4Addr, kind: u8, sequence: u64) -> Bytes {
|
||||
p[10..12].copy_from_slice(&c.to_be_bytes());
|
||||
Bytes::from(p)
|
||||
}
|
||||
/// Recognizes the reserved encrypted overlay echo used to measure peer RTT.
|
||||
pub fn is_path_probe(p: &[u8]) -> bool {
|
||||
p.len() == 45 && p[9] == 253 && &p[20..36] == PROBE && packet::header(p) == Some(20)
|
||||
}
|
||||
|
||||
fn parse_probe(p: &[u8]) -> Option<(u8, u64)> {
|
||||
(packet::header(p) == Some(20) && p.len() == 45 && p[9] == 253 && &p[20..36] == PROBE).then(
|
||||
|| {
|
||||
(
|
||||
p[36],
|
||||
u64::from_be_bytes([p[37], p[38], p[39], p[40], p[41], p[42], p[43], p[44]]),
|
||||
)
|
||||
},
|
||||
)
|
||||
is_path_probe(p).then(|| {
|
||||
(
|
||||
p[36],
|
||||
u64::from_be_bytes([p[37], p[38], p[39], p[40], p[41], p[42], p[43], p[44]]),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -1258,6 +1289,66 @@ mod tests {
|
||||
}
|
||||
assert!(r.statuses(n)[0].listeners[0].selected.is_some());
|
||||
}
|
||||
#[test]
|
||||
fn peer_rtt_survives_one_miss_and_expires_on_loss_or_new_membership() {
|
||||
let (router, network, local, peer, other, t) = fixture(Protocol::Udp);
|
||||
let remote = Ipv4Addr::new(10, 0, 0, 2);
|
||||
let configure = |available| {
|
||||
router.configure(
|
||||
network,
|
||||
local,
|
||||
Some(t.src),
|
||||
vec![],
|
||||
vec![(peer, remote, available)],
|
||||
&Limits::default(),
|
||||
)
|
||||
};
|
||||
configure(false);
|
||||
configure(true);
|
||||
assert!(router.peer_rtt(network, peer).is_none());
|
||||
let (probes, _) = router.tick(0);
|
||||
let (_, request) = probes.iter().find(|(route, _)| route.peer == peer).unwrap();
|
||||
let (_, seq) = parse_probe(request).unwrap();
|
||||
let reply = probe(remote, t.src, 2, seq);
|
||||
assert!(matches!(
|
||||
router.incoming(network, other, reply.clone()),
|
||||
Decision::Drop
|
||||
));
|
||||
assert!(router.peer_rtt(network, peer).is_none());
|
||||
assert!(matches!(
|
||||
router.incoming(network, peer, reply.clone()),
|
||||
Decision::ProbeReceived
|
||||
));
|
||||
let measured = router.peer_rtt(network, peer).unwrap();
|
||||
configure(true);
|
||||
assert_eq!(router.peer_rtt(network, peer), Some(measured));
|
||||
assert!(matches!(
|
||||
router.incoming(network, peer, reply.clone()),
|
||||
Decision::Drop
|
||||
));
|
||||
for missed in 1..=2 {
|
||||
{
|
||||
let mut state = router.lock();
|
||||
let p = state.paths.get_mut(&(network, peer)).unwrap();
|
||||
let sent = Instant::now() - Duration::from_secs(4);
|
||||
p.last_probe = Some(sent);
|
||||
p.pending = Some((seq + missed, sent));
|
||||
}
|
||||
router.tick(0);
|
||||
assert_eq!(
|
||||
router.peer_rtt(network, peer),
|
||||
(missed == 1).then_some(measured)
|
||||
);
|
||||
}
|
||||
configure(false);
|
||||
configure(true);
|
||||
assert!(matches!(
|
||||
router.incoming(network, peer, reply),
|
||||
Decision::Drop
|
||||
));
|
||||
assert!(router.peer_rtt(network, peer).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_rtt_is_not_selected_and_reflected_probes_do_not_forge_measurements() {
|
||||
let (r, n, _, a, _, _) = fixture(Protocol::Udp);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tsunagi-runtime"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
description = "Built-in mesh transports and status reporting for native tsunagi agents."
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
@@ -8,11 +8,11 @@ license.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
tsunagi-core = { path = "../tsunagi-core", version = "1.0.11" }
|
||||
tsunagi-wg-quic = { path = "../tsunagi-wg-quic", version = "1.0.11" }
|
||||
tsunagi-wireguard = { path = "../tsunagi-wireguard", version = "1.0.11" }
|
||||
tsunagi-awg = { path = "../tsunagi-awg", version = "1.0.11" }
|
||||
tsunagi-tcp-tls = { path = "../tsunagi-tcp-tls", version = "1.0.11" }
|
||||
tsunagi-core = { path = "../tsunagi-core", version = "1.0.12" }
|
||||
tsunagi-wg-quic = { path = "../tsunagi-wg-quic", version = "1.0.12" }
|
||||
tsunagi-wireguard = { path = "../tsunagi-wireguard", version = "1.0.12" }
|
||||
tsunagi-awg = { path = "../tsunagi-awg", version = "1.0.12" }
|
||||
tsunagi-tcp-tls = { path = "../tsunagi-tcp-tls", version = "1.0.12" }
|
||||
tsunagi-shoes = { path = "../tsunagi-shoes", version = "1.0.0" }
|
||||
tsunagi-vless-xhttp = { path = "../tsunagi-vless-xhttp", version = "1.0.0" }
|
||||
tsunagi-ss2022 = { path = "../tsunagi-ss2022", version = "1.0.0" }
|
||||
|
||||
@@ -25,6 +25,12 @@ pub fn networks(
|
||||
let mut peers: Vec<OverlayPeerReport> = Vec::new();
|
||||
|
||||
if let Some(view) = &wg_view {
|
||||
let confirmed: std::collections::HashSet<_> = network
|
||||
.peers
|
||||
.iter()
|
||||
.filter(|p| p.has_confirmed_data_path())
|
||||
.map(|p| p.endpoint_id)
|
||||
.collect();
|
||||
for peer in &view.peers {
|
||||
let tunnel = peer.tunnel.as_ref();
|
||||
peers.push(OverlayPeerReport {
|
||||
@@ -35,7 +41,8 @@ pub fn networks(
|
||||
address: peer.overlay_address_v4.map(|a| a.to_string()),
|
||||
handshake_secs_ago: tunnel
|
||||
.and_then(|t| t.health.since_handshake.map(|s| s.as_secs())),
|
||||
idle: tunnel.is_some_and(|t| t.health.idle),
|
||||
idle: tunnel.is_some_and(|t| t.health.idle)
|
||||
&& confirmed.contains(&peer.endpoint_id),
|
||||
tx_packets: tunnel.map_or(0, |t| t.stats.tx_packets),
|
||||
rx_packets: tunnel.map_or(0, |t| t.stats.rx_packets),
|
||||
tx_bytes: tunnel.map_or(0, |t| t.stats.tx_bytes),
|
||||
|
||||
@@ -192,6 +192,7 @@ impl Session {
|
||||
if self.cfg.mtu < MIN_MTU || self.cfg.byte_limit == 0 || self.cfg.local == self.cfg.remote {
|
||||
return Err(State::Failed);
|
||||
}
|
||||
let negotiation_started = Instant::now();
|
||||
if let Some(start) = self.request {
|
||||
if !Control::Start(start).valid() {
|
||||
return Err(State::Failed);
|
||||
@@ -232,6 +233,7 @@ impl Session {
|
||||
}
|
||||
}
|
||||
|
||||
let negotiation_time = negotiation_started.elapsed();
|
||||
for direction in [Direction::Download, Direction::Upload] {
|
||||
self.progress.state = match direction {
|
||||
Direction::Download => State::Download,
|
||||
@@ -240,7 +242,8 @@ impl Session {
|
||||
io.progress(self.progress);
|
||||
let sender = (direction == Direction::Download) == self.request.is_some();
|
||||
let result = if sender {
|
||||
self.send_probes(io, direction, deadline).await?
|
||||
self.send_probes(io, direction, deadline, negotiation_time)
|
||||
.await?
|
||||
} else {
|
||||
self.receive_probes(io, direction).await?
|
||||
};
|
||||
@@ -255,7 +258,9 @@ impl Session {
|
||||
io: &impl Io,
|
||||
direction: Direction,
|
||||
deadline: Instant,
|
||||
negotiation_time: Duration,
|
||||
) -> Result<Reading, State> {
|
||||
let waiting = Instant::now();
|
||||
loop {
|
||||
if matches!(open_control(self.events.recv().await)?, Control::Ready { direction: d, .. } if d == direction)
|
||||
{
|
||||
@@ -263,10 +268,17 @@ impl Session {
|
||||
}
|
||||
}
|
||||
let start = Instant::now();
|
||||
// Leave room for the opposite direction and the final reliable report.
|
||||
// End and Report travel on reliable control. Leave room for their
|
||||
// exchange and a queued feedback message even on a slow control path.
|
||||
// Only the receiver's data packets contribute to the measured rate.
|
||||
let report_time = negotiation_time
|
||||
.max(waiting.elapsed())
|
||||
.saturating_mul(3)
|
||||
.saturating_add(Duration::from_millis(200))
|
||||
.min(Duration::from_millis(1600));
|
||||
let remaining = deadline
|
||||
.saturating_duration_since(start)
|
||||
.saturating_sub(Duration::from_millis(200));
|
||||
.saturating_sub(report_time);
|
||||
let phase = if direction == Direction::Download {
|
||||
remaining / 2
|
||||
} else {
|
||||
|
||||
@@ -302,6 +302,22 @@ async fn an_unrelated_busy_reply_does_not_cancel_the_active_request() {
|
||||
assert_eq!(task.await.unwrap().state, State::Busy);
|
||||
}
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn a_half_second_control_round_trip_can_return_both_data_measurements() {
|
||||
let (a, b, _, _) = shaped(
|
||||
12_000_000,
|
||||
25_000_000,
|
||||
NORMAL_BYTES,
|
||||
Duration::from_millis(260),
|
||||
0,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(a.state, State::Complete, "{a:?}");
|
||||
assert_eq!(b.state, State::Complete, "{b:?}");
|
||||
assert!(a.down.bps.is_some() && a.up.bps.is_some(), "{a:?}");
|
||||
}
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn slower_control_feedback_leaves_time_for_both_directions() {
|
||||
let (a, b, _, _) = shaped(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tsunagi-tcp-tls"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
description = "TCP TLS carrier for independently encrypted tsunagi mesh traffic."
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
@@ -8,7 +8,7 @@ license.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
tsunagi-core = { path = "../tsunagi-core", version = "1.0.11" }
|
||||
tsunagi-core = { path = "../tsunagi-core", version = "1.0.12" }
|
||||
iroh.workspace = true
|
||||
tokio = { workspace = true, features = ["net", "io-util", "time", "sync", "macros"] }
|
||||
rustls = "0.23"
|
||||
|
||||
@@ -199,7 +199,7 @@ impl TcpTlsConfig {
|
||||
key: "port",
|
||||
value: "PORT",
|
||||
help: "TCP port to listen on for TLS 1.3 connections",
|
||||
default: Some("443"),
|
||||
default: Some("9442"),
|
||||
},
|
||||
ProtocolOption {
|
||||
key: "sni",
|
||||
|
||||
@@ -24,9 +24,9 @@ use tsunagi::identity::{DeviceIdentity, NetworkId};
|
||||
use crate::cert::{generate_self_signed_cert, make_client_config, make_server_config};
|
||||
|
||||
/// Default TCP port to bind and listen on.
|
||||
pub const DEFAULT_PORT: u16 = 443;
|
||||
pub const DEFAULT_PORT: u16 = 9442;
|
||||
|
||||
/// Fallback port if 443 is unprivileged on Linux and denied.
|
||||
/// Second unprivileged port when the preferred listener cannot bind.
|
||||
pub const FALLBACK_PORT: u16 = 8443;
|
||||
|
||||
/// Maximum payload length for a single framed datagram over TLS.
|
||||
@@ -269,7 +269,7 @@ pub struct TcpTlsTransport {
|
||||
sni: String,
|
||||
peer_addresses: Candidates,
|
||||
server_config: Arc<rustls::ServerConfig>,
|
||||
listener: Option<Arc<TcpListener>>,
|
||||
listener: TcpListener,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for TcpTlsTransport {
|
||||
@@ -363,72 +363,21 @@ impl TcpTlsTransport {
|
||||
};
|
||||
|
||||
let listener = match bind_result {
|
||||
Ok(l) => {
|
||||
tracing::info!(port = target_port, "TCP TLS listening");
|
||||
Some(Arc::new(l))
|
||||
}
|
||||
Ok(listener) => listener,
|
||||
Err(err) if requested_port.is_none() => {
|
||||
let exe = std::env::current_exe()
|
||||
.map(|p| p.display().to_string())
|
||||
.unwrap_or_else(|_| "tsunagi".into());
|
||||
|
||||
if err.kind() == std::io::ErrorKind::PermissionDenied {
|
||||
tracing::warn!(
|
||||
port = target_port,
|
||||
%err,
|
||||
"Cannot bind to default port {target_port} without privileges. \
|
||||
To allow port 443 and TUN on Linux, grant capabilities once with:\n \
|
||||
sudo setcap cap_net_admin,cap_net_bind_service+p {exe}\n\
|
||||
Falling back to port {FALLBACK_PORT}."
|
||||
);
|
||||
} else {
|
||||
tracing::warn!(
|
||||
port = target_port,
|
||||
%err,
|
||||
"Cannot bind to default port {target_port}: {err}. \
|
||||
Falling back to port {FALLBACK_PORT}."
|
||||
);
|
||||
}
|
||||
|
||||
match crate::candidates::listen(FALLBACK_PORT) {
|
||||
Ok(l) => {
|
||||
tracing::info!(port = FALLBACK_PORT, "TCP TLS listening on fallback port");
|
||||
Some(Arc::new(l))
|
||||
}
|
||||
Err(fallback_err) => {
|
||||
tracing::warn!(
|
||||
port = FALLBACK_PORT,
|
||||
err = %fallback_err,
|
||||
"Cannot bind to fallback port {FALLBACK_PORT}: {fallback_err}. \
|
||||
Falling back to ephemeral port."
|
||||
);
|
||||
let l = crate::candidates::listen(0)?;
|
||||
let bound = l.local_addr()?.port();
|
||||
tracing::info!(port = bound, "TCP TLS listening on ephemeral port");
|
||||
Some(Arc::new(l))
|
||||
}
|
||||
}
|
||||
tracing::warn!(port = target_port, %err, "TCP TLS default port unavailable");
|
||||
crate::candidates::listen(FALLBACK_PORT).or_else(|err| {
|
||||
tracing::warn!(port = FALLBACK_PORT, %err, "TCP TLS fallback port unavailable");
|
||||
crate::candidates::listen(0)
|
||||
})?
|
||||
}
|
||||
Err(err) => {
|
||||
let exe = std::env::current_exe()
|
||||
.map(|p| p.display().to_string())
|
||||
.unwrap_or_else(|_| "tsunagi".into());
|
||||
tracing::warn!(
|
||||
port = target_port,
|
||||
%err,
|
||||
"Cannot bind to requested port {target_port}: {err}. \
|
||||
To allow port {target_port} and TUN on Linux, grant capabilities once with:\n \
|
||||
sudo setcap cap_net_admin,cap_net_bind_service+p {exe}"
|
||||
);
|
||||
tracing::warn!(port = target_port, %err, "Cannot bind requested TCP TLS port");
|
||||
return Err(Box::new(err));
|
||||
}
|
||||
};
|
||||
|
||||
let bound_port = listener
|
||||
.as_ref()
|
||||
.and_then(|l| l.local_addr().ok())
|
||||
.map(|a| a.port())
|
||||
.unwrap_or(target_port);
|
||||
let bound_port = listener.local_addr()?.port();
|
||||
tracing::info!(port = bound_port, "TCP TLS listening");
|
||||
|
||||
Ok(Self {
|
||||
identity: identity.clone(),
|
||||
@@ -477,10 +426,6 @@ impl TcpTlsTransport {
|
||||
where
|
||||
F: Fn(InboundLink) + Send + Sync + Clone + 'static,
|
||||
{
|
||||
let Some(listener) = self.listener.as_ref().cloned() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let acceptor = tokio_rustls::TlsAcceptor::from(Arc::clone(&self.server_config));
|
||||
let local_id = self.local_id;
|
||||
|
||||
@@ -488,7 +433,7 @@ impl TcpTlsTransport {
|
||||
loop {
|
||||
let accepted = tokio::select! {
|
||||
_ = handshakes.join_next(), if !handshakes.is_empty() => continue,
|
||||
result = listener.accept(), if handshakes.len() < 64 => result,
|
||||
result = self.listener.accept(), if handshakes.len() < 64 => result,
|
||||
};
|
||||
let Ok((socket, remote_addr)) = accepted else {
|
||||
break;
|
||||
|
||||
@@ -11,6 +11,38 @@ use tsunagi::dataplane::transport::{InboundLink, PacketTransport};
|
||||
use tsunagi::identity::{DeviceIdentity, NetworkId};
|
||||
use tsunagi_tcp_tls::TcpTlsTransport;
|
||||
|
||||
#[tokio::test]
|
||||
async fn default_listeners_use_high_ports_and_report_the_actual_bound_port() {
|
||||
use tsunagi::dataplane::transport::DataCarrier;
|
||||
use tsunagi_tcp_tls::{TcpTlsCarrier, TcpTlsConfig, transport::DEFAULT_PORT};
|
||||
|
||||
assert_eq!(DEFAULT_PORT, 9442);
|
||||
let option = TcpTlsConfig::OPTIONS
|
||||
.iter()
|
||||
.find(|o| o.key == "port")
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
option.default.unwrap().parse::<u16>().unwrap(),
|
||||
DEFAULT_PORT
|
||||
);
|
||||
let identity = DeviceIdentity::generate();
|
||||
let first = TcpTlsTransport::bind(&identity, None, None).await.unwrap();
|
||||
let second = Arc::new(TcpTlsTransport::bind(&identity, None, None).await.unwrap());
|
||||
assert!(first.bound_port() >= 1024 && second.bound_port() >= 1024);
|
||||
assert_ne!(first.bound_port(), second.bound_port());
|
||||
assert!(
|
||||
TcpTlsTransport::bind(&identity, Some(first.bound_port()), None)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
let cap = TcpTlsCarrier::new(second.clone())
|
||||
.local_capability(NetworkId::from_bytes([3; 32]))
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let (port, _): (u16, Vec<std::net::IpAddr>) = postcard::from_bytes(&cap.data).unwrap();
|
||||
assert_eq!(port, second.bound_port());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_tcp_tls_transport_loopback() {
|
||||
let identity_a = DeviceIdentity::generate();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tsunagi-tray"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
description = "Tray application to manage a running tsunagi agent."
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
@@ -16,7 +16,7 @@ tsunagi-ui = { path = "../tsunagi-ui" }
|
||||
# The agent control client and the report types: the GUI is a thin client over
|
||||
# the same local control interface the CLI uses, so it reuses these directly
|
||||
# and never re-implements the protocol.
|
||||
tsunagi-core = { path = "../tsunagi-core", version = "1.0.11" }
|
||||
tsunagi-core = { path = "../tsunagi-core", version = "1.0.12" }
|
||||
# Native, lightweight GUI — no web engine. eframe re-exports egui.
|
||||
eframe = { version = "0.31", default-features = false, features = ["default_fonts", "glow", "wayland", "x11"] }
|
||||
# Cross-platform tray icon + menu (Windows tray, macOS menu bar, Linux SNI).
|
||||
|
||||
@@ -34,6 +34,17 @@ pub(crate) struct App {
|
||||
sampled: u64,
|
||||
}
|
||||
|
||||
const MIN_DEVICES_SIZE: egui::Vec2 = egui::vec2(560., 260.);
|
||||
|
||||
fn initial_devices_size(rows: usize, monitor: Option<egui::Vec2>, row_pitch: f32) -> egui::Vec2 {
|
||||
// The collapsed header, the roster header and the totals row are visible on open.
|
||||
let height = (110. + (rows as f32 + 2.) * row_pitch).clamp(MIN_DEVICES_SIZE.y, 780.);
|
||||
let preferred = egui::vec2(1240., height);
|
||||
monitor.map_or(preferred, |screen| {
|
||||
preferred.min((screen - egui::vec2(48., 80.)).max(MIN_DEVICES_SIZE))
|
||||
})
|
||||
}
|
||||
|
||||
impl App {
|
||||
/// Builds the app: resolves the socket and starts the worker.
|
||||
pub(crate) fn new(
|
||||
@@ -195,18 +206,27 @@ impl App {
|
||||
continue;
|
||||
};
|
||||
let viewport = egui::ViewportId::from_hash_of(("devices", id));
|
||||
let preferred = egui::vec2(1240., 740.);
|
||||
let size = ctx
|
||||
.input(|i| i.viewport().monitor_size)
|
||||
.map_or(preferred, |monitor| {
|
||||
preferred.min((monitor - egui::vec2(48., 80.)).max(egui::vec2(560., 400.)))
|
||||
});
|
||||
let builder = egui::ViewportBuilder::default()
|
||||
let mut builder = egui::ViewportBuilder::default()
|
||||
.with_title(devices::title(&report.networks[index]))
|
||||
.with_app_id(crate::icon::APP_ID)
|
||||
.with_icon(crate::icon::window())
|
||||
.with_inner_size(size)
|
||||
.with_min_inner_size([560., 400.]);
|
||||
.with_min_inner_size(MIN_DEVICES_SIZE);
|
||||
// Apply the roster estimate only when creating a native window.
|
||||
// Subsequent frames leave the user's own height and width in place.
|
||||
let (opened, monitor) = ctx.input(|i| {
|
||||
(
|
||||
i.raw.viewports.contains_key(&viewport),
|
||||
i.viewport().monitor_size,
|
||||
)
|
||||
});
|
||||
if !opened {
|
||||
let rows = devices::known_count(&report.networks[index], &report.endpoint_id);
|
||||
builder = builder.with_inner_size(initial_devices_size(
|
||||
rows,
|
||||
monitor,
|
||||
devices::row_pitch(ctx),
|
||||
));
|
||||
}
|
||||
let views = self.views.clone();
|
||||
let agent = self.agent.clone();
|
||||
let report = report.clone();
|
||||
@@ -245,6 +265,17 @@ mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn devices_window_opens_to_fit_the_roster_within_the_screen() {
|
||||
let size = |rows| initial_devices_size(rows, None, 34.);
|
||||
assert_eq!(size(0).y, size(1).y);
|
||||
assert!(size(6).y < size(16).y);
|
||||
assert!(size(16).y < size(80).y);
|
||||
assert_eq!(size(80), size(2000));
|
||||
let on_small_screen = initial_devices_size(80, Some(egui::vec2(950., 670.)), 34.);
|
||||
assert!(on_small_screen.x < 950. && on_small_screen.y < 670.);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn device_frames_are_scheduled_independently_of_the_main_window() {
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
@@ -277,6 +308,28 @@ mod tests {
|
||||
app.show_devices_windows(ctx, &report, &["test-id".to_string()], true);
|
||||
});
|
||||
assert!(out.viewport_output[&id].class == egui::ViewportClass::Deferred);
|
||||
assert_eq!(
|
||||
out.viewport_output[&id].builder.inner_size.unwrap().y,
|
||||
MIN_DEVICES_SIZE.y
|
||||
);
|
||||
|
||||
let mut resized = egui::RawInput::default();
|
||||
resized.viewports.entry(id).or_default().inner_rect = Some(egui::Rect::from_min_size(
|
||||
egui::Pos2::ZERO,
|
||||
egui::vec2(1300., 900.),
|
||||
));
|
||||
let mut larger = Arc::clone(&report);
|
||||
Arc::make_mut(&mut larger).networks[0].members = (0..60)
|
||||
.map(|i| tsunagi::ipc::MemberReport {
|
||||
endpoint_id: i.to_string(),
|
||||
..Default::default()
|
||||
})
|
||||
.collect();
|
||||
let out = ctx.run(resized, |ctx| {
|
||||
app.show_devices_windows(ctx, &larger, &["test-id".to_string()], true);
|
||||
});
|
||||
let builder = &out.viewport_output[&id].builder;
|
||||
assert!(builder.inner_size.is_none() && builder.max_inner_size.is_none());
|
||||
let draw = out.viewport_output[&id].viewport_ui_cb.as_ref().unwrap();
|
||||
let mut input = egui::RawInput {
|
||||
viewport_id: id,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tsunagi-ui"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
description = "Shared egui widgets for the tray and Android clients."
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
@@ -210,6 +210,12 @@ fn short_name_cell(ui: &mut egui::Ui, device: &Device<'_>) {
|
||||
));
|
||||
}
|
||||
|
||||
/// Height of one desktop roster row, including the gap to its neighbour.
|
||||
pub fn row_pitch(ctx: &egui::Context) -> f32 {
|
||||
let style = ctx.style();
|
||||
crate::table::row_height(ctx, &style) + style.spacing.item_spacing.y
|
||||
}
|
||||
|
||||
/// Draws the window body into its viewport.
|
||||
pub fn show(
|
||||
ctx: &egui::Context,
|
||||
@@ -280,11 +286,7 @@ pub fn show(
|
||||
columns[0].collapsing("Network details", |ui| summary(ui, network));
|
||||
let plot = &mut columns[1];
|
||||
plot.label("Network traffic");
|
||||
let width = plot.available_width().min(440.0);
|
||||
plot.scope(|ui| {
|
||||
ui.set_max_width(width);
|
||||
format::sparkline(ui, traffic.network(&network.network_id), unit, 48.0);
|
||||
});
|
||||
format::sparkline(plot, traffic.network(&network.network_id), unit, 48.0);
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
egui::ScrollArea::vertical()
|
||||
@@ -769,7 +771,7 @@ const MIN_PLOT_WIDTH: f32 = 100.;
|
||||
|
||||
fn stretch_columns(mut widths: [f32; 9], available: f32) -> [f32; 9] {
|
||||
let gaps = crate::table::GAP * (widths.len() - 1) as f32;
|
||||
widths[8] = (available - gaps - widths[..8].iter().sum::<f32>()).clamp(MIN_PLOT_WIDTH, 180.0);
|
||||
widths[8] = (available - gaps - widths[..8].iter().sum::<f32>()).max(MIN_PLOT_WIDTH);
|
||||
widths
|
||||
}
|
||||
|
||||
@@ -997,7 +999,7 @@ fn device_table(
|
||||
2 => tunnel_cell(ui, device),
|
||||
3 => {
|
||||
ui.label(rtt_pair(device)).on_hover_text(
|
||||
"Median authenticated direct data-link RTT / selected control-connection RTT. A dash means there is no current measurement.",
|
||||
"Round trip to the device over the encrypted data path, including relay hops / round trip over the control connection.",
|
||||
);
|
||||
}
|
||||
4 => match &device.address {
|
||||
@@ -1436,10 +1438,10 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wider_windows_keep_a_compact_plot_and_narrow_windows_preserve_column_floors() {
|
||||
fn plots_fill_wide_windows_and_narrow_windows_preserve_column_floors() {
|
||||
let minimum = [100.0; 9];
|
||||
let wide = stretch_columns(minimum, 1440.0);
|
||||
assert!((100.0..=190.0).contains(&wide[8]));
|
||||
assert!((wide.iter().sum::<f32>() + 8. * crate::table::GAP - 1440.).abs() < 0.1);
|
||||
assert_eq!(&wide[..8], &minimum[..8]);
|
||||
let narrow = stretch_columns(minimum, 800.0);
|
||||
assert_eq!(
|
||||
@@ -1453,6 +1455,20 @@ mod tests {
|
||||
);
|
||||
|
||||
let ctx = egui::Context::default();
|
||||
let network = NetworkReport {
|
||||
peers: vec![tsunagi::ipc::PeerReport {
|
||||
endpoint_id: "peer".into(),
|
||||
..Default::default()
|
||||
}],
|
||||
overlay: Some(tsunagi::ipc::OverlayReport {
|
||||
peers: vec![OverlayPeerReport {
|
||||
endpoint_id: "peer".into(),
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
for window_width in [800.0, 1000.0, 1440.0] {
|
||||
let frame = ctx.run(
|
||||
egui::RawInput {
|
||||
@@ -1468,21 +1484,27 @@ mod tests {
|
||||
&ReadOnly,
|
||||
&mut Unit::Bytes,
|
||||
(&mut None, &mut None),
|
||||
&NetworkReport::default(),
|
||||
&network,
|
||||
"self",
|
||||
&Traffic::default(),
|
||||
);
|
||||
},
|
||||
);
|
||||
let chart = frame
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|s| match &s.shape {
|
||||
egui::Shape::Rect(r) if r.rect.height() == 48.0 => Some(r.rect),
|
||||
let chart = |height| {
|
||||
frame.shapes.iter().find_map(|s| match &s.shape {
|
||||
egui::Shape::Rect(r) if r.rect.height() == height => Some(r.rect),
|
||||
_ => None,
|
||||
})
|
||||
.expect("network traffic chart");
|
||||
assert!((300.0..=440.0).contains(&chart.width()), "{chart:?}");
|
||||
};
|
||||
let total = chart(48.).expect("network traffic chart");
|
||||
assert!((window_width - total.right()).abs() < 12., "{total:?}");
|
||||
if window_width == 1440. {
|
||||
let peer = chart(24.).expect("desktop peer traffic chart");
|
||||
assert!(
|
||||
(peer.right() - total.right()).abs() < 2.,
|
||||
"{peer:?} {total:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! The same speed control occupies one fixed cell throughout a measurement.
|
||||
use super::{Client, Command, Device, NetworkReport, format, icon, widgets};
|
||||
use super::{Client, Command, Device, NetworkReport, format, icon, status, widgets};
|
||||
use crate::client::speed_running;
|
||||
use egui::{Align2, Color32, FontId, Rect, Sense, Ui, pos2, vec2};
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
@@ -44,18 +44,28 @@ impl<'a> Controls<'a> {
|
||||
)
|
||||
} else {
|
||||
let available = self.network.active
|
||||
&& self
|
||||
.network
|
||||
.peers
|
||||
.iter()
|
||||
.any(|p| p.exit_node && self.capable(&p.endpoint_id));
|
||||
&& self.network.peers.iter().any(|p| {
|
||||
p.exit_node
|
||||
&& self.capable(&p.endpoint_id)
|
||||
&& p.data_error.is_none()
|
||||
&& status::confirmed(
|
||||
Some(&p.path),
|
||||
p.data_rtt_ms,
|
||||
self.network.overlay.as_ref().and_then(|overlay| {
|
||||
overlay
|
||||
.peers
|
||||
.iter()
|
||||
.find(|t| t.endpoint_id == p.endpoint_id)
|
||||
}),
|
||||
)
|
||||
});
|
||||
(
|
||||
icon::GAUGE,
|
||||
"Test exits".to_owned(),
|
||||
if available {
|
||||
"Test each compatible online exit node in this network, one at a time."
|
||||
} else {
|
||||
"No online exit in this network supports peer speed tests."
|
||||
"No compatible exit has a confirmed data path."
|
||||
},
|
||||
available,
|
||||
)
|
||||
@@ -100,7 +110,12 @@ impl<'a> Controls<'a> {
|
||||
}
|
||||
let reading = self.network.speed.peers.get(peer.id);
|
||||
let supported = self.capable(peer.id);
|
||||
let ready = self.network.active && peer.online && supported;
|
||||
let ready = self.network.active
|
||||
&& supported
|
||||
&& matches!(
|
||||
peer.channel(),
|
||||
status::Channel::Ready | status::Channel::Idle
|
||||
);
|
||||
let can_start = ready && !self.running && !self.client.busy();
|
||||
let id = ui.make_persistent_id(("test peer speed", &self.network.network_id, peer.id));
|
||||
let r = ui.interact(rect, id, Sense::click());
|
||||
@@ -185,7 +200,9 @@ fn paint_reading(
|
||||
label("Starting", color);
|
||||
activity(ui, rect, color);
|
||||
}
|
||||
SpeedPhase::Failed(_) if !ready => label("Failed", v.weak_text_color()),
|
||||
SpeedPhase::Failed(_) => label(&format!("{} Retry", icon::WARNING), v.error_fg_color),
|
||||
SpeedPhase::Cancelled if !ready => label("Stopped", v.weak_text_color()),
|
||||
SpeedPhase::Cancelled => label(&format!("{} Retry", icon::ARROW_CLOCKWISE), color),
|
||||
SpeedPhase::Download | SpeedPhase::Upload | SpeedPhase::Done => {
|
||||
// Reserve the same two slots for idle, live and completed readings.
|
||||
@@ -329,6 +346,11 @@ fn tooltip(
|
||||
}
|
||||
if !peer.online {
|
||||
hint.push_str("\nPeer is offline.");
|
||||
} else if !matches!(
|
||||
peer.channel(),
|
||||
status::Channel::Ready | status::Channel::Idle
|
||||
) {
|
||||
hint.push_str("\nWaiting for a confirmed data path.");
|
||||
} else if !supported {
|
||||
hint.push_str("\nNo compatible speed-test session with this peer.");
|
||||
} else if !running {
|
||||
|
||||
@@ -27,8 +27,20 @@ fn network() -> NetworkReport {
|
||||
endpoint_id: id.into(),
|
||||
hostname: Some(id.into()),
|
||||
exit_node: offers_exit,
|
||||
path: DataPathReport::Direct {
|
||||
transport: "wg".into(),
|
||||
},
|
||||
data_rtt_ms: Some(12),
|
||||
..Default::default()
|
||||
});
|
||||
n.overlay
|
||||
.get_or_insert_with(Default::default)
|
||||
.peers
|
||||
.push(OverlayPeerReport {
|
||||
endpoint_id: id.into(),
|
||||
handshake_secs_ago: Some(1),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
n.speed.capable = vec!["alice".into(), "ben".into()];
|
||||
n
|
||||
@@ -328,6 +340,26 @@ fn long_press_explains_a_partial_result_without_requesting_another_test() {
|
||||
assert!(s.log.0.borrow().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_control_only_peer_cannot_look_idle_or_start_a_speed_test() {
|
||||
let mut n = network();
|
||||
n.peers[0].data_rtt_ms = None;
|
||||
n.peers[0].rtt_ms = Some(12);
|
||||
n.overlay.as_mut().unwrap().peers[0].idle = true;
|
||||
let row = devices(&n, "self");
|
||||
assert!(matches!(
|
||||
row.iter().find(|p| p.id == "alice").unwrap().channel(),
|
||||
status::Channel::Waiting
|
||||
));
|
||||
let screen = Screen::new(360., true);
|
||||
screen.frame(&n, vec![]);
|
||||
let output = screen.frame(&n, vec![]);
|
||||
assert_eq!(positions(&output, |s| s == icon::GAUGE).len(), 1);
|
||||
let start = positions(&output, |s| s.contains("Test exits"))[0];
|
||||
screen.click(&n, start);
|
||||
assert!(screen.log.0.borrow().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exit_batch_requires_an_online_capable_exit_and_stops_in_its_own_network() {
|
||||
let mut n = network();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::{DataPathReport, Device, icon};
|
||||
use super::{DataPathReport, Device, OverlayPeerReport, icon};
|
||||
use tsunagi::agent::{DATA_CONNECTING, DATA_DISABLED};
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
@@ -11,6 +11,16 @@ pub(super) enum Channel {
|
||||
Disabled,
|
||||
}
|
||||
|
||||
pub(super) fn confirmed(
|
||||
path: Option<&DataPathReport>,
|
||||
rtt: Option<u64>,
|
||||
tunnel: Option<&OverlayPeerReport>,
|
||||
) -> bool {
|
||||
!matches!(path, None | Some(DataPathReport::None))
|
||||
&& rtt.is_some()
|
||||
&& tunnel.is_some_and(OverlayPeerReport::is_up)
|
||||
}
|
||||
|
||||
impl Device<'_> {
|
||||
pub(super) fn channel(&self) -> Channel {
|
||||
if !self.online {
|
||||
@@ -20,10 +30,9 @@ impl Device<'_> {
|
||||
Some(DATA_DISABLED) => Channel::Disabled,
|
||||
Some(DATA_CONNECTING) => Channel::Waiting,
|
||||
Some(_) => Channel::Error,
|
||||
None if matches!(self.path, None | Some(DataPathReport::None)) => Channel::Waiting,
|
||||
None if !confirmed(self.path, self.data_rtt_ms, self.overlay) => Channel::Waiting,
|
||||
None if self.overlay.is_some_and(|p| p.idle) => Channel::Idle,
|
||||
None if self.overlay.is_some_and(|p| p.is_up()) => Channel::Ready,
|
||||
None => Channel::Waiting,
|
||||
None => Channel::Ready,
|
||||
}
|
||||
}
|
||||
pub(super) fn channel_hint(&self) -> &str {
|
||||
|
||||
@@ -232,6 +232,7 @@ fn rotating_the_devices_view_keeps_the_peer_and_fits_traffic_and_states_on_scree
|
||||
hops: 2,
|
||||
via: "another".into(),
|
||||
},
|
||||
data_rtt_ms: matches!(state, "ready" | "idle").then_some(37),
|
||||
data_error: match state {
|
||||
"waiting" => Some(tsunagi::agent::DATA_CONNECTING.into()),
|
||||
"error" => Some("Carrier unavailable".into()),
|
||||
@@ -256,6 +257,7 @@ fn rotating_the_devices_view_keeps_the_peer_and_fits_traffic_and_states_on_scree
|
||||
OverlayPeerReport {
|
||||
endpoint_id: id.into(),
|
||||
idle: true,
|
||||
handshake_secs_ago: Some(8),
|
||||
..Default::default()
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -3,6 +3,16 @@
|
||||
|
||||
pub(crate) const GAP: f32 = 10.0;
|
||||
|
||||
pub(crate) fn row_height(ctx: &egui::Context, style: &egui::Style) -> f32 {
|
||||
let font = egui::FontSelection::Default.resolve(style);
|
||||
style
|
||||
.spacing
|
||||
.interact_size
|
||||
.y
|
||||
.max(ctx.fonts(|fonts| fonts.row_height(&font)))
|
||||
+ 10.
|
||||
}
|
||||
|
||||
pub(crate) fn row(
|
||||
ui: &mut egui::Ui,
|
||||
id: impl std::hash::Hash,
|
||||
@@ -10,9 +20,7 @@ pub(crate) fn row(
|
||||
stripe: bool,
|
||||
mut cell: impl FnMut(usize, &mut egui::Ui),
|
||||
) {
|
||||
let font = egui::FontSelection::Default.resolve(ui.style());
|
||||
let text_height = ui.fonts(|fonts| fonts.row_height(&font));
|
||||
let height = ui.spacing().interact_size.y.max(text_height) + 10.0;
|
||||
let height = row_height(ui.ctx(), ui.style());
|
||||
let width = widths.iter().sum::<f32>() + GAP * widths.len().saturating_sub(1) as f32;
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(width, height), egui::Sense::hover());
|
||||
if stripe {
|
||||
|
||||
@@ -3,7 +3,7 @@ name = "tsunagi-wg-quic"
|
||||
# Its own version, and deliberately separate from the wire version it
|
||||
# negotiates: a release here does not stop it talking to a peer on an older
|
||||
# build, because what peers compare is `ANNOUNCEMENT_VERSION`.
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
description = "The single internal WireGuard tunnel for tsunagi, independent of external carriers."
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
@@ -11,7 +11,7 @@ license.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
tsunagi-core = { path = "../tsunagi-core", version = "1.0.11" }
|
||||
tsunagi-core = { path = "../tsunagi-core", version = "1.0.12" }
|
||||
iroh.workspace = true
|
||||
tokio.workspace = true
|
||||
serde.workspace = true
|
||||
|
||||
@@ -41,7 +41,7 @@ use tokio::task::JoinHandle;
|
||||
|
||||
use tsunagi::dataplane::routing::{FlowId, flow::ip_flow};
|
||||
use tsunagi::dataplane::transport::{SharedLink, TransportError};
|
||||
use tsunagi::dataplane::{PacketSink, PluginContext, PluginError};
|
||||
use tsunagi::dataplane::{PacketSink, PluginContext, PluginError, is_path_probe};
|
||||
use tsunagi::identity::NetworkId;
|
||||
|
||||
use crate::keys::{WgPublicKey, WgSecretKey};
|
||||
@@ -65,8 +65,8 @@ const SCRATCH: usize = 4096;
|
||||
struct FlowTunnel {
|
||||
tunn: Tunn,
|
||||
queued: VecDeque<(FlowId, usize)>,
|
||||
/// First usable session or most recent IP payload. Keepalives and later
|
||||
/// handshakes leave this alone, including when the current key expires.
|
||||
/// First usable session or most recent application payload. RTT probes,
|
||||
/// keepalives and later handshakes leave this alone.
|
||||
last_activity: Option<Instant>,
|
||||
}
|
||||
|
||||
@@ -81,17 +81,26 @@ impl FlowTunnel {
|
||||
scratch: &'a mut [u8],
|
||||
flow: FlowId,
|
||||
) -> (TunnResult<'a>, FlowId) {
|
||||
let probe = is_path_probe(packet);
|
||||
// A stale health check must never wait in the pending application FIFO.
|
||||
// Ask for a key and let the next scheduled probe use it.
|
||||
if probe && self.tunn.time_since_last_handshake().is_none() {
|
||||
return (self.tunn.format_handshake_initiation(scratch, false), flow);
|
||||
}
|
||||
let result = self.tunn.encapsulate(packet, scratch);
|
||||
if packet.is_empty() {
|
||||
return (result, 0);
|
||||
}
|
||||
if matches!(&result, TunnResult::WriteToNetwork(out) if carries_ip(out)) {
|
||||
self.last_activity = Some(Instant::now());
|
||||
if !probe {
|
||||
self.last_activity = Some(Instant::now());
|
||||
}
|
||||
return (result, flow);
|
||||
}
|
||||
// MAX_QUEUE_DEPTH in boringtun 0.7: the newest packet is dropped at 256.
|
||||
if self.queued.len() < 256 {
|
||||
self.queued.push_back((flow, packet.len()));
|
||||
self.queued
|
||||
.push_back((flow, if probe { 0 } else { packet.len() }));
|
||||
}
|
||||
(result, 0)
|
||||
}
|
||||
@@ -113,7 +122,7 @@ impl FlowTunnel {
|
||||
TunnResult::WriteToNetwork(out) if carries_ip(out) => {
|
||||
if let Some((tag, len)) = self.queued.pop_front() {
|
||||
flow = tag;
|
||||
plaintext_len = Some(len);
|
||||
plaintext_len = (len > 0).then_some(len);
|
||||
}
|
||||
}
|
||||
// An internal keepalive may occupy a slot in the bounded
|
||||
@@ -122,10 +131,13 @@ impl FlowTunnel {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if matches!(
|
||||
result,
|
||||
TunnResult::WriteToTunnelV4(..) | TunnResult::WriteToTunnelV6(..)
|
||||
) || plaintext_len.is_some()
|
||||
let application_data = match &result {
|
||||
TunnResult::WriteToTunnelV4(out, _) => !is_path_probe(out),
|
||||
TunnResult::WriteToTunnelV6(..) => true,
|
||||
_ => false,
|
||||
};
|
||||
if application_data
|
||||
|| plaintext_len.is_some()
|
||||
|| (self.last_activity.is_none() && self.tunn.time_since_last_handshake().is_some())
|
||||
{
|
||||
self.last_activity = Some(Instant::now());
|
||||
@@ -133,10 +145,10 @@ impl FlowTunnel {
|
||||
(result, flow, plaintext_len)
|
||||
}
|
||||
|
||||
fn health(&self, now: Instant, keep_warm: bool) -> PeerHealth {
|
||||
fn health(&self, now: Instant) -> PeerHealth {
|
||||
let since_handshake = self.tunn.time_since_last_handshake();
|
||||
let idle = self.queued.is_empty()
|
||||
&& (!keep_warm || since_handshake.is_some())
|
||||
&& since_handshake.is_some()
|
||||
&& self
|
||||
.last_activity
|
||||
.is_some_and(|at| now.duration_since(at) >= IDLE_AFTER);
|
||||
@@ -229,7 +241,7 @@ pub struct PeerStats {
|
||||
pub struct PeerHealth {
|
||||
/// Age of the last handshake while a usable WireGuard session exists.
|
||||
pub since_handshake: Option<Duration>,
|
||||
/// A previously established tunnel with no recent or queued IP traffic.
|
||||
/// A currently usable session with no recent or queued application traffic.
|
||||
pub idle: bool,
|
||||
}
|
||||
|
||||
@@ -290,12 +302,12 @@ impl Peer {
|
||||
}
|
||||
}
|
||||
|
||||
fn health(&self, keep_warm: bool) -> PeerHealth {
|
||||
fn health(&self) -> PeerHealth {
|
||||
let guard = match self.tunn.lock() {
|
||||
Ok(guard) => guard,
|
||||
Err(poisoned) => poisoned.into_inner(),
|
||||
};
|
||||
guard.health(Instant::now(), keep_warm)
|
||||
guard.health(Instant::now())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,14 +428,16 @@ impl WireguardDevice {
|
||||
}
|
||||
};
|
||||
let Some((len, selected_flow, data)) = result else {
|
||||
peer.counters
|
||||
.dropped_no_session
|
||||
.fetch_add(1, Ordering::Relaxed);
|
||||
if !is_path_probe(packet) {
|
||||
peer.counters
|
||||
.dropped_no_session
|
||||
.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
let sent = send_to_peer_flow(&peer, &scratch[..len], selected_flow);
|
||||
if sent && data {
|
||||
if sent && data && !is_path_probe(packet) {
|
||||
count_sent(&peer, packet.len());
|
||||
}
|
||||
sent
|
||||
@@ -523,7 +537,6 @@ impl WireguardDevice {
|
||||
|
||||
/// A snapshot of every peer.
|
||||
pub fn peers(&self) -> Vec<PeerSummary> {
|
||||
let warm_peer = self.inner.context.warm_peer(self.inner.network);
|
||||
let mut peers: Vec<PeerSummary> = read_lock(&self.inner.peers)
|
||||
.values()
|
||||
.map(|peer| {
|
||||
@@ -535,7 +548,7 @@ impl WireguardDevice {
|
||||
endpoint_id: peer.endpoint_id,
|
||||
public_key: peer.public_key,
|
||||
overlay_address_v4: overlay_v4,
|
||||
health: peer.health(warm_peer == Some(peer.endpoint_id)),
|
||||
health: peer.health(),
|
||||
stats: peer.stats(),
|
||||
path: peer.link.path_description(),
|
||||
max_datagram: peer.link.max_datagram_size(),
|
||||
@@ -675,10 +688,12 @@ async fn read_from_link(inner: Arc<Inner>, peer: Arc<Peer>) {
|
||||
.sink
|
||||
.deliver(inner.network, peer.endpoint_id, payload)
|
||||
.await;
|
||||
peer.counters.rx_packets.fetch_add(1, Ordering::Relaxed);
|
||||
peer.counters
|
||||
.rx_bytes
|
||||
.fetch_add(len as u64, Ordering::Relaxed);
|
||||
if !is_path_probe(&scratch[..len]) {
|
||||
peer.counters.rx_packets.fetch_add(1, Ordering::Relaxed);
|
||||
peer.counters
|
||||
.rx_bytes
|
||||
.fetch_add(len as u64, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
Outcome::Failed => {
|
||||
peer.counters
|
||||
@@ -809,24 +824,24 @@ mod flow_tests {
|
||||
let bk = WgSecretKey::from_bytes(&[2; 32]);
|
||||
let (mut a, mut b) = (tunnel(&ak, &bk), tunnel(&bk, &ak));
|
||||
let mut scratch = [0u8; SCRATCH];
|
||||
assert!(!a.health(Instant::now() + IDLE_AFTER, false).idle);
|
||||
assert!(!a.health(Instant::now() + IDLE_AFTER).idle);
|
||||
establish(&mut a, &mut b, &mut scratch);
|
||||
assert!(!a.health(Instant::now(), false).idle);
|
||||
assert!(!a.health(Instant::now()).idle);
|
||||
let activity = (a.last_activity, b.last_activity);
|
||||
let idle_at = Instant::now() + IDLE_AFTER;
|
||||
assert!(a.health(idle_at, true).idle);
|
||||
assert!(a.health(idle_at).idle);
|
||||
establish(&mut a, &mut b, &mut scratch);
|
||||
assert_eq!((a.last_activity, b.last_activity), activity);
|
||||
assert!(a.health(idle_at, true).idle);
|
||||
assert!(b.health(idle_at, false).idle);
|
||||
assert!(a.health(idle_at).idle);
|
||||
assert!(b.health(idle_at).idle);
|
||||
|
||||
let mut ip = [0u8; 20];
|
||||
ip[0] = 0x45;
|
||||
ip[2..4].copy_from_slice(&20u16.to_be_bytes());
|
||||
let ciphertext = wire(a.encapsulate(&ip, &mut scratch, 7).0);
|
||||
let _ = b.decapsulate(&ciphertext, &mut scratch);
|
||||
assert!(!a.health(Instant::now(), false).idle);
|
||||
assert!(!b.health(Instant::now(), false).idle);
|
||||
assert!(!a.health(Instant::now()).idle);
|
||||
assert!(!b.health(Instant::now()).idle);
|
||||
assert!(a.last_activity > activity.0 && b.last_activity > activity.1);
|
||||
|
||||
// Discard BoringTun's session keys to exercise an idle tunnel with no
|
||||
@@ -834,10 +849,9 @@ mod flow_tests {
|
||||
a.tunn
|
||||
.set_static_private(ak.to_static_secret(), ak.public().into_x25519(), None);
|
||||
let idle_at = Instant::now() + IDLE_AFTER;
|
||||
assert!(a.health(idle_at, false).idle);
|
||||
assert!(!a.health(idle_at, true).idle);
|
||||
assert!(!a.health(idle_at).idle);
|
||||
let _ = a.encapsulate(&ip, &mut scratch, 7);
|
||||
assert!(!a.health(idle_at, false).idle);
|
||||
assert!(!a.health(idle_at).idle);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -871,7 +885,7 @@ mod flow_tests {
|
||||
a.decapsulate(&[], &mut scratch).0,
|
||||
TunnResult::Done
|
||||
));
|
||||
assert!(a.health(Instant::now() + IDLE_AFTER, false).idle);
|
||||
assert!(a.health(Instant::now() + IDLE_AFTER).idle);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -441,8 +441,8 @@ async fn shared_networks<'a>(client: &Node, peer: &'a Node) -> [ExitNetwork<'a>;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore = "observes a full 180-second WireGuard key lifetime on real clocks"]
|
||||
async fn only_the_selected_exit_stays_keyed_through_idle_expiry() {
|
||||
#[ignore = "observes WireGuard's 120-second rekey timer on real clocks"]
|
||||
async fn confirmed_idle_paths_remain_usable_through_wireguard_rekeying() {
|
||||
let (client, peer) = shared_nodes().await;
|
||||
let [chosen, other] = shared_networks(&client, &peer).await;
|
||||
client
|
||||
@@ -463,39 +463,30 @@ async fn only_the_selected_exit_stays_keyed_through_idle_expiry() {
|
||||
.unwrap()
|
||||
};
|
||||
let epoch = tunnel(chosen.id).stats.counter_epoch;
|
||||
let mut old_key_seen = false;
|
||||
let mut old_keys_seen = false;
|
||||
tokio::time::timeout(Duration::from_secs(210), async {
|
||||
let mut poll = tokio::time::interval(Duration::from_millis(500));
|
||||
loop {
|
||||
poll.tick().await;
|
||||
let warm = tunnel(chosen.id);
|
||||
let cold = tunnel(other.id);
|
||||
let ordinary = tunnel(other.id);
|
||||
assert_eq!(warm.stats.counter_epoch, epoch);
|
||||
let warm_age = warm
|
||||
.health
|
||||
.since_handshake
|
||||
.expect("usable exit key throughout idle");
|
||||
assert_eq!((warm.stats.tx_bytes, warm.stats.rx_bytes), (0, 0));
|
||||
assert_eq!((cold.stats.tx_bytes, cold.stats.rx_bytes), (0, 0));
|
||||
if cold
|
||||
.health
|
||||
.since_handshake
|
||||
.is_some_and(|age| age >= Duration::from_secs(150))
|
||||
{
|
||||
old_key_seen = true;
|
||||
}
|
||||
if old_key_seen && !cold.health.is_up() {
|
||||
assert!(
|
||||
warm_age < Duration::from_secs(90),
|
||||
"exit key renewed before expiry"
|
||||
);
|
||||
assert!(warm.health.idle && cold.health.idle);
|
||||
assert_eq!((ordinary.stats.tx_bytes, ordinary.stats.rx_bytes), (0, 0));
|
||||
let ordinary_age = ordinary.health.since_handshake.expect("usable peer key");
|
||||
old_keys_seen |= warm_age.min(ordinary_age) >= Duration::from_secs(90);
|
||||
if old_keys_seen && warm_age.max(ordinary_age) < Duration::from_secs(60) {
|
||||
assert!(warm.health.idle && ordinary.health.idle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
})
|
||||
.await
|
||||
.expect("unselected peer's unused session expired");
|
||||
.expect("both confirmed data paths renewed their keys without application traffic");
|
||||
|
||||
let packet = ipv4_packet(chosen.client_addr, INTERNET, b"first IP packet after idle");
|
||||
client.tun().await.push_from_os(packet.clone());
|
||||
|
||||
@@ -2119,6 +2119,101 @@ async fn vip_udp_reaches_another_backend_after_the_selected_agent_stops() {
|
||||
alive.shutdown().await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn peer_speed_requires_a_bidirectional_data_path_and_can_measure_through_a_relay() {
|
||||
use tsunagi::agent::DataPath;
|
||||
use tsunagi::ipc::SpeedPhase;
|
||||
|
||||
let discovery = SharedMemoryDiscovery::new();
|
||||
let (name, secret) = network("speed-relayed");
|
||||
let blocked = Arc::new(std::sync::Mutex::new(std::collections::HashSet::new()));
|
||||
let a = WgAgent::spawn_cut_off(&discovery, "client", blocked.clone()).await;
|
||||
let b = WgAgent::spawn(&discovery, "server").await;
|
||||
let peer = b.endpoint_id();
|
||||
let key = peer.to_string();
|
||||
blocked.lock().unwrap().insert(peer);
|
||||
let net = a.agent.join_network(&name, &secret).await.unwrap();
|
||||
b.agent.join_network(&name, &secret).await.unwrap();
|
||||
wait_until(
|
||||
"authenticated control-only peer has advertised speed tests",
|
||||
|| async {
|
||||
let status = a.agent.network_status(net).await.ok()?;
|
||||
status
|
||||
.peers
|
||||
.iter()
|
||||
.find(|p| {
|
||||
p.endpoint_id == peer
|
||||
&& p.capabilities
|
||||
.iter()
|
||||
.any(|c| c.protocol == "speedtest" && c.enabled)
|
||||
})
|
||||
.map(|_| ())
|
||||
},
|
||||
)
|
||||
.await;
|
||||
let status = a.agent.network_status(net).await.unwrap();
|
||||
assert!(matches!(status.peers[0].data_path, DataPath::None));
|
||||
assert!(status.peers[0].data_rtt.is_none());
|
||||
assert!(!status.speed.capable.contains(&key));
|
||||
assert!(
|
||||
a.agent
|
||||
.start_speed_test(net, Some(peer), true)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
assert!(
|
||||
a.agent
|
||||
.network_status(net)
|
||||
.await
|
||||
.unwrap()
|
||||
.speed
|
||||
.peers
|
||||
.is_empty()
|
||||
);
|
||||
|
||||
let relay = WgAgent::spawn(&discovery, "relay").await;
|
||||
relay.agent.join_network(&name, &secret).await.unwrap();
|
||||
for (node, target) in [(&a, peer), (&b, a.endpoint_id())] {
|
||||
wait_until("end-to-end data RTT without a direct link", || async {
|
||||
let status = node.agent.network_status(net).await.ok()?;
|
||||
let p = status.peers.iter().find(|p| p.endpoint_id == target)?;
|
||||
(matches!(p.data_path, DataPath::Relayed { hops: 2, via } if via == relay.endpoint_id())
|
||||
&& p.data_rtt.is_some()
|
||||
&& status.speed.capable.contains(&target.to_string()))
|
||||
.then_some(())
|
||||
})
|
||||
.await;
|
||||
}
|
||||
a.agent
|
||||
.start_speed_test(net, Some(peer), true)
|
||||
.await
|
||||
.unwrap();
|
||||
let report = wait_until("both test directions carried over the relay", || async {
|
||||
let s = a.agent.network_status(net).await.ok()?.speed;
|
||||
let p = s.peers.get(&key)?;
|
||||
matches!(p.phase, SpeedPhase::Done | SpeedPhase::Failed(_)).then(|| p.clone())
|
||||
})
|
||||
.await;
|
||||
assert_eq!(report.phase, SpeedPhase::Done, "{report:?}");
|
||||
assert!(report.down.is_some() && report.up.is_some() && report.bytes > 0);
|
||||
assert!(report.path.unwrap().contains("2 hops"));
|
||||
relay.shutdown().await;
|
||||
wait_until(
|
||||
"losing only the relay clears data RTT and speed admission",
|
||||
|| async {
|
||||
let status = a.agent.network_status(net).await.ok()?;
|
||||
let p = status.peers.iter().find(|p| p.endpoint_id == peer)?;
|
||||
(matches!(p.data_path, DataPath::None)
|
||||
&& p.data_rtt.is_none()
|
||||
&& !status.speed.capable.contains(&key))
|
||||
.then_some(())
|
||||
},
|
||||
)
|
||||
.await;
|
||||
a.shutdown().await;
|
||||
b.shutdown().await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn peer_speed_measures_both_wireguard_directions_and_can_be_repeated() {
|
||||
use tsunagi::ipc::SpeedPhase;
|
||||
@@ -2155,6 +2250,20 @@ async fn peer_speed_measures_both_wireguard_directions_and_can_be_repeated() {
|
||||
.is_err()
|
||||
);
|
||||
b.agent.set_speed_test_metered(true);
|
||||
wait_until(
|
||||
"the initiator has confirmed the peer's data path",
|
||||
|| async {
|
||||
a.agent
|
||||
.network_status(net)
|
||||
.await
|
||||
.ok()?
|
||||
.speed
|
||||
.capable
|
||||
.contains(&key)
|
||||
.then_some(())
|
||||
},
|
||||
)
|
||||
.await;
|
||||
a.agent
|
||||
.start_speed_test(net, Some(remote), false)
|
||||
.await
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tsunagi-wireguard"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
description = "Independent authenticated WireGuard and Amnezia UDP carriers for tsunagi."
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
@@ -8,7 +8,7 @@ license = "WTFPL AND Apache-2.0"
|
||||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
tsunagi-core = { path = "../tsunagi-core", version = "1.0.11" }
|
||||
tsunagi-core = { path = "../tsunagi-core", version = "1.0.12" }
|
||||
iroh.workspace = true
|
||||
tokio = { workspace = true, features = ["net", "io-util", "time", "sync", "macros"] }
|
||||
serde.workspace = true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tsunagi"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
description = "The tsunagi command line agent."
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
@@ -12,11 +12,11 @@ name = "tsng"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
tsunagi-runtime = { path = "../tsunagi-runtime", version = "1.0.11" }
|
||||
tsunagi-core = { path = "../tsunagi-core", version = "1.0.11", features = ["tun-device", "dns-publish"] }
|
||||
tsunagi-wireguard = { path = "../tsunagi-wireguard", version = "1.0.11" }
|
||||
tsunagi-wg-quic = { path = "../tsunagi-wg-quic", version = "1.0.11" }
|
||||
tsunagi-tcp-tls = { path = "../tsunagi-tcp-tls", version = "1.0.11" }
|
||||
tsunagi-runtime = { path = "../tsunagi-runtime", version = "1.0.12" }
|
||||
tsunagi-core = { path = "../tsunagi-core", version = "1.0.12", features = ["tun-device", "dns-publish"] }
|
||||
tsunagi-wireguard = { path = "../tsunagi-wireguard", version = "1.0.12" }
|
||||
tsunagi-wg-quic = { path = "../tsunagi-wg-quic", version = "1.0.12" }
|
||||
tsunagi-tcp-tls = { path = "../tsunagi-tcp-tls", version = "1.0.12" }
|
||||
iroh.workspace = true
|
||||
tokio = { version = "1.53", features = ["rt", "rt-multi-thread", "sync", "time", "macros", "signal"] }
|
||||
tracing.workspace = true
|
||||
|
||||
@@ -3965,7 +3965,6 @@ fn member_row(row: &MemberRow<'_>) -> report::Row {
|
||||
}
|
||||
|
||||
use tsunagi::ipc::DataPathReport;
|
||||
let tunnel_up = row.tunnel.is_some_and(|tunnel| tunnel.is_up());
|
||||
let has_overlay = row.tunnel.is_some();
|
||||
// Online is online: a member reached through others is as much here as
|
||||
// one reached directly, and is said to be reached that way.
|
||||
@@ -3982,8 +3981,9 @@ fn member_row(row: &MemberRow<'_>) -> report::Row {
|
||||
),
|
||||
Some(DataPathReport::None) | None => ("connected · no data path yet".to_string(), false),
|
||||
};
|
||||
let idle = data_path_good && row.data_error.is_none() && row.tunnel.is_some_and(|t| t.idle);
|
||||
let show_counters = tunnel_up || idle;
|
||||
let confirmed = data_path_good && row.data_error.is_none() && row.data_rtt_ms.is_some();
|
||||
let show_counters = confirmed && row.tunnel.is_some_and(|t| t.is_up());
|
||||
let idle = show_counters && row.tunnel.is_some_and(|t| t.idle);
|
||||
|
||||
let mut detail = String::new();
|
||||
if let Some(v4) = row.overlay_address_v4 {
|
||||
@@ -4009,7 +4009,7 @@ fn member_row(row: &MemberRow<'_>) -> report::Row {
|
||||
}
|
||||
detail.extend(taken);
|
||||
|
||||
let health = if !data_path_good || row.data_error.is_some() || (has_overlay && !show_counters) {
|
||||
let health = if !confirmed || (has_overlay && !show_counters) {
|
||||
Health::Degraded
|
||||
} else {
|
||||
Health::Good
|
||||
@@ -5316,7 +5316,7 @@ mod status_tests {
|
||||
hostname: Some("music".into()),
|
||||
transport: "direct".into(),
|
||||
rtt_ms: Some(24),
|
||||
data_rtt_ms: None,
|
||||
data_rtt_ms: Some(16),
|
||||
data_transport_detail: None,
|
||||
exit_node: false,
|
||||
path: tsunagi::ipc::DataPathReport::Direct {
|
||||
@@ -5775,8 +5775,8 @@ mod status_tests {
|
||||
|
||||
#[test]
|
||||
fn a_member_reached_through_another_is_online_and_says_through_whom() {
|
||||
// No direct link, a path through somebody else: online all the same,
|
||||
// and said to be, rather than being shown as away or as a fault.
|
||||
// The member is online via the mesh. Reachability alone hasn't
|
||||
// confirmed an encrypted round trip to it.
|
||||
let mut network = network_after_a_peer_returned();
|
||||
network.members.push(MemberReport {
|
||||
record_version: 1,
|
||||
@@ -5804,7 +5804,7 @@ mod status_tests {
|
||||
"names the member it goes through: {text}"
|
||||
);
|
||||
assert!(!text.contains("offline"), "{text}");
|
||||
assert_eq!(out.worst(), Health::Good, "{text}");
|
||||
assert_eq!(out.worst(), Health::Degraded, "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -5880,7 +5880,7 @@ mod status_tests {
|
||||
#[test]
|
||||
fn an_idle_peer_keeps_its_counters_and_a_missing_route_is_still_degraded() {
|
||||
let mut network = network_after_a_peer_returned();
|
||||
let mut quiet = tunnel(ONLINE, None);
|
||||
let mut quiet = tunnel(ONLINE, Some(29));
|
||||
quiet.idle = true;
|
||||
network.overlay = Some(overlay(vec![quiet]));
|
||||
for (path, health) in [
|
||||
@@ -5907,6 +5907,25 @@ mod status_tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_key_and_a_control_rtt_cannot_make_an_unverified_data_path_idle() {
|
||||
let mut network = network_after_a_peer_returned();
|
||||
network.peers[0].data_rtt_ms = None;
|
||||
let mut quiet = tunnel(ONLINE, Some(29));
|
||||
quiet.idle = true;
|
||||
network.overlay = Some(overlay(vec![quiet]));
|
||||
let mut out = report::Report::new();
|
||||
out.push(network_section(&network, OWN, false));
|
||||
let text = out.render(false);
|
||||
assert_eq!(out.worst(), Health::Degraded, "{text}");
|
||||
assert!(text.contains("control RTT 24ms"), "{text}");
|
||||
assert!(
|
||||
text.contains("encrypted data channel is not ready yet"),
|
||||
"{text}"
|
||||
);
|
||||
assert!(!text.contains("· idle"), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn handshake_failures_with_nobody_connected_point_at_the_secret() {
|
||||
// The classic symptom of one member being given a different secret.
|
||||
|
||||
+6
-4
@@ -243,10 +243,12 @@ The client renews the selected exit peer's session key at 120 seconds, even
|
||||
when no IP traffic is flowing. The current key can carry packets during the
|
||||
exchange. Changing the exit moves this behavior to the new network and peer.
|
||||
|
||||
The device list shows **Idle** after an established tunnel has had 30 seconds
|
||||
without IP traffic. Handshakes and keepalives do not restart this interval.
|
||||
Pending IP packets, a missing path, or a selected exit waiting for a usable
|
||||
key still show **Waiting**. A reported transport failure shows **Error**.
|
||||
The device list shows **Idle** after 30 seconds without application traffic
|
||||
on a confirmed path with a usable key and an empty packet queue. Encrypted
|
||||
round-trip probes keep measuring an idle path all the way to the destination.
|
||||
Probes, handshakes and keepalives leave the idle timer and application counters
|
||||
unchanged. A missing key or an unconfirmed path shows **Waiting**. A reported
|
||||
transport failure shows **Error**.
|
||||
|
||||
User traffic counters count original IP bytes once when the encrypted frame is
|
||||
accepted by the logical transport, and once when decrypted on receipt. They do
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ let
|
||||
in
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = if withTray then "tsunagi" else "tsunagi-cli";
|
||||
version = "1.0.11";
|
||||
version = "1.0.12";
|
||||
|
||||
src = lib.cleanSource ../.;
|
||||
cargoLock.lockFile = ../Cargo.lock;
|
||||
|
||||
Reference in new issue
Block a user