leodos_protocols/transport/cfdp/mod.rs
1//! CCSDS File Delivery Protocol (CFDP) Protocol
2//!
3//! Spec: https://ccsds.org/Pubs/727x0b5e1.pdf
4//!
5//! This module provides a complete CFDP implementation with both low-level
6//! state machines and high-level async APIs.
7//!
8//! # Architecture
9//!
10//! The implementation is split into layers:
11//!
12//! - [`pdu`]: PDU parsing and serialization
13//! - [`machine`]: Pure, synchronous state machines (sender and receiver)
14//! - [`filestore`]: Abstract file I/O trait
15//! - [`api`]: High-level async API with explicit sender/receiver roles
16//!
17//! # Features
18//!
19//! - `tokio`: Enables async API with tokio runtime support
20//! - `cfs`: Enables async API with leodos-libcfs runtime support
21//!
22//! # Example (tokio)
23//!
24//! ```rust,ignore
25//! use leodos_ccsds::cfdp::api::net::{CfdpSender, CfdpReceiver};
26//!
27//! let mut sender = CfdpSender::new(entity_id);
28//! let stream = sender.put("file.txt", "remote.txt", dest_id, addr).await?;
29//!
30//! let mut receiver = CfdpReceiver::new(entity_id);
31//! let file = receiver.accept().await;
32//! ```
33//! TODO: Finish this implementation
34
35/// Class 2 (acknowledged) CFDP state machines and transaction management.
36pub mod class2;
37/// Abstract file I/O trait for platform-independent file operations.
38pub mod filestore;
39/// PDU parsing, serialization, and zero-copy views.
40pub mod pdu;
41/// Checksum algorithms for CFDP data integrity verification.
42pub mod checksum;
43
44/// Errors that can occur during CFDP operations.
45#[derive(Debug, PartialEq, Eq)]
46pub enum CfdpError {
47 // Build errors
48 /// The provided buffer is too small for the required data.
49 BufferTooSmall {
50 /// Minimum number of bytes needed.
51 required: usize,
52 /// Actual buffer size provided.
53 provided: usize,
54 },
55 /// A field's data exceeds its maximum allowed size.
56 DataTooLarge {
57 /// Name of the field that exceeded its limit.
58 field: &'static str,
59 /// Maximum allowed size in bytes.
60 max: usize,
61 },
62 /// An entity or sequence number ID has an invalid length.
63 IdLengthInvalid {
64 /// Name of the field with the invalid ID length.
65 field: &'static str,
66 /// The invalid length that was provided.
67 len: usize,
68 },
69 /// Source and destination entity ID lengths do not match.
70 IdLengthMismatch,
71 // Other errors
72 /// A custom error with a static message.
73 Custom(&'static str),
74 /// The referenced transaction was not found.
75 TransactionNotFound,
76 /// The maximum number of concurrent transactions has been reached.
77 TooManyConcurrentTransactions,
78 /// The action buffer is full and cannot accept more actions.
79 ActionBufferFull,
80}
81
82impl core::fmt::Display for CfdpError {
83 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
84 match self {
85 CfdpError::BufferTooSmall { required, provided } => {
86 write!(
87 f,
88 "Buffer too small: required {} bytes, provided {} bytes",
89 required, provided
90 )
91 }
92 CfdpError::DataTooLarge { field, max } => {
93 write!(f, "Data too large for field '{}': max {} bytes", field, max)
94 }
95 CfdpError::IdLengthInvalid { field, len } => {
96 write!(
97 f,
98 "Invalid ID length for field '{}': got {} bytes",
99 field, len
100 )
101 }
102 CfdpError::IdLengthMismatch => {
103 write!(f, "Source and destination entity ID lengths do not match")
104 }
105 CfdpError::Custom(msg) => write!(f, "CFDP Error: {}", msg),
106 CfdpError::TransactionNotFound => write!(f, "CFDP Error: Transaction not found"),
107 CfdpError::TooManyConcurrentTransactions => {
108 write!(f, "CFDP Error: Too many concurrent transactions")
109 }
110 CfdpError::ActionBufferFull => write!(f, "CFDP Error: Action buffer full"),
111 }
112 }
113}
114
115// #[cfg(feature = "async")]
116// pub mod api;