Merge branch 'incoming'

master
Ray 2017-04-27 14:14:32 -07:00
commit 41a71fccd9
4 changed files with 32 additions and 4 deletions

View File

@ -1,3 +1,11 @@
2017-04-27 Ray Brown <code@liquibits.com>
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 <code@liquibits.com>
Release 1.2.2

View File

@ -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():
"""

View File

@ -72,14 +72,27 @@ 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,
keyfile=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

View File

@ -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: