mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 06:48:16 +00:00
Adding bridge transport to TrezorDevice, using as default transport
This commit is contained in:
parent
562a19c812
commit
03a11450c1
@ -17,6 +17,7 @@
|
|||||||
# along with this library. If not, see <http://www.gnu.org/licenses/>.
|
# along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
from .transport_bridge import BridgeTransport
|
||||||
from .transport_hid import HidTransport
|
from .transport_hid import HidTransport
|
||||||
from .transport_udp import UdpTransport
|
from .transport_udp import UdpTransport
|
||||||
from .transport_webusb import WebUsbTransport
|
from .transport_webusb import WebUsbTransport
|
||||||
@ -27,6 +28,9 @@ class TrezorDevice(object):
|
|||||||
def enumerate(cls):
|
def enumerate(cls):
|
||||||
devices = []
|
devices = []
|
||||||
|
|
||||||
|
for d in BridgeTransport.enumerate():
|
||||||
|
devices.append(d)
|
||||||
|
|
||||||
for d in UdpTransport.enumerate():
|
for d in UdpTransport.enumerate():
|
||||||
devices.append(d)
|
devices.append(d)
|
||||||
|
|
||||||
@ -46,9 +50,11 @@ class TrezorDevice(object):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
raise Exception("No TREZOR device found")
|
raise Exception("No TREZOR device found")
|
||||||
|
|
||||||
|
|
||||||
prefix = path.split(':')[0]
|
prefix = path.split(':')[0]
|
||||||
|
|
||||||
|
if prefix == BridgeTransport.PATH_PREFIX:
|
||||||
|
return BridgeTransport.find_by_path(path)
|
||||||
|
|
||||||
if prefix == UdpTransport.PATH_PREFIX:
|
if prefix == UdpTransport.PATH_PREFIX:
|
||||||
return UdpTransport.find_by_path(path)
|
return UdpTransport.find_by_path(path)
|
||||||
|
|
||||||
|
@ -41,6 +41,8 @@ class BridgeTransport(Transport):
|
|||||||
BridgeTransport implements transport through TREZOR Bridge (aka trezord).
|
BridgeTransport implements transport through TREZOR Bridge (aka trezord).
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
PATH_PREFIX = 'bridge'
|
||||||
|
|
||||||
def __init__(self, device):
|
def __init__(self, device):
|
||||||
super(BridgeTransport, self).__init__()
|
super(BridgeTransport, self).__init__()
|
||||||
|
|
||||||
@ -50,17 +52,21 @@ class BridgeTransport(Transport):
|
|||||||
self.response = None
|
self.response = None
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.device['path']
|
return '%s:%s' % (self.PATH_PREFIX, self.device['path'])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def enumerate():
|
def enumerate():
|
||||||
r = requests.post(TREZORD_HOST + '/enumerate')
|
try:
|
||||||
if r.status_code != 200:
|
r = requests.post(TREZORD_HOST + '/enumerate')
|
||||||
raise TransportException('trezord: Could not enumerate devices' + get_error(r))
|
if r.status_code != 200:
|
||||||
return [BridgeTransport(dev) for dev in r.json()]
|
raise TransportException('trezord: Could not enumerate devices' + get_error(r))
|
||||||
|
return [BridgeTransport(dev) for dev in r.json()]
|
||||||
|
except:
|
||||||
|
return []
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def find_by_path(path):
|
def find_by_path(cls, path):
|
||||||
|
path = path.replace('%s:' % cls.PATH_PREFIX, '')
|
||||||
for transport in BridgeTransport.enumerate():
|
for transport in BridgeTransport.enumerate():
|
||||||
if path is None or transport.device['path'] == path:
|
if path is None or transport.device['path'] == path:
|
||||||
return transport
|
return transport
|
||||||
|
Loading…
Reference in New Issue
Block a user