mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-22 23:10:33 +00:00
paths: pool target scales with used paths, and over-limit hops are culled
This commit is contained in:
1 parent
45172c1cac
commit
0e937f32ff
6 files changed
+262
-82
No files matched your search
@@ -251,15 +251,17 @@ impl TransportActor {
|
||||
};
|
||||
let check_unused = now > self.path_pool_last_checked + PATH_POOL_CHECK_INTERVAL;
|
||||
let interfaces = &self.interfaces;
|
||||
let (removed, unused) = self.path_table.cull(now, linger, check_unused, |id| {
|
||||
interfaces.get(&id).map(|entry| entry.bitrate)
|
||||
});
|
||||
if let Some(unused) = unused {
|
||||
let (removed, unused) =
|
||||
self.path_table
|
||||
.cull(now, linger, check_unused, self.hop_limiter, |id| {
|
||||
interfaces.get(&id).map(|entry| entry.bitrate)
|
||||
});
|
||||
if let Some((unused, target)) = unused {
|
||||
self.path_pool_last_checked = now;
|
||||
if unused > PATH_POOL_UNUSED_TARGET {
|
||||
if unused > target {
|
||||
debug!(
|
||||
culled = unused - PATH_POOL_UNUSED_TARGET,
|
||||
"culled never-used paths to reach the pool size target"
|
||||
culled = unused - target,
|
||||
target, "culled never-used paths to reach the pool size target"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Path-table lifetime against upstream RNS 1.6.0: never-used linger on a
|
||||
//! leaf and a transport node, the never-used pool cap, traffic marking use
|
||||
//! Path-table lifetime against upstream RNS 1.6.1: never-used linger on a
|
||||
//! leaf and a transport node, instance-local (0-hop) paths, the hop limiter,
|
||||
//! the never-used pool cap and its used-count scaling, traffic marking use
|
||||
//! without renewing a path, and rediscovery after a local Link that never
|
||||
//! established.
|
||||
//!
|
||||
@@ -17,7 +18,7 @@ fn golden() -> Value {
|
||||
"../../../tests/fixtures/path_table_lifecycle/path_table_lifecycle.json"
|
||||
))
|
||||
.unwrap();
|
||||
assert_eq!(v["provenance"]["version"], "1.6.0");
|
||||
assert_eq!(v["provenance"]["version"], "1.6.1");
|
||||
v
|
||||
}
|
||||
|
||||
@@ -99,12 +100,14 @@ async fn linger_case(case: &Value) {
|
||||
ids.insert(kind, i as u64 + 1);
|
||||
keep.push(rx);
|
||||
}
|
||||
// An interface Transport no longer has.
|
||||
ids.insert("gone", 99);
|
||||
let t = now();
|
||||
let entries = case["entries"].as_array().unwrap();
|
||||
for (i, e) in entries.iter().enumerate() {
|
||||
let mut p = PathEntry::new(
|
||||
None,
|
||||
1,
|
||||
e["hops"].as_u64().unwrap() as u8,
|
||||
ids[e["iface"].as_str().unwrap()],
|
||||
InterfaceMode::Full,
|
||||
);
|
||||
@@ -118,7 +121,7 @@ async fn linger_case(case: &Value) {
|
||||
assert_eq!(
|
||||
live.contains_key(&h16(i as u64 + 1)),
|
||||
e["survives"].as_bool().unwrap(),
|
||||
"transport={transport} {}: upstream cull (Transport.py:1118-1160@1.6.0)",
|
||||
"transport={transport} {}: upstream cull (Transport.py:1180-1220@1.6.1)",
|
||||
e["label"]
|
||||
);
|
||||
}
|
||||
@@ -174,16 +177,86 @@ async fn never_used_pool_is_culled_to_the_upstream_target() {
|
||||
.iter()
|
||||
.map(|v| v.as_u64().unwrap())
|
||||
.collect();
|
||||
assert_eq!(
|
||||
removed, want,
|
||||
"PATH_POOL_UNUSED_TARGET cull (Transport.py:1150-1156@1.6.0)"
|
||||
);
|
||||
assert_eq!(removed, want, "pool cull (Transport.py:1220-1228@1.6.1)");
|
||||
assert_eq!(
|
||||
(0..field("used_count")).all(|j| live.contains_key(&h16(count + j + 1))),
|
||||
c["used_survive"].as_bool().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn paths_beyond_the_hop_limiter_are_culled() {
|
||||
let g = golden();
|
||||
let c = &g["hop_limit"];
|
||||
let (mut actor, tx) = TransportActor::new();
|
||||
tx.try_send(TransportMessage::SetTransportEnabled { enabled: true })
|
||||
.unwrap();
|
||||
tx.try_send(TransportMessage::SetFilterPolicy {
|
||||
policy: crate::destination_filter::FilterPolicy {
|
||||
hop_limiter: c["hop_limiter"].as_u64().unwrap() as u8,
|
||||
..Default::default()
|
||||
},
|
||||
})
|
||||
.unwrap();
|
||||
let (entry, _rx) = iface("a", 10_000_000, InterfaceMode::Full);
|
||||
tx.try_send(TransportMessage::RegisterInterface { id: 1, entry })
|
||||
.unwrap();
|
||||
let t = now();
|
||||
let entries = c["entries"].as_array().unwrap();
|
||||
for (i, e) in entries.iter().enumerate() {
|
||||
let hops = e["hops"].as_u64().unwrap() as u8;
|
||||
let mut p = PathEntry::new(None, hops, 1, InterfaceMode::Full);
|
||||
p.timestamp = t - 30.0;
|
||||
p.used = t - 1.0;
|
||||
actor.path_table.insert(h16(i as u64 + 1), p);
|
||||
}
|
||||
let live = run(actor, &tx).await;
|
||||
for (i, e) in entries.iter().enumerate() {
|
||||
assert_eq!(
|
||||
live.contains_key(&h16(i as u64 + 1)),
|
||||
e["survives"].as_bool().unwrap(),
|
||||
"hops {} (Transport.py:1216-1219@1.6.1)",
|
||||
e["hops"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn never_used_pool_target_shrinks_as_used_paths_grow() {
|
||||
let g = golden();
|
||||
for c in g["pool_scaling"].as_array().unwrap() {
|
||||
let (mut actor, tx) = TransportActor::new();
|
||||
tx.try_send(TransportMessage::SetTransportEnabled { enabled: true })
|
||||
.unwrap();
|
||||
actor.path_pool_last_checked = 0.0;
|
||||
let (entry, _rx) = iface("a", 10_000_000, InterfaceMode::Full);
|
||||
tx.try_send(TransportMessage::RegisterInterface { id: 1, entry })
|
||||
.unwrap();
|
||||
let t = now();
|
||||
let (unused, used) = (c["unused"].as_u64().unwrap(), c["used"].as_u64().unwrap());
|
||||
for i in 0..unused {
|
||||
let mut p = PathEntry::new(None, 1, 1, InterfaceMode::Full);
|
||||
p.timestamp = t - 30.0;
|
||||
p.expires = t + 3600.0 + i as f64;
|
||||
actor.path_table.insert(h16(i + 1), p);
|
||||
}
|
||||
for j in 0..used {
|
||||
let mut p = PathEntry::new(None, 1, 1, InterfaceMode::Full);
|
||||
p.timestamp = t - 30.0;
|
||||
p.expires = t + 60.0;
|
||||
p.used = t - 1.0;
|
||||
actor.path_table.insert(h16(unused + j + 1), p);
|
||||
}
|
||||
let live = run(actor, &tx).await;
|
||||
let got = serde_json::json!({
|
||||
"unused": unused, "used": used,
|
||||
"removed": (0..unused).filter(|i| !live.contains_key(&h16(i + 1))).count(),
|
||||
"used_survive": (0..used).all(|j| live.contains_key(&h16(unused + j + 1))),
|
||||
});
|
||||
assert_eq!(&got, c, "pool target (Transport.py:1220-1222@1.6.1)");
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn outbound_traffic_marks_use_without_renewing_the_path() {
|
||||
let g = golden();
|
||||
@@ -224,7 +297,7 @@ async fn outbound_traffic_marks_use_without_renewing_the_path() {
|
||||
"timestamp_unchanged": e.timestamp == ts0, "expires_unchanged": e.expires == exp0,
|
||||
"used_is_send_time": e.used >= before,
|
||||
});
|
||||
assert_eq!(&got, case, "Transport.py:1618@1.6.0");
|
||||
assert_eq!(&got, case, "Transport.py:1618@1.6.1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,7 +318,8 @@ async fn link_never_established_expires_the_path_and_rediscovers_as_upstream() {
|
||||
.unwrap();
|
||||
let dest = h16(7);
|
||||
let t = now();
|
||||
let mut p = PathEntry::new(None, 1, 1, InterfaceMode::Full);
|
||||
let hops = case["hops"].as_u64().unwrap() as u8;
|
||||
let mut p = PathEntry::new(None, hops, 1, InterfaceMode::Full);
|
||||
p.timestamp = t - 10.0;
|
||||
p.used = t - 1.0;
|
||||
actor.path_table.insert(dest, p);
|
||||
@@ -311,10 +385,10 @@ async fn link_never_established_expires_the_path_and_rediscovers_as_upstream() {
|
||||
}
|
||||
let got = serde_json::json!({
|
||||
"transport_enabled": case["transport_enabled"], "shared_client": case["shared_client"],
|
||||
"last_request_age_s": case["last_request_age_s"],
|
||||
"last_request_age_s": case["last_request_age_s"], "hops": hops,
|
||||
"path_kept": path_table(&tx).await.contains_key(&dest),
|
||||
"rediscovery_queued": requested,
|
||||
});
|
||||
assert_eq!(&got, case, "Transport.py:839-866@1.6.0");
|
||||
assert_eq!(&got, case, "Transport.py:896-918@1.6.1");
|
||||
}
|
||||
}
|
||||
@@ -42,8 +42,14 @@ pub const UNUSED_PATH_LINGER: f64 = 60.0 * 60.0 * 1.75;
|
||||
/// Never-used path linger on a leaf or shared-instance client (Transport.py).
|
||||
pub const UNUSED_PATH_LINGER_LEAF: f64 = 60.0 * 12.0;
|
||||
|
||||
/// Never-used paths kept by the pool cull (Transport.py).
|
||||
pub const PATH_POOL_UNUSED_TARGET: usize = 2048;
|
||||
/// Never-used paths the pool cull keeps at most (Transport.py).
|
||||
pub const PATH_POOL_UNUSED_MAX: usize = 1536;
|
||||
|
||||
/// Never-used paths the pool cull keeps however many paths are used.
|
||||
pub const PATH_POOL_UNUSED_MIN: usize = 512;
|
||||
|
||||
/// Used paths beyond this shrink the never-used pool target one for one.
|
||||
pub const PATH_POOL_USED_TARGET: usize = 2048;
|
||||
|
||||
/// Interfaces below this bitrate linger never-used paths longer (Transport.py).
|
||||
pub const PATH_SLOW_BITRATE: u64 = 25_000;
|
||||
|
||||
@@ -2,8 +2,9 @@ use crate::now_f64;
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
|
||||
use crate::constants::{
|
||||
AP_PATH_TIME, DESTINATION_TIMEOUT, InterfaceMode, MAX_RANDOM_BLOBS, PATH_POOL_UNUSED_TARGET,
|
||||
PATH_SLOW_BITRATE, PATH_SLOW_LINGER_FACTOR, PERSIST_RANDOM_BLOBS, PathState, ROAMING_PATH_TIME,
|
||||
AP_PATH_TIME, DESTINATION_TIMEOUT, InterfaceMode, MAX_RANDOM_BLOBS, PATH_POOL_UNUSED_MAX,
|
||||
PATH_POOL_UNUSED_MIN, PATH_POOL_USED_TARGET, PATH_SLOW_BITRATE, PATH_SLOW_LINGER_FACTOR,
|
||||
PERSIST_RANDOM_BLOBS, PathState, ROAMING_PATH_TIME,
|
||||
};
|
||||
use crate::messages::InterfaceId;
|
||||
use rns_wire::types::DestHash;
|
||||
@@ -233,25 +234,32 @@ impl PathTable {
|
||||
}
|
||||
|
||||
/// Python's path-table cull (Transport.py): drop expired
|
||||
/// paths, paths on a missing interface and never-used paths older than
|
||||
/// `linger` (x10 on slow interfaces). A 0-hop path neither expires nor
|
||||
/// lingers out. With `check_unused`, never-used
|
||||
/// paths beyond `PATH_POOL_UNUSED_TARGET` are dropped too, fast-interface
|
||||
/// and earliest-expiring first. Returns the removed count and, with
|
||||
/// `check_unused`, the never-used count before removal.
|
||||
/// paths, paths on a missing interface, never-used paths older than
|
||||
/// `linger` (x10 on slow interfaces) and paths of more than `hop_limiter`
|
||||
/// hops. A 0-hop path neither expires nor lingers out. With
|
||||
/// `check_unused`, never-used paths beyond the pool target are dropped
|
||||
/// too, fast-interface and earliest-expiring first; the target shrinks
|
||||
/// from `PATH_POOL_UNUSED_MAX` towards `PATH_POOL_UNUSED_MIN` once more
|
||||
/// than `PATH_POOL_USED_TARGET` paths are used. Returns the removed count
|
||||
/// and, with `check_unused`, the never-used count before removal and the
|
||||
/// target.
|
||||
pub fn cull(
|
||||
&mut self,
|
||||
now: f64,
|
||||
linger: f64,
|
||||
check_unused: bool,
|
||||
hop_limiter: u8,
|
||||
bitrate_of: impl Fn(InterfaceId) -> Option<u64>,
|
||||
) -> (usize, Option<usize>) {
|
||||
) -> (usize, Option<(usize, usize)>) {
|
||||
let mut stale: Vec<DestHash> = Vec::new();
|
||||
let mut unused: Vec<(u8, f64, DestHash)> = Vec::new();
|
||||
let mut used_count = 0usize;
|
||||
for (hash, entry) in &self.entries {
|
||||
let bitrate = bitrate_of(entry.interface_id);
|
||||
let slow = bitrate.is_some_and(|b| b > 0 && b < PATH_SLOW_BITRATE);
|
||||
if check_unused && entry.used == 0.0 {
|
||||
if entry.used != 0.0 {
|
||||
used_count += 1;
|
||||
} else if check_unused {
|
||||
unused.push((u8::from(slow), entry.expires, *hash));
|
||||
}
|
||||
let factor = if slow { PATH_SLOW_LINGER_FACTOR } else { 1.0 };
|
||||
@@ -259,13 +267,17 @@ impl PathTable {
|
||||
if (!local && now > entry.expires)
|
||||
|| bitrate.is_none()
|
||||
|| (!local && entry.used == 0.0 && now > entry.timestamp + linger * factor)
|
||||
|| entry.hops > hop_limiter
|
||||
{
|
||||
stale.push(*hash);
|
||||
}
|
||||
}
|
||||
let unused_count = check_unused.then_some(unused.len());
|
||||
if unused.len() > PATH_POOL_UNUSED_TARGET {
|
||||
let cull_count = unused.len() - PATH_POOL_UNUSED_TARGET;
|
||||
let unused_target = PATH_POOL_UNUSED_MIN.max(
|
||||
PATH_POOL_UNUSED_MAX.saturating_sub(used_count.saturating_sub(PATH_POOL_USED_TARGET)),
|
||||
);
|
||||
let unused_count = check_unused.then_some((unused.len(), unused_target));
|
||||
if unused.len() > unused_target {
|
||||
let cull_count = unused.len() - unused_target;
|
||||
unused.sort_by(|a, b| {
|
||||
a.0.cmp(&b.0)
|
||||
.then(a.1.total_cmp(&b.1))
|
||||
@@ -381,9 +393,13 @@ mod tests {
|
||||
assert!(!table.has_path(&remote));
|
||||
assert_eq!(table.iter_live().count(), 1);
|
||||
|
||||
let (removed, _) = table.cull(now, crate::constants::UNUSED_PATH_LINGER, false, |_| {
|
||||
Some(1_000_000)
|
||||
});
|
||||
let (removed, _) = table.cull(
|
||||
now,
|
||||
crate::constants::UNUSED_PATH_LINGER,
|
||||
false,
|
||||
128,
|
||||
|_| Some(1_000_000),
|
||||
);
|
||||
assert_eq!(removed, 1);
|
||||
assert!(table.has_path(&local));
|
||||
|
||||
@@ -392,11 +408,37 @@ mod tests {
|
||||
assert!(table.has_path(&local));
|
||||
assert_eq!(table.cull_expired_batch(16), 0);
|
||||
|
||||
let (removed, _) = table.cull(now, crate::constants::UNUSED_PATH_LINGER, false, |_| None);
|
||||
let (removed, _) = table.cull(
|
||||
now,
|
||||
crate::constants::UNUSED_PATH_LINGER,
|
||||
false,
|
||||
128,
|
||||
|_| None,
|
||||
);
|
||||
assert_eq!(removed, 1);
|
||||
assert!(table.get(&local).is_none());
|
||||
}
|
||||
|
||||
/// Transport.py 1.6.1 (023849ed): 1536 never-used paths at most, fewer
|
||||
/// once more than 2048 are used, never below 512.
|
||||
#[test]
|
||||
fn never_used_pool_target_follows_the_used_count() {
|
||||
let now = now_f64();
|
||||
let pool = |unused: usize, used: usize| {
|
||||
let mut table = PathTable::new();
|
||||
for i in 0..unused + used {
|
||||
let mut entry = PathEntry::new(None, 1, 1, InterfaceMode::Full);
|
||||
entry.used = if i < used { now } else { 0.0 };
|
||||
table.insert((i as u128).to_be_bytes(), entry);
|
||||
}
|
||||
let (removed, report) = table.cull(now, f64::MAX, true, 128, |_| Some(1_000_000));
|
||||
(removed, report)
|
||||
};
|
||||
assert_eq!(pool(1600, 0), (64, Some((1600, 1536))));
|
||||
assert_eq!(pool(1600, 2148), (164, Some((1600, 1436))));
|
||||
assert_eq!(pool(600, 3100), (88, Some((600, 512))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn use_leaves_lifetime_and_liveness_proof_renews_it() {
|
||||
let mut table = PathTable::new();
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
|
||||
Drives upstream Transport.jobs() and Transport.outbound() on synthetic tables
|
||||
and records what upstream leaves in them: never-used linger on a leaf and on a
|
||||
transport node, the never-used pool cap, the outbound
|
||||
use mark and the rediscovery after a link that never established. Every
|
||||
expected value is read back from upstream's own tables.
|
||||
transport node, instance-local (0-hop) paths, the hop limiter, the never-used
|
||||
pool cap and its used-count scaling, the outbound use mark and the rediscovery
|
||||
after a link that never established. Every expected value is read back from
|
||||
upstream's own tables.
|
||||
|
||||
Usage: generate.py [OUT] (default: path_table_lifecycle.json beside this file)
|
||||
Until the pin lift, set RATSPEAK_UPSTREAM_RETICULUM_DIR to upstream/candidate/Reticulum.
|
||||
"""
|
||||
import json, os, subprocess, sys, time
|
||||
|
||||
@@ -19,7 +21,7 @@ sys.path.insert(0, RNS_DIR)
|
||||
import RNS
|
||||
from RNS.Transport import Transport
|
||||
from RNS.Interfaces.Interface import Interface
|
||||
assert RNS.__version__ == "1.6.0", RNS.__version__
|
||||
assert RNS.__version__ == "1.6.1", RNS.__version__
|
||||
T = sys.modules["RNS.Transport"]
|
||||
RNS.loglevel = RNS.LOG_CRITICAL
|
||||
OUT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(HERE, "path_table_lifecycle.json")
|
||||
@@ -75,22 +77,27 @@ BITRATES = {"fast": 10_000_000, "slow": 9600, "zero": 0, "none": None, "edge": 2
|
||||
|
||||
def linger(linger_s, transport):
|
||||
L = linger_s
|
||||
specs = [("fast_young", "fast", L - 60, None), ("fast_old", "fast", L + 1, None),
|
||||
("fast_old_used", "fast", L * 20, 5.0), ("slow_past_x1", "slow", L + 60, None),
|
||||
("slow_past_x10", "slow", L * 10 + 1, None), ("slow_inside_x10", "slow", L * 10 - 60, None),
|
||||
("zero_bitrate_old", "zero", L + 1, None), ("none_bitrate_old", "none", L + 1, None),
|
||||
("edge_bitrate_old", "edge", L + 1, None), ("expired_used", "fast", 60, 5.0)]
|
||||
# (label, interface, age, used age, hops); "gone" is an interface Transport no longer has.
|
||||
specs = [("fast_young", "fast", L - 60, None, 1), ("fast_old", "fast", L + 1, None, 1),
|
||||
("fast_old_used", "fast", L * 20, 5.0, 1), ("slow_past_x1", "slow", L + 60, None, 1),
|
||||
("slow_past_x10", "slow", L * 10 + 1, None, 1), ("slow_inside_x10", "slow", L * 10 - 60, None, 1),
|
||||
("zero_bitrate_old", "zero", L + 1, None, 1), ("none_bitrate_old", "none", L + 1, None, 1),
|
||||
("edge_bitrate_old", "edge", L + 1, None, 1), ("expired_used", "fast", 60, 5.0, 1),
|
||||
("local_old_unused", "fast", L * 20, None, 0), ("local_expired", "fast", 60, None, 0),
|
||||
("local_on_gone_iface", "gone", 60, 5.0, 0)]
|
||||
ifaces = {k: FakeIface(k, b) for k, b in BITRATES.items()}
|
||||
gone = FakeIface("gone", 10_000_000)
|
||||
now = time.time()
|
||||
reset(now, ifaces.values(), linger_s, transport)
|
||||
entries = []
|
||||
for i, (label, kind, age, used_age) in enumerate(specs):
|
||||
for i, (label, kind, age, used_age, hops) in enumerate(specs):
|
||||
ts = now - age
|
||||
exp = (now - 10) if label == "expired_used" else ts + WEEK
|
||||
exp = (now - 10) if label in ("expired_used", "local_expired") else ts + WEEK
|
||||
used = 0 if used_age is None else now - used_age
|
||||
Transport.path_table[h16(i + 1)] = path_entry(ts, exp, ifaces[kind], used)
|
||||
iface = gone if kind == "gone" else ifaces[kind]
|
||||
Transport.path_table[h16(i + 1)] = path_entry(ts, exp, iface, used, hops)
|
||||
entries.append({"label": label, "iface": kind, "age_s": age, "expires_rel_s": exp - now,
|
||||
"used_age_s": used_age})
|
||||
"used_age_s": used_age, "hops": hops})
|
||||
Transport.jobs()
|
||||
for i, e in enumerate(entries):
|
||||
e["survives"] = h16(i + 1) in Transport.path_table
|
||||
@@ -121,6 +128,35 @@ def pool():
|
||||
return dict(POOL, removed=removed, used_survive=used_survive)
|
||||
|
||||
|
||||
def hop_limit():
|
||||
a = FakeIface("a", 10_000_000)
|
||||
now = time.time()
|
||||
reset(now, [a], Transport.UNUSED_PATH_LINGER, True)
|
||||
saved, Transport.HOP_LIMITER = Transport.HOP_LIMITER, 4
|
||||
hops = [0, 3, 4, 5, 9]
|
||||
for i, h in enumerate(hops):
|
||||
Transport.path_table[h16(i + 1)] = path_entry(now - 30, now + WEEK, a, now - 1, h)
|
||||
Transport.jobs()
|
||||
Transport.HOP_LIMITER = saved
|
||||
return {"hop_limiter": 4, "entries": [{"hops": h, "survives": h16(i + 1) in Transport.path_table}
|
||||
for i, h in enumerate(hops)]}
|
||||
|
||||
|
||||
def pool_scaling(used_count):
|
||||
a = FakeIface("a", 10_000_000)
|
||||
now = time.time()
|
||||
reset(now, [a], Transport.UNUSED_PATH_LINGER, True)
|
||||
unused = 2100
|
||||
for i in range(unused):
|
||||
Transport.path_table[h16(i + 1)] = path_entry(now - 30, now + 3600 + i, a, 0)
|
||||
for j in range(used_count):
|
||||
Transport.path_table[h16(unused + j + 1)] = path_entry(now - 30, now + 60, a, now - 1)
|
||||
Transport.jobs()
|
||||
left = sum(1 for i in range(unused) if h16(i + 1) in Transport.path_table)
|
||||
return {"unused": unused, "used": used_count, "removed": unused - left,
|
||||
"used_survive": all(h16(unused + j + 1) in Transport.path_table for j in range(used_count))}
|
||||
|
||||
|
||||
def outbound(hops):
|
||||
a = FakeIface("a", 10_000_000)
|
||||
now = time.time()
|
||||
@@ -144,20 +180,20 @@ class FakeLink:
|
||||
self.status = RNS.Link.CLOSED; self.destination = type("D", (), {"hash": h})(); self.link_id = lid
|
||||
|
||||
|
||||
def pending_link(transport, shared_client, last_request_age):
|
||||
def pending_link(transport, shared_client, last_request_age, hops=1):
|
||||
a = FakeIface("a", 10_000_000)
|
||||
now = time.time()
|
||||
reset(now, [a], Transport.UNUSED_PATH_LINGER_LEAF, transport, shared_client)
|
||||
Transport.links_last_checked = 0.0
|
||||
dh = h16(7)
|
||||
Transport.path_table[dh] = path_entry(now - 10, now + WEEK, a, now - 1)
|
||||
Transport.path_table[dh] = path_entry(now - 10, now + WEEK, a, now - 1, hops)
|
||||
if last_request_age is not None:
|
||||
Transport.path_requests[dh] = now - last_request_age
|
||||
link = FakeLink(dh, h16(8))
|
||||
Transport.pending_links.append(link); Transport.pending_links_map[link.link_id] = link
|
||||
Transport.jobs()
|
||||
return {"transport_enabled": transport, "shared_client": shared_client, "last_request_age_s": last_request_age,
|
||||
"path_kept": dh in Transport.path_table,
|
||||
"hops": hops, "path_kept": dh in Transport.path_table,
|
||||
"rediscovery_queued": [e[0] for e in Transport.pending_discovery_prs] == [dh]}
|
||||
|
||||
|
||||
@@ -167,7 +203,9 @@ out = {
|
||||
"upstream": "Reticulum", "version": RNS.__version__, "commit": commit},
|
||||
"linger_leaf": linger(Transport.UNUSED_PATH_LINGER_LEAF, False),
|
||||
"linger_transport": linger(Transport.UNUSED_PATH_LINGER, True),
|
||||
"hop_limit": hop_limit(),
|
||||
"pool_cap": pool(),
|
||||
"pool_scaling": [pool_scaling(n) for n in (2048, 2500, 4000)],
|
||||
"outbound": [outbound(1), outbound(3)],
|
||||
"pending_link_rediscovery": [pending_link(False, False, None), pending_link(False, False, 10),
|
||||
pending_link(False, False, 25), pending_link(False, True, None),
|
||||
|
||||
+45
-27
@@ -1,39 +1,57 @@
|
||||
{
|
||||
"provenance": {"generator": "crates/rns-transport/tests/fixtures/path_table_lifecycle/generate.py", "upstream": "Reticulum", "version": "1.6.0", "commit": "cb1260891d1b6da8f6e9b21542c4f0cc0725cac4"},
|
||||
"provenance": {"generator": "crates/rns-transport/tests/fixtures/path_table_lifecycle/generate.py", "upstream": "Reticulum", "version": "1.6.1", "commit": "cff4d03fdbd6bfb63b765280cd944756ac5cce8d"},
|
||||
"linger_leaf": {"transport_enabled": false, "linger_s": 720, "entries": [
|
||||
{"label": "fast_young", "iface": "fast", "age_s": 660, "expires_rel_s": 604140.0, "used_age_s": null, "survives": true},
|
||||
{"label": "fast_old", "iface": "fast", "age_s": 721, "expires_rel_s": 604079.0, "used_age_s": null, "survives": false},
|
||||
{"label": "fast_old_used", "iface": "fast", "age_s": 14400, "expires_rel_s": 590400.0, "used_age_s": 5.0, "survives": true},
|
||||
{"label": "slow_past_x1", "iface": "slow", "age_s": 780, "expires_rel_s": 604020.0, "used_age_s": null, "survives": true},
|
||||
{"label": "slow_past_x10", "iface": "slow", "age_s": 7201, "expires_rel_s": 597599.0, "used_age_s": null, "survives": false},
|
||||
{"label": "slow_inside_x10", "iface": "slow", "age_s": 7140, "expires_rel_s": 597660.0, "used_age_s": null, "survives": true},
|
||||
{"label": "zero_bitrate_old", "iface": "zero", "age_s": 721, "expires_rel_s": 604079.0, "used_age_s": null, "survives": false},
|
||||
{"label": "none_bitrate_old", "iface": "none", "age_s": 721, "expires_rel_s": 604079.0, "used_age_s": null, "survives": false},
|
||||
{"label": "edge_bitrate_old", "iface": "edge", "age_s": 721, "expires_rel_s": 604079.0, "used_age_s": null, "survives": false},
|
||||
{"label": "expired_used", "iface": "fast", "age_s": 60, "expires_rel_s": -10.0, "used_age_s": 5.0, "survives": false}
|
||||
{"label": "fast_young", "iface": "fast", "age_s": 660, "expires_rel_s": 604140.0, "used_age_s": null, "hops": 1, "survives": true},
|
||||
{"label": "fast_old", "iface": "fast", "age_s": 721, "expires_rel_s": 604079.0, "used_age_s": null, "hops": 1, "survives": false},
|
||||
{"label": "fast_old_used", "iface": "fast", "age_s": 14400, "expires_rel_s": 590400.0, "used_age_s": 5.0, "hops": 1, "survives": true},
|
||||
{"label": "slow_past_x1", "iface": "slow", "age_s": 780, "expires_rel_s": 604020.0, "used_age_s": null, "hops": 1, "survives": true},
|
||||
{"label": "slow_past_x10", "iface": "slow", "age_s": 7201, "expires_rel_s": 597599.0, "used_age_s": null, "hops": 1, "survives": false},
|
||||
{"label": "slow_inside_x10", "iface": "slow", "age_s": 7140, "expires_rel_s": 597660.0, "used_age_s": null, "hops": 1, "survives": true},
|
||||
{"label": "zero_bitrate_old", "iface": "zero", "age_s": 721, "expires_rel_s": 604079.0, "used_age_s": null, "hops": 1, "survives": false},
|
||||
{"label": "none_bitrate_old", "iface": "none", "age_s": 721, "expires_rel_s": 604079.0, "used_age_s": null, "hops": 1, "survives": false},
|
||||
{"label": "edge_bitrate_old", "iface": "edge", "age_s": 721, "expires_rel_s": 604079.0, "used_age_s": null, "hops": 1, "survives": false},
|
||||
{"label": "expired_used", "iface": "fast", "age_s": 60, "expires_rel_s": -10.0, "used_age_s": 5.0, "hops": 1, "survives": false},
|
||||
{"label": "local_old_unused", "iface": "fast", "age_s": 14400, "expires_rel_s": 590400.0, "used_age_s": null, "hops": 0, "survives": true},
|
||||
{"label": "local_expired", "iface": "fast", "age_s": 60, "expires_rel_s": -10.0, "used_age_s": null, "hops": 0, "survives": true},
|
||||
{"label": "local_on_gone_iface", "iface": "gone", "age_s": 60, "expires_rel_s": 604740.0, "used_age_s": 5.0, "hops": 0, "survives": false}
|
||||
]},
|
||||
"linger_transport": {"transport_enabled": true, "linger_s": 6300.0, "entries": [
|
||||
{"label": "fast_young", "iface": "fast", "age_s": 6240.0, "expires_rel_s": 598560.0, "used_age_s": null, "survives": true},
|
||||
{"label": "fast_old", "iface": "fast", "age_s": 6301.0, "expires_rel_s": 598499.0, "used_age_s": null, "survives": false},
|
||||
{"label": "fast_old_used", "iface": "fast", "age_s": 126000.0, "expires_rel_s": 478800.0, "used_age_s": 5.0, "survives": true},
|
||||
{"label": "slow_past_x1", "iface": "slow", "age_s": 6360.0, "expires_rel_s": 598440.0, "used_age_s": null, "survives": true},
|
||||
{"label": "slow_past_x10", "iface": "slow", "age_s": 63001.0, "expires_rel_s": 541799.0, "used_age_s": null, "survives": false},
|
||||
{"label": "slow_inside_x10", "iface": "slow", "age_s": 62940.0, "expires_rel_s": 541860.0, "used_age_s": null, "survives": true},
|
||||
{"label": "zero_bitrate_old", "iface": "zero", "age_s": 6301.0, "expires_rel_s": 598499.0, "used_age_s": null, "survives": false},
|
||||
{"label": "none_bitrate_old", "iface": "none", "age_s": 6301.0, "expires_rel_s": 598499.0, "used_age_s": null, "survives": false},
|
||||
{"label": "edge_bitrate_old", "iface": "edge", "age_s": 6301.0, "expires_rel_s": 598499.0, "used_age_s": null, "survives": false},
|
||||
{"label": "expired_used", "iface": "fast", "age_s": 60, "expires_rel_s": -10.0, "used_age_s": 5.0, "survives": false}
|
||||
{"label": "fast_young", "iface": "fast", "age_s": 6240.0, "expires_rel_s": 598560.0, "used_age_s": null, "hops": 1, "survives": true},
|
||||
{"label": "fast_old", "iface": "fast", "age_s": 6301.0, "expires_rel_s": 598499.0, "used_age_s": null, "hops": 1, "survives": false},
|
||||
{"label": "fast_old_used", "iface": "fast", "age_s": 126000.0, "expires_rel_s": 478800.0, "used_age_s": 5.0, "hops": 1, "survives": true},
|
||||
{"label": "slow_past_x1", "iface": "slow", "age_s": 6360.0, "expires_rel_s": 598440.0, "used_age_s": null, "hops": 1, "survives": true},
|
||||
{"label": "slow_past_x10", "iface": "slow", "age_s": 63001.0, "expires_rel_s": 541799.0, "used_age_s": null, "hops": 1, "survives": false},
|
||||
{"label": "slow_inside_x10", "iface": "slow", "age_s": 62940.0, "expires_rel_s": 541860.0, "used_age_s": null, "hops": 1, "survives": true},
|
||||
{"label": "zero_bitrate_old", "iface": "zero", "age_s": 6301.0, "expires_rel_s": 598499.0, "used_age_s": null, "hops": 1, "survives": false},
|
||||
{"label": "none_bitrate_old", "iface": "none", "age_s": 6301.0, "expires_rel_s": 598499.0, "used_age_s": null, "hops": 1, "survives": false},
|
||||
{"label": "edge_bitrate_old", "iface": "edge", "age_s": 6301.0, "expires_rel_s": 598499.0, "used_age_s": null, "hops": 1, "survives": false},
|
||||
{"label": "expired_used", "iface": "fast", "age_s": 60, "expires_rel_s": -10.0, "used_age_s": 5.0, "hops": 1, "survives": false},
|
||||
{"label": "local_old_unused", "iface": "fast", "age_s": 126000.0, "expires_rel_s": 478800.0, "used_age_s": null, "hops": 0, "survives": true},
|
||||
{"label": "local_expired", "iface": "fast", "age_s": 60, "expires_rel_s": -10.0, "used_age_s": null, "hops": 0, "survives": true},
|
||||
{"label": "local_on_gone_iface", "iface": "gone", "age_s": 60, "expires_rel_s": 604740.0, "used_age_s": 5.0, "hops": 0, "survives": false}
|
||||
]},
|
||||
"pool_cap": {"count": 2100, "slow_every": 3, "expiry_base_s": 3600, "expiry_step_s": 240, "expiry_mod": 700, "used_count": 5, "removed": [16, 32, 64, 80, 179, 211, 227, 259, 275, 358, 374, 406, 422, 553, 569, 601, 617, 700, 716, 748, 764, 796, 895, 911, 943, 959, 1058, 1090, 1106, 1138, 1237, 1253, 1285, 1301, 1400, 1432, 1448, 1480, 1496, 1579, 1595, 1627, 1643, 1675, 1774, 1790, 1822, 1838, 1937, 1969, 1985, 2017], "used_survive": true},
|
||||
"hop_limit": {"hop_limiter": 4, "entries": [
|
||||
{"hops": 0, "survives": true},
|
||||
{"hops": 3, "survives": true},
|
||||
{"hops": 4, "survives": true},
|
||||
{"hops": 5, "survives": false},
|
||||
{"hops": 9, "survives": false}
|
||||
]},
|
||||
"pool_cap": {"count": 2100, "slow_every": 3, "expiry_base_s": 3600, "expiry_step_s": 240, "expiry_mod": 700, "used_count": 5, "removed": [1, 4, 7, 10, 13, 14, 16, 17, 20, 23, 26, 29, 32, 46, 49, 52, 55, 58, 61, 62, 64, 65, 68, 71, 74, 77, 80, 97, 100, 103, 106, 109, 112, 113, 116, 119, 122, 125, 128, 145, 148, 151, 154, 157, 160, 161, 164, 167, 170, 173, 176, 179, 193, 196, 199, 202, 205, 208, 209, 211, 212, 215, 218, 221, 224, 227, 241, 244, 247, 250, 253, 256, 259, 260, 263, 266, 269, 272, 275, 292, 295, 298, 301, 304, 307, 308, 311, 314, 317, 320, 323, 340, 343, 346, 349, 352, 355, 356, 358, 359, 362, 365, 368, 371, 374, 388, 391, 394, 397, 400, 403, 404, 406, 407, 410, 413, 416, 419, 422, 439, 442, 445, 448, 451, 454, 455, 458, 461, 464, 467, 470, 487, 490, 493, 496, 499, 502, 503, 506, 509, 512, 515, 518, 535, 538, 541, 544, 547, 550, 551, 553, 554, 557, 560, 563, 566, 569, 583, 586, 589, 592, 595, 598, 599, 601, 602, 605, 608, 611, 614, 617, 634, 637, 640, 643, 646, 649, 650, 653, 656, 659, 662, 665, 682, 685, 688, 691, 694, 697, 698, 700, 701, 704, 707, 710, 713, 716, 730, 733, 736, 739, 742, 745, 746, 748, 749, 752, 755, 758, 761, 764, 781, 784, 787, 790, 793, 796, 797, 800, 803, 806, 809, 812, 829, 832, 835, 838, 841, 844, 845, 848, 851, 854, 857, 860, 877, 880, 883, 886, 889, 892, 893, 895, 896, 899, 902, 905, 908, 911, 925, 928, 931, 934, 937, 940, 941, 943, 944, 947, 950, 953, 956, 959, 976, 979, 982, 985, 988, 991, 992, 995, 998, 1001, 1004, 1007, 1024, 1027, 1030, 1033, 1036, 1039, 1040, 1043, 1046, 1049, 1052, 1055, 1058, 1072, 1075, 1078, 1081, 1084, 1087, 1088, 1090, 1091, 1094, 1097, 1100, 1103, 1106, 1120, 1123, 1126, 1129, 1132, 1135, 1138, 1139, 1142, 1145, 1148, 1151, 1154, 1171, 1174, 1177, 1180, 1183, 1186, 1187, 1190, 1193, 1196, 1199, 1202, 1219, 1222, 1225, 1228, 1231, 1234, 1235, 1237, 1238, 1241, 1244, 1247, 1250, 1253, 1267, 1270, 1273, 1276, 1279, 1282, 1283, 1285, 1286, 1289, 1292, 1295, 1298, 1301, 1318, 1321, 1324, 1327, 1330, 1333, 1334, 1337, 1340, 1343, 1346, 1349, 1366, 1369, 1372, 1375, 1378, 1381, 1382, 1385, 1388, 1391, 1394, 1397, 1400, 1414, 1417, 1420, 1423, 1426, 1429, 1430, 1432, 1433, 1436, 1439, 1442, 1445, 1448, 1462, 1465, 1468, 1471, 1474, 1477, 1480, 1481, 1484, 1487, 1490, 1493, 1496, 1513, 1516, 1519, 1522, 1525, 1528, 1529, 1532, 1535, 1538, 1541, 1544, 1561, 1564, 1567, 1570, 1573, 1576, 1577, 1579, 1580, 1583, 1586, 1589, 1592, 1595, 1609, 1612, 1615, 1618, 1621, 1624, 1625, 1627, 1628, 1631, 1634, 1637, 1640, 1643, 1660, 1663, 1666, 1669, 1672, 1675, 1676, 1679, 1682, 1685, 1688, 1691, 1708, 1711, 1714, 1717, 1720, 1723, 1724, 1727, 1730, 1733, 1736, 1739, 1756, 1759, 1762, 1765, 1768, 1771, 1772, 1774, 1775, 1778, 1781, 1784, 1787, 1790, 1804, 1807, 1810, 1813, 1816, 1819, 1820, 1822, 1823, 1826, 1829, 1832, 1835, 1838, 1855, 1858, 1861, 1864, 1867, 1870, 1871, 1874, 1877, 1880, 1883, 1886, 1903, 1906, 1909, 1912, 1915, 1918, 1919, 1922, 1925, 1928, 1931, 1934, 1937, 1951, 1954, 1957, 1960, 1963, 1966, 1967, 1969, 1970, 1973, 1976, 1979, 1982, 1985, 1999, 2002, 2005, 2008, 2011, 2014, 2017, 2018, 2021, 2024, 2027, 2030, 2033, 2050, 2053, 2056, 2059, 2062, 2065, 2066, 2069, 2072, 2075, 2078, 2081, 2098], "used_survive": true},
|
||||
"pool_scaling": [
|
||||
{"unused": 2100, "used": 2048, "removed": 564, "used_survive": true},
|
||||
{"unused": 2100, "used": 2500, "removed": 1016, "used_survive": true},
|
||||
{"unused": 2100, "used": 4000, "removed": 1588, "used_survive": true}
|
||||
],
|
||||
"outbound": [
|
||||
{"hops": 1, "age_s": 3600.0, "sent": true, "timestamp_unchanged": true, "expires_unchanged": true, "used_is_send_time": true},
|
||||
{"hops": 3, "age_s": 3600.0, "sent": true, "timestamp_unchanged": true, "expires_unchanged": true, "used_is_send_time": true}
|
||||
],
|
||||
"pending_link_rediscovery": [
|
||||
{"transport_enabled": false, "shared_client": false, "last_request_age_s": null, "path_kept": false, "rediscovery_queued": true},
|
||||
{"transport_enabled": false, "shared_client": false, "last_request_age_s": 10, "path_kept": false, "rediscovery_queued": false},
|
||||
{"transport_enabled": false, "shared_client": false, "last_request_age_s": 25, "path_kept": false, "rediscovery_queued": true},
|
||||
{"transport_enabled": false, "shared_client": true, "last_request_age_s": null, "path_kept": false, "rediscovery_queued": false},
|
||||
{"transport_enabled": true, "shared_client": false, "last_request_age_s": null, "path_kept": true, "rediscovery_queued": false}
|
||||
{"transport_enabled": false, "shared_client": false, "last_request_age_s": null, "hops": 1, "path_kept": false, "rediscovery_queued": true},
|
||||
{"transport_enabled": false, "shared_client": false, "last_request_age_s": 10, "hops": 1, "path_kept": false, "rediscovery_queued": false},
|
||||
{"transport_enabled": false, "shared_client": false, "last_request_age_s": 25, "hops": 1, "path_kept": false, "rediscovery_queued": true},
|
||||
{"transport_enabled": false, "shared_client": true, "last_request_age_s": null, "hops": 1, "path_kept": false, "rediscovery_queued": false},
|
||||
{"transport_enabled": true, "shared_client": false, "last_request_age_s": null, "hops": 1, "path_kept": true, "rediscovery_queued": false}
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user