remove obsolete pipe transport

This commit is contained in:
Pavol Rusnak 2017-01-09 16:38:22 +01:00
parent 3aa18c1f2b
commit d7ce51e858
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
4 changed files with 5 additions and 123 deletions

View File

@ -19,6 +19,8 @@ setup(
py_modules=[
'trezorlib.ckd_public',
'trezorlib.client',
'trezorlib.connection_hid',
'trezorlib.connection_udp',
'trezorlib.debuglink',
'trezorlib.mapping',
'trezorlib.messages_pb2',
@ -27,9 +29,8 @@ setup(
'trezorlib.tools',
'trezorlib.transport',
'trezorlib.transport_bridge',
'trezorlib.transport_hid',
'trezorlib.transport_pipe',
'trezorlib.transport_udp',
'trezorlib.transport_v1',
'trezorlib.transport_v2',
'trezorlib.tx_api',
'trezorlib.types_pb2',
],

View File

@ -21,18 +21,9 @@ from __future__ import print_function
import sys
sys.path = ['../../'] + sys.path
from trezorlib.transport_pipe import PipeTransport
from trezorlib.transport_hid import HidTransport
from trezorlib.transport_udp import UdpTransport
def pipe_exists(path):
import os
try:
os.stat(path)
return True
except:
return False
devices = HidTransport.enumerate()
if len(devices) > 0:
@ -44,15 +35,6 @@ if len(devices) > 0:
DEBUG_TRANSPORT_ARGS = (devices[0],)
DEBUG_TRANSPORT_KWARGS = {'debug_link': True}
elif pipe_exists('/tmp/pipe.trezor.to'):
print('Using Emulator (v1=pipe)')
TRANSPORT = PipeTransport
TRANSPORT_ARGS = ('/tmp/pipe.trezor', False)
TRANSPORT_KWARGS = {}
DEBUG_TRANSPORT = PipeTransport
DEBUG_TRANSPORT_ARGS = ('/tmp/pipe.trezor_debug', False)
DEBUG_TRANSPORT_KWARGS = {}
elif True:
print('Using Emulator (v2=udp)')
TRANSPORT = UdpTransport

View File

@ -57,7 +57,7 @@ ether_units = {
def init_parser(commands):
parser = argparse.ArgumentParser(description='Commandline tool for TREZOR devices.')
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='Prints communication to device')
parser.add_argument('-t', '--transport', dest='transport', choices=['hid', 'udp', 'pipe', 'bridge'], default='hid', help="Transport used for talking with the device")
parser.add_argument('-t', '--transport', dest='transport', choices=['hid', 'udp', 'bridge'], default='hid', help="Transport used for talking with the device")
parser.add_argument('-w', '--protocol', dest='protocol', choices=['v1', 'v2'], default='', help="Wire protocol used for talking with the device")
parser.add_argument('-p', '--path', dest='path', default='', help="Path used by the transport")
parser.add_argument('-j', '--json', dest='json', action='store_true', help="Prints result as json object")
@ -112,15 +112,6 @@ def get_transport(transport_string, protocol_string, path):
else: # default is v2
return TransportV2(UdpConnection(path))
if transport_string == 'pipe':
from trezorlib.connection_pipe import PipeConnection
if path == '':
path = '/tmp/pipe.trezor'
if protocol_string == 'v2':
return TransportV2(PipeConnection(path, is_device=False))
else: # default is v1
return TransportV1(PipeConnection(path, is_device=False))
if transport_string == 'bridge':
from trezorlib.transport_bridge import TransportBridge

View File

@ -1,92 +0,0 @@
# This file is part of the TREZOR project.
#
# Copyright (C) 2012-2016 Marek Palatinus <slush@satoshilabs.com>
# Copyright (C) 2012-2016 Pavol Rusnak <stick@satoshilabs.com>
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import os
import time
"""PipeConnection implements fake wire connection over local named pipe.
Use this connection for talking with trezor simulator."""
class PipeConnection(object):
def __init__(self, device, is_device):
self.device = device
self.is_device = is_device # Set True if act as device
self.filename_read = None
self.filename_write = None
self.write_fd = None
self.write_f = None
self.read_fd = None
self.read_f = None
def open(self):
if self.is_device:
self.filename_read = self.device+'.to'
self.filename_write = self.device+'.from'
os.mkfifo(self.filename_read, 0o600)
os.mkfifo(self.filename_write, 0o600)
else:
self.filename_read = self.device+'.from'
self.filename_write = self.device+'.to'
if not os.path.exists(self.filename_write):
raise Exception("Not connected")
self.write_fd = os.open(self.filename_write, os.O_RDWR)#|os.O_NONBLOCK)
self.write_f = os.fdopen(self.write_fd, 'w+b', 0)
self.read_fd = os.open(self.filename_read, os.O_RDWR)#|os.O_NONBLOCK)
self.read_f = os.fdopen(self.read_fd, 'rb', 0)
def close(self):
self.read_f.close()
self.write_f.close()
if self.is_device:
os.unlink(self.filename_read)
os.unlink(self.filename_write)
def write_chunk(self, chunk):
if len(chunk) != 64:
raise Exception("Unexpected data length")
try:
self.write_f.write(chunk)
self.write_f.flush()
except OSError:
print("Error while writing to socket")
raise
def read_chunk(self):
while True:
try:
data = self.read_f.read(64)
except IOError:
print("Failed to read from device")
raise
if not len(data):
time.sleep(0.001)
continue
break
if len(data) != 64:
raise Exception("Unexpected chunk size: %d" % len(data))
return bytearray(data)