Skip to main content

leodos_protocols/transport/cfdp/class2/machine/receiver/
transaction.rs

1//! Contains the transaction data structures specific to the receiver state machine.
2
3use core::ops::Deref;
4use core::ops::DerefMut;
5
6use crate::transport::cfdp::class2::machine::tracker::SegmentTracker;
7use crate::transport::cfdp::class2::machine::transaction::TransactionConfig;
8use crate::transport::cfdp::pdu::tlv::filestore_request::FilestoreRequest;
9use heapless::Vec;
10
11/// The lifecycle state of a receiving transaction.
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum TransactionState {
14    /// The receiver is actively receiving `FileData` PDUs.
15    ReceivingFileData,
16    /// The receiver has received the `EOF` PDU but has missing data, and is waiting for retransmissions.
17    WaitingForNakData,
18    /// The receiver has a complete file and is waiting for the Runner to verify the checksum.
19    VerifyingChecksum,
20    /// The receiver is waiting for the runner to execute filestore requests.
21    WaitingForFilestoreResponses,
22}
23
24/// Holds all the dynamic and static state for a single, ongoing receiving transaction.
25#[derive(Debug)]
26pub struct Transaction {
27    /// The data structure used to track missing file segments.
28    pub tracker: SegmentTracker,
29    /// The shared, static configuration for this transaction.
30    pub config: TransactionConfig,
31    /// Filestore requests to be processed by the Runner.
32    pub filestore_requests: Vec<FilestoreRequest, 4, u8>,
33    /// The number of bytes of the file that have been successfully received and written.
34    pub progress: u64,
35    /// Timeout in seconds to wait for missing data after sending a `NAK`.
36    pub nak_timeout_secs: u16,
37    /// The interval at which to send periodic `KeepAlive` PDUs.
38    pub keep_alive_interval_secs: u16,
39    /// The current position in the receiver's lifecycle.
40    pub state: TransactionState,
41    /// A counter for the number of times a `NAK` sequence has been retransmitted.
42    pub nak_retries: u8,
43    /// The number of times to retry sending a `NAK` sequence before faulting.
44    pub nak_limit: u8,
45    /// Whether the transaction is currently suspended.
46    pub suspended: bool,
47}
48
49impl Deref for Transaction {
50    type Target = TransactionConfig;
51
52    fn deref(&self) -> &Self::Target {
53        &self.config
54    }
55}
56
57impl DerefMut for Transaction {
58    fn deref_mut(&mut self) -> &mut Self::Target {
59        &mut self.config
60    }
61}