mirror of
https://github.com/ratspeak/rsLXMF
synced 2026-11-27 13:52:18 +00:00
propagation: enforce node stamp costs
This commit is contained in:
1 parent
feb76bc953
commit
9b7489f82d
2 files changed
+30
-5
No files matched your search
@@ -18,8 +18,8 @@ use crate::sync::{OfferResponse, SyncGet, SyncOffer, SyncSession};
|
||||
pub struct PropagationNodeConfig {
|
||||
pub max_storage: usize,
|
||||
pub max_message_age: u64,
|
||||
/// Messages below this stamp value are rejected. Matches Python
|
||||
/// `propagation_stamp_cost` (production default PROPAGATION_COST = 16).
|
||||
/// Messages below this effective stamp value are rejected. Python derives
|
||||
/// this from `propagation_stamp_cost - propagation_stamp_cost_flexibility`.
|
||||
pub min_stamp_cost: u8,
|
||||
pub peering_cost: u8,
|
||||
pub max_message_size: usize,
|
||||
@@ -170,6 +170,9 @@ impl PropagationNode {
|
||||
if lxmf_data.len() < DESTINATION_LENGTH + 1 {
|
||||
return false;
|
||||
}
|
||||
if self.config.min_stamp_cost > 0 && stamp_value < self.config.min_stamp_cost {
|
||||
return false;
|
||||
}
|
||||
|
||||
let full = rns_crypto::sha::full_hash(lxmf_data);
|
||||
let mut transient_id = [0u8; 16];
|
||||
@@ -1624,6 +1627,24 @@ mod tests {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_accept_propagated_blob_enforces_min_stamp_cost() {
|
||||
let config = PropagationNodeConfig {
|
||||
min_stamp_cost: 8,
|
||||
..Default::default()
|
||||
};
|
||||
let mut node = PropagationNode::new(config, [0xAA; 16]);
|
||||
|
||||
let mut lxmf_data = vec![0xBB; 16];
|
||||
lxmf_data.extend_from_slice(&[0xCC; 128]);
|
||||
|
||||
assert!(!node.accept_propagated_blob(&lxmf_data, 7));
|
||||
assert_eq!(node.message_count(), 0);
|
||||
|
||||
assert!(node.accept_propagated_blob(&lxmf_data, 8));
|
||||
assert_eq!(node.message_count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_opaque_propagated_blob_reload_preserves_destination() {
|
||||
let dir = std::env::temp_dir().join("lxmf_test_propagated_blob_reload");
|
||||
|
||||
@@ -404,7 +404,9 @@ impl LxmdRunner {
|
||||
.unwrap_or(config.propagation_limit_kb * 1024),
|
||||
max_message_size: config.propagation_limit_kb * 1024,
|
||||
max_message_age: lxmf_core::constants::MESSAGE_EXPIRY,
|
||||
min_stamp_cost: config.propagation_stamp_cost,
|
||||
min_stamp_cost: config
|
||||
.propagation_stamp_cost
|
||||
.saturating_sub(config.propagation_stamp_flex),
|
||||
..Default::default()
|
||||
};
|
||||
let prop_storage_path = paths.propagation_store_dir.clone();
|
||||
@@ -423,7 +425,9 @@ impl LxmdRunner {
|
||||
.unwrap_or(config.propagation_limit_kb * 1024),
|
||||
max_message_size: config.propagation_limit_kb * 1024,
|
||||
max_message_age: lxmf_core::constants::MESSAGE_EXPIRY,
|
||||
min_stamp_cost: config.propagation_stamp_cost,
|
||||
min_stamp_cost: config
|
||||
.propagation_stamp_cost
|
||||
.saturating_sub(config.propagation_stamp_flex),
|
||||
..Default::default()
|
||||
},
|
||||
propagation_dest_hash,
|
||||
@@ -1244,7 +1248,7 @@ impl LxmdRunner {
|
||||
let min_cost = self
|
||||
.config
|
||||
.propagation_stamp_cost
|
||||
.saturating_sub(lxmf_core::constants::PROPAGATION_COST_FLEX);
|
||||
.saturating_sub(self.config.propagation_stamp_flex);
|
||||
let mut accepted = 0usize;
|
||||
let mut rejected = 0usize;
|
||||
|
||||
|
||||
Reference in new issue
Block a user