[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.
This commit is contained in:
Calum Lind 2018-05-20 22:35:43 +01:00
parent 8439698336
commit d4addeedd6
2 changed files with 4 additions and 4 deletions

View File

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

View File

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