mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-27 13:52:16 +00:00
runtime: normalize announce cap percent
This commit is contained in:
1 parent
08848509b6
commit
46449b21d3
5 files changed
+90
-7
No files matched your search
@@ -12,9 +12,12 @@ pub const RESOURCE_CACHE: u64 = 86400;
|
||||
pub const MAX_QUEUED_ANNOUNCES: usize = 16384;
|
||||
pub const QUEUED_ANNOUNCE_LIFE: u64 = 86400;
|
||||
|
||||
/// Percentage matching Python `Reticulum.ANNOUNCE_CAP = 2`; transport actor
|
||||
/// divides by 100 before applying to bitrate math.
|
||||
pub const ANNOUNCE_CAP: f64 = 2.0;
|
||||
/// Announce bandwidth cap as a fraction of interface bitrate (2%).
|
||||
///
|
||||
/// Python exposes/configures this as `2` percent, then stores `0.02` on live
|
||||
/// interfaces. Runtime registration must hand the transport actor the stored
|
||||
/// fraction, because queue spacing is calculated as `tx_time / announce_cap`.
|
||||
pub const ANNOUNCE_CAP: f64 = 0.02;
|
||||
|
||||
pub const MINIMUM_BITRATE: u64 = 5;
|
||||
pub const IFAC_MIN_SIZE: usize = 1;
|
||||
|
||||
@@ -1032,7 +1032,9 @@ impl InterfacePostInit {
|
||||
Self {
|
||||
outgoing: section.get_bool("outgoing").unwrap_or(true),
|
||||
bitrate: section.get_uint("bitrate"),
|
||||
announce_cap: section.get_float("announce_cap"),
|
||||
announce_cap: section
|
||||
.get_float("announce_cap")
|
||||
.and_then(normalize_announce_cap_percent),
|
||||
announce_rate_target,
|
||||
announce_rate_grace: section
|
||||
.get_uint("announce_rate_grace")
|
||||
@@ -1062,6 +1064,14 @@ impl InterfacePostInit {
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_announce_cap_percent(value: f64) -> Option<f64> {
|
||||
if value > 0.0 && value <= 100.0 {
|
||||
Some(value / 100.0)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Python `DEFAULT_IFAC_SIZE`: network interfaces 16 bytes, serial/packet-radio 8.
|
||||
pub fn default_ifac_size_for(config: &InterfaceConfig) -> usize {
|
||||
match config {
|
||||
@@ -1622,7 +1632,7 @@ mod tests {
|
||||
assert_eq!(pi.ifac_passphrase.as_deref(), Some("secret"));
|
||||
assert_eq!(pi.ifac_size, Some(16));
|
||||
assert!(!pi.ingress_control);
|
||||
assert!((pi.announce_cap.unwrap() - 5.0).abs() < f64::EPSILON);
|
||||
assert!((pi.announce_cap.unwrap() - 0.05).abs() < f64::EPSILON);
|
||||
assert_eq!(pi.ingress_overrides.enabled, Some(false));
|
||||
assert_eq!(pi.ingress_overrides.pr_burst_freq_new, Some(4.5));
|
||||
assert_eq!(pi.ingress_overrides.pr_burst_freq, Some(9.5));
|
||||
@@ -1630,6 +1640,26 @@ mod tests {
|
||||
assert_eq!(pi.ingress_overrides.egress_control, Some(true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn announce_cap_config_uses_python_percent_shape() {
|
||||
let mut section = ConfigSection::new();
|
||||
section.set("announce_cap", "2");
|
||||
let pi = InterfacePostInit::from_section(§ion);
|
||||
assert_eq!(pi.announce_cap, Some(0.02));
|
||||
|
||||
section.set("announce_cap", "100");
|
||||
let pi = InterfacePostInit::from_section(§ion);
|
||||
assert_eq!(pi.announce_cap, Some(1.0));
|
||||
|
||||
section.set("announce_cap", "0");
|
||||
let pi = InterfacePostInit::from_section(§ion);
|
||||
assert_eq!(pi.announce_cap, None);
|
||||
|
||||
section.set("announce_cap", "101");
|
||||
let pi = InterfacePostInit::from_section(§ion);
|
||||
assert_eq!(pi.announce_cap, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_synthesize_i2p() {
|
||||
let mut section = ConfigSection::new();
|
||||
|
||||
@@ -487,7 +487,7 @@ mod tests {
|
||||
announce_rate_target: None,
|
||||
announce_rate_grace: None,
|
||||
announce_rate_penalty: None,
|
||||
announce_cap: 2.0,
|
||||
announce_cap: 0.02,
|
||||
ifac_size: 0,
|
||||
tx_drops: 0,
|
||||
}];
|
||||
|
||||
@@ -3807,6 +3807,56 @@ egress_control = Yes
|
||||
assert_eq!(post_init.announce_rate_grace, Some(9));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn runtime_registration_uses_fractional_announce_cap() {
|
||||
let (transport_tx, mut transport_rx) = mpsc::channel::<TransportMessage>(4);
|
||||
let interface_controls: InterfaceControlMap =
|
||||
Arc::new(std::sync::Mutex::new(HashMap::new()));
|
||||
|
||||
let post_init = interface_factory::InterfacePostInit::from_section(&ConfigSection::new());
|
||||
register_interface_with_post_init(
|
||||
&transport_tx,
|
||||
test_interface_handle(920_001, None, "default-cap"),
|
||||
&post_init,
|
||||
None,
|
||||
&interface_controls,
|
||||
)
|
||||
.await;
|
||||
let TransportMessage::RegisterInterface { entry, .. } =
|
||||
transport_rx.recv().await.expect("default cap registration")
|
||||
else {
|
||||
panic!("expected RegisterInterface");
|
||||
};
|
||||
assert!((entry.announce_cap - ANNOUNCE_CAP).abs() < f64::EPSILON);
|
||||
|
||||
let mut section = ConfigSection::new();
|
||||
section.set("announce_cap", "5.0");
|
||||
let post_init = interface_factory::InterfacePostInit::from_section(§ion);
|
||||
register_interface_with_post_init(
|
||||
&transport_tx,
|
||||
test_interface_handle(920_002, None, "custom-cap"),
|
||||
&post_init,
|
||||
None,
|
||||
&interface_controls,
|
||||
)
|
||||
.await;
|
||||
let TransportMessage::RegisterInterface { entry, .. } =
|
||||
transport_rx.recv().await.expect("custom cap registration")
|
||||
else {
|
||||
panic!("expected RegisterInterface");
|
||||
};
|
||||
assert!((entry.announce_cap - 0.05).abs() < f64::EPSILON);
|
||||
|
||||
interface_tasks()
|
||||
.lock()
|
||||
.expect("interface_tasks mutex poisoned")
|
||||
.remove(&920_001);
|
||||
interface_tasks()
|
||||
.lock()
|
||||
.expect("interface_tasks mutex poisoned")
|
||||
.remove(&920_002);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn dynamic_child_inherits_parent_control_settings() {
|
||||
let parent_id = 910_001;
|
||||
|
||||
@@ -1721,7 +1721,7 @@ mod tests {
|
||||
announce_rate_target: Some(3600.0),
|
||||
announce_rate_grace: Some(5),
|
||||
announce_rate_penalty: Some(30.0),
|
||||
announce_cap: 2.0,
|
||||
announce_cap: 0.02,
|
||||
ifac_size: 0,
|
||||
tx_drops: 1,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user