nopasaran.tools.http_3_socket_base.EventCapturingProtocol¶
- class nopasaran.tools.http_3_socket_base.EventCapturingProtocol(*args, **kwargs)¶
Bases:
QuicConnectionProtocolCustom protocol that intercepts QUIC events before they’re consumed
- __init__(*args, **kwargs)¶
Methods
__init__(*args, **kwargs)Change the connection ID used to communicate with the peer.
close([error_code, reason_phrase])Close the connection.
connect(addr[, transmit])Initiate the TLS handshake.
connection_lost(exc)Called when the connection is lost or closed.
connection_made(transport)create_stream([is_unidirectional])Create a QUIC stream and return a pair of (reader, writer) objects.
datagram_received(data, addr)Disable event capturing and restore original next_event
Enable event capturing by monkey-patching next_event
error_received(exc)Called when a send or receive operation raises an OSError.
Return captured events (don't clear - let disable_capture handle that)
Called when the transport's buffer goes over the high-water mark.
ping()Ping the peer and wait for the response.
quic_event_received(event)Called when a QUIC event is received.
Request an update of the encryption keys.
Called when the transport's buffer drains below the low-water mark.
transmit()Send pending datagrams to the peer and arm the timer if needed.
Wait for the connection to be closed.
Wait for the TLS handshake to complete.
- change_connection_id() None¶
Change the connection ID used to communicate with the peer.
The previous connection ID will be retired.
- close(error_code: int = QuicErrorCode.NO_ERROR, reason_phrase: str = '') None¶
Close the connection.
- Parameters:
error_code – An error code indicating why the connection is being closed.
reason_phrase – A human-readable explanation of why the connection is being closed.
- connect(addr: Any, transmit=True) None¶
Initiate the TLS handshake.
This method can only be called for clients and a single time.
- connection_lost(exc)¶
Called when the connection is lost or closed.
The argument is an exception object or None (the latter meaning a regular EOF is received or the connection was aborted or closed).
- async create_stream(is_unidirectional: bool = False) tuple[StreamReader, StreamWriter]¶
Create a QUIC stream and return a pair of (reader, writer) objects.
The returned reader and writer objects are instances of
asyncio.StreamReaderandasyncio.StreamWriterclasses.
- disable_capture()¶
Disable event capturing and restore original next_event
- enable_capture()¶
Enable event capturing by monkey-patching next_event
- error_received(exc)¶
Called when a send or receive operation raises an OSError.
(Other than BlockingIOError or InterruptedError.)
- get_captured_events() List[QuicEvent]¶
Return captured events (don’t clear - let disable_capture handle that)
- pause_writing()¶
Called when the transport’s buffer goes over the high-water mark.
Pause and resume calls are paired – pause_writing() is called once when the buffer goes strictly over the high-water mark (even if subsequent writes increases the buffer size even more), and eventually resume_writing() is called once when the buffer size reaches the low-water mark.
Note that if the buffer size equals the high-water mark, pause_writing() is not called – it must go strictly over. Conversely, resume_writing() is called when the buffer size is equal or lower than the low-water mark. These end conditions are important to ensure that things go as expected when either mark is zero.
NOTE: This is the only Protocol callback that is not called through EventLoop.call_soon() – if it were, it would have no effect when it’s most needed (when the app keeps writing without yielding until pause_writing() is called).
- async ping() None¶
Ping the peer and wait for the response.
- quic_event_received(event: QuicEvent) None¶
Called when a QUIC event is received.
Reimplement this in your subclass to handle the events.
- request_key_update() None¶
Request an update of the encryption keys.
- resume_writing()¶
Called when the transport’s buffer drains below the low-water mark.
See pause_writing() for details.
- transmit() None¶
Send pending datagrams to the peer and arm the timer if needed.
This method is called automatically when data is received from the peer or when a timer goes off. If you interact directly with the underlying
QuicConnection, make sure you call this method whenever data needs to be sent out to the network.
- async wait_closed() None¶
Wait for the connection to be closed.
- async wait_connected() None¶
Wait for the TLS handshake to complete.