mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-14 02:26:58 -07:00
Bump dnspython from 2.4.2 to 2.6.1 (#2264)
* Bump dnspython from 2.4.2 to 2.6.1 Bumps [dnspython](https://github.com/rthalley/dnspython) from 2.4.2 to 2.6.1. - [Release notes](https://github.com/rthalley/dnspython/releases) - [Changelog](https://github.com/rthalley/dnspython/blob/main/doc/whatsnew.rst) - [Commits](https://github.com/rthalley/dnspython/compare/v2.4.2...v2.6.1) --- updated-dependencies: - dependency-name: dnspython dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Update dnspython==2.6.1 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> [skip ci]
This commit is contained in:
parent
aca7e72715
commit
cfefa928be
101 changed files with 1052 additions and 459 deletions
|
@ -1,9 +1,11 @@
|
|||
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
||||
|
||||
try:
|
||||
import dns._features
|
||||
import dns.asyncbackend
|
||||
|
||||
if dns._features.have("doq"):
|
||||
import aioquic.quic.configuration # type: ignore
|
||||
|
||||
import dns.asyncbackend
|
||||
from dns._asyncbackend import NullContext
|
||||
from dns.quic._asyncio import (
|
||||
AsyncioQuicConnection,
|
||||
|
@ -17,7 +19,7 @@ try:
|
|||
|
||||
def null_factory(
|
||||
*args, # pylint: disable=unused-argument
|
||||
**kwargs # pylint: disable=unused-argument
|
||||
**kwargs, # pylint: disable=unused-argument
|
||||
):
|
||||
return NullContext(None)
|
||||
|
||||
|
@ -31,7 +33,7 @@ try:
|
|||
|
||||
_async_factories = {"asyncio": (null_factory, _asyncio_manager_factory)}
|
||||
|
||||
try:
|
||||
if dns._features.have("trio"):
|
||||
import trio
|
||||
|
||||
from dns.quic._trio import ( # pylint: disable=ungrouped-imports
|
||||
|
@ -47,15 +49,13 @@ try:
|
|||
return TrioQuicManager(context, *args, **kwargs)
|
||||
|
||||
_async_factories["trio"] = (_trio_context_factory, _trio_manager_factory)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
def factories_for_backend(backend=None):
|
||||
if backend is None:
|
||||
backend = dns.asyncbackend.get_default_backend()
|
||||
return _async_factories[backend.name()]
|
||||
|
||||
except ImportError:
|
||||
else: # pragma: no cover
|
||||
have_quic = False
|
||||
|
||||
from typing import Any
|
||||
|
|
|
@ -101,9 +101,7 @@ class AsyncioQuicConnection(AsyncQuicConnection):
|
|||
)
|
||||
if address[0] != self._peer[0] or address[1] != self._peer[1]:
|
||||
continue
|
||||
self._connection.receive_datagram(
|
||||
datagram, self._peer[0], time.time()
|
||||
)
|
||||
self._connection.receive_datagram(datagram, address, time.time())
|
||||
# Wake up the timer in case the sender is sleeping, as there may be
|
||||
# stuff to send now.
|
||||
async with self._wake_timer:
|
||||
|
@ -125,7 +123,7 @@ class AsyncioQuicConnection(AsyncQuicConnection):
|
|||
while not self._done:
|
||||
datagrams = self._connection.datagrams_to_send(time.time())
|
||||
for datagram, address in datagrams:
|
||||
assert address == self._peer[0]
|
||||
assert address == self._peer
|
||||
await self._socket.sendto(datagram, self._peer, None)
|
||||
(expiration, interval) = self._get_timer_values()
|
||||
try:
|
||||
|
@ -147,11 +145,14 @@ class AsyncioQuicConnection(AsyncQuicConnection):
|
|||
await stream._add_input(event.data, event.end_stream)
|
||||
elif isinstance(event, aioquic.quic.events.HandshakeCompleted):
|
||||
self._handshake_complete.set()
|
||||
elif isinstance(
|
||||
event, aioquic.quic.events.ConnectionTerminated
|
||||
) or isinstance(event, aioquic.quic.events.StreamReset):
|
||||
elif isinstance(event, aioquic.quic.events.ConnectionTerminated):
|
||||
self._done = True
|
||||
self._receiver_task.cancel()
|
||||
elif isinstance(event, aioquic.quic.events.StreamReset):
|
||||
stream = self._streams.get(event.stream_id)
|
||||
if stream:
|
||||
await stream._add_input(b"", True)
|
||||
|
||||
count += 1
|
||||
if count > 10:
|
||||
# yield
|
||||
|
@ -188,7 +189,6 @@ class AsyncioQuicConnection(AsyncQuicConnection):
|
|||
self._connection.close()
|
||||
# sender might be blocked on this, so set it
|
||||
self._socket_created.set()
|
||||
await self._socket.close()
|
||||
async with self._wake_timer:
|
||||
self._wake_timer.notify_all()
|
||||
try:
|
||||
|
@ -199,14 +199,19 @@ class AsyncioQuicConnection(AsyncQuicConnection):
|
|||
await self._sender_task
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
await self._socket.close()
|
||||
|
||||
|
||||
class AsyncioQuicManager(AsyncQuicManager):
|
||||
def __init__(self, conf=None, verify_mode=ssl.CERT_REQUIRED, server_name=None):
|
||||
super().__init__(conf, verify_mode, AsyncioQuicConnection, server_name)
|
||||
|
||||
def connect(self, address, port=853, source=None, source_port=0):
|
||||
(connection, start) = self._connect(address, port, source, source_port)
|
||||
def connect(
|
||||
self, address, port=853, source=None, source_port=0, want_session_ticket=True
|
||||
):
|
||||
(connection, start) = self._connect(
|
||||
address, port, source, source_port, want_session_ticket
|
||||
)
|
||||
if start:
|
||||
connection.run()
|
||||
return connection
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
||||
|
||||
import copy
|
||||
import functools
|
||||
import socket
|
||||
import struct
|
||||
import time
|
||||
|
@ -11,6 +13,10 @@ import aioquic.quic.connection # type: ignore
|
|||
import dns.inet
|
||||
|
||||
QUIC_MAX_DATAGRAM = 2048
|
||||
MAX_SESSION_TICKETS = 8
|
||||
# If we hit the max sessions limit we will delete this many of the oldest connections.
|
||||
# The value must be a integer > 0 and <= MAX_SESSION_TICKETS.
|
||||
SESSIONS_TO_DELETE = MAX_SESSION_TICKETS // 4
|
||||
|
||||
|
||||
class UnexpectedEOF(Exception):
|
||||
|
@ -79,7 +85,10 @@ class BaseQuicStream:
|
|||
|
||||
def _common_add_input(self, data, is_end):
|
||||
self._buffer.put(data, is_end)
|
||||
return self._expecting > 0 and self._buffer.have(self._expecting)
|
||||
try:
|
||||
return self._expecting > 0 and self._buffer.have(self._expecting)
|
||||
except UnexpectedEOF:
|
||||
return True
|
||||
|
||||
def _close(self):
|
||||
self._connection.close_stream(self._stream_id)
|
||||
|
@ -142,6 +151,7 @@ class BaseQuicManager:
|
|||
def __init__(self, conf, verify_mode, connection_factory, server_name=None):
|
||||
self._connections = {}
|
||||
self._connection_factory = connection_factory
|
||||
self._session_tickets = {}
|
||||
if conf is None:
|
||||
verify_path = None
|
||||
if isinstance(verify_mode, str):
|
||||
|
@ -156,12 +166,35 @@ class BaseQuicManager:
|
|||
conf.load_verify_locations(verify_path)
|
||||
self._conf = conf
|
||||
|
||||
def _connect(self, address, port=853, source=None, source_port=0):
|
||||
def _connect(
|
||||
self, address, port=853, source=None, source_port=0, want_session_ticket=True
|
||||
):
|
||||
connection = self._connections.get((address, port))
|
||||
if connection is not None:
|
||||
return (connection, False)
|
||||
qconn = aioquic.quic.connection.QuicConnection(configuration=self._conf)
|
||||
qconn.connect(address, time.time())
|
||||
conf = self._conf
|
||||
if want_session_ticket:
|
||||
try:
|
||||
session_ticket = self._session_tickets.pop((address, port))
|
||||
# We found a session ticket, so make a configuration that uses it.
|
||||
conf = copy.copy(conf)
|
||||
conf.session_ticket = session_ticket
|
||||
except KeyError:
|
||||
# No session ticket.
|
||||
pass
|
||||
# Whether or not we found a session ticket, we want a handler to save
|
||||
# one.
|
||||
session_ticket_handler = functools.partial(
|
||||
self.save_session_ticket, address, port
|
||||
)
|
||||
else:
|
||||
session_ticket_handler = None
|
||||
qconn = aioquic.quic.connection.QuicConnection(
|
||||
configuration=conf,
|
||||
session_ticket_handler=session_ticket_handler,
|
||||
)
|
||||
lladdress = dns.inet.low_level_address_tuple((address, port))
|
||||
qconn.connect(lladdress, time.time())
|
||||
connection = self._connection_factory(
|
||||
qconn, address, port, source, source_port, self
|
||||
)
|
||||
|
@ -174,6 +207,17 @@ class BaseQuicManager:
|
|||
except KeyError:
|
||||
pass
|
||||
|
||||
def save_session_ticket(self, address, port, ticket):
|
||||
# We rely on dictionaries keys() being in insertion order here. We
|
||||
# can't just popitem() as that would be LIFO which is the opposite of
|
||||
# what we want.
|
||||
l = len(self._session_tickets)
|
||||
if l >= MAX_SESSION_TICKETS:
|
||||
keys_to_delete = list(self._session_tickets.keys())[0:SESSIONS_TO_DELETE]
|
||||
for key in keys_to_delete:
|
||||
del self._session_tickets[key]
|
||||
self._session_tickets[(address, port)] = ticket
|
||||
|
||||
|
||||
class AsyncQuicManager(BaseQuicManager):
|
||||
def connect(self, address, port=853, source=None, source_port=0):
|
||||
|
|
|
@ -82,10 +82,6 @@ class SyncQuicConnection(BaseQuicConnection):
|
|||
def __init__(self, connection, address, port, source, source_port, manager):
|
||||
super().__init__(connection, address, port, source, source_port, manager)
|
||||
self._socket = socket.socket(self._af, socket.SOCK_DGRAM, 0)
|
||||
self._socket.connect(self._peer)
|
||||
(self._send_wakeup, self._receive_wakeup) = socket.socketpair()
|
||||
self._receive_wakeup.setblocking(False)
|
||||
self._socket.setblocking(False)
|
||||
if self._source is not None:
|
||||
try:
|
||||
self._socket.bind(
|
||||
|
@ -94,6 +90,10 @@ class SyncQuicConnection(BaseQuicConnection):
|
|||
except Exception:
|
||||
self._socket.close()
|
||||
raise
|
||||
self._socket.connect(self._peer)
|
||||
(self._send_wakeup, self._receive_wakeup) = socket.socketpair()
|
||||
self._receive_wakeup.setblocking(False)
|
||||
self._socket.setblocking(False)
|
||||
self._handshake_complete = threading.Event()
|
||||
self._worker_thread = None
|
||||
self._lock = threading.Lock()
|
||||
|
@ -107,7 +107,7 @@ class SyncQuicConnection(BaseQuicConnection):
|
|||
except BlockingIOError:
|
||||
return
|
||||
with self._lock:
|
||||
self._connection.receive_datagram(datagram, self._peer[0], time.time())
|
||||
self._connection.receive_datagram(datagram, self._peer, time.time())
|
||||
|
||||
def _drain_wakeup(self):
|
||||
while True:
|
||||
|
@ -128,6 +128,8 @@ class SyncQuicConnection(BaseQuicConnection):
|
|||
key.data()
|
||||
with self._lock:
|
||||
self._handle_timer(expiration)
|
||||
self._handle_events()
|
||||
with self._lock:
|
||||
datagrams = self._connection.datagrams_to_send(time.time())
|
||||
for datagram, _ in datagrams:
|
||||
try:
|
||||
|
@ -135,7 +137,6 @@ class SyncQuicConnection(BaseQuicConnection):
|
|||
except BlockingIOError:
|
||||
# we let QUIC handle any lossage
|
||||
pass
|
||||
self._handle_events()
|
||||
finally:
|
||||
with self._lock:
|
||||
self._done = True
|
||||
|
@ -155,11 +156,14 @@ class SyncQuicConnection(BaseQuicConnection):
|
|||
stream._add_input(event.data, event.end_stream)
|
||||
elif isinstance(event, aioquic.quic.events.HandshakeCompleted):
|
||||
self._handshake_complete.set()
|
||||
elif isinstance(
|
||||
event, aioquic.quic.events.ConnectionTerminated
|
||||
) or isinstance(event, aioquic.quic.events.StreamReset):
|
||||
elif isinstance(event, aioquic.quic.events.ConnectionTerminated):
|
||||
with self._lock:
|
||||
self._done = True
|
||||
elif isinstance(event, aioquic.quic.events.StreamReset):
|
||||
with self._lock:
|
||||
stream = self._streams.get(event.stream_id)
|
||||
if stream:
|
||||
stream._add_input(b"", True)
|
||||
|
||||
def write(self, stream, data, is_end=False):
|
||||
with self._lock:
|
||||
|
@ -203,9 +207,13 @@ class SyncQuicManager(BaseQuicManager):
|
|||
super().__init__(conf, verify_mode, SyncQuicConnection, server_name)
|
||||
self._lock = threading.Lock()
|
||||
|
||||
def connect(self, address, port=853, source=None, source_port=0):
|
||||
def connect(
|
||||
self, address, port=853, source=None, source_port=0, want_session_ticket=True
|
||||
):
|
||||
with self._lock:
|
||||
(connection, start) = self._connect(address, port, source, source_port)
|
||||
(connection, start) = self._connect(
|
||||
address, port, source, source_port, want_session_ticket
|
||||
)
|
||||
if start:
|
||||
connection.run()
|
||||
return connection
|
||||
|
@ -214,6 +222,10 @@ class SyncQuicManager(BaseQuicManager):
|
|||
with self._lock:
|
||||
super().closed(address, port)
|
||||
|
||||
def save_session_ticket(self, address, port, ticket):
|
||||
with self._lock:
|
||||
super().save_session_ticket(address, port, ticket)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
|
|
|
@ -76,30 +76,43 @@ class TrioQuicConnection(AsyncQuicConnection):
|
|||
def __init__(self, connection, address, port, source, source_port, manager=None):
|
||||
super().__init__(connection, address, port, source, source_port, manager)
|
||||
self._socket = trio.socket.socket(self._af, socket.SOCK_DGRAM, 0)
|
||||
if self._source:
|
||||
trio.socket.bind(dns.inet.low_level_address_tuple(self._source, self._af))
|
||||
self._handshake_complete = trio.Event()
|
||||
self._run_done = trio.Event()
|
||||
self._worker_scope = None
|
||||
self._send_pending = False
|
||||
|
||||
async def _worker(self):
|
||||
try:
|
||||
if self._source:
|
||||
await self._socket.bind(
|
||||
dns.inet.low_level_address_tuple(self._source, self._af)
|
||||
)
|
||||
await self._socket.connect(self._peer)
|
||||
while not self._done:
|
||||
(expiration, interval) = self._get_timer_values(False)
|
||||
if self._send_pending:
|
||||
# Do not block forever if sends are pending. Even though we
|
||||
# have a wake-up mechanism if we've already started the blocking
|
||||
# read, the possibility of context switching in send means that
|
||||
# more writes can happen while we have no wake up context, so
|
||||
# we need self._send_pending to avoid (effectively) a "lost wakeup"
|
||||
# race.
|
||||
interval = 0.0
|
||||
with trio.CancelScope(
|
||||
deadline=trio.current_time() + interval
|
||||
) as self._worker_scope:
|
||||
datagram = await self._socket.recv(QUIC_MAX_DATAGRAM)
|
||||
self._connection.receive_datagram(
|
||||
datagram, self._peer[0], time.time()
|
||||
)
|
||||
self._connection.receive_datagram(datagram, self._peer, time.time())
|
||||
self._worker_scope = None
|
||||
self._handle_timer(expiration)
|
||||
await self._handle_events()
|
||||
# We clear this now, before sending anything, as sending can cause
|
||||
# context switches that do more sends. We want to know if that
|
||||
# happens so we don't block a long time on the recv() above.
|
||||
self._send_pending = False
|
||||
datagrams = self._connection.datagrams_to_send(time.time())
|
||||
for datagram, _ in datagrams:
|
||||
await self._socket.send(datagram)
|
||||
await self._handle_events()
|
||||
finally:
|
||||
self._done = True
|
||||
self._handshake_complete.set()
|
||||
|
@ -116,11 +129,13 @@ class TrioQuicConnection(AsyncQuicConnection):
|
|||
await stream._add_input(event.data, event.end_stream)
|
||||
elif isinstance(event, aioquic.quic.events.HandshakeCompleted):
|
||||
self._handshake_complete.set()
|
||||
elif isinstance(
|
||||
event, aioquic.quic.events.ConnectionTerminated
|
||||
) or isinstance(event, aioquic.quic.events.StreamReset):
|
||||
elif isinstance(event, aioquic.quic.events.ConnectionTerminated):
|
||||
self._done = True
|
||||
self._socket.close()
|
||||
elif isinstance(event, aioquic.quic.events.StreamReset):
|
||||
stream = self._streams.get(event.stream_id)
|
||||
if stream:
|
||||
await stream._add_input(b"", True)
|
||||
count += 1
|
||||
if count > 10:
|
||||
# yield
|
||||
|
@ -129,6 +144,7 @@ class TrioQuicConnection(AsyncQuicConnection):
|
|||
|
||||
async def write(self, stream, data, is_end=False):
|
||||
self._connection.send_stream_data(stream, data, is_end)
|
||||
self._send_pending = True
|
||||
if self._worker_scope is not None:
|
||||
self._worker_scope.cancel()
|
||||
|
||||
|
@ -159,6 +175,7 @@ class TrioQuicConnection(AsyncQuicConnection):
|
|||
self._manager.closed(self._peer[0], self._peer[1])
|
||||
self._closed = True
|
||||
self._connection.close()
|
||||
self._send_pending = True
|
||||
if self._worker_scope is not None:
|
||||
self._worker_scope.cancel()
|
||||
await self._run_done.wait()
|
||||
|
@ -171,8 +188,12 @@ class TrioQuicManager(AsyncQuicManager):
|
|||
super().__init__(conf, verify_mode, TrioQuicConnection, server_name)
|
||||
self._nursery = nursery
|
||||
|
||||
def connect(self, address, port=853, source=None, source_port=0):
|
||||
(connection, start) = self._connect(address, port, source, source_port)
|
||||
def connect(
|
||||
self, address, port=853, source=None, source_port=0, want_session_ticket=True
|
||||
):
|
||||
(connection, start) = self._connect(
|
||||
address, port, source, source_port, want_session_ticket
|
||||
)
|
||||
if start:
|
||||
self._nursery.start_soon(connection.run)
|
||||
return connection
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue