mirror of
https://github.com/wownero/wownero.git
synced 2026-11-28 03:43:54 +01:00
device: implement default device locking
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <boost/thread/lock_guard.hpp>
|
||||||
#include "device_default.hpp"
|
#include "device_default.hpp"
|
||||||
#include "int-util.h"
|
#include "int-util.h"
|
||||||
#include "crypto/wallet/crypto.h"
|
#include "crypto/wallet/crypto.h"
|
||||||
@@ -82,19 +83,32 @@ namespace hw {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// serialize mode access so callers cannot observe another wallet's transient signing mode
|
||||||
bool device_default::set_mode(device_mode mode) {
|
bool device_default::set_mode(device_mode mode) {
|
||||||
|
boost::lock_guard<boost::recursive_mutex> lock(device_locker);
|
||||||
return device::set_mode(mode);
|
return device::set_mode(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
device::device_mode device_default::get_mode() const {
|
||||||
|
boost::lock_guard<boost::recursive_mutex> lock(device_locker);
|
||||||
|
return device::get_mode();
|
||||||
|
}
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
/* LOCKER */
|
/* LOCKER */
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
|
|
||||||
void device_default::lock() { }
|
void device_default::lock() {
|
||||||
|
device_locker.lock();
|
||||||
|
}
|
||||||
|
|
||||||
bool device_default::try_lock() { return true; }
|
bool device_default::try_lock() {
|
||||||
|
return device_locker.try_lock();
|
||||||
|
}
|
||||||
|
|
||||||
void device_default::unlock() { }
|
void device_default::unlock() {
|
||||||
|
device_locker.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
/* WALLET & ADDRESS */
|
/* WALLET & ADDRESS */
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <boost/thread/recursive_mutex.hpp>
|
||||||
#include "device.hpp"
|
#include "device.hpp"
|
||||||
|
|
||||||
namespace hw {
|
namespace hw {
|
||||||
@@ -60,6 +61,7 @@ namespace hw {
|
|||||||
bool disconnect() override;
|
bool disconnect() override;
|
||||||
|
|
||||||
bool set_mode(device_mode mode) override;
|
bool set_mode(device_mode mode) override;
|
||||||
|
device_mode get_mode() const override;
|
||||||
|
|
||||||
device_type get_type() const override {return device_type::SOFTWARE;};
|
device_type get_type() const override {return device_type::SOFTWARE;};
|
||||||
|
|
||||||
@@ -141,6 +143,10 @@ namespace hw {
|
|||||||
bool clsag_sign(const rct::key &c, const rct::key &a, const rct::key &p, const rct::key &z, const rct::key &mu_P, const rct::key &mu_C, rct::key &s) override;
|
bool clsag_sign(const rct::key &c, const rct::key &a, const rct::key &p, const rct::key &z, const rct::key &mu_P, const rct::key &mu_C, rct::key &s) override;
|
||||||
|
|
||||||
bool close_tx(void) override;
|
bool close_tx(void) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Locker for concurrent access
|
||||||
|
mutable boost::recursive_mutex device_locker;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user