mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-27 13:52:16 +00:00
discovery: announce KISS TCP clients and unset radio parameters as Python does
This commit is contained in:
1 parent
feb11b0089
commit
2e8fa290dc
3 files changed
+128
-33
No files matched your search
@@ -18,6 +18,7 @@
|
||||
- Python Reticulum 1.5 `rnstatus` and `rnpath` work against `rnsd-rs`, locally and with `-R`: interface stats carry every field they read, including announce and path request counts, violation counters and the transport instance, and remote management answers on the transport identity, as in Python Reticulum.
|
||||
- Announces held during an ingress burst on an IFAC interface are processed when released instead of being dropped, and released or replayed announces no longer count as received traffic again, as in Python Reticulum.
|
||||
- Interface discovery announces name this stack, `rsRNS`, and its version. `rnsd-rs` auto-connects only to Backbone interfaces announced by Python Reticulum 1.5.2 or later, or to any announced Backbone interface with `autoconnect_unverified_implementations`, and no longer stores or lists discovered TCP client interfaces, as in Python Reticulum.
|
||||
- Discovery announces a KISS-framed TCP client as a KISS interface and sends and reads unset radio parameters as nil, so Python and `rnsd-rs` read each other's KISS, Weave and RNode announces, as in Python Reticulum.
|
||||
|
||||
## 1.4.0 - 2026-10-12
|
||||
|
||||
|
||||
@@ -5876,15 +5876,11 @@ fn discovery_config_for_interface(
|
||||
None,
|
||||
None,
|
||||
),
|
||||
interface_factory::InterfaceConfig::TcpClient(c) if c.kiss_framing => (
|
||||
"TCPClientInterface",
|
||||
configured_reachable_on(section).or_else(|| Some(c.target_host.clone())),
|
||||
Some(c.target_port),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
// Python announces a KISS-framed TCP client as a KISS interface
|
||||
// (Discovery.py:230-234).
|
||||
interface_factory::InterfaceConfig::TcpClient(c) if c.kiss_framing => {
|
||||
("KISSInterface", None, None, None, None, None, None)
|
||||
}
|
||||
interface_factory::InterfaceConfig::Backbone(c) => (
|
||||
"BackboneInterface",
|
||||
configured_reachable_on(section).or_else(|| {
|
||||
@@ -12135,6 +12131,21 @@ loglevel = 7
|
||||
}
|
||||
}
|
||||
|
||||
/// Python announces a KISS-framed TCP client as a KISS interface with its
|
||||
/// discovery radio parameters and no address (Discovery.py:182-185, :230-234).
|
||||
#[test]
|
||||
fn a_kiss_framed_tcp_client_is_discovered_as_a_kiss_interface() {
|
||||
let config = Config::parse("[interfaces]\n[[kiss tnc]]\ntype = TCPClientInterface\nenabled = yes\nkiss_framing = yes\ntarget_host = 10.0.0.2\ntarget_port = 8001\ndiscoverable = yes\ndiscovery_frequency = 433775000\ndiscovery_modulation = AFSK\n").unwrap();
|
||||
let interfaces = synthesize_interfaces(&config, false).unwrap();
|
||||
let post_init = get_post_init_for_config(&config, &interfaces[0]).unwrap();
|
||||
let discovery =
|
||||
discovery_config_for_interface(&config, &interfaces[0], &post_init, true).unwrap();
|
||||
assert_eq!(discovery.interface_type, "KISSInterface");
|
||||
assert_eq!((discovery.reachable_on, discovery.port), (None, None));
|
||||
assert_eq!(discovery.frequency, Some(433_775_000));
|
||||
assert_eq!(discovery.modulation.as_deref(), Some("AFSK"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn discovery_disabled_by_default() {
|
||||
let h = dummy_handle();
|
||||
|
||||
@@ -209,24 +209,39 @@ fn info_to_map(info: &DiscoveryInfo) -> Vec<(Value, Value)> {
|
||||
if let Some(k) = &info.ifac_netkey {
|
||||
entries.push((u8_key(key::IFAC_NETKEY), Value::from(k.clone())));
|
||||
}
|
||||
if let Some(f) = info.frequency {
|
||||
entries.push((u8_key(key::FREQUENCY), Value::from(f)));
|
||||
}
|
||||
if let Some(b) = info.bandwidth {
|
||||
entries.push((u8_key(key::BANDWIDTH), Value::from(b)));
|
||||
}
|
||||
if let Some(sf) = info.spreading_factor {
|
||||
entries.push((u8_key(key::SPREADING_FACTOR), Value::from(sf)));
|
||||
}
|
||||
if let Some(cr) = info.coding_rate {
|
||||
entries.push((u8_key(key::CODING_RATE), Value::from(cr)));
|
||||
}
|
||||
if let Some(mod_) = &info.modulation {
|
||||
entries.push((u8_key(key::MODULATION), Value::from(mod_.clone())));
|
||||
}
|
||||
if let Some(ch) = info.channel {
|
||||
entries.push((u8_key(key::CHANNEL), Value::from(ch)));
|
||||
}
|
||||
// Python always writes a radio type's parameters, unset ones as nil.
|
||||
let required: &[u8] = match info.interface_type.as_str() {
|
||||
"RNodeInterface" => &[
|
||||
key::FREQUENCY,
|
||||
key::BANDWIDTH,
|
||||
key::SPREADING_FACTOR,
|
||||
key::CODING_RATE,
|
||||
],
|
||||
"WeaveInterface" => &[
|
||||
key::FREQUENCY,
|
||||
key::BANDWIDTH,
|
||||
key::CHANNEL,
|
||||
key::MODULATION,
|
||||
],
|
||||
"KISSInterface" => &[key::FREQUENCY, key::BANDWIDTH, key::MODULATION],
|
||||
_ => &[],
|
||||
};
|
||||
let radio = [
|
||||
(key::FREQUENCY, info.frequency.map(Value::from)),
|
||||
(key::BANDWIDTH, info.bandwidth.map(Value::from)),
|
||||
(
|
||||
key::SPREADING_FACTOR,
|
||||
info.spreading_factor.map(Value::from),
|
||||
),
|
||||
(key::CODING_RATE, info.coding_rate.map(Value::from)),
|
||||
(key::MODULATION, info.modulation.clone().map(Value::from)),
|
||||
(key::CHANNEL, info.channel.map(Value::from)),
|
||||
];
|
||||
entries.extend(radio.into_iter().filter_map(|(k, value)| {
|
||||
value
|
||||
.or_else(|| required.contains(&k).then_some(Value::Nil))
|
||||
.map(|value| (u8_key(k), value))
|
||||
}));
|
||||
|
||||
entries
|
||||
}
|
||||
@@ -306,17 +321,23 @@ pub fn decode_info(packed: &[u8]) -> Result<DiscoveryInfo, AppDataError> {
|
||||
}
|
||||
key::IFAC_NETNAME => info.ifac_netname = Some(value_as_string(&v, kb)?),
|
||||
key::IFAC_NETKEY => info.ifac_netkey = Some(value_as_string(&v, kb)?),
|
||||
key::FREQUENCY => info.frequency = Some(value_as_u64(&v, kb)?),
|
||||
key::BANDWIDTH => info.bandwidth = Some(value_as_u64(&v, kb)?),
|
||||
key::FREQUENCY => info.frequency = unset_or(&v, |v| value_as_u64(v, kb))?,
|
||||
key::BANDWIDTH => info.bandwidth = unset_or(&v, |v| value_as_u64(v, kb))?,
|
||||
key::SPREADING_FACTOR => {
|
||||
info.spreading_factor = Some(value_as_u64(&v, kb)?.min(u8::MAX as u64) as u8);
|
||||
info.spreading_factor = unset_or(&v, |v| {
|
||||
value_as_u64(v, kb).map(|n| n.min(u8::MAX as u64) as u8)
|
||||
})?;
|
||||
}
|
||||
key::CODING_RATE => {
|
||||
info.coding_rate = Some(value_as_u64(&v, kb)?.min(u8::MAX as u64) as u8);
|
||||
info.coding_rate = unset_or(&v, |v| {
|
||||
value_as_u64(v, kb).map(|n| n.min(u8::MAX as u64) as u8)
|
||||
})?;
|
||||
}
|
||||
key::MODULATION => info.modulation = Some(value_as_string(&v, kb)?),
|
||||
key::MODULATION => info.modulation = unset_or(&v, |v| value_as_string(v, kb))?,
|
||||
key::CHANNEL => {
|
||||
info.channel = Some(value_as_u64(&v, kb)?.min(u16::MAX as u64) as u16);
|
||||
info.channel = unset_or(&v, |v| {
|
||||
value_as_u64(v, kb).map(|n| n.min(u16::MAX as u64) as u16)
|
||||
})?;
|
||||
}
|
||||
_ => { /* unknown key: ignore for forward compat */ }
|
||||
}
|
||||
@@ -425,6 +446,18 @@ fn value_as_f64(v: &Value, kb: u8) -> Result<Option<f64>, AppDataError> {
|
||||
}
|
||||
}
|
||||
|
||||
/// A radio parameter Python leaves unset arrives as nil.
|
||||
fn unset_or<T>(
|
||||
v: &Value,
|
||||
read: impl FnOnce(&Value) -> Result<T, AppDataError>,
|
||||
) -> Result<Option<T>, AppDataError> {
|
||||
if v.is_nil() {
|
||||
Ok(None)
|
||||
} else {
|
||||
read(v).map(Some)
|
||||
}
|
||||
}
|
||||
|
||||
fn value_as_u64(v: &Value, kb: u8) -> Result<u64, AppDataError> {
|
||||
v.as_u64().ok_or(AppDataError::TypeMismatch {
|
||||
key: kb,
|
||||
@@ -634,6 +667,56 @@ mod tests {
|
||||
));
|
||||
}
|
||||
|
||||
/// Python's announcer always writes a radio type's parameters, unset ones
|
||||
/// as nil, and its receiver reads them unguarded (Discovery.py:218-234,
|
||||
/// :410-456).
|
||||
#[test]
|
||||
fn radio_types_carry_every_parameter_python_reads() {
|
||||
for (interface_type, keys) in [
|
||||
(
|
||||
"RNodeInterface",
|
||||
&[
|
||||
key::FREQUENCY,
|
||||
key::BANDWIDTH,
|
||||
key::SPREADING_FACTOR,
|
||||
key::CODING_RATE,
|
||||
][..],
|
||||
),
|
||||
(
|
||||
"WeaveInterface",
|
||||
&[
|
||||
key::FREQUENCY,
|
||||
key::BANDWIDTH,
|
||||
key::CHANNEL,
|
||||
key::MODULATION,
|
||||
][..],
|
||||
),
|
||||
(
|
||||
"KISSInterface",
|
||||
&[key::FREQUENCY, key::BANDWIDTH, key::MODULATION][..],
|
||||
),
|
||||
] {
|
||||
let info = DiscoveryInfo {
|
||||
interface_type: interface_type.into(),
|
||||
transport_id: [0x33; 16],
|
||||
..Default::default()
|
||||
};
|
||||
let packed = encode_info(&info).unwrap().packed;
|
||||
let Value::Map(map) = rmpv::decode::read_value(&mut Cursor::new(&packed)).unwrap()
|
||||
else {
|
||||
panic!("info is a map");
|
||||
};
|
||||
for k in keys {
|
||||
assert!(
|
||||
map.iter()
|
||||
.any(|(key, value)| value_as_u8(key) == Some(*k) && value.is_nil()),
|
||||
"{interface_type} carries {k:#04x}"
|
||||
);
|
||||
}
|
||||
assert_eq!(decode_info(&packed).unwrap(), info, "{interface_type}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_trip_rnode_info() {
|
||||
let info = sample_rnode();
|
||||
|
||||
Reference in new issue
Block a user