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

Get next available stream ID more efficiently #338

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 9 additions & 4 deletions src/aioquic/quic/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dataclasses import dataclass
from enum import Enum
from functools import partial
from itertools import count
from typing import Any, Deque, Dict, FrozenSet, List, Optional, Sequence, Set, Tuple

from .. import tls
Expand Down Expand Up @@ -416,6 +417,13 @@ def __init__(
0x31: (self._handle_datagram_frame, EPOCHS("01")),
}

if self._is_client:
self._bidi_stream_id = count(0, 4)
self._uni_stream_id = count(2, 4)
else:
self._bidi_stream_id = count(1, 4)
self._uni_stream_id = count(3, 4)

@property
def configuration(self) -> QuicConfiguration:
return self._configuration
Expand Down Expand Up @@ -623,10 +631,7 @@ 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
return next(self._uni_stream_id if is_unidirectional else self._bidi_stream_id)

def get_timer(self) -> Optional[float]:
"""
Expand Down