Skip to content

Commit 5e7e788

Browse files
committed
Exchange: Add support for session termination
1 parent fcb7f9c commit 5e7e788

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

matter/src/interaction_model/core.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ impl<'a> Transaction<'a> {
6868
}
6969
}
7070

71+
/// Terminates the transaction, no communication (even ACKs) happens hence forth
72+
pub fn terminate(&mut self) {
73+
self.state = TransactionState::Terminate
74+
}
75+
76+
pub fn is_terminate(&self) -> bool {
77+
self.state == TransactionState::Terminate
78+
}
79+
80+
/// Marks the transaction as completed from the application's perspective
7181
pub fn complete(&mut self) {
7282
self.state = TransactionState::Complete
7383
}
@@ -200,7 +210,9 @@ impl proto_demux::HandleProto for InteractionModel {
200210
info!("Sending response");
201211
tlv::print_tlv_list(ctx.tx.as_borrow_slice());
202212
}
203-
if trans.is_complete() {
213+
if trans.is_terminate() {
214+
ctx.exch_ctx.exch.terminate();
215+
} else if trans.is_complete() {
204216
ctx.exch_ctx.exch.close();
205217
}
206218
Ok(result)

matter/src/interaction_model/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use self::{
3030
pub enum TransactionState {
3131
Ongoing,
3232
Complete,
33+
Terminate,
3334
}
3435
pub struct Transaction<'a> {
3536
pub state: TransactionState,

matter/src/transport/exchange.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ impl Default for Role {
4848
}
4949
}
5050

51+
/// State of the exchange
5152
#[derive(Debug, PartialEq)]
5253
enum State {
54+
/// The exchange is open and active
5355
Open,
56+
/// The exchange is closed, but keys are active since retransmissions/acks may be pending
5457
Close,
58+
/// The exchange is terminated, keys are destroyed, no communication can happen
59+
Terminate,
5560
}
5661

5762
impl Default for State {
@@ -100,6 +105,11 @@ impl Exchange {
100105
}
101106
}
102107

108+
pub fn terminate(&mut self) {
109+
self.data = DataOption::None;
110+
self.state = State::Terminate;
111+
}
112+
103113
pub fn close(&mut self) {
104114
self.data = DataOption::None;
105115
self.state = State::Close;
@@ -111,7 +121,7 @@ impl Exchange {
111121

112122
pub fn is_purgeable(&self) -> bool {
113123
// No Users, No pending ACKs/Retrans
114-
self.state == State::Close && self.mrp.is_empty()
124+
self.state == State::Terminate || (self.state == State::Close && self.mrp.is_empty())
115125
}
116126

117127
pub fn get_id(&self) -> u16 {
@@ -170,6 +180,11 @@ impl Exchange {
170180
mut proto_tx: BoxSlab<PacketPool>,
171181
session: &mut SessionHandle,
172182
) -> Result<(), Error> {
183+
if self.state == State::Terminate {
184+
info!("Skipping tx for terminated exchange {}", self.id);
185+
return Ok(());
186+
}
187+
173188
trace!("payload: {:x?}", proto_tx.as_borrow_slice());
174189
info!(
175190
"{} with proto id: {} opcode: {}",

0 commit comments

Comments
 (0)