build: raise LXMF host minimum to Rust 1.89

This commit is contained in:
DeFiDude committed 2026-10-08 22:59:46 -06:00
1 parent 284d56fee3
commit e38d30e02a
19 files changed
+763 -814

No files matched your search

+3 -3
View File
@@ -10,7 +10,7 @@ permissions:
contents: read contents: read
env: env:
RSLXMF_RSRETICULUM_COMMIT: 5edb8f22f5d8e6b2bd7392dc06e255ead96576fb RSLXMF_RSRETICULUM_COMMIT: cac8151fd8207ada9775310fe2b3c9c7340a7ecd
jobs: jobs:
api-compat: api-compat:
@@ -119,7 +119,7 @@ jobs:
working-directory: rsLXMF working-directory: rsLXMF
msrv: msrv:
name: Rust 1.87 MSRV name: Rust 1.89 MSRV
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 30 timeout-minutes: 30
steps: steps:
@@ -133,7 +133,7 @@ jobs:
path: rsReticulum path: rsReticulum
- uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # master - uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # master
with: with:
toolchain: 1.87.0 toolchain: 1.89.0
components: clippy components: clippy
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2 - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
with: with:
+2 -2
View File
@@ -38,7 +38,7 @@ jobs:
path: rsReticulum path: rsReticulum
- uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # master - uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # master
with: with:
toolchain: 1.87.0 toolchain: 1.89.0
- name: Verify release source and dependency - name: Verify release source and dependency
working-directory: rsLXMF working-directory: rsLXMF
run: python3 scripts/ci/check_source_release_contract.py --release-tag "${RELEASE_TAG}" run: python3 scripts/ci/check_source_release_contract.py --release-tag "${RELEASE_TAG}"
@@ -75,7 +75,7 @@ jobs:
path: rsReticulum path: rsReticulum
- uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # master - uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # master
with: with:
toolchain: 1.87.0 toolchain: 1.89.0
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2 - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
with: with:
workspaces: rsLXMF -> target workspaces: rsLXMF -> target
+2
View File
@@ -15,6 +15,8 @@
### Build and compatibility ### Build and compatibility
- Raised the host source-build minimum to Rust 1.89 and qualified the corresponding protocol dependency update.
- Restricted rsReticulum compatibility to the 1.3 patch line so a later breaking minor release requires an explicit update. - Restricted rsReticulum compatibility to the 1.3 patch line so a later breaking minor release requires an explicit update.
- Updated the Python interoperability baseline to Reticulum 1.4.2 and LXMF 1.0.1, with separate LXMF 1.1.0 checks. - Updated the Python interoperability baseline to Reticulum 1.4.2 and LXMF 1.0.1, with separate LXMF 1.1.0 checks.
+1 -1
View File
@@ -9,7 +9,7 @@ members = [
version = "1.2.0" version = "1.2.0"
edition = "2024" edition = "2024"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
rust-version = "1.87" rust-version = "1.89"
[workspace.dependencies] [workspace.dependencies]
# Reticulum crates from a sibling rsReticulum checkout during development. # Reticulum crates from a sibling rsReticulum checkout during development.
+1 -1
View File
@@ -5,7 +5,7 @@
**Rust LXMF messaging and propagation for Reticulum.** **Rust LXMF messaging and propagation for Reticulum.**
[![License: AGPL-3.0-or-later](https://img.shields.io/badge/license-AGPL--3.0--or--later-blue.svg)](LICENSE) [![License: AGPL-3.0-or-later](https://img.shields.io/badge/license-AGPL--3.0--or--later-blue.svg)](LICENSE)
[![Rust 1.87+](https://img.shields.io/badge/rust-1.87%2B-orange.svg)](https://www.rust-lang.org) [![Rust 1.89+](https://img.shields.io/badge/rust-1.89%2B-orange.svg)](https://www.rust-lang.org)
[![Compatibility floor: LXMF 1.0.1](https://img.shields.io/badge/compatibility%20floor-LXMF%201.0.1-success.svg)](https://github.com/markqvist/LXMF) [![Compatibility floor: LXMF 1.0.1](https://img.shields.io/badge/compatibility%20floor-LXMF%201.0.1-success.svg)](https://github.com/markqvist/LXMF)
[![Current reference: LXMF 1.1.0](https://img.shields.io/badge/current%20reference-LXMF%201.1.0-blue.svg)](https://github.com/markqvist/LXMF) [![Current reference: LXMF 1.1.0](https://img.shields.io/badge/current%20reference-LXMF%201.1.0-blue.svg)](https://github.com/markqvist/LXMF)
[![Status](https://img.shields.io/badge/status-experimental-yellow.svg)](#feature-status) [![Status](https://img.shields.io/badge/status-experimental-yellow.svg)](#feature-status)
+2 -2
View File
@@ -5,7 +5,7 @@
{ {
"name": "lxmf-core", "name": "lxmf-core",
"version": "1.2.0", "version": "1.2.0",
"rustVersion": "1.87", "rustVersion": "1.89",
"edition": "2024", "edition": "2024",
"features": {}, "features": {},
"targets": [ "targets": [
@@ -239,7 +239,7 @@
{ {
"name": "lxmf-tools", "name": "lxmf-tools",
"version": "1.2.0", "version": "1.2.0",
"rustVersion": "1.87", "rustVersion": "1.89",
"edition": "2024", "edition": "2024",
"features": {}, "features": {},
"targets": [ "targets": [
+1 -1
View File
@@ -1,2 +1,2 @@
# Keep Clippy suggestions aligned with the public MSRV in Cargo.toml. # Keep Clippy suggestions aligned with the public MSRV in Cargo.toml.
msrv = "1.87" msrv = "1.89"
+21 -21
View File
@@ -159,14 +159,15 @@ impl DeliveryRatchetState {
} }
} }
if control_file_trusted && (!control_existed || control_changed) { if control_file_trusted
if let Err(error) = control.save_verified(&control_path, identity) { && (!control_existed || control_changed)
tracing::warn!( && let Err(error) = control.save_verified(&control_path, identity)
path = %control_path.display(), {
%error, tracing::warn!(
"could not persist initial ratchet control state; new announces remain deferred until persistence recovers" path = %control_path.display(),
); %error,
} "could not persist initial ratchet control state; new announces remain deferred until persistence recovers"
);
} }
Ok(Self { Ok(Self {
@@ -210,13 +211,12 @@ impl DeliveryRatchetState {
} }
let announce_time = AnnounceTime::new(wall_now, cache_now)?; let announce_time = AnnounceTime::new(wall_now, cache_now)?;
if let DeliveryAnnounceKind::PathResponse { tag: Some(tag) } = kind { if let DeliveryAnnounceKind::PathResponse { tag: Some(tag) } = kind
if let Some(packet) = self && let Some(packet) = self
.destination .destination
.cached_path_response_packet(tag, cache_now)? .cached_path_response_packet(tag, cache_now)?
{ {
return Ok(packet); return Ok(packet);
}
} }
if !self.control_file_trusted { if !self.control_file_trusted {
@@ -292,15 +292,15 @@ impl DeliveryRatchetState {
/// Best-effort shutdown checkpoint. Invalid files detected during load are /// Best-effort shutdown checkpoint. Invalid files detected during load are
/// never overwritten by this operation. /// never overwritten by this operation.
pub fn save(&self, identity: &Identity) { pub fn save(&self, identity: &Identity) {
if self.ring_file_trusted { if self.ring_file_trusted
if let Err(error) = self.ring.save_verified(&self.ring_path, identity) { && let Err(error) = self.ring.save_verified(&self.ring_path, identity)
tracing::warn!(%error, "failed to save ratchet ring"); {
} tracing::warn!(%error, "failed to save ratchet ring");
} }
if self.control_file_trusted { if self.control_file_trusted
if let Err(error) = self.control.save_verified(&self.control_path, identity) { && let Err(error) = self.control.save_verified(&self.control_path, identity)
tracing::warn!(%error, "failed to save ratchet control state"); {
} tracing::warn!(%error, "failed to save ratchet control state");
} }
} }
+146 -155
View File
@@ -187,10 +187,10 @@ impl<T> From<oneshot::Receiver<T>> for ReadyReceipt<T> {
} }
impl<T> ReadyReceipt<T> { impl<T> ReadyReceipt<T> {
fn poll_ready(&mut self, cx: &mut Context<'_>) -> bool { fn poll_ready(&mut self, cx: &mut Context<'_>) -> bool {
if self.ready.is_none() { if self.ready.is_none()
if let Poll::Ready(result) = Pin::new(&mut self.receiver).poll(cx) { && let Poll::Ready(result) = Pin::new(&mut self.receiver).poll(cx)
self.ready = Some(result); {
} self.ready = Some(result);
} }
self.ready.is_some() self.ready.is_some()
} }
@@ -907,15 +907,15 @@ impl LinkDeliveryManager {
/// Use one polling task per manager and retain periodic ticks for protocol /// Use one polling task per manager and retain periodic ticks for protocol
/// deadlines. A bounded drain may leave more input ready for the next turn. /// deadlines. A bounded drain may leave more input ready for the next turn.
pub fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<()> { pub fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<()> {
if self.ready_event.is_none() { if self.ready_event.is_none()
if let Poll::Ready(event) = self.event_rx.poll_recv(cx) { && let Poll::Ready(event) = self.event_rx.poll_recv(cx)
self.ready_event = event; {
} self.ready_event = event;
} }
if self.ready_lifecycle.is_none() { if self.ready_lifecycle.is_none()
if let Poll::Ready(event) = self.endpoint_lifecycle_rx.poll_recv(cx) { && let Poll::Ready(event) = self.endpoint_lifecycle_rx.poll_recv(cx)
self.ready_lifecycle = event; {
} self.ready_lifecycle = event;
} }
let mut ready = self.ready_event.is_some() || self.ready_lifecycle.is_some(); let mut ready = self.ready_event.is_some() || self.ready_lifecycle.is_some();
for pending in self.pending_endpoint_binds.values_mut() { for pending in self.pending_endpoint_binds.values_mut() {
@@ -1844,26 +1844,25 @@ impl LinkDeliveryManager {
if event.binding.role != LinkEndpointRole::Initiator { if event.binding.role != LinkEndpointRole::Initiator {
continue; continue;
} }
if let Some(delivery) = self.pending.get_mut(&event.binding.link_id) { if let Some(delivery) = self.pending.get_mut(&event.binding.link_id)
if delivery.attached_interface == Some(event.binding.interface_id) && (delivery.attached_interface == Some(event.binding.interface_id)
|| self || self
.pending_endpoint_binds .pending_endpoint_binds
.get(&event.binding.link_id) .get(&event.binding.link_id)
.is_some_and(|pending| pending.interface_id == event.binding.interface_id) .is_some_and(|pending| pending.interface_id == event.binding.interface_id))
{ {
tracing::warn!( tracing::warn!(
link_id = %hex_encode(&event.binding.link_id), link_id = %hex_encode(&event.binding.link_id),
interface_id = event.binding.interface_id, interface_id = event.binding.interface_id,
reason = ?event.reason, reason = ?event.reason,
dropped_packets = event.dropped_packets, dropped_packets = event.dropped_packets,
"Direct Link endpoint terminated" "Direct Link endpoint terminated"
); );
delivery.attached_interface = None; delivery.attached_interface = None;
delivery.state = DeliveryState::Failed; delivery.state = DeliveryState::Failed;
delivery.failure_reason = delivery.failure_reason =
Some(format!("Link endpoint terminated: {:?}", event.reason)); Some(format!("Link endpoint terminated: {:?}", event.reason));
self.pending_endpoint_binds.remove(&event.binding.link_id); self.pending_endpoint_binds.remove(&event.binding.link_id);
}
} }
} }
@@ -2109,10 +2108,10 @@ impl LinkDeliveryManager {
} }
rns_wire::context::PacketContext::ResourceHmu => { rns_wire::context::PacketContext::ResourceHmu => {
let plaintext = self.decrypt_resource_control(&link_id, data); let plaintext = self.decrypt_resource_control(&link_id, data);
if let Some(pt) = plaintext { if let Some(pt) = plaintext
if !self.handle_inbound_resource_hmu(&link_id, &pt) { && !self.handle_inbound_resource_hmu(&link_id, &pt)
self.handle_hmu(&link_id, &pt); {
} self.handle_hmu(&link_id, &pt);
} }
} }
rns_wire::context::PacketContext::ResourceReq => { rns_wire::context::PacketContext::ResourceReq => {
@@ -2852,49 +2851,45 @@ impl LinkDeliveryManager {
{ {
continue; continue;
} }
if !delivery.reusable && !delivery.pretransfer_identify_staged { if !delivery.reusable
if let (Some(pub_key), Some(sign_key)) = && !delivery.pretransfer_identify_staged
&& let (Some(pub_key), Some(sign_key)) =
(&self.identity_pub, &self.identity_key) (&self.identity_pub, &self.identity_key)
{ && let Ok(identify_data) = delivery.link.identify(pub_key, sign_key)
if let Ok(identify_data) = delivery.link.identify(pub_key, sign_key) {
{ let id_header = rns_wire::header::PacketHeader {
let id_header = rns_wire::header::PacketHeader { flags: rns_wire::flags::PacketFlags {
flags: rns_wire::flags::PacketFlags { header_type: rns_wire::flags::HeaderType::Header1,
header_type: rns_wire::flags::HeaderType::Header1, context_flag: false,
context_flag: false, transport_type: rns_wire::flags::TransportType::Broadcast,
transport_type: destination_type: rns_wire::flags::DestinationType::Link,
rns_wire::flags::TransportType::Broadcast, packet_type: rns_wire::flags::PacketType::Data,
destination_type: },
rns_wire::flags::DestinationType::Link, hops: 0,
packet_type: rns_wire::flags::PacketType::Data, transport_id: None,
}, destination_hash: *link_id,
hops: 0, context: rns_wire::context::PacketContext::LinkIdentify,
transport_id: None, };
destination_hash: *link_id, let mut id_raw = id_header.pack();
context: rns_wire::context::PacketContext::LinkIdentify, id_raw.extend_from_slice(&identify_data);
}; if let Err(reason) = stage_link_endpoint_with_success(
let mut id_raw = id_header.pack(); &self.transport_tx,
id_raw.extend_from_slice(&identify_data); &mut self.pending_transport,
if let Err(reason) = stage_link_endpoint_with_success( &mut self.pending_endpoint_sends,
&self.transport_tx, *link_id,
&mut self.pending_transport, OutboundRequest {
&mut self.pending_endpoint_sends, raw: Bytes::from(id_raw),
*link_id, destination_hash: *link_id,
OutboundRequest { },
raw: Bytes::from(id_raw), EndpointSendSuccess::FinishHandshake,
destination_hash: *link_id, ) {
}, delivery.state = DeliveryState::Failed;
EndpointSendSuccess::FinishHandshake, delivery.failure_reason = Some(reason.to_string());
) { continue;
delivery.state = DeliveryState::Failed; }
delivery.failure_reason = Some(reason.to_string()); delivery.pretransfer_identify_staged = true;
continue; if delivery.endpoint_dispatch_token.is_some() {
} continue;
delivery.pretransfer_identify_staged = true;
if delivery.endpoint_dispatch_token.is_some() {
continue;
}
}
} }
} }
// Reusable Direct links follow upstream LXMF and identify // Reusable Direct links follow upstream LXMF and identify
@@ -3375,10 +3370,10 @@ impl LinkDeliveryManager {
) { ) {
results.push(result); results.push(result);
} }
} else if proof_observed { } else if proof_observed
if let Some(result) = self.complete_backchannel_delivery(key) { && let Some(result) = self.complete_backchannel_delivery(key)
results.push(result); {
} results.push(result);
} }
} }
Ok(Err(err)) => { Ok(Err(err)) => {
@@ -3527,10 +3522,10 @@ impl LinkDeliveryManager {
if let Some(ref mut transfer) = delivery.transfer { if let Some(ref mut transfer) = delivery.transfer {
transfer.handle_hmu(hmu_data); transfer.handle_hmu(hmu_data);
let progress = delivery_resource_progress(delivery); let progress = delivery_resource_progress(delivery);
if let Some(progress) = progress { if let Some(progress) = progress
if should_update_resource_progress(delivery.message.progress, progress) { && should_update_resource_progress(delivery.message.progress, progress)
delivery.message.progress = progress; {
} delivery.message.progress = progress;
} }
progress.map(|_| { progress.map(|_| {
delivery_event( delivery_event(
@@ -3610,10 +3605,10 @@ impl LinkDeliveryManager {
} }
} }
let progress = delivery_resource_progress(delivery); let progress = delivery_resource_progress(delivery);
if let Some(progress) = progress { if let Some(progress) = progress
if should_update_resource_progress(delivery.message.progress, progress) { && should_update_resource_progress(delivery.message.progress, progress)
delivery.message.progress = progress; {
} delivery.message.progress = progress;
} }
progress.map(|_| { progress.map(|_| {
delivery_event( delivery_event(
@@ -3701,17 +3696,16 @@ impl LinkDeliveryManager {
let mut rejected_hash = [0u8; 32]; let mut rejected_hash = [0u8; 32];
rejected_hash.copy_from_slice(&reject_data[..32]); rejected_hash.copy_from_slice(&reject_data[..32]);
if let Some(delivery) = self.pending.get_mut(link_id) { if let Some(delivery) = self.pending.get_mut(link_id)
if let Some(ref mut transfer) = delivery.transfer { && let Some(ref mut transfer) = delivery.transfer
if transfer.resource.resource_hash == rejected_hash { && transfer.resource.resource_hash == rejected_hash
transfer.handle_cancel(); {
delivery.remaining_segments = None; transfer.handle_cancel();
delivery.message.mark_rejected(); delivery.remaining_segments = None;
delivery.state = DeliveryState::Rejected; delivery.message.mark_rejected();
delivery.failure_reason = Some("resource rejected".to_string()); delivery.state = DeliveryState::Rejected;
return true; delivery.failure_reason = Some("resource rejected".to_string());
} return true;
}
} }
false false
@@ -3762,20 +3756,17 @@ impl LinkDeliveryManager {
/// Apply an inbound link-packet proof; returns `true` when the packet delivery is complete. /// Apply an inbound link-packet proof; returns `true` when the packet delivery is complete.
pub fn handle_link_packet_proof(&mut self, link_id: &[u8; 16], proof_data: &[u8]) -> bool { pub fn handle_link_packet_proof(&mut self, link_id: &[u8; 16], proof_data: &[u8]) -> bool {
if let Some(delivery) = self.pending.get_mut(link_id) { if let Some(delivery) = self.pending.get_mut(link_id)
if delivery.state == DeliveryState::AwaitingProof { && delivery.state == DeliveryState::AwaitingProof
if let Some(packet_hash) = delivery.packet_proof_hash { && let Some(packet_hash) = delivery.packet_proof_hash
if delivery && delivery
.link .link
.validate_packet_proof(&packet_hash, proof_data) .validate_packet_proof(&packet_hash, proof_data)
{ {
delivery.link.record_inbound(); delivery.link.record_inbound();
delivery.link.record_rx(proof_data.len()); delivery.link.record_rx(proof_data.len());
delivery.state = DeliveryState::Complete; delivery.state = DeliveryState::Complete;
return true; return true;
}
}
}
} }
false false
} }
@@ -4268,39 +4259,39 @@ impl LinkDeliveryManager {
.pending_backchannel_deliveries .pending_backchannel_deliveries
.iter() .iter()
.find_map(|(key, delivery)| (delivery.message.hash == Some(msg_hash)).then_some(*key)); .find_map(|(key, delivery)| (delivery.message.hash == Some(msg_hash)).then_some(*key));
if let Some(key) = pending_key { if let Some(key) = pending_key
if let Some(delivery) = self.pending_backchannel_deliveries.remove(&key) { && let Some(delivery) = self.pending_backchannel_deliveries.remove(&key)
self.remove_backchannel_owner(delivery.dest_hash, delivery.link_id); {
self.cancel_backchannel_packet_key(key, delivery.packet_cancellation); self.remove_backchannel_owner(delivery.dest_hash, delivery.link_id);
if let BackchannelProofKey::Resource(link_id, resource_hash) = key { self.cancel_backchannel_packet_key(key, delivery.packet_cancellation);
self.pending_backchannel_resource_cancellations.push_back( if let BackchannelProofKey::Resource(link_id, resource_hash) = key {
BackchannelResourceCancelRequest { self.pending_backchannel_resource_cancellations.push_back(
link_id, BackchannelResourceCancelRequest {
resource_hash, link_id,
}, resource_hash,
);
}
self.delivery_events.push_back(backchannel_delivery_event(
BackchannelDeliveryEventInput {
kind: LxmfDeliveryEventKind::Failed,
message: &delivery.message,
dest_hash: delivery.dest_hash,
link_id: delivery.link_id,
representation: delivery.representation,
progress: Some(delivery.message.progress),
reason: Some(reason.to_string()),
link_state: LinkState::Closed,
delivery_state: DeliveryState::Failed,
}, },
)); );
results.push(DeliveryResult::Failed {
link_id: delivery.link_id,
msg_hash: delivery.message.hash,
dest_hash: delivery.dest_hash,
message: delivery.message,
reason: reason.to_string(),
});
} }
self.delivery_events.push_back(backchannel_delivery_event(
BackchannelDeliveryEventInput {
kind: LxmfDeliveryEventKind::Failed,
message: &delivery.message,
dest_hash: delivery.dest_hash,
link_id: delivery.link_id,
representation: delivery.representation,
progress: Some(delivery.message.progress),
reason: Some(reason.to_string()),
link_state: LinkState::Closed,
delivery_state: DeliveryState::Failed,
},
));
results.push(DeliveryResult::Failed {
link_id: delivery.link_id,
msg_hash: delivery.message.hash,
dest_hash: delivery.dest_hash,
message: delivery.message,
reason: reason.to_string(),
});
} }
results results
@@ -4965,18 +4956,18 @@ fn finish_reusable_delivery(
link_id: &[u8; 16], link_id: &[u8; 16],
delivery: &mut PendingDelivery, delivery: &mut PendingDelivery,
) { ) {
if !delivery.backchannel_identified { if !delivery.backchannel_identified
if let (Some(pub_key), Some(sign_key)) = (identity_pub, identity_key) { && let (Some(pub_key), Some(sign_key)) = (identity_pub, identity_key)
delivery.backchannel_identified = send_link_identify( {
transport_tx, delivery.backchannel_identified = send_link_identify(
pending_transport, transport_tx,
pending_endpoint_sends, pending_transport,
link_id, pending_endpoint_sends,
&delivery.link, link_id,
pub_key, &delivery.link,
sign_key, pub_key,
); sign_key,
} );
} }
delivery.transfer = None; delivery.transfer = None;
+19 -20
View File
@@ -606,19 +606,19 @@ impl LxMessage {
self.transient_id = Some(tid); self.transient_id = Some(tid);
let mut stamp_value = 0; let mut stamp_value = 0;
if let Some(target_cost) = propagation_stamp_cost { if let Some(target_cost) = propagation_stamp_cost
if self.propagation_stamp.is_none() { && self.propagation_stamp.is_none()
let (stamp, value) = crate::stamper::generate_stamp( {
&tid, let (stamp, value) = crate::stamper::generate_stamp(
target_cost, &tid,
crate::constants::STAMP_WORKBLOCK_EXPAND_ROUNDS_PN, target_cost,
) crate::constants::STAMP_WORKBLOCK_EXPAND_ROUNDS_PN,
.ok_or_else(|| { )
MessageError::PackFailed("failed to generate propagation stamp".to_string()) .ok_or_else(|| {
})?; MessageError::PackFailed("failed to generate propagation stamp".to_string())
self.propagation_stamp = Some(stamp); })?;
stamp_value = value; self.propagation_stamp = Some(stamp);
} stamp_value = value;
} }
if let Some(ref prop_stamp) = self.propagation_stamp { if let Some(ref prop_stamp) = self.propagation_stamp {
@@ -1008,14 +1008,13 @@ impl LxMessage {
// 4. Generate PoW stamp // 4. Generate PoW stamp
let cost = self.stamp_cost.unwrap(); let cost = self.stamp_cost.unwrap();
if let Some(message_id) = self.message_id { if let Some(message_id) = self.message_id
if let Some((stamp, value)) = && let Some((stamp, value)) =
crate::stamper::generate_stamp(&message_id, cost, STAMP_WORKBLOCK_EXPAND_ROUNDS) crate::stamper::generate_stamp(&message_id, cost, STAMP_WORKBLOCK_EXPAND_ROUNDS)
{ {
self.stamp_value = Some(value as u16); self.stamp_value = Some(value as u16);
self.stamp = Some(stamp.to_vec()); self.stamp = Some(stamp.to_vec());
return Some(stamp.to_vec()); return Some(stamp.to_vec());
}
} }
None None
+9 -8
View File
@@ -68,14 +68,15 @@ pub fn write_file_atomic(path: &Path, data: &[u8]) -> io::Result<()> {
fs::rename(&tmp, path) fs::rename(&tmp, path)
})(); })();
if result.is_err() && tmp.exists() { if result.is_err()
if let Err(e) = fs::remove_file(&tmp) { && tmp.exists()
tracing::error!( && let Err(e) = fs::remove_file(&tmp)
"Error while cleaning temporary file {} for {}: {e}", {
tmp.display(), tracing::error!(
path.display() "Error while cleaning temporary file {} for {}: {e}",
); tmp.display(),
} path.display()
);
} }
result result
+79 -82
View File
@@ -620,30 +620,28 @@ impl PropagationClient {
continue; continue;
} }
let node_hex = self.outbound_propagation_node.map(|h| hex_encode(&h)); let node_hex = self.outbound_propagation_node.map(|h| hex_encode(&h));
if let Some(node_hex) = node_hex { if let Some(node_hex) = node_hex
if let Some(pub_key) = known_identities.get(&node_hex) { && let Some(pub_key) = known_identities.get(&node_hex)
let ed25519_bytes: [u8; 32] = pub_key[32..64] {
let ed25519_bytes: [u8; 32] = pub_key[32..64]
.try_into() .try_into()
.expect("known_identities values are [u8; 64]; slice [32..64] is always 32 bytes"); .expect("known_identities values are [u8; 64]; slice [32..64] is always 32 bytes");
if let Ok(verify_key) = if let Ok(verify_key) = Ed25519PublicKey::from_bytes(&ed25519_bytes)
Ed25519PublicKey::from_bytes(&ed25519_bytes) {
{ self.handle_link_proof(
self.handle_link_proof( data,
data, &verify_key,
&verify_key, &ed25519_bytes,
&ed25519_bytes, interface_id,
interface_id, );
);
}
} }
} }
} }
rns_wire::context::PacketContext::Response => { rns_wire::context::PacketContext::Response => {
if let Some(ref mut link) = self.link { if let Some(ref mut link) = self.link
if let Ok((_request_id, response_data)) = link.handle_response(data) && let Ok((_request_id, response_data)) = link.handle_response(data)
{ {
self.handle_response_data(&response_data); self.handle_response_data(&response_data);
}
} }
} }
rns_wire::context::PacketContext::ResourceAdv => { rns_wire::context::PacketContext::ResourceAdv => {
@@ -709,47 +707,47 @@ impl PropagationClient {
None => return, None => return,
}; };
if let Ok(rtt_data) = link.validate_proof(proof_data, verify_key, ed25519_pub) { if let Ok(rtt_data) = link.validate_proof(proof_data, verify_key, ed25519_pub)
if let Some(link_id) = self.link_id { && let Some(link_id) = self.link_id
let rtt_header = rns_wire::header::PacketHeader { {
flags: rns_wire::flags::PacketFlags { let rtt_header = rns_wire::header::PacketHeader {
header_type: rns_wire::flags::HeaderType::Header1, flags: rns_wire::flags::PacketFlags {
context_flag: false, header_type: rns_wire::flags::HeaderType::Header1,
transport_type: rns_wire::flags::TransportType::Broadcast, context_flag: false,
destination_type: rns_wire::flags::DestinationType::Link, transport_type: rns_wire::flags::TransportType::Broadcast,
packet_type: rns_wire::flags::PacketType::Data, destination_type: rns_wire::flags::DestinationType::Link,
}, packet_type: rns_wire::flags::PacketType::Data,
hops: 0, },
transport_id: None, hops: 0,
destination_hash: link_id, transport_id: None,
context: rns_wire::context::PacketContext::Lrrtt, destination_hash: link_id,
}; context: rns_wire::context::PacketContext::Lrrtt,
let mut rtt_raw = rtt_header.pack(); };
rtt_raw.extend_from_slice(&rtt_data); let mut rtt_raw = rtt_header.pack();
rtt_raw.extend_from_slice(&rtt_data);
let rtt_request = OutboundRequest { let rtt_request = OutboundRequest {
raw: Bytes::from(rtt_raw), raw: Bytes::from(rtt_raw),
destination_hash: link_id, destination_hash: link_id,
}; };
let (result_tx, result_rx) = oneshot::channel(); let (result_tx, result_rx) = oneshot::channel();
if !self.queue_transport(TransportMessage::BindLinkEndpoint { if !self.queue_transport(TransportMessage::BindLinkEndpoint {
binding: LinkEndpointBinding { binding: LinkEndpointBinding {
link_id, link_id,
interface_id,
role: LinkEndpointRole::Initiator,
},
lifecycle_tx: self.endpoint_lifecycle_tx.clone(),
result_tx,
}) {
self.status.state = PropagationClientState::Failed;
return;
}
self.pending_endpoint_bind = Some(PendingEndpointBind {
interface_id, interface_id,
rtt_request, role: LinkEndpointRole::Initiator,
result_rx, },
}); lifecycle_tx: self.endpoint_lifecycle_tx.clone(),
result_tx,
}) {
self.status.state = PropagationClientState::Failed;
return;
} }
self.pending_endpoint_bind = Some(PendingEndpointBind {
interface_id,
rtt_request,
result_rx,
});
} }
} }
@@ -1206,10 +1204,10 @@ impl PropagationClient {
if let Some(arr) = value.as_array() { if let Some(arr) = value.as_array() {
self.available_messages.clear(); self.available_messages.clear();
for item in arr { for item in arr {
if let Some(id_bytes) = item.as_slice() { if let Some(id_bytes) = item.as_slice()
if id_bytes.len() == 32 { && id_bytes.len() == 32
self.available_messages.push(id_bytes.to_vec()); {
} self.available_messages.push(id_bytes.to_vec());
} }
} }
@@ -1272,20 +1270,19 @@ impl PropagationClient {
return; return;
} }
if let Some(started) = self.started_at { if let Some(started) = self.started_at
if started.elapsed() > self.timeout && started.elapsed() > self.timeout
&& matches!( && matches!(
self.status.state, self.status.state,
PropagationClientState::LinkEstablishing PropagationClientState::LinkEstablishing
| PropagationClientState::ListRequested | PropagationClientState::ListRequested
| PropagationClientState::GetRequested | PropagationClientState::GetRequested
| PropagationClientState::PurgeRequested | PropagationClientState::PurgeRequested
) )
{ {
self.cleanup(); self.cleanup();
self.status.state = PropagationClientState::Failed; self.status.state = PropagationClientState::Failed;
return; return;
}
} }
let link_action = self.link.as_mut().map(Link::tick); let link_action = self.link.as_mut().map(Link::tick);
@@ -1384,10 +1381,10 @@ impl PropagationClient {
} else { } else {
None None
}; };
if let Some(outbound) = outbound { if let Some(outbound) = outbound
if !self.queue_link_endpoint(outbound) { && !self.queue_link_endpoint(outbound)
self.status.state = PropagationClientState::Failed; {
} self.status.state = PropagationClientState::Failed;
} }
} }
@@ -1539,10 +1536,10 @@ impl PropagationClient {
fn cleanup(&mut self) { fn cleanup(&mut self) {
let graceful_release = self.endpoint_release_queued || self.send_teardown(); let graceful_release = self.endpoint_release_queued || self.send_teardown();
if let Some(link_id) = self.link_id.take() { if let Some(link_id) = self.link_id.take()
if !graceful_release { && !graceful_release
self.queue_endpoint_cleanup(link_id); {
} self.queue_endpoint_cleanup(link_id);
} }
self.attached_interface = None; self.attached_interface = None;
self.endpoint_release_queued = false; self.endpoint_release_queued = false;
+31 -35
View File
@@ -254,12 +254,11 @@ pub(crate) fn prepare_sync_offer_snapshot(
.propagation_sync_limit .propagation_sync_limit
.map(kilobytes_to_bytes_fail_closed); .map(kilobytes_to_bytes_fail_closed);
let mut handled_messages = snapshot.policy.handled_messages.clone(); let mut handled_messages = snapshot.policy.handled_messages.clone();
if let Some(path) = snapshot.peer_path.as_ref() { if let Some(path) = snapshot.peer_path.as_ref()
if let Ok(data) = std::fs::read(path) { && let Ok(data) = std::fs::read(path)
if let Some(peer) = LxmPeer::from_bytes_with_handled(&data) { && let Some(peer) = LxmPeer::from_bytes_with_handled(&data)
handled_messages.extend(peer.handled_messages); {
} handled_messages.extend(peer.handled_messages);
}
} }
let mut candidates = snapshot.candidates; let mut candidates = snapshot.candidates;
@@ -792,10 +791,10 @@ impl PropagationNode {
self.advance_offer_generation(); self.advance_offer_generation();
} }
if before > after { if before > after
if let Some(ref dir) = self.storage_path { && let Some(ref dir) = self.storage_path
self.cleanup_orphaned_files(dir); {
} self.cleanup_orphaned_files(dir);
} }
} }
@@ -813,10 +812,10 @@ impl PropagationNode {
if filename.ends_with(".peer") || filename.ends_with(".msgpack") { if filename.ends_with(".peer") || filename.ends_with(".msgpack") {
continue; continue;
} }
if let Some((tid, _, _)) = PropagationEntry::parse_filename(&filename) { if let Some((tid, _, _)) = PropagationEntry::parse_filename(&filename)
if !self.store.contains(&tid) { && !self.store.contains(&tid)
let _ = std::fs::remove_file(&path); {
} let _ = std::fs::remove_file(&path);
} }
} }
} }
@@ -1116,16 +1115,15 @@ impl PropagationNode {
for want_val in wants_arr { for want_val in wants_arr {
if let (Some(tid), Some(dir)) = if let (Some(tid), Some(dir)) =
(parse_store_id(want_val), self.storage_path.as_ref()) (parse_store_id(want_val), self.storage_path.as_ref())
&& let Some(entry) = self.store.get(&tid)
{ {
if let Some(entry) = self.store.get(&tid) { // Ownership gate (Python LXMRouter.py:1479): a client
// Ownership gate (Python LXMRouter.py:1479): a client // may only download messages addressed to itself.
// may only download messages addressed to itself. if entry.destination_hash == *client_dest_hash {
if entry.destination_hash == *client_dest_hash { reads.push(PlannedRead {
reads.push(PlannedRead { path: dir.join(entry.filename()),
path: dir.join(entry.filename()), stamped: entry.stamped,
stamped: entry.stamped, });
});
}
} }
} }
} }
@@ -1288,11 +1286,10 @@ impl PropagationNode {
// Compatibility wrapper: production uses the staged task // Compatibility wrapper: production uses the staged task
// path and exposes this delta to the daemon for off-loop // path and exposes this delta to the daemon for off-loop
// persistence. // persistence.
if !terminal_handled_ids.is_empty() { if !terminal_handled_ids.is_empty()
if let Err(error) = self.persist_peer_handled(policy, &terminal_handled_ids) && let Err(error) = self.persist_peer_handled(policy, &terminal_handled_ids)
{ {
tracing::warn!(%error, "failed to persist terminal offer dispositions"); tracing::warn!(%error, "failed to persist terminal offer dispositions");
}
} }
return offer; return offer;
} }
@@ -1406,13 +1403,12 @@ impl PropagationNode {
if let Ok(entries) = std::fs::read_dir(dir) { if let Ok(entries) = std::fs::read_dir(dir) {
for entry in entries.flatten() { for entry in entries.flatten() {
let path = entry.path(); let path = entry.path();
if path.extension().map(|e| e == "peer").unwrap_or(false) { if path.extension().map(|e| e == "peer").unwrap_or(false)
if let Ok(data) = std::fs::read(&path) { && let Ok(data) = std::fs::read(&path)
if let Some(mut peer) = LxmPeer::from_bytes_with_handled(&data) { && let Some(mut peer) = LxmPeer::from_bytes_with_handled(&data)
self.prune_handled_against_store(&mut peer); {
peers.push(peer); self.prune_handled_against_store(&mut peer);
} peers.push(peer);
}
} }
} }
} }
+75 -83
View File
@@ -718,30 +718,27 @@ impl PropagationSyncTask {
continue; continue;
} }
let node_hex = self.node_dest_hash.map(|h| hex_encode(&h)); let node_hex = self.node_dest_hash.map(|h| hex_encode(&h));
if let Some(node_hex) = node_hex { if let Some(node_hex) = node_hex
if let Some(pub_key) = known_identities.get(&node_hex) { && let Some(pub_key) = known_identities.get(&node_hex)
let ed25519_bytes: [u8; 32] = {
pub_key[32..64].try_into().unwrap(); let ed25519_bytes: [u8; 32] = pub_key[32..64].try_into().unwrap();
if let Ok(verify_key) = if let Ok(verify_key) = Ed25519PublicKey::from_bytes(&ed25519_bytes)
Ed25519PublicKey::from_bytes(&ed25519_bytes) {
{ self.handle_link_proof(
self.handle_link_proof( data,
data, &verify_key,
&verify_key, &ed25519_bytes,
&ed25519_bytes, interface_id,
interface_id, );
);
}
} }
} }
} }
rns_wire::context::PacketContext::ResourceHmu => { rns_wire::context::PacketContext::ResourceHmu => {
if let Some(ref link) = self.link { if let Some(ref link) = self.link
if let Ok(plaintext) = link.decrypt(data) { && let Ok(plaintext) = link.decrypt(data)
if let Some(ref mut transfer) = self.active_transfer { && let Some(ref mut transfer) = self.active_transfer
transfer.handle_hmu(&plaintext); {
} transfer.handle_hmu(&plaintext);
}
} }
} }
rns_wire::context::PacketContext::ResourceReq => { rns_wire::context::PacketContext::ResourceReq => {
@@ -760,16 +757,12 @@ impl PropagationSyncTask {
} }
} }
rns_wire::context::PacketContext::Response => { rns_wire::context::PacketContext::Response => {
if self.state == SyncTaskState::AwaitingResponse { if self.state == SyncTaskState::AwaitingResponse
if let Some(ref mut link) = self.link { && let Some(ref mut link) = self.link
if let Ok((_request_id, response_data)) = && let Ok((_request_id, response_data)) = link.handle_response(data)
link.handle_response(data) {
{ let offer_response = OfferResponse::from_msgpack(&response_data);
let offer_response = self.handle_offer_response(offer_response);
OfferResponse::from_msgpack(&response_data);
self.handle_offer_response(offer_response);
}
}
} }
} }
rns_wire::context::PacketContext::ResourceRcl rns_wire::context::PacketContext::ResourceRcl
@@ -1039,10 +1032,10 @@ impl PropagationSyncTask {
fn prepare_transfer_for_ids(&mut self, ids: &[PropagationTransientId]) { fn prepare_transfer_for_ids(&mut self, ids: &[PropagationTransientId]) {
if ids.is_empty() { if ids.is_empty() {
if let Some(node_hash) = self.node_dest_hash { if let Some(node_hash) = self.node_dest_hash
if let Ok(mut node) = self.propagation_node.lock() { && let Ok(mut node) = self.propagation_node.lock()
node.complete_sync(&node_hash); {
} node.complete_sync(&node_hash);
} }
self.state = SyncTaskState::Complete; self.state = SyncTaskState::Complete;
return; return;
@@ -1128,13 +1121,12 @@ impl PropagationSyncTask {
if self.terminal_result.is_none() if self.terminal_result.is_none()
&& self.offer_policy.is_none() && self.offer_policy.is_none()
&& self.last_sync.elapsed() >= self.sync_interval && self.last_sync.elapsed() >= self.sync_interval
&& let Some(node_hash) = self.node_dest_hash
{ {
if let Some(node_hash) = self.node_dest_hash { if self.message_count() > 0 {
if self.message_count() > 0 { let _ = self.start_sync(node_hash);
let _ = self.start_sync(node_hash); } else {
} else { self.last_sync = Instant::now();
self.last_sync = Instant::now();
}
} }
} }
} }
@@ -1146,38 +1138,38 @@ impl PropagationSyncTask {
self.drive_transfers(); self.drive_transfers();
} }
SyncTaskState::Complete | SyncTaskState::Failed => { SyncTaskState::Complete | SyncTaskState::Failed => {
if self.terminal_result.is_none() { if self.terminal_result.is_none()
if let Some(peer_hash) = self.node_dest_hash { && let Some(peer_hash) = self.node_dest_hash
let complete = self.state == SyncTaskState::Complete; {
self.terminal_result = Some(PeerSyncTerminalResult { let complete = self.state == SyncTaskState::Complete;
peer_hash, self.terminal_result = Some(PeerSyncTerminalResult {
state: if complete { peer_hash,
PeerSyncTerminalState::Complete state: if complete {
} else { PeerSyncTerminalState::Complete
PeerSyncTerminalState::Failed } else {
}, PeerSyncTerminalState::Failed
offer_generation: complete },
.then_some(self.active_offer_generation) offer_generation: complete
.flatten(), .then_some(self.active_offer_generation)
generation_exhausted: complete && self.generation_exhausted, .flatten(),
offered: if complete { self.offered_count } else { 0 }, generation_exhausted: complete && self.generation_exhausted,
outgoing: if complete { self.outgoing_count } else { 0 }, offered: if complete { self.offered_count } else { 0 },
tx_bytes: if complete { self.transfer_data_size } else { 0 }, outgoing: if complete { self.outgoing_count } else { 0 },
link_establishment_rate: self.link_establishment_rate, tx_bytes: if complete { self.transfer_data_size } else { 0 },
sync_transfer_rate: (complete && self.outgoing_count > 0) link_establishment_rate: self.link_establishment_rate,
.then(|| { sync_transfer_rate: (complete && self.outgoing_count > 0)
self.transfer_started.map(|started| { .then(|| {
let elapsed = started.elapsed().as_secs_f64(); self.transfer_started.map(|started| {
if elapsed > 0.0 { let elapsed = started.elapsed().as_secs_f64();
self.transfer_wire_size as f64 * 8.0 / elapsed if elapsed > 0.0 {
} else { self.transfer_wire_size as f64 * 8.0 / elapsed
0.0 } else {
} 0.0
}) }
}) })
.flatten(), })
}); .flatten(),
} });
} }
self.cleanup_sync(); self.cleanup_sync();
self.last_sync = Instant::now(); self.last_sync = Instant::now();
@@ -1311,10 +1303,10 @@ impl PropagationSyncTask {
self.active_offer_generation = Some(generation); self.active_offer_generation = Some(generation);
self.generation_exhausted = generation_exhausted; self.generation_exhausted = generation_exhausted;
self.record_handled_updates(&terminal_handled_ids); self.record_handled_updates(&terminal_handled_ids);
if offer.transient_ids.is_empty() { if offer.transient_ids.is_empty()
if let Ok(mut node) = self.propagation_node.lock() { && let Ok(mut node) = self.propagation_node.lock()
node.complete_sync(&node_hash); {
} node.complete_sync(&node_hash);
} }
offer offer
} }
@@ -1589,10 +1581,10 @@ impl PropagationSyncTask {
let completed_ids = std::mem::take(&mut self.active_transfer_ids); let completed_ids = std::mem::take(&mut self.active_transfer_ids);
self.record_handled_updates(&completed_ids); self.record_handled_updates(&completed_ids);
if let Some(node_hash) = self.node_dest_hash { if let Some(node_hash) = self.node_dest_hash
if let Ok(mut node) = self.propagation_node.lock() { && let Ok(mut node) = self.propagation_node.lock()
node.complete_sync(&node_hash); {
} node.complete_sync(&node_hash);
} }
self.state = SyncTaskState::Complete; self.state = SyncTaskState::Complete;
} }
@@ -1741,10 +1733,10 @@ impl PropagationSyncTask {
peer.link_closed(); peer.link_closed();
} }
if let Some(link_id) = self.link_id.take() { if let Some(link_id) = self.link_id.take()
if !graceful_release { && !graceful_release
self.queue_endpoint_cleanup(link_id); {
} self.queue_endpoint_cleanup(link_id);
} }
self.attached_interface = None; self.attached_interface = None;
self.pending_endpoint_bind = None; self.pending_endpoint_bind = None;
+16 -19
View File
@@ -561,16 +561,16 @@ impl LxmRouter {
} }
} }
if message.method == DeliveryMethod::Opportunistic { if message.method == DeliveryMethod::Opportunistic
if let Ok(packed) = message.pack_payload() { && let Ok(packed) = message.pack_payload()
let content_size = packed {
.len() let content_size = packed
.saturating_sub(TIMESTAMP_SIZE + STRUCT_OVERHEAD); .len()
// Approximates ENCRYPTED_PACKET_MAX_CONTENT for default RNS parameters. .saturating_sub(TIMESTAMP_SIZE + STRUCT_OVERHEAD);
let max_content = 295; // Approximates ENCRYPTED_PACKET_MAX_CONTENT for default RNS parameters.
if content_size > max_content { let max_content = 295;
message.method = DeliveryMethod::Direct; if content_size > max_content {
} message.method = DeliveryMethod::Direct;
} }
} }
@@ -591,13 +591,12 @@ impl LxmRouter {
message: &mut LxMessage, message: &mut LxMessage,
) -> Result<(), TicketPreparationError> { ) -> Result<(), TicketPreparationError> {
let now = now_f64(); let now = now_f64();
if message.outbound_ticket.is_none() { if message.outbound_ticket.is_none()
if let Some(ticket) = self && let Some(ticket) = self
.ticket_store .ticket_store
.find_outbound(&message.destination_hash, now) .find_outbound(&message.destination_hash, now)
{ {
message.outbound_ticket = Some(ticket.token); message.outbound_ticket = Some(ticket.token);
}
} }
if message.include_ticket && !message.fields.contains_key(&FIELD_TICKET) { if message.include_ticket && !message.fields.contains_key(&FIELD_TICKET) {
@@ -915,10 +914,8 @@ impl LxmRouter {
.active_deferred_stamp .active_deferred_stamp
.as_ref() .as_ref()
.is_some_and(|job| job.message_hash == *message_hash); .is_some_and(|job| job.message_hash == *message_hash);
if active_matches { if active_matches && let Some(job) = self.active_deferred_stamp.take() {
if let Some(job) = self.active_deferred_stamp.take() { job.handle.cancel();
job.handle.cancel();
}
} }
return true; return true;
} }
+334 -359
View File
@@ -323,15 +323,14 @@ fn apply_propagation_store_commit(
for (transient_id, _) in result.committed { for (transient_id, _) in result.committed {
peer.add_handled_message(&transient_id); peer.add_handled_message(&transient_id);
} }
if let Some(node) = node { if let Some(node) = node
if let Ok(node) = node.lock() { && let Ok(node) = node.lock()
if let Err(error) = node.save_peer(peer) { && let Err(error) = node.save_peer(peer)
tracing::warn!( {
peer = %hex::encode(peer_hash), tracing::warn!(
"failed to persist committed peer accounting: {error}" peer = %hex::encode(peer_hash),
); "failed to persist committed peer accounting: {error}"
} );
}
} }
} else { } else {
router.unpeered_propagation_incoming = router router.unpeered_propagation_incoming = router
@@ -1396,10 +1395,10 @@ impl LxmdRunner {
if let Ok(entries) = std::fs::read_dir(&received_dir) { if let Ok(entries) = std::fs::read_dir(&received_dir) {
for entry in entries.flatten() { for entry in entries.flatten() {
let path = entry.path(); let path = entry.path();
if let Some(name) = path.file_stem().and_then(|n| n.to_str()) { if let Some(name) = path.file_stem().and_then(|n| n.to_str())
if let Ok(rr) = ReceivedRatchet::load(&path) { && let Ok(rr) = ReceivedRatchet::load(&path)
received_ratchets.insert(name.to_string(), rr); {
} received_ratchets.insert(name.to_string(), rr);
} }
} }
} }
@@ -1407,17 +1406,17 @@ impl LxmdRunner {
// known_identities format: concat of [dest_hash:16][pubkey:64] // known_identities format: concat of [dest_hash:16][pubkey:64]
let ki_path = paths.known_identities_path.clone(); let ki_path = paths.known_identities_path.clone();
let mut known_identities: HashMap<String, [u8; 64]> = HashMap::new(); let mut known_identities: HashMap<String, [u8; 64]> = HashMap::new();
if ki_path.exists() { if ki_path.exists()
if let Ok(data) = std::fs::read(&ki_path) { && let Ok(data) = std::fs::read(&ki_path)
let mut pos = 0; {
while pos + 80 <= data.len() { let mut pos = 0;
let mut dh = [0u8; 16]; while pos + 80 <= data.len() {
dh.copy_from_slice(&data[pos..pos + 16]); let mut dh = [0u8; 16];
let mut pk = [0u8; 64]; dh.copy_from_slice(&data[pos..pos + 16]);
pk.copy_from_slice(&data[pos + 16..pos + 80]); let mut pk = [0u8; 64];
known_identities.insert(hex::encode(dh), pk); pk.copy_from_slice(&data[pos + 16..pos + 80]);
pos += 80; known_identities.insert(hex::encode(dh), pk);
} pos += 80;
} }
} }
@@ -2080,10 +2079,10 @@ impl LxmdRunner {
match parse_destination_hash(configured) { match parse_destination_hash(configured) {
Ok(hash) => { Ok(hash) => {
self.router.prioritise(hash, 1); self.router.prioritise(hash, 1);
if let Some(ref node) = self.propagation_node { if let Some(ref node) = self.propagation_node
if let Ok(mut node) = node.lock() { && let Ok(mut node) = node.lock()
node.prioritise_destination(hash); {
} node.prioritise_destination(hash);
} }
} }
Err(e) => { Err(e) => {
@@ -2222,15 +2221,14 @@ impl LxmdRunner {
// Upstream control unpeer breaks the live peering without // Upstream control unpeer breaks the live peering without
// mutating the operator's configured static-peer set. // mutating the operator's configured static-peer set.
self.router.remove_peer(&peer_hash); self.router.remove_peer(&peer_hash);
if let Some(ref node) = self.propagation_node { if let Some(ref node) = self.propagation_node
if let Ok(mut node) = node.lock() { && let Ok(mut node) = node.lock()
if let Err(error) = node.delete_peer(&peer_hash) { && let Err(error) = node.delete_peer(&peer_hash)
tracing::warn!( {
peer = %hex::encode(peer_hash), tracing::warn!(
"failed to remove persisted propagation peer: {error}" peer = %hex::encode(peer_hash),
); "failed to remove persisted propagation peer: {error}"
} );
}
} }
if let Err(e) = self.router.save_state(&self.data_dir) { if let Err(e) = self.router.save_state(&self.data_dir) {
tracing::warn!("Failed to save router state after control unpeer: {e}"); tracing::warn!("Failed to save router state after control unpeer: {e}");
@@ -2253,11 +2251,11 @@ impl LxmdRunner {
// announce timebase (or a lower current target) does not make // announce timebase (or a lower current target) does not make
// a completed key stale if its measured value is still high // a completed key stale if its measured value is still high
// enough for the current policy. // enough for the current policy.
if let Some((key, value)) = result.peering_key { if let Some((key, value)) = result.peering_key
if value >= peer.peering_cost as u32 { && value >= peer.peering_cost as u32
peer.peering_key = Some((key, value)); {
applied = true; peer.peering_key = Some((key, value));
} applied = true;
} }
} }
@@ -2265,15 +2263,13 @@ impl LxmdRunner {
if let (Some(node), Some(peer)) = ( if let (Some(node), Some(peer)) = (
self.propagation_node.as_ref(), self.propagation_node.as_ref(),
self.router.peers.get(&result.peer_hash), self.router.peers.get(&result.peer_hash),
) { ) && let Ok(node) = node.lock()
if let Ok(node) = node.lock() { && let Err(error) = node.save_peer(peer)
if let Err(error) = node.save_peer(peer) { {
tracing::warn!( tracing::warn!(
peer = %hex::encode(result.peer_hash), peer = %hex::encode(result.peer_hash),
"failed to persist generated peering key: {error}" "failed to persist generated peering key: {error}"
); );
}
}
} }
} else if current_cost { } else if current_cost {
// A bounded key search can fail for an excessive advertised // A bounded key search can fail for an excessive advertised
@@ -2354,14 +2350,14 @@ impl LxmdRunner {
.then(|| OutboundOfferPolicy::from(peer)) .then(|| OutboundOfferPolicy::from(peer))
}); });
if let Some(policy) = policy { if let Some(policy) = policy {
if let Some(sync) = self.propagation_sync.as_mut() { if let Some(sync) = self.propagation_sync.as_mut()
if sync.request_sync_now_with_policy(policy) { && sync.request_sync_now_with_policy(policy)
if let Some(peer) = self.router.peers.get_mut(&peer_hash) { {
peer.begin_sync(); if let Some(peer) = self.router.peers.get_mut(&peer_hash) {
} peer.begin_sync();
self.pending_peer_syncs.remove(&peer_hash);
self.peer_sync_cursor = Some(peer_hash);
} }
self.pending_peer_syncs.remove(&peer_hash);
self.peer_sync_cursor = Some(peer_hash);
} }
return; return;
} }
@@ -2471,15 +2467,14 @@ impl LxmdRunner {
link_id, link_id,
packet_hash, packet_hash,
} => { } => {
if let Some(ld) = &mut self.link_delivery { if let Some(ld) = &mut self.link_delivery
if !ld.abandon_backchannel_packet(link_id, packet_hash) { && !ld.abandon_backchannel_packet(link_id, packet_hash)
self.pending_backchannel_abandon = {
Some(BackchannelSendReceipt::Packet { self.pending_backchannel_abandon = Some(BackchannelSendReceipt::Packet {
link_id, link_id,
packet_hash, packet_hash,
}); });
break; break;
}
} }
} }
BackchannelSendReceipt::Resource { BackchannelSendReceipt::Resource {
@@ -2727,64 +2722,62 @@ impl LxmdRunner {
sync.drain_events(&self.known_identities); sync.drain_events(&self.known_identities);
sync.tick(); sync.tick();
let updates = sync.take_handled_updates(); let updates = sync.take_handled_updates();
if !updates.is_empty() { if !updates.is_empty()
if let Some(peer_hash) = sync.node_dest_hash() { && let Some(peer_hash) = sync.node_dest_hash()
peer_handled_updates = Some((peer_hash, updates)); {
} peer_handled_updates = Some((peer_hash, updates));
} }
peer_terminal_result = sync.take_terminal_peer_result(); peer_terminal_result = sync.take_terminal_peer_result();
} }
let mut peers_to_persist = HashSet::new(); let mut peers_to_persist = HashSet::new();
if let Some((peer_hash, updates)) = peer_handled_updates { if let Some((peer_hash, updates)) = peer_handled_updates
if let Some(peer) = self.router.peers.get_mut(&peer_hash) { && let Some(peer) = self.router.peers.get_mut(&peer_hash)
for transient_id in updates { {
peer.add_handled_message(&transient_id); for transient_id in updates {
} peer.add_handled_message(&transient_id);
peers_to_persist.insert(peer_hash);
} }
peers_to_persist.insert(peer_hash);
} }
if let Some(result) = peer_terminal_result { if let Some(result) = peer_terminal_result
if let Some(peer) = self.router.peers.get_mut(&result.peer_hash) { && let Some(peer) = self.router.peers.get_mut(&result.peer_hash)
if let Some(rate) = result.link_establishment_rate { {
peer.link_establishment_rate = rate; if let Some(rate) = result.link_establishment_rate {
peer.heard(); peer.link_establishment_rate = rate;
} peer.heard();
match result.state {
lxmf_core::propagation_sync::PeerSyncTerminalState::Complete => {
peer.offered = peer.offered.saturating_add(result.offered);
peer.outgoing = peer.outgoing.saturating_add(result.outgoing);
peer.tx_bytes = peer.tx_bytes.saturating_add(result.tx_bytes);
if let Some(rate) = result.sync_transfer_rate {
peer.sync_transfer_rate = rate;
}
peer.sync_complete();
if result.generation_exhausted {
if let Some(generation) = result.offer_generation {
peer.mark_offer_generation_processed(generation);
}
}
}
lxmf_core::propagation_sync::PeerSyncTerminalState::Failed => {
peer.sync_failed();
}
}
peers_to_persist.insert(result.peer_hash);
} }
match result.state {
lxmf_core::propagation_sync::PeerSyncTerminalState::Complete => {
peer.offered = peer.offered.saturating_add(result.offered);
peer.outgoing = peer.outgoing.saturating_add(result.outgoing);
peer.tx_bytes = peer.tx_bytes.saturating_add(result.tx_bytes);
if let Some(rate) = result.sync_transfer_rate {
peer.sync_transfer_rate = rate;
}
peer.sync_complete();
if result.generation_exhausted
&& let Some(generation) = result.offer_generation
{
peer.mark_offer_generation_processed(generation);
}
}
lxmf_core::propagation_sync::PeerSyncTerminalState::Failed => {
peer.sync_failed();
}
}
peers_to_persist.insert(result.peer_hash);
} }
for peer_hash in peers_to_persist { for peer_hash in peers_to_persist {
if let (Some(node), Some(peer)) = ( if let (Some(node), Some(peer)) = (
self.propagation_node.as_ref(), self.propagation_node.as_ref(),
self.router.peers.get(&peer_hash), self.router.peers.get(&peer_hash),
) { ) && let Ok(node) = node.lock()
if let Ok(node) = node.lock() { && let Err(error) = node.save_peer(peer)
if let Err(error) = node.save_peer(peer) { {
tracing::warn!( tracing::warn!(
peer = %hex::encode(peer_hash), peer = %hex::encode(peer_hash),
"failed to persist peer sync state: {error}" "failed to persist peer sync state: {error}"
); );
}
}
} }
} }
} }
@@ -3014,18 +3007,18 @@ impl LxmdRunner {
client.start_download(); client.start_download();
self.last_propagation_check = now; self.last_propagation_check = now;
tracing::debug!("auto-triggered propagation download"); tracing::debug!("auto-triggered propagation download");
} else if let Some(node) = self.router.outbound_propagation_node { } else if let Some(node) = self.router.outbound_propagation_node
if queue_unknown_propagation_node_path_request( && queue_unknown_propagation_node_path_request(
&self.transport_tx, &self.transport_tx,
node, node,
&mut self.last_propagation_check, &mut self.last_propagation_check,
now, now,
) { )
tracing::debug!( {
node = %hex::encode(node), tracing::debug!(
"propagation node identity unknown; requesting path before download" node = %hex::encode(node),
); "propagation node identity unknown; requesting path before download"
} );
} }
} }
let status = client.transfer_status(); let status = client.transfer_status();
@@ -3043,65 +3036,56 @@ impl LxmdRunner {
for msg_data in downloaded_messages { for msg_data in downloaded_messages {
self.handle_propagation_downloaded_data(&msg_data); self.handle_propagation_downloaded_data(&msg_data);
} }
if acknowledge_propagation { if acknowledge_propagation && let Some(client) = self.propagation_client.as_mut() {
if let Some(client) = self.propagation_client.as_mut() { client.acknowledge_transfer();
client.acknowledge_transfer(); }
if let Some(interval) = self.config.announce_interval
&& now - self.last_peer_announce > interval as f64
&& let Ok(raw) = self.create_announce_packet()
{
let dest = self.lxmf_dest_hash;
if self.queue_runtime_transport(
TransportMessage::Outbound(rns_transport::messages::OutboundRequest {
raw: Bytes::from(raw),
destination_hash: dest,
}),
"periodic delivery announce",
) {
self.last_peer_announce = now;
tracing::debug!("periodic peer announce staged");
} }
} }
if let Some(interval) = self.config.announce_interval { if self.config.propagation_enabled
if now - self.last_peer_announce > interval as f64 { && let Some(interval) = self.config.node_announce_interval
if let Ok(raw) = self.create_announce_packet() { && now - self.last_node_announce > interval as f64
let dest = self.lxmf_dest_hash; && let Ok(raw) = self.create_propagation_announce_packet()
if self.queue_runtime_transport( {
TransportMessage::Outbound(rns_transport::messages::OutboundRequest { let dest = self.propagation_dest_hash;
raw: Bytes::from(raw), let node_staged = self.queue_runtime_transport(
destination_hash: dest, TransportMessage::Outbound(rns_transport::messages::OutboundRequest {
}), raw: Bytes::from(raw),
"periodic delivery announce", destination_hash: dest,
) { }),
self.last_peer_announce = now; "periodic propagation announce",
tracing::debug!("periodic peer announce staged"); );
} let mut control_staged = true;
} if self.should_announce_control()
&& let Ok(raw) =
create_control_announce_packet(&self.identity, self.control_dest_hash)
{
control_staged = self.queue_runtime_transport(
TransportMessage::Outbound(rns_transport::messages::OutboundRequest {
raw: Bytes::from(raw),
destination_hash: self.control_dest_hash,
}),
"periodic control announce",
);
} }
} if node_staged && control_staged {
self.last_node_announce = now;
if self.config.propagation_enabled { tracing::debug!("periodic propagation node announce staged");
if let Some(interval) = self.config.node_announce_interval {
if now - self.last_node_announce > interval as f64 {
if let Ok(raw) = self.create_propagation_announce_packet() {
let dest = self.propagation_dest_hash;
let node_staged = self.queue_runtime_transport(
TransportMessage::Outbound(rns_transport::messages::OutboundRequest {
raw: Bytes::from(raw),
destination_hash: dest,
}),
"periodic propagation announce",
);
let mut control_staged = true;
if self.should_announce_control() {
if let Ok(raw) = create_control_announce_packet(
&self.identity,
self.control_dest_hash,
) {
control_staged = self.queue_runtime_transport(
TransportMessage::Outbound(
rns_transport::messages::OutboundRequest {
raw: Bytes::from(raw),
destination_hash: self.control_dest_hash,
},
),
"periodic control announce",
);
}
}
if node_staged && control_staged {
self.last_node_announce = now;
tracing::debug!("periodic propagation node announce staged");
}
}
}
} }
} }
@@ -3111,10 +3095,10 @@ impl LxmdRunner {
// jobloop cadences. The propagation node's own store (separate // jobloop cadences. The propagation node's own store (separate
// from the router's) ages out expired messages and enforces the // from the router's) ages out expired messages and enforces the
// weight cap here — previously this never ran. // weight cap here — previously this never ran.
if let Some(ref pn) = self.propagation_node { if let Some(ref pn) = self.propagation_node
if let Ok(mut node) = pn.lock() { && let Ok(mut node) = pn.lock()
node.tick(); {
} node.tick();
} }
self.last_cull = now; self.last_cull = now;
} }
@@ -3169,21 +3153,20 @@ impl LxmdRunner {
.insert(event.destination_hash, event.hops.max(1)); .insert(event.destination_hash, event.hops.max(1));
if event.name_hash == delivery_name_hash { if event.name_hash == delivery_name_hash {
if let Some(ref data) = event.app_data { if let Some(ref data) = event.app_data
if let Some((display_name, stamp_cost)) = && let Some((display_name, stamp_cost)) =
lxmf_core::handlers::parse_announce_app_data(data) lxmf_core::handlers::parse_announce_app_data(data)
{ {
if let Some(name) = display_name { if let Some(name) = display_name {
tracing::info!(dest = %dest_hex, name = %name, "announce display name"); tracing::info!(dest = %dest_hex, name = %name, "announce display name");
} }
if let Some(cost) = stamp_cost { if let Some(cost) = stamp_cost {
self.router.set_stamp_cost(event.destination_hash, cost); self.router.set_stamp_cost(event.destination_hash, cost);
tracing::debug!( tracing::debug!(
dest = %dest_hex, dest = %dest_hex,
stamp_cost = cost, stamp_cost = cost,
"learned delivery stamp cost from announce" "learned delivery stamp cost from announce"
); );
}
} }
} }
let triggered = self let triggered = self
@@ -3257,15 +3240,14 @@ impl LxmdRunner {
if let Some(sync) = self.propagation_sync.as_mut() { if let Some(sync) = self.propagation_sync.as_mut() {
sync.cancel_peer_sync(&event.destination_hash); sync.cancel_peer_sync(&event.destination_hash);
} }
if let Some(node) = self.propagation_node.as_ref() { if let Some(node) = self.propagation_node.as_ref()
if let Ok(mut node) = node.lock() { && let Ok(mut node) = node.lock()
if let Err(error) = node.delete_peer(&event.destination_hash) { && let Err(error) = node.delete_peer(&event.destination_hash)
tracing::warn!( {
peer = %dest_hex, tracing::warn!(
"failed to remove retired propagation peer: {error}" peer = %dest_hex,
); "failed to remove retired propagation peer: {error}"
} );
}
} }
} else if peer_changed { } else if peer_changed {
let offer_constraints_changed = let offer_constraints_changed =
@@ -3290,15 +3272,13 @@ impl LxmdRunner {
if let (Some(node), Some(peer)) = ( if let (Some(node), Some(peer)) = (
self.propagation_node.as_ref(), self.propagation_node.as_ref(),
self.router.peers.get(&event.destination_hash), self.router.peers.get(&event.destination_hash),
) { ) && let Ok(node) = node.lock()
if let Ok(node) = node.lock() { && let Err(error) = node.save_peer(peer)
if let Err(error) = node.save_peer(peer) { {
tracing::warn!( tracing::warn!(
peer = %dest_hex, peer = %dest_hex,
"failed to persist propagation peer policy: {error}" "failed to persist propagation peer policy: {error}"
); );
}
}
} }
} }
tracing::debug!( tracing::debug!(
@@ -3317,35 +3297,34 @@ impl LxmdRunner {
); );
} }
} }
if let Some(pub_key) = event.public_key { if let Some(pub_key) = event.public_key
if self.known_identities.get(&dest_hex) != Some(&pub_key) { && self.known_identities.get(&dest_hex) != Some(&pub_key)
self.known_identities.insert(dest_hex.clone(), pub_key); {
tracing::debug!(dest = %dest_hex, "learned identity key from announce"); self.known_identities.insert(dest_hex.clone(), pub_key);
} tracing::debug!(dest = %dest_hex, "learned identity key from announce");
} }
// Python Identity._remember_ratchet: persist only the single // Python Identity._remember_ratchet: persist only the single
// changed ratchet, off the daemon loop. Identity keys and the // changed ratchet, off the daemon loop. Identity keys and the
// ring stay on the periodic/shutdown saves. // ring stay on the periodic/shutdown saves.
if let Some(ratchet_key) = event.ratchet { if let Some(ratchet_key) = event.ratchet
if self && self
.received_ratchets .received_ratchets
.get(&dest_hex) .get(&dest_hex)
.is_none_or(|rr| rr.ratchet_pub != ratchet_key) .is_none_or(|rr| rr.ratchet_pub != ratchet_key)
{ {
let rr = ReceivedRatchet::new(ratchet_key); let rr = ReceivedRatchet::new(ratchet_key);
self.received_ratchets.insert(dest_hex.clone(), rr); self.received_ratchets.insert(dest_hex.clone(), rr);
tracing::debug!(dest = %dest_hex, "learned ratchet from announce"); tracing::debug!(dest = %dest_hex, "learned ratchet from announce");
let path = self let path = self
.received_ratchets_dir .received_ratchets_dir
.join(format!("{dest_hex}.ratchet")); .join(format!("{dest_hex}.ratchet"));
let dir = self.received_ratchets_dir.clone(); let dir = self.received_ratchets_dir.clone();
tokio::task::spawn_blocking(move || { tokio::task::spawn_blocking(move || {
std::fs::create_dir_all(&dir).ok(); std::fs::create_dir_all(&dir).ok();
if let Err(e) = rr.save(&path) { if let Err(e) = rr.save(&path) {
tracing::warn!("Failed to persist received ratchet: {e}"); tracing::warn!("Failed to persist received ratchet: {e}");
} }
}); });
}
} }
} }
seen seen
@@ -3366,10 +3345,9 @@ impl LxmdRunner {
direction: LinkResourceDirection::Inbound, direction: LinkResourceDirection::Inbound,
.. ..
} }
) { ) && let Some(event) = delivery_resource_event_from_runtime(event)
if let Some(event) = delivery_resource_event_from_runtime(event) { {
self.router.handle_inbound_resource_event(event); self.router.handle_inbound_resource_event(event);
}
} }
} }
@@ -3661,31 +3639,31 @@ impl LxmdRunner {
.map(PropagationStoreWriteOrigin::Peer) .map(PropagationStoreWriteOrigin::Peer)
.unwrap_or(PropagationStoreWriteOrigin::Client); .unwrap_or(PropagationStoreWriteOrigin::Client);
let mut write_plans = Vec::new(); let mut write_plans = Vec::new();
if let Some(ref node) = self.propagation_node { if let Some(ref node) = self.propagation_node
if let Ok(mut node) = node.lock() { && let Ok(mut node) = node.lock()
for entry in &result.entries { {
let stamp_value = u8::try_from(entry.stamp_value).unwrap_or(u8::MAX); for entry in &result.entries {
if let Some(plan) = node.plan_accept_stamped_propagated_blob( let stamp_value = u8::try_from(entry.stamp_value).unwrap_or(u8::MAX);
&entry.lxmf_data, if let Some(plan) = node.plan_accept_stamped_propagated_blob(
&entry.stamp_data, &entry.lxmf_data,
stamp_value, &entry.stamp_data,
) { stamp_value,
write_plans.push((plan, entry.lxmf_data.len() as u64)); ) {
} write_plans.push((plan, entry.lxmf_data.len() as u64));
} }
} }
} }
let reserved = write_plans.len(); let reserved = write_plans.len();
if let Some(node) = self.propagation_node.clone() { if let Some(node) = self.propagation_node.clone()
if let Some(task) = spawn_propagation_store_writes( && let Some(task) = spawn_propagation_store_writes(
node, node,
write_plans, write_plans,
write_origin, write_origin,
self.prop_store_commit_tx.clone(), self.prop_store_commit_tx.clone(),
"propagation Resource ingress", "propagation Resource ingress",
) { )
self.prop_store_write_tasks.push(task); {
} self.prop_store_write_tasks.push(task);
} }
tracing::info!( tracing::info!(
@@ -3696,26 +3674,26 @@ impl LxmdRunner {
"processed inbound propagation Resource" "processed inbound propagation Resource"
); );
if claim.should_close_link() { if claim.should_close_link()
if let Some(command_tx) = self.prop_link_command_tx.clone() { && let Some(command_tx) = self.prop_link_command_tx.clone()
let link_id = claim.link_id(); {
tokio::spawn(async move { let link_id = claim.link_id();
if command_tx tokio::spawn(async move {
.send(rns_runtime::link_manager::LinkManagerCommand::CloseLink { if command_tx
link_id, .send(rns_runtime::link_manager::LinkManagerCommand::CloseLink {
reason: rns_runtime::prelude::CloseReason::DestinationClosed, link_id,
send_teardown: true, reason: rns_runtime::prelude::CloseReason::DestinationClosed,
}) send_teardown: true,
.await })
.is_err() .await
{ .is_err()
tracing::debug!( {
link_id = %hex::encode(link_id), tracing::debug!(
"propagation Link already closed before validation teardown" link_id = %hex::encode(link_id),
); "propagation Link already closed before validation teardown"
} );
}); }
} });
} }
} }
@@ -3780,30 +3758,30 @@ impl LxmdRunner {
result: PnPacketValidationWorkerResult, result: PnPacketValidationWorkerResult,
) { ) {
let mut write_plans = Vec::new(); let mut write_plans = Vec::new();
if let Some(ref node) = self.propagation_node { if let Some(ref node) = self.propagation_node
if let Ok(mut node) = node.lock() { && let Ok(mut node) = node.lock()
for entry in &result.entries { {
if let Some(plan) = node.plan_accept_stamped_propagated_blob( for entry in &result.entries {
&entry.lxmf_data, if let Some(plan) = node.plan_accept_stamped_propagated_blob(
&entry.stamp_data, &entry.lxmf_data,
u8::try_from(entry.stamp_value).unwrap_or(u8::MAX), &entry.stamp_data,
) { u8::try_from(entry.stamp_value).unwrap_or(u8::MAX),
write_plans.push((plan, entry.lxmf_data.len() as u64)); ) {
} write_plans.push((plan, entry.lxmf_data.len() as u64));
} }
} }
} }
let reserved = write_plans.len(); let reserved = write_plans.len();
if let Some(node) = self.propagation_node.clone() { if let Some(node) = self.propagation_node.clone()
if let Some(task) = spawn_propagation_store_writes( && let Some(task) = spawn_propagation_store_writes(
node, node,
write_plans, write_plans,
PropagationStoreWriteOrigin::Client, PropagationStoreWriteOrigin::Client,
self.prop_store_commit_tx.clone(), self.prop_store_commit_tx.clone(),
"client packet ingress", "client packet ingress",
) { )
self.prop_store_write_tasks.push(task); {
} self.prop_store_write_tasks.push(task);
} }
tracing::info!( tracing::info!(
@@ -3813,18 +3791,18 @@ impl LxmdRunner {
"processed inbound propagation packet" "processed inbound propagation packet"
); );
if result.rejected > 0 { if result.rejected > 0
if let Some(command_tx) = self.prop_link_command_tx.clone() { && let Some(command_tx) = self.prop_link_command_tx.clone()
tokio::spawn(async move { {
let _ = command_tx tokio::spawn(async move {
.send(rns_runtime::link_manager::LinkManagerCommand::CloseLink { let _ = command_tx
link_id: result.link_id, .send(rns_runtime::link_manager::LinkManagerCommand::CloseLink {
reason: rns_runtime::prelude::CloseReason::DestinationClosed, link_id: result.link_id,
send_teardown: true, reason: rns_runtime::prelude::CloseReason::DestinationClosed,
}) send_teardown: true,
.await; })
}); .await;
} });
} }
} }
@@ -4165,25 +4143,24 @@ impl LxmdRunner {
} }
let hops = route_hops_for(&self.route_hops, prop_hash); let hops = route_hops_for(&self.route_hops, prop_hash);
self.ensure_link_delivery(); self.ensure_link_delivery();
if let Some(ref mut ld) = self.link_delivery { if let Some(ref mut ld) = self.link_delivery
if let Err(err) = ld && let Err(err) = ld
.start_packed_delivery(message, prop_hash, hops, packed, false) .start_packed_delivery(message, prop_hash, hops, packed, false)
{ {
let reason = err.error.to_string(); let reason = err.error.to_string();
tracing::warn!( tracing::warn!(
error = %reason, error = %reason,
prop = %hex::encode(prop_hash), prop = %hex::encode(prop_hash),
"failed to start propagated link delivery" "failed to start propagated link delivery"
); );
requeue_after_path_request( requeue_after_path_request(
&mut self.router, &mut self.router,
&self.transport_tx, &self.transport_tx,
*err.message, *err.message,
prop_hash, prop_hash,
&reason, &reason,
false, false,
); );
}
} }
} }
None => { None => {
@@ -4218,18 +4195,17 @@ impl LxmdRunner {
} }
}; };
if message.stamp.is_none() { if message.stamp.is_none()
if let Some(cost) = self.router.get_stamp_cost(&message.destination_hash) { && let Some(cost) = self.router.get_stamp_cost(&message.destination_hash)
if cost > 0 { && cost > 0
tracing::info!( {
dest = %hex::encode(message.destination_hash), tracing::info!(
cost = cost, dest = %hex::encode(message.destination_hash),
"generating stamp" cost = cost,
); "generating stamp"
message.stamp_cost = Some(cost); );
message.get_stamp(); message.stamp_cost = Some(cost);
} message.get_stamp();
}
} }
let dest_hex = hex::encode(dest_hash); let dest_hex = hex::encode(dest_hash);
@@ -4483,23 +4459,23 @@ impl LxmdRunner {
} }
let hops = route_hops_for(&self.route_hops, dest_hash); let hops = route_hops_for(&self.route_hops, dest_hash);
self.ensure_link_delivery(); self.ensure_link_delivery();
if let Some(ref mut ld) = self.link_delivery { if let Some(ref mut ld) = self.link_delivery
if let Err(err) = ld.start_delivery(message, dest_hash, hops) { && let Err(err) = ld.start_delivery(message, dest_hash, hops)
let reason = err.error.to_string(); {
tracing::warn!( let reason = err.error.to_string();
error = %reason, tracing::warn!(
dest = %dest_hex, error = %reason,
"failed to start oversized direct link delivery" dest = %dest_hex,
); "failed to start oversized direct link delivery"
requeue_after_path_request( );
&mut self.router, requeue_after_path_request(
&self.transport_tx, &mut self.router,
*err.message, &self.transport_tx,
dest_hash, *err.message,
&reason, dest_hash,
false, &reason,
); false,
} );
} }
continue; continue;
} }
@@ -4667,11 +4643,11 @@ impl LxmdRunner {
let ki_path = ratchet_dir.join("known_identities"); let ki_path = ratchet_dir.join("known_identities");
let mut data = Vec::with_capacity(self.known_identities.len() * 80); let mut data = Vec::with_capacity(self.known_identities.len() * 80);
for (hash_hex, pk) in &self.known_identities { for (hash_hex, pk) in &self.known_identities {
if let Ok(hash_bytes) = hex::decode(hash_hex) { if let Ok(hash_bytes) = hex::decode(hash_hex)
if hash_bytes.len() == 16 { && hash_bytes.len() == 16
data.extend_from_slice(&hash_bytes); {
data.extend_from_slice(pk); data.extend_from_slice(&hash_bytes);
} data.extend_from_slice(pk);
} }
} }
if let Err(e) = rns_identity::persistence::atomic_write(&ki_path, &data) { if let Err(e) = rns_identity::persistence::atomic_write(&ki_path, &data) {
@@ -4947,10 +4923,10 @@ pub(crate) async fn main() {
); );
for destination in ignored { for destination in ignored {
runner.router.ignore_destination(destination); runner.router.ignore_destination(destination);
if let Some(ref node) = runner.propagation_node { if let Some(ref node) = runner.propagation_node
if let Ok(mut node) = node.lock() { && let Ok(mut node) = node.lock()
node.ignore_destination(destination); {
} node.ignore_destination(destination);
} }
} }
} }
@@ -5281,11 +5257,10 @@ pub(crate) async fn main() {
direction: LinkResourceDirection::Inbound, direction: LinkResourceDirection::Inbound,
.. ..
} }
) { )
if let Some(event) = delivery_resource_event_from_runtime(event) { && let Some(event) = delivery_resource_event_from_runtime(event) {
runner.router.handle_inbound_resource_event(event); runner.router.handle_inbound_resource_event(event);
} }
}
runner.drain_link_packets(); runner.drain_link_packets();
} }
Some((data, link_id)) = runner.prop_link_packet_rx.recv() => { Some((data, link_id)) = runner.prop_link_packet_rx.recv() => {
+14 -15
View File
@@ -324,17 +324,16 @@ impl DaemonConfig {
dc.outbound_propagation_node = Some(trimmed.to_string()); dc.outbound_propagation_node = Some(trimmed.to_string());
} }
} }
if get_int(Some(sec), "propagation_stamp_cost_target").is_none() { if get_int(Some(sec), "propagation_stamp_cost_target").is_none()
if let Some(cost) = sec.get_uint("propagation_stamp_cost") { && let Some(cost) = sec.get_uint("propagation_stamp_cost")
dc.propagation_stamp_cost = cost as u8; {
} dc.propagation_stamp_cost = cost as u8;
} }
if get_float(Some(sec), "propagation_message_max_accepted_size").is_none() if get_float(Some(sec), "propagation_message_max_accepted_size").is_none()
&& get_float(Some(sec), "propagation_transfer_max_accepted_size").is_none() && get_float(Some(sec), "propagation_transfer_max_accepted_size").is_none()
&& let Some(limit) = sec.get_uint("propagation_limit")
{ {
if let Some(limit) = sec.get_uint("propagation_limit") { dc.propagation_limit_kb = limit as usize;
dc.propagation_limit_kb = limit as usize;
}
} }
dc.enforce_stamps = sec.get_bool_or("enforce_stamps", false); dc.enforce_stamps = sec.get_bool_or("enforce_stamps", false);
} }
@@ -343,14 +342,14 @@ impl DaemonConfig {
if !dc.auth_required { if !dc.auth_required {
dc.auth_required = sec.get_bool_or("auth_required", false); dc.auth_required = sec.get_bool_or("auth_required", false);
} }
if dc.control_allowed.is_empty() { if dc.control_allowed.is_empty()
if let Some(allowed) = sec.get("allowed") { && let Some(allowed) = sec.get("allowed")
dc.control_allowed = allowed {
.split(',') dc.control_allowed = allowed
.map(|s| s.trim().to_string()) .split(',')
.filter(|s| !s.is_empty()) .map(|s| s.trim().to_string())
.collect(); .filter(|s| !s.is_empty())
} .collect();
} }
} }
+4 -4
View File
@@ -111,10 +111,10 @@ pub fn decode_control_response(response: &[u8]) -> ControlResponse {
return ControlResponse::Success; return ControlResponse::Success;
}; };
if let Some(code) = value.as_u64() { if let Some(code) = value.as_u64()
if let Some(error) = peer_error_from_code(code as u8) { && let Some(error) = peer_error_from_code(code as u8)
return ControlResponse::Error(error); {
} return ControlResponse::Error(error);
} }
if value.is_nil() { if value.is_nil() {
+3 -3
View File
@@ -11,7 +11,7 @@ from pathlib import Path
ROOT = Path(__file__).resolve().parents[2] ROOT = Path(__file__).resolve().parents[2]
EXPECTED_RUST_VERSION = "1.87" EXPECTED_RUST_VERSION = "1.89"
SHA_PATTERN = re.compile(r"^[0-9a-f]{40}$") SHA_PATTERN = re.compile(r"^[0-9a-f]{40}$")
@@ -94,8 +94,8 @@ def check_workflow_actions() -> None:
def check_release_workflow(reticulum_version: str) -> str: def check_release_workflow(reticulum_version: str) -> str:
workflow = (ROOT / ".github/workflows/release.yml").read_text() workflow = (ROOT / ".github/workflows/release.yml").read_text()
if not re.search(r"^\s*toolchain:\s*1\.87\.0\s*$", workflow, re.MULTILINE): if not re.search(r"^\s*toolchain:\s*1\.89\.0\s*$", workflow, re.MULTILINE):
fail("release workflow does not select Rust 1.87.0") fail("release workflow does not select Rust 1.89.0")
if "ref: ${{ env.RELEASE_TAG }}" not in workflow: if "ref: ${{ env.RELEASE_TAG }}" not in workflow:
fail("release workflow does not check out RELEASE_TAG") fail("release workflow does not check out RELEASE_TAG")