Skip to content

Commit

Permalink
Address feedback from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Andrei Litvin <andy314@gmail.com>
  • Loading branch information
ivmarkov and andy31415 committed Jun 22, 2024
1 parent 904d20e commit 7f4e437
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion rs-matter/src/transport/network/btp/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ where
.find(|session| session.address() == address)
{
if !session.set_subscribed() {
unreachable!();
warn!("Got a second subscribe request for an address which is already subscribed: {address}");
Err(ErrorCode::InvalidState)?;
}

self.handshake_notif.notify();
Expand Down
11 changes: 7 additions & 4 deletions rs-matter/src/transport/network/btp/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,12 @@ impl RecvWindow {
}

fn check_data_integrity(&self, hdr: &BtpHdr, payload: &[u8], mtu: u16) -> Result<(), Error> {
if hdr.is_handshake() // Handshake packets are not allowed here
|| hdr.get_opcode().is_some()
{
if hdr.is_handshake() {
warn!("RX data integrity failure: Handshake packets are not allowed here");
return Err(ErrorCode::InvalidData.into());
}

if hdr.get_opcode().is_some() {
warn!("RX data integrity failure: Data and standalone ACK packets must not have an opcode");
return Err(ErrorCode::InvalidData.into());
}
Expand Down Expand Up @@ -455,7 +458,7 @@ impl Session {
/// (As per the Matter Core spec, at any moment in time, a session
/// can send the BTP segments of a single BTP SDU, hence the need for locking.)
///
/// Will return `false` if the session is already locked for sending.
/// Will return `false` if sending is true and the session is already locked for sending.
pub fn set_sending(&mut self, sending: bool) -> bool {
if sending && self.send_window.sending {
return false; // already in sending mode, cannot set twice
Expand Down

0 comments on commit 7f4e437

Please sign in to comment.