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
aioquic.stream/QuicStream.__init__
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<1>:<add> self.max_stream_data_local = max_stream_data_local <add> self.max_stream_data_remote = max_stream_data_remote
# module: aioquic.stream class QuicStream: def __init__( + self, + stream_id: Optional[int] = None, + connection: Optional[Any] = None, + max_stream_data_local: int = 0, + max_stream_data_remote: int = 0, - self, stream_id: Optional[int] = None, connection: Optional[Any] = None ) -> None: <0> self._connection = connection <1> <2> if stream_id is not None: <3> self.reader = asyncio.StreamReader() <4> self.writer = asyncio.StreamWriter(self, None, self.reader, None) <5> else: <6> self.reader = None <7> self.writer = None <8> <9> self._recv_buffer = bytearray() <10> self._recv_start = 0 <11> self._recv_ranges = RangeSet() <12> <13> self._send_buffer = bytearray() <14> self._send_fin = False <15> self._send_start = 0 <16> <17> self.__stream_id = stream_id <18>
===========unchanged ref 0=========== at: aioquic.rangeset RangeSet(ranges: Iterable[range]=[]) at: aioquic.stream.QuicStream.add_frame self._recv_buffer += bytearray(gap) at: aioquic.stream.QuicStream.pull_data self._recv_buffer = self._recv_buffer[pos:] self._recv_start = r.stop at: asyncio.streams StreamWriter(transport: transports.BaseTransport, protocol: protocols.BaseProtocol, reader: Optional[StreamReader], loop: events.AbstractEventLoop) StreamReader(limit: int=..., loop: Optional[events.AbstractEventLoop]=...)
aioquic.connection/QuicConnection.__init__
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<24>:<add> self._local_max_data = 1048576 <add> self._local_max_stream_data_bidi_local = 1048576 <add> self._local_max_stream_data_bidi_remote = 1048576 <add> self._local_max_stream_data_uni = 1048576 <30>:<add> self._remote_max_data = 0 <add> self._remote_max_stream_data_bidi_local = 0 <add> self._remote_max_stream_data_bidi_remote = 0 <add> self._remote_max_stream_data_uni = 0
# module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: <0> if not is_client: <1> assert certificate is not None, "SSL certificate is required" <2> assert private_key is not None, "SSL private key is required" <3> <4> self.alpn_protocols = alpn_protocols <5> self.certificate = certificate <6> self.is_client = is_client <7> self.host_cid = os.urandom(8) <8> self.peer_cid = os.urandom(8) <9> self.peer_cid_set = False <10> self.peer_token = b"" <11> self.private_key = private_key <12> self.secrets_log_file = secrets_log_file <13> self.server_name = server_name <14> self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} <15> <16> # protocol versions <17> self.version = max(self.supported_versions) <18> <19> self.__close: Optional[Dict] = None <20> self.__connected = asyncio.Event() <21> self.__epoch = tls.Epoch.INITIAL <22> self.__initialized = False <23> self._local_idle_timeout = 60.0 # seconds <24> self._local_max_streams_bidi = 128 <25> self._local_max_streams_uni = 128 <26> self.__logger = logger <27> self.__path_challenge: Optional[bytes] = None <28> self._pending_flow_control: List[bytes] = [] <29> self._remote_idle_timeout = 0.0 <30> self._remote_max_streams_bidi = 0 <31> self._remote_max_streams_uni = 0 <32> self.__transport: Optional[asyncio.Dat</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame,</s> ===========below chunk 1=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s>path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ] ===========unchanged ref 0=========== at: aioquic.connection logger = logging.getLogger("quic") at: aioquic.connection.QuicConnection supported_versions = [ QuicProtocolVersion.DRAFT_17, QuicProtocolVersion.DRAFT_18, QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20, ] _handle_ack_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_crypto_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_data_blocked_frame(self, epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_data_frame(self, epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_stream_data_frame(self, epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_stream_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_bidi_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_uni_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_token_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_padding_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_reset_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None ===========unchanged ref 1=========== _handle_stop_sending_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stop_sending_frame(self, epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_streams_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.connection.QuicConnection._handle_crypto_frame self.__epoch = tls.Epoch.ONE_RTT self.__epoch = tls.Epoch.HANDSHAKE at: aioquic.connection.QuicConnection._handle_max_data_frame self._remote_max_data = max_data at: aioquic.connection.QuicConnection._handle_max_streams_bidi_frame self._remote_max_streams_bidi = max_streams at: aioquic.connection.QuicConnection._handle_max_streams_uni_frame self._remote_max_streams_uni = max_streams at: aioquic.connection.QuicConnection._initialize self.__initialized = True at: aioquic.connection.QuicConnection._parse_transport_parameters self._remote_idle_timeout = quic_transport_parameters.idle_timeout self._remote_idle_timeout = ( quic_transport_parameters.idle_timeout / 1000 ) at: aioquic.connection.QuicConnection._send_path_challenge self.__path_challenge = os.urandom(8) at: aioquic.connection.QuicConnection._write_application self._pending_flow_control = [] self.__close = None at: aioquic.connection.QuicConnection._write_handshake self.__close = None
aioquic.connection/QuicConnection.create_stream
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<10>:<add> if is_unidirectional: <add> max_stream_data_local = 0 <add> max_stream_data_remote = self._remote_max_stream_data_uni <add> else: <add> max_stream_data_local = self._local_max_stream_data_bidi_local <add> max_stream_data_remote = self._remote_max_stream_data_bidi_remote <add> <12>:<add> connection=self, <add> stream_id=stream_id, <del> connection=self, stream_id=stream_id <13>:<add> max_stream_data_local=max_stream_data_local, <add> max_stream_data_remote=max_stream_data_remote,
# module: aioquic.connection class QuicConnection: def create_stream( self, is_unidirectional: bool = False ) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]: <0> """ <1> Create a QUIC stream and return a pair of (reader, writer) objects. <2> <3> The returned reader and writer objects are instances of :class:`asyncio.StreamReader` <4> and :class:`asyncio.StreamWriter` classes. <5> """ <6> stream_id = (int(is_unidirectional) << 1) | int(not self.is_client) <7> while stream_id in self.streams: <8> stream_id += 4 <9> <10> # create stream <11> stream = self.streams[stream_id] = QuicStream( <12> connection=self, stream_id=stream_id <13> ) <14> self.stream_created_cb(stream.reader, stream.writer) <15> <16> return stream.reader, stream.writer <17>
===========unchanged ref 0=========== at: aioquic.connection.QuicConnection _send_pending(self) -> None _send_pending() -> None at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} self.__connected = asyncio.Event() at: asyncio.locks.Event wait() -> bool at: asyncio.streams StreamWriter(transport: transports.BaseTransport, protocol: protocols.BaseProtocol, reader: Optional[StreamReader], loop: events.AbstractEventLoop) StreamReader(limit: int=..., loop: Optional[events.AbstractEventLoop]=...) at: typing Tuple = _TupleType(tuple, -1, inst=False, name='Tuple') ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: if not is_client: assert certificate is not None, "SSL certificate is required" assert private_key is not None, "SSL private key is required" self.alpn_protocols = alpn_protocols self.certificate = certificate self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.private_key = private_key self.secrets_log_file = secrets_log_file self.server_name = server_name self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} # protocol versions self.version = max(self.supported_versions) self.__close: Optional[Dict] = None self.__connected = asyncio.Event() self.__epoch = tls.Epoch.INITIAL self.__initialized = False self._local_idle_timeout = 60.0 # seconds + self._local_max_data = 1048576 + self._local_max_stream_data_bidi_local = 1048576 + self._local_max_stream_data_bidi_remote = 1048576 + self._local_max_stream_data_uni = 1048576 self._local_max_streams_bidi = 128 self._local_max_streams_uni = 128 self.__logger = logger self.__path_challenge: Optional[bytes] = None self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0</s> ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 <s>] = None self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0.0 + self._remote_max_data = 0 + 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 self._remote_max_streams_uni = 0 self.__transport: Optional[asyncio.DatagramTransport] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle</s> ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s>_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ] ===========changed ref 3=========== # module: aioquic.stream class QuicStream: def __init__( + self, + stream_id: Optional[int] = None, + connection: Optional[Any] = None, + max_stream_data_local: int = 0, + max_stream_data_remote: int = 0, - self, stream_id: Optional[int] = None, connection: Optional[Any] = None ) -> None: self._connection = connection + self.max_stream_data_local = max_stream_data_local + self.max_stream_data_remote = max_stream_data_remote if stream_id is not None: self.reader = asyncio.StreamReader() self.writer = asyncio.StreamWriter(self, None, self.reader, None) else: self.reader = None self.writer = None self._recv_buffer = bytearray() self._recv_start = 0 self._recv_ranges = RangeSet() self._send_buffer = bytearray() self._send_fin = False self._send_start = 0 self.__stream_id = stream_id
aioquic.connection/QuicConnection.datagram_received
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<19>:<add> self.__logger.info("Retrying with %s", self.version) <del> self.__logger.info("Retrying with %s" % self.version)
# module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: <0> """ <1> Handle an incoming datagram. <2> """ <3> buf = Buffer(data=data) <4> <5> while not buf.eof(): <6> start_off = buf.tell() <7> header = pull_quic_header(buf, host_cid_length=len(self.host_cid)) <8> <9> if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION: <10> # version negotiation <11> versions = [] <12> while not buf.eof(): <13> versions.append(pull_uint32(buf)) <14> common = set(self.supported_versions).intersection(versions) <15> if not common: <16> self.__logger.error("Could not find a common protocol version") <17> return <18> self.version = QuicProtocolVersion(max(common)) <19> self.__logger.info("Retrying with %s" % self.version) <20> self.connection_made(self.__transport) <21> return <22> elif self.is_client and header.packet_type == PACKET_TYPE_RETRY: <23> # stateless retry <24> if ( <25> header.destination_cid == self.host_cid <26> and header.original_destination_cid == self.peer_cid <27> ): <28> self.__logger.info("Performing stateless retry") <29> self.peer_cid = header.source_cid <30> self.peer_token = header.token <31> self.connection_made(self.__transport) <32> return <33> <34> # server initialization <35> if not self.is_client and not self.__initialized: <36> assert ( <37> header.packet_type == PACKET_TYPE_INITIAL <38> ), "first packet must be INITIAL" <39> self._initialize(header.destination_cid) <40> <41> # decrypt packet <42> encrypted_off = buf.tell() - start_off <43> end_off = buf.tell() + header</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 1 pull_bytes(buf, header.rest_length) epoch = get_epoch(header.packet_type) space = self.spaces[epoch] if not space.crypto.recv.is_valid(): return try: plain_header, plain_payload, packet_number = space.crypto.decrypt_packet( data[start_off:end_off], encrypted_off ) except CryptoError as exc: self.__logger.warning(exc) return if not self.peer_cid_set: self.peer_cid = header.source_cid self.peer_cid_set = True # handle payload try: is_ack_only = self._payload_received(epoch, plain_payload) except QuicConnectionError as exc: self.__logger.warning(exc) self.close( error_code=exc.error_code, frame_type=exc.frame_type, reason_phrase=exc.reason_phrase, ) return # record packet as received space.ack_queue.add(packet_number) if not is_ack_only: self.send_ack[epoch] = True self._send_pending() ===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) pull_bytes(buf: Buffer, length: int) -> bytes pull_uint32(buf: Buffer) -> int at: aioquic.buffer.Buffer eof() -> bool tell() -> int at: aioquic.connection get_epoch(packet_type: int) -> tls.Epoch at: aioquic.connection.PacketSpace.__init__ self.crypto = CryptoPair() at: aioquic.connection.QuicConnection supported_versions = [ QuicProtocolVersion.DRAFT_17, QuicProtocolVersion.DRAFT_18, QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20, ] _initialize(peer_cid: bytes) -> None _push_crypto_data() -> None _push_crypto_data(self) -> None _send_pending(self) -> None _send_pending() -> None at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.version = max(self.supported_versions) self.__initialized = False self.__logger = logger self.__transport: Optional[asyncio.DatagramTransport] = None at: aioquic.connection.QuicConnection._initialize self.tls = tls.Context(is_client=self.is_client, logger=self.__logger) self.send_buffer = { tls.Epoch.INITIAL: Buffer(capacity=4096), tls.Epoch.HANDSHAKE: Buffer(capacity=4096), tls.Epoch.ONE_RTT: Buffer(capacity=4096), } ===========unchanged ref 1=========== self.spaces = { tls.Epoch.INITIAL: PacketSpace(), tls.Epoch.HANDSHAKE: PacketSpace(), tls.Epoch.ONE_RTT: PacketSpace(), } self.__initialized = True at: aioquic.crypto CryptoError(*args: object) at: aioquic.crypto.CryptoContext is_valid() -> bool at: aioquic.crypto.CryptoPair decrypt_packet(packet: bytes, encrypted_offset: int) -> Tuple[bytes, bytes, int] at: aioquic.crypto.CryptoPair.__init__ self.recv = CryptoContext() at: aioquic.packet PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int) QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) pull_quic_header(buf: Buffer, host_cid_length: Optional[int]=None) -> QuicHeader at: aioquic.packet.QuicHeader version: Optional[int] packet_type: int destination_cid: bytes source_cid: bytes original_destination_cid: bytes = b"" token: bytes = b"" rest_length: int = 0 at: aioquic.stream.QuicStream.__init__ self.reader = asyncio.StreamReader() self.reader = None at: aioquic.tls.Context handle_message(input_data: bytes, output_buf: Dict[Epoch, Buffer]) -> None at: asyncio.streams.StreamReader _source_traceback = None feed_eof() -> None at: asyncio.transports DatagramTransport(extra: Optional[Mapping[Any, Any]]=...) ===========unchanged ref 2=========== at: logging.Logger info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None warning(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None error(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def create_stream( self, is_unidirectional: bool = False ) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]: """ Create a QUIC stream and return a pair of (reader, writer) objects. The returned reader and writer objects are instances of :class:`asyncio.StreamReader` and :class:`asyncio.StreamWriter` classes. """ stream_id = (int(is_unidirectional) << 1) | int(not self.is_client) while stream_id in self.streams: stream_id += 4 + if is_unidirectional: + max_stream_data_local = 0 + max_stream_data_remote = self._remote_max_stream_data_uni + else: + max_stream_data_local = self._local_max_stream_data_bidi_local + max_stream_data_remote = self._remote_max_stream_data_bidi_remote + # create stream stream = self.streams[stream_id] = QuicStream( + connection=self, + stream_id=stream_id, - connection=self, stream_id=stream_id + max_stream_data_local=max_stream_data_local, + max_stream_data_remote=max_stream_data_remote, ) self.stream_created_cb(stream.reader, stream.writer) return stream.reader, stream.writer
aioquic.connection/QuicConnection._get_or_create_stream
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<13>:<add> # determine limits <del> # check max streams <15>:<add> max_stream_data_local = self._local_max_stream_data_uni <add> max_stream_data_remote = 0 <17>:<add> max_stream_data_local = self._local_max_stream_data_bidi_remote <add> max_stream_data_remote = self._remote_max_stream_data_bidi_local <18>:<add> <add> # check max streams <27>:<add> connection=self, <add> stream_id=stream_id, <del> connection=self, stream_id=stream_id <28>:<add> max_stream_data_local=max_stream_data_local, <add> max_stream_data_remote=max_stream_data_remote,
# module: aioquic.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> # check max streams <14> if stream_is_unidirectional(stream_id): <15> max_streams = self._local_max_streams_uni <16> else: <17> max_streams = self._local_max_streams_bidi <18> if stream_id // 4 >= max_streams: <19> raise QuicConnectionError( <20> error_code=QuicErrorCode.STREAM_LIMIT_ERROR, <21> frame_type=frame_type, <22> reason_phrase="Too many streams open", <23> ) <24> <25> # create stream <26> stream = self.streams[stream_id] = QuicStream( <27> connection=self, stream_id=stream_id <28> ) <29> self.stream_created_cb(stream.reader, stream.writer) <30> return stream <31>
===========unchanged ref 0=========== at: aioquic.connection stream_is_client_initiated(stream_id: int) -> bool QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: aioquic.connection.QuicConnection _stream_can_receive(stream_id: int) -> bool _stream_can_send(stream_id: int) -> bool at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} at: aioquic.packet QuicErrorCode(x: Union[str, bytes, bytearray], base: int) QuicErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) at: aioquic.stream QuicStream(stream_id: Optional[int]=None, connection: Optional[Any]=None, max_stream_data_local: int=0, max_stream_data_remote: int=0) 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.connection class QuicConnection: def create_stream( self, is_unidirectional: bool = False ) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]: """ Create a QUIC stream and return a pair of (reader, writer) objects. The returned reader and writer objects are instances of :class:`asyncio.StreamReader` and :class:`asyncio.StreamWriter` classes. """ stream_id = (int(is_unidirectional) << 1) | int(not self.is_client) while stream_id in self.streams: stream_id += 4 + if is_unidirectional: + max_stream_data_local = 0 + max_stream_data_remote = self._remote_max_stream_data_uni + else: + max_stream_data_local = self._local_max_stream_data_bidi_local + max_stream_data_remote = self._remote_max_stream_data_bidi_remote + # create stream stream = self.streams[stream_id] = QuicStream( + connection=self, + stream_id=stream_id, - connection=self, stream_id=stream_id + max_stream_data_local=max_stream_data_local, + max_stream_data_remote=max_stream_data_remote, ) self.stream_created_cb(stream.reader, stream.writer) return stream.reader, stream.writer ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: """ Handle an incoming datagram. """ buf = Buffer(data=data) while not buf.eof(): start_off = buf.tell() header = pull_quic_header(buf, host_cid_length=len(self.host_cid)) if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION: # version negotiation versions = [] while not buf.eof(): versions.append(pull_uint32(buf)) common = set(self.supported_versions).intersection(versions) if not common: self.__logger.error("Could not find a common protocol version") return self.version = QuicProtocolVersion(max(common)) + self.__logger.info("Retrying with %s", self.version) - self.__logger.info("Retrying with %s" % self.version) self.connection_made(self.__transport) return elif self.is_client and header.packet_type == PACKET_TYPE_RETRY: # stateless retry if ( header.destination_cid == self.host_cid and header.original_destination_cid == self.peer_cid ): self.__logger.info("Performing stateless retry") self.peer_cid = header.source_cid self.peer_token = header.token self.connection_made(self.__transport) return # server initialization if not self.is_client and not self.__initialized: assert ( header.packet_type == PACKET_TYPE_INITIAL ), "first packet must be INITIAL" self._initialize(header.destination_cid) # decrypt packet encrypted_off = buf.tell() - start_off end_off = buf.tell() + header.rest_length pull_bytes(buf, header.rest_length) epoch = get</s> ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 1 <s>.tell() + header.rest_length pull_bytes(buf, header.rest_length) epoch = get_epoch(header.packet_type) space = self.spaces[epoch] if not space.crypto.recv.is_valid(): return try: plain_header, plain_payload, packet_number = space.crypto.decrypt_packet( data[start_off:end_off], encrypted_off ) except CryptoError as exc: self.__logger.warning(exc) return if not self.peer_cid_set: self.peer_cid = header.source_cid self.peer_cid_set = True # handle payload try: is_ack_only = self._payload_received(epoch, plain_payload) except QuicConnectionError as exc: self.__logger.warning(exc) self.close( error_code=exc.error_code, frame_type=exc.frame_type, reason_phrase=exc.reason_phrase, ) return # record packet as received space.ack_queue.add(packet_number) if not is_ack_only: self.send_ack[epoch] = True self._send_pending()
aioquic.connection/QuicConnection._handle_connection_close_frame
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<8>:<add> "Connection close code 0x%X, reason %s", error_code, reason_phrase <del> "Connection close code 0x%X, reason %s" % (error_code, reason_phrase)
# module: aioquic.connection class QuicConnection: def _handle_connection_close_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: <0> """ <1> Handle a CONNECTION_CLOSE frame. <2> """ <3> if frame_type == QuicFrameType.TRANSPORT_CLOSE: <4> error_code, _, reason_phrase = packet.pull_transport_close_frame(buf) <5> else: <6> error_code, reason_phrase = packet.pull_application_close_frame(buf) <7> self.__logger.info( <8> "Connection close code 0x%X, reason %s" % (error_code, reason_phrase) <9> ) <10> self.connection_lost(None) <11>
===========unchanged ref 0=========== at: aioquic.connection PacketSpace() at: aioquic.connection.PacketSpace.__init__ self.crypto = CryptoPair() at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} at: aioquic.crypto.CryptoPair setup_initial(cid: bytes, is_client: bool) -> None at: aioquic.stream QuicStream(stream_id: Optional[int]=None, connection: Optional[Any]=None, max_stream_data_local: int=0, max_stream_data_remote: int=0) at: aioquic.tls Epoch() ===========changed ref 0=========== # module: aioquic.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 - # check max streams 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 if stream_id // 4 >= max_streams: raise QuicConnectionError( error_code=QuicErrorCode.STREAM_LIMIT_ERROR, frame_type=frame_type, reason_phrase="Too many streams open", ) # create stream stream = self.streams[stream_id] = QuicStream( + connection=self, + stream_id=stream_id, - connection=self, stream_id=stream_id + max_stream_data_local=max_stream_data_local, + max_stream_data_remote=max_stream_data_remote, ) self.stream_created_cb(stream.reader, stream.writer) return stream ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def create_stream( self, is_unidirectional: bool = False ) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]: """ Create a QUIC stream and return a pair of (reader, writer) objects. The returned reader and writer objects are instances of :class:`asyncio.StreamReader` and :class:`asyncio.StreamWriter` classes. """ stream_id = (int(is_unidirectional) << 1) | int(not self.is_client) while stream_id in self.streams: stream_id += 4 + if is_unidirectional: + max_stream_data_local = 0 + max_stream_data_remote = self._remote_max_stream_data_uni + else: + max_stream_data_local = self._local_max_stream_data_bidi_local + max_stream_data_remote = self._remote_max_stream_data_bidi_remote + # create stream stream = self.streams[stream_id] = QuicStream( + connection=self, + stream_id=stream_id, - connection=self, stream_id=stream_id + max_stream_data_local=max_stream_data_local, + max_stream_data_remote=max_stream_data_remote, ) self.stream_created_cb(stream.reader, stream.writer) return stream.reader, stream.writer ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: """ Handle an incoming datagram. """ buf = Buffer(data=data) while not buf.eof(): start_off = buf.tell() header = pull_quic_header(buf, host_cid_length=len(self.host_cid)) if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION: # version negotiation versions = [] while not buf.eof(): versions.append(pull_uint32(buf)) common = set(self.supported_versions).intersection(versions) if not common: self.__logger.error("Could not find a common protocol version") return self.version = QuicProtocolVersion(max(common)) + self.__logger.info("Retrying with %s", self.version) - self.__logger.info("Retrying with %s" % self.version) self.connection_made(self.__transport) return elif self.is_client and header.packet_type == PACKET_TYPE_RETRY: # stateless retry if ( header.destination_cid == self.host_cid and header.original_destination_cid == self.peer_cid ): self.__logger.info("Performing stateless retry") self.peer_cid = header.source_cid self.peer_token = header.token self.connection_made(self.__transport) return # server initialization if not self.is_client and not self.__initialized: assert ( header.packet_type == PACKET_TYPE_INITIAL ), "first packet must be INITIAL" self._initialize(header.destination_cid) # decrypt packet encrypted_off = buf.tell() - start_off end_off = buf.tell() + header.rest_length pull_bytes(buf, header.rest_length) epoch = get</s> ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 1 <s>.tell() + header.rest_length pull_bytes(buf, header.rest_length) epoch = get_epoch(header.packet_type) space = self.spaces[epoch] if not space.crypto.recv.is_valid(): return try: plain_header, plain_payload, packet_number = space.crypto.decrypt_packet( data[start_off:end_off], encrypted_off ) except CryptoError as exc: self.__logger.warning(exc) return if not self.peer_cid_set: self.peer_cid = header.source_cid self.peer_cid_set = True # handle payload try: is_ack_only = self._payload_received(epoch, plain_payload) except QuicConnectionError as exc: self.__logger.warning(exc) self.close( error_code=exc.error_code, frame_type=exc.frame_type, reason_phrase=exc.reason_phrase, ) return # record packet as received space.ack_queue.add(packet_number) if not is_ack_only: self.send_ack[epoch] = True self._send_pending()
aioquic.connection/QuicConnection._handle_max_data_frame
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<5>:<add> max_data = pull_uint_var(buf) <add> if max_data > self._remote_max_data: <add> self.__logger.info("Remote max_data raised to %d", max_data) <add> self._remote_max_data = max_data <del> pull_uint_var(buf) # limit
# module: aioquic.connection class QuicConnection: def _handle_max_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: <0> """ <1> Handle a MAX_DATA frame. <2> <3> This adjusts the total amount of we can send to the peer. <4> """ <5> pull_uint_var(buf) # limit <6>
===========unchanged ref 0=========== at: aioquic.connection.QuicConnection.__init__ self.__connected = asyncio.Event() at: aioquic.connection.QuicConnection._initialize self.tls = tls.Context(is_client=self.is_client, logger=self.__logger) at: aioquic.tls State() at: aioquic.tls.Context.__init__ self.state = State.CLIENT_HANDSHAKE_START self.state = State.SERVER_EXPECT_CLIENT_HELLO at: aioquic.tls.Context._set_state self.state = state at: asyncio.locks.Event is_set() -> bool ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def _handle_connection_close_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a CONNECTION_CLOSE frame. """ if frame_type == QuicFrameType.TRANSPORT_CLOSE: error_code, _, reason_phrase = packet.pull_transport_close_frame(buf) else: error_code, reason_phrase = packet.pull_application_close_frame(buf) self.__logger.info( + "Connection close code 0x%X, reason %s", error_code, reason_phrase - "Connection close code 0x%X, reason %s" % (error_code, reason_phrase) ) self.connection_lost(None) ===========changed ref 1=========== # module: aioquic.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 - # check max streams 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 if stream_id // 4 >= max_streams: raise QuicConnectionError( error_code=QuicErrorCode.STREAM_LIMIT_ERROR, frame_type=frame_type, reason_phrase="Too many streams open", ) # create stream stream = self.streams[stream_id] = QuicStream( + connection=self, + stream_id=stream_id, - connection=self, stream_id=stream_id + max_stream_data_local=max_stream_data_local, + max_stream_data_remote=max_stream_data_remote, ) self.stream_created_cb(stream.reader, stream.writer) return stream ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def create_stream( self, is_unidirectional: bool = False ) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]: """ Create a QUIC stream and return a pair of (reader, writer) objects. The returned reader and writer objects are instances of :class:`asyncio.StreamReader` and :class:`asyncio.StreamWriter` classes. """ stream_id = (int(is_unidirectional) << 1) | int(not self.is_client) while stream_id in self.streams: stream_id += 4 + if is_unidirectional: + max_stream_data_local = 0 + max_stream_data_remote = self._remote_max_stream_data_uni + else: + max_stream_data_local = self._local_max_stream_data_bidi_local + max_stream_data_remote = self._remote_max_stream_data_bidi_remote + # create stream stream = self.streams[stream_id] = QuicStream( + connection=self, + stream_id=stream_id, - connection=self, stream_id=stream_id + max_stream_data_local=max_stream_data_local, + max_stream_data_remote=max_stream_data_remote, ) self.stream_created_cb(stream.reader, stream.writer) return stream.reader, stream.writer ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: """ Handle an incoming datagram. """ buf = Buffer(data=data) while not buf.eof(): start_off = buf.tell() header = pull_quic_header(buf, host_cid_length=len(self.host_cid)) if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION: # version negotiation versions = [] while not buf.eof(): versions.append(pull_uint32(buf)) common = set(self.supported_versions).intersection(versions) if not common: self.__logger.error("Could not find a common protocol version") return self.version = QuicProtocolVersion(max(common)) + self.__logger.info("Retrying with %s", self.version) - self.__logger.info("Retrying with %s" % self.version) self.connection_made(self.__transport) return elif self.is_client and header.packet_type == PACKET_TYPE_RETRY: # stateless retry if ( header.destination_cid == self.host_cid and header.original_destination_cid == self.peer_cid ): self.__logger.info("Performing stateless retry") self.peer_cid = header.source_cid self.peer_token = header.token self.connection_made(self.__transport) return # server initialization if not self.is_client and not self.__initialized: assert ( header.packet_type == PACKET_TYPE_INITIAL ), "first packet must be INITIAL" self._initialize(header.destination_cid) # decrypt packet encrypted_off = buf.tell() - start_off end_off = buf.tell() + header.rest_length pull_bytes(buf, header.rest_length) epoch = get</s>
aioquic.connection/QuicConnection._handle_max_stream_data_frame
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<6>:<add> max_stream_data = pull_uint_var(buf) <del> pull_uint_var(buf) # limit <11>:<add> stream = self._get_or_create_stream(frame_type, stream_id) <del> self._get_or_create_stream(frame_type, stream_id) <12>:<add> if max_stream_data > stream.max_stream_data_remote: <add> self.__logger.info( <add> "Stream %d remote max_stream_data raised to %d", <add> stream_id, <add> max_stream_data, <add> ) <add> stream.max_stream_data_remote = max_stream_data
# module: aioquic.connection class QuicConnection: def _handle_max_stream_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: <0> """ <1> Handle a MAX_STREAM_DATA frame. <2> <3> This adjusts the amount of data we can send on a specific stream. <4> """ <5> stream_id = pull_uint_var(buf) <6> pull_uint_var(buf) # limit <7> <8> # check stream direction <9> self._assert_stream_can_send(frame_type, stream_id) <10> <11> self._get_or_create_stream(frame_type, stream_id) <12>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.connection.QuicConnection _parse_transport_parameters(self, data: bytes) -> None _parse_transport_parameters(data: bytes) -> None at: aioquic.connection.QuicConnection.__init__ self.__connected = asyncio.Event() self.__epoch = tls.Epoch.INITIAL at: aioquic.connection.QuicConnection._initialize self.tls = tls.Context(is_client=self.is_client, logger=self.__logger) at: aioquic.tls Epoch() ExtensionType(x: Union[str, bytes, bytearray], base: int) ExtensionType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) at: aioquic.tls.Context.__init__ self.received_extensions: List[Extension] = [] at: aioquic.tls.Context._client_handle_encrypted_extensions self.received_extensions = encrypted_extensions.other_extensions at: aioquic.tls.Context._server_handle_hello self.received_extensions = peer_hello.other_extensions at: asyncio.locks.Event set() -> None ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def _handle_max_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_DATA frame. This adjusts the total amount of we can send to the peer. """ + max_data = pull_uint_var(buf) + if max_data > self._remote_max_data: + self.__logger.info("Remote max_data raised to %d", max_data) + self._remote_max_data = max_data - pull_uint_var(buf) # limit ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def _handle_connection_close_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a CONNECTION_CLOSE frame. """ if frame_type == QuicFrameType.TRANSPORT_CLOSE: error_code, _, reason_phrase = packet.pull_transport_close_frame(buf) else: error_code, reason_phrase = packet.pull_application_close_frame(buf) self.__logger.info( + "Connection close code 0x%X, reason %s", error_code, reason_phrase - "Connection close code 0x%X, reason %s" % (error_code, reason_phrase) ) self.connection_lost(None) ===========changed ref 2=========== # module: aioquic.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 - # check max streams 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 if stream_id // 4 >= max_streams: raise QuicConnectionError( error_code=QuicErrorCode.STREAM_LIMIT_ERROR, frame_type=frame_type, reason_phrase="Too many streams open", ) # create stream stream = self.streams[stream_id] = QuicStream( + connection=self, + stream_id=stream_id, - connection=self, stream_id=stream_id + max_stream_data_local=max_stream_data_local, + max_stream_data_remote=max_stream_data_remote, ) self.stream_created_cb(stream.reader, stream.writer) return stream ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def create_stream( self, is_unidirectional: bool = False ) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]: """ Create a QUIC stream and return a pair of (reader, writer) objects. The returned reader and writer objects are instances of :class:`asyncio.StreamReader` and :class:`asyncio.StreamWriter` classes. """ stream_id = (int(is_unidirectional) << 1) | int(not self.is_client) while stream_id in self.streams: stream_id += 4 + if is_unidirectional: + max_stream_data_local = 0 + max_stream_data_remote = self._remote_max_stream_data_uni + else: + max_stream_data_local = self._local_max_stream_data_bidi_local + max_stream_data_remote = self._remote_max_stream_data_bidi_remote + # create stream stream = self.streams[stream_id] = QuicStream( + connection=self, + stream_id=stream_id, - connection=self, stream_id=stream_id + max_stream_data_local=max_stream_data_local, + max_stream_data_remote=max_stream_data_remote, ) self.stream_created_cb(stream.reader, stream.writer) return stream.reader, stream.writer
aioquic.connection/QuicConnection._handle_max_streams_bidi_frame
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<7>:<add> self.__logger.info("Remote max_streams_bidi raised to %d", max_streams) <del> self.__logger.info("Remote max_streams_bidi raised to %d" % max_streams)
# module: aioquic.connection class QuicConnection: def _handle_max_streams_bidi_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: <0> """ <1> Handle a MAX_STREAMS_BIDI frame. <2> <3> This raises number of bidirectional streams we can initiate to the peer. <4> """ <5> max_streams = pull_uint_var(buf) <6> if max_streams > self._remote_max_streams_bidi: <7> self.__logger.info("Remote max_streams_bidi raised to %d" % max_streams) <8> self._remote_max_streams_bidi = max_streams <9>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.connection.QuicConnection.__init__ self.__logger = logger self._remote_max_data = 0 at: aioquic.connection.QuicConnection._handle_max_data_frame self._remote_max_data = max_data at: aioquic.packet pull_uint_var(buf: Buffer) -> int at: aioquic.tls Epoch() at: logging.Logger info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def _handle_max_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_DATA frame. This adjusts the total amount of we can send to the peer. """ + max_data = pull_uint_var(buf) + if max_data > self._remote_max_data: + self.__logger.info("Remote max_data raised to %d", max_data) + self._remote_max_data = max_data - pull_uint_var(buf) # limit ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def _handle_connection_close_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a CONNECTION_CLOSE frame. """ if frame_type == QuicFrameType.TRANSPORT_CLOSE: error_code, _, reason_phrase = packet.pull_transport_close_frame(buf) else: error_code, reason_phrase = packet.pull_application_close_frame(buf) self.__logger.info( + "Connection close code 0x%X, reason %s", error_code, reason_phrase - "Connection close code 0x%X, reason %s" % (error_code, reason_phrase) ) self.connection_lost(None) ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def _handle_max_stream_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAM_DATA frame. This adjusts the amount of data we can send on a specific stream. """ stream_id = pull_uint_var(buf) + max_stream_data = pull_uint_var(buf) - pull_uint_var(buf) # limit # check stream direction self._assert_stream_can_send(frame_type, stream_id) + stream = self._get_or_create_stream(frame_type, stream_id) - self._get_or_create_stream(frame_type, stream_id) + if max_stream_data > stream.max_stream_data_remote: + self.__logger.info( + "Stream %d remote max_stream_data raised to %d", + stream_id, + max_stream_data, + ) + stream.max_stream_data_remote = max_stream_data ===========changed ref 3=========== # module: aioquic.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 - # check max streams 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 if stream_id // 4 >= max_streams: raise QuicConnectionError( error_code=QuicErrorCode.STREAM_LIMIT_ERROR, frame_type=frame_type, reason_phrase="Too many streams open", ) # create stream stream = self.streams[stream_id] = QuicStream( + connection=self, + stream_id=stream_id, - connection=self, stream_id=stream_id + max_stream_data_local=max_stream_data_local, + max_stream_data_remote=max_stream_data_remote, ) self.stream_created_cb(stream.reader, stream.writer) return stream ===========changed ref 4=========== # module: aioquic.connection class QuicConnection: def create_stream( self, is_unidirectional: bool = False ) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]: """ Create a QUIC stream and return a pair of (reader, writer) objects. The returned reader and writer objects are instances of :class:`asyncio.StreamReader` and :class:`asyncio.StreamWriter` classes. """ stream_id = (int(is_unidirectional) << 1) | int(not self.is_client) while stream_id in self.streams: stream_id += 4 + if is_unidirectional: + max_stream_data_local = 0 + max_stream_data_remote = self._remote_max_stream_data_uni + else: + max_stream_data_local = self._local_max_stream_data_bidi_local + max_stream_data_remote = self._remote_max_stream_data_bidi_remote + # create stream stream = self.streams[stream_id] = QuicStream( + connection=self, + stream_id=stream_id, - connection=self, stream_id=stream_id + max_stream_data_local=max_stream_data_local, + max_stream_data_remote=max_stream_data_remote, ) self.stream_created_cb(stream.reader, stream.writer) return stream.reader, stream.writer
aioquic.connection/QuicConnection._handle_max_streams_uni_frame
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<7>:<add> self.__logger.info("Remote max_streams_uni raised to %d", max_streams) <del> self.__logger.info("Remote max_streams_uni raised to %d" % max_streams)
# module: aioquic.connection class QuicConnection: def _handle_max_streams_uni_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: <0> """ <1> Handle a MAX_STREAMS_UNI frame. <2> <3> This raises number of unidirectional streams we can initiate to the peer. <4> """ <5> max_streams = pull_uint_var(buf) <6> if max_streams > self._remote_max_streams_uni: <7> self.__logger.info("Remote max_streams_uni raised to %d" % max_streams) <8> self._remote_max_streams_uni = max_streams <9>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.packet pull_uint_var(buf: Buffer) -> int at: aioquic.tls Epoch() ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def _handle_max_streams_bidi_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAMS_BIDI frame. This raises number of bidirectional streams we can initiate to the peer. """ max_streams = pull_uint_var(buf) if max_streams > self._remote_max_streams_bidi: + self.__logger.info("Remote max_streams_bidi raised to %d", max_streams) - self.__logger.info("Remote max_streams_bidi raised to %d" % max_streams) self._remote_max_streams_bidi = max_streams ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def _handle_max_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_DATA frame. This adjusts the total amount of we can send to the peer. """ + max_data = pull_uint_var(buf) + if max_data > self._remote_max_data: + self.__logger.info("Remote max_data raised to %d", max_data) + self._remote_max_data = max_data - pull_uint_var(buf) # limit ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def _handle_connection_close_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a CONNECTION_CLOSE frame. """ if frame_type == QuicFrameType.TRANSPORT_CLOSE: error_code, _, reason_phrase = packet.pull_transport_close_frame(buf) else: error_code, reason_phrase = packet.pull_application_close_frame(buf) self.__logger.info( + "Connection close code 0x%X, reason %s", error_code, reason_phrase - "Connection close code 0x%X, reason %s" % (error_code, reason_phrase) ) self.connection_lost(None) ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def _handle_max_stream_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAM_DATA frame. This adjusts the amount of data we can send on a specific stream. """ stream_id = pull_uint_var(buf) + max_stream_data = pull_uint_var(buf) - pull_uint_var(buf) # limit # check stream direction self._assert_stream_can_send(frame_type, stream_id) + stream = self._get_or_create_stream(frame_type, stream_id) - self._get_or_create_stream(frame_type, stream_id) + if max_stream_data > stream.max_stream_data_remote: + self.__logger.info( + "Stream %d remote max_stream_data raised to %d", + stream_id, + max_stream_data, + ) + stream.max_stream_data_remote = max_stream_data ===========changed ref 4=========== # module: aioquic.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 - # check max streams 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 if stream_id // 4 >= max_streams: raise QuicConnectionError( error_code=QuicErrorCode.STREAM_LIMIT_ERROR, frame_type=frame_type, reason_phrase="Too many streams open", ) # create stream stream = self.streams[stream_id] = QuicStream( + connection=self, + stream_id=stream_id, - connection=self, stream_id=stream_id + max_stream_data_local=max_stream_data_local, + max_stream_data_remote=max_stream_data_remote, ) self.stream_created_cb(stream.reader, stream.writer) return stream ===========changed ref 5=========== # module: aioquic.connection class QuicConnection: def create_stream( self, is_unidirectional: bool = False ) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]: """ Create a QUIC stream and return a pair of (reader, writer) objects. The returned reader and writer objects are instances of :class:`asyncio.StreamReader` and :class:`asyncio.StreamWriter` classes. """ stream_id = (int(is_unidirectional) << 1) | int(not self.is_client) while stream_id in self.streams: stream_id += 4 + if is_unidirectional: + max_stream_data_local = 0 + max_stream_data_remote = self._remote_max_stream_data_uni + else: + max_stream_data_local = self._local_max_stream_data_bidi_local + max_stream_data_remote = self._remote_max_stream_data_bidi_remote + # create stream stream = self.streams[stream_id] = QuicStream( + connection=self, + stream_id=stream_id, - connection=self, stream_id=stream_id + max_stream_data_local=max_stream_data_local, + max_stream_data_remote=max_stream_data_remote, ) self.stream_created_cb(stream.reader, stream.writer) return stream.reader, stream.writer
aioquic.connection/QuicConnection._handle_stream_frame
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<22>:<add> # check limits <23>:<add> if offset + length > stream.max_stream_data_local: <add> raise QuicConnectionError( <add> error_code=QuicErrorCode.FLOW_CONTROL_ERROR, <add> frame_type=frame_type, <add> reason_phrase="Over stream data limit", <add> )
# module: aioquic.connection class QuicConnection: def _handle_stream_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: <0> """ <1> Handle a STREAM frame. <2> """ <3> flags = frame_type & STREAM_FLAGS <4> stream_id = pull_uint_var(buf) <5> if flags & QuicStreamFlag.OFF: <6> offset = pull_uint_var(buf) <7> else: <8> offset = 0 <9> if flags & QuicStreamFlag.LEN: <10> length = pull_uint_var(buf) <11> else: <12> length = buf.capacity - buf.tell() <13> frame = QuicStreamFrame( <14> offset=offset, <15> data=pull_bytes(buf, length), <16> fin=bool(flags & QuicStreamFlag.FIN), <17> ) <18> <19> # check stream direction <20> self._assert_stream_can_receive(frame_type, stream_id) <21> <22> stream = self._get_or_create_stream(frame_type, stream_id) <23> stream.add_frame(frame) <24>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) pull_uint16(buf: Buffer) -> int at: aioquic.connection.QuicConnection _assert_stream_can_receive(frame_type: int, stream_id: int) -> None _get_or_create_stream(frame_type: int, stream_id: int) -> QuicStream _get_or_create_stream(self, frame_type: int, stream_id: int) -> QuicStream at: aioquic.packet pull_uint_var(buf: Buffer) -> int at: aioquic.tls Epoch() ===========changed ref 0=========== # module: aioquic.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 - # check max streams 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 if stream_id // 4 >= max_streams: raise QuicConnectionError( error_code=QuicErrorCode.STREAM_LIMIT_ERROR, frame_type=frame_type, reason_phrase="Too many streams open", ) # create stream stream = self.streams[stream_id] = QuicStream( + connection=self, + stream_id=stream_id, - connection=self, stream_id=stream_id + max_stream_data_local=max_stream_data_local, + max_stream_data_remote=max_stream_data_remote, ) self.stream_created_cb(stream.reader, stream.writer) return stream ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def _handle_max_streams_uni_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAMS_UNI frame. This raises number of unidirectional streams we can initiate to the peer. """ max_streams = pull_uint_var(buf) if max_streams > self._remote_max_streams_uni: + self.__logger.info("Remote max_streams_uni raised to %d", max_streams) - self.__logger.info("Remote max_streams_uni raised to %d" % max_streams) self._remote_max_streams_uni = max_streams ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def _handle_max_streams_bidi_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAMS_BIDI frame. This raises number of bidirectional streams we can initiate to the peer. """ max_streams = pull_uint_var(buf) if max_streams > self._remote_max_streams_bidi: + self.__logger.info("Remote max_streams_bidi raised to %d", max_streams) - self.__logger.info("Remote max_streams_bidi raised to %d" % max_streams) self._remote_max_streams_bidi = max_streams ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def _handle_max_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_DATA frame. This adjusts the total amount of we can send to the peer. """ + max_data = pull_uint_var(buf) + if max_data > self._remote_max_data: + self.__logger.info("Remote max_data raised to %d", max_data) + self._remote_max_data = max_data - pull_uint_var(buf) # limit ===========changed ref 4=========== # module: aioquic.connection class QuicConnection: def _handle_connection_close_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a CONNECTION_CLOSE frame. """ if frame_type == QuicFrameType.TRANSPORT_CLOSE: error_code, _, reason_phrase = packet.pull_transport_close_frame(buf) else: error_code, reason_phrase = packet.pull_application_close_frame(buf) self.__logger.info( + "Connection close code 0x%X, reason %s", error_code, reason_phrase - "Connection close code 0x%X, reason %s" % (error_code, reason_phrase) ) self.connection_lost(None) ===========changed ref 5=========== # module: aioquic.connection class QuicConnection: def _handle_max_stream_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAM_DATA frame. This adjusts the amount of data we can send on a specific stream. """ stream_id = pull_uint_var(buf) + max_stream_data = pull_uint_var(buf) - pull_uint_var(buf) # limit # check stream direction self._assert_stream_can_send(frame_type, stream_id) + stream = self._get_or_create_stream(frame_type, stream_id) - self._get_or_create_stream(frame_type, stream_id) + if max_stream_data > stream.max_stream_data_remote: + self.__logger.info( + "Stream %d remote max_stream_data raised to %d", + stream_id, + max_stream_data, + ) + stream.max_stream_data_remote = max_stream_data
aioquic.connection/QuicConnection._parse_transport_parameters
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<7>:<add> <add> # store remote parameters <14>:<add> for param in [ <add> "max_data", <add> "max_stream_data_bidi_local", <add> "max_stream_data_bidi_remote", <add> "max_stream_data_uni", <add> "max_streams_bidi", <add> "max_streams_uni", <add> ]: <add> value = getattr(quic_transport_parameters, "initial_" + param) <add> if value is not None: <add> setattr(self, "_remote_" + param, value) <del> if quic_transport_parameters.initial_max_streams_bidi is not None: <15>:<del> self._remote_max_streams_bidi = ( <16>:<del> quic_transport_parameters.initial_max_streams_bidi <17>:<del> ) <18>:<del> if quic_transport_parameters.initial_max_streams_uni is not None: <19>:<del> self._remote_max_streams_uni = ( <20>:<del> quic_transport_parameters.initial_max_streams_uni <21>:<del> )
# module: aioquic.connection class QuicConnection: def _parse_transport_parameters(self, data: bytes) -> None: <0> if self.version >= QuicProtocolVersion.DRAFT_19: <1> is_client = None <2> else: <3> is_client = not self.is_client <4> quic_transport_parameters = pull_quic_transport_parameters( <5> Buffer(data=data), is_client=is_client <6> ) <7> if quic_transport_parameters.idle_timeout is not None: <8> if self.version >= QuicProtocolVersion.DRAFT_19: <9> self._remote_idle_timeout = ( <10> quic_transport_parameters.idle_timeout / 1000 <11> ) <12> else: <13> self._remote_idle_timeout = quic_transport_parameters.idle_timeout <14> if quic_transport_parameters.initial_max_streams_bidi is not None: <15> self._remote_max_streams_bidi = ( <16> quic_transport_parameters.initial_max_streams_bidi <17> ) <18> if quic_transport_parameters.initial_max_streams_uni is not None: <19> self._remote_max_streams_uni = ( <20> quic_transport_parameters.initial_max_streams_uni <21> ) <22>
===========unchanged ref 0=========== at: aioquic.buffer.Buffer eof() -> bool at: aioquic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: aioquic.connection.QuicConnection _push_crypto_data() -> None _push_crypto_data(self) -> None at: aioquic.connection.QuicConnection.__init__ self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ] at: aioquic.connection.QuicConnection._payload_received buf = Buffer(data=plain) ===========unchanged ref 1=========== at: aioquic.packet QuicErrorCode(x: Union[str, bytes, bytearray], base: int) QuicErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) pull_uint_var(buf: Buffer) -> int QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) at: typing Iterator = _alias(collections.abc.Iterator, 1) ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def _handle_max_streams_uni_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAMS_UNI frame. This raises number of unidirectional streams we can initiate to the peer. """ max_streams = pull_uint_var(buf) if max_streams > self._remote_max_streams_uni: + self.__logger.info("Remote max_streams_uni raised to %d", max_streams) - self.__logger.info("Remote max_streams_uni raised to %d" % max_streams) self._remote_max_streams_uni = max_streams ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def _handle_max_streams_bidi_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAMS_BIDI frame. This raises number of bidirectional streams we can initiate to the peer. """ max_streams = pull_uint_var(buf) if max_streams > self._remote_max_streams_bidi: + self.__logger.info("Remote max_streams_bidi raised to %d", max_streams) - self.__logger.info("Remote max_streams_bidi raised to %d" % max_streams) self._remote_max_streams_bidi = max_streams ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def _handle_max_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_DATA frame. This adjusts the total amount of we can send to the peer. """ + max_data = pull_uint_var(buf) + if max_data > self._remote_max_data: + self.__logger.info("Remote max_data raised to %d", max_data) + self._remote_max_data = max_data - pull_uint_var(buf) # limit ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def _handle_stream_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a STREAM frame. """ flags = frame_type & STREAM_FLAGS stream_id = pull_uint_var(buf) if flags & QuicStreamFlag.OFF: offset = pull_uint_var(buf) else: offset = 0 if flags & QuicStreamFlag.LEN: length = pull_uint_var(buf) else: length = buf.capacity - buf.tell() frame = QuicStreamFrame( offset=offset, data=pull_bytes(buf, length), fin=bool(flags & QuicStreamFlag.FIN), ) # check stream direction self._assert_stream_can_receive(frame_type, stream_id) + # check 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", + ) stream.add_frame(frame) ===========changed ref 4=========== # module: aioquic.connection class QuicConnection: def _handle_connection_close_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a CONNECTION_CLOSE frame. """ if frame_type == QuicFrameType.TRANSPORT_CLOSE: error_code, _, reason_phrase = packet.pull_transport_close_frame(buf) else: error_code, reason_phrase = packet.pull_application_close_frame(buf) self.__logger.info( + "Connection close code 0x%X, reason %s", error_code, reason_phrase - "Connection close code 0x%X, reason %s" % (error_code, reason_phrase) ) self.connection_lost(None)
aioquic.connection/QuicConnection._serialize_transport_parameters
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<1>:<add> initial_max_data=self._local_max_data, <add> initial_max_stream_data_bidi_local=self._local_max_stream_data_bidi_local, <add> initial_max_stream_data_bidi_remote=self._local_max_stream_data_bidi_remote, <add> initial_max_stream_data_uni=self._local_max_stream_data_uni, <del> initial_max_data=16777216, <2>:<del> initial_max_stream_data_bidi_local=1048576, <3>:<del> initial_max_stream_data_bidi_remote=1048576, <4>:<del> initial_max_stream_data_uni=1048576,
# module: aioquic.connection class QuicConnection: def _serialize_transport_parameters(self) -> bytes: <0> quic_transport_parameters = QuicTransportParameters( <1> initial_max_data=16777216, <2> initial_max_stream_data_bidi_local=1048576, <3> initial_max_stream_data_bidi_remote=1048576, <4> initial_max_stream_data_uni=1048576, <5> initial_max_streams_bidi=self._local_max_streams_bidi, <6> initial_max_streams_uni=self._local_max_streams_uni, <7> ack_delay_exponent=10, <8> ) <9> if self.version >= QuicProtocolVersion.DRAFT_19: <10> is_client = None <11> quic_transport_parameters.idle_timeout = int( <12> self._local_idle_timeout * 1000 <13> ) <14> else: <15> is_client = self.is_client <16> quic_transport_parameters.idle_timeout = int(self._local_idle_timeout) <17> if self.is_client: <18> quic_transport_parameters.initial_version = self.version <19> else: <20> quic_transport_parameters.negotiated_version = self.version <21> quic_transport_parameters.supported_versions = self.supported_versions <22> quic_transport_parameters.stateless_reset_token = bytes(16) <23> <24> buf = Buffer(capacity=512) <25> push_quic_transport_parameters( <26> buf, quic_transport_parameters, is_client=is_client <27> ) <28> return buf.data <29>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.buffer.Buffer seek(pos: int) -> None at: aioquic.connection.QuicConnection _pending_datagrams() -> Iterator[bytes] _pending_datagrams(self) -> Iterator[bytes] _write_application() -> Iterator[bytes] _write_handshake(epoch: tls.Epoch) -> Iterator[bytes] at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} self.version = max(self.supported_versions) self.__path_challenge: Optional[bytes] = None self._pending_flow_control: List[bytes] = [] self.__transport: Optional[asyncio.DatagramTransport] = None at: aioquic.connection.QuicConnection._initialize self.send_buffer = { tls.Epoch.INITIAL: Buffer(capacity=4096), tls.Epoch.HANDSHAKE: Buffer(capacity=4096), tls.Epoch.ONE_RTT: Buffer(capacity=4096), } at: aioquic.connection.QuicConnection._write_application self._pending_flow_control = [] at: aioquic.connection.QuicConnection.connection_made self.__transport = transport at: aioquic.connection.QuicConnection.datagram_received self.version = QuicProtocolVersion(max(common)) at: aioquic.packet QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int) QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) pull_quic_transport_parameters(buf: Buffer, is_client: Optional[bool]=None) -> QuicTransportParameters ===========unchanged ref 1=========== QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) at: aioquic.stream.QuicStream write(data: bytes) -> None at: asyncio.transports.DatagramTransport __slots__ = () sendto(data: Any, addr: Optional[_Address]=...) -> None at: os urandom(size: int, /) -> bytes ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def _handle_max_streams_uni_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAMS_UNI frame. This raises number of unidirectional streams we can initiate to the peer. """ max_streams = pull_uint_var(buf) if max_streams > self._remote_max_streams_uni: + self.__logger.info("Remote max_streams_uni raised to %d", max_streams) - self.__logger.info("Remote max_streams_uni raised to %d" % max_streams) self._remote_max_streams_uni = max_streams ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def _handle_max_streams_bidi_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAMS_BIDI frame. This raises number of bidirectional streams we can initiate to the peer. """ max_streams = pull_uint_var(buf) if max_streams > self._remote_max_streams_bidi: + self.__logger.info("Remote max_streams_bidi raised to %d", max_streams) - self.__logger.info("Remote max_streams_bidi raised to %d" % max_streams) self._remote_max_streams_bidi = max_streams ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def _handle_max_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_DATA frame. This adjusts the total amount of we can send to the peer. """ + max_data = pull_uint_var(buf) + if max_data > self._remote_max_data: + self.__logger.info("Remote max_data raised to %d", max_data) + self._remote_max_data = max_data - pull_uint_var(buf) # limit ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def _handle_stream_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a STREAM frame. """ flags = frame_type & STREAM_FLAGS stream_id = pull_uint_var(buf) if flags & QuicStreamFlag.OFF: offset = pull_uint_var(buf) else: offset = 0 if flags & QuicStreamFlag.LEN: length = pull_uint_var(buf) else: length = buf.capacity - buf.tell() frame = QuicStreamFrame( offset=offset, data=pull_bytes(buf, length), fin=bool(flags & QuicStreamFlag.FIN), ) # check stream direction self._assert_stream_can_receive(frame_type, stream_id) + # check 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", + ) stream.add_frame(frame) ===========changed ref 4=========== # module: aioquic.connection class QuicConnection: def _parse_transport_parameters(self, data: bytes) -> None: if self.version >= QuicProtocolVersion.DRAFT_19: is_client = None else: is_client = not self.is_client quic_transport_parameters = pull_quic_transport_parameters( Buffer(data=data), is_client=is_client ) + + # store remote parameters if quic_transport_parameters.idle_timeout is not None: if self.version >= QuicProtocolVersion.DRAFT_19: self._remote_idle_timeout = ( quic_transport_parameters.idle_timeout / 1000 ) else: self._remote_idle_timeout = quic_transport_parameters.idle_timeout + for param in [ + "max_data", + "max_stream_data_bidi_local", + "max_stream_data_bidi_remote", + "max_stream_data_uni", + "max_streams_bidi", + "max_streams_uni", + ]: + value = getattr(quic_transport_parameters, "initial_" + param) + if value is not None: + setattr(self, "_remote_" + param, value) - if quic_transport_parameters.initial_max_streams_bidi is not None: - self._remote_max_streams_bidi = ( - quic_transport_parameters.initial_max_streams_bidi - ) - if quic_transport_parameters.initial_max_streams_uni is not None: - self._remote_max_streams_uni = ( - quic_transport_parameters.initial_max_streams_uni - )
tests.test_connection/QuicConnectionTest.test_handle_max_data_frame
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<9>:<add> self.assertEqual(client._remote_max_data, 1048576) <10>:<add> # client receives MAX_DATA raising limit <add> client._handle_max_data_frame( <add> tls.Epoch.ONE_RTT, <add> QuicFrameType.MAX_DATA, <add> Buffer(data=encode_uint_var(1048577)), <add> ) <add> self.assertEqual(client._remote_max_data, 1048577) <del> # server sends MAX_DATA: 12345 <11>:<del> server._pending_flow_control.append(b"\x10\x70\x39") <12>:<del> server._send_pending()
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_max_data_frame(self): <0> client = QuicConnection(is_client=True) <1> server = QuicConnection( <2> is_client=False, <3> certificate=SERVER_CERTIFICATE, <4> private_key=SERVER_PRIVATE_KEY, <5> ) <6> <7> # perform handshake <8> client_transport, server_transport = create_transport(client, server) <9> <10> # server sends MAX_DATA: 12345 <11> server._pending_flow_control.append(b"\x10\x70\x39") <12> server._send_pending() <13>
===========unchanged ref 0=========== at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection supported_versions = [ QuicProtocolVersion.DRAFT_17, QuicProtocolVersion.DRAFT_18, QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20, ] _send_pending() -> None at: aioquic.connection.QuicConnection.__init__ self._pending_flow_control: List[bytes] = [] at: aioquic.connection.QuicConnection._write_application self._pending_flow_control = [] at: tests.test_connection SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) create_transport(client, server) at: tests.test_connection.QuicConnectionTest.test_handle_data_blocked_frame client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) ===========changed ref 0=========== # module: tests.test_connection + def encode_uint_var(v): + buf = Buffer(capacity=8) + push_uint_var(buf, v) + return buf.data + ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def _handle_max_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_DATA frame. This adjusts the total amount of we can send to the peer. """ + max_data = pull_uint_var(buf) + if max_data > self._remote_max_data: + self.__logger.info("Remote max_data raised to %d", max_data) + self._remote_max_data = max_data - pull_uint_var(buf) # limit ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def _handle_max_streams_uni_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAMS_UNI frame. This raises number of unidirectional streams we can initiate to the peer. """ max_streams = pull_uint_var(buf) if max_streams > self._remote_max_streams_uni: + self.__logger.info("Remote max_streams_uni raised to %d", max_streams) - self.__logger.info("Remote max_streams_uni raised to %d" % max_streams) self._remote_max_streams_uni = max_streams ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def _handle_max_streams_bidi_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAMS_BIDI frame. This raises number of bidirectional streams we can initiate to the peer. """ max_streams = pull_uint_var(buf) if max_streams > self._remote_max_streams_bidi: + self.__logger.info("Remote max_streams_bidi raised to %d", max_streams) - self.__logger.info("Remote max_streams_bidi raised to %d" % max_streams) self._remote_max_streams_bidi = max_streams ===========changed ref 4=========== # module: aioquic.connection class QuicConnection: def _handle_connection_close_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a CONNECTION_CLOSE frame. """ if frame_type == QuicFrameType.TRANSPORT_CLOSE: error_code, _, reason_phrase = packet.pull_transport_close_frame(buf) else: error_code, reason_phrase = packet.pull_application_close_frame(buf) self.__logger.info( + "Connection close code 0x%X, reason %s", error_code, reason_phrase - "Connection close code 0x%X, reason %s" % (error_code, reason_phrase) ) self.connection_lost(None) ===========changed ref 5=========== # module: aioquic.stream class QuicStream: def __init__( + self, + stream_id: Optional[int] = None, + connection: Optional[Any] = None, + max_stream_data_local: int = 0, + max_stream_data_remote: int = 0, - self, stream_id: Optional[int] = None, connection: Optional[Any] = None ) -> None: self._connection = connection + self.max_stream_data_local = max_stream_data_local + self.max_stream_data_remote = max_stream_data_remote if stream_id is not None: self.reader = asyncio.StreamReader() self.writer = asyncio.StreamWriter(self, None, self.reader, None) else: self.reader = None self.writer = None self._recv_buffer = bytearray() self._recv_start = 0 self._recv_ranges = RangeSet() self._send_buffer = bytearray() self._send_fin = False self._send_start = 0 self.__stream_id = stream_id ===========changed ref 6=========== # module: aioquic.connection class QuicConnection: def _handle_max_stream_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAM_DATA frame. This adjusts the amount of data we can send on a specific stream. """ stream_id = pull_uint_var(buf) + max_stream_data = pull_uint_var(buf) - pull_uint_var(buf) # limit # check stream direction self._assert_stream_can_send(frame_type, stream_id) + stream = self._get_or_create_stream(frame_type, stream_id) - self._get_or_create_stream(frame_type, stream_id) + if max_stream_data > stream.max_stream_data_remote: + self.__logger.info( + "Stream %d remote max_stream_data raised to %d", + stream_id, + max_stream_data, + ) + stream.max_stream_data_remote = max_stream_data
tests.test_connection/QuicConnectionTest.test_handle_max_stream_data_frame
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<11>:<add> stream = client.create_stream()[1].transport <add> self.assertEqual(stream.max_stream_data_remote, 1048576) <del> client.create_stream() <13>:<add> # client receives MAX_STREAM_DATA raising limit <del> # client receives MAX_STREAM_DATA: 0, 1 <15>:<add> tls.Epoch.ONE_RTT, <add> QuicFrameType.MAX_STREAM_DATA, <add> Buffer(data=b"\x00" + encode_uint_var(1048577)), <del> tls.Epoch.ONE_RTT, QuicFrameType.MAX_STREAM_DATA, Buffer(data=b"\x00\x01") <17>:<add> self.assertEqual(stream.max_stream_data_remote, 1048577)
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_max_stream_data_frame(self): <0> client = QuicConnection(is_client=True) <1> server = QuicConnection( <2> is_client=False, <3> certificate=SERVER_CERTIFICATE, <4> private_key=SERVER_PRIVATE_KEY, <5> ) <6> <7> # perform handshake <8> client_transport, server_transport = create_transport(client, server) <9> <10> # client creates bidirectional stream 0 <11> client.create_stream() <12> <13> # client receives MAX_STREAM_DATA: 0, 1 <14> client._handle_max_stream_data_frame( <15> tls.Epoch.ONE_RTT, QuicFrameType.MAX_STREAM_DATA, Buffer(data=b"\x00\x01") <16> ) <17>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.connection.QuicConnection _handle_max_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.connection.QuicConnection.__init__ self._remote_max_data = 0 at: aioquic.connection.QuicConnection._handle_max_data_frame self._remote_max_data = max_data at: aioquic.packet QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) at: aioquic.tls Epoch() at: tests.test_connection SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) encode_uint_var(v) create_transport(client, server) at: tests.test_connection.QuicConnectionTest.test_handle_max_data_frame client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_connection + def encode_uint_var(v): + buf = Buffer(capacity=8) + push_uint_var(buf, v) + return buf.data + ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def _handle_max_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_DATA frame. This adjusts the total amount of we can send to the peer. """ + max_data = pull_uint_var(buf) + if max_data > self._remote_max_data: + self.__logger.info("Remote max_data raised to %d", max_data) + self._remote_max_data = max_data - pull_uint_var(buf) # limit ===========changed ref 2=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_max_data_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + self.assertEqual(client._remote_max_data, 1048576) + # client receives MAX_DATA raising limit + client._handle_max_data_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.MAX_DATA, + Buffer(data=encode_uint_var(1048577)), + ) + self.assertEqual(client._remote_max_data, 1048577) - # server sends MAX_DATA: 12345 - server._pending_flow_control.append(b"\x10\x70\x39") - server._send_pending() ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def _handle_max_streams_uni_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAMS_UNI frame. This raises number of unidirectional streams we can initiate to the peer. """ max_streams = pull_uint_var(buf) if max_streams > self._remote_max_streams_uni: + self.__logger.info("Remote max_streams_uni raised to %d", max_streams) - self.__logger.info("Remote max_streams_uni raised to %d" % max_streams) self._remote_max_streams_uni = max_streams ===========changed ref 4=========== # module: aioquic.connection class QuicConnection: def _handle_max_streams_bidi_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAMS_BIDI frame. This raises number of bidirectional streams we can initiate to the peer. """ max_streams = pull_uint_var(buf) if max_streams > self._remote_max_streams_bidi: + self.__logger.info("Remote max_streams_bidi raised to %d", max_streams) - self.__logger.info("Remote max_streams_bidi raised to %d" % max_streams) self._remote_max_streams_bidi = max_streams ===========changed ref 5=========== # module: aioquic.connection class QuicConnection: def _handle_connection_close_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a CONNECTION_CLOSE frame. """ if frame_type == QuicFrameType.TRANSPORT_CLOSE: error_code, _, reason_phrase = packet.pull_transport_close_frame(buf) else: error_code, reason_phrase = packet.pull_application_close_frame(buf) self.__logger.info( + "Connection close code 0x%X, reason %s", error_code, reason_phrase - "Connection close code 0x%X, reason %s" % (error_code, reason_phrase) ) self.connection_lost(None) ===========changed ref 6=========== # module: aioquic.stream class QuicStream: def __init__( + self, + stream_id: Optional[int] = None, + connection: Optional[Any] = None, + max_stream_data_local: int = 0, + max_stream_data_remote: int = 0, - self, stream_id: Optional[int] = None, connection: Optional[Any] = None ) -> None: self._connection = connection + self.max_stream_data_local = max_stream_data_local + self.max_stream_data_remote = max_stream_data_remote if stream_id is not None: self.reader = asyncio.StreamReader() self.writer = asyncio.StreamWriter(self, None, self.reader, None) else: self.reader = None self.writer = None self._recv_buffer = bytearray() self._recv_start = 0 self._recv_ranges = RangeSet() self._send_buffer = bytearray() self._send_fin = False self._send_start = 0 self.__stream_id = stream_id
tests.test_connection/QuicConnectionTest.test_handle_max_streams_bidi_frame
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<11>:<add> # client receives MAX_STREAMS_BIDI raising limit <add> client._handle_max_streams_bidi_frame( <add> tls.Epoch.ONE_RTT, <add> QuicFrameType.MAX_STREAMS_BIDI, <add> Buffer(data=encode_uint_var(129)), <add> ) <del> # server sends MAX_STREAMS_BIDI: 129 <12>:<del> server._pending_flow_control.append(b"\x12\x40\x81") <13>:<del> server._send_pending() <16>:<add> # client receives MAX_STREAMS_BIDI lowering limit <add> client._handle_max_streams_bidi_frame( <add> tls.Epoch.ONE_RTT, <add> QuicFrameType.MAX_STREAMS_BIDI, <add> Buffer(data=encode_uint_var(127)), <add> ) <del> # server sends MAX_STREAMS_BIDI: 127 -> discarded <17>:<del> server._pending_flow_control.append(b"\x12\x40\x7f") <18>:<del> server._send_pending()
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_max_streams_bidi_frame(self): <0> client = QuicConnection(is_client=True) <1> server = QuicConnection( <2> is_client=False, <3> certificate=SERVER_CERTIFICATE, <4> private_key=SERVER_PRIVATE_KEY, <5> ) <6> <7> # perform handshake <8> client_transport, server_transport = create_transport(client, server) <9> self.assertEqual(client._remote_max_streams_bidi, 128) <10> <11> # server sends MAX_STREAMS_BIDI: 129 <12> server._pending_flow_control.append(b"\x12\x40\x81") <13> server._send_pending() <14> self.assertEqual(client._remote_max_streams_bidi, 129) <15> <16> # server sends MAX_STREAMS_BIDI: 127 -> discarded <17> server._pending_flow_control.append(b"\x12\x40\x7f") <18> server._send_pending() <19> self.assertEqual(client._remote_max_streams_bidi, 129) <20>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection create_stream(is_unidirectional: bool=False) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter] _handle_max_stream_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: tests.test_connection SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) encode_uint_var(v) create_transport(client, server) at: tests.test_connection.QuicConnectionTest.test_handle_max_stream_data_frame stream = client.create_stream()[1].transport at: unittest.case.TestCase 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 ===========changed ref 0=========== # module: tests.test_connection + def encode_uint_var(v): + buf = Buffer(capacity=8) + push_uint_var(buf, v) + return buf.data + ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def _handle_max_stream_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAM_DATA frame. This adjusts the amount of data we can send on a specific stream. """ stream_id = pull_uint_var(buf) + max_stream_data = pull_uint_var(buf) - pull_uint_var(buf) # limit # check stream direction self._assert_stream_can_send(frame_type, stream_id) + stream = self._get_or_create_stream(frame_type, stream_id) - self._get_or_create_stream(frame_type, stream_id) + if max_stream_data > stream.max_stream_data_remote: + self.__logger.info( + "Stream %d remote max_stream_data raised to %d", + stream_id, + max_stream_data, + ) + stream.max_stream_data_remote = max_stream_data ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def create_stream( self, is_unidirectional: bool = False ) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]: """ Create a QUIC stream and return a pair of (reader, writer) objects. The returned reader and writer objects are instances of :class:`asyncio.StreamReader` and :class:`asyncio.StreamWriter` classes. """ stream_id = (int(is_unidirectional) << 1) | int(not self.is_client) while stream_id in self.streams: stream_id += 4 + if is_unidirectional: + max_stream_data_local = 0 + max_stream_data_remote = self._remote_max_stream_data_uni + else: + max_stream_data_local = self._local_max_stream_data_bidi_local + max_stream_data_remote = self._remote_max_stream_data_bidi_remote + # create stream stream = self.streams[stream_id] = QuicStream( + connection=self, + stream_id=stream_id, - connection=self, stream_id=stream_id + max_stream_data_local=max_stream_data_local, + max_stream_data_remote=max_stream_data_remote, ) self.stream_created_cb(stream.reader, stream.writer) return stream.reader, stream.writer ===========changed ref 3=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_max_data_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + self.assertEqual(client._remote_max_data, 1048576) + # client receives MAX_DATA raising limit + client._handle_max_data_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.MAX_DATA, + Buffer(data=encode_uint_var(1048577)), + ) + self.assertEqual(client._remote_max_data, 1048577) - # server sends MAX_DATA: 12345 - server._pending_flow_control.append(b"\x10\x70\x39") - server._send_pending() ===========changed ref 4=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_max_stream_data_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) # client creates bidirectional stream 0 + stream = client.create_stream()[1].transport + self.assertEqual(stream.max_stream_data_remote, 1048576) - client.create_stream() + # client receives MAX_STREAM_DATA raising limit - # client receives MAX_STREAM_DATA: 0, 1 client._handle_max_stream_data_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.MAX_STREAM_DATA, + Buffer(data=b"\x00" + encode_uint_var(1048577)), - tls.Epoch.ONE_RTT, QuicFrameType.MAX_STREAM_DATA, Buffer(data=b"\x00\x01") ) + self.assertEqual(stream.max_stream_data_remote, 1048577) ===========changed ref 5=========== # module: aioquic.connection class QuicConnection: def _handle_max_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_DATA frame. This adjusts the total amount of we can send to the peer. """ + max_data = pull_uint_var(buf) + if max_data > self._remote_max_data: + self.__logger.info("Remote max_data raised to %d", max_data) + self._remote_max_data = max_data - pull_uint_var(buf) # limit
tests.test_connection/QuicConnectionTest.test_handle_max_streams_uni_frame
Modified
aiortc~aioquic
0ba1f54c33e529fc15e7b81a467b1623bad2d104
[connection] store and enforce per-stream max data
<11>:<add> # client receives MAX_STREAMS_UNI raising limit <add> client._handle_max_streams_uni_frame( <add> tls.Epoch.ONE_RTT, <add> QuicFrameType.MAX_STREAMS_UNI, <add> Buffer(data=encode_uint_var(129)), <add> ) <del> # server sends MAX_STREAMS_UNI: 129 <12>:<del> server._pending_flow_control.append(b"\x13\x40\x81") <13>:<del> server._send_pending() <16>:<add> # client receives MAX_STREAMS_UNI raising limit <add> client._handle_max_streams_uni_frame( <add> tls.Epoch.ONE_RTT, <add> QuicFrameType.MAX_STREAMS_UNI, <add> Buffer(data=encode_uint_var(127)), <add> ) <del> # server sends MAX_STREAMS_UNI: 129 -> discarded <17>:<del> server._pending_flow_control.append(b"\x13\x40\x7f") <18>:<del> server._send_pending()
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_max_streams_uni_frame(self): <0> client = QuicConnection(is_client=True) <1> server = QuicConnection( <2> is_client=False, <3> certificate=SERVER_CERTIFICATE, <4> private_key=SERVER_PRIVATE_KEY, <5> ) <6> <7> # perform handshake <8> client_transport, server_transport = create_transport(client, server) <9> self.assertEqual(client._remote_max_streams_uni, 128) <10> <11> # server sends MAX_STREAMS_UNI: 129 <12> server._pending_flow_control.append(b"\x13\x40\x81") <13> server._send_pending() <14> self.assertEqual(client._remote_max_streams_uni, 129) <15> <16> # server sends MAX_STREAMS_UNI: 129 -> discarded <17> server._pending_flow_control.append(b"\x13\x40\x7f") <18> server._send_pending() <19> self.assertEqual(client._remote_max_streams_uni, 129) <20>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection _handle_max_streams_bidi_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.connection.QuicConnection.__init__ self._remote_max_streams_bidi = 0 at: aioquic.connection.QuicConnection._handle_max_streams_bidi_frame self._remote_max_streams_bidi = max_streams at: aioquic.packet QuicErrorCode(x: Union[str, bytes, bytearray], base: int) QuicErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) at: tests.test_connection SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) create_transport(client, server) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None at: unittest.case._AssertRaisesContext.__exit__ self.exception = exc_value.with_traceback(None) ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def _handle_max_streams_bidi_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_STREAMS_BIDI frame. This raises number of bidirectional streams we can initiate to the peer. """ max_streams = pull_uint_var(buf) if max_streams > self._remote_max_streams_bidi: + self.__logger.info("Remote max_streams_bidi raised to %d", max_streams) - self.__logger.info("Remote max_streams_bidi raised to %d" % max_streams) self._remote_max_streams_bidi = max_streams ===========changed ref 1=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_max_data_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + self.assertEqual(client._remote_max_data, 1048576) + # client receives MAX_DATA raising limit + client._handle_max_data_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.MAX_DATA, + Buffer(data=encode_uint_var(1048577)), + ) + self.assertEqual(client._remote_max_data, 1048577) - # server sends MAX_DATA: 12345 - server._pending_flow_control.append(b"\x10\x70\x39") - server._send_pending() ===========changed ref 2=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_max_stream_data_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) # client creates bidirectional stream 0 + stream = client.create_stream()[1].transport + self.assertEqual(stream.max_stream_data_remote, 1048576) - client.create_stream() + # client receives MAX_STREAM_DATA raising limit - # client receives MAX_STREAM_DATA: 0, 1 client._handle_max_stream_data_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.MAX_STREAM_DATA, + Buffer(data=b"\x00" + encode_uint_var(1048577)), - tls.Epoch.ONE_RTT, QuicFrameType.MAX_STREAM_DATA, Buffer(data=b"\x00\x01") ) + self.assertEqual(stream.max_stream_data_remote, 1048577) ===========changed ref 3=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_max_streams_bidi_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) self.assertEqual(client._remote_max_streams_bidi, 128) + # client receives MAX_STREAMS_BIDI raising limit + client._handle_max_streams_bidi_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.MAX_STREAMS_BIDI, + Buffer(data=encode_uint_var(129)), + ) - # server sends MAX_STREAMS_BIDI: 129 - server._pending_flow_control.append(b"\x12\x40\x81") - server._send_pending() self.assertEqual(client._remote_max_streams_bidi, 129) + # client receives MAX_STREAMS_BIDI lowering limit + client._handle_max_streams_bidi_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.MAX_STREAMS_BIDI, + Buffer(data=encode_uint_var(127)), + ) - # server sends MAX_STREAMS_BIDI: 127 -> discarded - server._pending_flow_control.append(b"\x12\x40\x7f") - server._send_pending() self.assertEqual(client._remote_max_streams_bidi, 129) ===========changed ref 4=========== # module: tests.test_connection + def encode_uint_var(v): + buf = Buffer(capacity=8) + push_uint_var(buf, v) + return buf.data + ===========changed ref 5=========== # module: aioquic.connection class QuicConnection: def _handle_max_data_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: """ Handle a MAX_DATA frame. This adjusts the total amount of we can send to the peer. """ + max_data = pull_uint_var(buf) + if max_data > self._remote_max_data: + self.__logger.info("Remote max_data raised to %d", max_data) + self._remote_max_data = max_data - pull_uint_var(buf) # limit
tests.test_connection/QuicConnectionTest.test_handle_data_blocked_frame
Modified
aiortc~aioquic
b58d044bb86489fecfdbf25c872a1535ad754722
[tests] refactor some tests
<10>:<add> # client receives DATA_BLOCKED: 12345 <del> # server sends DATA_BLOCKED: 12345 <11>:<add> client._handle_data_blocked_frame( <add> tls.Epoch.ONE_RTT, <add> QuicFrameType.DATA_BLOCKED, <add> Buffer(data=encode_uint_var(12345)), <add> ) <del> server._pending_flow_control.append(b"\x14\x70\x39") <12>:<del> server._send_pending()
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_data_blocked_frame(self): <0> client = QuicConnection(is_client=True) <1> server = QuicConnection( <2> is_client=False, <3> certificate=SERVER_CERTIFICATE, <4> private_key=SERVER_PRIVATE_KEY, <5> ) <6> <7> # perform handshake <8> client_transport, server_transport = create_transport(client, server) <9> <10> # server sends DATA_BLOCKED: 12345 <11> server._pending_flow_control.append(b"\x14\x70\x39") <12> server._send_pending() <13>
===========unchanged ref 0=========== at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection supported_versions = [ QuicProtocolVersion.DRAFT_17, QuicProtocolVersion.DRAFT_18, QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20, ] _handle_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.tls Epoch() at: tests.test_connection SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) create_transport(client, server)
tests.test_connection/QuicConnectionTest.test_handle_new_connection_id_frame
Modified
aiortc~aioquic
b58d044bb86489fecfdbf25c872a1535ad754722
[tests] refactor some tests
<10>:<add> # client receives NEW_CONNECTION_ID <del> # server sends NEW_CONNECTION_ID <11>:<add> client._handle_new_connection_id_frame( <add> tls.Epoch.ONE_RTT, <add> QuicFrameType.NEW_CONNECTION_ID, <add> Buffer( <del> server._pending_flow_control.append( <12>:<add> data=binascii.unhexlify( <del> binascii.unhexlify( <13>:<add> "02117813f3d9e45e0cacbb491b4b66b039f20406f68fede38ec4c31aba8ab1245244e8" <del> "1802117813f3d9e45e0cacbb491b4b66b039f20406f68fede38ec4c31aba8ab1245244e8" <14>:<add> ) <add> ), <del> ) <16>:<del> server._send_pending()
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_new_connection_id_frame(self): <0> client = QuicConnection(is_client=True) <1> server = QuicConnection( <2> is_client=False, <3> certificate=SERVER_CERTIFICATE, <4> private_key=SERVER_PRIVATE_KEY, <5> ) <6> <7> # perform handshake <8> client_transport, server_transport = create_transport(client, server) <9> <10> # server sends NEW_CONNECTION_ID <11> server._pending_flow_control.append( <12> binascii.unhexlify( <13> "1802117813f3d9e45e0cacbb491b4b66b039f20406f68fede38ec4c31aba8ab1245244e8" <14> ) <15> ) <16> server._send_pending() <17>
===========unchanged ref 0=========== at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection _handle_new_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.connection.QuicConnection.__init__ self._remote_max_streams_uni = 0 at: aioquic.connection.QuicConnection._handle_max_streams_uni_frame self._remote_max_streams_uni = max_streams at: aioquic.packet QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) at: aioquic.tls Epoch() at: tests.test_connection SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) create_transport(client, server) at: tests.test_connection.QuicConnectionTest.test_handle_max_streams_uni_frame client = QuicConnection(is_client=True) at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_data_blocked_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives DATA_BLOCKED: 12345 - # server sends DATA_BLOCKED: 12345 + client._handle_data_blocked_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.DATA_BLOCKED, + Buffer(data=encode_uint_var(12345)), + ) - server._pending_flow_control.append(b"\x14\x70\x39") - server._send_pending()
tests.test_connection/QuicConnectionTest.test_handle_new_token_frame
Modified
aiortc~aioquic
b58d044bb86489fecfdbf25c872a1535ad754722
[tests] refactor some tests
<10>:<add> # client receives NEW_TOKEN <add> client._handle_new_token_frame( <add> tls.Epoch.ONE_RTT, <add> QuicFrameType.NEW_TOKEN, <add> Buffer(data=binascii.unhexlify("080102030405060708")), <add> ) <del> # server sends NEW_TOKEN <11>:<del> server._pending_flow_control.append(binascii.unhexlify("07080102030405060708")) <12>:<del> server._send_pending()
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_new_token_frame(self): <0> client = QuicConnection(is_client=True) <1> server = QuicConnection( <2> is_client=False, <3> certificate=SERVER_CERTIFICATE, <4> private_key=SERVER_PRIVATE_KEY, <5> ) <6> <7> # perform handshake <8> client_transport, server_transport = create_transport(client, server) <9> <10> # server sends NEW_TOKEN <11> server._pending_flow_control.append(binascii.unhexlify("07080102030405060708")) <12> server._send_pending() <13>
===========unchanged ref 0=========== at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: binascii unhexlify(hexstr: _Ascii, /) -> bytes at: tests.test_connection SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) ===========changed ref 0=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_new_connection_id_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives NEW_CONNECTION_ID - # server sends NEW_CONNECTION_ID + client._handle_new_connection_id_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.NEW_CONNECTION_ID, + Buffer( - server._pending_flow_control.append( + data=binascii.unhexlify( - binascii.unhexlify( + "02117813f3d9e45e0cacbb491b4b66b039f20406f68fede38ec4c31aba8ab1245244e8" - "1802117813f3d9e45e0cacbb491b4b66b039f20406f68fede38ec4c31aba8ab1245244e8" + ) + ), - ) ) - server._send_pending() ===========changed ref 1=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_data_blocked_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives DATA_BLOCKED: 12345 - # server sends DATA_BLOCKED: 12345 + client._handle_data_blocked_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.DATA_BLOCKED, + Buffer(data=encode_uint_var(12345)), + ) - server._pending_flow_control.append(b"\x14\x70\x39") - server._send_pending()
tests.test_connection/QuicConnectionTest.test_handle_retire_connection_id_frame
Modified
aiortc~aioquic
b58d044bb86489fecfdbf25c872a1535ad754722
[tests] refactor some tests
<10>:<add> # client receives RETIRE_CONNECTION_ID <del> # server sends RETIRE_CONNECTION_ID <11>:<add> client._handle_retire_connection_id_frame( <add> tls.Epoch.ONE_RTT, QuicFrameType.RETIRE_CONNECTION_ID, Buffer(data=b"\x02") <add> ) <del> server._pending_flow_control.append(b"\x19\x02") <12>:<del> server._send_pending()
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_retire_connection_id_frame(self): <0> client = QuicConnection(is_client=True) <1> server = QuicConnection( <2> is_client=False, <3> certificate=SERVER_CERTIFICATE, <4> private_key=SERVER_PRIVATE_KEY, <5> ) <6> <7> # perform handshake <8> client_transport, server_transport = create_transport(client, server) <9> <10> # server sends RETIRE_CONNECTION_ID <11> server._pending_flow_control.append(b"\x19\x02") <12> server._send_pending() <13>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection _handle_reset_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.packet QuicErrorCode(x: Union[str, bytes, bytearray], base: int) QuicErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) at: aioquic.tls Epoch() at: binascii unhexlify(hexstr: _Ascii, /) -> bytes at: tests.test_connection SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) at: tests.test_connection.QuicConnectionTest.test_handle_reset_stream_frame_send_only client = QuicConnection(is_client=True) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None at: unittest.case._AssertRaisesContext.__exit__ self.exception = exc_value.with_traceback(None) ===========changed ref 0=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_new_token_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives NEW_TOKEN + client._handle_new_token_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.NEW_TOKEN, + Buffer(data=binascii.unhexlify("080102030405060708")), + ) - # server sends NEW_TOKEN - server._pending_flow_control.append(binascii.unhexlify("07080102030405060708")) - server._send_pending() ===========changed ref 1=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_new_connection_id_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives NEW_CONNECTION_ID - # server sends NEW_CONNECTION_ID + client._handle_new_connection_id_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.NEW_CONNECTION_ID, + Buffer( - server._pending_flow_control.append( + data=binascii.unhexlify( - binascii.unhexlify( + "02117813f3d9e45e0cacbb491b4b66b039f20406f68fede38ec4c31aba8ab1245244e8" - "1802117813f3d9e45e0cacbb491b4b66b039f20406f68fede38ec4c31aba8ab1245244e8" + ) + ), - ) ) - server._send_pending() ===========changed ref 2=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_data_blocked_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives DATA_BLOCKED: 12345 - # server sends DATA_BLOCKED: 12345 + client._handle_data_blocked_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.DATA_BLOCKED, + Buffer(data=encode_uint_var(12345)), + ) - server._pending_flow_control.append(b"\x14\x70\x39") - server._send_pending()
tests.test_connection/QuicConnectionTest.test_handle_streams_blocked_uni_frame
Modified
aiortc~aioquic
b58d044bb86489fecfdbf25c872a1535ad754722
[tests] refactor some tests
<10>:<add> # client receives STREAMS_BLOCKED_UNI: 0 <del> # server sends STREAM_BLOCKED_UNI: 0 <11>:<add> client._handle_streams_blocked_frame( <add> tls.Epoch.ONE_RTT, QuicFrameType.STREAMS_BLOCKED_UNI, Buffer(data=b"\x00") <add> ) <del> server._pending_flow_control.append(b"\x17\x00") <12>:<del> server._send_pending()
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_streams_blocked_uni_frame(self): <0> client = QuicConnection(is_client=True) <1> server = QuicConnection( <2> is_client=False, <3> certificate=SERVER_CERTIFICATE, <4> private_key=SERVER_PRIVATE_KEY, <5> ) <6> <7> # perform handshake <8> client_transport, server_transport = create_transport(client, server) <9> <10> # server sends STREAM_BLOCKED_UNI: 0 <11> server._pending_flow_control.append(b"\x17\x00") <12> server._send_pending() <13>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection _handle_stream_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.packet QuicErrorCode(x: Union[str, bytes, bytearray], base: int) QuicErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) at: aioquic.tls Epoch() at: tests.test_connection.QuicConnectionTest.test_handle_stream_data_blocked_frame_send_only client = QuicConnection(is_client=True) at: unittest.case.TestCase 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 ===========changed ref 0=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_retire_connection_id_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives RETIRE_CONNECTION_ID - # server sends RETIRE_CONNECTION_ID + client._handle_retire_connection_id_frame( + tls.Epoch.ONE_RTT, QuicFrameType.RETIRE_CONNECTION_ID, Buffer(data=b"\x02") + ) - server._pending_flow_control.append(b"\x19\x02") - server._send_pending() ===========changed ref 1=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_new_token_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives NEW_TOKEN + client._handle_new_token_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.NEW_TOKEN, + Buffer(data=binascii.unhexlify("080102030405060708")), + ) - # server sends NEW_TOKEN - server._pending_flow_control.append(binascii.unhexlify("07080102030405060708")) - server._send_pending() ===========changed ref 2=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_new_connection_id_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives NEW_CONNECTION_ID - # server sends NEW_CONNECTION_ID + client._handle_new_connection_id_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.NEW_CONNECTION_ID, + Buffer( - server._pending_flow_control.append( + data=binascii.unhexlify( - binascii.unhexlify( + "02117813f3d9e45e0cacbb491b4b66b039f20406f68fede38ec4c31aba8ab1245244e8" - "1802117813f3d9e45e0cacbb491b4b66b039f20406f68fede38ec4c31aba8ab1245244e8" + ) + ), - ) ) - server._send_pending() ===========changed ref 3=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_data_blocked_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives DATA_BLOCKED: 12345 - # server sends DATA_BLOCKED: 12345 + client._handle_data_blocked_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.DATA_BLOCKED, + Buffer(data=encode_uint_var(12345)), + ) - server._pending_flow_control.append(b"\x14\x70\x39") - server._send_pending()
tests.test_connection/QuicConnectionTest.test_handle_unknown_frame
Modified
aiortc~aioquic
b58d044bb86489fecfdbf25c872a1535ad754722
[tests] refactor some tests
<11>:<add> # client receives unknown frame <del> # server sends unknown frame <12>:<add> with self.assertRaises(QuicConnectionError) as cm: <add> client._payload_received(tls.Epoch.ONE_RTT, b"\x1e") <add> self.assertEqual(cm.exception.error_code, QuicErrorCode.PROTOCOL_VIOLATION) <add> self.assertEqual(cm.exception.frame_type, 0x1E) <add> self.assertEqual(cm.exception.reason_phrase, "Unexpected frame type") <del> server._pending_flow_control.append(b"\x1e") <13>:<del> server._send_pending()
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_unknown_frame(self): <0> client = QuicConnection(is_client=True) <1> <2> server = QuicConnection( <3> is_client=False, <4> certificate=SERVER_CERTIFICATE, <5> private_key=SERVER_PRIVATE_KEY, <6> ) <7> <8> # perform handshake <9> client_transport, server_transport = create_transport(client, server) <10> <11> # server sends unknown frame <12> server._pending_flow_control.append(b"\x1e") <13> server._send_pending() <14>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection _handle_streams_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.packet QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) at: aioquic.tls Epoch() at: tests.test_connection SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) create_transport(client, server) at: tests.test_connection.QuicConnectionTest.test_handle_streams_blocked_uni_frame client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) ===========changed ref 0=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_streams_blocked_uni_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives STREAMS_BLOCKED_UNI: 0 - # server sends STREAM_BLOCKED_UNI: 0 + client._handle_streams_blocked_frame( + tls.Epoch.ONE_RTT, QuicFrameType.STREAMS_BLOCKED_UNI, Buffer(data=b"\x00") + ) - server._pending_flow_control.append(b"\x17\x00") - server._send_pending() ===========changed ref 1=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_retire_connection_id_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives RETIRE_CONNECTION_ID - # server sends RETIRE_CONNECTION_ID + client._handle_retire_connection_id_frame( + tls.Epoch.ONE_RTT, QuicFrameType.RETIRE_CONNECTION_ID, Buffer(data=b"\x02") + ) - server._pending_flow_control.append(b"\x19\x02") - server._send_pending() ===========changed ref 2=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_new_token_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives NEW_TOKEN + client._handle_new_token_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.NEW_TOKEN, + Buffer(data=binascii.unhexlify("080102030405060708")), + ) - # server sends NEW_TOKEN - server._pending_flow_control.append(binascii.unhexlify("07080102030405060708")) - server._send_pending() ===========changed ref 3=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_new_connection_id_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives NEW_CONNECTION_ID - # server sends NEW_CONNECTION_ID + client._handle_new_connection_id_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.NEW_CONNECTION_ID, + Buffer( - server._pending_flow_control.append( + data=binascii.unhexlify( - binascii.unhexlify( + "02117813f3d9e45e0cacbb491b4b66b039f20406f68fede38ec4c31aba8ab1245244e8" - "1802117813f3d9e45e0cacbb491b4b66b039f20406f68fede38ec4c31aba8ab1245244e8" + ) + ), - ) ) - server._send_pending() ===========changed ref 4=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_data_blocked_frame(self): client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) # perform handshake client_transport, server_transport = create_transport(client, server) + # client receives DATA_BLOCKED: 12345 - # server sends DATA_BLOCKED: 12345 + client._handle_data_blocked_frame( + tls.Epoch.ONE_RTT, + QuicFrameType.DATA_BLOCKED, + Buffer(data=encode_uint_var(12345)), + ) - server._pending_flow_control.append(b"\x14\x70\x39") - server._send_pending()
aioquic.connection/QuicConnection.__init__
Modified
aiortc~aioquic
517b566439faed528d4fb1bf3a0bf8fa1a585d2a
[connection] update spin bit
# module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: <0> if not is_client: <1> assert certificate is not None, "SSL certificate is required" <2> assert private_key is not None, "SSL private key is required" <3> <4> self.alpn_protocols = alpn_protocols <5> self.certificate = certificate <6> self.is_client = is_client <7> self.host_cid = os.urandom(8) <8> self.peer_cid = os.urandom(8) <9> self.peer_cid_set = False <10> self.peer_token = b"" <11> self.private_key = private_key <12> self.secrets_log_file = secrets_log_file <13> self.server_name = server_name <14> self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} <15> <16> # protocol versions <17> self.version = max(self.supported_versions) <18> <19> self.__close: Optional[Dict] = None <20> self.__connected = asyncio.Event() <21> self.__epoch = tls.Epoch.INITIAL <22> self.__initialized = False <23> self._local_idle_timeout = 60.0 # seconds <24> self._local_max_data = 1048576 <25> self._local_max_stream_data_bidi_local = 1048576 <26> self._local_max_stream_data_bidi_remote = 1048576 <27> self._local_max_stream_data_uni = 1048576 <28> self._local_max_streams_bidi = 128 <29> self._local_max_streams_uni = 128 <30> self.__logger = logger <31> self.__path_challenge: Optional[bytes] =</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0.0 self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self.__transport: Optional[asyncio.DatagramTransport] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle</s> ===========below chunk 1=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s>handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ] ===========unchanged ref 0=========== at: aioquic.connection logger = logging.getLogger("quic") at: aioquic.connection.QuicConnection supported_versions = [ QuicProtocolVersion.DRAFT_17, QuicProtocolVersion.DRAFT_18, QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20, ] _handle_ack_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_crypto_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_stream_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_bidi_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_uni_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_token_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_padding_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_challenge_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_reset_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_retire_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None ===========unchanged ref 1=========== _handle_stop_sending_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_streams_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.connection.QuicConnection._handle_crypto_frame self.__epoch = tls.Epoch.ONE_RTT self.__epoch = tls.Epoch.HANDSHAKE at: aioquic.connection.QuicConnection._handle_max_data_frame self._remote_max_data = max_data at: aioquic.connection.QuicConnection._handle_max_streams_bidi_frame self._remote_max_streams_bidi = max_streams at: aioquic.connection.QuicConnection._handle_max_streams_uni_frame self._remote_max_streams_uni = max_streams at: aioquic.connection.QuicConnection._initialize self.__initialized = True at: aioquic.connection.QuicConnection._parse_transport_parameters self._remote_idle_timeout = quic_transport_parameters.idle_timeout self._remote_idle_timeout = ( quic_transport_parameters.idle_timeout / 1000 ) at: aioquic.connection.QuicConnection._send_path_challenge self.__path_challenge = os.urandom(8) at: aioquic.connection.QuicConnection._write_application self._pending_flow_control = [] self.__close = None at: aioquic.connection.QuicConnection._write_handshake self.__close = None
aioquic.connection/QuicConnection.datagram_received
Modified
aiortc~aioquic
517b566439faed528d4fb1bf3a0bf8fa1a585d2a
[connection] update spin bit
# module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: <0> """ <1> Handle an incoming datagram. <2> """ <3> buf = Buffer(data=data) <4> <5> while not buf.eof(): <6> start_off = buf.tell() <7> header = pull_quic_header(buf, host_cid_length=len(self.host_cid)) <8> <9> if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION: <10> # version negotiation <11> versions = [] <12> while not buf.eof(): <13> versions.append(pull_uint32(buf)) <14> common = set(self.supported_versions).intersection(versions) <15> if not common: <16> self.__logger.error("Could not find a common protocol version") <17> return <18> self.version = QuicProtocolVersion(max(common)) <19> self.__logger.info("Retrying with %s", self.version) <20> self.connection_made(self.__transport) <21> return <22> elif self.is_client and header.packet_type == PACKET_TYPE_RETRY: <23> # stateless retry <24> if ( <25> header.destination_cid == self.host_cid <26> and header.original_destination_cid == self.peer_cid <27> ): <28> self.__logger.info("Performing stateless retry") <29> self.peer_cid = header.source_cid <30> self.peer_token = header.token <31> self.connection_made(self.__transport) <32> return <33> <34> # server initialization <35> if not self.is_client and not self.__initialized: <36> assert ( <37> header.packet_type == PACKET_TYPE_INITIAL <38> ), "first packet must be INITIAL" <39> self._initialize(header.destination_cid) <40> <41> # decrypt packet <42> encrypted_off = buf.tell() - start_off <43> end_off = buf.tell() + header.</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 1 pull_bytes(buf, header.rest_length) epoch = get_epoch(header.packet_type) space = self.spaces[epoch] if not space.crypto.recv.is_valid(): return try: plain_header, plain_payload, packet_number = space.crypto.decrypt_packet( data[start_off:end_off], encrypted_off ) except CryptoError as exc: self.__logger.warning(exc) return if not self.peer_cid_set: self.peer_cid = header.source_cid self.peer_cid_set = True # handle payload try: is_ack_only = self._payload_received(epoch, plain_payload) except QuicConnectionError as exc: self.__logger.warning(exc) self.close( error_code=exc.error_code, frame_type=exc.frame_type, reason_phrase=exc.reason_phrase, ) return # record packet as received space.ack_queue.add(packet_number) if not is_ack_only: self.send_ack[epoch] = True self._send_pending() ===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) pull_bytes(buf: Buffer, length: int) -> bytes pull_uint32(buf: Buffer) -> int at: aioquic.buffer.Buffer eof() -> bool tell() -> int at: aioquic.connection get_epoch(packet_type: int) -> tls.Epoch at: aioquic.connection.PacketSpace.__init__ self.crypto = CryptoPair() at: aioquic.connection.QuicConnection supported_versions = [ QuicProtocolVersion.DRAFT_17, QuicProtocolVersion.DRAFT_18, QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20, ] connection_made(transport: asyncio.DatagramTransport) -> None _initialize(peer_cid: bytes) -> None _payload_received(epoch: tls.Epoch, plain: bytes) -> bool _push_crypto_data() -> None _send_pending() -> None at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.version = max(self.supported_versions) self.__initialized = False self.__logger = logger self._spin_bit = False self._spin_highest_pn = 0 self.__transport: Optional[asyncio.DatagramTransport] = None at: aioquic.connection.QuicConnection._initialize self.tls = tls.Context(is_client=self.is_client, logger=self.__logger) ===========unchanged ref 1=========== self.send_buffer = { tls.Epoch.INITIAL: Buffer(capacity=4096), tls.Epoch.HANDSHAKE: Buffer(capacity=4096), tls.Epoch.ONE_RTT: Buffer(capacity=4096), } self.spaces = { tls.Epoch.INITIAL: PacketSpace(), tls.Epoch.HANDSHAKE: PacketSpace(), tls.Epoch.ONE_RTT: PacketSpace(), } self.__initialized = True at: aioquic.connection.QuicConnection.connection_made self.__transport = transport at: aioquic.crypto CryptoError(*args: object) at: aioquic.crypto.CryptoContext is_valid() -> bool at: aioquic.crypto.CryptoPair decrypt_packet(packet: bytes, encrypted_offset: int) -> Tuple[bytes, bytes, int] at: aioquic.crypto.CryptoPair.__init__ self.recv = CryptoContext() at: aioquic.packet PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int) QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) get_spin_bit(first_byte: int) -> bool is_long_header(first_byte: int) -> bool pull_quic_header(buf: Buffer, host_cid_length: Optional[int]=None) -> QuicHeader at: aioquic.packet.QuicHeader version: Optional[int] packet_type: int destination_cid: bytes source_cid: bytes original_destination_cid: bytes = b"" token: bytes = b"" rest_length: int = 0 ===========unchanged ref 2=========== at: aioquic.tls.Context handle_message(input_data: bytes, output_buf: Dict[Epoch, Buffer]) -> None at: logging.Logger info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None warning(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None error(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None ===========changed ref 0=========== # module: aioquic.packet + def get_spin_bit(first_byte: int) -> bool: + return bool(first_byte & PACKET_SPIN_BIT) +
aioquic.connection/QuicConnection._write_application
Modified
aiortc~aioquic
517b566439faed528d4fb1bf3a0bf8fa1a585d2a
[connection] update spin bit
<11>:<add> PACKET_FIXED_BIT <add> | (self._spin_bit << 5) <add> | (space.crypto.key_phase << 2) <add> | (SEND_PN_SIZE - 1), <del> PACKET_FIXED_BIT | (space.crypto.key_phase << 2) | (SEND_PN_SIZE - 1),
# module: aioquic.connection class QuicConnection: def _write_application(self) -> Iterator[bytes]: <0> epoch = tls.Epoch.ONE_RTT <1> space = self.spaces[epoch] <2> if not space.crypto.send.is_valid(): <3> return <4> <5> buf = Buffer(capacity=PACKET_MAX_SIZE) <6> <7> while True: <8> # write header <9> push_uint8( <10> buf, <11> PACKET_FIXED_BIT | (space.crypto.key_phase << 2) | (SEND_PN_SIZE - 1), <12> ) <13> push_bytes(buf, self.peer_cid) <14> push_uint16(buf, self.packet_number) <15> header_size = buf.tell() <16> <17> # ACK <18> if self.send_ack[epoch] and space.ack_queue: <19> push_uint_var(buf, QuicFrameType.ACK) <20> packet.push_ack_frame(buf, space.ack_queue, 0) <21> self.send_ack[epoch] = False <22> <23> # FLOW CONTROL <24> for control_frame in self._pending_flow_control: <25> push_bytes(buf, control_frame) <26> self._pending_flow_control = [] <27> <28> # CLOSE <29> if self.__close and self.__epoch == epoch: <30> push_close(buf, **self.__close) <31> self.__close = None <32> <33> # STREAM <34> for stream_id, stream in self.streams.items(): <35> if isinstance(stream_id, int) and stream.has_data_to_send(): <36> frame = stream.get_frame( <37> PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 6 <38> ) <39> flags = QuicStreamFlag.LEN <40> if frame.offset: <41> flags |= QuicStreamFlag.OFF <42> if frame.fin: <43> flags |= QuicStreamFlag.FIN <44> push_uint_</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def _write_application(self) -> Iterator[bytes]: # offset: 1 with push_stream_frame(buf, 0, frame.offset): push_bytes(buf, frame.data) packet_size = buf.tell() if packet_size > header_size: # encrypt data = buf.data yield space.crypto.encrypt_packet( data[0:header_size], data[header_size:packet_size] ) self.packet_number += 1 buf.seek(0) else: break ===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) push_bytes(buf: Buffer, v: bytes) -> None push_uint8(buf: Buffer, v: int) -> None push_uint16(buf: Buffer, v: int) -> None at: aioquic.buffer.Buffer tell() -> int at: aioquic.connection PACKET_MAX_SIZE = 1280 SECRETS_LABELS = [ [ None, "QUIC_CLIENT_EARLY_TRAFFIC_SECRET", "QUIC_CLIENT_HANDSHAKE_TRAFFIC_SECRET", "QUIC_CLIENT_TRAFFIC_SECRET_0", ], [ None, None, "QUIC_SERVER_HANDSHAKE_TRAFFIC_SECRET", "QUIC_SERVER_TRAFFIC_SECRET_0", ], ] SEND_PN_SIZE = 2 push_close(buf: Buffer, error_code: int, frame_type: Optional[int], reason_phrase: str) -> None at: aioquic.connection.PacketSpace.__init__ self.ack_queue = RangeSet() self.crypto = CryptoPair() at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.peer_cid = os.urandom(8) self.secrets_log_file = secrets_log_file self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} self.__close: Optional[Dict] = None self.__epoch = tls.Epoch.INITIAL self._pending_flow_control: List[bytes] = [] self._spin_bit = False at: aioquic.connection.QuicConnection._handle_crypto_frame self.__epoch = tls.Epoch.ONE_RTT self.__epoch = tls.Epoch.HANDSHAKE ===========unchanged ref 1=========== at: aioquic.connection.QuicConnection._initialize self.tls = tls.Context(is_client=self.is_client, logger=self.__logger) self.send_ack = { tls.Epoch.INITIAL: False, tls.Epoch.HANDSHAKE: False, tls.Epoch.ONE_RTT: False, } self.spaces = { tls.Epoch.INITIAL: PacketSpace(), tls.Epoch.HANDSHAKE: PacketSpace(), tls.Epoch.ONE_RTT: PacketSpace(), } self.packet_number = 0 at: aioquic.connection.QuicConnection._write_application self.packet_number += 1 at: aioquic.connection.QuicConnection._write_handshake self.__close = None self.packet_number += 1 at: aioquic.connection.QuicConnection.close self.__close = { "error_code": error_code, "frame_type": frame_type, "reason_phrase": reason_phrase, } at: aioquic.connection.QuicConnection.datagram_received self.peer_cid = header.source_cid self._spin_bit = not get_spin_bit(plain_header[0]) self._spin_bit = get_spin_bit(plain_header[0]) at: aioquic.crypto.CryptoContext is_valid() -> bool setup(cipher_suite: CipherSuite, secret: bytes) -> None at: aioquic.crypto.CryptoPair.__init__ self.aead_tag_size = 16 self.recv = CryptoContext() self.send = CryptoContext() at: aioquic.packet PACKET_FIXED_BIT = 0x40 push_uint_var(buf: Buffer, value: int) -> None ===========unchanged ref 2=========== QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) push_ack_frame(buf: Buffer, rangeset: RangeSet, delay: int) -> None QuicStreamFlag(x: Union[str, bytes, bytearray], base: int) QuicStreamFlag(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) at: aioquic.packet.QuicStreamFrame data: bytes = b"" fin: bool = False offset: int = 0 at: aioquic.stream.QuicStream get_frame(size: int) -> QuicStreamFrame has_data_to_send() -> bool at: aioquic.tls Direction() Epoch() at: aioquic.tls.Context.__init__ self.key_schedule: Optional[KeySchedule] = None self.client_random = None self.client_random = os.urandom(32) at: aioquic.tls.Context._client_handle_hello self.key_schedule = self._key_schedule_proxy.select(peer_hello.cipher_suite) at: aioquic.tls.Context._server_handle_hello self.client_random = peer_hello.random self.key_schedule = KeySchedule(cipher_suite) at: aioquic.tls.KeySchedule.__init__ self.cipher_suite = cipher_suite at: enum.Enum name: str value: Any _name_: str _value_: Any _member_names_: List[str] # undocumented _member_map_: Dict[str, Enum] # undocumented _value2member_map_: Dict[int, Enum] # undocumented _ignore_: Union[str, List[str]] _order_: str ===========unchanged ref 3=========== __order__: str at: typing Iterator = _alias(collections.abc.Iterator, 1) at: typing.IO __slots__ = () flush() -> None write(s: AnyStr) -> int ===========changed ref 0=========== # module: aioquic.packet + def get_spin_bit(first_byte: int) -> bool: + return bool(first_byte & PACKET_SPIN_BIT) + ===========changed ref 1=========== # module: aioquic.packet PACKET_LONG_HEADER = 0x80 PACKET_FIXED_BIT = 0x40 + PACKET_SPIN_BIT = 0x20 PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10 PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 PACKET_TYPE_MASK = 0xF0 UINT_VAR_FORMATS = [ (pull_uint8, push_uint8, 0x3F), (pull_uint16, push_uint16, 0x3FFF), (pull_uint32, push_uint32, 0x3FFFFFFF), (pull_uint64, push_uint64, 0x3FFFFFFFFFFFFFFF), ]
aioquic.stream/QuicStream.write
Modified
aiortc~aioquic
ea1c771bf25a3faacf8cc1ca8c4bcfada1a1d54e
[stream] delay sending data on write by one tick
<3>:<add> self._connection._send_soon() <del> self._connection._send_pending()
# module: aioquic.stream class QuicStream: def write(self, data: bytes) -> None: <0> if data: <1> self._send_buffer += data <2> if self._connection is not None: <3> self._connection._send_pending() <4>
===========unchanged ref 0=========== at: aioquic.stream.QuicStream.__init__ self._connection = connection self._send_buffer = bytearray() at: aioquic.stream.QuicStream.get_frame self._send_buffer = self._send_buffer[size:]
aioquic.stream/QuicStream.write_eof
Modified
aiortc~aioquic
ea1c771bf25a3faacf8cc1ca8c4bcfada1a1d54e
[stream] delay sending data on write by one tick
<1>:<add> self._connection._send_soon() <del> self._connection._send_pending()
# module: aioquic.stream class QuicStream: def write_eof(self) -> None: <0> self._send_fin = True <1> self._connection._send_pending() <2>
===========unchanged ref 0=========== at: aioquic.stream.QuicStream.__init__ self._connection = connection self._send_fin = False at: aioquic.stream.QuicStream.get_frame self._send_fin = False ===========changed ref 0=========== # module: aioquic.stream class QuicStream: def write(self, data: bytes) -> None: if data: self._send_buffer += data if self._connection is not None: + self._connection._send_soon() - self._connection._send_pending()
aioquic.connection/QuicConnection.__init__
Modified
aiortc~aioquic
ea1c771bf25a3faacf8cc1ca8c4bcfada1a1d54e
[stream] delay sending data on write by one tick
# module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: <0> if not is_client: <1> assert certificate is not None, "SSL certificate is required" <2> assert private_key is not None, "SSL private key is required" <3> <4> self.alpn_protocols = alpn_protocols <5> self.certificate = certificate <6> self.is_client = is_client <7> self.host_cid = os.urandom(8) <8> self.peer_cid = os.urandom(8) <9> self.peer_cid_set = False <10> self.peer_token = b"" <11> self.private_key = private_key <12> self.secrets_log_file = secrets_log_file <13> self.server_name = server_name <14> self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} <15> <16> # protocol versions <17> self.version = max(self.supported_versions) <18> <19> self.__close: Optional[Dict] = None <20> self.__connected = asyncio.Event() <21> self.__epoch = tls.Epoch.INITIAL <22> self.__initialized = False <23> self._local_idle_timeout = 60.0 # seconds <24> self._local_max_data = 1048576 <25> self._local_max_stream_data_bidi_local = 1048576 <26> self._local_max_stream_data_bidi_remote = 1048576 <27> self._local_max_stream_data_uni = 1048576 <28> self._local_max_streams_bidi = 128 <29> self._local_max_streams_uni = 128 <30> self.__logger = logger <31> self.__path_challenge: Optional[bytes] =</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0.0 self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self._spin_bit = False self._spin_highest_pn = 0 self.__transport: Optional[asyncio.DatagramTransport] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame</s> ===========below chunk 1=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s>_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ] ===========unchanged ref 0=========== at: aioquic.connection logger = logging.getLogger("quic") at: aioquic.connection.QuicConnection supported_versions = [ QuicProtocolVersion.DRAFT_17, QuicProtocolVersion.DRAFT_18, QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20, ] _handle_ack_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_connection_close_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_crypto_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_stream_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_bidi_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_uni_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_token_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_padding_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_challenge_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_response_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_reset_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None ===========unchanged ref 1=========== _handle_retire_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stop_sending_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_streams_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.connection.QuicConnection._handle_crypto_frame self.__epoch = tls.Epoch.ONE_RTT self.__epoch = tls.Epoch.HANDSHAKE at: aioquic.connection.QuicConnection._handle_max_data_frame self._remote_max_data = max_data at: aioquic.connection.QuicConnection._handle_max_streams_bidi_frame self._remote_max_streams_bidi = max_streams at: aioquic.connection.QuicConnection._handle_max_streams_uni_frame self._remote_max_streams_uni = max_streams at: aioquic.connection.QuicConnection._initialize self.__initialized = True at: aioquic.connection.QuicConnection._parse_transport_parameters self._remote_idle_timeout = quic_transport_parameters.idle_timeout self._remote_idle_timeout = ( quic_transport_parameters.idle_timeout / 1000 ) at: aioquic.connection.QuicConnection._send_path_challenge self.__path_challenge = os.urandom(8) at: aioquic.connection.QuicConnection._send_pending self.__send_pending_task = None at: aioquic.connection.QuicConnection._send_soon self.__send_pending_task = loop.call_soon(self._send_pending)
aioquic.connection/QuicConnection._send_pending
Modified
aiortc~aioquic
ea1c771bf25a3faacf8cc1ca8c4bcfada1a1d54e
[stream] delay sending data on write by one tick
<2>:<add> self.__send_pending_task = None
# module: aioquic.connection class QuicConnection: def _send_pending(self) -> None: <0> for datagram in self._pending_datagrams(): <1> self.__transport.sendto(datagram) <2>
===========unchanged ref 0=========== at: aioquic.connection.QuicConnection _pending_datagrams() -> Iterator[bytes] ===========changed ref 0=========== # module: aioquic.stream class QuicStream: def write_eof(self) -> None: self._send_fin = True + self._connection._send_soon() - self._connection._send_pending() ===========changed ref 1=========== # module: aioquic.stream class QuicStream: def write(self, data: bytes) -> None: if data: self._send_buffer += data if self._connection is not None: + self._connection._send_soon() - self._connection._send_pending() ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: if not is_client: assert certificate is not None, "SSL certificate is required" assert private_key is not None, "SSL private key is required" self.alpn_protocols = alpn_protocols self.certificate = certificate self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.private_key = private_key self.secrets_log_file = secrets_log_file self.server_name = server_name self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} # protocol versions self.version = max(self.supported_versions) self.__close: Optional[Dict] = None self.__connected = asyncio.Event() self.__epoch = tls.Epoch.INITIAL self.__initialized = False self._local_idle_timeout = 60.0 # seconds self._local_max_data = 1048576 self._local_max_stream_data_bidi_local = 1048576 self._local_max_stream_data_bidi_remote = 1048576 self._local_max_stream_data_uni = 1048576 self._local_max_streams_bidi = 128 self._local_max_streams_uni = 128 self.__logger = logger self.__path_challenge: Optional[bytes] = None self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0.0 </s> ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 <s> self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0.0 self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self._spin_bit = False self._spin_highest_pn = 0 + self.__send_pending_task: Optional[asyncio.Handle] = None self.__transport: Optional[asyncio.DatagramTransport] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, </s> ===========changed ref 4=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s>handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ]
tests.test_connection/QuicConnectionTest._test_connect_with_version
Modified
aiortc~aioquic
ea1c771bf25a3faacf8cc1ca8c4bcfada1a1d54e
[stream] delay sending data on write by one tick
<21>:<add> run(asyncio.sleep(0)) <31>:<add> run(asyncio.sleep(0)) <39>:<add> run(asyncio.sleep(0))
# module: tests.test_connection class QuicConnectionTest(TestCase): def _test_connect_with_version(self, client_versions, server_versions): <0> client = QuicConnection(is_client=True) <1> client.supported_versions = client_versions <2> client.version = max(client_versions) <3> <4> server = QuicConnection( <5> is_client=False, <6> certificate=SERVER_CERTIFICATE, <7> private_key=SERVER_PRIVATE_KEY, <8> ) <9> server.supported_versions = server_versions <10> server.version = max(server_versions) <11> <12> # perform handshake <13> client_transport, server_transport = create_transport(client, server) <14> self.assertEqual(client_transport.sent, 4) <15> self.assertEqual(server_transport.sent, 4) <16> run(client.connect()) <17> <18> # send data over stream <19> client_reader, client_writer = client.create_stream() <20> client_writer.write(b"ping") <21> self.assertEqual(client_transport.sent, 5) <22> self.assertEqual(server_transport.sent, 5) <23> <24> # FIXME: needs an API <25> server_reader, server_writer = ( <26> server.streams[0].reader, <27> server.streams[0].writer, <28> ) <29> self.assertEqual(run(server_reader.read(1024)), b"ping") <30> server_writer.write(b"pong") <31> self.assertEqual(client_transport.sent, 6) <32> self.assertEqual(server_transport.sent, 6) <33> <34> # client receives pong <35> self.assertEqual(run(client_reader.read(1024)), b"pong") <36> <37> # client writes EOF <38> client_writer.write_eof() <39> self.assertEqual(client_transport.sent, 7) <40> self.assertEqual(server_transport.sent, 7) <41> <42> # server receives EOF <43> self.</s>
===========below chunk 0=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def _test_connect_with_version(self, client_versions, server_versions): # offset: 1 ===========unchanged ref 0=========== at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection supported_versions = [ QuicProtocolVersion.DRAFT_17, QuicProtocolVersion.DRAFT_18, QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20, ] connect() -> None create_stream(is_unidirectional: bool=False) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter] at: aioquic.connection.QuicConnection.__init__ self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} self.version = max(self.supported_versions) at: aioquic.connection.QuicConnection.datagram_received self.version = QuicProtocolVersion(max(common)) at: aioquic.stream.QuicStream.__init__ self.reader = asyncio.StreamReader() self.reader = None self.writer = None self.writer = asyncio.StreamWriter(self, None, self.reader, None) at: asyncio.streams.StreamReader _source_traceback = None read(n: int=...) -> bytes at: asyncio.streams.StreamWriter write(data: bytes) -> None write_eof() -> None at: asyncio.tasks sleep(delay: float, result: _T=..., *, loop: Optional[AbstractEventLoop]=...) -> Future[_T] at: tests.test_connection SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) ===========unchanged ref 1=========== create_transport(client, server) at: tests.test_connection.FakeTransport.sendto self.sent += 1 at: tests.utils run(coro) at: unittest.case TestCase(methodName: str=...) at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.stream class QuicStream: def write_eof(self) -> None: self._send_fin = True + self._connection._send_soon() - self._connection._send_pending() ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def _send_pending(self) -> None: for datagram in self._pending_datagrams(): self.__transport.sendto(datagram) + self.__send_pending_task = None ===========changed ref 2=========== # module: aioquic.stream class QuicStream: def write(self, data: bytes) -> None: if data: self._send_buffer += data if self._connection is not None: + self._connection._send_soon() - self._connection._send_pending() ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: + def _send_soon(self) -> None: + if self.__send_pending_task is None: + loop = asyncio.get_event_loop() + self.__send_pending_task = loop.call_soon(self._send_pending) + ===========changed ref 4=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: if not is_client: assert certificate is not None, "SSL certificate is required" assert private_key is not None, "SSL private key is required" self.alpn_protocols = alpn_protocols self.certificate = certificate self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.private_key = private_key self.secrets_log_file = secrets_log_file self.server_name = server_name self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} # protocol versions self.version = max(self.supported_versions) self.__close: Optional[Dict] = None self.__connected = asyncio.Event() self.__epoch = tls.Epoch.INITIAL self.__initialized = False self._local_idle_timeout = 60.0 # seconds self._local_max_data = 1048576 self._local_max_stream_data_bidi_local = 1048576 self._local_max_stream_data_bidi_remote = 1048576 self._local_max_stream_data_uni = 1048576 self._local_max_streams_bidi = 128 self._local_max_streams_uni = 128 self.__logger = logger self.__path_challenge: Optional[bytes] = None self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0.0 </s> ===========changed ref 5=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 <s> self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0.0 self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self._spin_bit = False self._spin_highest_pn = 0 + self.__send_pending_task: Optional[asyncio.Handle] = None self.__transport: Optional[asyncio.DatagramTransport] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, </s>
tests.test_connection/QuicConnectionTest.test_connection_lost
Modified
aiortc~aioquic
ea1c771bf25a3faacf8cc1ca8c4bcfada1a1d54e
[stream] delay sending data on write by one tick
<16>:<add> run(asyncio.sleep(0))
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_connection_lost(self): <0> client = QuicConnection(is_client=True) <1> server = QuicConnection( <2> is_client=False, <3> certificate=SERVER_CERTIFICATE, <4> private_key=SERVER_PRIVATE_KEY, <5> ) <6> <7> # perform handshake <8> client_transport, server_transport = create_transport(client, server) <9> self.assertEqual(client_transport.sent, 4) <10> self.assertEqual(server_transport.sent, 4) <11> run(client.connect()) <12> <13> # send data over stream <14> client_reader, client_writer = client.create_stream() <15> client_writer.write(b"ping") <16> self.assertEqual(client_transport.sent, 5) <17> self.assertEqual(server_transport.sent, 5) <18> <19> # break connection <20> client.connection_lost(None) <21> self.assertEqual(run(client_reader.read()), b"") <22>
===========unchanged ref 0=========== at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection connect() -> None create_stream(is_unidirectional: bool=False) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter] at: asyncio.streams.StreamWriter write(data: bytes) -> None at: asyncio.tasks sleep(delay: float, result: _T=..., *, loop: Optional[AbstractEventLoop]=...) -> Future[_T] at: tests.test_connection SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) create_transport(client, server) at: tests.utils run(coro) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def _test_connect_with_version(self, client_versions, server_versions): client = QuicConnection(is_client=True) client.supported_versions = client_versions client.version = max(client_versions) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) server.supported_versions = server_versions server.version = max(server_versions) # perform handshake client_transport, server_transport = create_transport(client, server) self.assertEqual(client_transport.sent, 4) self.assertEqual(server_transport.sent, 4) run(client.connect()) # send data over stream client_reader, client_writer = client.create_stream() client_writer.write(b"ping") + run(asyncio.sleep(0)) self.assertEqual(client_transport.sent, 5) self.assertEqual(server_transport.sent, 5) # FIXME: needs an API server_reader, server_writer = ( server.streams[0].reader, server.streams[0].writer, ) self.assertEqual(run(server_reader.read(1024)), b"ping") server_writer.write(b"pong") + run(asyncio.sleep(0)) self.assertEqual(client_transport.sent, 6) self.assertEqual(server_transport.sent, 6) # client receives pong self.assertEqual(run(client_reader.read(1024)), b"pong") # client writes EOF client_writer.write_eof() + run(asyncio.sleep(0)) self.assertEqual(client_transport.sent, 7) self.assertEqual(server_transport.sent, 7) # server receives EOF self.assertEqual(run(server_reader</s> ===========changed ref 1=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def _test_connect_with_version(self, client_versions, server_versions): # offset: 1 <s>assertEqual(server_transport.sent, 7) # server receives EOF self.assertEqual(run(server_reader.read()), b"") ===========changed ref 2=========== # module: aioquic.stream class QuicStream: def write_eof(self) -> None: self._send_fin = True + self._connection._send_soon() - self._connection._send_pending() ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def _send_pending(self) -> None: for datagram in self._pending_datagrams(): self.__transport.sendto(datagram) + self.__send_pending_task = None ===========changed ref 4=========== # module: aioquic.stream class QuicStream: def write(self, data: bytes) -> None: if data: self._send_buffer += data if self._connection is not None: + self._connection._send_soon() - self._connection._send_pending() ===========changed ref 5=========== # module: aioquic.connection class QuicConnection: + def _send_soon(self) -> None: + if self.__send_pending_task is None: + loop = asyncio.get_event_loop() + self.__send_pending_task = loop.call_soon(self._send_pending) + ===========changed ref 6=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: if not is_client: assert certificate is not None, "SSL certificate is required" assert private_key is not None, "SSL private key is required" self.alpn_protocols = alpn_protocols self.certificate = certificate self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.private_key = private_key self.secrets_log_file = secrets_log_file self.server_name = server_name self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} # protocol versions self.version = max(self.supported_versions) self.__close: Optional[Dict] = None self.__connected = asyncio.Event() self.__epoch = tls.Epoch.INITIAL self.__initialized = False self._local_idle_timeout = 60.0 # seconds self._local_max_data = 1048576 self._local_max_stream_data_bidi_local = 1048576 self._local_max_stream_data_bidi_remote = 1048576 self._local_max_stream_data_uni = 1048576 self._local_max_streams_bidi = 128 self._local_max_streams_uni = 128 self.__logger = logger self.__path_challenge: Optional[bytes] = None self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0.0 </s>
examples.client/run
Modified
aiortc~aioquic
786ce61ff41b52d426c667a7ac81ac3e2fe44f48
[examples] make client read response up to EOF
<15>:<del> print(await reader.read(1024))
# module: examples.client def run(host, port, **kwargs): <0> # if host is not an IP address, pass it to enable SNI <1> try: <2> ipaddress.ip_address(host) <3> except ValueError: <4> kwargs["server_name"] = host <5> <6> _, protocol = await loop.create_datagram_endpoint( <7> lambda: QuicConnection(is_client=True, **kwargs), remote_addr=(host, port) <8> ) <9> await protocol.connect() <10> <11> # perform HTTP/0.9 request <12> reader, writer = protocol.create_stream() <13> writer.write(b"GET /\r\n") <14> writer.write_eof() <15> print(await reader.read(1024)) <16>
===========unchanged ref 0=========== at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) 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.client loop = asyncio.get_event_loop() at: ipaddress ip_address(address: object) -> Any
examples.server/QuicServerProtocol.stream_created
Modified
aiortc~aioquic
617ede1edcb11df00458bec53762a484ec317811
[examples] respond to HTTP/0.9 on any client-initiated bidi stream
<6>:<add> <add> # we serve HTTP/0.9 on Client-Initiated Bidirectional streams <add> if not stream_id % 4: <del> if stream_id == 0:
# module: examples.server class QuicServerProtocol(asyncio.DatagramProtocol): def stream_created(self, reader, writer): <0> connection = writer.get_extra_info("connection") <1> stream_id = writer.get_extra_info("stream_id") <2> logger.info( <3> "%s Stream %d created by remote party" <4> % (connection_id(connection), stream_id) <5> ) <6> if stream_id == 0: <7> asyncio.ensure_future(serve_http_request(reader, writer)) <8>
===========unchanged ref 0=========== at: examples.server logger = logging.getLogger("server") connection_id(connection) at: logging.Logger info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
aioquic.connection/QuicConnection.__init__
Modified
aiortc~aioquic
c2fe1d62cdca6b6404f918b4cd1cde9ad9df693f
[connection] start adding state tracking
# module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: <0> if not is_client: <1> assert certificate is not None, "SSL certificate is required" <2> assert private_key is not None, "SSL private key is required" <3> <4> self.alpn_protocols = alpn_protocols <5> self.certificate = certificate <6> self.is_client = is_client <7> self.host_cid = os.urandom(8) <8> self.peer_cid = os.urandom(8) <9> self.peer_cid_set = False <10> self.peer_token = b"" <11> self.private_key = private_key <12> self.secrets_log_file = secrets_log_file <13> self.server_name = server_name <14> self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} <15> <16> # protocol versions <17> self.version = max(self.supported_versions) <18> <19> self.__close: Optional[Dict] = None <20> self.__connected = asyncio.Event() <21> self.__epoch = tls.Epoch.INITIAL <22> self.__initialized = False <23> self._local_idle_timeout = 60.0 # seconds <24> self._local_max_data = 1048576 <25> self._local_max_stream_data_bidi_local = 1048576 <26> self._local_max_stream_data_bidi_remote = 1048576 <27> self._local_max_stream_data_uni = 1048576 <28> self._local_max_streams_bidi = 128 <29> self._local_max_streams_uni = 128 <30> self.__logger = logger <31> self.__path_challenge: Optional[bytes] =</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0.0 self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self._spin_bit = False self._spin_highest_pn = 0 self.__send_pending_task: Optional[asyncio.Handle] = None self.__transport: Optional[asyncio.DatagramTransport] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_</s> ===========below chunk 1=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s>stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ] ===========unchanged ref 0=========== at: aioquic.connection logger = logging.getLogger("quic") QuicConnectionState() at: aioquic.connection.QuicConnection _handle_ack_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_crypto_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_stream_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_bidi_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_uni_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_token_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_padding_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_reset_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stop_sending_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.connection.QuicConnection._handle_crypto_frame self.__epoch = tls.Epoch.ONE_RTT self.__epoch = tls.Epoch.HANDSHAKE ===========unchanged ref 1=========== at: aioquic.connection.QuicConnection._handle_max_data_frame self._remote_max_data = max_data at: aioquic.connection.QuicConnection._handle_max_streams_bidi_frame self._remote_max_streams_bidi = max_streams at: aioquic.connection.QuicConnection._handle_max_streams_uni_frame self._remote_max_streams_uni = max_streams at: aioquic.connection.QuicConnection._initialize self.__initialized = True at: aioquic.connection.QuicConnection._parse_transport_parameters self._remote_idle_timeout = quic_transport_parameters.idle_timeout self._remote_idle_timeout = ( quic_transport_parameters.idle_timeout / 1000 ) at: aioquic.connection.QuicConnection._send_path_challenge self.__path_challenge = os.urandom(8) at: aioquic.connection.QuicConnection._send_pending self.__send_pending_task = None at: aioquic.connection.QuicConnection._send_soon self.__send_pending_task = loop.call_soon(self._send_pending) at: aioquic.connection.QuicConnection._set_state self.__state = state at: aioquic.connection.QuicConnection._write_application self._pending_flow_control = [] self.__close = None at: aioquic.connection.QuicConnection._write_handshake self.__close = None at: aioquic.connection.QuicConnection.close self.__close = { "error_code": error_code, "frame_type": frame_type, "reason_phrase": reason_phrase, } at: aioquic.connection.QuicConnection.connection_made self.__transport = transport at: aioquic.connection.QuicConnection.datagram_received self.version = QuicProtocolVersion(max(common))
aioquic.connection/QuicConnection.close
Modified
aiortc~aioquic
c2fe1d62cdca6b6404f918b4cd1cde9ad9df693f
[connection] start adding state tracking
<8>:<add> if self.__state not in [ <add> QuicConnectionState.CLOSING, <add> QuicConnectionState.DRAINING, <add> ]: <add> self._set_state(QuicConnectionState.CLOSING) <add> self.connection_lost(None)
# module: aioquic.connection class QuicConnection: def close( + self, + error_code: int = QuicErrorCode.NO_ERROR, + frame_type: Optional[int] = None, + reason_phrase: str = "", - self, error_code: int, frame_type: Optional[int] = None, reason_phrase: str = "" ) -> None: <0> """ <1> Close the connection. <2> """ <3> self.__close = { <4> "error_code": error_code, <5> "frame_type": frame_type, <6> "reason_phrase": reason_phrase, <7> } <8> self._send_pending() <9>
===========unchanged ref 0=========== at: aioquic.connection.QuicConnection _handle_connection_close_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_challenge_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_response_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_retire_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_streams_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.packet QuicErrorCode(x: Union[str, bytes, bytearray], base: int) QuicErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) ===========changed ref 0=========== # module: aioquic.connection + class QuicConnectionState(Enum): + FIRSTFLIGHT = 0 + CONNECTED = 1 + CLOSING = 2 + DRAINING = 3 + ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: if not is_client: assert certificate is not None, "SSL certificate is required" assert private_key is not None, "SSL private key is required" self.alpn_protocols = alpn_protocols self.certificate = certificate self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.private_key = private_key self.secrets_log_file = secrets_log_file self.server_name = server_name self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} # protocol versions self.version = max(self.supported_versions) self.__close: Optional[Dict] = None self.__connected = asyncio.Event() self.__epoch = tls.Epoch.INITIAL self.__initialized = False self._local_idle_timeout = 60.0 # seconds self._local_max_data = 1048576 self._local_max_stream_data_bidi_local = 1048576 self._local_max_stream_data_bidi_remote = 1048576 self._local_max_stream_data_uni = 1048576 self._local_max_streams_bidi = 128 self._local_max_streams_uni = 128 self.__logger = logger self.__path_challenge: Optional[bytes] = None self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0.0 </s> ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 <s> self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0.0 self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self._spin_bit = False self._spin_highest_pn = 0 self.__send_pending_task: Optional[asyncio.Handle] = None + self.__state = QuicConnectionState.FIRSTFLIGHT self.__transport: Optional[asyncio.DatagramTransport] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_</s> ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s> self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ]
aioquic.connection/QuicConnection.datagram_received
Modified
aiortc~aioquic
c2fe1d62cdca6b6404f918b4cd1cde9ad9df693f
[connection] start adding state tracking
<4>:<add> <add> # stop handling packets when closing <add> if self.__state in [QuicConnectionState.CLOSING, QuicConnectionState.DRAINING]: <add> return
# module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: <0> """ <1> Handle an incoming datagram. <2> """ <3> buf = Buffer(data=data) <4> <5> while not buf.eof(): <6> start_off = buf.tell() <7> header = pull_quic_header(buf, host_cid_length=len(self.host_cid)) <8> <9> if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION: <10> # version negotiation <11> versions = [] <12> while not buf.eof(): <13> versions.append(pull_uint32(buf)) <14> common = set(self.supported_versions).intersection(versions) <15> if not common: <16> self.__logger.error("Could not find a common protocol version") <17> return <18> self.version = QuicProtocolVersion(max(common)) <19> self.__logger.info("Retrying with %s", self.version) <20> self.connection_made(self.__transport) <21> return <22> elif self.is_client and header.packet_type == PACKET_TYPE_RETRY: <23> # stateless retry <24> if ( <25> header.destination_cid == self.host_cid <26> and header.original_destination_cid == self.peer_cid <27> ): <28> self.__logger.info("Performing stateless retry") <29> self.peer_cid = header.source_cid <30> self.peer_token = header.token <31> self.connection_made(self.__transport) <32> return <33> <34> # server initialization <35> if not self.is_client and not self.__initialized: <36> assert ( <37> header.packet_type == PACKET_TYPE_INITIAL <38> ), "first packet must be INITIAL" <39> self._initialize(header.destination_cid) <40> <41> # decrypt packet <42> encrypted_off = buf.tell() - start_off <43> end_off = buf.tell() + header.</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 1 pull_bytes(buf, header.rest_length) epoch = get_epoch(header.packet_type) space = self.spaces[epoch] if not space.crypto.recv.is_valid(): return try: plain_header, plain_payload, packet_number = space.crypto.decrypt_packet( data[start_off:end_off], encrypted_off ) except CryptoError as exc: self.__logger.warning(exc) return if not self.peer_cid_set: self.peer_cid = header.source_cid self.peer_cid_set = True # update spin bit if ( not is_long_header(plain_header[0]) and packet_number > self._spin_highest_pn ): if self.is_client: self._spin_bit = not get_spin_bit(plain_header[0]) else: self._spin_bit = get_spin_bit(plain_header[0]) self._spin_highest_pn = packet_number # handle payload try: is_ack_only = self._payload_received(epoch, plain_payload) except QuicConnectionError as exc: self.__logger.warning(exc) self.close( error_code=exc.error_code, frame_type=exc.frame_type, reason_phrase=exc.reason_phrase, ) return # record packet as received space.ack_queue.add(packet_number) if not is_ack_only: self.send_ack[epoch] = True self._send_pending() ===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) pull_bytes(buf: Buffer, length: int) -> bytes pull_uint32(buf: Buffer) -> int at: aioquic.buffer.Buffer eof() -> bool tell() -> int at: aioquic.connection get_epoch(packet_type: int) -> tls.Epoch QuicConnectionState() at: aioquic.connection.PacketSpace.__init__ self.crypto = CryptoPair() at: aioquic.connection.QuicConnection supported_versions = [ QuicProtocolVersion.DRAFT_17, QuicProtocolVersion.DRAFT_18, QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20, ] _initialize(peer_cid: bytes) -> None _push_crypto_data() -> None _send_pending() -> None _set_state(state: QuicConnectionState) -> None at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.version = max(self.supported_versions) self.__initialized = False self.__logger = logger self.__state = QuicConnectionState.FIRSTFLIGHT self.__transport: Optional[asyncio.DatagramTransport] = None at: aioquic.connection.QuicConnection._initialize self.tls = tls.Context(is_client=self.is_client, logger=self.__logger) ===========unchanged ref 1=========== self.send_buffer = { tls.Epoch.INITIAL: Buffer(capacity=4096), tls.Epoch.HANDSHAKE: Buffer(capacity=4096), tls.Epoch.ONE_RTT: Buffer(capacity=4096), } self.spaces = { tls.Epoch.INITIAL: PacketSpace(), tls.Epoch.HANDSHAKE: PacketSpace(), tls.Epoch.ONE_RTT: PacketSpace(), } self.__initialized = True at: aioquic.connection.QuicConnection._set_state self.__state = state at: aioquic.crypto CryptoError(*args: object) at: aioquic.crypto.CryptoContext is_valid() -> bool at: aioquic.crypto.CryptoPair decrypt_packet(packet: bytes, encrypted_offset: int) -> Tuple[bytes, bytes, int] at: aioquic.crypto.CryptoPair.__init__ self.recv = CryptoContext() at: aioquic.packet PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int) QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) is_long_header(first_byte: int) -> bool pull_quic_header(buf: Buffer, host_cid_length: Optional[int]=None) -> QuicHeader at: aioquic.packet.QuicHeader version: Optional[int] packet_type: int destination_cid: bytes source_cid: bytes original_destination_cid: bytes = b"" token: bytes = b"" rest_length: int = 0 ===========unchanged ref 2=========== at: aioquic.stream.QuicStream.__init__ self.reader = asyncio.StreamReader() self.reader = None at: aioquic.tls.Context handle_message(input_data: bytes, output_buf: Dict[Epoch, Buffer]) -> None at: asyncio.streams.StreamReader _source_traceback = None feed_eof() -> None at: asyncio.transports DatagramTransport(extra: Optional[Mapping[Any, Any]]=...) at: logging.Logger info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None warning(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None error(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None ===========changed ref 0=========== # module: aioquic.connection + class QuicConnectionState(Enum): + FIRSTFLIGHT = 0 + CONNECTED = 1 + CLOSING = 2 + DRAINING = 3 + ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def close( + self, + error_code: int = QuicErrorCode.NO_ERROR, + frame_type: Optional[int] = None, + reason_phrase: str = "", - self, error_code: int, frame_type: Optional[int] = None, reason_phrase: str = "" ) -> None: """ Close the connection. """ self.__close = { "error_code": error_code, "frame_type": frame_type, "reason_phrase": reason_phrase, } + if self.__state not in [ + QuicConnectionState.CLOSING, + QuicConnectionState.DRAINING, + ]: + self._set_state(QuicConnectionState.CLOSING) + self.connection_lost(None) self._send_pending()
aioquic.connection/QuicConnection._handle_connection_close_frame
Modified
aiortc~aioquic
c2fe1d62cdca6b6404f918b4cd1cde9ad9df693f
[connection] start adding state tracking
<10>:<add> self._set_state(QuicConnectionState.DRAINING)
# module: aioquic.connection class QuicConnection: def _handle_connection_close_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: <0> """ <1> Handle a CONNECTION_CLOSE frame. <2> """ <3> if frame_type == QuicFrameType.TRANSPORT_CLOSE: <4> error_code, _, reason_phrase = packet.pull_transport_close_frame(buf) <5> else: <6> error_code, reason_phrase = packet.pull_application_close_frame(buf) <7> self.__logger.info( <8> "Connection close code 0x%X, reason %s", error_code, reason_phrase <9> ) <10> self.connection_lost(None) <11>
===========unchanged ref 0=========== at: aioquic.connection PacketSpace() at: aioquic.connection.PacketSpace.__init__ self.crypto = CryptoPair() at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} self.__initialized = False at: aioquic.crypto.CryptoPair setup_initial(cid: bytes, is_client: bool) -> None at: aioquic.stream QuicStream(stream_id: Optional[int]=None, connection: Optional[Any]=None, max_stream_data_local: int=0, max_stream_data_remote: int=0) at: aioquic.tls Epoch() ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def close( + self, + error_code: int = QuicErrorCode.NO_ERROR, + frame_type: Optional[int] = None, + reason_phrase: str = "", - self, error_code: int, frame_type: Optional[int] = None, reason_phrase: str = "" ) -> None: """ Close the connection. """ self.__close = { "error_code": error_code, "frame_type": frame_type, "reason_phrase": reason_phrase, } + if self.__state not in [ + QuicConnectionState.CLOSING, + QuicConnectionState.DRAINING, + ]: + self._set_state(QuicConnectionState.CLOSING) + self.connection_lost(None) self._send_pending() ===========changed ref 1=========== # module: aioquic.connection + class QuicConnectionState(Enum): + FIRSTFLIGHT = 0 + CONNECTED = 1 + CLOSING = 2 + DRAINING = 3 + ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: """ Handle an incoming datagram. """ buf = Buffer(data=data) + + # stop handling packets when closing + if self.__state in [QuicConnectionState.CLOSING, QuicConnectionState.DRAINING]: + return while not buf.eof(): start_off = buf.tell() header = pull_quic_header(buf, host_cid_length=len(self.host_cid)) if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION: # version negotiation versions = [] while not buf.eof(): versions.append(pull_uint32(buf)) common = set(self.supported_versions).intersection(versions) if not common: self.__logger.error("Could not find a common protocol version") return self.version = QuicProtocolVersion(max(common)) self.__logger.info("Retrying with %s", self.version) self.connection_made(self.__transport) return elif self.is_client and header.packet_type == PACKET_TYPE_RETRY: # stateless retry if ( header.destination_cid == self.host_cid and header.original_destination_cid == self.peer_cid ): self.__logger.info("Performing stateless retry") self.peer_cid = header.source_cid self.peer_token = header.token self.connection_made(self.__transport) return # server initialization if not self.is_client and not self.__initialized: assert ( header.packet_type == PACKET_TYPE_INITIAL ), "first packet must be INITIAL" self._initialize(header.destination_cid) # decrypt packet encrypted_off = buf.tell() - start_off end_off = buf.tell() + header.rest_length</s> ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 1 <s> encrypted_off = buf.tell() - start_off end_off = buf.tell() + header.rest_length pull_bytes(buf, header.rest_length) epoch = get_epoch(header.packet_type) space = self.spaces[epoch] if not space.crypto.recv.is_valid(): return try: plain_header, plain_payload, packet_number = space.crypto.decrypt_packet( data[start_off:end_off], encrypted_off ) except CryptoError as exc: self.__logger.warning(exc) return if not self.peer_cid_set: self.peer_cid = header.source_cid self.peer_cid_set = True + # update state + if self.__state == QuicConnectionState.FIRSTFLIGHT: + self._set_state(QuicConnectionState.CONNECTED) + # update spin bit if ( not is_long_header(plain_header[0]) and packet_number > self._spin_highest_pn ): if self.is_client: self._spin_bit = not get_spin_bit(plain_header[0]) else: self._spin_bit = get_spin_bit(plain_header[0]) self._spin_highest_pn = packet_number # handle payload try: is_ack_only = self._payload_received(epoch, plain_payload) except QuicConnectionError as exc: self.__logger.warning(exc) self.close( error_code=exc.error_code, frame_type=exc.frame_type, reason_phrase=exc.reason_phrase, ) </s> ===========changed ref 4=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 2 <s> # record packet as received space.ack_queue.add(packet_number) if not is_ack_only: self.send_ack[epoch] = True self._send_pending()
aioquic.packet/pull_ack_frame
Modified
aiortc~aioquic
3d79fc1182757b33db16d45c3a1b8f7f33a44594
[packet] fix ACK range parsing / serialization
<8>:<add> end -= pull_uint_var(buf) + 2 <del> end -= pull_uint_var(buf)
# module: aioquic.packet def pull_ack_frame(buf: Buffer) -> Tuple[RangeSet, int]: <0> rangeset = RangeSet() <1> end = pull_uint_var(buf) # largest acknowledged <2> delay = pull_uint_var(buf) <3> ack_range_count = pull_uint_var(buf) <4> ack_count = pull_uint_var(buf) # first ack range <5> rangeset.add(end - ack_count, end + 1) <6> end -= ack_count <7> for _ in range(ack_range_count): <8> end -= pull_uint_var(buf) <9> ack_count = pull_uint_var(buf) <10> rangeset.add(end - ack_count, end + 1) <11> end -= ack_count <12> return rangeset, delay <13>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.packet pull_uint_var(buf: Buffer) -> int at: aioquic.rangeset RangeSet(ranges: Iterable[range]=[]) at: aioquic.rangeset.RangeSet add(start: int, stop: Optional[int]=None) -> None at: typing Tuple = _TupleType(tuple, -1, inst=False, name='Tuple')
aioquic.packet/push_ack_frame
Modified
aiortc~aioquic
3d79fc1182757b33db16d45c3a1b8f7f33a44594
[packet] fix ACK range parsing / serialization
<10>:<add> push_uint_var(buf, start - r.stop - 1) <del> push_uint_var(buf, start - r.stop + 1)
# module: aioquic.packet def push_ack_frame(buf: Buffer, rangeset: RangeSet, delay: int) -> None: <0> index = len(rangeset) - 1 <1> r = rangeset[index] <2> push_uint_var(buf, r.stop - 1) <3> push_uint_var(buf, delay) <4> push_uint_var(buf, index) <5> push_uint_var(buf, r.stop - 1 - r.start) <6> start = r.start <7> while index > 0: <8> index -= 1 <9> r = rangeset[index] <10> push_uint_var(buf, start - r.stop + 1) <11> push_uint_var(buf, r.stop - r.start - 1) <12> start = r.start <13>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.packet push_uint_var(buf: Buffer, value: int) -> None at: aioquic.rangeset RangeSet(ranges: Iterable[range]=[]) ===========changed ref 0=========== # module: aioquic.packet def pull_ack_frame(buf: Buffer) -> Tuple[RangeSet, int]: rangeset = RangeSet() end = pull_uint_var(buf) # largest acknowledged delay = pull_uint_var(buf) ack_range_count = pull_uint_var(buf) ack_count = pull_uint_var(buf) # first ack range rangeset.add(end - ack_count, end + 1) end -= ack_count for _ in range(ack_range_count): + end -= pull_uint_var(buf) + 2 - end -= pull_uint_var(buf) ack_count = pull_uint_var(buf) rangeset.add(end - ack_count, end + 1) end -= ack_count return rangeset, delay
tests.test_connection/QuicConnectionTest.test_version_negotiation_fail
Modified
aiortc~aioquic
5cdd823e035acfcd762257bdc6d4eecf5f93d97c
[tests] serialize a version negotiation packet
<8>:<add> client.datagram_received( <add> encode_quic_version_negotiation( <add> source_cid=client.peer_cid, <add> destination_cid=client.host_cid, <add> supported_versions=[0xFF000011], # DRAFT_16 <add> ), <add> None, <add> ) <del> client.datagram_received(load("version_negotiation.bin"), None)
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_version_negotiation_fail(self): <0> client = QuicConnection(is_client=True) <1> client.supported_versions = [QuicProtocolVersion.DRAFT_19] <2> <3> client_transport = FakeTransport() <4> client.connection_made(client_transport) <5> self.assertEqual(client_transport.sent, 1) <6> <7> # no common version, no retry <8> client.datagram_received(load("version_negotiation.bin"), None) <9> self.assertEqual(client_transport.sent, 1) <10>
===========unchanged ref 0=========== at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection supported_versions = [ QuicProtocolVersion.DRAFT_17, QuicProtocolVersion.DRAFT_18, QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20, ] connection_made(transport: asyncio.DatagramTransport) -> None datagram_received(data: bytes, addr: Any) -> None at: aioquic.packet QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int) QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) at: tests.test_connection FakeTransport() at: tests.test_connection.FakeTransport.sendto self.sent += 1 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_connection/QuicConnectionTest.test_version_negotiation_ok
Modified
aiortc~aioquic
5cdd823e035acfcd762257bdc6d4eecf5f93d97c
[tests] serialize a version negotiation packet
<7>:<add> client.datagram_received( <add> encode_quic_version_negotiation( <add> source_cid=client.peer_cid, <add> destination_cid=client.host_cid, <add> supported_versions=[QuicProtocolVersion.DRAFT_19], <add> ), <add> None, <add> ) <del> client.datagram_received(load("version_negotiation.bin"), None)
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_version_negotiation_ok(self): <0> client = QuicConnection(is_client=True) <1> <2> client_transport = FakeTransport() <3> client.connection_made(client_transport) <4> self.assertEqual(client_transport.sent, 1) <5> <6> # found a common version, retry <7> client.datagram_received(load("version_negotiation.bin"), None) <8> self.assertEqual(client_transport.sent, 2) <9>
===========unchanged ref 0=========== at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection.__init__ self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) at: aioquic.connection.QuicConnection.datagram_received self.peer_cid = header.source_cid at: tests.test_connection.FakeTransport.sendto self.sent += 1 at: tests.test_connection.QuicConnectionTest.test_version_negotiation_fail client = QuicConnection(is_client=True) client_transport = FakeTransport() at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_version_negotiation_fail(self): client = QuicConnection(is_client=True) client.supported_versions = [QuicProtocolVersion.DRAFT_19] client_transport = FakeTransport() client.connection_made(client_transport) self.assertEqual(client_transport.sent, 1) # no common version, no retry + client.datagram_received( + encode_quic_version_negotiation( + source_cid=client.peer_cid, + destination_cid=client.host_cid, + supported_versions=[0xFF000011], # DRAFT_16 + ), + None, + ) - client.datagram_received(load("version_negotiation.bin"), None) self.assertEqual(client_transport.sent, 1)
aioquic.packet/push_quic_header
Modified
aiortc~aioquic
5672dd1bb49ab4293316afdc67c139f34fca9a13
[connection] remove support for draft 17 and draft 18
<1>:<add> push_uint32(buf, header.version) <del> push_protocol_version(buf, header.version)
# module: aioquic.packet def push_quic_header(buf: Buffer, header: QuicHeader) -> None: <0> push_uint8(buf, header.packet_type) <1> push_protocol_version(buf, header.version) <2> push_uint8( <3> buf, <4> (encode_cid_length(len(header.destination_cid)) << 4) <5> | encode_cid_length(len(header.source_cid)), <6> ) <7> push_bytes(buf, header.destination_cid) <8> push_bytes(buf, header.source_cid) <9> if (header.packet_type & PACKET_TYPE_MASK) == PACKET_TYPE_INITIAL: <10> push_uint_var(buf, len(header.token)) <11> push_bytes(buf, header.token) <12> push_uint16(buf, 0) # length <13> push_uint16(buf, 0) # pn <14>
===========unchanged ref 0=========== at: aioquic.buffer push_bytes(buf: Buffer, v: bytes) -> None push_uint16(buf: Buffer, v: int) -> None at: aioquic.packet PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_MASK = 0xF0 QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int) QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) push_uint_var(buf: Buffer, value: int) -> None at: aioquic.packet.QuicHeader version: Optional[int] packet_type: int destination_cid: bytes source_cid: bytes original_destination_cid: bytes = b"" token: bytes = b"" rest_length: int = 0 at: typing List = _alias(list, 1, inst=False, name='List') ===========changed ref 0=========== # module: aioquic.packet - push_protocol_version = push_uint32 - ===========changed ref 1=========== # module: aioquic.packet - def pull_protocol_version(buf: Buffer) -> QuicProtocolVersion: - return QuicProtocolVersion(pull_uint32(buf)) - ===========changed ref 2=========== # module: aioquic.packet PACKET_LONG_HEADER = 0x80 PACKET_FIXED_BIT = 0x40 PACKET_SPIN_BIT = 0x20 PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10 PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 PACKET_TYPE_MASK = 0xF0 UINT_VAR_FORMATS = [ (pull_uint8, push_uint8, 0x3F), (pull_uint16, push_uint16, 0x3FFF), (pull_uint32, push_uint32, 0x3FFFFFFF), (pull_uint64, push_uint64, 0x3FFFFFFFFFFFFFFF), ] -
aioquic.packet/encode_quic_version_negotiation
Modified
aiortc~aioquic
5672dd1bb49ab4293316afdc67c139f34fca9a13
[connection] remove support for draft 17 and draft 18
<2>:<add> push_uint32(buf, QuicProtocolVersion.NEGOTIATION) <del> push_protocol_version(buf, QuicProtocolVersion.NEGOTIATION) <11>:<add> push_uint32(buf, version) <del> push_protocol_version(buf, version)
# module: aioquic.packet def encode_quic_version_negotiation( source_cid: bytes, destination_cid: bytes, supported_versions: List[QuicProtocolVersion], ) -> bytes: <0> buf = Buffer(capacity=100) <1> push_uint8(buf, os.urandom(1)[0] | PACKET_LONG_HEADER) <2> push_protocol_version(buf, QuicProtocolVersion.NEGOTIATION) <3> push_uint8( <4> buf, <5> (encode_cid_length(len(destination_cid)) << 4) <6> | encode_cid_length(len(source_cid)), <7> ) <8> push_bytes(buf, destination_cid) <9> push_bytes(buf, source_cid) <10> for version in supported_versions: <11> push_protocol_version(buf, version) <12> return buf.data <13>
===========unchanged ref 0=========== at: aioquic.buffer push_bytes(buf: Buffer, v: bytes) -> None push_uint8(buf: Buffer, v: int) -> None push_uint32(buf: Buffer, v: int) -> None at: aioquic.packet QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int) QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) encode_cid_length(length: int) -> int at: aioquic.packet.encode_quic_version_negotiation buf = Buffer(capacity=100) at: dataclasses dataclass(*, init: bool=..., repr: bool=..., eq: bool=..., order: bool=..., unsafe_hash: bool=..., frozen: bool=...) -> Callable[[Type[_T]], Type[_T]] dataclass(_cls: None) -> Callable[[Type[_T]], Type[_T]] dataclass(_cls: Type[_T]) -> Type[_T] ===========changed ref 0=========== # module: aioquic.packet - push_protocol_version = push_uint32 - ===========changed ref 1=========== # module: aioquic.packet - def pull_protocol_version(buf: Buffer) -> QuicProtocolVersion: - return QuicProtocolVersion(pull_uint32(buf)) - ===========changed ref 2=========== # module: aioquic.packet def push_quic_header(buf: Buffer, header: QuicHeader) -> None: push_uint8(buf, header.packet_type) + push_uint32(buf, header.version) - push_protocol_version(buf, header.version) push_uint8( buf, (encode_cid_length(len(header.destination_cid)) << 4) | encode_cid_length(len(header.source_cid)), ) push_bytes(buf, header.destination_cid) push_bytes(buf, header.source_cid) if (header.packet_type & PACKET_TYPE_MASK) == PACKET_TYPE_INITIAL: push_uint_var(buf, len(header.token)) push_bytes(buf, header.token) push_uint16(buf, 0) # length push_uint16(buf, 0) # pn ===========changed ref 3=========== # module: aioquic.packet PACKET_LONG_HEADER = 0x80 PACKET_FIXED_BIT = 0x40 PACKET_SPIN_BIT = 0x20 PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10 PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 PACKET_TYPE_MASK = 0xF0 UINT_VAR_FORMATS = [ (pull_uint8, push_uint8, 0x3F), (pull_uint16, push_uint16, 0x3FFF), (pull_uint32, push_uint32, 0x3FFFFFFF), (pull_uint64, push_uint64, 0x3FFFFFFFFFFFFFFF), ] -
aioquic.packet/pull_quic_transport_parameters
Modified
aiortc~aioquic
5672dd1bb49ab4293316afdc67c139f34fca9a13
[connection] remove support for draft 17 and draft 18
<1>:<del> <2>:<del> # version < DRAFT_19 <3>:<del> if is_client: <4>:<del> params.initial_version = pull_protocol_version(buf) <5>:<del> elif is_client is False: <6>:<del> params.negotiated_version = pull_protocol_version(buf) <7>:<del> params.supported_versions = pull_list(buf, 1, pull_protocol_version)
# module: aioquic.packet - def pull_quic_transport_parameters( - buf: Buffer, is_client: Optional[bool] = None - ) -> QuicTransportParameters: + def pull_quic_transport_parameters(buf: Buffer) -> QuicTransportParameters: <0> params = QuicTransportParameters() <1> <2> # version < DRAFT_19 <3> if is_client: <4> params.initial_version = pull_protocol_version(buf) <5> elif is_client is False: <6> params.negotiated_version = pull_protocol_version(buf) <7> params.supported_versions = pull_list(buf, 1, pull_protocol_version) <8> <9> with pull_block(buf, 2) as length: <10> end = buf.tell() + length <11> while buf.tell() < end: <12> param_id = pull_uint16(buf) <13> param_len = pull_uint16(buf) <14> param_start = buf.tell() <15> if param_id < len(PARAMS): <16> # parse known parameter <17> param_name, param_type = PARAMS[param_id] <18> if param_type == int: <19> setattr(params, param_name, pull_uint_var(buf)) <20> elif param_type == bytes: <21> setattr(params, param_name, pull_bytes(buf, param_len)) <22> else: <23> setattr(params, param_name, True) <24> else: <25> # skip unknown parameter <26> pull_bytes(buf, param_len) <27> assert buf.tell() == param_start + param_len <28> <29> return params <30>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) pull_bytes(buf: Buffer, length: int) -> bytes push_bytes(buf: Buffer, v: bytes) -> None pull_uint16(buf: Buffer) -> int push_uint16(buf: Buffer, v: int) -> None at: aioquic.buffer.Buffer tell() -> int at: aioquic.packet pull_uint_var(buf: Buffer) -> int push_uint_var(buf: Buffer, value: int) -> None QuicTransportParameters(initial_version: Optional[QuicProtocolVersion]=None, negotiated_version: Optional[QuicProtocolVersion]=None, supported_versions: List[QuicProtocolVersion]=field(default_factory=list), original_connection_id: Optional[bytes]=None, idle_timeout: Optional[int]=None, stateless_reset_token: Optional[bytes]=None, max_packet_size: Optional[int]=None, initial_max_data: Optional[int]=None, initial_max_stream_data_bidi_local: Optional[int]=None, initial_max_stream_data_bidi_remote: Optional[int]=None, initial_max_stream_data_uni: Optional[int]=None, initial_max_streams_bidi: Optional[int]=None, initial_max_streams_uni: Optional[int]=None, ack_delay_exponent: Optional[int]=None, max_ack_delay: Optional[int]=None, disable_migration: Optional[bool]=False, preferred_address: Optional[bytes]=None) ===========unchanged ref 1=========== PARAMS = [ ("original_connection_id", bytes), ("idle_timeout", int), ("stateless_reset_token", bytes), ("max_packet_size", int), ("initial_max_data", int), ("initial_max_stream_data_bidi_local", int), ("initial_max_stream_data_bidi_remote", int), ("initial_max_stream_data_uni", int), ("initial_max_streams_bidi", int), ("initial_max_streams_uni", int), ("ack_delay_exponent", int), ("max_ack_delay", int), ("disable_migration", bool), ("preferred_address", bytes), ] at: aioquic.packet.pull_quic_transport_parameters params = QuicTransportParameters() param_id = pull_uint16(buf) at: aioquic.tls push_block(buf: Buffer, capacity: int) -> Generator ===========changed ref 0=========== # module: aioquic.packet - push_protocol_version = push_uint32 - ===========changed ref 1=========== # module: aioquic.packet - def pull_protocol_version(buf: Buffer) -> QuicProtocolVersion: - return QuicProtocolVersion(pull_uint32(buf)) - ===========changed ref 2=========== # module: aioquic.packet def encode_quic_version_negotiation( source_cid: bytes, destination_cid: bytes, supported_versions: List[QuicProtocolVersion], ) -> bytes: buf = Buffer(capacity=100) push_uint8(buf, os.urandom(1)[0] | PACKET_LONG_HEADER) + push_uint32(buf, QuicProtocolVersion.NEGOTIATION) - push_protocol_version(buf, QuicProtocolVersion.NEGOTIATION) push_uint8( buf, (encode_cid_length(len(destination_cid)) << 4) | encode_cid_length(len(source_cid)), ) push_bytes(buf, destination_cid) push_bytes(buf, source_cid) for version in supported_versions: + push_uint32(buf, version) - push_protocol_version(buf, version) return buf.data ===========changed ref 3=========== # module: aioquic.packet def push_quic_header(buf: Buffer, header: QuicHeader) -> None: push_uint8(buf, header.packet_type) + push_uint32(buf, header.version) - push_protocol_version(buf, header.version) push_uint8( buf, (encode_cid_length(len(header.destination_cid)) << 4) | encode_cid_length(len(header.source_cid)), ) push_bytes(buf, header.destination_cid) push_bytes(buf, header.source_cid) if (header.packet_type & PACKET_TYPE_MASK) == PACKET_TYPE_INITIAL: push_uint_var(buf, len(header.token)) push_bytes(buf, header.token) push_uint16(buf, 0) # length push_uint16(buf, 0) # pn ===========changed ref 4=========== # module: aioquic.packet PACKET_LONG_HEADER = 0x80 PACKET_FIXED_BIT = 0x40 PACKET_SPIN_BIT = 0x20 PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10 PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 PACKET_TYPE_MASK = 0xF0 UINT_VAR_FORMATS = [ (pull_uint8, push_uint8, 0x3F), (pull_uint16, push_uint16, 0x3FFF), (pull_uint32, push_uint32, 0x3FFFFFFF), (pull_uint64, push_uint64, 0x3FFFFFFFFFFFFFFF), ] -
aioquic.packet/push_quic_transport_parameters
Modified
aiortc~aioquic
5672dd1bb49ab4293316afdc67c139f34fca9a13
[connection] remove support for draft 17 and draft 18
<0>:<del> # version < DRAFT_19 <1>:<del> if is_client: <2>:<del> push_protocol_version(buf, params.initial_version) <3>:<del> elif is_client is False: <4>:<del> push_protocol_version(buf, params.negotiated_version) <5>:<del> push_list(buf, 1, push_protocol_version, params.supported_versions) <6>:<del>
# module: aioquic.packet def push_quic_transport_parameters( + buf: Buffer, params: QuicTransportParameters - buf: Buffer, params: QuicTransportParameters, is_client: Optional[bool] = None ) -> None: <0> # version < DRAFT_19 <1> if is_client: <2> push_protocol_version(buf, params.initial_version) <3> elif is_client is False: <4> push_protocol_version(buf, params.negotiated_version) <5> push_list(buf, 1, push_protocol_version, params.supported_versions) <6> <7> with push_block(buf, 2): <8> for param_id, (param_name, param_type) in enumerate(PARAMS): <9> param_value = getattr(params, param_name) <10> if param_value is not None and param_value is not False: <11> push_uint16(buf, param_id) <12> with push_block(buf, 2): <13> if param_type == int: <14> push_uint_var(buf, param_value) <15> elif param_type == bytes: <16> push_bytes(buf, param_value) <17>
===========unchanged ref 0=========== at: aioquic.packet.QuicFrameType NEW_CONNECTION_ID = 0x18 RETIRE_CONNECTION_ID = 0x19 PATH_CHALLENGE = 0x1A PATH_RESPONSE = 0x1B TRANSPORT_CLOSE = 0x1C APPLICATION_CLOSE = 0x1D at: enum IntEnum(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) IntEnum(x: Union[str, bytes, bytearray], base: int) ===========changed ref 0=========== # module: aioquic.packet - push_protocol_version = push_uint32 - ===========changed ref 1=========== # module: aioquic.packet - def pull_protocol_version(buf: Buffer) -> QuicProtocolVersion: - return QuicProtocolVersion(pull_uint32(buf)) - ===========changed ref 2=========== # module: aioquic.packet def encode_quic_version_negotiation( source_cid: bytes, destination_cid: bytes, supported_versions: List[QuicProtocolVersion], ) -> bytes: buf = Buffer(capacity=100) push_uint8(buf, os.urandom(1)[0] | PACKET_LONG_HEADER) + push_uint32(buf, QuicProtocolVersion.NEGOTIATION) - push_protocol_version(buf, QuicProtocolVersion.NEGOTIATION) push_uint8( buf, (encode_cid_length(len(destination_cid)) << 4) | encode_cid_length(len(source_cid)), ) push_bytes(buf, destination_cid) push_bytes(buf, source_cid) for version in supported_versions: + push_uint32(buf, version) - push_protocol_version(buf, version) return buf.data ===========changed ref 3=========== # module: aioquic.packet def push_quic_header(buf: Buffer, header: QuicHeader) -> None: push_uint8(buf, header.packet_type) + push_uint32(buf, header.version) - push_protocol_version(buf, header.version) push_uint8( buf, (encode_cid_length(len(header.destination_cid)) << 4) | encode_cid_length(len(header.source_cid)), ) push_bytes(buf, header.destination_cid) push_bytes(buf, header.source_cid) if (header.packet_type & PACKET_TYPE_MASK) == PACKET_TYPE_INITIAL: push_uint_var(buf, len(header.token)) push_bytes(buf, header.token) push_uint16(buf, 0) # length push_uint16(buf, 0) # pn ===========changed ref 4=========== # module: aioquic.packet - def pull_quic_transport_parameters( - buf: Buffer, is_client: Optional[bool] = None - ) -> QuicTransportParameters: + def pull_quic_transport_parameters(buf: Buffer) -> QuicTransportParameters: params = QuicTransportParameters() - - # version < DRAFT_19 - if is_client: - params.initial_version = pull_protocol_version(buf) - elif is_client is False: - params.negotiated_version = pull_protocol_version(buf) - params.supported_versions = pull_list(buf, 1, pull_protocol_version) with pull_block(buf, 2) as length: end = buf.tell() + length while buf.tell() < end: param_id = pull_uint16(buf) param_len = pull_uint16(buf) param_start = buf.tell() if param_id < len(PARAMS): # parse known parameter param_name, param_type = PARAMS[param_id] if param_type == int: setattr(params, param_name, pull_uint_var(buf)) elif param_type == bytes: setattr(params, param_name, pull_bytes(buf, param_len)) else: setattr(params, param_name, True) else: # skip unknown parameter pull_bytes(buf, param_len) assert buf.tell() == param_start + param_len return params ===========changed ref 5=========== # module: aioquic.packet PACKET_LONG_HEADER = 0x80 PACKET_FIXED_BIT = 0x40 PACKET_SPIN_BIT = 0x20 PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10 PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 PACKET_TYPE_MASK = 0xF0 UINT_VAR_FORMATS = [ (pull_uint8, push_uint8, 0x3F), (pull_uint16, push_uint16, 0x3FFF), (pull_uint32, push_uint32, 0x3FFFFFFF), (pull_uint64, push_uint64, 0x3FFFFFFFFFFFFFFF), ] -
aioquic.connection/QuicConnection.__init__
Modified
aiortc~aioquic
5672dd1bb49ab4293316afdc67c139f34fca9a13
[connection] remove support for draft 17 and draft 18
<23>:<add> self._local_idle_timeout = 60000 # milliseconds <del> self._local_idle_timeout = 60.0 # seconds
# module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: <0> if not is_client: <1> assert certificate is not None, "SSL certificate is required" <2> assert private_key is not None, "SSL private key is required" <3> <4> self.alpn_protocols = alpn_protocols <5> self.certificate = certificate <6> self.is_client = is_client <7> self.host_cid = os.urandom(8) <8> self.peer_cid = os.urandom(8) <9> self.peer_cid_set = False <10> self.peer_token = b"" <11> self.private_key = private_key <12> self.secrets_log_file = secrets_log_file <13> self.server_name = server_name <14> self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} <15> <16> # protocol versions <17> self.version = max(self.supported_versions) <18> <19> self.__close: Optional[Dict] = None <20> self.__connected = asyncio.Event() <21> self.__epoch = tls.Epoch.INITIAL <22> self.__initialized = False <23> self._local_idle_timeout = 60.0 # seconds <24> self._local_max_data = 1048576 <25> self._local_max_stream_data_bidi_local = 1048576 <26> self._local_max_stream_data_bidi_remote = 1048576 <27> self._local_max_stream_data_uni = 1048576 <28> self._local_max_streams_bidi = 128 <29> self._local_max_streams_uni = 128 <30> self.__logger = logger <31> self.__path_challenge: Optional[bytes] =</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0.0 self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self._spin_bit = False self._spin_highest_pn = 0 self.__send_pending_task: Optional[asyncio.Handle] = None self.__state = QuicConnectionState.FIRSTFLIGHT self.__transport: Optional[asyncio.DatagramTransport] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, </s> ===========below chunk 1=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s> self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ] ===========unchanged ref 0=========== at: aioquic.connection logger = logging.getLogger("quic") QuicConnectionState() at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] _handle_ack_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_connection_close_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_crypto_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_stream_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_bidi_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_uni_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_token_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_padding_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_challenge_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_response_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_reset_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None ===========unchanged ref 1=========== _handle_retire_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stop_sending_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_streams_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.connection.QuicConnection._handle_crypto_frame self.__epoch = tls.Epoch.ONE_RTT self.__epoch = tls.Epoch.HANDSHAKE at: aioquic.connection.QuicConnection._handle_max_data_frame self._remote_max_data = max_data at: aioquic.connection.QuicConnection._handle_max_streams_bidi_frame self._remote_max_streams_bidi = max_streams at: aioquic.connection.QuicConnection._handle_max_streams_uni_frame self._remote_max_streams_uni = max_streams at: aioquic.connection.QuicConnection._initialize self.__initialized = True at: aioquic.connection.QuicConnection._parse_transport_parameters self._remote_idle_timeout = quic_transport_parameters.idle_timeout at: aioquic.connection.QuicConnection._send_path_challenge self.__path_challenge = os.urandom(8) at: aioquic.connection.QuicConnection._send_pending self.__send_pending_task = None at: aioquic.connection.QuicConnection._send_soon self.__send_pending_task = loop.call_soon(self._send_pending) at: aioquic.connection.QuicConnection._set_state self.__state = state
aioquic.connection/QuicConnection._parse_transport_parameters
Modified
aiortc~aioquic
5672dd1bb49ab4293316afdc67c139f34fca9a13
[connection] remove support for draft 17 and draft 18
<0>:<del> if self.version >= QuicProtocolVersion.DRAFT_19: <1>:<del> is_client = None <2>:<del> else: <3>:<del> is_client = not self.is_client <4>:<add> quic_transport_parameters = pull_quic_transport_parameters(Buffer(data=data)) <del> quic_transport_parameters = pull_quic_transport_parameters( <5>:<del> Buffer(data=data), is_client=is_client <6>:<del> ) <10>:<del> if self.version >= QuicProtocolVersion.DRAFT_19: <11>:<del> self._remote_idle_timeout = ( <12>:<del> quic_transport_parameters.idle_timeout / 1000 <13>:<del> ) <14>:<del> else: <15>:<add> self._remote_idle_timeout = quic_transport_parameters.idle_timeout <del> self._remote_idle_timeout = quic_transport_parameters.idle_timeout
# module: aioquic.connection class QuicConnection: def _parse_transport_parameters(self, data: bytes) -> None: <0> if self.version >= QuicProtocolVersion.DRAFT_19: <1> is_client = None <2> else: <3> is_client = not self.is_client <4> quic_transport_parameters = pull_quic_transport_parameters( <5> Buffer(data=data), is_client=is_client <6> ) <7> <8> # store remote parameters <9> if quic_transport_parameters.idle_timeout is not None: <10> if self.version >= QuicProtocolVersion.DRAFT_19: <11> self._remote_idle_timeout = ( <12> quic_transport_parameters.idle_timeout / 1000 <13> ) <14> else: <15> self._remote_idle_timeout = quic_transport_parameters.idle_timeout <16> for param in [ <17> "max_data", <18> "max_stream_data_bidi_local", <19> "max_stream_data_bidi_remote", <20> "max_stream_data_uni", <21> "max_streams_bidi", <22> "max_streams_uni", <23> ]: <24> value = getattr(quic_transport_parameters, "initial_" + param) <25> if value is not None: <26> setattr(self, "_remote_" + param, value) <27>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.connection.QuicConnection.__init__ self._local_idle_timeout = 60000 # milliseconds self._local_max_data = 1048576 self._local_max_stream_data_bidi_local = 1048576 self._local_max_stream_data_bidi_remote = 1048576 self._local_max_stream_data_uni = 1048576 self._local_max_streams_bidi = 128 self._local_max_streams_uni = 128 self._remote_idle_timeout = 0 # milliseconds at: aioquic.connection.QuicConnection._parse_transport_parameters quic_transport_parameters = pull_quic_transport_parameters(Buffer(data=data)) at: aioquic.packet QuicTransportParameters(initial_version: Optional[QuicProtocolVersion]=None, negotiated_version: Optional[QuicProtocolVersion]=None, supported_versions: List[QuicProtocolVersion]=field(default_factory=list), original_connection_id: Optional[bytes]=None, idle_timeout: Optional[int]=None, stateless_reset_token: Optional[bytes]=None, max_packet_size: Optional[int]=None, initial_max_data: Optional[int]=None, initial_max_stream_data_bidi_local: Optional[int]=None, initial_max_stream_data_bidi_remote: Optional[int]=None, initial_max_stream_data_uni: Optional[int]=None, initial_max_streams_bidi: Optional[int]=None, initial_max_streams_uni: Optional[int]=None, ack_delay_exponent: Optional[int]=None, max_ack_delay: Optional[int]=None, disable_migration: Optional[bool]=False, preferred_address: Optional[bytes]=None) ===========unchanged ref 1=========== push_quic_transport_parameters(buf: Buffer, params: QuicTransportParameters) -> None at: aioquic.packet.QuicTransportParameters initial_version: Optional[QuicProtocolVersion] = None negotiated_version: Optional[QuicProtocolVersion] = None supported_versions: List[QuicProtocolVersion] = field(default_factory=list) original_connection_id: Optional[bytes] = None idle_timeout: Optional[int] = None stateless_reset_token: Optional[bytes] = None max_packet_size: Optional[int] = None initial_max_data: Optional[int] = None initial_max_stream_data_bidi_local: Optional[int] = None initial_max_stream_data_bidi_remote: Optional[int] = None initial_max_stream_data_uni: Optional[int] = None initial_max_streams_bidi: Optional[int] = None initial_max_streams_uni: Optional[int] = None ack_delay_exponent: Optional[int] = None max_ack_delay: Optional[int] = None disable_migration: Optional[bool] = False preferred_address: Optional[bytes] = None ===========changed ref 0=========== # module: aioquic.packet def push_quic_transport_parameters( + buf: Buffer, params: QuicTransportParameters - buf: Buffer, params: QuicTransportParameters, is_client: Optional[bool] = None ) -> None: - # version < DRAFT_19 - if is_client: - push_protocol_version(buf, params.initial_version) - elif is_client is False: - push_protocol_version(buf, params.negotiated_version) - push_list(buf, 1, push_protocol_version, params.supported_versions) - with push_block(buf, 2): for param_id, (param_name, param_type) in enumerate(PARAMS): param_value = getattr(params, param_name) if param_value is not None and param_value is not False: push_uint16(buf, param_id) with push_block(buf, 2): if param_type == int: push_uint_var(buf, param_value) elif param_type == bytes: push_bytes(buf, param_value) ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: """ A QUIC connection. :param: is_client: `True` for a client, `False` for a server. :param: certificate: For a server, its certificate. See :func:`cryptography.x509.load_pem_x509_certificate`. :param: private_key: For a server, its private key. See :func:`cryptography.hazmat.primitives.serialization.load_pem_private_key`. """ - supported_versions = [ - QuicProtocolVersion.DRAFT_17, - QuicProtocolVersion.DRAFT_18, - QuicProtocolVersion.DRAFT_19, - QuicProtocolVersion.DRAFT_20, - ] + supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] ===========changed ref 2=========== # module: aioquic.packet - push_protocol_version = push_uint32 - ===========changed ref 3=========== # module: aioquic.packet - def pull_protocol_version(buf: Buffer) -> QuicProtocolVersion: - return QuicProtocolVersion(pull_uint32(buf)) - ===========changed ref 4=========== # module: aioquic.packet def encode_quic_version_negotiation( source_cid: bytes, destination_cid: bytes, supported_versions: List[QuicProtocolVersion], ) -> bytes: buf = Buffer(capacity=100) push_uint8(buf, os.urandom(1)[0] | PACKET_LONG_HEADER) + push_uint32(buf, QuicProtocolVersion.NEGOTIATION) - push_protocol_version(buf, QuicProtocolVersion.NEGOTIATION) push_uint8( buf, (encode_cid_length(len(destination_cid)) << 4) | encode_cid_length(len(source_cid)), ) push_bytes(buf, destination_cid) push_bytes(buf, source_cid) for version in supported_versions: + push_uint32(buf, version) - push_protocol_version(buf, version) return buf.data ===========changed ref 5=========== # module: aioquic.packet def push_quic_header(buf: Buffer, header: QuicHeader) -> None: push_uint8(buf, header.packet_type) + push_uint32(buf, header.version) - push_protocol_version(buf, header.version) push_uint8( buf, (encode_cid_length(len(header.destination_cid)) << 4) | encode_cid_length(len(header.source_cid)), ) push_bytes(buf, header.destination_cid) push_bytes(buf, header.source_cid) if (header.packet_type & PACKET_TYPE_MASK) == PACKET_TYPE_INITIAL: push_uint_var(buf, len(header.token)) push_bytes(buf, header.token) push_uint16(buf, 0) # length push_uint16(buf, 0) # pn
aioquic.connection/QuicConnection._serialize_transport_parameters
Modified
aiortc~aioquic
5672dd1bb49ab4293316afdc67c139f34fca9a13
[connection] remove support for draft 17 and draft 18
<1>:<add> idle_timeout=self._local_idle_timeout, <9>:<del> if self.version >= QuicProtocolVersion.DRAFT_19: <10>:<del> is_client = None <11>:<del> quic_transport_parameters.idle_timeout = int( <12>:<del> self._local_idle_timeout * 1000 <13>:<del> ) <14>:<del> else: <15>:<del> is_client = self.is_client <16>:<del> quic_transport_parameters.idle_timeout = int(self._local_idle_timeout) <17>:<del> if self.is_client: <18>:<del> quic_transport_parameters.initial_version = self.version <19>:<del> else: <20>:<del> quic_transport_parameters.negotiated_version = self.version <21>:<del> quic_transport_parameters.supported_versions = self.supported_versions <22>:<del> quic_transport_parameters.stateless_reset_token = bytes(16) <25>:<del> push_quic_transport_parameters( <26>:<del> buf, quic_transport_parameters, is_client=is_client <27>:<del> ) <28>:<add> push_quic_transport_parameters(buf, quic_transport_parameters)
# module: aioquic.connection class QuicConnection: def _serialize_transport_parameters(self) -> bytes: <0> quic_transport_parameters = QuicTransportParameters( <1> initial_max_data=self._local_max_data, <2> initial_max_stream_data_bidi_local=self._local_max_stream_data_bidi_local, <3> initial_max_stream_data_bidi_remote=self._local_max_stream_data_bidi_remote, <4> initial_max_stream_data_uni=self._local_max_stream_data_uni, <5> initial_max_streams_bidi=self._local_max_streams_bidi, <6> initial_max_streams_uni=self._local_max_streams_uni, <7> ack_delay_exponent=10, <8> ) <9> if self.version >= QuicProtocolVersion.DRAFT_19: <10> is_client = None <11> quic_transport_parameters.idle_timeout = int( <12> self._local_idle_timeout * 1000 <13> ) <14> else: <15> is_client = self.is_client <16> quic_transport_parameters.idle_timeout = int(self._local_idle_timeout) <17> if self.is_client: <18> quic_transport_parameters.initial_version = self.version <19> else: <20> quic_transport_parameters.negotiated_version = self.version <21> quic_transport_parameters.supported_versions = self.supported_versions <22> quic_transport_parameters.stateless_reset_token = bytes(16) <23> <24> buf = Buffer(capacity=512) <25> push_quic_transport_parameters( <26> buf, quic_transport_parameters, is_client=is_client <27> ) <28> return buf.data <29>
===========unchanged ref 0=========== at: aioquic.connection SECRETS_LABELS = [ [ None, "QUIC_CLIENT_EARLY_TRAFFIC_SECRET", "QUIC_CLIENT_HANDSHAKE_TRAFFIC_SECRET", "QUIC_CLIENT_TRAFFIC_SECRET_0", ], [ None, None, "QUIC_SERVER_HANDSHAKE_TRAFFIC_SECRET", "QUIC_SERVER_TRAFFIC_SECRET_0", ], ] stream_is_client_initiated(stream_id: int) -> bool stream_is_unidirectional(stream_id: int) -> bool QuicConnectionState() at: aioquic.connection.PacketSpace.__init__ self.crypto = CryptoPair() at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.secrets_log_file = secrets_log_file self.__logger = logger self.__state = QuicConnectionState.FIRSTFLIGHT at: aioquic.connection.QuicConnection._initialize self.tls = tls.Context(is_client=self.is_client, logger=self.__logger) self.spaces = { tls.Epoch.INITIAL: PacketSpace(), tls.Epoch.HANDSHAKE: PacketSpace(), tls.Epoch.ONE_RTT: PacketSpace(), } at: aioquic.crypto.CryptoContext setup(cipher_suite: CipherSuite, secret: bytes) -> None at: aioquic.crypto.CryptoPair.__init__ self.recv = CryptoContext() self.send = CryptoContext() at: aioquic.tls Direction() Epoch() at: aioquic.tls.Context.__init__ self.key_schedule: Optional[KeySchedule] = None self.client_random = None self.client_random = os.urandom(32) ===========unchanged ref 1=========== at: aioquic.tls.Context._client_handle_hello self.key_schedule = self._key_schedule_proxy.select(peer_hello.cipher_suite) at: aioquic.tls.Context._server_handle_hello self.client_random = peer_hello.random self.key_schedule = KeySchedule(cipher_suite) at: aioquic.tls.KeySchedule.__init__ self.cipher_suite = cipher_suite at: enum.Enum name: str value: Any _name_: str _value_: Any _member_names_: List[str] # undocumented _member_map_: Dict[str, Enum] # undocumented _value2member_map_: Dict[int, Enum] # undocumented _ignore_: Union[str, List[str]] _order_: str __order__: str at: logging.Logger info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None at: typing.IO __slots__ = () flush() -> None write(s: AnyStr) -> int ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def _parse_transport_parameters(self, data: bytes) -> None: - if self.version >= QuicProtocolVersion.DRAFT_19: - is_client = None - else: - is_client = not self.is_client + quic_transport_parameters = pull_quic_transport_parameters(Buffer(data=data)) - quic_transport_parameters = pull_quic_transport_parameters( - Buffer(data=data), is_client=is_client - ) # store remote parameters if quic_transport_parameters.idle_timeout is not None: - if self.version >= QuicProtocolVersion.DRAFT_19: - self._remote_idle_timeout = ( - quic_transport_parameters.idle_timeout / 1000 - ) - else: + self._remote_idle_timeout = quic_transport_parameters.idle_timeout - self._remote_idle_timeout = quic_transport_parameters.idle_timeout for param in [ "max_data", "max_stream_data_bidi_local", "max_stream_data_bidi_remote", "max_stream_data_uni", "max_streams_bidi", "max_streams_uni", ]: value = getattr(quic_transport_parameters, "initial_" + param) if value is not None: setattr(self, "_remote_" + param, value) ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: """ A QUIC connection. :param: is_client: `True` for a client, `False` for a server. :param: certificate: For a server, its certificate. See :func:`cryptography.x509.load_pem_x509_certificate`. :param: private_key: For a server, its private key. See :func:`cryptography.hazmat.primitives.serialization.load_pem_private_key`. """ - supported_versions = [ - QuicProtocolVersion.DRAFT_17, - QuicProtocolVersion.DRAFT_18, - QuicProtocolVersion.DRAFT_19, - QuicProtocolVersion.DRAFT_20, - ] + supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] ===========changed ref 2=========== # module: aioquic.packet - push_protocol_version = push_uint32 - ===========changed ref 3=========== # module: aioquic.packet - def pull_protocol_version(buf: Buffer) -> QuicProtocolVersion: - return QuicProtocolVersion(pull_uint32(buf)) - ===========changed ref 4=========== # module: aioquic.packet def encode_quic_version_negotiation( source_cid: bytes, destination_cid: bytes, supported_versions: List[QuicProtocolVersion], ) -> bytes: buf = Buffer(capacity=100) push_uint8(buf, os.urandom(1)[0] | PACKET_LONG_HEADER) + push_uint32(buf, QuicProtocolVersion.NEGOTIATION) - push_protocol_version(buf, QuicProtocolVersion.NEGOTIATION) push_uint8( buf, (encode_cid_length(len(destination_cid)) << 4) | encode_cid_length(len(source_cid)), ) push_bytes(buf, destination_cid) push_bytes(buf, source_cid) for version in supported_versions: + push_uint32(buf, version) - push_protocol_version(buf, version) return buf.data ===========changed ref 5=========== # module: aioquic.packet def push_quic_header(buf: Buffer, header: QuicHeader) -> None: push_uint8(buf, header.packet_type) + push_uint32(buf, header.version) - push_protocol_version(buf, header.version) push_uint8( buf, (encode_cid_length(len(header.destination_cid)) << 4) | encode_cid_length(len(header.source_cid)), ) push_bytes(buf, header.destination_cid) push_bytes(buf, header.source_cid) if (header.packet_type & PACKET_TYPE_MASK) == PACKET_TYPE_INITIAL: push_uint_var(buf, len(header.token)) push_bytes(buf, header.token) push_uint16(buf, 0) # length push_uint16(buf, 0) # pn
aioquic.connection/QuicConnection.datagram_received
Modified
aiortc~aioquic
975d3acc15e8e789e7fe159356dd92e4ea3d27d3
[connection] for clients, check destination CID matches
<12>:<add> <add> # check destination CID matches <add> if self.is_client and header.destination_cid != self.host_cid: <add> return
# module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: <0> """ <1> Handle an incoming datagram. <2> """ <3> buf = Buffer(data=data) <4> <5> # stop handling packets when closing <6> if self.__state in [QuicConnectionState.CLOSING, QuicConnectionState.DRAINING]: <7> return <8> <9> while not buf.eof(): <10> start_off = buf.tell() <11> header = pull_quic_header(buf, host_cid_length=len(self.host_cid)) <12> <13> if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION: <14> # version negotiation <15> versions = [] <16> while not buf.eof(): <17> versions.append(pull_uint32(buf)) <18> common = set(self.supported_versions).intersection(versions) <19> if not common: <20> self.__logger.error("Could not find a common protocol version") <21> return <22> self.version = QuicProtocolVersion(max(common)) <23> self.__logger.info("Retrying with %s", self.version) <24> self.connection_made(self.__transport) <25> return <26> elif self.is_client and header.packet_type == PACKET_TYPE_RETRY: <27> # stateless retry <28> if ( <29> header.destination_cid == self.host_cid <30> and header.original_destination_cid == self.peer_cid <31> ): <32> self.__logger.info("Performing stateless retry") <33> self.peer_cid = header.source_cid <34> self.peer_token = header.token <35> self.connection_made(self.__transport) <36> return <37> <38> # server initialization <39> if not self.is_client and not self.__initialized: <40> assert ( <41> header.packet_type == PACKET_TYPE_INITIAL <42> ), "first packet must be INITIAL" <43> self._initialize(header.destination_</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 1 # decrypt packet encrypted_off = buf.tell() - start_off end_off = buf.tell() + header.rest_length pull_bytes(buf, header.rest_length) epoch = get_epoch(header.packet_type) space = self.spaces[epoch] if not space.crypto.recv.is_valid(): return try: plain_header, plain_payload, packet_number = space.crypto.decrypt_packet( data[start_off:end_off], encrypted_off ) except CryptoError as exc: self.__logger.warning(exc) return if not self.peer_cid_set: self.peer_cid = header.source_cid self.peer_cid_set = True # update state if self.__state == QuicConnectionState.FIRSTFLIGHT: self._set_state(QuicConnectionState.CONNECTED) # update spin bit if ( not is_long_header(plain_header[0]) and packet_number > self._spin_highest_pn ): if self.is_client: self._spin_bit = not get_spin_bit(plain_header[0]) else: self._spin_bit = get_spin_bit(plain_header[0]) self._spin_highest_pn = packet_number # handle payload try: is_ack_only = self._payload_received(epoch, plain_payload) except QuicConnectionError as exc: self.__logger.warning(exc) self.close( error_code=exc.error_code, frame_type=exc.frame_type, reason_phrase=exc.reason_phrase, ) return # record packet as received space.ack_queue.add(packet_number) if not is_</s> ===========below chunk 1=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 2 <s> return # record packet as received space.ack_queue.add(packet_number) if not is_ack_only: self.send_ack[epoch] = True self._send_pending() ===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) pull_bytes(buf: Buffer, length: int) -> bytes pull_uint32(buf: Buffer) -> int at: aioquic.buffer.Buffer eof() -> bool tell() -> int at: aioquic.connection get_epoch(packet_type: int) -> tls.Epoch QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) QuicConnectionState() at: aioquic.connection.PacketSpace.__init__ self.ack_queue = RangeSet() self.crypto = CryptoPair() at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] close(error_code: int=QuicErrorCode.NO_ERROR, frame_type: Optional[int]=None, reason_phrase: str="") -> None connection_made(transport: asyncio.DatagramTransport) -> None _initialize(peer_cid: bytes) -> None _payload_received(epoch: tls.Epoch, plain: bytes) -> bool _set_state(state: QuicConnectionState) -> None at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.version = max(self.supported_versions) self.__initialized = False self.__logger = logger self._spin_bit = False self._spin_highest_pn = 0 self.__state = QuicConnectionState.FIRSTFLIGHT self.__transport: Optional[asyncio.DatagramTransport] = None ===========unchanged ref 1=========== at: aioquic.connection.QuicConnection._initialize self.spaces = { tls.Epoch.INITIAL: PacketSpace(), tls.Epoch.HANDSHAKE: PacketSpace(), tls.Epoch.ONE_RTT: PacketSpace(), } self.__initialized = True at: aioquic.connection.QuicConnection._set_state self.__state = state at: aioquic.connection.QuicConnection.connection_made self.__transport = transport at: aioquic.connection.QuicConnectionError.__init__ self.error_code = error_code self.frame_type = frame_type self.reason_phrase = reason_phrase at: aioquic.crypto CryptoError(*args: object) at: aioquic.crypto.CryptoContext is_valid() -> bool at: aioquic.crypto.CryptoPair decrypt_packet(packet: bytes, encrypted_offset: int) -> Tuple[bytes, bytes, int] at: aioquic.crypto.CryptoPair.__init__ self.recv = CryptoContext() at: aioquic.packet PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int) QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) get_spin_bit(first_byte: int) -> bool is_long_header(first_byte: int) -> bool pull_quic_header(buf: Buffer, host_cid_length: Optional[int]=None) -> QuicHeader at: aioquic.packet.QuicHeader version: Optional[int] packet_type: int destination_cid: bytes source_cid: bytes original_destination_cid: bytes = b"" token: bytes = b"" ===========unchanged ref 2=========== rest_length: int = 0 at: aioquic.rangeset.RangeSet add(start: int, stop: Optional[int]=None) -> None at: logging.Logger info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None warning(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None error(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
aioquic.connection/QuicConnection.__init__
Modified
aiortc~aioquic
7dfa8f5a66d4d818662e28183ac2a92a8c5ba5ad
[connection] drop packets with unsupported version
<16>:<del> # protocol versions <17>:<del> self.version = max(self.supported_versions) <18>:<del> <22>:<del> self.__initialized = False
# module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: <0> if not is_client: <1> assert certificate is not None, "SSL certificate is required" <2> assert private_key is not None, "SSL private key is required" <3> <4> self.alpn_protocols = alpn_protocols <5> self.certificate = certificate <6> self.is_client = is_client <7> self.host_cid = os.urandom(8) <8> self.peer_cid = os.urandom(8) <9> self.peer_cid_set = False <10> self.peer_token = b"" <11> self.private_key = private_key <12> self.secrets_log_file = secrets_log_file <13> self.server_name = server_name <14> self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} <15> <16> # protocol versions <17> self.version = max(self.supported_versions) <18> <19> self.__close: Optional[Dict] = None <20> self.__connected = asyncio.Event() <21> self.__epoch = tls.Epoch.INITIAL <22> self.__initialized = False <23> self._local_idle_timeout = 60000 # milliseconds <24> self._local_max_data = 1048576 <25> self._local_max_stream_data_bidi_local = 1048576 <26> self._local_max_stream_data_bidi_remote = 1048576 <27> self._local_max_stream_data_uni = 1048576 <28> self._local_max_streams_bidi = 128 <29> self._local_max_streams_uni = 128 <30> self.__logger = logger <31> self.__path_challenge: Optional[bytes] = None</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 self._remote_idle_timeout = 0 # milliseconds self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self._spin_bit = False self._spin_highest_pn = 0 self.__send_pending_task: Optional[asyncio.Handle] = None self.__state = QuicConnectionState.FIRSTFLIGHT self.__transport: Optional[asyncio.DatagramTransport] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max</s> ===========below chunk 1=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s>_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ] ===========unchanged ref 0=========== at: aioquic.connection logger = logging.getLogger("quic") QuicConnectionState() at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] _handle_ack_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_connection_close_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_crypto_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_stream_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_bidi_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_uni_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_token_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_padding_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_challenge_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_response_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_reset_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None ===========unchanged ref 1=========== _handle_retire_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stop_sending_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_streams_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.connection.QuicConnection._handle_crypto_frame self.__epoch = tls.Epoch.ONE_RTT self.__epoch = tls.Epoch.HANDSHAKE at: aioquic.connection.QuicConnection._handle_max_data_frame self._remote_max_data = max_data at: aioquic.connection.QuicConnection._handle_max_streams_bidi_frame self._remote_max_streams_bidi = max_streams at: aioquic.connection.QuicConnection._handle_max_streams_uni_frame self._remote_max_streams_uni = max_streams at: aioquic.connection.QuicConnection._parse_transport_parameters self._remote_idle_timeout = quic_transport_parameters.idle_timeout at: aioquic.connection.QuicConnection._send_path_challenge self.__path_challenge = os.urandom(8) at: aioquic.connection.QuicConnection._send_pending self.__send_pending_task = None at: aioquic.connection.QuicConnection._send_soon self.__send_pending_task = loop.call_soon(self._send_pending) at: aioquic.connection.QuicConnection._set_state self.__state = state at: aioquic.connection.QuicConnection._write_application self._pending_flow_control = []
aioquic.connection/QuicConnection.connection_made
Modified
aiortc~aioquic
7dfa8f5a66d4d818662e28183ac2a92a8c5ba5ad
[connection] drop packets with unsupported version
<8>:<add> self.__version = max(self.supported_versions) <add> self._connect() <del> self._initialize(self.peer_cid) <10>:<del> self.tls.handle_message(b"", self.send_buffer) <11>:<del> self._push_crypto_data() <12>:<del> self._send_pending() <13>:<del>
# module: aioquic.connection class QuicConnection: def connection_made(self, transport: asyncio.DatagramTransport) -> None: <0> """ <1> Inform the connection of the transport used to send data. This object <2> must have a ``sendto`` method which accepts a datagram to send. <3> <4> Calling :meth:`connection_made` on a client starts the TLS handshake. <5> """ <6> self.__transport = transport <7> if self.is_client: <8> self._initialize(self.peer_cid) <9> <10> self.tls.handle_message(b"", self.send_buffer) <11> self._push_crypto_data() <12> self._send_pending() <13>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] _connect() at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.__transport: Optional[asyncio.DatagramTransport] = None self.__version: Optional[int] = None at: aioquic.connection.QuicConnection.datagram_received self.__version = QuicProtocolVersion(max(common)) self.__version = QuicProtocolVersion(header.version) ===========changed ref 0=========== # module: aioquic.connection logger = logging.getLogger("quic") PACKET_MAX_SIZE = 1280 SECRETS_LABELS = [ [ None, "QUIC_CLIENT_EARLY_TRAFFIC_SECRET", "QUIC_CLIENT_HANDSHAKE_TRAFFIC_SECRET", "QUIC_CLIENT_TRAFFIC_SECRET_0", ], [ None, None, "QUIC_SERVER_HANDSHAKE_TRAFFIC_SECRET", "QUIC_SERVER_TRAFFIC_SECRET_0", ], ] - SEND_PN_SIZE = 2 STREAM_FLAGS = 0x07 ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: if not is_client: assert certificate is not None, "SSL certificate is required" assert private_key is not None, "SSL private key is required" self.alpn_protocols = alpn_protocols self.certificate = certificate self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.private_key = private_key self.secrets_log_file = secrets_log_file self.server_name = server_name self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} - # protocol versions - self.version = max(self.supported_versions) - self.__close: Optional[Dict] = None self.__connected = asyncio.Event() self.__epoch = tls.Epoch.INITIAL - self.__initialized = False self._local_idle_timeout = 60000 # milliseconds self._local_max_data = 1048576 self._local_max_stream_data_bidi_local = 1048576 self._local_max_stream_data_bidi_remote = 1048576 self._local_max_stream_data_uni = 1048576 self._local_max_streams_bidi = 128 self._local_max_streams_uni = 128 self.__logger = logger self.__path_challenge: Optional[bytes] = None self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0 </s> ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 <s> = None self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0 # milliseconds self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self._spin_bit = False self._spin_highest_pn = 0 self.__send_pending_task: Optional[asyncio.Handle] = None self.__state = QuicConnectionState.FIRSTFLIGHT self.__transport: Optional[asyncio.DatagramTransport] = None + self.__version: Optional[int] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, </s> ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s>handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ] ===========changed ref 4=========== # module: aioquic.packet PACKET_LONG_HEADER = 0x80 PACKET_FIXED_BIT = 0x40 PACKET_SPIN_BIT = 0x20 PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10 PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 PACKET_TYPE_MASK = 0xF0 + PACKET_NUMBER_SEND_SIZE = 2 + UINT_VAR_FORMATS = [ (pull_uint8, push_uint8, 0x3F), (pull_uint16, push_uint16, 0x3FFF), (pull_uint32, push_uint32, 0x3FFFFFFF), (pull_uint64, push_uint64, 0x3FFFFFFFFFFFFFFF), ]
aioquic.connection/QuicConnection.datagram_received
Modified
aiortc~aioquic
7dfa8f5a66d4d818662e28183ac2a92a8c5ba5ad
[connection] drop packets with unsupported version
<17>:<add> # check protocol version <26>:<add> self.__version = QuicProtocolVersion(max(common)) <del> self.version = QuicProtocolVersion(max(common)) <27>:<add> self.__logger.info("Retrying with %s", self.__version) <del> self.__logger.info("Retrying with %s", self.version) <28>:<add> self._connect() <del> self.connection_made(self.__transport) <30>:<add> elif ( <add> header.version is not None <add> and header.version not in self.supported_versions <add> ): <add> # unsupported version <add> return <add> <add> if self.is_client and header.packet_type == PACKET_TYPE_RETRY: <del> elif self.is_client and header.packet_type == PACKET_TYPE_RETRY: <39>:<add> self._connect() <del> self.connection_made(self.__transport) <43>:<add> if not self.is_client and self.__state == QuicConnectionState.FIRSTFLIGHT: <del> if not self.is_client and not self.__initialized:
# module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: <0> """ <1> Handle an incoming datagram. <2> """ <3> buf = Buffer(data=data) <4> <5> # stop handling packets when closing <6> if self.__state in [QuicConnectionState.CLOSING, QuicConnectionState.DRAINING]: <7> return <8> <9> while not buf.eof(): <10> start_off = buf.tell() <11> header = pull_quic_header(buf, host_cid_length=len(self.host_cid)) <12> <13> # check destination CID matches <14> if self.is_client and header.destination_cid != self.host_cid: <15> return <16> <17> if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION: <18> # version negotiation <19> versions = [] <20> while not buf.eof(): <21> versions.append(pull_uint32(buf)) <22> common = set(self.supported_versions).intersection(versions) <23> if not common: <24> self.__logger.error("Could not find a common protocol version") <25> return <26> self.version = QuicProtocolVersion(max(common)) <27> self.__logger.info("Retrying with %s", self.version) <28> self.connection_made(self.__transport) <29> return <30> elif self.is_client and header.packet_type == PACKET_TYPE_RETRY: <31> # stateless retry <32> if ( <33> header.destination_cid == self.host_cid <34> and header.original_destination_cid == self.peer_cid <35> ): <36> self.__logger.info("Performing stateless retry") <37> self.peer_cid = header.source_cid <38> self.peer_token = header.token <39> self.connection_made(self.__transport) <40> return <41> <42> # server initialization <43> if not self.is_client and not self.__initialized: <44> assert ( </s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 1 ), "first packet must be INITIAL" self._initialize(header.destination_cid) # decrypt packet encrypted_off = buf.tell() - start_off end_off = buf.tell() + header.rest_length pull_bytes(buf, header.rest_length) epoch = get_epoch(header.packet_type) space = self.spaces[epoch] if not space.crypto.recv.is_valid(): return try: plain_header, plain_payload, packet_number = space.crypto.decrypt_packet( data[start_off:end_off], encrypted_off ) except CryptoError as exc: self.__logger.warning(exc) return if not self.peer_cid_set: self.peer_cid = header.source_cid self.peer_cid_set = True # update state if self.__state == QuicConnectionState.FIRSTFLIGHT: self._set_state(QuicConnectionState.CONNECTED) # update spin bit if ( not is_long_header(plain_header[0]) and packet_number > self._spin_highest_pn ): if self.is_client: self._spin_bit = not get_spin_bit(plain_header[0]) else: self._spin_bit = get_spin_bit(plain_header[0]) self._spin_highest_pn = packet_number # handle payload try: is_ack_only = self._payload_received(epoch, plain_payload) except QuicConnectionError as exc: self.__logger.warning(exc) self.close( error_code=exc.error_code, frame_type=exc.frame_type, reason_phrase=exc.reason_phrase, ) return # record</s> ===========below chunk 1=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 2 <s>=exc.frame_type, reason_phrase=exc.reason_phrase, ) return # record packet as received space.ack_queue.add(packet_number) if not is_ack_only: self.send_ack[epoch] = True self._send_pending() ===========unchanged ref 0=========== at: aioquic.buffer pull_bytes(buf: Buffer, length: int) -> bytes pull_uint32(buf: Buffer) -> int at: aioquic.buffer.Buffer eof() -> bool tell() -> int at: aioquic.connection get_epoch(packet_type: int) -> tls.Epoch QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) QuicConnectionState() at: aioquic.connection.PacketSpace.__init__ self.ack_queue = RangeSet() self.crypto = CryptoPair() at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] close(error_code: int=QuicErrorCode.NO_ERROR, frame_type: Optional[int]=None, reason_phrase: str="") -> None close(self, error_code: int=QuicErrorCode.NO_ERROR, frame_type: Optional[int]=None, reason_phrase: str="") -> None _connect() _initialize(self, peer_cid: bytes) -> None _initialize(peer_cid: bytes) -> None _payload_received(epoch: tls.Epoch, plain: bytes) -> bool _set_state(state: QuicConnectionState) -> None at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.__logger = logger self._spin_bit = False self._spin_highest_pn = 0 self.__state = QuicConnectionState.FIRSTFLIGHT self.__version: Optional[int] = None ===========unchanged ref 1=========== at: aioquic.connection.QuicConnection._initialize self.spaces = { tls.Epoch.INITIAL: PacketSpace(), tls.Epoch.HANDSHAKE: PacketSpace(), tls.Epoch.ONE_RTT: PacketSpace(), } at: aioquic.connection.QuicConnection._set_state self.__state = state at: aioquic.connection.QuicConnection.connection_made self.__version = max(self.supported_versions) at: aioquic.connection.QuicConnection.datagram_received buf = Buffer(data=data) at: aioquic.connection.QuicConnectionError.__init__ self.error_code = error_code self.frame_type = frame_type self.reason_phrase = reason_phrase at: aioquic.crypto CryptoError(*args: object) at: aioquic.crypto.CryptoContext is_valid() -> bool at: aioquic.crypto.CryptoPair decrypt_packet(packet: bytes, encrypted_offset: int) -> Tuple[bytes, bytes, int] at: aioquic.crypto.CryptoPair.__init__ self.recv = CryptoContext() at: aioquic.packet PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int) QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) get_spin_bit(first_byte: int) -> bool is_long_header(first_byte: int) -> bool pull_quic_header(buf: Buffer, host_cid_length: Optional[int]=None) -> QuicHeader at: aioquic.packet.QuicHeader version: Optional[int] packet_type: int destination_cid: bytes ===========unchanged ref 2=========== source_cid: bytes original_destination_cid: bytes = b"" token: bytes = b"" rest_length: int = 0 at: aioquic.rangeset.RangeSet add(start: int, stop: Optional[int]=None) -> None at: logging.Logger info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None warning(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None error(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
aioquic.connection/QuicConnection._initialize
Modified
aiortc~aioquic
7dfa8f5a66d4d818662e28183ac2a92a8c5ba5ad
[connection] drop packets with unsupported version
<38>:<del> self.__initialized = True
# module: aioquic.connection class QuicConnection: def _initialize(self, peer_cid: bytes) -> None: <0> # TLS <1> self.tls = tls.Context(is_client=self.is_client, logger=self.__logger) <2> self.tls.alpn_protocols = self.alpn_protocols <3> self.tls.certificate = self.certificate <4> self.tls.certificate_private_key = self.private_key <5> self.tls.handshake_extensions = [ <6> ( <7> tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, <8> self._serialize_transport_parameters(), <9> ) <10> ] <11> self.tls.server_name = self.server_name <12> self.tls.update_traffic_key_cb = self._update_traffic_key <13> <14> # packet spaces <15> self.send_ack = { <16> tls.Epoch.INITIAL: False, <17> tls.Epoch.HANDSHAKE: False, <18> tls.Epoch.ONE_RTT: False, <19> } <20> self.send_buffer = { <21> tls.Epoch.INITIAL: Buffer(capacity=4096), <22> tls.Epoch.HANDSHAKE: Buffer(capacity=4096), <23> tls.Epoch.ONE_RTT: Buffer(capacity=4096), <24> } <25> self.spaces = { <26> tls.Epoch.INITIAL: PacketSpace(), <27> tls.Epoch.HANDSHAKE: PacketSpace(), <28> tls.Epoch.ONE_RTT: PacketSpace(), <29> } <30> self.streams[tls.Epoch.INITIAL] = QuicStream() <31> self.streams[tls.Epoch.HANDSHAKE] = QuicStream() <32> self.streams[tls.Epoch.ONE_RTT] = QuicStream() <33> <34> self.spaces[tls.Epoch.INITIAL].crypto.setup_initial( <35> cid=peer_cid, is_client=self.is_client <36> ) <37> <38> self.__initialized = True <39> self.packet_number = 0 <40>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.connection.QuicConnection _serialize_transport_parameters() -> bytes _update_traffic_key(direction: tls.Direction, epoch: tls.Epoch, secret: bytes) -> None at: aioquic.connection.QuicConnection.__init__ self.alpn_protocols = alpn_protocols self.certificate = certificate self.is_client = is_client self.private_key = private_key self.server_name = server_name self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} self.__logger = logger self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None at: aioquic.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 at: aioquic.packet QuicErrorCode(x: Union[str, bytes, bytearray], base: int) QuicErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) at: aioquic.stream QuicStream(stream_id: Optional[int]=None, connection: Optional[Any]=None, max_stream_data_local: int=0, max_stream_data_remote: int=0) at: aioquic.stream.QuicStream.__init__ self.reader = asyncio.StreamReader() self.reader = None self.writer = None self.writer = asyncio.StreamWriter(self, None, self.reader, None) ===========unchanged ref 1=========== at: aioquic.tls Epoch() ExtensionType(x: Union[str, bytes, bytearray], base: int) ExtensionType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) Context(is_client: bool, logger: logging.Logger=None) at: aioquic.tls.Context.__init__ self.alpn_protocols: Optional[List[str]] = None self.certificate: Optional[x509.Certificate] = None self.certificate_private_key: Optional[ Union[dsa.DSAPublicKey, ec.EllipticCurvePublicKey, rsa.RSAPublicKey] ] = None self.handshake_extensions: List[Extension] = [] self.server_name: Optional[str] = None self.update_traffic_key_cb: Callable[ [Direction, Epoch, bytes], None ] = lambda d, e, s: None ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: + def _connect(self): + """ + Start the client handshake. + """ + assert self.is_client + + self._initialize(self.peer_cid) + + self.tls.handle_message(b"", self.send_buffer) + self._push_crypto_data() + self._send_pending() + ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def connection_made(self, transport: asyncio.DatagramTransport) -> None: """ Inform the connection of the transport used to send data. This object must have a ``sendto`` method which accepts a datagram to send. Calling :meth:`connection_made` on a client starts the TLS handshake. """ self.__transport = transport if self.is_client: + self.__version = max(self.supported_versions) + self._connect() - self._initialize(self.peer_cid) - self.tls.handle_message(b"", self.send_buffer) - self._push_crypto_data() - self._send_pending() - ===========changed ref 2=========== # module: aioquic.connection logger = logging.getLogger("quic") PACKET_MAX_SIZE = 1280 SECRETS_LABELS = [ [ None, "QUIC_CLIENT_EARLY_TRAFFIC_SECRET", "QUIC_CLIENT_HANDSHAKE_TRAFFIC_SECRET", "QUIC_CLIENT_TRAFFIC_SECRET_0", ], [ None, None, "QUIC_SERVER_HANDSHAKE_TRAFFIC_SECRET", "QUIC_SERVER_TRAFFIC_SECRET_0", ], ] - SEND_PN_SIZE = 2 STREAM_FLAGS = 0x07 ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: """ Handle an incoming datagram. """ buf = Buffer(data=data) # stop handling packets when closing if self.__state in [QuicConnectionState.CLOSING, QuicConnectionState.DRAINING]: return while not buf.eof(): start_off = buf.tell() header = pull_quic_header(buf, host_cid_length=len(self.host_cid)) # check destination CID matches if self.is_client and header.destination_cid != self.host_cid: return + # check protocol version if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION: # version negotiation versions = [] while not buf.eof(): versions.append(pull_uint32(buf)) common = set(self.supported_versions).intersection(versions) if not common: self.__logger.error("Could not find a common protocol version") return + self.__version = QuicProtocolVersion(max(common)) - self.version = QuicProtocolVersion(max(common)) + self.__logger.info("Retrying with %s", self.__version) - self.__logger.info("Retrying with %s", self.version) + self._connect() - self.connection_made(self.__transport) return + elif ( + header.version is not None + and header.version not in self.supported_versions + ): + # unsupported version + return + + if self.is_client and header.packet_type == PACKET_TYPE_RETRY: - elif self.is_client and header.packet_type == PACKET_TYPE_RETRY: # stateless retry if ( header.destination_cid == self.host_cid and header.original_destination_cid == self.peer_cid ): self.__logger</s>
aioquic.connection/QuicConnection._write_application
Modified
aiortc~aioquic
7dfa8f5a66d4d818662e28183ac2a92a8c5ba5ad
[connection] drop packets with unsupported version
<14>:<add> | (PACKET_NUMBER_SEND_SIZE - 1), <del> | (SEND_PN_SIZE - 1),
# module: aioquic.connection class QuicConnection: def _write_application(self) -> Iterator[bytes]: <0> epoch = tls.Epoch.ONE_RTT <1> space = self.spaces[epoch] <2> if not space.crypto.send.is_valid(): <3> return <4> <5> buf = Buffer(capacity=PACKET_MAX_SIZE) <6> <7> while True: <8> # write header <9> push_uint8( <10> buf, <11> PACKET_FIXED_BIT <12> | (self._spin_bit << 5) <13> | (space.crypto.key_phase << 2) <14> | (SEND_PN_SIZE - 1), <15> ) <16> push_bytes(buf, self.peer_cid) <17> push_uint16(buf, self.packet_number) <18> header_size = buf.tell() <19> <20> # ACK <21> if self.send_ack[epoch] and space.ack_queue: <22> push_uint_var(buf, QuicFrameType.ACK) <23> packet.push_ack_frame(buf, space.ack_queue, 0) <24> self.send_ack[epoch] = False <25> <26> # FLOW CONTROL <27> for control_frame in self._pending_flow_control: <28> push_bytes(buf, control_frame) <29> self._pending_flow_control = [] <30> <31> # CLOSE <32> if self.__close and self.__epoch == epoch: <33> push_close(buf, **self.__close) <34> self.__close = None <35> <36> # STREAM <37> for stream_id, stream in self.streams.items(): <38> if isinstance(stream_id, int) and stream.has_data_to_send(): <39> frame = stream.get_frame( <40> PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 6 <41> ) <42> flags = QuicStreamFlag.LEN <43> if frame.offset: <44> flags |= QuicStreamFlag.OFF <45> if frame.fin</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def _write_application(self) -> Iterator[bytes]: # offset: 1 flags |= QuicStreamFlag.FIN push_uint_var(buf, QuicFrameType.STREAM_BASE | flags) with push_stream_frame(buf, 0, frame.offset): push_bytes(buf, frame.data) packet_size = buf.tell() if packet_size > header_size: # encrypt data = buf.data yield space.crypto.encrypt_packet( data[0:header_size], data[header_size:packet_size] ) self.packet_number += 1 buf.seek(0) else: break ===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) push_bytes(buf: Buffer, v: bytes) -> None push_uint8(buf: Buffer, v: int) -> None push_uint16(buf: Buffer, v: int) -> None at: aioquic.buffer.Buffer tell() -> int at: aioquic.connection PACKET_MAX_SIZE = 1280 SECRETS_LABELS = [ [ None, "QUIC_CLIENT_EARLY_TRAFFIC_SECRET", "QUIC_CLIENT_HANDSHAKE_TRAFFIC_SECRET", "QUIC_CLIENT_TRAFFIC_SECRET_0", ], [ None, None, "QUIC_SERVER_HANDSHAKE_TRAFFIC_SECRET", "QUIC_SERVER_TRAFFIC_SECRET_0", ], ] push_close(buf: Buffer, error_code: int, frame_type: Optional[int], reason_phrase: str) -> None at: aioquic.connection.PacketSpace.__init__ self.ack_queue = RangeSet() self.crypto = CryptoPair() at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.peer_cid = os.urandom(8) self.secrets_log_file = secrets_log_file self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} self.__close: Optional[Dict] = None self.__epoch = tls.Epoch.INITIAL self._pending_flow_control: List[bytes] = [] self._spin_bit = False at: aioquic.connection.QuicConnection._handle_crypto_frame self.__epoch = tls.Epoch.ONE_RTT self.__epoch = tls.Epoch.HANDSHAKE ===========unchanged ref 1=========== at: aioquic.connection.QuicConnection._initialize self.tls = tls.Context(is_client=self.is_client, logger=self.__logger) self.send_ack = { tls.Epoch.INITIAL: False, tls.Epoch.HANDSHAKE: False, tls.Epoch.ONE_RTT: False, } self.spaces = { tls.Epoch.INITIAL: PacketSpace(), tls.Epoch.HANDSHAKE: PacketSpace(), tls.Epoch.ONE_RTT: PacketSpace(), } self.packet_number = 0 at: aioquic.connection.QuicConnection._write_application self.packet_number += 1 at: aioquic.connection.QuicConnection._write_handshake self.__close = None self.packet_number += 1 at: aioquic.connection.QuicConnection.close self.__close = { "error_code": error_code, "frame_type": frame_type, "reason_phrase": reason_phrase, } at: aioquic.connection.QuicConnection.datagram_received self.peer_cid = header.source_cid self._spin_bit = not get_spin_bit(plain_header[0]) self._spin_bit = get_spin_bit(plain_header[0]) at: aioquic.crypto.CryptoContext is_valid() -> bool setup(cipher_suite: CipherSuite, secret: bytes) -> None at: aioquic.crypto.CryptoPair.__init__ self.aead_tag_size = 16 self.recv = CryptoContext() self.send = CryptoContext() at: aioquic.packet PACKET_FIXED_BIT = 0x40 PACKET_NUMBER_SEND_SIZE = 2 push_uint_var(buf: Buffer, value: int) -> None ===========unchanged ref 2=========== QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) push_ack_frame(buf: Buffer, rangeset: RangeSet, delay: int) -> None QuicStreamFlag(x: Union[str, bytes, bytearray], base: int) QuicStreamFlag(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) push_stream_frame(buf: Buffer, stream_id: int, offset: int) -> Generator at: aioquic.packet.QuicStreamFrame data: bytes = b"" fin: bool = False offset: int = 0 at: aioquic.stream.QuicStream get_frame(size: int) -> QuicStreamFrame has_data_to_send() -> bool at: aioquic.tls Direction() Epoch() at: aioquic.tls.Context.__init__ self.key_schedule: Optional[KeySchedule] = None self.client_random = None self.client_random = os.urandom(32) at: aioquic.tls.Context._client_handle_hello self.key_schedule = self._key_schedule_proxy.select(peer_hello.cipher_suite) at: aioquic.tls.Context._server_handle_hello self.client_random = peer_hello.random self.key_schedule = KeySchedule(cipher_suite) at: aioquic.tls.KeySchedule.__init__ self.cipher_suite = cipher_suite at: enum.Enum name: str value: Any _name_: str _value_: Any _member_names_: List[str] # undocumented _member_map_: Dict[str, Enum] # undocumented _value2member_map_: Dict[int, Enum] # undocumented ===========unchanged ref 3=========== _ignore_: Union[str, List[str]] _order_: str __order__: str at: typing Iterator = _alias(collections.abc.Iterator, 1) at: typing.IO __slots__ = () flush() -> None write(s: AnyStr) -> int ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: + def _connect(self): + """ + Start the client handshake. + """ + assert self.is_client + + self._initialize(self.peer_cid) + + self.tls.handle_message(b"", self.send_buffer) + self._push_crypto_data() + self._send_pending() +
aioquic.connection/QuicConnection._write_handshake
Modified
aiortc~aioquic
7dfa8f5a66d4d818662e28183ac2a92a8c5ba5ad
[connection] drop packets with unsupported version
<16>:<add> version=self.__version, <del> version=self.version, <17>:<add> packet_type=packet_type | (PACKET_NUMBER_SEND_SIZE - 1), <del> packet_type=packet_type | (SEND_PN_SIZE - 1),
# module: aioquic.connection class QuicConnection: def _write_handshake(self, epoch: tls.Epoch) -> Iterator[bytes]: <0> space = self.spaces[epoch] <1> if not space.crypto.send.is_valid(): <2> return <3> <4> buf = Buffer(capacity=PACKET_MAX_SIZE) <5> <6> while True: <7> if epoch == tls.Epoch.INITIAL: <8> packet_type = PACKET_TYPE_INITIAL <9> else: <10> packet_type = PACKET_TYPE_HANDSHAKE <11> <12> # write header <13> push_quic_header( <14> buf, <15> QuicHeader( <16> version=self.version, <17> packet_type=packet_type | (SEND_PN_SIZE - 1), <18> destination_cid=self.peer_cid, <19> source_cid=self.host_cid, <20> token=self.peer_token, <21> ), <22> ) <23> header_size = buf.tell() <24> <25> # ACK <26> if self.send_ack[epoch] and space.ack_queue: <27> push_uint_var(buf, QuicFrameType.ACK) <28> packet.push_ack_frame(buf, space.ack_queue, 0) <29> self.send_ack[epoch] = False <30> <31> # CLOSE <32> if self.__close and self.__epoch == epoch: <33> push_close(buf, **self.__close) <34> self.__close = None <35> <36> stream = self.streams[epoch] <37> if stream.has_data_to_send(): <38> # CRYPTO <39> frame = stream.get_frame( <40> PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 4 <41> ) <42> push_uint_var(buf, QuicFrameType.CRYPTO) <43> with packet.push_crypto_frame(buf, frame.offset): <44> push_bytes(buf, frame.data) <45> <46> # PADDING <47> </s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def _write_handshake(self, epoch: tls.Epoch) -> Iterator[bytes]: # offset: 1 push_bytes( buf, bytes( PACKET_MAX_SIZE - space.crypto.aead_tag_size - buf.tell() ), ) packet_size = buf.tell() if packet_size > header_size: # finalize length buf.seek(header_size - SEND_PN_SIZE - 2) length = packet_size - header_size + 2 + space.crypto.aead_tag_size push_uint16(buf, length | 0x4000) push_uint16(buf, self.packet_number) buf.seek(packet_size) # encrypt data = buf.data yield space.crypto.encrypt_packet( data[0:header_size], data[header_size:packet_size] ) self.packet_number += 1 buf.seek(0) else: break ===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) push_bytes(buf: Buffer, v: bytes) -> None at: aioquic.buffer.Buffer seek(pos: int) -> None tell() -> int at: aioquic.connection PACKET_MAX_SIZE = 1280 push_close(buf: Buffer, error_code: int, frame_type: Optional[int], reason_phrase: str) -> None at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_token = b"" self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} self.__close: Optional[Dict] = None self.__epoch = tls.Epoch.INITIAL self.__version: Optional[int] = None at: aioquic.connection.QuicConnection._handle_crypto_frame self.__epoch = tls.Epoch.ONE_RTT self.__epoch = tls.Epoch.HANDSHAKE at: aioquic.connection.QuicConnection._initialize self.send_ack = { tls.Epoch.INITIAL: False, tls.Epoch.HANDSHAKE: False, tls.Epoch.ONE_RTT: False, } self.spaces = { tls.Epoch.INITIAL: PacketSpace(), tls.Epoch.HANDSHAKE: PacketSpace(), tls.Epoch.ONE_RTT: PacketSpace(), } self.packet_number = 0 at: aioquic.connection.QuicConnection._write_application space = self.spaces[epoch] buf = Buffer(capacity=PACKET_MAX_SIZE) header_size = buf.tell() self.__close = None ===========unchanged ref 1=========== at: aioquic.connection.QuicConnection._write_handshake self.packet_number += 1 at: aioquic.connection.QuicConnection.close self.__close = { "error_code": error_code, "frame_type": frame_type, "reason_phrase": reason_phrase, } at: aioquic.connection.QuicConnection.connection_made self.__version = max(self.supported_versions) at: aioquic.connection.QuicConnection.datagram_received self.__version = QuicProtocolVersion(max(common)) self.__version = QuicProtocolVersion(header.version) self.peer_cid = header.source_cid self.peer_token = header.token at: aioquic.packet PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20 PACKET_NUMBER_SEND_SIZE = 2 QuicHeader(version: Optional[int], packet_type: int, destination_cid: bytes, source_cid: bytes, original_destination_cid: bytes=b"", token: bytes=b"", rest_length: int=0) push_uint_var(buf: Buffer, value: int) -> None push_quic_header(buf: Buffer, header: QuicHeader) -> None QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) push_ack_frame(buf: Buffer, rangeset: RangeSet, delay: int) -> None push_crypto_frame(buf: Buffer, offset: int=0) -> Generator at: aioquic.packet.QuicStreamFrame data: bytes = b"" offset: int = 0 ===========unchanged ref 2=========== at: aioquic.stream.QuicStream get_frame(size: int) -> QuicStreamFrame has_data_to_send() -> bool at: aioquic.tls Epoch() at: typing Iterator = _alias(collections.abc.Iterator, 1) ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: + def _connect(self): + """ + Start the client handshake. + """ + assert self.is_client + + self._initialize(self.peer_cid) + + self.tls.handle_message(b"", self.send_buffer) + self._push_crypto_data() + self._send_pending() + ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def _write_application(self) -> Iterator[bytes]: epoch = tls.Epoch.ONE_RTT space = self.spaces[epoch] if not space.crypto.send.is_valid(): return buf = Buffer(capacity=PACKET_MAX_SIZE) while True: # write header push_uint8( buf, PACKET_FIXED_BIT | (self._spin_bit << 5) | (space.crypto.key_phase << 2) + | (PACKET_NUMBER_SEND_SIZE - 1), - | (SEND_PN_SIZE - 1), ) push_bytes(buf, self.peer_cid) push_uint16(buf, self.packet_number) header_size = buf.tell() # ACK if self.send_ack[epoch] and space.ack_queue: push_uint_var(buf, QuicFrameType.ACK) packet.push_ack_frame(buf, space.ack_queue, 0) self.send_ack[epoch] = False # FLOW CONTROL for control_frame in self._pending_flow_control: push_bytes(buf, control_frame) self._pending_flow_control = [] # CLOSE if self.__close and self.__epoch == epoch: push_close(buf, **self.__close) self.__close = None # STREAM for stream_id, stream in self.streams.items(): if isinstance(stream_id, int) and stream.has_data_to_send(): frame = stream.get_frame( PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 6 ) flags = QuicStreamFlag.LEN if frame.offset: flags |= QuicStreamFlag.OFF if frame.fin: flags |= QuicStreamFlag.FIN push_uint_var(buf, QuicFrameType.STREAM_BASE</s>
tests.test_connection/QuicConnectionTest._test_connect_with_version
Modified
aiortc~aioquic
7dfa8f5a66d4d818662e28183ac2a92a8c5ba5ad
[connection] drop packets with unsupported version
<2>:<del> client.version = max(client_versions) <10>:<del> server.version = max(server_versions)
# module: tests.test_connection class QuicConnectionTest(TestCase): def _test_connect_with_version(self, client_versions, server_versions): <0> client = QuicConnection(is_client=True) <1> client.supported_versions = client_versions <2> client.version = max(client_versions) <3> <4> server = QuicConnection( <5> is_client=False, <6> certificate=SERVER_CERTIFICATE, <7> private_key=SERVER_PRIVATE_KEY, <8> ) <9> server.supported_versions = server_versions <10> server.version = max(server_versions) <11> <12> # perform handshake <13> client_transport, server_transport = create_transport(client, server) <14> self.assertEqual(client_transport.sent, 4) <15> self.assertEqual(server_transport.sent, 4) <16> run(client.connect()) <17> <18> # send data over stream <19> client_reader, client_writer = client.create_stream() <20> client_writer.write(b"ping") <21> run(asyncio.sleep(0)) <22> self.assertEqual(client_transport.sent, 5) <23> self.assertEqual(server_transport.sent, 5) <24> <25> # FIXME: needs an API <26> server_reader, server_writer = ( <27> server.streams[0].reader, <28> server.streams[0].writer, <29> ) <30> self.assertEqual(run(server_reader.read(1024)), b"ping") <31> server_writer.write(b"pong") <32> run(asyncio.sleep(0)) <33> self.assertEqual(client_transport.sent, 6) <34> self.assertEqual(server_transport.sent, 6) <35> <36> # client receives pong <37> self.assertEqual(run(client_reader.read(1024)), b"pong") <38> <39> # client writes EOF <40> client_writer.write_eof() <41> run(asyncio.sleep(0)) <42> self.assertEqual(client_</s>
===========below chunk 0=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def _test_connect_with_version(self, client_versions, server_versions): # offset: 1 self.assertEqual(server_transport.sent, 7) # server receives EOF self.assertEqual(run(server_reader.read()), b"") ===========unchanged ref 0=========== at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] connect() -> None create_stream(is_unidirectional: bool=False) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter] at: aioquic.connection.QuicConnection.__init__ self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} at: aioquic.stream.QuicStream.__init__ self.reader = asyncio.StreamReader() self.reader = None self.writer = None self.writer = asyncio.StreamWriter(self, None, self.reader, None) at: asyncio.streams.StreamReader _source_traceback = None read(n: int=...) -> bytes at: asyncio.streams.StreamWriter write(data: bytes) -> None write_eof() -> None at: asyncio.tasks sleep(delay: float, result: _T=..., *, loop: Optional[AbstractEventLoop]=...) -> Future[_T] at: tests.test_connection SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) create_transport(client, server) at: tests.test_connection.FakeTransport.sendto self.sent += 1 at: tests.test_connection.create_transport client_transport = FakeTransport() server_transport = FakeTransport() ===========unchanged ref 1=========== at: tests.utils run(coro) at: unittest.case TestCase(methodName: str=...) at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: + def _connect(self): + """ + Start the client handshake. + """ + assert self.is_client + + self._initialize(self.peer_cid) + + self.tls.handle_message(b"", self.send_buffer) + self._push_crypto_data() + self._send_pending() + ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def connection_made(self, transport: asyncio.DatagramTransport) -> None: """ Inform the connection of the transport used to send data. This object must have a ``sendto`` method which accepts a datagram to send. Calling :meth:`connection_made` on a client starts the TLS handshake. """ self.__transport = transport if self.is_client: + self.__version = max(self.supported_versions) + self._connect() - self._initialize(self.peer_cid) - self.tls.handle_message(b"", self.send_buffer) - self._push_crypto_data() - self._send_pending() - ===========changed ref 2=========== # module: aioquic.connection logger = logging.getLogger("quic") PACKET_MAX_SIZE = 1280 SECRETS_LABELS = [ [ None, "QUIC_CLIENT_EARLY_TRAFFIC_SECRET", "QUIC_CLIENT_HANDSHAKE_TRAFFIC_SECRET", "QUIC_CLIENT_TRAFFIC_SECRET_0", ], [ None, None, "QUIC_SERVER_HANDSHAKE_TRAFFIC_SECRET", "QUIC_SERVER_TRAFFIC_SECRET_0", ], ] - SEND_PN_SIZE = 2 STREAM_FLAGS = 0x07 ===========changed ref 3=========== # module: aioquic.packet PACKET_LONG_HEADER = 0x80 PACKET_FIXED_BIT = 0x40 PACKET_SPIN_BIT = 0x20 PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10 PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 PACKET_TYPE_MASK = 0xF0 + PACKET_NUMBER_SEND_SIZE = 2 + UINT_VAR_FORMATS = [ (pull_uint8, push_uint8, 0x3F), (pull_uint16, push_uint16, 0x3FFF), (pull_uint32, push_uint32, 0x3FFFFFFF), (pull_uint64, push_uint64, 0x3FFFFFFFFFFFFFFF), ] ===========changed ref 4=========== # module: aioquic.connection class QuicConnection: def _initialize(self, peer_cid: bytes) -> None: # TLS self.tls = tls.Context(is_client=self.is_client, logger=self.__logger) self.tls.alpn_protocols = self.alpn_protocols self.tls.certificate = self.certificate self.tls.certificate_private_key = self.private_key self.tls.handshake_extensions = [ ( tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_transport_parameters(), ) ] self.tls.server_name = self.server_name self.tls.update_traffic_key_cb = self._update_traffic_key # packet spaces self.send_ack = { tls.Epoch.INITIAL: False, tls.Epoch.HANDSHAKE: False, tls.Epoch.ONE_RTT: False, } self.send_buffer = { tls.Epoch.INITIAL: Buffer(capacity=4096), tls.Epoch.HANDSHAKE: Buffer(capacity=4096), tls.Epoch.ONE_RTT: Buffer(capacity=4096), } self.spaces = { tls.Epoch.INITIAL: PacketSpace(), tls.Epoch.HANDSHAKE: PacketSpace(), tls.Epoch.ONE_RTT: PacketSpace(), } self.streams[tls.Epoch.INITIAL] = QuicStream() self.streams[tls.Epoch.HANDSHAKE] = QuicStream() self.streams[tls.Epoch.ONE_RTT] = QuicStream() self.spaces[tls.Epoch.INITIAL].crypto.setup_initial( cid=peer_cid, is_client=self.is_client ) - self.__initialized = True self.packet_number = 0
tests.test_connection/QuicConnectionTest.test_create_stream
Modified
aiortc~aioquic
7dfa8f5a66d4d818662e28183ac2a92a8c5ba5ad
[connection] drop packets with unsupported version
<1>:<del> client._initialize(b"") <2>:<del> <8>:<add> <add> # perform handshake <add> client_transport, server_transport = create_transport(client, server) <del> server._initialize(b"")
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_create_stream(self): <0> client = QuicConnection(is_client=True) <1> client._initialize(b"") <2> <3> server = QuicConnection( <4> is_client=False, <5> certificate=SERVER_CERTIFICATE, <6> private_key=SERVER_PRIVATE_KEY, <7> ) <8> server._initialize(b"") <9> <10> # client <11> reader, writer = client.create_stream() <12> self.assertEqual(writer.get_extra_info("stream_id"), 0) <13> self.assertIsNotNone(writer.get_extra_info("connection")) <14> <15> reader, writer = client.create_stream() <16> self.assertEqual(writer.get_extra_info("stream_id"), 4) <17> <18> reader, writer = client.create_stream(is_unidirectional=True) <19> self.assertEqual(writer.get_extra_info("stream_id"), 2) <20> <21> reader, writer = client.create_stream(is_unidirectional=True) <22> self.assertEqual(writer.get_extra_info("stream_id"), 6) <23> <24> # server <25> reader, writer = server.create_stream() <26> self.assertEqual(writer.get_extra_info("stream_id"), 1) <27> <28> reader, writer = server.create_stream() <29> self.assertEqual(writer.get_extra_info("stream_id"), 5) <30> <31> reader, writer = server.create_stream(is_unidirectional=True) <32> self.assertEqual(writer.get_extra_info("stream_id"), 3) <33> <34> reader, writer = server.create_stream(is_unidirectional=True) <35> self.assertEqual(writer.get_extra_info("stream_id"), 7) <36>
===========unchanged ref 0=========== at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection create_stream(is_unidirectional: bool=False) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter] at: asyncio.streams.StreamReader read(n: int=...) -> bytes at: asyncio.streams.StreamWriter get_extra_info(name: str, default: Any=...) -> Any at: tests.test_connection SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) create_transport(client, server) at: tests.test_connection.QuicConnectionTest.test_connection_lost client_reader, client_writer = client.create_stream() at: tests.utils run(coro) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None assertIsNotNone(obj: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def _test_connect_with_version(self, client_versions, server_versions): client = QuicConnection(is_client=True) client.supported_versions = client_versions - client.version = max(client_versions) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) server.supported_versions = server_versions - server.version = max(server_versions) # perform handshake client_transport, server_transport = create_transport(client, server) self.assertEqual(client_transport.sent, 4) self.assertEqual(server_transport.sent, 4) run(client.connect()) # send data over stream client_reader, client_writer = client.create_stream() client_writer.write(b"ping") run(asyncio.sleep(0)) self.assertEqual(client_transport.sent, 5) self.assertEqual(server_transport.sent, 5) # FIXME: needs an API server_reader, server_writer = ( server.streams[0].reader, server.streams[0].writer, ) self.assertEqual(run(server_reader.read(1024)), b"ping") server_writer.write(b"pong") run(asyncio.sleep(0)) self.assertEqual(client_transport.sent, 6) self.assertEqual(server_transport.sent, 6) # client receives pong self.assertEqual(run(client_reader.read(1024)), b"pong") # client writes EOF client_writer.write_eof() run(asyncio.sleep(0)) self.assertEqual(client_transport.sent, 7) self.assertEqual(server_transport.sent, 7) # server receives EOF self.assertEqual(run(server_reader.</s> ===========changed ref 1=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def _test_connect_with_version(self, client_versions, server_versions): # offset: 1 <s>Equal(server_transport.sent, 7) # server receives EOF self.assertEqual(run(server_reader.read()), b"") ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: + def _connect(self): + """ + Start the client handshake. + """ + assert self.is_client + + self._initialize(self.peer_cid) + + self.tls.handle_message(b"", self.send_buffer) + self._push_crypto_data() + self._send_pending() + ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def connection_made(self, transport: asyncio.DatagramTransport) -> None: """ Inform the connection of the transport used to send data. This object must have a ``sendto`` method which accepts a datagram to send. Calling :meth:`connection_made` on a client starts the TLS handshake. """ self.__transport = transport if self.is_client: + self.__version = max(self.supported_versions) + self._connect() - self._initialize(self.peer_cid) - self.tls.handle_message(b"", self.send_buffer) - self._push_crypto_data() - self._send_pending() - ===========changed ref 4=========== # module: aioquic.connection logger = logging.getLogger("quic") PACKET_MAX_SIZE = 1280 SECRETS_LABELS = [ [ None, "QUIC_CLIENT_EARLY_TRAFFIC_SECRET", "QUIC_CLIENT_HANDSHAKE_TRAFFIC_SECRET", "QUIC_CLIENT_TRAFFIC_SECRET_0", ], [ None, None, "QUIC_SERVER_HANDSHAKE_TRAFFIC_SECRET", "QUIC_SERVER_TRAFFIC_SECRET_0", ], ] - SEND_PN_SIZE = 2 STREAM_FLAGS = 0x07 ===========changed ref 5=========== # module: aioquic.packet PACKET_LONG_HEADER = 0x80 PACKET_FIXED_BIT = 0x40 PACKET_SPIN_BIT = 0x20 PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10 PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 PACKET_TYPE_MASK = 0xF0 + PACKET_NUMBER_SEND_SIZE = 2 + UINT_VAR_FORMATS = [ (pull_uint8, push_uint8, 0x3F), (pull_uint16, push_uint16, 0x3FFF), (pull_uint32, push_uint32, 0x3FFFFFFF), (pull_uint64, push_uint64, 0x3FFFFFFFFFFFFFFF), ]
tests.test_connection/QuicConnectionTest.test_version_negotiation_fail
Modified
aiortc~aioquic
7dfa8f5a66d4d818662e28183ac2a92a8c5ba5ad
[connection] drop packets with unsupported version
<1>:<del> client.supported_versions = [QuicProtocolVersion.DRAFT_19]
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_version_negotiation_fail(self): <0> client = QuicConnection(is_client=True) <1> client.supported_versions = [QuicProtocolVersion.DRAFT_19] <2> <3> client_transport = FakeTransport() <4> client.connection_made(client_transport) <5> self.assertEqual(client_transport.sent, 1) <6> <7> # no common version, no retry <8> client.datagram_received( <9> encode_quic_version_negotiation( <10> source_cid=client.peer_cid, <11> destination_cid=client.host_cid, <12> supported_versions=[0xFF000011], # DRAFT_16 <13> ), <14> None, <15> ) <16> self.assertEqual(client_transport.sent, 1) <17>
===========unchanged ref 0=========== at: aioquic.connection.QuicConnection _stream_can_receive(stream_id: int) -> bool _stream_can_send(stream_id: int) -> bool at: tests.test_connection.QuicConnectionTest.test_stream_direction client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) at: unittest.case.TestCase assertTrue(expr: Any, msg: Any=...) -> None assertFalse(expr: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_connection class QuicConnectionTest(TestCase): + def test_datagram_received_wrong_version(self): + client = QuicConnection(is_client=True) + client_transport = FakeTransport() + client.connection_made(client_transport) + self.assertEqual(client_transport.sent, 1) + + buf = Buffer(capacity=1300) + push_quic_header( + buf, + QuicHeader( + version=0xFF000011, # DRAFT_16 + packet_type=PACKET_TYPE_INITIAL | (PACKET_NUMBER_SEND_SIZE - 1), + destination_cid=client.host_cid, + source_cid=client.peer_cid, + ), + ) + buf.seek(1300) + client.datagram_received(buf.data, None) + self.assertEqual(client_transport.sent, 1) + ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: + def _connect(self): + """ + Start the client handshake. + """ + assert self.is_client + + self._initialize(self.peer_cid) + + self.tls.handle_message(b"", self.send_buffer) + self._push_crypto_data() + self._send_pending() + ===========changed ref 2=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_create_stream(self): client = QuicConnection(is_client=True) - client._initialize(b"") - server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) + + # perform handshake + client_transport, server_transport = create_transport(client, server) - server._initialize(b"") # client reader, writer = client.create_stream() self.assertEqual(writer.get_extra_info("stream_id"), 0) self.assertIsNotNone(writer.get_extra_info("connection")) reader, writer = client.create_stream() self.assertEqual(writer.get_extra_info("stream_id"), 4) reader, writer = client.create_stream(is_unidirectional=True) self.assertEqual(writer.get_extra_info("stream_id"), 2) reader, writer = client.create_stream(is_unidirectional=True) self.assertEqual(writer.get_extra_info("stream_id"), 6) # server reader, writer = server.create_stream() self.assertEqual(writer.get_extra_info("stream_id"), 1) reader, writer = server.create_stream() self.assertEqual(writer.get_extra_info("stream_id"), 5) reader, writer = server.create_stream(is_unidirectional=True) self.assertEqual(writer.get_extra_info("stream_id"), 3) reader, writer = server.create_stream(is_unidirectional=True) self.assertEqual(writer.get_extra_info("stream_id"), 7) ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def connection_made(self, transport: asyncio.DatagramTransport) -> None: """ Inform the connection of the transport used to send data. This object must have a ``sendto`` method which accepts a datagram to send. Calling :meth:`connection_made` on a client starts the TLS handshake. """ self.__transport = transport if self.is_client: + self.__version = max(self.supported_versions) + self._connect() - self._initialize(self.peer_cid) - self.tls.handle_message(b"", self.send_buffer) - self._push_crypto_data() - self._send_pending() - ===========changed ref 4=========== # module: aioquic.connection logger = logging.getLogger("quic") PACKET_MAX_SIZE = 1280 SECRETS_LABELS = [ [ None, "QUIC_CLIENT_EARLY_TRAFFIC_SECRET", "QUIC_CLIENT_HANDSHAKE_TRAFFIC_SECRET", "QUIC_CLIENT_TRAFFIC_SECRET_0", ], [ None, None, "QUIC_SERVER_HANDSHAKE_TRAFFIC_SECRET", "QUIC_SERVER_TRAFFIC_SECRET_0", ], ] - SEND_PN_SIZE = 2 STREAM_FLAGS = 0x07 ===========changed ref 5=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def _test_connect_with_version(self, client_versions, server_versions): client = QuicConnection(is_client=True) client.supported_versions = client_versions - client.version = max(client_versions) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) server.supported_versions = server_versions - server.version = max(server_versions) # perform handshake client_transport, server_transport = create_transport(client, server) self.assertEqual(client_transport.sent, 4) self.assertEqual(server_transport.sent, 4) run(client.connect()) # send data over stream client_reader, client_writer = client.create_stream() client_writer.write(b"ping") run(asyncio.sleep(0)) self.assertEqual(client_transport.sent, 5) self.assertEqual(server_transport.sent, 5) # FIXME: needs an API server_reader, server_writer = ( server.streams[0].reader, server.streams[0].writer, ) self.assertEqual(run(server_reader.read(1024)), b"ping") server_writer.write(b"pong") run(asyncio.sleep(0)) self.assertEqual(client_transport.sent, 6) self.assertEqual(server_transport.sent, 6) # client receives pong self.assertEqual(run(client_reader.read(1024)), b"pong") # client writes EOF client_writer.write_eof() run(asyncio.sleep(0)) self.assertEqual(client_transport.sent, 7) self.assertEqual(server_transport.sent, 7) # server receives EOF self.assertEqual(run(server_reader.</s> ===========changed ref 6=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def _test_connect_with_version(self, client_versions, server_versions): # offset: 1 <s>Equal(server_transport.sent, 7) # server receives EOF self.assertEqual(run(server_reader.read()), b"")
aioquic.connection/QuicConnection.close
Modified
aiortc~aioquic
62b05c0e95306da11d28ed63c77000bb8a15e5e8
[stream] propagate connection_lost() exception
<13>:<add> self.connection_lost( <del> self.connection_lost(None) <14>:<add> maybe_connection_error( <add> error_code=error_code, <add> frame_type=frame_type, <add> reason_phrase=reason_phrase, <add> ) <add> )
# module: aioquic.connection class QuicConnection: def close( self, error_code: int = QuicErrorCode.NO_ERROR, frame_type: Optional[int] = None, reason_phrase: str = "", ) -> None: <0> """ <1> Close the connection. <2> """ <3> self.__close = { <4> "error_code": error_code, <5> "frame_type": frame_type, <6> "reason_phrase": reason_phrase, <7> } <8> if self.__state not in [ <9> QuicConnectionState.CLOSING, <10> QuicConnectionState.DRAINING, <11> ]: <12> self._set_state(QuicConnectionState.CLOSING) <13> self.connection_lost(None) <14> self._send_pending() <15>
===========unchanged ref 0=========== at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] _handle_connection_close_frame(self, epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_connection_close_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_challenge_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_response_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_retire_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_streams_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.connection.QuicConnection.__init__ self.__close: Optional[Dict] = None at: aioquic.connection.QuicConnection._write_application self.__close = None at: aioquic.connection.QuicConnection._write_handshake self.__close = None at: aioquic.packet QuicErrorCode(x: Union[str, bytes, bytearray], base: int) QuicErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) ===========changed ref 0=========== # module: aioquic.connection + def maybe_connection_error( + error_code: int, frame_type: Optional[int], reason_phrase: str + ) -> Optional[QuicConnectionError]: + if error_code != QuicErrorCode.NO_ERROR: + return QuicConnectionError( + error_code=error_code, frame_type=frame_type, reason_phrase=reason_phrase + ) + ===========changed ref 1=========== # module: aioquic.stream class QuicStream: + def connection_lost(self, exc: Exception) -> None: + if self.reader is not None: + if exc is None: + self.reader.feed_eof() + else: + self.reader.set_exception(exc) +
aioquic.connection/QuicConnection.connection_lost
Modified
aiortc~aioquic
62b05c0e95306da11d28ed63c77000bb8a15e5e8
[stream] propagate connection_lost() exception
<1>:<del> if stream.reader: <2>:<del> stream.reader.feed_eof() <3>:<add> stream.connection_lost(exc)
# module: aioquic.connection class QuicConnection: # asyncio.DatagramProtocol def connection_lost(self, exc: Exception) -> None: <0> for stream in self.streams.values(): <1> if stream.reader: <2> stream.reader.feed_eof() <3>
===========unchanged ref 0=========== at: aioquic.connection.QuicConnection.__init__ self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} self._local_max_stream_data_bidi_local = 1048576 self._remote_max_stream_data_bidi_remote = 0 at: aioquic.connection.QuicConnection.create_stream stream_id += 4 stream_id = (int(is_unidirectional) << 1) | int(not self.is_client) at: aioquic.stream QuicStream(stream_id: Optional[int]=None, connection: Optional[Any]=None, max_stream_data_local: int=0, max_stream_data_remote: int=0) ===========changed ref 0=========== # module: aioquic.connection + def maybe_connection_error( + error_code: int, frame_type: Optional[int], reason_phrase: str + ) -> Optional[QuicConnectionError]: + if error_code != QuicErrorCode.NO_ERROR: + return QuicConnectionError( + error_code=error_code, frame_type=frame_type, reason_phrase=reason_phrase + ) + ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def close( self, error_code: int = QuicErrorCode.NO_ERROR, frame_type: Optional[int] = None, reason_phrase: str = "", ) -> None: """ Close the connection. """ self.__close = { "error_code": error_code, "frame_type": frame_type, "reason_phrase": reason_phrase, } if self.__state not in [ QuicConnectionState.CLOSING, QuicConnectionState.DRAINING, ]: self._set_state(QuicConnectionState.CLOSING) + self.connection_lost( - self.connection_lost(None) + maybe_connection_error( + error_code=error_code, + frame_type=frame_type, + reason_phrase=reason_phrase, + ) + ) self._send_pending() ===========changed ref 2=========== # module: aioquic.stream class QuicStream: + def connection_lost(self, exc: Exception) -> None: + if self.reader is not None: + if exc is None: + self.reader.feed_eof() + else: + self.reader.set_exception(exc) +
aioquic.connection/QuicConnection._handle_connection_close_frame
Modified
aiortc~aioquic
62b05c0e95306da11d28ed63c77000bb8a15e5e8
[stream] propagate connection_lost() exception
<4>:<add> error_code, frame_type, reason_phrase = packet.pull_transport_close_frame( <del> error_code, _, reason_phrase = packet.pull_transport_close_frame(buf) <5>:<add> buf <add> ) <7>:<add> frame_type = None <11>:<add> self.connection_lost( <del> self.connection_lost(None) <12>:<add> maybe_connection_error( <add> error_code=error_code, <add> frame_type=frame_type, <add> reason_phrase=reason_phrase, <add> ) <add> )
# module: aioquic.connection class QuicConnection: def _handle_connection_close_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: <0> """ <1> Handle a CONNECTION_CLOSE frame. <2> """ <3> if frame_type == QuicFrameType.TRANSPORT_CLOSE: <4> error_code, _, reason_phrase = packet.pull_transport_close_frame(buf) <5> else: <6> error_code, reason_phrase = packet.pull_application_close_frame(buf) <7> self.__logger.info( <8> "Connection close code 0x%X, reason %s", error_code, reason_phrase <9> ) <10> self._set_state(QuicConnectionState.DRAINING) <11> self.connection_lost(None) <12>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.connection.QuicConnection._write_application self.packet_number += 1 at: aioquic.connection.QuicConnection._write_handshake self.packet_number += 1 at: aioquic.packet pull_uint_var(buf: Buffer) -> int QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) pull_ack_frame(buf: Buffer) -> Tuple[RangeSet, int] at: aioquic.tls Epoch() ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: # asyncio.DatagramProtocol def connection_lost(self, exc: Exception) -> None: for stream in self.streams.values(): - if stream.reader: - stream.reader.feed_eof() + stream.connection_lost(exc) ===========changed ref 1=========== # module: aioquic.connection + def maybe_connection_error( + error_code: int, frame_type: Optional[int], reason_phrase: str + ) -> Optional[QuicConnectionError]: + if error_code != QuicErrorCode.NO_ERROR: + return QuicConnectionError( + error_code=error_code, frame_type=frame_type, reason_phrase=reason_phrase + ) + ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def close( self, error_code: int = QuicErrorCode.NO_ERROR, frame_type: Optional[int] = None, reason_phrase: str = "", ) -> None: """ Close the connection. """ self.__close = { "error_code": error_code, "frame_type": frame_type, "reason_phrase": reason_phrase, } if self.__state not in [ QuicConnectionState.CLOSING, QuicConnectionState.DRAINING, ]: self._set_state(QuicConnectionState.CLOSING) + self.connection_lost( - self.connection_lost(None) + maybe_connection_error( + error_code=error_code, + frame_type=frame_type, + reason_phrase=reason_phrase, + ) + ) self._send_pending() ===========changed ref 3=========== # module: aioquic.stream class QuicStream: + def connection_lost(self, exc: Exception) -> None: + if self.reader is not None: + if exc is None: + self.reader.feed_eof() + else: + self.reader.set_exception(exc) +
aioquic.stream/QuicStream.__init__
Modified
aiortc~aioquic
f3047b41a2c6c48c3b8866f52914b764d3fc7ba4
[stream] handle out-of-order FIN
<12>:<add> self._recv_fin = False <del> self._recv_start = 0 <13>:<add> self._recv_highest = 0 # the highest offset ever seen <add> self._recv_start = 0 # the offset for the start of the buffer
# module: aioquic.stream class QuicStream: def __init__( self, stream_id: Optional[int] = None, connection: Optional[Any] = None, max_stream_data_local: int = 0, max_stream_data_remote: int = 0, ) -> None: <0> self._connection = connection <1> self.max_stream_data_local = max_stream_data_local <2> self.max_stream_data_remote = max_stream_data_remote <3> <4> if stream_id is not None: <5> self.reader = asyncio.StreamReader() <6> self.writer = asyncio.StreamWriter(self, None, self.reader, None) <7> else: <8> self.reader = None <9> self.writer = None <10> <11> self._recv_buffer = bytearray() <12> self._recv_start = 0 <13> self._recv_ranges = RangeSet() <14> <15> self._send_buffer = bytearray() <16> self._send_fin = False <17> self._send_start = 0 <18> <19> self.__stream_id = stream_id <20>
===========unchanged ref 0=========== at: aioquic.rangeset RangeSet(ranges: Iterable[range]=[]) at: aioquic.stream.QuicStream.add_frame self._recv_highest = frame_end self._recv_buffer += bytearray(gap) self._recv_fin = True at: aioquic.stream.QuicStream.get_frame self._send_buffer = self._send_buffer[size:] self._send_fin = False self._send_start += size at: aioquic.stream.QuicStream.pull_data self._recv_buffer = self._recv_buffer[pos:] self._recv_start = r.stop at: aioquic.stream.QuicStream.write self._send_buffer += data at: aioquic.stream.QuicStream.write_eof self._send_fin = True at: asyncio.streams StreamWriter(transport: transports.BaseTransport, protocol: protocols.BaseProtocol, reader: Optional[StreamReader], loop: events.AbstractEventLoop) StreamReader(limit: int=..., loop: Optional[events.AbstractEventLoop]=...)
aioquic.stream/QuicStream.add_frame
Modified
aiortc~aioquic
f3047b41a2c6c48c3b8866f52914b764d3fc7ba4
[stream] handle out-of-order FIN
<5>:<add> frame_end = frame.offset + count <add> <add> # we should receive no more data beyond FIN! <add> if self._recv_fin and frame_end > self._recv_highest: <add> raise Exception("Data received beyond FIN") <16>:<add> self._recv_ranges.add(frame.offset, frame_end) <del> self._recv_ranges.add(frame.offset, frame.offset + count) <17>:<add> if frame_end > self._recv_highest: <add> self._recv_highest = frame_end <24>:<add> if frame.fin: <add> self._recv_fin = True <add> <27>:<add> if self._recv_fin and not self._recv_ranges: <del> if frame.fin:
# module: aioquic.stream class QuicStream: def add_frame(self, frame: QuicStreamFrame) -> None: <0> """ <1> Add a frame of received data. <2> """ <3> pos = frame.offset - self._recv_start <4> count = len(frame.data) <5> <6> if pos + count > 0: <7> # frame has been partially consumed <8> if pos < 0: <9> count += pos <10> frame.data = frame.data[-pos:] <11> frame.offset -= pos <12> pos = 0 <13> <14> # marked received <15> if count: <16> self._recv_ranges.add(frame.offset, frame.offset + count) <17> <18> # add data <19> gap = pos - len(self._recv_buffer) <20> if gap > 0: <21> self._recv_buffer += bytearray(gap) <22> self._recv_buffer[pos : pos + count] = frame.data <23> <24> if self.reader: <25> if self.has_data_to_read(): <26> self.reader.feed_data(self.pull_data()) <27> if frame.fin: <28> self.reader.feed_eof() <29>
===========unchanged ref 0=========== at: aioquic.packet QuicStreamFrame(data: bytes=b"", fin: bool=False, offset: int=0) at: aioquic.packet.QuicStreamFrame data: bytes = b"" fin: bool = False offset: int = 0 at: aioquic.rangeset.RangeSet add(start: int, stop: Optional[int]=None) -> None at: aioquic.stream.QuicStream.__init__ self._recv_buffer = bytearray() self._recv_fin = False self._recv_highest = 0 # the highest offset ever seen self._recv_start = 0 # the offset for the start of the buffer self._recv_ranges = RangeSet() self.__stream_id = stream_id at: aioquic.stream.QuicStream.add_frame self._recv_buffer += bytearray(gap) self._recv_fin = True at: aioquic.stream.QuicStream.pull_data self._recv_buffer = self._recv_buffer[pos:] self._recv_start = r.stop ===========changed ref 0=========== # module: aioquic.stream class QuicStream: def __init__( self, stream_id: Optional[int] = None, connection: Optional[Any] = None, max_stream_data_local: int = 0, max_stream_data_remote: int = 0, ) -> None: self._connection = connection self.max_stream_data_local = max_stream_data_local self.max_stream_data_remote = max_stream_data_remote if stream_id is not None: self.reader = asyncio.StreamReader() self.writer = asyncio.StreamWriter(self, None, self.reader, None) else: self.reader = None self.writer = None self._recv_buffer = bytearray() + self._recv_fin = False - self._recv_start = 0 + self._recv_highest = 0 # the highest offset ever seen + self._recv_start = 0 # the offset for the start of the buffer self._recv_ranges = RangeSet() self._send_buffer = bytearray() self._send_fin = False self._send_start = 0 self.__stream_id = stream_id
aioquic.packet/pull_transport_close_frame
Modified
aiortc~aioquic
0d3b95ebc93327d17e8705fef4a990f193dd013d
Fix type errors, thanks mypy!
<3>:<add> reason_phrase = decode_reason_phrase(pull_bytes(buf, reason_length)) <del> reason_phrase = pull_bytes(buf, reason_length)
# module: aioquic.packet + def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, str]: - def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, bytes]: <0> error_code = pull_uint16(buf) <1> frame_type = pull_uint_var(buf) <2> reason_length = pull_uint_var(buf) <3> reason_phrase = pull_bytes(buf, reason_length) <4> return (error_code, frame_type, reason_phrase) <5>
===========changed ref 0=========== # module: aioquic.packet + def decode_reason_phrase(reason_bytes: bytes) -> str: + try: + return reason_bytes.decode("utf8") + except UnicodeDecodeError: + return "" +
aioquic.packet/push_transport_close_frame
Modified
aiortc~aioquic
0d3b95ebc93327d17e8705fef4a990f193dd013d
Fix type errors, thanks mypy!
<0>:<add> reason_bytes = reason_phrase.encode("utf8") <2>:<add> push_uint_var(buf, len(reason_bytes)) <del> push_uint_var(buf, len(reason_phrase)) <3>:<add> push_bytes(buf, reason_bytes) <del> push_bytes(buf, reason_phrase)
# module: aioquic.packet def push_transport_close_frame( + buf: Buffer, error_code: int, frame_type: int, reason_phrase: str - buf: Buffer, error_code: int, frame_type: int, reason_phrase: bytes ) -> None: <0> push_uint16(buf, error_code) <1> push_uint_var(buf, frame_type) <2> push_uint_var(buf, len(reason_phrase)) <3> push_bytes(buf, reason_phrase) <4>
===========unchanged ref 0=========== at: aioquic.buffer pull_bytes(buf: Buffer, length: int) -> bytes pull_uint16(buf: Buffer) -> int at: aioquic.packet pull_uint_var(buf: Buffer) -> int decode_reason_phrase(reason_bytes: bytes) -> str ===========changed ref 0=========== # module: aioquic.packet + def decode_reason_phrase(reason_bytes: bytes) -> str: + try: + return reason_bytes.decode("utf8") + except UnicodeDecodeError: + return "" + ===========changed ref 1=========== # module: aioquic.packet + def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, str]: - def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, bytes]: error_code = pull_uint16(buf) frame_type = pull_uint_var(buf) reason_length = pull_uint_var(buf) + reason_phrase = decode_reason_phrase(pull_bytes(buf, reason_length)) - reason_phrase = pull_bytes(buf, reason_length) return (error_code, frame_type, reason_phrase)
aioquic.packet/pull_application_close_frame
Modified
aiortc~aioquic
0d3b95ebc93327d17e8705fef4a990f193dd013d
Fix type errors, thanks mypy!
<2>:<add> reason_phrase = decode_reason_phrase(pull_bytes(buf, reason_length)) <del> reason_phrase = pull_bytes(buf, reason_length)
# module: aioquic.packet + def pull_application_close_frame(buf: Buffer) -> Tuple[int, str]: - def pull_application_close_frame(buf: Buffer) -> Tuple[int, bytes]: <0> error_code = pull_uint16(buf) <1> reason_length = pull_uint_var(buf) <2> reason_phrase = pull_bytes(buf, reason_length) <3> return (error_code, reason_phrase) <4>
===========unchanged ref 0=========== at: aioquic.buffer push_uint16(buf: Buffer, v: int) -> None at: aioquic.packet push_uint_var(buf: Buffer, value: int) -> None ===========changed ref 0=========== # module: aioquic.packet + def decode_reason_phrase(reason_bytes: bytes) -> str: + try: + return reason_bytes.decode("utf8") + except UnicodeDecodeError: + return "" + ===========changed ref 1=========== # module: aioquic.packet def push_transport_close_frame( + buf: Buffer, error_code: int, frame_type: int, reason_phrase: str - buf: Buffer, error_code: int, frame_type: int, reason_phrase: bytes ) -> None: + reason_bytes = reason_phrase.encode("utf8") push_uint16(buf, error_code) push_uint_var(buf, frame_type) + push_uint_var(buf, len(reason_bytes)) - push_uint_var(buf, len(reason_phrase)) + push_bytes(buf, reason_bytes) - push_bytes(buf, reason_phrase) ===========changed ref 2=========== # module: aioquic.packet + def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, str]: - def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, bytes]: error_code = pull_uint16(buf) frame_type = pull_uint_var(buf) reason_length = pull_uint_var(buf) + reason_phrase = decode_reason_phrase(pull_bytes(buf, reason_length)) - reason_phrase = pull_bytes(buf, reason_length) return (error_code, frame_type, reason_phrase)
aioquic.packet/push_application_close_frame
Modified
aiortc~aioquic
0d3b95ebc93327d17e8705fef4a990f193dd013d
Fix type errors, thanks mypy!
<0>:<add> reason_bytes = reason_phrase.encode("utf8") <1>:<add> push_uint_var(buf, len(reason_bytes)) <del> push_uint_var(buf, len(reason_phrase)) <2>:<add> push_bytes(buf, reason_bytes) <del> push_bytes(buf, reason_phrase)
# module: aioquic.packet def push_application_close_frame( + buf: Buffer, error_code: int, reason_phrase: str - buf: Buffer, error_code: int, reason_phrase: bytes ) -> None: <0> push_uint16(buf, error_code) <1> push_uint_var(buf, len(reason_phrase)) <2> push_bytes(buf, reason_phrase) <3>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) pull_bytes(buf: Buffer, length: int) -> bytes pull_uint16(buf: Buffer) -> int at: aioquic.packet pull_uint_var(buf: Buffer) -> int decode_reason_phrase(reason_bytes: bytes) -> str at: typing Tuple = _TupleType(tuple, -1, inst=False, name='Tuple') ===========changed ref 0=========== # module: aioquic.packet + def decode_reason_phrase(reason_bytes: bytes) -> str: + try: + return reason_bytes.decode("utf8") + except UnicodeDecodeError: + return "" + ===========changed ref 1=========== # module: aioquic.packet + def pull_application_close_frame(buf: Buffer) -> Tuple[int, str]: - def pull_application_close_frame(buf: Buffer) -> Tuple[int, bytes]: error_code = pull_uint16(buf) reason_length = pull_uint_var(buf) + reason_phrase = decode_reason_phrase(pull_bytes(buf, reason_length)) - reason_phrase = pull_bytes(buf, reason_length) return (error_code, reason_phrase) ===========changed ref 2=========== # module: aioquic.packet def push_transport_close_frame( + buf: Buffer, error_code: int, frame_type: int, reason_phrase: str - buf: Buffer, error_code: int, frame_type: int, reason_phrase: bytes ) -> None: + reason_bytes = reason_phrase.encode("utf8") push_uint16(buf, error_code) push_uint_var(buf, frame_type) + push_uint_var(buf, len(reason_bytes)) - push_uint_var(buf, len(reason_phrase)) + push_bytes(buf, reason_bytes) - push_bytes(buf, reason_phrase) ===========changed ref 3=========== # module: aioquic.packet + def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, str]: - def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, bytes]: error_code = pull_uint16(buf) frame_type = pull_uint_var(buf) reason_length = pull_uint_var(buf) + reason_phrase = decode_reason_phrase(pull_bytes(buf, reason_length)) - reason_phrase = pull_bytes(buf, reason_length) return (error_code, frame_type, reason_phrase)
aioquic.connection/push_close
Modified
aiortc~aioquic
0d3b95ebc93327d17e8705fef4a990f193dd013d
Fix type errors, thanks mypy!
<0>:<del> reason_phrase_bytes = reason_phrase.encode("utf8") <3>:<add> packet.push_application_close_frame(buf, error_code, reason_phrase) <del> packet.push_application_close_frame(buf, error_code, reason_phrase_bytes) <6>:<del> packet.push_transport_close_frame( <7>:<del> buf, error_code, frame_type, reason_phrase_bytes <8>:<del> ) <9>:<add> packet.push_transport_close_frame(buf, error_code, frame_type, reason_phrase)
# module: aioquic.connection def push_close( buf: Buffer, error_code: int, frame_type: Optional[int], reason_phrase: str ) -> None: <0> reason_phrase_bytes = reason_phrase.encode("utf8") <1> if frame_type is None: <2> push_uint_var(buf, QuicFrameType.APPLICATION_CLOSE) <3> packet.push_application_close_frame(buf, error_code, reason_phrase_bytes) <4> else: <5> push_uint_var(buf, QuicFrameType.TRANSPORT_CLOSE) <6> packet.push_transport_close_frame( <7> buf, error_code, frame_type, reason_phrase_bytes <8> ) <9>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.packet push_uint_var(buf: Buffer, value: int) -> None QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) push_transport_close_frame(buf: Buffer, error_code: int, frame_type: int, reason_phrase: str) -> None push_application_close_frame(buf: Buffer, error_code: int, reason_phrase: str) -> None ===========changed ref 0=========== # module: aioquic.packet def push_application_close_frame( + buf: Buffer, error_code: int, reason_phrase: str - buf: Buffer, error_code: int, reason_phrase: bytes ) -> None: + reason_bytes = reason_phrase.encode("utf8") push_uint16(buf, error_code) + push_uint_var(buf, len(reason_bytes)) - push_uint_var(buf, len(reason_phrase)) + push_bytes(buf, reason_bytes) - push_bytes(buf, reason_phrase) ===========changed ref 1=========== # module: aioquic.packet def push_transport_close_frame( + buf: Buffer, error_code: int, frame_type: int, reason_phrase: str - buf: Buffer, error_code: int, frame_type: int, reason_phrase: bytes ) -> None: + reason_bytes = reason_phrase.encode("utf8") push_uint16(buf, error_code) push_uint_var(buf, frame_type) + push_uint_var(buf, len(reason_bytes)) - push_uint_var(buf, len(reason_phrase)) + push_bytes(buf, reason_bytes) - push_bytes(buf, reason_phrase) ===========changed ref 2=========== # module: aioquic.packet + def decode_reason_phrase(reason_bytes: bytes) -> str: + try: + return reason_bytes.decode("utf8") + except UnicodeDecodeError: + return "" + ===========changed ref 3=========== # module: aioquic.packet + def pull_application_close_frame(buf: Buffer) -> Tuple[int, str]: - def pull_application_close_frame(buf: Buffer) -> Tuple[int, bytes]: error_code = pull_uint16(buf) reason_length = pull_uint_var(buf) + reason_phrase = decode_reason_phrase(pull_bytes(buf, reason_length)) - reason_phrase = pull_bytes(buf, reason_length) return (error_code, reason_phrase) ===========changed ref 4=========== # module: aioquic.packet + def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, str]: - def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, bytes]: error_code = pull_uint16(buf) frame_type = pull_uint_var(buf) reason_length = pull_uint_var(buf) + reason_phrase = decode_reason_phrase(pull_bytes(buf, reason_length)) - reason_phrase = pull_bytes(buf, reason_length) return (error_code, frame_type, reason_phrase)
aioquic.connection/maybe_connection_error
Modified
aiortc~aioquic
0d3b95ebc93327d17e8705fef4a990f193dd013d
Fix type errors, thanks mypy!
<4>:<add> else: <add> return None
# module: aioquic.connection def maybe_connection_error( error_code: int, frame_type: Optional[int], reason_phrase: str ) -> Optional[QuicConnectionError]: <0> if error_code != QuicErrorCode.NO_ERROR: <1> return QuicConnectionError( <2> error_code=error_code, frame_type=frame_type, reason_phrase=reason_phrase <3> ) <4>
===========unchanged ref 0=========== at: aioquic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: aioquic.packet QuicErrorCode(x: Union[str, bytes, bytearray], base: int) QuicErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) ===========changed ref 0=========== # module: aioquic.connection def push_close( buf: Buffer, error_code: int, frame_type: Optional[int], reason_phrase: str ) -> None: - reason_phrase_bytes = reason_phrase.encode("utf8") if frame_type is None: push_uint_var(buf, QuicFrameType.APPLICATION_CLOSE) + packet.push_application_close_frame(buf, error_code, reason_phrase) - packet.push_application_close_frame(buf, error_code, reason_phrase_bytes) else: push_uint_var(buf, QuicFrameType.TRANSPORT_CLOSE) - packet.push_transport_close_frame( - buf, error_code, frame_type, reason_phrase_bytes - ) + packet.push_transport_close_frame(buf, error_code, frame_type, reason_phrase) ===========changed ref 1=========== # module: aioquic.packet + def decode_reason_phrase(reason_bytes: bytes) -> str: + try: + return reason_bytes.decode("utf8") + except UnicodeDecodeError: + return "" + ===========changed ref 2=========== # module: aioquic.packet + def pull_application_close_frame(buf: Buffer) -> Tuple[int, str]: - def pull_application_close_frame(buf: Buffer) -> Tuple[int, bytes]: error_code = pull_uint16(buf) reason_length = pull_uint_var(buf) + reason_phrase = decode_reason_phrase(pull_bytes(buf, reason_length)) - reason_phrase = pull_bytes(buf, reason_length) return (error_code, reason_phrase) ===========changed ref 3=========== # module: aioquic.packet def push_application_close_frame( + buf: Buffer, error_code: int, reason_phrase: str - buf: Buffer, error_code: int, reason_phrase: bytes ) -> None: + reason_bytes = reason_phrase.encode("utf8") push_uint16(buf, error_code) + push_uint_var(buf, len(reason_bytes)) - push_uint_var(buf, len(reason_phrase)) + push_bytes(buf, reason_bytes) - push_bytes(buf, reason_phrase) ===========changed ref 4=========== # module: aioquic.packet + def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, str]: - def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, bytes]: error_code = pull_uint16(buf) frame_type = pull_uint_var(buf) reason_length = pull_uint_var(buf) + reason_phrase = decode_reason_phrase(pull_bytes(buf, reason_length)) - reason_phrase = pull_bytes(buf, reason_length) return (error_code, frame_type, reason_phrase) ===========changed ref 5=========== # module: aioquic.packet def push_transport_close_frame( + buf: Buffer, error_code: int, frame_type: int, reason_phrase: str - buf: Buffer, error_code: int, frame_type: int, reason_phrase: bytes ) -> None: + reason_bytes = reason_phrase.encode("utf8") push_uint16(buf, error_code) push_uint_var(buf, frame_type) + push_uint_var(buf, len(reason_bytes)) - push_uint_var(buf, len(reason_phrase)) + push_bytes(buf, reason_bytes) - push_bytes(buf, reason_phrase)
tests.test_packet/FrameTest.test_transport_close
Modified
aiortc~aioquic
0d3b95ebc93327d17e8705fef4a990f193dd013d
Fix type errors, thanks mypy!
<5>:<add> self.assertEqual(frame, (10, 2, "illegal ACK frame\x00")) <del> self.assertEqual(frame, (10, 2, b"illegal ACK frame\x00"))
# module: tests.test_packet class FrameTest(TestCase): def test_transport_close(self): <0> data = binascii.unhexlify("000a0212696c6c6567616c2041434b206672616d6500") <1> <2> # parse <3> buf = Buffer(data=data) <4> frame = packet.pull_transport_close_frame(buf) <5> self.assertEqual(frame, (10, 2, b"illegal ACK frame\x00")) <6> <7> # serialize <8> buf = Buffer(capacity=len(data)) <9> packet.push_transport_close_frame(buf, *frame) <10> self.assertEqual(buf.data, data) <11>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.packet pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, str] push_transport_close_frame(buf: Buffer, error_code: int, frame_type: int, reason_phrase: str) -> None at: binascii unhexlify(hexstr: _Ascii, /) -> bytes at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.packet + def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, str]: - def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, bytes]: error_code = pull_uint16(buf) frame_type = pull_uint_var(buf) reason_length = pull_uint_var(buf) + reason_phrase = decode_reason_phrase(pull_bytes(buf, reason_length)) - reason_phrase = pull_bytes(buf, reason_length) return (error_code, frame_type, reason_phrase) ===========changed ref 1=========== # module: aioquic.packet def push_transport_close_frame( + buf: Buffer, error_code: int, frame_type: int, reason_phrase: str - buf: Buffer, error_code: int, frame_type: int, reason_phrase: bytes ) -> None: + reason_bytes = reason_phrase.encode("utf8") push_uint16(buf, error_code) push_uint_var(buf, frame_type) + push_uint_var(buf, len(reason_bytes)) - push_uint_var(buf, len(reason_phrase)) + push_bytes(buf, reason_bytes) - push_bytes(buf, reason_phrase) ===========changed ref 2=========== # module: aioquic.packet + def decode_reason_phrase(reason_bytes: bytes) -> str: + try: + return reason_bytes.decode("utf8") + except UnicodeDecodeError: + return "" + ===========changed ref 3=========== # module: aioquic.connection def maybe_connection_error( error_code: int, frame_type: Optional[int], reason_phrase: str ) -> Optional[QuicConnectionError]: if error_code != QuicErrorCode.NO_ERROR: return QuicConnectionError( error_code=error_code, frame_type=frame_type, reason_phrase=reason_phrase ) + else: + return None ===========changed ref 4=========== # module: aioquic.packet + def pull_application_close_frame(buf: Buffer) -> Tuple[int, str]: - def pull_application_close_frame(buf: Buffer) -> Tuple[int, bytes]: error_code = pull_uint16(buf) reason_length = pull_uint_var(buf) + reason_phrase = decode_reason_phrase(pull_bytes(buf, reason_length)) - reason_phrase = pull_bytes(buf, reason_length) return (error_code, reason_phrase) ===========changed ref 5=========== # module: aioquic.packet def push_application_close_frame( + buf: Buffer, error_code: int, reason_phrase: str - buf: Buffer, error_code: int, reason_phrase: bytes ) -> None: + reason_bytes = reason_phrase.encode("utf8") push_uint16(buf, error_code) + push_uint_var(buf, len(reason_bytes)) - push_uint_var(buf, len(reason_phrase)) + push_bytes(buf, reason_bytes) - push_bytes(buf, reason_phrase) ===========changed ref 6=========== # module: aioquic.connection def push_close( buf: Buffer, error_code: int, frame_type: Optional[int], reason_phrase: str ) -> None: - reason_phrase_bytes = reason_phrase.encode("utf8") if frame_type is None: push_uint_var(buf, QuicFrameType.APPLICATION_CLOSE) + packet.push_application_close_frame(buf, error_code, reason_phrase) - packet.push_application_close_frame(buf, error_code, reason_phrase_bytes) else: push_uint_var(buf, QuicFrameType.TRANSPORT_CLOSE) - packet.push_transport_close_frame( - buf, error_code, frame_type, reason_phrase_bytes - ) + packet.push_transport_close_frame(buf, error_code, frame_type, reason_phrase)
tests.test_packet/FrameTest.test_application_close
Modified
aiortc~aioquic
0d3b95ebc93327d17e8705fef4a990f193dd013d
Fix type errors, thanks mypy!
<5>:<add> self.assertEqual(frame, (0, "goodbye\x00")) <del> self.assertEqual(frame, (0, b"goodbye\x00"))
# module: tests.test_packet class FrameTest(TestCase): def test_application_close(self): <0> data = binascii.unhexlify("000008676f6f6462796500") <1> <2> # parse <3> buf = Buffer(data=data) <4> frame = packet.pull_application_close_frame(buf) <5> self.assertEqual(frame, (0, b"goodbye\x00")) <6> <7> # serialize <8> buf = Buffer(capacity=len(data)) <9> packet.push_application_close_frame(buf, *frame) <10> self.assertEqual(buf.data, data) <11>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.packet pull_application_close_frame(buf: Buffer) -> Tuple[int, str] push_application_close_frame(buf: Buffer, error_code: int, reason_phrase: str) -> None at: binascii unhexlify(hexstr: _Ascii, /) -> bytes at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.packet + def pull_application_close_frame(buf: Buffer) -> Tuple[int, str]: - def pull_application_close_frame(buf: Buffer) -> Tuple[int, bytes]: error_code = pull_uint16(buf) reason_length = pull_uint_var(buf) + reason_phrase = decode_reason_phrase(pull_bytes(buf, reason_length)) - reason_phrase = pull_bytes(buf, reason_length) return (error_code, reason_phrase) ===========changed ref 1=========== # module: aioquic.packet def push_application_close_frame( + buf: Buffer, error_code: int, reason_phrase: str - buf: Buffer, error_code: int, reason_phrase: bytes ) -> None: + reason_bytes = reason_phrase.encode("utf8") push_uint16(buf, error_code) + push_uint_var(buf, len(reason_bytes)) - push_uint_var(buf, len(reason_phrase)) + push_bytes(buf, reason_bytes) - push_bytes(buf, reason_phrase) ===========changed ref 2=========== # module: tests.test_packet class FrameTest(TestCase): def test_transport_close(self): data = binascii.unhexlify("000a0212696c6c6567616c2041434b206672616d6500") # parse buf = Buffer(data=data) frame = packet.pull_transport_close_frame(buf) + self.assertEqual(frame, (10, 2, "illegal ACK frame\x00")) - self.assertEqual(frame, (10, 2, b"illegal ACK frame\x00")) # serialize buf = Buffer(capacity=len(data)) packet.push_transport_close_frame(buf, *frame) self.assertEqual(buf.data, data) ===========changed ref 3=========== # module: aioquic.packet + def decode_reason_phrase(reason_bytes: bytes) -> str: + try: + return reason_bytes.decode("utf8") + except UnicodeDecodeError: + return "" + ===========changed ref 4=========== # module: aioquic.connection def maybe_connection_error( error_code: int, frame_type: Optional[int], reason_phrase: str ) -> Optional[QuicConnectionError]: if error_code != QuicErrorCode.NO_ERROR: return QuicConnectionError( error_code=error_code, frame_type=frame_type, reason_phrase=reason_phrase ) + else: + return None ===========changed ref 5=========== # module: aioquic.packet + def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, str]: - def pull_transport_close_frame(buf: Buffer) -> Tuple[int, int, bytes]: error_code = pull_uint16(buf) frame_type = pull_uint_var(buf) reason_length = pull_uint_var(buf) + reason_phrase = decode_reason_phrase(pull_bytes(buf, reason_length)) - reason_phrase = pull_bytes(buf, reason_length) return (error_code, frame_type, reason_phrase) ===========changed ref 6=========== # module: aioquic.packet def push_transport_close_frame( + buf: Buffer, error_code: int, frame_type: int, reason_phrase: str - buf: Buffer, error_code: int, frame_type: int, reason_phrase: bytes ) -> None: + reason_bytes = reason_phrase.encode("utf8") push_uint16(buf, error_code) push_uint_var(buf, frame_type) + push_uint_var(buf, len(reason_bytes)) - push_uint_var(buf, len(reason_phrase)) + push_bytes(buf, reason_bytes) - push_bytes(buf, reason_phrase) ===========changed ref 7=========== # module: aioquic.connection def push_close( buf: Buffer, error_code: int, frame_type: Optional[int], reason_phrase: str ) -> None: - reason_phrase_bytes = reason_phrase.encode("utf8") if frame_type is None: push_uint_var(buf, QuicFrameType.APPLICATION_CLOSE) + packet.push_application_close_frame(buf, error_code, reason_phrase) - packet.push_application_close_frame(buf, error_code, reason_phrase_bytes) else: push_uint_var(buf, QuicFrameType.TRANSPORT_CLOSE) - packet.push_transport_close_frame( - buf, error_code, frame_type, reason_phrase_bytes - ) + packet.push_transport_close_frame(buf, error_code, frame_type, reason_phrase)
aioquic.connection/QuicConnection.__init__
Modified
aiortc~aioquic
d5e97667116c132e3154ac97c53e514a2eb55dcf
[connection] check stream data does not exceed local MAX_DATA
<21>:<add> self._local_max_data_used = 0
# module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: <0> if not is_client: <1> assert certificate is not None, "SSL certificate is required" <2> assert private_key is not None, "SSL private key is required" <3> <4> self.alpn_protocols = alpn_protocols <5> self.certificate = certificate <6> self.is_client = is_client <7> self.host_cid = os.urandom(8) <8> self.peer_cid = os.urandom(8) <9> self.peer_cid_set = False <10> self.peer_token = b"" <11> self.private_key = private_key <12> self.secrets_log_file = secrets_log_file <13> self.server_name = server_name <14> self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} <15> <16> self.__close: Optional[Dict] = None <17> self.__connected = asyncio.Event() <18> self.__epoch = tls.Epoch.INITIAL <19> self._local_idle_timeout = 60000 # milliseconds <20> self._local_max_data = 1048576 <21> self._local_max_stream_data_bidi_local = 1048576 <22> self._local_max_stream_data_bidi_remote = 1048576 <23> self._local_max_stream_data_uni = 1048576 <24> self._local_max_streams_bidi = 128 <25> self._local_max_streams_uni = 128 <26> self.__logger = logger <27> self.__path_challenge: Optional[bytes] = None <28> self._pending_flow_control: List[bytes] = [] <29> self._remote_idle_timeout = 0 #</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self._spin_bit = False self._spin_highest_pn = 0 self.__send_pending_task: Optional[asyncio.Handle] = None self.__state = QuicConnectionState.FIRSTFLIGHT self.__transport: Optional[asyncio.DatagramTransport] = None self.__version: Optional[int] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data</s> ===========below chunk 1=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s>, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ] ===========unchanged ref 0=========== at: aioquic.connection logger = logging.getLogger("quic") QuicConnectionState() at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] _handle_ack_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_connection_close_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_crypto_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_stream_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_bidi_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_uni_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_token_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_padding_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_challenge_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_response_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_reset_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None ===========unchanged ref 1=========== _handle_retire_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stop_sending_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_frame(self, epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_streams_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.connection.QuicConnection._handle_crypto_frame self.__epoch = tls.Epoch.ONE_RTT self.__epoch = tls.Epoch.HANDSHAKE at: aioquic.connection.QuicConnection._handle_max_data_frame self._remote_max_data = max_data at: aioquic.connection.QuicConnection._handle_max_streams_bidi_frame self._remote_max_streams_bidi = max_streams at: aioquic.connection.QuicConnection._handle_max_streams_uni_frame self._remote_max_streams_uni = max_streams at: aioquic.connection.QuicConnection._handle_stream_frame self._local_max_data_used += newly_received at: aioquic.connection.QuicConnection._parse_transport_parameters self._remote_idle_timeout = quic_transport_parameters.idle_timeout at: aioquic.connection.QuicConnection._send_path_challenge self.__path_challenge = os.urandom(8) at: aioquic.connection.QuicConnection._send_pending self.__send_pending_task = None
aioquic.connection/QuicConnection._handle_stream_frame
Modified
aiortc~aioquic
d5e97667116c132e3154ac97c53e514a2eb55dcf
[connection] check stream data does not exceed local MAX_DATA
<22>:<add> # check flow-control limits <del> # check limits <30>:<add> newly_received = max(0, offset + length - stream._recv_highest) <add> if self._local_max_data_used + newly_received > self._local_max_data: <add> raise QuicConnectionError( <add> error_code=QuicErrorCode.FLOW_CONTROL_ERROR, <add> frame_type=frame_type, <add> reason_phrase="Over connection data limit", <add> ) <add> <31>:<add> self._local_max_data_used += newly_received
# module: aioquic.connection class QuicConnection: def _handle_stream_frame( self, epoch: tls.Epoch, frame_type: int, buf: Buffer ) -> None: <0> """ <1> Handle a STREAM frame. <2> """ <3> flags = frame_type & STREAM_FLAGS <4> stream_id = pull_uint_var(buf) <5> if flags & QuicStreamFlag.OFF: <6> offset = pull_uint_var(buf) <7> else: <8> offset = 0 <9> if flags & QuicStreamFlag.LEN: <10> length = pull_uint_var(buf) <11> else: <12> length = buf.capacity - buf.tell() <13> frame = QuicStreamFrame( <14> offset=offset, <15> data=pull_bytes(buf, length), <16> fin=bool(flags & QuicStreamFlag.FIN), <17> ) <18> <19> # check stream direction <20> self._assert_stream_can_receive(frame_type, stream_id) <21> <22> # check limits <23> stream = self._get_or_create_stream(frame_type, stream_id) <24> if offset + length > stream.max_stream_data_local: <25> raise QuicConnectionError( <26> error_code=QuicErrorCode.FLOW_CONTROL_ERROR, <27> frame_type=frame_type, <28> reason_phrase="Over stream data limit", <29> ) <30> stream.add_frame(frame) <31>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) pull_bytes(buf: Buffer, length: int) -> bytes at: aioquic.buffer.Buffer tell() -> int at: aioquic.connection STREAM_FLAGS = 0x07 QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: aioquic.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.packet QuicErrorCode(x: Union[str, bytes, bytearray], base: int) QuicErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) pull_uint_var(buf: Buffer) -> int QuicStreamFlag(x: Union[str, bytes, bytearray], base: int) QuicStreamFlag(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicStreamFrame(data: bytes=b"", fin: bool=False, offset: int=0) at: aioquic.packet.QuicStreamFrame data: bytes = b"" fin: bool = False offset: int = 0 at: aioquic.stream.QuicStream.__init__ self.max_stream_data_local = max_stream_data_local at: aioquic.tls Epoch() ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: if not is_client: assert certificate is not None, "SSL certificate is required" assert private_key is not None, "SSL private key is required" self.alpn_protocols = alpn_protocols self.certificate = certificate self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.private_key = private_key self.secrets_log_file = secrets_log_file self.server_name = server_name self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} self.__close: Optional[Dict] = None self.__connected = asyncio.Event() self.__epoch = tls.Epoch.INITIAL self._local_idle_timeout = 60000 # milliseconds self._local_max_data = 1048576 + self._local_max_data_used = 0 self._local_max_stream_data_bidi_local = 1048576 self._local_max_stream_data_bidi_remote = 1048576 self._local_max_stream_data_uni = 1048576 self._local_max_streams_bidi = 128 self._local_max_streams_uni = 128 self.__logger = logger self.__path_challenge: Optional[bytes] = None self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0 # milliseconds self._remote_max_data = 0 self._</s> ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 <s> [] self._remote_idle_timeout = 0 # milliseconds self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self._spin_bit = False self._spin_highest_pn = 0 self.__send_pending_task: Optional[asyncio.Handle] = None self.__state = QuicConnectionState.FIRSTFLIGHT self.__transport: Optional[asyncio.DatagramTransport] = None self.__version: Optional[int] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame,</s> ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s> self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ]
aioquic.stream/QuicStream.__init__
Modified
aiortc~aioquic
825fb8dbb0ad1817d2f625c58274a8bcba7eec90
[stream] ensure FIN is only written once all data is sent
<18>:<add> self._send_complete = False <add> self._send_eof = False <del> self._send_fin = False
# module: aioquic.stream class QuicStream: def __init__( self, stream_id: Optional[int] = None, connection: Optional[Any] = None, max_stream_data_local: int = 0, max_stream_data_remote: int = 0, ) -> None: <0> self._connection = connection <1> self.max_stream_data_local = max_stream_data_local <2> self.max_stream_data_remote = max_stream_data_remote <3> <4> if stream_id is not None: <5> self.reader = asyncio.StreamReader() <6> self.writer = asyncio.StreamWriter(self, None, self.reader, None) <7> else: <8> self.reader = None <9> self.writer = None <10> <11> self._recv_buffer = bytearray() <12> self._recv_fin = False <13> self._recv_highest = 0 # the highest offset ever seen <14> self._recv_start = 0 # the offset for the start of the buffer <15> self._recv_ranges = RangeSet() <16> <17> self._send_buffer = bytearray() <18> self._send_fin = False <19> self._send_start = 0 <20> <21> self.__stream_id = stream_id <22>
===========unchanged ref 0=========== at: aioquic.rangeset RangeSet(ranges: Iterable[range]=[]) at: aioquic.stream.QuicStream.add_frame self._recv_highest = frame_end self._recv_buffer += bytearray(gap) self._recv_fin = True at: aioquic.stream.QuicStream.get_frame self._send_buffer = self._send_buffer[size:] self._send_start += size self._send_complete = True at: aioquic.stream.QuicStream.pull_data self._recv_buffer = self._recv_buffer[pos:] self._recv_start = r.stop at: aioquic.stream.QuicStream.write self._send_buffer += data at: aioquic.stream.QuicStream.write_eof self._send_eof = True at: asyncio.streams StreamWriter(transport: transports.BaseTransport, protocol: protocols.BaseProtocol, reader: Optional[StreamReader], loop: events.AbstractEventLoop) StreamReader(limit: int=..., loop: Optional[events.AbstractEventLoop]=...)
aioquic.stream/QuicStream.get_frame
Modified
aiortc~aioquic
825fb8dbb0ad1817d2f625c58274a8bcba7eec90
[stream] ensure FIN is only written once all data is sent
<3>:<add> assert not self._send_complete, "cannot call get_frame() after completion" <add> <5>:<del> frame.fin = self._send_fin <7>:<del> self._send_fin = False <9>:<add> <add> # if the buffer is empty and EOF was written, set the FIN bit <add> if self._send_eof and not self._send_buffer: <add> frame.fin = True <add> self._send_complete = True <add>
# module: aioquic.stream class QuicStream: def get_frame(self, size: int) -> QuicStreamFrame: <0> """ <1> Get a frame of data to send. <2> """ <3> size = min(size, len(self._send_buffer)) <4> frame = QuicStreamFrame(data=self._send_buffer[:size], offset=self._send_start) <5> frame.fin = self._send_fin <6> self._send_buffer = self._send_buffer[size:] <7> self._send_fin = False <8> self._send_start += size <9> return frame <10>
===========unchanged ref 0=========== at: aioquic.packet QuicStreamFrame(data: bytes=b"", fin: bool=False, offset: int=0) at: aioquic.packet.QuicStreamFrame data: bytes = b"" fin: bool = False offset: int = 0 at: aioquic.stream.QuicStream.__init__ self._send_buffer = bytearray() self._send_complete = False self._send_start = 0 at: aioquic.stream.QuicStream.get_frame self._send_complete = True at: aioquic.stream.QuicStream.write self._send_buffer += data ===========changed ref 0=========== # module: aioquic.stream class QuicStream: def __init__( self, stream_id: Optional[int] = None, connection: Optional[Any] = None, max_stream_data_local: int = 0, max_stream_data_remote: int = 0, ) -> None: self._connection = connection self.max_stream_data_local = max_stream_data_local self.max_stream_data_remote = max_stream_data_remote if stream_id is not None: self.reader = asyncio.StreamReader() self.writer = asyncio.StreamWriter(self, None, self.reader, None) else: self.reader = None self.writer = None self._recv_buffer = bytearray() self._recv_fin = False self._recv_highest = 0 # the highest offset ever seen self._recv_start = 0 # the offset for the start of the buffer self._recv_ranges = RangeSet() self._send_buffer = bytearray() + self._send_complete = False + self._send_eof = False - self._send_fin = False self._send_start = 0 self.__stream_id = stream_id
aioquic.stream/QuicStream.has_data_to_send
Modified
aiortc~aioquic
825fb8dbb0ad1817d2f625c58274a8bcba7eec90
[stream] ensure FIN is only written once all data is sent
<0>:<add> return not self._send_complete and (self._send_eof or bool(self._send_buffer)) <del> return bool(self._send_buffer) or self._send_fin
# module: aioquic.stream class QuicStream: def has_data_to_send(self) -> bool: <0> return bool(self._send_buffer) or self._send_fin <1>
===========unchanged ref 0=========== at: aioquic.stream.QuicStream.get_frame frame = QuicStreamFrame(data=self._send_buffer[:size], offset=self._send_start) ===========changed ref 0=========== # module: aioquic.stream class QuicStream: def get_frame(self, size: int) -> QuicStreamFrame: """ Get a frame of data to send. """ + assert not self._send_complete, "cannot call get_frame() after completion" + size = min(size, len(self._send_buffer)) frame = QuicStreamFrame(data=self._send_buffer[:size], offset=self._send_start) - frame.fin = self._send_fin self._send_buffer = self._send_buffer[size:] - self._send_fin = False self._send_start += size + + # if the buffer is empty and EOF was written, set the FIN bit + if self._send_eof and not self._send_buffer: + frame.fin = True + self._send_complete = True + return frame ===========changed ref 1=========== # module: aioquic.stream class QuicStream: def __init__( self, stream_id: Optional[int] = None, connection: Optional[Any] = None, max_stream_data_local: int = 0, max_stream_data_remote: int = 0, ) -> None: self._connection = connection self.max_stream_data_local = max_stream_data_local self.max_stream_data_remote = max_stream_data_remote if stream_id is not None: self.reader = asyncio.StreamReader() self.writer = asyncio.StreamWriter(self, None, self.reader, None) else: self.reader = None self.writer = None self._recv_buffer = bytearray() self._recv_fin = False self._recv_highest = 0 # the highest offset ever seen self._recv_start = 0 # the offset for the start of the buffer self._recv_ranges = RangeSet() self._send_buffer = bytearray() + self._send_complete = False + self._send_eof = False - self._send_fin = False self._send_start = 0 self.__stream_id = stream_id
aioquic.stream/QuicStream.write
Modified
aiortc~aioquic
825fb8dbb0ad1817d2f625c58274a8bcba7eec90
[stream] ensure FIN is only written once all data is sent
<0>:<add> assert not self._send_complete, "cannot call write() after completion" <add>
# module: aioquic.stream class QuicStream: def write(self, data: bytes) -> None: <0> if data: <1> self._send_buffer += data <2> if self._connection is not None: <3> self._connection._send_soon() <4>
===========unchanged ref 0=========== at: aioquic.stream.QuicStream.__init__ self._connection = connection ===========changed ref 0=========== # module: aioquic.stream class QuicStream: def has_data_to_send(self) -> bool: + return not self._send_complete and (self._send_eof or bool(self._send_buffer)) - return bool(self._send_buffer) or self._send_fin ===========changed ref 1=========== # module: aioquic.stream class QuicStream: def get_frame(self, size: int) -> QuicStreamFrame: """ Get a frame of data to send. """ + assert not self._send_complete, "cannot call get_frame() after completion" + size = min(size, len(self._send_buffer)) frame = QuicStreamFrame(data=self._send_buffer[:size], offset=self._send_start) - frame.fin = self._send_fin self._send_buffer = self._send_buffer[size:] - self._send_fin = False self._send_start += size + + # if the buffer is empty and EOF was written, set the FIN bit + if self._send_eof and not self._send_buffer: + frame.fin = True + self._send_complete = True + return frame ===========changed ref 2=========== # module: aioquic.stream class QuicStream: def __init__( self, stream_id: Optional[int] = None, connection: Optional[Any] = None, max_stream_data_local: int = 0, max_stream_data_remote: int = 0, ) -> None: self._connection = connection self.max_stream_data_local = max_stream_data_local self.max_stream_data_remote = max_stream_data_remote if stream_id is not None: self.reader = asyncio.StreamReader() self.writer = asyncio.StreamWriter(self, None, self.reader, None) else: self.reader = None self.writer = None self._recv_buffer = bytearray() self._recv_fin = False self._recv_highest = 0 # the highest offset ever seen self._recv_start = 0 # the offset for the start of the buffer self._recv_ranges = RangeSet() self._send_buffer = bytearray() + self._send_complete = False + self._send_eof = False - self._send_fin = False self._send_start = 0 self.__stream_id = stream_id
aioquic.stream/QuicStream.write_eof
Modified
aiortc~aioquic
825fb8dbb0ad1817d2f625c58274a8bcba7eec90
[stream] ensure FIN is only written once all data is sent
<0>:<del> self._send_fin = True <1>:<del> self._connection._send_soon() <2>:<add> assert not self._send_complete, "cannot call write_eof() after completion"
# module: aioquic.stream class QuicStream: def write_eof(self) -> None: <0> self._send_fin = True <1> self._connection._send_soon() <2>
===========unchanged ref 0=========== at: aioquic.stream.QuicStream.__init__ self._send_complete = False at: aioquic.stream.QuicStream.get_frame self._send_complete = True ===========changed ref 0=========== # module: aioquic.stream class QuicStream: def write(self, data: bytes) -> None: + assert not self._send_complete, "cannot call write() after completion" + if data: self._send_buffer += data if self._connection is not None: self._connection._send_soon() ===========changed ref 1=========== # module: aioquic.stream class QuicStream: def has_data_to_send(self) -> bool: + return not self._send_complete and (self._send_eof or bool(self._send_buffer)) - return bool(self._send_buffer) or self._send_fin ===========changed ref 2=========== # module: aioquic.stream class QuicStream: def get_frame(self, size: int) -> QuicStreamFrame: """ Get a frame of data to send. """ + assert not self._send_complete, "cannot call get_frame() after completion" + size = min(size, len(self._send_buffer)) frame = QuicStreamFrame(data=self._send_buffer[:size], offset=self._send_start) - frame.fin = self._send_fin self._send_buffer = self._send_buffer[size:] - self._send_fin = False self._send_start += size + + # if the buffer is empty and EOF was written, set the FIN bit + if self._send_eof and not self._send_buffer: + frame.fin = True + self._send_complete = True + return frame ===========changed ref 3=========== # module: aioquic.stream class QuicStream: def __init__( self, stream_id: Optional[int] = None, connection: Optional[Any] = None, max_stream_data_local: int = 0, max_stream_data_remote: int = 0, ) -> None: self._connection = connection self.max_stream_data_local = max_stream_data_local self.max_stream_data_remote = max_stream_data_remote if stream_id is not None: self.reader = asyncio.StreamReader() self.writer = asyncio.StreamWriter(self, None, self.reader, None) else: self.reader = None self.writer = None self._recv_buffer = bytearray() self._recv_fin = False self._recv_highest = 0 # the highest offset ever seen self._recv_start = 0 # the offset for the start of the buffer self._recv_ranges = RangeSet() self._send_buffer = bytearray() + self._send_complete = False + self._send_eof = False - self._send_fin = False self._send_start = 0 self.__stream_id = stream_id
aioquic.connection/QuicConnection.__init__
Modified
aiortc~aioquic
cd8cee6eeff51543992c1a09d1d1853f97142d19
[connection] let server start tracking remote address
<29>:<add> self.__peer_addr: Optional[Any] = None
# module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: <0> if not is_client: <1> assert certificate is not None, "SSL certificate is required" <2> assert private_key is not None, "SSL private key is required" <3> <4> self.alpn_protocols = alpn_protocols <5> self.certificate = certificate <6> self.is_client = is_client <7> self.host_cid = os.urandom(8) <8> self.peer_cid = os.urandom(8) <9> self.peer_cid_set = False <10> self.peer_token = b"" <11> self.private_key = private_key <12> self.secrets_log_file = secrets_log_file <13> self.server_name = server_name <14> self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} <15> <16> self.__close: Optional[Dict] = None <17> self.__connected = asyncio.Event() <18> self.__epoch = tls.Epoch.INITIAL <19> self._local_idle_timeout = 60000 # milliseconds <20> self._local_max_data = 1048576 <21> self._local_max_data_used = 0 <22> self._local_max_stream_data_bidi_local = 1048576 <23> self._local_max_stream_data_bidi_remote = 1048576 <24> self._local_max_stream_data_uni = 1048576 <25> self._local_max_streams_bidi = 128 <26> self._local_max_streams_uni = 128 <27> self.__logger = logger <28> self.__path_challenge: Optional[bytes] = None <29> self._pending_flow_control: List[bytes] = []</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self._spin_bit = False self._spin_highest_pn = 0 self.__send_pending_task: Optional[asyncio.Handle] = None self.__state = QuicConnectionState.FIRSTFLIGHT self.__transport: Optional[asyncio.DatagramTransport] = None self.__version: Optional[int] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data</s> ===========below chunk 1=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s>, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ] ===========unchanged ref 0=========== at: aioquic.connection logger = logging.getLogger("quic") QuicConnectionState() at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] _handle_ack_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_connection_close_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_crypto_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_stream_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_bidi_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_uni_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_token_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_padding_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_challenge_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_response_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_reset_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None ===========unchanged ref 1=========== _handle_retire_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stop_sending_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_streams_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.connection.QuicConnection._handle_crypto_frame self.__epoch = tls.Epoch.ONE_RTT self.__epoch = tls.Epoch.HANDSHAKE at: aioquic.connection.QuicConnection._handle_max_data_frame self._remote_max_data = max_data at: aioquic.connection.QuicConnection._handle_max_streams_bidi_frame self._remote_max_streams_bidi = max_streams at: aioquic.connection.QuicConnection._handle_max_streams_uni_frame self._remote_max_streams_uni = max_streams at: aioquic.connection.QuicConnection._handle_stream_frame self._local_max_data_used += newly_received at: aioquic.connection.QuicConnection._parse_transport_parameters self._remote_idle_timeout = quic_transport_parameters.idle_timeout at: aioquic.connection.QuicConnection._send_path_challenge self.__path_challenge = os.urandom(8) at: aioquic.connection.QuicConnection._send_pending self.__send_pending_task = None at: aioquic.connection.QuicConnection._send_soon self.__send_pending_task = loop.call_soon(self._send_pending)
aioquic.connection/QuicConnection.datagram_received
Modified
aiortc~aioquic
cd8cee6eeff51543992c1a09d1d1853f97142d19
[connection] let server start tracking remote address
# module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: <0> """ <1> Handle an incoming datagram. <2> """ <3> buf = Buffer(data=data) <4> <5> # stop handling packets when closing <6> if self.__state in [QuicConnectionState.CLOSING, QuicConnectionState.DRAINING]: <7> return <8> <9> while not buf.eof(): <10> start_off = buf.tell() <11> header = pull_quic_header(buf, host_cid_length=len(self.host_cid)) <12> <13> # check destination CID matches <14> if self.is_client and header.destination_cid != self.host_cid: <15> return <16> <17> # check protocol version <18> if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION: <19> # version negotiation <20> versions = [] <21> while not buf.eof(): <22> versions.append(pull_uint32(buf)) <23> common = set(self.supported_versions).intersection(versions) <24> if not common: <25> self.__logger.error("Could not find a common protocol version") <26> return <27> self.__version = QuicProtocolVersion(max(common)) <28> self.__logger.info("Retrying with %s", self.__version) <29> self._connect() <30> return <31> elif ( <32> header.version is not None <33> and header.version not in self.supported_versions <34> ): <35> # unsupported version <36> return <37> <38> if self.is_client and header.packet_type == PACKET_TYPE_RETRY: <39> # stateless retry <40> if ( <41> header.destination_cid == self.host_cid <42> and header.original_destination_cid == self.peer_cid <43> ): <44> self.__logger.info("Performing stateless retry") <45> self.peer_cid = header.source_cid <46> self.peer_token = header.token <47> </s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 1 return # server initialization if not self.is_client and self.__state == QuicConnectionState.FIRSTFLIGHT: assert ( header.packet_type == PACKET_TYPE_INITIAL ), "first packet must be INITIAL" self.__version = QuicProtocolVersion(header.version) self._initialize(header.destination_cid) # decrypt packet encrypted_off = buf.tell() - start_off end_off = buf.tell() + header.rest_length pull_bytes(buf, header.rest_length) epoch = get_epoch(header.packet_type) space = self.spaces[epoch] if not space.crypto.recv.is_valid(): return try: plain_header, plain_payload, packet_number = space.crypto.decrypt_packet( data[start_off:end_off], encrypted_off ) except CryptoError as exc: self.__logger.warning(exc) return if not self.peer_cid_set: self.peer_cid = header.source_cid self.peer_cid_set = True # update state if self.__state == QuicConnectionState.FIRSTFLIGHT: self._set_state(QuicConnectionState.CONNECTED) # update spin bit if ( not is_long_header(plain_header[0]) and packet_number > self._spin_highest_pn ): if self.is_client: self._spin_bit = not get_spin_bit(plain_header[0]) else: self._spin_bit = get_spin_bit(plain_header[0]) self._spin_highest_pn = packet_number # handle payload try: is_ack_only = self._payload_received(epoch, plain_payload) except QuicConnectionError as exc</s> ===========below chunk 1=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 2 <s> try: is_ack_only = self._payload_received(epoch, plain_payload) except QuicConnectionError as exc: self.__logger.warning(exc) self.close( error_code=exc.error_code, frame_type=exc.frame_type, reason_phrase=exc.reason_phrase, ) return # record packet as received space.ack_queue.add(packet_number) if not is_ack_only: self.send_ack[epoch] = True self._send_pending() ===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) pull_bytes(buf: Buffer, length: int) -> bytes pull_uint32(buf: Buffer) -> int at: aioquic.buffer.Buffer eof() -> bool tell() -> int at: aioquic.connection get_epoch(packet_type: int) -> tls.Epoch QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) QuicConnectionState() at: aioquic.connection.PacketSpace.__init__ self.ack_queue = RangeSet() self.crypto = CryptoPair() at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] close(error_code: int=QuicErrorCode.NO_ERROR, frame_type: Optional[int]=None, reason_phrase: str="") -> None _connect() -> None _initialize(peer_cid: bytes) -> None _payload_received(epoch: tls.Epoch, plain: bytes) -> bool _set_state(state: QuicConnectionState) -> None at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.__logger = logger self.__peer_addr: Optional[Any] = None self._spin_bit = False self._spin_highest_pn = 0 self.__state = QuicConnectionState.FIRSTFLIGHT self.__version: Optional[int] = None ===========unchanged ref 1=========== at: aioquic.connection.QuicConnection._initialize self.send_ack = { tls.Epoch.INITIAL: False, tls.Epoch.HANDSHAKE: False, tls.Epoch.ONE_RTT: False, } self.spaces = { tls.Epoch.INITIAL: PacketSpace(), tls.Epoch.HANDSHAKE: PacketSpace(), tls.Epoch.ONE_RTT: PacketSpace(), } at: aioquic.connection.QuicConnection._set_state self.__state = state at: aioquic.connection.QuicConnection.connection_made self.__version = max(self.supported_versions) at: aioquic.connection.QuicConnectionError.__init__ self.error_code = error_code self.frame_type = frame_type self.reason_phrase = reason_phrase at: aioquic.crypto CryptoError(*args: object) at: aioquic.crypto.CryptoContext is_valid() -> bool at: aioquic.crypto.CryptoPair decrypt_packet(packet: bytes, encrypted_offset: int) -> Tuple[bytes, bytes, int] at: aioquic.crypto.CryptoPair.__init__ self.recv = CryptoContext() at: aioquic.packet PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int) QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) get_spin_bit(first_byte: int) -> bool is_long_header(first_byte: int) -> bool pull_quic_header(buf: Buffer, host_cid_length: Optional[int]=None) -> QuicHeader ===========unchanged ref 2=========== at: aioquic.packet.QuicHeader version: Optional[int] packet_type: int destination_cid: bytes source_cid: bytes original_destination_cid: bytes = b"" token: bytes = b"" rest_length: int = 0 at: aioquic.rangeset.RangeSet add(start: int, stop: Optional[int]=None) -> None at: logging.Logger info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None warning(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None error(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
aioquic.connection/QuicConnection._send_pending
Modified
aiortc~aioquic
cd8cee6eeff51543992c1a09d1d1853f97142d19
[connection] let server start tracking remote address
<1>:<add> self.__transport.sendto(datagram, self.__peer_addr) <del> self.__transport.sendto(datagram)
# module: aioquic.connection class QuicConnection: def _send_pending(self) -> None: <0> for datagram in self._pending_datagrams(): <1> self.__transport.sendto(datagram) <2> self.__send_pending_task = None <3>
===========unchanged ref 0=========== at: aioquic.connection.QuicConnection _pending_datagrams() -> Iterator[bytes] ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: """ Handle an incoming datagram. """ buf = Buffer(data=data) # stop handling packets when closing if self.__state in [QuicConnectionState.CLOSING, QuicConnectionState.DRAINING]: return while not buf.eof(): start_off = buf.tell() header = pull_quic_header(buf, host_cid_length=len(self.host_cid)) # check destination CID matches if self.is_client and header.destination_cid != self.host_cid: return # check protocol version if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION: # version negotiation versions = [] while not buf.eof(): versions.append(pull_uint32(buf)) common = set(self.supported_versions).intersection(versions) if not common: self.__logger.error("Could not find a common protocol version") return self.__version = QuicProtocolVersion(max(common)) self.__logger.info("Retrying with %s", self.__version) self._connect() return elif ( header.version is not None and header.version not in self.supported_versions ): # unsupported version return if self.is_client and header.packet_type == PACKET_TYPE_RETRY: # stateless retry if ( header.destination_cid == self.host_cid and header.original_destination_cid == self.peer_cid ): self.__logger.info("Performing stateless retry") self.peer_cid = header.source_cid self.peer_token = header.token self._connect() return # server initialization if not self.is_client and self.__state == QuicConnectionState.FIRSTFLIGHT: assert ( header.packet_type ==</s> ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 1 <s>.is_client and self.__state == QuicConnectionState.FIRSTFLIGHT: assert ( header.packet_type == PACKET_TYPE_INITIAL ), "first packet must be INITIAL" + self.__peer_addr = addr self.__version = QuicProtocolVersion(header.version) self._initialize(header.destination_cid) # decrypt packet encrypted_off = buf.tell() - start_off end_off = buf.tell() + header.rest_length pull_bytes(buf, header.rest_length) epoch = get_epoch(header.packet_type) space = self.spaces[epoch] if not space.crypto.recv.is_valid(): return try: plain_header, plain_payload, packet_number = space.crypto.decrypt_packet( data[start_off:end_off], encrypted_off ) except CryptoError as exc: self.__logger.warning(exc) return if not self.peer_cid_set: self.peer_cid = header.source_cid self.peer_cid_set = True # update state if self.__state == QuicConnectionState.FIRSTFLIGHT: self._set_state(QuicConnectionState.CONNECTED) # update spin bit if ( not is_long_header(plain_header[0]) and packet_number > self._spin_highest_pn ): if self.is_client: self._spin_bit = not get_spin_bit(plain_header[0]) else: self._spin_bit = get_spin_bit(plain_header[0]) self._spin_highest_pn = packet_number # handle payload </s> ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 2 <s> is_ack_only = self._payload_received(epoch, plain_payload) except QuicConnectionError as exc: self.__logger.warning(exc) self.close( error_code=exc.error_code, frame_type=exc.frame_type, reason_phrase=exc.reason_phrase, ) return # record packet as received space.ack_queue.add(packet_number) if not is_ack_only: self.send_ack[epoch] = True self._send_pending() ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: if not is_client: assert certificate is not None, "SSL certificate is required" assert private_key is not None, "SSL private key is required" self.alpn_protocols = alpn_protocols self.certificate = certificate self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.private_key = private_key self.secrets_log_file = secrets_log_file self.server_name = server_name self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} self.__close: Optional[Dict] = None self.__connected = asyncio.Event() self.__epoch = tls.Epoch.INITIAL self._local_idle_timeout = 60000 # milliseconds self._local_max_data = 1048576 self._local_max_data_used = 0 self._local_max_stream_data_bidi_local = 1048576 self._local_max_stream_data_bidi_remote = 1048576 self._local_max_stream_data_uni = 1048576 self._local_max_streams_bidi = 128 self._local_max_streams_uni = 128 self.__logger = logger self.__path_challenge: Optional[bytes] = None + self.__peer_addr: Optional[Any] = None self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0 # milliseconds </s>
examples.server/QuicServerProtocol.datagram_received
Modified
aiortc~aioquic
cd8cee6eeff51543992c1a09d1d1853f97142d19
[connection] let server start tracking remote address
<22>:<add> connection.connection_made(self._transport) <del> connection.connection_made(QuicConnectionTransport(self, addr))
# module: examples.server class QuicServerProtocol(asyncio.DatagramProtocol): def datagram_received(self, datagram, addr): <0> buf = Buffer(data=datagram) <1> header = pull_quic_header(buf, host_cid_length=8) <2> <3> # version negotiation <4> if ( <5> header.version is not None <6> and header.version not in QuicConnection.supported_versions <7> ): <8> self._transport.sendto( <9> encode_quic_version_negotiation( <10> source_cid=header.destination_cid, <11> destination_cid=header.source_cid, <12> supported_versions=QuicConnection.supported_versions, <13> ), <14> addr, <15> ) <16> return <17> <18> connection = self._connections.get(header.destination_cid, None) <19> if connection is None and header.packet_type == PACKET_TYPE_INITIAL: <20> # create new connection <21> connection = QuicConnection(is_client=False, **self._kwargs) <22> connection.connection_made(QuicConnectionTransport(self, addr)) <23> connection.stream_created_cb = self.stream_created <24> self._connections[connection.host_cid] = connection <25> logger.info("%s New connection from %s" % (connection_id(connection), addr)) <26> <27> if connection is not None: <28> connection.datagram_received(datagram, addr) <29>
===========unchanged ref 0=========== at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] connection_made(transport: asyncio.DatagramTransport) -> None at: aioquic.connection.QuicConnection.__init__ self.host_cid = os.urandom(8) self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None at: aioquic.packet PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 encode_quic_version_negotiation(source_cid: bytes, destination_cid: bytes, supported_versions: List[QuicProtocolVersion]) -> bytes at: aioquic.packet.QuicHeader version: Optional[int] packet_type: int destination_cid: bytes source_cid: bytes original_destination_cid: bytes = b"" token: bytes = b"" rest_length: int = 0 at: examples.server logger = logging.getLogger("server") connection_id(connection) at: examples.server.QuicServerProtocol.__init__ self._connections = {} self._kwargs = kwargs self._transport = None at: examples.server.QuicServerProtocol.connection_made self._transport = transport at: examples.server.QuicServerProtocol.datagram_received header = pull_quic_header(buf, host_cid_length=8) ===========unchanged ref 1=========== at: logging.Logger info(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: examples.server - class QuicConnectionTransport: - def sendto(self, datagram): - self.__protocol._transport.sendto(datagram, self.__addr) - ===========changed ref 1=========== # module: examples.server - class QuicConnectionTransport: - def __init__(self, protocol, addr): - self.__addr = addr - self.__protocol = protocol - ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def _send_pending(self) -> None: for datagram in self._pending_datagrams(): + self.__transport.sendto(datagram, self.__peer_addr) - self.__transport.sendto(datagram) self.__send_pending_task = None ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: if not is_client: assert certificate is not None, "SSL certificate is required" assert private_key is not None, "SSL private key is required" self.alpn_protocols = alpn_protocols self.certificate = certificate self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.private_key = private_key self.secrets_log_file = secrets_log_file self.server_name = server_name self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} self.__close: Optional[Dict] = None self.__connected = asyncio.Event() self.__epoch = tls.Epoch.INITIAL self._local_idle_timeout = 60000 # milliseconds self._local_max_data = 1048576 self._local_max_data_used = 0 self._local_max_stream_data_bidi_local = 1048576 self._local_max_stream_data_bidi_remote = 1048576 self._local_max_stream_data_uni = 1048576 self._local_max_streams_bidi = 128 self._local_max_streams_uni = 128 self.__logger = logger self.__path_challenge: Optional[bytes] = None + self.__peer_addr: Optional[Any] = None self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0 # milliseconds </s> ===========changed ref 4=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 <s> self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0 # milliseconds self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self._spin_bit = False self._spin_highest_pn = 0 self.__send_pending_task: Optional[asyncio.Handle] = None self.__state = QuicConnectionState.FIRSTFLIGHT self.__transport: Optional[asyncio.DatagramTransport] = None self.__version: Optional[int] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_</s>
tests.test_connection/QuicConnectionTest.test_datagram_received_wrong_destination_cid
Modified
aiortc~aioquic
81fe4de9b78ffdb3bc483884ce63422fcda585d2
[connection] refactor tests
<0>:<del> client = QuicConnection(is_client=True) <1>:<del> client_transport = FakeTransport() <2>:<del> client.connection_made(client_transport) <3>:<add> client, client_transport = create_standalone_client()
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_datagram_received_wrong_destination_cid(self): <0> client = QuicConnection(is_client=True) <1> client_transport = FakeTransport() <2> client.connection_made(client_transport) <3> self.assertEqual(client_transport.sent, 1) <4> <5> client.datagram_received(load("retry.bin"), None) <6> self.assertEqual(client_transport.sent, 1) <7>
===========unchanged ref 0=========== at: tests.test_connection create_transport(client, server) at: tests.test_connection.FakeTransport.sendto self.sent += 1 at: tests.test_connection.QuicConnectionTest.test_tls_error client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_connection + def create_standalone_client(): + client = QuicConnection(is_client=True) + client_transport = FakeTransport() + client.connection_made(client_transport) + return client, client_transport +
tests.test_connection/QuicConnectionTest.test_datagram_received_wrong_version
Modified
aiortc~aioquic
81fe4de9b78ffdb3bc483884ce63422fcda585d2
[connection] refactor tests
<0>:<del> client = QuicConnection(is_client=True) <1>:<del> client_transport = FakeTransport() <2>:<del> client.connection_made(client_transport) <3>:<add> client, client_transport = create_standalone_client()
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_datagram_received_wrong_version(self): <0> client = QuicConnection(is_client=True) <1> client_transport = FakeTransport() <2> client.connection_made(client_transport) <3> self.assertEqual(client_transport.sent, 1) <4> <5> buf = Buffer(capacity=1300) <6> push_quic_header( <7> buf, <8> QuicHeader( <9> version=0xFF000011, # DRAFT_16 <10> packet_type=PACKET_TYPE_INITIAL | (PACKET_NUMBER_SEND_SIZE - 1), <11> destination_cid=client.host_cid, <12> source_cid=client.peer_cid, <13> ), <14> ) <15> buf.seek(1300) <16> client.datagram_received(buf.data, None) <17> self.assertEqual(client_transport.sent, 1) <18>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] datagram_received(data: bytes, addr: Any) -> None at: aioquic.connection.QuicConnection.__init__ self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) at: aioquic.connection.QuicConnection.datagram_received self.peer_cid = header.source_cid at: aioquic.packet PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_NUMBER_SEND_SIZE = 2 QuicHeader(version: Optional[int], packet_type: int, destination_cid: bytes, source_cid: bytes, original_destination_cid: bytes=b"", token: bytes=b"", rest_length: int=0) push_quic_header(buf: Buffer, header: QuicHeader) -> None at: aioquic.packet.QuicHeader version: Optional[int] packet_type: int destination_cid: bytes source_cid: bytes original_destination_cid: bytes = b"" token: bytes = b"" rest_length: int = 0 at: tests.test_connection create_standalone_client() at: tests.test_connection.FakeTransport.sendto self.sent += 1 at: tests.test_connection.QuicConnectionTest.test_datagram_received_wrong_destination_cid client, client_transport = create_standalone_client() client, client_transport = create_standalone_client() at: tests.utils load(name) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_connection + def create_standalone_client(): + client = QuicConnection(is_client=True) + client_transport = FakeTransport() + client.connection_made(client_transport) + return client, client_transport + ===========changed ref 1=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_datagram_received_wrong_destination_cid(self): - client = QuicConnection(is_client=True) - client_transport = FakeTransport() - client.connection_made(client_transport) + client, client_transport = create_standalone_client() self.assertEqual(client_transport.sent, 1) client.datagram_received(load("retry.bin"), None) self.assertEqual(client_transport.sent, 1)
tests.test_connection/QuicConnectionTest.test_version_negotiation_fail
Modified
aiortc~aioquic
81fe4de9b78ffdb3bc483884ce63422fcda585d2
[connection] refactor tests
<0>:<del> client = QuicConnection(is_client=True) <1>:<del> <2>:<del> client_transport = FakeTransport() <3>:<del> client.connection_made(client_transport) <4>:<add> client, client_transport = create_standalone_client()
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_version_negotiation_fail(self): <0> client = QuicConnection(is_client=True) <1> <2> client_transport = FakeTransport() <3> client.connection_made(client_transport) <4> self.assertEqual(client_transport.sent, 1) <5> <6> # no common version, no retry <7> client.datagram_received( <8> encode_quic_version_negotiation( <9> source_cid=client.peer_cid, <10> destination_cid=client.host_cid, <11> supported_versions=[0xFF000011], # DRAFT_16 <12> ), <13> None, <14> ) <15> self.assertEqual(client_transport.sent, 1) <16>
===========unchanged ref 0=========== at: aioquic.connection.QuicConnection _stream_can_receive(stream_id: int) -> bool _stream_can_send(stream_id: int) -> bool at: aioquic.packet encode_quic_version_negotiation(source_cid: bytes, destination_cid: bytes, supported_versions: List[QuicProtocolVersion]) -> bytes at: tests.test_connection create_standalone_client() at: tests.test_connection.QuicConnectionTest.test_stream_direction server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None assertTrue(expr: Any, msg: Any=...) -> None assertFalse(expr: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_connection + def create_standalone_client(): + client = QuicConnection(is_client=True) + client_transport = FakeTransport() + client.connection_made(client_transport) + return client, client_transport + ===========changed ref 1=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_datagram_received_wrong_destination_cid(self): - client = QuicConnection(is_client=True) - client_transport = FakeTransport() - client.connection_made(client_transport) + client, client_transport = create_standalone_client() self.assertEqual(client_transport.sent, 1) client.datagram_received(load("retry.bin"), None) self.assertEqual(client_transport.sent, 1) ===========changed ref 2=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_datagram_received_wrong_version(self): - client = QuicConnection(is_client=True) - client_transport = FakeTransport() - client.connection_made(client_transport) + client, client_transport = create_standalone_client() self.assertEqual(client_transport.sent, 1) buf = Buffer(capacity=1300) push_quic_header( buf, QuicHeader( version=0xFF000011, # DRAFT_16 packet_type=PACKET_TYPE_INITIAL | (PACKET_NUMBER_SEND_SIZE - 1), destination_cid=client.host_cid, source_cid=client.peer_cid, ), ) buf.seek(1300) client.datagram_received(buf.data, None) self.assertEqual(client_transport.sent, 1)
tests.test_connection/QuicConnectionTest.test_version_negotiation_ok
Modified
aiortc~aioquic
81fe4de9b78ffdb3bc483884ce63422fcda585d2
[connection] refactor tests
<0>:<del> client = QuicConnection(is_client=True) <1>:<del> <2>:<del> client_transport = FakeTransport() <3>:<del> client.connection_made(client_transport) <4>:<add> client, client_transport = create_standalone_client()
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_version_negotiation_ok(self): <0> client = QuicConnection(is_client=True) <1> <2> client_transport = FakeTransport() <3> client.connection_made(client_transport) <4> self.assertEqual(client_transport.sent, 1) <5> <6> # found a common version, retry <7> client.datagram_received( <8> encode_quic_version_negotiation( <9> source_cid=client.peer_cid, <10> destination_cid=client.host_cid, <11> supported_versions=[QuicProtocolVersion.DRAFT_19], <12> ), <13> None, <14> ) <15> self.assertEqual(client_transport.sent, 2) <16>
===========unchanged ref 0=========== at: aioquic.packet QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int) QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) encode_quic_version_negotiation(source_cid: bytes, destination_cid: bytes, supported_versions: List[QuicProtocolVersion]) -> bytes at: tests.test_connection create_standalone_client() at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_connection + def create_standalone_client(): + client = QuicConnection(is_client=True) + client_transport = FakeTransport() + client.connection_made(client_transport) + return client, client_transport + ===========changed ref 1=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_version_negotiation_fail(self): - client = QuicConnection(is_client=True) - - client_transport = FakeTransport() - client.connection_made(client_transport) + client, client_transport = create_standalone_client() self.assertEqual(client_transport.sent, 1) # no common version, no retry client.datagram_received( encode_quic_version_negotiation( source_cid=client.peer_cid, destination_cid=client.host_cid, supported_versions=[0xFF000011], # DRAFT_16 ), None, ) self.assertEqual(client_transport.sent, 1) ===========changed ref 2=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_datagram_received_wrong_destination_cid(self): - client = QuicConnection(is_client=True) - client_transport = FakeTransport() - client.connection_made(client_transport) + client, client_transport = create_standalone_client() self.assertEqual(client_transport.sent, 1) client.datagram_received(load("retry.bin"), None) self.assertEqual(client_transport.sent, 1) ===========changed ref 3=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_datagram_received_wrong_version(self): - client = QuicConnection(is_client=True) - client_transport = FakeTransport() - client.connection_made(client_transport) + client, client_transport = create_standalone_client() self.assertEqual(client_transport.sent, 1) buf = Buffer(capacity=1300) push_quic_header( buf, QuicHeader( version=0xFF000011, # DRAFT_16 packet_type=PACKET_TYPE_INITIAL | (PACKET_NUMBER_SEND_SIZE - 1), destination_cid=client.host_cid, source_cid=client.peer_cid, ), ) buf.seek(1300) client.datagram_received(buf.data, None) self.assertEqual(client_transport.sent, 1)
aioquic.connection/QuicConnection.__init__
Modified
aiortc~aioquic
42589df9071642ee0dadef02e872ee1143959b44
[connection] make peer_addr and version accessible for tests
<29>:<add> self._peer_addr: Optional[Any] = None <del> self.__peer_addr: Optional[Any] = None
# module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: <0> if not is_client: <1> assert certificate is not None, "SSL certificate is required" <2> assert private_key is not None, "SSL private key is required" <3> <4> self.alpn_protocols = alpn_protocols <5> self.certificate = certificate <6> self.is_client = is_client <7> self.host_cid = os.urandom(8) <8> self.peer_cid = os.urandom(8) <9> self.peer_cid_set = False <10> self.peer_token = b"" <11> self.private_key = private_key <12> self.secrets_log_file = secrets_log_file <13> self.server_name = server_name <14> self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} <15> <16> self.__close: Optional[Dict] = None <17> self.__connected = asyncio.Event() <18> self.__epoch = tls.Epoch.INITIAL <19> self._local_idle_timeout = 60000 # milliseconds <20> self._local_max_data = 1048576 <21> self._local_max_data_used = 0 <22> self._local_max_stream_data_bidi_local = 1048576 <23> self._local_max_stream_data_bidi_remote = 1048576 <24> self._local_max_stream_data_uni = 1048576 <25> self._local_max_streams_bidi = 128 <26> self._local_max_streams_uni = 128 <27> self.__logger = logger <28> self.__path_challenge: Optional[bytes] = None <29> self.__peer_addr: Optional[Any] = None <30> </s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 self._remote_idle_timeout = 0 # milliseconds self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self._spin_bit = False self._spin_highest_pn = 0 self.__send_pending_task: Optional[asyncio.Handle] = None self.__state = QuicConnectionState.FIRSTFLIGHT self.__transport: Optional[asyncio.DatagramTransport] = None self.__version: Optional[int] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle</s> ===========below chunk 1=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s>_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ] ===========unchanged ref 0=========== at: aioquic.connection logger = logging.getLogger("quic") QuicConnectionState() at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] _handle_ack_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_connection_close_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_crypto_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_stream_data_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_bidi_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_max_streams_uni_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_new_token_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_padding_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_challenge_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_path_response_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_reset_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None ===========unchanged ref 1=========== _handle_retire_connection_id_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stop_sending_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_stream_data_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None _handle_streams_blocked_frame(epoch: tls.Epoch, frame_type: int, buf: Buffer) -> None at: aioquic.connection.QuicConnection._handle_crypto_frame self.__epoch = tls.Epoch.ONE_RTT self.__epoch = tls.Epoch.HANDSHAKE at: aioquic.connection.QuicConnection._handle_max_data_frame self._remote_max_data = max_data at: aioquic.connection.QuicConnection._handle_max_streams_bidi_frame self._remote_max_streams_bidi = max_streams at: aioquic.connection.QuicConnection._handle_max_streams_uni_frame self._remote_max_streams_uni = max_streams at: aioquic.connection.QuicConnection._handle_stream_frame self._local_max_data_used += newly_received at: aioquic.connection.QuicConnection._parse_transport_parameters self._remote_idle_timeout = quic_transport_parameters.idle_timeout at: aioquic.connection.QuicConnection._send_path_challenge self.__path_challenge = os.urandom(8) at: aioquic.connection.QuicConnection._send_pending self.__send_pending_task = None at: aioquic.connection.QuicConnection._send_soon self.__send_pending_task = loop.call_soon(self._send_pending)
aioquic.connection/QuicConnection.connection_made
Modified
aiortc~aioquic
42589df9071642ee0dadef02e872ee1143959b44
[connection] make peer_addr and version accessible for tests
<8>:<add> self._version = max(self.supported_versions) <del> self.__version = max(self.supported_versions)
# module: aioquic.connection class QuicConnection: def connection_made(self, transport: asyncio.DatagramTransport) -> None: <0> """ <1> Inform the connection of the transport used to send data. This object <2> must have a ``sendto`` method which accepts a datagram to send. <3> <4> Calling :meth:`connection_made` on a client starts the TLS handshake. <5> """ <6> self.__transport = transport <7> if self.is_client: <8> self.__version = max(self.supported_versions) <9> self._connect() <10>
===========unchanged ref 0=========== at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] _connect() -> None at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.__transport: Optional[asyncio.DatagramTransport] = None self._version: Optional[int] = None at: aioquic.connection.QuicConnection.datagram_received self._version = QuicProtocolVersion(header.version) self._version = QuicProtocolVersion(max(common)) at: asyncio.transports DatagramTransport(extra: Optional[Mapping[Any, Any]]=...) ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: if not is_client: assert certificate is not None, "SSL certificate is required" assert private_key is not None, "SSL private key is required" self.alpn_protocols = alpn_protocols self.certificate = certificate self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.private_key = private_key self.secrets_log_file = secrets_log_file self.server_name = server_name self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} self.__close: Optional[Dict] = None self.__connected = asyncio.Event() self.__epoch = tls.Epoch.INITIAL self._local_idle_timeout = 60000 # milliseconds self._local_max_data = 1048576 self._local_max_data_used = 0 self._local_max_stream_data_bidi_local = 1048576 self._local_max_stream_data_bidi_remote = 1048576 self._local_max_stream_data_uni = 1048576 self._local_max_streams_bidi = 128 self._local_max_streams_uni = 128 self.__logger = logger self.__path_challenge: Optional[bytes] = None + self._peer_addr: Optional[Any] = None - self.__peer_addr: Optional[Any] = None self._pending_flow_control: List[bytes] = []</s> ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 1 <s> <del> self.__peer_addr: Optional[Any] = None self._pending_flow_control: List[bytes] = [] self._remote_idle_timeout = 0 # milliseconds self._remote_max_data = 0 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 self._remote_max_streams_uni = 0 self._spin_bit = False self._spin_highest_pn = 0 self.__send_pending_task: Optional[asyncio.Handle] = None self.__state = QuicConnectionState.FIRSTFLIGHT self.__transport: Optional[asyncio.DatagramTransport] = None + self._version: Optional[int] = None - self.__version: Optional[int] = None # callbacks self.stream_created_cb: Callable[ [asyncio.StreamReader, asyncio.StreamWriter], None ] = lambda r, w: None # frame handlers self.__frame_handlers = [ self._handle_padding_frame, self._handle_padding_frame, self._handle_ack_frame, self._handle_ack_frame, self._handle_reset_stream_frame, self._handle_stop_sending_frame, self._handle_crypto_frame, self._handle_new_token</s> ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def __init__( self, is_client: bool = True, certificate: Any = None, private_key: Any = None, secrets_log_file: TextIO = None, alpn_protocols: Optional[List[str]] = None, server_name: Optional[str] = None, ) -> None: # offset: 2 <s>, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_stream_frame, self._handle_max_data_frame, self._handle_max_stream_data_frame, self._handle_max_streams_bidi_frame, self._handle_max_streams_uni_frame, self._handle_data_blocked_frame, self._handle_stream_data_blocked_frame, self._handle_streams_blocked_frame, self._handle_streams_blocked_frame, self._handle_new_connection_id_frame, self._handle_retire_connection_id_frame, self._handle_path_challenge_frame, self._handle_path_response_frame, self._handle_connection_close_frame, self._handle_connection_close_frame, ]
aioquic.connection/QuicConnection.datagram_received
Modified
aiortc~aioquic
42589df9071642ee0dadef02e872ee1143959b44
[connection] make peer_addr and version accessible for tests
<27>:<add> self._version = QuicProtocolVersion(max(common)) <del> self.__version = QuicProtocolVersion(max(common)) <28>:<add> self.__logger.info("Retrying with %s", self._version) <del> self.__logger.info("Retrying with %s", self.__version)
# module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: <0> """ <1> Handle an incoming datagram. <2> """ <3> buf = Buffer(data=data) <4> <5> # stop handling packets when closing <6> if self.__state in [QuicConnectionState.CLOSING, QuicConnectionState.DRAINING]: <7> return <8> <9> while not buf.eof(): <10> start_off = buf.tell() <11> header = pull_quic_header(buf, host_cid_length=len(self.host_cid)) <12> <13> # check destination CID matches <14> if self.is_client and header.destination_cid != self.host_cid: <15> return <16> <17> # check protocol version <18> if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION: <19> # version negotiation <20> versions = [] <21> while not buf.eof(): <22> versions.append(pull_uint32(buf)) <23> common = set(self.supported_versions).intersection(versions) <24> if not common: <25> self.__logger.error("Could not find a common protocol version") <26> return <27> self.__version = QuicProtocolVersion(max(common)) <28> self.__logger.info("Retrying with %s", self.__version) <29> self._connect() <30> return <31> elif ( <32> header.version is not None <33> and header.version not in self.supported_versions <34> ): <35> # unsupported version <36> return <37> <38> if self.is_client and header.packet_type == PACKET_TYPE_RETRY: <39> # stateless retry <40> if ( <41> header.destination_cid == self.host_cid <42> and header.original_destination_cid == self.peer_cid <43> ): <44> self.__logger.info("Performing stateless retry") <45> self.peer_cid = header.source_cid <46> self.peer_token = header.token <47> </s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 1 return # server initialization if not self.is_client and self.__state == QuicConnectionState.FIRSTFLIGHT: assert ( header.packet_type == PACKET_TYPE_INITIAL ), "first packet must be INITIAL" self.__peer_addr = addr self.__version = QuicProtocolVersion(header.version) self._initialize(header.destination_cid) # decrypt packet encrypted_off = buf.tell() - start_off end_off = buf.tell() + header.rest_length pull_bytes(buf, header.rest_length) epoch = get_epoch(header.packet_type) space = self.spaces[epoch] if not space.crypto.recv.is_valid(): return try: plain_header, plain_payload, packet_number = space.crypto.decrypt_packet( data[start_off:end_off], encrypted_off ) except CryptoError as exc: self.__logger.warning(exc) return if not self.peer_cid_set: self.peer_cid = header.source_cid self.peer_cid_set = True # update state if self.__state == QuicConnectionState.FIRSTFLIGHT: self._set_state(QuicConnectionState.CONNECTED) # update spin bit if ( not is_long_header(plain_header[0]) and packet_number > self._spin_highest_pn ): if self.is_client: self._spin_bit = not get_spin_bit(plain_header[0]) else: self._spin_bit = get_spin_bit(plain_header[0]) self._spin_highest_pn = packet_number # handle payload try: is_ack_only = self._payload_received(epoch, plain_payload</s> ===========below chunk 1=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 2 <s>number # handle payload try: is_ack_only = self._payload_received(epoch, plain_payload) except QuicConnectionError as exc: self.__logger.warning(exc) self.close( error_code=exc.error_code, frame_type=exc.frame_type, reason_phrase=exc.reason_phrase, ) return # record packet as received space.ack_queue.add(packet_number) if not is_ack_only: self.send_ack[epoch] = True self._send_pending() ===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) pull_bytes(buf: Buffer, length: int) -> bytes pull_uint32(buf: Buffer) -> int at: aioquic.buffer.Buffer eof() -> bool tell() -> int at: aioquic.connection get_epoch(packet_type: int) -> tls.Epoch QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) QuicConnectionState() at: aioquic.connection.PacketSpace.__init__ self.ack_queue = RangeSet() self.crypto = CryptoPair() at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] close(error_code: int=QuicErrorCode.NO_ERROR, frame_type: Optional[int]=None, reason_phrase: str="") -> None _connect() -> None _initialize(peer_cid: bytes) -> None _payload_received(epoch: tls.Epoch, plain: bytes) -> bool _send_pending(self) -> None _send_pending() -> None _set_state(state: QuicConnectionState) -> None at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_cid_set = False self.peer_token = b"" self.__logger = logger self._peer_addr: Optional[Any] = None self._spin_bit = False self._spin_highest_pn = 0 self.__state = QuicConnectionState.FIRSTFLIGHT self._version: Optional[int] = None ===========unchanged ref 1=========== at: aioquic.connection.QuicConnection._initialize self.send_ack = { tls.Epoch.INITIAL: False, tls.Epoch.HANDSHAKE: False, tls.Epoch.ONE_RTT: False, } self.spaces = { tls.Epoch.INITIAL: PacketSpace(), tls.Epoch.HANDSHAKE: PacketSpace(), tls.Epoch.ONE_RTT: PacketSpace(), } at: aioquic.connection.QuicConnection._set_state self.__state = state at: aioquic.connection.QuicConnection.connection_made self._version = max(self.supported_versions) at: aioquic.connection.QuicConnectionError.__init__ self.error_code = error_code self.frame_type = frame_type self.reason_phrase = reason_phrase at: aioquic.crypto CryptoError(*args: object) at: aioquic.crypto.CryptoContext is_valid() -> bool at: aioquic.crypto.CryptoPair decrypt_packet(packet: bytes, encrypted_offset: int) -> Tuple[bytes, bytes, int] at: aioquic.crypto.CryptoPair.__init__ self.recv = CryptoContext() at: aioquic.packet PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30 QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int) QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) get_spin_bit(first_byte: int) -> bool is_long_header(first_byte: int) -> bool pull_quic_header(buf: Buffer, host_cid_length: Optional[int]=None) -> QuicHeader ===========unchanged ref 2=========== at: aioquic.packet.QuicHeader version: Optional[int] packet_type: int destination_cid: bytes source_cid: bytes original_destination_cid: bytes = b"" token: bytes = b"" rest_length: int = 0 at: aioquic.rangeset.RangeSet add(start: int, stop: Optional[int]=None) -> None at: logging.Logger info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None warning(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None error(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
aioquic.connection/QuicConnection._send_pending
Modified
aiortc~aioquic
42589df9071642ee0dadef02e872ee1143959b44
[connection] make peer_addr and version accessible for tests
<1>:<add> self.__transport.sendto(datagram, self._peer_addr) <del> self.__transport.sendto(datagram, self.__peer_addr)
# module: aioquic.connection class QuicConnection: def _send_pending(self) -> None: <0> for datagram in self._pending_datagrams(): <1> self.__transport.sendto(datagram, self.__peer_addr) <2> self.__send_pending_task = None <3>
===========unchanged ref 0=========== at: aioquic.connection.QuicConnection _pending_datagrams() -> Iterator[bytes] at: aioquic.connection.QuicConnection.__init__ self._peer_addr: Optional[Any] = None self.__send_pending_task: Optional[asyncio.Handle] = None self.__transport: Optional[asyncio.DatagramTransport] = None at: aioquic.connection.QuicConnection._send_soon self.__send_pending_task = loop.call_soon(self._send_pending) at: aioquic.connection.QuicConnection.connection_made self.__transport = transport at: aioquic.connection.QuicConnection.datagram_received self._peer_addr = addr at: asyncio.transports.DatagramTransport __slots__ = () sendto(data: Any, addr: Optional[_Address]=...) -> None ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def connection_made(self, transport: asyncio.DatagramTransport) -> None: """ Inform the connection of the transport used to send data. This object must have a ``sendto`` method which accepts a datagram to send. Calling :meth:`connection_made` on a client starts the TLS handshake. """ self.__transport = transport if self.is_client: + self._version = max(self.supported_versions) - self.__version = max(self.supported_versions) self._connect() ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: """ Handle an incoming datagram. """ buf = Buffer(data=data) # stop handling packets when closing if self.__state in [QuicConnectionState.CLOSING, QuicConnectionState.DRAINING]: return while not buf.eof(): start_off = buf.tell() header = pull_quic_header(buf, host_cid_length=len(self.host_cid)) # check destination CID matches if self.is_client and header.destination_cid != self.host_cid: return # check protocol version if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION: # version negotiation versions = [] while not buf.eof(): versions.append(pull_uint32(buf)) common = set(self.supported_versions).intersection(versions) if not common: self.__logger.error("Could not find a common protocol version") return + self._version = QuicProtocolVersion(max(common)) - self.__version = QuicProtocolVersion(max(common)) + self.__logger.info("Retrying with %s", self._version) - self.__logger.info("Retrying with %s", self.__version) self._connect() return elif ( header.version is not None and header.version not in self.supported_versions ): # unsupported version return if self.is_client and header.packet_type == PACKET_TYPE_RETRY: # stateless retry if ( header.destination_cid == self.host_cid and header.original_destination_cid == self.peer_cid ): self.__logger.info("Performing stateless retry") self.peer_cid = header.source_cid self.peer_token = header.token self._connect() return # server</s> ===========changed ref 2=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 1 <s> header.source_cid self.peer_token = header.token self._connect() return # server initialization if not self.is_client and self.__state == QuicConnectionState.FIRSTFLIGHT: assert ( header.packet_type == PACKET_TYPE_INITIAL ), "first packet must be INITIAL" + self._peer_addr = addr - self.__peer_addr = addr + self._version = QuicProtocolVersion(header.version) - self.__version = QuicProtocolVersion(header.version) self._initialize(header.destination_cid) # decrypt packet encrypted_off = buf.tell() - start_off end_off = buf.tell() + header.rest_length pull_bytes(buf, header.rest_length) epoch = get_epoch(header.packet_type) space = self.spaces[epoch] if not space.crypto.recv.is_valid(): return try: plain_header, plain_payload, packet_number = space.crypto.decrypt_packet( data[start_off:end_off], encrypted_off ) except CryptoError as exc: self.__logger.warning(exc) return if not self.peer_cid_set: self.peer_cid = header.source_cid self.peer_cid_set = True # update state if self.__state == QuicConnectionState.FIRSTFLIGHT: self._set_state(QuicConnectionState.CONNECTED) # update spin bit if ( not is_long_header(plain_header[0]) and packet_number > self._spin_highest_pn ): if self.is_client: self._spin</s> ===========changed ref 3=========== # module: aioquic.connection class QuicConnection: def datagram_received(self, data: bytes, addr: Any) -> None: # offset: 2 <s> = not get_spin_bit(plain_header[0]) else: self._spin_bit = get_spin_bit(plain_header[0]) self._spin_highest_pn = packet_number # handle payload try: is_ack_only = self._payload_received(epoch, plain_payload) except QuicConnectionError as exc: self.__logger.warning(exc) self.close( error_code=exc.error_code, frame_type=exc.frame_type, reason_phrase=exc.reason_phrase, ) return # record packet as received space.ack_queue.add(packet_number) if not is_ack_only: self.send_ack[epoch] = True self._send_pending()
aioquic.connection/QuicConnection._write_handshake
Modified
aiortc~aioquic
42589df9071642ee0dadef02e872ee1143959b44
[connection] make peer_addr and version accessible for tests
<16>:<add> version=self._version, <del> version=self.__version,
# module: aioquic.connection class QuicConnection: def _write_handshake(self, epoch: tls.Epoch) -> Iterator[bytes]: <0> space = self.spaces[epoch] <1> if not space.crypto.send.is_valid(): <2> return <3> <4> buf = Buffer(capacity=PACKET_MAX_SIZE) <5> <6> while True: <7> if epoch == tls.Epoch.INITIAL: <8> packet_type = PACKET_TYPE_INITIAL <9> else: <10> packet_type = PACKET_TYPE_HANDSHAKE <11> <12> # write header <13> push_quic_header( <14> buf, <15> QuicHeader( <16> version=self.__version, <17> packet_type=packet_type | (PACKET_NUMBER_SEND_SIZE - 1), <18> destination_cid=self.peer_cid, <19> source_cid=self.host_cid, <20> token=self.peer_token, <21> ), <22> ) <23> header_size = buf.tell() <24> <25> # ACK <26> if self.send_ack[epoch] and space.ack_queue: <27> push_uint_var(buf, QuicFrameType.ACK) <28> packet.push_ack_frame(buf, space.ack_queue, 0) <29> self.send_ack[epoch] = False <30> <31> # CLOSE <32> if self.__close and self.__epoch == epoch: <33> push_close(buf, **self.__close) <34> self.__close = None <35> <36> stream = self.streams[epoch] <37> if stream.has_data_to_send(): <38> # CRYPTO <39> frame = stream.get_frame( <40> PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 4 <41> ) <42> push_uint_var(buf, QuicFrameType.CRYPTO) <43> with packet.push_crypto_frame(buf, frame.offset): <44> push_bytes(buf, frame.data) <45> <46> # P</s>
===========below chunk 0=========== # module: aioquic.connection class QuicConnection: def _write_handshake(self, epoch: tls.Epoch) -> Iterator[bytes]: # offset: 1 if epoch == tls.Epoch.INITIAL and self.is_client: push_bytes( buf, bytes( PACKET_MAX_SIZE - space.crypto.aead_tag_size - buf.tell() ), ) packet_size = buf.tell() if packet_size > header_size: # finalize length buf.seek(header_size - PACKET_NUMBER_SEND_SIZE - 2) length = packet_size - header_size + 2 + space.crypto.aead_tag_size push_uint16(buf, length | 0x4000) push_uint16(buf, self.packet_number) buf.seek(packet_size) # encrypt data = buf.data yield space.crypto.encrypt_packet( data[0:header_size], data[header_size:packet_size] ) self.packet_number += 1 buf.seek(0) else: break ===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) push_bytes(buf: Buffer, v: bytes) -> None push_uint16(buf: Buffer, v: int) -> None at: aioquic.buffer.Buffer seek(pos: int) -> None tell() -> int at: aioquic.connection PACKET_MAX_SIZE = 1280 push_close(buf: Buffer, error_code: int, frame_type: Optional[int], reason_phrase: str) -> None at: aioquic.connection.PacketSpace.__init__ self.ack_queue = RangeSet() self.crypto = CryptoPair() at: aioquic.connection.QuicConnection.__init__ self.is_client = is_client self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) self.peer_token = b"" self.streams: Dict[Union[tls.Epoch, int], QuicStream] = {} self.__close: Optional[Dict] = None self.__epoch = tls.Epoch.INITIAL self._version: Optional[int] = None at: aioquic.connection.QuicConnection._handle_crypto_frame self.__epoch = tls.Epoch.ONE_RTT self.__epoch = tls.Epoch.HANDSHAKE at: aioquic.connection.QuicConnection._initialize self.send_ack = { tls.Epoch.INITIAL: False, tls.Epoch.HANDSHAKE: False, tls.Epoch.ONE_RTT: False, } self.spaces = { tls.Epoch.INITIAL: PacketSpace(), tls.Epoch.HANDSHAKE: PacketSpace(), tls.Epoch.ONE_RTT: PacketSpace(), } self.packet_number = 0 at: aioquic.connection.QuicConnection._write_application self.__close = None ===========unchanged ref 1=========== self.packet_number += 1 at: aioquic.connection.QuicConnection.close self.__close = { "error_code": error_code, "frame_type": frame_type, "reason_phrase": reason_phrase, } at: aioquic.connection.QuicConnection.connection_made self._version = max(self.supported_versions) at: aioquic.connection.QuicConnection.datagram_received self._version = QuicProtocolVersion(header.version) self._version = QuicProtocolVersion(max(common)) self.peer_cid = header.source_cid self.peer_token = header.token at: aioquic.crypto.CryptoContext is_valid() -> bool at: aioquic.crypto.CryptoPair encrypt_packet(plain_header: bytes, plain_payload: bytes) -> bytes at: aioquic.crypto.CryptoPair.__init__ self.aead_tag_size = 16 self.send = CryptoContext() at: aioquic.packet PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20 PACKET_NUMBER_SEND_SIZE = 2 QuicHeader(version: Optional[int], packet_type: int, destination_cid: bytes, source_cid: bytes, original_destination_cid: bytes=b"", token: bytes=b"", rest_length: int=0) push_uint_var(buf: Buffer, value: int) -> None push_quic_header(buf: Buffer, header: QuicHeader) -> None QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) push_ack_frame(buf: Buffer, rangeset: RangeSet, delay: int) -> None ===========unchanged ref 2=========== push_crypto_frame(buf: Buffer, offset: int=0) -> Generator at: aioquic.packet.QuicStreamFrame data: bytes = b"" fin: bool = False offset: int = 0 at: aioquic.stream.QuicStream get_frame(size: int) -> QuicStreamFrame has_data_to_send() -> bool at: aioquic.tls Epoch() at: typing Iterator = _alias(collections.abc.Iterator, 1) ===========changed ref 0=========== # module: aioquic.connection class QuicConnection: def _send_pending(self) -> None: for datagram in self._pending_datagrams(): + self.__transport.sendto(datagram, self._peer_addr) - self.__transport.sendto(datagram, self.__peer_addr) self.__send_pending_task = None ===========changed ref 1=========== # module: aioquic.connection class QuicConnection: def connection_made(self, transport: asyncio.DatagramTransport) -> None: """ Inform the connection of the transport used to send data. This object must have a ``sendto`` method which accepts a datagram to send. Calling :meth:`connection_made` on a client starts the TLS handshake. """ self.__transport = transport if self.is_client: + self._version = max(self.supported_versions) - self.__version = max(self.supported_versions) self._connect()
tests.test_connection/FakeTransport.sendto
Modified
aiortc~aioquic
4c66db2e0a051d0da6b94285851bd35ece9c01d7
[tests] generate retry packet ourselves
<2>:<add> self.target.datagram_received(data, self.local_addr) <del> self.target.datagram_received(data, None)
# module: tests.test_connection class FakeTransport: def sendto(self, data, addr): <0> self.sent += 1 <1> if self.target is not None: <2> self.target.datagram_received(data, None) <3>
===========changed ref 0=========== # module: tests.test_connection + CLIENT_ADDR = None + + SERVER_ADDR = None SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) ===========changed ref 1=========== # module: aioquic.packet + def encode_quic_retry( + version: QuicProtocolVersion, + source_cid: bytes, + destination_cid: bytes, + original_destination_cid: bytes, + retry_token: bytes, + ) -> bytes: + buf = Buffer(capacity=100) + push_uint8( + buf, PACKET_TYPE_RETRY | encode_cid_length(len(original_destination_cid)) + ) + push_uint32(buf, version) + push_uint8( + buf, + (encode_cid_length(len(destination_cid)) << 4) + | encode_cid_length(len(source_cid)), + ) + push_bytes(buf, destination_cid) + push_bytes(buf, source_cid) + push_bytes(buf, original_destination_cid) + push_bytes(buf, retry_token) + return buf.data +
tests.test_connection/create_standalone_client
Modified
aiortc~aioquic
4c66db2e0a051d0da6b94285851bd35ece9c01d7
[tests] generate retry packet ourselves
<1>:<add> client_transport = FakeTransport(CLIENT_ADDR) <del> client_transport = FakeTransport()
# module: tests.test_connection def create_standalone_client(): <0> client = QuicConnection(is_client=True) <1> client_transport = FakeTransport() <2> client.connection_made(client_transport) <3> return client, client_transport <4>
===========unchanged ref 0=========== at: tests.test_connection.FakeTransport target = None at: tests.test_connection.FakeTransport.__init__ self.local_addr = local_addr ===========changed ref 0=========== # module: tests.test_connection class FakeTransport: + def __init__(self, local_addr): + self.local_addr = local_addr + ===========changed ref 1=========== # module: tests.test_connection class FakeTransport: def sendto(self, data, addr): self.sent += 1 if self.target is not None: + self.target.datagram_received(data, self.local_addr) - self.target.datagram_received(data, None) ===========changed ref 2=========== # module: tests.test_connection + CLIENT_ADDR = None + + SERVER_ADDR = None SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) ===========changed ref 3=========== # module: aioquic.packet + def encode_quic_retry( + version: QuicProtocolVersion, + source_cid: bytes, + destination_cid: bytes, + original_destination_cid: bytes, + retry_token: bytes, + ) -> bytes: + buf = Buffer(capacity=100) + push_uint8( + buf, PACKET_TYPE_RETRY | encode_cid_length(len(original_destination_cid)) + ) + push_uint32(buf, version) + push_uint8( + buf, + (encode_cid_length(len(destination_cid)) << 4) + | encode_cid_length(len(source_cid)), + ) + push_bytes(buf, destination_cid) + push_bytes(buf, source_cid) + push_bytes(buf, original_destination_cid) + push_bytes(buf, retry_token) + return buf.data +
tests.test_connection/create_transport
Modified
aiortc~aioquic
4c66db2e0a051d0da6b94285851bd35ece9c01d7
[tests] generate retry packet ourselves
<0>:<add> client_transport = FakeTransport(CLIENT_ADDR) <del> client_transport = FakeTransport() <3>:<add> server_transport = FakeTransport(SERVER_ADDR) <del> server_transport = FakeTransport()
# module: tests.test_connection def create_transport(client, server): <0> client_transport = FakeTransport() <1> client_transport.target = server <2> <3> server_transport = FakeTransport() <4> server_transport.target = client <5> <6> server.connection_made(server_transport) <7> client.connection_made(client_transport) <8> <9> return client_transport, server_transport <10>
===========unchanged ref 0=========== at: aioquic.connection QuicConnection(is_client: bool=True, certificate: Any=None, private_key: Any=None, secrets_log_file: TextIO=None, alpn_protocols: Optional[List[str]]=None, server_name: Optional[str]=None) at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] connection_made(transport: asyncio.DatagramTransport) -> None at: tests.test_connection CLIENT_ADDR = None FakeTransport(local_addr) at: tests.test_connection.FakeTransport target = None ===========changed ref 0=========== # module: tests.test_connection class FakeTransport: + def __init__(self, local_addr): + self.local_addr = local_addr + ===========changed ref 1=========== # module: tests.test_connection def create_standalone_client(): client = QuicConnection(is_client=True) + client_transport = FakeTransport(CLIENT_ADDR) - client_transport = FakeTransport() client.connection_made(client_transport) return client, client_transport ===========changed ref 2=========== # module: tests.test_connection class FakeTransport: def sendto(self, data, addr): self.sent += 1 if self.target is not None: + self.target.datagram_received(data, self.local_addr) - self.target.datagram_received(data, None) ===========changed ref 3=========== # module: tests.test_connection + CLIENT_ADDR = None + + SERVER_ADDR = None SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) ===========changed ref 4=========== # module: aioquic.packet + def encode_quic_retry( + version: QuicProtocolVersion, + source_cid: bytes, + destination_cid: bytes, + original_destination_cid: bytes, + retry_token: bytes, + ) -> bytes: + buf = Buffer(capacity=100) + push_uint8( + buf, PACKET_TYPE_RETRY | encode_cid_length(len(original_destination_cid)) + ) + push_uint32(buf, version) + push_uint8( + buf, + (encode_cid_length(len(destination_cid)) << 4) + | encode_cid_length(len(source_cid)), + ) + push_bytes(buf, destination_cid) + push_bytes(buf, source_cid) + push_bytes(buf, original_destination_cid) + push_bytes(buf, retry_token) + return buf.data +
tests.test_connection/QuicConnectionTest.test_datagram_received_wrong_version
Modified
aiortc~aioquic
4c66db2e0a051d0da6b94285851bd35ece9c01d7
[tests] generate retry packet ourselves
<14>:<add> client.datagram_received(buf.data, SERVER_ADDR) <del> client.datagram_received(buf.data, None)
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_datagram_received_wrong_version(self): <0> client, client_transport = create_standalone_client() <1> self.assertEqual(client_transport.sent, 1) <2> <3> buf = Buffer(capacity=1300) <4> push_quic_header( <5> buf, <6> QuicHeader( <7> version=0xFF000011, # DRAFT_16 <8> packet_type=PACKET_TYPE_INITIAL | (PACKET_NUMBER_SEND_SIZE - 1), <9> destination_cid=client.host_cid, <10> source_cid=client.peer_cid, <11> ), <12> ) <13> buf.seek(1300) <14> client.datagram_received(buf.data, None) <15> self.assertEqual(client_transport.sent, 1) <16>
===========unchanged ref 0=========== at: aioquic.buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.buffer.Buffer seek(pos: int) -> None at: aioquic.connection.QuicConnection datagram_received(data: bytes, addr: Any) -> None at: aioquic.connection.QuicConnection.__init__ self.host_cid = os.urandom(8) self.peer_cid = os.urandom(8) at: aioquic.connection.QuicConnection.datagram_received self.peer_cid = header.source_cid at: aioquic.packet PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00 PACKET_NUMBER_SEND_SIZE = 2 QuicHeader(version: Optional[int], packet_type: int, destination_cid: bytes, source_cid: bytes, original_destination_cid: bytes=b"", token: bytes=b"", rest_length: int=0) push_quic_header(buf: Buffer, header: QuicHeader) -> None at: aioquic.packet.QuicHeader version: Optional[int] packet_type: int destination_cid: bytes source_cid: bytes original_destination_cid: bytes = b"" token: bytes = b"" rest_length: int = 0 at: tests.test_connection SERVER_ADDR = None create_standalone_client() at: tests.test_connection.FakeTransport.sendto self.sent += 1 at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_connection def create_standalone_client(): client = QuicConnection(is_client=True) + client_transport = FakeTransport(CLIENT_ADDR) - client_transport = FakeTransport() client.connection_made(client_transport) return client, client_transport ===========changed ref 1=========== # module: tests.test_connection class QuicConnectionTest(TestCase): - def test_datagram_received_wrong_destination_cid(self): - client, client_transport = create_standalone_client() - self.assertEqual(client_transport.sent, 1) - - client.datagram_received(load("retry.bin"), None) - self.assertEqual(client_transport.sent, 1) - ===========changed ref 2=========== # module: tests.test_connection class FakeTransport: + def __init__(self, local_addr): + self.local_addr = local_addr + ===========changed ref 3=========== # module: tests.test_connection class FakeTransport: def sendto(self, data, addr): self.sent += 1 if self.target is not None: + self.target.datagram_received(data, self.local_addr) - self.target.datagram_received(data, None) ===========changed ref 4=========== # module: tests.test_connection def create_transport(client, server): + client_transport = FakeTransport(CLIENT_ADDR) - client_transport = FakeTransport() client_transport.target = server + server_transport = FakeTransport(SERVER_ADDR) - server_transport = FakeTransport() server_transport.target = client server.connection_made(server_transport) client.connection_made(client_transport) return client_transport, server_transport ===========changed ref 5=========== # module: tests.test_connection + CLIENT_ADDR = None + + SERVER_ADDR = None SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) ===========changed ref 6=========== # module: aioquic.packet + def encode_quic_retry( + version: QuicProtocolVersion, + source_cid: bytes, + destination_cid: bytes, + original_destination_cid: bytes, + retry_token: bytes, + ) -> bytes: + buf = Buffer(capacity=100) + push_uint8( + buf, PACKET_TYPE_RETRY | encode_cid_length(len(original_destination_cid)) + ) + push_uint32(buf, version) + push_uint8( + buf, + (encode_cid_length(len(destination_cid)) << 4) + | encode_cid_length(len(source_cid)), + ) + push_bytes(buf, destination_cid) + push_bytes(buf, source_cid) + push_bytes(buf, original_destination_cid) + push_bytes(buf, retry_token) + return buf.data +
tests.test_connection/QuicConnectionTest.test_datagram_received_retry
Modified
aiortc~aioquic
4c66db2e0a051d0da6b94285851bd35ece9c01d7
[tests] generate retry packet ourselves
<0>:<del> client = QuicConnection(is_client=True) <1>:<del> client.host_cid = binascii.unhexlify("c98343fe8f5f0ff4") <2>:<del> client.peer_cid = binascii.unhexlify("85abb547bf28be97") <3>:<del> <4>:<del> client_transport = FakeTransport() <5>:<del> client.connection_made(client_transport) <6>:<add> client, client_transport = create_standalone_client() <8>:<add> client.datagram_received( <add> encode_quic_retry( <add> version=QuicProtocolVersion.DRAFT_20, <add> source_cid=binascii.unhexlify("85abb547bf28be97"), <add> destination_cid=client.host_cid, <add> original_destination_cid=client.peer_cid, <add> retry_token=bytes(16), <add> ), <add> SERVER_ADDR, <add> ) <del> client.datagram_received(load("retry.bin"), None)
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_datagram_received_retry(self): <0> client = QuicConnection(is_client=True) <1> client.host_cid = binascii.unhexlify("c98343fe8f5f0ff4") <2> client.peer_cid = binascii.unhexlify("85abb547bf28be97") <3> <4> client_transport = FakeTransport() <5> client.connection_made(client_transport) <6> self.assertEqual(client_transport.sent, 1) <7> <8> client.datagram_received(load("retry.bin"), None) <9> self.assertEqual(client_transport.sent, 2) <10>
===========unchanged ref 0=========== at: aioquic.packet QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int) QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) encode_quic_retry(version: QuicProtocolVersion, source_cid: bytes, destination_cid: bytes, original_destination_cid: bytes, retry_token: bytes) -> bytes at: binascii unhexlify(hexstr: _Ascii, /) -> bytes at: tests.test_connection create_standalone_client() at: tests.test_connection.FakeTransport.sendto self.sent += 1 at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_connection def create_standalone_client(): client = QuicConnection(is_client=True) + client_transport = FakeTransport(CLIENT_ADDR) - client_transport = FakeTransport() client.connection_made(client_transport) return client, client_transport ===========changed ref 1=========== # module: aioquic.packet + def encode_quic_retry( + version: QuicProtocolVersion, + source_cid: bytes, + destination_cid: bytes, + original_destination_cid: bytes, + retry_token: bytes, + ) -> bytes: + buf = Buffer(capacity=100) + push_uint8( + buf, PACKET_TYPE_RETRY | encode_cid_length(len(original_destination_cid)) + ) + push_uint32(buf, version) + push_uint8( + buf, + (encode_cid_length(len(destination_cid)) << 4) + | encode_cid_length(len(source_cid)), + ) + push_bytes(buf, destination_cid) + push_bytes(buf, source_cid) + push_bytes(buf, original_destination_cid) + push_bytes(buf, retry_token) + return buf.data + ===========changed ref 2=========== # module: tests.test_connection class QuicConnectionTest(TestCase): - def test_datagram_received_wrong_destination_cid(self): - client, client_transport = create_standalone_client() - self.assertEqual(client_transport.sent, 1) - - client.datagram_received(load("retry.bin"), None) - self.assertEqual(client_transport.sent, 1) - ===========changed ref 3=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_datagram_received_wrong_version(self): client, client_transport = create_standalone_client() self.assertEqual(client_transport.sent, 1) buf = Buffer(capacity=1300) push_quic_header( buf, QuicHeader( version=0xFF000011, # DRAFT_16 packet_type=PACKET_TYPE_INITIAL | (PACKET_NUMBER_SEND_SIZE - 1), destination_cid=client.host_cid, source_cid=client.peer_cid, ), ) buf.seek(1300) + client.datagram_received(buf.data, SERVER_ADDR) - client.datagram_received(buf.data, None) self.assertEqual(client_transport.sent, 1) ===========changed ref 4=========== # module: tests.test_connection class FakeTransport: + def __init__(self, local_addr): + self.local_addr = local_addr + ===========changed ref 5=========== # module: tests.test_connection class FakeTransport: def sendto(self, data, addr): self.sent += 1 if self.target is not None: + self.target.datagram_received(data, self.local_addr) - self.target.datagram_received(data, None) ===========changed ref 6=========== # module: tests.test_connection def create_transport(client, server): + client_transport = FakeTransport(CLIENT_ADDR) - client_transport = FakeTransport() client_transport.target = server + server_transport = FakeTransport(SERVER_ADDR) - server_transport = FakeTransport() server_transport.target = client server.connection_made(server_transport) client.connection_made(client_transport) return client_transport, server_transport ===========changed ref 7=========== # module: tests.test_connection + CLIENT_ADDR = None + + SERVER_ADDR = None SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() )
tests.test_connection/QuicConnectionTest.test_version_negotiation_fail
Modified
aiortc~aioquic
4c66db2e0a051d0da6b94285851bd35ece9c01d7
[tests] generate retry packet ourselves
<10>:<add> SERVER_ADDR, <del> None,
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_version_negotiation_fail(self): <0> client, client_transport = create_standalone_client() <1> self.assertEqual(client_transport.sent, 1) <2> <3> # no common version, no retry <4> client.datagram_received( <5> encode_quic_version_negotiation( <6> source_cid=client.peer_cid, <7> destination_cid=client.host_cid, <8> supported_versions=[0xFF000011], # DRAFT_16 <9> ), <10> None, <11> ) <12> self.assertEqual(client_transport.sent, 1) <13>
===========unchanged ref 0=========== at: aioquic.connection.QuicConnection _stream_can_receive(stream_id: int) -> bool _stream_can_send(stream_id: int) -> bool at: tests.test_connection.QuicConnectionTest.test_stream_direction client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) at: unittest.case.TestCase assertTrue(expr: Any, msg: Any=...) -> None assertFalse(expr: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_connection class QuicConnectionTest(TestCase): - def test_datagram_received_wrong_destination_cid(self): - client, client_transport = create_standalone_client() - self.assertEqual(client_transport.sent, 1) - - client.datagram_received(load("retry.bin"), None) - self.assertEqual(client_transport.sent, 1) - ===========changed ref 1=========== # module: tests.test_connection class QuicConnectionTest(TestCase): + def test_datagram_received_retry_wrong_destination_cid(self): + client, client_transport = create_standalone_client() + self.assertEqual(client_transport.sent, 1) + + client.datagram_received( + encode_quic_retry( + version=QuicProtocolVersion.DRAFT_20, + source_cid=binascii.unhexlify("85abb547bf28be97"), + destination_cid=binascii.unhexlify("c98343fe8f5f0ff4"), + original_destination_cid=client.peer_cid, + retry_token=bytes(16), + ), + SERVER_ADDR, + ) + self.assertEqual(client_transport.sent, 1) + ===========changed ref 2=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_datagram_received_wrong_version(self): client, client_transport = create_standalone_client() self.assertEqual(client_transport.sent, 1) buf = Buffer(capacity=1300) push_quic_header( buf, QuicHeader( version=0xFF000011, # DRAFT_16 packet_type=PACKET_TYPE_INITIAL | (PACKET_NUMBER_SEND_SIZE - 1), destination_cid=client.host_cid, source_cid=client.peer_cid, ), ) buf.seek(1300) + client.datagram_received(buf.data, SERVER_ADDR) - client.datagram_received(buf.data, None) self.assertEqual(client_transport.sent, 1) ===========changed ref 3=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_datagram_received_retry(self): - client = QuicConnection(is_client=True) - client.host_cid = binascii.unhexlify("c98343fe8f5f0ff4") - client.peer_cid = binascii.unhexlify("85abb547bf28be97") - - client_transport = FakeTransport() - client.connection_made(client_transport) + client, client_transport = create_standalone_client() self.assertEqual(client_transport.sent, 1) + client.datagram_received( + encode_quic_retry( + version=QuicProtocolVersion.DRAFT_20, + source_cid=binascii.unhexlify("85abb547bf28be97"), + destination_cid=client.host_cid, + original_destination_cid=client.peer_cid, + retry_token=bytes(16), + ), + SERVER_ADDR, + ) - client.datagram_received(load("retry.bin"), None) self.assertEqual(client_transport.sent, 2) ===========changed ref 4=========== # module: tests.test_connection class FakeTransport: + def __init__(self, local_addr): + self.local_addr = local_addr + ===========changed ref 5=========== # module: tests.test_connection def create_standalone_client(): client = QuicConnection(is_client=True) + client_transport = FakeTransport(CLIENT_ADDR) - client_transport = FakeTransport() client.connection_made(client_transport) return client, client_transport ===========changed ref 6=========== # module: tests.test_connection class FakeTransport: def sendto(self, data, addr): self.sent += 1 if self.target is not None: + self.target.datagram_received(data, self.local_addr) - self.target.datagram_received(data, None) ===========changed ref 7=========== # module: tests.test_connection def create_transport(client, server): + client_transport = FakeTransport(CLIENT_ADDR) - client_transport = FakeTransport() client_transport.target = server + server_transport = FakeTransport(SERVER_ADDR) - server_transport = FakeTransport() server_transport.target = client server.connection_made(server_transport) client.connection_made(client_transport) return client_transport, server_transport ===========changed ref 8=========== # module: tests.test_connection + CLIENT_ADDR = None + + SERVER_ADDR = None SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) ===========changed ref 9=========== # module: aioquic.packet + def encode_quic_retry( + version: QuicProtocolVersion, + source_cid: bytes, + destination_cid: bytes, + original_destination_cid: bytes, + retry_token: bytes, + ) -> bytes: + buf = Buffer(capacity=100) + push_uint8( + buf, PACKET_TYPE_RETRY | encode_cid_length(len(original_destination_cid)) + ) + push_uint32(buf, version) + push_uint8( + buf, + (encode_cid_length(len(destination_cid)) << 4) + | encode_cid_length(len(source_cid)), + ) + push_bytes(buf, destination_cid) + push_bytes(buf, source_cid) + push_bytes(buf, original_destination_cid) + push_bytes(buf, retry_token) + return buf.data +
tests.test_connection/QuicConnectionTest.test_version_negotiation_ok
Modified
aiortc~aioquic
4c66db2e0a051d0da6b94285851bd35ece9c01d7
[tests] generate retry packet ourselves
<10>:<add> SERVER_ADDR, <del> None,
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_version_negotiation_ok(self): <0> client, client_transport = create_standalone_client() <1> self.assertEqual(client_transport.sent, 1) <2> <3> # found a common version, retry <4> client.datagram_received( <5> encode_quic_version_negotiation( <6> source_cid=client.peer_cid, <7> destination_cid=client.host_cid, <8> supported_versions=[QuicProtocolVersion.DRAFT_19], <9> ), <10> None, <11> ) <12> self.assertEqual(client_transport.sent, 2) <13>
===========unchanged ref 0=========== at: aioquic.connection.QuicConnection _stream_can_receive(stream_id: int) -> bool _stream_can_send(stream_id: int) -> bool at: aioquic.packet encode_quic_version_negotiation(source_cid: bytes, destination_cid: bytes, supported_versions: List[QuicProtocolVersion]) -> bytes at: tests.test_connection create_standalone_client() at: tests.test_connection.QuicConnectionTest.test_stream_direction client = QuicConnection(is_client=True) server = QuicConnection( is_client=False, certificate=SERVER_CERTIFICATE, private_key=SERVER_PRIVATE_KEY, ) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None assertTrue(expr: Any, msg: Any=...) -> None assertFalse(expr: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_connection def create_standalone_client(): client = QuicConnection(is_client=True) + client_transport = FakeTransport(CLIENT_ADDR) - client_transport = FakeTransport() client.connection_made(client_transport) return client, client_transport ===========changed ref 1=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_version_negotiation_fail(self): client, client_transport = create_standalone_client() self.assertEqual(client_transport.sent, 1) # no common version, no retry client.datagram_received( encode_quic_version_negotiation( source_cid=client.peer_cid, destination_cid=client.host_cid, supported_versions=[0xFF000011], # DRAFT_16 ), + SERVER_ADDR, - None, ) self.assertEqual(client_transport.sent, 1) ===========changed ref 2=========== # module: tests.test_connection class QuicConnectionTest(TestCase): - def test_datagram_received_wrong_destination_cid(self): - client, client_transport = create_standalone_client() - self.assertEqual(client_transport.sent, 1) - - client.datagram_received(load("retry.bin"), None) - self.assertEqual(client_transport.sent, 1) - ===========changed ref 3=========== # module: tests.test_connection class QuicConnectionTest(TestCase): + def test_datagram_received_retry_wrong_destination_cid(self): + client, client_transport = create_standalone_client() + self.assertEqual(client_transport.sent, 1) + + client.datagram_received( + encode_quic_retry( + version=QuicProtocolVersion.DRAFT_20, + source_cid=binascii.unhexlify("85abb547bf28be97"), + destination_cid=binascii.unhexlify("c98343fe8f5f0ff4"), + original_destination_cid=client.peer_cid, + retry_token=bytes(16), + ), + SERVER_ADDR, + ) + self.assertEqual(client_transport.sent, 1) + ===========changed ref 4=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_datagram_received_wrong_version(self): client, client_transport = create_standalone_client() self.assertEqual(client_transport.sent, 1) buf = Buffer(capacity=1300) push_quic_header( buf, QuicHeader( version=0xFF000011, # DRAFT_16 packet_type=PACKET_TYPE_INITIAL | (PACKET_NUMBER_SEND_SIZE - 1), destination_cid=client.host_cid, source_cid=client.peer_cid, ), ) buf.seek(1300) + client.datagram_received(buf.data, SERVER_ADDR) - client.datagram_received(buf.data, None) self.assertEqual(client_transport.sent, 1) ===========changed ref 5=========== # module: tests.test_connection class QuicConnectionTest(TestCase): def test_datagram_received_retry(self): - client = QuicConnection(is_client=True) - client.host_cid = binascii.unhexlify("c98343fe8f5f0ff4") - client.peer_cid = binascii.unhexlify("85abb547bf28be97") - - client_transport = FakeTransport() - client.connection_made(client_transport) + client, client_transport = create_standalone_client() self.assertEqual(client_transport.sent, 1) + client.datagram_received( + encode_quic_retry( + version=QuicProtocolVersion.DRAFT_20, + source_cid=binascii.unhexlify("85abb547bf28be97"), + destination_cid=client.host_cid, + original_destination_cid=client.peer_cid, + retry_token=bytes(16), + ), + SERVER_ADDR, + ) - client.datagram_received(load("retry.bin"), None) self.assertEqual(client_transport.sent, 2) ===========changed ref 6=========== # module: tests.test_connection class FakeTransport: + def __init__(self, local_addr): + self.local_addr = local_addr + ===========changed ref 7=========== # module: tests.test_connection class FakeTransport: def sendto(self, data, addr): self.sent += 1 if self.target is not None: + self.target.datagram_received(data, self.local_addr) - self.target.datagram_received(data, None) ===========changed ref 8=========== # module: tests.test_connection def create_transport(client, server): + client_transport = FakeTransport(CLIENT_ADDR) - client_transport = FakeTransport() client_transport.target = server + server_transport = FakeTransport(SERVER_ADDR) - server_transport = FakeTransport() server_transport.target = client server.connection_made(server_transport) client.connection_made(client_transport) return client_transport, server_transport ===========changed ref 9=========== # module: tests.test_connection + CLIENT_ADDR = None + + SERVER_ADDR = None SERVER_CERTIFICATE = x509.load_pem_x509_certificate( load("ssl_cert.pem"), backend=default_backend() ) SERVER_PRIVATE_KEY = serialization.load_pem_private_key( load("ssl_key.pem"), password=None, backend=default_backend() ) ===========changed ref 10=========== # module: aioquic.packet + def encode_quic_retry( + version: QuicProtocolVersion, + source_cid: bytes, + destination_cid: bytes, + original_destination_cid: bytes, + retry_token: bytes, + ) -> bytes: + buf = Buffer(capacity=100) + push_uint8( + buf, PACKET_TYPE_RETRY | encode_cid_length(len(original_destination_cid)) + ) + push_uint32(buf, version) + push_uint8( + buf, + (encode_cid_length(len(destination_cid)) << 4) + | encode_cid_length(len(source_cid)), + ) + push_bytes(buf, destination_cid) + push_bytes(buf, source_cid) + push_bytes(buf, original_destination_cid) + push_bytes(buf, retry_token) + return buf.data +
aioquic.connection/QuicConnection.connect
Modified
aiortc~aioquic
f12180ae527f69ee085df5007a46d26154ced102
[connection] make QuicConnection.connect() trigger handshake
<1>:<add> Initiate the TLS handshake and wait for it to complete. <del> Wait for the TLS handshake to complete. <3>:<add> self._peer_addr = addr <add> self._version = max(self.supported_versions) <add> self._connect()
# module: aioquic.connection + class QuicConnection(asyncio.DatagramProtocol): - class QuicConnection: + def connect(self, addr: Any) -> None: - def connect(self) -> None: <0> """ <1> Wait for the TLS handshake to complete. <2> """ <3> await self.__connected.wait() <4>
===========unchanged ref 0=========== at: aioquic.connection QuicConnectionState() maybe_connection_error(error_code: int, frame_type: Optional[int], reason_phrase: str) -> Optional[QuicConnectionError] at: aioquic.connection.QuicConnection supported_versions = [QuicProtocolVersion.DRAFT_19, QuicProtocolVersion.DRAFT_20] connection_lost(exc: Exception) -> None _set_state(state: QuicConnectionState) -> None