mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-22 23:10:33 +00:00
rpc: a shared instance's path hash and state reach its clients
This commit is contained in:
1 parent
03b6f411ad
commit
d7ec577253
2 files changed
+52
No files matched your search
@@ -2824,6 +2824,17 @@ fn rpc_response_to_transport_response(
|
||||
out.value = entry.value;
|
||||
out.used = entry.used;
|
||||
out.lr_cost = entry.lr_cost;
|
||||
// Before 1.6.1 the hash is upstream's, of `str(interface)`.
|
||||
out.interface_hash = entry
|
||||
.interface_hash
|
||||
.as_deref()
|
||||
.and_then(|hash| hash.try_into().ok())
|
||||
.unwrap_or_else(|| rns_crypto::sha::sha256(entry.interface.as_bytes()));
|
||||
out.state = match entry.state {
|
||||
Some(1) => rns_transport::constants::PathState::Unresponsive,
|
||||
Some(2) => rns_transport::constants::PathState::Responsive,
|
||||
_ => rns_transport::constants::PathState::Unknown,
|
||||
};
|
||||
out.interface = entry.interface;
|
||||
out.interface_id = 0;
|
||||
out.interface_mode = rns_transport::constants::InterfaceMode::Full;
|
||||
|
||||
@@ -192,3 +192,44 @@ async fn interface_discovery_registers_its_announce_type() {
|
||||
.await
|
||||
);
|
||||
}
|
||||
|
||||
/// A shared instance's path table keeps 1.6.1's keys; a 1.6.0 instance's
|
||||
/// hash is upstream's, of the interface string.
|
||||
#[test]
|
||||
fn shared_instance_path_tables_carry_interface_hash_and_state() {
|
||||
let entry = |interface_hash: Option<Vec<u8>>, state| crate::rpc::PathTableEntry {
|
||||
hash: vec![0x51; 16],
|
||||
timestamp: 1.0,
|
||||
via: None,
|
||||
hops: 1,
|
||||
expires: 2.0,
|
||||
value: None,
|
||||
used: 0.0,
|
||||
lr_cost: None,
|
||||
interface: "TCPInterface[test]".into(),
|
||||
interface_hash,
|
||||
state,
|
||||
};
|
||||
let response = crate::rpc::RpcResponse::PathTable(vec![
|
||||
entry(Some(vec![0x77; 32]), Some(1)),
|
||||
entry(None, None),
|
||||
]);
|
||||
let Some(TransportQueryResponse::PathTable(entries)) =
|
||||
rpc_response_to_transport_response(response)
|
||||
else {
|
||||
panic!("expected a path table");
|
||||
};
|
||||
assert_eq!(entries[0].interface_hash, [0x77; 32]);
|
||||
assert_eq!(
|
||||
entries[0].state,
|
||||
rns_transport::constants::PathState::Unresponsive
|
||||
);
|
||||
assert_eq!(
|
||||
entries[1].interface_hash,
|
||||
rns_crypto::sha::sha256(b"TCPInterface[test]")
|
||||
);
|
||||
assert_eq!(
|
||||
entries[1].state,
|
||||
rns_transport::constants::PathState::Unknown
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user