Trezor: session timeout improvements
Move session timeout from wallet to config Prevent timeouts whenever a device operation is in progress Move timeout job from each plugin to device manager
This commit is contained in:
@@ -45,8 +45,9 @@ class Plugins(DaemonThread):
|
||||
self.plugins = {}
|
||||
self.gui_name = gui_name
|
||||
self.descriptions = {}
|
||||
self.device_manager = DeviceMgr()
|
||||
self.device_manager = DeviceMgr(config)
|
||||
self.load_plugins()
|
||||
self.add_jobs(self.device_manager.thread_jobs())
|
||||
self.start()
|
||||
|
||||
def load_plugins(self):
|
||||
@@ -247,7 +248,7 @@ class DeviceUnpairableError(Exception):
|
||||
Device = namedtuple("Device", "path interface_number id_ product_key")
|
||||
DeviceInfo = namedtuple("DeviceInfo", "device description initialized")
|
||||
|
||||
class DeviceMgr(PrintError):
|
||||
class DeviceMgr(ThreadJob, PrintError):
|
||||
'''Manages hardware clients. A client communicates over a hardware
|
||||
channel with the device.
|
||||
|
||||
@@ -276,11 +277,9 @@ class DeviceMgr(PrintError):
|
||||
the HID IDs.
|
||||
|
||||
This plugin is thread-safe. Currently only devices supported by
|
||||
hidapi are implemented.
|
||||
hidapi are implemented.'''
|
||||
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, config):
|
||||
super(DeviceMgr, self).__init__()
|
||||
# Keyed by wallet. The value is the device id if the wallet
|
||||
# has been paired, and None otherwise.
|
||||
@@ -293,6 +292,20 @@ class DeviceMgr(PrintError):
|
||||
self.recognised_hardware = set()
|
||||
# For synchronization
|
||||
self.lock = threading.RLock()
|
||||
self.config = config
|
||||
|
||||
def thread_jobs(self):
|
||||
# Thread job to handle device timeouts
|
||||
return [self]
|
||||
|
||||
def run(self):
|
||||
'''Handle device timeouts. Runs in the context of the Plugins
|
||||
thread.'''
|
||||
with self.lock:
|
||||
clients = list(self.clients.keys())
|
||||
cutoff = time.time() - self.config.get_session_timeout()
|
||||
for client in clients:
|
||||
client.timeout(cutoff)
|
||||
|
||||
def register_devices(self, device_pairs):
|
||||
for pair in device_pairs:
|
||||
@@ -343,9 +356,6 @@ class DeviceMgr(PrintError):
|
||||
self.wallets[wallet] = id_
|
||||
wallet.paired()
|
||||
|
||||
def paired_wallets(self):
|
||||
return list(self.wallets.keys())
|
||||
|
||||
def client_lookup(self, id_):
|
||||
with self.lock:
|
||||
for client, (path, client_id) in self.clients.items():
|
||||
|
||||
@@ -4,7 +4,7 @@ import threading
|
||||
import os
|
||||
|
||||
from copy import deepcopy
|
||||
from util import user_dir, print_error, print_msg, print_stderr
|
||||
from util import user_dir, print_error, print_msg, print_stderr, PrintError
|
||||
|
||||
SYSTEM_CONFIG_PATH = "/etc/electrum.conf"
|
||||
|
||||
@@ -21,7 +21,7 @@ def set_config(c):
|
||||
config = c
|
||||
|
||||
|
||||
class SimpleConfig(object):
|
||||
class SimpleConfig(PrintError):
|
||||
"""
|
||||
The SimpleConfig class is responsible for handling operations involving
|
||||
configuration files.
|
||||
@@ -168,6 +168,13 @@ class SimpleConfig(object):
|
||||
recent.remove(filename)
|
||||
self.set_key('recently_open', recent)
|
||||
|
||||
def set_session_timeout(self, seconds):
|
||||
self.print_error("session timeout -> %d seconds" % seconds)
|
||||
self.set_key('session_timeout', seconds)
|
||||
|
||||
def get_session_timeout(self):
|
||||
return self.get('session_timeout', 300)
|
||||
|
||||
|
||||
def read_system_config(path=SYSTEM_CONFIG_PATH):
|
||||
"""Parse and return the system config settings in /etc/electrum.conf."""
|
||||
|
||||
Reference in New Issue
Block a user