4343 from OpenSSL .SSL import Context
4444 from typing_extensions import Self , TypeAlias
4545
46- from trio .socket import Address , _SocketType
46+ from trio .socket import SocketType
4747
4848MAX_UDP_PACKET_SIZE = 65527
4949
5050
51- def packet_header_overhead (sock : _SocketType ) -> int :
51+ def packet_header_overhead (sock : SocketType ) -> int :
5252 if sock .family == trio .socket .AF_INET :
5353 return 28
5454 else :
5555 return 48
5656
5757
58- def worst_case_mtu (sock : _SocketType ) -> int :
58+ def worst_case_mtu (sock : SocketType ) -> int :
5959 if sock .family == trio .socket .AF_INET :
6060 return 576 - packet_header_overhead (sock )
6161 else :
6262 return 1280 - packet_header_overhead (sock )
6363
6464
65- def best_guess_mtu (sock : _SocketType ) -> int :
65+ def best_guess_mtu (sock : SocketType ) -> int :
6666 return 1500 - packet_header_overhead (sock )
6767
6868
@@ -563,7 +563,7 @@ def _signable(*fields: bytes) -> bytes:
563563
564564
565565def _make_cookie (
566- key : bytes , salt : bytes , tick : int , address : Address , client_hello_bits : bytes
566+ key : bytes , salt : bytes , tick : int , address : Any , client_hello_bits : bytes
567567) -> bytes :
568568 assert len (salt ) == SALT_BYTES
569569 assert len (key ) == KEY_BYTES
@@ -581,7 +581,7 @@ def _make_cookie(
581581
582582
583583def valid_cookie (
584- key : bytes , cookie : bytes , address : Address , client_hello_bits : bytes
584+ key : bytes , cookie : bytes , address : Any , client_hello_bits : bytes
585585) -> bool :
586586 if len (cookie ) > SALT_BYTES :
587587 salt = cookie [:SALT_BYTES ]
@@ -603,7 +603,7 @@ def valid_cookie(
603603
604604
605605def challenge_for (
606- key : bytes , address : Address , epoch_seqno : int , client_hello_bits : bytes
606+ key : bytes , address : Any , epoch_seqno : int , client_hello_bits : bytes
607607) -> bytes :
608608 salt = os .urandom (SALT_BYTES )
609609 tick = _current_cookie_tick ()
@@ -664,7 +664,7 @@ def _read_loop(read_fn: Callable[[int], bytes]) -> bytes:
664664
665665
666666async def handle_client_hello_untrusted (
667- endpoint : DTLSEndpoint , address : Address , packet : bytes
667+ endpoint : DTLSEndpoint , address : Any , packet : bytes
668668) -> None :
669669 if endpoint ._listening_context is None :
670670 return
@@ -739,7 +739,7 @@ async def handle_client_hello_untrusted(
739739
740740
741741async def dtls_receive_loop (
742- endpoint_ref : ReferenceType [DTLSEndpoint ], sock : _SocketType
742+ endpoint_ref : ReferenceType [DTLSEndpoint ], sock : SocketType
743743) -> None :
744744 try :
745745 while True :
@@ -829,7 +829,7 @@ class DTLSChannel(trio.abc.Channel[bytes], metaclass=NoPublicConstructor):
829829
830830 """
831831
832- def __init__ (self , endpoint : DTLSEndpoint , peer_address : Address , ctx : Context ):
832+ def __init__ (self , endpoint : DTLSEndpoint , peer_address : Any , ctx : Context ):
833833 self .endpoint = endpoint
834834 self .peer_address = peer_address
835835 self ._packets_dropped_in_trio = 0
@@ -1180,7 +1180,7 @@ class DTLSEndpoint:
11801180
11811181 """
11821182
1183- def __init__ (self , socket : _SocketType , * , incoming_packets_buffer : int = 10 ):
1183+ def __init__ (self , socket : SocketType , * , incoming_packets_buffer : int = 10 ):
11841184 # We do this lazily on first construction, so only people who actually use DTLS
11851185 # have to install PyOpenSSL.
11861186 global SSL
@@ -1191,7 +1191,7 @@ def __init__(self, socket: _SocketType, *, incoming_packets_buffer: int = 10):
11911191 if socket .type != trio .socket .SOCK_DGRAM :
11921192 raise ValueError ("DTLS requires a SOCK_DGRAM socket" )
11931193 self ._initialized = True
1194- self .socket : _SocketType = socket
1194+ self .socket : SocketType = socket
11951195
11961196 self .incoming_packets_buffer = incoming_packets_buffer
11971197 self ._token = trio .lowlevel .current_trio_token ()
@@ -1200,7 +1200,7 @@ def __init__(self, socket: _SocketType, *, incoming_packets_buffer: int = 10):
12001200 # as a peer provides a valid cookie, we can immediately tear down the
12011201 # old connection.
12021202 # {remote address: DTLSChannel}
1203- self ._streams : WeakValueDictionary [Address , DTLSChannel ] = WeakValueDictionary ()
1203+ self ._streams : WeakValueDictionary [Any , DTLSChannel ] = WeakValueDictionary ()
12041204 self ._listening_context : Context | None = None
12051205 self ._listening_key : bytes | None = None
12061206 self ._incoming_connections_q = _Queue [DTLSChannel ](float ("inf" ))
0 commit comments