lxmf: send and honour Resource cancels in delivery and propagation

This commit is contained in:
DeFiDude committed 2026-11-10 20:57:10 -07:00
1 parent 747c7e98ab
commit 1a7d5aaa90
3 files changed
+63 -4

No files matched your search

+8 -1
View File
@@ -5940,6 +5940,8 @@ fn drive_inbound_resource_watchdogs(
let resource_id = drop_inbound_resource(delivery, resource_hash);
notify_inbound_resource_concluded(concluded_handler, *link_id, resource_id);
}
// Resource.cancel() sends RCL only on an active Link (Resource.py:1133-1139).
TransferAction::SendCancel(_, _) if delivery.link.state != LinkState::Active => {}
retry => {
if dispatch_inbound_resource_action(
link_id,
@@ -6232,7 +6234,12 @@ fn dispatch_action(
ActionOutcome::Fail(reason)
}
TransferAction::SendCancel(cancel_type, resource_hash) => {
if let Ok(encrypted) = delivery.link.encrypt(&resource_hash) {
// Resource.cancel() sends ICL/RCL only on an active Link (Resource.py:1126, 1134).
let active = delivery.link.state == LinkState::Active;
if let Some(encrypted) = active
.then(|| delivery.link.encrypt(&resource_hash).ok())
.flatten()
{
let context = match cancel_type {
rns_protocol::resource::CancelType::Icl => {
rns_wire::context::PacketContext::ResourceIcl
+39 -2
View File
@@ -29,7 +29,7 @@ use std::time::{Duration, Instant};
use bytes::Bytes;
use rns_crypto::ed25519::{Ed25519PrivateKey, Ed25519PublicKey};
use rns_link::link::{CloseReason, Link, LinkAction};
use rns_link::link::{CloseReason, Link, LinkAction, LinkState};
use rns_link::stamp::{LinkRequestStamper, LinkStampPolicy};
use rns_protocol::resource::{
InboundTransfer, MAX_EFFICIENT_SIZE, MAX_RESOURCE_SIZE, MAX_SEGMENTS, MultiSegmentInbound,
@@ -2215,11 +2215,17 @@ impl PropagationClient {
if self.status.state == PropagationClientState::Receiving {
let mut retry_requests = Vec::new();
let mut cancel = None;
let mut failed = false;
for transfer in self.inbound_resources.values_mut() {
match transfer.check_timeout() {
TransferAction::SendRequest(request) => retry_requests.push(request),
TransferAction::SendCancel(_, hash) => {
cancel = Some(hash);
break;
}
TransferAction::Failed(_) => {
self.fail();
failed = true;
break;
}
_ => {}
@@ -2231,6 +2237,23 @@ impl PropagationClient {
&request,
);
}
if let Some(hash) = cancel {
// Resource.cancel() sends RCL only on an active Link (Resource.py:1133-1139).
if self
.link
.as_ref()
.is_some_and(|link| link.state == LinkState::Active)
{
self.send_encrypted_resource_control(
rns_wire::context::PacketContext::ResourceRcl,
&hash,
);
}
failed = true;
}
if failed {
self.fail();
}
}
match self.status.state {
@@ -2552,6 +2575,20 @@ impl PropagationClient {
&data,
);
}
Some(TransferAction::SendCancel(_, hash)) => {
// Resource.cancel() sends ICL only on an active Link (Resource.py:1124-1132).
if self
.link
.as_ref()
.is_some_and(|link| link.state == LinkState::Active)
{
self.send_encrypted_resource_control(
rns_wire::context::PacketContext::ResourceIcl,
&hash,
);
}
self.fail();
}
Some(TransferAction::Failed(_)) => self.fail(),
_ => {}
}
+16 -1
View File
@@ -19,7 +19,7 @@ use std::time::{Duration, Instant};
use bytes::Bytes;
use rns_crypto::ed25519::{Ed25519PrivateKey, Ed25519PublicKey};
use rns_link::link::{CloseReason, Link, LinkAction};
use rns_link::link::{CloseReason, Link, LinkAction, LinkState};
use rns_link::stamp::{LinkRequestStamper, LinkStampPolicy};
use rns_protocol::resource::{
MAX_EFFICIENT_SIZE, MultiSegmentOutbound, OutboundTransfer, ResourceError, TransferAction,
@@ -1776,6 +1776,21 @@ impl PropagationSyncTask {
}
break;
}
TransferAction::SendCancel(_, resource_hash) => {
// Resource.cancel() sends ICL only on an active Link (Resource.py:1124-1132).
if self
.link
.as_ref()
.is_some_and(|link| link.state == LinkState::Active)
{
let _ = self.send_resource_packet(
&resource_hash,
rns_wire::context::PacketContext::ResourceIcl,
);
}
self.fail_active_transfer();
break;
}
TransferAction::None => break,
_ => break,
}