Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hw_device: support for multiple devices added [for review] #4299

Merged
merged 1 commit into from
Sep 18, 2018

Conversation

ph4r05
Copy link
Contributor

@ph4r05 ph4r05 commented Aug 23, 2018

  • Device name is a new wallet property
  • Full device name is now a bit more structured so we can address particular device vendor + device path. Example: Ledger, Trezor:udp, Trezor:udp:127.0.0.1:21324, Trezor:bridge:usb01. The part before : identifies HW device implementation, the optional part after : is device path to look for.
  • Device registry changed a bit so devices can be registered also in runtime - required for Trezor to break circular dependencies (Trezor is in separate cmake module as it has more dependencies which would cause circular deps)
  • New --hw-device parameter added to the wallet, can name the hardware device
  • Device reconnect command added to wallet2 and simplewallet

for( const auto& sm_pair : devices.registry ) {
auto device = registry.find(device_descriptor_lookup);
if (device == registry.end()) {
MERROR("device not found in registry: '" << device_descriptor << "'\n" << "known devices:");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That \n sucks because for grep etc it adds lines without the right format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, will fix it

device& get_device(const std::string & device_descriptor);
};

static std::unique_ptr<device_registry> registry;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bad idea as you may end up with several versions of that. Put it in a cpp file.

}

} catch(std::exception & e){
LOG_PRINT_L2(std::string("Device reconnect failed: ") + e.what());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using the severity based macros in new code, not the old ones. Moreover, you don't have to cast anything: MERROR("Device reconnect failed: " << e.what()); Also the previous error is shown to the user, but not this one ?

const auto pwd_container = get_and_verify_password();
if (pwd_container)
{
m_wallet->device_name(args[0]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem to check there is an argument

try {
r = m_wallet->reconnect_device();
if (!r){
fail_msg_writer() << "Device reconnect failed";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tr() for user visible output.

@@ -2188,6 +2189,28 @@ bool simple_wallet::set_ignore_fractional_outputs(const std::vector<std::string>
return true;
}

bool simple_wallet::set_device_name(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
const auto pwd_container = get_and_verify_password();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can change that on the fly, which password are you verifying here, since the password is on the hw AFAIK ? No other place in simplewallet expects you can load another wallet on the fly. Is this actually needed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm you are right, the on the fly change of the device is not really needed.

The original idea is to address the situation where the device descriptor changes (device path) so the user can fix the device name / path, otherwise wallet won't connect / work.
This solution does not fix it well as the wallet cannot be started if the device is not found. I will just let to specify the device with the command line argument, that should do the job. Thanks!

{
bool r = m_wallet->reconnect_device();
if (!r){
fail_msg_writer() << "Failed to reconnect device";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tr()

}
catch (const std::exception &e)
{
fail_msg_writer() << "Failed to reconnect device: " << e.what();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tr()

src/wallet/wallet2.cpp Show resolved Hide resolved
@@ -940,6 +941,8 @@ namespace tools
void ignore_fractional_outputs(bool value) { m_ignore_fractional_outputs = value; }
bool confirm_non_default_ring_size() const { return m_confirm_non_default_ring_size; }
void confirm_non_default_ring_size(bool always) { m_confirm_non_default_ring_size = always; }
std::string device_name() const { return m_device_name; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be const std::string &

@ph4r05
Copy link
Contributor Author

ph4r05 commented Aug 24, 2018

@moneromooo-monero thanks for review! I will fix it soon

@ph4r05 ph4r05 force-pushed the multi-device branch 3 times, most recently from 12f140d to 135015f Compare August 25, 2018 01:49
auto device_descriptor_lookup = device_descriptor;
if (delim != std::string::npos) {
device_descriptor_lookup = device_descriptor.substr(0, delim);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if adding a mutex for acessing the global would be better. It seems safe reading this anyway.

- device name is a new wallet property
- full device name is now a bit more structured so we can address particular device vendor + device path. Example: 'Ledger', 'Trezor:udp', 'Trezor:udp:127.0.0.1:21324', 'Trezor:bridge:usb01'. The part before ':' identifies HW device implementation, the optional part after ':' is device path to look for.
- new --hw-device parameter added to the wallet, can name the hardware device
- device reconnect added
Copy link
Contributor

@fluffypony fluffypony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed

@fluffypony fluffypony merged commit f9b22a7 into monero-project:master Sep 18, 2018
fluffypony added a commit that referenced this pull request Sep 18, 2018
f9b22a7 hw_device: support for multiple devices added [for review] (Dusan Klinec)
@ph4r05 ph4r05 deleted the multi-device branch January 3, 2020 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants