mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-27 13:52:16 +00:00
discovery: auto-connect trusts rsRNS 1.5.0 and later without the opt-in
This commit is contained in:
1 parent
0d98f0fd5b
commit
8652acfaa3
7 files changed
+128
-47
No files matched your search
@@ -499,6 +499,12 @@ Exhaustive literals and matches over these types need updating:
|
||||
appear, so a default `rnsd` log is quieter than 1.4.0's. 1.4.0 mapped levels
|
||||
3 and 4 both to `INFO`. Set `loglevel = 4` for the old volume. `rnsd`
|
||||
ignores `-v`/`-q` in service mode, as it did before.
|
||||
- **Discovery auto-connect.** Without `autoconnect_unverified_implementations`,
|
||||
a discovered Backbone is auto-connected when it advertises `RNS` 1.5.7 or
|
||||
later (1.4.0 took 1.5.2; `RNS/Discovery.py:485-486`) or `rsRNS` 1.5.0 or
|
||||
later (1.4.0 required the opt-in for every `rsRNS` node). Any other
|
||||
implementation still needs the opt-in. Upstream trusts only `RNS`, so a
|
||||
Python node needs the opt-in to auto-connect to an `rsRNS` hub.
|
||||
- **Link MTU.** Links signal and adopt the next hop's hardware MTU when
|
||||
`link_mtu_discovery` is on. It is on by default (`RNS/Reticulum.py:105`,
|
||||
`RNS/Link.py:392-397`). Resources on such links use larger parts, and a
|
||||
|
||||
@@ -3104,9 +3104,9 @@ pub struct ReticulumConfig {
|
||||
/// auto-connect. Receiving discovery and installing a stamper are also
|
||||
/// required. Other discovered interface types are not auto-connected.
|
||||
pub autoconnect_discovered_interfaces: usize,
|
||||
/// Permit Backbone auto-connect when advertised implementation/version
|
||||
/// metadata does not pass the configured release floor, including rsRNS.
|
||||
/// The default check is metadata matching, not software attestation.
|
||||
/// Permit Backbone auto-connect for any advertised implementation/version.
|
||||
/// Without it only `RNS` 1.5.7 and `rsRNS` 1.5.0 or later qualify. The
|
||||
/// default check is metadata matching, not software attestation.
|
||||
pub autoconnect_unverified_implementations: bool,
|
||||
/// Python `autoconnect_interface_mode`. Unset gives auto-connected
|
||||
/// interfaces Gateway mode on transport nodes and Full mode otherwise.
|
||||
@@ -8302,9 +8302,9 @@ async fn maybe_autoconnect_discovered(handle: &ReticulumHandle, record: Discover
|
||||
}
|
||||
}
|
||||
|
||||
/// Python auto-connects only Backbone interfaces of a transport node running
|
||||
/// a trusted stack and release, unless unverified stacks are allowed; the
|
||||
/// transport requirement holds either way (Discovery.py).
|
||||
/// Auto-connects only Backbone interfaces of a transport node running a
|
||||
/// trusted stack and release (Python's, plus rsRNS), unless unverified stacks
|
||||
/// are allowed; the transport requirement holds either way (Discovery.py).
|
||||
fn autoconnect_admits(record: &DiscoveredInterface, config: &ReticulumConfig) -> bool {
|
||||
let admitted = rns_transport::discovery::autoconnect::qualifies(
|
||||
&record.info,
|
||||
@@ -15439,10 +15439,10 @@ loglevel = 7
|
||||
assert!(rc.autoconnect_unverified_implementations);
|
||||
}
|
||||
|
||||
/// Only Backbone interfaces from Python 1.5.7 or later, unless unverified
|
||||
/// stacks are allowed (Discovery.py).
|
||||
/// Only Backbone interfaces from RNS 1.5.7 or rsRNS 1.5.0 or later, unless
|
||||
/// unverified stacks are allowed (Discovery.py; rsRNS is ours).
|
||||
#[test]
|
||||
fn discovered_interfaces_auto_connect_like_python() {
|
||||
fn discovered_interfaces_auto_connect_by_stack_and_release() {
|
||||
let record = |interface_type: &str, impl_name: Option<&str>, version: Option<&str>| {
|
||||
DiscoveredInterface {
|
||||
info: rns_transport::discovery::app_data::DiscoveryInfo {
|
||||
@@ -15465,18 +15465,25 @@ loglevel = 7
|
||||
}
|
||||
};
|
||||
let mut config = ReticulumConfig::default();
|
||||
assert!(autoconnect_admits(
|
||||
&record("BackboneInterface", Some("RNS"), Some("1.6.0")),
|
||||
&config
|
||||
));
|
||||
for rejected in [
|
||||
record("TCPServerInterface", Some("RNS"), Some("1.5.5")),
|
||||
record("BackboneInterface", Some("RNS"), Some("1.5.6")),
|
||||
for admitted in [
|
||||
record("BackboneInterface", Some("RNS"), Some("1.6.0")),
|
||||
record(
|
||||
"BackboneInterface",
|
||||
Some("rsRNS"),
|
||||
Some(env!("CARGO_PKG_VERSION")),
|
||||
Some(rns_transport::discovery::constants::IMPLEMENTATION_VERSION),
|
||||
),
|
||||
] {
|
||||
assert!(
|
||||
autoconnect_admits(&admitted, &config),
|
||||
"{:?}",
|
||||
admitted.info
|
||||
);
|
||||
}
|
||||
for rejected in [
|
||||
record("TCPServerInterface", Some("RNS"), Some("1.5.5")),
|
||||
record("BackboneInterface", Some("RNS"), Some("1.5.6")),
|
||||
record("BackboneInterface", Some("rsRNS"), Some("1.4.0")),
|
||||
record("BackboneInterface", Some("MeshChatX"), Some("9.9.9")),
|
||||
record("BackboneInterface", None, None),
|
||||
] {
|
||||
assert!(
|
||||
@@ -15486,10 +15493,18 @@ loglevel = 7
|
||||
);
|
||||
}
|
||||
config.autoconnect_unverified_implementations = true;
|
||||
assert!(autoconnect_admits(
|
||||
&record("BackboneInterface", Some("rsRNS"), Some("1.4.0")),
|
||||
&config
|
||||
));
|
||||
for admitted in [
|
||||
record("BackboneInterface", Some("RNS"), Some("1.5.6")),
|
||||
record("BackboneInterface", Some("rsRNS"), Some("1.4.0")),
|
||||
record("BackboneInterface", Some("MeshChatX"), Some("9.9.9")),
|
||||
record("BackboneInterface", None, None),
|
||||
] {
|
||||
assert!(
|
||||
autoconnect_admits(&admitted, &config),
|
||||
"{:?}",
|
||||
admitted.info
|
||||
);
|
||||
}
|
||||
assert!(!autoconnect_admits(
|
||||
&record("TCPServerInterface", None, None),
|
||||
&config
|
||||
|
||||
@@ -183,26 +183,44 @@ fn decisions() -> serde_json::Value {
|
||||
fixture
|
||||
}
|
||||
|
||||
/// rsRNS releases in the fixture that Rust auto-connects without the opt-in
|
||||
/// and upstream refuses: a deliberate difference, as upstream trusts only RNS.
|
||||
const RSRNS_TRUSTED_ONLY_HERE: &[&str] = &["1.5.0", "1.6.0"];
|
||||
|
||||
/// Upstream's discovery admission and announce decisions, recorded by
|
||||
/// `tests/fixtures/discovery_autoconnect/gen_decisions.py`.
|
||||
#[test]
|
||||
fn autoconnect_and_announce_decisions_match_upstream() {
|
||||
let fixture = decisions();
|
||||
let mut differences = Vec::new();
|
||||
for case in fixture["qualified"].as_array().unwrap() {
|
||||
let mut record = discovered("hub", "relay.example.org", 4242);
|
||||
record.info.impl_name = case["impl_name"].as_str().map(Into::into);
|
||||
record.info.impl_version = case["version"].as_str().map(Into::into);
|
||||
record.info.transport_enabled = case["transport"].as_bool().unwrap();
|
||||
let allow_unverified = case["allow_unverified"].as_bool().unwrap();
|
||||
let config = ReticulumConfig {
|
||||
autoconnect_unverified_implementations: case["allow_unverified"].as_bool().unwrap(),
|
||||
autoconnect_unverified_implementations: allow_unverified,
|
||||
..ReticulumConfig::default()
|
||||
};
|
||||
assert_eq!(
|
||||
let (rust, upstream) = (
|
||||
autoconnect_admits(&record, &config),
|
||||
case["qualified"].as_bool().unwrap(),
|
||||
"{case}"
|
||||
);
|
||||
let version = case["version"].as_str().unwrap();
|
||||
if case["impl_name"] == "rsRNS"
|
||||
&& record.info.transport_enabled
|
||||
&& !allow_unverified
|
||||
&& RSRNS_TRUSTED_ONLY_HERE.contains(&version)
|
||||
{
|
||||
assert!(!upstream, "upstream refuses rsRNS: {case}");
|
||||
assert!(rust, "rsRNS 1.5.0 or later is trusted here: {case}");
|
||||
differences.push(version);
|
||||
} else {
|
||||
assert_eq!(rust, upstream, "{case}");
|
||||
}
|
||||
}
|
||||
assert_eq!(differences, RSRNS_TRUSTED_ONLY_HERE);
|
||||
for case in fixture["costs"].as_array().unwrap() {
|
||||
let mut record = discovered("hub", "relay.example.org", 4242);
|
||||
record.info.dst_cost = case["dst_cost"].as_f64();
|
||||
|
||||
@@ -11,7 +11,12 @@
|
||||
{"impl_name": "rsRNS", "version": "1.4.0", "transport": true, "allow_unverified": false, "qualified": false},
|
||||
{"impl_name": "rsRNS", "version": "1.4.0", "transport": true, "allow_unverified": true, "qualified": true},
|
||||
{"impl_name": "rsRNS", "version": "1.4.0", "transport": false, "allow_unverified": true, "qualified": false},
|
||||
{"impl_name": "RNS", "version": "1.5.5", "transport": false, "allow_unverified": true, "qualified": false}
|
||||
{"impl_name": "RNS", "version": "1.5.5", "transport": false, "allow_unverified": true, "qualified": false},
|
||||
{"impl_name": "rsRNS", "version": "1.4.9", "transport": true, "allow_unverified": false, "qualified": false},
|
||||
{"impl_name": "rsRNS", "version": "1.5.0", "transport": true, "allow_unverified": false, "qualified": false},
|
||||
{"impl_name": "rsRNS", "version": "1.6.0", "transport": true, "allow_unverified": false, "qualified": false},
|
||||
{"impl_name": "MeshChatX", "version": "9.9.9", "transport": true, "allow_unverified": false, "qualified": false},
|
||||
{"impl_name": "MeshChatX", "version": "9.9.9", "transport": true, "allow_unverified": true, "qualified": true}
|
||||
],
|
||||
"costs": [
|
||||
{"dst_cost": 23.5, "pr_cost": 15.8, "dst_value": 25.0, "pr_value": 15.8, "accepted": true},
|
||||
|
||||
@@ -28,6 +28,8 @@ for impl, version, transport, unverified in [
|
||||
("RNS", "1.5.7", True, False), ("RNS", "1.5.6", True, False),
|
||||
("rsRNS", "1.4.0", True, False), ("rsRNS", "1.4.0", True, True), ("rsRNS", "1.4.0", False, True),
|
||||
("RNS", "1.5.5", False, True),
|
||||
("rsRNS", "1.4.9", True, False), ("rsRNS", "1.5.0", True, False), ("rsRNS", "1.6.0", True, False),
|
||||
("MeshChatX", "9.9.9", True, False), ("MeshChatX", "9.9.9", True, True),
|
||||
]:
|
||||
R.should_autoconnect_unverified_implementations = staticmethod(lambda u=unverified: u)
|
||||
info = {"type": "BackboneInterface", "transport": transport, "impl_name": impl, "version": version}
|
||||
|
||||
@@ -7,14 +7,15 @@ use super::constants::{AUTOCONNECT_INTERFACE_TYPES, AUTOCONNECT_MINIMUM_VERSIONS
|
||||
/// Check the advertised type, transport state and implementation/version
|
||||
/// against the local auto-connect policy. Only a transport-enabled
|
||||
/// `BackboneInterface` is eligible. With `allow_unverified`, any advertised
|
||||
/// implementation/version qualifies; otherwise `RNS` must advertise at least
|
||||
/// version `1.5.7`.
|
||||
/// `rsRNS`, unknown implementations and missing versions require the opt-in.
|
||||
/// implementation/version qualifies; otherwise only `RNS` 1.5.7 or later and
|
||||
/// `rsRNS` 1.5.0 or later do ([`AUTOCONNECT_MINIMUM_VERSIONS`]). Other or
|
||||
/// missing implementations and missing or unparsable versions need the opt-in.
|
||||
///
|
||||
/// Comparison uses leading numeric components, not full semantic-version
|
||||
/// rules: for example, `1.5.2rc1` compares as `1.5.2`. These are sender-supplied
|
||||
/// claims, not attestation. This helper does not check
|
||||
/// freshness, endpoint validity, source permissions or available connection slots.
|
||||
/// Comparison uses leading numeric components, as Python's tuples, not full
|
||||
/// semantic-version rules: `1.5.0rc1` compares as `1.5.0`, and `1.5` sorts
|
||||
/// below `1.5.0`. These are sender-supplied claims, not attestation. This
|
||||
/// helper does not check freshness, endpoint validity, source permissions or
|
||||
/// available connection slots.
|
||||
pub fn qualifies(info: &DiscoveryInfo, allow_unverified: bool) -> bool {
|
||||
if !AUTOCONNECT_INTERFACE_TYPES.contains(&info.interface_type.as_str()) {
|
||||
return false;
|
||||
@@ -85,15 +86,48 @@ mod tests {
|
||||
assert!(!qualifies(&backbone(Some("RNS"), None), false));
|
||||
}
|
||||
|
||||
/// rsRNS hubs need the unverified opt-in, as unknown stacks and announces
|
||||
/// without an implementation do.
|
||||
/// rsRNS hubs qualify from 1.5.0 without the opt-in; upstream trusts only
|
||||
/// "RNS", so this is a deliberate difference.
|
||||
#[test]
|
||||
fn rust_and_unknown_stacks_need_the_unverified_opt_in() {
|
||||
fn rust_backbones_qualify_from_1_5_0() {
|
||||
assert_eq!(
|
||||
AUTOCONNECT_MINIMUM_VERSIONS,
|
||||
&[("RNS", Some("1.5.7")), ("rsRNS", Some("1.5.0"))]
|
||||
);
|
||||
for version in [
|
||||
crate::discovery::constants::IMPLEMENTATION_VERSION,
|
||||
"1.5.0",
|
||||
"1.5.0rc1",
|
||||
"1.5.0-rc1",
|
||||
"1.5.1",
|
||||
"1.6",
|
||||
"1.6.0",
|
||||
"2.0.0",
|
||||
] {
|
||||
assert!(
|
||||
qualifies(&backbone(Some("rsRNS"), Some(version)), false),
|
||||
"{version}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Without the opt-in, only the two known names at or above their floors
|
||||
/// qualify; with it, every one of these does.
|
||||
#[test]
|
||||
fn everything_else_needs_the_unverified_opt_in() {
|
||||
for info in [
|
||||
backbone(Some("rsRNS"), Some(env!("CARGO_PKG_VERSION"))),
|
||||
backbone(Some("rsRNS"), Some("99.0.0")),
|
||||
backbone(Some("OtherRNS"), Some("9.9.9")),
|
||||
backbone(None, Some("1.5.5")),
|
||||
backbone(Some("rsRNS"), Some("1.4.9")),
|
||||
backbone(Some("rsRNS"), Some("1.4.0")),
|
||||
backbone(Some("rsRNS"), Some("1.5")),
|
||||
backbone(Some("rsRNS"), Some("")),
|
||||
backbone(Some("rsRNS"), Some("next")),
|
||||
backbone(Some("rsRNS"), None),
|
||||
backbone(Some("RNS"), Some("1.5.6")),
|
||||
backbone(Some("RNS"), None),
|
||||
backbone(Some("MeshChatX"), Some("9.9.9")),
|
||||
backbone(Some("rsrns"), Some("1.6.0")),
|
||||
backbone(Some(""), Some("1.6.0")),
|
||||
backbone(None, Some("1.6.0")),
|
||||
backbone(None, None),
|
||||
] {
|
||||
assert!(!qualifies(&info, false), "{info:?}");
|
||||
@@ -105,10 +139,12 @@ mod tests {
|
||||
/// (Discovery.py).
|
||||
#[test]
|
||||
fn non_transport_interfaces_never_qualify() {
|
||||
let mut info = backbone(Some("RNS"), Some("1.6.0"));
|
||||
info.transport_enabled = false;
|
||||
assert!(!qualifies(&info, false));
|
||||
assert!(!qualifies(&info, true));
|
||||
for name in ["RNS", "rsRNS"] {
|
||||
let mut info = backbone(Some(name), Some("1.6.0"));
|
||||
info.transport_enabled = false;
|
||||
assert!(!qualifies(&info, false), "{name}");
|
||||
assert!(!qualifies(&info, true), "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Python auto-connects only Backbone interfaces (Discovery.py).
|
||||
|
||||
@@ -73,11 +73,10 @@ pub const IMPLEMENTATION_NAME: &str = "rsRNS";
|
||||
/// This transport crate's package version, emitted in discovery info (`0xFC`).
|
||||
pub const IMPLEMENTATION_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
/// Advertised-version floors for automatic connections. `RNS` has a `1.5.7`
|
||||
/// floor; `rsRNS` has none and requires the unverified-implementation opt-in.
|
||||
/// This policy checks sender claims, not authenticated software provenance.
|
||||
/// Advertised-version floors for auto-connect without the unverified opt-in
|
||||
/// (sender claims). Upstream trusts only `RNS`; `rsRNS` is a deliberate addition.
|
||||
pub const AUTOCONNECT_MINIMUM_VERSIONS: &[(&str, Option<&str>)] =
|
||||
&[("RNS", Some("1.5.7")), (IMPLEMENTATION_NAME, None)];
|
||||
&[("RNS", Some("1.5.7")), (IMPLEMENTATION_NAME, Some("1.5.0"))];
|
||||
|
||||
/// Age in seconds above which a record becomes `Unknown` (24 hours).
|
||||
/// Equality remains `Available`.
|
||||
|
||||
Reference in new issue
Block a user