#include <transport.hpp>
Definition at line 162 of file transport.hpp.
◆ BridgeTransport()
| hw::trezor::BridgeTransport::BridgeTransport |
( |
boost::optional< std::string > |
device_path = boost::none, |
|
|
boost::optional< std::string > |
bridge_host = boost::none |
|
) |
| |
Definition at line 315 of file transport.cpp.
318 m_device_path(device_path),
320 m_response(boost::none),
321 m_session(boost::none),
322 m_device_info(boost::none)
324 const char *env_bridge_port =
nullptr;
325 if (!bridge_host && (env_bridge_port = getenv(
"TREZOR_BRIDGE_PORT")) !=
nullptr)
329 assert_port_number(bridge_port);
331 m_bridge_host =
std::string(
"127.0.0.1:") + boost::lexical_cast<std::string>(env_bridge_port);
332 MDEBUG(
"Bridge host: " << m_bridge_host);
bool set_server(const std::string &address, boost::optional< login > user, ssl_options_t ssl_options=ssl_support_t::e_ssl_support_autodetect)
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
const std::string DEFAULT_BRIDGE
◆ ~BridgeTransport()
| virtual hw::trezor::BridgeTransport::~BridgeTransport |
( |
| ) |
|
|
virtualdefault |
◆ close()
| void hw::trezor::BridgeTransport::close |
( |
| ) |
|
|
overridevirtual |
Reimplemented from hw::trezor::Transport.
Definition at line 404 of file transport.cpp.
409 MTRACE(
"Closing Trezor:BridgeTransport");
410 if (!m_device_path || !m_session){
411 throw exc::CommunicationException(
"Device not open");
419 throw exc::CommunicationException(
"Failed to release device");
422 m_session = boost::none;
bool invoke_bridge_http(const boost::string_ref uri, const t_req &out_struct, t_res &result_struct, t_transport &transport, const boost::string_ref method="POST", std::chrono::milliseconds timeout=std::chrono::seconds(180))
◆ device_info()
| const boost::optional< json > & hw::trezor::BridgeTransport::device_info |
( |
| ) |
const |
◆ dump()
| std::ostream & hw::trezor::BridgeTransport::dump |
( |
std::ostream & |
o | ) |
const |
|
overridevirtual |
Reimplemented from hw::trezor::Transport.
Definition at line 480 of file transport.cpp.
481 return o <<
"BridgeTransport<path=" << (m_device_path ?
get_path() :
"None")
482 <<
", info=" << (m_device_info ?
t_serialize(m_device_info.
get()) :
"None")
483 <<
", session=" << (m_session ? m_session.
get() :
"None")
std::string get_path() const override
void get(std::istream &input, bool &res)
bool t_serialize(const std::string &in, std::string &out)
◆ enumerate()
Reimplemented from hw::trezor::Transport.
Definition at line 347 of file transport.cpp.
353 throw exc::CommunicationException(
"Bridge enumeration failed");
357 auto element = itr->GetObject();
358 auto t = std::make_shared<BridgeTransport>(boost::make_optional(json_get_string(element[
"path"])));
360 auto itr_vendor = element.FindMember(
"vendor");
361 auto itr_product = element.FindMember(
"product");
362 if (itr_vendor != element.MemberEnd() && itr_product != element.MemberEnd()
363 && itr_vendor->value.IsNumber() && itr_product->value.IsNumber()){
365 const auto id_vendor = (
uint16_t) itr_vendor->value.GetUint64();
366 const auto id_product = (
uint16_t) itr_product->value.GetUint64();
367 const auto device_idx = get_device_idx(id_vendor, id_product);
368 if (!is_device_supported(device_idx)){
369 MDEBUG(
"Device with idx " << device_idx <<
" is not supported. Vendor: " << id_vendor <<
", product: " << id_product);
372 }
catch(
const std::exception &e){
373 MERROR(
"Could not detect vendor & product: " << e.what());
377 t->m_device_info.emplace();
378 t->m_device_info->CopyFrom(*itr, t->m_device_info->GetAllocator());
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
◆ get_path()
| std::string hw::trezor::BridgeTransport::get_path |
( |
| ) |
const |
|
overridevirtual |
◆ open()
| void hw::trezor::BridgeTransport::open |
( |
| ) |
|
|
overridevirtual |
Reimplemented from hw::trezor::Transport.
Definition at line 383 of file transport.cpp.
389 throw exc::CommunicationException(
"Coud not open, empty device path");
392 std::string uri =
"/acquire/" + m_device_path.get() +
"/null";
397 throw exc::CommunicationException(
"Failed to acquire device");
400 m_session = boost::make_optional(json_get_string(bridge_res[
"session"]));
◆ read()
| void hw::trezor::BridgeTransport::read |
( |
std::shared_ptr< google::protobuf::Message > & |
msg, |
|
|
messages::MessageType * |
msg_type = nullptr |
|
) |
| |
|
overridevirtual |
Implements hw::trezor::Transport.
Definition at line 448 of file transport.cpp.
450 throw exc::CommunicationException(
"Could not read, no response stored");
455 throw exc::CommunicationException(
"Response is not well hexcoded");
460 deserialize_message_header(bin_data.c_str(), msg_tag, msg_len);
461 if (bin_data.size() != msg_len + 6){
462 throw exc::CommunicationException(
"Response is not well hexcoded");
466 *msg_type =
static_cast<messages::MessageType
>(msg_tag);
470 if (!msg_wrap->ParseFromArray(bin_data.c_str() + 6, msg_len)){
471 throw exc::EncodingException(
"Response is not well hexcoded");
::google::protobuf::Message * get_message(int wire_number)
◆ write()
| void hw::trezor::BridgeTransport::write |
( |
const google::protobuf::Message & |
req | ) |
|
|
overridevirtual |
Implements hw::trezor::Transport.
Definition at line 425 of file transport.cpp.
426 m_response = boost::none;
428 const auto msg_size = message_size(req);
429 const auto buff_size = serialize_message_buffer_size(msg_size);
431 std::unique_ptr<uint8_t[]> req_buff(
new uint8_t[buff_size]);
432 uint8_t * req_buff_raw = req_buff.get();
434 serialize_message(req, msg_size, req_buff_raw, buff_size);
442 throw exc::CommunicationException(
"Call method failed");
445 m_response = res_hex;
static std::string string(const span< const std::uint8_t > src)
◆ PATH_PREFIX
| const char * hw::trezor::BridgeTransport::PATH_PREFIX = "bridge:" |
|
static |
The documentation for this class was generated from the following files:
- /home/abuild/rpmbuild/BUILD/electroneum-4.0.0.0/src/device_trezor/trezor/transport.hpp
- /home/abuild/rpmbuild/BUILD/electroneum-4.0.0.0/src/device_trezor/trezor/transport.cpp