From d4addeedd6b115d35e79a31c7f385fd22717296e Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Sun, 20 May 2018 22:35:43 +0100 Subject: [PATCH] [UI] Fix non-unique hostlist host_id Use a sha1 of time.time() can result in identical host_id. This was evident with Travis tests randomly failing due to host_id collision returning the wrong host details. Using uuid4 to generate a random UUID in hex form should fix this issue. --- ChangeLog | 1 + deluge/ui/hostlist.py | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4bc14ee51..badc7562c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ there to allow acting upon them. * Enforced the use of the "deluge.plugins" namespace to reduce package names clashing beetween regular packages and deluge plugins. + * Fix potential for host_id collision when creating hostlist entries. ==== Core ==== * Make the distinction between adding to the session new unmanaged torrents diff --git a/deluge/ui/hostlist.py b/deluge/ui/hostlist.py index fa6155538..10d7063b5 100644 --- a/deluge/ui/hostlist.py +++ b/deluge/ui/hostlist.py @@ -11,8 +11,7 @@ from __future__ import unicode_literals import logging import os -import time -from hashlib import sha1 +import uuid from socket import gaierror, gethostbyname from twisted.internet import defer @@ -31,7 +30,7 @@ LOCALHOST = ('127.0.0.1', 'localhost') def default_hostlist(): """Create a new hosts key for hostlist with a localhost entry""" - host_id = sha1(str(time.time()).encode('utf8')).hexdigest() + host_id = uuid.uuid4().hex username, password = get_localhost_auth() return {'hosts': [(host_id, DEFAULT_HOST, DEFAULT_PORT, username, password)]} @@ -132,7 +131,7 @@ class HostList(object): validate_host_info(hostname, port) self.check_info_exists(hostname, port, username) - host_id = sha1(str(time.time())).hexdigest() + host_id = uuid.uuid4().hex self.config['hosts'].append((host_id, hostname, port, username, password)) self.config.save() return host_id