From 80d05b7d82b334e05892beb01d0265650e2f9eaa Mon Sep 17 00:00:00 2001 From: Jason Youzwak Date: Wed, 26 Apr 2017 20:04:45 -0400 Subject: [PATCH 1/2] Add optional parameter to DtlsSocket: client_timeout (seconds) If client_timeout is specified, clients that have not communicated within the time frame will be dropped. --- dtls/wrapper.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/dtls/wrapper.py b/dtls/wrapper.py index 3a53d26..cdb267c 100644 --- a/dtls/wrapper.py +++ b/dtls/wrapper.py @@ -72,13 +72,26 @@ class DtlsSocket(object): class _ClientSession(object): - def __init__(self, host, port, handshake_done=False): + def __init__(self, host, port, handshake_done=False, timeout=None): self.host = host self.port = int(port) self.handshake_done = handshake_done + self.timeout = timeout + self.updateTimestamp() def getAddr(self): return self.host, self.port + + def updateTimestamp(self): + if self.timeout != None: + self.last_update = time.time() + + def expired(self): + if self.timeout == None: + return False + else: + return (time.time() - self.last_update) > self.timeout + def __init__(self, sock=None, @@ -95,7 +108,8 @@ class DtlsSocket(object): sigalgs=None, user_mtu=None, server_key_exchange_curve=None, - server_cert_options=ssl.SSL_BUILD_CHAIN_FLAG_NONE): + server_cert_options=ssl.SSL_BUILD_CHAIN_FLAG_NONE, + client_timeout=None): if server_cert_options is None: server_cert_options = ssl.SSL_BUILD_CHAIN_FLAG_NONE @@ -108,6 +122,7 @@ class DtlsSocket(object): self._user_mtu = user_mtu self._server_key_exchange_curve = server_key_exchange_curve self._server_cert_options = server_cert_options + self._client_timeout = client_timeout # Default socket creation _sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) @@ -205,6 +220,7 @@ class DtlsSocket(object): else: buf = self._clientRead(conn, bufsize) if buf: + self._clients[conn].updateTimestamp() if conn in self._clients: return buf, self._clients[conn].getAddr() else: @@ -220,6 +236,10 @@ class DtlsSocket(object): ret = conn.handle_timeout() _logger.debug('Retransmission triggered for %s: %d' % (str(self._clients[conn].getAddr()), ret)) + if self._clients[conn].expired() == True: + _logger.debug('Found expired session') + self._clientDrop(conn) + except Exception as e: raise e From 7cda052bacfa63ff2bbe1f450986101e2d3e76e6 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 27 Apr 2017 13:53:12 -0700 Subject: [PATCH 2/2] Release 1.2.3 * dtls/wrapper.py: Add optional parameter to DtlsSocket: client_timeout (seconds). If client_timeout is specified, clients that have not communicated within the time frame will be dropped. * setup.py: Version incremented to 1.2.3 * dtls/__init__.py: Increment version --- ChangeLog | 8 ++++++++ dtls/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1f9cf30..4b9c9ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2017-04-27 Ray Brown + + Release 1.2.3 + + * dtls/wrapper.py: Add optional parameter to DtlsSocket: client_timeout (seconds). If client_timeout is specified, clients that have not communicated within the time frame will be dropped. + * setup.py: Version incremented to 1.2.3 + * dtls/__init__.py: Increment version + 2017-04-10 Ray Brown Release 1.2.2 diff --git a/dtls/__init__.py b/dtls/__init__.py index 7ea8c6e..8b122cd 100644 --- a/dtls/__init__.py +++ b/dtls/__init__.py @@ -32,7 +32,7 @@ sockets. wrap_socket's parameters and their semantics have been maintained. """ -VERSION = 1, 2, 2 +VERSION = 1, 2, 3 def _prep_bins(): """ diff --git a/setup.py b/setup.py index aaa4a7e..cd5f035 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ from pickle import dump, load from setuptools import setup NAME = "Dtls" -VERSION = "1.2.2" +VERSION = "1.2.3" if __name__ == "__main__": # Full upload sequence for new version: