Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[connection] Constant-time stream ID allocation #403

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/aioquic/quic/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ def __init__(
self._local_max_streams_uni = Limit(
frame_type=QuicFrameType.MAX_STREAMS_UNI, name="max_streams_uni", value=128
)
self._local_next_stream_id_bidi = 0 if self._is_client else 1
self._local_next_stream_id_uni = 2 if self._is_client else 3
self._loss_at: Optional[float] = None
self._network_paths: List[QuicNetworkPath] = []
self._pacing_at: Optional[float] = None
Expand Down Expand Up @@ -623,10 +625,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._local_next_stream_id_uni
else:
return self._local_next_stream_id_bidi

def get_timer(self) -> Optional[float]:
"""
Expand Down Expand Up @@ -1291,12 +1293,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._local_next_stream_id_uni = stream_id + 4
else:
self._local_next_stream_id_bidi = stream_id + 4

# mark stream as blocked if needed
if stream_id // 4 >= max_streams:
Expand Down
Loading