mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-22 23:10:33 +00:00
tunnels: an orphaned or loaded tunnel waits 10 minutes for its interface
This commit is contained in:
1 parent
54cdcbcc74
commit
26e4bc308d
4 files changed
+106
-5
No files matched your search
@@ -993,8 +993,9 @@ impl TransportActor {
|
||||
}
|
||||
}
|
||||
|
||||
/// Load a persisted tunnel unbound; only a later synthesis binds it.
|
||||
/// Python keeps a tunnel only when one of its paths loads.
|
||||
/// Load a persisted tunnel unbound, within the reconnect window; only a
|
||||
/// later synthesis binds it. Python keeps a tunnel only when one of its
|
||||
/// paths loads.
|
||||
fn load_unbound_tunnel(
|
||||
&mut self,
|
||||
tunnel_id: &[u8],
|
||||
@@ -1033,11 +1034,12 @@ impl TransportActor {
|
||||
if tunnel_paths.is_empty() {
|
||||
return false;
|
||||
}
|
||||
let window = now_f64() + crate::constants::TUNNEL_RECONNECT_WINDOW as f64;
|
||||
self.tunnel_table.insert(crate::tunnel::TunnelEntry {
|
||||
tunnel_id,
|
||||
interface_id: None,
|
||||
tunnel_paths,
|
||||
expires,
|
||||
expires: expires.min(window),
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
@@ -327,6 +327,65 @@ fn tunnels_without_an_interface_survive_a_reload() {
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
/// Python 1.6.1 caps a loaded tunnel's expiry at the reconnect window
|
||||
/// (Transport.py:636-637).
|
||||
#[test]
|
||||
fn loaded_tunnels_expire_within_the_reconnect_window() {
|
||||
let dir = unique_temp_dir("tunnel-reconnect-window");
|
||||
let now = now_f64();
|
||||
let window = crate::constants::TUNNEL_RECONNECT_WINDOW as f64;
|
||||
let path = |dest: u8| PersistedTunnelPath {
|
||||
used: None,
|
||||
destination_hash: vec![dest; 16],
|
||||
next_hop: None,
|
||||
hops: 1,
|
||||
expires: now + 600.0,
|
||||
timestamp: now,
|
||||
random_blobs: vec![vec![0x11; 10]],
|
||||
packet_hash: Some(vec![0x41; 32]),
|
||||
};
|
||||
let entry = |tunnel: u8, expires: f64| PersistedTunnelEntry {
|
||||
tunnel_id: vec![tunnel; 32],
|
||||
interface_id: 3,
|
||||
expires,
|
||||
paths: vec![path(tunnel)],
|
||||
interface_name: None,
|
||||
interface_hash: None,
|
||||
};
|
||||
let table = PersistedTunnelTable {
|
||||
entries: vec![
|
||||
entry(0x01, now + crate::constants::TUNNEL_TIMEOUT as f64),
|
||||
entry(0x02, now + 120.0),
|
||||
],
|
||||
version: PersistedTunnelTable::CURRENT_VERSION,
|
||||
};
|
||||
std::fs::write(
|
||||
dir.join("tunnel_table.msgpack"),
|
||||
rmp_serde::to_vec(&table).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut reader = hub();
|
||||
reader.handle_message(TransportMessage::SetStoragePaths {
|
||||
storage_dir: dir.clone(),
|
||||
role: crate::actor::StorageRole::Owner,
|
||||
done: None,
|
||||
});
|
||||
let long = reader.tunnel_table.get(&[0x01; 32]).unwrap().expires;
|
||||
assert!(
|
||||
long <= now_f64() + window && long > now + window - 5.0,
|
||||
"an eight-hour expiry loads capped at the window: {}",
|
||||
long - now
|
||||
);
|
||||
assert_eq!(
|
||||
reader.tunnel_table.get(&[0x02; 32]).unwrap().expires,
|
||||
now + 120.0,
|
||||
"a sooner expiry is kept"
|
||||
);
|
||||
stop(reader);
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_sidecar_tunnels_without_an_interface_survive_a_reload() {
|
||||
let dir = unique_temp_dir("sidecar-tunnel");
|
||||
|
||||
@@ -261,6 +261,10 @@ pub const TUNNEL_TIMEOUT: u64 = 28_800;
|
||||
/// Tunnel path timeout (8 hours, in seconds).
|
||||
pub const TUNNEL_PATH_TIMEOUT: u64 = 28_800;
|
||||
|
||||
/// How long an unbound tunnel awaits its interface's return (10 minutes, in
|
||||
/// seconds; Python `TUNNEL_RECONNECT_WINDOW`).
|
||||
pub const TUNNEL_RECONNECT_WINDOW: u64 = 600;
|
||||
|
||||
/// Exported announce-queue interval, in seconds. The current actor processes
|
||||
/// interface announce queues on its maintenance tick instead.
|
||||
pub const ANNOUNCE_QUEUE_INTERVAL: f64 = 1.0;
|
||||
|
||||
@@ -92,14 +92,16 @@ impl TunnelTable {
|
||||
}
|
||||
|
||||
/// Forget `interface_id`: it names no tunnel, and the tunnels bound to it
|
||||
/// become unbound but keep their paths. Returns
|
||||
/// how many tunnels were unbound.
|
||||
/// become unbound, keep their paths, and expire after the reconnect window
|
||||
/// unless a synthesis rebinds them. Returns how many tunnels were unbound.
|
||||
pub fn void_interface(&mut self, interface_id: InterfaceId) -> usize {
|
||||
self.by_interface.remove(&interface_id);
|
||||
let expires = crate::now_f64() + crate::constants::TUNNEL_RECONNECT_WINDOW as f64;
|
||||
let mut voided = 0;
|
||||
for entry in self.entries.values_mut() {
|
||||
if entry.interface_id == Some(interface_id) {
|
||||
entry.interface_id = None;
|
||||
entry.expires = expires;
|
||||
voided += 1;
|
||||
}
|
||||
}
|
||||
@@ -436,6 +438,40 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// Python 1.6.1 gives an orphaned tunnel `TUNNEL_RECONNECT_WINDOW` from
|
||||
/// the moment its interface goes, longer or shorter than before
|
||||
/// (Transport.py:1285-1288); a synthesis restores the full timeout.
|
||||
#[test]
|
||||
fn voiding_an_interface_starts_the_reconnect_window() {
|
||||
let now = 1_000_000.0;
|
||||
let _clock = crate::test_clock::Clock::at(now);
|
||||
let window = crate::constants::TUNNEL_RECONNECT_WINDOW as f64;
|
||||
let mut table = TunnelTable::new();
|
||||
handle_tunnel(&mut table, [0x01; 32], 1);
|
||||
table.insert(TunnelEntry {
|
||||
tunnel_id: [0x02; 32],
|
||||
interface_id: Some(1),
|
||||
tunnel_paths: HashMap::new(),
|
||||
expires: now + 60.0,
|
||||
});
|
||||
handle_tunnel(&mut table, [0x03; 32], 2);
|
||||
|
||||
assert_eq!(table.void_interface(1), 2);
|
||||
assert_eq!(table.get(&[0x01; 32]).unwrap().expires, now + window);
|
||||
assert_eq!(table.get(&[0x02; 32]).unwrap().expires, now + window);
|
||||
assert_eq!(
|
||||
table.get(&[0x03; 32]).unwrap().expires,
|
||||
now + crate::constants::TUNNEL_TIMEOUT as f64,
|
||||
"a tunnel on another interface keeps its expiry"
|
||||
);
|
||||
|
||||
handle_tunnel(&mut table, [0x01; 32], 3);
|
||||
assert_eq!(
|
||||
table.get(&[0x01; 32]).unwrap().expires,
|
||||
now + crate::constants::TUNNEL_TIMEOUT as f64
|
||||
);
|
||||
}
|
||||
|
||||
/// Python expires a tunnel TUNNEL_TIMEOUT after its synthesis
|
||||
/// (Transport.py), so the next cull keeps it.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user