Skip to content

Commit

Permalink
[package] Use pyOpenSSL >= 23.1.0 which supports DTLS timeouts
Browse files Browse the repository at this point in the history
Support for DTLS timeouts was contributed upstream in PR
pyca/pyopenssl#1180 which was released in
version 23.1.0, so we can remove our local implementation.
  • Loading branch information
jlaine authored and mametaro99 committed May 11, 2024
1 parent 2a7367f commit bb58fef
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"google-crc32c>=1.1",
"pyee>=9.0.0",
"pylibsrtp>=0.5.6",
"pyopenssl>=23.0.0",
"pyopenssl>=23.1.0",
]

extras_require = {
Expand Down
17 changes: 2 additions & 15 deletions src/aiortc/rtcdtlstransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,6 @@
logger = logging.getLogger(__name__)


def DTLSv1_get_timeout(self):
ptv_sec = SSL._ffi.new("time_t *")
ptv_usec = SSL._ffi.new("long *")
if SSL._lib.Cryptography_DTLSv1_get_timeout(self._ssl, ptv_sec, ptv_usec):
return ptv_sec[0] + (ptv_usec[0] / 1000000)
else:
return None


def DTLSv1_handle_timeout(self):
SSL._lib.DTLSv1_handle_timeout(self._ssl)


def certificate_digest(x509: crypto.X509) -> str:
return x509.digest("SHA256").decode("ascii")

Expand Down Expand Up @@ -515,15 +502,15 @@ async def _recv_next(self) -> None:
# get timeout
timeout = None
if not self.encrypted:
timeout = DTLSv1_get_timeout(self.ssl)
timeout = self.ssl.DTLSv1_get_timeout()

# receive next datagram
if timeout is not None:
try:
data = await asyncio.wait_for(self.transport._recv(), timeout=timeout)
except asyncio.TimeoutError:
self.__log_debug("x DTLS handling timeout")
DTLSv1_handle_timeout(self.ssl)
self.ssl.DTLSv1_handle_timeout()
await self._write_ssl()
return
else:
Expand Down

0 comments on commit bb58fef

Please sign in to comment.