s2n_quic_core/stream/state/recv.rs
1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::state::{event, is};
5
6//= https://www.rfc-editor.org/rfc/rfc9000#section-3.2
7//# o
8//# | Recv STREAM / STREAM_DATA_BLOCKED / RESET_STREAM
9//# | Create Bidirectional Stream (Sending)
10//# | Recv MAX_STREAM_DATA / STOP_SENDING (Bidirectional)
11//# | Create Higher-Numbered Stream
12//# v
13//# +-------+
14//# | Recv | Recv RESET_STREAM
15//# | |-----------------------.
16//# +-------+ |
17//# | |
18//# | Recv STREAM + FIN |
19//# v |
20//# +-------+ |
21//# | Size | Recv RESET_STREAM |
22//# | Known |---------------------->|
23//# +-------+ |
24//# | |
25//# | Recv All Data |
26//# v v
27//# +-------+ Recv RESET_STREAM +-------+
28//# | Data |--- (optional) --->| Reset |
29//# | Recvd | Recv All Data | Recvd |
30//# +-------+<-- (optional) ----+-------+
31//# | |
32//# | App Read All Data | App Read Reset
33//# v v
34//# +-------+ +-------+
35//# | Data | | Reset |
36//# | Read | | Read |
37//# +-------+ +-------+
38
39#[derive(Clone, Debug, Default, PartialEq, Eq)]
40pub enum Receiver {
41 #[default]
42 Recv,
43 SizeKnown,
44 DataRecvd,
45 DataRead,
46 ResetRecvd,
47 ResetRead,
48}
49
50impl Receiver {
51 is!(is_receiving, Recv);
52 is!(is_size_known, SizeKnown);
53 is!(is_data_received, DataRecvd);
54 is!(is_data_read, DataRead);
55 is!(is_reset_received, ResetRecvd);
56 is!(is_reset_read, ResetRead);
57 is!(is_terminal, DataRead | ResetRead);
58
59 event! {
60 on_receive_fin(Recv => SizeKnown);
61 on_receive_all_data(SizeKnown => DataRecvd);
62 on_app_read_all_data(DataRecvd => DataRead);
63
64 on_reset(Recv | SizeKnown => ResetRecvd);
65 on_app_read_reset(ResetRecvd => ResetRead);
66 }
67}
68
69#[cfg(test)]
70mod tests {
71 use super::*;
72 use insta::{assert_debug_snapshot, assert_snapshot};
73
74 #[test]
75 #[cfg_attr(miri, ignore)]
76 fn snapshots() {
77 assert_debug_snapshot!(Receiver::test_transitions());
78 }
79
80 #[test]
81 #[cfg_attr(miri, ignore)]
82 fn dot_test() {
83 assert_snapshot!(Receiver::dot());
84 }
85}