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:
@@ -33,18 +33,11 @@ class BIP44_HW_Wallet(BIP44_Wallet):
|
||||
|
||||
def __init__(self, storage):
|
||||
BIP44_Wallet.__init__(self, storage)
|
||||
# After timeout seconds we clear the device session
|
||||
self.session_timeout = storage.get('session_timeout', 180)
|
||||
# Errors and other user interaction is done through the wallet's
|
||||
# handler. The handler is per-window and preserved across
|
||||
# device reconnects
|
||||
self.handler = None
|
||||
|
||||
def set_session_timeout(self, seconds):
|
||||
self.print_error("setting session timeout to %d seconds" % seconds)
|
||||
self.session_timeout = seconds
|
||||
self.storage.put('session_timeout', seconds)
|
||||
|
||||
def unpaired(self):
|
||||
'''A device paired with the wallet was diconnected. This can be
|
||||
called in any thread context.'''
|
||||
@@ -55,14 +48,6 @@ class BIP44_HW_Wallet(BIP44_Wallet):
|
||||
called in any thread context.'''
|
||||
self.print_error("paired")
|
||||
|
||||
def timeout(self):
|
||||
'''Called when the wallet session times out. Note this is called from
|
||||
the Plugins thread.'''
|
||||
client = self.get_client(force_pair=False)
|
||||
if client:
|
||||
client.clear_session()
|
||||
self.print_error("timed out")
|
||||
|
||||
def get_action(self):
|
||||
pass
|
||||
|
||||
|
||||
@@ -17,14 +17,11 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import time
|
||||
|
||||
from electrum.util import ThreadJob
|
||||
from electrum.plugins import BasePlugin, hook
|
||||
from electrum.i18n import _
|
||||
|
||||
|
||||
class HW_PluginBase(BasePlugin, ThreadJob):
|
||||
class HW_PluginBase(BasePlugin):
|
||||
# Derived classes provide:
|
||||
#
|
||||
# class-static variables: client_class, firmware_URL, handler_class,
|
||||
@@ -35,7 +32,6 @@ class HW_PluginBase(BasePlugin, ThreadJob):
|
||||
BasePlugin.__init__(self, parent, config, name)
|
||||
self.device = self.wallet_class.device
|
||||
self.wallet_class.plugin = self
|
||||
self.prevent_timeout = time.time() + 3600 * 24 * 365
|
||||
|
||||
def is_enabled(self):
|
||||
return self.libraries_available
|
||||
@@ -43,21 +39,6 @@ class HW_PluginBase(BasePlugin, ThreadJob):
|
||||
def device_manager(self):
|
||||
return self.parent.device_manager
|
||||
|
||||
def thread_jobs(self):
|
||||
# Thread job to handle device timeouts
|
||||
return [self] if self.libraries_available else []
|
||||
|
||||
def run(self):
|
||||
'''Handle device timeouts. Runs in the context of the Plugins
|
||||
thread.'''
|
||||
now = time.time()
|
||||
for wallet in self.device_manager().paired_wallets():
|
||||
if (isinstance(wallet, self.wallet_class)
|
||||
and hasattr(wallet, 'last_operation')
|
||||
and now > wallet.last_operation + wallet.session_timeout):
|
||||
wallet.timeout()
|
||||
wallet.last_operation = self.prevent_timeout
|
||||
|
||||
@hook
|
||||
def close_wallet(self, wallet):
|
||||
if isinstance(wallet, self.wallet_class):
|
||||
|
||||
Reference in New Issue
Block a user