path
stringlengths 9
117
| type
stringclasses 2
values | project
stringclasses 10
values | commit_hash
stringlengths 40
40
| commit_message
stringlengths 1
137
| ground_truth
stringlengths 0
2.74k
| main_code
stringlengths 102
3.37k
| context
stringlengths 0
14.7k
|
---|---|---|---|---|---|---|---|
examples.http3_client/HttpClient.get
|
Modified
|
aiortc~aioquic
|
fd83fcf933e8e993fa06e3e6578c9b51b2b59f07
|
Remove extra None checks
|
<3>:<del> if headers is None:
<4>:<del> headers = {}
<5>:<del>
|
# module: examples.http3_client
class HttpClient(QuicConnectionProtocol):
def get(self, url: str, headers: Optional[Dict] = None) -> Deque[H3Event]:
<0> """
<1> Perform a GET request.
<2> """
<3> if headers is None:
<4> headers = {}
<5>
<6> return await self._request(
<7> HttpRequest(method="GET", url=URL(url), headers=headers)
<8> )
<9>
|
===========unchanged ref 0===========
at: examples.http3_client
URL(url: str)
HttpRequest(method: str, url: URL, content: bytes=b"", headers: Optional[Dict]=None)
at: examples.http3_client.HttpClient
_request(request: HttpRequest) -> Deque[H3Event]
at: typing
Deque = _alias(collections.deque, 1, name='Deque')
Dict = _alias(dict, 2, inst=False, name='Dict')
|
examples.http3_client/HttpClient.post
|
Modified
|
aiortc~aioquic
|
fd83fcf933e8e993fa06e3e6578c9b51b2b59f07
|
Remove extra None checks
|
<3>:<del> if headers is None:
<4>:<del> headers = {}
<5>:<del>
|
# module: examples.http3_client
class HttpClient(QuicConnectionProtocol):
def post(
self, url: str, data: bytes, headers: Optional[Dict] = None
) -> Deque[H3Event]:
<0> """
<1> Perform a POST request.
<2> """
<3> if headers is None:
<4> headers = {}
<5>
<6> return await self._request(
<7> HttpRequest(method="POST", url=URL(url), content=data, headers=headers)
<8> )
<9>
|
===========unchanged ref 0===========
at: examples.http3_client
URL(url: str)
HttpRequest(method: str, url: URL, content: bytes=b"", headers: Optional[Dict]=None)
WebSocket(http: HttpConnection, stream_id: int, transmit: Callable[[], None])
at: examples.http3_client.HttpClient
_request(request: HttpRequest) -> Deque[H3Event]
at: typing
List = _alias(list, 1, inst=False, name='List')
===========changed ref 0===========
# module: examples.http3_client
class HttpClient(QuicConnectionProtocol):
def get(self, url: str, headers: Optional[Dict] = None) -> Deque[H3Event]:
"""
Perform a GET request.
"""
- if headers is None:
- headers = {}
-
return await self._request(
HttpRequest(method="GET", url=URL(url), headers=headers)
)
|
examples.http3_client/HttpClient.websocket
|
Modified
|
aiortc~aioquic
|
fd83fcf933e8e993fa06e3e6578c9b51b2b59f07
|
Remove extra None checks
|
<3>:<del> if subprotocols is None:
<4>:<del> subprotocols = []
<5>:<del>
|
# module: examples.http3_client
class HttpClient(QuicConnectionProtocol):
def websocket(
self, url: str, subprotocols: Optional[List[str]] = None
) -> WebSocket:
<0> """
<1> Open a WebSocket.
<2> """
<3> if subprotocols is None:
<4> subprotocols = []
<5>
<6> request = HttpRequest(method="CONNECT", url=URL(url))
<7> stream_id = self._quic.get_next_available_stream_id()
<8> websocket = WebSocket(
<9> http=self._http, stream_id=stream_id, transmit=self.transmit
<10> )
<11>
<12> self._websockets[stream_id] = websocket
<13>
<14> headers = [
<15> (b":method", b"CONNECT"),
<16> (b":scheme", b"https"),
<17> (b":authority", request.url.authority.encode()),
<18> (b":path", request.url.full_path.encode()),
<19> (b":protocol", b"websocket"),
<20> (b"user-agent", USER_AGENT.encode()),
<21> (b"sec-websocket-version", b"13"),
<22> ]
<23> if subprotocols:
<24> headers.append(
<25> (b"sec-websocket-protocol", ", ".join(subprotocols).encode())
<26> )
<27> self._http.send_headers(stream_id=stream_id, headers=headers)
<28>
<29> self.transmit()
<30>
<31> return websocket
<32>
|
===========unchanged ref 0===========
at: collections.deque
append(x: _T) -> None
at: examples.http3_client
USER_AGENT = "aioquic/" + aioquic.__version__
URL(url: str)
HttpRequest(method: str, url: URL, content: bytes=b"", headers: Optional[Dict]=None)
WebSocket(http: HttpConnection, stream_id: int, transmit: Callable[[], None])
at: examples.http3_client.HttpClient.__init__
self._http = H3Connection(self._quic)
self._http: Optional[HttpConnection] = None
self._http = H0Connection(self._quic)
self._request_events: Dict[int, Deque[H3Event]] = {}
self._request_waiter: Dict[int, asyncio.Future[Deque[H3Event]]] = {}
self._websockets: Dict[int, WebSocket] = {}
at: examples.http3_client.HttpRequest.__init__
self.url = url
at: examples.http3_client.URL.__init__
self.authority = parsed.netloc
self.full_path += "?" + parsed.query
self.full_path = parsed.path
at: typing.MutableMapping
pop(key: _KT) -> _VT
pop(key: _KT, default: Union[_VT, _T]=...) -> Union[_VT, _T]
===========changed ref 0===========
# module: examples.http3_client
class HttpClient(QuicConnectionProtocol):
def post(
self, url: str, data: bytes, headers: Optional[Dict] = None
) -> Deque[H3Event]:
"""
Perform a POST request.
"""
- if headers is None:
- headers = {}
-
return await self._request(
HttpRequest(method="POST", url=URL(url), content=data, headers=headers)
)
===========changed ref 1===========
# module: examples.http3_client
class HttpClient(QuicConnectionProtocol):
def get(self, url: str, headers: Optional[Dict] = None) -> Deque[H3Event]:
"""
Perform a GET request.
"""
- if headers is None:
- headers = {}
-
return await self._request(
HttpRequest(method="GET", url=URL(url), headers=headers)
)
|
aioquic.buffer/encode_uint_var
|
Modified
|
aiortc~aioquic
|
62e9ba26a30de99f605a049370220897a40ae63a
|
[buffer] add UINT_VAR_MAX_SIZE constant
|
<3>:<add> buf = Buffer(capacity=UINT_VAR_MAX_SIZE)
<del> buf = Buffer(capacity=8)
|
# module: aioquic.buffer
def encode_uint_var(value: int) -> bytes:
<0> """
<1> Encode a variable-length unsigned integer.
<2> """
<3> buf = Buffer(capacity=8)
<4> buf.push_uint_var(value)
<5> return buf.data
<6>
|
===========unchanged ref 0===========
at: aioquic.buffer
UINT_VAR_MAX_SIZE = 8
===========changed ref 0===========
# module: aioquic.buffer
UINT_VAR_MAX = 0x3FFFFFFFFFFFFFFF
+ UINT_VAR_MAX_SIZE = 8
|
aioquic.h3.connection/encode_frame
|
Modified
|
aiortc~aioquic
|
62e9ba26a30de99f605a049370220897a40ae63a
|
[buffer] add UINT_VAR_MAX_SIZE constant
|
<1>:<add> buf = Buffer(capacity=frame_length + 2 * UINT_VAR_MAX_SIZE)
<del> buf = Buffer(capacity=frame_length + 16)
|
# module: aioquic.h3.connection
def encode_frame(frame_type: int, frame_data: bytes) -> bytes:
<0> frame_length = len(frame_data)
<1> buf = Buffer(capacity=frame_length + 16)
<2> buf.push_uint_var(frame_type)
<3> buf.push_uint_var(frame_length)
<4> buf.push_bytes(frame_data)
<5> return buf.data
<6>
|
===========changed ref 0===========
# module: aioquic.buffer
UINT_VAR_MAX = 0x3FFFFFFFFFFFFFFF
+ UINT_VAR_MAX_SIZE = 8
===========changed ref 1===========
# module: aioquic.buffer
def encode_uint_var(value: int) -> bytes:
"""
Encode a variable-length unsigned integer.
"""
+ buf = Buffer(capacity=UINT_VAR_MAX_SIZE)
- buf = Buffer(capacity=8)
buf.push_uint_var(value)
return buf.data
===========changed ref 2===========
# module: aioquic.quic.connection
logger = logging.getLogger("quic")
CRYPTO_BUFFER_SIZE = 16384
EPOCH_SHORTCUTS = {
"I": tls.Epoch.INITIAL,
"H": tls.Epoch.HANDSHAKE,
"0": tls.Epoch.ZERO_RTT,
"1": tls.Epoch.ONE_RTT,
}
MAX_EARLY_DATA = 0xFFFFFFFF
SECRETS_LABELS = [
[
None,
"CLIENT_EARLY_TRAFFIC_SECRET",
"CLIENT_HANDSHAKE_TRAFFIC_SECRET",
"CLIENT_TRAFFIC_SECRET_0",
],
[
None,
None,
"SERVER_HANDSHAKE_TRAFFIC_SECRET",
"SERVER_TRAFFIC_SECRET_0",
],
]
STREAM_FLAGS = 0x07
STREAM_COUNT_MAX = 0x1000000000000000
NetworkAddress = Any
# frame sizes
ACK_FRAME_CAPACITY = 64 # FIXME: this is arbitrary!
+ APPLICATION_CLOSE_FRAME_CAPACITY = 1 + 2 * UINT_VAR_MAX_SIZE # + reason length
- APPLICATION_CLOSE_FRAME_CAPACITY = 1 + 8 + 8 # + reason length
+ CONNECTION_LIMIT_FRAME_CAPACITY = 1 + UINT_VAR_MAX_SIZE
- CONNECTION_LIMIT_FRAME_CAPACITY = 1 + 8
HANDSHAKE_DONE_FRAME_CAPACITY = 1
+ MAX_STREAM_DATA_FRAME_CAPACITY = 1 + 2 * UINT_VAR_MAX_SIZE
- MAX_STREAM_DATA_FRAME_CAPACITY = 1 + 8 + 8
NEW_CONNECTION_ID_FRAME_CAPACITY = (
+ 1 + 2 * UINT_VAR_MAX_SIZE + 1 + CONNECTION_ID_MAX_SIZE + STATELESS_RESET_TOKEN_SIZE
- 1 + 8 + 8 + 1 + CONNECTION_ID_MAX_SIZE + STATELESS_RESET_TOKEN_SIZE
)
PATH_CHALLENGE_FRAME_CAPACITY = 1 + 8
PATH_RESPONSE_FRAME_CAPACITY = 1 + 8
PING_</s>
===========changed ref 3===========
# module: aioquic.quic.connection
# offset: 1
<s>_CHALLENGE_FRAME_CAPACITY = 1 + 8
PATH_RESPONSE_FRAME_CAPACITY = 1 + 8
PING_FRAME_CAPACITY = 1
+ RESET_STREAM_CAPACITY = 1 + 3 * UINT_VAR_MAX_SIZE
- RESET_STREAM_CAPACITY = 1 + 8 + 8 + 8
+ RETIRE_CONNECTION_ID_CAPACITY = 1 + UINT_VAR_MAX_SIZE
- RETIRE_CONNECTION_ID_CAPACITY = 1 + 8
+ STREAMS_BLOCKED_CAPACITY = 1 + UINT_VAR_MAX_SIZE
- STREAMS_BLOCKED_CAPACITY = 1 + 8
+ TRANSPORT_CLOSE_FRAME_CAPACITY = 1 + 3 * UINT_VAR_MAX_SIZE # + reason length
- TRANSPORT_CLOSE_FRAME_CAPACITY = 1 + 8 + 8 + 8 # + reason length
|
aioquic.h3.connection/H3Stream.__init__
|
Modified
|
aiortc~aioquic
|
59134f3e6ff40a26209f9c78ee01df242d5a3883
|
[web transport] add initial code for WebTransport support (#204)
|
<9>:<add> self.session_id: Optional[int] = None
|
# module: aioquic.h3.connection
class H3Stream:
def __init__(self, stream_id: int) -> None:
<0> self.blocked = False
<1> self.blocked_frame_size: Optional[int] = None
<2> self.buffer = b""
<3> self.ended = False
<4> self.frame_size: Optional[int] = None
<5> self.frame_type: Optional[int] = None
<6> self.headers_recv_state: HeadersState = HeadersState.INITIAL
<7> self.headers_send_state: HeadersState = HeadersState.INITIAL
<8> self.push_id: Optional[int] = None
<9> self.stream_id = stream_id
<10> self.stream_type: Optional[int] = None
<11>
|
===========changed ref 0===========
# module: aioquic.h3.connection
class StreamType(IntEnum):
CONTROL = 0
PUSH = 1
QPACK_ENCODER = 2
QPACK_DECODER = 3
+ WEBTRANSPORT = 0x54
===========changed ref 1===========
# module: aioquic.h3.connection
class FrameType(IntEnum):
DATA = 0x0
HEADERS = 0x1
PRIORITY = 0x2
CANCEL_PUSH = 0x3
SETTINGS = 0x4
PUSH_PROMISE = 0x5
GOAWAY = 0x7
MAX_PUSH_ID = 0xD
DUPLICATE_PUSH = 0xE
+ WEBTRANSPORT_STREAM = 0x41
===========changed ref 2===========
# module: aioquic.h3.connection
class Setting(IntEnum):
QPACK_MAX_TABLE_CAPACITY = 0x1
SETTINGS_MAX_HEADER_LIST_SIZE = 0x6
QPACK_BLOCKED_STREAMS = 0x7
SETTINGS_NUM_PLACEHOLDERS = 0x9
+ H3_DATAGRAM = 0x276
+ SETTINGS_ENABLE_WEBTRANSPORT = 0x2B603742
# Dummy setting to check it is correctly ignored by the peer.
# https://tools.ietf.org/html/draft-ietf-quic-http-34#section-7.2.4.1
DUMMY = 0x21
===========changed ref 3===========
+ # module: tests.test_webtransport
+
+
===========changed ref 4===========
+ # module: tests.test_webtransport
+ QUIC_CONFIGURATION_OPTIONS = {
+ "alpn_protocols": H3_ALPN,
+ "max_datagram_frame_size": 65536,
+ }
+
===========changed ref 5===========
# module: aioquic.h3.events
+ @dataclass
+ class DatagramReceived(H3Event):
+ """
+ The DatagramReceived is fired whenever a datagram is received from the
+ the remote peer.
+ """
+
+ data: bytes
+ "The data which was received."
+
+ flow_id: int
+ "The ID of the flow the data was received for."
+
===========changed ref 6===========
# module: aioquic.h3.events
+ @dataclass
+ class WebTransportStreamDataReceived(H3Event):
+ """
+ The WebTransportStreamDataReceived is fired whenever data is received
+ for a WebTransport stream.
+ """
+
+ data: bytes
+ "The data which was received."
+
+ stream_id: int
+ "The ID of the stream the data was received for."
+
+ stream_ended: bool
+ "Whether the STREAM frame had the FIN bit set."
+
+ session_id: int
+ "The ID of the session the data was received for."
+
===========changed ref 7===========
+ # module: tests.test_webtransport
+ class WebTransportTest(TestCase):
+ def test_handle_datagram_truncated(self):
+ quic_server = FakeQuicConnection(
+ configuration=QuicConfiguration(is_client=False)
+ )
+ h3_server = H3Connection(quic_server)
+
+ # receive a datagram with a truncated session ID
+ h3_server.handle_event(DatagramFrameReceived(data=b"\xff"))
+ self.assertEqual(
+ quic_server.closed,
+ (
+ ErrorCode.H3_GENERAL_PROTOCOL_ERROR,
+ "Could not parse flow ID",
+ ),
+ )
+
===========changed ref 8===========
+ # module: tests.test_webtransport
+ class WebTransportTest(TestCase):
+ def test_datagram(self):
+ with h3_client_and_server(QUIC_CONFIGURATION_OPTIONS) as (
+ quic_client,
+ quic_server,
+ ):
+ h3_client = H3Connection(quic_client, enable_webtransport=True)
+ h3_server = H3Connection(quic_server, enable_webtransport=True)
+
+ # create session
+ session_id = self._make_session(h3_client, h3_server)
+
+ # send datagram
+ h3_client.send_datagram(data=b"foo", flow_id=session_id)
+
+ # receive datagram
+ events = h3_transfer(quic_client, h3_server)
+ self.assertEqual(
+ events,
+ [DatagramReceived(data=b"foo", flow_id=session_id)],
+ )
+
===========changed ref 9===========
# module: tests.test_h3
class H3ConnectionTest(TestCase):
+ def test_validate_settings_h3_datagram_invalid_value(self):
+ quic_server = FakeQuicConnection(
+ configuration=QuicConfiguration(is_client=False)
+ )
+ h3_server = H3Connection(quic_server)
+
+ # receive SETTINGS with an invalid H3_DATAGRAM value
+ settings = copy.copy(DUMMY_SETTINGS)
+ settings[Setting.H3_DATAGRAM] = 2
+ h3_server.handle_event(
+ StreamDataReceived(
+ stream_id=2,
+ data=encode_uint_var(StreamType.CONTROL)
+ + encode_frame(FrameType.SETTINGS, encode_settings(settings)),
+ end_stream=False,
+ )
+ )
+ self.assertEqual(
+ quic_server.closed,
+ (
+ ErrorCode.H3_SETTINGS_ERROR,
+ "H3_DATAGRAM setting must be 0 or 1",
+ ),
+ )
+
===========changed ref 10===========
# module: tests.test_h3
class H3ConnectionTest(TestCase):
+ def test_validate_settings_enable_webtransport_invalid_value(self):
+ quic_server = FakeQuicConnection(
+ configuration=QuicConfiguration(is_client=False)
+ )
+ h3_server = H3Connection(quic_server)
+
+ # receive SETTINGS with an invalid SETTINGS_ENABLE_WEBTRANSPORT value
+ settings = copy.copy(DUMMY_SETTINGS)
+ settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 2
+ h3_server.handle_event(
+ StreamDataReceived(
+ stream_id=2,
+ data=encode_uint_var(StreamType.CONTROL)
+ + encode_frame(FrameType.SETTINGS, encode_settings(settings)),
+ end_stream=False,
+ )
+ )
+ self.assertEqual(
+ quic_server.closed,
+ (
+ ErrorCode.H3_SETTINGS_ERROR,
+ "SETTINGS_ENABLE_WEBTRANSPORT setting must be 0 or 1",
+ ),
+ )
+
===========changed ref 11===========
# module: tests.test_h3
class H3ConnectionTest(TestCase):
+ def test_validate_settings_enable_webtransport_without_h3_datagram(self):
+ quic_server = FakeQuicConnection(
+ configuration=QuicConfiguration(is_client=False)
+ )
+ h3_server = H3Connection(quic_server)
+
+ # receive SETTINGS requesting WebTransport, but DATAGRAM was not offered
+ settings = copy.copy(DUMMY_SETTINGS)
+ settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 1
+ h3_server.handle_event(
+ StreamDataReceived(
+ stream_id=2,
+ data=encode_uint_var(StreamType.CONTROL)
+ + encode_frame(FrameType.SETTINGS, encode_settings(settings)),
+ end_stream=False,
+ )
+ )
+ self.assertEqual(
+ quic_server.closed,
+ (
+ ErrorCode.H3_SETTINGS_ERROR,
+ "SETTINGS_ENABLE_WEBTRANSPORT requires H3_DATAGRAM",
+ ),
+ )
+
|
aioquic.h3.connection/H3Connection.__init__
|
Modified
|
aiortc~aioquic
|
59134f3e6ff40a26209f9c78ee01df242d5a3883
|
[web transport] add initial code for WebTransport support (#204)
|
<0>:<add> # settings
<2>:<add> self._enable_webtransport = enable_webtransport
|
# module: aioquic.h3.connection
class H3Connection:
+ def __init__(self, quic: QuicConnection, enable_webtransport: bool = False) -> None:
- def __init__(self, quic: QuicConnection):
<0> self._max_table_capacity = 4096
<1> self._blocked_streams = 16
<2>
<3> self._is_client = quic.configuration.is_client
<4> self._is_done = False
<5> self._quic = quic
<6> self._quic_logger: Optional[QuicLoggerTrace] = quic._quic_logger
<7> self._decoder = pylsqpack.Decoder(
<8> self._max_table_capacity, self._blocked_streams
<9> )
<10> self._decoder_bytes_received = 0
<11> self._decoder_bytes_sent = 0
<12> self._encoder = pylsqpack.Encoder()
<13> self._encoder_bytes_received = 0
<14> self._encoder_bytes_sent = 0
<15> self._settings_received = False
<16> self._stream: Dict[int, H3Stream] = {}
<17>
<18> self._max_push_id: Optional[int] = 8 if self._is_client else None
<19> self._next_push_id: int = 0
<20>
<21> self._local_control_stream_id: Optional[int] = None
<22> self._local_decoder_stream_id: Optional[int] = None
<23> self._local_encoder_stream_id: Optional[int] = None
<24>
<25> self._peer_control_stream_id: Optional[int] = None
<26> self._peer_decoder_stream_id: Optional[int] = None
<27> self._peer_encoder_stream_id: Optional[int] = None
<28>
<29> self._init_connection()
<30>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
H3Stream(stream_id: int)
at: aioquic.h3.connection.H3Connection._decode_headers
self._decoder_bytes_sent += len(decoder)
at: aioquic.h3.connection.H3Connection._encode_headers
self._encoder_bytes_sent += len(encoder)
at: aioquic.h3.connection.H3Connection._handle_control_frame
self._settings_received = True
self._max_push_id = parse_max_push_id(frame_data)
at: aioquic.h3.connection.H3Connection._receive_stream_data_uni
self._decoder_bytes_received += len(data)
self._encoder_bytes_received += len(data)
at: aioquic.h3.connection.H3Connection.handle_event
self._is_done = True
at: aioquic.h3.connection.H3Connection.send_push_promise
self._next_push_id += 1
at: tests.test_h3.FakeQuicConnection.__init__
self.configuration = configuration
self._quic_logger = QuicLogger().start_trace(
is_client=configuration.is_client, odcid=b""
)
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: aioquic.h3.connection
class H3Stream:
def __init__(self, stream_id: int) -> None:
self.blocked = False
self.blocked_frame_size: Optional[int] = None
self.buffer = b""
self.ended = False
self.frame_size: Optional[int] = None
self.frame_type: Optional[int] = None
self.headers_recv_state: HeadersState = HeadersState.INITIAL
self.headers_send_state: HeadersState = HeadersState.INITIAL
self.push_id: Optional[int] = None
+ self.session_id: Optional[int] = None
self.stream_id = stream_id
self.stream_type: Optional[int] = None
===========changed ref 1===========
# module: aioquic.h3.connection
class StreamType(IntEnum):
CONTROL = 0
PUSH = 1
QPACK_ENCODER = 2
QPACK_DECODER = 3
+ WEBTRANSPORT = 0x54
===========changed ref 2===========
# module: aioquic.h3.connection
class FrameType(IntEnum):
DATA = 0x0
HEADERS = 0x1
PRIORITY = 0x2
CANCEL_PUSH = 0x3
SETTINGS = 0x4
PUSH_PROMISE = 0x5
GOAWAY = 0x7
MAX_PUSH_ID = 0xD
DUPLICATE_PUSH = 0xE
+ WEBTRANSPORT_STREAM = 0x41
===========changed ref 3===========
# module: aioquic.h3.connection
class Setting(IntEnum):
QPACK_MAX_TABLE_CAPACITY = 0x1
SETTINGS_MAX_HEADER_LIST_SIZE = 0x6
QPACK_BLOCKED_STREAMS = 0x7
SETTINGS_NUM_PLACEHOLDERS = 0x9
+ H3_DATAGRAM = 0x276
+ SETTINGS_ENABLE_WEBTRANSPORT = 0x2B603742
# Dummy setting to check it is correctly ignored by the peer.
# https://tools.ietf.org/html/draft-ietf-quic-http-34#section-7.2.4.1
DUMMY = 0x21
===========changed ref 4===========
+ # module: tests.test_webtransport
+
+
===========changed ref 5===========
+ # module: tests.test_webtransport
+ QUIC_CONFIGURATION_OPTIONS = {
+ "alpn_protocols": H3_ALPN,
+ "max_datagram_frame_size": 65536,
+ }
+
===========changed ref 6===========
# module: aioquic.h3.events
+ @dataclass
+ class DatagramReceived(H3Event):
+ """
+ The DatagramReceived is fired whenever a datagram is received from the
+ the remote peer.
+ """
+
+ data: bytes
+ "The data which was received."
+
+ flow_id: int
+ "The ID of the flow the data was received for."
+
===========changed ref 7===========
# module: aioquic.h3.events
+ @dataclass
+ class WebTransportStreamDataReceived(H3Event):
+ """
+ The WebTransportStreamDataReceived is fired whenever data is received
+ for a WebTransport stream.
+ """
+
+ data: bytes
+ "The data which was received."
+
+ stream_id: int
+ "The ID of the stream the data was received for."
+
+ stream_ended: bool
+ "Whether the STREAM frame had the FIN bit set."
+
+ session_id: int
+ "The ID of the session the data was received for."
+
===========changed ref 8===========
+ # module: tests.test_webtransport
+ class WebTransportTest(TestCase):
+ def test_handle_datagram_truncated(self):
+ quic_server = FakeQuicConnection(
+ configuration=QuicConfiguration(is_client=False)
+ )
+ h3_server = H3Connection(quic_server)
+
+ # receive a datagram with a truncated session ID
+ h3_server.handle_event(DatagramFrameReceived(data=b"\xff"))
+ self.assertEqual(
+ quic_server.closed,
+ (
+ ErrorCode.H3_GENERAL_PROTOCOL_ERROR,
+ "Could not parse flow ID",
+ ),
+ )
+
===========changed ref 9===========
+ # module: tests.test_webtransport
+ class WebTransportTest(TestCase):
+ def test_datagram(self):
+ with h3_client_and_server(QUIC_CONFIGURATION_OPTIONS) as (
+ quic_client,
+ quic_server,
+ ):
+ h3_client = H3Connection(quic_client, enable_webtransport=True)
+ h3_server = H3Connection(quic_server, enable_webtransport=True)
+
+ # create session
+ session_id = self._make_session(h3_client, h3_server)
+
+ # send datagram
+ h3_client.send_datagram(data=b"foo", flow_id=session_id)
+
+ # receive datagram
+ events = h3_transfer(quic_client, h3_server)
+ self.assertEqual(
+ events,
+ [DatagramReceived(data=b"foo", flow_id=session_id)],
+ )
+
===========changed ref 10===========
# module: tests.test_h3
class H3ConnectionTest(TestCase):
+ def test_validate_settings_h3_datagram_invalid_value(self):
+ quic_server = FakeQuicConnection(
+ configuration=QuicConfiguration(is_client=False)
+ )
+ h3_server = H3Connection(quic_server)
+
+ # receive SETTINGS with an invalid H3_DATAGRAM value
+ settings = copy.copy(DUMMY_SETTINGS)
+ settings[Setting.H3_DATAGRAM] = 2
+ h3_server.handle_event(
+ StreamDataReceived(
+ stream_id=2,
+ data=encode_uint_var(StreamType.CONTROL)
+ + encode_frame(FrameType.SETTINGS, encode_settings(settings)),
+ end_stream=False,
+ )
+ )
+ self.assertEqual(
+ quic_server.closed,
+ (
+ ErrorCode.H3_SETTINGS_ERROR,
+ "H3_DATAGRAM setting must be 0 or 1",
+ ),
+ )
+
|
aioquic.h3.connection/H3Connection.handle_event
|
Modified
|
aiortc~aioquic
|
59134f3e6ff40a26209f9c78ee01df242d5a3883
|
[web transport] add initial code for WebTransport support (#204)
|
<5>:<del> if isinstance(event, StreamDataReceived) and not self._is_done:
<6>:<del> stream_id = event.stream_id
<7>:<del> stream = self._get_or_create_stream(stream_id)
<8>:<add>
<add> if not self._is_done:
<9>:<add> if isinstance(event, StreamDataReceived):
<add> stream_id = event.stream_id
<add> stream = self._get_or_create_stream(stream_id)
<add> if stream_id % 4 == 0:
<del> if stream_id % 4 == 0:
<10>:<add> return self._receive_request_or_push_data(
<del> return self._receive_request_or_push_data(
<11>:<add> stream, event.data, event.end_stream
<del> stream, event.data, event.end_stream
<12>:<add> )
<del> )
<13>:<add> elif stream_is_unidirectional(stream_id):
<del> elif stream_is_unidirectional(stream_id):
<14>:<add> return self._receive_stream_data_uni(
<del> return self._receive_stream_data_uni(
<15>:<add> stream, event.data, event.end_stream
<del> stream, event.data, event.end_stream
<16>:<add> )
<del> )
<17>:<add> elif isinstance(event, DatagramFrameReceived):
<add> return self._receive_datagram(event.data)
<22>:<add>
|
# module: aioquic.h3.connection
class H3Connection:
def handle_event(self, event: QuicEvent) -> List[H3Event]:
<0> """
<1> Handle a QUIC event and return a list of HTTP events.
<2>
<3> :param event: The QUIC event to handle.
<4> """
<5> if isinstance(event, StreamDataReceived) and not self._is_done:
<6> stream_id = event.stream_id
<7> stream = self._get_or_create_stream(stream_id)
<8> try:
<9> if stream_id % 4 == 0:
<10> return self._receive_request_or_push_data(
<11> stream, event.data, event.end_stream
<12> )
<13> elif stream_is_unidirectional(stream_id):
<14> return self._receive_stream_data_uni(
<15> stream, event.data, event.end_stream
<16> )
<17> except ProtocolError as exc:
<18> self._is_done = True
<19> self._quic.close(
<20> error_code=exc.error_code, reason_phrase=exc.reason_phrase
<21> )
<22> return []
<23>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
StreamType(x: Union[str, bytes, bytearray], base: int)
at: aioquic.h3.connection.H3Connection
_create_uni_stream(stream_type: int) -> int
_create_uni_stream(self, stream_type: int) -> int
_init_connection(self) -> None
_init_connection() -> None
at: aioquic.h3.connection.H3Connection.__init__
self._quic = quic
at: aioquic.h3.connection.H3Connection._init_connection
self._local_encoder_stream_id = self._create_uni_stream(
StreamType.QPACK_ENCODER
)
self._local_decoder_stream_id = self._create_uni_stream(
StreamType.QPACK_DECODER
)
at: aioquic.h3.connection.H3Connection._receive_stream_data_uni
self._peer_control_stream_id = stream.stream_id
self._peer_decoder_stream_id = stream.stream_id
self._peer_encoder_stream_id = stream.stream_id
at: tests.test_h3.FakeQuicConnection
get_next_available_stream_id(is_unidirectional=False)
send_stream_data(stream_id, data, end_stream=False)
===========changed ref 0===========
# module: aioquic.h3.connection
class StreamType(IntEnum):
CONTROL = 0
PUSH = 1
QPACK_ENCODER = 2
QPACK_DECODER = 3
+ WEBTRANSPORT = 0x54
===========changed ref 1===========
# module: aioquic.h3.connection
class H3Stream:
def __init__(self, stream_id: int) -> None:
self.blocked = False
self.blocked_frame_size: Optional[int] = None
self.buffer = b""
self.ended = False
self.frame_size: Optional[int] = None
self.frame_type: Optional[int] = None
self.headers_recv_state: HeadersState = HeadersState.INITIAL
self.headers_send_state: HeadersState = HeadersState.INITIAL
self.push_id: Optional[int] = None
+ self.session_id: Optional[int] = None
self.stream_id = stream_id
self.stream_type: Optional[int] = None
===========changed ref 2===========
# module: aioquic.h3.connection
class H3Connection:
+ def __init__(self, quic: QuicConnection, enable_webtransport: bool = False) -> None:
- def __init__(self, quic: QuicConnection):
+ # settings
self._max_table_capacity = 4096
self._blocked_streams = 16
+ self._enable_webtransport = enable_webtransport
self._is_client = quic.configuration.is_client
self._is_done = False
self._quic = quic
self._quic_logger: Optional[QuicLoggerTrace] = quic._quic_logger
self._decoder = pylsqpack.Decoder(
self._max_table_capacity, self._blocked_streams
)
self._decoder_bytes_received = 0
self._decoder_bytes_sent = 0
self._encoder = pylsqpack.Encoder()
self._encoder_bytes_received = 0
self._encoder_bytes_sent = 0
self._settings_received = False
self._stream: Dict[int, H3Stream] = {}
self._max_push_id: Optional[int] = 8 if self._is_client else None
self._next_push_id: int = 0
self._local_control_stream_id: Optional[int] = None
self._local_decoder_stream_id: Optional[int] = None
self._local_encoder_stream_id: Optional[int] = None
self._peer_control_stream_id: Optional[int] = None
self._peer_decoder_stream_id: Optional[int] = None
self._peer_encoder_stream_id: Optional[int] = None
self._init_connection()
===========changed ref 3===========
# module: aioquic.h3.connection
class FrameType(IntEnum):
DATA = 0x0
HEADERS = 0x1
PRIORITY = 0x2
CANCEL_PUSH = 0x3
SETTINGS = 0x4
PUSH_PROMISE = 0x5
GOAWAY = 0x7
MAX_PUSH_ID = 0xD
DUPLICATE_PUSH = 0xE
+ WEBTRANSPORT_STREAM = 0x41
===========changed ref 4===========
# module: aioquic.h3.connection
class Setting(IntEnum):
QPACK_MAX_TABLE_CAPACITY = 0x1
SETTINGS_MAX_HEADER_LIST_SIZE = 0x6
QPACK_BLOCKED_STREAMS = 0x7
SETTINGS_NUM_PLACEHOLDERS = 0x9
+ H3_DATAGRAM = 0x276
+ SETTINGS_ENABLE_WEBTRANSPORT = 0x2B603742
# Dummy setting to check it is correctly ignored by the peer.
# https://tools.ietf.org/html/draft-ietf-quic-http-34#section-7.2.4.1
DUMMY = 0x21
===========changed ref 5===========
+ # module: tests.test_webtransport
+
+
===========changed ref 6===========
+ # module: tests.test_webtransport
+ QUIC_CONFIGURATION_OPTIONS = {
+ "alpn_protocols": H3_ALPN,
+ "max_datagram_frame_size": 65536,
+ }
+
===========changed ref 7===========
# module: aioquic.h3.events
+ @dataclass
+ class DatagramReceived(H3Event):
+ """
+ The DatagramReceived is fired whenever a datagram is received from the
+ the remote peer.
+ """
+
+ data: bytes
+ "The data which was received."
+
+ flow_id: int
+ "The ID of the flow the data was received for."
+
===========changed ref 8===========
# module: aioquic.h3.events
+ @dataclass
+ class WebTransportStreamDataReceived(H3Event):
+ """
+ The WebTransportStreamDataReceived is fired whenever data is received
+ for a WebTransport stream.
+ """
+
+ data: bytes
+ "The data which was received."
+
+ stream_id: int
+ "The ID of the stream the data was received for."
+
+ stream_ended: bool
+ "Whether the STREAM frame had the FIN bit set."
+
+ session_id: int
+ "The ID of the session the data was received for."
+
===========changed ref 9===========
+ # module: tests.test_webtransport
+ class WebTransportTest(TestCase):
+ def test_handle_datagram_truncated(self):
+ quic_server = FakeQuicConnection(
+ configuration=QuicConfiguration(is_client=False)
+ )
+ h3_server = H3Connection(quic_server)
+
+ # receive a datagram with a truncated session ID
+ h3_server.handle_event(DatagramFrameReceived(data=b"\xff"))
+ self.assertEqual(
+ quic_server.closed,
+ (
+ ErrorCode.H3_GENERAL_PROTOCOL_ERROR,
+ "Could not parse flow ID",
+ ),
+ )
+
|
aioquic.h3.connection/H3Connection._handle_control_frame
|
Modified
|
aiortc~aioquic
|
59134f3e6ff40a26209f9c78ee01df242d5a3883
|
[web transport] add initial code for WebTransport support (#204)
|
<10>:<add> self._validate_settings(settings)
|
# module: aioquic.h3.connection
class H3Connection:
def _handle_control_frame(self, frame_type: int, frame_data: bytes) -> None:
<0> """
<1> Handle a frame received on the peer's control stream.
<2> """
<3> if frame_type != FrameType.SETTINGS and not self._settings_received:
<4> raise MissingSettingsError
<5>
<6> if frame_type == FrameType.SETTINGS:
<7> if self._settings_received:
<8> raise FrameUnexpected("SETTINGS have already been received")
<9> settings = parse_settings(frame_data)
<10> encoder = self._encoder.apply_settings(
<11> max_table_capacity=settings.get(Setting.QPACK_MAX_TABLE_CAPACITY, 0),
<12> blocked_streams=settings.get(Setting.QPACK_BLOCKED_STREAMS, 0),
<13> )
<14> self._quic.send_stream_data(self._local_encoder_stream_id, encoder)
<15> self._settings_received = True
<16> elif frame_type == FrameType.MAX_PUSH_ID:
<17> if self._is_client:
<18> raise FrameUnexpected("Servers must not send MAX_PUSH_ID")
<19> self._max_push_id = parse_max_push_id(frame_data)
<20> elif frame_type in (
<21> FrameType.DATA,
<22> FrameType.HEADERS,
<23> FrameType.PUSH_PROMISE,
<24> FrameType.DUPLICATE_PUSH,
<25> ):
<26> raise FrameUnexpected("Invalid frame type on control stream")
<27>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
FrameType(x: Union[str, bytes, bytearray], base: int)
FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QpackDecompressionFailed(reason_phrase: str="")
encode_frame(frame_type: int, frame_data: bytes) -> bytes
at: aioquic.h3.connection.H3Connection.__init__
self._quic = quic
self._decoder = pylsqpack.Decoder(
self._max_table_capacity, self._blocked_streams
)
self._decoder_bytes_sent = 0
self._local_decoder_stream_id: Optional[int] = None
at: aioquic.h3.connection.H3Connection._init_connection
self._local_decoder_stream_id = self._create_uni_stream(
StreamType.QPACK_DECODER
)
at: aioquic.h3.connection.H3Connection.send_headers
frame_data = self._encode_headers(stream_id, headers)
at: tests.test_h3.FakeQuicConnection
get_next_available_stream_id(is_unidirectional=False)
send_stream_data(stream_id, data, end_stream=False)
===========changed ref 0===========
# module: aioquic.h3.connection
class FrameType(IntEnum):
DATA = 0x0
HEADERS = 0x1
PRIORITY = 0x2
CANCEL_PUSH = 0x3
SETTINGS = 0x4
PUSH_PROMISE = 0x5
GOAWAY = 0x7
MAX_PUSH_ID = 0xD
DUPLICATE_PUSH = 0xE
+ WEBTRANSPORT_STREAM = 0x41
===========changed ref 1===========
# module: aioquic.h3.connection
class H3Connection:
+ def send_datagram(self, flow_id: int, data: bytes) -> None:
+ """
+ Send a datagram for the specified flow.
+
+ :param flow_id: The flow ID.
+ :param data: The HTTP/3 datagram payload.
+ """
+ self._quic.send_datagram_frame(encode_uint_var(flow_id) + data)
+
===========changed ref 2===========
# module: aioquic.h3.connection
class H3Connection:
+ def create_webtransport_stream(
+ self, session_id: int, is_unidirectional: bool = False
+ ) -> int:
+ """
+ Create a WebTransport stream and return the stream ID.
+
+ :param session_id: The WebTransport session identifier.
+ :param is_unidirectional: Whether to create a unidirectional stream.
+ """
+ if is_unidirectional:
+ stream_id = self._create_uni_stream(StreamType.WEBTRANSPORT)
+ self._quic.send_stream_data(stream_id, encode_uint_var(session_id))
+ else:
+ stream_id = self._quic.get_next_available_stream_id()
+ self._quic.send_stream_data(
+ stream_id,
+ encode_uint_var(FrameType.WEBTRANSPORT_STREAM)
+ + encode_uint_var(session_id),
+ )
+ return stream_id
+
===========changed ref 3===========
# module: aioquic.h3.connection
class H3Stream:
def __init__(self, stream_id: int) -> None:
self.blocked = False
self.blocked_frame_size: Optional[int] = None
self.buffer = b""
self.ended = False
self.frame_size: Optional[int] = None
self.frame_type: Optional[int] = None
self.headers_recv_state: HeadersState = HeadersState.INITIAL
self.headers_send_state: HeadersState = HeadersState.INITIAL
self.push_id: Optional[int] = None
+ self.session_id: Optional[int] = None
self.stream_id = stream_id
self.stream_type: Optional[int] = None
===========changed ref 4===========
# module: aioquic.h3.connection
class StreamType(IntEnum):
CONTROL = 0
PUSH = 1
QPACK_ENCODER = 2
QPACK_DECODER = 3
+ WEBTRANSPORT = 0x54
===========changed ref 5===========
# module: aioquic.h3.connection
class H3Connection:
+ def __init__(self, quic: QuicConnection, enable_webtransport: bool = False) -> None:
- def __init__(self, quic: QuicConnection):
+ # settings
self._max_table_capacity = 4096
self._blocked_streams = 16
+ self._enable_webtransport = enable_webtransport
self._is_client = quic.configuration.is_client
self._is_done = False
self._quic = quic
self._quic_logger: Optional[QuicLoggerTrace] = quic._quic_logger
self._decoder = pylsqpack.Decoder(
self._max_table_capacity, self._blocked_streams
)
self._decoder_bytes_received = 0
self._decoder_bytes_sent = 0
self._encoder = pylsqpack.Encoder()
self._encoder_bytes_received = 0
self._encoder_bytes_sent = 0
self._settings_received = False
self._stream: Dict[int, H3Stream] = {}
self._max_push_id: Optional[int] = 8 if self._is_client else None
self._next_push_id: int = 0
self._local_control_stream_id: Optional[int] = None
self._local_decoder_stream_id: Optional[int] = None
self._local_encoder_stream_id: Optional[int] = None
self._peer_control_stream_id: Optional[int] = None
self._peer_decoder_stream_id: Optional[int] = None
self._peer_encoder_stream_id: Optional[int] = None
self._init_connection()
===========changed ref 6===========
# module: aioquic.h3.connection
class H3Connection:
def handle_event(self, event: QuicEvent) -> List[H3Event]:
"""
Handle a QUIC event and return a list of HTTP events.
:param event: The QUIC event to handle.
"""
- if isinstance(event, StreamDataReceived) and not self._is_done:
- stream_id = event.stream_id
- stream = self._get_or_create_stream(stream_id)
+
+ if not self._is_done:
try:
+ if isinstance(event, StreamDataReceived):
+ stream_id = event.stream_id
+ stream = self._get_or_create_stream(stream_id)
+ if stream_id % 4 == 0:
- if stream_id % 4 == 0:
+ return self._receive_request_or_push_data(
- return self._receive_request_or_push_data(
+ stream, event.data, event.end_stream
- stream, event.data, event.end_stream
+ )
- )
+ elif stream_is_unidirectional(stream_id):
- elif stream_is_unidirectional(stream_id):
+ return self._receive_stream_data_uni(
- return self._receive_stream_data_uni(
+ stream, event.data, event.end_stream
- stream, event.data, event.end_stream
+ )
- )
+ elif isinstance(event, DatagramFrameReceived):
+ return self._receive_datagram(event.data)
except ProtocolError as exc:
self._is_done = True
self._quic.close(
error_code=exc.error_code, reason_phrase=exc.reason_phrase
)
+
return []
|
aioquic.h3.connection/H3Connection._handle_request_or_push_frame
|
Modified
|
aiortc~aioquic
|
59134f3e6ff40a26209f9c78ee01df242d5a3883
|
[web transport] add initial code for WebTransport support (#204)
|
# module: aioquic.h3.connection
class H3Connection:
def _handle_request_or_push_frame(
self,
frame_type: int,
frame_data: Optional[bytes],
stream: H3Stream,
stream_ended: bool,
) -> List[H3Event]:
<0> """
<1> Handle a frame received on a request or push stream.
<2> """
<3> http_events: List[H3Event] = []
<4>
<5> if frame_type == FrameType.DATA:
<6> # check DATA frame is allowed
<7> if stream.headers_recv_state != HeadersState.AFTER_HEADERS:
<8> raise FrameUnexpected("DATA frame is not allowed in this state")
<9>
<10> if stream_ended or frame_data:
<11> http_events.append(
<12> DataReceived(
<13> data=frame_data,
<14> push_id=stream.push_id,
<15> stream_ended=stream_ended,
<16> stream_id=stream.stream_id,
<17> )
<18> )
<19> elif frame_type == FrameType.HEADERS:
<20> # check HEADERS frame is allowed
<21> if stream.headers_recv_state == HeadersState.AFTER_TRAILERS:
<22> raise FrameUnexpected("HEADERS frame is not allowed in this state")
<23>
<24> # try to decode HEADERS, may raise pylsqpack.StreamBlocked
<25> headers = self._decode_headers(stream.stream_id, frame_data)
<26>
<27> # validate headers
<28> if stream.headers_recv_state == HeadersState.INITIAL:
<29> if self._is_client:
<30> validate_response_headers(headers)
<31> else:
<32> validate_request_headers(headers)
<33> else:
<34> validate_trailers(headers)
<35>
<36> # log frame
<37> if self._quic_logger is not None:
<38> self._quic_logger.log_event(
<39> category="http",
<40> event="frame_parsed",
<41> data=qlog_encode_headers_frame(
<42> byte_length=stream</s>
|
===========below chunk 0===========
# module: aioquic.h3.connection
class H3Connection:
def _handle_request_or_push_frame(
self,
frame_type: int,
frame_data: Optional[bytes],
stream: H3Stream,
stream_ended: bool,
) -> List[H3Event]:
# offset: 1
if frame_data is None
else len(frame_data),
headers=headers,
stream_id=stream.stream_id,
),
)
# update state and emit headers
if stream.headers_recv_state == HeadersState.INITIAL:
stream.headers_recv_state = HeadersState.AFTER_HEADERS
else:
stream.headers_recv_state = HeadersState.AFTER_TRAILERS
http_events.append(
HeadersReceived(
headers=headers,
push_id=stream.push_id,
stream_id=stream.stream_id,
stream_ended=stream_ended,
)
)
elif stream.frame_type == FrameType.PUSH_PROMISE and stream.push_id is None:
if not self._is_client:
raise FrameUnexpected("Clients must not send PUSH_PROMISE")
frame_buf = Buffer(data=frame_data)
push_id = frame_buf.pull_uint_var()
headers = self._decode_headers(
stream.stream_id, frame_data[frame_buf.tell() :]
)
# validate headers
validate_push_promise_headers(headers)
# log frame
if self._quic_logger is not None:
self._quic_logger.log_event(
category="http",
event="frame_parsed",
data=qlog_encode_push_promise_frame(
byte_length=len(frame_data),
headers=headers,
push_id=push_id,
stream_id=stream.stream_id,
),
)
# emit event
http_events.append(
PushPromiseReceived(
</s>
===========below chunk 1===========
# module: aioquic.h3.connection
class H3Connection:
def _handle_request_or_push_frame(
self,
frame_type: int,
frame_data: Optional[bytes],
stream: H3Stream,
stream_ended: bool,
) -> List[H3Event]:
# offset: 2
<s>id,
),
)
# emit event
http_events.append(
PushPromiseReceived(
headers=headers, push_id=push_id, stream_id=stream.stream_id
)
)
elif frame_type in (
FrameType.PRIORITY,
FrameType.CANCEL_PUSH,
FrameType.SETTINGS,
FrameType.PUSH_PROMISE,
FrameType.GOAWAY,
FrameType.MAX_PUSH_ID,
FrameType.DUPLICATE_PUSH,
):
raise FrameUnexpected(
"Invalid frame type on request stream"
if stream.push_id is None
else "Invalid frame type on push stream"
)
return http_events
===========unchanged ref 0===========
at: aioquic.h3.connection
FrameType(x: Union[str, bytes, bytearray], base: int)
FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
HeadersState()
Setting(x: Union[str, bytes, bytearray], base: int)
Setting(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
FrameUnexpected(reason_phrase: str="")
MissingSettingsError(reason_phrase: str="")
parse_max_push_id(data: bytes) -> int
parse_settings(data: bytes) -> Dict[int, int]
qlog_encode_headers_frame(byte_length: int, headers: Headers, stream_id: int) -> Dict
validate_request_headers(headers: Headers) -> None
validate_response_headers(headers: Headers) -> None
validate_trailers(headers: Headers) -> None
H3Stream(stream_id: int)
at: aioquic.h3.connection.H3Connection
_decode_headers(stream_id: int, frame_data: Optional[bytes]) -> Headers
_decode_headers(self, stream_id: int, frame_data: Optional[bytes]) -> Headers
_validate_settings(settings: Dict[int, int]) -> None
at: aioquic.h3.connection.H3Connection.__init__
self._max_table_capacity = 4096
self._blocked_streams = 16
self._enable_webtransport = enable_webtransport
self._is_client = quic.configuration.is_client
self._quic = quic
self._quic_logger: Optional[QuicLoggerTrace] = quic._quic_logger
self._encoder = pylsqpack.Encoder()
self._encoder_bytes_sent = 0
self._settings_received = False
self._stream: Dict[int, H3Stream] = {}
===========unchanged ref 1===========
self._max_push_id: Optional[int] = 8 if self._is_client else None
self._local_encoder_stream_id: Optional[int] = None
at: aioquic.h3.connection.H3Connection._init_connection
self._local_encoder_stream_id = self._create_uni_stream(
StreamType.QPACK_ENCODER
)
at: aioquic.h3.connection.H3Stream.__init__
self.blocked_frame_size: Optional[int] = None
self.headers_recv_state: HeadersState = HeadersState.INITIAL
self.push_id: Optional[int] = None
self.stream_id = stream_id
at: tests.test_h3.FakeQuicConnection
send_stream_data(stream_id, data, end_stream=False)
at: typing
List = _alias(list, 1, inst=False, name='List')
Dict = _alias(dict, 2, inst=False, name='Dict')
at: typing.Mapping
get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]
get(key: _KT) -> Optional[_VT_co]
===========changed ref 0===========
# module: aioquic.h3.connection
class FrameType(IntEnum):
DATA = 0x0
HEADERS = 0x1
PRIORITY = 0x2
CANCEL_PUSH = 0x3
SETTINGS = 0x4
PUSH_PROMISE = 0x5
GOAWAY = 0x7
MAX_PUSH_ID = 0xD
DUPLICATE_PUSH = 0xE
+ WEBTRANSPORT_STREAM = 0x41
===========changed ref 1===========
# module: aioquic.h3.connection
class Setting(IntEnum):
QPACK_MAX_TABLE_CAPACITY = 0x1
SETTINGS_MAX_HEADER_LIST_SIZE = 0x6
QPACK_BLOCKED_STREAMS = 0x7
SETTINGS_NUM_PLACEHOLDERS = 0x9
+ H3_DATAGRAM = 0x276
+ SETTINGS_ENABLE_WEBTRANSPORT = 0x2B603742
# Dummy setting to check it is correctly ignored by the peer.
# https://tools.ietf.org/html/draft-ietf-quic-http-34#section-7.2.4.1
DUMMY = 0x21
|
|
aioquic.h3.connection/H3Connection._init_connection
|
Modified
|
aiortc~aioquic
|
59134f3e6ff40a26209f9c78ee01df242d5a3883
|
[web transport] add initial code for WebTransport support (#204)
|
<5>:<del> FrameType.SETTINGS,
<6>:<del> encode_settings(
<7>:<del> {
<8>:<del> Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity,
<9>:<del> Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams,
<10>:<del> Setting.DUMMY: 1,
<11>:<del> }
<12>:<del> ),
<13>:<add> FrameType.SETTINGS, encode_settings(self._get_local_settings())
|
# module: aioquic.h3.connection
class H3Connection:
def _init_connection(self) -> None:
<0> # send our settings
<1> self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL)
<2> self._quic.send_stream_data(
<3> self._local_control_stream_id,
<4> encode_frame(
<5> FrameType.SETTINGS,
<6> encode_settings(
<7> {
<8> Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity,
<9> Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams,
<10> Setting.DUMMY: 1,
<11> }
<12> ),
<13> ),
<14> )
<15> if self._is_client and self._max_push_id is not None:
<16> self._quic.send_stream_data(
<17> self._local_control_stream_id,
<18> encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)),
<19> )
<20>
<21> # create encoder and decoder streams
<22> self._local_encoder_stream_id = self._create_uni_stream(
<23> StreamType.QPACK_ENCODER
<24> )
<25> self._local_decoder_stream_id = self._create_uni_stream(
<26> StreamType.QPACK_DECODER
<27> )
<28>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
FrameType(x: Union[str, bytes, bytearray], base: int)
FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
HeadersState()
FrameUnexpected(reason_phrase: str="")
qlog_encode_push_promise_frame(byte_length: int, headers: Headers, push_id: int, stream_id: int) -> Dict
validate_push_promise_headers(headers: Headers) -> None
at: aioquic.h3.connection.H3Connection
_decode_headers(stream_id: int, frame_data: Optional[bytes]) -> Headers
_decode_headers(self, stream_id: int, frame_data: Optional[bytes]) -> Headers
at: aioquic.h3.connection.H3Connection.__init__
self._is_client = quic.configuration.is_client
self._quic_logger: Optional[QuicLoggerTrace] = quic._quic_logger
at: aioquic.h3.connection.H3Connection._handle_request_or_push_frame
http_events: List[H3Event] = []
at: aioquic.h3.connection.H3Stream.__init__
self.headers_recv_state: HeadersState = HeadersState.INITIAL
self.push_id: Optional[int] = None
self.stream_id = stream_id
===========changed ref 0===========
# module: aioquic.h3.connection
class FrameType(IntEnum):
DATA = 0x0
HEADERS = 0x1
PRIORITY = 0x2
CANCEL_PUSH = 0x3
SETTINGS = 0x4
PUSH_PROMISE = 0x5
GOAWAY = 0x7
MAX_PUSH_ID = 0xD
DUPLICATE_PUSH = 0xE
+ WEBTRANSPORT_STREAM = 0x41
===========changed ref 1===========
# module: aioquic.h3.connection
class H3Connection:
+ def _get_local_settings(self) -> Dict[int, int]:
+ """
+ Return the local HTTP/3 settings.
+ """
+ settings = {
+ Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity,
+ Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams,
+ Setting.DUMMY: 1,
+ }
+ if self._enable_webtransport:
+ settings[Setting.H3_DATAGRAM] = 1
+ settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 1
+ return settings
+
===========changed ref 2===========
# module: aioquic.h3.connection
class H3Connection:
+ def send_datagram(self, flow_id: int, data: bytes) -> None:
+ """
+ Send a datagram for the specified flow.
+
+ :param flow_id: The flow ID.
+ :param data: The HTTP/3 datagram payload.
+ """
+ self._quic.send_datagram_frame(encode_uint_var(flow_id) + data)
+
===========changed ref 3===========
# module: aioquic.h3.connection
class H3Connection:
def _handle_control_frame(self, frame_type: int, frame_data: bytes) -> None:
"""
Handle a frame received on the peer's control stream.
"""
if frame_type != FrameType.SETTINGS and not self._settings_received:
raise MissingSettingsError
if frame_type == FrameType.SETTINGS:
if self._settings_received:
raise FrameUnexpected("SETTINGS have already been received")
settings = parse_settings(frame_data)
+ self._validate_settings(settings)
encoder = self._encoder.apply_settings(
max_table_capacity=settings.get(Setting.QPACK_MAX_TABLE_CAPACITY, 0),
blocked_streams=settings.get(Setting.QPACK_BLOCKED_STREAMS, 0),
)
self._quic.send_stream_data(self._local_encoder_stream_id, encoder)
self._settings_received = True
elif frame_type == FrameType.MAX_PUSH_ID:
if self._is_client:
raise FrameUnexpected("Servers must not send MAX_PUSH_ID")
self._max_push_id = parse_max_push_id(frame_data)
elif frame_type in (
FrameType.DATA,
FrameType.HEADERS,
FrameType.PUSH_PROMISE,
FrameType.DUPLICATE_PUSH,
):
raise FrameUnexpected("Invalid frame type on control stream")
===========changed ref 4===========
# module: aioquic.h3.connection
class H3Connection:
+ def create_webtransport_stream(
+ self, session_id: int, is_unidirectional: bool = False
+ ) -> int:
+ """
+ Create a WebTransport stream and return the stream ID.
+
+ :param session_id: The WebTransport session identifier.
+ :param is_unidirectional: Whether to create a unidirectional stream.
+ """
+ if is_unidirectional:
+ stream_id = self._create_uni_stream(StreamType.WEBTRANSPORT)
+ self._quic.send_stream_data(stream_id, encode_uint_var(session_id))
+ else:
+ stream_id = self._quic.get_next_available_stream_id()
+ self._quic.send_stream_data(
+ stream_id,
+ encode_uint_var(FrameType.WEBTRANSPORT_STREAM)
+ + encode_uint_var(session_id),
+ )
+ return stream_id
+
===========changed ref 5===========
# module: aioquic.h3.connection
class H3Stream:
def __init__(self, stream_id: int) -> None:
self.blocked = False
self.blocked_frame_size: Optional[int] = None
self.buffer = b""
self.ended = False
self.frame_size: Optional[int] = None
self.frame_type: Optional[int] = None
self.headers_recv_state: HeadersState = HeadersState.INITIAL
self.headers_send_state: HeadersState = HeadersState.INITIAL
self.push_id: Optional[int] = None
+ self.session_id: Optional[int] = None
self.stream_id = stream_id
self.stream_type: Optional[int] = None
===========changed ref 6===========
# module: aioquic.h3.connection
class StreamType(IntEnum):
CONTROL = 0
PUSH = 1
QPACK_ENCODER = 2
QPACK_DECODER = 3
+ WEBTRANSPORT = 0x54
|
aioquic.h3.connection/H3Connection._receive_request_or_push_data
|
Modified
|
aiortc~aioquic
|
59134f3e6ff40a26209f9c78ee01df242d5a3883
|
[web transport] add initial code for WebTransport support (#204)
|
<9>:<add> return http_events
<add>
<add> # shortcut for WEBTRANSPORT_STREAM frame fragments
<add> if (
<add> stream.frame_type == FrameType.WEBTRANSPORT_STREAM
<add> and stream.session_id is not None
<add> ):
<add> http_events.append(
<add> WebTransportStreamDataReceived(
<add> data=stream.buffer,
<add> session_id=stream.session_id,
<add> stream_id=stream.stream_id,
<add> stream_ended=stream_ended,
<add> )
<add> )
<add> stream.buffer = b""
<54>:<add> # WEBTRANSPORT_STREAM frames last until the end of the stream
<add> if stream.frame_type == FrameType.WEBTRANSPORT_STREAM:
<add> stream.session_id = stream.frame_size
<add> stream.frame_size = None
|
# module: aioquic.h3.connection
class H3Connection:
def _receive_request_or_push_data(
self, stream: H3Stream, data: bytes, stream_ended: bool
) -> List[H3Event]:
<0> """
<1> Handle data received on a request or push stream.
<2> """
<3> http_events: List[H3Event] = []
<4>
<5> stream.buffer += data
<6> if stream_ended:
<7> stream.ended = True
<8> if stream.blocked:
<9> return http_events
<10>
<11> # shortcut for DATA frame fragments
<12> if (
<13> stream.frame_type == FrameType.DATA
<14> and stream.frame_size is not None
<15> and len(stream.buffer) < stream.frame_size
<16> ):
<17> http_events.append(
<18> DataReceived(
<19> data=stream.buffer,
<20> push_id=stream.push_id,
<21> stream_id=stream.stream_id,
<22> stream_ended=False,
<23> )
<24> )
<25> stream.frame_size -= len(stream.buffer)
<26> stream.buffer = b""
<27> return http_events
<28>
<29> # handle lone FIN
<30> if stream_ended and not stream.buffer:
<31> http_events.append(
<32> DataReceived(
<33> data=b"",
<34> push_id=stream.push_id,
<35> stream_id=stream.stream_id,
<36> stream_ended=True,
<37> )
<38> )
<39> return http_events
<40>
<41> buf = Buffer(data=stream.buffer)
<42> consumed = 0
<43>
<44> while not buf.eof():
<45> # fetch next frame header
<46> if stream.frame_size is None:
<47> try:
<48> stream.frame_type = buf.pull_uint_var()
<49> stream.frame_size = buf.pull_uint_var()
<50> except BufferReadError:
<51> break
<52> consumed = buf.tell()
<53>
<54> </s>
|
===========below chunk 0===========
# module: aioquic.h3.connection
class H3Connection:
def _receive_request_or_push_data(
self, stream: H3Stream, data: bytes, stream_ended: bool
) -> List[H3Event]:
# offset: 1
if (
self._quic_logger is not None
and stream.frame_type == FrameType.DATA
):
self._quic_logger.log_event(
category="http",
event="frame_parsed",
data=qlog_encode_data_frame(
byte_length=stream.frame_size, stream_id=stream.stream_id
),
)
# check how much data is available
chunk_size = min(stream.frame_size, buf.capacity - consumed)
if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size:
break
# read available data
frame_data = buf.pull_bytes(chunk_size)
consumed = buf.tell()
# detect end of frame
stream.frame_size -= chunk_size
if not stream.frame_size:
stream.frame_size = None
try:
http_events.extend(
self._handle_request_or_push_frame(
frame_type=stream.frame_type,
frame_data=frame_data,
stream=stream,
stream_ended=stream.ended and buf.eof(),
)
)
except pylsqpack.StreamBlocked:
stream.blocked = True
stream.blocked_frame_size = len(frame_data)
break
# remove processed data from buffer
stream.buffer = stream.buffer[consumed:]
return http_events
===========unchanged ref 0===========
at: aioquic.h3.connection
FrameType(x: Union[str, bytes, bytearray], base: int)
FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
StreamType(x: Union[str, bytes, bytearray], base: int)
ProtocolError(reason_phrase: str="")
FrameUnexpected(reason_phrase: str="")
encode_frame(frame_type: int, frame_data: bytes) -> bytes
encode_settings(settings: Dict[int, int]) -> bytes
H3Stream(stream_id: int)
at: aioquic.h3.connection.H3Connection
_create_uni_stream(stream_type: int) -> int
_create_uni_stream(self, stream_type: int) -> int
_get_local_settings(self) -> Dict[int, int]
_get_local_settings() -> Dict[int, int]
at: aioquic.h3.connection.H3Connection.__init__
self._is_client = quic.configuration.is_client
self._quic = quic
self._max_push_id: Optional[int] = 8 if self._is_client else None
self._local_control_stream_id: Optional[int] = None
self._local_decoder_stream_id: Optional[int] = None
self._local_encoder_stream_id: Optional[int] = None
at: aioquic.h3.connection.H3Connection._handle_control_frame
self._max_push_id = parse_max_push_id(frame_data)
at: aioquic.h3.connection.H3Connection._handle_request_or_push_frame
http_events: List[H3Event] = []
===========unchanged ref 1===========
headers = self._decode_headers(stream.stream_id, frame_data)
headers = self._decode_headers(
stream.stream_id, frame_data[frame_buf.tell() :]
)
push_id = frame_buf.pull_uint_var()
at: aioquic.h3.connection.H3Stream.__init__
self.blocked = False
self.buffer = b""
self.ended = False
self.frame_size: Optional[int] = None
self.frame_type: Optional[int] = None
self.push_id: Optional[int] = None
self.session_id: Optional[int] = None
self.stream_id = stream_id
at: tests.test_h3.FakeQuicConnection
send_stream_data(stream_id, data, end_stream=False)
at: typing
List = _alias(list, 1, inst=False, name='List')
===========changed ref 0===========
# module: aioquic.h3.connection
class H3Connection:
+ def _get_local_settings(self) -> Dict[int, int]:
+ """
+ Return the local HTTP/3 settings.
+ """
+ settings = {
+ Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity,
+ Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams,
+ Setting.DUMMY: 1,
+ }
+ if self._enable_webtransport:
+ settings[Setting.H3_DATAGRAM] = 1
+ settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 1
+ return settings
+
===========changed ref 1===========
# module: aioquic.h3.connection
class StreamType(IntEnum):
CONTROL = 0
PUSH = 1
QPACK_ENCODER = 2
QPACK_DECODER = 3
+ WEBTRANSPORT = 0x54
===========changed ref 2===========
# module: aioquic.h3.connection
class FrameType(IntEnum):
DATA = 0x0
HEADERS = 0x1
PRIORITY = 0x2
CANCEL_PUSH = 0x3
SETTINGS = 0x4
PUSH_PROMISE = 0x5
GOAWAY = 0x7
MAX_PUSH_ID = 0xD
DUPLICATE_PUSH = 0xE
+ WEBTRANSPORT_STREAM = 0x41
===========changed ref 3===========
# module: aioquic.h3.connection
class H3Connection:
def _init_connection(self) -> None:
# send our settings
self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL)
self._quic.send_stream_data(
self._local_control_stream_id,
encode_frame(
- FrameType.SETTINGS,
- encode_settings(
- {
- Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity,
- Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams,
- Setting.DUMMY: 1,
- }
- ),
+ FrameType.SETTINGS, encode_settings(self._get_local_settings())
),
)
if self._is_client and self._max_push_id is not None:
self._quic.send_stream_data(
self._local_control_stream_id,
encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)),
)
# create encoder and decoder streams
self._local_encoder_stream_id = self._create_uni_stream(
StreamType.QPACK_ENCODER
)
self._local_decoder_stream_id = self._create_uni_stream(
StreamType.QPACK_DECODER
)
===========changed ref 4===========
# module: aioquic.h3.connection
class H3Connection:
+ def send_datagram(self, flow_id: int, data: bytes) -> None:
+ """
+ Send a datagram for the specified flow.
+
+ :param flow_id: The flow ID.
+ :param data: The HTTP/3 datagram payload.
+ """
+ self._quic.send_datagram_frame(encode_uint_var(flow_id) + data)
+
|
aioquic.h3.connection/H3Connection._receive_stream_data_uni
|
Modified
|
aiortc~aioquic
|
59134f3e6ff40a26209f9c78ee01df242d5a3883
|
[web transport] add initial code for WebTransport support (#204)
|
<11>:<add> stream.stream_type
<add> in (StreamType.PUSH, StreamType.CONTROL, StreamType.WEBTRANSPORT)
<add> or not buf.eof()
<del> stream.stream_type in (StreamType.PUSH, StreamType.CONTROL) or not buf.eof()
|
# module: aioquic.h3.connection
class H3Connection:
def _receive_stream_data_uni(
self, stream: H3Stream, data: bytes, stream_ended: bool
) -> List[H3Event]:
<0> http_events: List[H3Event] = []
<1>
<2> stream.buffer += data
<3> if stream_ended:
<4> stream.ended = True
<5>
<6> buf = Buffer(data=stream.buffer)
<7> consumed = 0
<8> unblocked_streams: Set[int] = set()
<9>
<10> while (
<11> stream.stream_type in (StreamType.PUSH, StreamType.CONTROL) or not buf.eof()
<12> ):
<13> # fetch stream type for unidirectional streams
<14> if stream.stream_type is None:
<15> try:
<16> stream.stream_type = buf.pull_uint_var()
<17> except BufferReadError:
<18> break
<19> consumed = buf.tell()
<20>
<21> # check unicity
<22> if stream.stream_type == StreamType.CONTROL:
<23> if self._peer_control_stream_id is not None:
<24> raise StreamCreationError("Only one control stream is allowed")
<25> self._peer_control_stream_id = stream.stream_id
<26> elif stream.stream_type == StreamType.QPACK_DECODER:
<27> if self._peer_decoder_stream_id is not None:
<28> raise StreamCreationError(
<29> "Only one QPACK decoder stream is allowed"
<30> )
<31> self._peer_decoder_stream_id = stream.stream_id
<32> elif stream.stream_type == StreamType.QPACK_ENCODER:
<33> if self._peer_encoder_stream_id is not None:
<34> raise StreamCreationError(
<35> "Only one QPACK encoder stream is allowed"
<36> )
<37> self._peer_encoder_stream_id = stream.stream_id
<38>
<39> if stream.stream_type == StreamType.CONTROL:
<40> if stream_ended:
<41> raise ClosedCriticalStream("Closing</s>
|
===========below chunk 0===========
# module: aioquic.h3.connection
class H3Connection:
def _receive_stream_data_uni(
self, stream: H3Stream, data: bytes, stream_ended: bool
) -> List[H3Event]:
# offset: 1
# fetch next frame
try:
frame_type = buf.pull_uint_var()
frame_length = buf.pull_uint_var()
frame_data = buf.pull_bytes(frame_length)
except BufferReadError:
break
consumed = buf.tell()
self._handle_control_frame(frame_type, frame_data)
elif stream.stream_type == StreamType.PUSH:
# fetch push id
if stream.push_id is None:
try:
stream.push_id = buf.pull_uint_var()
except BufferReadError:
break
consumed = buf.tell()
# remove processed data from buffer
stream.buffer = stream.buffer[consumed:]
return self._receive_request_or_push_data(stream, b"", stream_ended)
elif stream.stream_type == StreamType.QPACK_DECODER:
# feed unframed data to decoder
data = buf.pull_bytes(buf.capacity - buf.tell())
consumed = buf.tell()
try:
self._encoder.feed_decoder(data)
except pylsqpack.DecoderStreamError as exc:
raise QpackDecoderStreamError() from exc
self._decoder_bytes_received += len(data)
elif stream.stream_type == StreamType.QPACK_ENCODER:
# feed unframed data to encoder
data = buf.pull_bytes(buf.capacity - buf.tell())
consumed = buf.tell()
try:
unblocked_streams.update(self._decoder.feed_encoder(data))
except pylsqpack.EncoderStreamError as exc:
raise QpackEncoderStreamError() from exc
self._encoder_bytes_received += len(data)
else:
</s>
===========below chunk 1===========
# module: aioquic.h3.connection
class H3Connection:
def _receive_stream_data_uni(
self, stream: H3Stream, data: bytes, stream_ended: bool
) -> List[H3Event]:
# offset: 2
<s>
raise QpackEncoderStreamError() from exc
self._encoder_bytes_received += len(data)
else:
# unknown stream type, discard data
buf.seek(buf.capacity)
consumed = buf.tell()
# remove processed data from buffer
stream.buffer = stream.buffer[consumed:]
# process unblocked streams
for stream_id in unblocked_streams:
stream = self._stream[stream_id]
# resume headers
http_events.extend(
self._handle_request_or_push_frame(
frame_type=FrameType.HEADERS,
frame_data=None,
stream=stream,
stream_ended=stream.ended and not stream.buffer,
)
)
stream.blocked = False
stream.blocked_frame_size = None
# resume processing
if stream.buffer:
http_events.extend(
self._receive_request_or_push_data(stream, b"", stream.ended)
)
return http_events
===========unchanged ref 0===========
at: aioquic.h3.connection
FrameType(x: Union[str, bytes, bytearray], base: int)
FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
StreamType(x: Union[str, bytes, bytearray], base: int)
qlog_encode_data_frame(byte_length: int, stream_id: int) -> Dict
H3Stream(stream_id: int)
at: aioquic.h3.connection.H3Connection
_handle_request_or_push_frame(self, frame_type: int, frame_data: Optional[bytes], stream: H3Stream, stream_ended: bool) -> List[H3Event]
_handle_request_or_push_frame(frame_type: int, frame_data: Optional[bytes], stream: H3Stream, stream_ended: bool) -> List[H3Event]
at: aioquic.h3.connection.H3Connection.__init__
self._quic_logger: Optional[QuicLoggerTrace] = quic._quic_logger
at: aioquic.h3.connection.H3Connection._receive_request_or_push_data
http_events: List[H3Event] = []
at: aioquic.h3.connection.H3Stream.__init__
self.blocked = False
self.blocked_frame_size: Optional[int] = None
self.buffer = b""
self.ended = False
self.frame_size: Optional[int] = None
self.frame_type: Optional[int] = None
self.push_id: Optional[int] = None
self.session_id: Optional[int] = None
self.stream_id = stream_id
self.stream_type: Optional[int] = None
at: typing
List = _alias(list, 1, inst=False, name='List')
===========unchanged ref 1===========
Set = _alias(set, 1, inst=False, name='Set')
===========changed ref 0===========
# module: aioquic.h3.connection
class StreamType(IntEnum):
CONTROL = 0
PUSH = 1
QPACK_ENCODER = 2
QPACK_DECODER = 3
+ WEBTRANSPORT = 0x54
===========changed ref 1===========
# module: aioquic.h3.connection
class FrameType(IntEnum):
DATA = 0x0
HEADERS = 0x1
PRIORITY = 0x2
CANCEL_PUSH = 0x3
SETTINGS = 0x4
PUSH_PROMISE = 0x5
GOAWAY = 0x7
MAX_PUSH_ID = 0xD
DUPLICATE_PUSH = 0xE
+ WEBTRANSPORT_STREAM = 0x41
|
tests.test_tls/ContextTest._handshake
|
Modified
|
aiortc~aioquic
|
ceebca4b52649059f0f309a8b404e3b35ed5c46b
|
[tests] fix test flakiness
|
<15>:<add> self.assertGreaterEqual(len(client_input), 587)
<del> self.assertGreaterEqual(len(client_input), 588)
|
# module: tests.test_tls
class ContextTest(TestCase):
def _handshake(self, client, server):
<0> # send client hello
<1> client_buf = create_buffers()
<2> client.handle_message(b"", client_buf)
<3> self.assertEqual(client.state, State.CLIENT_EXPECT_SERVER_HELLO)
<4> server_input = merge_buffers(client_buf)
<5> self.assertGreaterEqual(len(server_input), 181)
<6> self.assertLessEqual(len(server_input), 358)
<7> reset_buffers(client_buf)
<8>
<9> # handle client hello
<10> # send server hello, encrypted extensions, certificate, certificate verify, finished, (session ticket)
<11> server_buf = create_buffers()
<12> server.handle_message(server_input, server_buf)
<13> self.assertEqual(server.state, State.SERVER_EXPECT_FINISHED)
<14> client_input = merge_buffers(server_buf)
<15> self.assertGreaterEqual(len(client_input), 588)
<16> self.assertLessEqual(len(client_input), 2316)
<17>
<18> reset_buffers(server_buf)
<19>
<20> # handle server hello, encrypted extensions, certificate, certificate verify, finished, (session ticket)
<21> # send finished
<22> client.handle_message(client_input, client_buf)
<23> self.assertEqual(client.state, State.CLIENT_POST_HANDSHAKE)
<24> server_input = merge_buffers(client_buf)
<25> self.assertEqual(len(server_input), 52)
<26> reset_buffers(client_buf)
<27>
<28> # handle finished
<29> server.handle_message(server_input, server_buf)
<30> self.assertEqual(server.state, State.SERVER_POST_HANDSHAKE)
<31> client_input = merge_buffers(server_buf)
<32> self.assertEqual(len(client_input), 0)
<33>
<34> # check keys match
<35> self.assertEqual(client._dec_key, server._enc</s>
|
===========below chunk 0===========
# module: tests.test_tls
class ContextTest(TestCase):
def _handshake(self, client, server):
# offset: 1
self.assertEqual(client._enc_key, server._dec_key)
# check cipher suite
self.assertEqual(
client.key_schedule.cipher_suite, tls.CipherSuite.AES_256_GCM_SHA384
)
self.assertEqual(
server.key_schedule.cipher_suite, tls.CipherSuite.AES_256_GCM_SHA384
)
===========unchanged ref 0===========
at: tests.test_tls
create_buffers()
merge_buffers(buffers)
reset_buffers(buffers)
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
assertGreaterEqual(a: Any, b: Any, msg: Any=...) -> None
assertLessEqual(a: Any, b: Any, msg: Any=...) -> None
|
tests.test_h3/H3ConnectionTest.test_validate_settings_enable_webtransport_invalid_value
|
Modified
|
aiortc~aioquic
|
7cf0c6659c743f32f7d1a57c6d2e124b669c1a04
|
[h3] remove SETTINGS_ prefix from setting identifiers
|
<5>:<add> # receive SETTINGS with an invalid ENABLE_WEBTRANSPORT value
<del> # receive SETTINGS with an invalid SETTINGS_ENABLE_WEBTRANSPORT value
<7>:<add> settings[Setting.ENABLE_WEBTRANSPORT] = 2
<del> settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 2
<20>:<add> "ENABLE_WEBTRANSPORT setting must be 0 or 1",
<del> "SETTINGS_ENABLE_WEBTRANSPORT setting must be 0 or 1",
|
# module: tests.test_h3
class H3ConnectionTest(TestCase):
def test_validate_settings_enable_webtransport_invalid_value(self):
<0> quic_server = FakeQuicConnection(
<1> configuration=QuicConfiguration(is_client=False)
<2> )
<3> h3_server = H3Connection(quic_server)
<4>
<5> # receive SETTINGS with an invalid SETTINGS_ENABLE_WEBTRANSPORT value
<6> settings = copy.copy(DUMMY_SETTINGS)
<7> settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 2
<8> h3_server.handle_event(
<9> StreamDataReceived(
<10> stream_id=2,
<11> data=encode_uint_var(StreamType.CONTROL)
<12> + encode_frame(FrameType.SETTINGS, encode_settings(settings)),
<13> end_stream=False,
<14> )
<15> )
<16> self.assertEqual(
<17> quic_server.closed,
<18> (
<19> ErrorCode.H3_SETTINGS_ERROR,
<20> "SETTINGS_ENABLE_WEBTRANSPORT setting must be 0 or 1",
<21> ),
<22> )
<23>
|
===========unchanged ref 0===========
at: copy
copy(x: _T) -> _T
at: tests.test_h3
DUMMY_SETTINGS = {
Setting.QPACK_MAX_TABLE_CAPACITY: 4096,
Setting.QPACK_BLOCKED_STREAMS: 16,
Setting.DUMMY: 1,
}
FakeQuicConnection(configuration)
at: tests.test_h3.FakeQuicConnection.__init__
self.closed = None
at: tests.test_h3.FakeQuicConnection.close
self.closed = (error_code, reason_phrase)
at: tests.test_h3.H3ConnectionTest
maxDiff = None
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
|
tests.test_h3/H3ConnectionTest.test_validate_settings_enable_webtransport_without_h3_datagram
|
Modified
|
aiortc~aioquic
|
7cf0c6659c743f32f7d1a57c6d2e124b669c1a04
|
[h3] remove SETTINGS_ prefix from setting identifiers
|
<7>:<add> settings[Setting.ENABLE_WEBTRANSPORT] = 1
<del> settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 1
<20>:<add> "ENABLE_WEBTRANSPORT requires H3_DATAGRAM",
<del> "SETTINGS_ENABLE_WEBTRANSPORT requires H3_DATAGRAM",
|
# module: tests.test_h3
class H3ConnectionTest(TestCase):
def test_validate_settings_enable_webtransport_without_h3_datagram(self):
<0> quic_server = FakeQuicConnection(
<1> configuration=QuicConfiguration(is_client=False)
<2> )
<3> h3_server = H3Connection(quic_server)
<4>
<5> # receive SETTINGS requesting WebTransport, but DATAGRAM was not offered
<6> settings = copy.copy(DUMMY_SETTINGS)
<7> settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 1
<8> h3_server.handle_event(
<9> StreamDataReceived(
<10> stream_id=2,
<11> data=encode_uint_var(StreamType.CONTROL)
<12> + encode_frame(FrameType.SETTINGS, encode_settings(settings)),
<13> end_stream=False,
<14> )
<15> )
<16> self.assertEqual(
<17> quic_server.closed,
<18> (
<19> ErrorCode.H3_SETTINGS_ERROR,
<20> "SETTINGS_ENABLE_WEBTRANSPORT requires H3_DATAGRAM",
<21> ),
<22> )
<23>
|
===========unchanged ref 0===========
at: copy
copy(x: _T) -> _T
at: tests.test_h3
DUMMY_SETTINGS = {
Setting.QPACK_MAX_TABLE_CAPACITY: 4096,
Setting.QPACK_BLOCKED_STREAMS: 16,
Setting.DUMMY: 1,
}
FakeQuicConnection(configuration)
at: tests.test_h3.FakeQuicConnection.__init__
self.closed = None
at: tests.test_h3.FakeQuicConnection.close
self.closed = (error_code, reason_phrase)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: tests.test_h3
class H3ConnectionTest(TestCase):
def test_validate_settings_enable_webtransport_invalid_value(self):
quic_server = FakeQuicConnection(
configuration=QuicConfiguration(is_client=False)
)
h3_server = H3Connection(quic_server)
+ # receive SETTINGS with an invalid ENABLE_WEBTRANSPORT value
- # receive SETTINGS with an invalid SETTINGS_ENABLE_WEBTRANSPORT value
settings = copy.copy(DUMMY_SETTINGS)
+ settings[Setting.ENABLE_WEBTRANSPORT] = 2
- settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 2
h3_server.handle_event(
StreamDataReceived(
stream_id=2,
data=encode_uint_var(StreamType.CONTROL)
+ encode_frame(FrameType.SETTINGS, encode_settings(settings)),
end_stream=False,
)
)
self.assertEqual(
quic_server.closed,
(
ErrorCode.H3_SETTINGS_ERROR,
+ "ENABLE_WEBTRANSPORT setting must be 0 or 1",
- "SETTINGS_ENABLE_WEBTRANSPORT setting must be 0 or 1",
),
)
|
aioquic.h3.connection/H3Connection._get_local_settings
|
Modified
|
aiortc~aioquic
|
7cf0c6659c743f32f7d1a57c6d2e124b669c1a04
|
[h3] remove SETTINGS_ prefix from setting identifiers
|
<10>:<add> settings[Setting.ENABLE_WEBTRANSPORT] = 1
<del> settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 1
|
# module: aioquic.h3.connection
class H3Connection:
def _get_local_settings(self) -> Dict[int, int]:
<0> """
<1> Return the local HTTP/3 settings.
<2> """
<3> settings = {
<4> Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity,
<5> Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams,
<6> Setting.DUMMY: 1,
<7> }
<8> if self._enable_webtransport:
<9> settings[Setting.H3_DATAGRAM] = 1
<10> settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 1
<11> return settings
<12>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
Setting(x: Union[str, bytes, bytearray], base: int)
Setting(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
at: aioquic.h3.connection.H3Connection.__init__
self._max_table_capacity = 4096
self._blocked_streams = 16
self._enable_webtransport = enable_webtransport
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: aioquic.h3.connection
class Setting(IntEnum):
QPACK_MAX_TABLE_CAPACITY = 0x1
+ MAX_HEADER_LIST_SIZE = 0x6
- SETTINGS_MAX_HEADER_LIST_SIZE = 0x6
QPACK_BLOCKED_STREAMS = 0x7
+ NUM_PLACEHOLDERS = 0x9
- SETTINGS_NUM_PLACEHOLDERS = 0x9
H3_DATAGRAM = 0x276
+ ENABLE_WEBTRANSPORT = 0x2B603742
- SETTINGS_ENABLE_WEBTRANSPORT = 0x2B603742
# Dummy setting to check it is correctly ignored by the peer.
# https://tools.ietf.org/html/draft-ietf-quic-http-34#section-7.2.4.1
DUMMY = 0x21
===========changed ref 1===========
# module: tests.test_h3
class H3ConnectionTest(TestCase):
def test_validate_settings_enable_webtransport_without_h3_datagram(self):
quic_server = FakeQuicConnection(
configuration=QuicConfiguration(is_client=False)
)
h3_server = H3Connection(quic_server)
# receive SETTINGS requesting WebTransport, but DATAGRAM was not offered
settings = copy.copy(DUMMY_SETTINGS)
+ settings[Setting.ENABLE_WEBTRANSPORT] = 1
- settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 1
h3_server.handle_event(
StreamDataReceived(
stream_id=2,
data=encode_uint_var(StreamType.CONTROL)
+ encode_frame(FrameType.SETTINGS, encode_settings(settings)),
end_stream=False,
)
)
self.assertEqual(
quic_server.closed,
(
ErrorCode.H3_SETTINGS_ERROR,
+ "ENABLE_WEBTRANSPORT requires H3_DATAGRAM",
- "SETTINGS_ENABLE_WEBTRANSPORT requires H3_DATAGRAM",
),
)
===========changed ref 2===========
# module: tests.test_h3
class H3ConnectionTest(TestCase):
def test_validate_settings_enable_webtransport_invalid_value(self):
quic_server = FakeQuicConnection(
configuration=QuicConfiguration(is_client=False)
)
h3_server = H3Connection(quic_server)
+ # receive SETTINGS with an invalid ENABLE_WEBTRANSPORT value
- # receive SETTINGS with an invalid SETTINGS_ENABLE_WEBTRANSPORT value
settings = copy.copy(DUMMY_SETTINGS)
+ settings[Setting.ENABLE_WEBTRANSPORT] = 2
- settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 2
h3_server.handle_event(
StreamDataReceived(
stream_id=2,
data=encode_uint_var(StreamType.CONTROL)
+ encode_frame(FrameType.SETTINGS, encode_settings(settings)),
end_stream=False,
)
)
self.assertEqual(
quic_server.closed,
(
ErrorCode.H3_SETTINGS_ERROR,
+ "ENABLE_WEBTRANSPORT setting must be 0 or 1",
- "SETTINGS_ENABLE_WEBTRANSPORT setting must be 0 or 1",
),
)
|
aioquic.h3.connection/H3Connection._validate_settings
|
Modified
|
aiortc~aioquic
|
7cf0c6659c743f32f7d1a57c6d2e124b669c1a04
|
[h3] remove SETTINGS_ prefix from setting identifiers
|
<12>:<add> if Setting.ENABLE_WEBTRANSPORT in settings:
<del> if Setting.SETTINGS_ENABLE_WEBTRANSPORT in settings:
<13>:<add> if settings[Setting.ENABLE_WEBTRANSPORT] not in (0, 1):
<del> if settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] not in (0, 1):
<14>:<del> raise SettingsError(
<15>:<add> raise SettingsError("ENABLE_WEBTRANSPORT setting must be 0 or 1")
<del> "SETTINGS_ENABLE_WEBTRANSPORT setting must be 0 or 1"
<16>:<del> )
<19>:<add> settings[Setting.ENABLE_WEBTRANSPORT] == 1
<del> settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] == 1
<22>:<add> raise SettingsError("ENABLE_WEBTRANSPORT requires H3_DATAGRAM")
<del> raise SettingsError("SETTINGS_ENABLE_WEBTRANSPORT requires H3_DATAGRAM")
|
# module: aioquic.h3.connection
class H3Connection:
def _validate_settings(self, settings: Dict[int, int]) -> None:
<0> if Setting.H3_DATAGRAM in settings:
<1> if settings[Setting.H3_DATAGRAM] not in (0, 1):
<2> raise SettingsError("H3_DATAGRAM setting must be 0 or 1")
<3>
<4> if (
<5> settings[Setting.H3_DATAGRAM] == 1
<6> and self._quic._remote_max_datagram_frame_size is None
<7> ):
<8> raise SettingsError(
<9> "H3_DATAGRAM requires max_datagram_frame_size transport parameter"
<10> )
<11>
<12> if Setting.SETTINGS_ENABLE_WEBTRANSPORT in settings:
<13> if settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] not in (0, 1):
<14> raise SettingsError(
<15> "SETTINGS_ENABLE_WEBTRANSPORT setting must be 0 or 1"
<16> )
<17>
<18> if (
<19> settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] == 1
<20> and settings.get(Setting.H3_DATAGRAM) != 1
<21> ):
<22> raise SettingsError("SETTINGS_ENABLE_WEBTRANSPORT requires H3_DATAGRAM")
<23>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
Setting(x: Union[str, bytes, bytearray], base: int)
Setting(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
SettingsError(reason_phrase: str="")
at: aioquic.h3.connection.H3Connection.__init__
self._quic = quic
at: tests.test_h3.FakeQuicConnection.__init__
self._remote_max_datagram_frame_size = None
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
at: typing.Mapping
get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]
get(key: _KT) -> Optional[_VT_co]
===========changed ref 0===========
# module: aioquic.h3.connection
class Setting(IntEnum):
QPACK_MAX_TABLE_CAPACITY = 0x1
+ MAX_HEADER_LIST_SIZE = 0x6
- SETTINGS_MAX_HEADER_LIST_SIZE = 0x6
QPACK_BLOCKED_STREAMS = 0x7
+ NUM_PLACEHOLDERS = 0x9
- SETTINGS_NUM_PLACEHOLDERS = 0x9
H3_DATAGRAM = 0x276
+ ENABLE_WEBTRANSPORT = 0x2B603742
- SETTINGS_ENABLE_WEBTRANSPORT = 0x2B603742
# Dummy setting to check it is correctly ignored by the peer.
# https://tools.ietf.org/html/draft-ietf-quic-http-34#section-7.2.4.1
DUMMY = 0x21
===========changed ref 1===========
# module: aioquic.h3.connection
class H3Connection:
def _get_local_settings(self) -> Dict[int, int]:
"""
Return the local HTTP/3 settings.
"""
settings = {
Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity,
Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams,
Setting.DUMMY: 1,
}
if self._enable_webtransport:
settings[Setting.H3_DATAGRAM] = 1
+ settings[Setting.ENABLE_WEBTRANSPORT] = 1
- settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 1
return settings
===========changed ref 2===========
# module: tests.test_h3
class H3ConnectionTest(TestCase):
def test_validate_settings_enable_webtransport_without_h3_datagram(self):
quic_server = FakeQuicConnection(
configuration=QuicConfiguration(is_client=False)
)
h3_server = H3Connection(quic_server)
# receive SETTINGS requesting WebTransport, but DATAGRAM was not offered
settings = copy.copy(DUMMY_SETTINGS)
+ settings[Setting.ENABLE_WEBTRANSPORT] = 1
- settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 1
h3_server.handle_event(
StreamDataReceived(
stream_id=2,
data=encode_uint_var(StreamType.CONTROL)
+ encode_frame(FrameType.SETTINGS, encode_settings(settings)),
end_stream=False,
)
)
self.assertEqual(
quic_server.closed,
(
ErrorCode.H3_SETTINGS_ERROR,
+ "ENABLE_WEBTRANSPORT requires H3_DATAGRAM",
- "SETTINGS_ENABLE_WEBTRANSPORT requires H3_DATAGRAM",
),
)
===========changed ref 3===========
# module: tests.test_h3
class H3ConnectionTest(TestCase):
def test_validate_settings_enable_webtransport_invalid_value(self):
quic_server = FakeQuicConnection(
configuration=QuicConfiguration(is_client=False)
)
h3_server = H3Connection(quic_server)
+ # receive SETTINGS with an invalid ENABLE_WEBTRANSPORT value
- # receive SETTINGS with an invalid SETTINGS_ENABLE_WEBTRANSPORT value
settings = copy.copy(DUMMY_SETTINGS)
+ settings[Setting.ENABLE_WEBTRANSPORT] = 2
- settings[Setting.SETTINGS_ENABLE_WEBTRANSPORT] = 2
h3_server.handle_event(
StreamDataReceived(
stream_id=2,
data=encode_uint_var(StreamType.CONTROL)
+ encode_frame(FrameType.SETTINGS, encode_settings(settings)),
end_stream=False,
)
)
self.assertEqual(
quic_server.closed,
(
ErrorCode.H3_SETTINGS_ERROR,
+ "ENABLE_WEBTRANSPORT setting must be 0 or 1",
- "SETTINGS_ENABLE_WEBTRANSPORT setting must be 0 or 1",
),
)
|
examples.http3_server/HttpServerProtocol.http_event_received
|
Modified
|
aiortc~aioquic
|
d42f65ed9e9a49de965205c26fff45a0a9d3179b
|
[webtransport] add a minimal demo for WebTransport
|
# module: examples.http3_server
class HttpServerProtocol(QuicConnectionProtocol):
def http_event_received(self, event: H3Event) -> None:
<0> if isinstance(event, HeadersReceived) and event.stream_id not in self._handlers:
<1> authority = None
<2> headers = []
<3> http_version = "0.9" if isinstance(self._http, H0Connection) else "3"
<4> raw_path = b""
<5> method = ""
<6> protocol = None
<7> for header, value in event.headers:
<8> if header == b":authority":
<9> authority = value
<10> headers.append((b"host", value))
<11> elif header == b":method":
<12> method = value.decode()
<13> elif header == b":path":
<14> raw_path = value
<15> elif header == b":protocol":
<16> protocol = value.decode()
<17> elif header and not header.startswith(b":"):
<18> headers.append((header, value))
<19>
<20> if b"?" in raw_path:
<21> path_bytes, query_string = raw_path.split(b"?", maxsplit=1)
<22> else:
<23> path_bytes, query_string = raw_path, b""
<24> path = path_bytes.decode()
<25> self._quic._logger.info("HTTP request %s %s", method, path)
<26>
<27> # FIXME: add a public API to retrieve peer address
<28> client_addr = self._http._quic._network_paths[0].addr
<29> client = (client_addr[0], client_addr[1])
<30>
<31> handler: Handler
<32> scope: Dict
<33> if method == "CONNECT" and protocol == "websocket":
<34> subprotocols: List[str] = []
<35> for header, value in event.headers:
<36> if header == b"sec-websocket-protocol":
<37> subprotocols = [x.strip() for x in value.decode().split(",")]
<38> scope = {
<39> "client": client,
<40> "headers": headers,
<41> </s>
|
===========below chunk 0===========
# module: examples.http3_server
class HttpServerProtocol(QuicConnectionProtocol):
def http_event_received(self, event: H3Event) -> None:
# offset: 1
"method": method,
"path": path,
"query_string": query_string,
"raw_path": raw_path,
"root_path": "",
"scheme": "wss",
"subprotocols": subprotocols,
"type": "websocket",
}
handler = WebSocketHandler(
connection=self._http,
scope=scope,
stream_id=event.stream_id,
transmit=self.transmit,
)
else:
extensions: Dict[str, Dict] = {}
if isinstance(self._http, H3Connection):
extensions["http.response.push"] = {}
scope = {
"client": client,
"extensions": extensions,
"headers": headers,
"http_version": http_version,
"method": method,
"path": path,
"query_string": query_string,
"raw_path": raw_path,
"root_path": "",
"scheme": "https",
"type": "http",
}
handler = HttpRequestHandler(
authority=authority,
connection=self._http,
protocol=self,
scope=scope,
stream_ended=event.stream_ended,
stream_id=event.stream_id,
transmit=self.transmit,
)
self._handlers[event.stream_id] = handler
asyncio.ensure_future(handler.run_asgi(application))
elif (
isinstance(event, (DataReceived, HeadersReceived))
and event.stream_id in self._handlers
):
handler = self._handlers[event.stream_id]
handler.http_event_received(event)
===========unchanged ref 0===========
at: asyncio.queues
Queue(maxsize: int=..., *, loop: Optional[AbstractEventLoop]=...)
at: asyncio.queues.Queue
__class_getitem__ = classmethod(GenericAlias)
put_nowait(item: _T) -> None
get() -> _T
at: collections
deque(iterable: Iterable[_T]=..., maxlen: Optional[int]=...)
at: collections.deque
append(x: _T) -> None
popleft() -> _T
at: email.utils
formatdate(timeval: Optional[float]=..., localtime: bool=..., usegmt: bool=...) -> str
at: examples.http3_server
AsgiApplication = Callable
HttpConnection = Union[H0Connection, H3Connection]
SERVER_NAME = "aioquic/" + aioquic.__version__
HttpRequestHandler(*, authority: bytes, connection: HttpConnection, protocol: QuicConnectionProtocol, scope: Dict, stream_ended: bool, stream_id: int, transmit: Callable[[], None])
WebSocketHandler(*, connection: HttpConnection, scope: Dict, stream_id: int, transmit: Callable[[], None])
WebTransportHandler(*, connection: HttpConnection, scope: Dict, stream_id: int, transmit: Callable[[], None])
at: time
time() -> float
at: typing
Callable = _CallableType(collections.abc.Callable, 2)
Deque = _alias(collections.deque, 1, name='Deque')
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: examples.http3_server
+ Handler = Union[HttpRequestHandler, WebSocketHandler, WebTransportHandler]
- Handler = Union[HttpRequestHandler, WebSocketHandler]
|
|
examples.http3_server/HttpServerProtocol.quic_event_received
|
Modified
|
aiortc~aioquic
|
d42f65ed9e9a49de965205c26fff45a0a9d3179b
|
[webtransport] add a minimal demo for WebTransport
|
<2>:<add> self._http = H3Connection(self._quic, enable_webtransport=True)
<del> self._http = H3Connection(self._quic)
|
# module: examples.http3_server
class HttpServerProtocol(QuicConnectionProtocol):
def quic_event_received(self, event: QuicEvent) -> None:
<0> if isinstance(event, ProtocolNegotiated):
<1> if event.alpn_protocol in H3_ALPN:
<2> self._http = H3Connection(self._quic)
<3> elif event.alpn_protocol in H0_ALPN:
<4> self._http = H0Connection(self._quic)
<5> elif isinstance(event, DatagramFrameReceived):
<6> if event.data == b"quack":
<7> self._quic.send_datagram_frame(b"quack-ack")
<8>
<9> # pass event to the HTTP layer
<10> if self._http is not None:
<11> for http_event in self._http.handle_event(event):
<12> self.http_event_received(http_event)
<13>
|
===========unchanged ref 0===========
at: examples.http3_server
HttpConnection = Union[H0Connection, H3Connection]
Handler = Union[HttpRequestHandler, WebSocketHandler, WebTransportHandler]
at: examples.http3_server.HttpServerProtocol.quic_event_received
self._http = H0Connection(self._quic)
self._http = H3Connection(self._quic, enable_webtransport=True)
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: examples.http3_server
+ class WebTransportHandler:
+ def receive(self) -> Dict:
+ return await self.queue.get()
+
===========changed ref 1===========
# module: examples.http3_server
+ class WebTransportHandler:
+ def run_asgi(self, app: AsgiApplication) -> None:
+ self.queue.put_nowait({"type": "webtransport.connect"})
+
+ try:
+ await app(self.scope, self.receive, self.send)
+ finally:
+ if not self.closed:
+ await self.send({"type": "webtransport.close"})
+
===========changed ref 2===========
# module: examples.http3_server
+ Handler = Union[HttpRequestHandler, WebSocketHandler, WebTransportHandler]
- Handler = Union[HttpRequestHandler, WebSocketHandler]
===========changed ref 3===========
# module: examples.http3_server
+ class WebTransportHandler:
+ def __init__(
+ self,
+ *,
+ connection: HttpConnection,
+ scope: Dict,
+ stream_id: int,
+ transmit: Callable[[], None],
+ ) -> None:
+ self.accepted = False
+ self.closed = False
+ self.connection = connection
+ self.http_event_queue: Deque[DataReceived] = deque()
+ self.queue: asyncio.Queue[Dict] = asyncio.Queue()
+ self.scope = scope
+ self.stream_id = stream_id
+ self.transmit = transmit
+
===========changed ref 4===========
# module: examples.http3_server
+ class WebTransportHandler:
+ def http_event_received(self, event: H3Event) -> None:
+ if not self.closed:
+ if self.accepted:
+ if isinstance(event, DatagramReceived):
+ self.queue.put_nowait(
+ {
+ "data": event.data,
+ "type": "webtransport.datagram.receive",
+ }
+ )
+ elif isinstance(event, WebTransportStreamDataReceived):
+ self.queue.put_nowait(
+ {
+ "data": event.data,
+ "stream": event.stream_id,
+ "type": "webtransport.stream.receive",
+ }
+ )
+ else:
+ # delay event processing until we get `webtransport.accept`
+ # from the ASGI application
+ self.http_event_queue.append(event)
+
===========changed ref 5===========
# module: examples.http3_server
+ class WebTransportHandler:
+ def send(self, message: Dict) -> None:
+ data = b""
+ end_stream = False
+
+ if message["type"] == "webtransport.accept":
+ self.accepted = True
+
+ headers = [
+ (b":status", b"200"),
+ (b"server", SERVER_NAME.encode()),
+ (b"date", formatdate(time.time(), usegmt=True).encode()),
+ ]
+ self.connection.send_headers(stream_id=self.stream_id, headers=headers)
+
+ # consume backlog
+ while self.http_event_queue:
+ self.http_event_received(self.http_event_queue.popleft())
+ elif message["type"] == "webtransport.close":
+ if not self.accepted:
+ self.connection.send_headers(
+ stream_id=self.stream_id, headers=[(b":status", b"403")]
+ )
+ end_stream = True
+ elif message["type"] == "webtransport.datagram.send":
+ self.connection.send_datagram(flow_id=self.stream_id, data=message["data"])
+ elif message["type"] == "webtransport.stream.send":
+ self.connection._quic.send_stream_data(
+ stream_id=message["stream"], data=message["data"]
+ )
+
+ if data or end_stream:
+ self.connection.send_data(
+ stream_id=self.stream_id, data=data, end_stream=end_stream
+ )
+ if end_stream:
+ self.closed = True
+ self.transmit()
+
===========changed ref 6===========
# module: examples.http3_server
class HttpServerProtocol(QuicConnectionProtocol):
def http_event_received(self, event: H3Event) -> None:
if isinstance(event, HeadersReceived) and event.stream_id not in self._handlers:
authority = None
headers = []
http_version = "0.9" if isinstance(self._http, H0Connection) else "3"
raw_path = b""
method = ""
protocol = None
for header, value in event.headers:
if header == b":authority":
authority = value
headers.append((b"host", value))
elif header == b":method":
method = value.decode()
elif header == b":path":
raw_path = value
elif header == b":protocol":
protocol = value.decode()
elif header and not header.startswith(b":"):
headers.append((header, value))
if b"?" in raw_path:
path_bytes, query_string = raw_path.split(b"?", maxsplit=1)
else:
path_bytes, query_string = raw_path, b""
path = path_bytes.decode()
self._quic._logger.info("HTTP request %s %s", method, path)
# FIXME: add a public API to retrieve peer address
client_addr = self._http._quic._network_paths[0].addr
client = (client_addr[0], client_addr[1])
handler: Handler
scope: Dict
if method == "CONNECT" and protocol == "websocket":
subprotocols: List[str] = []
for header, value in event.headers:
if header == b"sec-websocket-protocol":
subprotocols = [x.strip() for x in value.decode().split(",")]
scope = {
"client": client,
"headers": headers,
"http_version": http_version,
"method": method,
"path": path,
"query_string": query_string,
"raw_path": raw</s>
|
aioquic.quic.connection/QuicConnection._get_or_create_stream
|
Modified
|
aiortc~aioquic
|
978d64bc5bbb61f8db2c4168112820f31787b804
|
[streams] keep track of whether send / receive is finished
|
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream:
<0> """
<1> Get or create a stream in response to a received frame.
<2> """
<3> stream = self._streams.get(stream_id, None)
<4> if stream is None:
<5> # check initiator
<6> if stream_is_client_initiated(stream_id) == self._is_client:
<7> raise QuicConnectionError(
<8> error_code=QuicErrorCode.STREAM_STATE_ERROR,
<9> frame_type=frame_type,
<10> reason_phrase="Wrong stream initiator",
<11> )
<12>
<13> # determine limits
<14> if stream_is_unidirectional(stream_id):
<15> max_stream_data_local = self._local_max_stream_data_uni
<16> max_stream_data_remote = 0
<17> max_streams = self._local_max_streams_uni
<18> else:
<19> max_stream_data_local = self._local_max_stream_data_bidi_remote
<20> max_stream_data_remote = self._remote_max_stream_data_bidi_local
<21> max_streams = self._local_max_streams_bidi
<22>
<23> # check max streams
<24> stream_count = (stream_id // 4) + 1
<25> if stream_count > max_streams.value:
<26> raise QuicConnectionError(
<27> error_code=QuicErrorCode.STREAM_LIMIT_ERROR,
<28> frame_type=frame_type,
<29> reason_phrase="Too many streams open",
<30> )
<31> elif stream_count > max_streams.used:
<32> max_streams.used = stream_count
<33>
<34> # create stream
<35> self._logger.debug("Stream %d created by peer" % stream_id)
<36> stream = self._streams[stream_id] = QuicStream(
<37> stream_id=stream_id,
<38> max_stream_data_local=</s>
|
===========below chunk 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream:
# offset: 1
max_stream_data_remote=max_stream_data_remote,
)
return stream
===========unchanged ref 0===========
at: aioquic.quic.connection
stream_is_client_initiated(stream_id: int) -> bool
stream_is_unidirectional(stream_id: int) -> bool
QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)
at: aioquic.quic.connection.Limit.__init__
self.used = 0
self.value = value
at: aioquic.quic.connection.QuicConnection.__init__
self._is_client = configuration.is_client
self._local_max_stream_data_bidi_remote = configuration.max_stream_data
self._local_max_stream_data_uni = configuration.max_stream_data
self._local_max_streams_bidi = Limit(
frame_type=QuicFrameType.MAX_STREAMS_BIDI,
name="max_streams_bidi",
value=128,
)
self._local_max_streams_uni = Limit(
frame_type=QuicFrameType.MAX_STREAMS_UNI, name="max_streams_uni", value=128
)
self._remote_max_stream_data_bidi_local = 0
self._streams: Dict[int, QuicStream] = {}
self._logger = QuicConnectionAdapter(
logger, {"id": dump_cid(self._original_destination_connection_id)}
)
at: logging.LoggerAdapter
logger: Logger
extra: Mapping[str, Any]
debug(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
at: typing.Mapping
get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]
get(key: _KT) -> Optional[_VT_co]
|
|
aioquic.quic.connection/QuicConnection._get_or_create_stream_for_send
|
Modified
|
aiortc~aioquic
|
978d64bc5bbb61f8db2c4168112820f31787b804
|
[streams] keep track of whether send / receive is finished
|
<32>:<add> readable=not stream_is_unidirectional(stream_id),
|
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream_for_send(self, stream_id: int) -> QuicStream:
<0> """
<1> Get or create a QUIC stream in order to send data to the peer.
<2>
<3> This always occurs as a result of an API call.
<4> """
<5> if stream_is_client_initiated(stream_id) != self._is_client:
<6> if stream_id not in self._streams:
<7> raise ValueError("Cannot send data on unknown peer-initiated stream")
<8> if stream_is_unidirectional(stream_id):
<9> raise ValueError(
<10> "Cannot send data on peer-initiated unidirectional stream"
<11> )
<12>
<13> stream = self._streams.get(stream_id, None)
<14> if stream is None:
<15> # determine limits
<16> if stream_is_unidirectional(stream_id):
<17> max_stream_data_local = 0
<18> max_stream_data_remote = self._remote_max_stream_data_uni
<19> max_streams = self._remote_max_streams_uni
<20> streams_blocked = self._streams_blocked_uni
<21> else:
<22> max_stream_data_local = self._local_max_stream_data_bidi_local
<23> max_stream_data_remote = self._remote_max_stream_data_bidi_remote
<24> max_streams = self._remote_max_streams_bidi
<25> streams_blocked = self._streams_blocked_bidi
<26>
<27> # create stream
<28> stream = self._streams[stream_id] = QuicStream(
<29> stream_id=stream_id,
<30> max_stream_data_local=max_stream_data_local,
<31> max_stream_data_remote=max_stream_data_remote,
<32> )
<33>
<34> # mark stream as blocked if needed
<35> if stream_id // 4 >= max_streams:
<36> stream.is_blocked = True
<37> streams_blocked.</s>
|
===========below chunk 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream_for_send(self, stream_id: int) -> QuicStream:
# offset: 1
self._streams_blocked_pending = True
return stream
===========unchanged ref 0===========
at: aioquic.quic.connection
stream_is_client_initiated(stream_id: int) -> bool
stream_is_unidirectional(stream_id: int) -> bool
at: aioquic.quic.connection.QuicConnection.__init__
self._is_client = configuration.is_client
self._local_max_stream_data_bidi_local = configuration.max_stream_data
self._remote_max_stream_data_bidi_remote = 0
self._remote_max_stream_data_uni = 0
self._remote_max_streams_bidi = 0
self._remote_max_streams_uni = 0
self._streams: Dict[int, QuicStream] = {}
self._streams_blocked_bidi: List[QuicStream] = []
self._streams_blocked_uni: List[QuicStream] = []
at: aioquic.quic.connection.QuicConnection._handle_max_streams_bidi_frame
self._remote_max_streams_bidi = max_streams
at: aioquic.quic.connection.QuicConnection._handle_max_streams_uni_frame
self._remote_max_streams_uni = max_streams
at: typing.Mapping
get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]
get(key: _KT) -> Optional[_VT_co]
===========changed ref 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream:
"""
Get or create a stream in response to a received frame.
"""
stream = self._streams.get(stream_id, None)
if stream is None:
# check initiator
if stream_is_client_initiated(stream_id) == self._is_client:
raise QuicConnectionError(
error_code=QuicErrorCode.STREAM_STATE_ERROR,
frame_type=frame_type,
reason_phrase="Wrong stream initiator",
)
# determine limits
if stream_is_unidirectional(stream_id):
max_stream_data_local = self._local_max_stream_data_uni
max_stream_data_remote = 0
max_streams = self._local_max_streams_uni
else:
max_stream_data_local = self._local_max_stream_data_bidi_remote
max_stream_data_remote = self._remote_max_stream_data_bidi_local
max_streams = self._local_max_streams_bidi
# check max streams
stream_count = (stream_id // 4) + 1
if stream_count > max_streams.value:
raise QuicConnectionError(
error_code=QuicErrorCode.STREAM_LIMIT_ERROR,
frame_type=frame_type,
reason_phrase="Too many streams open",
)
elif stream_count > max_streams.used:
max_streams.used = stream_count
# create stream
self._logger.debug("Stream %d created by peer" % 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,
+ writable=not stream_is_unidirectional</s>
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream:
# offset: 1
<s> max_stream_data_remote=max_stream_data_remote,
+ writable=not stream_is_unidirectional(stream_id),
)
return stream
|
tests.test_stream/QuicStreamTest.test_recv_ordered
|
Modified
|
aiortc~aioquic
|
978d64bc5bbb61f8db2c4168112820f31787b804
|
[streams] keep track of whether send / receive is finished
|
<10>:<add> self.assertFalse(stream._recv_finished)
<19>:<add> self.assertFalse(stream._recv_finished)
<28>:<add> self.assertTrue(stream._recv_finished)
|
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_ordered(self):
<0> stream = QuicStream(stream_id=0)
<1>
<2> # add data at start
<3> self.assertEqual(
<4> stream.add_frame(QuicStreamFrame(offset=0, data=b"01234567")),
<5> StreamDataReceived(data=b"01234567", end_stream=False, stream_id=0),
<6> )
<7> self.assertEqual(bytes(stream._recv_buffer), b"")
<8> self.assertEqual(list(stream._recv_ranges), [])
<9> self.assertEqual(stream._recv_buffer_start, 8)
<10>
<11> # add more data
<12> self.assertEqual(
<13> stream.add_frame(QuicStreamFrame(offset=8, data=b"89012345")),
<14> StreamDataReceived(data=b"89012345", end_stream=False, stream_id=0),
<15> )
<16> self.assertEqual(bytes(stream._recv_buffer), b"")
<17> self.assertEqual(list(stream._recv_ranges), [])
<18> self.assertEqual(stream._recv_buffer_start, 16)
<19>
<20> # add data and fin
<21> self.assertEqual(
<22> stream.add_frame(QuicStreamFrame(offset=16, data=b"67890123", fin=True)),
<23> StreamDataReceived(data=b"67890123", end_stream=True, stream_id=0),
<24> )
<25> self.assertEqual(bytes(stream._recv_buffer), b"")
<26> self.assertEqual(list(stream._recv_ranges), [])
<27> self.assertEqual(stream._recv_buffer_start, 24)
<28>
|
===========unchanged ref 0===========
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
assertFalse(expr: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream_for_send(self, stream_id: int) -> QuicStream:
"""
Get or create a QUIC stream in order to send data to the peer.
This always occurs as a result of an API call.
"""
if stream_is_client_initiated(stream_id) != self._is_client:
if stream_id not in self._streams:
raise ValueError("Cannot send data on unknown peer-initiated stream")
if stream_is_unidirectional(stream_id):
raise ValueError(
"Cannot send data on peer-initiated unidirectional stream"
)
stream = self._streams.get(stream_id, None)
if stream is None:
# determine limits
if stream_is_unidirectional(stream_id):
max_stream_data_local = 0
max_stream_data_remote = self._remote_max_stream_data_uni
max_streams = self._remote_max_streams_uni
streams_blocked = self._streams_blocked_uni
else:
max_stream_data_local = self._local_max_stream_data_bidi_local
max_stream_data_remote = self._remote_max_stream_data_bidi_remote
max_streams = self._remote_max_streams_bidi
streams_blocked = self._streams_blocked_bidi
# create stream
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),
)
# mark stream as blocked if needed
if stream_id // 4 >= max_streams:
stream.is_blocked = True
streams_blocked.append(stream)
self._streams_blocked_pending = True
return stream
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream:
"""
Get or create a stream in response to a received frame.
"""
stream = self._streams.get(stream_id, None)
if stream is None:
# check initiator
if stream_is_client_initiated(stream_id) == self._is_client:
raise QuicConnectionError(
error_code=QuicErrorCode.STREAM_STATE_ERROR,
frame_type=frame_type,
reason_phrase="Wrong stream initiator",
)
# determine limits
if stream_is_unidirectional(stream_id):
max_stream_data_local = self._local_max_stream_data_uni
max_stream_data_remote = 0
max_streams = self._local_max_streams_uni
else:
max_stream_data_local = self._local_max_stream_data_bidi_remote
max_stream_data_remote = self._remote_max_stream_data_bidi_local
max_streams = self._local_max_streams_bidi
# check max streams
stream_count = (stream_id // 4) + 1
if stream_count > max_streams.value:
raise QuicConnectionError(
error_code=QuicErrorCode.STREAM_LIMIT_ERROR,
frame_type=frame_type,
reason_phrase="Too many streams open",
)
elif stream_count > max_streams.used:
max_streams.used = stream_count
# create stream
self._logger.debug("Stream %d created by peer" % 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,
+ writable=not stream_is_unidirectional</s>
===========changed ref 2===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream:
# offset: 1
<s> max_stream_data_remote=max_stream_data_remote,
+ writable=not stream_is_unidirectional(stream_id),
)
return stream
|
tests.test_stream/QuicStreamTest.test_recv_fin_out_of_order
|
Modified
|
aiortc~aioquic
|
978d64bc5bbb61f8db2c4168112820f31787b804
|
[streams] keep track of whether send / receive is finished
|
<7>:<add> self.assertFalse(stream._recv_finished)
<13>:<add> self.assertTrue(stream._recv_finished)
|
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_fin_out_of_order(self):
<0> stream = QuicStream(stream_id=0)
<1>
<2> # add data at offset 8 with FIN
<3> self.assertEqual(
<4> stream.add_frame(QuicStreamFrame(offset=8, data=b"89012345", fin=True)),
<5> None,
<6> )
<7>
<8> # add data at offset 0
<9> self.assertEqual(
<10> stream.add_frame(QuicStreamFrame(offset=0, data=b"01234567")),
<11> StreamDataReceived(data=b"0123456789012345", end_stream=True, stream_id=0),
<12> )
<13>
|
===========unchanged ref 0===========
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
assertFalse(expr: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_ordered(self):
stream = QuicStream(stream_id=0)
# add data at start
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=0, data=b"01234567")),
StreamDataReceived(data=b"01234567", end_stream=False, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 8)
+ self.assertFalse(stream._recv_finished)
# add more data
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=8, data=b"89012345")),
StreamDataReceived(data=b"89012345", end_stream=False, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 16)
+ self.assertFalse(stream._recv_finished)
# add data and fin
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=16, data=b"67890123", fin=True)),
StreamDataReceived(data=b"67890123", end_stream=True, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 24)
+ self.assertTrue(stream._recv_finished)
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream_for_send(self, stream_id: int) -> QuicStream:
"""
Get or create a QUIC stream in order to send data to the peer.
This always occurs as a result of an API call.
"""
if stream_is_client_initiated(stream_id) != self._is_client:
if stream_id not in self._streams:
raise ValueError("Cannot send data on unknown peer-initiated stream")
if stream_is_unidirectional(stream_id):
raise ValueError(
"Cannot send data on peer-initiated unidirectional stream"
)
stream = self._streams.get(stream_id, None)
if stream is None:
# determine limits
if stream_is_unidirectional(stream_id):
max_stream_data_local = 0
max_stream_data_remote = self._remote_max_stream_data_uni
max_streams = self._remote_max_streams_uni
streams_blocked = self._streams_blocked_uni
else:
max_stream_data_local = self._local_max_stream_data_bidi_local
max_stream_data_remote = self._remote_max_stream_data_bidi_remote
max_streams = self._remote_max_streams_bidi
streams_blocked = self._streams_blocked_bidi
# create stream
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),
)
# mark stream as blocked if needed
if stream_id // 4 >= max_streams:
stream.is_blocked = True
streams_blocked.append(stream)
self._streams_blocked_pending = True
return stream
===========changed ref 2===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream:
"""
Get or create a stream in response to a received frame.
"""
stream = self._streams.get(stream_id, None)
if stream is None:
# check initiator
if stream_is_client_initiated(stream_id) == self._is_client:
raise QuicConnectionError(
error_code=QuicErrorCode.STREAM_STATE_ERROR,
frame_type=frame_type,
reason_phrase="Wrong stream initiator",
)
# determine limits
if stream_is_unidirectional(stream_id):
max_stream_data_local = self._local_max_stream_data_uni
max_stream_data_remote = 0
max_streams = self._local_max_streams_uni
else:
max_stream_data_local = self._local_max_stream_data_bidi_remote
max_stream_data_remote = self._remote_max_stream_data_bidi_local
max_streams = self._local_max_streams_bidi
# check max streams
stream_count = (stream_id // 4) + 1
if stream_count > max_streams.value:
raise QuicConnectionError(
error_code=QuicErrorCode.STREAM_LIMIT_ERROR,
frame_type=frame_type,
reason_phrase="Too many streams open",
)
elif stream_count > max_streams.used:
max_streams.used = stream_count
# create stream
self._logger.debug("Stream %d created by peer" % 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,
+ writable=not stream_is_unidirectional</s>
===========changed ref 3===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream:
# offset: 1
<s> max_stream_data_remote=max_stream_data_remote,
+ writable=not stream_is_unidirectional(stream_id),
)
return stream
|
tests.test_stream/QuicStreamTest.test_recv_reset
|
Modified
|
aiortc~aioquic
|
978d64bc5bbb61f8db2c4168112820f31787b804
|
[streams] keep track of whether send / receive is finished
|
<5>:<add> self.assertTrue(stream._recv_finished)
|
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_reset(self):
<0> stream = QuicStream(stream_id=0)
<1> self.assertEqual(
<2> stream.handle_reset(final_size=4),
<3> StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
<4> )
<5>
|
===========unchanged ref 0===========
at: tests.test_stream.QuicStreamTest.test_recv_fin_without_data
stream = QuicStream(stream_id=0)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_fin_out_of_order(self):
stream = QuicStream(stream_id=0)
# add data at offset 8 with FIN
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=8, data=b"89012345", fin=True)),
None,
)
+ self.assertFalse(stream._recv_finished)
# add data at offset 0
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=0, data=b"01234567")),
StreamDataReceived(data=b"0123456789012345", end_stream=True, stream_id=0),
)
+ self.assertTrue(stream._recv_finished)
===========changed ref 1===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_ordered(self):
stream = QuicStream(stream_id=0)
# add data at start
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=0, data=b"01234567")),
StreamDataReceived(data=b"01234567", end_stream=False, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 8)
+ self.assertFalse(stream._recv_finished)
# add more data
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=8, data=b"89012345")),
StreamDataReceived(data=b"89012345", end_stream=False, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 16)
+ self.assertFalse(stream._recv_finished)
# add data and fin
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=16, data=b"67890123", fin=True)),
StreamDataReceived(data=b"67890123", end_stream=True, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 24)
+ self.assertTrue(stream._recv_finished)
===========changed ref 2===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream_for_send(self, stream_id: int) -> QuicStream:
"""
Get or create a QUIC stream in order to send data to the peer.
This always occurs as a result of an API call.
"""
if stream_is_client_initiated(stream_id) != self._is_client:
if stream_id not in self._streams:
raise ValueError("Cannot send data on unknown peer-initiated stream")
if stream_is_unidirectional(stream_id):
raise ValueError(
"Cannot send data on peer-initiated unidirectional stream"
)
stream = self._streams.get(stream_id, None)
if stream is None:
# determine limits
if stream_is_unidirectional(stream_id):
max_stream_data_local = 0
max_stream_data_remote = self._remote_max_stream_data_uni
max_streams = self._remote_max_streams_uni
streams_blocked = self._streams_blocked_uni
else:
max_stream_data_local = self._local_max_stream_data_bidi_local
max_stream_data_remote = self._remote_max_stream_data_bidi_remote
max_streams = self._remote_max_streams_bidi
streams_blocked = self._streams_blocked_bidi
# create stream
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),
)
# mark stream as blocked if needed
if stream_id // 4 >= max_streams:
stream.is_blocked = True
streams_blocked.append(stream)
self._streams_blocked_pending = True
return stream
===========changed ref 3===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream:
"""
Get or create a stream in response to a received frame.
"""
stream = self._streams.get(stream_id, None)
if stream is None:
# check initiator
if stream_is_client_initiated(stream_id) == self._is_client:
raise QuicConnectionError(
error_code=QuicErrorCode.STREAM_STATE_ERROR,
frame_type=frame_type,
reason_phrase="Wrong stream initiator",
)
# determine limits
if stream_is_unidirectional(stream_id):
max_stream_data_local = self._local_max_stream_data_uni
max_stream_data_remote = 0
max_streams = self._local_max_streams_uni
else:
max_stream_data_local = self._local_max_stream_data_bidi_remote
max_stream_data_remote = self._remote_max_stream_data_bidi_local
max_streams = self._local_max_streams_bidi
# check max streams
stream_count = (stream_id // 4) + 1
if stream_count > max_streams.value:
raise QuicConnectionError(
error_code=QuicErrorCode.STREAM_LIMIT_ERROR,
frame_type=frame_type,
reason_phrase="Too many streams open",
)
elif stream_count > max_streams.used:
max_streams.used = stream_count
# create stream
self._logger.debug("Stream %d created by peer" % 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,
+ writable=not stream_is_unidirectional</s>
===========changed ref 4===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream:
# offset: 1
<s> max_stream_data_remote=max_stream_data_remote,
+ writable=not stream_is_unidirectional(stream_id),
)
return stream
|
tests.test_stream/QuicStreamTest.test_send_data
|
Modified
|
aiortc~aioquic
|
978d64bc5bbb61f8db2c4168112820f31787b804
|
[streams] keep track of whether send / receive is finished
|
<36>:<add> self.assertFalse(stream._send_finished)
<39>:<add> self.assertFalse(stream._send_finished)
|
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_send_data(self):
<0> stream = QuicStream()
<1> self.assertEqual(stream.next_send_offset, 0)
<2>
<3> # nothing to send yet
<4> frame = stream.get_frame(8)
<5> self.assertIsNone(frame)
<6>
<7> # write data
<8> stream.write(b"0123456789012345")
<9> self.assertEqual(list(stream._send_pending), [range(0, 16)])
<10> self.assertEqual(stream.next_send_offset, 0)
<11>
<12> # send a chunk
<13> frame = stream.get_frame(8)
<14> self.assertEqual(frame.data, b"01234567")
<15> self.assertFalse(frame.fin)
<16> self.assertEqual(frame.offset, 0)
<17> self.assertEqual(list(stream._send_pending), [range(8, 16)])
<18> self.assertEqual(stream.next_send_offset, 8)
<19>
<20> # send another chunk
<21> frame = stream.get_frame(8)
<22> self.assertEqual(frame.data, b"89012345")
<23> self.assertFalse(frame.fin)
<24> self.assertEqual(frame.offset, 8)
<25> self.assertEqual(list(stream._send_pending), [])
<26> self.assertEqual(stream.next_send_offset, 16)
<27>
<28> # nothing more to send
<29> frame = stream.get_frame(8)
<30> self.assertIsNone(frame)
<31> self.assertEqual(list(stream._send_pending), [])
<32> self.assertEqual(stream.next_send_offset, 16)
<33>
<34> # first chunk gets acknowledged
<35> stream.on_data_delivery(QuicDeliveryState.ACKED, 0, 8)
<36>
<37> # second chunk gets acknowledged
<38> stream.on_data_delivery(QuicDeliveryState.ACKED, 8, 16)
<39>
|
===========unchanged ref 0===========
at: tests.test_stream.QuicStreamTest.test_recv_reset_twice_final_size_error
stream = QuicStream(stream_id=0)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
assertFalse(expr: Any, msg: Any=...) -> None
assertIsNone(obj: Any, msg: Any=...) -> None
assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E]
assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None
at: unittest.case._AssertRaisesContext.__exit__
self.exception = exc_value.with_traceback(None)
===========changed ref 0===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_reset(self):
stream = QuicStream(stream_id=0)
self.assertEqual(
stream.handle_reset(final_size=4),
StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
)
+ self.assertTrue(stream._recv_finished)
===========changed ref 1===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_fin_out_of_order(self):
stream = QuicStream(stream_id=0)
# add data at offset 8 with FIN
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=8, data=b"89012345", fin=True)),
None,
)
+ self.assertFalse(stream._recv_finished)
# add data at offset 0
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=0, data=b"01234567")),
StreamDataReceived(data=b"0123456789012345", end_stream=True, stream_id=0),
)
+ self.assertTrue(stream._recv_finished)
===========changed ref 2===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_ordered(self):
stream = QuicStream(stream_id=0)
# add data at start
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=0, data=b"01234567")),
StreamDataReceived(data=b"01234567", end_stream=False, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 8)
+ self.assertFalse(stream._recv_finished)
# add more data
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=8, data=b"89012345")),
StreamDataReceived(data=b"89012345", end_stream=False, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 16)
+ self.assertFalse(stream._recv_finished)
# add data and fin
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=16, data=b"67890123", fin=True)),
StreamDataReceived(data=b"67890123", end_stream=True, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 24)
+ self.assertTrue(stream._recv_finished)
===========changed ref 3===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream_for_send(self, stream_id: int) -> QuicStream:
"""
Get or create a QUIC stream in order to send data to the peer.
This always occurs as a result of an API call.
"""
if stream_is_client_initiated(stream_id) != self._is_client:
if stream_id not in self._streams:
raise ValueError("Cannot send data on unknown peer-initiated stream")
if stream_is_unidirectional(stream_id):
raise ValueError(
"Cannot send data on peer-initiated unidirectional stream"
)
stream = self._streams.get(stream_id, None)
if stream is None:
# determine limits
if stream_is_unidirectional(stream_id):
max_stream_data_local = 0
max_stream_data_remote = self._remote_max_stream_data_uni
max_streams = self._remote_max_streams_uni
streams_blocked = self._streams_blocked_uni
else:
max_stream_data_local = self._local_max_stream_data_bidi_local
max_stream_data_remote = self._remote_max_stream_data_bidi_remote
max_streams = self._remote_max_streams_bidi
streams_blocked = self._streams_blocked_bidi
# create stream
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),
)
# mark stream as blocked if needed
if stream_id // 4 >= max_streams:
stream.is_blocked = True
streams_blocked.append(stream)
self._streams_blocked_pending = True
return stream
|
tests.test_stream/QuicStreamTest.test_send_reset
|
Modified
|
aiortc~aioquic
|
978d64bc5bbb61f8db2c4168112820f31787b804
|
[streams] keep track of whether send / receive is finished
|
<11>:<add> self.assertFalse(stream._send_finished)
<12>:<add> # reset is acklowledged
<del> # reset is lost
<13>:<add> stream.on_reset_delivery(QuicDeliveryState.ACKED)
<del> stream.on_reset_delivery(QuicDeliveryState.LOST)
<14>:<add> self.assertFalse(stream.reset_pending)
<del> self.assertTrue(stream.reset_pending)
<15>:<add> self.assertTrue(stream._send_finished)
|
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_send_reset(self):
<0> stream = QuicStream()
<1>
<2> # reset is requested
<3> stream.reset(QuicErrorCode.NO_ERROR)
<4> self.assertTrue(stream.reset_pending)
<5>
<6> # reset is sent
<7> reset = stream.get_reset_frame()
<8> self.assertEqual(reset.error_code, QuicErrorCode.NO_ERROR)
<9> self.assertEqual(reset.final_size, 0)
<10> self.assertFalse(stream.reset_pending)
<11>
<12> # reset is lost
<13> stream.on_reset_delivery(QuicDeliveryState.LOST)
<14> self.assertTrue(stream.reset_pending)
<15>
|
===========unchanged ref 0===========
at: tests.test_stream.QuicStreamTest.test_send_fin_only_despite_blocked
stream = QuicStream()
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
assertTrue(expr: Any, msg: Any=...) -> None
assertFalse(expr: Any, msg: Any=...) -> None
assertIsNone(obj: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_reset(self):
stream = QuicStream(stream_id=0)
self.assertEqual(
stream.handle_reset(final_size=4),
StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
)
+ self.assertTrue(stream._recv_finished)
===========changed ref 1===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_fin_out_of_order(self):
stream = QuicStream(stream_id=0)
# add data at offset 8 with FIN
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=8, data=b"89012345", fin=True)),
None,
)
+ self.assertFalse(stream._recv_finished)
# add data at offset 0
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=0, data=b"01234567")),
StreamDataReceived(data=b"0123456789012345", end_stream=True, stream_id=0),
)
+ self.assertTrue(stream._recv_finished)
===========changed ref 2===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_send_data(self):
stream = QuicStream()
self.assertEqual(stream.next_send_offset, 0)
# nothing to send yet
frame = stream.get_frame(8)
self.assertIsNone(frame)
# write data
stream.write(b"0123456789012345")
self.assertEqual(list(stream._send_pending), [range(0, 16)])
self.assertEqual(stream.next_send_offset, 0)
# send a chunk
frame = stream.get_frame(8)
self.assertEqual(frame.data, b"01234567")
self.assertFalse(frame.fin)
self.assertEqual(frame.offset, 0)
self.assertEqual(list(stream._send_pending), [range(8, 16)])
self.assertEqual(stream.next_send_offset, 8)
# send another chunk
frame = stream.get_frame(8)
self.assertEqual(frame.data, b"89012345")
self.assertFalse(frame.fin)
self.assertEqual(frame.offset, 8)
self.assertEqual(list(stream._send_pending), [])
self.assertEqual(stream.next_send_offset, 16)
# nothing more to send
frame = stream.get_frame(8)
self.assertIsNone(frame)
self.assertEqual(list(stream._send_pending), [])
self.assertEqual(stream.next_send_offset, 16)
# first chunk gets acknowledged
stream.on_data_delivery(QuicDeliveryState.ACKED, 0, 8)
+ self.assertFalse(stream._send_finished)
# second chunk gets acknowledged
stream.on_data_delivery(QuicDeliveryState.ACKED, 8, 16)
+ self.assertFalse(stream._send_finished)
===========changed ref 3===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_ordered(self):
stream = QuicStream(stream_id=0)
# add data at start
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=0, data=b"01234567")),
StreamDataReceived(data=b"01234567", end_stream=False, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 8)
+ self.assertFalse(stream._recv_finished)
# add more data
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=8, data=b"89012345")),
StreamDataReceived(data=b"89012345", end_stream=False, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 16)
+ self.assertFalse(stream._recv_finished)
# add data and fin
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=16, data=b"67890123", fin=True)),
StreamDataReceived(data=b"67890123", end_stream=True, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 24)
+ self.assertTrue(stream._recv_finished)
===========changed ref 4===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream_for_send(self, stream_id: int) -> QuicStream:
"""
Get or create a QUIC stream in order to send data to the peer.
This always occurs as a result of an API call.
"""
if stream_is_client_initiated(stream_id) != self._is_client:
if stream_id not in self._streams:
raise ValueError("Cannot send data on unknown peer-initiated stream")
if stream_is_unidirectional(stream_id):
raise ValueError(
"Cannot send data on peer-initiated unidirectional stream"
)
stream = self._streams.get(stream_id, None)
if stream is None:
# determine limits
if stream_is_unidirectional(stream_id):
max_stream_data_local = 0
max_stream_data_remote = self._remote_max_stream_data_uni
max_streams = self._remote_max_streams_uni
streams_blocked = self._streams_blocked_uni
else:
max_stream_data_local = self._local_max_stream_data_bidi_local
max_stream_data_remote = self._remote_max_stream_data_bidi_remote
max_streams = self._remote_max_streams_bidi
streams_blocked = self._streams_blocked_bidi
# create stream
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),
)
# mark stream as blocked if needed
if stream_id // 4 >= max_streams:
stream.is_blocked = True
streams_blocked.append(stream)
self._streams_blocked_pending = True
return stream
|
aioquic.quic.stream/QuicStream.__init__
|
Modified
|
aiortc~aioquic
|
978d64bc5bbb61f8db2c4168112820f31787b804
|
[streams] keep track of whether send / receive is finished
|
<9>:<add> self._recv_finished = not readable
<17>:<add> self._send_finished = not writable
|
# module: aioquic.quic.stream
class QuicStream:
def __init__(
self,
stream_id: Optional[int] = None,
max_stream_data_local: int = 0,
max_stream_data_remote: int = 0,
+ readable: bool = True,
+ writable: bool = True,
) -> None:
<0> self.is_blocked = False
<1> self.max_stream_data_local = max_stream_data_local
<2> self.max_stream_data_local_sent = max_stream_data_local
<3> self.max_stream_data_remote = max_stream_data_remote
<4> self.send_buffer_is_empty = True
<5>
<6> self._recv_buffer = bytearray()
<7> self._recv_buffer_start = 0 # the offset for the start of the buffer
<8> self._recv_final_size: Optional[int] = None
<9> self._recv_highest = 0 # the highest offset ever seen
<10> self._recv_ranges = RangeSet()
<11>
<12> self._send_acked = RangeSet()
<13> self._send_buffer = bytearray()
<14> self._send_buffer_fin: Optional[int] = None
<15> self._send_buffer_start = 0 # the offset for the start of the buffer
<16> self._send_buffer_stop = 0 # the offset for the stop of the buffer
<17> self._send_highest = 0
<18> self._send_pending = RangeSet()
<19> self._send_pending_eof = False
<20> self._send_reset_error_code: Optional[int] = None
<21> self._send_reset_pending = False
<22>
<23> self.__stream_id = stream_id
<24>
|
===========unchanged ref 0===========
at: aioquic.quic.stream.QuicStream._pull_data
self._recv_buffer_start = r.stop
at: aioquic.quic.stream.QuicStream.add_frame
self._recv_final_size = frame_end
self._recv_highest = frame_end
self._recv_buffer_start += count
self._recv_finished = True
self._recv_buffer += bytearray(gap)
at: aioquic.quic.stream.QuicStream.get_frame
self._send_pending_eof = False
self.send_buffer_is_empty = True
self._send_highest = stop
at: aioquic.quic.stream.QuicStream.handle_reset
self._recv_final_size = final_size
self._recv_finished = True
at: aioquic.quic.stream.QuicStream.on_data_delivery
self.send_buffer_is_empty = False
self._send_buffer_start += size
self._send_finished = True
self._send_pending_eof = True
at: aioquic.quic.stream.QuicStream.on_reset_delivery
self._send_finished = True
at: aioquic.quic.stream.QuicStream.write
self.send_buffer_is_empty = False
self._send_buffer += data
self._send_buffer_stop += size
self._send_buffer_fin = self._send_buffer_stop
self._send_pending_eof = True
===========changed ref 0===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_reset(self):
stream = QuicStream(stream_id=0)
self.assertEqual(
stream.handle_reset(final_size=4),
StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
)
+ self.assertTrue(stream._recv_finished)
===========changed ref 1===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_fin_out_of_order(self):
stream = QuicStream(stream_id=0)
# add data at offset 8 with FIN
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=8, data=b"89012345", fin=True)),
None,
)
+ self.assertFalse(stream._recv_finished)
# add data at offset 0
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=0, data=b"01234567")),
StreamDataReceived(data=b"0123456789012345", end_stream=True, stream_id=0),
)
+ self.assertTrue(stream._recv_finished)
===========changed ref 2===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_send_reset(self):
stream = QuicStream()
# reset is requested
stream.reset(QuicErrorCode.NO_ERROR)
self.assertTrue(stream.reset_pending)
# reset is sent
reset = stream.get_reset_frame()
self.assertEqual(reset.error_code, QuicErrorCode.NO_ERROR)
self.assertEqual(reset.final_size, 0)
self.assertFalse(stream.reset_pending)
+ self.assertFalse(stream._send_finished)
+ # reset is acklowledged
- # reset is lost
+ stream.on_reset_delivery(QuicDeliveryState.ACKED)
- stream.on_reset_delivery(QuicDeliveryState.LOST)
+ self.assertFalse(stream.reset_pending)
- self.assertTrue(stream.reset_pending)
+ self.assertTrue(stream._send_finished)
===========changed ref 3===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
+ def test_send_reset_lost(self):
+ stream = QuicStream()
+
+ # reset is requested
+ stream.reset(QuicErrorCode.NO_ERROR)
+ self.assertTrue(stream.reset_pending)
+
+ # reset is sent
+ reset = stream.get_reset_frame()
+ self.assertEqual(reset.error_code, QuicErrorCode.NO_ERROR)
+ self.assertEqual(reset.final_size, 0)
+ self.assertFalse(stream.reset_pending)
+
+ # reset is lost
+ stream.on_reset_delivery(QuicDeliveryState.LOST)
+ self.assertTrue(stream.reset_pending)
+ self.assertFalse(stream._send_finished)
+
+ # reset is sent again
+ reset = stream.get_reset_frame()
+ self.assertEqual(reset.error_code, QuicErrorCode.NO_ERROR)
+ self.assertEqual(reset.final_size, 0)
+ self.assertFalse(stream.reset_pending)
+
+ # reset is acklowledged
+ stream.on_reset_delivery(QuicDeliveryState.ACKED)
+ self.assertFalse(stream.reset_pending)
+ self.assertTrue(stream._send_finished)
+
===========changed ref 4===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_ordered(self):
stream = QuicStream(stream_id=0)
# add data at start
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=0, data=b"01234567")),
StreamDataReceived(data=b"01234567", end_stream=False, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 8)
+ self.assertFalse(stream._recv_finished)
# add more data
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=8, data=b"89012345")),
StreamDataReceived(data=b"89012345", end_stream=False, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 16)
+ self.assertFalse(stream._recv_finished)
# add data and fin
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=16, data=b"67890123", fin=True)),
StreamDataReceived(data=b"67890123", end_stream=True, stream_id=0),
)
self.assertEqual(bytes(stream._recv_buffer), b"")
self.assertEqual(list(stream._recv_ranges), [])
self.assertEqual(stream._recv_buffer_start, 24)
+ self.assertTrue(stream._recv_finished)
|
aioquic.quic.stream/QuicStream.add_frame
|
Modified
|
aiortc~aioquic
|
978d64bc5bbb61f8db2c4168112820f31787b804
|
[streams] keep track of whether send / receive is finished
|
<21>:<add> if frame.fin:
<add> # all data up to the FIN has been received, we're done receiving
<add> self._recv_finished = True
|
# module: aioquic.quic.stream
class QuicStream:
# reader
def add_frame(self, frame: QuicStreamFrame) -> Optional[events.StreamDataReceived]:
<0> """
<1> Add a frame of received data.
<2> """
<3> pos = frame.offset - self._recv_buffer_start
<4> count = len(frame.data)
<5> frame_end = frame.offset + count
<6>
<7> # we should receive no more data beyond FIN!
<8> if self._recv_final_size is not None:
<9> if frame_end > self._recv_final_size:
<10> raise FinalSizeError("Data received beyond final size")
<11> elif frame.fin and frame_end != self._recv_final_size:
<12> raise FinalSizeError("Cannot change final size")
<13> if frame.fin:
<14> self._recv_final_size = frame_end
<15> if frame_end > self._recv_highest:
<16> self._recv_highest = frame_end
<17>
<18> # fast path: new in-order chunk
<19> if pos == 0 and count and not self._recv_buffer:
<20> self._recv_buffer_start += count
<21> return events.StreamDataReceived(
<22> data=frame.data, end_stream=frame.fin, stream_id=self.__stream_id
<23> )
<24>
<25> # discard duplicate data
<26> if pos < 0:
<27> frame.data = frame.data[-pos:]
<28> frame.offset -= pos
<29> pos = 0
<30> count = len(frame.data)
<31>
<32> # marked received range
<33> if frame_end > frame.offset:
<34> self._recv_ranges.add(frame.offset, frame_end)
<35>
<36> # add new data
<37> gap = pos - len(self._recv_buffer)
<38> if gap > 0:
<39> self._recv_buffer += bytearray(gap)
<40> self._recv_buffer[pos : pos + count] = frame.data
<41>
<42> # return data from the front of the buffer
<43> data = self._pull</s>
|
===========below chunk 0===========
# module: aioquic.quic.stream
class QuicStream:
# reader
def add_frame(self, frame: QuicStreamFrame) -> Optional[events.StreamDataReceived]:
# offset: 1
end_stream = self._recv_buffer_start == self._recv_final_size
if data or end_stream:
return events.StreamDataReceived(
data=data, end_stream=end_stream, stream_id=self.__stream_id
)
else:
return None
===========unchanged ref 0===========
at: aioquic.quic.stream
FinalSizeError(*args: object)
at: aioquic.quic.stream.QuicStream.__init__
self._recv_buffer = bytearray()
self._recv_buffer_start = 0 # the offset for the start of the buffer
self._recv_final_size: Optional[int] = None
self._recv_finished = not readable
self._recv_highest = 0 # the highest offset ever seen
self._recv_ranges = RangeSet()
self._send_reset_pending = False
self.__stream_id = stream_id
at: aioquic.quic.stream.QuicStream._pull_data
self._recv_buffer_start = r.stop
at: aioquic.quic.stream.QuicStream.get_reset_frame
self._send_reset_pending = False
at: aioquic.quic.stream.QuicStream.handle_reset
self._recv_final_size = final_size
self._recv_finished = True
at: aioquic.quic.stream.QuicStream.on_reset_delivery
self._send_reset_pending = True
at: aioquic.quic.stream.QuicStream.reset
self._send_reset_pending = True
===========changed ref 0===========
# module: aioquic.quic.stream
class QuicStream:
+ @property
+ def is_disposable(self) -> bool:
+ return self._recv_finished and self._send_finished
+
===========changed ref 1===========
# module: aioquic.quic.stream
class QuicStream:
def __init__(
self,
stream_id: Optional[int] = None,
max_stream_data_local: int = 0,
max_stream_data_remote: int = 0,
+ readable: bool = True,
+ writable: bool = True,
) -> None:
self.is_blocked = False
self.max_stream_data_local = max_stream_data_local
self.max_stream_data_local_sent = max_stream_data_local
self.max_stream_data_remote = max_stream_data_remote
self.send_buffer_is_empty = True
self._recv_buffer = bytearray()
self._recv_buffer_start = 0 # the offset for the start of the buffer
self._recv_final_size: Optional[int] = None
+ self._recv_finished = not readable
self._recv_highest = 0 # the highest offset ever seen
self._recv_ranges = RangeSet()
self._send_acked = RangeSet()
self._send_buffer = bytearray()
self._send_buffer_fin: Optional[int] = None
self._send_buffer_start = 0 # the offset for the start of the buffer
self._send_buffer_stop = 0 # the offset for the stop of the buffer
+ self._send_finished = not writable
self._send_highest = 0
self._send_pending = RangeSet()
self._send_pending_eof = False
self._send_reset_error_code: Optional[int] = None
self._send_reset_pending = False
self.__stream_id = stream_id
===========changed ref 2===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_reset(self):
stream = QuicStream(stream_id=0)
self.assertEqual(
stream.handle_reset(final_size=4),
StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
)
+ self.assertTrue(stream._recv_finished)
===========changed ref 3===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_fin_out_of_order(self):
stream = QuicStream(stream_id=0)
# add data at offset 8 with FIN
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=8, data=b"89012345", fin=True)),
None,
)
+ self.assertFalse(stream._recv_finished)
# add data at offset 0
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=0, data=b"01234567")),
StreamDataReceived(data=b"0123456789012345", end_stream=True, stream_id=0),
)
+ self.assertTrue(stream._recv_finished)
===========changed ref 4===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_send_reset(self):
stream = QuicStream()
# reset is requested
stream.reset(QuicErrorCode.NO_ERROR)
self.assertTrue(stream.reset_pending)
# reset is sent
reset = stream.get_reset_frame()
self.assertEqual(reset.error_code, QuicErrorCode.NO_ERROR)
self.assertEqual(reset.final_size, 0)
self.assertFalse(stream.reset_pending)
+ self.assertFalse(stream._send_finished)
+ # reset is acklowledged
- # reset is lost
+ stream.on_reset_delivery(QuicDeliveryState.ACKED)
- stream.on_reset_delivery(QuicDeliveryState.LOST)
+ self.assertFalse(stream.reset_pending)
- self.assertTrue(stream.reset_pending)
+ self.assertTrue(stream._send_finished)
===========changed ref 5===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
+ def test_send_reset_lost(self):
+ stream = QuicStream()
+
+ # reset is requested
+ stream.reset(QuicErrorCode.NO_ERROR)
+ self.assertTrue(stream.reset_pending)
+
+ # reset is sent
+ reset = stream.get_reset_frame()
+ self.assertEqual(reset.error_code, QuicErrorCode.NO_ERROR)
+ self.assertEqual(reset.final_size, 0)
+ self.assertFalse(stream.reset_pending)
+
+ # reset is lost
+ stream.on_reset_delivery(QuicDeliveryState.LOST)
+ self.assertTrue(stream.reset_pending)
+ self.assertFalse(stream._send_finished)
+
+ # reset is sent again
+ reset = stream.get_reset_frame()
+ self.assertEqual(reset.error_code, QuicErrorCode.NO_ERROR)
+ self.assertEqual(reset.final_size, 0)
+ self.assertFalse(stream.reset_pending)
+
+ # reset is acklowledged
+ stream.on_reset_delivery(QuicDeliveryState.ACKED)
+ self.assertFalse(stream.reset_pending)
+ self.assertTrue(stream._send_finished)
+
|
aioquic.quic.stream/QuicStream.handle_reset
|
Modified
|
aiortc~aioquic
|
978d64bc5bbb61f8db2c4168112820f31787b804
|
[streams] keep track of whether send / receive is finished
|
<5>:<add>
<add> # we are done receiving
<6>:<add> self._recv_finished = True
|
# module: aioquic.quic.stream
class QuicStream:
def handle_reset(
self, *, final_size: int, error_code: int = QuicErrorCode.NO_ERROR
) -> Optional[events.StreamReset]:
<0> """
<1> Handle an abrupt termination of the receiving part of the QUIC stream.
<2> """
<3> if self._recv_final_size is not None and final_size != self._recv_final_size:
<4> raise FinalSizeError("Cannot change final size")
<5> self._recv_final_size = final_size
<6> return events.StreamReset(error_code=error_code, stream_id=self.__stream_id)
<7>
|
===========changed ref 0===========
# module: aioquic.quic.stream
class QuicStream:
+ @property
+ def is_disposable(self) -> bool:
+ return self._recv_finished and self._send_finished
+
===========changed ref 1===========
# module: aioquic.quic.stream
class QuicStream:
def __init__(
self,
stream_id: Optional[int] = None,
max_stream_data_local: int = 0,
max_stream_data_remote: int = 0,
+ readable: bool = True,
+ writable: bool = True,
) -> None:
self.is_blocked = False
self.max_stream_data_local = max_stream_data_local
self.max_stream_data_local_sent = max_stream_data_local
self.max_stream_data_remote = max_stream_data_remote
self.send_buffer_is_empty = True
self._recv_buffer = bytearray()
self._recv_buffer_start = 0 # the offset for the start of the buffer
self._recv_final_size: Optional[int] = None
+ self._recv_finished = not readable
self._recv_highest = 0 # the highest offset ever seen
self._recv_ranges = RangeSet()
self._send_acked = RangeSet()
self._send_buffer = bytearray()
self._send_buffer_fin: Optional[int] = None
self._send_buffer_start = 0 # the offset for the start of the buffer
self._send_buffer_stop = 0 # the offset for the stop of the buffer
+ self._send_finished = not writable
self._send_highest = 0
self._send_pending = RangeSet()
self._send_pending_eof = False
self._send_reset_error_code: Optional[int] = None
self._send_reset_pending = False
self.__stream_id = stream_id
===========changed ref 2===========
# module: aioquic.quic.stream
class QuicStream:
# reader
def add_frame(self, frame: QuicStreamFrame) -> Optional[events.StreamDataReceived]:
"""
Add a frame of received data.
"""
pos = frame.offset - self._recv_buffer_start
count = len(frame.data)
frame_end = frame.offset + count
# we should receive no more data beyond FIN!
if self._recv_final_size is not None:
if frame_end > self._recv_final_size:
raise FinalSizeError("Data received beyond final size")
elif frame.fin and frame_end != self._recv_final_size:
raise FinalSizeError("Cannot change final size")
if frame.fin:
self._recv_final_size = frame_end
if frame_end > self._recv_highest:
self._recv_highest = frame_end
# fast path: new in-order chunk
if pos == 0 and count and not self._recv_buffer:
self._recv_buffer_start += count
+ if frame.fin:
+ # all data up to the FIN has been received, we're done receiving
+ self._recv_finished = True
return events.StreamDataReceived(
data=frame.data, end_stream=frame.fin, stream_id=self.__stream_id
)
# discard duplicate data
if pos < 0:
frame.data = frame.data[-pos:]
frame.offset -= pos
pos = 0
count = len(frame.data)
# marked received range
if frame_end > frame.offset:
self._recv_ranges.add(frame.offset, frame_end)
# add new data
gap = pos - len(self._recv_buffer)
if gap > 0:
self._recv_buffer += bytearray(gap)
self._recv_buffer[pos : pos + count] = frame.data
# return data from the front of the buffer
data = self._pull_data()
end_stream</s>
===========changed ref 3===========
# module: aioquic.quic.stream
class QuicStream:
# reader
def add_frame(self, frame: QuicStreamFrame) -> Optional[events.StreamDataReceived]:
# offset: 1
<s> frame.data
# return data from the front of the buffer
data = self._pull_data()
end_stream = self._recv_buffer_start == self._recv_final_size
+ if end_stream:
+ # all data up to the FIN has been received, we're done receiving
+ self._recv_finished = True
if data or end_stream:
return events.StreamDataReceived(
data=data, end_stream=end_stream, stream_id=self.__stream_id
)
else:
return None
===========changed ref 4===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_reset(self):
stream = QuicStream(stream_id=0)
self.assertEqual(
stream.handle_reset(final_size=4),
StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
)
+ self.assertTrue(stream._recv_finished)
===========changed ref 5===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_fin_out_of_order(self):
stream = QuicStream(stream_id=0)
# add data at offset 8 with FIN
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=8, data=b"89012345", fin=True)),
None,
)
+ self.assertFalse(stream._recv_finished)
# add data at offset 0
self.assertEqual(
stream.add_frame(QuicStreamFrame(offset=0, data=b"01234567")),
StreamDataReceived(data=b"0123456789012345", end_stream=True, stream_id=0),
)
+ self.assertTrue(stream._recv_finished)
===========changed ref 6===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_send_reset(self):
stream = QuicStream()
# reset is requested
stream.reset(QuicErrorCode.NO_ERROR)
self.assertTrue(stream.reset_pending)
# reset is sent
reset = stream.get_reset_frame()
self.assertEqual(reset.error_code, QuicErrorCode.NO_ERROR)
self.assertEqual(reset.final_size, 0)
self.assertFalse(stream.reset_pending)
+ self.assertFalse(stream._send_finished)
+ # reset is acklowledged
- # reset is lost
+ stream.on_reset_delivery(QuicDeliveryState.ACKED)
- stream.on_reset_delivery(QuicDeliveryState.LOST)
+ self.assertFalse(stream.reset_pending)
- self.assertTrue(stream.reset_pending)
+ self.assertTrue(stream._send_finished)
|
aioquic.quic.stream/QuicStream.on_data_delivery
|
Modified
|
aiortc~aioquic
|
978d64bc5bbb61f8db2c4168112820f31787b804
|
[streams] keep track of whether send / receive is finished
|
<13>:<add>
<add> if stop == self._send_buffer_fin:
<add> # the FIN has been ACK'd, we're done sending
<add> self._send_finished = True
|
# module: aioquic.quic.stream
class QuicStream:
def on_data_delivery(
self, delivery: QuicDeliveryState, start: int, stop: int
) -> None:
<0> """
<1> Callback when sent data is ACK'd.
<2> """
<3> self.send_buffer_is_empty = False
<4> if delivery == QuicDeliveryState.ACKED:
<5> if stop > start:
<6> self._send_acked.add(start, stop)
<7> first_range = self._send_acked[0]
<8> if first_range.start == self._send_buffer_start:
<9> size = first_range.stop - first_range.start
<10> self._send_acked.shift()
<11> self._send_buffer_start += size
<12> del self._send_buffer[:size]
<13> else:
<14> if stop > start:
<15> self._send_pending.add(start, stop)
<16> if stop == self._send_buffer_fin:
<17> self.send_buffer_empty = False
<18> self._send_pending_eof = True
<19>
|
===========unchanged ref 0===========
at: aioquic.quic.stream.QuicStream.__init__
self._send_buffer_fin: Optional[int] = None
self._send_highest = 0
self._send_pending_eof = False
self._send_reset_error_code: Optional[int] = None
self._send_reset_pending = False
at: aioquic.quic.stream.QuicStream.get_frame
stop = min(r.stop, start + max_size)
stop = max_offset
frame = QuicStreamFrame(
data=bytes(
self._send_buffer[
start - self._send_buffer_start : stop - self._send_buffer_start
]
),
offset=start,
)
at: aioquic.quic.stream.QuicStream.on_data_delivery
self._send_pending_eof = True
at: aioquic.quic.stream.QuicStream.on_reset_delivery
self._send_reset_pending = True
at: aioquic.quic.stream.QuicStream.reset
self._send_reset_error_code = error_code
self._send_reset_pending = True
at: aioquic.quic.stream.QuicStream.write
self._send_buffer_fin = self._send_buffer_stop
self._send_pending_eof = True
===========changed ref 0===========
# module: aioquic.quic.stream
class QuicStream:
+ @property
+ def is_disposable(self) -> bool:
+ return self._recv_finished and self._send_finished
+
===========changed ref 1===========
# module: aioquic.quic.stream
class QuicStream:
def handle_reset(
self, *, final_size: int, error_code: int = QuicErrorCode.NO_ERROR
) -> Optional[events.StreamReset]:
"""
Handle an abrupt termination of the receiving part of the QUIC stream.
"""
if self._recv_final_size is not None and final_size != self._recv_final_size:
raise FinalSizeError("Cannot change final size")
+
+ # we are done receiving
self._recv_final_size = final_size
+ self._recv_finished = True
return events.StreamReset(error_code=error_code, stream_id=self.__stream_id)
===========changed ref 2===========
# module: aioquic.quic.stream
class QuicStream:
def __init__(
self,
stream_id: Optional[int] = None,
max_stream_data_local: int = 0,
max_stream_data_remote: int = 0,
+ readable: bool = True,
+ writable: bool = True,
) -> None:
self.is_blocked = False
self.max_stream_data_local = max_stream_data_local
self.max_stream_data_local_sent = max_stream_data_local
self.max_stream_data_remote = max_stream_data_remote
self.send_buffer_is_empty = True
self._recv_buffer = bytearray()
self._recv_buffer_start = 0 # the offset for the start of the buffer
self._recv_final_size: Optional[int] = None
+ self._recv_finished = not readable
self._recv_highest = 0 # the highest offset ever seen
self._recv_ranges = RangeSet()
self._send_acked = RangeSet()
self._send_buffer = bytearray()
self._send_buffer_fin: Optional[int] = None
self._send_buffer_start = 0 # the offset for the start of the buffer
self._send_buffer_stop = 0 # the offset for the stop of the buffer
+ self._send_finished = not writable
self._send_highest = 0
self._send_pending = RangeSet()
self._send_pending_eof = False
self._send_reset_error_code: Optional[int] = None
self._send_reset_pending = False
self.__stream_id = stream_id
===========changed ref 3===========
# module: aioquic.quic.stream
class QuicStream:
# reader
def add_frame(self, frame: QuicStreamFrame) -> Optional[events.StreamDataReceived]:
"""
Add a frame of received data.
"""
pos = frame.offset - self._recv_buffer_start
count = len(frame.data)
frame_end = frame.offset + count
# we should receive no more data beyond FIN!
if self._recv_final_size is not None:
if frame_end > self._recv_final_size:
raise FinalSizeError("Data received beyond final size")
elif frame.fin and frame_end != self._recv_final_size:
raise FinalSizeError("Cannot change final size")
if frame.fin:
self._recv_final_size = frame_end
if frame_end > self._recv_highest:
self._recv_highest = frame_end
# fast path: new in-order chunk
if pos == 0 and count and not self._recv_buffer:
self._recv_buffer_start += count
+ if frame.fin:
+ # all data up to the FIN has been received, we're done receiving
+ self._recv_finished = True
return events.StreamDataReceived(
data=frame.data, end_stream=frame.fin, stream_id=self.__stream_id
)
# discard duplicate data
if pos < 0:
frame.data = frame.data[-pos:]
frame.offset -= pos
pos = 0
count = len(frame.data)
# marked received range
if frame_end > frame.offset:
self._recv_ranges.add(frame.offset, frame_end)
# add new data
gap = pos - len(self._recv_buffer)
if gap > 0:
self._recv_buffer += bytearray(gap)
self._recv_buffer[pos : pos + count] = frame.data
# return data from the front of the buffer
data = self._pull_data()
end_stream</s>
===========changed ref 4===========
# module: aioquic.quic.stream
class QuicStream:
# reader
def add_frame(self, frame: QuicStreamFrame) -> Optional[events.StreamDataReceived]:
# offset: 1
<s> frame.data
# return data from the front of the buffer
data = self._pull_data()
end_stream = self._recv_buffer_start == self._recv_final_size
+ if end_stream:
+ # all data up to the FIN has been received, we're done receiving
+ self._recv_finished = True
if data or end_stream:
return events.StreamDataReceived(
data=data, end_stream=end_stream, stream_id=self.__stream_id
)
else:
return None
===========changed ref 5===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_reset(self):
stream = QuicStream(stream_id=0)
self.assertEqual(
stream.handle_reset(final_size=4),
StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
)
+ self.assertTrue(stream._recv_finished)
|
aioquic.quic.stream/QuicStream.on_reset_delivery
|
Modified
|
aiortc~aioquic
|
978d64bc5bbb61f8db2c4168112820f31787b804
|
[streams] keep track of whether send / receive is finished
|
<3>:<add> if delivery == QuicDeliveryState.ACKED:
<del> if delivery != QuicDeliveryState.ACKED:
<4>:<add> # the reset has been ACK'd, we're done sending
<add> self._send_finished = True
<add> else:
|
# module: aioquic.quic.stream
class QuicStream:
def on_reset_delivery(self, delivery: QuicDeliveryState) -> None:
<0> """
<1> Callback when a reset is ACK'd.
<2> """
<3> if delivery != QuicDeliveryState.ACKED:
<4> self._send_reset_pending = True
<5>
|
===========unchanged ref 0===========
at: aioquic.quic.stream.QuicStream.__init__
self.send_buffer_is_empty = True
self._send_acked = RangeSet()
self._send_buffer_start = 0 # the offset for the start of the buffer
at: aioquic.quic.stream.QuicStream.get_frame
self.send_buffer_is_empty = True
at: aioquic.quic.stream.QuicStream.on_data_delivery
self._send_buffer_start += size
at: aioquic.quic.stream.QuicStream.write
self.send_buffer_is_empty = False
===========changed ref 0===========
# module: aioquic.quic.stream
class QuicStream:
+ @property
+ def is_disposable(self) -> bool:
+ return self._recv_finished and self._send_finished
+
===========changed ref 1===========
# module: aioquic.quic.stream
class QuicStream:
def handle_reset(
self, *, final_size: int, error_code: int = QuicErrorCode.NO_ERROR
) -> Optional[events.StreamReset]:
"""
Handle an abrupt termination of the receiving part of the QUIC stream.
"""
if self._recv_final_size is not None and final_size != self._recv_final_size:
raise FinalSizeError("Cannot change final size")
+
+ # we are done receiving
self._recv_final_size = final_size
+ self._recv_finished = True
return events.StreamReset(error_code=error_code, stream_id=self.__stream_id)
===========changed ref 2===========
# module: aioquic.quic.stream
class QuicStream:
def on_data_delivery(
self, delivery: QuicDeliveryState, start: int, stop: int
) -> None:
"""
Callback when sent data is ACK'd.
"""
self.send_buffer_is_empty = False
if delivery == QuicDeliveryState.ACKED:
if stop > start:
self._send_acked.add(start, stop)
first_range = self._send_acked[0]
if first_range.start == self._send_buffer_start:
size = first_range.stop - first_range.start
self._send_acked.shift()
self._send_buffer_start += size
del self._send_buffer[:size]
+
+ if stop == self._send_buffer_fin:
+ # the FIN has been ACK'd, we're done sending
+ self._send_finished = True
else:
if stop > start:
self._send_pending.add(start, stop)
if stop == self._send_buffer_fin:
self.send_buffer_empty = False
self._send_pending_eof = True
===========changed ref 3===========
# module: aioquic.quic.stream
class QuicStream:
def __init__(
self,
stream_id: Optional[int] = None,
max_stream_data_local: int = 0,
max_stream_data_remote: int = 0,
+ readable: bool = True,
+ writable: bool = True,
) -> None:
self.is_blocked = False
self.max_stream_data_local = max_stream_data_local
self.max_stream_data_local_sent = max_stream_data_local
self.max_stream_data_remote = max_stream_data_remote
self.send_buffer_is_empty = True
self._recv_buffer = bytearray()
self._recv_buffer_start = 0 # the offset for the start of the buffer
self._recv_final_size: Optional[int] = None
+ self._recv_finished = not readable
self._recv_highest = 0 # the highest offset ever seen
self._recv_ranges = RangeSet()
self._send_acked = RangeSet()
self._send_buffer = bytearray()
self._send_buffer_fin: Optional[int] = None
self._send_buffer_start = 0 # the offset for the start of the buffer
self._send_buffer_stop = 0 # the offset for the stop of the buffer
+ self._send_finished = not writable
self._send_highest = 0
self._send_pending = RangeSet()
self._send_pending_eof = False
self._send_reset_error_code: Optional[int] = None
self._send_reset_pending = False
self.__stream_id = stream_id
===========changed ref 4===========
# module: aioquic.quic.stream
class QuicStream:
# reader
def add_frame(self, frame: QuicStreamFrame) -> Optional[events.StreamDataReceived]:
"""
Add a frame of received data.
"""
pos = frame.offset - self._recv_buffer_start
count = len(frame.data)
frame_end = frame.offset + count
# we should receive no more data beyond FIN!
if self._recv_final_size is not None:
if frame_end > self._recv_final_size:
raise FinalSizeError("Data received beyond final size")
elif frame.fin and frame_end != self._recv_final_size:
raise FinalSizeError("Cannot change final size")
if frame.fin:
self._recv_final_size = frame_end
if frame_end > self._recv_highest:
self._recv_highest = frame_end
# fast path: new in-order chunk
if pos == 0 and count and not self._recv_buffer:
self._recv_buffer_start += count
+ if frame.fin:
+ # all data up to the FIN has been received, we're done receiving
+ self._recv_finished = True
return events.StreamDataReceived(
data=frame.data, end_stream=frame.fin, stream_id=self.__stream_id
)
# discard duplicate data
if pos < 0:
frame.data = frame.data[-pos:]
frame.offset -= pos
pos = 0
count = len(frame.data)
# marked received range
if frame_end > frame.offset:
self._recv_ranges.add(frame.offset, frame_end)
# add new data
gap = pos - len(self._recv_buffer)
if gap > 0:
self._recv_buffer += bytearray(gap)
self._recv_buffer[pos : pos + count] = frame.data
# return data from the front of the buffer
data = self._pull_data()
end_stream</s>
===========changed ref 5===========
# module: aioquic.quic.stream
class QuicStream:
# reader
def add_frame(self, frame: QuicStreamFrame) -> Optional[events.StreamDataReceived]:
# offset: 1
<s> frame.data
# return data from the front of the buffer
data = self._pull_data()
end_stream = self._recv_buffer_start == self._recv_final_size
+ if end_stream:
+ # all data up to the FIN has been received, we're done receiving
+ self._recv_finished = True
if data or end_stream:
return events.StreamDataReceived(
data=data, end_stream=end_stream, stream_id=self.__stream_id
)
else:
return None
===========changed ref 6===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
def test_recv_reset(self):
stream = QuicStream(stream_id=0)
self.assertEqual(
stream.handle_reset(final_size=4),
StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
)
+ self.assertTrue(stream._recv_finished)
|
aioquic.quic.connection/QuicConnection.reset_stream
|
Modified
|
aiortc~aioquic
|
5e39294f9a64b565b552419a85f4984c384e36be
|
[streams] split into QuicStreamReceiver / QuicStreamSender
|
<7>:<add> stream.sender.reset(error_code)
<del> stream.reset(error_code)
|
# module: aioquic.quic.connection
class QuicConnection:
def reset_stream(self, stream_id: int, error_code: int) -> None:
<0> """
<1> Abruptly terminate the sending part of a stream.
<2>
<3> :param stream_id: The stream's ID.
<4> :param error_code: An error code indicating why the stream is being reset.
<5> """
<6> stream = self._get_or_create_stream_for_send(stream_id)
<7> stream.reset(error_code)
<8>
|
===========unchanged ref 0===========
at: aioquic.quic.connection.QuicConnection
_get_or_create_stream_for_send(stream_id: int) -> QuicStream
|
aioquic.quic.connection/QuicConnection.send_stream_data
|
Modified
|
aiortc~aioquic
|
5e39294f9a64b565b552419a85f4984c384e36be
|
[streams] split into QuicStreamReceiver / QuicStreamSender
|
<8>:<add> stream.sender.write(data, end_stream=end_stream)
<del> stream.write(data, end_stream=end_stream)
|
# module: aioquic.quic.connection
class QuicConnection:
def send_stream_data(
self, stream_id: int, data: bytes, end_stream: bool = False
) -> None:
<0> """
<1> Send data on the specific stream.
<2>
<3> :param stream_id: The stream's ID.
<4> :param data: The data to be sent.
<5> :param end_stream: If set to `True`, the FIN bit will be set.
<6> """
<7> stream = self._get_or_create_stream_for_send(stream_id)
<8> stream.write(data, end_stream=end_stream)
<9>
|
===========unchanged ref 0===========
at: aioquic.quic.connection.QuicConnection
_get_or_create_stream_for_send(stream_id: int) -> QuicStream
===========changed ref 0===========
# module: aioquic.quic.connection
class QuicConnection:
def reset_stream(self, stream_id: int, error_code: int) -> None:
"""
Abruptly terminate the sending part of a stream.
:param stream_id: The stream's ID.
:param error_code: An error code indicating why the stream is being reset.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.reset(error_code)
- stream.reset(error_code)
|
aioquic.quic.connection/QuicConnection._handle_crypto_frame
|
Modified
|
aiortc~aioquic
|
5e39294f9a64b565b552419a85f4984c384e36be
|
[streams] split into QuicStreamReceiver / QuicStreamSender
|
<20>:<add> event = stream.receiver.handle_frame(frame)
<del> event = stream.add_frame(frame)
|
# module: aioquic.quic.connection
class QuicConnection:
def _handle_crypto_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
<0> """
<1> Handle a CRYPTO frame.
<2> """
<3> offset = buf.pull_uint_var()
<4> length = buf.pull_uint_var()
<5> if offset + length > UINT_VAR_MAX:
<6> raise QuicConnectionError(
<7> error_code=QuicErrorCode.FRAME_ENCODING_ERROR,
<8> frame_type=frame_type,
<9> reason_phrase="offset + length cannot exceed 2^62 - 1",
<10> )
<11> frame = QuicStreamFrame(offset=offset, data=buf.pull_bytes(length))
<12>
<13> # log frame
<14> if self._quic_logger is not None:
<15> context.quic_logger_frames.append(
<16> self._quic_logger.encode_crypto_frame(frame)
<17> )
<18>
<19> stream = self._crypto_streams[context.epoch]
<20> event = stream.add_frame(frame)
<21> if event is not None:
<22> # pass data to TLS layer
<23> try:
<24> self.tls.handle_message(event.data, self._crypto_buffers)
<25> self._push_crypto_data()
<26> except tls.Alert as exc:
<27> raise QuicConnectionError(
<28> error_code=QuicErrorCode.CRYPTO_ERROR + int(exc.description),
<29> frame_type=frame_type,
<30> reason_phrase=str(exc),
<31> )
<32>
<33> # parse transport parameters
<34> if (
<35> not self._parameters_received
<36> and self.tls.received_extensions is not None
<37> ):
<38> for ext_type, ext_data in self.tls.received_extensions:
<39> if ext_type == get_transport_parameters_extension(self._version):
<40> self._parse_transport_parameters(ext_data)
<41> self._parameters_received = True
<42> </s>
|
===========below chunk 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_crypto_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
# offset: 1
if not self._parameters_received:
raise QuicConnectionError(
error_code=QuicErrorCode.CRYPTO_ERROR
+ tls.AlertDescription.missing_extension,
frame_type=frame_type,
reason_phrase="No QUIC transport parameters received",
)
# update current epoch
if not self._handshake_complete and self.tls.state in [
tls.State.CLIENT_POST_HANDSHAKE,
tls.State.SERVER_POST_HANDSHAKE,
]:
self._handshake_complete = True
# for servers, the handshake is now confirmed
if not self._is_client:
self._discard_epoch(tls.Epoch.HANDSHAKE)
self._handshake_confirmed = True
self._handshake_done_pending = True
self._replenish_connection_ids()
self._events.append(
events.HandshakeCompleted(
alpn_protocol=self.tls.alpn_negotiated,
early_data_accepted=self.tls.early_data_accepted,
session_resumed=self.tls.session_resumed,
)
)
self._unblock_streams(is_unidirectional=False)
self._unblock_streams(is_unidirectional=True)
self._logger.info(
"ALPN negotiated protocol %s", self.tls.alpn_negotiated
)
===========unchanged ref 0===========
at: aioquic.quic.connection
get_transport_parameters_extension(version: int) -> tls.ExtensionType
QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)
QuicReceiveContext(epoch: tls.Epoch, host_cid: bytes, network_path: QuicNetworkPath, quic_logger_frames: Optional[List[Any]], time: float)
at: aioquic.quic.connection.QuicConnection
_discard_epoch(epoch: tls.Epoch) -> None
_replenish_connection_ids() -> None
_push_crypto_data() -> None
_push_crypto_data(self) -> None
_parse_transport_parameters(data: bytes, from_session_ticket: bool=False) -> None
_unblock_streams(is_unidirectional: bool) -> None
at: aioquic.quic.connection.QuicConnection.__init__
self._is_client = configuration.is_client
self._crypto_buffers: Dict[tls.Epoch, Buffer] = {}
self._crypto_streams: Dict[tls.Epoch, QuicStream] = {}
self._events: Deque[events.QuicEvent] = deque()
self._handshake_complete = False
self._handshake_confirmed = False
self._parameters_received = False
self._quic_logger: Optional[QuicLoggerTrace] = None
self._quic_logger = configuration.quic_logger.start_trace(
is_client=configuration.is_client,
odcid=self._original_destination_connection_id,
)
self._version: Optional[int] = None
self._logger = QuicConnectionAdapter(
logger, {"id": dump_cid(self._original_destination_connection_id)}
)
self._handshake_done_pending = False
at: aioquic.quic.connection.QuicConnection._close_end
self._quic_logger = None
===========unchanged ref 1===========
at: aioquic.quic.connection.QuicConnection._handle_handshake_done_frame
self._handshake_confirmed = True
at: aioquic.quic.connection.QuicConnection._initialize
self.tls = tls.Context(
alpn_protocols=self._configuration.alpn_protocols,
cadata=self._configuration.cadata,
cafile=self._configuration.cafile,
capath=self._configuration.capath,
cipher_suites=self.configuration.cipher_suites,
is_client=self._is_client,
logger=self._logger,
max_early_data=None if self._is_client else MAX_EARLY_DATA,
server_name=self._configuration.server_name,
verify_mode=self._configuration.verify_mode,
)
self._crypto_buffers = {
tls.Epoch.INITIAL: Buffer(capacity=CRYPTO_BUFFER_SIZE),
tls.Epoch.HANDSHAKE: Buffer(capacity=CRYPTO_BUFFER_SIZE),
tls.Epoch.ONE_RTT: Buffer(capacity=CRYPTO_BUFFER_SIZE),
}
self._crypto_streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
at: aioquic.quic.connection.QuicConnection._on_handshake_done_delivery
self._handshake_done_pending = True
at: aioquic.quic.connection.QuicConnection._write_application
self._handshake_done_pending = False
at: aioquic.quic.connection.QuicConnection.connect
self._version = self._configuration.supported_versions[0]
at: aioquic.quic.connection.QuicConnection.receive_datagram
self._version = QuicProtocolVersion(header.version)
self._version = QuicProtocolVersion(common[0])
at: aioquic.quic.connection.QuicReceiveContext
epoch: tls.Epoch
===========unchanged ref 2===========
host_cid: bytes
network_path: QuicNetworkPath
quic_logger_frames: Optional[List[Any]]
time: float
at: collections.deque
append(x: _T) -> None
at: logging.LoggerAdapter
logger: Logger
extra: Mapping[str, Any]
info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
===========changed ref 0===========
# module: aioquic.quic.connection
class QuicConnection:
def send_stream_data(
self, stream_id: int, data: bytes, end_stream: bool = False
) -> None:
"""
Send data on the specific stream.
:param stream_id: The stream's ID.
:param data: The data to be sent.
:param end_stream: If set to `True`, the FIN bit will be set.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.write(data, end_stream=end_stream)
- stream.write(data, end_stream=end_stream)
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def reset_stream(self, stream_id: int, error_code: int) -> None:
"""
Abruptly terminate the sending part of a stream.
:param stream_id: The stream's ID.
:param error_code: An error code indicating why the stream is being reset.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.reset(error_code)
- stream.reset(error_code)
|
aioquic.quic.connection/QuicConnection._handle_reset_stream_frame
|
Modified
|
aiortc~aioquic
|
5e39294f9a64b565b552419a85f4984c384e36be
|
[streams] split into QuicStreamReceiver / QuicStreamSender
|
<26>:<add> newly_received = max(0, final_size - stream.receiver.highest_offset)
<del> newly_received = max(0, final_size - stream._recv_highest)
|
# module: aioquic.quic.connection
class QuicConnection:
def _handle_reset_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
<0> """
<1> Handle a RESET_STREAM frame.
<2> """
<3> stream_id = buf.pull_uint_var()
<4> error_code = buf.pull_uint_var()
<5> final_size = buf.pull_uint_var()
<6>
<7> # log frame
<8> if self._quic_logger is not None:
<9> context.quic_logger_frames.append(
<10> self._quic_logger.encode_reset_stream_frame(
<11> error_code=error_code, final_size=final_size, stream_id=stream_id
<12> )
<13> )
<14>
<15> # check stream direction
<16> self._assert_stream_can_receive(frame_type, stream_id)
<17>
<18> # check flow-control limits
<19> stream = self._get_or_create_stream(frame_type, stream_id)
<20> if final_size > stream.max_stream_data_local:
<21> raise QuicConnectionError(
<22> error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
<23> frame_type=frame_type,
<24> reason_phrase="Over stream data limit",
<25> )
<26> newly_received = max(0, final_size - stream._recv_highest)
<27> if self._local_max_data.used + newly_received > self._local_max_data.value:
<28> raise QuicConnectionError(
<29> error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
<30> frame_type=frame_type,
<31> reason_phrase="Over connection data limit",
<32> )
<33>
<34> # process reset
<35> self._logger.info(
<36> "Stream %d reset by peer (error code %d, final size %d)",
<37> stream_id,
<38> error_code,
<39> final_size,
<40> )
<41> try:</s>
|
===========below chunk 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_reset_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
# offset: 1
except FinalSizeError as exc:
raise QuicConnectionError(
error_code=QuicErrorCode.FINAL_SIZE_ERROR,
frame_type=frame_type,
reason_phrase=str(exc),
)
if event is not None:
self._events.append(event)
self._local_max_data.used += newly_received
===========unchanged ref 0===========
at: aioquic.quic.connection
QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)
QuicReceiveContext(epoch: tls.Epoch, host_cid: bytes, network_path: QuicNetworkPath, quic_logger_frames: Optional[List[Any]], time: float)
at: aioquic.quic.connection.Limit.__init__
self.used = 0
self.value = value
at: aioquic.quic.connection.QuicConnection
_assert_stream_can_receive(frame_type: int, stream_id: int) -> None
_get_or_create_stream(frame_type: int, stream_id: int) -> QuicStream
at: aioquic.quic.connection.QuicConnection.__init__
self._local_max_data = Limit(
frame_type=QuicFrameType.MAX_DATA,
name="max_data",
value=configuration.max_data,
)
self._quic_logger: Optional[QuicLoggerTrace] = None
self._quic_logger = configuration.quic_logger.start_trace(
is_client=configuration.is_client,
odcid=self._original_destination_connection_id,
)
self._logger = QuicConnectionAdapter(
logger, {"id": dump_cid(self._original_destination_connection_id)}
)
at: aioquic.quic.connection.QuicConnection._close_end
self._quic_logger = None
at: aioquic.quic.connection.QuicReceiveContext
quic_logger_frames: Optional[List[Any]]
at: logging.LoggerAdapter
info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
===========changed ref 0===========
# module: aioquic.quic.connection
class QuicConnection:
def send_stream_data(
self, stream_id: int, data: bytes, end_stream: bool = False
) -> None:
"""
Send data on the specific stream.
:param stream_id: The stream's ID.
:param data: The data to be sent.
:param end_stream: If set to `True`, the FIN bit will be set.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.write(data, end_stream=end_stream)
- stream.write(data, end_stream=end_stream)
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def reset_stream(self, stream_id: int, error_code: int) -> None:
"""
Abruptly terminate the sending part of a stream.
:param stream_id: The stream's ID.
:param error_code: An error code indicating why the stream is being reset.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.reset(error_code)
- stream.reset(error_code)
===========changed ref 2===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_crypto_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
"""
Handle a CRYPTO frame.
"""
offset = buf.pull_uint_var()
length = buf.pull_uint_var()
if offset + length > UINT_VAR_MAX:
raise QuicConnectionError(
error_code=QuicErrorCode.FRAME_ENCODING_ERROR,
frame_type=frame_type,
reason_phrase="offset + length cannot exceed 2^62 - 1",
)
frame = QuicStreamFrame(offset=offset, data=buf.pull_bytes(length))
# log frame
if self._quic_logger is not None:
context.quic_logger_frames.append(
self._quic_logger.encode_crypto_frame(frame)
)
stream = self._crypto_streams[context.epoch]
+ event = stream.receiver.handle_frame(frame)
- event = stream.add_frame(frame)
if event is not None:
# pass data to TLS layer
try:
self.tls.handle_message(event.data, self._crypto_buffers)
self._push_crypto_data()
except tls.Alert as exc:
raise QuicConnectionError(
error_code=QuicErrorCode.CRYPTO_ERROR + int(exc.description),
frame_type=frame_type,
reason_phrase=str(exc),
)
# parse transport parameters
if (
not self._parameters_received
and self.tls.received_extensions is not None
):
for ext_type, ext_data in self.tls.received_extensions:
if ext_type == get_transport_parameters_extension(self._version):
self._parse_transport_parameters(ext_data)
self._parameters_received = True
break
if not self._parameters_received:
raise QuicConnectionError(
error_code=QuicErrorCode</s>
===========changed ref 3===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_crypto_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
# offset: 1
<s> True
break
if not self._parameters_received:
raise QuicConnectionError(
error_code=QuicErrorCode.CRYPTO_ERROR
+ tls.AlertDescription.missing_extension,
frame_type=frame_type,
reason_phrase="No QUIC transport parameters received",
)
# update current epoch
if not self._handshake_complete and self.tls.state in [
tls.State.CLIENT_POST_HANDSHAKE,
tls.State.SERVER_POST_HANDSHAKE,
]:
self._handshake_complete = True
# for servers, the handshake is now confirmed
if not self._is_client:
self._discard_epoch(tls.Epoch.HANDSHAKE)
self._handshake_confirmed = True
self._handshake_done_pending = True
self._replenish_connection_ids()
self._events.append(
events.HandshakeCompleted(
alpn_protocol=self.tls.alpn_negotiated,
early_data_accepted=self.tls.early_data_accepted,
session_resumed=self.tls.session_resumed,
)
)
self._unblock_streams(is_unidirectional=False)
self._unblock_streams(is_unidirectional=True)
self._logger.info(
"ALPN negotiated protocol %s", self.tls.alpn_negotiated
)
|
aioquic.quic.connection/QuicConnection._handle_stream_frame
|
Modified
|
aiortc~aioquic
|
5e39294f9a64b565b552419a85f4984c384e36be
|
[streams] split into QuicStreamReceiver / QuicStreamSender
|
<39>:<add> newly_received = max(0, offset + length - stream.receiver.highest_offset)
<del> newly_received = max(0, offset + length - stream._recv_highest)
|
# module: aioquic.quic.connection
class QuicConnection:
def _handle_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
<0> """
<1> Handle a STREAM frame.
<2> """
<3> stream_id = buf.pull_uint_var()
<4> if frame_type & 4:
<5> offset = buf.pull_uint_var()
<6> else:
<7> offset = 0
<8> if frame_type & 2:
<9> length = buf.pull_uint_var()
<10> else:
<11> length = buf.capacity - buf.tell()
<12> if offset + length > UINT_VAR_MAX:
<13> raise QuicConnectionError(
<14> error_code=QuicErrorCode.FRAME_ENCODING_ERROR,
<15> frame_type=frame_type,
<16> reason_phrase="offset + length cannot exceed 2^62 - 1",
<17> )
<18> frame = QuicStreamFrame(
<19> offset=offset, data=buf.pull_bytes(length), fin=bool(frame_type & 1)
<20> )
<21>
<22> # log frame
<23> if self._quic_logger is not None:
<24> context.quic_logger_frames.append(
<25> self._quic_logger.encode_stream_frame(frame, stream_id=stream_id)
<26> )
<27>
<28> # check stream direction
<29> self._assert_stream_can_receive(frame_type, stream_id)
<30>
<31> # check flow-control limits
<32> stream = self._get_or_create_stream(frame_type, stream_id)
<33> if offset + length > stream.max_stream_data_local:
<34> raise QuicConnectionError(
<35> error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
<36> frame_type=frame_type,
<37> reason_phrase="Over stream data limit",
<38> )
<39> newly_received = max(0, offset + length - stream._recv_highest)
<40> if self._local_max_data.used + newly_</s>
|
===========below chunk 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
# offset: 1
raise QuicConnectionError(
error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
frame_type=frame_type,
reason_phrase="Over connection data limit",
)
# process data
try:
event = stream.add_frame(frame)
except FinalSizeError as exc:
raise QuicConnectionError(
error_code=QuicErrorCode.FINAL_SIZE_ERROR,
frame_type=frame_type,
reason_phrase=str(exc),
)
if event is not None:
self._events.append(event)
self._local_max_data.used += newly_received
===========unchanged ref 0===========
at: aioquic.quic.connection
QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)
QuicReceiveContext(epoch: tls.Epoch, host_cid: bytes, network_path: QuicNetworkPath, quic_logger_frames: Optional[List[Any]], time: float)
at: aioquic.quic.connection.Limit.__init__
self.used = 0
self.value = value
at: aioquic.quic.connection.QuicConnection
_assert_stream_can_receive(frame_type: int, stream_id: int) -> None
_get_or_create_stream(frame_type: int, stream_id: int) -> QuicStream
at: aioquic.quic.connection.QuicConnection.__init__
self._local_max_data = Limit(
frame_type=QuicFrameType.MAX_DATA,
name="max_data",
value=configuration.max_data,
)
self._quic_logger: Optional[QuicLoggerTrace] = None
self._quic_logger = configuration.quic_logger.start_trace(
is_client=configuration.is_client,
odcid=self._original_destination_connection_id,
)
at: aioquic.quic.connection.QuicConnection._close_end
self._quic_logger = None
at: aioquic.quic.connection.QuicConnection._handle_stop_sending_frame
stream_id = buf.pull_uint_var()
at: aioquic.quic.connection.QuicReceiveContext
quic_logger_frames: Optional[List[Any]]
===========changed ref 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_reset_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
"""
Handle a RESET_STREAM frame.
"""
stream_id = buf.pull_uint_var()
error_code = buf.pull_uint_var()
final_size = buf.pull_uint_var()
# log frame
if self._quic_logger is not None:
context.quic_logger_frames.append(
self._quic_logger.encode_reset_stream_frame(
error_code=error_code, final_size=final_size, stream_id=stream_id
)
)
# check stream direction
self._assert_stream_can_receive(frame_type, stream_id)
# check flow-control limits
stream = self._get_or_create_stream(frame_type, stream_id)
if final_size > stream.max_stream_data_local:
raise QuicConnectionError(
error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
frame_type=frame_type,
reason_phrase="Over stream data limit",
)
+ newly_received = max(0, final_size - stream.receiver.highest_offset)
- newly_received = max(0, final_size - stream._recv_highest)
if self._local_max_data.used + newly_received > self._local_max_data.value:
raise QuicConnectionError(
error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
frame_type=frame_type,
reason_phrase="Over connection data limit",
)
# process reset
self._logger.info(
"Stream %d reset by peer (error code %d, final size %d)",
stream_id,
error_code,
final_size,
)
try:
+ event = stream.receiver.handle_reset(
+ error</s>
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_reset_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
# offset: 1
<s>
final_size,
)
try:
+ event = stream.receiver.handle_reset(
+ error_code=error_code, final_size=final_size
- event = stream.handle_reset(error_code=error_code, final_size=final_size)
+ )
except FinalSizeError as exc:
raise QuicConnectionError(
error_code=QuicErrorCode.FINAL_SIZE_ERROR,
frame_type=frame_type,
reason_phrase=str(exc),
)
if event is not None:
self._events.append(event)
self._local_max_data.used += newly_received
===========changed ref 2===========
# module: aioquic.quic.connection
class QuicConnection:
def send_stream_data(
self, stream_id: int, data: bytes, end_stream: bool = False
) -> None:
"""
Send data on the specific stream.
:param stream_id: The stream's ID.
:param data: The data to be sent.
:param end_stream: If set to `True`, the FIN bit will be set.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.write(data, end_stream=end_stream)
- stream.write(data, end_stream=end_stream)
===========changed ref 3===========
# module: aioquic.quic.connection
class QuicConnection:
def reset_stream(self, stream_id: int, error_code: int) -> None:
"""
Abruptly terminate the sending part of a stream.
:param stream_id: The stream's ID.
:param error_code: An error code indicating why the stream is being reset.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.reset(error_code)
- stream.reset(error_code)
|
aioquic.quic.connection/QuicConnection._push_crypto_data
|
Modified
|
aiortc~aioquic
|
5e39294f9a64b565b552419a85f4984c384e36be
|
[streams] split into QuicStreamReceiver / QuicStreamSender
|
<1>:<add> self._crypto_streams[epoch].sender.write(buf.data)
<del> self._crypto_streams[epoch].write(buf.data)
|
# module: aioquic.quic.connection
class QuicConnection:
def _push_crypto_data(self) -> None:
<0> for epoch, buf in self._crypto_buffers.items():
<1> self._crypto_streams[epoch].write(buf.data)
<2> buf.seek(0)
<3>
|
===========unchanged ref 0===========
at: aioquic.quic.connection.QuicConnection.__init__
self._crypto_buffers: Dict[tls.Epoch, Buffer] = {}
self._retire_connection_ids: List[int] = []
at: aioquic.quic.connection.QuicConnection._initialize
self._crypto_buffers = {
tls.Epoch.INITIAL: Buffer(capacity=CRYPTO_BUFFER_SIZE),
tls.Epoch.HANDSHAKE: Buffer(capacity=CRYPTO_BUFFER_SIZE),
tls.Epoch.ONE_RTT: Buffer(capacity=CRYPTO_BUFFER_SIZE),
}
at: aioquic.quic.connection.QuicConnectionId
cid: bytes
sequence_number: int
stateless_reset_token: bytes = b""
was_sent: bool = False
===========changed ref 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
"""
Handle a STREAM frame.
"""
stream_id = buf.pull_uint_var()
if frame_type & 4:
offset = buf.pull_uint_var()
else:
offset = 0
if frame_type & 2:
length = buf.pull_uint_var()
else:
length = buf.capacity - buf.tell()
if offset + length > UINT_VAR_MAX:
raise QuicConnectionError(
error_code=QuicErrorCode.FRAME_ENCODING_ERROR,
frame_type=frame_type,
reason_phrase="offset + length cannot exceed 2^62 - 1",
)
frame = QuicStreamFrame(
offset=offset, data=buf.pull_bytes(length), fin=bool(frame_type & 1)
)
# log frame
if self._quic_logger is not None:
context.quic_logger_frames.append(
self._quic_logger.encode_stream_frame(frame, stream_id=stream_id)
)
# check stream direction
self._assert_stream_can_receive(frame_type, stream_id)
# check flow-control limits
stream = self._get_or_create_stream(frame_type, stream_id)
if offset + length > stream.max_stream_data_local:
raise QuicConnectionError(
error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
frame_type=frame_type,
reason_phrase="Over stream data limit",
)
+ newly_received = max(0, offset + length - stream.receiver.highest_offset)
- newly_received = max(0, offset + length - stream._recv_highest)
if self._local_max_data.used + newly_received > self._local_max_data.value:
raise Qu</s>
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
# offset: 1
<s> if self._local_max_data.used + newly_received > self._local_max_data.value:
raise QuicConnectionError(
error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
frame_type=frame_type,
reason_phrase="Over connection data limit",
)
# process data
try:
+ event = stream.receiver.handle_frame(frame)
- event = stream.add_frame(frame)
except FinalSizeError as exc:
raise QuicConnectionError(
error_code=QuicErrorCode.FINAL_SIZE_ERROR,
frame_type=frame_type,
reason_phrase=str(exc),
)
if event is not None:
self._events.append(event)
self._local_max_data.used += newly_received
===========changed ref 2===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_reset_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
"""
Handle a RESET_STREAM frame.
"""
stream_id = buf.pull_uint_var()
error_code = buf.pull_uint_var()
final_size = buf.pull_uint_var()
# log frame
if self._quic_logger is not None:
context.quic_logger_frames.append(
self._quic_logger.encode_reset_stream_frame(
error_code=error_code, final_size=final_size, stream_id=stream_id
)
)
# check stream direction
self._assert_stream_can_receive(frame_type, stream_id)
# check flow-control limits
stream = self._get_or_create_stream(frame_type, stream_id)
if final_size > stream.max_stream_data_local:
raise QuicConnectionError(
error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
frame_type=frame_type,
reason_phrase="Over stream data limit",
)
+ newly_received = max(0, final_size - stream.receiver.highest_offset)
- newly_received = max(0, final_size - stream._recv_highest)
if self._local_max_data.used + newly_received > self._local_max_data.value:
raise QuicConnectionError(
error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
frame_type=frame_type,
reason_phrase="Over connection data limit",
)
# process reset
self._logger.info(
"Stream %d reset by peer (error code %d, final size %d)",
stream_id,
error_code,
final_size,
)
try:
+ event = stream.receiver.handle_reset(
+ error</s>
===========changed ref 3===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_reset_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
# offset: 1
<s>
final_size,
)
try:
+ event = stream.receiver.handle_reset(
+ error_code=error_code, final_size=final_size
- event = stream.handle_reset(error_code=error_code, final_size=final_size)
+ )
except FinalSizeError as exc:
raise QuicConnectionError(
error_code=QuicErrorCode.FINAL_SIZE_ERROR,
frame_type=frame_type,
reason_phrase=str(exc),
)
if event is not None:
self._events.append(event)
self._local_max_data.used += newly_received
===========changed ref 4===========
# module: aioquic.quic.connection
class QuicConnection:
def reset_stream(self, stream_id: int, error_code: int) -> None:
"""
Abruptly terminate the sending part of a stream.
:param stream_id: The stream's ID.
:param error_code: An error code indicating why the stream is being reset.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.reset(error_code)
- stream.reset(error_code)
|
aioquic.quic.connection/QuicConnection._write_application
|
Modified
|
aiortc~aioquic
|
5e39294f9a64b565b552419a85f4984c384e36be
|
[streams] split into QuicStreamReceiver / QuicStreamSender
|
# module: aioquic.quic.connection
class QuicConnection:
def _write_application(
self, builder: QuicPacketBuilder, network_path: QuicNetworkPath, now: float
) -> None:
<0> crypto_stream: Optional[QuicStream] = None
<1> if self._cryptos[tls.Epoch.ONE_RTT].send.is_valid():
<2> crypto = self._cryptos[tls.Epoch.ONE_RTT]
<3> crypto_stream = self._crypto_streams[tls.Epoch.ONE_RTT]
<4> packet_type = PACKET_TYPE_ONE_RTT
<5> elif self._cryptos[tls.Epoch.ZERO_RTT].send.is_valid():
<6> crypto = self._cryptos[tls.Epoch.ZERO_RTT]
<7> packet_type = PACKET_TYPE_ZERO_RTT
<8> else:
<9> return
<10> space = self._spaces[tls.Epoch.ONE_RTT]
<11>
<12> while True:
<13> # apply pacing, except if we have ACKs to send
<14> if space.ack_at is None or space.ack_at >= now:
<15> self._pacing_at = self._loss._pacer.next_send_time(now=now)
<16> if self._pacing_at is not None:
<17> break
<18> builder.start_packet(packet_type, crypto)
<19>
<20> if self._handshake_complete:
<21> # ACK
<22> if space.ack_at is not None and space.ack_at <= now:
<23> self._write_ack_frame(builder=builder, space=space, now=now)
<24>
<25> # HANDSHAKE_DONE
<26> if self._handshake_done_pending:
<27> self._write_handshake_done_frame(builder=builder)
<28> self._handshake_done_pending = False
<29>
<30> # PATH CHALLENGE
<31> if (
<32> not network_path.is_validated
<33> and network_path.local_challenge is None
<34> ):
<35> challenge = os.ur</s>
|
===========below chunk 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_application(
self, builder: QuicPacketBuilder, network_path: QuicNetworkPath, now: float
) -> None:
# offset: 1
self._write_path_challenge_frame(
builder=builder, challenge=challenge
)
network_path.local_challenge = challenge
# PATH RESPONSE
if network_path.remote_challenge is not None:
self._write_path_response_frame(
builder=builder, challenge=network_path.remote_challenge
)
network_path.remote_challenge = None
# NEW_CONNECTION_ID
for connection_id in self._host_cids:
if not connection_id.was_sent:
self._write_new_connection_id_frame(
builder=builder, connection_id=connection_id
)
# RETIRE_CONNECTION_ID
for sequence_number in self._retire_connection_ids[:]:
self._write_retire_connection_id_frame(
builder=builder, sequence_number=sequence_number
)
self._retire_connection_ids.pop(0)
# STREAMS_BLOCKED
if self._streams_blocked_pending:
if self._streams_blocked_bidi:
self._write_streams_blocked_frame(
builder=builder,
frame_type=QuicFrameType.STREAMS_BLOCKED_BIDI,
limit=self._remote_max_streams_bidi,
)
if self._streams_blocked_uni:
self._write_streams_blocked_frame(
builder=builder,
frame_type=QuicFrameType.STREAMS_BLOCKED_UNI,
limit=self._remote_max_streams_uni,
)
self._streams_blocked_pending = False
# MAX_DATA and MAX_STREAMS
self._write_connection_limits(builder=builder, space=space)
# stream-level limits
for stream in self._streams.values():
</s>
===========below chunk 1===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_application(
self, builder: QuicPacketBuilder, network_path: QuicNetworkPath, now: float
) -> None:
# offset: 2
<s>(builder=builder, space=space)
# stream-level limits
for stream in self._streams.values():
self._write_stream_limits(builder=builder, space=space, stream=stream)
# PING (user-request)
if self._ping_pending:
self._write_ping_frame(builder, self._ping_pending)
self._ping_pending.clear()
# PING (probe)
if self._probe_pending:
self._write_ping_frame(builder, comment="probe")
self._probe_pending = False
# CRYPTO
if crypto_stream is not None and not crypto_stream.send_buffer_is_empty:
self._write_crypto_frame(
builder=builder, space=space, stream=crypto_stream
)
# DATAGRAM
while self._datagrams_pending:
try:
self._write_datagram_frame(
builder=builder,
data=self._datagrams_pending[0],
frame_type=QuicFrameType.DATAGRAM_WITH_LENGTH,
)
self._datagrams_pending.popleft()
except QuicPacketBuilderStop:
break
# STREAM and RESET_STREAM
for stream in self._streams.values():
if stream.reset_pending:
self._write_reset_stream_frame(
builder=builder,
frame_type=QuicFrameType.RESET_STREAM,
stream=stream,
)
elif not stream.is_blocked and not stream.send_buffer_is_empty:
self._remote_max_data_used += self._write_stream_frame(
builder=builder,</s>
===========below chunk 2===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_application(
self, builder: QuicPacketBuilder, network_path: QuicNetworkPath, now: float
) -> None:
# offset: 3
<s> space=space,
stream=stream,
max_offset=min(
stream._send_highest
+ self._remote_max_data
- self._remote_max_data_used,
stream.max_stream_data_remote,
),
)
if builder.packet_is_empty:
break
else:
self._loss._pacer.update_after_send(now=now)
===========unchanged ref 0===========
at: aioquic.quic.connection
QuicNetworkPath(addr: NetworkAddress, bytes_received: int=0, bytes_sent: int=0, is_validated: bool=False, local_challenge: Optional[bytes]=None, remote_challenge: Optional[bytes]=None)
at: aioquic.quic.connection.QuicConnection
_write_ack_frame(builder: QuicPacketBuilder, space: QuicPacketSpace, now: float) -> None
_write_connection_limits(builder: QuicPacketBuilder, space: QuicPacketSpace) -> None
_write_crypto_frame(self, builder: QuicPacketBuilder, space: QuicPacketSpace, stream: QuicStream) -> bool
_write_crypto_frame(builder: QuicPacketBuilder, space: QuicPacketSpace, stream: QuicStream) -> bool
_write_datagram_frame(builder: QuicPacketBuilder, data: bytes, frame_type: QuicFrameType) -> bool
_write_handshake_done_frame(builder: QuicPacketBuilder) -> None
_write_new_connection_id_frame(builder: QuicPacketBuilder, connection_id: QuicConnectionId) -> None
_write_path_challenge_frame(builder: QuicPacketBuilder, challenge: bytes) -> None
_write_path_response_frame(builder: QuicPacketBuilder, challenge: bytes) -> None
_write_ping_frame(builder: QuicPacketBuilder, uids: List[int]=[], comment="")
_write_reset_stream_frame(self, builder: QuicPacketBuilder, frame_type: QuicFrameType, stream: QuicStream) -> None
_write_reset_stream_frame(builder: QuicPacketBuilder, frame_type: QuicFrameType, stream: QuicStream) -> None
_write_retire_connection_id_frame(builder: QuicPacketBuilder, sequence_number: int) -> None
|
|
aioquic.quic.connection/QuicConnection._write_handshake
|
Modified
|
aiortc~aioquic
|
5e39294f9a64b565b552419a85f4984c384e36be
|
[streams] split into QuicStreamReceiver / QuicStreamSender
|
<19>:<add> if not crypto_stream.sender.buffer_is_empty:
<del> if not crypto_stream.send_buffer_is_empty:
|
# module: aioquic.quic.connection
class QuicConnection:
def _write_handshake(
self, builder: QuicPacketBuilder, epoch: tls.Epoch, now: float
) -> None:
<0> crypto = self._cryptos[epoch]
<1> if not crypto.send.is_valid():
<2> return
<3>
<4> crypto_stream = self._crypto_streams[epoch]
<5> space = self._spaces[epoch]
<6>
<7> while True:
<8> if epoch == tls.Epoch.INITIAL:
<9> packet_type = PACKET_TYPE_INITIAL
<10> else:
<11> packet_type = PACKET_TYPE_HANDSHAKE
<12> builder.start_packet(packet_type, crypto)
<13>
<14> # ACK
<15> if space.ack_at is not None:
<16> self._write_ack_frame(builder=builder, space=space, now=now)
<17>
<18> # CRYPTO
<19> if not crypto_stream.send_buffer_is_empty:
<20> if self._write_crypto_frame(
<21> builder=builder, space=space, stream=crypto_stream
<22> ):
<23> self._probe_pending = False
<24>
<25> # PING (probe)
<26> if (
<27> self._probe_pending
<28> and not self._handshake_complete
<29> and (
<30> epoch == tls.Epoch.HANDSHAKE
<31> or not self._cryptos[tls.Epoch.HANDSHAKE].send.is_valid()
<32> )
<33> ):
<34> self._write_ping_frame(builder, comment="probe")
<35> self._probe_pending = False
<36>
<37> if builder.packet_is_empty:
<38> break
<39>
|
===========unchanged ref 0===========
at: aioquic.quic.connection.QuicConnection
_write_ack_frame(builder: QuicPacketBuilder, space: QuicPacketSpace, now: float) -> None
_write_crypto_frame(self, builder: QuicPacketBuilder, space: QuicPacketSpace, stream: QuicStream) -> bool
_write_crypto_frame(builder: QuicPacketBuilder, space: QuicPacketSpace, stream: QuicStream) -> bool
_write_ping_frame(builder: QuicPacketBuilder, uids: List[int]=[], comment="")
at: aioquic.quic.connection.QuicConnection.__init__
self._cryptos: Dict[tls.Epoch, CryptoPair] = {}
self._crypto_streams: Dict[tls.Epoch, QuicStream] = {}
self._handshake_complete = False
self._spaces: Dict[tls.Epoch, QuicPacketSpace] = {}
self._loss = QuicPacketRecovery(
initial_rtt=configuration.initial_rtt,
peer_completed_address_validation=not self._is_client,
quic_logger=self._quic_logger,
send_probe=self._send_probe,
)
self._probe_pending = False
at: aioquic.quic.connection.QuicConnection._handle_crypto_frame
self._handshake_complete = True
at: aioquic.quic.connection.QuicConnection._initialize
self._cryptos = dict(
(epoch, create_crypto_pair(epoch))
for epoch in (
tls.Epoch.INITIAL,
tls.Epoch.ZERO_RTT,
tls.Epoch.HANDSHAKE,
tls.Epoch.ONE_RTT,
)
)
self._crypto_streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
===========unchanged ref 1===========
self._spaces = {
tls.Epoch.INITIAL: QuicPacketSpace(),
tls.Epoch.HANDSHAKE: QuicPacketSpace(),
tls.Epoch.ONE_RTT: QuicPacketSpace(),
}
at: aioquic.quic.connection.QuicConnection._send_probe
self._probe_pending = True
at: aioquic.quic.connection.QuicConnection._write_application
self._probe_pending = False
===========changed ref 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _push_crypto_data(self) -> None:
for epoch, buf in self._crypto_buffers.items():
+ self._crypto_streams[epoch].sender.write(buf.data)
- self._crypto_streams[epoch].write(buf.data)
buf.seek(0)
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def reset_stream(self, stream_id: int, error_code: int) -> None:
"""
Abruptly terminate the sending part of a stream.
:param stream_id: The stream's ID.
:param error_code: An error code indicating why the stream is being reset.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.reset(error_code)
- stream.reset(error_code)
===========changed ref 2===========
# module: aioquic.quic.connection
class QuicConnection:
def send_stream_data(
self, stream_id: int, data: bytes, end_stream: bool = False
) -> None:
"""
Send data on the specific stream.
:param stream_id: The stream's ID.
:param data: The data to be sent.
:param end_stream: If set to `True`, the FIN bit will be set.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.write(data, end_stream=end_stream)
- stream.write(data, end_stream=end_stream)
===========changed ref 3===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
"""
Handle a STREAM frame.
"""
stream_id = buf.pull_uint_var()
if frame_type & 4:
offset = buf.pull_uint_var()
else:
offset = 0
if frame_type & 2:
length = buf.pull_uint_var()
else:
length = buf.capacity - buf.tell()
if offset + length > UINT_VAR_MAX:
raise QuicConnectionError(
error_code=QuicErrorCode.FRAME_ENCODING_ERROR,
frame_type=frame_type,
reason_phrase="offset + length cannot exceed 2^62 - 1",
)
frame = QuicStreamFrame(
offset=offset, data=buf.pull_bytes(length), fin=bool(frame_type & 1)
)
# log frame
if self._quic_logger is not None:
context.quic_logger_frames.append(
self._quic_logger.encode_stream_frame(frame, stream_id=stream_id)
)
# check stream direction
self._assert_stream_can_receive(frame_type, stream_id)
# check flow-control limits
stream = self._get_or_create_stream(frame_type, stream_id)
if offset + length > stream.max_stream_data_local:
raise QuicConnectionError(
error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
frame_type=frame_type,
reason_phrase="Over stream data limit",
)
+ newly_received = max(0, offset + length - stream.receiver.highest_offset)
- newly_received = max(0, offset + length - stream._recv_highest)
if self._local_max_data.used + newly_received > self._local_max_data.value:
raise Qu</s>
===========changed ref 4===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
# offset: 1
<s> if self._local_max_data.used + newly_received > self._local_max_data.value:
raise QuicConnectionError(
error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
frame_type=frame_type,
reason_phrase="Over connection data limit",
)
# process data
try:
+ event = stream.receiver.handle_frame(frame)
- event = stream.add_frame(frame)
except FinalSizeError as exc:
raise QuicConnectionError(
error_code=QuicErrorCode.FINAL_SIZE_ERROR,
frame_type=frame_type,
reason_phrase=str(exc),
)
if event is not None:
self._events.append(event)
self._local_max_data.used += newly_received
|
aioquic.quic.connection/QuicConnection._write_crypto_frame
|
Modified
|
aiortc~aioquic
|
5e39294f9a64b565b552419a85f4984c384e36be
|
[streams] split into QuicStreamReceiver / QuicStreamSender
|
<0>:<add> frame_overhead = 3 + size_uint_var(stream.sender.next_offset)
<del> frame_overhead = 3 + size_uint_var(stream.next_send_offset)
<1>:<add> frame = stream.sender.get_frame(builder.remaining_flight_space - frame_overhead)
<del> frame = stream.get_frame(builder.remaining_flight_space - frame_overhead)
<6>:<add> handler=stream.sender.on_data_delivery,
<del> handler=stream.on_data_delivery,
|
# module: aioquic.quic.connection
class QuicConnection:
def _write_crypto_frame(
self, builder: QuicPacketBuilder, space: QuicPacketSpace, stream: QuicStream
) -> bool:
<0> frame_overhead = 3 + size_uint_var(stream.next_send_offset)
<1> frame = stream.get_frame(builder.remaining_flight_space - frame_overhead)
<2> if frame is not None:
<3> buf = builder.start_frame(
<4> QuicFrameType.CRYPTO,
<5> capacity=frame_overhead,
<6> handler=stream.on_data_delivery,
<7> handler_args=(frame.offset, frame.offset + len(frame.data)),
<8> )
<9> buf.push_uint_var(frame.offset)
<10> buf.push_uint16(len(frame.data) | 0x4000)
<11> buf.push_bytes(frame.data)
<12>
<13> # log frame
<14> if self._quic_logger is not None:
<15> builder.quic_logger_frames.append(
<16> self._quic_logger.encode_crypto_frame(frame)
<17> )
<18> return True
<19>
<20> return False
<21>
|
===========unchanged ref 0===========
at: aioquic.quic.connection.QuicConnection.__init__
self._quic_logger: Optional[QuicLoggerTrace] = None
self._quic_logger = configuration.quic_logger.start_trace(
is_client=configuration.is_client,
odcid=self._original_destination_connection_id,
)
at: aioquic.quic.connection.QuicConnection._close_end
self._quic_logger = None
===========changed ref 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_handshake(
self, builder: QuicPacketBuilder, epoch: tls.Epoch, now: float
) -> None:
crypto = self._cryptos[epoch]
if not crypto.send.is_valid():
return
crypto_stream = self._crypto_streams[epoch]
space = self._spaces[epoch]
while True:
if epoch == tls.Epoch.INITIAL:
packet_type = PACKET_TYPE_INITIAL
else:
packet_type = PACKET_TYPE_HANDSHAKE
builder.start_packet(packet_type, crypto)
# ACK
if space.ack_at is not None:
self._write_ack_frame(builder=builder, space=space, now=now)
# CRYPTO
+ if not crypto_stream.sender.buffer_is_empty:
- if not crypto_stream.send_buffer_is_empty:
if self._write_crypto_frame(
builder=builder, space=space, stream=crypto_stream
):
self._probe_pending = False
# PING (probe)
if (
self._probe_pending
and not self._handshake_complete
and (
epoch == tls.Epoch.HANDSHAKE
or not self._cryptos[tls.Epoch.HANDSHAKE].send.is_valid()
)
):
self._write_ping_frame(builder, comment="probe")
self._probe_pending = False
if builder.packet_is_empty:
break
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def _push_crypto_data(self) -> None:
for epoch, buf in self._crypto_buffers.items():
+ self._crypto_streams[epoch].sender.write(buf.data)
- self._crypto_streams[epoch].write(buf.data)
buf.seek(0)
===========changed ref 2===========
# module: aioquic.quic.connection
class QuicConnection:
def reset_stream(self, stream_id: int, error_code: int) -> None:
"""
Abruptly terminate the sending part of a stream.
:param stream_id: The stream's ID.
:param error_code: An error code indicating why the stream is being reset.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.reset(error_code)
- stream.reset(error_code)
===========changed ref 3===========
# module: aioquic.quic.connection
class QuicConnection:
def send_stream_data(
self, stream_id: int, data: bytes, end_stream: bool = False
) -> None:
"""
Send data on the specific stream.
:param stream_id: The stream's ID.
:param data: The data to be sent.
:param end_stream: If set to `True`, the FIN bit will be set.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.write(data, end_stream=end_stream)
- stream.write(data, end_stream=end_stream)
===========changed ref 4===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
"""
Handle a STREAM frame.
"""
stream_id = buf.pull_uint_var()
if frame_type & 4:
offset = buf.pull_uint_var()
else:
offset = 0
if frame_type & 2:
length = buf.pull_uint_var()
else:
length = buf.capacity - buf.tell()
if offset + length > UINT_VAR_MAX:
raise QuicConnectionError(
error_code=QuicErrorCode.FRAME_ENCODING_ERROR,
frame_type=frame_type,
reason_phrase="offset + length cannot exceed 2^62 - 1",
)
frame = QuicStreamFrame(
offset=offset, data=buf.pull_bytes(length), fin=bool(frame_type & 1)
)
# log frame
if self._quic_logger is not None:
context.quic_logger_frames.append(
self._quic_logger.encode_stream_frame(frame, stream_id=stream_id)
)
# check stream direction
self._assert_stream_can_receive(frame_type, stream_id)
# check flow-control limits
stream = self._get_or_create_stream(frame_type, stream_id)
if offset + length > stream.max_stream_data_local:
raise QuicConnectionError(
error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
frame_type=frame_type,
reason_phrase="Over stream data limit",
)
+ newly_received = max(0, offset + length - stream.receiver.highest_offset)
- newly_received = max(0, offset + length - stream._recv_highest)
if self._local_max_data.used + newly_received > self._local_max_data.value:
raise Qu</s>
===========changed ref 5===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
# offset: 1
<s> if self._local_max_data.used + newly_received > self._local_max_data.value:
raise QuicConnectionError(
error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
frame_type=frame_type,
reason_phrase="Over connection data limit",
)
# process data
try:
+ event = stream.receiver.handle_frame(frame)
- event = stream.add_frame(frame)
except FinalSizeError as exc:
raise QuicConnectionError(
error_code=QuicErrorCode.FINAL_SIZE_ERROR,
frame_type=frame_type,
reason_phrase=str(exc),
)
if event is not None:
self._events.append(event)
self._local_max_data.used += newly_received
|
aioquic.quic.connection/QuicConnection._write_reset_stream_frame
|
Modified
|
aiortc~aioquic
|
5e39294f9a64b565b552419a85f4984c384e36be
|
[streams] split into QuicStreamReceiver / QuicStreamSender
|
<3>:<add> handler=stream.sender.on_reset_delivery,
<del> handler=stream.on_reset_delivery,
<5>:<add> reset = stream.sender.get_reset_frame()
<del> reset = stream.get_reset_frame()
|
# module: aioquic.quic.connection
class QuicConnection:
def _write_reset_stream_frame(
self,
builder: QuicPacketBuilder,
frame_type: QuicFrameType,
stream: QuicStream,
) -> None:
<0> buf = builder.start_frame(
<1> frame_type=frame_type,
<2> capacity=RESET_STREAM_CAPACITY,
<3> handler=stream.on_reset_delivery,
<4> )
<5> reset = stream.get_reset_frame()
<6> buf.push_uint_var(stream.stream_id)
<7> buf.push_uint_var(reset.error_code)
<8> buf.push_uint_var(reset.final_size)
<9>
<10> # log frame
<11> if self._quic_logger is not None:
<12> builder.quic_logger_frames.append(
<13> self._quic_logger.encode_reset_stream_frame(
<14> error_code=reset.error_code,
<15> final_size=reset.final_size,
<16> stream_id=stream.stream_id,
<17> )
<18> )
<19>
|
===========unchanged ref 0===========
at: aioquic.quic.connection
RESET_STREAM_CAPACITY = 1 + 3 * UINT_VAR_MAX_SIZE
at: aioquic.quic.connection.QuicConnection.__init__
self._quic_logger: Optional[QuicLoggerTrace] = None
self._quic_logger = configuration.quic_logger.start_trace(
is_client=configuration.is_client,
odcid=self._original_destination_connection_id,
)
at: aioquic.quic.connection.QuicConnection._close_end
self._quic_logger = None
===========changed ref 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_crypto_frame(
self, builder: QuicPacketBuilder, space: QuicPacketSpace, stream: QuicStream
) -> bool:
+ frame_overhead = 3 + size_uint_var(stream.sender.next_offset)
- frame_overhead = 3 + size_uint_var(stream.next_send_offset)
+ frame = stream.sender.get_frame(builder.remaining_flight_space - frame_overhead)
- frame = stream.get_frame(builder.remaining_flight_space - frame_overhead)
if frame is not None:
buf = builder.start_frame(
QuicFrameType.CRYPTO,
capacity=frame_overhead,
+ handler=stream.sender.on_data_delivery,
- handler=stream.on_data_delivery,
handler_args=(frame.offset, frame.offset + len(frame.data)),
)
buf.push_uint_var(frame.offset)
buf.push_uint16(len(frame.data) | 0x4000)
buf.push_bytes(frame.data)
# log frame
if self._quic_logger is not None:
builder.quic_logger_frames.append(
self._quic_logger.encode_crypto_frame(frame)
)
return True
return False
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_handshake(
self, builder: QuicPacketBuilder, epoch: tls.Epoch, now: float
) -> None:
crypto = self._cryptos[epoch]
if not crypto.send.is_valid():
return
crypto_stream = self._crypto_streams[epoch]
space = self._spaces[epoch]
while True:
if epoch == tls.Epoch.INITIAL:
packet_type = PACKET_TYPE_INITIAL
else:
packet_type = PACKET_TYPE_HANDSHAKE
builder.start_packet(packet_type, crypto)
# ACK
if space.ack_at is not None:
self._write_ack_frame(builder=builder, space=space, now=now)
# CRYPTO
+ if not crypto_stream.sender.buffer_is_empty:
- if not crypto_stream.send_buffer_is_empty:
if self._write_crypto_frame(
builder=builder, space=space, stream=crypto_stream
):
self._probe_pending = False
# PING (probe)
if (
self._probe_pending
and not self._handshake_complete
and (
epoch == tls.Epoch.HANDSHAKE
or not self._cryptos[tls.Epoch.HANDSHAKE].send.is_valid()
)
):
self._write_ping_frame(builder, comment="probe")
self._probe_pending = False
if builder.packet_is_empty:
break
===========changed ref 2===========
# module: aioquic.quic.connection
class QuicConnection:
def _push_crypto_data(self) -> None:
for epoch, buf in self._crypto_buffers.items():
+ self._crypto_streams[epoch].sender.write(buf.data)
- self._crypto_streams[epoch].write(buf.data)
buf.seek(0)
===========changed ref 3===========
# module: aioquic.quic.connection
class QuicConnection:
def reset_stream(self, stream_id: int, error_code: int) -> None:
"""
Abruptly terminate the sending part of a stream.
:param stream_id: The stream's ID.
:param error_code: An error code indicating why the stream is being reset.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.reset(error_code)
- stream.reset(error_code)
===========changed ref 4===========
# module: aioquic.quic.connection
class QuicConnection:
def send_stream_data(
self, stream_id: int, data: bytes, end_stream: bool = False
) -> None:
"""
Send data on the specific stream.
:param stream_id: The stream's ID.
:param data: The data to be sent.
:param end_stream: If set to `True`, the FIN bit will be set.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.write(data, end_stream=end_stream)
- stream.write(data, end_stream=end_stream)
===========changed ref 5===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_stream_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
"""
Handle a STREAM frame.
"""
stream_id = buf.pull_uint_var()
if frame_type & 4:
offset = buf.pull_uint_var()
else:
offset = 0
if frame_type & 2:
length = buf.pull_uint_var()
else:
length = buf.capacity - buf.tell()
if offset + length > UINT_VAR_MAX:
raise QuicConnectionError(
error_code=QuicErrorCode.FRAME_ENCODING_ERROR,
frame_type=frame_type,
reason_phrase="offset + length cannot exceed 2^62 - 1",
)
frame = QuicStreamFrame(
offset=offset, data=buf.pull_bytes(length), fin=bool(frame_type & 1)
)
# log frame
if self._quic_logger is not None:
context.quic_logger_frames.append(
self._quic_logger.encode_stream_frame(frame, stream_id=stream_id)
)
# check stream direction
self._assert_stream_can_receive(frame_type, stream_id)
# check flow-control limits
stream = self._get_or_create_stream(frame_type, stream_id)
if offset + length > stream.max_stream_data_local:
raise QuicConnectionError(
error_code=QuicErrorCode.FLOW_CONTROL_ERROR,
frame_type=frame_type,
reason_phrase="Over stream data limit",
)
+ newly_received = max(0, offset + length - stream.receiver.highest_offset)
- newly_received = max(0, offset + length - stream._recv_highest)
if self._local_max_data.used + newly_received > self._local_max_data.value:
raise Qu</s>
|
aioquic.quic.connection/QuicConnection._write_stream_frame
|
Modified
|
aiortc~aioquic
|
5e39294f9a64b565b552419a85f4984c384e36be
|
[streams] split into QuicStreamReceiver / QuicStreamSender
|
<5>:<add> + (
<add> size_uint_var(stream.sender.next_offset)
<add> if stream.sender.next_offset
<add> else 0
<add> )
<del> + (size_uint_var(stream.next_send_offset) if stream.next_send_offset else 0)
<7>:<add> previous_send_highest = stream.sender.highest_offset
<del> previous_send_highest = stream._send_highest
<8>:<add> frame = stream.sender.get_frame(
<del> frame = stream.get_frame(
<21>:<add> handler=stream.sender.on_data_delivery,
<del> handler=stream.on_data_delivery,
<38>:<add> return stream.sender.highest_offset - previous_send_highest
<del> return stream._send_highest - previous_send_highest
|
# module: aioquic.quic.connection
class QuicConnection:
def _write_stream_frame(
self,
builder: QuicPacketBuilder,
space: QuicPacketSpace,
stream: QuicStream,
max_offset: int,
) -> int:
<0> # the frame data size is constrained by our peer's MAX_DATA and
<1> # the space available in the current packet
<2> frame_overhead = (
<3> 3
<4> + size_uint_var(stream.stream_id)
<5> + (size_uint_var(stream.next_send_offset) if stream.next_send_offset else 0)
<6> )
<7> previous_send_highest = stream._send_highest
<8> frame = stream.get_frame(
<9> builder.remaining_flight_space - frame_overhead, max_offset
<10> )
<11>
<12> if frame is not None:
<13> frame_type = QuicFrameType.STREAM_BASE | 2 # length
<14> if frame.offset:
<15> frame_type |= 4
<16> if frame.fin:
<17> frame_type |= 1
<18> buf = builder.start_frame(
<19> frame_type,
<20> capacity=frame_overhead,
<21> handler=stream.on_data_delivery,
<22> handler_args=(frame.offset, frame.offset + len(frame.data)),
<23> )
<24> buf.push_uint_var(stream.stream_id)
<25> if frame.offset:
<26> buf.push_uint_var(frame.offset)
<27> buf.push_uint16(len(frame.data) | 0x4000)
<28> buf.push_bytes(frame.data)
<29>
<30> # log frame
<31> if self._quic_logger is not None:
<32> builder.quic_logger_frames.append(
<33> self._quic_logger.encode_stream_frame(
<34> frame, stream_id=stream.stream_id
<35> )
<36> )
<37>
<38> return stream._send_highest - previous_send_highest</s>
|
===========below chunk 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_stream_frame(
self,
builder: QuicPacketBuilder,
space: QuicPacketSpace,
stream: QuicStream,
max_offset: int,
) -> int:
# offset: 1
return 0
===========unchanged ref 0===========
at: aioquic.quic.connection.QuicConnection.__init__
self._quic_logger: Optional[QuicLoggerTrace] = None
self._quic_logger = configuration.quic_logger.start_trace(
is_client=configuration.is_client,
odcid=self._original_destination_connection_id,
)
at: aioquic.quic.connection.QuicConnection._close_end
self._quic_logger = None
===========changed ref 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_reset_stream_frame(
self,
builder: QuicPacketBuilder,
frame_type: QuicFrameType,
stream: QuicStream,
) -> None:
buf = builder.start_frame(
frame_type=frame_type,
capacity=RESET_STREAM_CAPACITY,
+ handler=stream.sender.on_reset_delivery,
- handler=stream.on_reset_delivery,
)
+ reset = stream.sender.get_reset_frame()
- reset = stream.get_reset_frame()
buf.push_uint_var(stream.stream_id)
buf.push_uint_var(reset.error_code)
buf.push_uint_var(reset.final_size)
# log frame
if self._quic_logger is not None:
builder.quic_logger_frames.append(
self._quic_logger.encode_reset_stream_frame(
error_code=reset.error_code,
final_size=reset.final_size,
stream_id=stream.stream_id,
)
)
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_crypto_frame(
self, builder: QuicPacketBuilder, space: QuicPacketSpace, stream: QuicStream
) -> bool:
+ frame_overhead = 3 + size_uint_var(stream.sender.next_offset)
- frame_overhead = 3 + size_uint_var(stream.next_send_offset)
+ frame = stream.sender.get_frame(builder.remaining_flight_space - frame_overhead)
- frame = stream.get_frame(builder.remaining_flight_space - frame_overhead)
if frame is not None:
buf = builder.start_frame(
QuicFrameType.CRYPTO,
capacity=frame_overhead,
+ handler=stream.sender.on_data_delivery,
- handler=stream.on_data_delivery,
handler_args=(frame.offset, frame.offset + len(frame.data)),
)
buf.push_uint_var(frame.offset)
buf.push_uint16(len(frame.data) | 0x4000)
buf.push_bytes(frame.data)
# log frame
if self._quic_logger is not None:
builder.quic_logger_frames.append(
self._quic_logger.encode_crypto_frame(frame)
)
return True
return False
===========changed ref 2===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_handshake(
self, builder: QuicPacketBuilder, epoch: tls.Epoch, now: float
) -> None:
crypto = self._cryptos[epoch]
if not crypto.send.is_valid():
return
crypto_stream = self._crypto_streams[epoch]
space = self._spaces[epoch]
while True:
if epoch == tls.Epoch.INITIAL:
packet_type = PACKET_TYPE_INITIAL
else:
packet_type = PACKET_TYPE_HANDSHAKE
builder.start_packet(packet_type, crypto)
# ACK
if space.ack_at is not None:
self._write_ack_frame(builder=builder, space=space, now=now)
# CRYPTO
+ if not crypto_stream.sender.buffer_is_empty:
- if not crypto_stream.send_buffer_is_empty:
if self._write_crypto_frame(
builder=builder, space=space, stream=crypto_stream
):
self._probe_pending = False
# PING (probe)
if (
self._probe_pending
and not self._handshake_complete
and (
epoch == tls.Epoch.HANDSHAKE
or not self._cryptos[tls.Epoch.HANDSHAKE].send.is_valid()
)
):
self._write_ping_frame(builder, comment="probe")
self._probe_pending = False
if builder.packet_is_empty:
break
===========changed ref 3===========
# module: aioquic.quic.connection
class QuicConnection:
def _push_crypto_data(self) -> None:
for epoch, buf in self._crypto_buffers.items():
+ self._crypto_streams[epoch].sender.write(buf.data)
- self._crypto_streams[epoch].write(buf.data)
buf.seek(0)
===========changed ref 4===========
# module: aioquic.quic.connection
class QuicConnection:
def reset_stream(self, stream_id: int, error_code: int) -> None:
"""
Abruptly terminate the sending part of a stream.
:param stream_id: The stream's ID.
:param error_code: An error code indicating why the stream is being reset.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.reset(error_code)
- stream.reset(error_code)
===========changed ref 5===========
# module: aioquic.quic.connection
class QuicConnection:
def send_stream_data(
self, stream_id: int, data: bytes, end_stream: bool = False
) -> None:
"""
Send data on the specific stream.
:param stream_id: The stream's ID.
:param data: The data to be sent.
:param end_stream: If set to `True`, the FIN bit will be set.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.write(data, end_stream=end_stream)
- stream.write(data, end_stream=end_stream)
|
aioquic.quic.connection/QuicConnection._write_stream_limits
|
Modified
|
aiortc~aioquic
|
5e39294f9a64b565b552419a85f4984c384e36be
|
[streams] split into QuicStreamReceiver / QuicStreamSender
|
<9>:<add> and stream.receiver.highest_offset * 2 > stream.max_stream_data_local
<del> and stream._recv_highest * 2 > stream.max_stream_data_local
|
# module: aioquic.quic.connection
class QuicConnection:
def _write_stream_limits(
self, builder: QuicPacketBuilder, space: QuicPacketSpace, stream: QuicStream
) -> None:
<0> """
<1> Raise MAX_STREAM_DATA if needed.
<2>
<3> The only case where `stream.max_stream_data_local` is zero is for
<4> locally created unidirectional streams. We skip such streams to avoid
<5> spurious logging.
<6> """
<7> if (
<8> stream.max_stream_data_local
<9> and stream._recv_highest * 2 > stream.max_stream_data_local
<10> ):
<11> stream.max_stream_data_local *= 2
<12> self._logger.debug(
<13> "Stream %d local max_stream_data raised to %d",
<14> stream.stream_id,
<15> stream.max_stream_data_local,
<16> )
<17> if stream.max_stream_data_local_sent != stream.max_stream_data_local:
<18> buf = builder.start_frame(
<19> QuicFrameType.MAX_STREAM_DATA,
<20> capacity=MAX_STREAM_DATA_FRAME_CAPACITY,
<21> handler=self._on_max_stream_data_delivery,
<22> handler_args=(stream,),
<23> )
<24> buf.push_uint_var(stream.stream_id)
<25> buf.push_uint_var(stream.max_stream_data_local)
<26> stream.max_stream_data_local_sent = stream.max_stream_data_local
<27>
<28> # log frame
<29> if self._quic_logger is not None:
<30> builder.quic_logger_frames.append(
<31> self._quic_logger.encode_max_stream_data_frame(
<32> maximum=stream.max_stream_data_local, stream_id=stream.stream_id
<33> )
<34> )
<35>
|
===========unchanged ref 0===========
at: aioquic.quic.connection
MAX_STREAM_DATA_FRAME_CAPACITY = 1 + 2 * UINT_VAR_MAX_SIZE
at: aioquic.quic.connection.QuicConnection
_on_max_stream_data_delivery(delivery: QuicDeliveryState, stream: QuicStream) -> None
at: aioquic.quic.connection.QuicConnection.__init__
self._logger = QuicConnectionAdapter(
logger, {"id": dump_cid(self._original_destination_connection_id)}
)
at: aioquic.quic.connection.QuicConnection._write_stream_frame
previous_send_highest = stream.sender.highest_offset
===========changed ref 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_reset_stream_frame(
self,
builder: QuicPacketBuilder,
frame_type: QuicFrameType,
stream: QuicStream,
) -> None:
buf = builder.start_frame(
frame_type=frame_type,
capacity=RESET_STREAM_CAPACITY,
+ handler=stream.sender.on_reset_delivery,
- handler=stream.on_reset_delivery,
)
+ reset = stream.sender.get_reset_frame()
- reset = stream.get_reset_frame()
buf.push_uint_var(stream.stream_id)
buf.push_uint_var(reset.error_code)
buf.push_uint_var(reset.final_size)
# log frame
if self._quic_logger is not None:
builder.quic_logger_frames.append(
self._quic_logger.encode_reset_stream_frame(
error_code=reset.error_code,
final_size=reset.final_size,
stream_id=stream.stream_id,
)
)
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_crypto_frame(
self, builder: QuicPacketBuilder, space: QuicPacketSpace, stream: QuicStream
) -> bool:
+ frame_overhead = 3 + size_uint_var(stream.sender.next_offset)
- frame_overhead = 3 + size_uint_var(stream.next_send_offset)
+ frame = stream.sender.get_frame(builder.remaining_flight_space - frame_overhead)
- frame = stream.get_frame(builder.remaining_flight_space - frame_overhead)
if frame is not None:
buf = builder.start_frame(
QuicFrameType.CRYPTO,
capacity=frame_overhead,
+ handler=stream.sender.on_data_delivery,
- handler=stream.on_data_delivery,
handler_args=(frame.offset, frame.offset + len(frame.data)),
)
buf.push_uint_var(frame.offset)
buf.push_uint16(len(frame.data) | 0x4000)
buf.push_bytes(frame.data)
# log frame
if self._quic_logger is not None:
builder.quic_logger_frames.append(
self._quic_logger.encode_crypto_frame(frame)
)
return True
return False
===========changed ref 2===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_stream_frame(
self,
builder: QuicPacketBuilder,
space: QuicPacketSpace,
stream: QuicStream,
max_offset: int,
) -> int:
# the frame data size is constrained by our peer's MAX_DATA and
# the space available in the current packet
frame_overhead = (
3
+ size_uint_var(stream.stream_id)
+ + (
+ size_uint_var(stream.sender.next_offset)
+ if stream.sender.next_offset
+ else 0
+ )
- + (size_uint_var(stream.next_send_offset) if stream.next_send_offset else 0)
)
+ previous_send_highest = stream.sender.highest_offset
- previous_send_highest = stream._send_highest
+ frame = stream.sender.get_frame(
- frame = stream.get_frame(
builder.remaining_flight_space - frame_overhead, max_offset
)
if frame is not None:
frame_type = QuicFrameType.STREAM_BASE | 2 # length
if frame.offset:
frame_type |= 4
if frame.fin:
frame_type |= 1
buf = builder.start_frame(
frame_type,
capacity=frame_overhead,
+ handler=stream.sender.on_data_delivery,
- handler=stream.on_data_delivery,
handler_args=(frame.offset, frame.offset + len(frame.data)),
)
buf.push_uint_var(stream.stream_id)
if frame.offset:
buf.push_uint_var(frame.offset)
buf.push_uint16(len(frame.data) | 0x4000)
buf.push_bytes(frame.data)
# log frame
if self._quic_logger is not None:
builder.quic_logger_frames.</s>
===========changed ref 3===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_stream_frame(
self,
builder: QuicPacketBuilder,
space: QuicPacketSpace,
stream: QuicStream,
max_offset: int,
) -> int:
# offset: 1
<s>
# log frame
if self._quic_logger is not None:
builder.quic_logger_frames.append(
self._quic_logger.encode_stream_frame(
frame, stream_id=stream.stream_id
)
)
+ return stream.sender.highest_offset - previous_send_highest
- return stream._send_highest - previous_send_highest
else:
return 0
===========changed ref 4===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_handshake(
self, builder: QuicPacketBuilder, epoch: tls.Epoch, now: float
) -> None:
crypto = self._cryptos[epoch]
if not crypto.send.is_valid():
return
crypto_stream = self._crypto_streams[epoch]
space = self._spaces[epoch]
while True:
if epoch == tls.Epoch.INITIAL:
packet_type = PACKET_TYPE_INITIAL
else:
packet_type = PACKET_TYPE_HANDSHAKE
builder.start_packet(packet_type, crypto)
# ACK
if space.ack_at is not None:
self._write_ack_frame(builder=builder, space=space, now=now)
# CRYPTO
+ if not crypto_stream.sender.buffer_is_empty:
- if not crypto_stream.send_buffer_is_empty:
if self._write_crypto_frame(
builder=builder, space=space, stream=crypto_stream
):
self._probe_pending = False
# PING (probe)
if (
self._probe_pending
and not self._handshake_complete
and (
epoch == tls.Epoch.HANDSHAKE
or not self._cryptos[tls.Epoch.HANDSHAKE].send.is_valid()
)
):
self._write_ping_frame(builder, comment="probe")
self._probe_pending = False
if builder.packet_is_empty:
break
|
aioquic.quic.stream/QuicStream.__init__
|
Modified
|
aiortc~aioquic
|
5e39294f9a64b565b552419a85f4984c384e36be
|
[streams] split into QuicStreamReceiver / QuicStreamSender
|
<4>:<add> self.receiver = QuicStreamReceiver(stream_id=stream_id, readable=readable)
<add> self.sender = QuicStreamSender(stream_id=stream_id, writable=writable)
<add> self.stream_id = stream_id
<del> self.send_buffer_is_empty = True
<6>:<del> self._recv_buffer = bytearray()
<7>:<del> self._recv_buffer_start = 0 # the offset for the start of the buffer
<8>:<del> self._recv_final_size: Optional[int] = None
<9>:<del> self._recv_finished = not readable
<10>:<del> self._recv_highest = 0 # the highest offset ever seen
<11>:<del> self._recv_ranges = RangeSet()
<12>:<del>
<13>:<del> self._send_acked = RangeSet()
<14>:<del> self._send_buffer = bytearray()
<15>:<del> self._send_buffer_fin: Optional[int] = None
<16>:<del> self._send_buffer_start = 0 # the offset for the start of the buffer
<17>:<del> self._send_buffer_stop = 0 # the offset for the stop of the buffer
<18>:<del> self._send_finished = not writable
<19>:<del> self._send_highest = 0
<20>:<del> self._send_pending = RangeSet()
<21>:<del> self._send_pending_eof = False
<22>:<del> self._send_reset_error_code: Optional[int] = None
<23>:<del> self._send_reset_pending = False
<24>:<del>
<25>:<del> self.__stream_id = stream_id
<26>:<del>
|
# module: aioquic.quic.stream
class QuicStream:
def __init__(
self,
stream_id: Optional[int] = None,
max_stream_data_local: int = 0,
max_stream_data_remote: int = 0,
readable: bool = True,
writable: bool = True,
) -> None:
<0> self.is_blocked = False
<1> self.max_stream_data_local = max_stream_data_local
<2> self.max_stream_data_local_sent = max_stream_data_local
<3> self.max_stream_data_remote = max_stream_data_remote
<4> self.send_buffer_is_empty = True
<5>
<6> self._recv_buffer = bytearray()
<7> self._recv_buffer_start = 0 # the offset for the start of the buffer
<8> self._recv_final_size: Optional[int] = None
<9> self._recv_finished = not readable
<10> self._recv_highest = 0 # the highest offset ever seen
<11> self._recv_ranges = RangeSet()
<12>
<13> self._send_acked = RangeSet()
<14> self._send_buffer = bytearray()
<15> self._send_buffer_fin: Optional[int] = None
<16> self._send_buffer_start = 0 # the offset for the start of the buffer
<17> self._send_buffer_stop = 0 # the offset for the stop of the buffer
<18> self._send_finished = not writable
<19> self._send_highest = 0
<20> self._send_pending = RangeSet()
<21> self._send_pending_eof = False
<22> self._send_reset_error_code: Optional[int] = None
<23> self._send_reset_pending = False
<24>
<25> self.__stream_id = stream_id
<26>
|
===========unchanged ref 0===========
at: aioquic.quic.stream
FinalSizeError(*args: object)
at: aioquic.quic.stream.QuicStreamReceiver._pull_data
self._buffer_start = r.stop
at: aioquic.quic.stream.QuicStreamReceiver.handle_frame
self.is_finished = True
self._buffer += bytearray(gap)
at: aioquic.quic.stream.QuicStreamReceiver.handle_reset
self._final_size = final_size
self.is_finished = True
===========changed ref 0===========
# module: aioquic.quic.stream
+ class QuicStreamReceiver:
+ def __init__(self, stream_id: Optional[int], readable: bool) -> None:
+ self.highest_offset = 0 # the highest offset ever seen
+ self.is_finished = False
+
+ self._buffer = bytearray()
+ self._buffer_start = 0 # the offset for the start of the buffer
+ self._final_size: Optional[int] = None
+ self._ranges = RangeSet()
+ self._stream_id = stream_id
+
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def _push_crypto_data(self) -> None:
for epoch, buf in self._crypto_buffers.items():
+ self._crypto_streams[epoch].sender.write(buf.data)
- self._crypto_streams[epoch].write(buf.data)
buf.seek(0)
===========changed ref 2===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
+ def test_receiver_fin_without_data(self):
+ stream = QuicStream(stream_id=0)
+ self.assertEqual(
+ stream.receiver.handle_frame(QuicStreamFrame(offset=0, data=b"", fin=True)),
+ StreamDataReceived(data=b"", end_stream=True, stream_id=0),
+ )
+
===========changed ref 3===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
+ def test_receiver_reset(self):
+ stream = QuicStream(stream_id=0)
+ self.assertEqual(
+ stream.receiver.handle_reset(final_size=4),
+ StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
+ )
+ self.assertTrue(stream.receiver.is_finished)
+
===========changed ref 4===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
- def test_recv_fin_without_data(self):
- stream = QuicStream(stream_id=0)
- self.assertEqual(
- stream.add_frame(QuicStreamFrame(offset=0, data=b"", fin=True)),
- StreamDataReceived(data=b"", end_stream=True, stream_id=0),
- )
-
===========changed ref 5===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
- def test_recv_reset(self):
- stream = QuicStream(stream_id=0)
- self.assertEqual(
- stream.handle_reset(final_size=4),
- StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
- )
- self.assertTrue(stream._recv_finished)
-
===========changed ref 6===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
+ def test_receiver_reset_after_fin(self):
+ stream = QuicStream(stream_id=0)
+ stream.receiver.handle_frame(QuicStreamFrame(offset=0, data=b"0123", fin=True))
+ self.assertEqual(
+ stream.receiver.handle_reset(final_size=4),
+ StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
+ )
+
===========changed ref 7===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
- def test_recv_reset_after_fin(self):
- stream = QuicStream(stream_id=0)
- stream.add_frame(QuicStreamFrame(offset=0, data=b"0123", fin=True)),
- self.assertEqual(
- stream.handle_reset(final_size=4),
- StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
- )
-
===========changed ref 8===========
# module: aioquic.quic.connection
class QuicConnection:
def reset_stream(self, stream_id: int, error_code: int) -> None:
"""
Abruptly terminate the sending part of a stream.
:param stream_id: The stream's ID.
:param error_code: An error code indicating why the stream is being reset.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.reset(error_code)
- stream.reset(error_code)
===========changed ref 9===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
+ def test_receiver_reset_twice(self):
+ stream = QuicStream(stream_id=0)
+ self.assertEqual(
+ stream.receiver.handle_reset(final_size=4),
+ StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
+ )
+ self.assertEqual(
+ stream.receiver.handle_reset(final_size=4),
+ StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
+ )
+
===========changed ref 10===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
+ def test_receiver_reset_twice_final_size_error(self):
+ stream = QuicStream(stream_id=0)
+ self.assertEqual(
+ stream.receiver.handle_reset(final_size=4),
+ StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
+ )
+
+ with self.assertRaises(FinalSizeError) as cm:
+ stream.receiver.handle_reset(final_size=5)
+ self.assertEqual(str(cm.exception), "Cannot change final size")
+
===========changed ref 11===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
- def test_recv_reset_twice(self):
- stream = QuicStream(stream_id=0)
- self.assertEqual(
- stream.handle_reset(final_size=4),
- StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
- )
- self.assertEqual(
- stream.handle_reset(final_size=4),
- StreamReset(error_code=QuicErrorCode.NO_ERROR, stream_id=0),
- )
-
===========changed ref 12===========
# module: aioquic.quic.connection
class QuicConnection:
def send_stream_data(
self, stream_id: int, data: bytes, end_stream: bool = False
) -> None:
"""
Send data on the specific stream.
:param stream_id: The stream's ID.
:param data: The data to be sent.
:param end_stream: If set to `True`, the FIN bit will be set.
"""
stream = self._get_or_create_stream_for_send(stream_id)
+ stream.sender.write(data, end_stream=end_stream)
- stream.write(data, end_stream=end_stream)
|
tests.test_connection/QuicConnectionTest.test_handle_new_connection_id_with_retire_prior_to
|
Modified
|
aiortc~aioquic
|
55b531a1dab7498efd5bd5e0052d8e996a2a370b
|
[stream] add API to stop receiving (fixes: #193)
|
<1>:<add> buf = Buffer(capacity=42)
<del> buf = Buffer(capacity=100)
|
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_handle_new_connection_id_with_retire_prior_to(self):
<0> with client_and_server() as (client, server):
<1> buf = Buffer(capacity=100)
<2> buf.push_uint_var(8) # sequence_number
<3> buf.push_uint_var(2) # retire_prior_to
<4> buf.push_uint_var(8)
<5> buf.push_bytes(bytes(8))
<6> buf.push_bytes(bytes(16))
<7> buf.seek(0)
<8>
<9> # client receives NEW_CONNECTION_ID
<10> client._handle_new_connection_id_frame(
<11> client_receive_context(client),
<12> QuicFrameType.NEW_CONNECTION_ID,
<13> buf,
<14> )
<15>
<16> self.assertEqual(client._peer_cid.sequence_number, 2)
<17> self.assertEqual(
<18> sequence_numbers(client._peer_cid_available), [3, 4, 5, 6, 7, 8]
<19> )
<20>
|
===========unchanged ref 0===========
at: tests.test_connection
client_receive_context(client, epoch=tls.Epoch.ONE_RTT)
client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_certfile=SERVER_CERTFILE, server_keyfile=SERVER_KEYFILE, server_options={}, server_patch=lambda x: None)
sequence_numbers(connection_ids)
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
|
aioquic.quic.stream/QuicStreamReceiver.__init__
|
Modified
|
aiortc~aioquic
|
55b531a1dab7498efd5bd5e0052d8e996a2a370b
|
[stream] add API to stop receiving (fixes: #193)
|
<2>:<add> self.stop_pending = False
<8>:<add> self._stop_error_code: Optional[int] = None
|
# module: aioquic.quic.stream
class QuicStreamReceiver:
def __init__(self, stream_id: Optional[int], readable: bool) -> None:
<0> self.highest_offset = 0 # the highest offset ever seen
<1> self.is_finished = False
<2>
<3> self._buffer = bytearray()
<4> self._buffer_start = 0 # the offset for the start of the buffer
<5> self._final_size: Optional[int] = None
<6> self._ranges = RangeSet()
<7> self._stream_id = stream_id
<8>
|
===========changed ref 0===========
# module: aioquic.quic.packet
+ @dataclass
+ class QuicStopSendingFrame:
+ error_code: int
+ stream_id: int
+
===========changed ref 1===========
# module: aioquic.quic.packet
@dataclass
class QuicResetStreamFrame:
error_code: int
final_size: int
+ stream_id: int
===========changed ref 2===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def test_send_stop_sending_unknown_stream(self):
+ with client_and_server() as (client, server):
+ # check handshake completed
+ self.check_handshake(client=client, server=server)
+
+ # client sends STOP_SENDING frame
+ with self.assertRaises(ValueError) as cm:
+ client.stop_stream(0, QuicErrorCode.NO_ERROR)
+ self.assertEqual(
+ str(cm.exception), "Cannot stop receiving on an unknown stream"
+ )
+
===========changed ref 3===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def test_send_stop_sending_uni_stream(self):
+ with client_and_server() as (client, server):
+ # check handshake completed
+ self.check_handshake(client=client, server=server)
+
+ # client sends STOP_SENDING frame
+ with self.assertRaises(ValueError) as cm:
+ client.stop_stream(2, QuicErrorCode.NO_ERROR)
+ self.assertEqual(
+ str(cm.exception),
+ "Cannot stop receiving on a local-initiated unidirectional stream",
+ )
+
===========changed ref 4===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
+ def test_receiver_stop(self):
+ stream = QuicStream()
+
+ # stop is requested
+ stream.receiver.stop(QuicErrorCode.NO_ERROR)
+ self.assertTrue(stream.receiver.stop_pending)
+
+ # stop is sent
+ frame = stream.receiver.get_stop_frame()
+ self.assertEqual(frame.error_code, QuicErrorCode.NO_ERROR)
+ self.assertFalse(stream.receiver.stop_pending)
+
+ # stop is acklowledged
+ stream.receiver.on_stop_sending_delivery(QuicDeliveryState.ACKED)
+ self.assertFalse(stream.receiver.stop_pending)
+
===========changed ref 5===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def test_send_stop_sending(self):
+ with client_and_server() as (client, server):
+ # check handshake completed
+ self.check_handshake(client=client, server=server)
+
+ # client creates bidirectional stream
+ client.send_stream_data(0, b"hello")
+ self.assertEqual(roundtrip(client, server), (1, 1))
+
+ # client sends STOP_SENDING frame
+ client.stop_stream(0, QuicErrorCode.NO_ERROR)
+ self.assertEqual(roundtrip(client, server), (1, 1))
+
+ # client receives STREAM_RESET frame
+ event = client.next_event()
+ self.assertEqual(type(event), events.StreamReset)
+ self.assertEqual(event.error_code, QuicErrorCode.NO_ERROR)
+ self.assertEqual(event.stream_id, 0)
+
===========changed ref 6===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_handle_new_connection_id_with_retire_prior_to(self):
with client_and_server() as (client, server):
+ buf = Buffer(capacity=42)
- buf = Buffer(capacity=100)
buf.push_uint_var(8) # sequence_number
buf.push_uint_var(2) # retire_prior_to
buf.push_uint_var(8)
buf.push_bytes(bytes(8))
buf.push_bytes(bytes(16))
buf.seek(0)
# client receives NEW_CONNECTION_ID
client._handle_new_connection_id_frame(
client_receive_context(client),
QuicFrameType.NEW_CONNECTION_ID,
buf,
)
self.assertEqual(client._peer_cid.sequence_number, 2)
self.assertEqual(
sequence_numbers(client._peer_cid_available), [3, 4, 5, 6, 7, 8]
)
===========changed ref 7===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
+ def test_receiver_stop_lost(self):
+ stream = QuicStream()
+
+ # stop is requested
+ stream.receiver.stop(QuicErrorCode.NO_ERROR)
+ self.assertTrue(stream.receiver.stop_pending)
+
+ # stop is sent
+ frame = stream.receiver.get_stop_frame()
+ self.assertEqual(frame.error_code, QuicErrorCode.NO_ERROR)
+ self.assertFalse(stream.receiver.stop_pending)
+
+ # stop is lost
+ stream.receiver.on_stop_sending_delivery(QuicDeliveryState.LOST)
+ self.assertTrue(stream.receiver.stop_pending)
+
+ # stop is sent again
+ frame = stream.receiver.get_stop_frame()
+ self.assertEqual(frame.error_code, QuicErrorCode.NO_ERROR)
+ self.assertFalse(stream.receiver.stop_pending)
+
+ # stop is acklowledged
+ stream.receiver.on_stop_sending_delivery(QuicDeliveryState.ACKED)
+ self.assertFalse(stream.receiver.stop_pending)
+
|
aioquic.quic.stream/QuicStreamSender.get_reset_frame
|
Modified
|
aiortc~aioquic
|
55b531a1dab7498efd5bd5e0052d8e996a2a370b
|
[stream] add API to stop receiving (fixes: #193)
|
<2>:<add> error_code=self._reset_error_code,
<add> final_size=self.highest_offset,
<add> stream_id=self._stream_id,
<del> error_code=self._reset_error_code, final_size=self.highest_offset
|
# module: aioquic.quic.stream
class QuicStreamSender:
def get_reset_frame(self) -> QuicResetStreamFrame:
<0> self.reset_pending = False
<1> return QuicResetStreamFrame(
<2> error_code=self._reset_error_code, final_size=self.highest_offset
<3> )
<4>
|
===========changed ref 0===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
+ def stop(self, error_code: int = QuicErrorCode.NO_ERROR) -> None:
+ """
+ Request the peer stop sending data on the QUIC stream.
+ """
+ self._stop_error_code = error_code
+ self.stop_pending = True
+
===========changed ref 1===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
+ def on_stop_sending_delivery(self, delivery: QuicDeliveryState) -> None:
+ """
+ Callback when a STOP_SENDING is ACK'd.
+ """
+ if delivery != QuicDeliveryState.ACKED:
+ self.stop_pending = True
+
===========changed ref 2===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
+ def get_stop_frame(self) -> QuicStopSendingFrame:
+ self.stop_pending = False
+ return QuicStopSendingFrame(
+ error_code=self._stop_error_code,
+ stream_id=self._stream_id,
+ )
+
===========changed ref 3===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
def __init__(self, stream_id: Optional[int], readable: bool) -> None:
self.highest_offset = 0 # the highest offset ever seen
self.is_finished = False
+ self.stop_pending = False
self._buffer = bytearray()
self._buffer_start = 0 # the offset for the start of the buffer
self._final_size: Optional[int] = None
self._ranges = RangeSet()
self._stream_id = stream_id
+ self._stop_error_code: Optional[int] = None
===========changed ref 4===========
# module: aioquic.quic.packet
+ @dataclass
+ class QuicStopSendingFrame:
+ error_code: int
+ stream_id: int
+
===========changed ref 5===========
# module: aioquic.quic.packet
@dataclass
class QuicResetStreamFrame:
error_code: int
final_size: int
+ stream_id: int
===========changed ref 6===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def test_send_stop_sending_unknown_stream(self):
+ with client_and_server() as (client, server):
+ # check handshake completed
+ self.check_handshake(client=client, server=server)
+
+ # client sends STOP_SENDING frame
+ with self.assertRaises(ValueError) as cm:
+ client.stop_stream(0, QuicErrorCode.NO_ERROR)
+ self.assertEqual(
+ str(cm.exception), "Cannot stop receiving on an unknown stream"
+ )
+
===========changed ref 7===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def test_send_stop_sending_uni_stream(self):
+ with client_and_server() as (client, server):
+ # check handshake completed
+ self.check_handshake(client=client, server=server)
+
+ # client sends STOP_SENDING frame
+ with self.assertRaises(ValueError) as cm:
+ client.stop_stream(2, QuicErrorCode.NO_ERROR)
+ self.assertEqual(
+ str(cm.exception),
+ "Cannot stop receiving on a local-initiated unidirectional stream",
+ )
+
===========changed ref 8===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
+ def test_receiver_stop(self):
+ stream = QuicStream()
+
+ # stop is requested
+ stream.receiver.stop(QuicErrorCode.NO_ERROR)
+ self.assertTrue(stream.receiver.stop_pending)
+
+ # stop is sent
+ frame = stream.receiver.get_stop_frame()
+ self.assertEqual(frame.error_code, QuicErrorCode.NO_ERROR)
+ self.assertFalse(stream.receiver.stop_pending)
+
+ # stop is acklowledged
+ stream.receiver.on_stop_sending_delivery(QuicDeliveryState.ACKED)
+ self.assertFalse(stream.receiver.stop_pending)
+
===========changed ref 9===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def test_send_stop_sending(self):
+ with client_and_server() as (client, server):
+ # check handshake completed
+ self.check_handshake(client=client, server=server)
+
+ # client creates bidirectional stream
+ client.send_stream_data(0, b"hello")
+ self.assertEqual(roundtrip(client, server), (1, 1))
+
+ # client sends STOP_SENDING frame
+ client.stop_stream(0, QuicErrorCode.NO_ERROR)
+ self.assertEqual(roundtrip(client, server), (1, 1))
+
+ # client receives STREAM_RESET frame
+ event = client.next_event()
+ self.assertEqual(type(event), events.StreamReset)
+ self.assertEqual(event.error_code, QuicErrorCode.NO_ERROR)
+ self.assertEqual(event.stream_id, 0)
+
===========changed ref 10===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_handle_new_connection_id_with_retire_prior_to(self):
with client_and_server() as (client, server):
+ buf = Buffer(capacity=42)
- buf = Buffer(capacity=100)
buf.push_uint_var(8) # sequence_number
buf.push_uint_var(2) # retire_prior_to
buf.push_uint_var(8)
buf.push_bytes(bytes(8))
buf.push_bytes(bytes(16))
buf.seek(0)
# client receives NEW_CONNECTION_ID
client._handle_new_connection_id_frame(
client_receive_context(client),
QuicFrameType.NEW_CONNECTION_ID,
buf,
)
self.assertEqual(client._peer_cid.sequence_number, 2)
self.assertEqual(
sequence_numbers(client._peer_cid_available), [3, 4, 5, 6, 7, 8]
)
===========changed ref 11===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
+ def test_receiver_stop_lost(self):
+ stream = QuicStream()
+
+ # stop is requested
+ stream.receiver.stop(QuicErrorCode.NO_ERROR)
+ self.assertTrue(stream.receiver.stop_pending)
+
+ # stop is sent
+ frame = stream.receiver.get_stop_frame()
+ self.assertEqual(frame.error_code, QuicErrorCode.NO_ERROR)
+ self.assertFalse(stream.receiver.stop_pending)
+
+ # stop is lost
+ stream.receiver.on_stop_sending_delivery(QuicDeliveryState.LOST)
+ self.assertTrue(stream.receiver.stop_pending)
+
+ # stop is sent again
+ frame = stream.receiver.get_stop_frame()
+ self.assertEqual(frame.error_code, QuicErrorCode.NO_ERROR)
+ self.assertFalse(stream.receiver.stop_pending)
+
+ # stop is acklowledged
+ stream.receiver.on_stop_sending_delivery(QuicDeliveryState.ACKED)
+ self.assertFalse(stream.receiver.stop_pending)
+
|
aioquic.quic.connection/QuicConnection._get_or_create_stream_for_send
|
Modified
|
aiortc~aioquic
|
55b531a1dab7498efd5bd5e0052d8e996a2a370b
|
[stream] add API to stop receiving (fixes: #193)
|
<5>:<del> if stream_is_client_initiated(stream_id) != self._is_client:
<6>:<del> if stream_id not in self._streams:
<7>:<del> raise ValueError("Cannot send data on unknown peer-initiated stream")
<8>:<del> if stream_is_unidirectional(stream_id):
<9>:<del> raise ValueError(
<10>:<add> if not self._stream_can_send(stream_id):
<add> raise ValueError("Cannot send data on peer-initiated unidirectional stream")
<del> "Cannot send data on peer-initiated unidirectional stream"
<11>:<del> )
<15>:<add> # check initiator
<add> if stream_is_client_initiated(stream_id) != self._is_client:
<add> raise ValueError("Cannot send data on unknown peer-initiated stream")
<add>
|
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream_for_send(self, stream_id: int) -> QuicStream:
<0> """
<1> Get or create a QUIC stream in order to send data to the peer.
<2>
<3> This always occurs as a result of an API call.
<4> """
<5> if stream_is_client_initiated(stream_id) != self._is_client:
<6> if stream_id not in self._streams:
<7> raise ValueError("Cannot send data on unknown peer-initiated stream")
<8> if stream_is_unidirectional(stream_id):
<9> raise ValueError(
<10> "Cannot send data on peer-initiated unidirectional stream"
<11> )
<12>
<13> stream = self._streams.get(stream_id, None)
<14> if stream is None:
<15> # determine limits
<16> if stream_is_unidirectional(stream_id):
<17> max_stream_data_local = 0
<18> max_stream_data_remote = self._remote_max_stream_data_uni
<19> max_streams = self._remote_max_streams_uni
<20> streams_blocked = self._streams_blocked_uni
<21> else:
<22> max_stream_data_local = self._local_max_stream_data_bidi_local
<23> max_stream_data_remote = self._remote_max_stream_data_bidi_remote
<24> max_streams = self._remote_max_streams_bidi
<25> streams_blocked = self._streams_blocked_bidi
<26>
<27> # create stream
<28> stream = self._streams[stream_id] = QuicStream(
<29> stream_id=stream_id,
<30> max_stream_data_local=max_stream_data_local,
<31> max_stream_data_remote=max_stream_data_remote,
<32> readable=not stream_is_unidirectional(stream_id),
<33> )
<34>
<35> # mark stream as blocked if needed
<36> if stream_id // 4 >= max_streams</s>
|
===========below chunk 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream_for_send(self, stream_id: int) -> QuicStream:
# offset: 1
stream.is_blocked = True
streams_blocked.append(stream)
self._streams_blocked_pending = True
return stream
===========unchanged ref 0===========
at: aioquic.quic.connection
stream_is_client_initiated(stream_id: int) -> bool
stream_is_unidirectional(stream_id: int) -> bool
QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)
at: aioquic.quic.connection.Limit.__init__
self.used = 0
self.value = value
at: aioquic.quic.connection.QuicConnection
_stream_can_send(stream_id: int) -> bool
at: aioquic.quic.connection.QuicConnection.__init__
self._is_client = configuration.is_client
self._local_max_stream_data_bidi_local = configuration.max_stream_data
self._remote_max_stream_data_uni = 0
self._remote_max_streams_uni = 0
self._streams: Dict[int, QuicStream] = {}
self._streams_blocked_uni: List[QuicStream] = []
self._logger = QuicConnectionAdapter(
logger, {"id": dump_cid(self._original_destination_connection_id)}
)
at: aioquic.quic.connection.QuicConnection._get_or_create_stream
max_stream_data_local = self._local_max_stream_data_uni
max_stream_data_local = self._local_max_stream_data_bidi_remote
max_stream_data_remote = 0
max_stream_data_remote = self._remote_max_stream_data_bidi_local
max_streams = self._local_max_streams_uni
max_streams = self._local_max_streams_bidi
stream_count = (stream_id // 4) + 1
at: aioquic.quic.connection.QuicConnection._handle_max_streams_uni_frame
self._remote_max_streams_uni = max_streams
===========unchanged ref 1===========
at: logging.LoggerAdapter
logger: Logger
extra: Mapping[str, Any]
debug(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
at: typing.Mapping
get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]
get(key: _KT) -> Optional[_VT_co]
===========changed ref 0===========
# module: aioquic.quic.connection
class QuicConnection:
+ def stop_stream(self, stream_id: int, error_code: int) -> None:
+ """
+ Request termination of the receiving part of a stream.
+
+ :param stream_id: The stream's ID.
+ :param error_code: An error code indicating why the stream is being stopped.
+ """
+ if not self._stream_can_receive(stream_id):
+ raise ValueError(
+ "Cannot stop receiving on a local-initiated unidirectional stream"
+ )
+
+ stream = self._streams.get(stream_id, None)
+ if stream is None:
+ raise ValueError("Cannot stop receiving on an unknown stream")
+
+ stream.receiver.stop(error_code)
+
===========changed ref 1===========
# module: aioquic.quic.packet
+ @dataclass
+ class QuicStopSendingFrame:
+ error_code: int
+ stream_id: int
+
===========changed ref 2===========
# module: aioquic.quic.packet
@dataclass
class QuicResetStreamFrame:
error_code: int
final_size: int
+ stream_id: int
===========changed ref 3===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
+ def on_stop_sending_delivery(self, delivery: QuicDeliveryState) -> None:
+ """
+ Callback when a STOP_SENDING is ACK'd.
+ """
+ if delivery != QuicDeliveryState.ACKED:
+ self.stop_pending = True
+
===========changed ref 4===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
+ def stop(self, error_code: int = QuicErrorCode.NO_ERROR) -> None:
+ """
+ Request the peer stop sending data on the QUIC stream.
+ """
+ self._stop_error_code = error_code
+ self.stop_pending = True
+
===========changed ref 5===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
+ def get_stop_frame(self) -> QuicStopSendingFrame:
+ self.stop_pending = False
+ return QuicStopSendingFrame(
+ error_code=self._stop_error_code,
+ stream_id=self._stream_id,
+ )
+
===========changed ref 6===========
# module: aioquic.quic.stream
class QuicStreamSender:
def get_reset_frame(self) -> QuicResetStreamFrame:
self.reset_pending = False
return QuicResetStreamFrame(
+ error_code=self._reset_error_code,
+ final_size=self.highest_offset,
+ stream_id=self._stream_id,
- error_code=self._reset_error_code, final_size=self.highest_offset
)
===========changed ref 7===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def test_send_stop_sending_unknown_stream(self):
+ with client_and_server() as (client, server):
+ # check handshake completed
+ self.check_handshake(client=client, server=server)
+
+ # client sends STOP_SENDING frame
+ with self.assertRaises(ValueError) as cm:
+ client.stop_stream(0, QuicErrorCode.NO_ERROR)
+ self.assertEqual(
+ str(cm.exception), "Cannot stop receiving on an unknown stream"
+ )
+
===========changed ref 8===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
def __init__(self, stream_id: Optional[int], readable: bool) -> None:
self.highest_offset = 0 # the highest offset ever seen
self.is_finished = False
+ self.stop_pending = False
self._buffer = bytearray()
self._buffer_start = 0 # the offset for the start of the buffer
self._final_size: Optional[int] = None
self._ranges = RangeSet()
self._stream_id = stream_id
+ self._stop_error_code: Optional[int] = None
===========changed ref 9===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def test_send_stop_sending_uni_stream(self):
+ with client_and_server() as (client, server):
+ # check handshake completed
+ self.check_handshake(client=client, server=server)
+
+ # client sends STOP_SENDING frame
+ with self.assertRaises(ValueError) as cm:
+ client.stop_stream(2, QuicErrorCode.NO_ERROR)
+ self.assertEqual(
+ str(cm.exception),
+ "Cannot stop receiving on a local-initiated unidirectional stream",
+ )
+
|
aioquic.quic.connection/QuicConnection._handle_stop_sending_frame
|
Modified
|
aiortc~aioquic
|
55b531a1dab7498efd5bd5e0052d8e996a2a370b
|
[stream] add API to stop receiving (fixes: #193)
|
<17>:<add> # reset the stream
<add> stream = self._get_or_create_stream(frame_type, stream_id)
<del> self._get_or_create_stream(frame_type, stream_id)
<18>:<add> stream.sender.reset(error_code=QuicErrorCode.NO_ERROR)
|
# module: aioquic.quic.connection
class QuicConnection:
def _handle_stop_sending_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
<0> """
<1> Handle a STOP_SENDING frame.
<2> """
<3> stream_id = buf.pull_uint_var()
<4> error_code = buf.pull_uint_var() # application error code
<5>
<6> # log frame
<7> if self._quic_logger is not None:
<8> context.quic_logger_frames.append(
<9> self._quic_logger.encode_stop_sending_frame(
<10> error_code=error_code, stream_id=stream_id
<11> )
<12> )
<13>
<14> # check stream direction
<15> self._assert_stream_can_send(frame_type, stream_id)
<16>
<17> self._get_or_create_stream(frame_type, stream_id)
<18>
|
===========unchanged ref 0===========
at: aioquic.quic.connection
dump_cid(cid: bytes) -> str
QuicReceiveContext(epoch: tls.Epoch, host_cid: bytes, network_path: QuicNetworkPath, quic_logger_frames: Optional[List[Any]], time: float)
at: aioquic.quic.connection.QuicConnection
_replenish_connection_ids() -> None
at: aioquic.quic.connection.QuicConnection.__init__
self._events: Deque[events.QuicEvent] = deque()
self._host_cids = [
QuicConnectionId(
cid=os.urandom(configuration.connection_id_length),
sequence_number=0,
stateless_reset_token=os.urandom(16) if not self._is_client else None,
was_sent=True,
)
]
self._logger = QuicConnectionAdapter(
logger, {"id": dump_cid(self._original_destination_connection_id)}
)
at: aioquic.quic.connection.QuicConnectionId
cid: bytes
sequence_number: int
stateless_reset_token: bytes = b""
was_sent: bool = False
at: collections.deque
append(x: _T) -> None
at: logging.LoggerAdapter
debug(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
===========changed ref 0===========
# module: aioquic.quic.packet
+ @dataclass
+ class QuicStopSendingFrame:
+ error_code: int
+ stream_id: int
+
===========changed ref 1===========
# module: aioquic.quic.packet
@dataclass
class QuicResetStreamFrame:
error_code: int
final_size: int
+ stream_id: int
===========changed ref 2===========
# module: aioquic.quic.connection
class QuicConnection:
+ def stop_stream(self, stream_id: int, error_code: int) -> None:
+ """
+ Request termination of the receiving part of a stream.
+
+ :param stream_id: The stream's ID.
+ :param error_code: An error code indicating why the stream is being stopped.
+ """
+ if not self._stream_can_receive(stream_id):
+ raise ValueError(
+ "Cannot stop receiving on a local-initiated unidirectional stream"
+ )
+
+ stream = self._streams.get(stream_id, None)
+ if stream is None:
+ raise ValueError("Cannot stop receiving on an unknown stream")
+
+ stream.receiver.stop(error_code)
+
===========changed ref 3===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
+ def on_stop_sending_delivery(self, delivery: QuicDeliveryState) -> None:
+ """
+ Callback when a STOP_SENDING is ACK'd.
+ """
+ if delivery != QuicDeliveryState.ACKED:
+ self.stop_pending = True
+
===========changed ref 4===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
+ def stop(self, error_code: int = QuicErrorCode.NO_ERROR) -> None:
+ """
+ Request the peer stop sending data on the QUIC stream.
+ """
+ self._stop_error_code = error_code
+ self.stop_pending = True
+
===========changed ref 5===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
+ def get_stop_frame(self) -> QuicStopSendingFrame:
+ self.stop_pending = False
+ return QuicStopSendingFrame(
+ error_code=self._stop_error_code,
+ stream_id=self._stream_id,
+ )
+
===========changed ref 6===========
# module: aioquic.quic.stream
class QuicStreamSender:
def get_reset_frame(self) -> QuicResetStreamFrame:
self.reset_pending = False
return QuicResetStreamFrame(
+ error_code=self._reset_error_code,
+ final_size=self.highest_offset,
+ stream_id=self._stream_id,
- error_code=self._reset_error_code, final_size=self.highest_offset
)
===========changed ref 7===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def test_send_stop_sending_unknown_stream(self):
+ with client_and_server() as (client, server):
+ # check handshake completed
+ self.check_handshake(client=client, server=server)
+
+ # client sends STOP_SENDING frame
+ with self.assertRaises(ValueError) as cm:
+ client.stop_stream(0, QuicErrorCode.NO_ERROR)
+ self.assertEqual(
+ str(cm.exception), "Cannot stop receiving on an unknown stream"
+ )
+
===========changed ref 8===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
def __init__(self, stream_id: Optional[int], readable: bool) -> None:
self.highest_offset = 0 # the highest offset ever seen
self.is_finished = False
+ self.stop_pending = False
self._buffer = bytearray()
self._buffer_start = 0 # the offset for the start of the buffer
self._final_size: Optional[int] = None
self._ranges = RangeSet()
self._stream_id = stream_id
+ self._stop_error_code: Optional[int] = None
===========changed ref 9===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def test_send_stop_sending_uni_stream(self):
+ with client_and_server() as (client, server):
+ # check handshake completed
+ self.check_handshake(client=client, server=server)
+
+ # client sends STOP_SENDING frame
+ with self.assertRaises(ValueError) as cm:
+ client.stop_stream(2, QuicErrorCode.NO_ERROR)
+ self.assertEqual(
+ str(cm.exception),
+ "Cannot stop receiving on a local-initiated unidirectional stream",
+ )
+
===========changed ref 10===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
+ def test_receiver_stop(self):
+ stream = QuicStream()
+
+ # stop is requested
+ stream.receiver.stop(QuicErrorCode.NO_ERROR)
+ self.assertTrue(stream.receiver.stop_pending)
+
+ # stop is sent
+ frame = stream.receiver.get_stop_frame()
+ self.assertEqual(frame.error_code, QuicErrorCode.NO_ERROR)
+ self.assertFalse(stream.receiver.stop_pending)
+
+ # stop is acklowledged
+ stream.receiver.on_stop_sending_delivery(QuicDeliveryState.ACKED)
+ self.assertFalse(stream.receiver.stop_pending)
+
|
aioquic.quic.connection/QuicConnection._write_application
|
Modified
|
aiortc~aioquic
|
55b531a1dab7498efd5bd5e0052d8e996a2a370b
|
[stream] add API to stop receiving (fixes: #193)
|
# module: aioquic.quic.connection
class QuicConnection:
def _write_application(
self, builder: QuicPacketBuilder, network_path: QuicNetworkPath, now: float
) -> None:
<0> crypto_stream: Optional[QuicStream] = None
<1> if self._cryptos[tls.Epoch.ONE_RTT].send.is_valid():
<2> crypto = self._cryptos[tls.Epoch.ONE_RTT]
<3> crypto_stream = self._crypto_streams[tls.Epoch.ONE_RTT]
<4> packet_type = PACKET_TYPE_ONE_RTT
<5> elif self._cryptos[tls.Epoch.ZERO_RTT].send.is_valid():
<6> crypto = self._cryptos[tls.Epoch.ZERO_RTT]
<7> packet_type = PACKET_TYPE_ZERO_RTT
<8> else:
<9> return
<10> space = self._spaces[tls.Epoch.ONE_RTT]
<11>
<12> while True:
<13> # apply pacing, except if we have ACKs to send
<14> if space.ack_at is None or space.ack_at >= now:
<15> self._pacing_at = self._loss._pacer.next_send_time(now=now)
<16> if self._pacing_at is not None:
<17> break
<18> builder.start_packet(packet_type, crypto)
<19>
<20> if self._handshake_complete:
<21> # ACK
<22> if space.ack_at is not None and space.ack_at <= now:
<23> self._write_ack_frame(builder=builder, space=space, now=now)
<24>
<25> # HANDSHAKE_DONE
<26> if self._handshake_done_pending:
<27> self._write_handshake_done_frame(builder=builder)
<28> self._handshake_done_pending = False
<29>
<30> # PATH CHALLENGE
<31> if (
<32> not network_path.is_validated
<33> and network_path.local_challenge is None
<34> ):
<35> challenge = os.ur</s>
|
===========below chunk 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_application(
self, builder: QuicPacketBuilder, network_path: QuicNetworkPath, now: float
) -> None:
# offset: 1
self._write_path_challenge_frame(
builder=builder, challenge=challenge
)
network_path.local_challenge = challenge
# PATH RESPONSE
if network_path.remote_challenge is not None:
self._write_path_response_frame(
builder=builder, challenge=network_path.remote_challenge
)
network_path.remote_challenge = None
# NEW_CONNECTION_ID
for connection_id in self._host_cids:
if not connection_id.was_sent:
self._write_new_connection_id_frame(
builder=builder, connection_id=connection_id
)
# RETIRE_CONNECTION_ID
for sequence_number in self._retire_connection_ids[:]:
self._write_retire_connection_id_frame(
builder=builder, sequence_number=sequence_number
)
self._retire_connection_ids.pop(0)
# STREAMS_BLOCKED
if self._streams_blocked_pending:
if self._streams_blocked_bidi:
self._write_streams_blocked_frame(
builder=builder,
frame_type=QuicFrameType.STREAMS_BLOCKED_BIDI,
limit=self._remote_max_streams_bidi,
)
if self._streams_blocked_uni:
self._write_streams_blocked_frame(
builder=builder,
frame_type=QuicFrameType.STREAMS_BLOCKED_UNI,
limit=self._remote_max_streams_uni,
)
self._streams_blocked_pending = False
# MAX_DATA and MAX_STREAMS
self._write_connection_limits(builder=builder, space=space)
# stream-level limits
for stream in self._streams.values():
</s>
===========below chunk 1===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_application(
self, builder: QuicPacketBuilder, network_path: QuicNetworkPath, now: float
) -> None:
# offset: 2
<s>(builder=builder, space=space)
# stream-level limits
for stream in self._streams.values():
self._write_stream_limits(builder=builder, space=space, stream=stream)
# PING (user-request)
if self._ping_pending:
self._write_ping_frame(builder, self._ping_pending)
self._ping_pending.clear()
# PING (probe)
if self._probe_pending:
self._write_ping_frame(builder, comment="probe")
self._probe_pending = False
# CRYPTO
if crypto_stream is not None and not crypto_stream.sender.buffer_is_empty:
self._write_crypto_frame(
builder=builder, space=space, stream=crypto_stream
)
# DATAGRAM
while self._datagrams_pending:
try:
self._write_datagram_frame(
builder=builder,
data=self._datagrams_pending[0],
frame_type=QuicFrameType.DATAGRAM_WITH_LENGTH,
)
self._datagrams_pending.popleft()
except QuicPacketBuilderStop:
break
# STREAM and RESET_STREAM
for stream in self._streams.values():
if stream.sender.reset_pending:
self._write_reset_stream_frame(
builder=builder,
frame_type=QuicFrameType.RESET_STREAM,
stream=stream,
)
elif not stream.is_blocked and not stream.sender.buffer_is_empty:
self._remote_max_data_used += self._write_stream_frame(
builder=</s>
===========below chunk 2===========
# module: aioquic.quic.connection
class QuicConnection:
def _write_application(
self, builder: QuicPacketBuilder, network_path: QuicNetworkPath, now: float
) -> None:
# offset: 3
<s>
space=space,
stream=stream,
max_offset=min(
stream.sender.highest_offset
+ self._remote_max_data
- self._remote_max_data_used,
stream.max_stream_data_remote,
),
)
if builder.packet_is_empty:
break
else:
self._loss._pacer.update_after_send(now=now)
===========unchanged ref 0===========
at: aioquic.quic.connection
SECRETS_LABELS = [
[
None,
"CLIENT_EARLY_TRAFFIC_SECRET",
"CLIENT_HANDSHAKE_TRAFFIC_SECRET",
"CLIENT_TRAFFIC_SECRET_0",
],
[
None,
None,
"SERVER_HANDSHAKE_TRAFFIC_SECRET",
"SERVER_TRAFFIC_SECRET_0",
],
]
QuicNetworkPath(addr: NetworkAddress, bytes_received: int=0, bytes_sent: int=0, is_validated: bool=False, local_challenge: Optional[bytes]=None, remote_challenge: Optional[bytes]=None)
at: aioquic.quic.connection.QuicConnection
_write_ack_frame(builder: QuicPacketBuilder, space: QuicPacketSpace, now: float) -> None
_write_connection_limits(builder: QuicPacketBuilder, space: QuicPacketSpace) -> None
_write_crypto_frame(builder: QuicPacketBuilder, space: QuicPacketSpace, stream: QuicStream) -> bool
_write_datagram_frame(builder: QuicPacketBuilder, data: bytes, frame_type: QuicFrameType) -> bool
_write_handshake_done_frame(builder: QuicPacketBuilder) -> None
_write_new_connection_id_frame(builder: QuicPacketBuilder, connection_id: QuicConnectionId) -> None
_write_path_challenge_frame(builder: QuicPacketBuilder, challenge: bytes) -> None
_write_path_response_frame(builder: QuicPacketBuilder, challenge: bytes) -> None
_write_ping_frame(self, builder: QuicPacketBuilder, uids: List[int]=[], comment="")
_write_ping_frame(builder: QuicPacketBuilder, uids: List[int]=[], comment="")
|
|
aioquic.quic.connection/QuicConnection._write_reset_stream_frame
|
Modified
|
aiortc~aioquic
|
55b531a1dab7498efd5bd5e0052d8e996a2a370b
|
[stream] add API to stop receiving (fixes: #193)
|
<1>:<add> frame_type=QuicFrameType.RESET_STREAM,
<del> frame_type=frame_type,
<2>:<add> capacity=RESET_STREAM_FRAME_CAPACITY,
<del> capacity=RESET_STREAM_CAPACITY,
<5>:<add> frame = stream.sender.get_reset_frame()
<del> reset = stream.sender.get_reset_frame()
<6>:<add> buf.push_uint_var(frame.stream_id)
<del> buf.push_uint_var(stream.stream_id)
<7>:<add> buf.push_uint_var(frame.error_code)
<del> buf.push_uint_var(reset.error_code)
<8>:<add> buf.push_uint_var(frame.final_size)
<del> buf.push_uint_var(reset.final_size)
<14>:<add> error_code=frame.error_code,
<del> error_code=reset.error_code,
<15>:<add> final_size=frame.final_size,
<del> final_size=reset.final_size,
<16>:<add> stream_id=frame.stream_id,
<del> stream_id=stream.stream_id,
|
# module: aioquic.quic.connection
class QuicConnection:
def _write_reset_stream_frame(
self,
builder: QuicPacketBuilder,
- frame_type: QuicFrameType,
stream: QuicStream,
) -> None:
<0> buf = builder.start_frame(
<1> frame_type=frame_type,
<2> capacity=RESET_STREAM_CAPACITY,
<3> handler=stream.sender.on_reset_delivery,
<4> )
<5> reset = stream.sender.get_reset_frame()
<6> buf.push_uint_var(stream.stream_id)
<7> buf.push_uint_var(reset.error_code)
<8> buf.push_uint_var(reset.final_size)
<9>
<10> # log frame
<11> if self._quic_logger is not None:
<12> builder.quic_logger_frames.append(
<13> self._quic_logger.encode_reset_stream_frame(
<14> error_code=reset.error_code,
<15> final_size=reset.final_size,
<16> stream_id=stream.stream_id,
<17> )
<18> )
<19>
|
===========unchanged ref 0===========
at: aioquic.quic.connection
PING_FRAME_CAPACITY = 1
at: aioquic.quic.connection.QuicConnection
_on_ping_delivery(delivery: QuicDeliveryState, uids: Sequence[int]) -> None
at: aioquic.quic.connection.QuicConnection.__init__
self._quic_logger: Optional[QuicLoggerTrace] = None
self._quic_logger = configuration.quic_logger.start_trace(
is_client=configuration.is_client,
odcid=self._original_destination_connection_id,
)
self._logger = QuicConnectionAdapter(
logger, {"id": dump_cid(self._original_destination_connection_id)}
)
at: aioquic.quic.connection.QuicConnection._close_end
self._quic_logger = None
at: logging.LoggerAdapter
debug(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
at: typing
List = _alias(list, 1, inst=False, name='List')
===========changed ref 0===========
# module: aioquic.quic.packet
+ @dataclass
+ class QuicStopSendingFrame:
+ error_code: int
+ stream_id: int
+
===========changed ref 1===========
# module: aioquic.quic.packet
@dataclass
class QuicResetStreamFrame:
error_code: int
final_size: int
+ stream_id: int
===========changed ref 2===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
+ def on_stop_sending_delivery(self, delivery: QuicDeliveryState) -> None:
+ """
+ Callback when a STOP_SENDING is ACK'd.
+ """
+ if delivery != QuicDeliveryState.ACKED:
+ self.stop_pending = True
+
===========changed ref 3===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
+ def stop(self, error_code: int = QuicErrorCode.NO_ERROR) -> None:
+ """
+ Request the peer stop sending data on the QUIC stream.
+ """
+ self._stop_error_code = error_code
+ self.stop_pending = True
+
===========changed ref 4===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
+ def get_stop_frame(self) -> QuicStopSendingFrame:
+ self.stop_pending = False
+ return QuicStopSendingFrame(
+ error_code=self._stop_error_code,
+ stream_id=self._stream_id,
+ )
+
===========changed ref 5===========
# module: aioquic.quic.stream
class QuicStreamSender:
def get_reset_frame(self) -> QuicResetStreamFrame:
self.reset_pending = False
return QuicResetStreamFrame(
+ error_code=self._reset_error_code,
+ final_size=self.highest_offset,
+ stream_id=self._stream_id,
- error_code=self._reset_error_code, final_size=self.highest_offset
)
===========changed ref 6===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def test_send_stop_sending_unknown_stream(self):
+ with client_and_server() as (client, server):
+ # check handshake completed
+ self.check_handshake(client=client, server=server)
+
+ # client sends STOP_SENDING frame
+ with self.assertRaises(ValueError) as cm:
+ client.stop_stream(0, QuicErrorCode.NO_ERROR)
+ self.assertEqual(
+ str(cm.exception), "Cannot stop receiving on an unknown stream"
+ )
+
===========changed ref 7===========
# module: aioquic.quic.stream
class QuicStreamReceiver:
def __init__(self, stream_id: Optional[int], readable: bool) -> None:
self.highest_offset = 0 # the highest offset ever seen
self.is_finished = False
+ self.stop_pending = False
self._buffer = bytearray()
self._buffer_start = 0 # the offset for the start of the buffer
self._final_size: Optional[int] = None
self._ranges = RangeSet()
self._stream_id = stream_id
+ self._stop_error_code: Optional[int] = None
===========changed ref 8===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def test_send_stop_sending_uni_stream(self):
+ with client_and_server() as (client, server):
+ # check handshake completed
+ self.check_handshake(client=client, server=server)
+
+ # client sends STOP_SENDING frame
+ with self.assertRaises(ValueError) as cm:
+ client.stop_stream(2, QuicErrorCode.NO_ERROR)
+ self.assertEqual(
+ str(cm.exception),
+ "Cannot stop receiving on a local-initiated unidirectional stream",
+ )
+
===========changed ref 9===========
# module: aioquic.quic.connection
class QuicConnection:
+ def stop_stream(self, stream_id: int, error_code: int) -> None:
+ """
+ Request termination of the receiving part of a stream.
+
+ :param stream_id: The stream's ID.
+ :param error_code: An error code indicating why the stream is being stopped.
+ """
+ if not self._stream_can_receive(stream_id):
+ raise ValueError(
+ "Cannot stop receiving on a local-initiated unidirectional stream"
+ )
+
+ stream = self._streams.get(stream_id, None)
+ if stream is None:
+ raise ValueError("Cannot stop receiving on an unknown stream")
+
+ stream.receiver.stop(error_code)
+
===========changed ref 10===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
+ def test_receiver_stop(self):
+ stream = QuicStream()
+
+ # stop is requested
+ stream.receiver.stop(QuicErrorCode.NO_ERROR)
+ self.assertTrue(stream.receiver.stop_pending)
+
+ # stop is sent
+ frame = stream.receiver.get_stop_frame()
+ self.assertEqual(frame.error_code, QuicErrorCode.NO_ERROR)
+ self.assertFalse(stream.receiver.stop_pending)
+
+ # stop is acklowledged
+ stream.receiver.on_stop_sending_delivery(QuicDeliveryState.ACKED)
+ self.assertFalse(stream.receiver.stop_pending)
+
===========changed ref 11===========
# module: aioquic.quic.connection
class QuicConnection:
def _handle_stop_sending_frame(
self, context: QuicReceiveContext, frame_type: int, buf: Buffer
) -> None:
"""
Handle a STOP_SENDING frame.
"""
stream_id = buf.pull_uint_var()
error_code = buf.pull_uint_var() # application error code
# log frame
if self._quic_logger is not None:
context.quic_logger_frames.append(
self._quic_logger.encode_stop_sending_frame(
error_code=error_code, stream_id=stream_id
)
)
# check stream direction
self._assert_stream_can_send(frame_type, stream_id)
+ # reset the stream
+ stream = self._get_or_create_stream(frame_type, stream_id)
- self._get_or_create_stream(frame_type, stream_id)
+ stream.sender.reset(error_code=QuicErrorCode.NO_ERROR)
|
aioquic.quic.stream/QuicStreamSender.on_data_delivery
|
Modified
|
aiortc~aioquic
|
5d2f815198007fdf6cda83d05b4ccf9cd2c826b2
|
[stream] rework sender termination condition
|
<14>:<add> if self._buffer_start == self._buffer_fin:
<del> if stop == self._buffer_fin:
<15>:<add> # all date up to the FIN has been ACK'd, we're done sending
<del> # the FIN has been ACK'd, we're done sending
|
# module: aioquic.quic.stream
class QuicStreamSender:
def on_data_delivery(
self, delivery: QuicDeliveryState, start: int, stop: int
) -> None:
<0> """
<1> Callback when sent data is ACK'd.
<2> """
<3> self.buffer_is_empty = False
<4> if delivery == QuicDeliveryState.ACKED:
<5> if stop > start:
<6> self._acked.add(start, stop)
<7> first_range = self._acked[0]
<8> if first_range.start == self._buffer_start:
<9> size = first_range.stop - first_range.start
<10> self._acked.shift()
<11> self._buffer_start += size
<12> del self._buffer[:size]
<13>
<14> if stop == self._buffer_fin:
<15> # the FIN has been ACK'd, we're done sending
<16> self.is_finished = True
<17> else:
<18> if stop > start:
<19> self._pending.add(start, stop)
<20> if stop == self._buffer_fin:
<21> self.send_buffer_empty = False
<22> self._pending_eof = True
<23>
|
===========unchanged ref 0===========
at: aioquic.quic.stream.QuicStreamSender.__init__
self.buffer_is_empty = True
self.is_finished = not writable
self._acked = RangeSet()
self._buffer = bytearray()
self._buffer_fin: Optional[int] = None
self._buffer_start = 0 # the offset for the start of the buffer
self._pending = RangeSet()
self._pending_eof = False
at: aioquic.quic.stream.QuicStreamSender.get_frame
self._pending_eof = False
self.buffer_is_empty = True
at: aioquic.quic.stream.QuicStreamSender.on_reset_delivery
self.is_finished = True
at: aioquic.quic.stream.QuicStreamSender.write
self.buffer_is_empty = False
self._buffer += data
self._buffer_fin = self._buffer_stop
self._pending_eof = True
===========changed ref 0===========
# module: tests.test_stream
class QuicStreamTest(TestCase):
+ def test_sender_data_and_fin_ack_out_of_order(self):
+ stream = QuicStream()
+
+ # nothing to send yet
+ frame = stream.sender.get_frame(8)
+ self.assertIsNone(frame)
+
+ # write data and EOF
+ stream.sender.write(b"0123456789012345", end_stream=True)
+ self.assertEqual(list(stream.sender._pending), [range(0, 16)])
+ self.assertEqual(stream.sender.next_offset, 0)
+
+ # send a chunk
+ frame = stream.sender.get_frame(8)
+ self.assertEqual(frame.data, b"01234567")
+ self.assertFalse(frame.fin)
+ self.assertEqual(frame.offset, 0)
+ self.assertEqual(stream.sender.next_offset, 8)
+
+ # send another chunk
+ frame = stream.sender.get_frame(8)
+ self.assertEqual(frame.data, b"89012345")
+ self.assertTrue(frame.fin)
+ self.assertEqual(frame.offset, 8)
+ self.assertEqual(stream.sender.next_offset, 16)
+
+ # nothing more to send
+ frame = stream.sender.get_frame(8)
+ self.assertIsNone(frame)
+ self.assertEqual(stream.sender.next_offset, 16)
+
+ # second chunk gets acknowledged
+ stream.sender.on_data_delivery(QuicDeliveryState.ACKED, 8, 16)
+ self.assertFalse(stream.sender.is_finished)
+
+ # first chunk gets acknowledged
+ stream.sender.on_data_delivery(QuicDeliveryState.ACKED, 0, 8)
+ self.assertTrue(stream.sender.is_finished)
+
|
aioquic.quic.connection/QuicConnection.get_next_available_stream_id
|
Modified
|
aiortc~aioquic
|
5011cfa6c4ab7c312a6501d7fb24d9cf72185fe2
|
[streams] discard stream when sending / receiving complete (fixes: #99)
|
<4>:<add> while stream_id in self._streams or stream_id in self._streams_finished:
<del> while stream_id in self._streams:
|
# module: aioquic.quic.connection
class QuicConnection:
def get_next_available_stream_id(self, is_unidirectional=False) -> int:
<0> """
<1> Return the stream ID for the next stream created by this endpoint.
<2> """
<3> stream_id = (int(is_unidirectional) << 1) | int(not self._is_client)
<4> while stream_id in self._streams:
<5> stream_id += 4
<6> return stream_id
<7>
|
===========unchanged ref 0===========
at: aioquic.quic.connection.QuicConnection.__init__
self._is_client = configuration.is_client
self._streams: Dict[int, QuicStream] = {}
self._streams_finished: Set[int] = set()
===========changed ref 0===========
# module: aioquic.quic.connection
class QuicConnection:
def __init__(
self,
*,
configuration: QuicConfiguration,
original_destination_connection_id: Optional[bytes] = None,
retry_source_connection_id: Optional[bytes] = None,
session_ticket_fetcher: Optional[tls.SessionTicketFetcher] = None,
session_ticket_handler: Optional[tls.SessionTicketHandler] = None,
) -> None:
if configuration.is_client:
assert (
original_destination_connection_id is None
), "Cannot set original_destination_connection_id for a client"
assert (
retry_source_connection_id is None
), "Cannot set retry_source_connection_id for a client"
else:
assert (
configuration.certificate is not None
), "SSL certificate is required for a server"
assert (
configuration.private_key is not None
), "SSL private key is required for a server"
assert (
original_destination_connection_id is not None
), "original_destination_connection_id is required for a server"
# configuration
self._configuration = configuration
self._is_client = configuration.is_client
self._ack_delay = K_GRANULARITY
self._close_at: Optional[float] = None
self._close_event: Optional[events.ConnectionTerminated] = None
self._connect_called = False
self._cryptos: Dict[tls.Epoch, CryptoPair] = {}
self._crypto_buffers: Dict[tls.Epoch, Buffer] = {}
self._crypto_streams: Dict[tls.Epoch, QuicStream] = {}
self._events: Deque[events.QuicEvent] = deque()
self._handshake_complete = False
self._handshake_confirmed = False
self._host_cids = [
QuicConnectionId(
cid=os.urandom(configuration.connection_id_length),
sequence_number=0,
stateless_reset_token=os</s>
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def __init__(
self,
*,
configuration: QuicConfiguration,
original_destination_connection_id: Optional[bytes] = None,
retry_source_connection_id: Optional[bytes] = None,
session_ticket_fetcher: Optional[tls.SessionTicketFetcher] = None,
session_ticket_handler: Optional[tls.SessionTicketHandler] = None,
) -> None:
# offset: 1
<s>.urandom(configuration.connection_id_length),
sequence_number=0,
stateless_reset_token=os.urandom(16) if not self._is_client else None,
was_sent=True,
)
]
self.host_cid = self._host_cids[0].cid
self._host_cid_seq = 1
self._local_ack_delay_exponent = 3
self._local_active_connection_id_limit = 8
self._local_initial_source_connection_id = self._host_cids[0].cid
self._local_max_data = Limit(
frame_type=QuicFrameType.MAX_DATA,
name="max_data",
value=configuration.max_data,
)
self._local_max_stream_data_bidi_local = configuration.max_stream_data
self._local_max_stream_data_bidi_remote = configuration.max_stream_data
self._local_max_stream_data_uni = configuration.max_stream_data
self._local_max_streams_bidi = Limit(
frame_type=QuicFrameType.MAX_STREAMS_BIDI,
name="max_streams_bidi",
value=128,
)
self._local_max_streams_uni = Limit(
frame_type=QuicFrameType.MAX_STREAMS_UNI, name="max_streams_un</s>
===========changed ref 2===========
# module: aioquic.quic.connection
class QuicConnection:
def __init__(
self,
*,
configuration: QuicConfiguration,
original_destination_connection_id: Optional[bytes] = None,
retry_source_connection_id: Optional[bytes] = None,
session_ticket_fetcher: Optional[tls.SessionTicketFetcher] = None,
session_ticket_handler: Optional[tls.SessionTicketHandler] = None,
) -> None:
# offset: 2
<s> value=128
)
self._loss_at: Optional[float] = None
self._network_paths: List[QuicNetworkPath] = []
self._pacing_at: Optional[float] = None
self._packet_number = 0
self._parameters_received = False
self._peer_cid = QuicConnectionId(
cid=os.urandom(configuration.connection_id_length), sequence_number=None
)
self._peer_cid_available: List[QuicConnectionId] = []
self._peer_cid_sequence_numbers: Set[int] = set([0])
self._peer_token = b""
self._quic_logger: Optional[QuicLoggerTrace] = None
self._remote_ack_delay_exponent = 3
self._remote_active_connection_id_limit = 2
self._remote_initial_source_connection_id: Optional[bytes] = None
self._remote_max_idle_timeout = 0.0 # seconds
self._remote_max_data = 0
self._remote_max_data_used = 0
self._remote_max_datagram_frame_size: Optional[int] = None
self._remote_max_stream_data_bidi_local = 0
self._remote_max_stream_data_bidi_remote = 0
self._remote_max_stream_data_uni = 0
self._remote_max_streams_bidi = 0</s>
|
aioquic.quic.connection/QuicConnection._get_or_create_stream
|
Modified
|
aiortc~aioquic
|
c28946bed2549a08f16ddf159254ddea72c1f2e5
|
[stream] ignore frames for discarded streams
|
<3>:<add> if stream_id in self._streams_finished:
<add> # the stream was created, but its state was since discarded
<add> raise StreamFinishedError
<add>
|
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream:
<0> """
<1> Get or create a stream in response to a received frame.
<2> """
<3> stream = self._streams.get(stream_id, None)
<4> if stream is None:
<5> # check initiator
<6> if stream_is_client_initiated(stream_id) == self._is_client:
<7> raise QuicConnectionError(
<8> error_code=QuicErrorCode.STREAM_STATE_ERROR,
<9> frame_type=frame_type,
<10> reason_phrase="Wrong stream initiator",
<11> )
<12>
<13> # determine limits
<14> if stream_is_unidirectional(stream_id):
<15> max_stream_data_local = self._local_max_stream_data_uni
<16> max_stream_data_remote = 0
<17> max_streams = self._local_max_streams_uni
<18> else:
<19> max_stream_data_local = self._local_max_stream_data_bidi_remote
<20> max_stream_data_remote = self._remote_max_stream_data_bidi_local
<21> max_streams = self._local_max_streams_bidi
<22>
<23> # check max streams
<24> stream_count = (stream_id // 4) + 1
<25> if stream_count > max_streams.value:
<26> raise QuicConnectionError(
<27> error_code=QuicErrorCode.STREAM_LIMIT_ERROR,
<28> frame_type=frame_type,
<29> reason_phrase="Too many streams open",
<30> )
<31> elif stream_count > max_streams.used:
<32> max_streams.used = stream_count
<33>
<34> # create stream
<35> self._logger.debug("Stream %d created by peer" % stream_id)
<36> stream = self._streams[stream_id] = QuicStream(
<37> stream_id=stream_id,
<38> max_stream_data_local=</s>
|
===========below chunk 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream:
# offset: 1
max_stream_data_remote=max_stream_data_remote,
writable=not stream_is_unidirectional(stream_id),
)
return stream
===========unchanged ref 0===========
at: aioquic.quic.connection
stream_is_client_initiated(stream_id: int) -> bool
stream_is_unidirectional(stream_id: int) -> bool
QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)
at: aioquic.quic.connection.Limit.__init__
self.used = 0
self.value = value
at: aioquic.quic.connection.QuicConnection.__init__
self._is_client = configuration.is_client
self._local_max_stream_data_bidi_remote = configuration.max_stream_data
self._local_max_stream_data_uni = configuration.max_stream_data
self._local_max_streams_bidi = Limit(
frame_type=QuicFrameType.MAX_STREAMS_BIDI,
name="max_streams_bidi",
value=128,
)
self._local_max_streams_uni = Limit(
frame_type=QuicFrameType.MAX_STREAMS_UNI, name="max_streams_uni", value=128
)
self._remote_max_stream_data_bidi_local = 0
self._streams: Dict[int, QuicStream] = {}
self._streams_finished: Set[int] = set()
self._logger = QuicConnectionAdapter(
logger, {"id": dump_cid(self._original_destination_connection_id)}
)
at: logging.LoggerAdapter
logger: Logger
extra: Mapping[str, Any]
debug(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
===========unchanged ref 1===========
at: typing.Mapping
get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]
get(key: _KT) -> Optional[_VT_co]
===========changed ref 0===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def test_handle_reset_stream_frame_twice(self):
+ stream_id = 3
+ reset_stream_data = (
+ encode_uint_var(QuicFrameType.RESET_STREAM)
+ + encode_uint_var(stream_id)
+ + encode_uint_var(QuicErrorCode.INTERNAL_ERROR)
+ + encode_uint_var(0)
+ )
+ with client_and_server() as (client, server):
+ # server creates unidirectional stream
+ server.send_stream_data(stream_id=stream_id, data=b"hello")
+ roundtrip(server, client)
+ consume_events(client)
+
+ # client receives RESET_STREAM
+ client._payload_received(client_receive_context(client), reset_stream_data)
+
+ event = client.next_event()
+ self.assertEqual(type(event), events.StreamReset)
+ self.assertEqual(event.error_code, QuicErrorCode.INTERNAL_ERROR)
+ self.assertEqual(event.stream_id, stream_id)
+
+ # stream gets discarded
+ self.assertEqual(drop(client), 0)
+
+ # client receives RESET_STREAM again
+ client._payload_received(client_receive_context(client), reset_stream_data)
+
+ event = client.next_event()
+ self.assertIsNone(event)
+
|
aioquic.quic.connection/QuicConnection._payload_received
|
Modified
|
aiortc~aioquic
|
c28946bed2549a08f16ddf159254ddea72c1f2e5
|
[stream] ignore frames for discarded streams
|
<38>:<add> except StreamFinishedError:
<add> # we lack the state for the stream, ignore the frame
<add> pass
|
# module: aioquic.quic.connection
class QuicConnection:
def _payload_received(
self, context: QuicReceiveContext, plain: bytes
) -> Tuple[bool, bool]:
<0> """
<1> Handle a QUIC packet payload.
<2> """
<3> buf = Buffer(data=plain)
<4>
<5> frame_found = False
<6> is_ack_eliciting = False
<7> is_probing = None
<8> while not buf.eof():
<9> frame_type = buf.pull_uint_var()
<10>
<11> # check frame type is known
<12> try:
<13> frame_handler, frame_epochs = self.__frame_handlers[frame_type]
<14> except KeyError:
<15> raise QuicConnectionError(
<16> error_code=QuicErrorCode.PROTOCOL_VIOLATION,
<17> frame_type=frame_type,
<18> reason_phrase="Unknown frame type",
<19> )
<20>
<21> # check frame is allowed for the epoch
<22> if context.epoch not in frame_epochs:
<23> raise QuicConnectionError(
<24> error_code=QuicErrorCode.PROTOCOL_VIOLATION,
<25> frame_type=frame_type,
<26> reason_phrase="Unexpected frame type",
<27> )
<28>
<29> # handle the frame
<30> try:
<31> frame_handler(context, frame_type, buf)
<32> except BufferReadError:
<33> raise QuicConnectionError(
<34> error_code=QuicErrorCode.FRAME_ENCODING_ERROR,
<35> frame_type=frame_type,
<36> reason_phrase="Failed to parse frame",
<37> )
<38>
<39> # update ACK only / probing flags
<40> frame_found = True
<41>
<42> if frame_type not in NON_ACK_ELICITING_FRAME_TYPES:
<43> is_ack_eliciting = True
<44>
<45> if frame_type not in PROBING_FRAME_TYPES:
<46> is_probing = False
<47> elif is_probing is None:
<48> is_probing = True
<49>
<50> if not frame_found:
</s>
|
===========below chunk 0===========
# module: aioquic.quic.connection
class QuicConnection:
def _payload_received(
self, context: QuicReceiveContext, plain: bytes
) -> Tuple[bool, bool]:
# offset: 1
error_code=QuicErrorCode.PROTOCOL_VIOLATION,
frame_type=QuicFrameType.PADDING,
reason_phrase="Packet contains no frames",
)
return is_ack_eliciting, bool(is_probing)
===========unchanged ref 0===========
at: aioquic.quic.connection
QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)
QuicReceiveContext(epoch: tls.Epoch, host_cid: bytes, network_path: QuicNetworkPath, quic_logger_frames: Optional[List[Any]], time: float)
at: aioquic.quic.connection.QuicConnection.__init__
self._retire_connection_ids: List[int] = []
===========unchanged ref 1===========
self.__frame_handlers = {
0x00: (self._handle_padding_frame, EPOCHS("IH01")),
0x01: (self._handle_ping_frame, EPOCHS("IH01")),
0x02: (self._handle_ack_frame, EPOCHS("IH1")),
0x03: (self._handle_ack_frame, EPOCHS("IH1")),
0x04: (self._handle_reset_stream_frame, EPOCHS("01")),
0x05: (self._handle_stop_sending_frame, EPOCHS("01")),
0x06: (self._handle_crypto_frame, EPOCHS("IH1")),
0x07: (self._handle_new_token_frame, EPOCHS("1")),
0x08: (self._handle_stream_frame, EPOCHS("01")),
0x09: (self._handle_stream_frame, EPOCHS("01")),
0x0A: (self._handle_stream_frame, EPOCHS("01")),
0x0B: (self._handle_stream_frame, EPOCHS("01")),
0x0C: (self._handle_stream_frame, EPOCHS("01")),
0x0D: (self._handle_stream_frame, EPOCHS("01")),
0x0E: (self._handle_stream_frame, EPOCHS("01")),
0x0F: (self._handle_stream_frame, EPOCHS("01")),
0x10: (self._handle_max_data_frame, EPOCHS("01")),
0x11: (self._handle_max_stream_data_frame, EPOCHS("01")),
0x12: (self._handle_max_streams_bidi_frame, EPOCHS("01")),
0x13: (self._handle_max_streams_uni_frame, EPOCHS("01")),
0x14: (self._handle_data_blocked_frame, EPOCHS("01")),</s>
===========unchanged ref 2===========
at: aioquic.quic.connection.QuicReceiveContext
epoch: tls.Epoch
host_cid: bytes
network_path: QuicNetworkPath
quic_logger_frames: Optional[List[Any]]
time: float
at: typing
Tuple = _TupleType(tuple, -1, inst=False, name='Tuple')
===========changed ref 0===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def test_handle_reset_stream_frame_twice(self):
+ stream_id = 3
+ reset_stream_data = (
+ encode_uint_var(QuicFrameType.RESET_STREAM)
+ + encode_uint_var(stream_id)
+ + encode_uint_var(QuicErrorCode.INTERNAL_ERROR)
+ + encode_uint_var(0)
+ )
+ with client_and_server() as (client, server):
+ # server creates unidirectional stream
+ server.send_stream_data(stream_id=stream_id, data=b"hello")
+ roundtrip(server, client)
+ consume_events(client)
+
+ # client receives RESET_STREAM
+ client._payload_received(client_receive_context(client), reset_stream_data)
+
+ event = client.next_event()
+ self.assertEqual(type(event), events.StreamReset)
+ self.assertEqual(event.error_code, QuicErrorCode.INTERNAL_ERROR)
+ self.assertEqual(event.stream_id, stream_id)
+
+ # stream gets discarded
+ self.assertEqual(drop(client), 0)
+
+ # client receives RESET_STREAM again
+ client._payload_received(client_receive_context(client), reset_stream_data)
+
+ event = client.next_event()
+ self.assertIsNone(event)
+
===========changed ref 1===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream:
"""
Get or create a stream in response to a received frame.
"""
+ if stream_id in self._streams_finished:
+ # the stream was created, but its state was since discarded
+ raise StreamFinishedError
+
stream = self._streams.get(stream_id, None)
if stream is None:
# check initiator
if stream_is_client_initiated(stream_id) == self._is_client:
raise QuicConnectionError(
error_code=QuicErrorCode.STREAM_STATE_ERROR,
frame_type=frame_type,
reason_phrase="Wrong stream initiator",
)
# determine limits
if stream_is_unidirectional(stream_id):
max_stream_data_local = self._local_max_stream_data_uni
max_stream_data_remote = 0
max_streams = self._local_max_streams_uni
else:
max_stream_data_local = self._local_max_stream_data_bidi_remote
max_stream_data_remote = self._remote_max_stream_data_bidi_local
max_streams = self._local_max_streams_bidi
# check max streams
stream_count = (stream_id // 4) + 1
if stream_count > max_streams.value:
raise QuicConnectionError(
error_code=QuicErrorCode.STREAM_LIMIT_ERROR,
frame_type=frame_type,
reason_phrase="Too many streams open",
)
elif stream_count > max_streams.used:
max_streams.used = stream_count
# create stream
self._logger.debug("Stream %d created by peer" % stream_id)
stream = self._streams[stream_id] = QuicStream(
stream_id=stream_id,
max_stream_data_local=max</s>
===========changed ref 2===========
# module: aioquic.quic.connection
class QuicConnection:
def _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream:
# offset: 1
<s>stream_id] = QuicStream(
stream_id=stream_id,
max_stream_data_local=max_stream_data_local,
max_stream_data_remote=max_stream_data_remote,
writable=not stream_is_unidirectional(stream_id),
)
return stream
|
aioquic.h3.connection/H3Connection.handle_event
|
Modified
|
aiortc~aioquic
|
963f252e893040579ab394bcaaff010b5dfc78d7
|
[webtransport] fix receiving data on server-initiated streams
|
<11>:<add> if stream_is_unidirectional(stream_id):
<del> if stream_id % 4 == 0:
<12>:<add> return self._receive_stream_data_uni(
<del> return self._receive_request_or_push_data(
<15>:<add> else:
<del> elif stream_is_unidirectional(stream_id):
<16>:<add> return self._receive_request_or_push_data(
<del> return self._receive_stream_data_uni(
|
# module: aioquic.h3.connection
class H3Connection:
def handle_event(self, event: QuicEvent) -> List[H3Event]:
<0> """
<1> Handle a QUIC event and return a list of HTTP events.
<2>
<3> :param event: The QUIC event to handle.
<4> """
<5>
<6> if not self._is_done:
<7> try:
<8> if isinstance(event, StreamDataReceived):
<9> stream_id = event.stream_id
<10> stream = self._get_or_create_stream(stream_id)
<11> if stream_id % 4 == 0:
<12> return self._receive_request_or_push_data(
<13> stream, event.data, event.end_stream
<14> )
<15> elif stream_is_unidirectional(stream_id):
<16> return self._receive_stream_data_uni(
<17> stream, event.data, event.end_stream
<18> )
<19> elif isinstance(event, DatagramFrameReceived):
<20> return self._receive_datagram(event.data)
<21> except ProtocolError as exc:
<22> self._is_done = True
<23> self._quic.close(
<24> error_code=exc.error_code, reason_phrase=exc.reason_phrase
<25> )
<26>
<27> return []
<28>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
ProtocolError(reason_phrase: str="")
at: aioquic.h3.connection.H3Connection
_get_or_create_stream(stream_id: int) -> H3Stream
_receive_datagram(data: bytes) -> List[H3Event]
_receive_request_or_push_data(stream: H3Stream, data: bytes, stream_ended: bool) -> List[H3Event]
_receive_stream_data_uni(stream: H3Stream, data: bytes, stream_ended: bool) -> List[H3Event]
at: aioquic.h3.connection.H3Connection.__init__
self._is_done = False
self._quic = quic
at: aioquic.h3.connection.ProtocolError
error_code = ErrorCode.H3_GENERAL_PROTOCOL_ERROR
at: aioquic.h3.connection.ProtocolError.__init__
self.reason_phrase = reason_phrase
at: tests.test_h3.FakeQuicConnection
close(error_code, reason_phrase)
at: typing
List = _alias(list, 1, inst=False, name='List')
|
tests.test_h3/H3ParserTest.test_validate_request_headers
|
Modified
|
aiortc~aioquic
|
a18a6cfbf349c5812923b099dad6bd48738b640a
|
Required Connect Header Validation
|
# module: tests.test_h3
class H3ParserTest(TestCase):
def test_validate_request_headers(self):
<0> # OK
<1> validate_request_headers(
<2> [
<3> (b":method", b"GET"),
<4> (b":scheme", b"https"),
<5> (b":path", b"/"),
<6> (b":authority", b"localhost"),
<7> ]
<8> )
<9> validate_request_headers(
<10> [
<11> (b":method", b"GET"),
<12> (b":scheme", b"https"),
<13> (b":path", b"/"),
<14> (b":authority", b"localhost"),
<15> (b"x-foo", b"bar"),
<16> ]
<17> )
<18>
<19> # uppercase header
<20> with self.assertRaises(MessageError) as cm:
<21> validate_request_headers([(b"X-Foo", b"foo")])
<22> self.assertEqual(
<23> cm.exception.reason_phrase, "Header b'X-Foo' contains uppercase letters"
<24> )
<25>
<26> # invalid pseudo-header
<27> with self.assertRaises(MessageError) as cm:
<28> validate_request_headers([(b":status", b"foo")])
<29> self.assertEqual(
<30> cm.exception.reason_phrase, "Pseudo-header b':status' is not valid"
<31> )
<32>
<33> # duplicate pseudo-header
<34> with self.assertRaises(MessageError) as cm:
<35> validate_request_headers(
<36> [
<37> (b":method", b"GET"),
<38> (b":method", b"POST"),
<39> ]
<40> )
<41> self.assertEqual(
<42> cm.exception.reason_phrase, "Pseudo-header b':method' is included twice"
<43> )
<44>
<45> # pseudo-header after regular headers
<46> with self.assertRaises(MessageError) as cm:
<47> validate_request_headers(
<48> [
<49> (</s>
|
===========below chunk 0===========
# module: tests.test_h3
class H3ParserTest(TestCase):
def test_validate_request_headers(self):
# offset: 1
(b":scheme", b"https"),
(b":path", b"/"),
(b"x-foo", b"bar"),
(b":authority", b"foo"),
]
)
self.assertEqual(
cm.exception.reason_phrase,
"Pseudo-header b':authority' is not allowed after regular headers",
)
# missing pseudo-headers
with self.assertRaises(MessageError) as cm:
validate_request_headers([(b":method", b"GET")])
self.assertEqual(
cm.exception.reason_phrase,
"Pseudo-headers [b':path', b':scheme'] are missing",
)
# empty :authority pseudo-header for http/https
for scheme in [b"http", b"https"]:
with self.assertRaises(MessageError) as cm:
validate_request_headers(
[
(b":method", b"GET"),
(b":scheme", scheme),
(b":authority", b""),
(b":path", b"/"),
]
)
self.assertEqual(
cm.exception.reason_phrase,
"Pseudo-header b':authority' cannot be empty",
)
# empty :path pseudo-header for http/https
for scheme in [b"http", b"https"]:
with self.assertRaises(MessageError) as cm:
validate_request_headers(
[
(b":method", b"GET"),
(b":scheme", scheme),
(b":authority", b"localhost"),
(b":path", b""),
]
)
self.assertEqual(
cm.exception.reason_phrase, "Pseudo-header b':path' cannot be empty"
)
===========unchanged ref 0===========
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E]
assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None
at: unittest.case._AssertRaisesContext.__exit__
self.exception = exc_value.with_traceback(None)
|
|
aioquic.h3.connection/validate_request_headers
|
Modified
|
aiortc~aioquic
|
a18a6cfbf349c5812923b099dad6bd48738b640a
|
Required Connect Header Validation
|
<7>:<add> required_pseudo_headers=frozenset((b":method", b":authority")),
<del> required_pseudo_headers=frozenset((b":method", b":scheme", b":path")),
|
# module: aioquic.h3.connection
def validate_request_headers(headers: Headers) -> None:
<0> validate_headers(
<1> headers,
<2> allowed_pseudo_headers=frozenset(
<3> # FIXME: The pseudo-header :protocol is not actually defined, but
<4> # we use it for the WebSocket demo.
<5> (b":method", b":scheme", b":authority", b":path", b":protocol")
<6> ),
<7> required_pseudo_headers=frozenset((b":method", b":scheme", b":path")),
<8> )
<9>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
validate_headers(headers: Headers, allowed_pseudo_headers: FrozenSet[bytes], required_pseudo_headers: FrozenSet[bytes]) -> None
===========changed ref 0===========
# module: tests.test_h3
class H3ParserTest(TestCase):
def test_validate_request_headers(self):
# OK
validate_request_headers(
[
(b":method", b"GET"),
(b":scheme", b"https"),
(b":path", b"/"),
(b":authority", b"localhost"),
]
)
validate_request_headers(
[
(b":method", b"GET"),
(b":scheme", b"https"),
(b":path", b"/"),
(b":authority", b"localhost"),
(b"x-foo", b"bar"),
]
)
# uppercase header
with self.assertRaises(MessageError) as cm:
validate_request_headers([(b"X-Foo", b"foo")])
self.assertEqual(
cm.exception.reason_phrase, "Header b'X-Foo' contains uppercase letters"
)
# invalid pseudo-header
with self.assertRaises(MessageError) as cm:
validate_request_headers([(b":status", b"foo")])
self.assertEqual(
cm.exception.reason_phrase, "Pseudo-header b':status' is not valid"
)
# duplicate pseudo-header
with self.assertRaises(MessageError) as cm:
validate_request_headers(
[
(b":method", b"GET"),
(b":method", b"POST"),
]
)
self.assertEqual(
cm.exception.reason_phrase, "Pseudo-header b':method' is included twice"
)
# pseudo-header after regular headers
with self.assertRaises(MessageError) as cm:
validate_request_headers(
[
(b":method", b"GET"),
(b":scheme", b"https"),
(b":path", b"/"),
(b"x-foo", b"bar"),
(b</s>
===========changed ref 1===========
# module: tests.test_h3
class H3ParserTest(TestCase):
def test_validate_request_headers(self):
# offset: 1
<s>),
(b":path", b"/"),
(b"x-foo", b"bar"),
(b":authority", b"foo"),
]
)
self.assertEqual(
cm.exception.reason_phrase,
"Pseudo-header b':authority' is not allowed after regular headers",
)
# missing pseudo-headers
with self.assertRaises(MessageError) as cm:
validate_request_headers([(b":method", b"GET")])
self.assertEqual(
cm.exception.reason_phrase,
+ "Pseudo-headers [b':authority'] are missing",
- "Pseudo-headers [b':path', b':scheme'] are missing",
)
# empty :authority pseudo-header for http/https
for scheme in [b"http", b"https"]:
with self.assertRaises(MessageError) as cm:
validate_request_headers(
[
(b":method", b"GET"),
(b":scheme", scheme),
(b":authority", b""),
(b":path", b"/"),
]
)
self.assertEqual(
cm.exception.reason_phrase,
"Pseudo-header b':authority' cannot be empty",
)
# empty :path pseudo-header for http/https
for scheme in [b"http", b"https"]:
with self.assertRaises(MessageError) as cm:
validate_request_headers(
[
(b":method", b"GET"),
(b":scheme", scheme),
(b":authority", b"localhost"),
(b":path", b""),
]
)
self.assertEqual(
cm.exception.reason_phrase, "Pseudo-header b':path
|
examples.interop/run
|
Modified
|
aiortc~aioquic
|
bf7f4098eb434292f7c52e510fe177b6570f02a0
|
[logger] move QuicFileLogger into the library
|
<8>:<add> quic_logger=QuicFileLogger(quic_log) if quic_log else QuicLogger(),
<del> quic_logger=QuicDirectoryLogger(quic_log) if quic_log else QuicLogger(),
|
# module: examples.interop
def run(servers, tests, quic_log=False, secrets_log_file=None) -> None:
<0> for server in servers:
<1> if server.structured_logging:
<2> server.result |= Result.L
<3> for test_name, test_func in tests:
<4> print("\n=== %s %s ===\n" % (server.name, test_name))
<5> configuration = QuicConfiguration(
<6> alpn_protocols=H3_ALPN + H0_ALPN,
<7> is_client=True,
<8> quic_logger=QuicDirectoryLogger(quic_log) if quic_log else QuicLogger(),
<9> secrets_log_file=secrets_log_file,
<10> verify_mode=server.verify_mode,
<11> )
<12> if test_name == "test_throughput":
<13> timeout = 120
<14> else:
<15> timeout = 10
<16> try:
<17> await asyncio.wait_for(
<18> test_func(server, configuration), timeout=timeout
<19> )
<20> except Exception as exc:
<21> print(exc)
<22>
<23> print("")
<24> print_result(server)
<25>
<26> # print summary
<27> if len(servers) > 1:
<28> print("SUMMARY")
<29> for server in servers:
<30> print_result(server)
<31>
|
===========unchanged ref 0===========
at: asyncio.tasks
wait_for(fut: _FutureT[_T], timeout: Optional[float], *, loop: Optional[AbstractEventLoop]=...) -> Future[_T]
at: examples.interop
Result()
print_result(server: Server) -> None
at: examples.interop.Server
name: str
host: str
port: int = 4433
http3: bool = True
http3_port: Optional[int] = None
retry_port: Optional[int] = 4434
path: str = "/"
push_path: Optional[str] = None
result: Result = field(default_factory=lambda: Result(0))
session_resumption_port: Optional[int] = None
structured_logging: bool = False
throughput_path: Optional[str] = "/%(size)d"
verify_mode: Optional[int] = None
===========changed ref 0===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
+ def test_single_trace(self):
+ logger = QuicLogger()
+ trace = logger.start_trace(is_client=True, odcid=bytes(8))
+ logger.end_trace(trace)
+ self.assertEqual(logger.to_dict(), SINGLE_TRACE)
+
===========changed ref 1===========
# module: tests.test_logger
+ class QuicFileLoggerTest(TestCase):
+ def test_invalid_path(self):
+ with self.assertRaises(ValueError) as cm:
+ QuicFileLogger("this_path_should_not_exist")
+ self.assertEqual(
+ str(cm.exception),
+ "QUIC log output directory 'this_path_should_not_exist' does not exist",
+ )
+
===========changed ref 2===========
# module: tests.test_logger
+ class QuicFileLoggerTest(TestCase):
+ def test_single_trace(self):
+ with tempfile.TemporaryDirectory() as dirpath:
+ logger = QuicFileLogger(dirpath)
+ trace = logger.start_trace(is_client=True, odcid=bytes(8))
+ logger.end_trace(trace)
+
+ filepath = os.path.join(dirpath, "0000000000000000.qlog")
+ self.assertTrue(os.path.exists(filepath))
+
+ with open(filepath, "r") as fp:
+ data = json.load(fp)
+ self.assertEqual(data, SINGLE_TRACE)
+
===========changed ref 3===========
# module: tests.test_logger
+ SINGLE_TRACE = {
+ "qlog_version": "draft-01",
+ "traces": [
+ {
+ "common_fields": {
+ "ODCID": "0000000000000000",
+ "reference_time": "0",
+ },
+ "configuration": {"time_units": "us"},
+ "event_fields": [
+ "relative_time",
+ "category",
+ "event_type",
+ "data",
+ ],
+ "events": [],
+ "vantage_point": {"name": "aioquic", "type": "client"},
+ }
+ ],
+ }
===========changed ref 4===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
- def test_empty_trace(self):
- logger = QuicLogger()
- trace = logger.start_trace(is_client=True, odcid=bytes(8))
- logger.end_trace(trace)
- self.assertEqual(
- logger.to_dict(),
- {
- "qlog_version": "draft-01",
- "traces": [
- {
- "common_fields": {
- "ODCID": "0000000000000000",
- "reference_time": "0",
- },
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
- "events": [],
- "vantage_point": {"name": "aioquic", "type": "client"},
- }
- ],
- },
- )
-
===========changed ref 5===========
# module: examples.siduck_client
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="SiDUCK client")
parser.add_argument(
"host", type=str, help="The remote peer's host name or IP address"
)
parser.add_argument("port", type=int, help="The remote peer's port number")
parser.add_argument(
"-k",
"--insecure",
action="store_true",
help="do not validate server certificate",
)
parser.add_argument(
"-q",
"--quic-log",
type=str,
help="log QUIC events to QLOG files in the specified directory",
)
parser.add_argument(
"-l",
"--secrets-log",
type=str,
help="log secrets to a file, for use with Wireshark",
)
parser.add_argument(
"-v", "--verbose", action="store_true", help="increase logging verbosity"
)
args = parser.parse_args()
logging.basicConfig(
format="%(asctime)s %(levelname)s %(name)s %(message)s",
level=logging.DEBUG if args.verbose else logging.INFO,
)
configuration = QuicConfiguration(
alpn_protocols=["siduck"], is_client=True, max_datagram_frame_size=65536
)
if args.insecure:
configuration.verify_mode = ssl.CERT_NONE
if args.quic_log:
+ configuration.quic_logger = QuicFileLogger(args.quic_log)
- configuration.quic_logger = QuicDirectoryLogger(args.quic_log)
if args.secrets_log:
configuration.secrets_log_file = open(args.secrets_log, "a")
loop = asyncio.get_event_loop()
loop.run_until_complete(
run(configuration=configuration, host=args.host, port=args.port)</s>
===========changed ref 6===========
# module: examples.siduck_client
# offset: 1
<s>
loop.run_until_complete(
run(configuration=configuration, host=args.host, port=args.port)
)
|
tests.test_logger/QuicLoggerTest.test_empty
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<1>:<add> self.assertEqual(
<add> logger.to_dict(),
<add> {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
<add> )
<del> self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
|
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
<0> logger = QuicLogger()
<1> self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
<2>
|
===========changed ref 0===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
|
aioquic.quic.recovery/QuicPacketRecovery._on_packets_lost
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<16>:<add> "packet_number": packet.packet_number,
<del> "packet_number": str(packet.packet_number),
|
# module: aioquic.quic.recovery
class QuicPacketRecovery:
def _on_packets_lost(
self, packets: Iterable[QuicSentPacket], space: QuicPacketSpace, now: float
) -> None:
<0> lost_packets_cc = []
<1> for packet in packets:
<2> del space.sent_packets[packet.packet_number]
<3>
<4> if packet.in_flight:
<5> lost_packets_cc.append(packet)
<6>
<7> if packet.is_ack_eliciting:
<8> space.ack_eliciting_in_flight -= 1
<9>
<10> if self._quic_logger is not None:
<11> self._quic_logger.log_event(
<12> category="recovery",
<13> event="packet_lost",
<14> data={
<15> "type": self._quic_logger.packet_type(packet.packet_type),
<16> "packet_number": str(packet.packet_number),
<17> },
<18> )
<19> self._log_metrics_updated()
<20>
<21> # trigger callbacks
<22> for handler, args in packet.delivery_handlers:
<23> handler(QuicDeliveryState.LOST, *args)
<24>
<25> # inform congestion controller
<26> if lost_packets_cc:
<27> self._cc.on_packets_lost(lost_packets_cc, now=now)
<28> self._pacer.update_rate(
<29> congestion_window=self._cc.congestion_window,
<30> smoothed_rtt=self._rtt_smoothed,
<31> )
<32> if self._quic_logger is not None:
<33> self._log_metrics_updated()
<34>
|
===========unchanged ref 0===========
at: aioquic.quic.recovery
QuicPacketSpace()
at: aioquic.quic.recovery.QuicCongestionControl
on_packets_lost(packets: Iterable[QuicSentPacket], now: float) -> None
at: aioquic.quic.recovery.QuicCongestionControl.__init__
self.congestion_window = K_INITIAL_WINDOW
at: aioquic.quic.recovery.QuicCongestionControl.on_packet_acked
self.congestion_window += packet.sent_bytes
self.congestion_window += count * K_MAX_DATAGRAM_SIZE
at: aioquic.quic.recovery.QuicCongestionControl.on_packets_lost
self.congestion_window = max(
int(self.congestion_window * K_LOSS_REDUCTION_FACTOR), K_MINIMUM_WINDOW
)
at: aioquic.quic.recovery.QuicPacketPacer
update_rate(congestion_window: int, smoothed_rtt: float) -> None
at: aioquic.quic.recovery.QuicPacketRecovery
_log_metrics_updated(log_rtt=False) -> None
at: aioquic.quic.recovery.QuicPacketRecovery.__init__
self._quic_logger = quic_logger
self._rtt_smoothed = 0.0
self._cc = QuicCongestionControl()
self._pacer = QuicPacketPacer()
at: aioquic.quic.recovery.QuicPacketRecovery.on_ack_received
self._rtt_smoothed = latest_rtt
self._rtt_smoothed = (
7 / 8 * self._rtt_smoothed + 1 / 8 * self._rtt_latest
)
at: aioquic.quic.recovery.QuicPacketSpace.__init__
self.ack_eliciting_in_flight = 0
===========unchanged ref 1===========
self.sent_packets: Dict[int, QuicSentPacket] = {}
at: typing
Iterable = _alias(collections.abc.Iterable, 1)
===========changed ref 0===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 1===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
|
examples.interop/test_version_negotiation
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<9>:<del> for stamp, category, event, data in configuration.quic_logger.to_dict()[
<10>:<del> "traces"
<11>:<del> ][0]["events"]:
<12>:<add> for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
<13>:<del> category == "transport"
<14>:<add> event["name"] == "transport:packet_received"
<del> and event == "packet_received"
<15>:<add> and event["data"]["packet_type"] == "version_negotiation"
<del> and data["packet_type"] == "version_negotiation"
|
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
<0> # force version negotiation
<1> configuration.supported_versions.insert(0, 0x1A2A3A4A)
<2>
<3> async with connect(
<4> server.host, server.port, configuration=configuration
<5> ) as protocol:
<6> await protocol.ping()
<7>
<8> # check log
<9> for stamp, category, event, data in configuration.quic_logger.to_dict()[
<10> "traces"
<11> ][0]["events"]:
<12> if (
<13> category == "transport"
<14> and event == "packet_received"
<15> and data["packet_type"] == "version_negotiation"
<16> ):
<17> server.result |= Result.V
<18>
|
===========unchanged ref 0===========
at: examples.interop
Result()
Server(name: str, host: str, port: int=4433, http3: bool=True, http3_port: Optional[int]=None, retry_port: Optional[int]=4434, path: str="/", push_path: Optional[str]=None, result: Result=field(default_factory=lambda: Result(0)), session_resumption_port: Optional[int]=None, structured_logging: bool=False, throughput_path: Optional[str]="/%(size)d", verify_mode: Optional[int]=None)
at: examples.interop.Server
name: str
host: str
port: int = 4433
http3: bool = True
http3_port: Optional[int] = None
retry_port: Optional[int] = 4434
path: str = "/"
push_path: Optional[str] = None
result: Result = field(default_factory=lambda: Result(0))
session_resumption_port: Optional[int] = None
structured_logging: bool = False
throughput_path: Optional[str] = "/%(size)d"
verify_mode: Optional[int] = None
===========changed ref 0===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 1===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 2===========
# module: aioquic.quic.recovery
class QuicPacketRecovery:
def _on_packets_lost(
self, packets: Iterable[QuicSentPacket], space: QuicPacketSpace, now: float
) -> None:
lost_packets_cc = []
for packet in packets:
del space.sent_packets[packet.packet_number]
if packet.in_flight:
lost_packets_cc.append(packet)
if packet.is_ack_eliciting:
space.ack_eliciting_in_flight -= 1
if self._quic_logger is not None:
self._quic_logger.log_event(
category="recovery",
event="packet_lost",
data={
"type": self._quic_logger.packet_type(packet.packet_type),
+ "packet_number": packet.packet_number,
- "packet_number": str(packet.packet_number),
},
)
self._log_metrics_updated()
# trigger callbacks
for handler, args in packet.delivery_handlers:
handler(QuicDeliveryState.LOST, *args)
# inform congestion controller
if lost_packets_cc:
self._cc.on_packets_lost(lost_packets_cc, now=now)
self._pacer.update_rate(
congestion_window=self._cc.congestion_window,
smoothed_rtt=self._rtt_smoothed,
)
if self._quic_logger is not None:
self._log_metrics_updated()
|
examples.interop/test_retry
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<10>:<del> for stamp, category, event, data in configuration.quic_logger.to_dict()[
<11>:<del> "traces"
<12>:<del> ][0]["events"]:
<13>:<add> for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
<14>:<del> category == "transport"
<15>:<add> event["name"] == "transport:packet_received"
<del> and event == "packet_received"
<16>:<add> and event["data"]["packet_type"] == "retry"
<del> and data["packet_type"] == "retry"
|
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
<0> # skip test if there is not retry port
<1> if server.retry_port is None:
<2> return
<3>
<4> async with connect(
<5> server.host, server.retry_port, configuration=configuration
<6> ) as protocol:
<7> await protocol.ping()
<8>
<9> # check log
<10> for stamp, category, event, data in configuration.quic_logger.to_dict()[
<11> "traces"
<12> ][0]["events"]:
<13> if (
<14> category == "transport"
<15> and event == "packet_received"
<16> and data["packet_type"] == "retry"
<17> ):
<18> server.result |= Result.S
<19>
|
===========unchanged ref 0===========
at: examples.interop
Result()
Server(name: str, host: str, port: int=4433, http3: bool=True, http3_port: Optional[int]=None, retry_port: Optional[int]=4434, path: str="/", push_path: Optional[str]=None, result: Result=field(default_factory=lambda: Result(0)), session_resumption_port: Optional[int]=None, structured_logging: bool=False, throughput_path: Optional[str]="/%(size)d", verify_mode: Optional[int]=None)
at: examples.interop.Server
host: str
port: int = 4433
retry_port: Optional[int] = 4434
result: Result = field(default_factory=lambda: Result(0))
===========changed ref 0===========
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
# force version negotiation
configuration.supported_versions.insert(0, 0x1A2A3A4A)
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "version_negotiation"
- and data["packet_type"] == "version_negotiation"
):
server.result |= Result.V
===========changed ref 1===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 2===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 3===========
# module: aioquic.quic.recovery
class QuicPacketRecovery:
def _on_packets_lost(
self, packets: Iterable[QuicSentPacket], space: QuicPacketSpace, now: float
) -> None:
lost_packets_cc = []
for packet in packets:
del space.sent_packets[packet.packet_number]
if packet.in_flight:
lost_packets_cc.append(packet)
if packet.is_ack_eliciting:
space.ack_eliciting_in_flight -= 1
if self._quic_logger is not None:
self._quic_logger.log_event(
category="recovery",
event="packet_lost",
data={
"type": self._quic_logger.packet_type(packet.packet_type),
+ "packet_number": packet.packet_number,
- "packet_number": str(packet.packet_number),
},
)
self._log_metrics_updated()
# trigger callbacks
for handler, args in packet.delivery_handlers:
handler(QuicDeliveryState.LOST, *args)
# inform congestion controller
if lost_packets_cc:
self._cc.on_packets_lost(lost_packets_cc, now=now)
self._pacer.update_rate(
congestion_window=self._cc.congestion_window,
smoothed_rtt=self._rtt_smoothed,
)
if self._quic_logger is not None:
self._log_metrics_updated()
|
examples.interop/test_nat_rebinding
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<15>:<del> for stamp, category, event, data in configuration.quic_logger.to_dict()[
<16>:<del> "traces"
<17>:<del> ][0]["events"]:
<18>:<add> for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
<19>:<del> category == "transport"
<20>:<add> event["name"] == "transport:packet_received"
<del> and event == "packet_received"
<21>:<add> and event["data"]["packet_type"] == "1RTT"
<del> and data["packet_type"] == "1RTT"
<23>:<add> for frame in event["data"]["frames"]:
<del> for frame in data["frames"]:
|
# module: examples.interop
def test_nat_rebinding(server: Server, configuration: QuicConfiguration):
<0> async with connect(
<1> server.host, server.port, configuration=configuration
<2> ) as protocol:
<3> # cause some traffic
<4> await protocol.ping()
<5>
<6> # replace transport
<7> protocol._transport.close()
<8> await loop.create_datagram_endpoint(lambda: protocol, local_addr=("::", 0))
<9>
<10> # cause more traffic
<11> await protocol.ping()
<12>
<13> # check log
<14> path_challenges = 0
<15> for stamp, category, event, data in configuration.quic_logger.to_dict()[
<16> "traces"
<17> ][0]["events"]:
<18> if (
<19> category == "transport"
<20> and event == "packet_received"
<21> and data["packet_type"] == "1RTT"
<22> ):
<23> for frame in data["frames"]:
<24> if frame["frame_type"] == "path_challenge":
<25> path_challenges += 1
<26> if not path_challenges:
<27> protocol._quic._logger.warning("No PATH_CHALLENGE received")
<28> else:
<29> server.result |= Result.B
<30>
|
===========unchanged ref 0===========
at: asyncio.events.AbstractEventLoop
create_datagram_endpoint(protocol_factory: _ProtocolFactory, local_addr: Optional[Tuple[str, int]]=..., remote_addr: Optional[Tuple[str, int]]=..., *, family: int=..., proto: int=..., flags: int=..., reuse_address: Optional[bool]=..., reuse_port: Optional[bool]=..., allow_broadcast: Optional[bool]=..., sock: Optional[socket]=...) -> _TransProtPair
at: examples.interop
Result()
Server(name: str, host: str, port: int=4433, http3: bool=True, http3_port: Optional[int]=None, retry_port: Optional[int]=4434, path: str="/", push_path: Optional[str]=None, result: Result=field(default_factory=lambda: Result(0)), session_resumption_port: Optional[int]=None, structured_logging: bool=False, throughput_path: Optional[str]="/%(size)d", verify_mode: Optional[int]=None)
loop = asyncio.get_event_loop()
at: examples.interop.Server
host: str
port: int = 4433
result: Result = field(default_factory=lambda: Result(0))
===========changed ref 0===========
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
# skip test if there is not retry port
if server.retry_port is None:
return
async with connect(
server.host, server.retry_port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "retry"
- and data["packet_type"] == "retry"
):
server.result |= Result.S
===========changed ref 1===========
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
# force version negotiation
configuration.supported_versions.insert(0, 0x1A2A3A4A)
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "version_negotiation"
- and data["packet_type"] == "version_negotiation"
):
server.result |= Result.V
===========changed ref 2===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 3===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 4===========
# module: aioquic.quic.recovery
class QuicPacketRecovery:
def _on_packets_lost(
self, packets: Iterable[QuicSentPacket], space: QuicPacketSpace, now: float
) -> None:
lost_packets_cc = []
for packet in packets:
del space.sent_packets[packet.packet_number]
if packet.in_flight:
lost_packets_cc.append(packet)
if packet.is_ack_eliciting:
space.ack_eliciting_in_flight -= 1
if self._quic_logger is not None:
self._quic_logger.log_event(
category="recovery",
event="packet_lost",
data={
"type": self._quic_logger.packet_type(packet.packet_type),
+ "packet_number": packet.packet_number,
- "packet_number": str(packet.packet_number),
},
)
self._log_metrics_updated()
# trigger callbacks
for handler, args in packet.delivery_handlers:
handler(QuicDeliveryState.LOST, *args)
# inform congestion controller
if lost_packets_cc:
self._cc.on_packets_lost(lost_packets_cc, now=now)
self._pacer.update_rate(
congestion_window=self._cc.congestion_window,
smoothed_rtt=self._rtt_smoothed,
)
if self._quic_logger is not None:
self._log_metrics_updated()
|
examples.interop/test_address_mobility
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<18>:<del> for stamp, category, event, data in configuration.quic_logger.to_dict()[
<19>:<del> "traces"
<20>:<del> ][0]["events"]:
<21>:<add> for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
<22>:<del> category == "transport"
<23>:<add> event["name"] == "transport:packet_received"
<del> and event == "packet_received"
<24>:<add> and event["data"]["packet_type"] == "1RTT"
<del> and data["packet_type"] == "1RTT"
<26>:<add> for frame in event["data"]["frames"]:
<del> for frame in data["frames"]:
<29>:<del>
|
# module: examples.interop
def test_address_mobility(server: Server, configuration: QuicConfiguration):
<0> async with connect(
<1> server.host, server.port, configuration=configuration
<2> ) as protocol:
<3> # cause some traffic
<4> await protocol.ping()
<5>
<6> # replace transport
<7> protocol._transport.close()
<8> await loop.create_datagram_endpoint(lambda: protocol, local_addr=("::", 0))
<9>
<10> # change connection ID
<11> protocol.change_connection_id()
<12>
<13> # cause more traffic
<14> await protocol.ping()
<15>
<16> # check log
<17> path_challenges = 0
<18> for stamp, category, event, data in configuration.quic_logger.to_dict()[
<19> "traces"
<20> ][0]["events"]:
<21> if (
<22> category == "transport"
<23> and event == "packet_received"
<24> and data["packet_type"] == "1RTT"
<25> ):
<26> for frame in data["frames"]:
<27> if frame["frame_type"] == "path_challenge":
<28> path_challenges += 1
<29>
<30> if not path_challenges:
<31> protocol._quic._logger.warning("No PATH_CHALLENGE received")
<32> else:
<33> server.result |= Result.A
<34>
|
===========unchanged ref 0===========
at: asyncio.events.AbstractEventLoop
create_datagram_endpoint(protocol_factory: _ProtocolFactory, local_addr: Optional[Tuple[str, int]]=..., remote_addr: Optional[Tuple[str, int]]=..., *, family: int=..., proto: int=..., flags: int=..., reuse_address: Optional[bool]=..., reuse_port: Optional[bool]=..., allow_broadcast: Optional[bool]=..., sock: Optional[socket]=...) -> _TransProtPair
at: examples.interop
Result()
Server(name: str, host: str, port: int=4433, http3: bool=True, http3_port: Optional[int]=None, retry_port: Optional[int]=4434, path: str="/", push_path: Optional[str]=None, result: Result=field(default_factory=lambda: Result(0)), session_resumption_port: Optional[int]=None, structured_logging: bool=False, throughput_path: Optional[str]="/%(size)d", verify_mode: Optional[int]=None)
loop = asyncio.get_event_loop()
at: examples.interop.Server
host: str
port: int = 4433
result: Result = field(default_factory=lambda: Result(0))
===========changed ref 0===========
# module: examples.interop
def test_nat_rebinding(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
# cause some traffic
await protocol.ping()
# replace transport
protocol._transport.close()
await loop.create_datagram_endpoint(lambda: protocol, local_addr=("::", 0))
# cause more traffic
await protocol.ping()
# check log
path_challenges = 0
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "1RTT"
- and data["packet_type"] == "1RTT"
):
+ for frame in event["data"]["frames"]:
- for frame in data["frames"]:
if frame["frame_type"] == "path_challenge":
path_challenges += 1
if not path_challenges:
protocol._quic._logger.warning("No PATH_CHALLENGE received")
else:
server.result |= Result.B
===========changed ref 1===========
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
# skip test if there is not retry port
if server.retry_port is None:
return
async with connect(
server.host, server.retry_port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "retry"
- and data["packet_type"] == "retry"
):
server.result |= Result.S
===========changed ref 2===========
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
# force version negotiation
configuration.supported_versions.insert(0, 0x1A2A3A4A)
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "version_negotiation"
- and data["packet_type"] == "version_negotiation"
):
server.result |= Result.V
===========changed ref 3===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 4===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 5===========
# module: aioquic.quic.recovery
class QuicPacketRecovery:
def _on_packets_lost(
self, packets: Iterable[QuicSentPacket], space: QuicPacketSpace, now: float
) -> None:
lost_packets_cc = []
for packet in packets:
del space.sent_packets[packet.packet_number]
if packet.in_flight:
lost_packets_cc.append(packet)
if packet.is_ack_eliciting:
space.ack_eliciting_in_flight -= 1
if self._quic_logger is not None:
self._quic_logger.log_event(
category="recovery",
event="packet_lost",
data={
"type": self._quic_logger.packet_type(packet.packet_type),
+ "packet_number": packet.packet_number,
- "packet_number": str(packet.packet_number),
},
)
self._log_metrics_updated()
# trigger callbacks
for handler, args in packet.delivery_handlers:
handler(QuicDeliveryState.LOST, *args)
# inform congestion controller
if lost_packets_cc:
self._cc.on_packets_lost(lost_packets_cc, now=now)
self._pacer.update_rate(
congestion_window=self._cc.congestion_window,
smoothed_rtt=self._rtt_smoothed,
)
if self._quic_logger is not None:
self._log_metrics_updated()
|
examples.interop/test_spin_bit
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<8>:<del> for stamp, category, event, data in configuration.quic_logger.to_dict()[
<9>:<del> "traces"
<10>:<del> ][0]["events"]:
<11>:<add> for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
<add> if event["name"] == "connectivity:spin_bit_updated":
<del> if category == "connectivity" and event == "spin_bit_updated":
<12>:<add> spin_bits.add(event["data"]["state"])
<del> spin_bits.add(data["state"])
|
# module: examples.interop
def test_spin_bit(server: Server, configuration: QuicConfiguration):
<0> async with connect(
<1> server.host, server.port, configuration=configuration
<2> ) as protocol:
<3> for i in range(5):
<4> await protocol.ping()
<5>
<6> # check log
<7> spin_bits = set()
<8> for stamp, category, event, data in configuration.quic_logger.to_dict()[
<9> "traces"
<10> ][0]["events"]:
<11> if category == "connectivity" and event == "spin_bit_updated":
<12> spin_bits.add(data["state"])
<13> if len(spin_bits) == 2:
<14> server.result |= Result.P
<15>
|
===========unchanged ref 0===========
at: examples.interop
Result()
Server(name: str, host: str, port: int=4433, http3: bool=True, http3_port: Optional[int]=None, retry_port: Optional[int]=4434, path: str="/", push_path: Optional[str]=None, result: Result=field(default_factory=lambda: Result(0)), session_resumption_port: Optional[int]=None, structured_logging: bool=False, throughput_path: Optional[str]="/%(size)d", verify_mode: Optional[int]=None)
at: examples.interop.Server
host: str
result: Result = field(default_factory=lambda: Result(0))
throughput_path: Optional[str] = "/%(size)d"
at: httpx._api
get(url: URL | str, *, params: QueryParamTypes | None=None, headers: HeaderTypes | None=None, cookies: CookieTypes | None=None, auth: AuthTypes | None=None, proxy: ProxyTypes | None=None, proxies: ProxiesTypes | None=None, follow_redirects: bool=False, cert: CertTypes | None=None, verify: VerifyTypes=True, timeout: TimeoutTypes=DEFAULT_TIMEOUT_CONFIG, trust_env: bool=True) -> Response
at: time
time() -> float
===========changed ref 0===========
# module: examples.interop
def test_address_mobility(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
# cause some traffic
await protocol.ping()
# replace transport
protocol._transport.close()
await loop.create_datagram_endpoint(lambda: protocol, local_addr=("::", 0))
# change connection ID
protocol.change_connection_id()
# cause more traffic
await protocol.ping()
# check log
path_challenges = 0
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "1RTT"
- and data["packet_type"] == "1RTT"
):
+ for frame in event["data"]["frames"]:
- for frame in data["frames"]:
if frame["frame_type"] == "path_challenge":
path_challenges += 1
-
if not path_challenges:
protocol._quic._logger.warning("No PATH_CHALLENGE received")
else:
server.result |= Result.A
===========changed ref 1===========
# module: examples.interop
def test_nat_rebinding(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
# cause some traffic
await protocol.ping()
# replace transport
protocol._transport.close()
await loop.create_datagram_endpoint(lambda: protocol, local_addr=("::", 0))
# cause more traffic
await protocol.ping()
# check log
path_challenges = 0
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "1RTT"
- and data["packet_type"] == "1RTT"
):
+ for frame in event["data"]["frames"]:
- for frame in data["frames"]:
if frame["frame_type"] == "path_challenge":
path_challenges += 1
if not path_challenges:
protocol._quic._logger.warning("No PATH_CHALLENGE received")
else:
server.result |= Result.B
===========changed ref 2===========
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
# skip test if there is not retry port
if server.retry_port is None:
return
async with connect(
server.host, server.retry_port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "retry"
- and data["packet_type"] == "retry"
):
server.result |= Result.S
===========changed ref 3===========
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
# force version negotiation
configuration.supported_versions.insert(0, 0x1A2A3A4A)
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "version_negotiation"
- and data["packet_type"] == "version_negotiation"
):
server.result |= Result.V
===========changed ref 4===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 5===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
|
aioquic.quic.connection/QuicConnection.datagrams_to_send
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
# module: aioquic.quic.connection
class QuicConnection:
def datagrams_to_send(self, now: float) -> List[Tuple[bytes, NetworkAddress]]:
<0> """
<1> Return a list of `(data, addr)` tuples of datagrams which need to be
<2> sent, and the network address to which they need to be sent.
<3>
<4> After calling this method call :meth:`get_timer` to know when the next
<5> timer needs to be set.
<6>
<7> :param now: The current time.
<8> """
<9> network_path = self._network_paths[0]
<10>
<11> if self._state in END_STATES:
<12> return []
<13>
<14> # build datagrams
<15> builder = QuicPacketBuilder(
<16> host_cid=self.host_cid,
<17> is_client=self._is_client,
<18> packet_number=self._packet_number,
<19> peer_cid=self._peer_cid.cid,
<20> peer_token=self._peer_token,
<21> quic_logger=self._quic_logger,
<22> spin_bit=self._spin_bit,
<23> version=self._version,
<24> )
<25> if self._close_pending:
<26> epoch_packet_types = []
<27> if not self._handshake_confirmed:
<28> epoch_packet_types += [
<29> (tls.Epoch.INITIAL, PACKET_TYPE_INITIAL),
<30> (tls.Epoch.HANDSHAKE, PACKET_TYPE_HANDSHAKE),
<31> ]
<32> epoch_packet_types.append((tls.Epoch.ONE_RTT, PACKET_TYPE_ONE_RTT))
<33> for epoch, packet_type in epoch_packet_types:
<34> crypto = self._cryptos[epoch]
<35> if crypto.send.is_valid():
<36> builder.start_packet(packet_type, crypto)
<37> self._write_connection_close_frame(
<38> builder=builder,
<39> epoch=epoch,
<40> error_code=self._close_event.error_code</s>
|
===========below chunk 0===========
# module: aioquic.quic.connection
class QuicConnection:
def datagrams_to_send(self, now: float) -> List[Tuple[bytes, NetworkAddress]]:
# offset: 1
frame_type=self._close_event.frame_type,
reason_phrase=self._close_event.reason_phrase,
)
self._logger.info(
"Connection close sent (code 0x%X, reason %s)",
self._close_event.error_code,
self._close_event.reason_phrase,
)
self._close_pending = False
self._close_begin(is_initiator=True, now=now)
else:
# congestion control
builder.max_flight_bytes = (
self._loss.congestion_window - self._loss.bytes_in_flight
)
if self._probe_pending and builder.max_flight_bytes < PACKET_MAX_SIZE:
builder.max_flight_bytes = PACKET_MAX_SIZE
# limit data on un-validated network paths
if not network_path.is_validated:
builder.max_total_bytes = (
network_path.bytes_received * 3 - network_path.bytes_sent
)
try:
if not self._handshake_confirmed:
for epoch in [tls.Epoch.INITIAL, tls.Epoch.HANDSHAKE]:
self._write_handshake(builder, epoch, now)
self._write_application(builder, network_path, now)
except QuicPacketBuilderStop:
pass
datagrams, packets = builder.flush()
if datagrams:
self._packet_number = builder.packet_number
# register packets
sent_handshake = False
for packet in packets:
packet.sent_time = now
self._loss.on_packet_sent(
packet=packet, space=self._spaces[packet.epoch]
)
if packet.epoch == tls.Epoch.HANDSHAKE:
sent_handshake = True
</s>
===========below chunk 1===========
# module: aioquic.quic.connection
class QuicConnection:
def datagrams_to_send(self, now: float) -> List[Tuple[bytes, NetworkAddress]]:
# offset: 2
<s>]
)
if packet.epoch == tls.Epoch.HANDSHAKE:
sent_handshake = True
# log packet
if self._quic_logger is not None:
self._quic_logger.log_event(
category="transport",
event="packet_sent",
data={
"packet_type": self._quic_logger.packet_type(
packet.packet_type
),
"header": {
"packet_number": str(packet.packet_number),
"packet_size": packet.sent_bytes,
"scid": dump_cid(self.host_cid)
if is_long_header(packet.packet_type)
else "",
"dcid": dump_cid(self._peer_cid.cid),
},
"frames": packet.quic_logger_frames,
},
)
# check if we can discard initial keys
if sent_handshake and self._is_client:
self._discard_epoch(tls.Epoch.INITIAL)
# return datagrams to send and the destination network address
ret = []
for datagram in datagrams:
byte_length = len(datagram)
network_path.bytes_sent += byte_length
ret.append((datagram, network_path.addr))
if self._quic_logger is not None:
self._quic_logger.log_event(
category="transport",
event="datagrams_sent",
data={"byte_length": byte_length, "count": 1},
)
return ret
===========unchanged ref 0===========
at: aioquic.quic.connection
NetworkAddress = Any
dump_cid(cid: bytes) -> str
END_STATES = frozenset(
[
QuicConnectionState.CLOSING,
QuicConnectionState.DRAINING,
QuicConnectionState.TERMINATED,
]
)
at: aioquic.quic.connection.QuicConnection
_close_begin(is_initiator: bool, now: float) -> None
_write_application(builder: QuicPacketBuilder, network_path: QuicNetworkPath, now: float) -> None
_write_handshake(builder: QuicPacketBuilder, epoch: tls.Epoch, now: float) -> None
_write_connection_close_frame(builder: QuicPacketBuilder, epoch: tls.Epoch, error_code: int, frame_type: Optional[int], reason_phrase: str) -> None
at: aioquic.quic.connection.QuicConnection.__init__
self._is_client = configuration.is_client
self._close_event: Optional[events.ConnectionTerminated] = None
self._cryptos: Dict[tls.Epoch, CryptoPair] = {}
self._handshake_confirmed = False
self.host_cid = self._host_cids[0].cid
self._network_paths: List[QuicNetworkPath] = []
self._packet_number = 0
self._peer_cid = QuicConnectionId(
cid=os.urandom(configuration.connection_id_length), sequence_number=None
)
self._peer_token = b""
self._quic_logger: Optional[QuicLoggerTrace] = None
self._quic_logger = configuration.quic_logger.start_trace(
is_client=configuration.is_client,
odcid=self._original_destination_connection_id,
)
self._spaces: Dict[tls.Epoch, QuicPacketSpace] = {}
self._spin_bit = False
===========unchanged ref 1===========
self._state = QuicConnectionState.FIRSTFLIGHT
self._version: Optional[int] = None
self._logger = QuicConnectionAdapter(
logger, {"id": dump_cid(self._original_destination_connection_id)}
)
self._loss = QuicPacketRecovery(
initial_rtt=configuration.initial_rtt,
peer_completed_address_validation=not self._is_client,
quic_logger=self._quic_logger,
send_probe=self._send_probe,
)
self._close_pending = False
self._probe_pending = False
at: aioquic.quic.connection.QuicConnection._close_end
self._quic_logger = None
at: aioquic.quic.connection.QuicConnection._consume_peer_cid
self._peer_cid = self._peer_cid_available.pop(0)
at: aioquic.quic.connection.QuicConnection._handle_connection_close_frame
self._close_event = events.ConnectionTerminated(
error_code=error_code,
frame_type=frame_type,
reason_phrase=reason_phrase,
)
at: aioquic.quic.connection.QuicConnection._handle_crypto_frame
self._handshake_confirmed = True
at: aioquic.quic.connection.QuicConnection._handle_handshake_done_frame
self._handshake_confirmed = True
at: aioquic.quic.connection.QuicConnection._initialize
self._cryptos = dict(
(epoch, create_crypto_pair(epoch))
for epoch in (
tls.Epoch.INITIAL,
tls.Epoch.ZERO_RTT,
tls.Epoch.HANDSHAKE,
tls.Epoch.ONE_RTT,
)
)
self._spaces = {
tls.Epoch.INITIAL: QuicPacketSpace(),
tls.Epoch.HANDSHAKE: QuicPacketSpace(),
tls.Epoch.ONE_RTT: QuicPacketSpace(),
}
|
|
aioquic.quic.logger/QuicLoggerTrace.encode_ack_frame
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<1>:<add> "ack_delay": self.encode_time(delay),
<del> "ack_delay": str(self.encode_time(delay)),
<2>:<add> "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
<del> "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
<0> return {
<1> "ack_delay": str(self.encode_time(delay)),
<2> "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
<3> "frame_type": "ack",
<4> }
<5>
|
===========changed ref 0===========
# module: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
+ QLOG_VERSION = "0.3"
===========changed ref 1===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 2===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 3===========
# module: examples.interop
def test_spin_bit(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
for i in range(5):
await protocol.ping()
# check log
spin_bits = set()
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
+ if event["name"] == "connectivity:spin_bit_updated":
- if category == "connectivity" and event == "spin_bit_updated":
+ spin_bits.add(event["data"]["state"])
- spin_bits.add(data["state"])
if len(spin_bits) == 2:
server.result |= Result.P
===========changed ref 4===========
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
# skip test if there is not retry port
if server.retry_port is None:
return
async with connect(
server.host, server.retry_port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "retry"
- and data["packet_type"] == "retry"
):
server.result |= Result.S
===========changed ref 5===========
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
# force version negotiation
configuration.supported_versions.insert(0, 0x1A2A3A4A)
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "version_negotiation"
- and data["packet_type"] == "version_negotiation"
):
server.result |= Result.V
===========changed ref 6===========
# module: aioquic.quic.recovery
class QuicPacketRecovery:
def _on_packets_lost(
self, packets: Iterable[QuicSentPacket], space: QuicPacketSpace, now: float
) -> None:
lost_packets_cc = []
for packet in packets:
del space.sent_packets[packet.packet_number]
if packet.in_flight:
lost_packets_cc.append(packet)
if packet.is_ack_eliciting:
space.ack_eliciting_in_flight -= 1
if self._quic_logger is not None:
self._quic_logger.log_event(
category="recovery",
event="packet_lost",
data={
"type": self._quic_logger.packet_type(packet.packet_type),
+ "packet_number": packet.packet_number,
- "packet_number": str(packet.packet_number),
},
)
self._log_metrics_updated()
# trigger callbacks
for handler, args in packet.delivery_handlers:
handler(QuicDeliveryState.LOST, *args)
# inform congestion controller
if lost_packets_cc:
self._cc.on_packets_lost(lost_packets_cc, now=now)
self._pacer.update_rate(
congestion_window=self._cc.congestion_window,
smoothed_rtt=self._rtt_smoothed,
)
if self._quic_logger is not None:
self._log_metrics_updated()
===========changed ref 7===========
# module: examples.interop
def test_nat_rebinding(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
# cause some traffic
await protocol.ping()
# replace transport
protocol._transport.close()
await loop.create_datagram_endpoint(lambda: protocol, local_addr=("::", 0))
# cause more traffic
await protocol.ping()
# check log
path_challenges = 0
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "1RTT"
- and data["packet_type"] == "1RTT"
):
+ for frame in event["data"]["frames"]:
- for frame in data["frames"]:
if frame["frame_type"] == "path_challenge":
path_challenges += 1
if not path_challenges:
protocol._quic._logger.warning("No PATH_CHALLENGE received")
else:
server.result |= Result.B
|
aioquic.quic.logger/QuicLoggerTrace.encode_connection_limit_frame
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<1>:<add> return {"frame_type": "max_data", "maximum": maximum}
<del> return {"frame_type": "max_data", "maximum": str(maximum)}
<5>:<add> "maximum": maximum,
<del> "maximum": str(maximum),
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_connection_limit_frame(self, frame_type: int, maximum: int) -> Dict:
<0> if frame_type == QuicFrameType.MAX_DATA:
<1> return {"frame_type": "max_data", "maximum": str(maximum)}
<2> else:
<3> return {
<4> "frame_type": "max_streams",
<5> "maximum": str(maximum),
<6> "stream_type": "unidirectional"
<7> if frame_type == QuicFrameType.MAX_STREAMS_UNI
<8> else "bidirectional",
<9> }
<10>
|
===========unchanged ref 0===========
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
return {
+ "ack_delay": self.encode_time(delay),
- "ack_delay": str(self.encode_time(delay)),
+ "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
- "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
"frame_type": "ack",
}
===========changed ref 1===========
# module: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
+ QLOG_VERSION = "0.3"
===========changed ref 2===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 3===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 4===========
# module: examples.interop
def test_spin_bit(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
for i in range(5):
await protocol.ping()
# check log
spin_bits = set()
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
+ if event["name"] == "connectivity:spin_bit_updated":
- if category == "connectivity" and event == "spin_bit_updated":
+ spin_bits.add(event["data"]["state"])
- spin_bits.add(data["state"])
if len(spin_bits) == 2:
server.result |= Result.P
===========changed ref 5===========
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
# skip test if there is not retry port
if server.retry_port is None:
return
async with connect(
server.host, server.retry_port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "retry"
- and data["packet_type"] == "retry"
):
server.result |= Result.S
===========changed ref 6===========
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
# force version negotiation
configuration.supported_versions.insert(0, 0x1A2A3A4A)
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "version_negotiation"
- and data["packet_type"] == "version_negotiation"
):
server.result |= Result.V
===========changed ref 7===========
# module: aioquic.quic.recovery
class QuicPacketRecovery:
def _on_packets_lost(
self, packets: Iterable[QuicSentPacket], space: QuicPacketSpace, now: float
) -> None:
lost_packets_cc = []
for packet in packets:
del space.sent_packets[packet.packet_number]
if packet.in_flight:
lost_packets_cc.append(packet)
if packet.is_ack_eliciting:
space.ack_eliciting_in_flight -= 1
if self._quic_logger is not None:
self._quic_logger.log_event(
category="recovery",
event="packet_lost",
data={
"type": self._quic_logger.packet_type(packet.packet_type),
+ "packet_number": packet.packet_number,
- "packet_number": str(packet.packet_number),
},
)
self._log_metrics_updated()
# trigger callbacks
for handler, args in packet.delivery_handlers:
handler(QuicDeliveryState.LOST, *args)
# inform congestion controller
if lost_packets_cc:
self._cc.on_packets_lost(lost_packets_cc, now=now)
self._pacer.update_rate(
congestion_window=self._cc.congestion_window,
smoothed_rtt=self._rtt_smoothed,
)
if self._quic_logger is not None:
self._log_metrics_updated()
|
aioquic.quic.logger/QuicLoggerTrace.encode_crypto_frame
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<3>:<add> "offset": frame.offset,
<del> "offset": str(frame.offset),
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
<0> return {
<1> "frame_type": "crypto",
<2> "length": len(frame.data),
<3> "offset": str(frame.offset),
<4> }
<5>
|
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
return {
+ "ack_delay": self.encode_time(delay),
- "ack_delay": str(self.encode_time(delay)),
+ "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
- "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
"frame_type": "ack",
}
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_connection_limit_frame(self, frame_type: int, maximum: int) -> Dict:
if frame_type == QuicFrameType.MAX_DATA:
+ return {"frame_type": "max_data", "maximum": maximum}
- return {"frame_type": "max_data", "maximum": str(maximum)}
else:
return {
"frame_type": "max_streams",
+ "maximum": maximum,
- "maximum": str(maximum),
"stream_type": "unidirectional"
if frame_type == QuicFrameType.MAX_STREAMS_UNI
else "bidirectional",
}
===========changed ref 2===========
# module: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
+ QLOG_VERSION = "0.3"
===========changed ref 3===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 4===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 5===========
# module: examples.interop
def test_spin_bit(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
for i in range(5):
await protocol.ping()
# check log
spin_bits = set()
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
+ if event["name"] == "connectivity:spin_bit_updated":
- if category == "connectivity" and event == "spin_bit_updated":
+ spin_bits.add(event["data"]["state"])
- spin_bits.add(data["state"])
if len(spin_bits) == 2:
server.result |= Result.P
===========changed ref 6===========
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
# skip test if there is not retry port
if server.retry_port is None:
return
async with connect(
server.host, server.retry_port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "retry"
- and data["packet_type"] == "retry"
):
server.result |= Result.S
===========changed ref 7===========
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
# force version negotiation
configuration.supported_versions.insert(0, 0x1A2A3A4A)
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "version_negotiation"
- and data["packet_type"] == "version_negotiation"
):
server.result |= Result.V
===========changed ref 8===========
# module: aioquic.quic.recovery
class QuicPacketRecovery:
def _on_packets_lost(
self, packets: Iterable[QuicSentPacket], space: QuicPacketSpace, now: float
) -> None:
lost_packets_cc = []
for packet in packets:
del space.sent_packets[packet.packet_number]
if packet.in_flight:
lost_packets_cc.append(packet)
if packet.is_ack_eliciting:
space.ack_eliciting_in_flight -= 1
if self._quic_logger is not None:
self._quic_logger.log_event(
category="recovery",
event="packet_lost",
data={
"type": self._quic_logger.packet_type(packet.packet_type),
+ "packet_number": packet.packet_number,
- "packet_number": str(packet.packet_number),
},
)
self._log_metrics_updated()
# trigger callbacks
for handler, args in packet.delivery_handlers:
handler(QuicDeliveryState.LOST, *args)
# inform congestion controller
if lost_packets_cc:
self._cc.on_packets_lost(lost_packets_cc, now=now)
self._pacer.update_rate(
congestion_window=self._cc.congestion_window,
smoothed_rtt=self._rtt_smoothed,
)
if self._quic_logger is not None:
self._log_metrics_updated()
|
aioquic.quic.logger/QuicLoggerTrace.encode_data_blocked_frame
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<0>:<add> return {"frame_type": "data_blocked", "limit": limit}
<del> return {"frame_type": "data_blocked", "limit": str(limit)}
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
<0> return {"frame_type": "data_blocked", "limit": str(limit)}
<1>
|
===========unchanged ref 0===========
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
return {
+ "ack_delay": self.encode_time(delay),
- "ack_delay": str(self.encode_time(delay)),
+ "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
- "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
"frame_type": "ack",
}
===========changed ref 2===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_connection_limit_frame(self, frame_type: int, maximum: int) -> Dict:
if frame_type == QuicFrameType.MAX_DATA:
+ return {"frame_type": "max_data", "maximum": maximum}
- return {"frame_type": "max_data", "maximum": str(maximum)}
else:
return {
"frame_type": "max_streams",
+ "maximum": maximum,
- "maximum": str(maximum),
"stream_type": "unidirectional"
if frame_type == QuicFrameType.MAX_STREAMS_UNI
else "bidirectional",
}
===========changed ref 3===========
# module: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
+ QLOG_VERSION = "0.3"
===========changed ref 4===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 5===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 6===========
# module: examples.interop
def test_spin_bit(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
for i in range(5):
await protocol.ping()
# check log
spin_bits = set()
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
+ if event["name"] == "connectivity:spin_bit_updated":
- if category == "connectivity" and event == "spin_bit_updated":
+ spin_bits.add(event["data"]["state"])
- spin_bits.add(data["state"])
if len(spin_bits) == 2:
server.result |= Result.P
===========changed ref 7===========
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
# skip test if there is not retry port
if server.retry_port is None:
return
async with connect(
server.host, server.retry_port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "retry"
- and data["packet_type"] == "retry"
):
server.result |= Result.S
===========changed ref 8===========
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
# force version negotiation
configuration.supported_versions.insert(0, 0x1A2A3A4A)
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "version_negotiation"
- and data["packet_type"] == "version_negotiation"
):
server.result |= Result.V
|
aioquic.quic.logger/QuicLoggerTrace.encode_max_stream_data_frame
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<2>:<add> "maximum": maximum,
<del> "maximum": str(maximum),
<3>:<add> "stream_id": stream_id,
<del> "stream_id": str(stream_id),
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_max_stream_data_frame(self, maximum: int, stream_id: int) -> Dict:
<0> return {
<1> "frame_type": "max_stream_data",
<2> "maximum": str(maximum),
<3> "stream_id": str(stream_id),
<4> }
<5>
|
===========unchanged ref 0===========
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 2===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
return {
+ "ack_delay": self.encode_time(delay),
- "ack_delay": str(self.encode_time(delay)),
+ "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
- "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
"frame_type": "ack",
}
===========changed ref 3===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_connection_limit_frame(self, frame_type: int, maximum: int) -> Dict:
if frame_type == QuicFrameType.MAX_DATA:
+ return {"frame_type": "max_data", "maximum": maximum}
- return {"frame_type": "max_data", "maximum": str(maximum)}
else:
return {
"frame_type": "max_streams",
+ "maximum": maximum,
- "maximum": str(maximum),
"stream_type": "unidirectional"
if frame_type == QuicFrameType.MAX_STREAMS_UNI
else "bidirectional",
}
===========changed ref 4===========
# module: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
+ QLOG_VERSION = "0.3"
===========changed ref 5===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 6===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 7===========
# module: examples.interop
def test_spin_bit(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
for i in range(5):
await protocol.ping()
# check log
spin_bits = set()
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
+ if event["name"] == "connectivity:spin_bit_updated":
- if category == "connectivity" and event == "spin_bit_updated":
+ spin_bits.add(event["data"]["state"])
- spin_bits.add(data["state"])
if len(spin_bits) == 2:
server.result |= Result.P
===========changed ref 8===========
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
# skip test if there is not retry port
if server.retry_port is None:
return
async with connect(
server.host, server.retry_port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "retry"
- and data["packet_type"] == "retry"
):
server.result |= Result.S
===========changed ref 9===========
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
# force version negotiation
configuration.supported_versions.insert(0, 0x1A2A3A4A)
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "version_negotiation"
- and data["packet_type"] == "version_negotiation"
):
server.result |= Result.V
|
aioquic.quic.logger/QuicLoggerTrace.encode_new_connection_id_frame
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<5>:<add> "retire_prior_to": retire_prior_to,
<del> "retire_prior_to": str(retire_prior_to),
<6>:<add> "sequence_number": sequence_number,
<del> "sequence_number": str(sequence_number),
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_new_connection_id_frame(
self,
connection_id: bytes,
retire_prior_to: int,
sequence_number: int,
stateless_reset_token: bytes,
) -> Dict:
<0> return {
<1> "connection_id": hexdump(connection_id),
<2> "frame_type": "new_connection_id",
<3> "length": len(connection_id),
<4> "reset_token": hexdump(stateless_reset_token),
<5> "retire_prior_to": str(retire_prior_to),
<6> "sequence_number": str(sequence_number),
<7> }
<8>
|
===========unchanged ref 0===========
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_max_stream_data_frame(self, maximum: int, stream_id: int) -> Dict:
return {
"frame_type": "max_stream_data",
+ "maximum": maximum,
- "maximum": str(maximum),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 2===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 3===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
return {
+ "ack_delay": self.encode_time(delay),
- "ack_delay": str(self.encode_time(delay)),
+ "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
- "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
"frame_type": "ack",
}
===========changed ref 4===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_connection_limit_frame(self, frame_type: int, maximum: int) -> Dict:
if frame_type == QuicFrameType.MAX_DATA:
+ return {"frame_type": "max_data", "maximum": maximum}
- return {"frame_type": "max_data", "maximum": str(maximum)}
else:
return {
"frame_type": "max_streams",
+ "maximum": maximum,
- "maximum": str(maximum),
"stream_type": "unidirectional"
if frame_type == QuicFrameType.MAX_STREAMS_UNI
else "bidirectional",
}
===========changed ref 5===========
# module: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
+ QLOG_VERSION = "0.3"
===========changed ref 6===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 7===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 8===========
# module: examples.interop
def test_spin_bit(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
for i in range(5):
await protocol.ping()
# check log
spin_bits = set()
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
+ if event["name"] == "connectivity:spin_bit_updated":
- if category == "connectivity" and event == "spin_bit_updated":
+ spin_bits.add(event["data"]["state"])
- spin_bits.add(data["state"])
if len(spin_bits) == 2:
server.result |= Result.P
===========changed ref 9===========
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
# skip test if there is not retry port
if server.retry_port is None:
return
async with connect(
server.host, server.retry_port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "retry"
- and data["packet_type"] == "retry"
):
server.result |= Result.S
===========changed ref 10===========
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
# force version negotiation
configuration.supported_versions.insert(0, 0x1A2A3A4A)
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "version_negotiation"
- and data["packet_type"] == "version_negotiation"
):
server.result |= Result.V
|
aioquic.quic.logger/QuicLoggerTrace.encode_reset_stream_frame
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<2>:<add> "final_size": final_size,
<del> "final_size": str(final_size),
<4>:<add> "stream_id": stream_id,
<del> "stream_id": str(stream_id),
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_reset_stream_frame(
self, error_code: int, final_size: int, stream_id: int
) -> Dict:
<0> return {
<1> "error_code": error_code,
<2> "final_size": str(final_size),
<3> "frame_type": "reset_stream",
<4> "stream_id": str(stream_id),
<5> }
<6>
|
===========unchanged ref 0===========
at: aioquic.quic.logger
hexdump(data: bytes) -> str
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_max_stream_data_frame(self, maximum: int, stream_id: int) -> Dict:
return {
"frame_type": "max_stream_data",
+ "maximum": maximum,
- "maximum": str(maximum),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 2===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 3===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_new_connection_id_frame(
self,
connection_id: bytes,
retire_prior_to: int,
sequence_number: int,
stateless_reset_token: bytes,
) -> Dict:
return {
"connection_id": hexdump(connection_id),
"frame_type": "new_connection_id",
"length": len(connection_id),
"reset_token": hexdump(stateless_reset_token),
+ "retire_prior_to": retire_prior_to,
- "retire_prior_to": str(retire_prior_to),
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 4===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
return {
+ "ack_delay": self.encode_time(delay),
- "ack_delay": str(self.encode_time(delay)),
+ "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
- "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
"frame_type": "ack",
}
===========changed ref 5===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_connection_limit_frame(self, frame_type: int, maximum: int) -> Dict:
if frame_type == QuicFrameType.MAX_DATA:
+ return {"frame_type": "max_data", "maximum": maximum}
- return {"frame_type": "max_data", "maximum": str(maximum)}
else:
return {
"frame_type": "max_streams",
+ "maximum": maximum,
- "maximum": str(maximum),
"stream_type": "unidirectional"
if frame_type == QuicFrameType.MAX_STREAMS_UNI
else "bidirectional",
}
===========changed ref 6===========
# module: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
+ QLOG_VERSION = "0.3"
===========changed ref 7===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 8===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 9===========
# module: examples.interop
def test_spin_bit(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
for i in range(5):
await protocol.ping()
# check log
spin_bits = set()
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
+ if event["name"] == "connectivity:spin_bit_updated":
- if category == "connectivity" and event == "spin_bit_updated":
+ spin_bits.add(event["data"]["state"])
- spin_bits.add(data["state"])
if len(spin_bits) == 2:
server.result |= Result.P
===========changed ref 10===========
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
# skip test if there is not retry port
if server.retry_port is None:
return
async with connect(
server.host, server.retry_port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "retry"
- and data["packet_type"] == "retry"
):
server.result |= Result.S
|
aioquic.quic.logger/QuicLoggerTrace.encode_retire_connection_id_frame
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<2>:<add> "sequence_number": sequence_number,
<del> "sequence_number": str(sequence_number),
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_retire_connection_id_frame(self, sequence_number: int) -> Dict:
<0> return {
<1> "frame_type": "retire_connection_id",
<2> "sequence_number": str(sequence_number),
<3> }
<4>
|
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_reset_stream_frame(
self, error_code: int, final_size: int, stream_id: int
) -> Dict:
return {
"error_code": error_code,
+ "final_size": final_size,
- "final_size": str(final_size),
"frame_type": "reset_stream",
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 2===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_max_stream_data_frame(self, maximum: int, stream_id: int) -> Dict:
return {
"frame_type": "max_stream_data",
+ "maximum": maximum,
- "maximum": str(maximum),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 3===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 4===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_new_connection_id_frame(
self,
connection_id: bytes,
retire_prior_to: int,
sequence_number: int,
stateless_reset_token: bytes,
) -> Dict:
return {
"connection_id": hexdump(connection_id),
"frame_type": "new_connection_id",
"length": len(connection_id),
"reset_token": hexdump(stateless_reset_token),
+ "retire_prior_to": retire_prior_to,
- "retire_prior_to": str(retire_prior_to),
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 5===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
return {
+ "ack_delay": self.encode_time(delay),
- "ack_delay": str(self.encode_time(delay)),
+ "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
- "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
"frame_type": "ack",
}
===========changed ref 6===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_connection_limit_frame(self, frame_type: int, maximum: int) -> Dict:
if frame_type == QuicFrameType.MAX_DATA:
+ return {"frame_type": "max_data", "maximum": maximum}
- return {"frame_type": "max_data", "maximum": str(maximum)}
else:
return {
"frame_type": "max_streams",
+ "maximum": maximum,
- "maximum": str(maximum),
"stream_type": "unidirectional"
if frame_type == QuicFrameType.MAX_STREAMS_UNI
else "bidirectional",
}
===========changed ref 7===========
# module: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
+ QLOG_VERSION = "0.3"
===========changed ref 8===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 9===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 10===========
# module: examples.interop
def test_spin_bit(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
for i in range(5):
await protocol.ping()
# check log
spin_bits = set()
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
+ if event["name"] == "connectivity:spin_bit_updated":
- if category == "connectivity" and event == "spin_bit_updated":
+ spin_bits.add(event["data"]["state"])
- spin_bits.add(data["state"])
if len(spin_bits) == 2:
server.result |= Result.P
===========changed ref 11===========
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
# skip test if there is not retry port
if server.retry_port is None:
return
async with connect(
server.host, server.retry_port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "retry"
- and data["packet_type"] == "retry"
):
server.result |= Result.S
|
aioquic.quic.logger/QuicLoggerTrace.encode_stream_data_blocked_frame
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<2>:<add> "limit": limit,
<del> "limit": str(limit),
<3>:<add> "stream_id": stream_id,
<del> "stream_id": str(stream_id),
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_data_blocked_frame(self, limit: int, stream_id: int) -> Dict:
<0> return {
<1> "frame_type": "stream_data_blocked",
<2> "limit": str(limit),
<3> "stream_id": str(stream_id),
<4> }
<5>
|
===========unchanged ref 0===========
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_retire_connection_id_frame(self, sequence_number: int) -> Dict:
return {
"frame_type": "retire_connection_id",
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_reset_stream_frame(
self, error_code: int, final_size: int, stream_id: int
) -> Dict:
return {
"error_code": error_code,
+ "final_size": final_size,
- "final_size": str(final_size),
"frame_type": "reset_stream",
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 2===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 3===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_max_stream_data_frame(self, maximum: int, stream_id: int) -> Dict:
return {
"frame_type": "max_stream_data",
+ "maximum": maximum,
- "maximum": str(maximum),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 4===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 5===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_new_connection_id_frame(
self,
connection_id: bytes,
retire_prior_to: int,
sequence_number: int,
stateless_reset_token: bytes,
) -> Dict:
return {
"connection_id": hexdump(connection_id),
"frame_type": "new_connection_id",
"length": len(connection_id),
"reset_token": hexdump(stateless_reset_token),
+ "retire_prior_to": retire_prior_to,
- "retire_prior_to": str(retire_prior_to),
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 6===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
return {
+ "ack_delay": self.encode_time(delay),
- "ack_delay": str(self.encode_time(delay)),
+ "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
- "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
"frame_type": "ack",
}
===========changed ref 7===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_connection_limit_frame(self, frame_type: int, maximum: int) -> Dict:
if frame_type == QuicFrameType.MAX_DATA:
+ return {"frame_type": "max_data", "maximum": maximum}
- return {"frame_type": "max_data", "maximum": str(maximum)}
else:
return {
"frame_type": "max_streams",
+ "maximum": maximum,
- "maximum": str(maximum),
"stream_type": "unidirectional"
if frame_type == QuicFrameType.MAX_STREAMS_UNI
else "bidirectional",
}
===========changed ref 8===========
# module: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
+ QLOG_VERSION = "0.3"
===========changed ref 9===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 10===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 11===========
# module: examples.interop
def test_spin_bit(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
for i in range(5):
await protocol.ping()
# check log
spin_bits = set()
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
+ if event["name"] == "connectivity:spin_bit_updated":
- if category == "connectivity" and event == "spin_bit_updated":
+ spin_bits.add(event["data"]["state"])
- spin_bits.add(data["state"])
if len(spin_bits) == 2:
server.result |= Result.P
===========changed ref 12===========
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
# skip test if there is not retry port
if server.retry_port is None:
return
async with connect(
server.host, server.retry_port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
- category == "transport"
+ event["name"] == "transport:packet_received"
- and event == "packet_received"
+ and event["data"]["packet_type"] == "retry"
- and data["packet_type"] == "retry"
):
server.result |= Result.S
|
aioquic.quic.logger/QuicLoggerTrace.encode_stop_sending_frame
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<3>:<add> "stream_id": stream_id,
<del> "stream_id": str(stream_id),
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stop_sending_frame(self, error_code: int, stream_id: int) -> Dict:
<0> return {
<1> "frame_type": "stop_sending",
<2> "error_code": error_code,
<3> "stream_id": str(stream_id),
<4> }
<5>
|
===========unchanged ref 0===========
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_retire_connection_id_frame(self, sequence_number: int) -> Dict:
return {
"frame_type": "retire_connection_id",
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_data_blocked_frame(self, limit: int, stream_id: int) -> Dict:
return {
"frame_type": "stream_data_blocked",
+ "limit": limit,
- "limit": str(limit),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 2===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_reset_stream_frame(
self, error_code: int, final_size: int, stream_id: int
) -> Dict:
return {
"error_code": error_code,
+ "final_size": final_size,
- "final_size": str(final_size),
"frame_type": "reset_stream",
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 3===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 4===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_max_stream_data_frame(self, maximum: int, stream_id: int) -> Dict:
return {
"frame_type": "max_stream_data",
+ "maximum": maximum,
- "maximum": str(maximum),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 5===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 6===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_new_connection_id_frame(
self,
connection_id: bytes,
retire_prior_to: int,
sequence_number: int,
stateless_reset_token: bytes,
) -> Dict:
return {
"connection_id": hexdump(connection_id),
"frame_type": "new_connection_id",
"length": len(connection_id),
"reset_token": hexdump(stateless_reset_token),
+ "retire_prior_to": retire_prior_to,
- "retire_prior_to": str(retire_prior_to),
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 7===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
return {
+ "ack_delay": self.encode_time(delay),
- "ack_delay": str(self.encode_time(delay)),
+ "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
- "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
"frame_type": "ack",
}
===========changed ref 8===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_connection_limit_frame(self, frame_type: int, maximum: int) -> Dict:
if frame_type == QuicFrameType.MAX_DATA:
+ return {"frame_type": "max_data", "maximum": maximum}
- return {"frame_type": "max_data", "maximum": str(maximum)}
else:
return {
"frame_type": "max_streams",
+ "maximum": maximum,
- "maximum": str(maximum),
"stream_type": "unidirectional"
if frame_type == QuicFrameType.MAX_STREAMS_UNI
else "bidirectional",
}
===========changed ref 9===========
# module: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
+ QLOG_VERSION = "0.3"
===========changed ref 10===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 11===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 12===========
# module: examples.interop
def test_spin_bit(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
for i in range(5):
await protocol.ping()
# check log
spin_bits = set()
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
+ if event["name"] == "connectivity:spin_bit_updated":
- if category == "connectivity" and event == "spin_bit_updated":
+ spin_bits.add(event["data"]["state"])
- spin_bits.add(data["state"])
if len(spin_bits) == 2:
server.result |= Result.P
|
aioquic.quic.logger/QuicLoggerTrace.encode_stream_frame
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<4>:<add> "offset": frame.offset,
<del> "offset": str(frame.offset),
<5>:<add> "stream_id": stream_id,
<del> "stream_id": str(stream_id),
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_frame(self, frame: QuicStreamFrame, stream_id: int) -> Dict:
<0> return {
<1> "fin": frame.fin,
<2> "frame_type": "stream",
<3> "length": len(frame.data),
<4> "offset": str(frame.offset),
<5> "stream_id": str(stream_id),
<6> }
<7>
|
===========unchanged ref 0===========
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stop_sending_frame(self, error_code: int, stream_id: int) -> Dict:
return {
"frame_type": "stop_sending",
"error_code": error_code,
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_retire_connection_id_frame(self, sequence_number: int) -> Dict:
return {
"frame_type": "retire_connection_id",
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 2===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_data_blocked_frame(self, limit: int, stream_id: int) -> Dict:
return {
"frame_type": "stream_data_blocked",
+ "limit": limit,
- "limit": str(limit),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 3===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_reset_stream_frame(
self, error_code: int, final_size: int, stream_id: int
) -> Dict:
return {
"error_code": error_code,
+ "final_size": final_size,
- "final_size": str(final_size),
"frame_type": "reset_stream",
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 4===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 5===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_max_stream_data_frame(self, maximum: int, stream_id: int) -> Dict:
return {
"frame_type": "max_stream_data",
+ "maximum": maximum,
- "maximum": str(maximum),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 6===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 7===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_new_connection_id_frame(
self,
connection_id: bytes,
retire_prior_to: int,
sequence_number: int,
stateless_reset_token: bytes,
) -> Dict:
return {
"connection_id": hexdump(connection_id),
"frame_type": "new_connection_id",
"length": len(connection_id),
"reset_token": hexdump(stateless_reset_token),
+ "retire_prior_to": retire_prior_to,
- "retire_prior_to": str(retire_prior_to),
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 8===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
return {
+ "ack_delay": self.encode_time(delay),
- "ack_delay": str(self.encode_time(delay)),
+ "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
- "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
"frame_type": "ack",
}
===========changed ref 9===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_connection_limit_frame(self, frame_type: int, maximum: int) -> Dict:
if frame_type == QuicFrameType.MAX_DATA:
+ return {"frame_type": "max_data", "maximum": maximum}
- return {"frame_type": "max_data", "maximum": str(maximum)}
else:
return {
"frame_type": "max_streams",
+ "maximum": maximum,
- "maximum": str(maximum),
"stream_type": "unidirectional"
if frame_type == QuicFrameType.MAX_STREAMS_UNI
else "bidirectional",
}
===========changed ref 10===========
# module: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
+ QLOG_VERSION = "0.3"
===========changed ref 11===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 12===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
===========changed ref 13===========
# module: examples.interop
def test_spin_bit(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
for i in range(5):
await protocol.ping()
# check log
spin_bits = set()
- for stamp, category, event, data in configuration.quic_logger.to_dict()[
- "traces"
- ][0]["events"]:
+ for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
+ if event["name"] == "connectivity:spin_bit_updated":
- if category == "connectivity" and event == "spin_bit_updated":
+ spin_bits.add(event["data"]["state"])
- spin_bits.add(data["state"])
if len(spin_bits) == 2:
server.result |= Result.P
|
aioquic.quic.logger/QuicLoggerTrace.encode_streams_blocked_frame
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<2>:<add> "limit": limit,
<del> "limit": str(limit),
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_streams_blocked_frame(self, is_unidirectional: bool, limit: int) -> Dict:
<0> return {
<1> "frame_type": "streams_blocked",
<2> "limit": str(limit),
<3> "stream_type": "unidirectional" if is_unidirectional else "bidirectional",
<4> }
<5>
|
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stop_sending_frame(self, error_code: int, stream_id: int) -> Dict:
return {
"frame_type": "stop_sending",
"error_code": error_code,
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_retire_connection_id_frame(self, sequence_number: int) -> Dict:
return {
"frame_type": "retire_connection_id",
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 2===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_data_blocked_frame(self, limit: int, stream_id: int) -> Dict:
return {
"frame_type": "stream_data_blocked",
+ "limit": limit,
- "limit": str(limit),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 3===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_frame(self, frame: QuicStreamFrame, stream_id: int) -> Dict:
return {
"fin": frame.fin,
"frame_type": "stream",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 4===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_reset_stream_frame(
self, error_code: int, final_size: int, stream_id: int
) -> Dict:
return {
"error_code": error_code,
+ "final_size": final_size,
- "final_size": str(final_size),
"frame_type": "reset_stream",
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 5===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 6===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_max_stream_data_frame(self, maximum: int, stream_id: int) -> Dict:
return {
"frame_type": "max_stream_data",
+ "maximum": maximum,
- "maximum": str(maximum),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 7===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 8===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_new_connection_id_frame(
self,
connection_id: bytes,
retire_prior_to: int,
sequence_number: int,
stateless_reset_token: bytes,
) -> Dict:
return {
"connection_id": hexdump(connection_id),
"frame_type": "new_connection_id",
"length": len(connection_id),
"reset_token": hexdump(stateless_reset_token),
+ "retire_prior_to": retire_prior_to,
- "retire_prior_to": str(retire_prior_to),
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 9===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
return {
+ "ack_delay": self.encode_time(delay),
- "ack_delay": str(self.encode_time(delay)),
+ "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
- "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
"frame_type": "ack",
}
===========changed ref 10===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_connection_limit_frame(self, frame_type: int, maximum: int) -> Dict:
if frame_type == QuicFrameType.MAX_DATA:
+ return {"frame_type": "max_data", "maximum": maximum}
- return {"frame_type": "max_data", "maximum": str(maximum)}
else:
return {
"frame_type": "max_streams",
+ "maximum": maximum,
- "maximum": str(maximum),
"stream_type": "unidirectional"
if frame_type == QuicFrameType.MAX_STREAMS_UNI
else "bidirectional",
}
===========changed ref 11===========
# module: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
+ QLOG_VERSION = "0.3"
===========changed ref 12===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 13===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
|
aioquic.quic.logger/QuicLoggerTrace.encode_time
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<1>:<add> Convert a time to milliseconds.
<del> Convert a time to integer microseconds.
<3>:<add> return seconds * 1000
<del> return int(seconds * 1000000)
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def encode_time(self, seconds: float) -> float:
- def encode_time(self, seconds: float) -> int:
<0> """
<1> Convert a time to integer microseconds.
<2> """
<3> return int(seconds * 1000000)
<4>
|
===========unchanged ref 0===========
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_streams_blocked_frame(self, is_unidirectional: bool, limit: int) -> Dict:
return {
"frame_type": "streams_blocked",
+ "limit": limit,
- "limit": str(limit),
"stream_type": "unidirectional" if is_unidirectional else "bidirectional",
}
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stop_sending_frame(self, error_code: int, stream_id: int) -> Dict:
return {
"frame_type": "stop_sending",
"error_code": error_code,
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 2===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_retire_connection_id_frame(self, sequence_number: int) -> Dict:
return {
"frame_type": "retire_connection_id",
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 3===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_data_blocked_frame(self, limit: int, stream_id: int) -> Dict:
return {
"frame_type": "stream_data_blocked",
+ "limit": limit,
- "limit": str(limit),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 4===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_frame(self, frame: QuicStreamFrame, stream_id: int) -> Dict:
return {
"fin": frame.fin,
"frame_type": "stream",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 5===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_reset_stream_frame(
self, error_code: int, final_size: int, stream_id: int
) -> Dict:
return {
"error_code": error_code,
+ "final_size": final_size,
- "final_size": str(final_size),
"frame_type": "reset_stream",
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 6===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 7===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_max_stream_data_frame(self, maximum: int, stream_id: int) -> Dict:
return {
"frame_type": "max_stream_data",
+ "maximum": maximum,
- "maximum": str(maximum),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 8===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 9===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_new_connection_id_frame(
self,
connection_id: bytes,
retire_prior_to: int,
sequence_number: int,
stateless_reset_token: bytes,
) -> Dict:
return {
"connection_id": hexdump(connection_id),
"frame_type": "new_connection_id",
"length": len(connection_id),
"reset_token": hexdump(stateless_reset_token),
+ "retire_prior_to": retire_prior_to,
- "retire_prior_to": str(retire_prior_to),
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 10===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
return {
+ "ack_delay": self.encode_time(delay),
- "ack_delay": str(self.encode_time(delay)),
+ "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
- "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
"frame_type": "ack",
}
===========changed ref 11===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_connection_limit_frame(self, frame_type: int, maximum: int) -> Dict:
if frame_type == QuicFrameType.MAX_DATA:
+ return {"frame_type": "max_data", "maximum": maximum}
- return {"frame_type": "max_data", "maximum": str(maximum)}
else:
return {
"frame_type": "max_streams",
+ "maximum": maximum,
- "maximum": str(maximum),
"stream_type": "unidirectional"
if frame_type == QuicFrameType.MAX_STREAMS_UNI
else "bidirectional",
}
===========changed ref 12===========
# module: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
+ QLOG_VERSION = "0.3"
===========changed ref 13===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
===========changed ref 14===========
# module: tests.test_logger
SINGLE_TRACE = {
+ "qlog_format": "JSON",
+ "qlog_version": "0.3",
- "qlog_version": "draft-01",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
- "reference_time": "0",
},
- "configuration": {"time_units": "us"},
- "event_fields": [
- "relative_time",
- "category",
- "event_type",
- "data",
- ],
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
|
aioquic.quic.logger/QuicLoggerTrace.log_event
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<0>:<add> self._events.append(
<add> {
<add> "data": data,
<add> "name": category + ":" + event,
<add> "time": self.encode_time(time.time()),
<add> }
<add> )
<del> self._events.append((time.time(), category, event, data))
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # CORE
+
def log_event(self, *, category: str, event: str, data: Dict) -> None:
<0> self._events.append((time.time(), category, event, data))
<1>
|
===========unchanged ref 0===========
at: aioquic.quic.logger.QuicLoggerTrace.encode_transport_parameters
data: Dict[str, Any] = {"owner": owner}
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def encode_time(self, seconds: float) -> float:
- def encode_time(self, seconds: float) -> int:
"""
+ Convert a time to milliseconds.
- Convert a time to integer microseconds.
"""
+ return seconds * 1000
- return int(seconds * 1000000)
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_streams_blocked_frame(self, is_unidirectional: bool, limit: int) -> Dict:
return {
"frame_type": "streams_blocked",
+ "limit": limit,
- "limit": str(limit),
"stream_type": "unidirectional" if is_unidirectional else "bidirectional",
}
===========changed ref 2===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stop_sending_frame(self, error_code: int, stream_id: int) -> Dict:
return {
"frame_type": "stop_sending",
"error_code": error_code,
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 3===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_retire_connection_id_frame(self, sequence_number: int) -> Dict:
return {
"frame_type": "retire_connection_id",
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 4===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_data_blocked_frame(self, limit: int, stream_id: int) -> Dict:
return {
"frame_type": "stream_data_blocked",
+ "limit": limit,
- "limit": str(limit),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 5===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_frame(self, frame: QuicStreamFrame, stream_id: int) -> Dict:
return {
"fin": frame.fin,
"frame_type": "stream",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 6===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_reset_stream_frame(
self, error_code: int, final_size: int, stream_id: int
) -> Dict:
return {
"error_code": error_code,
+ "final_size": final_size,
- "final_size": str(final_size),
"frame_type": "reset_stream",
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 7===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 8===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_max_stream_data_frame(self, maximum: int, stream_id: int) -> Dict:
return {
"frame_type": "max_stream_data",
+ "maximum": maximum,
- "maximum": str(maximum),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 9===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 10===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_new_connection_id_frame(
self,
connection_id: bytes,
retire_prior_to: int,
sequence_number: int,
stateless_reset_token: bytes,
) -> Dict:
return {
"connection_id": hexdump(connection_id),
"frame_type": "new_connection_id",
"length": len(connection_id),
"reset_token": hexdump(stateless_reset_token),
+ "retire_prior_to": retire_prior_to,
- "retire_prior_to": str(retire_prior_to),
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 11===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
return {
+ "ack_delay": self.encode_time(delay),
- "ack_delay": str(self.encode_time(delay)),
+ "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
- "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
"frame_type": "ack",
}
===========changed ref 12===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_connection_limit_frame(self, frame_type: int, maximum: int) -> Dict:
if frame_type == QuicFrameType.MAX_DATA:
+ return {"frame_type": "max_data", "maximum": maximum}
- return {"frame_type": "max_data", "maximum": str(maximum)}
else:
return {
"frame_type": "max_streams",
+ "maximum": maximum,
- "maximum": str(maximum),
"stream_type": "unidirectional"
if frame_type == QuicFrameType.MAX_STREAMS_UNI
else "bidirectional",
}
===========changed ref 13===========
# module: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
+ QLOG_VERSION = "0.3"
===========changed ref 14===========
# module: tests.test_logger
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
+ self.assertEqual(
+ logger.to_dict(),
+ {"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
+ )
- self.assertEqual(logger.to_dict(), {"qlog_version": "draft-01", "traces": []})
|
aioquic.quic.logger/QuicLoggerTrace.to_dict
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<3>:<del> if self._events:
<4>:<del> reference_time = self._events[0][0]
<5>:<del> else:
<6>:<del> reference_time = 0.0
<8>:<del> "configuration": {"time_units": "us"},
<11>:<del> "reference_time": str(self.encode_time(reference_time)),
<13>:<del> "event_fields": ["relative_time", "category", "event_type", "data"],
<14>:<add> "events": list(self._events),
<del> "events": list(
<15>:<del> map(
<16>:<del> lambda event: (
<17>:<del> str(self.encode_time(event[0] - reference_time)),
<18>:<del> event[1],
<19>:<del> event[2],
<20>:<del> event[3],
<21>:<del> ),
<22>:<del> self._events,
<23>:<del> )
<24>:<del> ),
|
# module: aioquic.quic.logger
class QuicLoggerTrace:
def to_dict(self) -> Dict[str, Any]:
<0> """
<1> Return the trace as a dictionary which can be written as JSON.
<2> """
<3> if self._events:
<4> reference_time = self._events[0][0]
<5> else:
<6> reference_time = 0.0
<7> return {
<8> "configuration": {"time_units": "us"},
<9> "common_fields": {
<10> "ODCID": hexdump(self._odcid),
<11> "reference_time": str(self.encode_time(reference_time)),
<12> },
<13> "event_fields": ["relative_time", "category", "event_type", "data"],
<14> "events": list(
<15> map(
<16> lambda event: (
<17> str(self.encode_time(event[0] - reference_time)),
<18> event[1],
<19> event[2],
<20> event[3],
<21> ),
<22> self._events,
<23> )
<24> ),
<25> "vantage_point": self._vantage_point,
<26> }
<27>
|
===========unchanged ref 0===========
at: aioquic.quic.logger
PACKET_TYPE_NAMES = {
PACKET_TYPE_INITIAL: "initial",
PACKET_TYPE_HANDSHAKE: "handshake",
PACKET_TYPE_ZERO_RTT: "0RTT",
PACKET_TYPE_ONE_RTT: "1RTT",
PACKET_TYPE_RETRY: "retry",
}
at: aioquic.quic.logger.QuicLoggerTrace
_encode_http3_headers(headers: Headers) -> List[Dict]
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
at: typing.Mapping
get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]
get(key: _KT) -> Optional[_VT_co]
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def encode_time(self, seconds: float) -> float:
- def encode_time(self, seconds: float) -> int:
"""
+ Convert a time to milliseconds.
- Convert a time to integer microseconds.
"""
+ return seconds * 1000
- return int(seconds * 1000000)
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # CORE
+
def log_event(self, *, category: str, event: str, data: Dict) -> None:
+ self._events.append(
+ {
+ "data": data,
+ "name": category + ":" + event,
+ "time": self.encode_time(time.time()),
+ }
+ )
- self._events.append((time.time(), category, event, data))
===========changed ref 2===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_streams_blocked_frame(self, is_unidirectional: bool, limit: int) -> Dict:
return {
"frame_type": "streams_blocked",
+ "limit": limit,
- "limit": str(limit),
"stream_type": "unidirectional" if is_unidirectional else "bidirectional",
}
===========changed ref 3===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stop_sending_frame(self, error_code: int, stream_id: int) -> Dict:
return {
"frame_type": "stop_sending",
"error_code": error_code,
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 4===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_retire_connection_id_frame(self, sequence_number: int) -> Dict:
return {
"frame_type": "retire_connection_id",
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 5===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_data_blocked_frame(self, limit: int, stream_id: int) -> Dict:
return {
"frame_type": "stream_data_blocked",
+ "limit": limit,
- "limit": str(limit),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 6===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_frame(self, frame: QuicStreamFrame, stream_id: int) -> Dict:
return {
"fin": frame.fin,
"frame_type": "stream",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 7===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_reset_stream_frame(
self, error_code: int, final_size: int, stream_id: int
) -> Dict:
return {
"error_code": error_code,
+ "final_size": final_size,
- "final_size": str(final_size),
"frame_type": "reset_stream",
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 8===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 9===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_max_stream_data_frame(self, maximum: int, stream_id: int) -> Dict:
return {
"frame_type": "max_stream_data",
+ "maximum": maximum,
- "maximum": str(maximum),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 10===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 11===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_new_connection_id_frame(
self,
connection_id: bytes,
retire_prior_to: int,
sequence_number: int,
stateless_reset_token: bytes,
) -> Dict:
return {
"connection_id": hexdump(connection_id),
"frame_type": "new_connection_id",
"length": len(connection_id),
"reset_token": hexdump(stateless_reset_token),
+ "retire_prior_to": retire_prior_to,
- "retire_prior_to": str(retire_prior_to),
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 12===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # QUIC
+
def encode_ack_frame(self, ranges: RangeSet, delay: float) -> Dict:
return {
+ "ack_delay": self.encode_time(delay),
- "ack_delay": str(self.encode_time(delay)),
+ "acked_ranges": [[x.start, x.stop - 1] for x in ranges],
- "acked_ranges": [[str(x.start), str(x.stop - 1)] for x in ranges],
"frame_type": "ack",
}
===========changed ref 13===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_connection_limit_frame(self, frame_type: int, maximum: int) -> Dict:
if frame_type == QuicFrameType.MAX_DATA:
+ return {"frame_type": "max_data", "maximum": maximum}
- return {"frame_type": "max_data", "maximum": str(maximum)}
else:
return {
"frame_type": "max_streams",
+ "maximum": maximum,
- "maximum": str(maximum),
"stream_type": "unidirectional"
if frame_type == QuicFrameType.MAX_STREAMS_UNI
else "bidirectional",
}
|
aioquic.quic.logger/QuicLogger.to_dict
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<4>:<add> "qlog_format": "JSON",
<add> "qlog_version": QLOG_VERSION,
<del> "qlog_version": "draft-01",
|
# module: aioquic.quic.logger
class QuicLogger:
def to_dict(self) -> Dict[str, Any]:
<0> """
<1> Return the traces as a dictionary which can be written as JSON.
<2> """
<3> return {
<4> "qlog_version": "draft-01",
<5> "traces": [trace.to_dict() for trace in self._traces],
<6> }
<7>
|
===========unchanged ref 0===========
at: aioquic.quic.logger.QuicLoggerTrace
encode_time(seconds: float) -> float
at: time
time() -> float
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def encode_time(self, seconds: float) -> float:
- def encode_time(self, seconds: float) -> int:
"""
+ Convert a time to milliseconds.
- Convert a time to integer microseconds.
"""
+ return seconds * 1000
- return int(seconds * 1000000)
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def _encode_http3_headers(self, headers: Headers) -> List[Dict]:
+ return [
+ {"name": h[0].decode("utf8"), "value": h[1].decode("utf8")} for h in headers
+ ]
+
===========changed ref 2===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # HTTP/3
+
+ def encode_http3_data_frame(self, length: int, stream_id: int) -> Dict:
+ return {
+ "frame": {"frame_type": "data"},
+ "length": length,
+ "stream_id": stream_id,
+ }
+
===========changed ref 3===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def encode_http3_push_promise_frame(
+ self, length: int, headers: Headers, push_id: int, stream_id: int
+ ) -> Dict:
+ return {
+ "frame": {
+ "frame_type": "push_promise",
+ "headers": self._encode_http3_headers(headers),
+ "push_id": push_id,
+ },
+ "length": length,
+ "stream_id": stream_id,
+ }
+
===========changed ref 4===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def encode_http3_headers_frame(
+ self, length: int, headers: Headers, stream_id: int
+ ) -> Dict:
+ return {
+ "frame": {
+ "frame_type": "headers",
+ "headers": self._encode_http3_headers(headers),
+ },
+ "length": length,
+ "stream_id": stream_id,
+ }
+
===========changed ref 5===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # CORE
+
def log_event(self, *, category: str, event: str, data: Dict) -> None:
+ self._events.append(
+ {
+ "data": data,
+ "name": category + ":" + event,
+ "time": self.encode_time(time.time()),
+ }
+ )
- self._events.append((time.time(), category, event, data))
===========changed ref 6===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_streams_blocked_frame(self, is_unidirectional: bool, limit: int) -> Dict:
return {
"frame_type": "streams_blocked",
+ "limit": limit,
- "limit": str(limit),
"stream_type": "unidirectional" if is_unidirectional else "bidirectional",
}
===========changed ref 7===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stop_sending_frame(self, error_code: int, stream_id: int) -> Dict:
return {
"frame_type": "stop_sending",
"error_code": error_code,
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 8===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_retire_connection_id_frame(self, sequence_number: int) -> Dict:
return {
"frame_type": "retire_connection_id",
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 9===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_data_blocked_frame(self, limit: int, stream_id: int) -> Dict:
return {
"frame_type": "stream_data_blocked",
+ "limit": limit,
- "limit": str(limit),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 10===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_frame(self, frame: QuicStreamFrame, stream_id: int) -> Dict:
return {
"fin": frame.fin,
"frame_type": "stream",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 11===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_reset_stream_frame(
self, error_code: int, final_size: int, stream_id: int
) -> Dict:
return {
"error_code": error_code,
+ "final_size": final_size,
- "final_size": str(final_size),
"frame_type": "reset_stream",
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 12===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 13===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_max_stream_data_frame(self, maximum: int, stream_id: int) -> Dict:
return {
"frame_type": "max_stream_data",
+ "maximum": maximum,
- "maximum": str(maximum),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 14===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 15===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_new_connection_id_frame(
self,
connection_id: bytes,
retire_prior_to: int,
sequence_number: int,
stateless_reset_token: bytes,
) -> Dict:
return {
"connection_id": hexdump(connection_id),
"frame_type": "new_connection_id",
"length": len(connection_id),
"reset_token": hexdump(stateless_reset_token),
+ "retire_prior_to": retire_prior_to,
- "retire_prior_to": str(retire_prior_to),
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
|
aioquic.quic.logger/QuicFileLogger.end_trace
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<5>:<add> json.dump(
<add> {
<add> "qlog_format": "JSON",
<add> "qlog_version": QLOG_VERSION,
<add> "traces": [trace_dict],
<add> },
<add> logger_fp,
<add> )
<del> json.dump({"qlog_version": "draft-01", "traces": [trace_dict]}, logger_fp)
|
# module: aioquic.quic.logger
class QuicFileLogger(QuicLogger):
def end_trace(self, trace: QuicLoggerTrace) -> None:
<0> trace_dict = trace.to_dict()
<1> trace_path = os.path.join(
<2> self.path, trace_dict["common_fields"]["ODCID"] + ".qlog"
<3> )
<4> with open(trace_path, "w") as logger_fp:
<5> json.dump({"qlog_version": "draft-01", "traces": [trace_dict]}, logger_fp)
<6> self._traces.remove(trace)
<7>
|
===========changed ref 0===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def _encode_http3_headers(self, headers: Headers) -> List[Dict]:
+ return [
+ {"name": h[0].decode("utf8"), "value": h[1].decode("utf8")} for h in headers
+ ]
+
===========changed ref 1===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # HTTP/3
+
+ def encode_http3_data_frame(self, length: int, stream_id: int) -> Dict:
+ return {
+ "frame": {"frame_type": "data"},
+ "length": length,
+ "stream_id": stream_id,
+ }
+
===========changed ref 2===========
# module: aioquic.quic.logger
class QuicLogger:
def to_dict(self) -> Dict[str, Any]:
"""
Return the traces as a dictionary which can be written as JSON.
"""
return {
+ "qlog_format": "JSON",
+ "qlog_version": QLOG_VERSION,
- "qlog_version": "draft-01",
"traces": [trace.to_dict() for trace in self._traces],
}
===========changed ref 3===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def encode_http3_push_promise_frame(
+ self, length: int, headers: Headers, push_id: int, stream_id: int
+ ) -> Dict:
+ return {
+ "frame": {
+ "frame_type": "push_promise",
+ "headers": self._encode_http3_headers(headers),
+ "push_id": push_id,
+ },
+ "length": length,
+ "stream_id": stream_id,
+ }
+
===========changed ref 4===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def encode_http3_headers_frame(
+ self, length: int, headers: Headers, stream_id: int
+ ) -> Dict:
+ return {
+ "frame": {
+ "frame_type": "headers",
+ "headers": self._encode_http3_headers(headers),
+ },
+ "length": length,
+ "stream_id": stream_id,
+ }
+
===========changed ref 5===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def encode_time(self, seconds: float) -> float:
- def encode_time(self, seconds: float) -> int:
"""
+ Convert a time to milliseconds.
- Convert a time to integer microseconds.
"""
+ return seconds * 1000
- return int(seconds * 1000000)
===========changed ref 6===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # CORE
+
def log_event(self, *, category: str, event: str, data: Dict) -> None:
+ self._events.append(
+ {
+ "data": data,
+ "name": category + ":" + event,
+ "time": self.encode_time(time.time()),
+ }
+ )
- self._events.append((time.time(), category, event, data))
===========changed ref 7===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_streams_blocked_frame(self, is_unidirectional: bool, limit: int) -> Dict:
return {
"frame_type": "streams_blocked",
+ "limit": limit,
- "limit": str(limit),
"stream_type": "unidirectional" if is_unidirectional else "bidirectional",
}
===========changed ref 8===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stop_sending_frame(self, error_code: int, stream_id: int) -> Dict:
return {
"frame_type": "stop_sending",
"error_code": error_code,
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 9===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_retire_connection_id_frame(self, sequence_number: int) -> Dict:
return {
"frame_type": "retire_connection_id",
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 10===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_data_blocked_frame(self, limit: int, stream_id: int) -> Dict:
return {
"frame_type": "stream_data_blocked",
+ "limit": limit,
- "limit": str(limit),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 11===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_frame(self, frame: QuicStreamFrame, stream_id: int) -> Dict:
return {
"fin": frame.fin,
"frame_type": "stream",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 12===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_reset_stream_frame(
self, error_code: int, final_size: int, stream_id: int
) -> Dict:
return {
"error_code": error_code,
+ "final_size": final_size,
- "final_size": str(final_size),
"frame_type": "reset_stream",
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 13===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 14===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_max_stream_data_frame(self, maximum: int, stream_id: int) -> Dict:
return {
"frame_type": "max_stream_data",
+ "maximum": maximum,
- "maximum": str(maximum),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 15===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 16===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_new_connection_id_frame(
self,
connection_id: bytes,
retire_prior_to: int,
sequence_number: int,
stateless_reset_token: bytes,
) -> Dict:
return {
"connection_id": hexdump(connection_id),
"frame_type": "new_connection_id",
"length": len(connection_id),
"reset_token": hexdump(stateless_reset_token),
+ "retire_prior_to": retire_prior_to,
- "retire_prior_to": str(retire_prior_to),
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
|
aioquic.h3.connection/H3Connection.send_data
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<21>:<add> data=self._quic_logger.encode_http3_data_frame(
<add> length=len(data), stream_id=stream_id
<add> ),
<del> data=qlog_encode_data_frame(byte_length=len(data), stream_id=stream_id),
|
# module: aioquic.h3.connection
class H3Connection:
def send_data(self, stream_id: int, data: bytes, end_stream: bool) -> None:
<0> """
<1> Send data on the given stream.
<2>
<3> To retrieve datagram which need to be sent over the network call the QUIC
<4> connection's :meth:`~aioquic.connection.QuicConnection.datagrams_to_send`
<5> method.
<6>
<7> :param stream_id: The stream ID on which to send the data.
<8> :param data: The data to send.
<9> :param end_stream: Whether to end the stream.
<10> """
<11> # check DATA frame is allowed
<12> stream = self._get_or_create_stream(stream_id)
<13> if stream.headers_send_state != HeadersState.AFTER_HEADERS:
<14> raise FrameUnexpected("DATA frame is not allowed in this state")
<15>
<16> # log frame
<17> if self._quic_logger is not None:
<18> self._quic_logger.log_event(
<19> category="http",
<20> event="frame_created",
<21> data=qlog_encode_data_frame(byte_length=len(data), stream_id=stream_id),
<22> )
<23>
<24> self._quic.send_stream_data(
<25> stream_id, encode_frame(FrameType.DATA, data), end_stream
<26> )
<27>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
HeadersState()
FrameUnexpected(reason_phrase: str="")
at: aioquic.h3.connection.H3Connection
_encode_headers(stream_id: int, headers: Headers) -> bytes
_encode_headers(self, stream_id: int, headers: Headers) -> bytes
_get_or_create_stream(stream_id: int) -> H3Stream
at: aioquic.h3.connection.H3Connection.__init__
self._quic_logger: Optional[QuicLoggerTrace] = quic._quic_logger
at: aioquic.h3.connection.H3Stream.__init__
self.headers_send_state: HeadersState = HeadersState.INITIAL
===========changed ref 0===========
# module: aioquic.h3.connection
- def qlog_encode_headers(headers: Headers) -> List[Dict]:
- return [
- {"name": h[0].decode("utf8"), "value": h[1].decode("utf8")} for h in headers
- ]
-
===========changed ref 1===========
# module: aioquic.h3.connection
- def qlog_encode_headers_frame(
- byte_length: int, headers: Headers, stream_id: int
- ) -> Dict:
- return {
- "byte_length": str(byte_length),
- "frame": {"frame_type": "headers", "headers": qlog_encode_headers(headers)},
- "stream_id": str(stream_id),
- }
-
===========changed ref 2===========
# module: aioquic.h3.connection
- def qlog_encode_data_frame(byte_length: int, stream_id: int) -> Dict:
- return {
- "byte_length": str(byte_length),
- "frame": {"frame_type": "data"},
- "stream_id": str(stream_id),
- }
-
===========changed ref 3===========
# module: aioquic.h3.connection
- def qlog_encode_push_promise_frame(
- byte_length: int, headers: Headers, push_id: int, stream_id: int
- ) -> Dict:
- return {
- "byte_length": str(byte_length),
- "frame": {
- "frame_type": "push_promise",
- "headers": qlog_encode_headers(headers),
- "push_id": str(push_id),
- },
- "stream_id": str(stream_id),
- }
-
===========changed ref 4===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 5===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def _encode_http3_headers(self, headers: Headers) -> List[Dict]:
+ return [
+ {"name": h[0].decode("utf8"), "value": h[1].decode("utf8")} for h in headers
+ ]
+
===========changed ref 6===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # HTTP/3
+
+ def encode_http3_data_frame(self, length: int, stream_id: int) -> Dict:
+ return {
+ "frame": {"frame_type": "data"},
+ "length": length,
+ "stream_id": stream_id,
+ }
+
===========changed ref 7===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def encode_time(self, seconds: float) -> float:
- def encode_time(self, seconds: float) -> int:
"""
+ Convert a time to milliseconds.
- Convert a time to integer microseconds.
"""
+ return seconds * 1000
- return int(seconds * 1000000)
===========changed ref 8===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_retire_connection_id_frame(self, sequence_number: int) -> Dict:
return {
"frame_type": "retire_connection_id",
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 9===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 10===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stop_sending_frame(self, error_code: int, stream_id: int) -> Dict:
return {
"frame_type": "stop_sending",
"error_code": error_code,
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 11===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_streams_blocked_frame(self, is_unidirectional: bool, limit: int) -> Dict:
return {
"frame_type": "streams_blocked",
+ "limit": limit,
- "limit": str(limit),
"stream_type": "unidirectional" if is_unidirectional else "bidirectional",
}
===========changed ref 12===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def encode_http3_headers_frame(
+ self, length: int, headers: Headers, stream_id: int
+ ) -> Dict:
+ return {
+ "frame": {
+ "frame_type": "headers",
+ "headers": self._encode_http3_headers(headers),
+ },
+ "length": length,
+ "stream_id": stream_id,
+ }
+
===========changed ref 13===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stream_data_blocked_frame(self, limit: int, stream_id: int) -> Dict:
return {
"frame_type": "stream_data_blocked",
+ "limit": limit,
- "limit": str(limit),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 14===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_max_stream_data_frame(self, maximum: int, stream_id: int) -> Dict:
return {
"frame_type": "max_stream_data",
+ "maximum": maximum,
- "maximum": str(maximum),
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 15===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # CORE
+
def log_event(self, *, category: str, event: str, data: Dict) -> None:
+ self._events.append(
+ {
+ "data": data,
+ "name": category + ":" + event,
+ "time": self.encode_time(time.time()),
+ }
+ )
- self._events.append((time.time(), category, event, data))
===========changed ref 16===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def encode_http3_push_promise_frame(
+ self, length: int, headers: Headers, push_id: int, stream_id: int
+ ) -> Dict:
+ return {
+ "frame": {
+ "frame_type": "push_promise",
+ "headers": self._encode_http3_headers(headers),
+ "push_id": push_id,
+ },
+ "length": length,
+ "stream_id": stream_id,
+ }
+
|
aioquic.h3.connection/H3Connection.send_headers
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<23>:<add> data=self._quic_logger.encode_http3_headers_frame(
<del> data=qlog_encode_headers_frame(
<24>:<add> length=len(frame_data), headers=headers, stream_id=stream_id
<del> byte_length=len(frame_data), headers=headers, stream_id=stream_id
|
# module: aioquic.h3.connection
class H3Connection:
def send_headers(
self, stream_id: int, headers: Headers, end_stream: bool = False
) -> None:
<0> """
<1> Send headers on the given stream.
<2>
<3> To retrieve datagram which need to be sent over the network call the QUIC
<4> connection's :meth:`~aioquic.connection.QuicConnection.datagrams_to_send`
<5> method.
<6>
<7> :param stream_id: The stream ID on which to send the headers.
<8> :param headers: The HTTP headers to send.
<9> :param end_stream: Whether to end the stream.
<10> """
<11> # check HEADERS frame is allowed
<12> stream = self._get_or_create_stream(stream_id)
<13> if stream.headers_send_state == HeadersState.AFTER_TRAILERS:
<14> raise FrameUnexpected("HEADERS frame is not allowed in this state")
<15>
<16> frame_data = self._encode_headers(stream_id, headers)
<17>
<18> # log frame
<19> if self._quic_logger is not None:
<20> self._quic_logger.log_event(
<21> category="http",
<22> event="frame_created",
<23> data=qlog_encode_headers_frame(
<24> byte_length=len(frame_data), headers=headers, stream_id=stream_id
<25> ),
<26> )
<27>
<28> # update state and send headers
<29> if stream.headers_send_state == HeadersState.INITIAL:
<30> stream.headers_send_state = HeadersState.AFTER_HEADERS
<31> else:
<32> stream.headers_send_state = HeadersState.AFTER_TRAILERS
<33> self._quic.send_stream_data(
<34> stream_id, encode_frame(FrameType.HEADERS, frame_data), end_stream
<35> )
<36>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
FrameType(x: Union[str, bytes, bytearray], base: int)
FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QpackDecompressionFailed(reason_phrase: str="")
encode_frame(frame_type: int, frame_data: bytes) -> bytes
at: aioquic.h3.connection.H3Connection.__init__
self._quic = quic
self._decoder = pylsqpack.Decoder(
self._max_table_capacity, self._blocked_streams
)
self._decoder_bytes_sent = 0
self._encoder = pylsqpack.Encoder()
self._encoder_bytes_sent = 0
self._local_decoder_stream_id: Optional[int] = None
self._local_encoder_stream_id: Optional[int] = None
at: aioquic.h3.connection.H3Connection._init_connection
self._local_encoder_stream_id = self._create_uni_stream(
StreamType.QPACK_ENCODER
)
self._local_decoder_stream_id = self._create_uni_stream(
StreamType.QPACK_DECODER
)
at: aioquic.h3.connection.H3Connection.send_headers
frame_data = self._encode_headers(stream_id, headers)
at: tests.test_h3.FakeQuicConnection
get_next_available_stream_id(is_unidirectional=False)
send_stream_data(stream_id, data, end_stream=False)
===========changed ref 0===========
# module: aioquic.h3.connection
class H3Connection:
def send_data(self, stream_id: int, data: bytes, end_stream: bool) -> None:
"""
Send data on the given stream.
To retrieve datagram which need to be sent over the network call the QUIC
connection's :meth:`~aioquic.connection.QuicConnection.datagrams_to_send`
method.
:param stream_id: The stream ID on which to send the data.
:param data: The data to send.
:param end_stream: Whether to end the stream.
"""
# check DATA frame is allowed
stream = self._get_or_create_stream(stream_id)
if stream.headers_send_state != HeadersState.AFTER_HEADERS:
raise FrameUnexpected("DATA frame is not allowed in this state")
# log frame
if self._quic_logger is not None:
self._quic_logger.log_event(
category="http",
event="frame_created",
+ data=self._quic_logger.encode_http3_data_frame(
+ length=len(data), stream_id=stream_id
+ ),
- data=qlog_encode_data_frame(byte_length=len(data), stream_id=stream_id),
)
self._quic.send_stream_data(
stream_id, encode_frame(FrameType.DATA, data), end_stream
)
===========changed ref 1===========
# module: aioquic.h3.connection
- def qlog_encode_headers(headers: Headers) -> List[Dict]:
- return [
- {"name": h[0].decode("utf8"), "value": h[1].decode("utf8")} for h in headers
- ]
-
===========changed ref 2===========
# module: aioquic.h3.connection
- def qlog_encode_headers_frame(
- byte_length: int, headers: Headers, stream_id: int
- ) -> Dict:
- return {
- "byte_length": str(byte_length),
- "frame": {"frame_type": "headers", "headers": qlog_encode_headers(headers)},
- "stream_id": str(stream_id),
- }
-
===========changed ref 3===========
# module: aioquic.h3.connection
- def qlog_encode_data_frame(byte_length: int, stream_id: int) -> Dict:
- return {
- "byte_length": str(byte_length),
- "frame": {"frame_type": "data"},
- "stream_id": str(stream_id),
- }
-
===========changed ref 4===========
# module: aioquic.h3.connection
- def qlog_encode_push_promise_frame(
- byte_length: int, headers: Headers, push_id: int, stream_id: int
- ) -> Dict:
- return {
- "byte_length": str(byte_length),
- "frame": {
- "frame_type": "push_promise",
- "headers": qlog_encode_headers(headers),
- "push_id": str(push_id),
- },
- "stream_id": str(stream_id),
- }
-
===========changed ref 5===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_data_blocked_frame(self, limit: int) -> Dict:
+ return {"frame_type": "data_blocked", "limit": limit}
- return {"frame_type": "data_blocked", "limit": str(limit)}
===========changed ref 6===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def _encode_http3_headers(self, headers: Headers) -> List[Dict]:
+ return [
+ {"name": h[0].decode("utf8"), "value": h[1].decode("utf8")} for h in headers
+ ]
+
===========changed ref 7===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ # HTTP/3
+
+ def encode_http3_data_frame(self, length: int, stream_id: int) -> Dict:
+ return {
+ "frame": {"frame_type": "data"},
+ "length": length,
+ "stream_id": stream_id,
+ }
+
===========changed ref 8===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
+ def encode_time(self, seconds: float) -> float:
- def encode_time(self, seconds: float) -> int:
"""
+ Convert a time to milliseconds.
- Convert a time to integer microseconds.
"""
+ return seconds * 1000
- return int(seconds * 1000000)
===========changed ref 9===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_retire_connection_id_frame(self, sequence_number: int) -> Dict:
return {
"frame_type": "retire_connection_id",
+ "sequence_number": sequence_number,
- "sequence_number": str(sequence_number),
}
===========changed ref 10===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_crypto_frame(self, frame: QuicStreamFrame) -> Dict:
return {
"frame_type": "crypto",
"length": len(frame.data),
+ "offset": frame.offset,
- "offset": str(frame.offset),
}
===========changed ref 11===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_stop_sending_frame(self, error_code: int, stream_id: int) -> Dict:
return {
"frame_type": "stop_sending",
"error_code": error_code,
+ "stream_id": stream_id,
- "stream_id": str(stream_id),
}
===========changed ref 12===========
# module: aioquic.quic.logger
class QuicLoggerTrace:
def encode_streams_blocked_frame(self, is_unidirectional: bool, limit: int) -> Dict:
return {
"frame_type": "streams_blocked",
+ "limit": limit,
- "limit": str(limit),
"stream_type": "unidirectional" if is_unidirectional else "bidirectional",
}
|
aioquic.h3.connection/H3Connection._handle_request_or_push_frame
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
<41>:<add> data=self._quic_logger.encode_http3_headers_frame(
<del> data=qlog_encode_headers_frame(
<42>:<add> length=stream.blocked_frame_size
<del> byte_length=stream
|
# module: aioquic.h3.connection
class H3Connection:
def _handle_request_or_push_frame(
self,
frame_type: int,
frame_data: Optional[bytes],
stream: H3Stream,
stream_ended: bool,
) -> List[H3Event]:
<0> """
<1> Handle a frame received on a request or push stream.
<2> """
<3> http_events: List[H3Event] = []
<4>
<5> if frame_type == FrameType.DATA:
<6> # check DATA frame is allowed
<7> if stream.headers_recv_state != HeadersState.AFTER_HEADERS:
<8> raise FrameUnexpected("DATA frame is not allowed in this state")
<9>
<10> if stream_ended or frame_data:
<11> http_events.append(
<12> DataReceived(
<13> data=frame_data,
<14> push_id=stream.push_id,
<15> stream_ended=stream_ended,
<16> stream_id=stream.stream_id,
<17> )
<18> )
<19> elif frame_type == FrameType.HEADERS:
<20> # check HEADERS frame is allowed
<21> if stream.headers_recv_state == HeadersState.AFTER_TRAILERS:
<22> raise FrameUnexpected("HEADERS frame is not allowed in this state")
<23>
<24> # try to decode HEADERS, may raise pylsqpack.StreamBlocked
<25> headers = self._decode_headers(stream.stream_id, frame_data)
<26>
<27> # validate headers
<28> if stream.headers_recv_state == HeadersState.INITIAL:
<29> if self._is_client:
<30> validate_response_headers(headers)
<31> else:
<32> validate_request_headers(headers)
<33> else:
<34> validate_trailers(headers)
<35>
<36> # log frame
<37> if self._quic_logger is not None:
<38> self._quic_logger.log_event(
<39> category="http",
<40> event="frame_parsed",
<41> data=qlog_encode_headers_frame(
<42> byte_length=stream</s>
|
===========below chunk 0===========
# module: aioquic.h3.connection
class H3Connection:
def _handle_request_or_push_frame(
self,
frame_type: int,
frame_data: Optional[bytes],
stream: H3Stream,
stream_ended: bool,
) -> List[H3Event]:
# offset: 1
if frame_data is None
else len(frame_data),
headers=headers,
stream_id=stream.stream_id,
),
)
# update state and emit headers
if stream.headers_recv_state == HeadersState.INITIAL:
stream.headers_recv_state = HeadersState.AFTER_HEADERS
else:
stream.headers_recv_state = HeadersState.AFTER_TRAILERS
http_events.append(
HeadersReceived(
headers=headers,
push_id=stream.push_id,
stream_id=stream.stream_id,
stream_ended=stream_ended,
)
)
elif frame_type == FrameType.PUSH_PROMISE and stream.push_id is None:
if not self._is_client:
raise FrameUnexpected("Clients must not send PUSH_PROMISE")
frame_buf = Buffer(data=frame_data)
push_id = frame_buf.pull_uint_var()
headers = self._decode_headers(
stream.stream_id, frame_data[frame_buf.tell() :]
)
# validate headers
validate_push_promise_headers(headers)
# log frame
if self._quic_logger is not None:
self._quic_logger.log_event(
category="http",
event="frame_parsed",
data=qlog_encode_push_promise_frame(
byte_length=len(frame_data),
headers=headers,
push_id=push_id,
stream_id=stream.stream_id,
),
)
# emit event
http_events.append(
PushPromiseReceived(
headers</s>
===========below chunk 1===========
# module: aioquic.h3.connection
class H3Connection:
def _handle_request_or_push_frame(
self,
frame_type: int,
frame_data: Optional[bytes],
stream: H3Stream,
stream_ended: bool,
) -> List[H3Event]:
# offset: 2
<s>
),
)
# emit event
http_events.append(
PushPromiseReceived(
headers=headers, push_id=push_id, stream_id=stream.stream_id
)
)
elif frame_type in (
FrameType.PRIORITY,
FrameType.CANCEL_PUSH,
FrameType.SETTINGS,
FrameType.PUSH_PROMISE,
FrameType.GOAWAY,
FrameType.MAX_PUSH_ID,
FrameType.DUPLICATE_PUSH,
):
raise FrameUnexpected(
"Invalid frame type on request stream"
if stream.push_id is None
else "Invalid frame type on push stream"
)
return http_events
===========unchanged ref 0===========
at: aioquic.h3.connection
FrameType(x: Union[str, bytes, bytearray], base: int)
FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
HeadersState()
StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
StreamType(x: Union[str, bytes, bytearray], base: int)
ProtocolError(reason_phrase: str="")
FrameUnexpected(reason_phrase: str="")
encode_frame(frame_type: int, frame_data: bytes) -> bytes
encode_settings(settings: Dict[int, int]) -> bytes
validate_push_promise_headers(headers: Headers) -> None
validate_request_headers(headers: Headers) -> None
validate_response_headers(headers: Headers) -> None
validate_trailers(headers: Headers) -> None
at: aioquic.h3.connection.H3Connection
_create_uni_stream(stream_type: int) -> int
_create_uni_stream(self, stream_type: int) -> int
_decode_headers(stream_id: int, frame_data: Optional[bytes]) -> Headers
_decode_headers(self, stream_id: int, frame_data: Optional[bytes]) -> Headers
_get_local_settings() -> Dict[int, int]
at: aioquic.h3.connection.H3Connection.__init__
self._is_client = quic.configuration.is_client
self._quic = quic
self._quic_logger: Optional[QuicLoggerTrace] = quic._quic_logger
self._max_push_id: Optional[int] = 8 if self._is_client else None
self._local_control_stream_id: Optional[int] = None
self._local_decoder_stream_id: Optional[int] = None
self._local_encoder_stream_id: Optional[int] = None
===========unchanged ref 1===========
at: aioquic.h3.connection.H3Connection._handle_control_frame
self._max_push_id = parse_max_push_id(frame_data)
at: aioquic.h3.connection.H3Connection._handle_request_or_push_frame
http_events: List[H3Event] = []
at: aioquic.h3.connection.H3Stream.__init__
self.blocked_frame_size: Optional[int] = None
self.headers_recv_state: HeadersState = HeadersState.INITIAL
self.push_id: Optional[int] = None
self.stream_id = stream_id
at: tests.test_h3.FakeQuicConnection
send_stream_data(stream_id, data, end_stream=False)
at: typing
List = _alias(list, 1, inst=False, name='List')
===========changed ref 0===========
# module: aioquic.h3.connection
class H3Connection:
def send_data(self, stream_id: int, data: bytes, end_stream: bool) -> None:
"""
Send data on the given stream.
To retrieve datagram which need to be sent over the network call the QUIC
connection's :meth:`~aioquic.connection.QuicConnection.datagrams_to_send`
method.
:param stream_id: The stream ID on which to send the data.
:param data: The data to send.
:param end_stream: Whether to end the stream.
"""
# check DATA frame is allowed
stream = self._get_or_create_stream(stream_id)
if stream.headers_send_state != HeadersState.AFTER_HEADERS:
raise FrameUnexpected("DATA frame is not allowed in this state")
# log frame
if self._quic_logger is not None:
self._quic_logger.log_event(
category="http",
event="frame_created",
+ data=self._quic_logger.encode_http3_data_frame(
+ length=len(data), stream_id=stream_id
+ ),
- data=qlog_encode_data_frame(byte_length=len(data), stream_id=stream_id),
)
self._quic.send_stream_data(
stream_id, encode_frame(FrameType.DATA, data), end_stream
)
===========changed ref 1===========
# module: aioquic.h3.connection
- def qlog_encode_headers(headers: Headers) -> List[Dict]:
- return [
- {"name": h[0].decode("utf8"), "value": h[1].decode("utf8")} for h in headers
- ]
-
|
aioquic.h3.connection/H3Connection._receive_request_or_push_data
|
Modified
|
aiortc~aioquic
|
65b534a92dc38fa603d9c6ad501096911e3287a9
|
[logger] switch to draft-ietf-quic-qlog-main-schema-01
|
# module: aioquic.h3.connection
class H3Connection:
def _receive_request_or_push_data(
self, stream: H3Stream, data: bytes, stream_ended: bool
) -> List[H3Event]:
<0> """
<1> Handle data received on a request or push stream.
<2> """
<3> http_events: List[H3Event] = []
<4>
<5> stream.buffer += data
<6> if stream_ended:
<7> stream.ended = True
<8> if stream.blocked:
<9> return http_events
<10>
<11> # shortcut for WEBTRANSPORT_STREAM frame fragments
<12> if (
<13> stream.frame_type == FrameType.WEBTRANSPORT_STREAM
<14> and stream.session_id is not None
<15> ):
<16> http_events.append(
<17> WebTransportStreamDataReceived(
<18> data=stream.buffer,
<19> session_id=stream.session_id,
<20> stream_id=stream.stream_id,
<21> stream_ended=stream_ended,
<22> )
<23> )
<24> stream.buffer = b""
<25> return http_events
<26>
<27> # shortcut for DATA frame fragments
<28> if (
<29> stream.frame_type == FrameType.DATA
<30> and stream.frame_size is not None
<31> and len(stream.buffer) < stream.frame_size
<32> ):
<33> http_events.append(
<34> DataReceived(
<35> data=stream.buffer,
<36> push_id=stream.push_id,
<37> stream_id=stream.stream_id,
<38> stream_ended=False,
<39> )
<40> )
<41> stream.frame_size -= len(stream.buffer)
<42> stream.buffer = b""
<43> return http_events
<44>
<45> # handle lone FIN
<46> if stream_ended and not stream.buffer:
<47> http_events.append(
<48> DataReceived(
<49> data=b"",
<50> push_id=stream.push_id,
<51> stream_id=stream.stream_id,</s>
|
===========below chunk 0===========
# module: aioquic.h3.connection
class H3Connection:
def _receive_request_or_push_data(
self, stream: H3Stream, data: bytes, stream_ended: bool
) -> List[H3Event]:
# offset: 1
)
)
return http_events
buf = Buffer(data=stream.buffer)
consumed = 0
while not buf.eof():
# fetch next frame header
if stream.frame_size is None:
try:
stream.frame_type = buf.pull_uint_var()
stream.frame_size = buf.pull_uint_var()
except BufferReadError:
break
consumed = buf.tell()
# WEBTRANSPORT_STREAM frames last until the end of the stream
if stream.frame_type == FrameType.WEBTRANSPORT_STREAM:
stream.session_id = stream.frame_size
stream.frame_size = None
frame_data = stream.buffer[consumed:]
stream.buffer = b""
if frame_data or stream_ended:
http_events.append(
WebTransportStreamDataReceived(
data=frame_data,
session_id=stream.session_id,
stream_id=stream.stream_id,
stream_ended=stream_ended,
)
)
return http_events
# log frame
if (
self._quic_logger is not None
and stream.frame_type == FrameType.DATA
):
self._quic_logger.log_event(
category="http",
event="frame_parsed",
data=qlog_encode_data_frame(
byte_length=stream.frame_size, stream_id=stream.stream_id
),
)
# check how much data is available
chunk_size = min(stream.frame_size, buf.capacity - consumed)
if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size:
break
# read available data
frame_</s>
===========below chunk 1===========
# module: aioquic.h3.connection
class H3Connection:
def _receive_request_or_push_data(
self, stream: H3Stream, data: bytes, stream_ended: bool
) -> List[H3Event]:
# offset: 2
<s> != FrameType.DATA and chunk_size < stream.frame_size:
break
# read available data
frame_data = buf.pull_bytes(chunk_size)
frame_type = stream.frame_type
consumed = buf.tell()
# detect end of frame
stream.frame_size -= chunk_size
if not stream.frame_size:
stream.frame_size = None
stream.frame_type = None
try:
http_events.extend(
self._handle_request_or_push_frame(
frame_type=frame_type,
frame_data=frame_data,
stream=stream,
stream_ended=stream.ended and buf.eof(),
)
)
except pylsqpack.StreamBlocked:
stream.blocked = True
stream.blocked_frame_size = len(frame_data)
break
# remove processed data from buffer
stream.buffer = stream.buffer[consumed:]
return http_events
===========unchanged ref 0===========
at: aioquic.h3.connection
FrameType(x: Union[str, bytes, bytearray], base: int)
FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
StreamType(x: Union[str, bytes, bytearray], base: int)
StreamCreationError(reason_phrase: str="")
H3Stream(stream_id: int)
at: aioquic.h3.connection.H3Connection
_handle_request_or_push_frame(frame_type: int, frame_data: Optional[bytes], stream: H3Stream, stream_ended: bool) -> List[H3Event]
at: aioquic.h3.connection.H3Connection.__init__
self._quic_logger: Optional[QuicLoggerTrace] = quic._quic_logger
self._peer_control_stream_id: Optional[int] = None
self._peer_decoder_stream_id: Optional[int] = None
at: aioquic.h3.connection.H3Connection._receive_request_or_push_data
http_events: List[H3Event] = []
at: aioquic.h3.connection.H3Connection._receive_stream_data_uni
self._peer_decoder_stream_id = stream.stream_id
at: aioquic.h3.connection.H3Stream.__init__
self.blocked = False
self.blocked_frame_size: Optional[int] = None
self.buffer = b""
self.ended = False
self.frame_size: Optional[int] = None
self.frame_type: Optional[int] = None
self.push_id: Optional[int] = None
self.session_id: Optional[int] = None
self.stream_id = stream_id
self.stream_type: Optional[int] = None
===========unchanged ref 1===========
at: typing
List = _alias(list, 1, inst=False, name='List')
Set = _alias(set, 1, inst=False, name='Set')
===========changed ref 0===========
# module: aioquic.h3.connection
class H3Connection:
def _handle_request_or_push_frame(
self,
frame_type: int,
frame_data: Optional[bytes],
stream: H3Stream,
stream_ended: bool,
) -> List[H3Event]:
"""
Handle a frame received on a request or push stream.
"""
http_events: List[H3Event] = []
if frame_type == FrameType.DATA:
# check DATA frame is allowed
if stream.headers_recv_state != HeadersState.AFTER_HEADERS:
raise FrameUnexpected("DATA frame is not allowed in this state")
if stream_ended or frame_data:
http_events.append(
DataReceived(
data=frame_data,
push_id=stream.push_id,
stream_ended=stream_ended,
stream_id=stream.stream_id,
)
)
elif frame_type == FrameType.HEADERS:
# check HEADERS frame is allowed
if stream.headers_recv_state == HeadersState.AFTER_TRAILERS:
raise FrameUnexpected("HEADERS frame is not allowed in this state")
# try to decode HEADERS, may raise pylsqpack.StreamBlocked
headers = self._decode_headers(stream.stream_id, frame_data)
# validate headers
if stream.headers_recv_state == HeadersState.INITIAL:
if self._is_client:
validate_response_headers(headers)
else:
validate_request_headers(headers)
else:
validate_trailers(headers)
# log frame
if self._quic_logger is not None:
self._quic_logger.log_event(
category="http",
event="frame_parsed",
+ data=self._quic_logger.encode_http3_headers_frame(
- data=qlog_encode_headers_frame(
+ length=stream.blocked_frame_size
- byte_length=stream.blocked_frame_size
</s>
|
|
aioquic.h3.connection/H3Connection.create_webtransport_stream
|
Modified
|
aiortc~aioquic
|
778f1cef8e05770b92799ceffb390e03bc19b898
|
[logger] add support for HTTP/3 stream_type_set event
|
<11>:<add> self._log_stream_type(
<add> stream_id=stream_id, stream_type=StreamType.WEBTRANSPORT
<add> )
|
# module: aioquic.h3.connection
class H3Connection:
def create_webtransport_stream(
self, session_id: int, is_unidirectional: bool = False
) -> int:
<0> """
<1> Create a WebTransport stream and return the stream ID.
<2>
<3> :param session_id: The WebTransport session identifier.
<4> :param is_unidirectional: Whether to create a unidirectional stream.
<5> """
<6> if is_unidirectional:
<7> stream_id = self._create_uni_stream(StreamType.WEBTRANSPORT)
<8> self._quic.send_stream_data(stream_id, encode_uint_var(session_id))
<9> else:
<10> stream_id = self._quic.get_next_available_stream_id()
<11> self._quic.send_stream_data(
<12> stream_id,
<13> encode_uint_var(FrameType.WEBTRANSPORT_STREAM)
<14> + encode_uint_var(session_id),
<15> )
<16> return stream_id
<17>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
FrameType(x: Union[str, bytes, bytearray], base: int)
FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
StreamType(x: Union[str, bytes, bytearray], base: int)
at: aioquic.h3.connection.H3Connection
_create_uni_stream(stream_type: int, push_id: Optional[int]=None) -> int
_create_uni_stream(self, stream_type: int, push_id: Optional[int]=None) -> int
_log_stream_type(stream_id: int, stream_type: int, push_id: Optional[int]=None) -> None
at: aioquic.h3.connection.H3Connection.__init__
self._quic = quic
at: tests.test_h3.FakeQuicConnection
get_next_available_stream_id(is_unidirectional=False)
send_stream_data(stream_id, data, end_stream=False)
|
aioquic.h3.connection/H3Connection.send_push_promise
|
Modified
|
aiortc~aioquic
|
778f1cef8e05770b92799ceffb390e03bc19b898
|
[logger] add support for HTTP/3 stream_type_set event
|
<24>:<add> push_stream_id = self._create_uni_stream(StreamType.PUSH, push_id=push_id)
<del> push_stream_id = self._create_uni_stream(StreamType.PUSH)
|
# module: aioquic.h3.connection
class H3Connection:
def send_push_promise(self, stream_id: int, headers: Headers) -> int:
<0> """
<1> Send a push promise related to the specified stream.
<2>
<3> Returns the stream ID on which headers and data can be sent.
<4>
<5> :param stream_id: The stream ID on which to send the data.
<6> :param headers: The HTTP request headers for this push.
<7> """
<8> assert not self._is_client, "Only servers may send a push promise."
<9> if self._max_push_id is None or self._next_push_id >= self._max_push_id:
<10> raise NoAvailablePushIDError
<11>
<12> # send push promise
<13> push_id = self._next_push_id
<14> self._next_push_id += 1
<15> self._quic.send_stream_data(
<16> stream_id,
<17> encode_frame(
<18> FrameType.PUSH_PROMISE,
<19> encode_uint_var(push_id) + self._encode_headers(stream_id, headers),
<20> ),
<21> )
<22>
<23> # create push stream
<24> push_stream_id = self._create_uni_stream(StreamType.PUSH)
<25> self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id))
<26>
<27> return push_stream_id
<28>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
FrameType(x: Union[str, bytes, bytearray], base: int)
FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
StreamType(x: Union[str, bytes, bytearray], base: int)
encode_frame(frame_type: int, frame_data: bytes) -> bytes
at: aioquic.h3.connection.H3Connection
_create_uni_stream(stream_type: int, push_id: Optional[int]=None) -> int
_create_uni_stream(self, stream_type: int, push_id: Optional[int]=None) -> int
_encode_headers(stream_id: int, headers: Headers) -> bytes
at: aioquic.h3.connection.H3Connection.__init__
self._is_client = quic.configuration.is_client
self._quic = quic
self._max_push_id: Optional[int] = 8 if self._is_client else None
self._next_push_id: int = 0
at: aioquic.h3.connection.H3Connection._handle_control_frame
self._max_push_id = parse_max_push_id(frame_data)
at: tests.test_h3.FakeQuicConnection
send_stream_data(stream_id, data, end_stream=False)
===========changed ref 0===========
# module: aioquic.h3.connection
class H3Connection:
def create_webtransport_stream(
self, session_id: int, is_unidirectional: bool = False
) -> int:
"""
Create a WebTransport stream and return the stream ID.
:param session_id: The WebTransport session identifier.
:param is_unidirectional: Whether to create a unidirectional stream.
"""
if is_unidirectional:
stream_id = self._create_uni_stream(StreamType.WEBTRANSPORT)
self._quic.send_stream_data(stream_id, encode_uint_var(session_id))
else:
stream_id = self._quic.get_next_available_stream_id()
+ self._log_stream_type(
+ stream_id=stream_id, stream_type=StreamType.WEBTRANSPORT
+ )
self._quic.send_stream_data(
stream_id,
encode_uint_var(FrameType.WEBTRANSPORT_STREAM)
+ encode_uint_var(session_id),
)
return stream_id
|
aioquic.h3.connection/H3Connection._create_uni_stream
|
Modified
|
aiortc~aioquic
|
778f1cef8e05770b92799ceffb390e03bc19b898
|
[logger] add support for HTTP/3 stream_type_set event
|
<4>:<add> self._log_stream_type(
<add> push_id=push_id, stream_id=stream_id, stream_type=stream_type
<add> )
|
# module: aioquic.h3.connection
class H3Connection:
+ def _create_uni_stream(
+ self, stream_type: int, push_id: Optional[int] = None
+ ) -> int:
- def _create_uni_stream(self, stream_type: int) -> int:
<0> """
<1> Create an unidirectional stream of the given type.
<2> """
<3> stream_id = self._quic.get_next_available_stream_id(is_unidirectional=True)
<4> self._quic.send_stream_data(stream_id, encode_uint_var(stream_type))
<5> return stream_id
<6>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
FrameType(x: Union[str, bytes, bytearray], base: int)
FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
encode_frame(frame_type: int, frame_data: bytes) -> bytes
at: aioquic.h3.connection.H3Connection.send_headers
frame_data = self._encode_headers(stream_id, headers)
===========changed ref 0===========
# module: aioquic.h3.connection
class H3Connection:
def create_webtransport_stream(
self, session_id: int, is_unidirectional: bool = False
) -> int:
"""
Create a WebTransport stream and return the stream ID.
:param session_id: The WebTransport session identifier.
:param is_unidirectional: Whether to create a unidirectional stream.
"""
if is_unidirectional:
stream_id = self._create_uni_stream(StreamType.WEBTRANSPORT)
self._quic.send_stream_data(stream_id, encode_uint_var(session_id))
else:
stream_id = self._quic.get_next_available_stream_id()
+ self._log_stream_type(
+ stream_id=stream_id, stream_type=StreamType.WEBTRANSPORT
+ )
self._quic.send_stream_data(
stream_id,
encode_uint_var(FrameType.WEBTRANSPORT_STREAM)
+ encode_uint_var(session_id),
)
return stream_id
===========changed ref 1===========
# module: aioquic.h3.connection
class H3Connection:
def send_push_promise(self, stream_id: int, headers: Headers) -> int:
"""
Send a push promise related to the specified stream.
Returns the stream ID on which headers and data can be sent.
:param stream_id: The stream ID on which to send the data.
:param headers: The HTTP request headers for this push.
"""
assert not self._is_client, "Only servers may send a push promise."
if self._max_push_id is None or self._next_push_id >= self._max_push_id:
raise NoAvailablePushIDError
# send push promise
push_id = self._next_push_id
self._next_push_id += 1
self._quic.send_stream_data(
stream_id,
encode_frame(
FrameType.PUSH_PROMISE,
encode_uint_var(push_id) + self._encode_headers(stream_id, headers),
),
)
# create push stream
+ push_stream_id = self._create_uni_stream(StreamType.PUSH, push_id=push_id)
- push_stream_id = self._create_uni_stream(StreamType.PUSH)
self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id))
return push_stream_id
|
aioquic.h3.connection/H3Connection._receive_request_or_push_data
|
Modified
|
aiortc~aioquic
|
778f1cef8e05770b92799ceffb390e03bc19b898
|
[logger] add support for HTTP/3 stream_type_set event
|
# module: aioquic.h3.connection
class H3Connection:
def _receive_request_or_push_data(
self, stream: H3Stream, data: bytes, stream_ended: bool
) -> List[H3Event]:
<0> """
<1> Handle data received on a request or push stream.
<2> """
<3> http_events: List[H3Event] = []
<4>
<5> stream.buffer += data
<6> if stream_ended:
<7> stream.ended = True
<8> if stream.blocked:
<9> return http_events
<10>
<11> # shortcut for WEBTRANSPORT_STREAM frame fragments
<12> if (
<13> stream.frame_type == FrameType.WEBTRANSPORT_STREAM
<14> and stream.session_id is not None
<15> ):
<16> http_events.append(
<17> WebTransportStreamDataReceived(
<18> data=stream.buffer,
<19> session_id=stream.session_id,
<20> stream_id=stream.stream_id,
<21> stream_ended=stream_ended,
<22> )
<23> )
<24> stream.buffer = b""
<25> return http_events
<26>
<27> # shortcut for DATA frame fragments
<28> if (
<29> stream.frame_type == FrameType.DATA
<30> and stream.frame_size is not None
<31> and len(stream.buffer) < stream.frame_size
<32> ):
<33> http_events.append(
<34> DataReceived(
<35> data=stream.buffer,
<36> push_id=stream.push_id,
<37> stream_id=stream.stream_id,
<38> stream_ended=False,
<39> )
<40> )
<41> stream.frame_size -= len(stream.buffer)
<42> stream.buffer = b""
<43> return http_events
<44>
<45> # handle lone FIN
<46> if stream_ended and not stream.buffer:
<47> http_events.append(
<48> DataReceived(
<49> data=b"",
<50> push_id=stream.push_id,
<51> stream_id=stream.stream_id,</s>
|
===========below chunk 0===========
# module: aioquic.h3.connection
class H3Connection:
def _receive_request_or_push_data(
self, stream: H3Stream, data: bytes, stream_ended: bool
) -> List[H3Event]:
# offset: 1
)
)
return http_events
buf = Buffer(data=stream.buffer)
consumed = 0
while not buf.eof():
# fetch next frame header
if stream.frame_size is None:
try:
stream.frame_type = buf.pull_uint_var()
stream.frame_size = buf.pull_uint_var()
except BufferReadError:
break
consumed = buf.tell()
# WEBTRANSPORT_STREAM frames last until the end of the stream
if stream.frame_type == FrameType.WEBTRANSPORT_STREAM:
stream.session_id = stream.frame_size
stream.frame_size = None
frame_data = stream.buffer[consumed:]
stream.buffer = b""
if frame_data or stream_ended:
http_events.append(
WebTransportStreamDataReceived(
data=frame_data,
session_id=stream.session_id,
stream_id=stream.stream_id,
stream_ended=stream_ended,
)
)
return http_events
# log frame
if (
self._quic_logger is not None
and stream.frame_type == FrameType.DATA
):
self._quic_logger.log_event(
category="http",
event="frame_parsed",
data=self._quic_logger.encode_http3_data_frame(
length=stream.frame_size, stream_id=stream.stream_id
),
)
# check how much data is available
chunk_size = min(stream.frame_size, buf.capacity - consumed)
if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size:
break
# read available</s>
===========below chunk 1===========
# module: aioquic.h3.connection
class H3Connection:
def _receive_request_or_push_data(
self, stream: H3Stream, data: bytes, stream_ended: bool
) -> List[H3Event]:
# offset: 2
<s> stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size:
break
# read available data
frame_data = buf.pull_bytes(chunk_size)
frame_type = stream.frame_type
consumed = buf.tell()
# detect end of frame
stream.frame_size -= chunk_size
if not stream.frame_size:
stream.frame_size = None
stream.frame_type = None
try:
http_events.extend(
self._handle_request_or_push_frame(
frame_type=frame_type,
frame_data=frame_data,
stream=stream,
stream_ended=stream.ended and buf.eof(),
)
)
except pylsqpack.StreamBlocked:
stream.blocked = True
stream.blocked_frame_size = len(frame_data)
break
# remove processed data from buffer
stream.buffer = stream.buffer[consumed:]
return http_events
===========unchanged ref 0===========
at: aioquic.h3.connection
FrameType(x: Union[str, bytes, bytearray], base: int)
FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
StreamType(x: Union[str, bytes, bytearray], base: int)
ProtocolError(reason_phrase: str="")
H3Stream(stream_id: int)
at: aioquic.h3.connection.H3Connection
_log_stream_type(stream_id: int, stream_type: int, push_id: Optional[int]=None) -> None
at: aioquic.h3.connection.H3Connection.__init__
self._quic_logger: Optional[QuicLoggerTrace] = quic._quic_logger
at: aioquic.h3.connection.H3Stream.__init__
self.blocked = False
self.buffer = b""
self.ended = False
self.frame_size: Optional[int] = None
self.frame_type: Optional[int] = None
self.push_id: Optional[int] = None
self.session_id: Optional[int] = None
self.stream_id = stream_id
at: typing
List = _alias(list, 1, inst=False, name='List')
at: typing.Mapping
get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]
get(key: _KT) -> Optional[_VT_co]
===========changed ref 0===========
# module: aioquic.h3.connection
class H3Connection:
+ def _log_stream_type(
+ self, stream_id: int, stream_type: int, push_id: Optional[int] = None
+ ) -> None:
+ if self._quic_logger is not None:
+ type_name = {
+ 0: "control",
+ 1: "push",
+ 2: "qpack_encoder",
+ 3: "qpack_decoder",
+ 0x54: "webtransport", # NOTE: not standardized yet
+ }.get(stream_type, "unknown")
+
+ data = {"new": type_name, "stream_id": stream_id}
+ if push_id is not None:
+ data["associated_push_id"] = push_id
+
+ self._quic_logger.log_event(
+ category="http",
+ event="stream_type_set",
+ data=data,
+ )
+
===========changed ref 1===========
# module: aioquic.h3.connection
class H3Connection:
+ def _create_uni_stream(
+ self, stream_type: int, push_id: Optional[int] = None
+ ) -> int:
- def _create_uni_stream(self, stream_type: int) -> int:
"""
Create an unidirectional stream of the given type.
"""
stream_id = self._quic.get_next_available_stream_id(is_unidirectional=True)
+ self._log_stream_type(
+ push_id=push_id, stream_id=stream_id, stream_type=stream_type
+ )
self._quic.send_stream_data(stream_id, encode_uint_var(stream_type))
return stream_id
===========changed ref 2===========
# module: aioquic.h3.connection
class H3Connection:
def create_webtransport_stream(
self, session_id: int, is_unidirectional: bool = False
) -> int:
"""
Create a WebTransport stream and return the stream ID.
:param session_id: The WebTransport session identifier.
:param is_unidirectional: Whether to create a unidirectional stream.
"""
if is_unidirectional:
stream_id = self._create_uni_stream(StreamType.WEBTRANSPORT)
self._quic.send_stream_data(stream_id, encode_uint_var(session_id))
else:
stream_id = self._quic.get_next_available_stream_id()
+ self._log_stream_type(
+ stream_id=stream_id, stream_type=StreamType.WEBTRANSPORT
+ )
self._quic.send_stream_data(
stream_id,
encode_uint_var(FrameType.WEBTRANSPORT_STREAM)
+ encode_uint_var(session_id),
)
return stream_id
|
|
examples.interop/test_version_negotiation
|
Modified
|
aiortc~aioquic
|
bc65169b9a83940ffa3c43fb7953c0d168472e24
|
[interop] fix breakage du to QLOG format change
|
<12>:<add> and event["data"]["header"]["packet_type"] == "version_negotiation"
<del> and event["data"]["packet_type"] == "version_negotiation"
|
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
<0> # force version negotiation
<1> configuration.supported_versions.insert(0, 0x1A2A3A4A)
<2>
<3> async with connect(
<4> server.host, server.port, configuration=configuration
<5> ) as protocol:
<6> await protocol.ping()
<7>
<8> # check log
<9> for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
<10> if (
<11> event["name"] == "transport:packet_received"
<12> and event["data"]["packet_type"] == "version_negotiation"
<13> ):
<14> server.result |= Result.V
<15>
|
===========unchanged ref 0===========
at: examples.interop
Result()
Server(name: str, host: str, port: int=4433, http3: bool=True, http3_port: Optional[int]=None, retry_port: Optional[int]=4434, path: str="/", push_path: Optional[str]=None, result: Result=field(default_factory=lambda: Result(0)), session_resumption_port: Optional[int]=None, structured_logging: bool=False, throughput_path: Optional[str]="/%(size)d", verify_mode: Optional[int]=None)
at: examples.interop.Server
name: str
host: str
port: int = 4433
http3: bool = True
http3_port: Optional[int] = None
retry_port: Optional[int] = 4434
path: str = "/"
push_path: Optional[str] = None
result: Result = field(default_factory=lambda: Result(0))
session_resumption_port: Optional[int] = None
structured_logging: bool = False
throughput_path: Optional[str] = "/%(size)d"
verify_mode: Optional[int] = None
|
examples.interop/test_retry
|
Modified
|
aiortc~aioquic
|
bc65169b9a83940ffa3c43fb7953c0d168472e24
|
[interop] fix breakage du to QLOG format change
|
<13>:<add> and event["data"]["header"]["packet_type"] == "retry"
<del> and event["data"]["packet_type"] == "retry"
|
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
<0> # skip test if there is not retry port
<1> if server.retry_port is None:
<2> return
<3>
<4> async with connect(
<5> server.host, server.retry_port, configuration=configuration
<6> ) as protocol:
<7> await protocol.ping()
<8>
<9> # check log
<10> for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
<11> if (
<12> event["name"] == "transport:packet_received"
<13> and event["data"]["packet_type"] == "retry"
<14> ):
<15> server.result |= Result.S
<16>
|
===========unchanged ref 0===========
at: examples.interop
Result()
Server(name: str, host: str, port: int=4433, http3: bool=True, http3_port: Optional[int]=None, retry_port: Optional[int]=4434, path: str="/", push_path: Optional[str]=None, result: Result=field(default_factory=lambda: Result(0)), session_resumption_port: Optional[int]=None, structured_logging: bool=False, throughput_path: Optional[str]="/%(size)d", verify_mode: Optional[int]=None)
at: examples.interop.Server
host: str
retry_port: Optional[int] = 4434
result: Result = field(default_factory=lambda: Result(0))
===========changed ref 0===========
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
# force version negotiation
configuration.supported_versions.insert(0, 0x1A2A3A4A)
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
event["name"] == "transport:packet_received"
+ and event["data"]["header"]["packet_type"] == "version_negotiation"
- and event["data"]["packet_type"] == "version_negotiation"
):
server.result |= Result.V
|
examples.interop/test_nat_rebinding
|
Modified
|
aiortc~aioquic
|
bc65169b9a83940ffa3c43fb7953c0d168472e24
|
[interop] fix breakage du to QLOG format change
|
<18>:<add> and event["data"]["header"]["packet_type"] == "1RTT"
<del> and event["data"]["packet_type"] == "1RTT"
|
# module: examples.interop
def test_nat_rebinding(server: Server, configuration: QuicConfiguration):
<0> async with connect(
<1> server.host, server.port, configuration=configuration
<2> ) as protocol:
<3> # cause some traffic
<4> await protocol.ping()
<5>
<6> # replace transport
<7> protocol._transport.close()
<8> await loop.create_datagram_endpoint(lambda: protocol, local_addr=("::", 0))
<9>
<10> # cause more traffic
<11> await protocol.ping()
<12>
<13> # check log
<14> path_challenges = 0
<15> for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
<16> if (
<17> event["name"] == "transport:packet_received"
<18> and event["data"]["packet_type"] == "1RTT"
<19> ):
<20> for frame in event["data"]["frames"]:
<21> if frame["frame_type"] == "path_challenge":
<22> path_challenges += 1
<23> if not path_challenges:
<24> protocol._quic._logger.warning("No PATH_CHALLENGE received")
<25> else:
<26> server.result |= Result.B
<27>
|
===========unchanged ref 0===========
at: asyncio.events.AbstractEventLoop
create_datagram_endpoint(protocol_factory: _ProtocolFactory, local_addr: Optional[Tuple[str, int]]=..., remote_addr: Optional[Tuple[str, int]]=..., *, family: int=..., proto: int=..., flags: int=..., reuse_address: Optional[bool]=..., reuse_port: Optional[bool]=..., allow_broadcast: Optional[bool]=..., sock: Optional[socket]=...) -> _TransProtPair
at: examples.interop
Result()
Server(name: str, host: str, port: int=4433, http3: bool=True, http3_port: Optional[int]=None, retry_port: Optional[int]=4434, path: str="/", push_path: Optional[str]=None, result: Result=field(default_factory=lambda: Result(0)), session_resumption_port: Optional[int]=None, structured_logging: bool=False, throughput_path: Optional[str]="/%(size)d", verify_mode: Optional[int]=None)
loop = asyncio.get_event_loop()
at: examples.interop.Server
host: str
port: int = 4433
result: Result = field(default_factory=lambda: Result(0))
===========changed ref 0===========
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
# skip test if there is not retry port
if server.retry_port is None:
return
async with connect(
server.host, server.retry_port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
event["name"] == "transport:packet_received"
+ and event["data"]["header"]["packet_type"] == "retry"
- and event["data"]["packet_type"] == "retry"
):
server.result |= Result.S
===========changed ref 1===========
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
# force version negotiation
configuration.supported_versions.insert(0, 0x1A2A3A4A)
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
event["name"] == "transport:packet_received"
+ and event["data"]["header"]["packet_type"] == "version_negotiation"
- and event["data"]["packet_type"] == "version_negotiation"
):
server.result |= Result.V
|
examples.interop/test_address_mobility
|
Modified
|
aiortc~aioquic
|
bc65169b9a83940ffa3c43fb7953c0d168472e24
|
[interop] fix breakage du to QLOG format change
|
<21>:<add> and event["data"]["header"]["packet_type"] == "1RTT"
<del> and event["data"]["packet_type"] == "1RTT"
|
# module: examples.interop
def test_address_mobility(server: Server, configuration: QuicConfiguration):
<0> async with connect(
<1> server.host, server.port, configuration=configuration
<2> ) as protocol:
<3> # cause some traffic
<4> await protocol.ping()
<5>
<6> # replace transport
<7> protocol._transport.close()
<8> await loop.create_datagram_endpoint(lambda: protocol, local_addr=("::", 0))
<9>
<10> # change connection ID
<11> protocol.change_connection_id()
<12>
<13> # cause more traffic
<14> await protocol.ping()
<15>
<16> # check log
<17> path_challenges = 0
<18> for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
<19> if (
<20> event["name"] == "transport:packet_received"
<21> and event["data"]["packet_type"] == "1RTT"
<22> ):
<23> for frame in event["data"]["frames"]:
<24> if frame["frame_type"] == "path_challenge":
<25> path_challenges += 1
<26> if not path_challenges:
<27> protocol._quic._logger.warning("No PATH_CHALLENGE received")
<28> else:
<29> server.result |= Result.A
<30>
|
===========unchanged ref 0===========
at: asyncio.events.AbstractEventLoop
create_datagram_endpoint(protocol_factory: _ProtocolFactory, local_addr: Optional[Tuple[str, int]]=..., remote_addr: Optional[Tuple[str, int]]=..., *, family: int=..., proto: int=..., flags: int=..., reuse_address: Optional[bool]=..., reuse_port: Optional[bool]=..., allow_broadcast: Optional[bool]=..., sock: Optional[socket]=...) -> _TransProtPair
at: examples.interop
Result()
Server(name: str, host: str, port: int=4433, http3: bool=True, http3_port: Optional[int]=None, retry_port: Optional[int]=4434, path: str="/", push_path: Optional[str]=None, result: Result=field(default_factory=lambda: Result(0)), session_resumption_port: Optional[int]=None, structured_logging: bool=False, throughput_path: Optional[str]="/%(size)d", verify_mode: Optional[int]=None)
loop = asyncio.get_event_loop()
at: examples.interop.Server
host: str
port: int = 4433
result: Result = field(default_factory=lambda: Result(0))
===========changed ref 0===========
# module: examples.interop
def test_nat_rebinding(server: Server, configuration: QuicConfiguration):
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
# cause some traffic
await protocol.ping()
# replace transport
protocol._transport.close()
await loop.create_datagram_endpoint(lambda: protocol, local_addr=("::", 0))
# cause more traffic
await protocol.ping()
# check log
path_challenges = 0
for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
event["name"] == "transport:packet_received"
+ and event["data"]["header"]["packet_type"] == "1RTT"
- and event["data"]["packet_type"] == "1RTT"
):
for frame in event["data"]["frames"]:
if frame["frame_type"] == "path_challenge":
path_challenges += 1
if not path_challenges:
protocol._quic._logger.warning("No PATH_CHALLENGE received")
else:
server.result |= Result.B
===========changed ref 1===========
# module: examples.interop
def test_retry(server: Server, configuration: QuicConfiguration):
# skip test if there is not retry port
if server.retry_port is None:
return
async with connect(
server.host, server.retry_port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
event["name"] == "transport:packet_received"
+ and event["data"]["header"]["packet_type"] == "retry"
- and event["data"]["packet_type"] == "retry"
):
server.result |= Result.S
===========changed ref 2===========
# module: examples.interop
def test_version_negotiation(server: Server, configuration: QuicConfiguration):
# force version negotiation
configuration.supported_versions.insert(0, 0x1A2A3A4A)
async with connect(
server.host, server.port, configuration=configuration
) as protocol:
await protocol.ping()
# check log
for event in configuration.quic_logger.to_dict()["traces"][0]["events"]:
if (
event["name"] == "transport:packet_received"
+ and event["data"]["header"]["packet_type"] == "version_negotiation"
- and event["data"]["packet_type"] == "version_negotiation"
):
server.result |= Result.V
|
tests.test_h3/H3ConnectionTest.test_handle_control_frame_headers
|
Modified
|
aiortc~aioquic
|
6538849b7805f5c50df949e449eef6d171ea8471
|
Add accessor to sent and received SETTINGS
|
<7>:<add> self.assertIsNotNone(h3_server.sent_settings)
<add> self.assertIsNone(h3_server.received_settings)
<18>:<add> self.assertIsNotNone(h3_server.sent_settings)
<add> self.assertEqual(h3_server.received_settings, DUMMY_SETTINGS)
|
# module: tests.test_h3
class H3ConnectionTest(TestCase):
def test_handle_control_frame_headers(self):
<0> """
<1> We should not receive HEADERS on the control stream.
<2> """
<3> quic_server = FakeQuicConnection(
<4> configuration=QuicConfiguration(is_client=False)
<5> )
<6> h3_server = H3Connection(quic_server)
<7>
<8> # receive SETTINGS
<9> h3_server.handle_event(
<10> StreamDataReceived(
<11> stream_id=2,
<12> data=encode_uint_var(StreamType.CONTROL)
<13> + encode_frame(FrameType.SETTINGS, encode_settings(DUMMY_SETTINGS)),
<14> end_stream=False,
<15> )
<16> )
<17> self.assertIsNone(quic_server.closed)
<18>
<19> # receive unexpected HEADERS
<20> h3_server.handle_event(
<21> StreamDataReceived(
<22> stream_id=2,
<23> data=encode_frame(FrameType.HEADERS, b""),
<24> end_stream=False,
<25> )
<26> )
<27> self.assertEqual(
<28> quic_server.closed,
<29> (ErrorCode.H3_FRAME_UNEXPECTED, "Invalid frame type on control stream"),
<30> )
<31>
|
===========unchanged ref 0===========
at: tests.test_h3
DUMMY_SETTINGS = {
Setting.QPACK_MAX_TABLE_CAPACITY: 4096,
Setting.QPACK_BLOCKED_STREAMS: 16,
Setting.DUMMY: 1,
}
FakeQuicConnection(configuration)
at: tests.test_h3.FakeQuicConnection.__init__
self.closed = None
at: tests.test_h3.FakeQuicConnection.close
self.closed = (error_code, reason_phrase)
at: tests.test_h3.H3ConnectionTest
maxDiff = None
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
assertIsNone(obj: Any, msg: Any=...) -> None
assertIsNotNone(obj: Any, msg: Any=...) -> None
|
aioquic.h3.connection/H3Connection.__init__
|
Modified
|
aiortc~aioquic
|
6538849b7805f5c50df949e449eef6d171ea8471
|
Add accessor to sent and received SETTINGS
|
<30>:<add> self._received_settings: Optional[Dict[int, int]] = None
<add> self._sent_settings: Optional[Dict[int, int]] = None
|
# module: aioquic.h3.connection
class H3Connection:
def __init__(self, quic: QuicConnection, enable_webtransport: bool = False) -> None:
<0> # settings
<1> self._max_table_capacity = 4096
<2> self._blocked_streams = 16
<3> self._enable_webtransport = enable_webtransport
<4>
<5> self._is_client = quic.configuration.is_client
<6> self._is_done = False
<7> self._quic = quic
<8> self._quic_logger: Optional[QuicLoggerTrace] = quic._quic_logger
<9> self._decoder = pylsqpack.Decoder(
<10> self._max_table_capacity, self._blocked_streams
<11> )
<12> self._decoder_bytes_received = 0
<13> self._decoder_bytes_sent = 0
<14> self._encoder = pylsqpack.Encoder()
<15> self._encoder_bytes_received = 0
<16> self._encoder_bytes_sent = 0
<17> self._settings_received = False
<18> self._stream: Dict[int, H3Stream] = {}
<19>
<20> self._max_push_id: Optional[int] = 8 if self._is_client else None
<21> self._next_push_id: int = 0
<22>
<23> self._local_control_stream_id: Optional[int] = None
<24> self._local_decoder_stream_id: Optional[int] = None
<25> self._local_encoder_stream_id: Optional[int] = None
<26>
<27> self._peer_control_stream_id: Optional[int] = None
<28> self._peer_decoder_stream_id: Optional[int] = None
<29> self._peer_encoder_stream_id: Optional[int] = None
<30>
<31> self._init_connection()
<32>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
H3Stream(stream_id: int)
at: aioquic.h3.connection.H3Connection._decode_headers
self._decoder_bytes_sent += len(decoder)
at: aioquic.h3.connection.H3Connection._encode_headers
self._encoder_bytes_sent += len(encoder)
at: aioquic.h3.connection.H3Connection._handle_control_frame
self._received_settings = settings
self._settings_received = True
self._max_push_id = parse_max_push_id(frame_data)
at: aioquic.h3.connection.H3Connection._init_connection
self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL)
self._sent_settings = self._get_local_settings()
self._local_encoder_stream_id = self._create_uni_stream(
StreamType.QPACK_ENCODER
)
self._local_decoder_stream_id = self._create_uni_stream(
StreamType.QPACK_DECODER
)
at: aioquic.h3.connection.H3Connection._receive_stream_data_uni
self._peer_control_stream_id = stream.stream_id
self._peer_decoder_stream_id = stream.stream_id
self._peer_encoder_stream_id = stream.stream_id
self._decoder_bytes_received += len(data)
self._encoder_bytes_received += len(data)
at: aioquic.h3.connection.H3Connection.handle_event
self._is_done = True
at: aioquic.h3.connection.H3Connection.send_push_promise
self._next_push_id += 1
at: tests.test_h3.FakeQuicConnection.__init__
self.configuration = configuration
===========unchanged ref 1===========
self._quic_logger = QuicLogger().start_trace(
is_client=configuration.is_client, odcid=b""
)
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: tests.test_h3
class H3ConnectionTest(TestCase):
def test_handle_control_frame_headers(self):
"""
We should not receive HEADERS on the control stream.
"""
quic_server = FakeQuicConnection(
configuration=QuicConfiguration(is_client=False)
)
h3_server = H3Connection(quic_server)
+ self.assertIsNotNone(h3_server.sent_settings)
+ self.assertIsNone(h3_server.received_settings)
# receive SETTINGS
h3_server.handle_event(
StreamDataReceived(
stream_id=2,
data=encode_uint_var(StreamType.CONTROL)
+ encode_frame(FrameType.SETTINGS, encode_settings(DUMMY_SETTINGS)),
end_stream=False,
)
)
self.assertIsNone(quic_server.closed)
+ self.assertIsNotNone(h3_server.sent_settings)
+ self.assertEqual(h3_server.received_settings, DUMMY_SETTINGS)
# receive unexpected HEADERS
h3_server.handle_event(
StreamDataReceived(
stream_id=2,
data=encode_frame(FrameType.HEADERS, b""),
end_stream=False,
)
)
self.assertEqual(
quic_server.closed,
(ErrorCode.H3_FRAME_UNEXPECTED, "Invalid frame type on control stream"),
)
|
aioquic.h3.connection/H3Connection._handle_control_frame
|
Modified
|
aiortc~aioquic
|
6538849b7805f5c50df949e449eef6d171ea8471
|
Add accessor to sent and received SETTINGS
|
<11>:<add> self._received_settings = settings
|
# module: aioquic.h3.connection
class H3Connection:
def _handle_control_frame(self, frame_type: int, frame_data: bytes) -> None:
<0> """
<1> Handle a frame received on the peer's control stream.
<2> """
<3> if frame_type != FrameType.SETTINGS and not self._settings_received:
<4> raise MissingSettingsError
<5>
<6> if frame_type == FrameType.SETTINGS:
<7> if self._settings_received:
<8> raise FrameUnexpected("SETTINGS have already been received")
<9> settings = parse_settings(frame_data)
<10> self._validate_settings(settings)
<11> encoder = self._encoder.apply_settings(
<12> max_table_capacity=settings.get(Setting.QPACK_MAX_TABLE_CAPACITY, 0),
<13> blocked_streams=settings.get(Setting.QPACK_BLOCKED_STREAMS, 0),
<14> )
<15> self._quic.send_stream_data(self._local_encoder_stream_id, encoder)
<16> self._settings_received = True
<17> elif frame_type == FrameType.MAX_PUSH_ID:
<18> if self._is_client:
<19> raise FrameUnexpected("Servers must not send MAX_PUSH_ID")
<20> self._max_push_id = parse_max_push_id(frame_data)
<21> elif frame_type in (
<22> FrameType.DATA,
<23> FrameType.HEADERS,
<24> FrameType.PUSH_PROMISE,
<25> FrameType.DUPLICATE_PUSH,
<26> ):
<27> raise FrameUnexpected("Invalid frame type on control stream")
<28>
|
===========unchanged ref 0===========
at: aioquic.h3.connection
FrameType(x: Union[str, bytes, bytearray], base: int)
FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
Setting(x: Union[str, bytes, bytearray], base: int)
Setting(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
FrameUnexpected(reason_phrase: str="")
MissingSettingsError(reason_phrase: str="")
parse_settings(data: bytes) -> Dict[int, int]
at: aioquic.h3.connection.H3Connection
_validate_settings(settings: Dict[int, int]) -> None
at: aioquic.h3.connection.H3Connection.__init__
self._max_table_capacity = 4096
self._blocked_streams = 16
self._enable_webtransport = enable_webtransport
self._settings_received = False
self._stream: Dict[int, H3Stream] = {}
self._received_settings: Optional[Dict[int, int]] = None
at: aioquic.h3.connection.H3Connection._handle_control_frame
self._settings_received = True
at: typing
Dict = _alias(dict, 2, inst=False, name='Dict')
===========changed ref 0===========
# module: aioquic.h3.connection
class H3Connection:
+ @property
+ def sent_settings(self) -> Optional[Dict[int, int]]:
+ """
+ Return the sent SETTINGS frame, or None.
+ """
+ return self._sent_settings
+
===========changed ref 1===========
# module: aioquic.h3.connection
class H3Connection:
+ @property
+ def received_settings(self) -> Optional[Dict[int, int]]:
+ """
+ Return the received SETTINGS frame, or None.
+ """
+ return self._received_settings
+
===========changed ref 2===========
# module: aioquic.h3.connection
class H3Connection:
def __init__(self, quic: QuicConnection, enable_webtransport: bool = False) -> None:
# settings
self._max_table_capacity = 4096
self._blocked_streams = 16
self._enable_webtransport = enable_webtransport
self._is_client = quic.configuration.is_client
self._is_done = False
self._quic = quic
self._quic_logger: Optional[QuicLoggerTrace] = quic._quic_logger
self._decoder = pylsqpack.Decoder(
self._max_table_capacity, self._blocked_streams
)
self._decoder_bytes_received = 0
self._decoder_bytes_sent = 0
self._encoder = pylsqpack.Encoder()
self._encoder_bytes_received = 0
self._encoder_bytes_sent = 0
self._settings_received = False
self._stream: Dict[int, H3Stream] = {}
self._max_push_id: Optional[int] = 8 if self._is_client else None
self._next_push_id: int = 0
self._local_control_stream_id: Optional[int] = None
self._local_decoder_stream_id: Optional[int] = None
self._local_encoder_stream_id: Optional[int] = None
self._peer_control_stream_id: Optional[int] = None
self._peer_decoder_stream_id: Optional[int] = None
self._peer_encoder_stream_id: Optional[int] = None
+ self._received_settings: Optional[Dict[int, int]] = None
+ self._sent_settings: Optional[Dict[int, int]] = None
self._init_connection()
===========changed ref 3===========
# module: tests.test_h3
class H3ConnectionTest(TestCase):
def test_handle_control_frame_headers(self):
"""
We should not receive HEADERS on the control stream.
"""
quic_server = FakeQuicConnection(
configuration=QuicConfiguration(is_client=False)
)
h3_server = H3Connection(quic_server)
+ self.assertIsNotNone(h3_server.sent_settings)
+ self.assertIsNone(h3_server.received_settings)
# receive SETTINGS
h3_server.handle_event(
StreamDataReceived(
stream_id=2,
data=encode_uint_var(StreamType.CONTROL)
+ encode_frame(FrameType.SETTINGS, encode_settings(DUMMY_SETTINGS)),
end_stream=False,
)
)
self.assertIsNone(quic_server.closed)
+ self.assertIsNotNone(h3_server.sent_settings)
+ self.assertEqual(h3_server.received_settings, DUMMY_SETTINGS)
# receive unexpected HEADERS
h3_server.handle_event(
StreamDataReceived(
stream_id=2,
data=encode_frame(FrameType.HEADERS, b""),
end_stream=False,
)
)
self.assertEqual(
quic_server.closed,
(ErrorCode.H3_FRAME_UNEXPECTED, "Invalid frame type on control stream"),
)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.