mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-18 12:38:37 +00:00
Configure Bridge only once per process (#107)
This saves a lot of time on requests retrieving config_signed.bin and reconfiguring the bridge for every device enumeration or transport instantiation.
This commit is contained in:
parent
3cb4118850
commit
637d45b196
@ -32,6 +32,8 @@ def get_error(resp):
|
|||||||
return ' (error=%d str=%s)' % (resp.status_code, resp.json()['error'])
|
return ' (error=%d str=%s)' % (resp.status_code, resp.json()['error'])
|
||||||
|
|
||||||
class BridgeTransport(TransportV1):
|
class BridgeTransport(TransportV1):
|
||||||
|
CONFIGURED = False
|
||||||
|
|
||||||
def __init__(self, device, *args, **kwargs):
|
def __init__(self, device, *args, **kwargs):
|
||||||
self.configure()
|
self.configure()
|
||||||
|
|
||||||
@ -45,6 +47,7 @@ class BridgeTransport(TransportV1):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def configure():
|
def configure():
|
||||||
|
if BridgeTransport.CONFIGURED: return
|
||||||
r = requests.get(CONFIG_URL, verify=False)
|
r = requests.get(CONFIG_URL, verify=False)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise Exception('Could not fetch config from %s' % CONFIG_URL)
|
raise Exception('Could not fetch config from %s' % CONFIG_URL)
|
||||||
@ -54,6 +57,7 @@ class BridgeTransport(TransportV1):
|
|||||||
r = requests.post(TREZORD_HOST + '/configure', data=config)
|
r = requests.post(TREZORD_HOST + '/configure', data=config)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise Exception('trezord: Could not configure' + get_error(r))
|
raise Exception('trezord: Could not configure' + get_error(r))
|
||||||
|
BridgeTransport.CONFIGURED = True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def enumerate(cls):
|
def enumerate(cls):
|
||||||
|
Loading…
Reference in New Issue
Block a user