Skip to main content

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

1//! Contains the transaction data structures specific to the sender state machine.
2
3use core::ops::Deref;
4
5use crate::transport::cfdp::class2::machine::transaction::TransactionConfig;
6
7/// The lifecycle state of a sending transaction.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum TransactionState {
10    /// The sender is actively sending `FileData` PDUs.
11    SendingFileData,
12    /// The sender has sent all file data and is waiting for the file checksum.
13    WaitingForChecksum,
14    /// The sender has sent an `EOF` PDU and is waiting for the corresponding `ACK`.
15    WaitingForEofAck,
16    /// The sender has received the `ACK(EOF)` and is now waiting for the `Finished` PDU.
17    WaitingForFinishedPdu,
18}
19
20/// Holds all the dynamic and static state for a single, ongoing sending transaction.
21#[derive(Debug)]
22pub struct Transaction {
23    /// The shared, static configuration for this transaction.
24    pub config: TransactionConfig,
25    /// The number of bytes of the file that have been successfully sent.
26    pub progress: u64,
27    /// The last known progress of the receiver, as reported by `KeepAlive` PDUs.
28    pub last_receiver_progress: u64,
29    /// The byte discrepancy limit for Keep Alive checks.
30    pub keep_alive_limit: u64,
31    /// The calculated checksum of the source file. `Some` once calculated.
32    pub file_checksum: Option<u32>,
33    /// The number of times to retry sending an `EOF` before faulting.
34    pub ack_limit: u8,
35    /// The current position in the sender's lifecycle.
36    pub state: TransactionState,
37    /// Whether the transaction is currently suspended.
38    pub suspended: bool,
39    /// A counter for the number of times an `EOF` PDU has been retransmitted.
40    pub ack_retries: u8,
41}
42
43impl Deref for Transaction {
44    type Target = TransactionConfig;
45
46    fn deref(&self) -> &Self::Target {
47        &self.config
48    }
49}
50
51impl core::ops::DerefMut for Transaction {
52    fn deref_mut(&mut self) -> &mut Self::Target {
53        &mut self.config
54    }
55}