From 100b7bc10dcb83f81d6bbd37eca1c8708c4dfbb6 Mon Sep 17 00:00:00 2001 From: cslashm Date: Mon, 26 Mar 2018 12:38:38 +0200 Subject: Change mutex lock model to avoid dead lock and ensure locks are always released. Additional cosmetic fixes: move 'name' as protected remove unnecessary local var Fix debug log --- src/device/device.hpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/device/device.hpp') diff --git a/src/device/device.hpp b/src/device/device.hpp index b47460472..dee191234 100644 --- a/src/device/device.hpp +++ b/src/device/device.hpp @@ -78,8 +78,10 @@ namespace hw { return false; } - class device { + protected: + std::string name; + public: device() {} @@ -92,8 +94,6 @@ namespace hw { static const int SIGNATURE_FAKE = 1; - std::string name; - /* ======================================================================= */ /* SETUP/TEARDOWN */ /* ======================================================================= */ @@ -104,7 +104,15 @@ namespace hw { virtual bool release() = 0; virtual bool connect(void) = 0; - virtual bool disconnect() = 0; + virtual bool disconnect(void) = 0; + + /* ======================================================================= */ + /* LOCKER */ + /* ======================================================================= */ + virtual void lock(void) = 0; + virtual void unlock(void) = 0; + virtual bool try_lock(void) = 0; + /* ======================================================================= */ /* WALLET & ADDRESS */ -- cgit v1.2.3 From c77d2bfaa0e0390e421b4d337f49451d504f7046 Mon Sep 17 00:00:00 2001 From: cslashm Date: Mon, 26 Mar 2018 12:55:48 +0200 Subject: Add the possibility to export private view key for fast scan. On client startup the device asks for authorization to export the private view key. If user agree, the client hold the private view key allowing a fast blockchain scan. If the user does not agree, the blockchain scan is fully done via the device. --- src/device/device.hpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/device/device.hpp') diff --git a/src/device/device.hpp b/src/device/device.hpp index dee191234..db489ff0c 100644 --- a/src/device/device.hpp +++ b/src/device/device.hpp @@ -78,6 +78,7 @@ namespace hw { return false; } + class device { protected: std::string name; @@ -89,10 +90,12 @@ namespace hw { virtual ~device() {} explicit virtual operator bool() const = 0; - - static const int SIGNATURE_REAL = 0; - static const int SIGNATURE_FAKE = 1; - + enum device_mode { + NONE, + TRANSACTION_CREATE_REAL, + TRANSACTION_CREATE_FAKE, + TRANSACTION_PARSE + }; /* ======================================================================= */ /* SETUP/TEARDOWN */ @@ -106,6 +109,9 @@ namespace hw { virtual bool connect(void) = 0; virtual bool disconnect(void) = 0; + virtual bool set_mode(device_mode mode) = 0; + + /* ======================================================================= */ /* LOCKER */ /* ======================================================================= */ @@ -166,8 +172,6 @@ namespace hw { virtual bool open_tx(crypto::secret_key &tx_key) = 0; - virtual bool set_signature_mode(unsigned int sig_mode) = 0; - virtual bool encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) = 0; bool decrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) { @@ -191,6 +195,12 @@ namespace hw { virtual bool close_tx(void) = 0; } ; + struct reset_mode { + device& hwref; + reset_mode(hw::device& dev) : hwref(dev) { } + ~reset_mode() { hwref.set_mode(hw::device::NONE);} + }; + device& get_device(const std::string device_descriptor) ; } -- cgit v1.2.3