Merge pull request 'bump spacepackets' (#15) from bump-spacepackets into main

Reviewed-on: #15
This commit was merged in pull request #15.
This commit is contained in:
2025-11-27 13:55:10 +01:00
8 changed files with 109 additions and 120 deletions

View File

@@ -29,7 +29,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.86.0
- uses: dtolnay/rust-toolchain@1.87
- run: cargo check --release
cross-check:
@@ -63,7 +63,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- run: RUSTDOCFLAGS="--cfg docsrs --generate-link-to-definition -Z unstable-options" cargo +nightly doc --features "serde, defmt"
- run: RUSTDOCFLAGS="--cfg docsrs --generate-link-to-definition -Z unstable-options" cargo +nightly doc --features "serde, defmt" --no-deps
clippy:
name: Clippy

View File

@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [unreleased]
- Bumped `spacepackets` to v0.17
# [v0.3.0] 2025-09-25
- Bumped `spacepackets` to v0.16

View File

@@ -2,7 +2,7 @@
name = "cfdp-rs"
version = "0.3.0"
edition = "2024"
rust-version = "1.86.0"
rust-version = "1.87"
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
description = "High level CCSDS File Delivery Protocol components"
homepage = "https://egit.irs.uni-stuttgart.de/rust/cfdp"
@@ -20,7 +20,7 @@ crc = "3"
smallvec = "1"
derive-new = ">=0.6, <=0.7"
hashbrown = { version = ">=0.14, <=0.15", optional = true }
spacepackets = { version = "0.16", default-features = false }
spacepackets = { version = "0.17", default-features = false }
thiserror = { version = "2", default-features = false }
heapless = "0.9"
serde = { version = "1", optional = true }

View File

@@ -28,7 +28,7 @@ use spacepackets::{
ChecksumType, ConditionCode, TransmissionMode,
pdu::{PduError, file_data::FileDataPdu, metadata::MetadataPduReader},
},
util::{UnsignedByteFieldU16, UnsignedEnum},
util::UnsignedByteFieldU16,
};
static KILL_APP: AtomicBool = AtomicBool::new(false);
@@ -258,17 +258,17 @@ impl UdpServer {
fn pdu_printout(pdu: &PduOwnedWithInfo) {
match pdu.pdu_type() {
spacepackets::cfdp::PduType::FileDirective => match pdu.file_directive_type().unwrap() {
spacepackets::cfdp::pdu::FileDirectiveType::EofPdu => (),
spacepackets::cfdp::pdu::FileDirectiveType::FinishedPdu => (),
spacepackets::cfdp::pdu::FileDirectiveType::AckPdu => (),
spacepackets::cfdp::pdu::FileDirectiveType::MetadataPdu => {
spacepackets::cfdp::pdu::FileDirectiveType::Eof => (),
spacepackets::cfdp::pdu::FileDirectiveType::Finished => (),
spacepackets::cfdp::pdu::FileDirectiveType::Ack => (),
spacepackets::cfdp::pdu::FileDirectiveType::Metadata => {
let meta_pdu =
MetadataPduReader::new(pdu.raw_pdu()).expect("creating metadata pdu failed");
debug!("Metadata PDU: {:?}", meta_pdu)
}
spacepackets::cfdp::pdu::FileDirectiveType::NakPdu => (),
spacepackets::cfdp::pdu::FileDirectiveType::PromptPdu => (),
spacepackets::cfdp::pdu::FileDirectiveType::KeepAlivePdu => (),
spacepackets::cfdp::pdu::FileDirectiveType::Nak => (),
spacepackets::cfdp::pdu::FileDirectiveType::Prompt => (),
spacepackets::cfdp::pdu::FileDirectiveType::KeepAlive => (),
},
spacepackets::cfdp::PduType::FileData => {
let fd_pdu =

View File

@@ -1,9 +1,12 @@
all: check build embedded clippy fmt docs test coverage
all: check build embedded clippy check-fmt docs test coverage
clippy:
cargo clippy -- -D warnings
fmt:
cargo fmt --all
check-fmt:
cargo fmt --all -- --check
check:
@@ -20,7 +23,7 @@ embedded:
cargo build --target thumbv7em-none-eabihf --no-default-features --features "defmt, packet-buf-1k"
docs:
RUSTDOCFLAGS="--cfg docsrs --generate-link-to-definition -Z unstable-options" cargo +nightly doc --features "serde, defmt"
RUSTDOCFLAGS="--cfg docsrs --generate-link-to-definition -Z unstable-options" cargo +nightly doc --features "serde, defmt" --no-deps
docs-html:
RUSTDOCFLAGS="--cfg docsrs --generate-link-to-definition -Z unstable-options" cargo +nightly doc --features "serde, defmt" --open

View File

@@ -62,7 +62,7 @@ use spacepackets::{
},
tlv::{EntityIdTlv, GenericTlv, ReadableTlv, TlvType, msg_to_user::MsgToUserTlv},
},
util::{UnsignedByteField, UnsignedEnum},
util::UnsignedByteField,
};
#[derive(Debug)]
@@ -608,33 +608,31 @@ impl<
) -> Result<u32, DestError> {
let mut sent_packets = 0;
match pdu_directive {
FileDirectiveType::EofPdu => {
FileDirectiveType::Eof => {
let eof_pdu = EofPdu::from_bytes(raw_packet)?;
sent_packets += self.handle_eof_pdu(cfdp_user, eof_pdu)?
}
FileDirectiveType::FinishedPdu
| FileDirectiveType::NakPdu
| FileDirectiveType::KeepAlivePdu => {
FileDirectiveType::Finished | FileDirectiveType::Nak | FileDirectiveType::KeepAlive => {
return Err(DestError::CantProcessPacketType {
pdu_type: PduType::FileDirective,
directive_type: Some(pdu_directive),
});
}
FileDirectiveType::AckPdu => {
FileDirectiveType::Ack => {
let ack_pdu = AckPdu::from_bytes(raw_packet)?;
self.handle_ack_pdu(ack_pdu)?;
}
FileDirectiveType::MetadataPdu => {
FileDirectiveType::Metadata => {
let metadata_pdu = MetadataPduReader::from_bytes(raw_packet)?;
self.handle_metadata_pdu(metadata_pdu)?
}
FileDirectiveType::PromptPdu => self.handle_prompt_pdu(raw_packet)?,
FileDirectiveType::Prompt => self.handle_prompt_pdu(raw_packet)?,
};
Ok(sent_packets)
}
fn handle_ack_pdu(&mut self, ack_pdu: AckPdu) -> Result<(), DestError> {
if ack_pdu.directive_code_of_acked_pdu() != FileDirectiveType::FinishedPdu {
if ack_pdu.directive_code_of_acked_pdu() != FileDirectiveType::Finished {
self.transaction_params
.anomaly_tracker
.increment_invalid_ack_directive_code();
@@ -827,7 +825,7 @@ impl<
.finish(0, self.transaction_params.progress)
.map_err(PduError::from)?;
self.pdu_sender.send_file_directive_pdu(
FileDirectiveType::NakPdu,
FileDirectiveType::Nak,
&self.pdu_and_cksum_buffer.borrow()[0..written_size],
)?;
packets_sent += 1;
@@ -954,7 +952,7 @@ impl<
};
let written_len = nak_pdu.write_to_bytes(self.pdu_and_cksum_buffer.get_mut())?;
self.pdu_sender.send_file_directive_pdu(
FileDirectiveType::NakPdu,
FileDirectiveType::Nak,
&self.pdu_and_cksum_buffer.borrow()[0..written_len],
)?;
sent_packets += 1;
@@ -998,7 +996,7 @@ impl<
if self.transmission_mode().unwrap() == TransmissionMode::Unacknowledged {
return Err(DestError::WrongStepForPdu {
pdu_type: PduType::FileDirective,
file_directive_type: Some(FileDirectiveType::EofPdu),
file_directive_type: Some(FileDirectiveType::Eof),
step: self.step(),
});
}
@@ -1116,7 +1114,7 @@ impl<
);
let written_len = ack_pdu.write_to_bytes(self.pdu_and_cksum_buffer.get_mut())?;
self.pdu_sender.send_file_directive_pdu(
FileDirectiveType::AckPdu,
FileDirectiveType::Ack,
&self.pdu_and_cksum_buffer.borrow()[0..written_len],
)?;
Ok(())
@@ -1280,7 +1278,7 @@ impl<
.finish(0, self.transaction_params.file_size)
.map_err(PduError::from)?;
self.pdu_sender.send_file_directive_pdu(
FileDirectiveType::NakPdu,
FileDirectiveType::Nak,
&self.pdu_and_cksum_buffer.borrow()[0..written_len],
)?;
sent_packets += 1;
@@ -1336,7 +1334,7 @@ impl<
.finish(current_start_of_scope, current_end_of_scope)
.map_err(PduError::from)?;
self.pdu_sender.send_file_directive_pdu(
FileDirectiveType::NakPdu,
FileDirectiveType::Nak,
&self.pdu_and_cksum_buffer.borrow()[..written_len],
)?;
sent_packets += 1;
@@ -1382,7 +1380,7 @@ impl<
.finish(current_start_of_scope, current_end_of_scope)
.map_err(PduError::from)?;
self.pdu_sender.send_file_directive_pdu(
FileDirectiveType::NakPdu,
FileDirectiveType::Nak,
&self.pdu_and_cksum_buffer.borrow()[..written_len],
)?;
sent_packets += 1;
@@ -1898,7 +1896,7 @@ impl<
};
finished_pdu.write_to_bytes(self.pdu_and_cksum_buffer.get_mut())?;
self.pdu_sender.send_file_directive_pdu(
FileDirectiveType::FinishedPdu,
FileDirectiveType::Finished,
&self.pdu_and_cksum_buffer.borrow()[0..finished_pdu.len_written()],
)?;
Ok(1)
@@ -1926,7 +1924,7 @@ mod tests {
nak::NakPduReader,
},
},
util::UnsignedByteFieldU8,
util::{UnsignedByteFieldU8, UnsignedEnum},
};
use crate::{
@@ -2053,7 +2051,7 @@ mod tests {
fn remote_cfg_mut(&mut self) -> &mut RemoteEntityConfig {
self.handler
.remote_cfg_table
.get_mut(LOCAL_ID.value())
.get_mut(LOCAL_ID.value_raw())
.unwrap()
}
@@ -2214,13 +2212,13 @@ mod tests {
assert!(!self.pdu_queue_empty());
let pdu = self.get_next_pdu().unwrap();
assert_eq!(pdu.pdu_type, PduType::FileDirective);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::AckPdu);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::Ack);
let ack_pdu = AckPdu::from_bytes(&pdu.raw_pdu).unwrap();
assert_eq!(ack_pdu.condition_code(), cond_code);
assert_eq!(ack_pdu.transaction_status(), TransactionStatus::Active);
assert_eq!(
ack_pdu.directive_code_of_acked_pdu(),
FileDirectiveType::EofPdu
FileDirectiveType::Eof
);
}
@@ -2229,7 +2227,7 @@ mod tests {
assert_eq!(pdu.pdu_type, PduType::FileDirective);
assert_eq!(
pdu.file_directive_type.unwrap(),
FileDirectiveType::FinishedPdu
FileDirectiveType::Finished
);
let finished_pdu = FinishedPduReader::from_bytes(&pdu.raw_pdu).unwrap();
assert_eq!(finished_pdu.delivery_code(), DeliveryCode::Complete);
@@ -2248,7 +2246,7 @@ mod tests {
assert_eq!(pdu.pdu_type, PduType::FileDirective);
assert_eq!(
pdu.file_directive_type.unwrap(),
FileDirectiveType::FinishedPdu
FileDirectiveType::Finished
);
let finished_pdu = FinishedPduReader::from_bytes(&pdu.raw_pdu).unwrap();
assert_eq!(finished_pdu.delivery_code(), delivery_code);
@@ -2764,7 +2762,7 @@ mod tests {
assert_eq!(sent_pdu.pdu_type, PduType::FileDirective);
assert_eq!(
sent_pdu.file_directive_type,
Some(FileDirectiveType::FinishedPdu)
Some(FileDirectiveType::Finished)
);
let finished_pdu = FinishedPduReader::from_bytes(&sent_pdu.raw_pdu).unwrap();
assert_eq!(finished_pdu.file_status(), FileStatus::Retained);
@@ -2826,7 +2824,7 @@ mod tests {
} = error
{
assert_eq!(pdu_type, PduType::FileDirective);
assert_eq!(directive_type, Some(FileDirectiveType::FinishedPdu));
assert_eq!(directive_type, Some(FileDirectiveType::Finished));
}
}
@@ -2938,7 +2936,7 @@ mod tests {
assert_eq!(sent_pdu.pdu_type, PduType::FileDirective);
assert_eq!(
sent_pdu.file_directive_type,
Some(FileDirectiveType::FinishedPdu)
Some(FileDirectiveType::Finished)
);
let finished_pdu = FinishedPduReader::from_bytes(&sent_pdu.raw_pdu).unwrap();
assert_eq!(finished_pdu.file_status(), FileStatus::Retained);
@@ -3083,7 +3081,7 @@ mod tests {
assert_eq!(finished_pdu.pdu_type, PduType::FileDirective);
assert_eq!(
finished_pdu.file_directive_type.unwrap(),
FileDirectiveType::FinishedPdu
FileDirectiveType::Finished
);
let finished_pdu = FinishedPduReader::from_bytes(&finished_pdu.raw_pdu).unwrap();
assert_eq!(
@@ -3197,7 +3195,7 @@ mod tests {
assert_eq!(next_pdu.pdu_type, PduType::FileDirective);
assert_eq!(
next_pdu.file_directive_type.unwrap(),
FileDirectiveType::FinishedPdu
FileDirectiveType::Finished
);
let finished_pdu =
FinishedPduReader::new(&next_pdu.raw_pdu).expect("finished pdu read failed");
@@ -3249,7 +3247,7 @@ mod tests {
assert_eq!(next_pdu.pdu_type, PduType::FileDirective);
assert_eq!(
next_pdu.file_directive_type.unwrap(),
FileDirectiveType::FinishedPdu
FileDirectiveType::Finished
);
let finished_pdu =
FinishedPduReader::new(&next_pdu.raw_pdu).expect("finished pdu read failed");
@@ -3284,7 +3282,7 @@ mod tests {
let remote_cfg_mut = tb
.handler
.remote_cfg_table
.get_mut(LOCAL_ID.value())
.get_mut(LOCAL_ID.value_raw())
.unwrap();
remote_cfg_mut.disposition_on_cancellation = true;
let mut user = tb.test_user_from_cached_paths(0);
@@ -3322,7 +3320,7 @@ mod tests {
let remote_cfg_mut = tb
.handler
.remote_cfg_table
.get_mut(LOCAL_ID.value())
.get_mut(LOCAL_ID.value_raw())
.unwrap();
remote_cfg_mut.disposition_on_cancellation = true;
let mut user = tb.test_user_from_cached_paths(file_size);
@@ -3378,7 +3376,7 @@ mod tests {
assert_eq!(tb.pdu_queue_len(), 1);
let pdu = tb.get_next_pdu().unwrap();
assert_eq!(pdu.pdu_type, PduType::FileDirective);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::NakPdu);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::Nak);
let nak_pdu = NakPduReader::new(&pdu.raw_pdu).unwrap();
assert_eq!(nak_pdu.pdu_header().common_pdu_conf().file_flag, file_flag);
assert_eq!(nak_pdu.start_of_scope(), 0);
@@ -3444,7 +3442,7 @@ mod tests {
assert_eq!(tb.pdu_queue_len(), 1);
let pdu = tb.get_next_pdu().unwrap();
assert_eq!(pdu.pdu_type, PduType::FileDirective);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::NakPdu);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::Nak);
let nak_pdu = NakPduReader::new(&pdu.raw_pdu).unwrap();
assert_eq!(nak_pdu.start_of_scope(), 0);
assert_eq!(nak_pdu.end_of_scope(), file_size);
@@ -3494,7 +3492,7 @@ mod tests {
assert_eq!(tb.pdu_queue_len(), 1);
let pdu = tb.get_next_pdu().unwrap();
assert_eq!(pdu.pdu_type, PduType::FileDirective);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::NakPdu);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::Nak);
let nak_pdu = NakPduReader::new(&pdu.raw_pdu).unwrap();
assert_eq!(nak_pdu.start_of_scope(), 0);
assert_eq!(nak_pdu.end_of_scope(), file_size);
@@ -3552,7 +3550,7 @@ mod tests {
tb.check_eof_ack_pdu(ConditionCode::NoError);
let pdu = tb.get_next_pdu().unwrap();
assert_eq!(pdu.pdu_type, PduType::FileDirective);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::NakPdu);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::Nak);
let nak_pdu = NakPduReader::new(&pdu.raw_pdu).unwrap();
assert_eq!(nak_pdu.start_of_scope(), 0);
assert_eq!(nak_pdu.end_of_scope(), file_size);
@@ -3614,7 +3612,7 @@ mod tests {
assert_eq!(tb.pdu_queue_len(), 1);
let pdu = tb.get_next_pdu().unwrap();
assert_eq!(pdu.pdu_type, PduType::FileDirective);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::NakPdu);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::Nak);
let nak_pdu = NakPduReader::new(&pdu.raw_pdu).unwrap();
assert_eq!(nak_pdu.start_of_scope(), 0);
assert_eq!(nak_pdu.end_of_scope(), file_size);
@@ -3628,7 +3626,7 @@ mod tests {
assert_eq!(tb.pdu_queue_len(), 1);
let pdu = tb.get_next_pdu().unwrap();
assert_eq!(pdu.pdu_type, PduType::FileDirective);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::NakPdu);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::Nak);
let nak_pdu = NakPduReader::new(&pdu.raw_pdu).unwrap();
assert_eq!(nak_pdu.start_of_scope(), 0);
assert_eq!(nak_pdu.end_of_scope(), file_size);
@@ -3842,7 +3840,7 @@ mod tests {
assert_eq!(tb.pdu_queue_len(), 1);
let pdu = tb.get_next_pdu().unwrap();
assert_eq!(pdu.pdu_type, PduType::FileDirective);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::NakPdu);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::Nak);
let nak_pdu = NakPduReader::new(&pdu.raw_pdu).unwrap();
assert_eq!(nak_pdu.start_of_scope(), 0);
assert_eq!(nak_pdu.end_of_scope(), file_size);
@@ -3926,7 +3924,7 @@ mod tests {
tb.check_eof_ack_pdu(ConditionCode::NoError);
let pdu = tb.get_next_pdu().unwrap();
assert_eq!(pdu.pdu_type, PduType::FileDirective);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::NakPdu);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::Nak);
let nak_pdu = NakPduReader::new(&pdu.raw_pdu).unwrap();
assert_eq!(nak_pdu.start_of_scope(), 0);
assert_eq!(nak_pdu.end_of_scope(), 10);
@@ -3935,7 +3933,7 @@ mod tests {
let pdu = tb.get_next_pdu().unwrap();
assert_eq!(pdu.pdu_type, PduType::FileDirective);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::NakPdu);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::Nak);
let nak_pdu = NakPduReader::new(&pdu.raw_pdu).unwrap();
assert_eq!(nak_pdu.start_of_scope(), 10);
assert_eq!(nak_pdu.end_of_scope(), file_size);
@@ -4036,7 +4034,7 @@ mod tests {
tb.check_eof_ack_pdu(ConditionCode::NoError);
let pdu = tb.get_next_pdu().unwrap();
assert_eq!(pdu.pdu_type, PduType::FileDirective);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::NakPdu);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::Nak);
let nak_pdu = NakPduReader::new(&pdu.raw_pdu).unwrap();
assert_eq!(nak_pdu.start_of_scope(), 0);
assert_eq!(nak_pdu.end_of_scope(), 14);
@@ -4045,7 +4043,7 @@ mod tests {
let pdu = tb.get_next_pdu().unwrap();
assert_eq!(pdu.pdu_type, PduType::FileDirective);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::NakPdu);
assert_eq!(pdu.file_directive_type.unwrap(), FileDirectiveType::Nak);
let nak_pdu = NakPduReader::new(&pdu.raw_pdu).unwrap();
assert_eq!(nak_pdu.start_of_scope(), 14);
assert_eq!(nak_pdu.end_of_scope(), file_size);

View File

@@ -138,7 +138,7 @@ use spacepackets::{
ChecksumType, ConditionCode, FaultHandlerCode, PduType, TransmissionMode,
pdu::{FileDirectiveType, PduError, PduHeader},
},
util::{UnsignedByteField, UnsignedEnum},
util::UnsignedByteField,
};
#[cfg(feature = "std")]
pub use std_mod::*;
@@ -942,26 +942,26 @@ pub fn determine_packet_target(raw_pdu: &[u8]) -> Result<PacketTarget, PduError>
let packet_target = match file_directive_type {
// Section c) of 4.5.3: These PDUs should always be targeted towards the file sender a.k.a.
// the source handler
FileDirectiveType::NakPdu
| FileDirectiveType::FinishedPdu
| FileDirectiveType::KeepAlivePdu => PacketTarget::SourceEntity,
FileDirectiveType::Nak | FileDirectiveType::Finished | FileDirectiveType::KeepAlive => {
PacketTarget::SourceEntity
}
// Section b) of 4.5.3: These PDUs should always be targeted towards the file receiver a.k.a.
// the destination handler
FileDirectiveType::MetadataPdu
| FileDirectiveType::EofPdu
| FileDirectiveType::PromptPdu => PacketTarget::DestEntity,
FileDirectiveType::Metadata | FileDirectiveType::Eof | FileDirectiveType::Prompt => {
PacketTarget::DestEntity
}
// Section a): Recipient depends of the type of PDU that is being acknowledged. We can simply
// extract the PDU type from the raw stream. If it is an EOF PDU, this packet is passed to
// the source handler, for a Finished PDU, it is passed to the destination handler.
FileDirectiveType::AckPdu => {
FileDirectiveType::Ack => {
let acked_directive = FileDirectiveType::try_from(raw_pdu[header_len + 1] >> 4)
.map_err(|_| PduError::InvalidDirectiveType {
found: (raw_pdu[header_len + 1] >> 4),
expected: None,
})?;
if acked_directive == FileDirectiveType::EofPdu {
if acked_directive == FileDirectiveType::Eof {
PacketTarget::SourceEntity
} else if acked_directive == FileDirectiveType::FinishedPdu {
} else if acked_directive == FileDirectiveType::Finished {
PacketTarget::DestEntity
} else {
// TODO: Maybe a better error? This might be confusing..
@@ -1576,7 +1576,7 @@ pub(crate) mod tests {
assert!(packet_info.file_directive_type().is_some());
assert_eq!(
packet_info.file_directive_type().unwrap(),
FileDirectiveType::MetadataPdu
FileDirectiveType::Metadata
);
assert_eq!(
packet_info.raw_packet(),
@@ -1623,7 +1623,7 @@ pub(crate) mod tests {
assert_eq!(packet_info.raw_packet(), &buf[0..eof_pdu.len_written()]);
assert_eq!(
packet_info.file_directive_type().unwrap(),
FileDirectiveType::EofPdu
FileDirectiveType::Eof
);
}
@@ -1659,7 +1659,7 @@ pub(crate) mod tests {
TransmissionMode::Unacknowledged,
ChecksumType::Crc32,
);
let remote_entity_retrieved = remote_entity_cfg.get(REMOTE_ID.value()).unwrap();
let remote_entity_retrieved = remote_entity_cfg.get(REMOTE_ID.value().into()).unwrap();
assert_eq!(remote_entity_retrieved.entity_id, REMOTE_ID.into());
assert_eq!(remote_entity_retrieved.max_packet_len, 1024);
assert!(remote_entity_retrieved.closure_requested_by_default);
@@ -1668,7 +1668,7 @@ pub(crate) mod tests {
remote_entity_retrieved.default_crc_type,
ChecksumType::Crc32
);
let remote_entity_mut = remote_entity_cfg.get_mut(REMOTE_ID.value()).unwrap();
let remote_entity_mut = remote_entity_cfg.get_mut(REMOTE_ID.value_raw()).unwrap();
assert_eq!(remote_entity_mut.entity_id, REMOTE_ID.into());
let dummy = RemoteEntityConfig::new_with_default_values(
LOCAL_ID.into(),
@@ -1682,11 +1682,11 @@ pub(crate) mod tests {
remote_entity_cfg.add_config(&dummy).unwrap_err(),
RemoteConfigStoreError::Full
);
let remote_entity_retrieved = remote_entity_cfg.get(REMOTE_ID.value()).unwrap();
let remote_entity_retrieved = remote_entity_cfg.get(REMOTE_ID.value_raw()).unwrap();
assert_eq!(remote_entity_retrieved.entity_id, REMOTE_ID.into());
// Does not exist.
assert!(remote_entity_cfg.get(LOCAL_ID.value()).is_none());
assert!(remote_entity_cfg.get_mut(LOCAL_ID.value()).is_none());
assert!(remote_entity_cfg.get(LOCAL_ID.value_raw()).is_none());
assert!(remote_entity_cfg.get_mut(LOCAL_ID.value_raw()).is_none());
}
#[test]
@@ -1711,20 +1711,20 @@ pub(crate) mod tests {
TransmissionMode::Unacknowledged,
ChecksumType::Crc32,
);
let cfg_0 = remote_cfg_provider.get(REMOTE_ID.value()).unwrap();
let cfg_0 = remote_cfg_provider.get(REMOTE_ID.value_raw()).unwrap();
assert_eq!(cfg_0.entity_id, REMOTE_ID.into());
remote_cfg_provider
.add_config(&remote_entity_cfg_2)
.unwrap();
assert_eq!(remote_cfg_provider.0.len(), 2);
let cfg_1 = remote_cfg_provider.get(LOCAL_ID.value()).unwrap();
let cfg_1 = remote_cfg_provider.get(LOCAL_ID.value_raw()).unwrap();
assert_eq!(cfg_1.entity_id, LOCAL_ID.into());
assert!(remote_cfg_provider.remove_config(REMOTE_ID.value()));
assert!(remote_cfg_provider.remove_config(REMOTE_ID.value_raw()));
assert_eq!(remote_cfg_provider.0.len(), 1);
let cfg_1_mut = remote_cfg_provider.get_mut(LOCAL_ID.value()).unwrap();
let cfg_1_mut = remote_cfg_provider.get_mut(LOCAL_ID.value_raw()).unwrap();
cfg_1_mut.default_crc_type = ChecksumType::Crc32C;
assert!(!remote_cfg_provider.remove_config(REMOTE_ID.value()));
assert!(remote_cfg_provider.get_mut(REMOTE_ID.value()).is_none());
assert!(!remote_cfg_provider.remove_config(REMOTE_ID.value_raw()));
assert!(remote_cfg_provider.get_mut(REMOTE_ID.value_raw()).is_none());
}
#[test]
@@ -1749,7 +1749,7 @@ pub(crate) mod tests {
TransmissionMode::Unacknowledged,
ChecksumType::Crc32,
);
let cfg_0 = remote_cfg_provider.get(REMOTE_ID.value()).unwrap();
let cfg_0 = remote_cfg_provider.get(REMOTE_ID.value_raw()).unwrap();
assert_eq!(cfg_0.entity_id, REMOTE_ID.into());
assert!(
remote_cfg_provider
@@ -1757,14 +1757,14 @@ pub(crate) mod tests {
.unwrap()
);
assert_eq!(remote_cfg_provider.0.len(), 2);
let cfg_1 = remote_cfg_provider.get(LOCAL_ID.value()).unwrap();
let cfg_1 = remote_cfg_provider.get(LOCAL_ID.value_raw()).unwrap();
assert_eq!(cfg_1.entity_id, LOCAL_ID.into());
assert!(remote_cfg_provider.remove_config(REMOTE_ID.value()));
assert!(remote_cfg_provider.remove_config(REMOTE_ID.value_raw()));
assert_eq!(remote_cfg_provider.0.len(), 1);
let cfg_1_mut = remote_cfg_provider.get_mut(LOCAL_ID.value()).unwrap();
let cfg_1_mut = remote_cfg_provider.get_mut(LOCAL_ID.value_raw()).unwrap();
cfg_1_mut.default_crc_type = ChecksumType::Crc32C;
assert!(!remote_cfg_provider.remove_config(REMOTE_ID.value()));
assert!(remote_cfg_provider.get_mut(REMOTE_ID.value()).is_none());
assert!(!remote_cfg_provider.remove_config(REMOTE_ID.value_raw()));
assert!(remote_cfg_provider.get_mut(REMOTE_ID.value_raw()).is_none());
}
#[test]

View File

@@ -442,12 +442,9 @@ impl<
return Err(PutRequestError::AlreadyBusy);
}
self.put_request_cacher.set(put_request)?;
let remote_cfg = self.remote_cfg_table.get(
self.put_request_cacher
.static_fields
.destination_id
.value_const(),
);
let remote_cfg = self
.remote_cfg_table
.get(self.put_request_cacher.static_fields.destination_id.value());
if remote_cfg.is_none() {
return Err(PutRequestError::NoRemoteCfgFound(
self.put_request_cacher.static_fields.destination_id,
@@ -495,7 +492,7 @@ impl<
);
let create_id = |cached_id: &UnsignedByteField| {
if larger_entity_width != cached_id.size() {
UnsignedByteField::new(larger_entity_width, cached_id.value_const())
UnsignedByteField::new(larger_entity_width, cached_id.value())
} else {
*cached_id
}
@@ -558,22 +555,20 @@ impl<
.file_directive_type()
.expect("PDU directive type unexpectedly not set")
{
FileDirectiveType::FinishedPdu => {
FileDirectiveType::Finished => {
let finished_pdu = FinishedPduReader::new(packet_to_insert.raw_pdu())?;
self.handle_finished_pdu(&finished_pdu)?
}
FileDirectiveType::NakPdu => {
FileDirectiveType::Nak => {
let nak_pdu = NakPduReader::new(packet_to_insert.raw_pdu())?;
sent_packets += self.handle_nak_pdu(&nak_pdu)?;
}
FileDirectiveType::KeepAlivePdu => self.handle_keep_alive_pdu(),
FileDirectiveType::AckPdu => {
FileDirectiveType::KeepAlive => self.handle_keep_alive_pdu(),
FileDirectiveType::Ack => {
let ack_pdu = AckPdu::from_bytes(packet_to_insert.raw_pdu())?;
self.handle_ack_pdu(&ack_pdu)?
}
FileDirectiveType::EofPdu
| FileDirectiveType::PromptPdu
| FileDirectiveType::MetadataPdu => {
FileDirectiveType::Eof | FileDirectiveType::Prompt | FileDirectiveType::Metadata => {
return Err(SourceError::CantProcessPacketType {
pdu_type: packet_to_insert.pdu_type(),
directive_type: packet_to_insert.file_directive_type(),
@@ -898,7 +893,7 @@ impl<
) -> Result<(), SourceError> {
let ack_pdu = AckPdu::new(
PduHeader::new_for_file_directive(self.transaction_params.pdu_conf, 0),
FileDirectiveType::FinishedPdu,
FileDirectiveType::Finished,
condition_code,
transaction_status,
)
@@ -1093,7 +1088,7 @@ impl<
if self.step() != TransactionStep::WaitingForFinished {
return Err(SourceError::UnexpectedPdu {
pdu_type: PduType::FileDirective,
directive_type: Some(FileDirectiveType::FinishedPdu),
directive_type: Some(FileDirectiveType::Finished),
});
}
// Unwrapping should be fine here, the transfer state is valid when we are not in IDLE
@@ -1122,10 +1117,10 @@ impl<
// Drop the packet, wrong state to handle it..
return Err(SourceError::UnexpectedPdu {
pdu_type: PduType::FileDirective,
directive_type: Some(FileDirectiveType::AckPdu),
directive_type: Some(FileDirectiveType::Ack),
});
}
if ack_pdu.directive_code_of_acked_pdu() == FileDirectiveType::EofPdu {
if ack_pdu.directive_code_of_acked_pdu() == FileDirectiveType::Eof {
self.set_step(TransactionStep::WaitingForFinished);
} else {
self.anomalies.invalid_ack_directive_code =
@@ -1550,7 +1545,7 @@ mod tests {
assert_eq!(next_pdu.pdu_type, PduType::FileDirective);
assert_eq!(
next_pdu.file_directive_type,
Some(FileDirectiveType::MetadataPdu)
Some(FileDirectiveType::Metadata)
);
let metadata_pdu =
MetadataPduReader::new(&next_pdu.raw_pdu).expect("invalid metadata PDU format");
@@ -1599,7 +1594,7 @@ mod tests {
) {
let ack_pdu = AckPdu::new(
transaction_info.pdu_header,
FileDirectiveType::EofPdu,
FileDirectiveType::Eof,
ConditionCode::NoError,
TransactionStatus::Active,
)
@@ -1616,16 +1611,13 @@ mod tests {
let next_pdu = self.get_next_sent_pdu().unwrap();
assert!(self.pdu_queue_empty());
assert_eq!(next_pdu.pdu_type, PduType::FileDirective);
assert_eq!(
next_pdu.file_directive_type,
Some(FileDirectiveType::AckPdu)
);
assert_eq!(next_pdu.file_directive_type, Some(FileDirectiveType::Ack));
let ack_pdu = AckPdu::from_bytes(&next_pdu.raw_pdu).unwrap();
self.common_pdu_check_for_file_transfer(ack_pdu.pdu_header(), CrcFlag::NoCrc);
assert_eq!(ack_pdu.condition_code(), ConditionCode::NoError);
assert_eq!(
ack_pdu.directive_code_of_acked_pdu(),
FileDirectiveType::FinishedPdu
FileDirectiveType::Finished
);
assert_eq!(ack_pdu.transaction_status(), TransactionStatus::Active);
}
@@ -1639,10 +1631,7 @@ mod tests {
) {
let next_pdu = self.get_next_sent_pdu().unwrap();
assert_eq!(next_pdu.pdu_type, PduType::FileDirective);
assert_eq!(
next_pdu.file_directive_type,
Some(FileDirectiveType::EofPdu)
);
assert_eq!(next_pdu.file_directive_type, Some(FileDirectiveType::Eof));
let eof_pdu = EofPdu::from_bytes(&next_pdu.raw_pdu).expect("invalid EOF PDU format");
self.common_pdu_check_for_file_transfer(eof_pdu.pdu_header(), CrcFlag::NoCrc);
assert_eq!(eof_pdu.condition_code(), eof_params.condition_code);
@@ -1653,7 +1642,7 @@ mod tests {
.pdu_header()
.common_pdu_conf()
.transaction_seq_num
.value_const(),
.value(),
0
);
if self.transmission_mode == TransmissionMode::Unacknowledged {
@@ -2031,10 +2020,7 @@ mod tests {
let eof_pdu = tb
.get_next_sent_pdu()
.expect("no EOF PDU generated like expected");
assert_eq!(
eof_pdu.file_directive_type.unwrap(),
FileDirectiveType::EofPdu
);
assert_eq!(eof_pdu.file_directive_type.unwrap(), FileDirectiveType::Eof);
let eof_pdu = EofPdu::from_bytes(&eof_pdu.raw_pdu).unwrap();
assert_eq!(
eof_pdu.condition_code(),
@@ -2096,7 +2082,7 @@ mod tests {
assert_eq!(next_packet.pdu_type, PduType::FileDirective);
assert_eq!(
next_packet.file_directive_type.unwrap(),
FileDirectiveType::EofPdu
FileDirectiveType::Eof
);
// As specified in 4.11.2.2 of the standard, the file size will be the progress of the
// file copy operation so far, and the checksum is calculated for that progress.