Skip to content

Commit

Permalink
Add StopSendingReceived QUIC event
Browse files Browse the repository at this point in the history
Section 2.4 of RFC9000 says that an application protocol can
request to be informed of state changes on streams. Even though
the state machines described in section 3 don't explicitly have
state transitions regarding STOP_SENDING, an application
protocol sometimes needs to know the reception of STOP_SENDING.
  • Loading branch information
bashi authored and jlaine committed Nov 4, 2023
1 parent ec69a11 commit 2fe490a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/quic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Events
.. autoclass:: PingAcknowledged
:members:

.. autoclass:: StopSendingReceived
:members:

.. autoclass:: StreamDataReceived
:members:

Expand Down
4 changes: 4 additions & 0 deletions src/aioquic/quic/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,10 @@ def _handle_stop_sending_frame(
stream = self._get_or_create_stream(frame_type, stream_id)
stream.sender.reset(error_code=QuicErrorCode.NO_ERROR)

self._events.append(
events.StopSendingReceived(error_code=error_code, stream_id=stream_id)
)

def _handle_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
Expand Down
14 changes: 14 additions & 0 deletions src/aioquic/quic/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ class ProtocolNegotiated(QuicEvent):
"The protocol which was negotiated using ALPN, or `None`."


@dataclass
class StopSendingReceived(QuicEvent):
"""
The StopSendingReceived event is fired when the remote peer requests
stopping data transmission on a stream.
"""

error_code: int
"The error code that was sent from the peer."

stream_id: int
"The ID of the stream that the peer requested stopping data transmission."


@dataclass
class StreamDataReceived(QuicEvent):
"""
Expand Down
13 changes: 13 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,19 @@ def test_handle_stop_sending_frame(self):
Buffer(data=b"\x00\x11"),
)

# check events
self.assertEqual(type(client.next_event()), events.ProtocolNegotiated)
self.assertEqual(type(client.next_event()), events.HandshakeCompleted)
for i in range(7):
self.assertEqual(type(client.next_event()), events.ConnectionIdIssued)

event = client.next_event()
self.assertEqual(type(event), events.StopSendingReceived)
self.assertEqual(event.stream_id, 0)
self.assertEqual(event.error_code, 0x11)

self.assertIsNone(client.next_event())

def test_handle_stop_sending_frame_receive_only(self):
with client_and_server() as (client, server):
# server creates unidirectional stream 3
Expand Down

0 comments on commit 2fe490a

Please sign in to comment.