mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-27 13:52:16 +00:00
link: the link request stamper takes the MTU to signal
This commit is contained in:
1 parent
7f6d964789
commit
6bc738385a
2 files changed
+39
-16
No files matched your search
@@ -72,6 +72,9 @@ pub type LinkCostRecall = Arc<dyn Fn(&[u8; 16]) -> Option<f64> + Send + Sync>;
|
||||
#[derive(Clone)]
|
||||
pub struct LinkRequestStamper {
|
||||
pub policy: LinkStampPolicy,
|
||||
/// Python `Reticulum.link_mtu_discovery()`: whether requests signal the
|
||||
/// next hop's hardware MTU instead of the base MTU.
|
||||
pub link_mtu_discovery: bool,
|
||||
recall: LinkCostRecall,
|
||||
}
|
||||
|
||||
@@ -79,13 +82,18 @@ impl std::fmt::Debug for LinkRequestStamper {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("LinkRequestStamper")
|
||||
.field("policy", &self.policy)
|
||||
.field("link_mtu_discovery", &self.link_mtu_discovery)
|
||||
.finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
impl LinkRequestStamper {
|
||||
pub fn new(policy: LinkStampPolicy, recall: LinkCostRecall) -> Self {
|
||||
Self { policy, recall }
|
||||
Self {
|
||||
policy,
|
||||
link_mtu_discovery: true,
|
||||
recall,
|
||||
}
|
||||
}
|
||||
|
||||
/// Upstream default policy with no announced costs: requests are stamped
|
||||
@@ -105,21 +113,17 @@ impl LinkRequestStamper {
|
||||
}
|
||||
|
||||
/// Create an initiator Link with a stamped request where upstream stamps
|
||||
/// one. Blocks the calling thread while grinding, up to the policy timeout.
|
||||
/// one, signalling `signalled_mtu` (Link.py:392-397@1.6.0). Blocks the
|
||||
/// calling thread while grinding, up to the policy timeout.
|
||||
pub fn new_initiator(
|
||||
&self,
|
||||
destination_hash: [u8; 16],
|
||||
hops: u8,
|
||||
signalled_mtu: u32,
|
||||
) -> Result<(crate::link::Link, Vec<u8>), LinkStampError> {
|
||||
let cost = self.request_cost(&destination_hash);
|
||||
let ctl = self.policy.control(cost.unwrap_or(0.0));
|
||||
crate::link::Link::new_stamped_initiator(
|
||||
destination_hash,
|
||||
hops,
|
||||
cost,
|
||||
&ctl,
|
||||
rns_wire::constants::MTU as u32,
|
||||
)
|
||||
crate::link::Link::new_stamped_initiator(destination_hash, hops, cost, &ctl, signalled_mtu)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,6 +218,18 @@ mod tests {
|
||||
assert!(!link_request_stamp_valid(&dest, &request[..63], 0.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stamper_initiator_signals_the_given_mtu() {
|
||||
let stamper = LinkRequestStamper::without_recall(LinkStampPolicy::default());
|
||||
for mtu in [500, 262_144] {
|
||||
let (_, request) = stamper.new_initiator([0x5A; 16], 1, mtu).unwrap();
|
||||
assert_eq!(
|
||||
LinkRequestData::unpack(&request).unwrap().signalling.mtu,
|
||||
mtu
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stopped_generation_reports_failure() {
|
||||
let ctl = StampControl {
|
||||
|
||||
@@ -71,6 +71,12 @@ impl Drop for CancelOnDrop {
|
||||
}
|
||||
}
|
||||
|
||||
/// Python `Reticulum.link_mtu_discovery()`: the running instance's setting,
|
||||
/// on by default.
|
||||
pub fn link_mtu_discovery() -> bool {
|
||||
crate::reticulum::get_instance().is_none_or(|handle| handle.link_mtu_discovery())
|
||||
}
|
||||
|
||||
/// The MTU a new link request to `destination_hash` signals (Link.py:392-397@1.6.0):
|
||||
/// the next-hop interface's hardware MTU when discovery is on and that interface
|
||||
/// autoconfigures or fixes its MTU, otherwise the base MTU.
|
||||
@@ -79,9 +85,7 @@ pub async fn signalled_link_mtu(
|
||||
destination_hash: [u8; 16],
|
||||
) -> u32 {
|
||||
let base = rns_wire::constants::MTU as u32;
|
||||
let discovery =
|
||||
crate::reticulum::get_instance().is_none_or(|handle| handle.link_mtu_discovery());
|
||||
if !discovery {
|
||||
if !link_mtu_discovery() {
|
||||
return base;
|
||||
}
|
||||
let (response_tx, response_rx) = oneshot::channel();
|
||||
@@ -159,10 +163,11 @@ pub async fn new_initiator(
|
||||
}
|
||||
|
||||
/// A stamper for synchronous Link owners on a multi-threaded runtime: link
|
||||
/// costs are recalled from Transport by blocking in place. Elsewhere no cost
|
||||
/// is recalled and requests are stamped only under `always_stamp_lrs`.
|
||||
/// costs are recalled from Transport by blocking in place, and MTU discovery
|
||||
/// follows the running instance. Elsewhere no cost is recalled and requests
|
||||
/// are stamped only under `always_stamp_lrs`.
|
||||
pub fn blocking_stamper(transport_tx: mpsc::Sender<TransportMessage>) -> LinkRequestStamper {
|
||||
LinkRequestStamper::new(
|
||||
let mut stamper = LinkRequestStamper::new(
|
||||
link_stamp_policy(),
|
||||
Arc::new(move |destination_hash: &[u8; 16]| {
|
||||
let handle = tokio::runtime::Handle::try_current().ok()?;
|
||||
@@ -174,5 +179,7 @@ pub fn blocking_stamper(transport_tx: mpsc::Sender<TransportMessage>) -> LinkReq
|
||||
handle.block_on(recall_link_cost(&transport_tx, destination_hash))
|
||||
})
|
||||
}),
|
||||
)
|
||||
);
|
||||
stamper.link_mtu_discovery = link_mtu_discovery();
|
||||
stamper
|
||||
}
|
||||
Reference in new issue
Block a user