propagation: guard transfer restarts

This commit is contained in:
DeFiDude 2026-07-26 02:01:04 -06:00
parent c52c0a254f
commit 3070484a5f

View file

@ -188,6 +188,20 @@ impl PropagationClient {
Some(h) => h,
None => return false,
};
if !matches!(
self.status.state,
PropagationClientState::Idle
| PropagationClientState::Complete
| PropagationClientState::Failed
) {
return false;
}
if matches!(
self.status.state,
PropagationClientState::Complete | PropagationClientState::Failed
) {
self.cleanup();
}
let (link, request_data) = Link::new_initiator(node_hash, 1);
let link_id = link.link_id;
@ -1179,6 +1193,20 @@ mod tests {
assert!(matches!(outbound.unwrap(), TransportMessage::Outbound(_)));
}
#[test]
fn test_start_download_rejects_an_active_transfer() {
let (tx, mut rx) = mpsc::channel(64);
let mut client = PropagationClient::new(tx, None, None);
client.set_propagation_node([0xBC; 16]);
assert!(client.start_download());
while rx.try_recv().is_ok() {}
assert!(!client.start_download());
assert!(rx.try_recv().is_err());
assert_eq!(client.state(), PropagationClientState::LinkEstablishing);
}
#[test]
fn test_add_local_messages() {
let (tx, _rx) = mpsc::channel(16);