Daemon-specific proxy for the wallet-rpc.
1. Daemon-specific proxy is exclusive with global proxy (--proxy). 2. If you set global proxy (--proxy) you cannot set daemon-specific proxy. 3. If you don't set global proxy, you can set proxy (or not set) proxy for each daemon connection with the proxy field in jsonrpc to the wallet-rpc.
This commit is contained in:
parent
059028a30a
commit
c50ade514f
@ -1267,6 +1267,11 @@ bool wallet2::has_stagenet_option(const boost::program_options::variables_map& v
|
||||
return command_line::get_arg(vm, options().stagenet);
|
||||
}
|
||||
|
||||
bool wallet2::has_proxy_option() const
|
||||
{
|
||||
return !m_proxy.empty();
|
||||
}
|
||||
|
||||
std::string wallet2::device_name_option(const boost::program_options::variables_map& vm)
|
||||
{
|
||||
return command_line::get_arg(vm, options().hw_device);
|
||||
@ -1351,12 +1356,15 @@ std::unique_ptr<wallet2> wallet2::make_dummy(const boost::program_options::varia
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool wallet2::set_daemon(std::string daemon_address, boost::optional<epee::net_utils::http::login> daemon_login, bool trusted_daemon, epee::net_utils::ssl_options_t ssl_options)
|
||||
bool wallet2::set_daemon(std::string daemon_address, boost::optional<epee::net_utils::http::login> daemon_login, bool trusted_daemon, epee::net_utils::ssl_options_t ssl_options, const std::string& proxy)
|
||||
{
|
||||
boost::lock_guard<boost::recursive_mutex> lock(m_daemon_rpc_mutex);
|
||||
|
||||
if(m_http_client->is_connected())
|
||||
m_http_client->disconnect();
|
||||
CHECK_AND_ASSERT_MES2(m_proxy.empty() || proxy.empty() , "It is not possible to set global proxy (--proxy) and daemon specific proxy together.");
|
||||
if(m_proxy.empty())
|
||||
CHECK_AND_ASSERT_MES(set_proxy(proxy), false, "failed to set proxy address");
|
||||
const bool changed = m_daemon_address != daemon_address;
|
||||
m_daemon_address = std::move(daemon_address);
|
||||
m_daemon_login = std::move(daemon_login);
|
||||
@ -1386,7 +1394,8 @@ bool wallet2::set_proxy(const std::string &address)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool wallet2::init(std::string daemon_address, boost::optional<epee::net_utils::http::login> daemon_login, const std::string &proxy_address, uint64_t upper_transaction_weight_limit, bool trusted_daemon, epee::net_utils::ssl_options_t ssl_options)
|
||||
{
|
||||
CHECK_AND_ASSERT_MES(set_proxy(proxy_address), false, "failed to set proxy address");
|
||||
m_proxy = proxy_address;
|
||||
CHECK_AND_ASSERT_MES(set_proxy(m_proxy), false, "failed to set proxy address");
|
||||
m_checkpoints.init_default_checkpoints(m_nettype);
|
||||
m_is_initialized = true;
|
||||
m_upper_transaction_weight_limit = upper_transaction_weight_limit;
|
||||
|
@ -962,6 +962,12 @@ private:
|
||||
|
||||
std::string path() const;
|
||||
|
||||
/*!
|
||||
* \brief has_proxy_option Check the global proxy (--proxy) has been defined or not.
|
||||
* \return returns bool representing the global proxy (--proxy).
|
||||
*/
|
||||
bool has_proxy_option() const;
|
||||
|
||||
/*!
|
||||
* \brief verifies given password is correct for default wallet keys file
|
||||
*/
|
||||
@ -992,7 +998,8 @@ private:
|
||||
epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
|
||||
bool set_daemon(std::string daemon_address = "http://localhost:8080",
|
||||
boost::optional<epee::net_utils::http::login> daemon_login = boost::none, bool trusted_daemon = true,
|
||||
epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
|
||||
epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_autodetect,
|
||||
const std::string &proxy = "");
|
||||
bool set_proxy(const std::string &address);
|
||||
|
||||
void stop() { m_run.store(false, std::memory_order_relaxed); m_message_store.stop(); }
|
||||
@ -1771,6 +1778,7 @@ private:
|
||||
cryptonote::account_base m_account;
|
||||
boost::optional<epee::net_utils::http::login> m_daemon_login;
|
||||
std::string m_daemon_address;
|
||||
std::string m_proxy;
|
||||
std::string m_wallet_file;
|
||||
std::string m_keys_file;
|
||||
std::string m_mms_file;
|
||||
|
@ -4407,6 +4407,13 @@ namespace tools
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_wallet->has_proxy_option() && !req.proxy.empty())
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_PROXY_ALREADY_DEFINED;
|
||||
er.message = "It is not possible to set daemon specific proxy when --proxy is defined.";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::vector<uint8_t>> ssl_allowed_fingerprints;
|
||||
ssl_allowed_fingerprints.reserve(req.ssl_allowed_fingerprints.size());
|
||||
for (const std::string &fp: req.ssl_allowed_fingerprints)
|
||||
@ -4449,7 +4456,7 @@ namespace tools
|
||||
if (!req.username.empty() || !req.password.empty())
|
||||
daemon_login.emplace(req.username, req.password);
|
||||
|
||||
if (!m_wallet->set_daemon(req.address, daemon_login, req.trusted, std::move(ssl_options)))
|
||||
if (!m_wallet->set_daemon(req.address, daemon_login, req.trusted, std::move(ssl_options), req.proxy))
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_NO_DAEMON_CONNECTION;
|
||||
er.message = std::string("Unable to set daemon");
|
||||
|
@ -2581,6 +2581,7 @@ namespace wallet_rpc
|
||||
std::string ssl_ca_file;
|
||||
std::vector<std::string> ssl_allowed_fingerprints;
|
||||
bool ssl_allow_any_cert;
|
||||
std::string proxy;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(address)
|
||||
@ -2593,6 +2594,7 @@ namespace wallet_rpc
|
||||
KV_SERIALIZE(ssl_ca_file)
|
||||
KV_SERIALIZE(ssl_allowed_fingerprints)
|
||||
KV_SERIALIZE_OPT(ssl_allow_any_cert, false)
|
||||
KV_SERIALIZE_OPT(proxy, (std::string)"")
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
typedef epee::misc_utils::struct_init<request_t> request;
|
||||
|
@ -79,3 +79,4 @@
|
||||
#define WALLET_RPC_ERROR_CODE_ZERO_AMOUNT -46
|
||||
#define WALLET_RPC_ERROR_CODE_INVALID_SIGNATURE_TYPE -47
|
||||
#define WALLET_RPC_ERROR_CODE_DISABLED -48
|
||||
#define WALLET_RPC_ERROR_CODE_PROXY_ALREADY_DEFINED -49
|
||||
|
Loading…
Reference in New Issue
Block a user