mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
Added session depth
This commit is contained in:
parent
8e5abb560e
commit
813fb233a1
@ -64,6 +64,9 @@ class BitkeyClient(object):
|
||||
print '----------------------'
|
||||
print "Sending", self._pprint(msg)
|
||||
|
||||
try:
|
||||
self.transport.session_begin()
|
||||
|
||||
self.transport.write(msg)
|
||||
resp = self.transport.read_blocking()
|
||||
|
||||
@ -87,6 +90,9 @@ class BitkeyClient(object):
|
||||
|
||||
return self.call(msg2)
|
||||
|
||||
finally:
|
||||
self.transport.session_end()
|
||||
|
||||
if isinstance(resp, proto.Failure):
|
||||
self.message_func(resp.message)
|
||||
|
||||
@ -132,6 +138,9 @@ class BitkeyClient(object):
|
||||
|
||||
start = time.time()
|
||||
|
||||
try:
|
||||
self.transport.session_begin()
|
||||
|
||||
# Prepare and send initial message
|
||||
tx = proto.SignTx()
|
||||
tx.inputs_count = len(inputs)
|
||||
@ -175,6 +184,9 @@ class BitkeyClient(object):
|
||||
res = self.call(inputs[res.request_index])
|
||||
continue
|
||||
|
||||
finally:
|
||||
self.transport.session_end()
|
||||
|
||||
print "SIGNED IN %.03f SECONDS, CALLED %d MESSAGES, %d BYTES" % \
|
||||
(time.time() - start, counter, len(serialized_tx))
|
||||
|
||||
|
@ -7,6 +7,7 @@ class NotImplementedException(Exception):
|
||||
class Transport(object):
|
||||
def __init__(self, device, *args, **kwargs):
|
||||
self.device = device
|
||||
self.session_depth = 0
|
||||
self._open()
|
||||
|
||||
def _open(self):
|
||||
@ -21,9 +22,26 @@ class Transport(object):
|
||||
def _read(self):
|
||||
raise NotImplementedException("Not implemented")
|
||||
|
||||
def _session_begin(self):
|
||||
pass
|
||||
|
||||
def _session_end(self):
|
||||
pass
|
||||
|
||||
def ready_to_read(self):
|
||||
raise NotImplementedException("Not implemented")
|
||||
|
||||
def session_begin(self):
|
||||
if self.session_depth == 0:
|
||||
self._session_begin()
|
||||
self.session_depth += 1
|
||||
|
||||
def session_end(self):
|
||||
self.session_depth -= 1
|
||||
self.session_depth = max(0, self.session_depth)
|
||||
if self.session_depth == 0:
|
||||
self._session_end()
|
||||
|
||||
def close(self):
|
||||
self._close()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user