diff --git a/src/aioquic/quic/connection.py b/src/aioquic/quic/connection.py index b99c4ab85..49c6e65d8 100644 --- a/src/aioquic/quic/connection.py +++ b/src/aioquic/quic/connection.py @@ -342,10 +342,14 @@ def __init__( if self._is_client: self._original_destination_connection_id = self._peer_cid.cid + self._next_uni_id = 2 + self._next_bidi_id = 0 else: self._original_destination_connection_id = ( original_destination_connection_id ) + self._next_uni_id = 3 + self._next_bidi_id = 1 # logging self._logger = QuicConnectionAdapter( @@ -623,10 +627,10 @@ def get_next_available_stream_id(self, is_unidirectional=False) -> int: """ Return the stream ID for the next stream created by this endpoint. """ - stream_id = (int(is_unidirectional) << 1) | int(not self._is_client) - while stream_id in self._streams or stream_id in self._streams_finished: - stream_id += 4 - return stream_id + if is_unidirectional: + return self._next_uni_id + else: + return self._next_bidi_id def get_timer(self) -> Optional[float]: """ @@ -1291,12 +1295,17 @@ def _get_or_create_stream_for_send(self, stream_id: int) -> QuicStream: streams_blocked = self._streams_blocked_bidi # create stream + is_unidirectional = stream_is_unidirectional(stream_id) stream = self._streams[stream_id] = QuicStream( stream_id=stream_id, max_stream_data_local=max_stream_data_local, max_stream_data_remote=max_stream_data_remote, - readable=not stream_is_unidirectional(stream_id), + readable=not is_unidirectional ) + if is_unidirectional: + self._next_uni_id = stream_id + 4 + else: + self._next_bidi_id = stream_id + 4 # mark stream as blocked if needed if stream_id // 4 >= max_streams: